xref: /illumos-gate/usr/src/lib/nsswitch/ldap/common/ldap_common.h (revision 734b6a94890be549309b21156f8ed6d4561cac51)
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 2006 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 /*
80  * Superset the nss_backend_t abstract data type. This ADT has
81  * been extended to include ldap associated data structures.
82  */
83 
84 typedef struct ldap_backend *ldap_backend_ptr;
85 typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
86 typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
87 
88 struct ldap_backend {
89 	ldap_backend_op_t	*ops;
90 	nss_dbop_t		nops;
91 	char			*tablename;
92 	void			*enumcookie;
93 	char			*filter;
94 	int			setcalled;
95 	const char		**attrs;
96 	ns_ldap_result_t	*result;
97 	fnf			ldapobj2ent;
98 	void			*netgroup_cookie;
99 	void			*services_cookie;
100 	char			*toglue;
101 };
102 
103 extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
104 extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
105 extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
106 extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
107 nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
108 			char *tablename, const char **attrs, fnf ldapobj2ent);
109 extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
110 			nss_XbyY_args_t *argp, char *database,
111 			char *searchfilter, char *domain,
112 			int (*init_filter_cb)(
113 				const ns_ldap_search_desc_t *desc,
114 				char **realfilter, const void *userdata),
115 			const void *userdata);
116 extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
117 			nss_XbyY_args_t *argp, char *database,
118 			char *searchfilter, char *domain,
119 			int (*init_filter_cb)(
120 				const ns_ldap_search_desc_t *desc,
121 				char **realfilter, const void *userdata),
122 			const void *userdata);
123 extern void		_clean_ldap_backend(ldap_backend_ptr be);
124 
125 extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
126 extern const char *_strip_quotes(char *ipaddress);
127 extern int __nss2herrno(nss_status_t nsstat);
128 extern int propersubdomain(char *domain, char *subdomain);
129 extern int chophostdomain(char *string, char *host, char *domain);
130 extern char *_get_domain_name(char *cdn);
131 extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
132 	char **realfilter, const void *userdata);
133 extern int _ldap_filter_name(char *filter_name, const char *name,
134 	int filter_name_size);
135 extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
136 
137 extern void _nss_services_cookie_free(void **cookieP);
138 
139 #ifdef DEBUG
140 extern int printresult(ns_ldap_result_t *result);
141 #endif /* DEBUG */
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif	/* _LDAP_COMMON_H */
148