xref: /titanic_50/usr/src/lib/nsswitch/compat/common/compat_common.h (revision bdb9230ac765cb7af3fc1f4119caf2c5720dceb3)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Common code and structures used by name-service-switch "compat" backends.
27  */
28 
29 #ifndef _COMPAT_COMMON_H
30 #define	_COMPAT_COMMON_H
31 
32 #include <nss_common.h>
33 #include <nss_dbdefs.h>
34 #include <stdio.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct compat_backend *compat_backend_ptr_t;
41 typedef nss_status_t	(*compat_backend_op_t)(compat_backend_ptr_t, void *);
42 
43 /*
44  * ===> Fix da comments (and in files_common.h too...)
45  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
46  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
47  *   other values don't make much sense.  In other words we're abusing
48  *   (overloading) the meaning of nss_status_t, but hey...
49  * _nss_compat_XY_all() is a wrapper around _nss_files_do_all() that does the
50  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
51  */
52 typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
53 /* ===> ^^ nuke this line */
54 typedef int		(*compat_XY_check_func)(nss_XbyY_args_t *);
55 typedef const char 	*(*compat_get_name)(nss_XbyY_args_t *);
56 typedef int		(*compat_merge_func)(compat_backend_ptr_t,
57 					    nss_XbyY_args_t	*,
58 					    const char		**fields);
59 
60 typedef struct setofstrings	*strset_t;
61 
62 struct compat_backend {
63 	compat_backend_op_t	*ops;
64 	int			n_ops;
65 	const char		*filename;
66 	FILE			*f;
67 	int			minbuf;
68 	char			*buf;
69 	int			linelen;	/* <== Explain use, lifetime */
70 
71 	nss_db_initf_t		db_initf;
72 	nss_db_root_t		*db_rootp;	/* Shared between instances */
73 	nss_getent_t		db_context;	/* Per-instance enumeration */
74 
75 	compat_get_name		getnamef;
76 	compat_merge_func	mergef;
77 
78 	/* We wouldn't need all this hokey state stuff if we */
79 	/*   used another thread to implement a coroutine... */
80 	enum {
81 		GETENT_FILE,
82 		GETENT_NETGROUP,
83 		GETENT_ATTRDB,
84 		GETENT_ALL,
85 		GETENT_DONE
86 	}			state;
87 	strset_t		minuses;
88 
89 	int			permit_netgroups;
90 	const char		*yp_domain;
91 	nss_backend_t		*getnetgrent_backend;
92 	char			*netgr_buffer;
93 	int			return_string_data;
94 	int			(*str2ent_save)();
95 	int			(*str2ent_alt)();
96 	void			*workarea;
97 };
98 
99 #if defined(__STDC__)
100 extern nss_backend_t	*_nss_compat_constr(compat_backend_op_t	*ops,
101 					    int			n_ops,
102 					    const char		*filename,
103 					    int			min_bufsize,
104 					    nss_db_root_t	*rootp,
105 					    nss_db_initf_t	initf,
106 					    int			netgroups,
107 					    compat_get_name	getname_func,
108 					    compat_merge_func	merge_func);
109 extern nss_status_t	_nss_compat_destr(compat_backend_ptr_t, void *dummy);
110 extern nss_status_t	_nss_compat_setent(compat_backend_ptr_t, void *dummy);
111 extern nss_status_t	_nss_compat_endent(compat_backend_ptr_t, void *dummy);
112 extern nss_status_t	_nss_compat_getent(compat_backend_ptr_t, void *);
113 extern nss_status_t 	_nss_compat_XY_all(compat_backend_ptr_t,
114 					nss_XbyY_args_t	*args,
115 					compat_XY_check_func	check,
116 					nss_dbop_t		op_num);
117 extern nss_status_t 	_attrdb_compat_XY_all(compat_backend_ptr_t,
118 					nss_XbyY_args_t	*args,
119 					int netdb,
120 					compat_XY_check_func	check,
121 					nss_dbop_t		op_num);
122 #else
123 extern nss_backend_t	*_nss_compat_constr();
124 extern nss_status_t	_nss_compat_destr();
125 extern nss_status_t	_nss_compat_setent();
126 extern nss_status_t	_nss_compat_endent();
127 extern nss_status_t	_nss_compat_getent();
128 extern nss_status_t	_nss_compat_XY_all();
129 extern nss_status_t	_attrdb_compat_XY_all();
130 #endif
131 
132 /* functions to validate passwd and group ids */
133 extern int validate_passwd_ids(char *line, int *linelenp, int buflen,
134 	int extra_chars);
135 extern int validate_group_ids(char *line, int *linelenp, int buflen,
136 	int extra_chars);
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif /* _COMPAT_COMMON_H */
143