xref: /titanic_51/usr/src/lib/nsswitch/ldap/common/ldap_common.h (revision 9f2fd570dfad3c35512617ae887140b15e3ec4c5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*9f2fd570SJulian Pullen  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_LDAP_COMMON_H
267c478bd9Sstevel@tonic-gate #define	_LDAP_COMMON_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <strings.h>
377c478bd9Sstevel@tonic-gate #include <signal.h>
387c478bd9Sstevel@tonic-gate #include <lber.h>
397c478bd9Sstevel@tonic-gate #include <ldap.h>
407c478bd9Sstevel@tonic-gate #include <pwd.h>
417c478bd9Sstevel@tonic-gate #include "ns_sldap.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	_ALIASES		"aliases"
447c478bd9Sstevel@tonic-gate #define	_AUTOMOUNT		"automount"
457c478bd9Sstevel@tonic-gate #define	_AUTHATTR		"auth_attr"
467c478bd9Sstevel@tonic-gate #define	_AUUSER			"audit_user"
477c478bd9Sstevel@tonic-gate #define	_BOOTPARAMS		"bootparams"
487c478bd9Sstevel@tonic-gate #define	_DEFAULT		"default"
497c478bd9Sstevel@tonic-gate #define	_ETHERS			"ethers"
507c478bd9Sstevel@tonic-gate #define	_EXECATTR		"exec_attr"
517c478bd9Sstevel@tonic-gate #define	_GROUP			"group"
527c478bd9Sstevel@tonic-gate #define	_PROJECT		"project"
537c478bd9Sstevel@tonic-gate #define	_HOSTS			"hosts"
547c478bd9Sstevel@tonic-gate #define	_HOSTS6			"hosts"
557c478bd9Sstevel@tonic-gate #define	_NETGROUP		"netgroup"
567c478bd9Sstevel@tonic-gate #define	_NETMASKS		"netmasks"
577c478bd9Sstevel@tonic-gate #define	_NETWORKS		"networks"
587c478bd9Sstevel@tonic-gate #define	_PASSWD			"passwd"
597c478bd9Sstevel@tonic-gate #define	_PRINTERS		"printers"
607c478bd9Sstevel@tonic-gate #define	_PROFATTR		"prof_attr"
617c478bd9Sstevel@tonic-gate #define	_PROTOCOLS		"protocols"
627c478bd9Sstevel@tonic-gate #define	_PUBLICKEY		"publickey"
637c478bd9Sstevel@tonic-gate #define	_RPC			"rpc"
647c478bd9Sstevel@tonic-gate #define	_SERVICES		"services"
657c478bd9Sstevel@tonic-gate #define	_SHADOW			"shadow"
667c478bd9Sstevel@tonic-gate #define	_USERATTR		"user_attr"
6745916cd2Sjpk #define	_TNRHDB			"tnrhdb"
6845916cd2Sjpk #define	_TNRHTP			"tnrhtp"
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	NSS_STR_PARSE_NO_ADDR	(NSS_STR_PARSE_ERANGE + 100)
71*9f2fd570SJulian Pullen #define	NSS_STR_PARSE_NO_RESULT	(NSS_STR_PARSE_ERANGE + 101)
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	DOTTEDSUBDOMAIN(string) \
747c478bd9Sstevel@tonic-gate 	((string != NULL) && (strchr(string, '.') != NULL))
757c478bd9Sstevel@tonic-gate #define	SEARCHFILTERLEN		256
767c478bd9Sstevel@tonic-gate 
77cb5caa98Sdjl #define	_NO_VALUE		""
78cb5caa98Sdjl 
79cb5caa98Sdjl #define	TEST_AND_ADJUST(len, buffer, buflen, label) \
80cb5caa98Sdjl 	    /* Use '>=' to ensure there is at least one byte left for '\0' */ \
81cb5caa98Sdjl 	    if (len >= buflen || len < 0) { \
82cb5caa98Sdjl 		nss_result = NSS_STR_PARSE_ERANGE; \
83cb5caa98Sdjl 		goto label; \
84cb5caa98Sdjl 	    } \
85cb5caa98Sdjl 	    /* Adjust pointer and available buffer length */ \
86cb5caa98Sdjl 	    buffer += len; \
87cb5caa98Sdjl 	    buflen -= len;
88cb5caa98Sdjl 
892b4a7802SBaban Kenkre /*
902b4a7802SBaban Kenkre  * We need to use UID_NOBODY and GID_NOBODY as strings. Therefore we use
912b4a7802SBaban Kenkre  * snprintf to convert [U|G]ID_NOBODY into a string. The target buffer
922b4a7802SBaban Kenkre  * size was chosen as 21 to allow the largest 64-bit number to be stored
932b4a7802SBaban Kenkre  * as string in it. Right now uid_t and gid_t are 32-bit so we don't
942b4a7802SBaban Kenkre  * really need 21 characters but it does allow for future expansion
952b4a7802SBaban Kenkre  * without having to modify this code.
962b4a7802SBaban Kenkre  */
972b4a7802SBaban Kenkre #define	NOBODY_STR_LEN	21
982b4a7802SBaban Kenkre 
99cb5caa98Sdjl 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * Superset the nss_backend_t abstract data type. This ADT has
1027c478bd9Sstevel@tonic-gate  * been extended to include ldap associated data structures.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate typedef struct ldap_backend *ldap_backend_ptr;
1067c478bd9Sstevel@tonic-gate typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
1077c478bd9Sstevel@tonic-gate typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
1087c478bd9Sstevel@tonic-gate 
109cb5caa98Sdjl typedef enum {
110cb5caa98Sdjl 	NSS_LDAP_DB_NONE	= 0,
111cb5caa98Sdjl 	NSS_LDAP_DB_PUBLICKEY	= 1,
112cb5caa98Sdjl 	NSS_LDAP_DB_ETHERS	= 2
113cb5caa98Sdjl } nss_ldap_db_type_t;
114cb5caa98Sdjl 
1157c478bd9Sstevel@tonic-gate struct ldap_backend {
1167c478bd9Sstevel@tonic-gate 	ldap_backend_op_t	*ops;
1177c478bd9Sstevel@tonic-gate 	nss_dbop_t		nops;
1187c478bd9Sstevel@tonic-gate 	char			*tablename;
1197c478bd9Sstevel@tonic-gate 	void			*enumcookie;
1207c478bd9Sstevel@tonic-gate 	char			*filter;
121*9f2fd570SJulian Pullen 	char			*sortattr;
1227c478bd9Sstevel@tonic-gate 	int			setcalled;
1237c478bd9Sstevel@tonic-gate 	const char		**attrs;
1247c478bd9Sstevel@tonic-gate 	ns_ldap_result_t	*result;
125cb5caa98Sdjl 	fnf			ldapobj2str;
1267c478bd9Sstevel@tonic-gate 	void			*netgroup_cookie;
1277c478bd9Sstevel@tonic-gate 	void			*services_cookie;
1287c478bd9Sstevel@tonic-gate 	char			*toglue;
129cb5caa98Sdjl 	char			*buffer;
130cb5caa98Sdjl 	int			buflen;
131cb5caa98Sdjl 	nss_ldap_db_type_t	db_type;
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
1357c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
1367c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
1377c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
1387c478bd9Sstevel@tonic-gate nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
139cb5caa98Sdjl 			char *tablename, const char **attrs, fnf ldapobj2str);
1407c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
1417c478bd9Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1427c478bd9Sstevel@tonic-gate 			char *searchfilter, char *domain,
1437c478bd9Sstevel@tonic-gate 			int (*init_filter_cb)(
1447c478bd9Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1457c478bd9Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1467c478bd9Sstevel@tonic-gate 			const void *userdata);
1477c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
1487c478bd9Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1497c478bd9Sstevel@tonic-gate 			char *searchfilter, char *domain,
1507c478bd9Sstevel@tonic-gate 			int (*init_filter_cb)(
1517c478bd9Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1527c478bd9Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1537c478bd9Sstevel@tonic-gate 			const void *userdata);
1547c478bd9Sstevel@tonic-gate extern void		_clean_ldap_backend(ldap_backend_ptr be);
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
1577c478bd9Sstevel@tonic-gate extern const char *_strip_quotes(char *ipaddress);
1587c478bd9Sstevel@tonic-gate extern int __nss2herrno(nss_status_t nsstat);
1597c478bd9Sstevel@tonic-gate extern int propersubdomain(char *domain, char *subdomain);
1607c478bd9Sstevel@tonic-gate extern int chophostdomain(char *string, char *host, char *domain);
1617c478bd9Sstevel@tonic-gate extern char *_get_domain_name(char *cdn);
1627c478bd9Sstevel@tonic-gate extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
1637c478bd9Sstevel@tonic-gate 	char **realfilter, const void *userdata);
1647c478bd9Sstevel@tonic-gate extern int _ldap_filter_name(char *filter_name, const char *name,
1657c478bd9Sstevel@tonic-gate 	int filter_name_size);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate extern void _nss_services_cookie_free(void **cookieP);
1683d047983Smichen extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #ifdef DEBUG
1717c478bd9Sstevel@tonic-gate extern int printresult(ns_ldap_result_t *result);
1727c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate #endif
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #endif	/* _LDAP_COMMON_H */
179