1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1995-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * Common code and structures used by name-service-switch "files" backends.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #ifndef _FILES_COMMON_H
30*0Sstevel@tonic-gate #define	_FILES_COMMON_H
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include "synonyms.h"
35*0Sstevel@tonic-gate #include <nss_common.h>
36*0Sstevel@tonic-gate #include <nss_dbdefs.h>
37*0Sstevel@tonic-gate #include <stdio.h>
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include "../../../libnsl/include/nsl_stdio_prv.h"
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #ifdef	__cplusplus
42*0Sstevel@tonic-gate extern "C" {
43*0Sstevel@tonic-gate #endif
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate typedef struct files_backend *files_backend_ptr_t;
46*0Sstevel@tonic-gate typedef nss_status_t	(*files_backend_op_t)(files_backend_ptr_t, void *);
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate typedef u_int (*files_hash_func)(nss_XbyY_args_t *, int);
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate typedef struct files_hashent {
51*0Sstevel@tonic-gate 	struct files_hashent	*h_first;
52*0Sstevel@tonic-gate 	struct files_hashent	*h_next;
53*0Sstevel@tonic-gate 	u_int			h_hash;
54*0Sstevel@tonic-gate } files_hashent_t;
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate typedef struct {
57*0Sstevel@tonic-gate 	char			*l_start;
58*0Sstevel@tonic-gate 	int			l_len;
59*0Sstevel@tonic-gate } files_linetab_t;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate typedef struct {
62*0Sstevel@tonic-gate 	mutex_t		fh_lock;
63*0Sstevel@tonic-gate 	int		fh_resultsize;
64*0Sstevel@tonic-gate 	int		fh_bufsize;
65*0Sstevel@tonic-gate 	int		fh_nhtab;
66*0Sstevel@tonic-gate 	files_hash_func	*fh_hash_func;
67*0Sstevel@tonic-gate 	int		fh_refcnt;
68*0Sstevel@tonic-gate 	int		fh_size;
69*0Sstevel@tonic-gate 	timestruc_t	fh_mtime;
70*0Sstevel@tonic-gate 	char		*fh_file_start;
71*0Sstevel@tonic-gate 	char		*fh_file_end;
72*0Sstevel@tonic-gate 	files_linetab_t	*fh_line;
73*0Sstevel@tonic-gate 	files_hashent_t	*fh_table;
74*0Sstevel@tonic-gate } files_hash_t;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate struct files_backend {
77*0Sstevel@tonic-gate 	files_backend_op_t	*ops;
78*0Sstevel@tonic-gate 	int			n_ops;
79*0Sstevel@tonic-gate 	const char		*filename;
80*0Sstevel@tonic-gate 	__NSL_FILE		*f;
81*0Sstevel@tonic-gate 	int			minbuf;
82*0Sstevel@tonic-gate 	char			*buf;
83*0Sstevel@tonic-gate 	files_hash_t		*hashinfo;
84*0Sstevel@tonic-gate };
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
88*0Sstevel@tonic-gate  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
89*0Sstevel@tonic-gate  *   other values don't make much sense.  In other words we're abusing
90*0Sstevel@tonic-gate  *   (overloading) the meaning of nss_status_t, but hey...
91*0Sstevel@tonic-gate  * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the
92*0Sstevel@tonic-gate  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
93*0Sstevel@tonic-gate  */
94*0Sstevel@tonic-gate typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
95*0Sstevel@tonic-gate typedef int		(*files_XY_check_func)(nss_XbyY_args_t *);
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate #if defined(__STDC__)
98*0Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr(files_backend_op_t	*ops,
99*0Sstevel@tonic-gate 					int			n_ops,
100*0Sstevel@tonic-gate 					const char		*filename,
101*0Sstevel@tonic-gate 					int			min_bufsize,
102*0Sstevel@tonic-gate 					files_hash_t		*fhp);
103*0Sstevel@tonic-gate extern nss_status_t	_nss_files_destr (files_backend_ptr_t, void *dummy);
104*0Sstevel@tonic-gate extern nss_status_t	_nss_files_setent(files_backend_ptr_t, void *dummy);
105*0Sstevel@tonic-gate extern nss_status_t	_nss_files_endent(files_backend_ptr_t, void *dummy);
106*0Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid(files_backend_ptr_t, void *);
107*0Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb(files_backend_ptr_t, void *);
108*0Sstevel@tonic-gate extern nss_status_t 	_nss_files_do_all(files_backend_ptr_t,
109*0Sstevel@tonic-gate 					void			*func_priv,
110*0Sstevel@tonic-gate 					const char		*filter,
111*0Sstevel@tonic-gate 					files_do_all_func_t	func);
112*0Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_all(files_backend_ptr_t	be,
113*0Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
114*0Sstevel@tonic-gate 					int 			netdb,
115*0Sstevel@tonic-gate 					const char		*filter,
116*0Sstevel@tonic-gate 					files_XY_check_func	check);
117*0Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_hash(files_backend_ptr_t	be,
118*0Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
119*0Sstevel@tonic-gate 					int 			netdb,
120*0Sstevel@tonic-gate 					files_hash_t		*fhp,
121*0Sstevel@tonic-gate 					int			hashop,
122*0Sstevel@tonic-gate 					files_XY_check_func	check);
123*0Sstevel@tonic-gate int _nss_files_read_line(__NSL_FILE *f, char *buffer, int	buflen);
124*0Sstevel@tonic-gate #else
125*0Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr();
126*0Sstevel@tonic-gate extern nss_status_t	_nss_files_destr ();
127*0Sstevel@tonic-gate extern nss_status_t	_nss_files_setent();
128*0Sstevel@tonic-gate extern nss_status_t	_nss_files_endent();
129*0Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid();
130*0Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb();
131*0Sstevel@tonic-gate extern nss_status_t	_nss_files_do_all();
132*0Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_all();
133*0Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_hash();
134*0Sstevel@tonic-gate #endif
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate #ifdef	__cplusplus
137*0Sstevel@tonic-gate }
138*0Sstevel@tonic-gate #endif
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate #endif /* _FILES_COMMON_H */
141