setgid on directories

Jim Ogilvie jogilvie at us.ibm.com
Wed Mar 17 15:41:04 GMT 2004





We needed the group id bit to always be set on directories when rsync
creates them. We always run
rsync from a script with just the -ltR options.  The destination file
system uses acl's to control file access
so new files need to inherit the properties of the directories they're in.
(This is for IBM's global storage
architecture on Aix or Linux).

I made the following changes to make rsync set the group id bit on new
directories. It seems to work
fine for what I needed. I doubt you'll want to include the patch but
thought someone might say if this
is a bad way to do it, or have a better way to do it.

I added the --setgid_dirs option to enable it.  I catch incoming rsync
connections in a script run as a
forced command by ssh, reject connections if the -p option is set, and add
in my --setgid_dirs option.

The patch is incomplete since the option doesn't get passed to a remote
call. If there's any interest in
adding this to rsync, I can try to figure out how to pass the option.

--- generator.c   Tue Dec 23 20:14:16 2003
+++ ../rsync-2.6.0.gsa/generator.c  Thu Feb 12 12:16:11 2004
@@ -41,6 +41,7 @@
 extern int modify_window;
 extern char *compare_dest;
 extern int link_dest;
+extern int setgid_dirs;


 /* choose whether to skip a particular file */
@@ -557,6 +558,11 @@
               them. This is then fixed after the files are transferred */
            if (!am_root && S_ISDIR(file->mode)) {
                  file->mode |= S_IWUSR; /* user write */
+
+      if( setgid_dirs){
+        file->mode |= S_ISGID;
+      }
+
                  /* XXX: Could this be causing a problem on SCO?  Perhaps
their
                   * handling of permissions is strange? */
            }

--- options.c     Tue Dec 30 13:16:25 2003
+++ ../rsync-2.6.0.gsa/options.c    Thu Feb 12 12:22:21 2004
@@ -88,6 +88,7 @@
 int ignore_errors=0;
 int modify_window=0;
 int blocking_io=-1;
+int setgid_dirs=0;


 /** Network address family. **/
@@ -380,6 +381,7 @@
   {0,                  '4', POPT_ARG_VAL,    &default_af_hint, AF_INET, 0,
0 },
   {0,                  '6', POPT_ARG_VAL,    &default_af_hint, AF_INET6,
0, 0 },
 #endif
+  {"setgid_dirs",      0,  POPT_ARG_NONE,   &setgid_dirs, 0, 0, 0 },
   {0,0,0,0, 0, 0, 0}
 };

Jim Ogilvie


More information about the rsync mailing list