| 1 | /* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */
|
|---|
| 2 | /* $FreeBSD: src/include/nsswitch.h,v 1.3 2003/04/17 14:14:21 nectar Exp $ */
|
|---|
| 3 |
|
|---|
| 4 | /*-
|
|---|
| 5 | * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
|
|---|
| 6 | * All rights reserved.
|
|---|
| 7 | *
|
|---|
| 8 | * This code is derived from software contributed to The NetBSD Foundation
|
|---|
| 9 | * by Luke Mewburn.
|
|---|
| 10 | *
|
|---|
| 11 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 12 | * modification, are permitted provided that the following conditions
|
|---|
| 13 | * are met:
|
|---|
| 14 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 15 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 16 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 17 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 18 | * documentation and/or other materials provided with the distribution.
|
|---|
| 19 | * 3. All advertising materials mentioning features or use of this software
|
|---|
| 20 | * must display the following acknowledgement:
|
|---|
| 21 | * This product includes software developed by the NetBSD
|
|---|
| 22 | * Foundation, Inc. and its contributors.
|
|---|
| 23 | * 4. Neither the name of The NetBSD Foundation nor the names of its
|
|---|
| 24 | * contributors may be used to endorse or promote products derived
|
|---|
| 25 | * from this software without specific prior written permission.
|
|---|
| 26 | *
|
|---|
| 27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|---|
| 28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|---|
| 29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|---|
| 30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|---|
| 31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|---|
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|---|
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|---|
| 34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|---|
| 35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|---|
| 36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|---|
| 37 | * POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 38 | */
|
|---|
| 39 |
|
|---|
| 40 | #ifndef _NSSWITCH_H
|
|---|
| 41 | #define _NSSWITCH_H 1
|
|---|
| 42 |
|
|---|
| 43 | #include <sys/types.h>
|
|---|
| 44 | #include <stdarg.h>
|
|---|
| 45 |
|
|---|
| 46 | #define NSS_MODULE_INTERFACE_VERSION 1
|
|---|
| 47 |
|
|---|
| 48 | #ifndef _PATH_NS_CONF
|
|---|
| 49 | #define _PATH_NS_CONF "/etc/nsswitch.conf"
|
|---|
| 50 | #endif
|
|---|
| 51 |
|
|---|
| 52 | /* NSS source actions */
|
|---|
| 53 | #define NS_ACTION_CONTINUE 0 /* try the next source */
|
|---|
| 54 | #define NS_ACTION_RETURN 1 /* look no further */
|
|---|
| 55 |
|
|---|
| 56 | #define NS_SUCCESS (1<<0) /* entry was found */
|
|---|
| 57 | #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */
|
|---|
| 58 | #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */
|
|---|
| 59 | #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */
|
|---|
| 60 | #define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */
|
|---|
| 61 | #define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */
|
|---|
| 62 | #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */
|
|---|
| 63 |
|
|---|
| 64 | /*
|
|---|
| 65 | * currently implemented sources
|
|---|
| 66 | */
|
|---|
| 67 | #define NSSRC_FILES "files" /* local files */
|
|---|
| 68 | #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */
|
|---|
| 69 | #define NSSRC_NIS "nis" /* YP/NIS */
|
|---|
| 70 | #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */
|
|---|
| 71 |
|
|---|
| 72 | /*
|
|---|
| 73 | * currently implemented databases
|
|---|
| 74 | */
|
|---|
| 75 | #define NSDB_HOSTS "hosts"
|
|---|
| 76 | #define NSDB_GROUP "group"
|
|---|
| 77 | #define NSDB_GROUP_COMPAT "group_compat"
|
|---|
| 78 | #define NSDB_NETGROUP "netgroup"
|
|---|
| 79 | #define NSDB_NETWORKS "networks"
|
|---|
| 80 | #define NSDB_PASSWD "passwd"
|
|---|
| 81 | #define NSDB_PASSWD_COMPAT "passwd_compat"
|
|---|
| 82 | #define NSDB_SHELLS "shells"
|
|---|
| 83 |
|
|---|
| 84 | /*
|
|---|
| 85 | * suggested databases to implement
|
|---|
| 86 | */
|
|---|
| 87 | #define NSDB_ALIASES "aliases"
|
|---|
| 88 | #define NSDB_AUTH "auth"
|
|---|
| 89 | #define NSDB_AUTOMOUNT "automount"
|
|---|
| 90 | #define NSDB_BOOTPARAMS "bootparams"
|
|---|
| 91 | #define NSDB_ETHERS "ethers"
|
|---|
| 92 | #define NSDB_EXPORTS "exports"
|
|---|
| 93 | #define NSDB_NETMASKS "netmasks"
|
|---|
| 94 | #define NSDB_PHONES "phones"
|
|---|
| 95 | #define NSDB_PRINTCAP "printcap"
|
|---|
| 96 | #define NSDB_PROTOCOLS "protocols"
|
|---|
| 97 | #define NSDB_REMOTE "remote"
|
|---|
| 98 | #define NSDB_RPC "rpc"
|
|---|
| 99 | #define NSDB_SENDMAILVARS "sendmailvars"
|
|---|
| 100 | #define NSDB_SERVICES "services"
|
|---|
| 101 | #define NSDB_TERMCAP "termcap"
|
|---|
| 102 | #define NSDB_TTYS "ttys"
|
|---|
| 103 |
|
|---|
| 104 | /*
|
|---|
| 105 | * ns_dtab `method' function signature.
|
|---|
| 106 | */
|
|---|
| 107 | typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap);
|
|---|
| 108 |
|
|---|
| 109 | /*
|
|---|
| 110 | * Macro for generating method prototypes.
|
|---|
| 111 | */
|
|---|
| 112 | #define NSS_METHOD_PROTOTYPE(method) \
|
|---|
| 113 | int method(void *, void *, va_list)
|
|---|
| 114 |
|
|---|
| 115 | /*
|
|---|
| 116 | * ns_dtab - `nsswitch dispatch table'
|
|---|
| 117 | * Contains an entry for each source and the appropriate function to
|
|---|
| 118 | * call. ns_dtabs are used in the nsdispatch() API in order to allow
|
|---|
| 119 | * the application to override built-in actions.
|
|---|
| 120 | */
|
|---|
| 121 | typedef 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 | */
|
|---|
| 150 | typedef 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 | */
|
|---|
| 160 | extern 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 | */
|
|---|
| 167 | typedef 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 | */
|
|---|
| 177 | typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int);
|
|---|
| 178 |
|
|---|
| 179 | /*
|
|---|
| 180 | * NSS module registration, called at module load.
|
|---|
| 181 | */
|
|---|
| 182 | typedef 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 | */
|
|---|
| 189 | enum 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 | */
|
|---|
|
|---|