xref: /freebsd/include/nsswitch.h (revision ee2ea5ceafed78a5bd9810beb9e3ca927180c226)
1 /*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
2 /*	$FreeBSD$ */
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 
45 #include <stdarg.h>
46 
47 #ifndef _PATH_NS_CONF
48 #define _PATH_NS_CONF	"/etc/nsswitch.conf"
49 #endif
50 
51 #define	NS_CONTINUE	0
52 #define	NS_RETURN	1
53 
54 #define	NS_SUCCESS	(1<<0)		/* entry was found */
55 #define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
56 #define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
57 #define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retrys */
58 #define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
59 
60 /*
61  * currently implemented sources
62  */
63 #define NSSRC_FILES	"files"		/* local files */
64 #define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
65 #define	NSSRC_NIS	"nis"		/* YP/NIS */
66 #define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
67 
68 /*
69  * currently implemented databases
70  */
71 #define NSDB_HOSTS		"hosts"
72 #define NSDB_GROUP		"group"
73 #define NSDB_GROUP_COMPAT	"group_compat"
74 #define NSDB_NETGROUP		"netgroup"
75 #define NSDB_NETWORKS		"networks"
76 #define NSDB_PASSWD		"passwd"
77 #define NSDB_PASSWD_COMPAT	"passwd_compat"
78 #define NSDB_SHELLS		"shells"
79 
80 /*
81  * suggested databases to implement
82  */
83 #define NSDB_ALIASES		"aliases"
84 #define NSDB_AUTH		"auth"
85 #define NSDB_AUTOMOUNT		"automount"
86 #define NSDB_BOOTPARAMS		"bootparams"
87 #define NSDB_ETHERS		"ethers"
88 #define NSDB_EXPORTS		"exports"
89 #define NSDB_NETMASKS		"netmasks"
90 #define NSDB_PHONES		"phones"
91 #define NSDB_PRINTCAP		"printcap"
92 #define NSDB_PROTOCOLS		"protocols"
93 #define NSDB_REMOTE		"remote"
94 #define NSDB_RPC		"rpc"
95 #define NSDB_SENDMAILVARS	"sendmailvars"
96 #define NSDB_SERVICES		"services"
97 #define NSDB_TERMCAP		"termcap"
98 #define NSDB_TTYS		"ttys"
99 
100 /*
101  * ns_dtab - `nsswitch dispatch table'
102  * contains an entry for each source and the appropriate function to call
103  */
104 typedef struct {
105 	const char	 *src;
106 	int		(*callback)(void *retval, void *cb_data, va_list ap);
107 	void		 *cb_data;
108 } ns_dtab;
109 
110 /*
111  * macros to help build an ns_dtab[]
112  */
113 #define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
114 #define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
115 
116 #ifdef HESIOD
117 #   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
118 #else
119 #   define NS_DNS_CB(F,C)
120 #endif
121 
122 #ifdef YP
123 #   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
124 #else
125 #   define NS_NIS_CB(F,C)
126 #endif
127 
128 /*
129  * ns_src - `nsswitch source'
130  * used by the nsparser routines to store a mapping between a source
131  * and its dispatch control flags for a given database.
132  */
133 typedef struct {
134 	const char	*name;
135 	u_int32_t	 flags;
136 } ns_src;
137 
138 
139 /*
140  * default sourcelist (if nsswitch.conf is missing, corrupt,
141  * or the requested database doesn't have an entry.
142  */
143 extern const ns_src __nsdefaultsrc[];
144 
145 
146 #ifdef _NS_PRIVATE
147 
148 /*
149  * private data structures for back-end nsswitch implementation
150  */
151 
152 /*
153  * ns_dbt - `nsswitch database thang'
154  * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
155  * name and a list of ns_src's containing the source information.
156  */
157 typedef struct {
158 	const char	*name;		/* name of database */
159 	ns_src		*srclist;	/* list of sources */
160 	int		 srclistsize;	/* size of srclist */
161 } ns_dbt;
162 
163 #endif /* _NS_PRIVATE */
164 
165 
166 #include <sys/cdefs.h>
167 
168 __BEGIN_DECLS
169 extern	int	nsdispatch(void *, const ns_dtab [], const char *,
170 			   const char *, const ns_src [], ...);
171 
172 #ifdef _NS_PRIVATE
173 extern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
174 extern	void		 _nsdbtdump(const ns_dbt *);
175 extern	const ns_dbt	*_nsdbtget(const char *);
176 extern	void		 _nsdbtput(const ns_dbt *);
177 extern	void		 _nsyyerror(const char *);
178 extern	int		 _nsyylex(void);
179 extern	int		 _nsyylineno;
180 #endif /* _NS_PRIVATE */
181 
182 __END_DECLS
183 
184 #endif /* !_NSSWITCH_H */
185