1 /* $NetBSD: nsswitch.h,v 1.18 2005/11/29 03:12:58 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998, 1999, 2004 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 #include <sys/types.h> 43 #include <stdarg.h> 44 45 #define NSS_MODULE_INTERFACE_VERSION 0 46 47 #ifndef _PATH_NS_CONF 48 #define _PATH_NS_CONF "/etc/nsswitch.conf" 49 #endif 50 51 #define NS_CONTINUE 0 52 #define NS_RETURN 1 53 54 /* 55 * Layout of: 56 * uint32_t ns_src.flags 57 */ 58 /* nsswitch.conf status codes and nsdispatch(3) return values */ 59 #define NS_SUCCESS (1<<0) /* entry was found */ 60 #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 61 #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 62 #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retrys */ 63 #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 64 65 /* internal nsdispatch(3) flags; not settable in nsswitch.conf(5) */ 66 #define NS_FORCEALL (1<<8) /* force all methods to be invoked; */ 67 68 /* 69 * Currently implemented sources. 70 */ 71 #define NSSRC_FILES "files" /* local files */ 72 #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 73 #define NSSRC_NIS "nis" /* YP/NIS */ 74 #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 75 76 /* 77 * Currently implemented databases. 78 */ 79 #define NSDB_HOSTS "hosts" 80 #define NSDB_GROUP "group" 81 #define NSDB_GROUP_COMPAT "group_compat" 82 #define NSDB_NETGROUP "netgroup" 83 #define NSDB_NETWORKS "networks" 84 #define NSDB_PASSWD "passwd" 85 #define NSDB_PASSWD_COMPAT "passwd_compat" 86 #define NSDB_SHELLS "shells" 87 88 /* 89 * Suggested databases to implement. 90 */ 91 #define NSDB_ALIASES "aliases" 92 #define NSDB_AUTH "auth" 93 #define NSDB_AUTOMOUNT "automount" 94 #define NSDB_BOOTPARAMS "bootparams" 95 #define NSDB_ETHERS "ethers" 96 #define NSDB_EXPORTS "exports" 97 #define NSDB_NETMASKS "netmasks" 98 #define NSDB_PHONES "phones" 99 #define NSDB_PRINTCAP "printcap" 100 #define NSDB_PROTOCOLS "protocols" 101 #define NSDB_REMOTE "remote" 102 #define NSDB_RPC "rpc" 103 #define NSDB_SENDMAILVARS "sendmailvars" 104 #define NSDB_SERVICES "services" 105 #define NSDB_TERMCAP "termcap" 106 #define NSDB_TTYS "ttys" 107 108 /* 109 * ns_dtab `callback' function signature. 110 */ 111 typedef int (*nss_method)(void *, void *, va_list); 112 113 /* 114 * ns_dtab - `nsswitch dispatch table' 115 * Contains an entry for each source and the appropriate function to call. 116 */ 117 typedef struct { 118 const char *src; 119 nss_method callback; 120 void *cb_data; 121 } ns_dtab; 122 123 /* 124 * Macros to help build an ns_dtab[] 125 */ 126 #define NS_FILES_CB(F,C) { NSSRC_FILES, F, __UNCONST(C) }, 127 #define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, __UNCONST(C) }, 128 129 #ifdef HESIOD 130 # define NS_DNS_CB(F,C) { NSSRC_DNS, F, __UNCONST(C) }, 131 #else 132 # define NS_DNS_CB(F,C) 133 #endif 134 135 #ifdef YP 136 # define NS_NIS_CB(F,C) { NSSRC_NIS, F, __UNCONST(C) }, 137 #else 138 # define NS_NIS_CB(F,C) 139 #endif 140 141 /* 142 * ns_src - `nsswitch source' 143 * Used by the nsparser routines to store a mapping between a source 144 * and its dispatch control flags for a given database. 145 */ 146 typedef struct { 147 const char *name; 148 uint32_t flags; 149 } ns_src; 150 151 152 #if 0 153 /* 154 * Default sourcelists (if nsswitch.conf is missing, corrupt, 155 * or the requested database doesn't have an entry) 156 */ 157 extern const ns_src __nsdefaultsrc[]; 158 extern const ns_src __nsdefaultcompat[]; 159 extern const ns_src __nsdefaultcompat_forceall[]; 160 extern const ns_src __nsdefaultfiles[]; 161 extern const ns_src __nsdefaultfiles_forceall[]; 162 extern const ns_src __nsdefaultnis[]; 163 extern const ns_src __nsdefaultnis_forceall[]; 164 #endif 165 166 /* 167 * ns_mtab - `nsswitch method table' 168 * An nsswitch module provides a mapping from (database name, method name) 169 * tuples to the nss_method and associated callback data. Effectively, 170 * ns_dtab, but used for dynamically loaded modules. 171 */ 172 typedef struct { 173 const char *database; 174 const char *name; 175 nss_method method; 176 void *mdata; 177 } ns_mtab; 178 179 /* 180 * nss_module_register_fn - module registration function 181 * called at module load 182 * nss_module_unregister_fn - module un-registration function 183 * called at module unload 184 */ 185 typedef void (*nss_module_unregister_fn)(ns_mtab *, u_int); 186 typedef ns_mtab *(*nss_module_register_fn)(const char *, u_int *, 187 nss_module_unregister_fn *); 188 189 #ifdef _NS_PRIVATE 190 191 /* 192 * Private data structures for back-end nsswitch implementation. 193 */ 194 195 /* 196 * ns_dbt - `nsswitch database thang' 197 * For each database in /etc/nsswitch.conf there is a ns_dbt, with its 198 * name and a list of ns_src's containing the source information. 199 */ 200 typedef struct { 201 const char *name; /* name of database */ 202 ns_src *srclist; /* list of sources */ 203 u_int srclistsize; /* size of srclist */ 204 } ns_dbt; 205 206 /* 207 * ns_mod - `nsswitch module' 208 */ 209 typedef struct { 210 const char *name; /* module name */ 211 void *handle; /* handle from dlopen() */ 212 ns_mtab *mtab; /* method table */ 213 u_int mtabsize; /* size of mtab */ 214 /* called to unload module */ 215 nss_module_unregister_fn unregister; 216 } ns_mod; 217 218 #endif /* _NS_PRIVATE */ 219 220 221 #include <sys/cdefs.h> 222 223 __BEGIN_DECLS 224 int nsdispatch(void *, const ns_dtab [], const char *, 225 const char *, const ns_src [], ...); 226 227 #ifdef _NS_PRIVATE 228 int _nsdbtaddsrc(ns_dbt *, const ns_src *); 229 void _nsdbtdump(const ns_dbt *); 230 int _nsdbtput(const ns_dbt *); 231 void _nsyyerror(const char *); 232 int _nsyylex(void); 233 #endif /* _NS_PRIVATE */ 234 235 __END_DECLS 236 237 #endif /* !_NSSWITCH_H */ 238