xref: /titanic_50/usr/src/lib/nsswitch/files/common/files_common.h (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
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 2008 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 <nss_common.h>
37 #include <nss_dbdefs.h>
38 #include <stdio.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 typedef struct files_backend *files_backend_ptr_t;
45 typedef nss_status_t	(*files_backend_op_t)(files_backend_ptr_t, void *);
46 
47 typedef uint_t (*files_hash_func)(nss_XbyY_args_t *, int, const char *, int);
48 
49 typedef struct files_hashent {
50 	struct files_hashent	*h_first;
51 	struct files_hashent	*h_next;
52 	uint_t			h_hash;
53 } files_hashent_t;
54 
55 typedef struct {
56 	char			*l_start;
57 	int			l_len;
58 } files_linetab_t;
59 
60 typedef struct {
61 	mutex_t		fh_lock;
62 	int		fh_resultsize;
63 	int		fh_bufsize;
64 	int		fh_nhtab;
65 	files_hash_func	*fh_hash_func;
66 	int		fh_refcnt;
67 	int		fh_size;
68 	timestruc_t	fh_mtime;
69 	char		*fh_file_start;
70 	char		*fh_file_end;
71 	files_linetab_t	*fh_line;
72 	files_hashent_t	*fh_table;
73 } files_hash_t;
74 
75 struct files_backend {
76 	files_backend_op_t	*ops;
77 	int			n_ops;
78 	const char		*filename;
79 	FILE			*f;
80 	int			minbuf;
81 	char			*buf;
82 	files_hash_t		*hashinfo;
83 };
84 
85 /*
86  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
87  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
88  *   other values don't make much sense.  In other words we're abusing
89  *   (overloading) the meaning of nss_status_t, but hey...
90  * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the
91  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
92  */
93 typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
94 typedef int		(*files_XY_check_func)(nss_XbyY_args_t *,
95 						const char *, int);
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 int	_nss_files_check_name_aliases(nss_XbyY_args_t *, const char *, int);
137 int	_nss_files_check_name_colon(nss_XbyY_args_t *, const char *, int);
138 
139 #ifdef	__cplusplus
140 }
141 #endif
142 
143 #endif /* _FILES_COMMON_H */
144