]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
ROFL: Rolling on the floor looping
authorAlejandro Colomar <alx@kernel.org>
Thu, 25 May 2023 20:24:30 +0000 (22:24 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 31 May 2023 14:29:49 +0000 (09:29 -0500)
Please tell me this was an easter egg :P

 #define go_banana() ({ goto nowhere; nowhere: 0-0; })

Closes: <https://github.com/shadow-maint/shadow/issues/736>
Easter-egg: 8492dee6632e ("subids: support nsswitch")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/nss.c

index 30199a63e0a4a473f09c04326215e4d9084d996d..b902e5d775546607ff86c94f9b7ac5724f024d36 100644 (file)
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -46,6 +46,8 @@ void nss_init(const char *nsswitch_path) {
        char *line = NULL, *p, *token, *saveptr;
        size_t len = 0;
        FILE *shadow_logfd = log_get_logfd();
+       char libname[65];
+       void *h;
 
        if (atomic_flag_test_and_set(&nss_init_started)) {
                // Another thread has started nss_init, wait for it to complete
@@ -68,9 +70,6 @@ void nss_init(const char *nsswitch_path) {
                return;
        }
        while ((getline(&line, &len, nssfp)) != -1) {
-               char libname[65];
-               void *h;
-
                if (line[0] == '\0' || line[0] == '#')
                        continue;
                if (strlen(line) < 8)
@@ -80,66 +79,65 @@ void nss_init(const char *nsswitch_path) {
                p = &line[6];
                while ((*p) && isspace(*p))
                        p++;
-               if (!*p)
-                       continue;
-               token = strtok_r(p, " \n\t", &saveptr);
-               if (token == NULL) {
-                       fprintf(shadow_logfd, "No usable subid NSS module found, using files\n");
-                       // subid_nss has to be null here, but to ease reviews:
-                       free(subid_nss);
-                       subid_nss = NULL;
-                       goto done;
-               }
-               if (strcmp(token, "files") == 0) {
-                       subid_nss = NULL;
-                       goto done;
-               }
-               if (strlen(token) > 50) {
-                       fprintf(shadow_logfd, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
-                       fprintf(shadow_logfd, "Using files\n");
-                       subid_nss = NULL;
-                       goto done;
-               }
-               snprintf(libname, 64,  "libsubid_%s.so", token);
-               h = dlopen(libname, RTLD_LAZY);
-               if (!h) {
-                       fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
-                       fprintf(shadow_logfd, "Using files\n");
-                       subid_nss = NULL;
-                       goto done;
-               }
-               subid_nss = MALLOC(struct subid_nss_ops);
-               if (!subid_nss) {
-                       dlclose(h);
-                       goto done;
-               }
-               subid_nss->has_range = dlsym(h, "shadow_subid_has_range");
-               if (!subid_nss->has_range) {
-                       fprintf(shadow_logfd, "%s did not provide @has_range@\n", libname);
-                       dlclose(h);
-                       free(subid_nss);
-                       subid_nss = NULL;
-                       goto done;
-               }
-               subid_nss->list_owner_ranges = dlsym(h, "shadow_subid_list_owner_ranges");
-               if (!subid_nss->list_owner_ranges) {
-                       fprintf(shadow_logfd, "%s did not provide @list_owner_ranges@\n", libname);
-                       dlclose(h);
-                       free(subid_nss);
-                       subid_nss = NULL;
-                       goto done;
-               }
-               subid_nss->find_subid_owners = dlsym(h, "shadow_subid_find_subid_owners");
-               if (!subid_nss->find_subid_owners) {
-                       fprintf(shadow_logfd, "%s did not provide @find_subid_owners@\n", libname);
-                       dlclose(h);
-                       free(subid_nss);
-                       subid_nss = NULL;
-                       goto done;
-               }
-               subid_nss->handle = h;
+               if (*p != '\0')
+                       break;
+       }
+       token = strtok_r(p, " \n\t", &saveptr);
+       if (token == NULL) {
+               fprintf(shadow_logfd, "No usable subid NSS module found, using files\n");
+               // subid_nss has to be null here, but to ease reviews:
+               free(subid_nss);
+               subid_nss = NULL;
+               goto done;
+       }
+       if (strcmp(token, "files") == 0) {
+               subid_nss = NULL;
+               goto done;
+       }
+       if (strlen(token) > 50) {
+               fprintf(shadow_logfd, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
+               fprintf(shadow_logfd, "Using files\n");
+               subid_nss = NULL;
+               goto done;
+       }
+       snprintf(libname, 64,  "libsubid_%s.so", token);
+       h = dlopen(libname, RTLD_LAZY);
+       if (!h) {
+               fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
+               fprintf(shadow_logfd, "Using files\n");
+               subid_nss = NULL;
+               goto done;
+       }
+       subid_nss = MALLOC(struct subid_nss_ops);
+       if (!subid_nss) {
+               dlclose(h);
+               goto done;
+       }
+       subid_nss->has_range = dlsym(h, "shadow_subid_has_range");
+       if (!subid_nss->has_range) {
+               fprintf(shadow_logfd, "%s did not provide @has_range@\n", libname);
+               dlclose(h);
+               free(subid_nss);
+               subid_nss = NULL;
+               goto done;
+       }
+       subid_nss->list_owner_ranges = dlsym(h, "shadow_subid_list_owner_ranges");
+       if (!subid_nss->list_owner_ranges) {
+               fprintf(shadow_logfd, "%s did not provide @list_owner_ranges@\n", libname);
+               dlclose(h);
+               free(subid_nss);
+               subid_nss = NULL;
+               goto done;
+       }
+       subid_nss->find_subid_owners = dlsym(h, "shadow_subid_find_subid_owners");
+       if (!subid_nss->find_subid_owners) {
+               fprintf(shadow_logfd, "%s did not provide @find_subid_owners@\n", libname);
+               dlclose(h);
+               free(subid_nss);
+               subid_nss = NULL;
                goto done;
        }
+       subid_nss->handle = h;
 
 done:
        atomic_store(&nss_init_completed, true);