]> granicus.if.org Git - shadow/blobdiff - lib/subordinateio.c
remove unused fn commonio_next
[shadow] / lib / subordinateio.c
index 25353368238fd620c7e1425cd716e752be08b56c..0d89a64ef7bb0e6dcc954198ec71c39022fed395 100644 (file)
@@ -152,11 +152,6 @@ static struct commonio_ops subordinate_ops = {
        NULL,                   /* close_hook */
 };
 
-static /*@observer@*/ /*@null*/const struct subordinate_range *subordinate_next(struct commonio_db *db)
-{
-       return (const struct subordinate_range *)commonio_next (db);
-}
-
 /*
  * range_exists: Check whether @owner owns any ranges
  *
@@ -181,7 +176,7 @@ static const bool range_exists(struct commonio_db *db, const char *owner)
  *             subuid @val.
  *
  * @db: database to query
- * @owner: owning uid being queuried
+ * @owner: owning uid being queried
  * @val: subuid being searched for.
  *
  * Returns a range of subuids belonging to @owner and including the subuid
@@ -221,7 +216,7 @@ static const struct subordinate_range *find_range(struct commonio_db *db,
 
         /*
          * Search loop above did not produce any result. Let's rerun it,
-         * but this time try to matcha actual UIDs. The first entry that
+         * but this time try to match actual UIDs. The first entry that
          * matches is considered a success.
          * (It may be specified as literal UID or as another username which
          * has the same UID as the username we are looking for.)
@@ -245,36 +240,38 @@ static const struct subordinate_range *find_range(struct commonio_db *db,
                 unsigned long first = range->start;
                 unsigned long last = first + range->count - 1;
 
+                /* For performance reasons check range before using getpwnam() */
+                if ((val < first) || (val > last)) {
+                        continue;
+                }
+
                 /*
-                 * First check if range owner is specified as numeric UID
-                 * and if it matches.
+                 * Range matches. Check if range owner is specified
+                 * as numeric UID and if it matches.
                  */
-                if (0 != strcmp(range->owner, owner_uid_string)) {
-                        /*
-                         * Ok, this range owner is not specified as numeric UID
-                         * we are looking for. It may be specified as another
-                         * UID or as a literal username.
-                         *
-                         * If specified as another UID, the call to getpwnam()
-                         * will return NULL.
-                         *
-                         * If specified as literal username, we will get its
-                         * UID and compare that to UID we are looking for.
-                         */
-                        const struct passwd *range_owner_pwd;
-
-                        range_owner_pwd = getpwnam(range->owner);
-                        if (NULL == range_owner_pwd) {
-                                continue;
-                        }
-
-                        if (owner_uid != range_owner_pwd->pw_uid) {
-                                continue;
-                        }
+                if (0 == strcmp(range->owner, owner_uid_string)) {
+                        return range;
+                }
+
+                /*
+                 * Ok, this range owner is not specified as numeric UID
+                 * we are looking for. It may be specified as another
+                 * UID or as a literal username.
+                 *
+                 * If specified as another UID, the call to getpwnam()
+                 * will return NULL.
+                 *
+                 * If specified as literal username, we will get its
+                 * UID and compare that to UID we are looking for.
+                 */
+                const struct passwd *range_owner_pwd;
+
+                range_owner_pwd = getpwnam(range->owner);
+                if (NULL == range_owner_pwd) {
+                        continue;
                 }
 
-                /* Owner matches, now let us check this UID/GID range */
-                if ((val >= first) && (val <= last)) {
+                if (owner_uid == range_owner_pwd->pw_uid) {
                         return range;
                 }
         }
@@ -416,7 +413,7 @@ fail:
  * @start: the first uid in the owned range
  * @count: the number of uids in the range
  *
- * Return 1 if the range is already present or on succcess.  On error
+ * Return 1 if the range is already present or on success.  On error
  * return 0 and set errno appropriately.
  */
 static int add_range(struct commonio_db *db,
@@ -539,13 +536,17 @@ static struct commonio_db subordinate_uid_db = {
 #ifdef WITH_SELINUX
        NULL,                   /* scontext */
 #endif
+       0644,                   /* st_mode */
+       0,                      /* st_uid */
+       0,                      /* st_gid */
        NULL,                   /* head */
        NULL,                   /* tail */
        NULL,                   /* cursor */
        false,                  /* changed */
        false,                  /* isopen */
        false,                  /* locked */
-       false                   /* readonly */
+       false,                  /* readonly */
+       false                   /* setname */
 };
 
 int sub_uid_setdbname (const char *filename)
@@ -617,13 +618,17 @@ static struct commonio_db subordinate_gid_db = {
 #ifdef WITH_SELINUX
        NULL,                   /* scontext */
 #endif
+       0644,                   /* st_mode */
+       0,                      /* st_uid */
+       0,                      /* st_gid */
        NULL,                   /* head */
        NULL,                   /* tail */
        NULL,                   /* cursor */
        false,                  /* changed */
        false,                  /* isopen */
        false,                  /* locked */
-       false                   /* readonly */
+       false,                  /* readonly */
+       false                   /* setname */
 };
 
 int sub_gid_setdbname (const char *filename)