Home | History | Annotate | Line # | Download | only in gen
      1 /*	$NetBSD: gr_private.h,v 1.2 2008/04/28 20:22:59 martin 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Structures and functions used by various group(5) public functions
     34  * and their back-end implementations.
     35  * These are subject to change without notice and should not be used
     36  * outside of libc (even by third-party nss_*.so modules implementing
     37  * group(5) back-ends).
     38  */
     39 
     40 #define _GROUP_COMPAT	/* "group" defaults to compat, so always provide it */
     41 
     42 
     43 	/*
     44 	 * mutex to serialize the public group(5) functions use of the
     45 	 * back-end implementations, which may not be reentrant.
     46 	 */
     47 extern 	mutex_t		__grmutex;
     48 
     49 	/*
     50 	 * files methods
     51 	 */
     52 struct __grstate_files {	/* state shared between files methods */
     53 	int	 stayopen;	/* see getgroupent(3) */
     54 	FILE	*fp;		/* groups file handle */
     55 };
     56 
     57 extern int	__grstart_files(struct __grstate_files *);
     58 extern int	__grend_files(struct __grstate_files *);
     59 extern int	__grscan_files(int *, struct group *, char *, size_t,
     60 			struct __grstate_files *, int, const char *, gid_t);
     61 
     62 	/*
     63 	 * dns methods
     64 	 */
     65 struct __grstate_dns {		/* state shared between dns methods */
     66 	int	 stayopen;	/* see getgroupent(3) */
     67 	void	*context;	/* Hesiod context */
     68 	int	 num;		/* group index, -1 if no more */
     69 };
     70 
     71 extern int	__grstart_dns(struct __grstate_dns *);
     72 extern int	__grend_dns(struct __grstate_dns *state);
     73 extern int	__grscan_dns(int *, struct group *, char *, size_t,
     74 			struct __grstate_dns *, int, const char *, gid_t);
     75 
     76 	/*
     77 	 * nis methods
     78 	 */
     79 struct __grstate_nis {		/* state shared between nis methods */
     80 	int	 stayopen;	/* see getgroupent(3) */
     81 	char	*domain;	/* NIS domain */
     82 	int	 done;		/* non-zero if search exhausted */
     83 	char	*current;	/* current first/next match */
     84 	int	 currentlen;	/* length of _nis_current */
     85 };
     86 
     87 extern int	__grstart_nis(struct __grstate_nis *);
     88 extern int	__grend_nis(struct __grstate_nis *);
     89 extern int	__grscan_nis(int *, struct group *, char *, size_t,
     90 			struct __grstate_nis *, int, const char *, gid_t);
     91 
     92 	/*
     93 	 * compat methods
     94 	 */
     95 struct __grstate_compat {	/* state shared between compat methods */
     96 	int	 stayopen;	/* see getgroupent(3) */
     97 	FILE	*fp;		/* file handle */
     98 /*
     99  * XXX:	convert name to a separate compatstate enum and grow name as necessary
    100  *	instead of using strdup & free for each + line
    101  */
    102 	char	*name;		/* NULL if reading file,	*/
    103 				/*   "" if compat "+",		*/
    104 				/* name if compat "+name"	*/
    105 };
    106 
    107 extern int	__grbad_compat(void *nsrv, void *nscb, va_list ap);
    108 extern int	__grstart_compat(struct __grstate_compat *);
    109 extern int	__grend_compat(struct __grstate_compat *);
    110 extern int	__grscan_compat(int *, struct group *, char *, size_t,
    111 			struct __grstate_compat *, int, const char *, gid_t,
    112 			int (*)(void *, struct group **), void *);
    113