xref: /netbsd/include/nsswitch.h (revision bf9ec67e)
1 /*	$NetBSD: nsswitch.h,v 1.11 2000/12/20 20:47:55 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Luke Mewburn.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _NSSWITCH_H
40 #define _NSSWITCH_H	1
41 
42 /*
43  * Don't use va_list in prototypes.   Va_list is typedef'd in two places
44  * (<machine/varargs.h> and <machine/stdarg.h>), so if we include one of
45  * them here we may collide with the utility's includes.  It's unreasonable
46  * for utilities to have to include one of them to include nsswitch.h, so
47  * we get _BSD_VA_LIST_ from <machine/ansi.h> and use it.
48  */
49 #include <machine/ansi.h>
50 #include <sys/types.h>
51 
52 #ifndef _PATH_NS_CONF
53 #define _PATH_NS_CONF	"/etc/nsswitch.conf"
54 #endif
55 
56 #define	NS_CONTINUE	0
57 #define	NS_RETURN	1
58 
59 #define	NS_SUCCESS	(1<<0)		/* entry was found */
60 #define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
61 #define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
62 #define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retrys */
63 #define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
64 
65 /*
66  * currently implemented sources
67  */
68 #define NSSRC_FILES	"files"		/* local files */
69 #define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
70 #define	NSSRC_NIS	"nis"		/* YP/NIS */
71 #define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
72 
73 /*
74  * currently implemented databases
75  */
76 #define NSDB_HOSTS		"hosts"
77 #define NSDB_GROUP		"group"
78 #define NSDB_GROUP_COMPAT	"group_compat"
79 #define NSDB_NETGROUP		"netgroup"
80 #define NSDB_NETWORKS		"networks"
81 #define NSDB_PASSWD		"passwd"
82 #define NSDB_PASSWD_COMPAT	"passwd_compat"
83 #define NSDB_SHELLS		"shells"
84 
85 /*
86  * suggested databases to implement
87  */
88 #define NSDB_ALIASES		"aliases"
89 #define NSDB_AUTH		"auth"
90 #define NSDB_AUTOMOUNT		"automount"
91 #define NSDB_BOOTPARAMS		"bootparams"
92 #define NSDB_ETHERS		"ethers"
93 #define NSDB_EXPORTS		"exports"
94 #define NSDB_NETMASKS		"netmasks"
95 #define NSDB_PHONES		"phones"
96 #define NSDB_PRINTCAP		"printcap"
97 #define NSDB_PROTOCOLS		"protocols"
98 #define NSDB_REMOTE		"remote"
99 #define NSDB_RPC		"rpc"
100 #define NSDB_SENDMAILVARS	"sendmailvars"
101 #define NSDB_SERVICES		"services"
102 #define NSDB_TERMCAP		"termcap"
103 #define NSDB_TTYS		"ttys"
104 
105 /*
106  * ns_dtab - `nsswitch dispatch table'
107  * contains an entry for each source and the appropriate function to call
108  */
109 typedef struct {
110 	const char	 *src;
111 	int		(*callback) __P((void *retval, void *cb_data,
112 					_BSD_VA_LIST_));
113 	void		 *cb_data;
114 } ns_dtab;
115 
116 /*
117  * macros to help build an ns_dtab[]
118  */
119 #define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
120 #define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
121 
122 #ifdef HESIOD
123 #   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
124 #else
125 #   define NS_DNS_CB(F,C)
126 #endif
127 
128 #ifdef YP
129 #   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
130 #else
131 #   define NS_NIS_CB(F,C)
132 #endif
133 
134 /*
135  * ns_src - `nsswitch source'
136  * used by the nsparser routines to store a mapping between a source
137  * and its dispatch control flags for a given database.
138  */
139 typedef struct {
140 	const char	*name;
141 	u_int32_t	 flags;
142 } ns_src;
143 
144 
145 /*
146  * default sourcelist (if nsswitch.conf is missing, corrupt,
147  * or the requested database doesn't have an entry.
148  */
149 extern const ns_src __nsdefaultsrc[];
150 
151 
152 #ifdef _NS_PRIVATE
153 
154 /*
155  * private data structures for back-end nsswitch implementation
156  */
157 
158 /*
159  * ns_dbt - `nsswitch database thang'
160  * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
161  * name and a list of ns_src's containing the source information.
162  */
163 typedef struct {
164 	const char	*name;		/* name of database */
165 	ns_src		*srclist;	/* list of sources */
166 	int		 srclistsize;	/* size of srclist */
167 } ns_dbt;
168 
169 #endif /* _NS_PRIVATE */
170 
171 
172 #include <sys/cdefs.h>
173 
174 __BEGIN_DECLS
175 int	nsdispatch	__P((void *, const ns_dtab [], const char *,
176 			    const char *, const ns_src [], ...));
177 
178 #ifdef _NS_PRIVATE
179 int		 _nsdbtaddsrc __P((ns_dbt *, const ns_src *));
180 void		 _nsdbtdump __P((const ns_dbt *));
181 const ns_dbt	*_nsdbtget __P((const char *));
182 int		 _nsdbtput __P((const ns_dbt *));
183 void		 _nsyyerror __P((const char *));
184 int		 _nsyylex __P((void));
185 #endif /* _NS_PRIVATE */
186 
187 __END_DECLS
188 
189 #endif /* !_NSSWITCH_H */
190