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