From: Alejandro Colomar Date: Thu, 25 May 2023 20:24:30 +0000 (+0200) Subject: ROFL: Rolling on the floor looping X-Git-Tag: 4.14.0-rc1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f9ca4b49d30c7095fab4f2e0f6a03afed6b906a;p=thirdparty%2Fshadow.git ROFL: Rolling on the floor looping Please tell me this was an easter egg :P #define go_banana() ({ goto nowhere; nowhere: 0-0; }) Closes: Easter-egg: 8492dee6632e ("subids: support nsswitch") Signed-off-by: Alejandro Colomar --- diff --git a/lib/nss.c b/lib/nss.c index 30199a63e..b902e5d77 100644 --- 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);