Add safety check for local --remove-source-files.
[rsync.git] / acls.c
diff --git a/acls.c b/acls.c
index 46c5be5949e097954a32bb35069f9dd8c7abc908..12e662cf445e52af697b9cd180a4b0c1d044afc4 100644 (file)
--- a/acls.c
+++ b/acls.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2006-2013 Wayne Davison
+ * Copyright (C) 2006-2022 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@ extern int preserve_specials;
 /* When we send the access bits over the wire, we shift them 2 bits to the
  * left and use the lower 2 bits as flags (relevant only to a name entry).
  * This makes the protocol more efficient than sending a value that would
- * be likely to have its hightest bits set. */
+ * be likely to have its highest bits set. */
 #define XFLAG_NAME_FOLLOWS 0x0001u
 #define XFLAG_NAME_IS_USER 0x0002u
 
@@ -168,8 +168,6 @@ static rsync_acl *create_racl(void)
 {
        rsync_acl *racl = new(rsync_acl);
 
-       if (!racl)
-               out_of_memory("create_racl");
        *racl = empty_rsync_acl;
 
        return racl;
@@ -332,14 +330,11 @@ static BOOL unpack_smb_acl(SMB_ACL_T sacl, rsync_acl *racl)
        if (temp_ida_list.count) {
 #ifdef SMB_ACL_NEED_SORT
                if (temp_ida_list.count > 1) {
-                       qsort(temp_ida_list.items, temp_ida_list.count,
-                             sizeof (id_access), id_access_sorter);
+                       qsort(temp_ida_list.items, temp_ida_list.count, sizeof (id_access), id_access_sorter);
                }
 #endif
-               if (!(racl->names.idas = new_array(id_access, temp_ida_list.count)))
-                       out_of_memory("unpack_smb_acl");
-               memcpy(racl->names.idas, temp_ida_list.items,
-                      temp_ida_list.count * sizeof (id_access));
+               racl->names.idas = new_array(id_access, temp_ida_list.count);
+               memcpy(racl->names.idas, temp_ida_list.items, temp_ida_list.count * sizeof (id_access));
        } else
                racl->names.idas = NULL;
 
@@ -423,7 +418,7 @@ static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
 #ifdef ACLS_NEED_MASK
        mask_bits = racl->mask_obj == NO_ENTRY ? racl->group_obj & ~NO_ENTRY : racl->mask_obj;
        COE( sys_acl_create_entry,(smb_acl, &entry) );
-       COE( sys_acl_set_info,(entry, SMB_ACL_MASK, mask_bits, NULL) );
+       COE( sys_acl_set_info,(entry, SMB_ACL_MASK, mask_bits, 0) );
 #else
        if (racl->mask_obj != NO_ENTRY) {
                COE( sys_acl_create_entry,(smb_acl, &entry) );
@@ -507,9 +502,7 @@ static int get_rsync_acl(const char *fname, rsync_acl *racl,
 
                if (cnt) {
                        char *bp = buf + 4*4;
-                       id_access *ida;
-                       if (!(ida = racl->names.idas = new_array(id_access, cnt)))
-                               out_of_memory("get_rsync_acl");
+                       id_access *ida = racl->names.idas = new_array(id_access, cnt);
                        racl->names.count = cnt;
                        for ( ; cnt--; ida++, bp += 4+4) {
                                ida->id = IVAL(bp, 0);
@@ -560,7 +553,8 @@ int get_acl(const char *fname, stat_x *sxp)
                if (!preserve_devices)
 #endif
                        return 0;
-       }
+       } else if (IS_MISSING_FILE(sxp->st))
+               return 0;
 
        if (get_rsync_acl(fname, sxp->acc_acl, SMB_ACL_TYPE_ACCESS,
                          sxp->st.st_mode) < 0) {
@@ -704,12 +698,7 @@ static uchar recv_ida_entries(int f, ida_entries *ent)
        uchar computed_mask_bits = 0;
        int i, count = read_varint(f);
 
-       if (count) {
-               if (!(ent->idas = new_array(id_access, count)))
-                       out_of_memory("recv_ida_entries");
-       } else
-               ent->idas = NULL;
-
+       ent->idas = count ? new_array(id_access, count) : NULL;
        ent->count = count;
 
        for (i = 0; i < count; i++) {
@@ -774,6 +763,7 @@ static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type, mode
 #ifdef HAVE_OSX_ACLS
        /* If we received a superfluous mask, throw it away. */
        duo_item->racl.mask_obj = NO_ENTRY;
+       (void)mode;
 #else
        if (duo_item->racl.names.count && duo_item->racl.mask_obj == NO_ENTRY) {
                /* Mask must be non-empty with lists. */
@@ -824,14 +814,12 @@ void cache_tmp_acl(struct file_struct *file, stat_x *sxp)
        if (prior_access_count == (size_t)-1)
                prior_access_count = access_acl_list.count;
 
-       F_ACL(file) = cache_rsync_acl(sxp->acc_acl,
-                                     SMB_ACL_TYPE_ACCESS, &access_acl_list);
+       F_ACL(file) = cache_rsync_acl(sxp->acc_acl, SMB_ACL_TYPE_ACCESS, &access_acl_list);
 
        if (S_ISDIR(sxp->st.st_mode)) {
                if (prior_default_count == (size_t)-1)
                        prior_default_count = default_acl_list.count;
-               F_DIR_DEFACL(file) = cache_rsync_acl(sxp->def_acl,
-                                     SMB_ACL_TYPE_DEFAULT, &default_acl_list);
+               F_DIR_DEFACL(file) = cache_rsync_acl(sxp->def_acl, SMB_ACL_TYPE_DEFAULT, &default_acl_list);
        }
 }
 
@@ -995,8 +983,7 @@ static int set_rsync_acl(const char *fname, acl_duo *duo_item,
                mode = 0; /* eliminate compiler warning */
 #else
                if (type == SMB_ACL_TYPE_ACCESS) {
-                       cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
-                                                    cur_mode, mode);
+                       cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl, cur_mode, mode);
                        if (cur_mode == (mode_t)-1)
                                return 0;
                }
@@ -1116,14 +1103,12 @@ int default_perms_for_dir(const char *dir)
                case ENOSYS:
                        /* No ACLs are available. */
                        break;
-               case ENOENT:
-                       if (dry_run) {
+               default:
+                       if (dry_run && errno == ENOENT) {
                                /* We're doing a dry run, so the containing directory
                                 * wasn't actually created.  Don't worry about it. */
                                break;
                        }
-                       /* Otherwise fall through. */
-               default:
                        rprintf(FWARNING,
                                "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
                                dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));