nsswitch.h revision 203963
113547Schegar/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ 213547Schegar/* $FreeBSD: head/include/nsswitch.h 203963 2010-02-16 19:28:10Z imp $ */ 313547Schegar 413547Schegar/*- 513547Schegar * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 613547Schegar * All rights reserved. 713547Schegar * 813547Schegar * This code is derived from software contributed to The NetBSD Foundation 913547Schegar * by Luke Mewburn. 1013547Schegar * 1113547Schegar * Redistribution and use in source and binary forms, with or without 1213547Schegar * modification, are permitted provided that the following conditions 1313547Schegar * are met: 1413547Schegar * 1. Redistributions of source code must retain the above copyright 1513547Schegar * notice, this list of conditions and the following disclaimer. 1613547Schegar * 2. Redistributions in binary form must reproduce the above copyright 1713547Schegar * notice, this list of conditions and the following disclaimer in the 1813547Schegar * documentation and/or other materials provided with the distribution. 1913547Schegar * 2013547Schegar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2113547Schegar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2213547Schegar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2313547Schegar * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2413547Schegar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2513547Schegar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2613547Schegar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2713547Schegar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2813547Schegar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2913547Schegar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3013547Schegar * POSSIBILITY OF SUCH DAMAGE. 3113547Schegar */ 3213547Schegar 3313547Schegar#ifndef _NSSWITCH_H 3413547Schegar#define _NSSWITCH_H 1 3513547Schegar 3613547Schegar#include <sys/types.h> 3713547Schegar#include <stdarg.h> 3813547Schegar 3913547Schegar#define NSS_MODULE_INTERFACE_VERSION 1 4013547Schegar 4113547Schegar#ifndef _PATH_NS_CONF 4213547Schegar#define _PATH_NS_CONF "/etc/nsswitch.conf" 4313547Schegar#endif 4413547Schegar 4513547Schegar/* NSS source actions */ 4613547Schegar#define NS_ACTION_CONTINUE 0 /* try the next source */ 4713547Schegar#define NS_ACTION_RETURN 1 /* look no further */ 4813547Schegar 4913547Schegar#define NS_SUCCESS (1<<0) /* entry was found */ 5013547Schegar#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ 5113547Schegar#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ 5213547Schegar#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ 5313547Schegar#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ 5413547Schegar#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ 5513547Schegar#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ 5613547Schegar 5713547Schegar/* 5813547Schegar * currently implemented sources 5913547Schegar */ 6013547Schegar#define NSSRC_FILES "files" /* local files */ 6113547Schegar#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ 6213547Schegar#define NSSRC_NIS "nis" /* YP/NIS */ 6313547Schegar#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ 6413547Schegar#define NSSRC_CACHE "cache" /* nscd daemon */ 6513547Schegar#define NSSRC_FALLBACK "__fallback" /* internal fallback source */ 6613547Schegar 6713547Schegar/* 6813547Schegar * currently implemented databases 6913547Schegar */ 7013547Schegar#define NSDB_HOSTS "hosts" 7113547Schegar#define NSDB_GROUP "group" 7213547Schegar#define NSDB_GROUP_COMPAT "group_compat" 7313547Schegar#define NSDB_NETGROUP "netgroup" 7413547Schegar#define NSDB_NETWORKS "networks" 7513547Schegar#define NSDB_PASSWD "passwd" 7613547Schegar#define NSDB_PASSWD_COMPAT "passwd_compat" 7713547Schegar#define NSDB_SHELLS "shells" 7813547Schegar#define NSDB_SERVICES "services" 7913547Schegar#define NSDB_SERVICES_COMPAT "services_compat" 8013547Schegar#define NSDB_SSH_HOSTKEYS "ssh_hostkeys" 8113547Schegar#define NSDB_PROTOCOLS "protocols" 8213547Schegar#define NSDB_RPC "rpc" 8313547Schegar 8413547Schegar/* 8513547Schegar * suggested databases to implement 8613547Schegar */ 8713547Schegar#define NSDB_ALIASES "aliases" 8813547Schegar#define NSDB_AUTH "auth" 8913547Schegar#define NSDB_AUTOMOUNT "automount" 9013547Schegar#define NSDB_BOOTPARAMS "bootparams" 9113547Schegar#define NSDB_ETHERS "ethers" 9213547Schegar#define NSDB_EXPORTS "exports" 9313547Schegar#define NSDB_NETMASKS "netmasks" 9413547Schegar#define NSDB_PHONES "phones" 9513547Schegar#define NSDB_PRINTCAP "printcap" 9613547Schegar#define NSDB_REMOTE "remote" 9713547Schegar#define NSDB_SENDMAILVARS "sendmailvars" 9813547Schegar#define NSDB_TERMCAP "termcap" 9913547Schegar#define NSDB_TTYS "ttys" 10013547Schegar 10113547Schegar/* 10213547Schegar * ns_dtab `method' function signature. 10313547Schegar */ 10413547Schegartypedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); 10513547Schegar 10613547Schegar/* 10713547Schegar * Macro for generating method prototypes. 10813547Schegar */ 10913547Schegar#define NSS_METHOD_PROTOTYPE(method) \ 11013547Schegar int method(void *, void *, va_list) 11113547Schegar 11213547Schegar/* 11313547Schegar * ns_dtab - `nsswitch dispatch table' 11413547Schegar * Contains an entry for each source and the appropriate function to 11513547Schegar * call. ns_dtabs are used in the nsdispatch() API in order to allow 11613547Schegar * the application to override built-in actions. 11713547Schegar */ 11813547Schegartypedef struct _ns_dtab { 11913547Schegar const char *src; /* Source this entry implements */ 12013547Schegar nss_method method; /* Method to be called */ 12113547Schegar void *mdata; /* Data passed to method */ 12213547Schegar} ns_dtab; 12313547Schegar 12413547Schegar/* 12513547Schegar * macros to help build an ns_dtab[] 12613547Schegar */ 12713547Schegar#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, 12813547Schegar#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, 12913547Schegar#define NS_FALLBACK_CB(F) { NSSRC_FALLBACK, F, NULL }, 13013547Schegar 131#ifdef HESIOD 132# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, 133#else 134# define NS_DNS_CB(F,C) 135#endif 136 137#ifdef YP 138# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, 139#else 140# define NS_NIS_CB(F,C) 141#endif 142 143/* 144 * ns_src - `nsswitch source' 145 * used by the nsparser routines to store a mapping between a source 146 * and its dispatch control flags for a given database. 147 */ 148typedef struct _ns_src { 149 const char *name; 150 u_int32_t flags; 151} ns_src; 152 153 154/* 155 * default sourcelist (if nsswitch.conf is missing, corrupt, 156 * or the requested database doesn't have an entry. 157 */ 158extern const ns_src __nsdefaultsrc[]; 159 160/* 161 * ns_mtab - NSS method table 162 * An NSS module provides a mapping from (database name, method name) 163 * tuples to the nss_method and associated data. 164 */ 165typedef struct _ns_mtab { 166 const char *database; 167 const char *name; 168 nss_method method; 169 void *mdata; 170} ns_mtab; 171 172/* 173 * NSS module de-registration, called at module unload. 174 */ 175typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); 176 177/* 178 * NSS module registration, called at module load. 179 */ 180typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, 181 nss_module_unregister_fn *); 182 183/* 184 * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. 185 * Developers are encouraged to use nss_lookup_type where approriate. 186 */ 187enum nss_lookup_type { 188 nss_lt_name = 1, 189 nss_lt_id = 2, 190 nss_lt_all = 3 191}; 192 193#ifdef _NS_PRIVATE 194/* 195 * private data structures for back-end nsswitch implementation 196 */ 197 198/* 199 * ns_dbt - `nsswitch database thang' 200 * for each database in /etc/nsswitch.conf there is a ns_dbt, with its 201 * name and a list of ns_src's containing the source information. 202 */ 203typedef struct _ns_dbt { 204 const char *name; /* name of database */ 205 ns_src *srclist; /* list of sources */ 206 int srclistsize; /* size of srclist */ 207} ns_dbt; 208 209/* 210 * ns_mod - NSS module 211 */ 212typedef struct _ns_mod { 213 char *name; /* module name */ 214 void *handle; /* handle from dlopen */ 215 ns_mtab *mtab; /* method table */ 216 unsigned int mtabsize; /* count of entries in method table */ 217 nss_module_unregister_fn unregister; /* called to unload module */ 218} ns_mod; 219 220#endif /* _NS_PRIVATE */ 221 222 223#include <sys/cdefs.h> 224 225__BEGIN_DECLS 226extern int nsdispatch(void *, const ns_dtab [], const char *, 227 const char *, const ns_src [], ...); 228 229#ifdef _NS_PRIVATE 230extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); 231extern void _nsdbtput(const ns_dbt *); 232extern void _nsyyerror(const char *); 233extern int _nsyylex(void); 234extern int _nsyyparse(void); 235extern int _nsyylineno; 236#ifdef _NSS_DEBUG 237extern void _nsdbtdump(const ns_dbt *); 238#endif 239#endif /* _NS_PRIVATE */ 240 241__END_DECLS 242 243#endif /* !_NSSWITCH_H */ 244