usr/src/lib/libc/port/gen/nss_common.c
author djl
Fri, 29 Sep 2006 06:00:17 -0700
changeset 2830 5228d1267a01
parent 1914 8a8c5f225b1b
child 3015 0e6edb9f6863
permissions -rw-r--r--
PSARC 2005/133 Sparks: Name Service Switch 2 4406529 artificial limit of 10 threads per backend 4516075 LDAP connections could be reused more 4696964 LDAP naming services should support Kerberos authentication 4740951 Need host based authentication options in Native LDAP 4952533 Some backends of gethostby* do not set h_errno correctly 4979596 getXbyY calls should have better buffer mechanism 5028908 /usr/bin/logins accesses free memory deep in nss_getent_u(). 5046881 nscd: old-data-ok parameter is not useful, should go away 6225323 NSS/nscd Enhancements (Sparks Project)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    21
/*
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 0
diff changeset
    22
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    23
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
 * Shared code used by the name-service-switch frontends (e.g. getpwnam_r())
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
#pragma weak nss_delete = _nss_delete
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
#pragma weak nss_endent = _nss_endent
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
#pragma weak nss_getent = _nss_getent
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#pragma weak nss_search = _nss_search
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#pragma weak nss_setent = _nss_setent
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#include "synonyms.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
#include <mtlib.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
#include <dlfcn.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
#define	__NSS_PRIVATE_INTERFACE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
#include "nsswitch_priv.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
#undef	__NSS_PRIVATE_INTERFACE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
#include <nss_common.h>
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    47
#include <nss_dbdefs.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
#include <unistd.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
#include <stdlib.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
#include <stdio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
#include <string.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
#include <thread.h>
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    53
#include <sys/types.h>
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    54
#include <sys/mman.h>
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    55
#include <errno.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    56
#include "libc.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
#include "tsd.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    59
#include <getxby_door.h>
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    60
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    61
/*
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    62
 * policy component function interposing definitions:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    63
 * nscd if so desired can interpose it's own switch functions over
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    64
 * the internal unlocked counterparts.  This will allow nscd to replace
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    65
 * the switch policy state engine with one that uses it's internal
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    66
 * components.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    67
 * Only nscd can change this through it's use of nss_config.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    68
 * The golden rule is: ptr == NULL checking is used in the switch to
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    69
 * see if a function was interposed.  But nscd is responsible for seeing
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    70
 * that mutex locking to change the values are observed when the data is
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    71
 * changed.  Especially if it happens > once.  The switch does not lock
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    72
 * the pointer with mutexs.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    73
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    74
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    75
typedef struct {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    76
	void	*p;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    77
#if 0
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    78
	void		(*nss_delete_fp)(nss_db_root_t *rootp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    79
	nss_status_t	(*nss_search_fp)(nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    80
				nss_db_initf_t initf, int search_fnum,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    81
				void *search_args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    82
	void		(*nss_setent_u_fp)(nss_db_root_t *,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    83
				nss_db_initf_t, nss_getent_t *);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    84
	nss_status_t	(*nss_getent_u_fp)(nss_db_root_t *,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    85
				nss_db_initf_t, nss_getent_t *, void *);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    86
	void		(*nss_endent_u_fp)(nss_db_root_t *,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    87
				nss_db_initf_t, nss_getent_t *);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    88
	void		(*end_iter_u_fp)(nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    89
				struct nss_getent_context *contextp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    90
#endif
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    91
} nss_policyf_t;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    92
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    93
static mutex_t nss_policyf_lock = DEFAULTMUTEX;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    94
static nss_policyf_t nss_policyf_ptrs =
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    95
	{ (void *)NULL };
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    96
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    97
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
    98
 * nsswitch db_root state machine definitions:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
 * The golden rule is:  if you hold a pointer to an nss_db_state struct and
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
 * you don't hold the lock, you'd better have incremented the refcount
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
 * while you held the lock;  otherwise, it may vanish or change
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
 * significantly when you least expect it.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
 * The pointer in nss_db_root_t is one such, so the reference count >= 1.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
 * Ditto the pointer in struct nss_getent_context.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   109
 * State for one nsswitch database (e.g. "passwd", "hosts")
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   111
struct nss_db_state {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
	nss_db_root_t		orphan_root;	/* XXX explain */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   113
	unsigned		refcount;	/* One for the pointer in    */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   114
						/*   nss_db_root_t, plus one */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
						/*   for each active thread. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   116
	nss_db_params_t		p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   117
	struct __nsw_switchconfig_v1 *config;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
	int			max_src;	/* is == config->num_lookups */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   119
	struct nss_src_state	*src;		/* Pointer to array[max_src] */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   120
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   121
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   122
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
 * State for one of the sources (e.g. "nis", "compat") for a database
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   125
struct nss_src_state {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   126
	struct __nsw_lookup_v1	*lkp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   127
	int			n_active;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
	int			n_dormant;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	int			n_waiting;	/* ... on wanna_be */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   130
	cond_t			wanna_be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
	union {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   132
		nss_backend_t	*single; /* Efficiency hack for common case */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   133
					    /* when limit_dead_backends == 1 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   134
		nss_backend_t	**multi; /* array[limit_dead_backends] of */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
	} dormant;			    /* pointers to dormant backends */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   136
	nss_backend_constr_t	be_constr;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
	nss_backend_finder_t	*finder;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   138
	void			*finder_priv;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   139
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   140
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   141
static struct nss_db_state	*_nss_db_state_constr(nss_db_initf_t);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   142
void				_nss_db_state_destr(struct nss_db_state *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   143
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   144
/* ==== null definitions if !MTSAFE?  Ditto lock field in nss_db_root_t */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   145
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   146
#define	NSS_ROOTLOCK(r, sp)	((void) _private_mutex_lock(&(r)->lock), \
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   147
				*(sp) = (r)->s)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   148
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   149
#define	NSS_UNLOCK(r)		((void) _private_mutex_unlock(&(r)->lock))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   150
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   151
#define	NSS_CHECKROOT(rp, s)	((s) != (*(rp))->s &&			\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   152
			((void) _private_mutex_unlock(&(*(rp))->lock),	\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   153
			(void) _private_mutex_lock(&(s)->orphan_root.lock), \
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   154
			*(rp) = &(s)->orphan_root))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   155
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   156
#define	NSS_RELOCK(rp, s)	((void) _private_mutex_lock(&(*(rp))->lock), \
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
			NSS_CHECKROOT(rp, s))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   158
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   159
#define	NSS_STATE_REF_u(s)	(++(s)->refcount)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   160
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   161
#define	NSS_UNREF_UNLOCK(r, s)	(--(s)->refcount != 0			\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   162
			? ((void)NSS_UNLOCK(r))				\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   163
			: (NSS_UNLOCK(r), (void)_nss_db_state_destr(s)))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   164
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   165
#define	NSS_LOCK_CHECK(r, f, sp)    (NSS_ROOTLOCK((r), (sp)),	\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   166
				    *(sp) == 0 &&		\
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   167
				    (r->s = *(sp) = _nss_db_state_constr(f)))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   168
/* === In the future, NSS_LOCK_CHECK() may also have to check that   */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   169
/* === the config info hasn't changed (by comparing version numbers) */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   170
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   171
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   172
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   173
 * NSS_OPTIONS/NIS_OPTIONS environment varibles data definitions:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   174
 * This remains for backwards compatibility.  But generally nscd will
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   175
 * decide if/how this gets used.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   176
 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   177
