00001 /* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ 00002 /* $FreeBSD: src/include/nsswitch.h,v 1.3 2003/04/17 14:14:21 nectar Exp $ */ 00003 00004 /*- 00005 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 00006 * All rights reserved. 00007 * 00008 * This code is derived from software contributed to The NetBSD Foundation 00009 * by Luke Mewburn. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 1. Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright 00017 * notice, this list of conditions and the following disclaimer in the 00018 * documentation and/or other materials provided with the distribution. 00019 * 3. All advertising materials mentioning features or use of this software 00020 * must display the following acknowledgement: 00021 * This product includes software developed by the NetBSD 00022 * Foundation, Inc. and its contributors. 00023 * 4. Neither the name of The NetBSD Foundation nor the names of its 00024 * contributors may be used to endorse or promote products derived 00025 * from this software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 00028 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00029 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00030 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 00031 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved. 00039 */ 00040 00041 #ifndef _NSSWITCH_H 00042 #define _NSSWITCH_H 1 00043 00044 #include <sys/types.h> 00045 #include <stdarg.h> 00046 00047 #define NSS_MODULE_INTERFACE_VERSION 1 00048 00049 #ifndef _PATH_NS_CONF 00050 #define _PATH_NS_CONF "/etc/nsswitch.conf" 00051 #endif 00052 00053 /* NSS source actions */ 00054 #define NS_ACTION_CONTINUE 0 /* try the next source */ 00055 #define NS_ACTION_RETURN 1 /* look no further */ 00056 00057 #define NS_SUCCESS (1<<0) /* entry was found */ 00058 #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 00059 #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 00060 #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ 00061 #define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ 00062 #define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ 00063 #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 00064 00065 /* 00066 * currently implemented sources 00067 */ 00068 #define NSSRC_FILES "files" /* local files */ 00069 #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 00070 #define NSSRC_NIS "nis" /* YP/NIS */ 00071 #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 00072 00073 /* 00074 * currently implemented databases 00075 */ 00076 #define NSDB_HOSTS "hosts" 00077 #define NSDB_GROUP "group" 00078 #define NSDB_GROUP_COMPAT "group_compat" 00079 #define NSDB_NETGROUP "netgroup" 00080 #define NSDB_NETWORKS "networks" 00081 #define NSDB_PASSWD "passwd" 00082 #define NSDB_PASSWD_COMPAT "passwd_compat" 00083 #define NSDB_SHELLS "shells" 00084 00085 /* 00086 * suggested databases to implement 00087 */ 00088 #define NSDB_ALIASES "aliases" 00089 #define NSDB_AUTH "auth" 00090 #define NSDB_AUTOMOUNT "automount" 00091 #define NSDB_BOOTPARAMS "bootparams" 00092 #define NSDB_ETHERS "ethers" 00093 #define NSDB_EXPORTS "exports" 00094 #define NSDB_NETMASKS "netmasks" 00095 #define NSDB_PHONES "phones" 00096 #define NSDB_PRINTCAP "printcap" 00097 #define NSDB_PROTOCOLS "protocols" 00098 #define NSDB_REMOTE "remote" 00099 #define NSDB_RPC "rpc" 00100 #define NSDB_SENDMAILVARS "sendmailvars" 00101 #define NSDB_SERVICES "services" 00102 #define NSDB_TERMCAP "termcap" 00103 #define NSDB_TTYS "ttys" 00104 00105 /* 00106 * ns_dtab `method' function signature. 00107 */ 00108 typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); 00109 00110 /* 00111 * Macro for generating method prototypes. 00112 */ 00113 #define NSS_METHOD_PROTOTYPE(method) \ 00114 int method(void *, void *, va_list) 00115 00116 /* 00117 * ns_dtab - `nsswitch dispatch table' 00118 * Contains an entry for each source and the appropriate function to 00119 * call. ns_dtabs are used in the nsdispatch() API in order to allow 00120 * the application to override built-in actions. 00121 */ 00122 typedef struct _ns_dtab { 00123 const char *src; /* Source this entry implements */ 00124 nss_method method; /* Method to be called */ 00125 void *mdata; /* Data passed to method */ 00126 } ns_dtab; 00127 00128 /* 00129 * macros to help build an ns_dtab[] 00130 */ 00131 #define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, 00132 #define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, 00133 00134 #ifdef HESIOD 00135 # define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, 00136 #else 00137 # define NS_DNS_CB(F,C) 00138 #endif 00139 00140 #ifdef YP 00141 # define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, 00142 #else 00143 # define NS_NIS_CB(F,C) 00144 #endif 00145 00146 /* 00147 * ns_src - `nsswitch source' 00148 * used by the nsparser routines to store a mapping between a source 00149 * and its dispatch control flags for a given database. 00150 */ 00151 typedef struct _ns_src { 00152 const char *name; 00153 u_int32_t flags; 00154 } ns_src; 00155 00156 00157 /* 00158 * default sourcelist (if nsswitch.conf is missing, corrupt, 00159 * or the requested database doesn't have an entry. 00160 */ 00161 extern const ns_src __nsdefaultsrc[]; 00162 00163 /* 00164 * ns_mtab - NSS method table 00165 * An NSS module provides a mapping from (database name, method name) 00166 * tuples to the nss_method and associated data. 00167 */ 00168 typedef struct _ns_mtab { 00169 const char *database; 00170 const char *name; 00171 nss_method method; 00172 void *mdata; 00173 } ns_mtab; 00174 00175 /* 00176 * NSS module de-registration, called at module unload. 00177 */ 00178 typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); 00179 00180 /* 00181 * NSS module registration, called at module load. 00182 */ 00183 typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, 00184 nss_module_unregister_fn *); 00185 00186 /* 00187 * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. 00188 * Developers are encouraged to use nss_lookup_type where approriate. 00189 */ 00190 enum nss_lookup_type { 00191 nss_lt_name = 1, 00192 nss_lt_id = 2, 00193 nss_lt_all = 3 00194 }; 00195 00196 #ifdef _NS_PRIVATE 00197 00198 /* 00199 * private data structures for back-end nsswitch implementation 00200 */ 00201 00202 /* 00203 * ns_dbt - `nsswitch database thang' 00204 * for each database in /etc/nsswitch.conf there is a ns_dbt, with its 00205 * name and a list of ns_src's containing the source information. 00206 */ 00207 typedef struct _ns_dbt { 00208 const char *name; /* name of database */ 00209 ns_src *srclist; /* list of sources */ 00210 int srclistsize; /* size of srclist */ 00211 } ns_dbt; 00212 00213 /* 00214 * ns_mod - NSS module 00215 */ 00216 typedef struct _ns_mod { 00217 char *name; /* module name */ 00218 void *handle; /* handle from dlopen */ 00219 ns_mtab *mtab; /* method table */ 00220 unsigned int mtabsize; /* count of entries in method table */ 00221 nss_module_unregister_fn unregister; /* called to unload module */ 00222 } ns_mod; 00223 00224 #endif /* _NS_PRIVATE */ 00225 00226 #endif /* !_NSSWITCH_H */