xref: /titanic_50/usr/src/lib/nsswitch/ldap/common/ldap_common.h (revision 554ff184129088135ad2643c1c9832174a17be88)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LDAP_COMMON_H
28 #define	_LDAP_COMMON_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <ctype.h>
37 #include <nss_dbdefs.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <strings.h>
41 #include <signal.h>
42 #include <lber.h>
43 #include <ldap.h>
44 #include <pwd.h>
45 #include "ns_sldap.h"
46 
47 #define	_ALIASES		"aliases"
48 #define	_AUTOMOUNT		"automount"
49 #define	_AUTHATTR		"auth_attr"
50 #define	_AUUSER			"audit_user"
51 #define	_BOOTPARAMS		"bootparams"
52 #define	_DEFAULT		"default"
53 #define	_ETHERS			"ethers"
54 #define	_EXECATTR		"exec_attr"
55 #define	_GROUP			"group"
56 #define	_PROJECT		"project"
57 #define	_HOSTS			"hosts"
58 #define	_HOSTS6			"hosts"
59 #define	_NETGROUP		"netgroup"
60 #define	_NETMASKS		"netmasks"
61 #define	_NETWORKS		"networks"
62 #define	_PASSWD			"passwd"
63 #define	_PRINTERS		"printers"
64 #define	_PROFATTR		"prof_attr"
65 #define	_PROTOCOLS		"protocols"
66 #define	_PUBLICKEY		"publickey"
67 #define	_RPC			"rpc"
68 #define	_SERVICES		"services"
69 #define	_SHADOW			"shadow"
70 #define	_USERATTR		"user_attr"
71 
72 #define	NSS_STR_PARSE_NO_ADDR	(NSS_STR_PARSE_ERANGE + 100)
73 
74 #define	DOTTEDSUBDOMAIN(string) \
75 	((string != NULL) && (strchr(string, '.') != NULL))
76 #define	SEARCHFILTERLEN		256
77 
78 /*
79  * Superset the nss_backend_t abstract data type. This ADT has
80  * been extended to include ldap associated data structures.
81  */
82 
83 typedef struct ldap_backend *ldap_backend_ptr;
84 typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
85 typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
86 
87 struct ldap_backend {
88 	ldap_backend_op_t	*ops;
89 	nss_dbop_t		nops;
90 	char			*tablename;
91 	void			*enumcookie;
92 	char			*filter;
93 	int			setcalled;
94 	const char		**attrs;
95 	ns_ldap_result_t	*result;
96 	fnf			ldapobj2ent;
97 	void			*netgroup_cookie;
98 	void			*services_cookie;
99 	char			*toglue;
100 };
101 
102 extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
103 extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
104 extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
105 extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
106 nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
107 			char *tablename, const char **attrs, fnf ldapobj2ent);
108 extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
109 			nss_XbyY_args_t *argp, char *database,
110 			char *searchfilter, char *domain,
111 			int (*init_filter_cb)(
112 				const ns_ldap_search_desc_t *desc,
113 				char **realfilter, const void *userdata),
114 			const void *userdata);
115 extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
116 			nss_XbyY_args_t *argp, char *database,
117 			char *searchfilter, char *domain,
118 			int (*init_filter_cb)(
119 				const ns_ldap_search_desc_t *desc,
120 				char **realfilter, const void *userdata),
121 			const void *userdata);
122 extern void		_clean_ldap_backend(ldap_backend_ptr be);
123 
124 extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
125 extern const char *_strip_quotes(char *ipaddress);
126 extern int __nss2herrno(nss_status_t nsstat);
127 extern int propersubdomain(char *domain, char *subdomain);
128 extern int chophostdomain(char *string, char *host, char *domain);
129 extern char *_get_domain_name(char *cdn);
130 extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
131 	char **realfilter, const void *userdata);
132 extern int _ldap_filter_name(char *filter_name, const char *name,
133 	int filter_name_size);
134 extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
135 
136 extern void _nss_services_cookie_free(void **cookieP);
137 
138 #ifdef DEBUG
139 extern int printresult(ns_ldap_result_t *result);
140 #endif /* DEBUG */
141 
142 #ifdef	__cplusplus
143 }
144 #endif
145 
146 #endif	/* _LDAP_COMMON_H */
147