summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Hallyn <serge@hallyn.com>2023-05-25 22:00:36 -0500
committerSerge Hallyn <serge@hallyn.com>2023-05-26 15:16:29 -0500
commita80b792afc7d557270bf4024fddc97199a5a31fb (patch)
treeedede20d4a781baad0d7012c90d8582b563fd318
parent8665fe1957b0d565701ff1b834eae89e5c4d2c9a (diff)
sub_[ug]id_{add,remove}: fix return values
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>
-rw-r--r--lib/subordinateio.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/subordinateio.c b/lib/subordinateio.c
index 7fddf62f..597aeac5 100644
--- a/lib/subordinateio.c
+++ b/lib/subordinateio.c
@@ -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);
}