int pr_trace_set_levels(const char *channel, int min_level, int max_level) { if (channel == NULL) { void *v; if (trace_tab == NULL) { errno = EINVAL; return -1; } v = pr_table_remove(trace_tab, channel, NULL); if (v == NULL) { errno = EINVAL; return -1; } return 0; } if (min_level > max_level) { errno = EINVAL; return -1; } if (trace_tab == NULL && min_level < 0) { return 0; } if (trace_pool == NULL) { trace_pool = make_sub_pool(permanent_pool); pr_pool_tag(trace_pool, "Trace API"); trace_tab = pr_table_alloc(trace_pool, 0); /* Register a handler for churning the log pool during HUP. */ pr_event_register(NULL, "core.restart", trace_restart_ev, NULL); } if (min_level >= 0) { struct trace_levels *levels; levels = pcalloc(trace_pool, sizeof(struct trace_levels)); levels->min_level = min_level; levels->max_level = max_level; if (strcmp(channel, PR_TRACE_DEFAULT_CHANNEL) != 0) { int count = pr_table_exists(trace_tab, channel); if (count <= 0) { if (pr_table_add(trace_tab, pstrdup(trace_pool, channel), levels, sizeof(struct trace_levels)) < 0) { return -1; } } else { if (pr_table_set(trace_tab, pstrdup(trace_pool, channel), levels, sizeof(struct trace_levels)) < 0) return -1; } } else { register unsigned int i; for (i = 0; trace_channels[i]; i++) { (void) pr_trace_set_levels(trace_channels[i], min_level, max_level); } } } else { if (strcmp(channel, PR_TRACE_DEFAULT_CHANNEL) != 0) { (void) pr_table_remove(trace_tab, channel, NULL); } else { register unsigned int i; for (i = 0; trace_channels[i]; i++) { (void) pr_table_remove(trace_tab, trace_channels[i], NULL); } } } return 0; }
struct passwd *pr_auth_getpwnam(pool *p, const char *name) { cmd_rec *cmd = NULL; modret_t *mr = NULL; struct passwd *res = NULL; module *m = NULL; cmd = make_cmd(p, 1, name); mr = dispatch_auth(cmd, "getpwnam", &m); if (MODRET_ISHANDLED(mr) && MODRET_HASDATA(mr)) res = mr->data; if (cmd->tmp_pool) { destroy_pool(cmd->tmp_pool); cmd->tmp_pool = NULL; } /* Sanity check */ if (res == NULL) { errno = ENOENT; return NULL; } /* Make sure the UID and GID are not -1 */ if (res->pw_uid == (uid_t) -1) { pr_log_pri(PR_LOG_ERR, "error: UID of -1 not allowed"); return NULL; } if (res->pw_gid == (gid_t) -1) { pr_log_pri(PR_LOG_ERR, "error: GID of -1 not allowed"); return NULL; } if ((auth_caching & PR_AUTH_CACHE_FL_AUTH_MODULE) && !auth_tab && auth_pool) { auth_tab = pr_table_alloc(auth_pool, 0); } if (m && auth_tab) { int count = 0; void *value = NULL; value = palloc(auth_pool, sizeof(module *)); *((module **) value) = m; count = pr_table_exists(auth_tab, name); if (count <= 0) { if (pr_table_add(auth_tab, pstrdup(auth_pool, name), value, sizeof(module *)) < 0) { pr_trace_msg(trace_channel, 3, "error adding module 'mod_%s.c' for user '%s' to the authcache: %s", m->name, name, strerror(errno)); } else { pr_trace_msg(trace_channel, 5, "stashed module 'mod_%s.c' for user '%s' in the authcache", m->name, name); } } else { if (pr_table_set(auth_tab, pstrdup(auth_pool, name), value, sizeof(module *)) < 0) { pr_trace_msg(trace_channel, 3, "error setting module 'mod_%s.c' for user '%s' in the authcache: %s", m->name, name, strerror(errno)); } else { pr_trace_msg(trace_channel, 5, "stashed module 'mod_%s.c' for user '%s' in the authcache", m->name, name); } } } uidcache_add(res->pw_uid, name); /* Get the (possibly rewritten) home directory. */ res->pw_dir = pr_auth_get_home(p, res->pw_dir); pr_log_debug(DEBUG10, "retrieved UID %lu for user '%s'", (unsigned long) res->pw_uid, name); return res; }