Commit ee1c00fe authored by Wayne Davison's avatar Wayne Davison

Pass "new_mode" to set_acl() and change its return values.

parent 1b502f3e
...@@ -732,7 +732,7 @@ static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type) ...@@ -732,7 +732,7 @@ static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type)
if (ndx != 0) if (ndx != 0)
return ndx - 1; return ndx - 1;
ndx = racl_list->count; ndx = racl_list->count;
duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000); duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
duo_item->racl = empty_rsync_acl; duo_item->racl = empty_rsync_acl;
...@@ -984,17 +984,17 @@ static int set_rsync_acl(const char *fname, acl_duo *duo_item, ...@@ -984,17 +984,17 @@ static int set_rsync_acl(const char *fname, acl_duo *duo_item,
return 0; return 0;
} }
/* Set ACL on indicated filename. /* Given a fname, this sets extended access ACL entries, the default ACL (for a
* dir), and the regular mode bits on the file. Call this with fname set to
* NULL to just check if the ACL is different.
* *
* This sets extended access ACL entries and default ACL. If convenient, * If the ACL operation has a side-effect of changing the file's mode, the
* it sets permission bits along with the access ACL and signals having * sxp->st.st_mode value will be changed to match.
* done so by modifying sxp->st.st_mode.
* *
* Returns 1 for unchanged, 0 for changed, -1 for failed. Call this * Returns 0 for an unchanged ACL, 1 for changed, -1 for failed. */
* with fname set to NULL to just check if the ACL is unchanged. */ int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp, mode_t new_mode)
int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp)
{ {
int unchanged = 1; int changed = 0;
int32 ndx; int32 ndx;
BOOL eq; BOOL eq;
...@@ -1008,18 +1008,18 @@ int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp) ...@@ -1008,18 +1008,18 @@ int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp)
acl_duo *duo_item = access_acl_list.items; acl_duo *duo_item = access_acl_list.items;
duo_item += ndx; duo_item += ndx;
eq = sxp->acc_acl eq = sxp->acc_acl
&& rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode); && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, new_mode);
if (!eq) { if (!eq) {
unchanged = 0; changed = 1;
if (!dry_run && fname if (!dry_run && fname
&& set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_ACCESS, && set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_ACCESS,
sxp, file->mode) < 0) sxp, new_mode) < 0)
unchanged = -1; return -1;
} }
} }
if (!S_ISDIR(sxp->st.st_mode)) if (!S_ISDIR(new_mode))
return unchanged; return changed;
ndx = F_DIR_DEFACL(file); ndx = F_DIR_DEFACL(file);
if (ndx >= 0 && (size_t)ndx < default_acl_list.count) { if (ndx >= 0 && (size_t)ndx < default_acl_list.count) {
...@@ -1027,16 +1027,15 @@ int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp) ...@@ -1027,16 +1027,15 @@ int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp)
duo_item += ndx; duo_item += ndx;
eq = sxp->def_acl && rsync_acl_equal(sxp->def_acl, &duo_item->racl); eq = sxp->def_acl && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
if (!eq) { if (!eq) {
if (unchanged > 0) changed = 1;
unchanged = 0;
if (!dry_run && fname if (!dry_run && fname
&& set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_DEFAULT, && set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_DEFAULT,
sxp, file->mode) < 0) sxp, new_mode) < 0)
unchanged = -1; return -1;
} }
} }
return unchanged; return changed;
} }
/* Non-incremental recursion needs to convert all the received IDs. /* Non-incremental recursion needs to convert all the received IDs.
......
...@@ -417,7 +417,7 @@ int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp) ...@@ -417,7 +417,7 @@ int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp)
if (preserve_acls && !S_ISLNK(file->mode)) { if (preserve_acls && !S_ISLNK(file->mode)) {
if (!ACL_READY(*sxp)) if (!ACL_READY(*sxp))
get_acl(fname, sxp); get_acl(fname, sxp);
if (set_acl(NULL, file, sxp) == 0) if (set_acl(NULL, file, sxp, file->mode))
return 0; return 0;
} }
#endif #endif
...@@ -476,7 +476,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre ...@@ -476,7 +476,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
if (preserve_acls && !S_ISLNK(file->mode)) { if (preserve_acls && !S_ISLNK(file->mode)) {
if (!ACL_READY(*sxp)) if (!ACL_READY(*sxp))
get_acl(fnamecmp, sxp); get_acl(fnamecmp, sxp);
if (set_acl(NULL, file, sxp) == 0) if (set_acl(NULL, file, sxp, file->mode))
iflags |= ITEM_REPORT_ACL; iflags |= ITEM_REPORT_ACL;
} }
#endif #endif
......
...@@ -497,8 +497,10 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, ...@@ -497,8 +497,10 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
* If set_acl() changes permission bits in the process of setting * If set_acl() changes permission bits in the process of setting
* an access ACL, it changes sxp->st.st_mode so we know whether we * an access ACL, it changes sxp->st.st_mode so we know whether we
* need to chmod(). */ * need to chmod(). */
if (preserve_acls && !S_ISLNK(new_mode) && set_acl(fname, file, sxp) == 0) if (preserve_acls && !S_ISLNK(new_mode)) {
updated = 1; if (set_acl(fname, file, sxp, new_mode) > 0)
updated = 1;
}
#endif #endif
#ifdef HAVE_CHMOD #ifdef HAVE_CHMOD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment