xref: /onnv-gate/usr/src/lib/nsswitch/ldap/common/ldap_common.h (revision 12758:996c46be076f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12758SJulian.Pullen@Sun.COM  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_LDAP_COMMON_H
260Sstevel@tonic-gate #define	_LDAP_COMMON_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #ifdef	__cplusplus
290Sstevel@tonic-gate extern "C" {
300Sstevel@tonic-gate #endif
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <ctype.h>
330Sstevel@tonic-gate #include <nss_dbdefs.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <strings.h>
370Sstevel@tonic-gate #include <signal.h>
380Sstevel@tonic-gate #include <lber.h>
390Sstevel@tonic-gate #include <ldap.h>
400Sstevel@tonic-gate #include <pwd.h>
410Sstevel@tonic-gate #include "ns_sldap.h"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #define	_ALIASES		"aliases"
440Sstevel@tonic-gate #define	_AUTOMOUNT		"automount"
450Sstevel@tonic-gate #define	_AUTHATTR		"auth_attr"
460Sstevel@tonic-gate #define	_AUUSER			"audit_user"
470Sstevel@tonic-gate #define	_BOOTPARAMS		"bootparams"
480Sstevel@tonic-gate #define	_DEFAULT		"default"
490Sstevel@tonic-gate #define	_ETHERS			"ethers"
500Sstevel@tonic-gate #define	_EXECATTR		"exec_attr"
510Sstevel@tonic-gate #define	_GROUP			"group"
520Sstevel@tonic-gate #define	_PROJECT		"project"
530Sstevel@tonic-gate #define	_HOSTS			"hosts"
540Sstevel@tonic-gate #define	_HOSTS6			"hosts"
550Sstevel@tonic-gate #define	_NETGROUP		"netgroup"
560Sstevel@tonic-gate #define	_NETMASKS		"netmasks"
570Sstevel@tonic-gate #define	_NETWORKS		"networks"
580Sstevel@tonic-gate #define	_PASSWD			"passwd"
590Sstevel@tonic-gate #define	_PRINTERS		"printers"
600Sstevel@tonic-gate #define	_PROFATTR		"prof_attr"
610Sstevel@tonic-gate #define	_PROTOCOLS		"protocols"
620Sstevel@tonic-gate #define	_PUBLICKEY		"publickey"
630Sstevel@tonic-gate #define	_RPC			"rpc"
640Sstevel@tonic-gate #define	_SERVICES		"services"
650Sstevel@tonic-gate #define	_SHADOW			"shadow"
660Sstevel@tonic-gate #define	_USERATTR		"user_attr"
671676Sjpk #define	_TNRHDB			"tnrhdb"
681676Sjpk #define	_TNRHTP			"tnrhtp"
690Sstevel@tonic-gate 
700Sstevel@tonic-gate #define	NSS_STR_PARSE_NO_ADDR	(NSS_STR_PARSE_ERANGE + 100)
71*12758SJulian.Pullen@Sun.COM #define	NSS_STR_PARSE_NO_RESULT	(NSS_STR_PARSE_ERANGE + 101)
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #define	DOTTEDSUBDOMAIN(string) \
740Sstevel@tonic-gate 	((string != NULL) && (strchr(string, '.') != NULL))
750Sstevel@tonic-gate #define	SEARCHFILTERLEN		256
760Sstevel@tonic-gate 
772830Sdjl #define	_NO_VALUE		""
782830Sdjl 
792830Sdjl #define	TEST_AND_ADJUST(len, buffer, buflen, label) \
802830Sdjl 	    /* Use '>=' to ensure there is at least one byte left for '\0' */ \
812830Sdjl 	    if (len >= buflen || len < 0) { \
822830Sdjl 		nss_result = NSS_STR_PARSE_ERANGE; \
832830Sdjl 		goto label; \
842830Sdjl 	    } \
852830Sdjl 	    /* Adjust pointer and available buffer length */ \
862830Sdjl 	    buffer += len; \
872830Sdjl 	    buflen -= len;
882830Sdjl 
898040SBaban.Kenkre@Sun.COM /*
908040SBaban.Kenkre@Sun.COM  * We need to use UID_NOBODY and GID_NOBODY as strings. Therefore we use
918040SBaban.Kenkre@Sun.COM  * snprintf to convert [U|G]ID_NOBODY into a string. The target buffer
928040SBaban.Kenkre@Sun.COM  * size was chosen as 21 to allow the largest 64-bit number to be stored
938040SBaban.Kenkre@Sun.COM  * as string in it. Right now uid_t and gid_t are 32-bit so we don't
948040SBaban.Kenkre@Sun.COM  * really need 21 characters but it does allow for future expansion
958040SBaban.Kenkre@Sun.COM  * without having to modify this code.
968040SBaban.Kenkre@Sun.COM  */
978040SBaban.Kenkre@Sun.COM #define	NOBODY_STR_LEN	21
988040SBaban.Kenkre@Sun.COM 
992830Sdjl 
1000Sstevel@tonic-gate /*
1010Sstevel@tonic-gate  * Superset the nss_backend_t abstract data type. This ADT has
1020Sstevel@tonic-gate  * been extended to include ldap associated data structures.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef struct ldap_backend *ldap_backend_ptr;
1060Sstevel@tonic-gate typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
1070Sstevel@tonic-gate typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
1080Sstevel@tonic-gate 
1092830Sdjl typedef enum {
1102830Sdjl 	NSS_LDAP_DB_NONE	= 0,
1112830Sdjl 	NSS_LDAP_DB_PUBLICKEY	= 1,
1122830Sdjl 	NSS_LDAP_DB_ETHERS	= 2
1132830Sdjl } nss_ldap_db_type_t;
1142830Sdjl 
1150Sstevel@tonic-gate struct ldap_backend {
1160Sstevel@tonic-gate 	ldap_backend_op_t	*ops;
1170Sstevel@tonic-gate 	nss_dbop_t		nops;
1180Sstevel@tonic-gate 	char			*tablename;
1190Sstevel@tonic-gate 	void			*enumcookie;
1200Sstevel@tonic-gate 	char			*filter;
121*12758SJulian.Pullen@Sun.COM 	char			*sortattr;
1220Sstevel@tonic-gate 	int			setcalled;
1230Sstevel@tonic-gate 	const char		**attrs;
1240Sstevel@tonic-gate 	ns_ldap_result_t	*result;
1252830Sdjl 	fnf			ldapobj2str;
1260Sstevel@tonic-gate 	void			*netgroup_cookie;
1270Sstevel@tonic-gate 	void			*services_cookie;
1280Sstevel@tonic-gate 	char			*toglue;
1292830Sdjl 	char			*buffer;
1302830Sdjl 	int			buflen;
1312830Sdjl 	nss_ldap_db_type_t	db_type;
1320Sstevel@tonic-gate };
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
1350Sstevel@tonic-gate extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
1360Sstevel@tonic-gate extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
1370Sstevel@tonic-gate extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
1380Sstevel@tonic-gate nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
1392830Sdjl 			char *tablename, const char **attrs, fnf ldapobj2str);
1400Sstevel@tonic-gate extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
1410Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1420Sstevel@tonic-gate 			char *searchfilter, char *domain,
1430Sstevel@tonic-gate 			int (*init_filter_cb)(
1440Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1450Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1460Sstevel@tonic-gate 			const void *userdata);
1470Sstevel@tonic-gate extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
1480Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1490Sstevel@tonic-gate 			char *searchfilter, char *domain,
1500Sstevel@tonic-gate 			int (*init_filter_cb)(
1510Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1520Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1530Sstevel@tonic-gate 			const void *userdata);
1540Sstevel@tonic-gate extern void		_clean_ldap_backend(ldap_backend_ptr be);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
1570Sstevel@tonic-gate extern const char *_strip_quotes(char *ipaddress);
1580Sstevel@tonic-gate extern int __nss2herrno(nss_status_t nsstat);
1590Sstevel@tonic-gate extern int propersubdomain(char *domain, char *subdomain);
1600Sstevel@tonic-gate extern int chophostdomain(char *string, char *host, char *domain);
1610Sstevel@tonic-gate extern char *_get_domain_name(char *cdn);
1620Sstevel@tonic-gate extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
1630Sstevel@tonic-gate 	char **realfilter, const void *userdata);
1640Sstevel@tonic-gate extern int _ldap_filter_name(char *filter_name, const char *name,
1650Sstevel@tonic-gate 	int filter_name_size);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate extern void _nss_services_cookie_free(void **cookieP);
1684953Smichen extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate #ifdef DEBUG
1710Sstevel@tonic-gate extern int printresult(ns_ldap_result_t *result);
1720Sstevel@tonic-gate #endif /* DEBUG */
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #ifdef	__cplusplus
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate #endif
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate #endif	/* _LDAP_COMMON_H */
179