xref: /titanic_51/usr/src/lib/nsswitch/files/common/files_common.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 1995-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Common code and structures used by name-service-switch "files" backends.
27  */
28 
29 #ifndef _FILES_COMMON_H
30 #define	_FILES_COMMON_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include "synonyms.h"
35 #include <nss_common.h>
36 #include <nss_dbdefs.h>
37 #include <stdio.h>
38 
39 #include "../../../libnsl/include/nsl_stdio_prv.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 	__NSL_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(__NSL_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