]> git.samba.org - rsync.git/blobdiff - uidlist.c
Add safety check for local --remove-source-files.
[rsync.git] / uidlist.c
index 88847424d8f5c585c62493d68bfec7c2c83dfd63..99a34679a8500e14492a259e40a9433c02820129 100644 (file)
--- a/uidlist.c
+++ b/uidlist.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2004-2020 Wayne Davison
+ * Copyright (C) 2004-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
@@ -63,6 +63,16 @@ struct idlist {
 static struct idlist *uidlist, *uidmap;
 static struct idlist *gidlist, *gidmap;
 
+static inline int id_eq_uid(id_t id, uid_t uid)
+{
+       return id == (id_t)uid;
+}
+
+static inline int id_eq_gid(id_t id, gid_t gid)
+{
+       return id == (id_t)gid;
+}
+
 static id_t id_parse(const char *num_str)
 {
        id_t tmp, num = 0;
@@ -200,7 +210,7 @@ static int is_in_group(gid_t gid)
                        ngroups = getgroups(ngroups, gidset);
                /* The default gid might not be in the list on some systems. */
                for (n = 0; n < ngroups; n++) {
-                       if (gidset[n] == our_gid)
+                       if ((gid_t)gidset[n] == our_gid)
                                break;
                }
                if (n == ngroups)
@@ -219,7 +229,7 @@ static int is_in_group(gid_t gid)
 
        last_in = gid;
        for (n = 0; n < ngroups; n++) {
-               if (gidset[n] == gid)
+               if ((gid_t)gidset[n] == gid)
                        return last_out = 1;
        }
        return last_out = 0;
@@ -263,10 +273,10 @@ static struct idlist *recv_add_id(struct idlist **idlist_ptr, struct idlist *idm
        else if (*name && id) {
                if (idlist_ptr == &uidlist) {
                        uid_t uid;
-                       id2 = user_to_uid(name, &uid, False) ? uid : id;
+                       id2 = user_to_uid(name, &uid, False) ? (id_t)uid : id;
                } else {
                        gid_t gid;
-                       id2 = group_to_gid(name, &gid, False) ? gid : id;
+                       id2 = group_to_gid(name, &gid, False) ? (id_t)gid : id;
                }
        } else
                id2 = id;
@@ -289,11 +299,11 @@ uid_t match_uid(uid_t uid)
        static struct idlist *last = NULL;
        struct idlist *list;
 
-       if (last && uid == last->id)
+       if (last && id_eq_uid(last->id, uid))
                return last->id2;
 
        for (list = uidlist; list; list = list->next) {
-               if (list->id == uid)
+               if (id_eq_uid(list->id, uid))
                        break;
        }
 
@@ -309,11 +319,11 @@ gid_t match_gid(gid_t gid, uint16 *flags_ptr)
        static struct idlist *last = NULL;
        struct idlist *list;
 
-       if (last && gid == last->id)
+       if (last && id_eq_gid(last->id, gid))
                list = last;
        else {
                for (list = gidlist; list; list = list->next) {
-                       if (list->id == gid)
+                       if (id_eq_gid(list->id, gid))
                                break;
                }
                if (!list)
@@ -334,7 +344,7 @@ const char *add_uid(uid_t uid)
        union name_or_id noiu;
 
        for (list = uidlist; list; list = list->next) {
-               if (list->id == uid)
+               if (id_eq_uid(list->id, uid))
                        return NULL;
        }
 
@@ -351,7 +361,7 @@ const char *add_gid(gid_t gid)
        union name_or_id noiu;
 
        for (list = gidlist; list; list = list->next) {
-               if (list->id == gid)
+               if (id_eq_gid(list->id, gid))
                        return NULL;
        }