nsswitch.h revision 174547
138032Speter/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ 2261363Sgshapiro/* $FreeBSD: head/include/nsswitch.h 174547 2007-12-12 10:08:03Z bushman $ */ 390792Sgshapiro 490792Sgshapiro/*- 590792Sgshapiro * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 690792Sgshapiro * All rights reserved. 790792Sgshapiro * 890792Sgshapiro * This code is derived from software contributed to The NetBSD Foundation 990792Sgshapiro * by Luke Mewburn. 1090792Sgshapiro * 1190792Sgshapiro * Redistribution and use in source and binary forms, with or without 1238032Speter * modification, are permitted provided that the following conditions 1338032Speter * are met: 1438032Speter * 1. Redistributions of source code must retain the above copyright 1538032Speter * notice, this list of conditions and the following disclaimer. 1638032Speter * 2. Redistributions in binary form must reproduce the above copyright 1738032Speter * notice, this list of conditions and the following disclaimer in the 1864562Sgshapiro * documentation and/or other materials provided with the distribution. 1938032Speter * 3. All advertising materials mentioning features or use of this software 2038032Speter * must display the following acknowledgement: 2164562Sgshapiro * This product includes software developed by the NetBSD 2264562Sgshapiro * Foundation, Inc. and its contributors. 2364562Sgshapiro * 4. Neither the name of The NetBSD Foundation nor the names of its 2464562Sgshapiro * contributors may be used to endorse or promote products derived 2564562Sgshapiro * from this software without specific prior written permission. 2638032Speter * 2738032Speter * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2864562Sgshapiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29266692Sgshapiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3064562Sgshapiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3164562Sgshapiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3264562Sgshapiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3364562Sgshapiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3464562Sgshapiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3564562Sgshapiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3638032Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3738032Speter * POSSIBILITY OF SUCH DAMAGE. 3838032Speter */ 3938032Speter 4038032Speter#ifndef _NSSWITCH_H 4138032Speter#define _NSSWITCH_H 1 4238032Speter 4338032Speter#include <sys/types.h> 4438032Speter#include <stdarg.h> 4538032Speter 4638032Speter#define NSS_MODULE_INTERFACE_VERSION 1 4738032Speter 4838032Speter#ifndef _PATH_NS_CONF 4938032Speter#define _PATH_NS_CONF "/etc/nsswitch.conf" 5038032Speter#endif 5138032Speter 5238032Speter/* NSS source actions */ 5338032Speter#define NS_ACTION_CONTINUE 0 /* try the next source */ 5438032Speter#define NS_ACTION_RETURN 1 /* look no further */ 5538032Speter 5638032Speter#define NS_SUCCESS (1<<0) /* entry was found */ 5738032Speter#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 5838032Speter#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 5938032Speter#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ 6038032Speter#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ 6138032Speter#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ 6238032Speter#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 6338032Speter 6438032Speter/* 6538032Speter * currently implemented sources 6638032Speter */ 6738032Speter#define NSSRC_FILES "files" /* local files */ 6838032Speter#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 6938032Speter#define NSSRC_NIS "nis" /* YP/NIS */ 7038032Speter#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 7138032Speter#define NSSRC_CACHE "cache" /* nscd daemon */ 7238032Speter#define NSSRC_FALLBACK "__fallback" /* internal fallback source */ 7338032Speter 7438032Speter/* 7538032Speter * currently implemented databases 7638032Speter */ 7738032Speter#define NSDB_HOSTS "hosts" 7838032Speter#define NSDB_GROUP "group" 7938032Speter#define NSDB_GROUP_COMPAT "group_compat" 8038032Speter#define NSDB_NETGROUP "netgroup" 8138032Speter#define NSDB_NETWORKS "networks" 8264562Sgshapiro#define NSDB_PASSWD "passwd" 8338032Speter#define NSDB_PASSWD_COMPAT "passwd_compat" 8438032Speter#define NSDB_SHELLS "shells" 85#define NSDB_SERVICES "services" 86#define NSDB_SERVICES_COMPAT "services_compat" 87#define NSDB_SSH_HOSTKEYS "ssh_hostkeys" 88#define NSDB_PROTOCOLS "protocols" 89#define NSDB_RPC "rpc" 90 91/* 92 * suggested databases to implement 93 */ 94#define NSDB_ALIASES "aliases" 95#define NSDB_AUTH "auth" 96#define NSDB_AUTOMOUNT "automount" 97#define NSDB_BOOTPARAMS "bootparams" 98#define NSDB_ETHERS "ethers" 99#define NSDB_EXPORTS "exports" 100#define NSDB_NETMASKS "netmasks" 101#define NSDB_PHONES "phones" 102#define NSDB_PRINTCAP "printcap" 103#define NSDB_REMOTE "remote" 104#define NSDB_SENDMAILVARS "sendmailvars" 105#define NSDB_TERMCAP "termcap" 106#define NSDB_TTYS "ttys" 107 108/* 109 * ns_dtab `method' function signature. 110 */ 111typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); 112 113/* 114 * Macro for generating method prototypes. 115 */ 116#define NSS_METHOD_PROTOTYPE(method) \ 117 int method(void *, void *, va_list) 118 119/* 120 * ns_dtab - `nsswitch dispatch table' 121 * Contains an entry for each source and the appropriate function to 122 * call. ns_dtabs are used in the nsdispatch() API in order to allow 123 * the application to override built-in actions. 124 */ 125typedef struct _ns_dtab { 126 const char *src; /* Source this entry implements */ 127 nss_method method; /* Method to be called */ 128 void *mdata; /* Data passed to method */ 129} ns_dtab; 130 131/* 132 * macros to help build an ns_dtab[] 133 */ 134#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, 135#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, 136#define NS_FALLBACK_CB(F) { NSSRC_FALLBACK, F, NULL }, 137 138#ifdef HESIOD 139# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, 140#else 141# define NS_DNS_CB(F,C) 142#endif 143 144#ifdef YP 145# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, 146#else 147# define NS_NIS_CB(F,C) 148#endif 149 150/* 151 * ns_src - `nsswitch source' 152 * used by the nsparser routines to store a mapping between a source 153 * and its dispatch control flags for a given database. 154 */ 155typedef struct _ns_src { 156 const char *name; 157 u_int32_t flags; 158} ns_src; 159 160 161/* 162 * default sourcelist (if nsswitch.conf is missing, corrupt, 163 * or the requested database doesn't have an entry. 164 */ 165extern const ns_src __nsdefaultsrc[]; 166 167/* 168 * ns_mtab - NSS method table 169 * An NSS module provides a mapping from (database name, method name) 170 * tuples to the nss_method and associated data. 171 */ 172typedef struct _ns_mtab { 173 const char *database; 174 const char *name; 175 nss_method method; 176 void *mdata; 177} ns_mtab; 178 179/* 180 * NSS module de-registration, called at module unload. 181 */ 182typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); 183 184/* 185 * NSS module registration, called at module load. 186 */ 187typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, 188 nss_module_unregister_fn *); 189 190/* 191 * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. 192 * Developers are encouraged to use nss_lookup_type where approriate. 193 */ 194enum nss_lookup_type { 195 nss_lt_name = 1, 196 nss_lt_id = 2, 197 nss_lt_all = 3 198}; 199 200#ifdef _NS_PRIVATE 201/* 202 * private data structures for back-end nsswitch implementation 203 */ 204 205/* 206 * ns_dbt - `nsswitch database thang' 207 * for each database in /etc/nsswitch.conf there is a ns_dbt, with its 208 * name and a list of ns_src's containing the source information. 209 */ 210typedef struct _ns_dbt { 211 const char *name; /* name of database */ 212 ns_src *srclist; /* list of sources */ 213 int srclistsize; /* size of srclist */ 214} ns_dbt; 215 216/* 217 * ns_mod - NSS module 218 */ 219typedef struct _ns_mod { 220 char *name; /* module name */ 221 void *handle; /* handle from dlopen */ 222 ns_mtab *mtab; /* method table */ 223 unsigned int mtabsize; /* count of entries in method table */ 224 nss_module_unregister_fn unregister; /* called to unload module */ 225} ns_mod; 226 227#endif /* _NS_PRIVATE */ 228 229 230#include <sys/cdefs.h> 231 232__BEGIN_DECLS 233extern int nsdispatch(void *, const ns_dtab [], const char *, 234 const char *, const ns_src [], ...); 235 236#ifdef _NS_PRIVATE 237extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); 238extern void _nsdbtput(const ns_dbt *); 239extern void _nsyyerror(const char *); 240extern int _nsyylex(void); 241extern int _nsyyparse(void); 242extern int _nsyylineno; 243#ifdef _NSS_DEBUG 244extern void _nsdbtdump(const ns_dbt *); 245#endif 246#endif /* _NS_PRIVATE */ 247 248__END_DECLS 249 250#endif /* !_NSSWITCH_H */ 251