ba16931b9d0f86b161c0d475321d8ea22d6c0a7b
[rsync-patches.git] / rsyncd-perm.diff
1 --- orig/loadparm.c     2005-06-10 21:33:28
2 +++ loadparm.c  2005-06-10 23:38:53
3 @@ -143,6 +143,10 @@ typedef struct
4         int timeout;
5         int max_connections;
6         int max_verbosity;
7 +       int create_mask;
8 +       int force_create_mode;
9 +       int directory_mask;
10 +       int force_directory_mode;
11         BOOL ignore_nonreadable;
12  } service;
13  
14 @@ -178,6 +182,10 @@ static service sDefault =
15         0,        /* timeout */
16         0,        /* max connections */
17         1,        /* max verbosity */
18 +       CHMOD_BITS,/* create mask */
19 +       0,        /* force create mode */
20 +       CHMOD_BITS,/* directory mask */
21 +       0,        /* force directory mode */
22         False     /* ignore nonreadable */
23  };
24  
25 @@ -298,6 +306,10 @@ static struct parm_struct parm_table[] =
26    {"log format",       P_STRING,  P_LOCAL,  &sDefault.log_format,  NULL,   0},
27    {"refuse options",   P_STRING,  P_LOCAL,  &sDefault.refuse_options,NULL, 0},
28    {"dont compress",    P_STRING,  P_LOCAL,  &sDefault.dont_compress,NULL,  0},
29 +  {"create mask",      P_OCTAL,   P_LOCAL,  &sDefault.create_mask, NULL, 0},
30 +  {"force create mode",P_OCTAL,   P_LOCAL,  &sDefault.force_create_mode, NULL, 0},
31 +  {"directory mask",   P_OCTAL,   P_LOCAL,  &sDefault.directory_mask, NULL, 0},
32 +  {"force directory mode",P_OCTAL,P_LOCAL,  &sDefault.force_directory_mode, NULL, 0},
33    {NULL,               P_BOOL,    P_NONE,   NULL,                  NULL,   0}
34  };
35  
36 @@ -382,6 +394,10 @@ FN_LOCAL_STRING(lp_dont_compress, dont_c
37  FN_LOCAL_INTEGER(lp_timeout, timeout)
38  FN_LOCAL_INTEGER(lp_max_connections, max_connections)
39  FN_LOCAL_INTEGER(lp_max_verbosity, max_verbosity)
40 +FN_LOCAL_INTEGER(lp_create_mask, create_mask)
41 +FN_LOCAL_INTEGER(lp_force_create_mode, force_create_mode)
42 +FN_LOCAL_INTEGER(lp_directory_mask, directory_mask)
43 +FN_LOCAL_INTEGER(lp_force_directory_mode, force_directory_mode)
44  
45  /* local prototypes */
46  static int    strwicmp(char *psz1, char *psz2);
47 --- orig/rsync.c        2005-07-27 23:31:12
48 +++ rsync.c     2005-07-28 00:54:53
49 @@ -32,6 +32,8 @@ extern int am_server;
50  extern int am_sender;
51  extern int am_generator;
52  extern int am_starting_up;
53 +extern int am_daemon;
54 +extern int module_id;
55  extern int preserve_uid;
56  extern int preserve_gid;
57  extern int inplace;
58 @@ -56,6 +58,7 @@ int set_perms(char *fname,struct file_st
59         int updated = 0;
60         STRUCT_STAT st2;
61         int change_uid, change_gid;
62 +       mode_t mode = file->mode; /* file->mode shouldn't be modified */
63  
64         if (!st) {
65                 if (dry_run)
66 @@ -125,9 +128,19 @@ int set_perms(char *fname,struct file_st
67                 updated = 1;
68         }
69  
70 +       if (am_daemon) {
71 +               if (S_ISDIR(st->st_mode)) {
72 +                       mode = (mode & lp_directory_mask(module_id))
73 +                            | lp_force_directory_mode(module_id);
74 +               } else {
75 +                       mode = (mode & lp_create_mask(module_id))
76 +                            | lp_force_create_mode(module_id);
77 +               }
78 +       }
79 +
80  #ifdef HAVE_CHMOD
81 -       if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
82 -               int ret = do_chmod(fname, file->mode);
83 +       if ((st->st_mode & CHMOD_BITS) != (mode & CHMOD_BITS)) {
84 +               int ret = do_chmod(fname, mode);
85                 if (ret < 0) {
86                         rsyserr(FERROR, errno,
87                                 "failed to set permissions on %s",
88 --- orig/rsyncd.conf.yo 2005-07-07 23:11:09
89 +++ rsyncd.conf.yo      2005-03-31 08:28:41
90 @@ -221,6 +221,70 @@ file transfers to and from that module s
91  was run as root. This complements the "uid" option. The default is gid -2,
92  which is normally the group "nobody".
93  
94 +dit(bf(create mask)) When a file is created (or touched) by rsyncd the
95 +permissions will be taken from the source file bit-wise 'AND'ed with this
96 +parameter. This parameter may be thought of as a bit-wise MASK for the UNIX
97 +modes of a file. Any bit not set here will be removed from the modes set
98 +on a file when it is created.
99 +
100 +The default value of this parameter is set to 07777 to be provide the
101 +default behaviour of older versions.
102 +
103 +Following this rsync  will bit-wise 'OR' the UNIX mode created from this
104 +parameter with the value  of the force create mode parameter which is set
105 +to 000 by default.
106 +
107 +This parameter does not affect directory modes. See the parameter
108 +"directory mask" for details.
109 +
110 +See also the "force create mode" parameter for forcing particular mode bits
111 +to be set on created files. See also the "directory mask" parameter for
112 +masking mode bits on created directories.
113 +
114 +dit(bf(force create mode)) This parameter specifies a set of UNIX
115 +mode bit permissions that will always be set on a file created by
116 +rsyncd. This is done by bitwise 'OR'ing these bits onto the mode
117 +bits of a file that is being created or having its permissions changed.
118 +
119 +The default for this parameter is (in octal) 000.  The modes in this
120 +parameter are bitwise 'OR'ed onto the file mode after the mask set in
121 +the "create mask" parameter is applied.
122 +
123 +See also the parameter "create mask" for details on
124 +masking mode bits on files.
125 +
126 +
127 +dit(bf(directory mask)) When a directory is created (or touched) by
128 +rsyncd the permissions will be taken from the source directory
129 +bit-wise 'AND'ed with this parameter. This parameter may be thought
130 +of as a bit-wise MASK for the UNIX modes of a file. Any bit not set
131 +here will be removed from the modes set on a file when it is created.
132 +
133 +The default value of this parameter is set to 07777 to be provide the
134 +default behaviour of older versions.
135
136 +Following this rsync  will bit-wise 'OR' the UNIX mode created from this
137 +parameter with the value  of the "force directory mode" parameter which
138 +is set to 000 by default.
139 +
140 +This parameter does not affect file modes. See the parameter "create mask"
141 +for details.  
142 +
143 +See also the "force directory mode" parameter for forcing particular
144 +mode bits to be set on created directories. See also the "create mask"
145 +parameter for masking mode bits on created files.
146
147 +dit(bf(force directory mode)) This parameter specifies a set of UNIX mode
148 +bit permissions that will always be set on a directory created by rsyncd.
149 +This is done by bitwise 'OR'ing these bits onto the mode bits of a directory
150 +that is being created. The default for this parameter is (in octal) 0000
151 +which will not add any extra permission bits to a created directory. This
152 +operation is done after the mode mask in the parameter "directory mask"
153 +is applied.
154 +
155 +See also the parameter  directory mask for details on masking mode bits on
156 +created directories.
157 +
158  dit(bf(filter)) The "filter" option allows you to specify a space-separated
159  list of filter rules that the daemon will not allow to be read or written.
160  This is only superficially equivalent to the client specifying these