xref: /titanic_50/usr/src/lib/nsswitch/files/common/files_common.h (revision 60471b7bbfab236de7d8776aed871d919c5f81c3)
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 #include <nss_common.h>
35 #include <nss_dbdefs.h>
36 #include <stdio.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct files_backend *files_backend_ptr_t;
43 typedef nss_status_t	(*files_backend_op_t)(files_backend_ptr_t, void *);
44 
45 typedef uint_t (*files_hash_func)(nss_XbyY_args_t *, int, const char *, int);
46 
47 typedef struct files_hashent {
48 	struct files_hashent	*h_first;
49 	struct files_hashent	*h_next;
50 	uint_t			h_hash;
51 } files_hashent_t;
52 
53 typedef struct {
54 	char			*l_start;
55 	int			l_len;
56 } files_linetab_t;
57 
58 typedef struct {
59 	mutex_t		fh_lock;
60 	int		fh_resultsize;
61 	int		fh_bufsize;
62 	int		fh_nhtab;
63 	files_hash_func	*fh_hash_func;
64 	int		fh_refcnt;
65 	int		fh_size;
66 	timestruc_t	fh_mtime;
67 	char		*fh_file_start;
68 	char		*fh_file_end;
69 	files_linetab_t	*fh_line;
70 	files_hashent_t	*fh_table;
71 } files_hash_t;
72 
73 struct files_backend {
74 	files_backend_op_t	*ops;
75 	int			n_ops;
76 	const char		*filename;
77 	FILE			*f;
78 	int			minbuf;
79 	char			*buf;
80 	files_hash_t		*hashinfo;
81 };
82 
83 /*
84  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
85  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
86  *   other values don't make much sense.  In other words we're abusing
87  *   (overloading) the meaning of nss_status_t, but hey...
88  * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the
89  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
90  */
91 typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
92 typedef int		(*files_XY_check_func)(nss_XbyY_args_t *,
93 						const char *, int);
94 
95 #if defined(__STDC__)
96 extern nss_backend_t	*_nss_files_constr(files_backend_op_t	*ops,
97 					int			n_ops,
98 					const char		*filename,
99 					int			min_bufsize,
100 					files_hash_t		*fhp);
101 extern nss_status_t	_nss_files_destr(files_backend_ptr_t, void *dummy);
102 extern nss_status_t	_nss_files_setent(files_backend_ptr_t, void *dummy);
103 extern nss_status_t	_nss_files_endent(files_backend_ptr_t, void *dummy);
104 extern nss_status_t	_nss_files_getent_rigid(files_backend_ptr_t, void *);
105 extern nss_status_t	_nss_files_getent_netdb(files_backend_ptr_t, void *);
106 extern nss_status_t 	_nss_files_do_all(files_backend_ptr_t,
107 					void			*func_priv,
108 					const char		*filter,
109 					files_do_all_func_t	func);
110 extern nss_status_t 	_nss_files_XY_all(files_backend_ptr_t	be,
111 					nss_XbyY_args_t		*args,
112 					int 			netdb,
113 					const char		*filter,
114 					files_XY_check_func	check);
115 extern nss_status_t 	_nss_files_XY_hash(files_backend_ptr_t	be,
116 					nss_XbyY_args_t		*args,
117 					int 			netdb,
118 					files_hash_t		*fhp,
119 					int			hashop,
120 					files_XY_check_func	check);
121 int _nss_files_read_line(FILE *f, char *buffer, int	buflen);
122 #else
123 extern nss_backend_t	*_nss_files_constr();
124 extern nss_status_t	_nss_files_destr();
125 extern nss_status_t	_nss_files_setent();
126 extern nss_status_t	_nss_files_endent();
127 extern nss_status_t	_nss_files_getent_rigid();
128 extern nss_status_t	_nss_files_getent_netdb();
129 extern nss_status_t	_nss_files_do_all();
130 extern nss_status_t	_nss_files_XY_all();
131 extern nss_status_t	_nss_files_XY_hash();
132 #endif
133 
134 int	_nss_files_check_name_aliases(nss_XbyY_args_t *, const char *, int);
135 int	_nss_files_check_name_colon(nss_XbyY_args_t *, const char *, int);
136 
137 /* passwd and group validation functions */
138 extern int	validate_group_ids(char *line, int *linelenp, int buflen,
139 			int extra_chars, files_XY_check_func check);
140 extern int	validate_passwd_ids(char *line, int *linelenp, int buflen,
141 			int extra_chars);
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif /* _FILES_COMMON_H */
148