1*86d7f5d3SJohn Marino /* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ 2*86d7f5d3SJohn Marino /* $FreeBSD: src/include/nsswitch.h,v 1.5 2007/12/12 10:08:02 bushman Exp $ */ 3*86d7f5d3SJohn Marino 4*86d7f5d3SJohn Marino /*- 5*86d7f5d3SJohn Marino * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 6*86d7f5d3SJohn Marino * All rights reserved. 7*86d7f5d3SJohn Marino * 8*86d7f5d3SJohn Marino * This code is derived from software contributed to The NetBSD Foundation 9*86d7f5d3SJohn Marino * by Luke Mewburn. 10*86d7f5d3SJohn Marino * 11*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 12*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 13*86d7f5d3SJohn Marino * are met: 14*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 15*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 16*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 17*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 18*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 19*86d7f5d3SJohn Marino * 3. All advertising materials mentioning features or use of this software 20*86d7f5d3SJohn Marino * must display the following acknowledgement: 21*86d7f5d3SJohn Marino * This product includes software developed by the NetBSD 22*86d7f5d3SJohn Marino * Foundation, Inc. and its contributors. 23*86d7f5d3SJohn Marino * 4. Neither the name of The NetBSD Foundation nor the names of its 24*86d7f5d3SJohn Marino * contributors may be used to endorse or promote products derived 25*86d7f5d3SJohn Marino * from this software without specific prior written permission. 26*86d7f5d3SJohn Marino * 27*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28*86d7f5d3SJohn Marino * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29*86d7f5d3SJohn Marino * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30*86d7f5d3SJohn Marino * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31*86d7f5d3SJohn Marino * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32*86d7f5d3SJohn Marino * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33*86d7f5d3SJohn Marino * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34*86d7f5d3SJohn Marino * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35*86d7f5d3SJohn Marino * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36*86d7f5d3SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37*86d7f5d3SJohn Marino * POSSIBILITY OF SUCH DAMAGE. 38*86d7f5d3SJohn Marino */ 39*86d7f5d3SJohn Marino 40*86d7f5d3SJohn Marino #ifndef _NSSWITCH_H 41*86d7f5d3SJohn Marino #define _NSSWITCH_H 1 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino #include <sys/types.h> 44*86d7f5d3SJohn Marino #include <stdarg.h> 45*86d7f5d3SJohn Marino 46*86d7f5d3SJohn Marino #define NSS_MODULE_INTERFACE_VERSION 1 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino #ifndef _PATH_NS_CONF 49*86d7f5d3SJohn Marino #define _PATH_NS_CONF "/etc/nsswitch.conf" 50*86d7f5d3SJohn Marino #endif 51*86d7f5d3SJohn Marino 52*86d7f5d3SJohn Marino /* NSS source actions */ 53*86d7f5d3SJohn Marino #define NS_ACTION_CONTINUE 0 /* try the next source */ 54*86d7f5d3SJohn Marino #define NS_ACTION_RETURN 1 /* look no further */ 55*86d7f5d3SJohn Marino 56*86d7f5d3SJohn Marino #define NS_SUCCESS (1<<0) /* entry was found */ 57*86d7f5d3SJohn Marino #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 58*86d7f5d3SJohn Marino #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 59*86d7f5d3SJohn Marino #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ 60*86d7f5d3SJohn Marino #define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ 61*86d7f5d3SJohn Marino #define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ 62*86d7f5d3SJohn Marino #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 63*86d7f5d3SJohn Marino 64*86d7f5d3SJohn Marino /* 65*86d7f5d3SJohn Marino * currently implemented sources 66*86d7f5d3SJohn Marino */ 67*86d7f5d3SJohn Marino #define NSSRC_FILES "files" /* local files */ 68*86d7f5d3SJohn Marino #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 69*86d7f5d3SJohn Marino #define NSSRC_NIS "nis" /* YP/NIS */ 70*86d7f5d3SJohn Marino #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 71*86d7f5d3SJohn Marino #define NSSRC_CACHE "cache" /* nscd daemon */ 72*86d7f5d3SJohn Marino #define NSSRC_FALLBACK "__fallback" /* internal fallback source */ 73*86d7f5d3SJohn Marino 74*86d7f5d3SJohn Marino /* 75*86d7f5d3SJohn Marino * currently implemented databases 76*86d7f5d3SJohn Marino */ 77*86d7f5d3SJohn Marino #define NSDB_HOSTS "hosts" 78*86d7f5d3SJohn Marino #define NSDB_GROUP "group" 79*86d7f5d3SJohn Marino #define NSDB_GROUP_COMPAT "group_compat" 80*86d7f5d3SJohn Marino #define NSDB_NETGROUP "netgroup" 81*86d7f5d3SJohn Marino #define NSDB_NETWORKS "networks" 82*86d7f5d3SJohn Marino #define NSDB_PASSWD "passwd" 83*86d7f5d3SJohn Marino #define NSDB_PASSWD_COMPAT "passwd_compat" 84*86d7f5d3SJohn Marino #define NSDB_SHELLS "shells" 85*86d7f5d3SJohn Marino #define NSDB_SERVICES "services" 86*86d7f5d3SJohn Marino #define NSDB_SERVICES_COMPAT "services_compat" 87*86d7f5d3SJohn Marino #define NSDB_SSH_HOSTKEYS "ssh_hostkeys" 88*86d7f5d3SJohn Marino #define NSDB_PROTOCOLS "protocols" 89*86d7f5d3SJohn Marino #define NSDB_RPC "rpc" 90*86d7f5d3SJohn Marino 91*86d7f5d3SJohn Marino /* 92*86d7f5d3SJohn Marino * suggested databases to implement 93*86d7f5d3SJohn Marino */ 94*86d7f5d3SJohn Marino #define NSDB_ALIASES "aliases" 95*86d7f5d3SJohn Marino #define NSDB_AUTH "auth" 96*86d7f5d3SJohn Marino #define NSDB_AUTOMOUNT "automount" 97*86d7f5d3SJohn Marino #define NSDB_BOOTPARAMS "bootparams" 98*86d7f5d3SJohn Marino #define NSDB_ETHERS "ethers" 99*86d7f5d3SJohn Marino #define NSDB_EXPORTS "exports" 100*86d7f5d3SJohn Marino #define NSDB_NETMASKS "netmasks" 101*86d7f5d3SJohn Marino #define NSDB_PHONES "phones" 102*86d7f5d3SJohn Marino #define NSDB_PRINTCAP "printcap" 103*86d7f5d3SJohn Marino #define NSDB_REMOTE "remote" 104*86d7f5d3SJohn Marino #define NSDB_SENDMAILVARS "sendmailvars" 105*86d7f5d3SJohn Marino #define NSDB_TERMCAP "termcap" 106*86d7f5d3SJohn Marino #define NSDB_TTYS "ttys" 107*86d7f5d3SJohn Marino 108*86d7f5d3SJohn Marino /* 109*86d7f5d3SJohn Marino * ns_dtab `method' function signature. 110*86d7f5d3SJohn Marino */ 111*86d7f5d3SJohn Marino typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); 112*86d7f5d3SJohn Marino 113*86d7f5d3SJohn Marino /* 114*86d7f5d3SJohn Marino * Macro for generating method prototypes. 115*86d7f5d3SJohn Marino */ 116*86d7f5d3SJohn Marino #define NSS_METHOD_PROTOTYPE(method) \ 117*86d7f5d3SJohn Marino int method(void *, void *, va_list) 118*86d7f5d3SJohn Marino 119*86d7f5d3SJohn Marino /* 120*86d7f5d3SJohn Marino * ns_dtab - `nsswitch dispatch table' 121*86d7f5d3SJohn Marino * Contains an entry for each source and the appropriate function to 122*86d7f5d3SJohn Marino * call. ns_dtabs are used in the nsdispatch() API in order to allow 123*86d7f5d3SJohn Marino * the application to override built-in actions. 124*86d7f5d3SJohn Marino */ 125*86d7f5d3SJohn Marino typedef struct _ns_dtab { 126*86d7f5d3SJohn Marino const char *src; /* Source this entry implements */ 127*86d7f5d3SJohn Marino nss_method method; /* Method to be called */ 128*86d7f5d3SJohn Marino void *mdata; /* Data passed to method */ 129*86d7f5d3SJohn Marino } ns_dtab; 130*86d7f5d3SJohn Marino 131*86d7f5d3SJohn Marino /* 132*86d7f5d3SJohn Marino * macros to help build an ns_dtab[] 133*86d7f5d3SJohn Marino */ 134*86d7f5d3SJohn Marino #define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, 135*86d7f5d3SJohn Marino #define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, 136*86d7f5d3SJohn Marino #define NS_FALLBACK_CB(F) { NSSRC_FALLBACK, F, NULL }, 137*86d7f5d3SJohn Marino 138*86d7f5d3SJohn Marino #ifdef HESIOD 139*86d7f5d3SJohn Marino # define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, 140*86d7f5d3SJohn Marino #else 141*86d7f5d3SJohn Marino # define NS_DNS_CB(F,C) 142*86d7f5d3SJohn Marino #endif 143*86d7f5d3SJohn Marino 144*86d7f5d3SJohn Marino #ifdef YP 145*86d7f5d3SJohn Marino # define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, 146*86d7f5d3SJohn Marino #else 147*86d7f5d3SJohn Marino # define NS_NIS_CB(F,C) 148*86d7f5d3SJohn Marino #endif 149*86d7f5d3SJohn Marino 150*86d7f5d3SJohn Marino /* 151*86d7f5d3SJohn Marino * ns_src - `nsswitch source' 152*86d7f5d3SJohn Marino * used by the nsparser routines to store a mapping between a source 153*86d7f5d3SJohn Marino * and its dispatch control flags for a given database. 154*86d7f5d3SJohn Marino */ 155*86d7f5d3SJohn Marino typedef struct _ns_src { 156*86d7f5d3SJohn Marino const char *name; 157*86d7f5d3SJohn Marino u_int32_t flags; 158*86d7f5d3SJohn Marino } ns_src; 159*86d7f5d3SJohn Marino 160*86d7f5d3SJohn Marino 161*86d7f5d3SJohn Marino /* 162*86d7f5d3SJohn Marino * default sourcelist (if nsswitch.conf is missing, corrupt, 163*86d7f5d3SJohn Marino * or the requested database doesn't have an entry. 164*86d7f5d3SJohn Marino */ 165*86d7f5d3SJohn Marino extern const ns_src __nsdefaultsrc[]; 166*86d7f5d3SJohn Marino 167*86d7f5d3SJohn Marino /* 168*86d7f5d3SJohn Marino * ns_mtab - NSS method table 169*86d7f5d3SJohn Marino * An NSS module provides a mapping from (database name, method name) 170*86d7f5d3SJohn Marino * tuples to the nss_method and associated data. 171*86d7f5d3SJohn Marino */ 172*86d7f5d3SJohn Marino typedef struct _ns_mtab { 173*86d7f5d3SJohn Marino const char *database; 174*86d7f5d3SJohn Marino const char *name; 175*86d7f5d3SJohn Marino nss_method method; 176*86d7f5d3SJohn Marino void *mdata; 177*86d7f5d3SJohn Marino } ns_mtab; 178*86d7f5d3SJohn Marino 179*86d7f5d3SJohn Marino /* 180*86d7f5d3SJohn Marino * NSS module de-registration, called at module unload. 181*86d7f5d3SJohn Marino */ 182*86d7f5d3SJohn Marino typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); 183*86d7f5d3SJohn Marino 184*86d7f5d3SJohn Marino /* 185*86d7f5d3SJohn Marino * NSS module registration, called at module load. 186*86d7f5d3SJohn Marino */ 187*86d7f5d3SJohn Marino typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, 188*86d7f5d3SJohn Marino nss_module_unregister_fn *); 189*86d7f5d3SJohn Marino 190*86d7f5d3SJohn Marino /* 191*86d7f5d3SJohn Marino * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. 192*86d7f5d3SJohn Marino * Developers are encouraged to use nss_lookup_type where approriate. 193*86d7f5d3SJohn Marino */ 194*86d7f5d3SJohn Marino enum nss_lookup_type { 195*86d7f5d3SJohn Marino nss_lt_name = 1, 196*86d7f5d3SJohn Marino nss_lt_id = 2, 197*86d7f5d3SJohn Marino nss_lt_all = 3 198*86d7f5d3SJohn Marino }; 199*86d7f5d3SJohn Marino 200*86d7f5d3SJohn Marino #ifdef _NS_PRIVATE 201*86d7f5d3SJohn Marino /* 202*86d7f5d3SJohn Marino * private data structures for back-end nsswitch implementation 203*86d7f5d3SJohn Marino */ 204*86d7f5d3SJohn Marino 205*86d7f5d3SJohn Marino /* 206*86d7f5d3SJohn Marino * ns_dbt - `nsswitch database thang' 207*86d7f5d3SJohn Marino * for each database in /etc/nsswitch.conf there is a ns_dbt, with its 208*86d7f5d3SJohn Marino * name and a list of ns_src's containing the source information. 209*86d7f5d3SJohn Marino */ 210*86d7f5d3SJohn Marino typedef struct _ns_dbt { 211*86d7f5d3SJohn Marino const char *name; /* name of database */ 212*86d7f5d3SJohn Marino ns_src *srclist; /* list of sources */ 213*86d7f5d3SJohn Marino int srclistsize; /* size of srclist */ 214*86d7f5d3SJohn Marino } ns_dbt; 215*86d7f5d3SJohn Marino 216*86d7f5d3SJohn Marino /* 217*86d7f5d3SJohn Marino * ns_mod - NSS module 218*86d7f5d3SJohn Marino */ 219*86d7f5d3SJohn Marino typedef struct _ns_mod { 220*86d7f5d3SJohn Marino char *name; /* module name */ 221*86d7f5d3SJohn Marino void *handle; /* handle from dlopen */ 222*86d7f5d3SJohn Marino ns_mtab *mtab; /* method table */ 223*86d7f5d3SJohn Marino unsigned int mtabsize; /* count of entries in method table */ 224*86d7f5d3SJohn Marino nss_module_unregister_fn unregister; /* called to unload module */ 225*86d7f5d3SJohn Marino } ns_mod; 226*86d7f5d3SJohn Marino 227*86d7f5d3SJohn Marino #endif /* _NS_PRIVATE */ 228*86d7f5d3SJohn Marino 229*86d7f5d3SJohn Marino 230*86d7f5d3SJohn Marino #include <sys/cdefs.h> 231*86d7f5d3SJohn Marino 232*86d7f5d3SJohn Marino __BEGIN_DECLS 233*86d7f5d3SJohn Marino extern int nsdispatch(void *, const ns_dtab [], const char *, 234*86d7f5d3SJohn Marino const char *, const ns_src [], ...); 235*86d7f5d3SJohn Marino 236*86d7f5d3SJohn Marino #ifdef _NS_PRIVATE 237*86d7f5d3SJohn Marino extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); 238*86d7f5d3SJohn Marino extern void _nsdbtput(const ns_dbt *); 239*86d7f5d3SJohn Marino extern void _nsyyerror(const char *); 240*86d7f5d3SJohn Marino extern int _nsyylex(void); 241*86d7f5d3SJohn Marino extern int _nsyyparse(void); 242*86d7f5d3SJohn Marino extern int _nsyylineno; 243*86d7f5d3SJohn Marino #ifdef _NSS_DEBUG 244*86d7f5d3SJohn Marino extern void _nsdbtdump(const ns_dbt *); 245*86d7f5d3SJohn Marino #endif 246*86d7f5d3SJohn Marino #endif /* _NS_PRIVATE */ 247*86d7f5d3SJohn Marino 248*86d7f5d3SJohn Marino __END_DECLS 249*86d7f5d3SJohn Marino 250*86d7f5d3SJohn Marino #endif /* !_NSSWITCH_H */ 251