Date: Mon, 21 Aug 2006 02:34:34 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 104650 for review Message-ID: <200608210234.k7L2YYSP007609@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=104650 Change 104650 by bushman@bushman_nss_ldap_cached_make on 2006/08/21 02:33:35 IFC Affected files ... .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/Makefile#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agent.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agent.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/Makefile.inc#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/group.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/group.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/hosts.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/hosts.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/net.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/net.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/passwd.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/passwd.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/proto.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/proto.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/rpc.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/rpc.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/services.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/services.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cached.8#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cached.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cached.conf.5#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cachedcli.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cachedcli.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cachelib.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cachelib.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cacheplcs.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/cacheplcs.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/config.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/config.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/debug.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/debug.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/hashtable.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/log.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/log.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/mp_rs_query.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/mp_rs_query.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/mp_ws_query.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/mp_ws_query.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/parser.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/parser.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/protocol.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/protocol.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/query.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/query.h#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/singletons.c#3 integrate .. //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/singletons.h#3 integrate Differences ... ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/Makefile#3 (text) ==== ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agent.c#3 (text) ==== @@ -33,8 +33,14 @@ #include <string.h> #include <stdlib.h> #include <stdarg.h> +#include "cachelib.h" +#include "config.h" +#include "debug.h" +#include "log.h" +#include "singletons.h" #include "agent.h" -#include "debug.h" + +#define EIDSTR_SIZE (sizeof(uid_t) + sizeof(gid_t)) const ns_dtab emptydtab[] = { { NULL, NULL, NULL } @@ -82,7 +88,8 @@ if (rv == NS_RETURN) { *bufsize = size; if (*bufsize <= AGENT_BUFFER_STORAGE_MAX) { - *buffer = (char *)realloc(*buffer, *bufsize); + free(*buffer); + *buffer = malloc(*bufsize); if (*buffer == NULL) return (NS_UNAVAIL); @@ -96,6 +103,52 @@ free(*buffer); *buffer = NULL; *bufsize = 0; + } else + *bufsize = size; + + va_end(ap); + return (rv); +} + +int +agent_id_args(char **buffer, size_t *bufsize, + agent_id_func id_func, void *cache_mdata, ...) +{ + va_list ap; + size_t size; + int rv; + + va_start(ap, cache_mdata); + if (*buffer == NULL) { + *buffer = malloc(AGENT_KEY_BUFFER_STORAGE_INITIAL); + if (*buffer == NULL) + return (NS_UNAVAIL); + *bufsize = AGENT_KEY_BUFFER_STORAGE_INITIAL; + } + + size = *bufsize - EIDSTR_SIZE; + rv = id_func(*buffer + EIDSTR_SIZE, &size, ap, cache_mdata); + if (rv == NS_RETURN) { + *bufsize = size; + if (*bufsize <= AGENT_KEY_BUFFER_STORAGE_MAX) { + free(*buffer); + *buffer = malloc(*bufsize); + if (*buffer == NULL) + return (NS_UNAVAIL); + + size = *bufsize - EIDSTR_SIZE; + rv = id_func(*buffer + EIDSTR_SIZE, &size, ap, + cache_mdata); + } + } + + if (rv != NS_SUCCESS) { + free(*buffer); + *buffer = NULL; + *bufsize = 0; + } else { + *bufsize = size + EIDSTR_SIZE; + memset(*buffer, 0, EIDSTR_SIZE); } va_end(ap); @@ -108,7 +161,7 @@ struct agent_table *retval; TRACE_IN(init_agent_table); - retval = (struct agent_table *)malloc(sizeof(struct agent_table)); + retval = malloc(sizeof(struct agent_table)); if (retval == NULL) { TRACE_OUT(init_agent_table); return (NULL); @@ -134,8 +187,7 @@ } new_agents_num = at->agents_num + 1; - new_agents = (struct agent **)malloc(sizeof(struct agent *) * - new_agents_num); + new_agents = malloc(sizeof(struct agent *) * new_agents_num); if (new_agents == NULL) { TRACE_OUT(register_agent); return (-1); @@ -187,3 +239,120 @@ free(at); TRACE_OUT(destroy_agent_table); } + +int +agent_precache_results(struct configuration_entry *config_entry, + struct multipart_agent *mp_agent) +{ + cache_mp_write_session ws; + char *buffer, *keybuf, *dec_name, *en_bkp; + size_t buffer_size, keybuf_size; + void *mdata, *keygen_mdata, *retval; + cache_entry c_entry; + int res, res2; + + TRACE_IN(agent_precache_results); + + if (mp_agent->mp_keygen_func == NULL) { + LOG_ERR_2("agent_precache_results", + "'%s' does not support precaching", config_entry->name); + TRACE_OUT(agent_precache_results); + return (NS_UNAVAIL); + } + + configuration_lock_rdlock(s_configuration); + c_entry = find_cache_entry(s_cache, + config_entry->mp_cache_params.entry_name); + configuration_unlock(s_configuration); + + configuration_lock_entry(config_entry, CELT_MULTIPART); + if (c_entry == INVALID_CACHE) { + dec_name = strdup(config_entry->mp_cache_params.entry_name); + if (dec_name == NULL) { + configuration_unlock_entry(config_entry, CELT_MULTIPART); + TRACE_OUT(agent_precache_results); + return (NS_UNAVAIL); + } + + en_bkp = config_entry->mp_cache_params.entry_name; + config_entry->mp_cache_params.entry_name = dec_name; + register_cache_entry(s_cache, (struct cache_entry_params *) + &config_entry->mp_cache_params); + config_entry->mp_cache_params.entry_name = en_bkp; + + configuration_lock_rdlock(s_configuration); + c_entry = find_cache_entry(s_cache, + config_entry->mp_cache_params.entry_name); + configuration_unlock(s_configuration); + + if (c_entry == INVALID_CACHE) { + configuration_unlock_entry(config_entry, CELT_MULTIPART); + LOG_ERR_2("agent_precache_results", + "can't register multipart cache entry'%s'", + config_entry->name); + TRACE_OUT(agent_precache_results); + return (NS_UNAVAIL); + } + configuration_entry_add_mp_cache_entry(config_entry, + c_entry); + } + + ws = open_cache_mp_write_session(c_entry); + configuration_unlock_entry(config_entry, CELT_MULTIPART); + + keygen_mdata = NULL; + mdata = mp_agent->mp_init_func(); + if (ws != NULL) { + do { + buffer = NULL; + + res = mp_agent->mp_lookup_func(&buffer, &buffer_size, &retval, + mdata); + if ((res & NS_TERMINATE) && (buffer != NULL)) { + configuration_lock_entry(config_entry, CELT_MULTIPART); + if (cache_mp_write(ws, buffer, buffer_size) != 0) { + abandon_cache_mp_write_session(ws); + ws = NULL; + } + configuration_unlock_entry(config_entry, + CELT_MULTIPART); + + configuration_lock_entry(config_entry, CELT_POSITIVE); + + keybuf = NULL; + keybuf_size = 0; + while ((res2 = mp_agent->mp_keygen_func(&keybuf, + &keybuf_size, retval, &keygen_mdata)) == + NS_SUCCESS) { + if (keybuf == NULL) + break; + + cache_write(config_entry->positive_cache_entry, + keybuf, keybuf_size, buffer, + buffer_size); + + free(keybuf); + keybuf = NULL; + keybuf_size = 0; + } + configuration_unlock_entry(config_entry, CELT_POSITIVE); + + free(buffer); + buffer = NULL; + } else { + configuration_lock_entry(config_entry, + CELT_MULTIPART); + close_cache_mp_write_session(ws); + ws = NULL; + configuration_unlock_entry(config_entry, + CELT_MULTIPART); + + buffer = NULL; + } + } while ((res & NS_TERMINATE) && (ws != NULL)); + mp_agent->mp_keygen_func(NULL, NULL, NULL, &keygen_mdata); + } + + TRACE_OUT(agent_precache_results); + return (NS_SUCCESS); +} ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agent.h#3 (text) ==== @@ -76,6 +76,7 @@ #define AGENT_DECLARE_BUFFER_TLS_HANDLING(name) \ struct name##_state { \ + struct name inst; \ char *buffer; \ size_t bufsize; \ }; \ @@ -94,6 +95,12 @@ AGENT_BUFFER_STORAGE_MAX = 1 << 20, /* 1 MByte */ }; +enum agent_key_buffer_constants +{ + AGENT_KEY_BUFFER_STORAGE_INITIAL = 1 << 8, + AGENT_KEY_BUFFER_STORAGE_MAX = 1 << 20, +}; + #define AGENT_BUFFER_TLS_HANDLING_INIT(st) \ { \ if (st->buffer == NULL) { \ @@ -125,9 +132,11 @@ }; typedef int (*agent_marshal_func)(char *, size_t *, void *, va_list, void *); +typedef int (*agent_id_func)(char *, size_t *, va_list, void *); typedef int (*agent_lookup_func)(const char *, size_t, char **, size_t *); typedef void *(*agent_mp_init_func)(); -typedef int (*agent_mp_lookup_func)(char **, size_t *, void *); +typedef int (*agent_mp_lookup_func)(char **, size_t *, void *, void *); +typedef int (*agent_mp_keygen_func)(char **, size_t *, void *, void *); typedef void (*agent_mp_destroy_func)(void *); struct agent { @@ -145,6 +154,7 @@ agent_mp_init_func mp_init_func; agent_mp_lookup_func mp_lookup_func; + agent_mp_keygen_func mp_keygen_func; agent_mp_destroy_func mp_destroy_func; }; @@ -157,10 +167,15 @@ extern int agent_marshal_results(char **, size_t *, agent_marshal_func, void *, void *, ...); +extern int agent_id_args(char **, size_t *, agent_id_func, + void *, ...); extern struct agent_table *init_agent_table(); extern int register_agent(struct agent_table *, struct agent *); extern struct agent *find_agent(struct agent_table *, const char *, enum agent_type); extern void destroy_agent_table(struct agent_table *); + +extern int agent_precache_results(struct configuration_entry *, + struct multipart_agent *); #endif ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/Makefile.inc#3 (text) ==== ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/group.c#3 (text) ==== @@ -40,20 +40,30 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include "../debug.h" +#include "../cachelib.h" +#include "../config.h" +#include "../debug.h" +#include "../log.h" +#include "../singletons.h" #include "../agent.h" -#include "../debug.h" #include "group.h" +#define GROUP_KEYGEN_BYNAME (0) +#define GROUP_KEYGEN_BYGID (1) +#define GROUP_KEYGEN_END (2) + static const ns_src defaultsrc[] = { { NSSRC_COMPAT, NS_SUCCESS }, { NULL, 0 } }; - +static int group_id_func(char *, size_t *, va_list, void *); static int group_marshal_func(char *, size_t *, void *, va_list, void *); static int group_lookup_func(const char *, size_t, char **, size_t *); static void *group_mp_init_func(); -static int group_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata); +static int group_mp_lookup_func(char **, size_t *, void *, void *); +static int group_mp_keygen_func(char **, size_t *, void *, void *); static void group_mp_destroy_func(void *mdata); AGENT_DECLARE_BUFFER_TLS_HANDLING(group); @@ -67,6 +77,58 @@ #endif static int +group_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) +{ + char *name; + gid_t gid; + + size_t desired_size, size; + int res = NS_UNAVAIL; + enum nss_lookup_type lookup_type; + + + lookup_type = (enum nss_lookup_type)cache_mdata; + switch (lookup_type) { + case nss_lt_name: + name = va_arg(ap, char *); + size = strlen(name); + desired_size = sizeof(enum nss_lookup_type) + size + 1; + if (desired_size > *buffer_size) { + res = NS_RETURN; + goto fin; + } + + memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type)); + memcpy(buffer + sizeof(enum nss_lookup_type), name, size + 1); + + res = NS_SUCCESS; + break; + case nss_lt_id: + gid = va_arg(ap, gid_t); + desired_size = sizeof(enum nss_lookup_type) + sizeof(gid_t); + if (desired_size > *buffer_size) { + res = NS_RETURN; + goto fin; + } + + memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type)); + memcpy(buffer + sizeof(enum nss_lookup_type), &gid, + sizeof(gid_t)); + + res = NS_SUCCESS; + break; + default: + /* should be unreachable */ + return (NS_UNAVAIL); + } + +fin: + *buffer_size = desired_size; + return (res); +} + + +static int group_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) { @@ -122,7 +184,7 @@ } memcpy(&new_grp, grp, sizeof(struct group)); - //memset(buffer, 0, desired_size); + memset(buffer, 0, desired_size); *buffer_size = desired_size; p = buffer + sizeof(struct group) + sizeof(char *); @@ -166,7 +228,7 @@ size_t *out_size) { struct group_state *st; - struct group grp, *retval; + struct group *retval; enum nss_lookup_type lookup_type; char *name; gid_t gid; @@ -187,12 +249,11 @@ switch (lookup_type) { case nss_lt_name: size = key_size - sizeof(enum nss_lookup_type) + 1; - name = (char *)malloc(size); + name = malloc(size); if (name == NULL) { TRACE_OUT(group_lookup_func); return (NS_UNAVAIL); } - //memset(name, 0, size); name[size - 1] = '\0'; memcpy(name, key + sizeof(enum nss_lookup_type), size - 1); break; @@ -223,7 +284,7 @@ do { result = nsdispatch(&retval, emptydtab, NSDB_GROUP, "getgrnam_r", defaultsrc, name, - &grp, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); @@ -237,7 +298,7 @@ if (result == NS_SUCCESS) result = agent_marshal_results(out_buffer, out_size, group_marshal_func, (void *)nss_lt_name, - retval, name, &grp, + retval, name, &st->inst, st->buffer, st->bufsize, &error); break; @@ -245,7 +306,7 @@ do { result = nsdispatch(&retval, emptydtab, NSDB_GROUP, "getgrgid_r", defaultsrc, gid, - &grp, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); @@ -260,7 +321,7 @@ result = agent_marshal_results(out_buffer, out_size, group_marshal_func, (void *)nss_lt_id, retval, gid, - &grp, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); break; default: /* SHOULD NOT BE REACHED */ @@ -283,10 +344,10 @@ } static int -group_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata) +group_mp_lookup_func(char **out_buffer, size_t *out_size, void *retval, + void *mdata) { struct group_state *st; - struct group grp, *retval; int result, error; TRACE_IN(group_mp_lookup_func); @@ -297,8 +358,8 @@ return (NS_UNAVAIL); do { - result = nsdispatch(&retval, emptydtab, NSDB_GROUP, - "getgrent_r", defaultsrc, &grp, st->buffer, + result = nsdispatch(retval, emptydtab, NSDB_GROUP, + "getgrent_r", defaultsrc, &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { @@ -311,14 +372,59 @@ if (result == NS_SUCCESS) { result = agent_marshal_results(out_buffer, out_size, group_marshal_func, - (void *)nss_lt_all, retval, &grp, - st->buffer, st->bufsize, &error); + (void *)nss_lt_all, *((void **)retval), + &st->inst, st->buffer, st->bufsize, &error); } TRACE_OUT(group_mp_lookup_func); return (result); } +int +group_mp_keygen_func(char **out_buffer, size_t *out_size, + void *result, void *mdata) +{ + struct group *grp; + int rv, *conv_type; + + TRACE_IN(group_mp_keygen_func); + grp = (struct group *)result; + conv_type = *((int **)mdata); + + if (grp == NULL) { + free(conv_type); + *((int **)mdata) = NULL; + return (NS_UNAVAIL); + } + + if (conv_type == NULL) { + conv_type = malloc(sizeof(int)); + *conv_type = GROUP_KEYGEN_BYNAME; + *((int **)mdata) = conv_type; + } + + switch (*conv_type) { + case GROUP_KEYGEN_BYNAME: + rv = agent_id_args(out_buffer, out_size, group_id_func, + (void *)nss_lt_name, grp->gr_name); + *conv_type = GROUP_KEYGEN_BYGID; + break; + case GROUP_KEYGEN_BYGID: + rv = agent_id_args(out_buffer, out_size, group_id_func, + (void *)nss_lt_id, grp->gr_gid); + *conv_type = GROUP_KEYGEN_END; + break; + case GROUP_KEYGEN_END: + default: + *conv_type = GROUP_KEYGEN_BYNAME; + rv = NS_NOTFOUND; + break; + } + + TRACE_OUT(group_mp_keygen_func); + return (rv); +} + static void group_mp_destroy_func(void *mdata) { @@ -333,7 +439,7 @@ struct common_agent *retval; TRACE_IN(init_group_agent); - retval = (struct common_agent *)malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct common_agent)); if (retval == NULL) { TRACE_OUT(init_group_agent); return (NULL); @@ -360,8 +466,7 @@ struct multipart_agent *retval; TRACE_IN(init_group_mp_agent); - retval = (struct multipart_agent *)malloc( - sizeof(struct multipart_agent)); + retval = malloc(sizeof(struct multipart_agent)); if (retval == NULL) { TRACE_OUT(init_group_mp_agent); return (NULL); @@ -377,6 +482,7 @@ retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = group_mp_init_func; retval->mp_lookup_func = group_mp_lookup_func; + retval->mp_keygen_func = group_mp_keygen_func; retval->mp_destroy_func = group_mp_destroy_func; TRACE_OUT(init_group_mp_agent); ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/group.h#3 (text) ==== ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/hosts.c#3 (text+ko) ==== @@ -45,8 +45,13 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include "../debug.h" +#include "../cachelib.h" +#include "../config.h" +#include "../debug.h" +#include "../log.h" +#include "../singletons.h" #include "../agent.h" -#include "../debug.h" #include "hosts.h" static const ns_src defaultsrc[] = { @@ -133,7 +138,7 @@ } memcpy(&new_ht, ht, sizeof(struct hostent)); - //memset(buffer, 0, desired_size); + memset(buffer, 0, desired_size); *buffer_size = desired_size; p = buffer + sizeof(struct hostent) + sizeof(char *); @@ -205,7 +210,7 @@ return (NS_RETURN); } - //memset(buffer, 0, desired_size); + memset(buffer, 0, desired_size); p = buffer; memcpy(p, &ai_size, sizeof(size_t)); @@ -301,12 +306,11 @@ key_size -= sizeof(int); size = key_size + 1; - str = (char *)malloc(size); + str = malloc(size); if (str == NULL) { TRACE_OUT(hosts_lookup_func); return (NS_UNAVAIL); } - //memset(str, 0, size); str[size - 1] = '\0'; memcpy(str, key, key_size); @@ -339,12 +343,11 @@ switch (lookup_type) { case nss_lt_name: size = key_size + 1; - str = (char *)malloc(size); + str = malloc(size); if (str == NULL) { TRACE_OUT(hosts_lookup_func); return (NS_UNAVAIL); } - //memset(str, 0, size); str[size - 1] = '\0'; memcpy(str, key, key_size); break; @@ -447,7 +450,7 @@ struct common_agent *retval; TRACE_IN(init_hosts_agent); - retval = (struct common_agent *)malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct common_agent)); if (retval == NULL) { TRACE_OUT(init_hosts_agent); return (NULL); ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/hosts.h#3 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/net.c#3 (text+ko) ==== @@ -44,8 +44,13 @@ #include <string.h> #include <stdarg.h> #include <nsswitch.h> +#include "../debug.h" +#include "../cachelib.h" +#include "../config.h" +#include "../debug.h" +#include "../log.h" +#include "../singletons.h" #include "../agent.h" -#include "../debug.h" #include "net.h" static const ns_src defaultsrc[] = { @@ -126,7 +131,7 @@ memcpy(&new_ne, ne, sizeof(struct netent)); *buffer_size = desired_size; - //memset(buffer, 0, desired_size); + memset(buffer, 0, desired_size); p = buffer + sizeof(struct netent) + sizeof(char *); memcpy(buffer + sizeof(struct netent), &p, sizeof(char *)); p = (char *)_ALIGN(p); @@ -183,12 +188,11 @@ switch (lookup_type) { case nss_lt_name: size = key_size - sizeof(enum nss_lookup_type) + 1; - name = (char *)malloc(size); + name = malloc(size); if (name == NULL) { TRACE_OUT(networks_lookup_func); return (NS_UNAVAIL); } - //memset(name, 0, size); name[size - 1] = '\0'; memcpy(name, key + sizeof(enum nss_lookup_type), size - 1); break; @@ -277,7 +281,7 @@ struct common_agent *retval; TRACE_IN(init_networks_agent); - retval = (struct common_agent *)malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct common_agent)); if (retval == NULL) { TRACE_OUT(init_networks_agent); return (NULL); ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/net.h#3 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached_openldap/src/usr.sbin/cached/agents/passwd.c#3 (text) ==== @@ -38,25 +38,84 @@ #include <pwd.h> #include <string.h> #include <stdlib.h> +#include "../debug.h" +#include "../cachelib.h" +#include "../config.h" +#include "../debug.h" +#include "../log.h" +#include "../singletons.h" #include "../agent.h" -#include "../debug.h" #include "passwd.h" +#define PASSWD_KEYGEN_BYNAME (0) +#define PASSWD_KEYGEN_BYUID (1) +#define PASSWD_KEYGEN_END (2) + static const ns_src defaultsrc[] = { { NSSRC_COMPAT, NS_SUCCESS }, { NULL, 0 } }; - +static int passwd_id_func(char *, size_t *, va_list, void *); static int passwd_marshal_func(char *, size_t *, void *, va_list, void *); static int passwd_lookup_func(const char *, size_t, char **, size_t *); static void *passwd_mp_init_func(); -static int passwd_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata); -static void passwd_mp_destroy_func(void *mdata); +static int passwd_mp_lookup_func(char **, size_t *, void *, void *); +static int passwd_mp_keygen_func(char **, size_t *, void *, void *); +static void passwd_mp_destroy_func(void *); AGENT_DECLARE_BUFFER_TLS_HANDLING(passwd); static int +passwd_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) +{ + char *name; + uid_t uid; + size_t size, desired_size; + int res = NS_UNAVAIL; + enum nss_lookup_type lookup_type; + + lookup_type = (enum nss_lookup_type)cache_mdata; + switch (lookup_type) { + case nss_lt_name: + name = va_arg(ap, char *); + size = strlen(name); + desired_size = sizeof(enum nss_lookup_type) + size + 1; + if (desired_size > *buffer_size) { + res = NS_RETURN; + goto fin; + } + + memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type)); + memcpy(buffer + sizeof(enum nss_lookup_type), name, size + 1); + + res = NS_SUCCESS; + break; + case nss_lt_id: + uid = va_arg(ap, uid_t); + desired_size = sizeof(enum nss_lookup_type) + sizeof(uid_t); + if (desired_size > *buffer_size) { + res = NS_RETURN; + goto fin; + } + + memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type)); + memcpy(buffer + sizeof(enum nss_lookup_type), &uid, + sizeof(uid_t)); + + res = NS_SUCCESS; + break; + default: + /* should be unreachable */ + return (NS_UNAVAIL); + } + +fin: + *buffer_size = desired_size; + return (res); +} + +static int passwd_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) { @@ -108,7 +167,7 @@ } memcpy(&new_pwd, pwd, sizeof(struct passwd)); - //memset(buffer, 0, desired_size); + memset(buffer, 0, desired_size); *buffer_size = desired_size; p = buffer + sizeof(struct passwd) + sizeof(char *); @@ -165,7 +224,7 @@ size_t *out_size) { struct passwd_state *st; - struct passwd pwd, *retval; + struct passwd *retval; enum nss_lookup_type lookup_type; char *login; uid_t uid; @@ -186,12 +245,11 @@ switch (lookup_type) { case nss_lt_name: size = key_size - sizeof(enum nss_lookup_type) + 1; - login = (char *)malloc(size); + login = malloc(size); if (login == NULL) { TRACE_OUT(passwd_lookup_func); return (NS_UNAVAIL); } - //memset(login, 0, size); login[size - 1] ='\0'; memcpy(login, key + sizeof(enum nss_lookup_type), size - 1); break; @@ -222,7 +280,7 @@ do { result = nsdispatch(&retval, emptydtab, NSDB_PASSWD, "getpwnam_r", defaultsrc, login, - &pwd, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); @@ -236,7 +294,7 @@ if (result == NS_SUCCESS) result = agent_marshal_results(out_buffer, out_size, passwd_marshal_func, (void *)nss_lt_name, - retval, login, &pwd, + retval, login, &st->inst, st->buffer, st->bufsize, &error); break; @@ -244,7 +302,7 @@ do { result = nsdispatch(&retval, emptydtab, NSDB_PASSWD, "getpwuid_r", defaultsrc, uid, - &pwd, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); @@ -259,7 +317,7 @@ result = agent_marshal_results(out_buffer, out_size, passwd_marshal_func, (void *)nss_lt_id, retval, uid, - &pwd, st->buffer, st->bufsize, &error); + &st->inst, st->buffer, st->bufsize, &error); break; default: /* SHOULD NOT BE REACHED */ @@ -282,10 +340,10 @@ } static int -passwd_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata) +passwd_mp_lookup_func(char **out_buffer, size_t *out_size, void *retval, + void *mdata) { struct passwd_state *st; - struct passwd pwd, *retval; int result, error; TRACE_IN(passwd_mp_lookup_func); @@ -296,8 +354,8 @@ return (NS_UNAVAIL); do { - result = nsdispatch(&retval, emptydtab, NSDB_PASSWD, - "getpwent_r", defaultsrc, &pwd, st->buffer, + result = nsdispatch(retval, emptydtab, NSDB_PASSWD, + "getpwent_r", defaultsrc, &st->inst, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { @@ -309,15 +367,60 @@ if (result == NS_SUCCESS) { result = agent_marshal_results(out_buffer, - out_size, passwd_marshal_func, - (void *)nss_lt_all, retval, &pwd, - st->buffer, st->bufsize, &error); + out_size, passwd_marshal_func, (void *)nss_lt_all, + *((void **)retval), &st->inst, st->buffer, + st->bufsize, &error); } TRACE_OUT(passwd_mp_lookup_func); return (result); } +static int +passwd_mp_keygen_func(char **out_buffer, size_t *out_size, + void *result, void *mdata) +{ + struct passwd *pwd; + int rv, *conv_type; + + TRACE_IN(passwd_mp_keygen_type); + pwd = (struct passwd *)result; + conv_type = *((int **)mdata); + + if (pwd == NULL) { + free(conv_type); + *((int **)mdata) = NULL; + return (NS_UNAVAIL); + } + + if (conv_type == NULL) { + conv_type = malloc(sizeof(int)); + *conv_type = PASSWD_KEYGEN_BYNAME; + *((int **)mdata) = conv_type; + } + + switch (*conv_type) { + case PASSWD_KEYGEN_BYNAME: + rv = agent_id_args(out_buffer, out_size, passwd_id_func, + (void *)nss_lt_name, pwd->pw_name); + *conv_type = PASSWD_KEYGEN_BYUID; + break; + case PASSWD_KEYGEN_BYUID: + rv = agent_id_args(out_buffer, out_size, passwd_id_func, + (void *)nss_lt_id, pwd->pw_uid); + *conv_type = PASSWD_KEYGEN_END; + break; + case PASSWD_KEYGEN_END: + default: + *conv_type = PASSWD_KEYGEN_BYNAME; + rv = NS_NOTFOUND; + break; + } + + TRACE_OUT(passwd_mp_keygen_type); + return (rv); +} + static void passwd_mp_destroy_func(void *mdata) { >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608210234.k7L2YYSP007609>