static void load_plugin_conf(conf_llist *plugin) { DIR *d; /* init plugin list */ plist_create(plugin); /* read configs */ d = opendir(plugin_dir); if (d) { struct dirent *e; while ((e = readdir(d))) { plugin_conf_t config; char fname[PATH_MAX]; // Don't run backup files, hidden files, or dirs if (e->d_name[0] == '.' || count_dots(e->d_name) > 1) continue; snprintf(fname, sizeof(fname), "%s%s", plugin_dir, e->d_name); clear_pconfig(&config); if (load_pconfig(&config, fname) == 0) { /* Push onto config list only if active */ if (config.active == A_YES) plist_append(plugin, &config); else free_pconfig(&config); } else syslog(LOG_ERR, "Skipping %s plugin due to errors", e->d_name); } closedir(d); } }
/* If we run out of memory, we don't give already allocated memory free. The overhead for bringing getnames back in a safe state to free it is to big. */ nis_name * nis_getnames (const_nis_name name) { const char *local_domain = nis_local_directory (); size_t local_domain_len = strlen (local_domain); size_t name_len = strlen (name); char *path; int pos = 0; char *saveptr = NULL; int have_point; const char *cp; const char *cp2; int count = 2; nis_name *getnames = malloc ((count + 1) * sizeof (char *)); if (__glibc_unlikely (getnames == NULL)) return NULL; /* Do we have a fully qualified NIS+ name ? If yes, give it back */ if (name[name_len - 1] == '.') { if ((getnames[0] = strdup (name)) == NULL) { free_null: while (pos-- > 0) free (getnames[pos]); free (getnames); return NULL; } getnames[1] = NULL; return getnames; } /* If the passed NAME is shared a suffix (the latter of course with a final dot) with each other we pass back NAME with a final dot. */ if (local_domain_len > 2) { have_point = 0; cp = &local_domain[local_domain_len - 2]; cp2 = &name[name_len - 1]; while (*cp == *cp2) { if (*cp == '.') have_point = 1; --cp; --cp2; if (cp < local_domain) { have_point = cp2 < name || *cp2 == '.'; break; } if (cp2 < name) { have_point = *cp == '.'; break; } } if (have_point) { getnames[0] = malloc (name_len + 2); if (getnames[0] == NULL) goto free_null; strcpy (stpcpy (getnames[0], name), "."); ++pos; } } /* Get the search path, where we have to search "name" */ path = getenv ("NIS_PATH"); if (path == NULL) path = strdupa ("$"); else path = strdupa (path); have_point = strchr (name, '.') != NULL; cp = __strtok_r (path, ":", &saveptr); while (cp) { if (strcmp (cp, "$") == 0) { const char *cptr = local_domain; char *tmp; while (*cptr != '\0' && count_dots (cptr) >= 2) { if (pos >= count) { count += 5; nis_name *newp = realloc (getnames, (count + 1) * sizeof (char *)); if (__glibc_unlikely (newp == NULL)) goto free_null; getnames = newp; } tmp = malloc (strlen (cptr) + local_domain_len + name_len + 2); if (__glibc_unlikely (tmp == NULL)) goto free_null; getnames[pos] = tmp; tmp = stpcpy (tmp, name); *tmp++ = '.'; if (cptr[1] != '\0') stpcpy (tmp, cptr); else ++cptr; ++pos; while (*cptr != '.' && *cptr != '\0') ++cptr; if (cptr[0] != '\0' && cptr[1] != '\0') /* If we have only ".", don't remove the "." */ ++cptr; } } else { char *tmp; size_t cplen = strlen (cp); if (cp[cplen - 1] == '$') { char *p; tmp = malloc (cplen + local_domain_len + name_len + 2); if (__glibc_unlikely (tmp == NULL)) goto free_null; p = __stpcpy (tmp, name); *p++ = '.'; p = __mempcpy (p, cp, cplen); --p; if (p[-1] != '.') *p++ = '.'; __stpcpy (p, local_domain); } else { char *p; tmp = malloc (cplen + name_len + 3); if (__glibc_unlikely (tmp == NULL)) goto free_null; p = __mempcpy (tmp, name, name_len); *p++ = '.'; p = __mempcpy (p, cp, cplen); if (p[-1] != '.') *p++ = '.'; *p = '\0'; } if (pos >= count) { count += 5; nis_name *newp = realloc (getnames, (count + 1) * sizeof (char *)); if (__glibc_unlikely (newp == NULL)) goto free_null; getnames = newp; } getnames[pos] = tmp; ++pos; } cp = __strtok_r (NULL, ":", &saveptr); } if (pos == 0 && __asprintf (&getnames[pos++], "%s%s%s%s", name, name[name_len - 1] == '.' ? "" : ".", local_domain, local_domain[local_domain_len - 1] == '.' ? "" : ".") < 0) goto free_null; getnames[pos] = NULL; return getnames; }
/* If we run out of memory, we don't give already allocated memory free. The overhead for bringing getnames back in a safe state to free it is to big. */ nis_name * nis_getnames (const_nis_name name) { nis_name *getnames = NULL; char local_domain[NIS_MAXNAMELEN + 1]; char *path; char *cp; int count; int pos = 0; int have_point; char *saveptr; strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN); local_domain[NIS_MAXNAMELEN] = '\0'; count = 1; getnames = malloc ((count + 1) * sizeof (char *)); if (__builtin_expect (getnames == NULL, 0)) return NULL; /* Do we have a fully qualified NIS+ name ? If yes, give it back */ if (name[strlen (name) - 1] == '.') { if ((getnames[0] = strdup (name)) == NULL) { free_null: while (pos-- > 0) free (getnames[pos]); free (getnames); return NULL; } getnames[1] = NULL; return getnames; } /* Get the search path, where we have to search "name" */ path = getenv ("NIS_PATH"); if (path == NULL) path = strdupa ("$"); else path = strdupa (path); have_point = (strchr (name, '.') != NULL); cp = __strtok_r (path, ":", &saveptr); while (cp) { if (strcmp (cp, "$") == 0) { char *cptr = local_domain; char *tmp; while ((have_point && *cptr != '\0') || (count_dots (cptr) >= 2)) { if (pos >= count) { count += 5; nis_name *newp = realloc (getnames, (count + 1) * sizeof (char *)); if (__builtin_expect (newp == NULL, 0)) goto free_null; getnames = newp; } tmp = malloc (strlen (cptr) + strlen (local_domain) + strlen (name) + 2); if (__builtin_expect (tmp == NULL, 0)) goto free_null; getnames[pos] = tmp; tmp = stpcpy (tmp, name); *tmp++ = '.'; if (cptr[1] != '\0') stpcpy (tmp, cptr); else ++cptr; ++pos; while (*cptr != '.' && *cptr != '\0') ++cptr; if (cptr[0] != '\0' && cptr[1] != '\0') /* If we have only ".", don't remove the "." */ ++cptr; } } else { char *tmp; size_t cplen = strlen (cp); if (cp[cplen - 1] == '$') { char *p; tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2); if (__builtin_expect (tmp == NULL, 0)) goto free_null; p = __stpcpy (tmp, name); *p++ = '.'; p = __mempcpy (p, cp, cplen); --p; if (p[-1] != '.') *p++ = '.'; __stpcpy (p, local_domain); } else { char *p; tmp = malloc (cplen + strlen (name) + 2); if (__builtin_expect (tmp == NULL, 0)) goto free_null; p = __stpcpy (tmp, name); *p++ = '.'; memcpy (p, cp, cplen + 1); } if (pos >= count) { count += 5; nis_name *newp = realloc (getnames, (count + 1) * sizeof (char *)); if (__builtin_expect (newp == NULL, 0)) goto free_null; getnames = newp; } getnames[pos] = tmp; ++pos; } cp = __strtok_r (NULL, ":", &saveptr); } getnames[pos] = NULL; return getnames; }