xref: /illumos-gate/usr/src/lib/nsswitch/ldap/common/ldap_common.h (revision 1a7b528f36ec61147fc237b7b9a23642fab7ad13)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_LDAP_COMMON_H
27 #define	_LDAP_COMMON_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <ctype.h>
36 #include <nss_dbdefs.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <strings.h>
40 #include <signal.h>
41 #include <lber.h>
42 #include <ldap.h>
43 #include <pwd.h>
44 #include "ns_sldap.h"
45 
46 #define	_ALIASES		"aliases"
47 #define	_AUTOMOUNT		"automount"
48 #define	_AUTHATTR		"auth_attr"
49 #define	_AUUSER			"audit_user"
50 #define	_BOOTPARAMS		"bootparams"
51 #define	_DEFAULT		"default"
52 #define	_ETHERS			"ethers"
53 #define	_EXECATTR		"exec_attr"
54 #define	_GROUP			"group"
55 #define	_PROJECT		"project"
56 #define	_HOSTS			"hosts"
57 #define	_HOSTS6			"hosts"
58 #define	_NETGROUP		"netgroup"
59 #define	_NETMASKS		"netmasks"
60 #define	_NETWORKS		"networks"
61 #define	_PASSWD			"passwd"
62 #define	_PRINTERS		"printers"
63 #define	_PROFATTR		"prof_attr"
64 #define	_PROTOCOLS		"protocols"
65 #define	_PUBLICKEY		"publickey"
66 #define	_RPC			"rpc"
67 #define	_SERVICES		"services"
68 #define	_SHADOW			"shadow"
69 #define	_USERATTR		"user_attr"
70 #define	_TNRHDB			"tnrhdb"
71 #define	_TNRHTP			"tnrhtp"
72 
73 #define	NSS_STR_PARSE_NO_ADDR	(NSS_STR_PARSE_ERANGE + 100)
74 
75 #define	DOTTEDSUBDOMAIN(string) \
76 	((string != NULL) && (strchr(string, '.') != NULL))
77 #define	SEARCHFILTERLEN		256
78 
79 #define	_NO_VALUE		""
80 
81 #define	TEST_AND_ADJUST(len, buffer, buflen, label) \
82 	    /* Use '>=' to ensure there is at least one byte left for '\0' */ \
83 	    if (len >= buflen || len < 0) { \
84 		nss_result = NSS_STR_PARSE_ERANGE; \
85 		goto label; \
86 	    } \
87 	    /* Adjust pointer and available buffer length */ \
88 	    buffer += len; \
89 	    buflen -= len;
90 
91 
92 /*
93  * Superset the nss_backend_t abstract data type. This ADT has
94  * been extended to include ldap associated data structures.
95  */
96 
97 typedef struct ldap_backend *ldap_backend_ptr;
98 typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
99 typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
100 
101 typedef enum {
102 	NSS_LDAP_DB_NONE	= 0,
103 	NSS_LDAP_DB_PUBLICKEY	= 1,
104 	NSS_LDAP_DB_ETHERS	= 2
105 } nss_ldap_db_type_t;
106 
107 struct ldap_backend {
108 	ldap_backend_op_t	*ops;
109 	nss_dbop_t		nops;
110 	char			*tablename;
111 	void			*enumcookie;
112 	char			*filter;
113 	int			setcalled;
114 	const char		**attrs;
115 	ns_ldap_result_t	*result;
116 	fnf			ldapobj2str;
117 	void			*netgroup_cookie;
118 	void			*services_cookie;
119 	char			*toglue;
120 	char			*buffer;
121 	int			buflen;
122 	nss_ldap_db_type_t	db_type;
123 };
124 
125 extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
126 extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
127 extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
128 extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
129 nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
130 			char *tablename, const char **attrs, fnf ldapobj2str);
131 extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
132 			nss_XbyY_args_t *argp, char *database,
133 			char *searchfilter, char *domain,
134 			int (*init_filter_cb)(
135 				const ns_ldap_search_desc_t *desc,
136 				char **realfilter, const void *userdata),
137 			const void *userdata);
138 extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
139 			nss_XbyY_args_t *argp, char *database,
140 			char *searchfilter, char *domain,
141 			int (*init_filter_cb)(
142 				const ns_ldap_search_desc_t *desc,
143 				char **realfilter, const void *userdata),
144 			const void *userdata);
145 extern void		_clean_ldap_backend(ldap_backend_ptr be);
146 
147 extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
148 extern const char *_strip_quotes(char *ipaddress);
149 extern int __nss2herrno(nss_status_t nsstat);
150 extern int propersubdomain(char *domain, char *subdomain);
151 extern int chophostdomain(char *string, char *host, char *domain);
152 extern char *_get_domain_name(char *cdn);
153 extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
154 	char **realfilter, const void *userdata);
155 extern int _ldap_filter_name(char *filter_name, const char *name,
156 	int filter_name_size);
157 
158 extern void _nss_services_cookie_free(void **cookieP);
159 extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
160 
161 #ifdef DEBUG
162 extern int printresult(ns_ldap_result_t *result);
163 #endif /* DEBUG */
164 
165 #ifdef	__cplusplus
166 }
167 #endif
168 
169 #endif	/* _LDAP_COMMON_H */
170