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