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