| 1 | /* nsswitch.h,v 1.2 2004/09/14 22:27:34 bird Exp */ | 
|---|
| 2 | /** @file | 
|---|
| 3 | * FreeBSD 5.2 | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | /*      $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $       */ | 
|---|
| 7 | /*      $FreeBSD: src/include/nsswitch.h,v 1.3 2003/04/17 14:14:21 nectar Exp $ */ | 
|---|
| 8 |  | 
|---|
| 9 | /*- | 
|---|
| 10 | * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. | 
|---|
| 11 | * All rights reserved. | 
|---|
| 12 | * | 
|---|
| 13 | * This code is derived from software contributed to The NetBSD Foundation | 
|---|
| 14 | * by Luke Mewburn. | 
|---|
| 15 | * | 
|---|
| 16 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 17 | * modification, are permitted provided that the following conditions | 
|---|
| 18 | * are met: | 
|---|
| 19 | * 1. Redistributions of source code must retain the above copyright | 
|---|
| 20 | *    notice, this list of conditions and the following disclaimer. | 
|---|
| 21 | * 2. Redistributions in binary form must reproduce the above copyright | 
|---|
| 22 | *    notice, this list of conditions and the following disclaimer in the | 
|---|
| 23 | *    documentation and/or other materials provided with the distribution. | 
|---|
| 24 | * 3. All advertising materials mentioning features or use of this software | 
|---|
| 25 | *    must display the following acknowledgement: | 
|---|
| 26 | *        This product includes software developed by the NetBSD | 
|---|
| 27 | *        Foundation, Inc. and its contributors. | 
|---|
| 28 | * 4. Neither the name of The NetBSD Foundation nor the names of its | 
|---|
| 29 | *    contributors may be used to endorse or promote products derived | 
|---|
| 30 | *    from this software without specific prior written permission. | 
|---|
| 31 | * | 
|---|
| 32 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 
|---|
| 33 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 
|---|
| 34 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
|---|
| 35 | * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 
|---|
| 36 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
|---|
| 37 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
|---|
| 38 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 
|---|
| 39 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 
|---|
| 40 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 
|---|
| 41 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
|---|
| 42 | * POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 43 | */ | 
|---|
| 44 |  | 
|---|
| 45 | #ifndef _NSSWITCH_H | 
|---|
| 46 | #define _NSSWITCH_H     1 | 
|---|
| 47 |  | 
|---|
| 48 | #include <sys/types.h> | 
|---|
| 49 | #include <stdarg.h> | 
|---|
| 50 |  | 
|---|
| 51 | #define NSS_MODULE_INTERFACE_VERSION 1 | 
|---|
| 52 |  | 
|---|
| 53 | #ifndef _PATH_NS_CONF | 
|---|
| 54 | #define _PATH_NS_CONF   "/@unixroot/etc/nsswitch.conf" | 
|---|
| 55 | #endif | 
|---|
| 56 |  | 
|---|
| 57 | /* NSS source actions */ | 
|---|
| 58 | #define NS_ACTION_CONTINUE      0       /* try the next source */ | 
|---|
| 59 | #define NS_ACTION_RETURN        1       /* look no further */ | 
|---|
| 60 |  | 
|---|
| 61 | #define NS_SUCCESS      (1<<0)          /* entry was found */ | 
|---|
| 62 | #define NS_UNAVAIL      (1<<1)          /* source not responding, or corrupt */ | 
|---|
| 63 | #define NS_NOTFOUND     (1<<2)          /* source responded 'no such entry' */ | 
|---|
| 64 | #define NS_TRYAGAIN     (1<<3)          /* source busy, may respond to retry */ | 
|---|
| 65 | #define NS_RETURN       (1<<4)          /* stop search, e.g. for ERANGE */ | 
|---|
| 66 | #define NS_TERMINATE    (NS_SUCCESS|NS_RETURN) /* flags that end search */ | 
|---|
| 67 | #define NS_STATUSMASK   0x000000ff      /* bitmask to get the status flags */ | 
|---|
| 68 |  | 
|---|
| 69 | /* | 
|---|
| 70 | * currently implemented sources | 
|---|
| 71 | */ | 
|---|
| 72 | #define NSSRC_FILES     "files"         /* local files */ | 
|---|
| 73 | #define NSSRC_DNS       "dns"           /* DNS; IN for hosts, HS for others */ | 
|---|
| 74 | #define NSSRC_NIS       "nis"           /* YP/NIS */ | 
|---|
| 75 | #define NSSRC_COMPAT    "compat"        /* passwd,group in YP compat mode */ | 
|---|
| 76 |  | 
|---|
| 77 | /* | 
|---|
| 78 | * currently implemented databases | 
|---|
| 79 | */ | 
|---|
| 80 | #define NSDB_HOSTS              "hosts" | 
|---|
| 81 | #define NSDB_GROUP              "group" | 
|---|
| 82 | #define NSDB_GROUP_COMPAT       "group_compat" | 
|---|
| 83 | #define NSDB_NETGROUP           "netgroup" | 
|---|
| 84 | #define NSDB_NETWORKS           "networks" | 
|---|
| 85 | #define NSDB_PASSWD             "passwd" | 
|---|
| 86 | #define NSDB_PASSWD_COMPAT      "passwd_compat" | 
|---|
| 87 | #define NSDB_SHELLS             "shells" | 
|---|
| 88 |  | 
|---|
| 89 | /* | 
|---|
| 90 | * suggested databases to implement | 
|---|
| 91 | */ | 
|---|
| 92 | #define NSDB_ALIASES            "aliases" | 
|---|
| 93 | #define NSDB_AUTH               "auth" | 
|---|
| 94 | #define NSDB_AUTOMOUNT          "automount" | 
|---|
| 95 | #define NSDB_BOOTPARAMS         "bootparams" | 
|---|
| 96 | #define NSDB_ETHERS             "ethers" | 
|---|
| 97 | #define NSDB_EXPORTS            "exports" | 
|---|
| 98 | #define NSDB_NETMASKS           "netmasks" | 
|---|
| 99 | #define NSDB_PHONES             "phones" | 
|---|
| 100 | #define NSDB_PRINTCAP           "printcap" | 
|---|
| 101 | #define NSDB_PROTOCOLS          "protocols" | 
|---|
| 102 | #define NSDB_REMOTE             "remote" | 
|---|
| 103 | #define NSDB_RPC                "rpc" | 
|---|
| 104 | #define NSDB_SENDMAILVARS       "sendmailvars" | 
|---|
| 105 | #define NSDB_SERVICES           "services" | 
|---|
| 106 | #define NSDB_TERMCAP            "termcap" | 
|---|
| 107 | #define NSDB_TTYS               "ttys" | 
|---|
| 108 |  | 
|---|
| 109 | /* | 
|---|
| 110 | * ns_dtab `method' function signature. | 
|---|
| 111 | */ | 
|---|
| 112 | typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); | 
|---|
| 113 |  | 
|---|
| 114 | /* | 
|---|
| 115 | * Macro for generating method prototypes. | 
|---|
| 116 | */ | 
|---|
| 117 | #define NSS_METHOD_PROTOTYPE(method) \ | 
|---|
| 118 | int method(void *, void *, va_list) | 
|---|
| 119 |  | 
|---|
| 120 | /* | 
|---|
| 121 | * ns_dtab - `nsswitch dispatch table' | 
|---|
| 122 | * Contains an entry for each source and the appropriate function to | 
|---|
| 123 | * call.  ns_dtabs are used in the nsdispatch() API in order to allow | 
|---|
| 124 | * the application to override built-in actions. | 
|---|
| 125 | */ | 
|---|
| 126 | typedef struct _ns_dtab { | 
|---|
| 127 | const char       *src;          /* Source this entry implements */ | 
|---|
| 128 | nss_method        method;       /* Method to be called */ | 
|---|
| 129 | void             *mdata;        /* Data passed to method */ | 
|---|
| 130 | } ns_dtab; | 
|---|
| 131 |  | 
|---|
| 132 | /* | 
|---|
| 133 | * macros to help build an ns_dtab[] | 
|---|
| 134 | */ | 
|---|
| 135 | #define NS_FILES_CB(F,C)        { NSSRC_FILES,  F,      C }, | 
|---|
| 136 | #define NS_COMPAT_CB(F,C)       { NSSRC_COMPAT, F,      C }, | 
|---|
| 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 | */ | 
|---|
| 155 | typedef 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 | */ | 
|---|
| 165 | extern 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 | */ | 
|---|
| 172 | typedef 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 | */ | 
|---|
| 182 | typedef void     (*nss_module_unregister_fn)(ns_mtab *, unsigned int); | 
|---|
| 183 |  | 
|---|
| 184 | /* | 
|---|
| 185 | * NSS module registration, called at module load. | 
|---|
| 186 | */ | 
|---|
| 187 | typedef 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 | */ | 
|---|
| 194 | enum 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 | /* | 
|---|
| 203 | * private data structures for back-end nsswitch implementation | 
|---|
| 204 | */ | 
|---|
| 205 |  | 
|---|
| 206 | /* | 
|---|
| 207 | * ns_dbt - `nsswitch database thang' | 
|---|
| 208 | * for each database in /etc/nsswitch.conf there is a ns_dbt, with its | 
|---|
| 209 | * name and a list of ns_src's containing the source information. | 
|---|
| 210 | */ | 
|---|
| 211 | typedef struct _ns_dbt { | 
|---|
| 212 | const char      *name;          /* name of database */ | 
|---|
| 213 | ns_src          *srclist;       /* list of sources */ | 
|---|
| 214 | int              srclistsize;   /* size of srclist */ | 
|---|
| 215 | } ns_dbt; | 
|---|
| 216 |  | 
|---|
| 217 | /* | 
|---|
| 218 | * ns_mod - NSS module | 
|---|
| 219 | */ | 
|---|
| 220 | typedef struct _ns_mod { | 
|---|
| 221 | char            *name;          /* module name */ | 
|---|
| 222 | void            *handle;        /* handle from dlopen */ | 
|---|
| 223 | ns_mtab         *mtab;          /* method table */ | 
|---|
| 224 | unsigned int     mtabsize;      /* count of entries in method table */ | 
|---|
| 225 | nss_module_unregister_fn unregister; /* called to unload module */ | 
|---|
| 226 | } ns_mod; | 
|---|
| 227 |  | 
|---|
| 228 | #endif /* _NS_PRIVATE */ | 
|---|
| 229 |  | 
|---|
| 230 |  | 
|---|
| 231 | #include <sys/cdefs.h> | 
|---|
| 232 |  | 
|---|
| 233 | __BEGIN_DECLS | 
|---|
| 234 | extern  int     nsdispatch(void *, const ns_dtab [], const char *, | 
|---|
| 235 | const char *, const ns_src [], ...); | 
|---|
| 236 |  | 
|---|
| 237 | #ifdef _NS_PRIVATE | 
|---|
| 238 | extern  void             _nsdbtaddsrc(ns_dbt *, const ns_src *); | 
|---|
| 239 | extern  void             _nsdbtput(const ns_dbt *); | 
|---|
| 240 | extern  void             _nsyyerror(const char *); | 
|---|
| 241 | extern  int              _nsyylex(void); | 
|---|
| 242 | extern  int              _nsyyparse(void); | 
|---|
| 243 | extern  int              _nsyylineno; | 
|---|
| 244 | #ifdef _NSS_DEBUG | 
|---|
| 245 | extern  void             _nsdbtdump(const ns_dbt *); | 
|---|
| 246 | #endif | 
|---|
| 247 | #endif /* _NS_PRIVATE */ | 
|---|
| 248 |  | 
|---|
| 249 | __END_DECLS | 
|---|
| 250 |  | 
|---|
| 251 | #endif /* !_NSSWITCH_H */ | 
|---|