/* rexx */ /*********************************************************************** Author: Bill Schoen wjs@us.ibm.com Title: fsadmin utility This utility gives a non-superuser special capabilities on files sytems he owns. The owner of a file system is defined as the owner of root directory for that file system. Current capabilities are chown, chgrp, and chmod for any file node in that file system. A list of owning file systems can also be printed. Use fsadmin help for full usage information. Install note: This utility must be installed with UID=0 as the owner and with the setuid bit turned on. PROPERTY OF IBM COPYRIGHT IBM CORP. 1998,2000 last update: 4/12/00 ***********************************************************************/ address syscall cmd=translate(__argv.2) 'getuid' myuid=retval 'getlogin myuserid' select when cmd='CHGRP' then call chgrp when cmd='CHMOD' then call chmod when cmd='CHOWN' then call chown when cmd='DF' then call df when cmd='HELP' then call help otherwise usage: say 'Usage: for full syntax enter: fsadmin help' exit 1 end return 0 chown: p.='' m='' if __argv.0<4 then signal usage user=translate(__argv.3) if datatype(user,'w') then do uid=user 'getpwuid (uid) p.' user=p.pw_name if user='' then m='Invalid uid:' uid end else do 'getpwnam (user) p.' uid=p.pw_uid if uid='' then m='Invalid userid:' user end if m<>'' then say m else do k=4 to __argv.0 m=dochown(__argv.k) if m<>'' then say m end return dochown: parse arg ipath m=getpath() if m<>'' then return m g.='' g.0=0 'getgrgid' st.st_gid 'g.' do i=gr_mem to g.0 if g.i=myuserid then leave end if g.i<>myuserid then return path': you are not a member of group' g.gr_name do i=gr_mem to g.0 if g.i=user then leave end if g.i<>user then return path':' user'('uid') is not a member of group' g.gr_name 'chown (path)' uid st.st_gid if retval<>-1 then return '' return path 'chown error:' errno errnojr chgrp: p.='' m='' if __argv.0<4 then signal usage grp=translate(__argv.3) user=myuserid if datatype(grp,'w') then do gid=grp 'getgrgid (gid) p.' grp=p.gr_name if grp='' then m='Invalid gid:' gid end else do 'getgrnam (grp) p.' gid=p.gr_gid if gid='' then m='Invalid groupid:' grp end if m<>'' then say m else do g.0=0 'getgroups g.' do i=1 to g.0 if g.i=gid then leave end if g.i=gid then do k=4 to __argv.0 m=dochgrp(__argv.k) if m<>'' then say m end else say path':' user 'is not a member of group' grp'('gid')' end return dochgrp: parse arg ipath m=getpath() if m<>'' then return m pw.='' 'getpwuid' st.st_uid 'pw.' fowner=strip(pw.pw_name) do i=gr_mem to p.0 if p.i=fowner then leave end if p.i<>fowner then return path':' fowner'('st.st_uid') is not in group' grp'('gid')' 'chown (path)' st.st_uid gid if retval<>-1 then return '' return path 'chown error:' errno errnojr chmod: p.='' m='' if __argv.0<4 then signal usage mode=__argv.3 if verify(mode,'01234567')>0 | length(mode)>3 then signal usage do k=4 to __argv.0 ipath=__argv.k m=getpath() if m<>'' then do say m iterate end 'chmod (path)' mode if retval=-1 then say path 'chmod error:' errno errnojr end return df: coln=0 call cols 'Avail','Total','File system','Pathname' mnt.='' 'getmntent mnt.' do i=1 to mnt.0 path=mnt.mnte_path.i 'stat (path) st.' if st.st_uid<>myuid then iterate fs=strip(mnt.mnte_fsname.i) 'statfs (fs) stfs.' call cols stfs.stfs_avail,stfs.stfs_total,fs,path end do i=1 to coln ln='' do j=1 by 1 while coln.0.j>0 if j<3 then ln=ln || right(colv.i.j,coln.0.j) || ' ' else ln=ln || left(colv.i.j,coln.0.j) || ' ' end say ln end return getpath: /* sets path and stats into st. */ 'realpath (ipath) path' if retval=-1 then return 'Unable to resolve pathname' path st.='' 'stat (path) st.' mnt.='' 'getmntent mnt.' st.st_dev mst.='' 'stat' mnt.mnte_path.1 'mst.' if mst.st_uid<>myuid then return 'You do not own' mnt.mnte_path.1 return '' cols: if coln=0 then do coln.=0 colv.='' end coln=coln+1 do ci=1 to arg() colv.coln.ci=arg(ci) cj=length(arg(ci)) coln.coln.ci=cj if cj>coln.0.ci then coln.0.ci=cj end return help: procedure address syscall do i=1 to sourceline(), while sourceline(i)<>'' end do i=i+1 to sourceline(), while sourceline(i)<>'' say sourceline(i) end return /* Help for fsadmin utility ------------------------ This utility gives a non-superuser special capabilities on files systems he owns. The owner of a file system is defined as the owner of root directory for that file system. Current capabilities are chown, chgrp, and chmod for any file node in that file system. A list of owning file systems can also be printed. Syntax: ====== fsadmin chgrp groupid|gid filename... fsadmin chmod octal_mode filename... fsadmin chown userid|uid filename... fsadmin df Subcommands: =========== chown: Use this to change the owner of files or directories. Specify either the new owner name or the new uid for the files. The new owner must be a member of the file's current group. chgrp: Use this to change the group of files or directories. Specify either the new group name or the new gid for the files. You and the file owner must be a member of the new group. chmod: Use this to change the permission bits of files or directories. Specify the new permission bits in octal format for the files. The special mode bits (setuid, setgid, sticky) cannot be set. df: Use this to display a list of the file systems you own. It displays file system utilization information in units of block size, the name of the file system, and the mountpoint pathname. Install note: ============ This utility must be installed with UID=0 as the owner and with the setuid bit turned on. */