xref: /netbsd-src/lib/libc/gen/gr_private.h (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: gr_private.h,v 1.1 2005/01/06 15:00:45 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004-2005 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 /*
40  * Structures and functions used by various group(5) public functions
41  * and their back-end implementations.
42  * These are subject to change without notice and should not be used
43  * outside of libc (even by third-party nss_*.so modules implementing
44  * group(5) back-ends).
45  */
46 
47 #define _GROUP_COMPAT	/* "group" defaults to compat, so always provide it */
48 
49 
50 	/*
51 	 * mutex to serialize the public group(5) functions use of the
52 	 * back-end implementations, which may not be reentrant.
53 	 */
54 extern 	mutex_t		__grmutex;
55 
56 	/*
57 	 * files methods
58 	 */
59 struct __grstate_files {	/* state shared between files methods */
60 	int	 stayopen;	/* see getgroupent(3) */
61 	FILE	*fp;		/* groups file handle */
62 };
63 
64 extern int	__grstart_files(struct __grstate_files *);
65 extern int	__grend_files(struct __grstate_files *);
66 extern int	__grscan_files(int *, struct group *, char *, size_t,
67 			struct __grstate_files *, int, const char *, gid_t);
68 
69 	/*
70 	 * dns methods
71 	 */
72 struct __grstate_dns {		/* state shared between dns methods */
73 	int	 stayopen;	/* see getgroupent(3) */
74 	void	*context;	/* Hesiod context */
75 	int	 num;		/* group index, -1 if no more */
76 };
77 
78 extern int	__grstart_dns(struct __grstate_dns *);
79 extern int	__grend_dns(struct __grstate_dns *state);
80 extern int	__grscan_dns(int *, struct group *, char *, size_t,
81 			struct __grstate_dns *, int, const char *, gid_t);
82 
83 	/*
84 	 * nis methods
85 	 */
86 struct __grstate_nis {		/* state shared between nis methods */
87 	int	 stayopen;	/* see getgroupent(3) */
88 	char	*domain;	/* NIS domain */
89 	int	 done;		/* non-zero if search exhausted */
90 	char	*current;	/* current first/next match */
91 	int	 currentlen;	/* length of _nis_current */
92 };
93 
94 extern int	__grstart_nis(struct __grstate_nis *);
95 extern int	__grend_nis(struct __grstate_nis *);
96 extern int	__grscan_nis(int *, struct group *, char *, size_t,
97 			struct __grstate_nis *, int, const char *, gid_t);
98 
99 	/*
100 	 * compat methods
101 	 */
102 struct __grstate_compat {	/* state shared between compat methods */
103 	int	 stayopen;	/* see getgroupent(3) */
104 	FILE	*fp;		/* file handle */
105 /*
106  * XXX:	convert name to a separate compatstate enum and grow name as necessary
107  *	instead of using strdup & free for each + line
108  */
109 	char	*name;		/* NULL if reading file,	*/
110 				/*   "" if compat "+",		*/
111 				/* name if compat "+name"	*/
112 };
113 
114 extern int	__grbad_compat(void *nsrv, void *nscb, va_list ap);
115 extern int	__grstart_compat(struct __grstate_compat *);
116 extern int	__grend_compat(struct __grstate_compat *);
117 extern int	__grscan_compat(int *, struct group *, char *, size_t,
118 			struct __grstate_compat *, int, const char *, gid_t,
119 			int (*)(void *, struct group **), void *);
120