nsswitch.h revision 113595
11539Srgrimes/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ 21539Srgrimes/* $FreeBSD: head/include/nsswitch.h 113595 2003-04-17 14:14:22Z nectar $ */ 31539Srgrimes 41539Srgrimes/*- 51539Srgrimes * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 61539Srgrimes * All rights reserved. 71539Srgrimes * 81539Srgrimes * This code is derived from software contributed to The NetBSD Foundation 91539Srgrimes * by Luke Mewburn. 101539Srgrimes * 111539Srgrimes * Redistribution and use in source and binary forms, with or without 121539Srgrimes * modification, are permitted provided that the following conditions 131539Srgrimes * are met: 141539Srgrimes * 1. Redistributions of source code must retain the above copyright 151539Srgrimes * notice, this list of conditions and the following disclaimer. 161539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 171539Srgrimes * notice, this list of conditions and the following disclaimer in the 181539Srgrimes * documentation and/or other materials provided with the distribution. 191539Srgrimes * 3. All advertising materials mentioning features or use of this software 201539Srgrimes * must display the following acknowledgement: 211539Srgrimes * This product includes software developed by the NetBSD 221539Srgrimes * Foundation, Inc. and its contributors. 231539Srgrimes * 4. Neither the name of The NetBSD Foundation nor the names of its 241539Srgrimes * contributors may be used to endorse or promote products derived 251539Srgrimes * from this software without specific prior written permission. 261539Srgrimes * 271539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 281539Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 291539Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 301539Srgrimes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 311539Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 321539Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3384747Sbde * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3484699Smike * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 351539Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 361539Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 371539Srgrimes * POSSIBILITY OF SUCH DAMAGE. 381539Srgrimes */ 3993747Smike 4093747Smike#ifndef _NSSWITCH_H 41102227Smike#define _NSSWITCH_H 1 421539Srgrimes 4393747Smike#include <sys/types.h> 4493747Smike#include <stdarg.h> 4593747Smike 4693747Smike#define NSS_MODULE_INTERFACE_VERSION 1 4793747Smike 4893747Smike#ifndef _PATH_NS_CONF 4993747Smike#define _PATH_NS_CONF "/etc/nsswitch.conf" 5093747Smike#endif 51102227Smike 52102227Smike/* NSS source actions */ 53102227Smike#define NS_ACTION_CONTINUE 0 /* try the next source */ 541539Srgrimes#define NS_ACTION_RETURN 1 /* look no further */ 551539Srgrimes 561539Srgrimes#define NS_SUCCESS (1<<0) /* entry was found */ 571539Srgrimes#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 581539Srgrimes#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 591539Srgrimes#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ 601539Srgrimes#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ 61105128Smike#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ 62105128Smike#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 63105128Smike 6493032Simp/* 6593032Simp * currently implemented sources 6693747Smike */ 6793032Simp#define NSSRC_FILES "files" /* local files */ 6893032Simp#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 69105128Smike#define NSSRC_NIS "nis" /* YP/NIS */ 70105128Smike#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 71105128Smike 72105128Smike/* 7393747Smike * currently implemented databases 7493032Simp */ 7593032Simp#define NSDB_HOSTS "hosts" 7693032Simp#define NSDB_GROUP "group" 7793747Smike#define NSDB_GROUP_COMPAT "group_compat" 7893032Simp#define NSDB_NETGROUP "netgroup" 79105128Smike#define NSDB_NETWORKS "networks" 80105128Smike#define NSDB_PASSWD "passwd" 81105128Smike#define NSDB_PASSWD_COMPAT "passwd_compat" 8293032Simp#define NSDB_SHELLS "shells" 83105128Smike 84105128Smike/* 85105128Smike * suggested databases to implement 86105128Smike */ 87105128Smike#define NSDB_ALIASES "aliases" 88105128Smike#define NSDB_AUTH "auth" 89105128Smike#define NSDB_AUTOMOUNT "automount" 9093032Simp#define NSDB_BOOTPARAMS "bootparams" 91105128Smike#define NSDB_ETHERS "ethers" 92105128Smike#define NSDB_EXPORTS "exports" 93105128Smike#define NSDB_NETMASKS "netmasks" 9493747Smike#define NSDB_PHONES "phones" 9593032Simp#define NSDB_PRINTCAP "printcap" 9693747Smike#define NSDB_PROTOCOLS "protocols" 97105128Smike#define NSDB_REMOTE "remote" 98105128Smike#define NSDB_RPC "rpc" 99105128Smike#define NSDB_SENDMAILVARS "sendmailvars" 10093032Simp#define NSDB_SERVICES "services" 10193032Simp#define NSDB_TERMCAP "termcap" 102105128Smike#define NSDB_TTYS "ttys" 103105128Smike 104105128Smike/* 105105128Smike * ns_dtab `method' function signature. 10693032Simp */ 10793032Simptypedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); 10893747Smike 109105128Smike/* 11093747Smike * Macro for generating method prototypes. 11193747Smike */ 112105128Smike#define NSS_METHOD_PROTOTYPE(method) \ 11393747Smike int method(void *, void *, va_list) 11493032Simp 1158858Srgrimes/* 1161539Srgrimes * ns_dtab - `nsswitch dispatch table' 1171539Srgrimes * Contains an entry for each source and the appropriate function to 1181539Srgrimes * call. ns_dtabs are used in the nsdispatch() API in order to allow 119 * the application to override built-in actions. 120 */ 121typedef struct _ns_dtab { 122 const char *src; /* Source this entry implements */ 123 nss_method method; /* Method to be called */ 124 void *mdata; /* Data passed to method */ 125} ns_dtab; 126 127/* 128 * macros to help build an ns_dtab[] 129 */ 130#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, 131#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, 132 133#ifdef HESIOD 134# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, 135#else 136# define NS_DNS_CB(F,C) 137#endif 138 139#ifdef YP 140# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, 141#else 142# define NS_NIS_CB(F,C) 143#endif 144 145/* 146 * ns_src - `nsswitch source' 147 * used by the nsparser routines to store a mapping between a source 148 * and its dispatch control flags for a given database. 149 */ 150typedef struct _ns_src { 151 const char *name; 152 u_int32_t flags; 153} ns_src; 154 155 156/* 157 * default sourcelist (if nsswitch.conf is missing, corrupt, 158 * or the requested database doesn't have an entry. 159 */ 160extern const ns_src __nsdefaultsrc[]; 161 162/* 163 * ns_mtab - NSS method table 164 * An NSS module provides a mapping from (database name, method name) 165 * tuples to the nss_method and associated data. 166 */ 167typedef struct _ns_mtab { 168 const char *database; 169 const char *name; 170 nss_method method; 171 void *mdata; 172} ns_mtab; 173 174/* 175 * NSS module de-registration, called at module unload. 176 */ 177typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); 178 179/* 180 * NSS module registration, called at module load. 181 */ 182typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, 183 nss_module_unregister_fn *); 184 185/* 186 * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. 187 * Developers are encouraged to use nss_lookup_type where approriate. 188 */ 189enum nss_lookup_type { 190 nss_lt_name = 1, 191 nss_lt_id = 2, 192 nss_lt_all = 3 193}; 194 195#ifdef _NS_PRIVATE 196 197/* 198 * private data structures for back-end nsswitch implementation 199 */ 200 201/* 202 * ns_dbt - `nsswitch database thang' 203 * for each database in /etc/nsswitch.conf there is a ns_dbt, with its 204 * name and a list of ns_src's containing the source information. 205 */ 206typedef struct _ns_dbt { 207 const char *name; /* name of database */ 208 ns_src *srclist; /* list of sources */ 209 int srclistsize; /* size of srclist */ 210} ns_dbt; 211 212/* 213 * ns_mod - NSS module 214 */ 215typedef struct _ns_mod { 216 char *name; /* module name */ 217 void *handle; /* handle from dlopen */ 218 ns_mtab *mtab; /* method table */ 219 unsigned int mtabsize; /* count of entries in method table */ 220 nss_module_unregister_fn unregister; /* called to unload module */ 221} ns_mod; 222 223#endif /* _NS_PRIVATE */ 224 225 226#include <sys/cdefs.h> 227 228__BEGIN_DECLS 229extern int nsdispatch(void *, const ns_dtab [], const char *, 230 const char *, const ns_src [], ...); 231 232#ifdef _NS_PRIVATE 233extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); 234extern void _nsdbtput(const ns_dbt *); 235extern void _nsyyerror(const char *); 236extern int _nsyylex(void); 237extern int _nsyyparse(void); 238extern int _nsyylineno; 239#ifdef _NSS_DEBUG 240extern void _nsdbtdump(const ns_dbt *); 241#endif 242#endif /* _NS_PRIVATE */ 243 244__END_DECLS 245 246#endif /* !_NSSWITCH_H */ 247