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