]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
sub_[ug]id_{add,remove}: fix return values
authorSerge Hallyn <serge@hallyn.com>
Fri, 26 May 2023 03:00:36 +0000 (22:00 -0500)
committerSerge Hallyn <serge@hallyn.com>
Fri, 26 May 2023 20:16:29 +0000 (15:16 -0500)
On failure, these are meant to return 0 with errno set.  But if
an nss module is loaded, they were returning -ERRNO instead.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
lib/subordinateio.c

index 7fddf62f24266abd996253202489d91b62b3e8b1..597aeac58f231dff891fc46894765ca919b0d492 100644 (file)
@@ -623,17 +623,28 @@ bool have_sub_uids(const char *owner, uid_t start, unsigned long count)
        return have_range (&subordinate_uid_db, owner, start, count);
 }
 
+/*
+ * sub_uid_add: add a subuid range, perhaps through nss.
+ *
+ * Return 1 if the range is already present or on success.  On error
+ * return 0 and set errno appropriately.
+ */
 int sub_uid_add (const char *owner, uid_t start, unsigned long count)
 {
-       if (get_subid_nss_handle())
-               return -EOPNOTSUPP;
+       if (get_subid_nss_handle()) {
+               errno = EOPNOTSUPP;
+               return 0;
+       }
        return add_range (&subordinate_uid_db, owner, start, count);
 }
 
+/* Return 1 on success.  on failure, return 0 and set errno appropriately */
 int sub_uid_remove (const char *owner, uid_t start, unsigned long count)
 {
-       if (get_subid_nss_handle())
-               return -EOPNOTSUPP;
+       if (get_subid_nss_handle()) {
+               errno = EOPNOTSUPP;
+               return 0;
+       }
        return remove_range (&subordinate_uid_db, owner, start, count);
 }
 
@@ -719,17 +730,28 @@ bool local_sub_gid_assigned(const char *owner)
        return range_exists (&subordinate_gid_db, owner);
 }
 
+/*
+ * sub_gid_add: add a subgid range, perhaps through nss.
+ *
+ * Return 1 if the range is already present or on success.  On error
+ * return 0 and set errno appropriately.
+ */
 int sub_gid_add (const char *owner, gid_t start, unsigned long count)
 {
-       if (get_subid_nss_handle())
-               return -EOPNOTSUPP;
+       if (get_subid_nss_handle()) {
+               errno = EOPNOTSUPP;
+               return 0;
+       }
        return add_range (&subordinate_gid_db, owner, start, count);
 }
 
+/* Return 1 on success.  on failure, return 0 and set errno appropriately */
 int sub_gid_remove (const char *owner, gid_t start, unsigned long count)
 {
-       if (get_subid_nss_handle())
-               return -EOPNOTSUPP;
+       if (get_subid_nss_handle()) {
+               errno = EOPNOTSUPP;
+               return 0;
+       }
        return remove_range (&subordinate_gid_db, owner, start, count);
 }