nsswitch.h revision 93032
165532Snectar/*	$NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $	*/
265532Snectar/*	$FreeBSD: head/include/nsswitch.h 93032 2002-03-23 17:24:55Z imp $ */
365532Snectar
465532Snectar/*-
565532Snectar * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
665532Snectar * All rights reserved.
765532Snectar *
865532Snectar * This code is derived from software contributed to The NetBSD Foundation
965532Snectar * by Luke Mewburn.
1065532Snectar *
1165532Snectar * Redistribution and use in source and binary forms, with or without
1265532Snectar * modification, are permitted provided that the following conditions
1365532Snectar * are met:
1465532Snectar * 1. Redistributions of source code must retain the above copyright
1565532Snectar *    notice, this list of conditions and the following disclaimer.
1665532Snectar * 2. Redistributions in binary form must reproduce the above copyright
1765532Snectar *    notice, this list of conditions and the following disclaimer in the
1865532Snectar *    documentation and/or other materials provided with the distribution.
1965532Snectar * 3. All advertising materials mentioning features or use of this software
2065532Snectar *    must display the following acknowledgement:
2165532Snectar *        This product includes software developed by the NetBSD
2265532Snectar *        Foundation, Inc. and its contributors.
2365532Snectar * 4. Neither the name of The NetBSD Foundation nor the names of its
2465532Snectar *    contributors may be used to endorse or promote products derived
2565532Snectar *    from this software without specific prior written permission.
2665532Snectar *
2765532Snectar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2865532Snectar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2965532Snectar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3065532Snectar * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3165532Snectar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3265532Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3365532Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3465532Snectar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3565532Snectar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3665532Snectar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3765532Snectar * POSSIBILITY OF SUCH DAMAGE.
3865532Snectar */
3965532Snectar
4065532Snectar#ifndef _NSSWITCH_H
4165532Snectar#define _NSSWITCH_H	1
4265532Snectar
4365532Snectar#include <sys/types.h>
4465532Snectar
4565532Snectar#include <stdarg.h>
4665532Snectar
4765532Snectar#ifndef _PATH_NS_CONF
4865532Snectar#define _PATH_NS_CONF	"/etc/nsswitch.conf"
4965532Snectar#endif
5065532Snectar
5165532Snectar#define	NS_CONTINUE	0
5265532Snectar#define	NS_RETURN	1
5365532Snectar
5465532Snectar#define	NS_SUCCESS	(1<<0)		/* entry was found */
5565532Snectar#define	NS_UNAVAIL	(1<<1)		/* source not responding, or corrupt */
5665532Snectar#define	NS_NOTFOUND	(1<<2)		/* source responded 'no such entry' */
5765532Snectar#define	NS_TRYAGAIN	(1<<3)		/* source busy, may respond to retrys */
5865532Snectar#define	NS_STATUSMASK	0x000000ff	/* bitmask to get the status flags */
5965532Snectar
6065532Snectar/*
6165532Snectar * currently implemented sources
6265532Snectar */
6365532Snectar#define NSSRC_FILES	"files"		/* local files */
6465532Snectar#define	NSSRC_DNS	"dns"		/* DNS; IN for hosts, HS for others */
6565532Snectar#define	NSSRC_NIS	"nis"		/* YP/NIS */
6665532Snectar#define	NSSRC_COMPAT	"compat"	/* passwd,group in YP compat mode */
6765532Snectar
6865532Snectar/*
6965532Snectar * currently implemented databases
7065532Snectar */
7165532Snectar#define NSDB_HOSTS		"hosts"
7265532Snectar#define NSDB_GROUP		"group"
7365532Snectar#define NSDB_GROUP_COMPAT	"group_compat"
7465532Snectar#define NSDB_NETGROUP		"netgroup"
7565532Snectar#define NSDB_NETWORKS		"networks"
7665532Snectar#define NSDB_PASSWD		"passwd"
7765532Snectar#define NSDB_PASSWD_COMPAT	"passwd_compat"
7865532Snectar#define NSDB_SHELLS		"shells"
7965532Snectar
8065532Snectar/*
8165532Snectar * suggested databases to implement
8265532Snectar */
8365532Snectar#define NSDB_ALIASES		"aliases"
8465532Snectar#define NSDB_AUTH		"auth"
8565532Snectar#define NSDB_AUTOMOUNT		"automount"
8665532Snectar#define NSDB_BOOTPARAMS		"bootparams"
8765532Snectar#define NSDB_ETHERS		"ethers"
8865532Snectar#define NSDB_EXPORTS		"exports"
8965532Snectar#define NSDB_NETMASKS		"netmasks"
9065532Snectar#define NSDB_PHONES		"phones"
9165532Snectar#define NSDB_PRINTCAP		"printcap"
9265532Snectar#define NSDB_PROTOCOLS		"protocols"
9365532Snectar#define NSDB_REMOTE		"remote"
9465532Snectar#define NSDB_RPC		"rpc"
9565532Snectar#define NSDB_SENDMAILVARS	"sendmailvars"
9665532Snectar#define NSDB_SERVICES		"services"
9765532Snectar#define NSDB_TERMCAP		"termcap"
9865532Snectar#define NSDB_TTYS		"ttys"
9965532Snectar
10065532Snectar/*
10165532Snectar * ns_dtab - `nsswitch dispatch table'
10265532Snectar * contains an entry for each source and the appropriate function to call
10365532Snectar */
10465532Snectartypedef struct {
10565532Snectar	const char	 *src;
10665532Snectar	int		(*callback)(void *retval, void *cb_data, va_list ap);
10765532Snectar	void		 *cb_data;
10865532Snectar} ns_dtab;
10965532Snectar
11065532Snectar/*
11165532Snectar * macros to help build an ns_dtab[]
11265532Snectar */
11365532Snectar#define NS_FILES_CB(F,C)	{ NSSRC_FILES,	F,	C },
11465532Snectar#define NS_COMPAT_CB(F,C)	{ NSSRC_COMPAT,	F,	C },
11565532Snectar
11665532Snectar#ifdef HESIOD
11765532Snectar#   define NS_DNS_CB(F,C)	{ NSSRC_DNS,	F,	C },
11865532Snectar#else
11965532Snectar#   define NS_DNS_CB(F,C)
12065532Snectar#endif
12165532Snectar
12265532Snectar#ifdef YP
12365532Snectar#   define NS_NIS_CB(F,C)	{ NSSRC_NIS,	F,	C },
12465532Snectar#else
12565532Snectar#   define NS_NIS_CB(F,C)
12665532Snectar#endif
12765532Snectar
12865532Snectar/*
12965532Snectar * ns_src - `nsswitch source'
13065532Snectar * used by the nsparser routines to store a mapping between a source
13165532Snectar * and its dispatch control flags for a given database.
13265532Snectar */
13365532Snectartypedef struct {
13465532Snectar	const char	*name;
13565532Snectar	u_int32_t	 flags;
13665532Snectar} ns_src;
13765532Snectar
13865532Snectar
13965532Snectar/*
14065532Snectar * default sourcelist (if nsswitch.conf is missing, corrupt,
14165532Snectar * or the requested database doesn't have an entry.
14265532Snectar */
14365532Snectarextern const ns_src __nsdefaultsrc[];
14465532Snectar
14565532Snectar
14665532Snectar#ifdef _NS_PRIVATE
14765532Snectar
14865532Snectar/*
14965532Snectar * private data structures for back-end nsswitch implementation
15065532Snectar */
15165532Snectar
15265532Snectar/*
15365532Snectar * ns_dbt - `nsswitch database thang'
15465532Snectar * for each database in /etc/nsswitch.conf there is a ns_dbt, with its
15565532Snectar * name and a list of ns_src's containing the source information.
15665532Snectar */
15765532Snectartypedef struct {
15865532Snectar	const char	*name;		/* name of database */
15965532Snectar	ns_src		*srclist;	/* list of sources */
16065532Snectar	int		 srclistsize;	/* size of srclist */
16165532Snectar} ns_dbt;
16265532Snectar
16365532Snectar#endif /* _NS_PRIVATE */
16465532Snectar
16565532Snectar
16665532Snectar#include <sys/cdefs.h>
16765532Snectar
16865532Snectar__BEGIN_DECLS
16993032Simpextern	int	nsdispatch(void *, const ns_dtab [], const char *,
17093032Simp			   const char *, const ns_src [], ...);
17165532Snectar
17265532Snectar#ifdef _NS_PRIVATE
17393032Simpextern	void		 _nsdbtaddsrc(ns_dbt *, const ns_src *);
17493032Simpextern	void		 _nsdbtdump(const ns_dbt *);
17593032Simpextern	const ns_dbt	*_nsdbtget(const char *);
17693032Simpextern	void		 _nsdbtput(const ns_dbt *);
17793032Simpextern	void		 _nsyyerror(const char *);
17893032Simpextern	int		 _nsyylex(void);
17965532Snectarextern	int		 _nsyylineno;
18065532Snectar#endif /* _NS_PRIVATE */
18165532Snectar
18265532Snectar__END_DECLS
18365532Snectar
18465532Snectar#endif /* !_NSSWITCH_H */
185