xref: /titanic_52/usr/src/lib/libc/inc/nsswitch_priv.h (revision d58fda4376e4bf67072ce2e69f6f47036f9dbb68)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * nsswitch_priv.h
29  *
30  * The original switch low level interface to switch was defined in
31  * /usr/include/nsswitch.h.  Although it was marked "Project Private",
32  * it was none-the-less "exposed" and used by several apps.  This
33  * file, nsswitch_priv.h will *not* go in /usr/include to limit "exposure"
34  * and contains new versions of the switch low level interface.
35  *
36  * This is a Project Private interface.  It may change in future releases.
37  *	==== ^^^^^^^^^^^^^^^ ?
38  */
39 
40 #ifndef _NSSWITCH_PRIV_H
41 #define	_NSSWITCH_PRIV_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #include <nsswitch.h>
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 
52 #define	__NSW_STD_ERRS_V1	5 /* V1 number of reserved errors */
53 
54 /*
55  * Results: the first of which are from /usr/include/nsswitch.h
56  *
57  * #define	__NSW_SUCCESS	0	 found the required data
58  * #define	__NSW_NOTFOUND	1 the naming service returned lookup failure
59  * #define	__NSW_UNAVAIL	2	 could not call the naming service
60  * #define	__NSW_TRYAGAIN	3	 bind error to suggest a retry
61  */
62 
63 /* nis server in dns forwarding mode and dns server non-response */
64 #define	__NSW_NISSERVDNS_TRYAGAIN	4
65 
66 /*
67  * Actions: the first of which are from /usr/include/nsswitch.h
68  *
69  * #define	__NSW_CONTINUE	0 the action is to continue to next service
70  * #define	__NSW_RETURN	1 the action is to return to the user
71  */
72 
73 /* the action is to retry the request until we get an answer */
74 #define	__NSW_TRYAGAIN_FOREVER	2
75 /* the action is to retry the request N times maximum */
76 #define	__NSW_TRYAGAIN_NTIMES	3
77 /* retried N times so disable try-again until service is restored */
78 #define	__NSW_TRYAGAIN_PAUSED	4
79 
80 /* is this action available to all switch errs? */
81 #define	__NSW_COMMON_ACTION(act)\
82 	(((act) == __NSW_CONTINUE) || ((act) == __NSW_RETURN))
83 
84 #define	__NSW_SUCCESS_ACTION(act)	__NSW_COMMON_ACTION(act)
85 #define	__NSW_NOTFOUND_ACTION(act)	__NSW_COMMON_ACTION(act)
86 #define	__NSW_UNAVAIL_ACTION(act)	__NSW_COMMON_ACTION(act)
87 #define	__NSW_TRYAGAIN_ACTION(act) \
88 	(__NSW_COMMON_ACTION(act) || \
89 	    ((act) == __NSW_TRYAGAIN_FOREVER) || \
90 	    ((act) == __NSW_TRYAGAIN_NTIMES))
91 #define	__NSW_UNPAUSE_ACTION(act)\
92 	(((act) == __NSW_TRYAGAIN_PAUSED) && ((act) = __NSW_TRYAGAIN_NTIMES))
93 
94 #define	__NSW_STR_FOREVER	"forever"
95 
96 #ifdef __NSS_PRIVATE_INTERFACE
97 #define	__NSL_FILE_BUF_SIZE	1024
98 
99 /* To avoid the 256 file descriptor limitation in stdio, we use our own */
100 /* private version of stdio functions. A modified FILE structure is used */
101 /* in our private stdio functions. We support only read mode access in */
102 /* this private stdio implementation. */
103 
104 typedef struct {
105 	unsigned char	*_nsl_base;	/* __NSL_FILE_BUF_SIZE */
106 	int		_nsl_file;	/* an integer datatype to hold */
107 					/* the file pointer */
108 
109 	int		_nsl_cnt;	/* number of bytes available to read */
110 					/* in the buffer */
111 
112 	unsigned char	*_nsl_ptr; /* location of next byte in buffer to read */
113 } __NSL_FILE;
114 
115 struct __nsw_lookup_v1 {
116 	char *service_name;
117 	action_t actions[__NSW_STD_ERRS_V1];
118 	int max_retries;  /* for TRYAGAIN=N */
119 	struct __nsw_long_err *long_errs;
120 	struct __nsw_lookup_v1 *next;
121 };
122 
123 struct __nsw_switchconfig_v1 {
124 	int vers;
125 	char *dbase;
126 	int num_lookups;
127 	struct __nsw_lookup_v1 *lookups;
128 };
129 
130 #define	__NSW_ACTION_V1(lkp, err) 	\
131 	((lkp)->next == NULL ? \
132 		__NSW_RETURN \
133 	: \
134 		((err) >= 0 && (err) < __NSW_STD_ERRS_V1 ? \
135 			(lkp)->actions[err] \
136 		: \
137 			__nsw_extended_action_v1(lkp, err)))
138 
139 
140 struct __nsw_switchconfig_v1 *__nsw_getconfig_v1
141 	(const char *, enum __nsw_parse_err *);
142 int __nsw_freeconfig_v1(struct __nsw_switchconfig_v1 *);
143 action_t __nsw_extended_action_v1(struct __nsw_lookup_v1 *, int);
144 
145 extern __NSL_FILE	*__nsl_c_fopen(const char *filename, const char *mode);
146 extern int 		__nsl_c_fclose(__NSL_FILE *stream);
147 extern char		*__nsl_c_fgets(char *s, int n, __NSL_FILE *stream);
148 
149 #endif /* __NSS_PRIVATE_INTERFACE */
150 
151 #ifdef	__cplusplus
152 }
153 #endif
154 
155 #endif /* _NSSWITCH_PRIV_H */
156