1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1992-1999 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * 29*7c478bd9Sstevel@tonic-gate * NOTE: The interfaces documented in this file may change in a minor 30*7c478bd9Sstevel@tonic-gate * release. It is intended that in the future a stronger committment 31*7c478bd9Sstevel@tonic-gate * will be made to these interface definitions which will guarantee 32*7c478bd9Sstevel@tonic-gate * them across minor releases. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifndef _NSS_COMMON_H 36*7c478bd9Sstevel@tonic-gate #define _NSS_COMMON_H 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include <synch.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 43*7c478bd9Sstevel@tonic-gate extern "C" { 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* 47*7c478bd9Sstevel@tonic-gate * The name-service switch 48*7c478bd9Sstevel@tonic-gate * ----------------------- 49*7c478bd9Sstevel@tonic-gate * 50*7c478bd9Sstevel@tonic-gate * From nsswitch.conf(4): 51*7c478bd9Sstevel@tonic-gate * 52*7c478bd9Sstevel@tonic-gate * The operating system uses a number of ``databases'' of information 53*7c478bd9Sstevel@tonic-gate * about hosts, users (passwd/shadow), groups and so forth. Data for 54*7c478bd9Sstevel@tonic-gate * these can come from a variety of ``sources'': host-names and 55*7c478bd9Sstevel@tonic-gate * -addresses, for example, may be found in /etc/hosts, NIS, NIS+ or 56*7c478bd9Sstevel@tonic-gate * DNS. One or more sources may be used for each database; the 57*7c478bd9Sstevel@tonic-gate * sources and their lookup order are specified in the 58*7c478bd9Sstevel@tonic-gate * /etc/nsswitch.conf file. 59*7c478bd9Sstevel@tonic-gate * 60*7c478bd9Sstevel@tonic-gate * The implementation of this consists of: 61*7c478bd9Sstevel@tonic-gate * 62*7c478bd9Sstevel@tonic-gate * - a ``frontend'' for each database, which provides a programming 63*7c478bd9Sstevel@tonic-gate * interface for that database [for example, the "passwd" frontend 64*7c478bd9Sstevel@tonic-gate * consists of getpwnam_r(), getpwuid_r(), getpwent_r(), setpwent(), 65*7c478bd9Sstevel@tonic-gate * endpwent(), and the old MT-unsafe routines getpwnam() and getpwuid()] 66*7c478bd9Sstevel@tonic-gate * and is implemented by calls to... 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * - the common core of the switch (``switch engine''); it determines 69*7c478bd9Sstevel@tonic-gate * which sources to use and invokes... 70*7c478bd9Sstevel@tonic-gate * 71*7c478bd9Sstevel@tonic-gate * - A ``backend'' for each useful <database, source> pair. Each backend 72*7c478bd9Sstevel@tonic-gate * consists of whatever private data it needs and a set of functions 73*7c478bd9Sstevel@tonic-gate * that the switch engine may invoke on behalf of the frontend 74*7c478bd9Sstevel@tonic-gate * [e.g. the "nis" backend for "passwd" provides routines to lookup 75*7c478bd9Sstevel@tonic-gate * by name and by uid, as well as set/get/end iterator routines]. 76*7c478bd9Sstevel@tonic-gate * The set of functions, and their expected arguments and results, 77*7c478bd9Sstevel@tonic-gate * constitutes a (database-specific) interface between a frontend and 78*7c478bd9Sstevel@tonic-gate * all its backends. The switch engine knows as little as possible 79*7c478bd9Sstevel@tonic-gate * about these interfaces. 80*7c478bd9Sstevel@tonic-gate * 81*7c478bd9Sstevel@tonic-gate * (The term ``backend'' is used ambiguously; it may also refer to a 82*7c478bd9Sstevel@tonic-gate * particular instantiation of a backend, or to the set of all backends 83*7c478bd9Sstevel@tonic-gate * for a particular source, e.g. "the nis backend"). 84*7c478bd9Sstevel@tonic-gate * 85*7c478bd9Sstevel@tonic-gate * This header file defines the interface between the switch engine and the 86*7c478bd9Sstevel@tonic-gate * frontends and backends. Interfaces between specific frontends and 87*7c478bd9Sstevel@tonic-gate * backends are defined elsewhere; many are in <nss_dbdefs.h>. 88*7c478bd9Sstevel@tonic-gate * 89*7c478bd9Sstevel@tonic-gate * 90*7c478bd9Sstevel@tonic-gate * Switch-engine outline 91*7c478bd9Sstevel@tonic-gate * --------------------- 92*7c478bd9Sstevel@tonic-gate * 93*7c478bd9Sstevel@tonic-gate * Frontends may call the following routines in the switch engine: 94*7c478bd9Sstevel@tonic-gate * 95*7c478bd9Sstevel@tonic-gate * nss_search() does getXXXbyYYY, e.g. getpwnam_r(), getpwuid_r() 96*7c478bd9Sstevel@tonic-gate * nss_getent() does getXXXent, e.g. getpwent_r() 97*7c478bd9Sstevel@tonic-gate * nss_setent() does setXXXent, e.g. setpwent() 98*7c478bd9Sstevel@tonic-gate * nss_endent() does endXXXent, e.g. endpwent() 99*7c478bd9Sstevel@tonic-gate * nss_delete() releases resources, in the style of endpwent(). 100*7c478bd9Sstevel@tonic-gate * 101*7c478bd9Sstevel@tonic-gate * A getpwnam_r() call might proceed thus (with many details omitted): 102*7c478bd9Sstevel@tonic-gate * 103*7c478bd9Sstevel@tonic-gate * (1) getpwnam_r fills in (getpwnam-specific) argument/result struct, 104*7c478bd9Sstevel@tonic-gate * calls nss_search(), 105*7c478bd9Sstevel@tonic-gate * (2) nss_search looks up configuration info, gets "passwd: files nis", 106*7c478bd9Sstevel@tonic-gate * (3) nss_search decides to try first source ("files"), 107*7c478bd9Sstevel@tonic-gate * (a) nss_search locates code for <"passwd", "files"> backend, 108*7c478bd9Sstevel@tonic-gate * (b) nss_search creates instance of backend, 109*7c478bd9Sstevel@tonic-gate * (c) nss_search calls get-by-name routine in backend, 110*7c478bd9Sstevel@tonic-gate * (d) backend searches /etc/passwd, doesn't find the name, 111*7c478bd9Sstevel@tonic-gate * returns "not found" status to nss_search, 112*7c478bd9Sstevel@tonic-gate * (4) nss_search examines status and config info, decides to try 113*7c478bd9Sstevel@tonic-gate * next source ("nis"), 114*7c478bd9Sstevel@tonic-gate * (a) nss_search locates code for <"passwd", "nis"> backend, 115*7c478bd9Sstevel@tonic-gate * (b) nss_search creates instance of backend, 116*7c478bd9Sstevel@tonic-gate * (c) nss_search calls get-by-name routine in backend, 117*7c478bd9Sstevel@tonic-gate * (d) backend searches passwd.byname, finds the desired entry, 118*7c478bd9Sstevel@tonic-gate * fills in the result part of the getpwnam-specific 119*7c478bd9Sstevel@tonic-gate * struct, returns "success" status to nss_search, 120*7c478bd9Sstevel@tonic-gate * (5) nss_search examines status and config info, decides to return 121*7c478bd9Sstevel@tonic-gate * to caller, 122*7c478bd9Sstevel@tonic-gate * (6) getpwnam_r extracts result from getpwnam-specific struct, 123*7c478bd9Sstevel@tonic-gate * returns to caller. 124*7c478bd9Sstevel@tonic-gate * 125*7c478bd9Sstevel@tonic-gate * 126*7c478bd9Sstevel@tonic-gate * Data structures 127*7c478bd9Sstevel@tonic-gate * --------------- 128*7c478bd9Sstevel@tonic-gate * 129*7c478bd9Sstevel@tonic-gate * Both databases and sources are represented by case-sensitive strings 130*7c478bd9Sstevel@tonic-gate * (the same strings that appear in the configuration file). 131*7c478bd9Sstevel@tonic-gate * 132*7c478bd9Sstevel@tonic-gate * The switch engine maintains a per-frontend data structure so that the 133*7c478bd9Sstevel@tonic-gate * results of steps (2), (a) and (b) can be cached. The frontend holds a 134*7c478bd9Sstevel@tonic-gate * handle (nss_db_root_t) to this structure and passes it in to the 135*7c478bd9Sstevel@tonic-gate * nss_*() routines. 136*7c478bd9Sstevel@tonic-gate * 137*7c478bd9Sstevel@tonic-gate * The nss_setent(), nss_getent() and nss_endent() routines introduce another 138*7c478bd9Sstevel@tonic-gate * variety of state (the current position in the enumeration process). 139*7c478bd9Sstevel@tonic-gate * Within a single source, this information is maintained by private data 140*7c478bd9Sstevel@tonic-gate * in the backend instance -- but, in the presence of multiple sources, the 141*7c478bd9Sstevel@tonic-gate * switch engine must keep track of the current backend instance [e.g either 142*7c478bd9Sstevel@tonic-gate * <"passwd", "files"> or <"passwd", "nis"> instances]. The switch engine 143*7c478bd9Sstevel@tonic-gate * has a separate per-enumeration data structure for this; again, the 144*7c478bd9Sstevel@tonic-gate * frontend holds a handle (nss_getent_t) and passes it in, along with the 145*7c478bd9Sstevel@tonic-gate * nss_db_root_t handle, to nss_setent(), nss_getent() and nss_endent(). 146*7c478bd9Sstevel@tonic-gate * 147*7c478bd9Sstevel@tonic-gate * 148*7c478bd9Sstevel@tonic-gate * Multithreading 149*7c478bd9Sstevel@tonic-gate * -------------- 150*7c478bd9Sstevel@tonic-gate * 151*7c478bd9Sstevel@tonic-gate * The switch engine takes care of locking; frontends should be written to 152*7c478bd9Sstevel@tonic-gate * be reentrant, and a backend instance may assume that all calls to it are 153*7c478bd9Sstevel@tonic-gate * serialized. 154*7c478bd9Sstevel@tonic-gate * 155*7c478bd9Sstevel@tonic-gate * If multiple threads simultaneously want to use a particular backend, the 156*7c478bd9Sstevel@tonic-gate * switch engine creates multiple backend instances (up to some limit 157*7c478bd9Sstevel@tonic-gate * specified by the frontend). Backends must of course lock any state that 158*7c478bd9Sstevel@tonic-gate * is shared between instances, and must serialize calls to any MT-unsafe 159*7c478bd9Sstevel@tonic-gate * code. 160*7c478bd9Sstevel@tonic-gate * 161*7c478bd9Sstevel@tonic-gate * The switch engine has no notion of per-thread state. 162*7c478bd9Sstevel@tonic-gate * 163*7c478bd9Sstevel@tonic-gate * Frontends can use the nss_getent_t handle to define the scope of the 164*7c478bd9Sstevel@tonic-gate * enumeration (set/get/endXXXent) state: a static handle gives global state 165*7c478bd9Sstevel@tonic-gate * (which is what Posix has specified for the getXXXent_r routines), handles 166*7c478bd9Sstevel@tonic-gate * in Thread-Specific Data give per-thread state, and handles on the stack 167*7c478bd9Sstevel@tonic-gate * give per-invocation state. 168*7c478bd9Sstevel@tonic-gate */ 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate /* 172*7c478bd9Sstevel@tonic-gate * Backend instances 173*7c478bd9Sstevel@tonic-gate * ----------------- 174*7c478bd9Sstevel@tonic-gate * 175*7c478bd9Sstevel@tonic-gate * As far as the switch engine is concerned, an instance of a backend is a 176*7c478bd9Sstevel@tonic-gate * struct whose first two members are: 177*7c478bd9Sstevel@tonic-gate * - A pointer to a vector of function pointers, one for each 178*7c478bd9Sstevel@tonic-gate * database-specific function, 179*7c478bd9Sstevel@tonic-gate * - The length of the vector (an int), used for bounds-checking. 180*7c478bd9Sstevel@tonic-gate * There are four well-known function slots in the vector: 181*7c478bd9Sstevel@tonic-gate * [0] is a destructor for the backend instance, 182*7c478bd9Sstevel@tonic-gate * [1] is the endXXXent routine, 183*7c478bd9Sstevel@tonic-gate * [2] is the setXXXent routine, 184*7c478bd9Sstevel@tonic-gate * [3] is the getXXXent routine. 185*7c478bd9Sstevel@tonic-gate * Any other slots are database-specific getXXXbyYYY routines; the frontend 186*7c478bd9Sstevel@tonic-gate * specifies a slot-number to nss_search(). 187*7c478bd9Sstevel@tonic-gate * 188*7c478bd9Sstevel@tonic-gate * The functions take two arguments: 189*7c478bd9Sstevel@tonic-gate * - a pointer to the backend instance (like a C++ "this" pointer) 190*7c478bd9Sstevel@tonic-gate * - a single (void *) pointer to the database-specific argument/result 191*7c478bd9Sstevel@tonic-gate * structure (the contents are opaque to the switch engine). 192*7c478bd9Sstevel@tonic-gate * The four well-known functions ignore the (void *) pointer. 193*7c478bd9Sstevel@tonic-gate * 194*7c478bd9Sstevel@tonic-gate * Backend routines return one of five status codes to the switch engine: 195*7c478bd9Sstevel@tonic-gate * SUCCESS, UNAVAIL, NOTFOUND, TRYAGAIN (these are the same codes that may 196*7c478bd9Sstevel@tonic-gate * be specified in the config information; see nsswitch.conf(4)), or 197*7c478bd9Sstevel@tonic-gate * NSS_NISSERVDNS_TRYAGAIN (should only be used by the NIS backend for 198*7c478bd9Sstevel@tonic-gate * NIS server in DNS forwarding mode to indicate DNS server non-response). 199*7c478bd9Sstevel@tonic-gate */ 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate typedef enum { 202*7c478bd9Sstevel@tonic-gate NSS_SUCCESS, 203*7c478bd9Sstevel@tonic-gate NSS_NOTFOUND, 204*7c478bd9Sstevel@tonic-gate NSS_UNAVAIL, 205*7c478bd9Sstevel@tonic-gate NSS_TRYAGAIN, 206*7c478bd9Sstevel@tonic-gate NSS_NISSERVDNS_TRYAGAIN 207*7c478bd9Sstevel@tonic-gate } nss_status_t; 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate struct nss_backend; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 212*7c478bd9Sstevel@tonic-gate typedef nss_status_t (*nss_backend_op_t)(struct nss_backend *, void *args); 213*7c478bd9Sstevel@tonic-gate #else 214*7c478bd9Sstevel@tonic-gate typedef nss_status_t (*nss_backend_op_t)(); 215*7c478bd9Sstevel@tonic-gate #endif 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate struct nss_backend { 218*7c478bd9Sstevel@tonic-gate nss_backend_op_t *ops; 219*7c478bd9Sstevel@tonic-gate int n_ops; 220*7c478bd9Sstevel@tonic-gate }; 221*7c478bd9Sstevel@tonic-gate typedef struct nss_backend nss_backend_t; 222*7c478bd9Sstevel@tonic-gate typedef int nss_dbop_t; 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_DESTRUCTOR 0 225*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_ENDENT 1 226*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_SETENT 2 227*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_GETENT 3 228*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_next_iter (NSS_DBOP_GETENT + 1) 229*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_next_noiter (NSS_DBOP_DESTRUCTOR + 1) 230*7c478bd9Sstevel@tonic-gate #define NSS_DBOP_next_ipv6_iter (NSS_DBOP_GETENT + 3) 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate #define NSS_LOOKUP_DBOP(instp, n) \ 233*7c478bd9Sstevel@tonic-gate (((n) >= 0 && (n) < (instp)->n_ops) ? (instp)->ops[n] : 0) 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate #define NSS_INVOKE_DBOP(instp, n, argp) (\ 236*7c478bd9Sstevel@tonic-gate ((n) >= 0 && (n) < (instp)->n_ops && (instp)->ops[n] != 0) \ 237*7c478bd9Sstevel@tonic-gate ? (*(instp)->ops[n])(instp, argp) \ 238*7c478bd9Sstevel@tonic-gate : NSS_UNAVAIL) 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * Locating and instantiating backends 242*7c478bd9Sstevel@tonic-gate * ----------------------------------- 243*7c478bd9Sstevel@tonic-gate * 244*7c478bd9Sstevel@tonic-gate * To perform step (a), the switch consults a list of backend-finder routines, 245*7c478bd9Sstevel@tonic-gate * passing a <database, source> pair. 246*7c478bd9Sstevel@tonic-gate * 247*7c478bd9Sstevel@tonic-gate * There is a standard backend-finder; frontends may augment or replace this 248*7c478bd9Sstevel@tonic-gate * in order to, say, indicate that some backends are "compiled in" with the 249*7c478bd9Sstevel@tonic-gate * frontend. 250*7c478bd9Sstevel@tonic-gate * 251*7c478bd9Sstevel@tonic-gate * Backend-finders return a pointer to a constructor function for the backend. 252*7c478bd9Sstevel@tonic-gate * (or NULL if they can't find the backend). The switch engine caches these 253*7c478bd9Sstevel@tonic-gate * function pointers; when it needs to perform step (b), it calls the 254*7c478bd9Sstevel@tonic-gate * constructor function, which returns a pointer to a new instance of the 255*7c478bd9Sstevel@tonic-gate * backend, properly initialized (or returns NULL). 256*7c478bd9Sstevel@tonic-gate */ 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 259*7c478bd9Sstevel@tonic-gate typedef nss_backend_t * (*nss_backend_constr_t)(const char *db_name, 260*7c478bd9Sstevel@tonic-gate const char *src_name, 261*7c478bd9Sstevel@tonic-gate /* Hook for (unimplemented) args in nsswitch.conf */ const char *cfg_args); 262*7c478bd9Sstevel@tonic-gate #else 263*7c478bd9Sstevel@tonic-gate typedef nss_backend_t * (*nss_backend_constr_t)(); 264*7c478bd9Sstevel@tonic-gate #endif 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate struct nss_backend_finder { 267*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 268*7c478bd9Sstevel@tonic-gate nss_backend_constr_t (*lookup) 269*7c478bd9Sstevel@tonic-gate (void *lkp_priv, const char *, const char *, void **del_privp); 270*7c478bd9Sstevel@tonic-gate void (*delete) 271*7c478bd9Sstevel@tonic-gate (void *del_priv, nss_backend_constr_t); 272*7c478bd9Sstevel@tonic-gate #else 273*7c478bd9Sstevel@tonic-gate nss_backend_constr_t (*lookup)(); 274*7c478bd9Sstevel@tonic-gate void (*delete)(); 275*7c478bd9Sstevel@tonic-gate #endif 276*7c478bd9Sstevel@tonic-gate struct nss_backend_finder *next; 277*7c478bd9Sstevel@tonic-gate void *lookup_priv; 278*7c478bd9Sstevel@tonic-gate }; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate typedef struct nss_backend_finder nss_backend_finder_t; 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate extern nss_backend_finder_t *nss_default_finders; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate /* 285*7c478bd9Sstevel@tonic-gate * Frontend parameters 286*7c478bd9Sstevel@tonic-gate * ------------------- 287*7c478bd9Sstevel@tonic-gate * 288*7c478bd9Sstevel@tonic-gate * The frontend must tell the switch engine: 289*7c478bd9Sstevel@tonic-gate * - the database name, 290*7c478bd9Sstevel@tonic-gate * - the compiled-in default configuration entry. 291*7c478bd9Sstevel@tonic-gate * It may also override default values for: 292*7c478bd9Sstevel@tonic-gate * - the database name to use when looking up the configuration 293*7c478bd9Sstevel@tonic-gate * information (e.g. "shadow" uses the config entry for "passwd"), 294*7c478bd9Sstevel@tonic-gate * - a limit on the number of instances of each backend that are 295*7c478bd9Sstevel@tonic-gate * simultaneously active, 296*7c478bd9Sstevel@tonic-gate * - a limit on the number of instances of each backend that are 297*7c478bd9Sstevel@tonic-gate * simultaneously dormant (waiting for new requests), 298*7c478bd9Sstevel@tonic-gate * - a flag that tells the switch engine to use the default configuration 299*7c478bd9Sstevel@tonic-gate * entry and ignore any other config entry for this database, 300*7c478bd9Sstevel@tonic-gate * - backend-finders (see above) 301*7c478bd9Sstevel@tonic-gate * - a cleanup routine that should be called when these parameters are 302*7c478bd9Sstevel@tonic-gate * about to be deleted. 303*7c478bd9Sstevel@tonic-gate * 304*7c478bd9Sstevel@tonic-gate * In order to do this, the frontend includes a pointer to an initialization 305*7c478bd9Sstevel@tonic-gate * function (nss_db_initf_t) in every nss_*() call. When necessary (normally 306*7c478bd9Sstevel@tonic-gate * just on the first invocation), the switch engine allocates a parameter 307*7c478bd9Sstevel@tonic-gate * structure (nss_db_params_t), fills in the default values, then calls 308*7c478bd9Sstevel@tonic-gate * the initialization function, which should update the parameter structure 309*7c478bd9Sstevel@tonic-gate * as necessary. 310*7c478bd9Sstevel@tonic-gate * 311*7c478bd9Sstevel@tonic-gate * (This might look more natural if we put nss_db_initf_t in nss_db_root_t, 312*7c478bd9Sstevel@tonic-gate * or abolished nss_db_initf_t and put nss_db_params_t in nss_db_root_t. 313*7c478bd9Sstevel@tonic-gate * It's done the way it is for shared-library efficiency, namely: 314*7c478bd9Sstevel@tonic-gate * - keep the unshared data (nss_db_root_t) to a minimum, 315*7c478bd9Sstevel@tonic-gate * - keep the symbol lookups and relocations to a minimum. 316*7c478bd9Sstevel@tonic-gate * In particular this means that non-null pointers, e.g. strings and 317*7c478bd9Sstevel@tonic-gate * function pointers, in global data are a bad thing). 318*7c478bd9Sstevel@tonic-gate */ 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate enum nss_dbp_flags { 321*7c478bd9Sstevel@tonic-gate NSS_USE_DEFAULT_CONFIG = 0x1 322*7c478bd9Sstevel@tonic-gate }; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate struct nss_db_params { 325*7c478bd9Sstevel@tonic-gate const char *name; /* Mandatory: database name */ 326*7c478bd9Sstevel@tonic-gate const char *config_name; /* config-file database name */ 327*7c478bd9Sstevel@tonic-gate const char *default_config; /* Mandatory: default config */ 328*7c478bd9Sstevel@tonic-gate unsigned max_active_per_src; 329*7c478bd9Sstevel@tonic-gate unsigned max_dormant_per_src; 330*7c478bd9Sstevel@tonic-gate enum nss_dbp_flags flags; 331*7c478bd9Sstevel@tonic-gate nss_backend_finder_t *finders; 332*7c478bd9Sstevel@tonic-gate void *private; /* Not used by switch */ 333*7c478bd9Sstevel@tonic-gate void (*cleanup)(struct nss_db_params *); 334*7c478bd9Sstevel@tonic-gate }; 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate typedef struct nss_db_params nss_db_params_t; 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 339*7c478bd9Sstevel@tonic-gate typedef void (*nss_db_initf_t)(nss_db_params_t *); 340*7c478bd9Sstevel@tonic-gate #else 341*7c478bd9Sstevel@tonic-gate typedef void (*nss_db_initf_t)(); 342*7c478bd9Sstevel@tonic-gate #endif 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate /* 345*7c478bd9Sstevel@tonic-gate * These structures are defined inside the implementation of the switch 346*7c478bd9Sstevel@tonic-gate * engine; the interface just holds pointers to them. 347*7c478bd9Sstevel@tonic-gate */ 348*7c478bd9Sstevel@tonic-gate struct nss_db_state; 349*7c478bd9Sstevel@tonic-gate struct nss_getent_context; 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * Finally, the two handles that frontends hold: 353*7c478bd9Sstevel@tonic-gate */ 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate struct nss_db_root { 356*7c478bd9Sstevel@tonic-gate struct nss_db_state *s; 357*7c478bd9Sstevel@tonic-gate mutex_t lock; 358*7c478bd9Sstevel@tonic-gate }; 359*7c478bd9Sstevel@tonic-gate typedef struct nss_db_root nss_db_root_t; 360*7c478bd9Sstevel@tonic-gate #define NSS_DB_ROOT_INIT { 0, DEFAULTMUTEX } 361*7c478bd9Sstevel@tonic-gate #define DEFINE_NSS_DB_ROOT(name) nss_db_root_t name = NSS_DB_ROOT_INIT 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate 364*7c478bd9Sstevel@tonic-gate typedef struct { 365*7c478bd9Sstevel@tonic-gate struct nss_getent_context *ctx; 366*7c478bd9Sstevel@tonic-gate mutex_t lock; 367*7c478bd9Sstevel@tonic-gate } nss_getent_t; 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate #define NSS_GETENT_INIT { 0, DEFAULTMUTEX } 370*7c478bd9Sstevel@tonic-gate #define DEFINE_NSS_GETENT(name) nss_getent_t name = NSS_GETENT_INIT 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 373*7c478bd9Sstevel@tonic-gate extern nss_status_t nss_search(nss_db_root_t *, nss_db_initf_t, 374*7c478bd9Sstevel@tonic-gate int search_fnum, void *search_args); 375*7c478bd9Sstevel@tonic-gate extern nss_status_t nss_getent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *, 376*7c478bd9Sstevel@tonic-gate void *getent_args); 377*7c478bd9Sstevel@tonic-gate extern void nss_setent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *); 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate extern void nss_endent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *); 380*7c478bd9Sstevel@tonic-gate /* ^^ superfluous but consistent */ 381*7c478bd9Sstevel@tonic-gate extern void nss_delete(nss_db_root_t *); 382*7c478bd9Sstevel@tonic-gate #else 383*7c478bd9Sstevel@tonic-gate extern nss_status_t nss_search(); 384*7c478bd9Sstevel@tonic-gate extern nss_status_t nss_getent(); 385*7c478bd9Sstevel@tonic-gate extern void nss_setent(); 386*7c478bd9Sstevel@tonic-gate extern void nss_endent(); 387*7c478bd9Sstevel@tonic-gate extern void nss_delete(); 388*7c478bd9Sstevel@tonic-gate #endif 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 391*7c478bd9Sstevel@tonic-gate } 392*7c478bd9Sstevel@tonic-gate #endif 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate #endif /* _NSS_COMMON_H */ 395