xref: /illumos-gate/usr/src/lib/nsswitch/user/common/user_common.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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 "user" backends.
29  */
30 
31 #ifndef _USER_COMMON_H
32 #define	_USER_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 user_backend *user_backend_ptr_t;
43 typedef nss_status_t	(*user_backend_op_t)(user_backend_ptr_t, void *);
44 
45 
46 
47 struct user_backend {
48 	user_backend_op_t	*ops;
49 	int			n_ops;
50 	const char		*filename;
51 	FILE			*f;
52 	int			minbuf;
53 	char			*buf;
54 };
55 
56 /*
57  * Iterator function for _nss_user_do_all()
58  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
59  *   other values don't make much sense.  In other words we're abusing
60  *   (overloading) the meaning of nss_status_t, but hey...
61  * _nss_user_XY_all() is a wrapper around _nss_user_do_all() that does the
62  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
63  */
64 typedef nss_status_t	(*user_do_all_func_t)(const char *, int, void *args);
65 typedef int		(*user_XY_check_func)(nss_XbyY_args_t *);
66 
67 #if defined(__STDC__)
68 extern nss_backend_t	*_nss_user_constr(user_backend_op_t	*ops,
69 					int			n_ops,
70 					const char		*filename,
71 					int			min_bufsize);
72 extern nss_status_t	_nss_user_destr(user_backend_ptr_t, void *dummy);
73 extern nss_status_t	_nss_user_setent(user_backend_ptr_t, void *dummy);
74 extern nss_status_t	_nss_user_endent(user_backend_ptr_t, void *dummy);
75 extern nss_status_t 	_nss_user_do_all(user_backend_ptr_t,
76 					void			*func_priv,
77 					const char		*filter,
78 					user_do_all_func_t	func);
79 extern nss_status_t 	_nss_user_XY_all(user_backend_ptr_t	be,
80 					nss_XbyY_args_t		*args,
81 					int 			netdb,
82 					const char		*filter,
83 					user_XY_check_func	check);
84 extern int		_nss_user_read_line(FILE		*f,
85 					char			*buffer,
86 					int			buflen);
87 #else
88 extern nss_backend_t	*_nss_user_constr();
89 extern nss_status_t	_nss_user_destr();
90 extern nss_status_t	_nss_user_setent();
91 extern nss_status_t	_nss_user_endent();
92 extern nss_status_t	_nss_user_do_all();
93 extern nss_status_t	_nss_user_XY_all();
94 extern int		_nss_user_read_line();
95 #endif
96 
97 #ifdef	__cplusplus
98 }
99 #endif
100 
101 #endif /* _USER_COMMON_H */
102