Jump to content

monitor changes OR force gid/umask, inside a directory ?


Recommended Posts

Is it possible to monitor a directory, so that:

- if a file or sub-directory is created or modified inside, however deep inside the monitored directory,

- then a script can automatically be applied to the created/modified file/directory? (typically chgrp+chmod)

 

I've heard about "fam" that may be the answer, but I can't seem to find doc about it on internet...

 

Alternatively, is there a better/simpler solution, to just ensure that any content under a given directory is always read/writable for all members of a group (sort of forcing the gid and umask of that directory), without having to place this directory on a separate partition ? (because I know it is feasible with a mounted FAT32 partition, and besides, I want to rely on XFS or ReiserFS...)

 

Thanks,

 

Yves.

Link to comment
Share on other sites

Yes, indeed; and you probably saw that I wrote my version of the answer on this thread.

But as I wrote there, this is not the definitive solution. There's one big problem:

 

Unless I'm just plain wrong, when you set the s bit on a directory, you're sure that any file or directory created under the s'ed directory has the same rwx rights for user, group and others. BUT the s bit itself is not transmited, so files and directories created under a subdirectory of the s'ed directory do not follow the same pattern. That's why in my answer, I regularly do a find -type d -exec chmod.

 

Example:

Let's say I have the /data directory with user "root" and group "share". Here it is after the chmod:

6770 root share /data

I can be sure that any file created inside will inherit the mask from the middle two digits, as well as the user and group, so any file or directory will be listed like this:

6770 root share /data

0660 root share /data/a-file

0770 root share /data/a-directory

0660 root share /data/other-files

0770 root share /data/other-directories

But if user "user" of group "group" now creates a file or directory inside a subdirectory, then here's (for example) what I'll get:

6770 root share /data

0770 root share /data/a-directory

0644 user group /data/a-directory/file

0755 user group /data/a-directory/directory

... Unless I first execute

chmod ug+s /data/a-directory

...

 

So, is there a better way, than regularly executing chmod and chown (or chgrp) commands ? (Or am I simply wrong? I don't have Linux at hand right now...)

 

Yves.

Link to comment
Share on other sites

I've tested it again right now, and yes, it works. The group mask and the SGID is maintained across all the subdirectories, no matter what level of subdirectory and no matter who creates the new directories or files (I've created several dirs and a couple of files with different users, and the group mask and id persisted in all the tree):

 

/home# find /home/foo -type d -exec sh -c 'echo -e "nls -dl $0/*" && ls -dl $0/*' '{}';



ls -dl /home/foo/*

drwxrwsr-x    3 indra    internet      104 abr  9 16:10 /home/foo/indrafoo



ls -dl /home/foo/indrafoo/*

drwxrwsr-x    3 indra    internet       72 abr  9 16:04 /home/foo/indrafoo/foo

-rw-rw-r--    1 indra    internet        0 abr  9 16:10 /home/foo/indrafoo/indrafile



ls -dl /home/foo/indrafoo/foo/*

drwxrwsr-x    2 arusabal internet       72 abr  9 16:09 /home/foo/indrafoo/foo/arusabalfoo



ls -dl /home/foo/indrafoo/foo/arusabalfoo/*

-rw-rw-r--    1 arusabal internet        0 abr  9 16:09 /home/foo/indrafoo/foo/arusabalfoo/foofile

/home#

 

The files itself doesn't need the "s", because what is transmited is the 'group id' of the directory to the new files created.

Then if the rootdir has the SGID, independently of the depth level:

 

[*]The new directories will inherit the umask, the group id, and the SGID

 

[*]The new files will inherit the umask (in file terms) and the group id. But not the SGID because the files doesn't need it at all, as they have the "group id" which allows their editing by the members of the group.

 

So the way to go is with the "chgrp workgroup rootdir/ && chmod g+s rootdir/".

 

...Or maybe I'm missing something else?

 

HTH

Link to comment
Share on other sites

OFFTOPIC

/home# find /home/foo -type d -exec sh -c 'echo -e "nls -dl $0/*" && ls -dl $0/*' '{}';

After reinventing the wheel this morning, I've remembered that "ls -lR /home/foo" does exaclty the same that the above command... I'm getting old :P

Link to comment
Share on other sites

Not related directly but i recall YinYeti was asking about sharing via samba, you can add stuff to the smb.conf file like this:

 

directory mode = 0777

force directory mode = 0777

create mode = 0777

force create mode = 0777

force group = monsters

force user = imp

 

This will set the permissions for all directorys and files created through samba

I would recommend putting it only in the share section of the smb.conf file rather than the global part else it would be global :? :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...