Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How do I generate a listing of all users who can access a directory?

by sgifford (Prior)
on May 04, 2004 at 15:57 UTC ( [id://350384]=note: print w/replies, xml ) Need Help??


in reply to How do I generate a listing of all users who can access a directory?

The most robust way would be to start the program as the root user, loop through the passwd file with getpwent, switch to each of the UIDs, and try to open the file or opendir the directory. That will work with all kinds of ACLs and other oddities your version of Unix may include.

If you know your system only uses standard Unix stuff, you can just open the bottommost directory, make a hash of users who have access to it, then remove one directory component at a time with File::Basename's dirname function. Make sure all of the users in your hash have at least execute permission on that parent directory, and if not delete them from the hash. When you've checked the root filesystem, you're done, and whoever is in the hash can access that directory.

You may also have to deal with symlinks. For some help on that, see 346747.

Replies are listed 'Best First'.
Re: Re: How do I generate a listing of all users who can access a directory?
by BlaisePascal (Monk) on May 04, 2004 at 16:10 UTC
    Hmm, I was thinking of working from root out, trimming the hash, since I've got a directory tree I'm anotating. Going from the file/directory down to the root would work for the general "Why can't this user access this file question" better. I'll try it both ways and see which is faster.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://350384]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found