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