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