int pr_memcache_conn_set_namespace(pr_memcache_t *mcache, module *m, const char *prefix) { if (mcache == NULL || m == NULL) { errno = EINVAL; return -1; } if (mcache->namespace_tab == NULL) { pr_table_t *tab; tab = pr_table_alloc(mcache->pool, 0); if (pr_table_ctl(tab, PR_TABLE_CTL_SET_KEY_CMP, modptr_cmp_cb) < 0) { pr_trace_msg(trace_channel, 4, "error setting key comparison callback for namespace table: %s", strerror(errno)); } if (pr_table_ctl(tab, PR_TABLE_CTL_SET_KEY_HASH, modptr_hash_cb) < 0) { pr_trace_msg(trace_channel, 4, "error setting key hash callback for namespace table: %s", strerror(errno)); } mcache->namespace_tab = tab; } if (prefix != NULL) { int count; size_t prefix_len; prefix_len = strlen(prefix); count = pr_table_kexists(mcache->namespace_tab, m, sizeof(module *)); if (count <= 0) { if (pr_table_kadd(mcache->namespace_tab, m, sizeof(module *), pstrndup(mcache->pool, prefix, prefix_len), prefix_len) < 0) { pr_trace_msg(trace_channel, 7, "error adding namespace prefix '%s' for module 'mod_%s.c': %s", prefix, m->name, strerror(errno)); } } else { if (pr_table_kset(mcache->namespace_tab, m, sizeof(module *), pstrndup(mcache->pool, prefix, prefix_len), prefix_len) < 0) { pr_trace_msg(trace_channel, 7, "error setting namespace prefix '%s' for module 'mod_%s.c': %s", prefix, m->name, strerror(errno)); } } } else { /* A NULL prefix means the caller is removing their namespace maping. */ (void) pr_table_kremove(mcache->namespace_tab, m, sizeof(module *), NULL); } return 0; }
static void gidcache_add(gid_t gid, const char *name) { if (!(auth_caching & PR_AUTH_CACHE_FL_GID2NAME)) { return; } gidcache_create(); if (gid_tab) { int count; (void) pr_table_rewind(gid_tab); count = pr_table_kexists(gid_tab, (const void *) &gid, sizeof(gid_t)); if (count <= 0) { gid_t *cache_gid; /* Allocate memory for a GID out of the ID cache pool, so that this * GID can be used as a key. */ cache_gid = palloc(auth_pool, sizeof(gid_t)); *cache_gid = gid; if (pr_table_kadd(gid_tab, (const void *) cache_gid, sizeof(gid_t), pstrdup(auth_pool, name), strlen(name) + 1) < 0 && errno != EEXIST) { pr_trace_msg(trace_channel, 3, "error adding name '%s' for GID %lu to the gidcache: %s", name, (unsigned long) gid, strerror(errno)); } else { pr_trace_msg(trace_channel, 5, "stashed name '%s' for GID %lu in the gidcache", name, (unsigned long) gid); } } } }