Home | History | Annotate | Line # | Download | only in include
nsswitch.h revision 1.1.2.1
      1 /*-
      2  * Copyright 1995, 1996 Luke Mewburn <lm (at) werj.com.au>.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  * 	This product includes software developed by Luke Mewburn.
     16  * 4. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     25  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     28  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  *
     30  */
     31 #ifndef _NSSWITCH_H
     32 #define _NSSWITCH_H	1
     33 
     34 #if __STDC__
     35 #include <stdarg.h>
     36 #else
     37 #include <varargs.h>
     38 #endif
     39 #include <sys/types.h>
     40 
     41 #ifndef _PATH_NS_CONF
     42 #define _PATH_NS_CONF	"/etc/nsswitch.conf"
     43 #endif
     44 
     45 #define	NS_CONTINUE	0
     46 #define	NS_RETURN	1
     47 
     48 #define	NS_SUCCESS	0x10	/* entry was found */
     49 #define	NS_UNAVAIL	0x20	/* source not responding, or corrupt */
     50 #define	NS_NOTFOUND	0x40	/* source responded 'no such entry' */
     51 #define	NS_TRYAGAIN	0x80	/* source busy, may respond to retrys */
     52 #define	NS_STATUSMASK	0xf0 	/* bitmask to get the status */
     53 
     54 #define NS_FILES	0x00	/* local files */
     55 #define	NS_DNS		0x01	/* DNS; class IN for hosts, HS for others */
     56 #define	NS_NIS		0x02	/* yp/nis */
     57 #define	NS_NISPLUS	0x03	/* nis+ */
     58 #define	NS_COMPAT	0x04	/* passwd,group in yp compat mode */
     59 #define	NS_MAXSOURCE	0x0f	/* last possible source */
     60 #define	NS_SOURCEMASK	0x0f	/* bitmask to get the source */
     61 
     62 /*
     63  * implemented databases
     64  */
     65 #define NSDB_HOSTS		"hosts"
     66 #define NSDB_GROUP		"group"
     67 #define NSDB_GROUP_COMPAT	"group_compat"
     68 #define NSDB_NETGROUP		"netgroup"
     69 #define NSDB_PASSWD		"passwd"
     70 #define NSDB_PASSWD_COMPAT	"passwd_compat"
     71 #define NSDB_SHELLS		"shells"
     72 
     73 /*
     74  * suggested databases to implement
     75  */
     76 #define NSDB_ALIASES		"aliases"
     77 #define NSDB_AUTH		"auth"
     78 #define NSDB_AUTOMOUNT		"automount"
     79 #define NSDB_BOOTPARAMS		"bootparams"
     80 #define NSDB_ETHERS		"ethers"
     81 #define NSDB_EXPORTS		"exports"
     82 #define NSDB_NETMASKS		"netmasks"
     83 #define NSDB_NETWORKS		"networks"
     84 #define NSDB_PHONES		"phones"
     85 #define NSDB_PRINTCAP		"printcap"
     86 #define NSDB_PROTOCOLS		"protocols"
     87 #define NSDB_REMOTE		"remote"
     88 #define NSDB_RPC		"rpc"
     89 #define NSDB_SENDMAILVARS	"sendmailvars"
     90 #define NSDB_SERVICES		"services"
     91 #define NSDB_TERMCAP		"termcap"
     92 #define NSDB_TTYS		"ttys"
     93 
     94 #define NS_MAXDBLEN	32	/* max len of a database name */
     95 
     96 typedef struct {
     97 	int	(*cb)(void *retval, void *cb_data, va_list ap);
     98 	void	*cb_data;
     99 } ns_dtab [NS_MAXSOURCE];
    100 
    101 typedef struct {
    102 	char	name[NS_MAXDBLEN];	/* name of database */
    103 	int	size;			/* number of entries of map */
    104 	u_char	map[NS_MAXSOURCE];	/* map, described below */
    105 } ns_DBT;
    106 /*
    107  * ns_DBT.map --
    108  *	array of sources to try in order. each number is a bitmask:
    109  *	- lower 4 bits is source type
    110  *	- upper 4 bits is action bitmap
    111  *	If source has already been set, don't add again to array
    112  */
    113 
    114 #define NS_DEFAULTMAP	(NS_FILES | NS_SUCCESS)
    115 
    116 #define NS_CB(D,E,F,C)		{ D[E].cb = F; D[E].cb_data = C; }
    117 
    118 #define NS_FILES_CB(D,F,C)	NS_CB(D, NS_FILES, F, C)
    119 
    120 #ifdef HESIOD
    121 #   define NS_DNS_CB(D,F,C)	NS_CB(D, NS_DNS, F, C)
    122 #else
    123 #   define NS_DNS_CB(D,F,C)	NS_CB(D, NS_DNS, NULL, NULL)
    124 #endif
    125 
    126 #ifdef YP
    127 #   define NS_NIS_CB(D,F,C)	NS_CB(D, NS_NIS, F, C)
    128 #else
    129 #   define NS_NIS_CB(D,F,C)	NS_CB(D, NS_NIS, NULL, NULL)
    130 #endif
    131 
    132 #ifdef NISPLUS
    133 #   define NS_NISPLUS_CB(D,F,C)	NS_CB(D, NS_NISPLUS, F, C)
    134 #else
    135 #   define NS_NISPLUS_CB(D,F,C)	NS_CB(D, NS_NISPLUS, NULL, NULL)
    136 #endif
    137 
    138 #if defined(HESIOD) || defined(YP) || defined(NISPLUS)
    139 #   define NS_COMPAT_CB(D,F,C)	NS_CB(D, NS_COMPAT, F, C)
    140 #else
    141 #   define NS_COMPAT_CB(D,F,C)	NS_CB(D, NS_COMPAT, NULL, NULL)
    142 #endif
    143 
    144 
    145 #include <sys/cdefs.h>
    146 
    147 __BEGIN_DECLS
    148 extern	void	_nsgetdbt	__P((const char *, ns_DBT *));
    149 extern	void	_nsdumpdbt	__P((const ns_DBT *));
    150 extern	int	nsdispatch	__P((void *, ns_dtab, const char *, ...));
    151 __END_DECLS
    152 
    153 #endif /* !_NSSWITCH_H */
    154