SUID/GUID files search !

Paul Howarth paul at city-fan.org
Tue Feb 1 12:03:03 UTC 2005


fly over wrote:

(please don't top-post on this mailing list - it makes posts harder to 
follow)

 > From: Paul Howarth <paul at city-fan.org>
 > Subject: Re: SUID/GUID files search !
 > To: For users of Fedora Core releases <fedora-list at redhat.com>
 >
 > fly over wrote:
 >
 >>Hi guys, i'm trying to write a script for following purpose.
 >>
 >>shell program will be used by Linux/Unix sysadmins to search for
 >>SUID/SGID files. The default directory to search is the present
 >>working directory, however, the user may include a directory name
 >>on the command line as an alternative. Also, if the user includes
 >>the argument '-R' then the search should include all subdirectories
 >>recursively. Also, the '-G' argument will include SGID files which
 >>by default are not shown. The output of the script should show the
 >>absolute pathname of the file and the owner.
 >>
 >>
 >>Please help me in performin such task.
 >
 >
 > Sounds like a homework assignment to me...
 >
 >
 >>i'm trying using this line:
 >>
 >>ls -l | awk '{print $1}' | grep s
 >>it just prints the permissions having s bit.
 >
 >
 > Yes, that's right. Your awk command is just printing the first field of
 > the ls -l output, which is the permissions. What you want to do is to
 > search the permissions but output the filename, something more like this:
 >
 > $ ls -l | awk '/^-..[Ss]/ { print $9 }'
 >
 > This looks for regular files (1st character of line is "-") that have
 > the SUID bit set (fourth character of line is "s" or "S") and then
 > prints out the filename (9th field of line).
 >
 > You probably want to be using the "find" command rather than the "ls"
 > command though. Use "-maxdepth 1" by default to turn off its recursive
 > checking of directories, and skip the "-maxdepth 1" option when your
 > script is passed the -R option.

fly over wrote:
> Thanks Paul for supporting, yes it is a sort of assignment but from my boss.
> as your script returning file name, Please tell me how can i get the 
> absolute pathname of the file and the owner.

Try something like this:

DIR=`pwd` # starting directory
RECURSE_OPTION="-maxdepth 1" # "" for recursive search
PERM_BITS=04000 # 06000 for both SUID and SGID
find $DIR $RECURSE_OPTION -perm +$PERM_BITS -type f -printf '%p %u\n'

Paul.




More information about the fedora-list mailing list