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 /*
221676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_LDAP_COMMON_H
270Sstevel@tonic-gate #define	_LDAP_COMMON_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <ctype.h>
360Sstevel@tonic-gate #include <nss_dbdefs.h>
370Sstevel@tonic-gate #include <stdlib.h>
380Sstevel@tonic-gate #include <string.h>
390Sstevel@tonic-gate #include <strings.h>
400Sstevel@tonic-gate #include <signal.h>
410Sstevel@tonic-gate #include <lber.h>
420Sstevel@tonic-gate #include <ldap.h>
430Sstevel@tonic-gate #include <pwd.h>
440Sstevel@tonic-gate #include "ns_sldap.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #define	_ALIASES		"aliases"
470Sstevel@tonic-gate #define	_AUTOMOUNT		"automount"
480Sstevel@tonic-gate #define	_AUTHATTR		"auth_attr"
490Sstevel@tonic-gate #define	_AUUSER			"audit_user"
500Sstevel@tonic-gate #define	_BOOTPARAMS		"bootparams"
510Sstevel@tonic-gate #define	_DEFAULT		"default"
520Sstevel@tonic-gate #define	_ETHERS			"ethers"
530Sstevel@tonic-gate #define	_EXECATTR		"exec_attr"
540Sstevel@tonic-gate #define	_GROUP			"group"
550Sstevel@tonic-gate #define	_PROJECT		"project"
560Sstevel@tonic-gate #define	_HOSTS			"hosts"
570Sstevel@tonic-gate #define	_HOSTS6			"hosts"
580Sstevel@tonic-gate #define	_NETGROUP		"netgroup"
590Sstevel@tonic-gate #define	_NETMASKS		"netmasks"
600Sstevel@tonic-gate #define	_NETWORKS		"networks"
610Sstevel@tonic-gate #define	_PASSWD			"passwd"
620Sstevel@tonic-gate #define	_PRINTERS		"printers"
630Sstevel@tonic-gate #define	_PROFATTR		"prof_attr"
640Sstevel@tonic-gate #define	_PROTOCOLS		"protocols"
650Sstevel@tonic-gate #define	_PUBLICKEY		"publickey"
660Sstevel@tonic-gate #define	_RPC			"rpc"
670Sstevel@tonic-gate #define	_SERVICES		"services"
680Sstevel@tonic-gate #define	_SHADOW			"shadow"
690Sstevel@tonic-gate #define	_USERATTR		"user_attr"
701676Sjpk #define	_TNRHDB			"tnrhdb"
711676Sjpk #define	_TNRHTP			"tnrhtp"
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #define	NSS_STR_PARSE_NO_ADDR	(NSS_STR_PARSE_ERANGE + 100)
740Sstevel@tonic-gate 
750Sstevel@tonic-gate #define	DOTTEDSUBDOMAIN(string) \
760Sstevel@tonic-gate 	((string != NULL) && (strchr(string, '.') != NULL))
770Sstevel@tonic-gate #define	SEARCHFILTERLEN		256
780Sstevel@tonic-gate 
79*2830Sdjl #define	_NO_VALUE		""
80*2830Sdjl 
81*2830Sdjl #define	TEST_AND_ADJUST(len, buffer, buflen, label) \
82*2830Sdjl 	    /* Use '>=' to ensure there is at least one byte left for '\0' */ \
83*2830Sdjl 	    if (len >= buflen || len < 0) { \
84*2830Sdjl 		nss_result = NSS_STR_PARSE_ERANGE; \
85*2830Sdjl 		goto label; \
86*2830Sdjl 	    } \
87*2830Sdjl 	    /* Adjust pointer and available buffer length */ \
88*2830Sdjl 	    buffer += len; \
89*2830Sdjl 	    buflen -= len;
90*2830Sdjl 
91*2830Sdjl 
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate  * Superset the nss_backend_t abstract data type. This ADT has
940Sstevel@tonic-gate  * been extended to include ldap associated data structures.
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate typedef struct ldap_backend *ldap_backend_ptr;
980Sstevel@tonic-gate typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
990Sstevel@tonic-gate typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
1000Sstevel@tonic-gate 
101*2830Sdjl typedef enum {
102*2830Sdjl 	NSS_LDAP_DB_NONE	= 0,
103*2830Sdjl 	NSS_LDAP_DB_PUBLICKEY	= 1,
104*2830Sdjl 	NSS_LDAP_DB_ETHERS	= 2
105*2830Sdjl } nss_ldap_db_type_t;
106*2830Sdjl 
1070Sstevel@tonic-gate struct ldap_backend {
1080Sstevel@tonic-gate 	ldap_backend_op_t	*ops;
1090Sstevel@tonic-gate 	nss_dbop_t		nops;
1100Sstevel@tonic-gate 	char			*tablename;
1110Sstevel@tonic-gate 	void			*enumcookie;
1120Sstevel@tonic-gate 	char			*filter;
1130Sstevel@tonic-gate 	int			setcalled;
1140Sstevel@tonic-gate 	const char		**attrs;
1150Sstevel@tonic-gate 	ns_ldap_result_t	*result;
116*2830Sdjl 	fnf			ldapobj2str;
1170Sstevel@tonic-gate 	void			*netgroup_cookie;
1180Sstevel@tonic-gate 	void			*services_cookie;
1190Sstevel@tonic-gate 	char			*toglue;
120*2830Sdjl 	char			*buffer;
121*2830Sdjl 	int			buflen;
122*2830Sdjl 	nss_ldap_db_type_t	db_type;
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate extern nss_status_t	_nss_ldap_destr(ldap_backend_ptr be, void *a);
1260Sstevel@tonic-gate extern nss_status_t	_nss_ldap_endent(ldap_backend_ptr be, void *a);
1270Sstevel@tonic-gate extern nss_status_t	_nss_ldap_setent(ldap_backend_ptr be, void *a);
1280Sstevel@tonic-gate extern nss_status_t	_nss_ldap_getent(ldap_backend_ptr be, void *a);
1290Sstevel@tonic-gate nss_backend_t		*_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
130*2830Sdjl 			char *tablename, const char **attrs, fnf ldapobj2str);
1310Sstevel@tonic-gate extern nss_status_t	_nss_ldap_nocb_lookup(ldap_backend_ptr be,
1320Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1330Sstevel@tonic-gate 			char *searchfilter, char *domain,
1340Sstevel@tonic-gate 			int (*init_filter_cb)(
1350Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1360Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1370Sstevel@tonic-gate 			const void *userdata);
1380Sstevel@tonic-gate extern nss_status_t	_nss_ldap_lookup(ldap_backend_ptr be,
1390Sstevel@tonic-gate 			nss_XbyY_args_t *argp, char *database,
1400Sstevel@tonic-gate 			char *searchfilter, char *domain,
1410Sstevel@tonic-gate 			int (*init_filter_cb)(
1420Sstevel@tonic-gate 				const ns_ldap_search_desc_t *desc,
1430Sstevel@tonic-gate 				char **realfilter, const void *userdata),
1440Sstevel@tonic-gate 			const void *userdata);
1450Sstevel@tonic-gate extern void		_clean_ldap_backend(ldap_backend_ptr be);
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
1480Sstevel@tonic-gate extern const char *_strip_quotes(char *ipaddress);
1490Sstevel@tonic-gate extern int __nss2herrno(nss_status_t nsstat);
1500Sstevel@tonic-gate extern int propersubdomain(char *domain, char *subdomain);
1510Sstevel@tonic-gate extern int chophostdomain(char *string, char *host, char *domain);
1520Sstevel@tonic-gate extern char *_get_domain_name(char *cdn);
1530Sstevel@tonic-gate extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
1540Sstevel@tonic-gate 	char **realfilter, const void *userdata);
1550Sstevel@tonic-gate extern int _ldap_filter_name(char *filter_name, const char *name,
1560Sstevel@tonic-gate 	int filter_name_size);
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate extern void _nss_services_cookie_free(void **cookieP);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #ifdef DEBUG
1610Sstevel@tonic-gate extern int printresult(ns_ldap_result_t *result);
1620Sstevel@tonic-gate #endif /* DEBUG */
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate #ifdef	__cplusplus
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate #endif
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #endif	/* _LDAP_COMMON_H */
169