static int checked_env = 0;		/* protected by "rootlock" */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   178
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   179
	/* allowing __nss_debug_file to be set could be a security hole. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
FILE *__nss_debug_file = stdout;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   181
int __nss_debug_eng_loop;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   182
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
/* NIS_OPTIONS infrastructure (from linbsl/nis/cache/cache_api.cc) */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
	/* allowing __nis_debug_file to be set could be a security hole. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   185
FILE *__nis_debug_file = stdout;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
int __nis_debug_bind;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
int __nis_debug_rpc;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
int __nis_debug_calls;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
char *__nis_prefsrv;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
char *__nis_preftype;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   191
char *__nis_server;   /* if set, use only this server for binding */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   192
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   193
#define	OPT_INT 1
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   194
#define	OPT_STRING 2
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   195
#ifdef DEBUG
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   196
#define	OPT_FILE 3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   197
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   198
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   199
struct option {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
	char *name;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
	int type;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   202
	void *address;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   203
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   204
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   205
static struct option nss_options[] = {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   206
#ifdef DEBUG
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   207
	/* allowing __nss_debug_file to be set could be a security hole. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   208
	{ "debug_file", OPT_FILE, &__nss_debug_file },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   209
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   210
	{ "debug_eng_loop", OPT_INT, &__nss_debug_eng_loop },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   211
	{ 0, 0, 0 },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   212
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   213
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   214
static struct option nis_options[] = {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   215
#ifdef DEBUG
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   216
	/* allowing __nis_debug_file to be set could be a security hole. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   217
	{ "debug_file", OPT_FILE, &__nis_debug_file },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   218
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   219
	{ "debug_bind", OPT_INT, &__nis_debug_bind },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   220
	{ "debug_rpc", OPT_INT, &__nis_debug_rpc },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   221
	{ "debug_calls", OPT_INT, &__nis_debug_calls },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   222
	{ "server", OPT_STRING, &__nis_server },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   223
	{ "pref_srvr", OPT_STRING, &__nis_prefsrv },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   224
	{ "pref_type", OPT_STRING, &__nis_preftype },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   225
	{ 0, 0, 0 },
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   226
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   227
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   228
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   229
 * switch configuration parameter "database" definitions:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   230
 * The switch maintains a simmple read/write parameter database
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   231
 * that nscd and the switch components can use to communicate
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   232
 * nscd data to other components for configuration or out of band
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   233
 * [IE no in the context of a getXbyY or putXbyY operation] data.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   234
 * The data passed are pointers to a lock  data buffer and a length.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   235
 * Use of this is treated as SunwPrivate between nscd and the switch
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   236
 * unless other wise stated.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   237
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   238
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   239
typedef struct nss_cfgparam {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   240
	char 		*name;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   241
	mutex_t		*lock;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   242
	void		*buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   243
	size_t		length;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   244
} nss_cfgparam_t;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   245
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   246
typedef struct nss_cfglist {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   247
	char 		*name;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   248
	nss_cfgparam_t	*list;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   249
	int		count;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   250
	int		max;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   251
} nss_cfglist_t;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   252
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   253
#define	NSS_CFG_INCR	16
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   254
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   255
static nss_cfglist_t *nss_cfg = (nss_cfglist_t *)NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   256
static int nss_cfgcount = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   257
static int nss_cfgmax = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   258
static mutex_t nss_cfglock = DEFAULTMUTEX;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   259
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   260
static int nss_cfg_policy_init();
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   261
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   262
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   263
 * A config parameters are in the form component:parameter
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   264
 * as in: nss:parameter - switch (internal FE/policy/BE) parameter
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   265
 *	  nscd:param - nscd application parameter
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   266
 *	  ldap:param - nss_ldap BE parameter
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   267
 *	  passwd:param - get/put passwd FE parameter
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   268
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   269
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   270
#define	NSS_CONFIG_BRK	':'
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   271
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   272
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   273
 * The policy components initial parameter list
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   274
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   275
static nss_config_t	nss_policy_params[] = {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   276
	{ "nss:policyfunc", NSS_CONFIG_ADD, &nss_policyf_lock,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   277
		(void *)&nss_policyf_ptrs, (size_t)sizeof (nss_policyf_t) },
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   278
	{ NULL,	NSS_CONFIG_ADD,	(mutex_t *)NULL, (void *)NULL, (size_t)0 },
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   279
};
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   280
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   281
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   282
 * NSS parameter configuration routines
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   283
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   284
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   285
/* compare config name (component:parameter) to a component name */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   286
static int
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   287
nss_cfgcn_cmp(const char *cfgname, const char *compname)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   288
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   289
	char *c;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   290
	size_t len, len2;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   291
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   292
	/* this code assumes valid pointers */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   293
	if ((c = strchr(cfgname, NSS_CONFIG_BRK)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   294
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   295
	len = (size_t)(c - cfgname);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   296
	len2 = strlen(compname);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   297
	if (len2 != len)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   298
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   299
	return (strncmp(cfgname, compname, len));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   300
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   301
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   302
/* init configuration arena */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   303
static int
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   304
nss_cfg_init()
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   305
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   306
	int i;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   307
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   308
	/* First time caller? */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   309
	if (nss_cfg != NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   310
		return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   311
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   312
	/* Initialize internal tables */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   313
	lmutex_lock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   314
	if (nss_cfg != NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   315
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   316
		return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   317
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   318
	nss_cfg = (nss_cfglist_t *)libc_malloc(NSS_CFG_INCR *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   319
					    sizeof (nss_cfglist_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   320
	if (nss_cfg == (nss_cfglist_t *)NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   321
		errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   322
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   323
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   324
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   325
	nss_cfgmax = NSS_CFG_INCR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   326
	for (i = 0; i < nss_cfgmax; i++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   327
		nss_cfg[i].list = (nss_cfgparam_t *)libc_malloc(NSS_CFG_INCR *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   328
					sizeof (nss_cfgparam_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   329
		if (nss_cfg[i].list == (nss_cfgparam_t *)NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   330
			errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   331
			lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   332
			return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   333
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   334
		nss_cfg[i].max = NSS_CFG_INCR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   335
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   336
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   337
	/* Initialize Policy Engine values */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   338
	lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   339
	if (nss_cfg_policy_init() < 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   340
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   341
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   342
	return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   343
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   344
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   345
/* find the name'd component list - create it if non-existent */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   346
static nss_cfglist_t *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   347
nss_cfgcomp_get(char *name, int add)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   348
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   349
	nss_cfglist_t	*next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   350
	char	*c;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   351
	int	i, len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   352
	size_t	nsize;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   353
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   354
	/* Make sure system is init'd */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   355
	if (nss_cfg == NULL && nss_cfg_init() < 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   356
		return ((nss_cfglist_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   357
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   358
	/* and check component:name validity */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   359
	if (name == NULL || (c = strchr(name, NSS_CONFIG_BRK)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   360
		return ((nss_cfglist_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   361
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   362
	lmutex_lock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   363
	next = nss_cfg;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   364
	for (i = 0; i < nss_cfgcount; i++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   365
		if (next->name && nss_cfgcn_cmp(name, next->name) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   366
			lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   367
			return (next);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   368
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   369
		next++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   370
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   371
	if (!add) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   372
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   373
		return (NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   374
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   375
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   376
	/* not found, create a fresh one */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   377
	if (nss_cfgcount >= nss_cfgmax) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   378
		/* realloc first */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   379
		nsize = (nss_cfgmax + NSS_CFG_INCR) * sizeof (nss_cfgparam_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   380
		next = (nss_cfglist_t *)libc_realloc(nss_cfg, nsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   381
		if (next == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   382
			errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   383
			lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   384
			return ((nss_cfglist_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   385
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   386
		(void) memset((void *)(next + nss_cfgcount), '\0',
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   387
			NSS_CFG_INCR * sizeof (nss_cfglist_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   388
		nss_cfgmax += NSS_CFG_INCR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   389
		nss_cfg = next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   390
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   391
	next = nss_cfg + nss_cfgcount;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   392
	len = (size_t)(c - name) + 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   393
	if ((next->name = libc_malloc(len)) == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   394
		errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   395
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   396
		return ((nss_cfglist_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   397
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   398
	nss_cfgcount++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   399
	(void) strlcpy(next->name, name, len);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   400
	lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   401
	return (next);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   402
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   403
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   404
/* find the name'd parameter - create it if non-existent */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   405
static nss_cfgparam_t *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   406
nss_cfgparam_get(char *name, int add)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   407
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   408
	nss_cfglist_t	*comp;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   409
	nss_cfgparam_t	*next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   410
	int	count, i;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   411
	size_t	nsize;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   412
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   413
	if ((comp = nss_cfgcomp_get(name, add)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   414
		return ((nss_cfgparam_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   415
	lmutex_lock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   416
	count = comp->count;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   417
	next = comp->list;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   418
	for (i = 0; i < count; i++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   419
		if (next->name && strcmp(name, next->name) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   420
			lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   421
			return (next);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   422
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   423
		next++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   424
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   425
	if (!add) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   426
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   427
		return (NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   428
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   429
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   430
	/* not found, create a fresh one */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   431
	if (count >= comp->max) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   432
		/* realloc first */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   433
		nsize = (comp->max + NSS_CFG_INCR) * sizeof (nss_cfgparam_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   434
		next = (nss_cfgparam_t *)libc_realloc(comp->list, nsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   435
		if (next == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   436
			errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   437
			lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   438
			return ((nss_cfgparam_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   439
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   440
		comp->max += NSS_CFG_INCR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   441
		comp->list = next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   442
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   443
	next = comp->list + comp->count;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   444
	if ((next->name = libc_strdup(name)) == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   445
		errno = ENOMEM;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   446
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   447
		return ((nss_cfgparam_t *)NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   448
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   449
	comp->count++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   450
	lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   451
	return (next);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   452
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   453
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   454
/* find the name'd parameter - delete it if it exists */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   455
static void
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   456
nss_cfg_del(nss_config_t *cfgp)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   457
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   458
	char		*name;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   459
	nss_cfglist_t	*comp;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   460
	nss_cfgparam_t	*next, *cur;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   461
	int	count, i, j;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   462
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   463
	/* exit if component name does not already exist */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   464
	if ((name = cfgp->name) == NULL ||
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   465
	    (comp = nss_cfgcomp_get(name, 0)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   466
		return;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   467
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   468
	/* find it */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   469
	lmutex_lock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   470
	count = comp->count;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   471
	next = comp->list;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   472
	for (i = 0; i < count; i++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   473
		if (next->name && strcmp(name, next->name) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   474
			break;	/* found it... */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   475
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   476
		next++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   477
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   478
	if (i >= count) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   479
		/* not found, already deleted */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   480
		lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   481
		return;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   482
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   483
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   484
	/* copy down the remaining parameters, and clean up */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   485
	/* don't try to clean up component tables */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   486
	cur = next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   487
	next++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   488
	for (j = i+1; j < count; j++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   489
		*cur = *next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   490
		cur++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   491
		next++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   492
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   493
	/* erase the last one */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   494
	if (cur->name) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   495
		libc_free(cur->name);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   496
		cur->name = (char *)NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   497
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   498
	cur->lock = (mutex_t *)NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   499
	cur->buffer = (void *)NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   500
	cur->length = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   501
	comp->count--;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   502
	lmutex_unlock(&nss_cfglock);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   503
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   504
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   505
static int
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   506
nss_cfg_get(nss_config_t *next)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   507
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   508
	nss_cfgparam_t	*param;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   509
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   510
	errno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   511
	if ((param = nss_cfgparam_get(next->name, 0)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   512
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   513
	next->lock = param->lock;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   514
	next->buffer = param->buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   515
	next->length = param->length;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   516
	return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   517
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   518
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   519
static int
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   520
nss_cfg_put(nss_config_t *next, int add)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   521
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   522
	nss_cfgparam_t	*param;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   523
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   524
	errno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   525
	if ((param = nss_cfgparam_get(next->name, add)) == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   526
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   527
	param->lock = next->lock;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   528
	param->buffer = next->buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   529
	param->length = next->length;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   530
	return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   531
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   532
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   533
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   534
 * Policy engine configurator - set and get interface
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   535
 * argument is a NULL terminated list of set/get requests
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   536
 * with input/result buffers and lengths.  nss_cname is the
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   537
 * specifier of a set or get operation and the property being
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   538
 * managed.  The intent is limited functions and expandability.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   539
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   540
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   541
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   542
nss_config(nss_config_t **plist, int cnt)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   543
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   544
	nss_config_t	*next;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   545
	int 	i;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   546
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   547
	/* interface is only available to nscd */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   548
	if (_nsc_proc_is_cache() <= 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   549
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   550
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   551
	if (plist == NULL || cnt <= 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   552
		return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   553
	for (i = 0; i < cnt; i++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   554
		next = plist[i];
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   555
		if (next == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   556
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   557
		if (next->name == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   558
			errno = EFAULT;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   559
			return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   560
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   561
		switch (next->cop) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   562
		case NSS_CONFIG_GET:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   563
			/* get current lock/buffer/length fields */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   564
			if (nss_cfg_get(next) < 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   565
				return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   566
			}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   567
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   568
		case NSS_CONFIG_PUT:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   569
			/* set new lock/buffer/length fields */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   570
			if (nss_cfg_put(next, 0) < 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   571
				return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   572
			}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   573
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   574
		case NSS_CONFIG_ADD:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   575
			/* add parameter & set new lock/buffer/length fields */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   576
			if (nss_cfg_put(next, 1) < 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   577
				return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   578
			}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   579
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   580
		case NSS_CONFIG_DELETE:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   581
			/* delete parameter - should always work... */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   582
			nss_cfg_del(next);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   583
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   584
		case NSS_CONFIG_LIST:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   585
			break;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   586
		default:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   587
			continue;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   588
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   589
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   590
	return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   591
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   592
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   593
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   594
 * This routine is called immediately after nss_cfg_init but prior to
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   595
 * any commands from nscd being processed.  The intent here is to
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   596
 * initialize the nss:* parameters allowed by the policy component
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   597
 * so that nscd can then proceed and modify them if so desired.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   598
 *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   599
 * We know we can only get here if we are nscd so we can skip the
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   600
 * preliminaries.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   601
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   602
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   603
static int
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   604
nss_cfg_policy_init()
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   605
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   606
	nss_config_t	*next = &nss_policy_params[0];
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   607
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   608
	for (; next && next->name != NULL; next++) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   609
		if (nss_cfg_put(next, 1) < 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   610
			return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   611
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   612
	return (0);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   613
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   614
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   615
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   616
 * NSS_OPTION & NIS_OPTION environment variable functions
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   617
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   618
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   619
static
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   620
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   621
set_option(struct option *opt, char *name, char *val)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   622
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   623
	int n;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   624
	char *p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   625
#ifdef DEBUG
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   626
	FILE *fp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   627
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   628
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   629
	for (; opt->name; opt++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   630
		if (strcmp(name, opt->name) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   631
			switch (opt->type) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   632
			    case OPT_STRING:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   633
				p = libc_strdup(val);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   634
				*((char **)opt->address) = p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   635
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   636
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   637
			    case OPT_INT:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   638
				if (strcmp(val, "") == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   639
					n = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   640
				else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   641
					n = atoi(val);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   642
				*((int *)opt->address) = n;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   643
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   644
#ifdef DEBUG
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   645
			    case OPT_FILE:
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 0
diff changeset
   646
				fp = fopen(val, "wF");
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   647
				*((FILE **)opt->address) = fp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   648
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   649
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   650
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   651
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   652
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   653
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   654
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   655
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   656
static
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   657
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   658
__parse_environment(struct option *opt, char *p)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   659
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   660
	char *base;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   661
	char optname[100];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   662
	char optval[100];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   663
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   664
	while (*p) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   665
		while (isspace(*p))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   666
			p++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   667
		if (*p == '\0')
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   668
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   669
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   670
		base = p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   671
		while (*p && *p != '=' && !isspace(*p))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   672
			p++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   673
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   674
		 * play it safe and keep it simple, bail if an opt name
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   675
		 * is too long.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   676
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   677
		if ((p-base) >= sizeof (optname))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   678
			return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   679
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   680
		(void) strncpy(optname, base, p-base);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   681
		optname[p-base] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   682
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   683
		if (*p == '=') {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   684
			p++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   685
			base = p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   686
			while (*p && !isspace(*p))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   687
				p++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   688
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   689
			 * play it safe and keep it simple, bail if an opt
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   690
			 * value is too long.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   691
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   692
			if ((p-base) >= sizeof (optval))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   693
				return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   694
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   695
			(void) strncpy(optval, base, p-base);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   696
			optval[p-base] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   697
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   698
			optval[0] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   699
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   700
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   701
		set_option(opt, optname, optval);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   702
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   703
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   704
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   705
static
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   706
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   707
nss_get_environment()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   708
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   709
	char *p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   710
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   711
/* NSS_OPTIONS is undocumented and should be used without nscd running. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   712
	p = getenv("NSS_OPTIONS");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   713
	if (p == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   714
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   715
	__parse_environment(nss_options, p);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   716
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   717
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   718
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   719
 * sole external routine called from libnsl/nis/cache/cache_api.cc in the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   720
 * routines _nis_CacheInit/__nis_CacheLocalInit/__nis_CacheMgrInit_discard
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   721
 * Only after checking "checked_env" (which must be done with mutex
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   722
 * "cur_cache_lock" held) and is done once, (then "checked_env" is set)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   723
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   724
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   725
__nis_get_environment()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   726
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   727
	char *p;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   728
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   729
	p = getenv("NIS_OPTIONS");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   730
	if (p == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   731
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   732
	__parse_environment(nis_options, p);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   733
}
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   734
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   735
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   736
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   737
 * Switch policy component backend state machine functions
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   738
 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   739
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   740
static nss_backend_t *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   741
nss_get_backend_u(nss_db_root_t **rootpp, struct nss_db_state *s, int n_src)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   742
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   743
	struct nss_src_state	*src = &s->src[n_src];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   744
	nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   745
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   746
	for (;;) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   747
		if (src->n_dormant > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   748
			src->n_dormant--;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   749
			src->n_active++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   750
			if (s->p.max_dormant_per_src == 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   751
				be = src->dormant.single;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   752
			} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   753
				be = src->dormant.multi[src->n_dormant];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   754
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   755
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   756
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   757
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   758
		if (src->be_constr == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   759
			nss_backend_finder_t	*bf;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   760
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   761
			for (bf = s->p.finders;  bf != 0;  bf = bf->next) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   762
				nss_backend_constr_t c;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   763
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   764
				c = (*bf->lookup)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   765
					(bf->lookup_priv,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   766
						s->p.name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   767
						src->lkp->service_name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   768
						&src->finder_priv);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   769
				if (c != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   770
					src->be_constr = c;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   771
					src->finder = bf;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   772
					break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   773
				}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   774
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   775
			if (src->be_constr == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   776
				/* Couldn't find the backend anywhere */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   777
				be = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   778
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   779
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   780
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   781
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   782
		if (src->n_active < s->p.max_active_per_src) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   783
			be = (*src->be_constr)(s->p.name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   784
						src->lkp->service_name,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   785
						0 /* === unimplemented */);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   786
			if (be != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   787
				src->n_active++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   788
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   789
			} else if (src->n_active == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   790
				/* Something's wrong;  we should be */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   791
				/*   able to create at least one    */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   792
				/*   instance of the backend	    */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   793
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   794
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   795
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   796
			 * Else it's odd that we can't create another backend
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   797
			 *   instance, but don't sweat it;  instead, queue for
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   798
			 *   an existing backend instance.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   799
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   800
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   801
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   802
		src->n_waiting++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   803
		(void) cond_wait(&src->wanna_be, &(*rootpp)->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   804
		NSS_CHECKROOT(rootpp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   805
		src->n_waiting--;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   806
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   807
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   808
		 * Loop and see whether things got better for us, or whether
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   809
		 *   someone else got scheduled first and we have to try
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   810
		 *   this again.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   811
		 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   812
		 * === ?? Should count iterations, assume bug if many ??
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   813
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   814
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   815
	return (be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   816
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   817
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   818
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   819
nss_put_backend_u(struct nss_db_state *s, int n_src, nss_backend_t *be)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   820
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   821
	struct nss_src_state	*src = &s->src[n_src];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   822
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   823
	if (be == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   824
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   825
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   826
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   827
	src->n_active--;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   828
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   829
	if (src->n_dormant < s->p.max_dormant_per_src) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   830
		if (s->p.max_dormant_per_src == 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   831
			src->dormant.single = be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   832
			src->n_dormant++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   833
		} else if (src->dormant.multi != 0 ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   834
			(src->dormant.multi =
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   835
			    libc_malloc(s->p.max_dormant_per_src *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   836
			    sizeof (nss_backend_t *))) != NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   837
			src->dormant.multi[src->n_dormant] = be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   838
			src->n_dormant++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   839
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   840
			/* Can't store it, so toss it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   841
			(void) NSS_INVOKE_DBOP(be, NSS_DBOP_DESTRUCTOR, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   842
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   843
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   844
		/* We've stored as many as we want, so toss it */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   845
		(void) NSS_INVOKE_DBOP(be, NSS_DBOP_DESTRUCTOR, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   846
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   847
	if (src->n_waiting > 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   848
		(void) cond_signal(&src->wanna_be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   849
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   850
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   851
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   852
static struct nss_db_state *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   853
_nss_db_state_constr(nss_db_initf_t initf)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   854
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   855
	struct nss_db_state	*s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   856
	struct __nsw_switchconfig_v1 *config = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   857
	struct __nsw_lookup_v1	*lkp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   858
	enum __nsw_parse_err	err;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   859
	const char		*config_name;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   860
	int			n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   861
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   862
	if ((s = libc_malloc(sizeof (*s))) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   863
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   864
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   865
	(void) _private_mutex_init(&s->orphan_root.lock, USYNC_THREAD, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   866
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   867
	s->p.max_active_per_src	= 10;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   868
	s->p.max_dormant_per_src = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   869
	s->p.finders = nss_default_finders;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   870
	(*initf)(&s->p);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   871
	if (s->p.name == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   872
		_nss_db_state_destr(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   873
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   874
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   875
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   876
	if (!checked_env) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   877
/* NSS_OPTIONS is undocumented and should be used without nscd running. */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   878
		nss_get_environment();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   879
		checked_env = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   880
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   881
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   882
	config_name = s->p.config_name ? s->p.config_name : s->p.name;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   883
	if (! (s->p.flags & NSS_USE_DEFAULT_CONFIG)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   884
		config = __nsw_getconfig_v1(config_name, &err);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   885
		/* === ? test err ? */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   886
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   887
	if (config == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   888
		/* getconfig failed, or frontend demanded default config */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   889
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   890
		char	*str;	/* _nsw_getoneconfig() clobbers its argument */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   891
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   892
		if ((str = libc_strdup(s->p.default_config)) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   893
			config = _nsw_getoneconfig_v1(config_name, str, &err);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   894
			libc_free(str);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   895
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   896
		if (config == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   897
			_nss_db_state_destr(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   898
			return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   899
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   900
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   901
	s->config = config;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   902
	if ((s->max_src = config->num_lookups) <= 0 ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   903
	    (s->src = libc_malloc(s->max_src * sizeof (*s->src))) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   904
		_nss_db_state_destr(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   905
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   906
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   907
	for (n_src = 0, lkp = config->lookups;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   908
	    n_src < s->max_src; n_src++, lkp = lkp->next) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   909
		s->src[n_src].lkp = lkp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   910
		(void) cond_init(&s->src[n_src].wanna_be, USYNC_THREAD, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   911
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   912
	s->refcount = 1;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   913
	return (s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   914
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   915
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   916
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   917
_nss_src_state_destr(struct nss_src_state *src, int max_dormant)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   918
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   919
	if (max_dormant == 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   920
		if (src->n_dormant != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   921
			(void) NSS_INVOKE_DBOP(src->dormant.single,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   922
					NSS_DBOP_DESTRUCTOR, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   923
		};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   924
	} else if (src->dormant.multi != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   925
		int	n;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   926
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   927
		for (n = 0;  n < src->n_dormant;  n++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   928
			(void) NSS_INVOKE_DBOP(src->dormant.multi[n],
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   929
					NSS_DBOP_DESTRUCTOR, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   930
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   931
		libc_free(src->dormant.multi);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   932
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   933
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   934
	/* cond_destroy(&src->wanna_be); */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   935
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   936
	if (src->finder != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   937
		(*src->finder->delete)(src->finder_priv, src->be_constr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   938
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   939
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   940
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   941
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   942
 * _nss_db_state_destr() -- used by NSS_UNREF_UNLOCK() to free the entire
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   943
 *	nss_db_state structure.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   944
 * Assumes that s has been ref-counted down to zero (in particular,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   945
 *	rootp->s has already been dealt with).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   946
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   947
 * Nobody else holds a pointer to *s (if they did, refcount != 0),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   948
 *   so we can clean up state *after* we drop the lock (also, by the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   949
 *   time we finish freeing the state structures, the lock may have
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   950
 *   ceased to exist -- if we were using the orphan_root).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   951
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   952
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   953
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   954
_nss_db_state_destr(struct nss_db_state *s)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   955
{
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   956
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   957
	if (s == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   958
		return;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
   959
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   960
	/* === _private_mutex_destroy(&s->orphan_root.lock); */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   961
	if (s->p.cleanup != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   962
		(*s->p.cleanup)(&s->p);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   963
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   964
	if (s->config != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   965
		(void) __nsw_freeconfig_v1(s->config);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   966
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   967
	if (s->src != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   968
		int	n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   969
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   970
		for (n_src = 0;  n_src < s->max_src;  n_src++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   971
			_nss_src_state_destr(&s->src[n_src],
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   972
				s->p.max_dormant_per_src);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   973
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   974
		libc_free(s->src);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   975
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   976
	libc_free(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   977
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   978
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   979
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   980
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   981
 * _nss_status_vec() returns a bit vector of all status codes returned during
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   982
 * the most recent call to nss_search().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   983
 * _nss_status_vec_p() returns a pointer to this bit vector, or NULL on
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   984
 * failure.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   985
 * These functions are private.  Don't use them externally without discussing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   986
 * it with the switch maintainers.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   987
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   988
static uint_t *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   989
_nss_status_vec_p()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   990
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   991
	return (tsdalloc(_T_NSS_STATUS_VEC, sizeof (uint_t), NULL));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   992
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   993
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   994
unsigned int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   995
_nss_status_vec(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   996
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   997
	unsigned int *status_vec_p = _nss_status_vec_p();
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   998
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   999
	return ((status_vec_p != NULL) ? *status_vec_p : (1 << NSS_UNAVAIL));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1000
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1001
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1002
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1003
output_loop_diag_a(
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1004
	int n,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1005
	char *dbase,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1006
	struct __nsw_lookup_v1 *lkp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1007
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1008
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1009
	(void) fprintf(__nss_debug_file,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1010
		"NSS_retry(%d): '%s': trying '%s' ... ",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1011
		n, dbase, lkp->service_name);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1012
	(void) fflush(__nss_debug_file);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1013
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1014
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1015
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1016
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1017
output_loop_diag_b(
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1018
	nss_status_t res,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1019
	struct __nsw_lookup_v1 *lkp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1020
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1021
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1022
	(void) fprintf(__nss_debug_file, "result=");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1023
	switch (res) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1024
	case NSS_SUCCESS:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1025
		(void) fprintf(__nss_debug_file, "SUCCESS");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1026
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1027
	case NSS_NOTFOUND:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1028
		(void) fprintf(__nss_debug_file, "NOTFOUND");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1029
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1030
	case NSS_UNAVAIL:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1031
		(void) fprintf(__nss_debug_file, "UNAVAIL");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1032
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1033
	case NSS_TRYAGAIN:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1034
		(void) fprintf(__nss_debug_file, "TRYAGAIN");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1035
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1036
	case NSS_NISSERVDNS_TRYAGAIN:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1037
		(void) fprintf(__nss_debug_file, "NISSERVDNS_TRYAGAIN");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1038
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1039
	default:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1040
		(void) fprintf(__nss_debug_file, "undefined");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1041
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1042
	(void) fprintf(__nss_debug_file, ", action=");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1043
	switch (lkp->actions[res]) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1044
	case __NSW_CONTINUE:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1045
		(void) fprintf(__nss_debug_file, "CONTINUE");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1046
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1047
	case  __NSW_RETURN:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1048
		(void) fprintf(__nss_debug_file, "RETURN");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1049
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1050
	case __NSW_TRYAGAIN_FOREVER:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1051
		(void) fprintf(__nss_debug_file, "TRYAGAIN_FOREVER");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1052
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1053
	case __NSW_TRYAGAIN_NTIMES:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1054
		(void) fprintf(__nss_debug_file, "TRYAGAIN_NTIMES (N=%d)",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1055
			lkp->max_retries);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1056
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1057
	case __NSW_TRYAGAIN_PAUSED:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1058
		(void) fprintf(__nss_debug_file, "TRYAGAIN_PAUSED");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1059
		break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1060
	default:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1061
		(void) fprintf(__nss_debug_file, "undefined");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1062
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1063
	(void) fprintf(__nss_debug_file, "\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1064
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1065
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1066
#define	NSS_BACKOFF(n, b, t) \
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1067
			((n) > ((b) + 3) ? t : (1 << ((n) - ((b) + 1))))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1068
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1069
static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1070
retry_test(nss_status_t res, int n, struct __nsw_lookup_v1 *lkp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1071
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1072
	if (res != NSS_TRYAGAIN && res !=  NSS_NISSERVDNS_TRYAGAIN) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1073
		if (res == NSS_SUCCESS) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1074
			__NSW_UNPAUSE_ACTION(lkp->actions[__NSW_TRYAGAIN]);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1075
			__NSW_UNPAUSE_ACTION(
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1076
				lkp->actions[__NSW_NISSERVDNS_TRYAGAIN]);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1077
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1078
		return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1079
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1080
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1081
	if ((res == NSS_TRYAGAIN &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1082
	    lkp->actions[__NSW_TRYAGAIN] == __NSW_TRYAGAIN_FOREVER) ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1083
	    (res == NSS_NISSERVDNS_TRYAGAIN &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1084
	    lkp->actions[__NSW_NISSERVDNS_TRYAGAIN] == __NSW_TRYAGAIN_FOREVER))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1085
		return (1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1086
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1087
	if (res == NSS_TRYAGAIN &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1088
	    lkp->actions[__NSW_TRYAGAIN] == __NSW_TRYAGAIN_NTIMES)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1089
		if (n <= lkp->max_retries)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1090
			return (1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1091
		else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1092
			lkp->actions[__NSW_TRYAGAIN] = __NSW_TRYAGAIN_PAUSED;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1093
			return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1094
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1095
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1096
	if (res == NSS_NISSERVDNS_TRYAGAIN &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1097
	    lkp->actions[__NSW_NISSERVDNS_TRYAGAIN] == __NSW_TRYAGAIN_NTIMES)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1098
		if (n <= lkp->max_retries)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1099
			return (1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1100
		else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1101
			lkp->actions[__NSW_NISSERVDNS_TRYAGAIN] =
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1102
			    __NSW_TRYAGAIN_PAUSED;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1103
			return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1104
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1105
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1106
	return (0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1107
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1108
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1109
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1110
 * Switch policy component functional interfaces
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1111
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1112
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1113
void
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1114
nss_delete(nss_db_root_t *rootp)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1115
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1116
	struct nss_db_state	*s;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1117
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1118
	/* no name service cache daemon divert here */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1119
	/* local nss_delete decrements state reference counts */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1120
	/* and may free up opened switch resources. */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1121
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1122
	NSS_ROOTLOCK(rootp, &s);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1123
	if (s == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1124
		NSS_UNLOCK(rootp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1125
	} else {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1126
		rootp->s = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1127
		NSS_UNREF_UNLOCK(rootp, s);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1128
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1129
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1130
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1131
nss_status_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1132
nss_search(nss_db_root_t *rootp, nss_db_initf_t initf, int search_fnum,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1133
	void *search_args)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1134
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1135
	nss_status_t		res = NSS_UNAVAIL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1136
	struct nss_db_state	*s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1137
	int			n_src;
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1138
	unsigned int		*status_vec_p;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1139
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1140
	/* name service cache daemon divert */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1141
	res = _nsc_search(rootp, initf, search_fnum, search_args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1142
	if (res != NSS_TRYLOCAL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1143
		return (res);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1144
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1145
	/* fall through - process locally */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1146
	errno = 0;			/* just in case ... */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1147
	res = NSS_UNAVAIL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1148
	status_vec_p = _nss_status_vec_p();
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1149
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1150
	if (status_vec_p == NULL) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1151
		return (NSS_UNAVAIL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1152
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1153
	*status_vec_p = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1154
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1155
	NSS_LOCK_CHECK(rootp, initf, &s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1156
	if (s == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1157
		NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1158
		return (res);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1159
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1160
	NSS_STATE_REF_u(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1161
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1162
	for (n_src = 0;  n_src < s->max_src;  n_src++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1163
		nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1164
		nss_backend_op_t	funcp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1165
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1166
		res = NSS_UNAVAIL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1167
		if ((be = nss_get_backend_u(&rootp, s, n_src)) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1168
			if ((funcp = NSS_LOOKUP_DBOP(be, search_fnum)) != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1169
				int n_loop = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1170
				int no_backoff = 19;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1171
				int max_backoff = 5;	/* seconds */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1172
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1173
				do {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1174
					/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1175
					 * Backend operation may take a while;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1176
					 * drop the lock so we don't serialize
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1177
					 * more than necessary.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1178
					 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1179
					NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1180
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1181
					/* After several tries, backoff... */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1182
					if (n_loop > no_backoff) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1183
					    if (__nss_debug_eng_loop > 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1184
						(void) fprintf(__nss_debug_file,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1185
						"NSS: loop: sleeping %d ...\n",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1186
						    NSS_BACKOFF(n_loop,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1187
						    no_backoff, max_backoff));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1188
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1189
					    (void) sleep(NSS_BACKOFF(n_loop,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1190
						    no_backoff, max_backoff));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1191
					}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1192
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1193
					if (__nss_debug_eng_loop)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1194
						output_loop_diag_a(n_loop,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1195
							s->config->dbase,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1196
							s->src[n_src].lkp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1197
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1198
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1199
					res = (*funcp)(be, search_args);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1200
					NSS_RELOCK(&rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1201
					n_loop++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1202
					if (__nss_debug_eng_loop)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1203
						output_loop_diag_b(res,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1204
							s->src[n_src].lkp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1205
				} while (retry_test(res, n_loop,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1206
							s->src[n_src].lkp));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1207
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1208
			nss_put_backend_u(s, n_src, be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1209
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1210
		*status_vec_p |= (1 << res);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1211
		if (__NSW_ACTION_V1(s->src[n_src].lkp, res) == __NSW_RETURN) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1212
			if (__nss_debug_eng_loop)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1213
				(void) fprintf(__nss_debug_file,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1214
					"NSS: '%s': return.\n",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1215
					s->config->dbase);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1216
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1217
		} else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1218
			if (__nss_debug_eng_loop)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1219
				(void) fprintf(__nss_debug_file,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1220
					"NSS: '%s': continue ...\n",
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1221
					s->config->dbase);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1222
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1223
	NSS_UNREF_UNLOCK(rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1224
	return (res);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1225
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1226
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1227
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1228
/*
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1229
 * Start of nss_{setent|getent|endent}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1230
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1231
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1232
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1233
 * State (here called "context") for one setent/getent.../endent sequence.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1234
 *   In principle there could be multiple contexts active for a single
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1235
 *   database;  in practice, since Posix and UI have helpfully said that
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1236
 *   getent() state is global rather than, say, per-thread or user-supplied,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1237
 *   we have at most one of these per nss_db_state.
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1238
 *   XXX ? Is this statement still true?
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1239
 *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1240
 * NSS2 - a client's context is maintained as a cookie delivered by and
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1241
 * passed to nscd.  The cookie is a 64 bit (nssuint_t) unique opaque value
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1242
 * created by nscd.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1243
 * cookie states:
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1244
 *	NSCD_NEW_COOKIE		- cookie value uninitialized
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1245
 *	NSCD_LOCAL_COOKIE	- setent is a local setent
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1246
 *	all other		- NSCD unique opaque id for this setent
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1247
 * A client's context is also associated with a seq_num.  This is a nscd
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1248
 * opaque 64 bit (nssuint_t) value passed with a cookie, and used to by nscd
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1249
 * to validate the sequencing of the context.  The client treats this as
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1250
 * a pass through value.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1251
 *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1252
 * XXX ??  Use Cookie as cross-check info so that we can detect an
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1253
 * nss_context that missed an nss_delete() or similar.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1254
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1255
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1256
struct nss_getent_context {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1257
	int			n_src;	/* >= max_src ==> end of sequence */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1258
	nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1259
	struct nss_db_state	*s;
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1260
	nssuint_t		cookie;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1261
	nssuint_t		seq_num;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1262
	nss_db_params_t		param;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1263
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1264
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1265
static void		nss_setent_u(nss_db_root_t *,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1266
				    nss_db_initf_t,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1267
				    nss_getent_t *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1268
static nss_status_t	nss_getent_u(nss_db_root_t *,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1269
				    nss_db_initf_t,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1270
				    nss_getent_t *,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1271
				    void *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1272
static void		nss_endent_u(nss_db_root_t *,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1273
				    nss_db_initf_t,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1274
				    nss_getent_t *);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1275
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1276
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1277
nss_setent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1278
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1279
	if (contextpp == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1280
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1281
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1282
	(void) _private_mutex_lock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1283
	nss_setent_u(rootp, initf, contextpp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1284
	(void) _private_mutex_unlock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1285
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1286
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1287
nss_status_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1288
nss_getent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1289
	void *args)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1290
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1291
	nss_status_t		status;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1292
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1293
	if (contextpp == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1294
		return (NSS_UNAVAIL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1295
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1296
	(void) _private_mutex_lock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1297
	status = nss_getent_u(rootp, initf, contextpp, args);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1298
	(void) _private_mutex_unlock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1299
	return (status);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1300
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1301
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1302
void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1303
nss_endent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1304
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1305
	if (contextpp == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1306
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1307
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1308
	(void) _private_mutex_lock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1309
	nss_endent_u(rootp, initf, contextpp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1310
	(void) _private_mutex_unlock(&contextpp->lock);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1311
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1312
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1313
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1314
 * Each of the _u versions of the nss interfaces assume that the context
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1315
 * lock is held.  No need to divert to nscd.  Private to local sequencing.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1316
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1317
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1318
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1319
end_iter_u(nss_db_root_t *rootp, struct nss_getent_context *contextp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1320
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1321
	struct nss_db_state	*s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1322
	nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1323
	int			n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1324
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1325
	s = contextp->s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1326
	n_src = contextp->n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1327
	be = contextp->be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1328
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1329
	if (s != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1330
		if (n_src < s->max_src && be != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1331
			(void) NSS_INVOKE_DBOP(be, NSS_DBOP_ENDENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1332
			NSS_RELOCK(&rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1333
			nss_put_backend_u(s, n_src, be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1334
			contextp->be = 0;  /* Should be unnecessary, but hey */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1335
			NSS_UNREF_UNLOCK(rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1336
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1337
		contextp->s = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1338
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1339
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1340
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1341
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1342
nss_setent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1343
	nss_getent_t *contextpp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1344
{
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1345
	nss_status_t		status;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1346
	struct nss_db_state	*s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1347
	struct nss_getent_context *contextp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1348
	nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1349
	int			n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1350
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1351
	/* setup process wide context while locked */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1352
	if ((contextp = contextpp->ctx) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1353
		if ((contextp = libc_malloc(sizeof (*contextp))) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1354
			return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1355
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1356
		contextpp->ctx = contextp;
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1357
		contextp->cookie = NSCD_NEW_COOKIE;	/* cookie init */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1358
		contextp->seq_num = 0;			/* seq_num init */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1359
		s = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1360
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1361
		s = contextp->s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1362
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1363
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1364
	/* name service cache daemon divert */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1365
	status = _nsc_setent_u(rootp, initf, contextpp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1366
	if (status != NSS_TRYLOCAL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1367
		return;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1368
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1369
	/* fall through - process locally */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1370
	if (s == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1371
		NSS_LOCK_CHECK(rootp, initf, &s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1372
		if (s == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1373
			/* Couldn't set up state, so quit */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1374
			NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1375
			/* ==== is there any danger of not having done an */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1376
			/* end_iter() here, and hence of losing backends? */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1377
			contextpp->ctx = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1378
			libc_free(contextp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1379
			return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1380
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1381
		NSS_STATE_REF_u(s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1382
		contextp->s = s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1383
	} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1384
		s	= contextp->s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1385
		n_src	= contextp->n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1386
		be	= contextp->be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1387
		if (n_src == 0 && be != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1388
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1389
			 * Optimization:  don't do endent, don't change
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1390
			 *   backends, just do the setent.  Look Ma, no locks
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1391
			 *   (nor any context that needs updating).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1392
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1393
			(void) NSS_INVOKE_DBOP(be, NSS_DBOP_SETENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1394
			return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1395
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1396
		if (n_src < s->max_src && be != 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1397
			(void) NSS_INVOKE_DBOP(be, NSS_DBOP_ENDENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1398
			NSS_RELOCK(&rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1399
			nss_put_backend_u(s, n_src, be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1400
			contextp->be = 0;	/* Play it safe */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1401
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1402
			NSS_RELOCK(&rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1403
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1404
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1405
	for (n_src = 0, be = 0; n_src < s->max_src &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1406
		(be = nss_get_backend_u(&rootp, s, n_src)) == 0; n_src++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1407
		;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1408
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1409
	NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1410
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1411
	contextp->n_src	= n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1412
	contextp->be	= be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1413
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1414
	if (be == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1415
		/* Things are broken enough that we can't do setent/getent */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1416
		nss_endent_u(rootp, initf, contextpp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1417
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1418
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1419
	(void) NSS_INVOKE_DBOP(be, NSS_DBOP_SETENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1420
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1421
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1422
static nss_status_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1423
nss_getent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1424
	nss_getent_t *contextpp, void *args)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1425
{
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1426
	nss_status_t		status;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1427
	struct nss_db_state	*s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1428
	struct nss_getent_context *contextp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1429
	int			n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1430
	nss_backend_t		*be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1431
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1432
	if ((contextp = contextpp->ctx) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1433
		nss_setent_u(rootp, initf, contextpp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1434
		if ((contextp = contextpp->ctx) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1435
			/* Give up */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1436
			return (NSS_UNAVAIL);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1437
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1438
	}
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1439
	/* name service cache daemon divert */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1440
	status = _nsc_getent_u(rootp, initf, contextpp, args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1441
	if (status != NSS_TRYLOCAL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1442
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1443
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1444
	/* fall through - process locally */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1445
	s	= contextp->s;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1446
	n_src	= contextp->n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1447
	be	= contextp->be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1448
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1449
	if (s == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1450
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1451
		 * We've done an end_iter() and haven't done nss_setent()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1452
		 * or nss_endent() since;  we should stick in this state
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1453
		 * until the caller invokes one of those two routines.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1454
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1455
		return (NSS_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1456
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1457
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1458
	while (n_src < s->max_src) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1459
		nss_status_t res;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1460
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1461
		if (be == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1462
			/* If it's null it's a bug, but let's play safe */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1463
			res = NSS_UNAVAIL;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1464
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1465
			res = NSS_INVOKE_DBOP(be, NSS_DBOP_GETENT, args);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1466
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1467
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1468
		if (__NSW_ACTION_V1(s->src[n_src].lkp, res) == __NSW_RETURN) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1469
			if (res != __NSW_SUCCESS) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1470
				end_iter_u(rootp, contextp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1471
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1472
			return (res);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1473
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1474
		(void) NSS_INVOKE_DBOP(be, NSS_DBOP_ENDENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1475
		NSS_RELOCK(&rootp, s);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1476
		nss_put_backend_u(s, n_src, be);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1477
		do {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1478
			n_src++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1479
		} while (n_src < s->max_src &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1480
			(be = nss_get_backend_u(&rootp, s, n_src)) == 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1481
		if (be == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1482
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1483
			 * This is the case where we failed to get the backend
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1484
			 * for the last source. We exhausted all sources.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1485
			 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1486
			NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1487
			nss_endent_u(rootp, initf, contextpp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1488
			nss_delete(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1489
			return (NSS_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1490
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1491
		NSS_UNLOCK(rootp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1492
		contextp->n_src	= n_src;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1493
		contextp->be	= be;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1494
		(void) NSS_INVOKE_DBOP(be, NSS_DBOP_SETENT, 0);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1495
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1496
	/* Got to the end of the sources without finding another entry */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1497
	end_iter_u(rootp, contextp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1498
	return (NSS_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1499
	/* success is either a successful entry or end of the sources */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1500
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1501
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1502
/*ARGSUSED*/
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1503
static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1504
nss_endent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1505
	nss_getent_t *contextpp)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1506
{
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1507
	nss_status_t		status;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1508
	struct nss_getent_context *contextp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1509
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1510
	if ((contextp = contextpp->ctx) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1511
		/* nss_endent() on an unused context is a no-op */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1512
		return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1513
	}
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1514
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1515
	/* notify name service cache daemon */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1516
	status = _nsc_endent_u(rootp, initf, contextpp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1517
	if (status != NSS_TRYLOCAL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1518
		/* clean up */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1519
		libc_free(contextp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1520
		contextpp->ctx = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1521
		return;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1522
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1523
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1524
	/* fall through - process locally */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1525
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1526
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1527
	 * Existing code (BSD, SunOS) works in such a way that getXXXent()
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1528
	 *   following an endXXXent() behaves as though the user had invoked
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1529
	 *   setXXXent(), i.e. it iterates properly from the beginning.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1530
	 * We'd better not break this, so our choices are
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1531
	 *	(1) leave the context structure around, and do nss_setent or
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1532
	 *	    something equivalent,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1533
	 *   or	(2) free the context completely, and rely on the code in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1534
	 *	    nss_getent() that makes getXXXent() do the right thing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1535
	 *	    even without a preceding setXXXent().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1536
	 * The code below does (2), which frees up resources nicely but will
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1537
	 * cost more if the user then does more getXXXent() operations.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1538
	 * Moral:  for efficiency, don't call endXXXent() prematurely.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1539
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1540
	end_iter_u(rootp, contextp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1541
	libc_free(contextp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1542
	contextpp->ctx = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
  1543
}
2830
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1544
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1545
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1546
 * pack dbd data into header
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1547
 * Argment pointers assumed valid.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1548
 * poff offset position pointer
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1549
 *   IN = starting offset for dbd header
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1550
 *   OUT = starting offset for next section
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1551
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1552
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1553
static nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1554
nss_pack_dbd(void *buffer, size_t bufsize, nss_db_params_t *p, size_t *poff)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1555
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1556
	nss_pheader_t		*pbuf = (nss_pheader_t *)buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1557
	nss_dbd_t		*pdbd;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1558
	size_t			off = *poff;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1559
	size_t			len, blen;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1560
	size_t			n, nc, dc;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1561
	char			*bptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1562
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1563
	pbuf->dbd_off = (nssuint_t)off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1564
	bptr = (char *)buffer + off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1565
	blen = bufsize - off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1566
	len = sizeof (nss_dbd_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1567
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1568
	n = nc = dc = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1569
	if (p->name == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1570
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1571
		return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1572
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1573
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1574
	/* if default config not specified, the flag should be reset */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1575
	if (p->default_config == NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1576
		p->default_config = "<NULL>";
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1577
		p->flags = p->flags & ~NSS_USE_DEFAULT_CONFIG;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1578
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1579
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1580
	n = strlen(p->name) + 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1581
	dc = strlen(p->default_config) + 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1582
	if (n < 2 || dc < 2) {			/* What no DB? */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1583
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1584
		return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1585
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1586
	if (p->config_name != NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1587
		nc = strlen(p->config_name) + 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1588
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1589
	if ((len + n + nc + dc) >= blen) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1590
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1591
		return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1592
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1593
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1594
	pdbd = (nss_dbd_t *)((void *)bptr);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1595
	bptr += len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1596
	pdbd->flags = p->flags;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1597
	pdbd->o_name = len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1598
	(void) strlcpy(bptr, p->name, n);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1599
	len += n;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1600
	bptr += n;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1601
	if (nc == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1602
		pdbd->o_config_name = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1603
	} else {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1604
		pdbd->o_config_name = len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1605
		(void) strlcpy(bptr, p->config_name, nc);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1606
		bptr += nc;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1607
		len += nc;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1608
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1609
	pdbd->o_default_config = len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1610
	(void) strlcpy(bptr, p->default_config, dc);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1611
	len += dc;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1612
	pbuf->dbd_len = (nssuint_t)len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1613
	off += ROUND_UP(len, sizeof (nssuint_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1614
	*poff = off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1615
	return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1616
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1617
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1618
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1619
 * Switch packed and _nsc (switch->nscd) interfaces
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1620
 * Return: NSS_SUCCESS (OK to proceed), NSS_ERROR, NSS_NOTFOUND
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1621
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1622
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1623
/*ARGSUSED*/
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1624
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1625
nss_pack(void *buffer, size_t bufsize, nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1626
	    nss_db_initf_t initf, int search_fnum, void *search_args)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1627
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1628
	nss_pheader_t		*pbuf = (nss_pheader_t *)buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1629
	nss_XbyY_args_t		*in = (nss_XbyY_args_t *)search_args;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1630
	nss_db_params_t		tparam = { 0 };
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1631
	nss_status_t		ret = NSS_ERROR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1632
	const char		*dbn;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1633
	size_t			blen, len, off = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1634
	char			*bptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1635
	nssuint_t		*uptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1636
	struct nss_groupsbymem	*gbm;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1637
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1638
	if (pbuf == NULL || in == NULL || initf == (nss_db_initf_t)NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1639
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1640
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1641
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1642
	tparam.cleanup = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1643
	(*initf)(&tparam);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1644
	if ((dbn = tparam.name) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1645
		if (tparam.cleanup != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1646
			(tparam.cleanup)(&tparam);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1647
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1648
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1649
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1650
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1651
	/* init buffer header */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1652
	pbuf->pbufsiz = (nssuint_t)bufsize;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1653
	pbuf->p_ruid = (uint32_t)getuid();
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1654
	pbuf->p_euid = (uint32_t)geteuid();
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1655
	pbuf->p_version = NSCD_HEADER_REV;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1656
	pbuf->p_status = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1657
	pbuf->p_errno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1658
	pbuf->p_herrno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1659
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1660
	/* possible audituser init */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1661
	if (strcmp(dbn, NSS_DBNAM_AUTHATTR) == 0 && in->h_errno != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1662
		pbuf->p_herrno = (uint32_t)in->h_errno;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1663
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1664
	pbuf->libpriv = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1665
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1666
	off = sizeof (nss_pheader_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1667
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1668
	/* setup getXbyY operation - database and sub function */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1669
	pbuf->nss_dbop = (uint32_t)search_fnum;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1670
	ret = nss_pack_dbd(buffer, bufsize, &tparam, &off);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1671
	if (ret != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1672
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1673
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1674
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1675
	ret = NSS_ERROR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1676
	/* setup request key */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1677
	pbuf->key_off = (nssuint_t)off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1678
	bptr = (char *)buffer + off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1679
	blen = bufsize - off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1680
	/* use key2str if provided, else call default getXbyY packer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1681
	if (strcmp(dbn, NSS_DBNAM_NETGROUP) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1682
		/* This has to run locally due to backend knowledge */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1683
		if (search_fnum == NSS_DBOP_NETGROUP_SET) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1684
			errno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1685
			return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1686
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1687
		/* use default packer for known getXbyY ops */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1688
		ret = nss_default_key2str(bptr, blen, in, dbn,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1689
						search_fnum, &len);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1690
	} else if (in->key2str == NULL ||
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1691
		(search_fnum == NSS_DBOP_GROUP_BYMEMBER &&
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1692
			strcmp(dbn, NSS_DBNAM_GROUP) == 0)) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1693
		/* use default packer for known getXbyY ops */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1694
		ret = nss_default_key2str(bptr, blen, in, dbn,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1695
						search_fnum, &len);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1696
	} else {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1697
		ret = (*in->key2str)(bptr, blen, &in->key, &len);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1698
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1699
	if (tparam.cleanup != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1700
		(tparam.cleanup)(&tparam);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1701
	if (ret != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1702
		errno = ERANGE;			/* actually ENOMEM */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1703
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1704
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1705
	pbuf->key_len = (nssuint_t)len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1706
	off += ROUND_UP(len, sizeof (nssuint_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1707
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1708
	pbuf->data_off = (nssuint_t)off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1709
	pbuf->data_len = (nssuint_t)(bufsize - off);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1710
	/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1711
	 * Prime data return with first result if
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1712
	 * the first result is passed in
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1713
	 * [_getgroupsbymember oddness]
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1714
	 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1715
	gbm = (struct nss_groupsbymem *)search_args;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1716
	if (search_fnum == NSS_DBOP_GROUP_BYMEMBER &&
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1717
	    strcmp(dbn, NSS_DBNAM_GROUP) == 0 && gbm->numgids == 1) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1718
		uptr = (nssuint_t *)((void *)((char *)buffer + off));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1719
		*uptr = (nssuint_t)gbm->gid_array[0];
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1720
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1721
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1722
	errno = 0;				/* just in case ... */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1723
	return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1724
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1725
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1726
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1727
 * Switch packed and _nsc (switch->nscd) {set/get/end}ent interfaces
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1728
 * Return: NSS_SUCCESS (OK to proceed), NSS_ERROR, NSS_NOTFOUND
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1729
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1730
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1731
/*ARGSUSED*/
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1732
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1733
nss_pack_ent(void *buffer, size_t bufsize, nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1734
	    nss_db_initf_t initf, nss_getent_t *contextpp)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1735
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1736
	nss_pheader_t		*pbuf = (nss_pheader_t *)buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1737
	struct nss_getent_context *contextp = contextpp->ctx;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1738
	nss_status_t		ret = NSS_ERROR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1739
	size_t			blen, len = 0, off = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1740
	char			*bptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1741
	nssuint_t		*nptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1742
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1743
	if (pbuf == NULL || initf == (nss_db_initf_t)NULL) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1744
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1745
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1746
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1747
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1748
	/* init buffer header */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1749
	pbuf->pbufsiz = (nssuint_t)bufsize;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1750
	pbuf->p_ruid = (uint32_t)getuid();
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1751
	pbuf->p_euid = (uint32_t)geteuid();
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1752
	pbuf->p_version = NSCD_HEADER_REV;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1753
	pbuf->p_status = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1754
	pbuf->p_errno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1755
	pbuf->p_herrno = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1756
	pbuf->libpriv = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1757
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1758
	off = sizeof (nss_pheader_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1759
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1760
	/* setup getXXXent operation - database and sub function */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1761
	pbuf->nss_dbop = (uint32_t)0;	/* iterators have no dbop */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1762
	ret = nss_pack_dbd(buffer, bufsize, &contextp->param, &off);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1763
	if (ret != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1764
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1765
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1766
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1767
	ret = NSS_ERROR;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1768
	off += ROUND_UP(len, sizeof (nssuint_t));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1769
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1770
	pbuf->key_off = (nssuint_t)off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1771
	bptr = (char *)buffer + off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1772
	blen = bufsize - off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1773
	len = (size_t)(sizeof (nssuint_t) * 2);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1774
	if (len >= blen) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1775
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1776
		return (ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1777
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1778
	nptr = (nssuint_t *)((void *)bptr);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1779
	*nptr++ = contextp->cookie;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1780
	*nptr = contextp->seq_num;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1781
	pbuf->key_len = (nssuint_t)len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1782
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1783
	off += len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1784
	pbuf->data_off = (nssuint_t)off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1785
	pbuf->data_len = (nssuint_t)(bufsize - off);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1786
	return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1787
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1788
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1789
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1790
 * Unpack packed arguments buffer
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1791
 * Return: status, errnos and results from requested operation.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1792
 *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1793
 * NOTES: When getgroupsbymember is being processed in the NSCD backend,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1794
 * or via the backwards compatibility interfaces then the standard
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1795
 * str2group API is used in conjunction with process_cstr.  When,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1796
 * processing a returned buffer, in NSS2 the return results are the
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1797
 * already digested groups array.  Therefore, unpack the digested results
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1798
 * back to the return buffer.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1799
 *
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1800
 * Note: the digested results are nssuint_t quantities.  _getgroupsbymember
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1801
 * digests int quantities.  Therefore convert.  Assume input is in nssuint_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1802
 * quantities.  Store in an int array... Assume gid's are <= 32 bits...
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1803
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1804
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1805
/*ARGSUSED*/
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1806
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1807
nss_unpack(void *buffer, size_t bufsize, nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1808
	    nss_db_initf_t initf, int search_fnum, void *search_args)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1809
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1810
	nss_pheader_t		*pbuf = (nss_pheader_t *)buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1811
	nss_XbyY_args_t		*in = (nss_XbyY_args_t *)search_args;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1812
	nss_dbd_t		*pdbd;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1813
	char			*dbn;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1814
	nss_status_t		status;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1815
	char			*buf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1816
	int			len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1817
	int			ret;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1818
	int			i;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1819
	gid_t			*gidp;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1820
	nssuint_t		*uptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1821
	struct nss_groupsbymem	*arg;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1822
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1823
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1824
	if (pbuf == NULL || in == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1825
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1826
	status = pbuf->p_status;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1827
	/* if error - door's switch error */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1828
	/* extended data could contain additional information? */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1829
	if (status != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1830
		in->h_errno = (int)pbuf->p_herrno;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1831
		if (pbuf->p_errno == ERANGE)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1832
			in->erange = 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1833
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1834
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1835
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1836
	if (pbuf->data_off == 0 || pbuf->data_len == 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1837
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1838
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1839
	buf = (char *)buffer + pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1840
	len = pbuf->data_len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1841
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1842
	/* sidestep odd cases */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1843
	pdbd = (nss_dbd_t *)((void *)((char *)buffer + pbuf->dbd_off));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1844
	dbn = (char *)pdbd + pdbd->o_name;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1845
	if (search_fnum == NSS_DBOP_GROUP_BYMEMBER) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1846
		if (strcmp(dbn, NSS_DBNAM_GROUP) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1847
			arg = (struct nss_groupsbymem *)in;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1848
			/* copy returned gid array from returned nscd buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1849
			i = len / sizeof (nssuint_t);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1850
			/* not enough buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1851
			if (i > arg->maxgids) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1852
				i = arg->maxgids;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1853
			}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1854
			arg->numgids = i;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1855
			gidp = arg->gid_array;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1856
			uptr = (nssuint_t *)((void *)buf);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1857
			while (--i >= 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1858
				*gidp++ = (gid_t)*uptr++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1859
			return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1860
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1861
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1862
	if (search_fnum == NSS_DBOP_NETGROUP_IN) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1863
		if (strcmp(dbn, NSS_DBNAM_NETGROUP) == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1864
			struct nss_innetgr_args *arg =
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1865
				(struct nss_innetgr_args *)in;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1866
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1867
			if (pbuf->p_status == NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1868
				arg->status = NSS_NETGR_FOUND;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1869
				return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1870
			} else {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1871
				arg->status = NSS_NETGR_NO;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1872
				return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1873
			}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1874
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1875
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1876
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1877
	/* process the normal cases */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1878
	/* marshall data directly into users buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1879
	ret = (*in->str2ent)(buf, len, in->buf.result, in->buf.buffer,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1880
		in->buf.buflen);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1881
	if (ret == NSS_STR_PARSE_ERANGE) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1882
		in->returnval = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1883
		in->returnlen = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1884
		in->erange    = 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1885
		ret = NSS_NOTFOUND;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1886
	} else if (ret == NSS_STR_PARSE_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1887
		in->returnval = in->buf.result;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1888
		in->returnlen =  len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1889
		ret = NSS_SUCCESS;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1890
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1891
	in->h_errno = (int)pbuf->p_herrno;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1892
	return ((nss_status_t)ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1893
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1894
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1895
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1896
 * Unpack a returned packed {set,get,end}ent arguments buffer
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1897
 * Return: status, errnos, cookie info and results from requested operation.
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1898
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1899
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1900
/*ARGSUSED*/
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1901
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1902
nss_unpack_ent(void *buffer, size_t bufsize, nss_db_root_t *rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1903
	    nss_db_initf_t initf, nss_getent_t *contextpp, void *args)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1904
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1905
	nss_pheader_t		*pbuf = (nss_pheader_t *)buffer;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1906
	nss_XbyY_args_t		*in = (nss_XbyY_args_t *)args;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1907
	struct nss_getent_context *contextp = contextpp->ctx;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1908
	nssuint_t		*nptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1909
	nssuint_t		cookie;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1910
	nss_status_t		status;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1911
	char			*buf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1912
	int			len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1913
	int			ret;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1914
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1915
	if (pbuf == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1916
		return (-1);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1917
	status = pbuf->p_status;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1918
	/* if error - door's switch error */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1919
	/* extended data could contain additional information? */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1920
	if (status != NSS_SUCCESS)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1921
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1922
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1923
	/* unpack assigned cookie from SET/GET/END request */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1924
	if (pbuf->key_off == 0 ||
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1925
	    pbuf->key_len != (sizeof (nssuint_t) * 2))
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1926
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1927
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1928
	nptr = (nssuint_t *)((void *)((char *)buffer + pbuf->key_off));
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1929
	cookie = contextp->cookie;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1930
	if (cookie != NSCD_NEW_COOKIE && cookie != *nptr) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1931
		/* Should either be new or a match, else error */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1932
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1933
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1934
	/* save away for the next ent request */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1935
	contextp->cookie = *nptr++;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1936
	contextp->seq_num = *nptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1937
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1938
	/* All done if no marshalling is expected {set,end}ent */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1939
	if (args == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1940
		return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1941
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1942
	/* unmarshall the data */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1943
	if (pbuf->data_off == 0 || pbuf->data_len == 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1944
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1945
	buf = (char *)buffer + pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1946
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1947
	len = pbuf->data_len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1948
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1949
	/* marshall data directly into users buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1950
	ret = (*in->str2ent)(buf, len, in->buf.result, in->buf.buffer,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1951
		in->buf.buflen);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1952
	if (ret == NSS_STR_PARSE_ERANGE) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1953
		in->returnval = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1954
		in->returnlen = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1955
		in->erange    = 1;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1956
	} else if (ret == NSS_STR_PARSE_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1957
		in->returnval = in->buf.result;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1958
		in->returnlen =  len;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1959
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1960
	in->h_errno = (int)pbuf->p_herrno;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1961
	return ((nss_status_t)ret);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1962
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1963
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1964
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1965
 * Start of _nsc_{search|setent_u|getent_u|endent_u} NSCD interposition funcs
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1966
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1967
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1968
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1969
_nsc_search(nss_db_root_t *rootp, nss_db_initf_t initf, int search_fnum,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1970
	void *search_args)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1971
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1972
	nss_pheader_t		*pbuf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1973
	void			*doorptr = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1974
	size_t			bufsize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1975
	size_t			datasize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1976
	nss_status_t		status;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1977
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1978
	if (_nsc_proc_is_cache() > 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1979
		/* internal nscd call - don't use the door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1980
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1981
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1982
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1983
	/* standard client calls nscd code */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1984
	if (search_args == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1985
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1986
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1987
	/* get the door buffer  & configured size */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1988
	bufsize = ((nss_XbyY_args_t *)search_args)->buf.buflen;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1989
	if (_nsc_getdoorbuf(&doorptr, &bufsize) != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1990
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1991
	if (doorptr == NULL || bufsize == 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1992
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1993
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1994
	pbuf = (nss_pheader_t *)doorptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1995
	/* pack argument and request into door buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1996
	pbuf->nsc_callnumber = NSCD_SEARCH;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1997
	/* copy relevant door request info into door buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1998
	status = nss_pack((void *)pbuf, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  1999
			initf, search_fnum, search_args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2000
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2001
	/* Packing error return error results */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2002
	if (status != NSS_SUCCESS)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2003
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2004
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2005
	/* transfer packed switch request to nscd via door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2006
	/* data_off can be used because it is header+dbd_len+key_len */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2007
	datasize = pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2008
	status = _nsc_trydoorcall_ext(&doorptr, &bufsize, &datasize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2009
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2010
	/* If unsuccessful fallback to standard nss logic */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2011
	if (status != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2012
		/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2013
		 * check if doors reallocated the memory underneath us
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2014
		 * if they did munmap it or suffer a memory leak
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2015
		 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2016
		if (doorptr != (void *)pbuf) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2017
			_nsc_resizedoorbuf(bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2018
			munmap((void *)doorptr, bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2019
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2020
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2021
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2022
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2023
	/* unpack and marshall data/errors to user structure */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2024
	/* set any error conditions */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2025
	status = nss_unpack((void *)doorptr, bufsize, rootp, initf,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2026
			search_fnum, search_args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2027
	/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2028
	 * check if doors reallocated the memory underneath us
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2029
	 * if they did munmap it or suffer a memory leak
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2030
	 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2031
	if (doorptr != (void *)pbuf) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2032
		_nsc_resizedoorbuf(bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2033
		munmap((void *)doorptr, bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2034
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2035
	return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2036
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2037
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2038
/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2039
 * contact nscd for a cookie or to reset an existing cookie
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2040
 * if nscd fails (NSS_TRYLOCAL) then set cookie to -1 and
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2041
 * continue diverting to local
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2042
 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2043
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2044
_nsc_setent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2045
	nss_getent_t *contextpp)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2046
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2047
	nss_status_t		status = NSS_TRYLOCAL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2048
	struct nss_getent_context *contextp = contextpp->ctx;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2049
	nss_pheader_t		*pbuf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2050
	void			*doorptr = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2051
	size_t			bufsize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2052
	size_t			datasize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2053
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2054
	/* return if already in local mode */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2055
	if (contextp->cookie == NSCD_LOCAL_COOKIE)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2056
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2057
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2058
	if (_nsc_proc_is_cache() > 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2059
		/* internal nscd call - don't try to use the door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2060
		contextp->cookie = NSCD_LOCAL_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2061
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2062
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2063
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2064
	/* get the door buffer & configured size */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2065
	if (_nsc_getdoorbuf(&doorptr, &bufsize) != 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2066
		contextp->cookie = NSCD_LOCAL_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2067
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2068
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2069
	if (doorptr == NULL || bufsize == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2070
		contextp->cookie = NSCD_LOCAL_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2071
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2072
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2073
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2074
	pbuf = (nss_pheader_t *)doorptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2075
	pbuf->nsc_callnumber = NSCD_SETENT;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2076
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2077
	contextp->param.cleanup = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2078
	(*initf)(&contextp->param);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2079
	if (contextp->param.name == 0) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2080
		if (contextp->param.cleanup != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2081
			(contextp->param.cleanup)(&contextp->param);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2082
		errno = ERANGE;			/* actually EINVAL */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2083
		return (NSS_ERROR);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2084
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2085
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2086
	/* pack relevant setent request info into door buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2087
	status = nss_pack_ent((void *)pbuf, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2088
			initf, contextpp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2089
	if (status != NSS_SUCCESS)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2090
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2091
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2092
	/* transfer packed switch request to nscd via door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2093
	/* data_off can be used because it is header+dbd_len+key_len */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2094
	datasize = pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2095
	status = _nsc_trydoorcall_ext(&doorptr, &bufsize, &datasize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2096
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2097
	/* If fallback to standard nss logic (door failure) if possible */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2098
	if (status != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2099
		if (contextp->cookie == NSCD_NEW_COOKIE) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2100
			contextp->cookie = NSCD_LOCAL_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2101
			return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2102
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2103
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2104
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2105
	/* unpack returned cookie stash it away */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2106
	status = nss_unpack_ent((void *)doorptr, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2107
			initf, contextpp, NULL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2108
	/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2109
	 * check if doors reallocated the memory underneath us
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2110
	 * if they did munmap it or suffer a memory leak
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2111
	 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2112
	if (doorptr != (void *)pbuf) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2113
		_nsc_resizedoorbuf(bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2114
		munmap((void *)doorptr, bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2115
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2116
	return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2117
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2118
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2119
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2120
_nsc_getent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2121
	nss_getent_t *contextpp, void *args)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2122
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2123
	nss_status_t		status = NSS_TRYLOCAL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2124
	struct nss_getent_context *contextp = contextpp->ctx;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2125
	nss_pheader_t		*pbuf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2126
	void			*doorptr = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2127
	size_t			bufsize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2128
	size_t			datasize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2129
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2130
	/* return if already in local mode */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2131
	if (contextp->cookie == NSCD_LOCAL_COOKIE)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2132
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2133
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2134
	/* _nsc_setent_u already checked for nscd local case ... proceed */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2135
	if (args == NULL)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2136
		return (NSS_NOTFOUND);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2137
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2138
	/* get the door buffer  & configured size */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2139
	bufsize = ((nss_XbyY_args_t *)args)->buf.buflen;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2140
	if (_nsc_getdoorbuf(&doorptr, &bufsize) != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2141
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2142
	if (doorptr == NULL || bufsize == 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2143
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2144
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2145
	pbuf = (nss_pheader_t *)doorptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2146
	pbuf->nsc_callnumber = NSCD_GETENT;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2147
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2148
	/* pack relevant setent request info into door buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2149
	status = nss_pack_ent((void *)pbuf, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2150
			initf, contextpp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2151
	if (status != NSS_SUCCESS)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2152
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2153
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2154
	/* transfer packed switch request to nscd via door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2155
	/* data_off can be used because it is header+dbd_len+key_len */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2156
	datasize = pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2157
	status = _nsc_trydoorcall_ext(&doorptr, &bufsize, &datasize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2158
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2159
	/* If fallback to standard nss logic (door failure) if possible */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2160
	if (status != NSS_SUCCESS) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2161
		if (contextp->cookie == NSCD_NEW_COOKIE) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2162
			contextp->cookie = NSCD_LOCAL_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2163
			return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2164
		}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2165
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2166
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2167
	/* check error, unpack and process results */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2168
	status = nss_unpack_ent((void *)doorptr, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2169
			initf, contextpp, args);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2170
	/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2171
	 * check if doors reallocated the memory underneath us
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2172
	 * if they did munmap it or suffer a memory leak
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2173
	 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2174
	if (doorptr != (void *)pbuf) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2175
		_nsc_resizedoorbuf(bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2176
		munmap((void *)doorptr, bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2177
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2178
	return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2179
}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2180
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2181
nss_status_t
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2182
_nsc_endent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2183
	nss_getent_t *contextpp)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2184
{
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2185
	nss_status_t		status = NSS_TRYLOCAL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2186
	struct nss_getent_context *contextp = contextpp->ctx;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2187
	nss_pheader_t		*pbuf;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2188
	void			*doorptr = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2189
	size_t			bufsize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2190
	size_t			datasize = 0;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2191
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2192
	/* return if already in local mode */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2193
	if (contextp->cookie == NSCD_LOCAL_COOKIE)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2194
		return (NSS_TRYLOCAL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2195
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2196
	/* _nsc_setent_u already checked for nscd local case ... proceed */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2197
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2198
	/* get the door buffer  & configured size */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2199
	if (_nsc_getdoorbuf(&doorptr, &bufsize) != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2200
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2201
	if (doorptr == NULL || bufsize == 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2202
		return (NSS_UNAVAIL);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2203
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2204
	/* pack up a NSCD_ENDGET request passing in the cookie */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2205
	pbuf = (nss_pheader_t *)doorptr;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2206
	pbuf->nsc_callnumber = NSCD_ENDENT;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2207
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2208
	/* pack relevant setent request info into door buffer */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2209
	status = nss_pack_ent((void *)pbuf, bufsize, rootp,
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2210
			initf, contextpp);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2211
	if (status != NSS_SUCCESS)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2212
		return (status);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2213
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2214
	/* transfer packed switch request to nscd via door */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2215
	/* data_off can be used because it is header+dbd_len+key_len */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2216
	datasize = pbuf->data_off;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2217
	(void) _nsc_trydoorcall_ext(&doorptr, &bufsize, &datasize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2218
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2219
	/* error codes & unpacking ret values don't matter.  We're done */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2220
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2221
	/*
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2222
	 * check if doors reallocated the memory underneath us
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2223
	 * if they did munmap it or suffer a memory leak
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2224
	 */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2225
	if (doorptr != (void *)pbuf) {
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2226
		_nsc_resizedoorbuf(bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2227
		munmap((void *)doorptr, bufsize);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2228
	}
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2229
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2230
	/* clean up initf setup */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2231
	if (contextp->param.cleanup != 0)
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2232
		(contextp->param.cleanup)(&contextp->param);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2233
	contextp->param.cleanup = NULL;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2234
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2235
	/* clear cookie */
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2236
	contextp->cookie = NSCD_NEW_COOKIE;
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2237
	return (NSS_SUCCESS);
5228d1267a01 PSARC 2005/133 Sparks: Name Service Switch 2
djl
parents: 1914
diff changeset
  2238
}