From owner-p4-projects@FreeBSD.ORG Thu Jun 22 13:59:32 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C9E4116AA32; Thu, 22 Jun 2006 13:59:31 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7D5DA16A9C1 for ; Thu, 22 Jun 2006 13:59:31 +0000 (UTC) (envelope-from bushman@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 666C9442B4 for ; Thu, 22 Jun 2006 13:29:35 +0000 (GMT) (envelope-from bushman@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k5MDTZ9x065571 for ; Thu, 22 Jun 2006 13:29:35 GMT (envelope-from bushman@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5MDTY45065568 for perforce@freebsd.org; Thu, 22 Jun 2006 13:29:34 GMT (envelope-from bushman@freebsd.org) Date: Thu, 22 Jun 2006 13:29:34 GMT Message-Id: <200606221329.k5MDTY45065568@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bushman@freebsd.org using -f From: Michael Bushkov To: Perforce Change Reviews Cc: Subject: PERFORCE change 99809 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jun 2006 13:59:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=99809 Change 99809 by bushman@bushman_nss_ldap_cached on 2006/06/22 13:29:29 Cached has now agents (i.e. "perform-actual-lookup" option support) for all implemented nsswitch-databases, except shells. Shells database implementation should be reworked (nss-modules share the same static variables there) to allow this. Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/Makefile.inc#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.h#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.h#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.h#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.h#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cached.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/debug.h#3 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.c#3 (text) ==== @@ -29,8 +29,10 @@ __FBSDID("$FreeBSD: src/usr.sbin/cached/agent.c,v 1.1 2006/04/28 12:03:37 ume Exp $"); #include +#include #include #include +#include #include "agent.h" #include "debug.h" ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.h#3 (text) ==== @@ -29,9 +29,6 @@ #ifndef __CACHED_AGENT_H__ #define __CACHED_AGENT_H__ -#include -#include - extern int __isthreaded; /* TLS handling routine obtained from libc/include/nss_tls.h */ ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/Makefile.inc#3 (text) ==== @@ -1,3 +1,3 @@ # $FreeBSD: src/usr.sbin/cached/agents/Makefile.inc,v 1.1 2006/04/28 12:03:38 ume Exp $ -SRCS += passwd.c group.c services.c hosts.c +SRCS += group.c hosts.c net.c passwd.c proto.c rpc.c services.c ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.c#3 (text) ==== @@ -40,6 +40,7 @@ #include #include #include +#include "../agent.h" #include "../debug.h" #include "group.h" @@ -223,9 +224,8 @@ if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { - free(name); - TRACE_OUT(group_lookup_func); - return (NS_UNAVAIL); + result = NS_UNAVAIL; + break; } } } while ((result == NS_RETURN) && (error == ERANGE)); @@ -246,8 +246,8 @@ if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { - TRACE_OUT(group_lookup_func); - return (NS_UNAVAIL); + result = NS_UNAVAIL; + break; } } } while ((result == NS_RETURN) && (error == ERANGE)); @@ -319,6 +319,7 @@ group_mp_destroy_func(void *mdata) { TRACE_IN(group_mp_destroy_func); + endgrent(); TRACE_OUT(group_mp_destroy_func); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.h#3 (text) ==== @@ -26,7 +26,5 @@ * $FreeBSD: src/usr.sbin/cached/agents/group.h,v 1.1 2006/04/28 12:03:38 ume Exp $ */ -#include "../agent.h" - extern struct agent *init_group_agent(); extern struct agent *init_group_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.c#2 (text+ko) ==== @@ -28,7 +28,6 @@ #include __FBSDID("$FreeBSD$"); - #include #include #include @@ -46,6 +45,7 @@ #include #include #include +#include "../agent.h" #include "../debug.h" #include "hosts.h" @@ -61,7 +61,17 @@ AGENT_DECLARE_BUFFER_TLS_HANDLING(hostent); +#ifndef _ALIGNBYTES +#define _ALIGNBYTES ALIGNBYTES +#endif +#ifndef _ALIGN +#define _ALIGN(x) ALIGN(x) +#endif + +#define GETADDRINFO_OP_ID 0 +#define GETHOSTBY_OP_ID 1 + static int hostent_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) @@ -236,7 +246,7 @@ socklen_t len; int type; struct addrinfo hints, *ai_retval; - int error, result, op_id; + int error, h_error, result, op_id; size_t size; TRACE_IN(hosts_lookup_func); @@ -245,12 +255,12 @@ statp = __res_state(); if (statp == NULL) { - TRACE_OUT(passwd_lookup_func); + TRACE_OUT(hosts_lookup_func); return (NS_UNAVAIL); } if (key_size < sizeof(res_options) + sizeof(int)) { - TRACE_OUT(passwd_lookup_func); + TRACE_OUT(hosts_lookup_func); return (NS_UNAVAIL); } @@ -267,7 +277,7 @@ str = NULL; switch (op_id) { - case 0: /* getaddrinfo() */ + case GETADDRINFO_OP_ID: /* getaddrinfo() */ memset(&hints, 0, sizeof(struct addrinfo)); if (key_size < sizeof(int) * 4) { TRACE_OUT(hosts_lookup_func); @@ -298,8 +308,8 @@ old_options = statp->options; statp->options |= res_options; - result = nsdispatch(&ai_retval, emptydtab, NSDB_HOSTS, "getaddrinfo", - defaultsrc, str, &hints); + result = nsdispatch(&ai_retval, emptydtab, NSDB_HOSTS, + "getaddrinfo", defaultsrc, str, &hints); if (result == NS_SUCCESS) result = agent_marshal_results(out_buffer, out_size, @@ -308,7 +318,7 @@ statp->options = old_options; break; - case 1: /* gethostby**() */ + case GETHOSTBY_OP_ID: /* gethostby**() */ if (key_size < sizeof(enum nss_lookup_type) + sizeof(int)) { TRACE_OUT(hosts_lookup_func); return (NS_UNAVAIL); @@ -318,12 +328,12 @@ key += sizeof(enum nss_lookup_type); key_size -= sizeof(enum nss_lookup_type); + memcpy(&type, key, sizeof(int)); + key += sizeof(int); + key_size -= sizeof(int); + switch (lookup_type) { - case nss_lt_name: - memcpy(&type, key, sizeof(int)); - key += sizeof(int); - key_size -= sizeof(int); - + case nss_lt_name: size = key_size + 1; str = (char *)malloc(size); assert(str != NULL); @@ -331,10 +341,6 @@ memcpy(str, key, key_size); break; case nss_lt_id: - memcpy(&type, key, sizeof(int)); - key += sizeof(int); - key_size -= sizeof(int); - memcpy(&len, key, sizeof(socklen_t)); key += sizeof(socklen_t); key_size -= sizeof(socklen_t); @@ -363,48 +369,52 @@ switch (lookup_type) { case nss_lt_name: do { - result = nsdispatch(&h_retval, emptydtab, NSDB_HOSTS, - "gethostbyname2_r", defaultsrc, str, type, - &he, h_st->buffer, h_st->bufsize, &error); + result = nsdispatch(&h_retval, emptydtab, + NSDB_HOSTS, "gethostbyname2_r", + defaultsrc, str, type, + &he, h_st->buffer, h_st->bufsize, + &error, &h_error); - if ((result == NS_RETURN) && (error == ERANGE)) { - AGENT_BUFFER_TLS_HANDLING_RESIZE(h_st); - if (AGENT_BUFFER_TLS_HANDLING_CHECK(h_st) != 0) { - free(str); - statp->options = old_options; - TRACE_OUT(hosts_lookup_func); - return (NS_UNAVAIL); - } + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(h_st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(h_st) != 0) { + free(str); + statp->options = old_options; + TRACE_OUT(hosts_lookup_func); + return (NS_UNAVAIL); + } } } while ((result == NS_RETURN) && (error == ERANGE)); if (result == NS_SUCCESS) - result = agent_marshal_results(out_buffer, out_size, - hostent_marshal_func, (void *)nss_lt_name, - &h_retval, str, type, &he, - h_st->buffer, h_st->bufsize, &error); + result = agent_marshal_results(out_buffer, out_size, + hostent_marshal_func, (void *)nss_lt_name, + &h_retval, str, type, &he, + h_st->buffer, h_st->bufsize, + &error, &h_error); break; case nss_lt_all: do { - result = nsdispatch(&h_retval, emptydtab, NSDB_HOSTS, - "gethostbyaddr_r", defaultsrc, (void *)addr, len, type, - &he, h_st->buffer, h_st->bufsize, &error); + result = nsdispatch(&h_retval, emptydtab, NSDB_HOSTS, + "gethostbyaddr_r", defaultsrc, (void *)addr, + len, type, &he, h_st->buffer, h_st->bufsize, + &error); - if ((result == NS_RETURN) && (error == ERANGE)) { - AGENT_BUFFER_TLS_HANDLING_RESIZE(h_st); - if (AGENT_BUFFER_TLS_HANDLING_CHECK(h_st) != 0) { - statp->options = old_options; - TRACE_OUT(hosts_lookup_func); - return (NS_UNAVAIL); - } + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(h_st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(h_st) != 0) { + statp->options = old_options; + TRACE_OUT(hosts_lookup_func); + return (NS_UNAVAIL); } + } } while ((result == NS_RETURN) && (error == ERANGE)); if (result == NS_SUCCESS) - result = agent_marshal_results(out_buffer, out_size, - hostent_marshal_func, (void *)nss_lt_name, - &h_retval, (void *)addr, len, type, &he, - h_st->buffer, h_st->bufsize, &error); + result = agent_marshal_results(out_buffer, out_size, + hostent_marshal_func, (void *)nss_lt_name, + &h_retval, (void *)addr, len, type, &he, + h_st->buffer, h_st->bufsize, &error); break; default: /*SHOULD NOT BE REACHED */ ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.h#2 (text+ko) ==== @@ -26,6 +26,4 @@ * $FreeBSD$ */ -#include "../agent.h" - extern struct agent *init_hosts_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.c#2 (text+ko) ==== @@ -1,0 +1,288 @@ +/*- + * Copyright (c) 2006 Michael Bushkov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + + #include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../agent.h" +#include "../debug.h" +#include "net.h" + +static const ns_src defaultsrc[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NSSRC_DNS, NS_SUCCESS }, + { 0 } +}; + +static int networks_marshal_func(char *, size_t *, void *, va_list, void *); +static int networks_lookup_func(const char *, size_t, char **, size_t *); + +AGENT_DECLARE_BUFFER_TLS_HANDLING(netent); + +#ifndef _ALIGNBYTES +#define _ALIGNBYTES ALIGNBYTES +#endif + +#ifndef _ALIGN +#define _ALIGN(x) ALIGN(x) +#endif + +static int +networks_marshal_func(char *buffer, size_t *buffer_size, void *retval, + va_list ap, void *cache_mdata) +{ + char *name; + uint32_t net; + int type; + struct netent *ne; + char *orig_buf; + size_t orig_buf_size; + + struct netent new_ne; + size_t desired_size, size, aliases_size; + char *p; + char **alias; + + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + name = va_arg(ap, char *); + break; + case nss_lt_id: + net = va_arg(ap, uint32_t); + type = va_arg(ap, int); + break; + case nss_lt_all: + break; + default: + /* should be unreachable */ + return (NS_UNAVAIL); + } + + ne = va_arg(ap, struct netent *); + orig_buf = va_arg(ap, char *); + orig_buf_size = va_arg(ap, size_t); + + desired_size = _ALIGNBYTES + sizeof(struct netent) + sizeof(char *); + if (ne->n_name != NULL) + desired_size += strlen(ne->n_name) + 1; + + if (ne->n_aliases != NULL) { + aliases_size = 0; + for (alias = ne->n_aliases; *alias; ++alias) { + desired_size += strlen(*alias) + 1; + ++aliases_size; + } + + desired_size += _ALIGNBYTES + + (aliases_size + 1) * sizeof(char *); + } + + if (*buffer_size < desired_size) { + /* this assignment is here for future use */ + *buffer_size = desired_size; + return (NS_RETURN); + } + + memcpy(&new_ne, ne, sizeof(struct netent)); + + *buffer_size = 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); + + if (new_ne.n_name != NULL) { + size = strlen(new_ne.n_name); + memcpy(p, new_ne.n_name, size); + new_ne.n_name = p; + p += size + 1; + } + + if (new_ne.n_aliases != NULL) { + p = (char *)_ALIGN(p); + memcpy(p, new_ne.n_aliases, sizeof(char *) * aliases_size); + new_ne.n_aliases = (char **)p; + p += sizeof(char *) * (aliases_size + 1); + + for (alias = new_ne.n_aliases; *alias; ++alias) { + size = strlen(*alias); + memcpy(p, *alias, size); + *alias = p; + p += size + 1; + } + } + + memcpy(buffer, &new_ne, sizeof(struct netent)); + return (NS_SUCCESS); +} + +static int +networks_lookup_func(const char *key, size_t key_size, char **out_buffer, + size_t *out_size) +{ + struct netent_state *st; + struct netent ne, *retval; + enum nss_lookup_type lookup_type; + char *name; + uint32_t net; + int type; + int error, h_error, result; + size_t size; + + TRACE_IN(networks_lookup_func); + assert(out_buffer != NULL); + assert(out_size != NULL); + + if (key_size < sizeof(enum nss_lookup_type)) { + TRACE_OUT(networks_lookup_func); + return (NS_UNAVAIL); + } + memcpy(&lookup_type, key, sizeof(enum nss_lookup_type)); + + name = NULL; + switch (lookup_type) { + case nss_lt_name: + size = key_size - sizeof(enum nss_lookup_type) + 1; + name = (char *)malloc(size); + assert(name != NULL); + memset(name, 0, size); + memcpy(name, key + sizeof(enum nss_lookup_type), size - 1); + break; + case nss_lt_id: + if (key_size < sizeof(enum nss_lookup_type) + + sizeof(uint32_t) + sizeof(int)) { + TRACE_OUT(networks_lookup_func); + return (NS_UNAVAIL); + } + + memcpy(&net, key + sizeof(enum nss_lookup_type), + sizeof(uint32_t)); + memcpy(&type, key + sizeof(enum nss_lookup_type) + + sizeof(uint32_t), sizeof(int)); + break; + default: + TRACE_OUT(networks_lookup_func); + return (NS_UNAVAIL); + } + + result = netent_getstate(&st); + AGENT_BUFFER_TLS_HANDLING_INIT(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + free(name); + TRACE_OUT(networks_lookup_func); + return (NS_UNAVAIL); + } + + switch (lookup_type) { + case nss_lt_name: + do { + result = nsdispatch(&retval, emptydtab, NSDB_NETWORKS, + "getnetbyname_r", defaultsrc, name, + &ne, st->buffer, st->bufsize, &error, &h_error); + + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + result = NS_UNAVAIL; + break; + } + } + } while ((result == NS_RETURN) && (error == ERANGE)); + + if (result == NS_SUCCESS) + result = agent_marshal_results(out_buffer, out_size, + networks_marshal_func, (void *)nss_lt_name, + retval, name, &ne, + st->buffer, st->bufsize, &error, &h_error); + + break; + case nss_lt_id: + do { + result = nsdispatch(&retval, emptydtab, NSDB_NETWORKS, + "getnetbyaddr_r", defaultsrc, net, type, + &ne, st->buffer, st->bufsize, &error, &h_error); + + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + result = NS_UNAVAIL; + break; + } + } + } while ((result == NS_RETURN) && (error == ERANGE)); + + if (result == NS_SUCCESS) + result = agent_marshal_results(out_buffer, out_size, + networks_marshal_func, + (void *)nss_lt_id, retval, net, type, + &ne, st->buffer, st->bufsize, &error); + break; + default: + /* SHOULD NOT BE REACHED */ + break; + } + + free(name); + TRACE_OUT(networks_lookup_func); + return (result); +} + +struct agent * +init_networks_agent() +{ + struct common_agent *retval; + + TRACE_IN(init_networks_agent); + retval = (struct common_agent *)malloc(sizeof(struct common_agent)); + assert(retval != NULL); + memset(retval, 0, sizeof(struct common_agent)); + + retval->parent.name = strdup("networks"); + assert(retval->parent.name != NULL); + + retval->parent.type = COMMON_AGENT; + retval->lookup_func = networks_lookup_func; + + TRACE_OUT(init_networks_agent); + return ((struct agent *)retval); +} ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.h#2 (text+ko) ==== @@ -1,0 +1,29 @@ +/*- + * Copyright (c) 2006 Michael Bushkov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +extern struct agent *init_networks_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.c#3 (text) ==== @@ -38,6 +38,7 @@ #include #include #include +#include "../agent.h" #include "../debug.h" #include "passwd.h" @@ -175,7 +176,7 @@ assert(out_buffer != NULL); assert(out_size != NULL); - if (key_size < sizeof(enum nss_lookup_type) + 1) { + if (key_size < sizeof(enum nss_lookup_type)) { TRACE_OUT(passwd_lookup_func); return (NS_UNAVAIL); } @@ -222,9 +223,8 @@ if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { - free(login); - TRACE_OUT(passwd_lookup_func); - return (NS_UNAVAIL); + result = NS_UNAVAIL; + break; } } } while ((result == NS_RETURN) && (error == ERANGE)); @@ -238,15 +238,15 @@ break; case nss_lt_id: do { - result = nsdispatch(&retval, emptydtab, NSDB_SERVICES, + result = nsdispatch(&retval, emptydtab, NSDB_PASSWD, "getpwuid_r", defaultsrc, uid, &pwd, st->buffer, st->bufsize, &error); if ((result == NS_RETURN) && (error == ERANGE)) { AGENT_BUFFER_TLS_HANDLING_RESIZE(st); if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { - TRACE_OUT(passwd_lookup_func); - return (NS_UNAVAIL); + result = NS_UNAVAIL; + break; } } } while ((result == NS_RETURN) && (error == ERANGE)); @@ -318,6 +318,7 @@ passwd_mp_destroy_func(void *mdata) { TRACE_IN(passwd_mp_destroy_func); + endpwent(); TRACE_OUT(passwd_mp_destroy_func); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.h#3 (text) ==== @@ -26,7 +26,5 @@ * $FreeBSD: src/usr.sbin/cached/agents/passwd.h,v 1.1 2006/04/28 12:03:38 ume Exp $ */ -#include "../agent.h" - extern struct agent *init_passwd_agent(); extern struct agent *init_passwd_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.c#2 (text+ko) ==== @@ -1,0 +1,362 @@ +/*- + * Copyright (c) 2006 Michael Bushkov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + + #include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../agent.h" +#include "../debug.h" +#include "proto.h" + +static const ns_src defaultsrc[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NULL, 0 } +}; + +static int protocols_marshal_func(char *, size_t *, void *, va_list, void *); +static int protocols_lookup_func(const char *, size_t, char **, size_t *); +static void *protocols_mp_init_func(); +static int protocols_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata); +static void protocols_mp_destroy_func(void *mdata); + +AGENT_DECLARE_BUFFER_TLS_HANDLING(protoent); + +#ifndef _ALIGNBYTES +#define _ALIGNBYTES ALIGNBYTES +#endif + +#ifndef _ALIGN +#define _ALIGN(x) ALIGN(x) +#endif + +static int +protocols_marshal_func(char *buffer, size_t *buffer_size, void *retval, + va_list ap, void *cache_mdata) +{ + char *name; + int num; + struct protoent *proto; + char *orig_buf; + size_t orig_buf_size; + + struct protoent new_proto; + size_t desired_size, size, aliases_size; + char *p; + char **alias; + + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + name = va_arg(ap, char *); + break; + case nss_lt_id: + num = va_arg(ap, int); + break; + case nss_lt_all: + break; + default: + /* should be unreachable */ + return (NS_UNAVAIL); + } + + proto = va_arg(ap, struct protoent *); + orig_buf = va_arg(ap, char *); + orig_buf_size = va_arg(ap, size_t); + + desired_size = _ALIGNBYTES + sizeof(struct protoent) + sizeof(char *); + if (proto->p_name != NULL) + desired_size += strlen(proto->p_name) + 1; + + if (proto->p_aliases != NULL) { + aliases_size = 0; + for (alias = proto->p_aliases; *alias; ++alias) { + desired_size += strlen(*alias) + 1; + ++aliases_size; + } + + desired_size += _ALIGNBYTES + (aliases_size + 1) * + sizeof(char *); + } + + if (*buffer_size < desired_size) { + /* this assignment is here for future use */ + *buffer_size = desired_size; + return (NS_RETURN); + } + + memcpy(&new_proto, proto, sizeof(struct protoent)); + + *buffer_size = desired_size; + memset(buffer, 0, desired_size); + p = buffer + sizeof(struct protoent) + sizeof(char *); + memcpy(buffer + sizeof(struct protoent), &p, sizeof(char *)); + p = (char *)_ALIGN(p); + + if (new_proto.p_name != NULL) { + size = strlen(new_proto.p_name); + memcpy(p, new_proto.p_name, size); + new_proto.p_name = p; + p += size + 1; + } + + if (new_proto.p_aliases != NULL) { + p = (char *)_ALIGN(p); + memcpy(p, new_proto.p_aliases, sizeof(char *) * aliases_size); + new_proto.p_aliases = (char **)p; + p += sizeof(char *) * (aliases_size + 1); + + for (alias = new_proto.p_aliases; *alias; ++alias) { + size = strlen(*alias); + memcpy(p, *alias, size); + *alias = p; + p += size + 1; + } + } + + memcpy(buffer, &new_proto, sizeof(struct protoent)); + return (NS_SUCCESS); +} + +static int +protocols_lookup_func(const char *key, size_t key_size, char **out_buffer, + size_t *out_size) +{ + struct protoent_state *st; + struct protoent pe, *retval; + enum nss_lookup_type lookup_type; + char *name; + int num; + int error, result; + size_t size; + + TRACE_IN(protocols_lookup_func); + assert(out_buffer != NULL); + assert(out_size != NULL); + + if (key_size < sizeof(enum nss_lookup_type)) { + TRACE_OUT(protocols_lookup_func); + return (NS_UNAVAIL); + } + memcpy(&lookup_type, key, sizeof(enum nss_lookup_type)); + + name = NULL; + switch (lookup_type) { + case nss_lt_name: + size = key_size - sizeof(enum nss_lookup_type) + 1; + name = (char *)malloc(size); + assert(name != NULL); + memset(name, 0, size); + memcpy(name, key + sizeof(enum nss_lookup_type), size - 1); + break; + case nss_lt_id: + if (key_size < sizeof(enum nss_lookup_type) + + sizeof(int)) { + TRACE_OUT(protocols_lookup_func); + return (NS_UNAVAIL); + } + + memcpy(&num, key + sizeof(enum nss_lookup_type), sizeof(int)); + break; + default: + TRACE_OUT(protocols_lookup_func); + return (NS_UNAVAIL); + } + + result = protoent_getstate(&st); + AGENT_BUFFER_TLS_HANDLING_INIT(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + free(name); + TRACE_OUT(protocols_lookup_func); + return (NS_UNAVAIL); + } + + switch (lookup_type) { + case nss_lt_name: + do { + result = nsdispatch(&retval, emptydtab, NSDB_PROTOCOLS, + "getprotobyname_r", defaultsrc, name, + &pe, st->buffer, st->bufsize, &error); + + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + result = NS_UNAVAIL; + break; + } + } + } while ((result == NS_RETURN) && (error == ERANGE)); + + if (result == NS_SUCCESS) + result = agent_marshal_results(out_buffer, out_size, + protocols_marshal_func, (void *)nss_lt_name, + retval, name, &pe, + st->buffer, st->bufsize, &error); + + break; + case nss_lt_id: + do { + result = nsdispatch(&retval, emptydtab, NSDB_PROTOCOLS, + "getprotobynumber_r", defaultsrc, num, + &pe, st->buffer, st->bufsize, &error); + + if ((result == NS_RETURN) && (error == ERANGE)) { + AGENT_BUFFER_TLS_HANDLING_RESIZE(st); + if (AGENT_BUFFER_TLS_HANDLING_CHECK(st) != 0) { + result = NS_UNAVAIL; + break; + } + } + } while ((result == NS_RETURN) && (error == ERANGE)); + + if (result == NS_SUCCESS) + result = agent_marshal_results(out_buffer, out_size, + protocols_marshal_func, + (void *)nss_lt_id, retval, num, + &pe, st->buffer, st->bufsize, &error); + break; + default: + /* SHOULD NOT BE REACHED */ + break; + } + + free(name); + TRACE_OUT(protocols_lookup_func); + return (result); +} + +static void * +protocols_mp_init_func() +{ + TRACE_IN(protocols_mp_init_func); + setprotoent(1); + TRACE_OUT(protocols_mp_init_func); + + return (NULL); +} + +static int +protocols_mp_lookup_func(char **out_buffer, size_t *out_size, void *mdata) +{ >>> TRUNCATED FOR MAIL (1000 lines) <<<