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*8040SBaban.Kenkre@Sun.COM * Copyright 2008 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 #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <ctype.h> 340Sstevel@tonic-gate #include <nss_dbdefs.h> 350Sstevel@tonic-gate #include <stdlib.h> 360Sstevel@tonic-gate #include <string.h> 370Sstevel@tonic-gate #include <strings.h> 380Sstevel@tonic-gate #include <signal.h> 390Sstevel@tonic-gate #include <lber.h> 400Sstevel@tonic-gate #include <ldap.h> 410Sstevel@tonic-gate #include <pwd.h> 420Sstevel@tonic-gate #include "ns_sldap.h" 430Sstevel@tonic-gate 440Sstevel@tonic-gate #define _ALIASES "aliases" 450Sstevel@tonic-gate #define _AUTOMOUNT "automount" 460Sstevel@tonic-gate #define _AUTHATTR "auth_attr" 470Sstevel@tonic-gate #define _AUUSER "audit_user" 480Sstevel@tonic-gate #define _BOOTPARAMS "bootparams" 490Sstevel@tonic-gate #define _DEFAULT "default" 500Sstevel@tonic-gate #define _ETHERS "ethers" 510Sstevel@tonic-gate #define _EXECATTR "exec_attr" 520Sstevel@tonic-gate #define _GROUP "group" 530Sstevel@tonic-gate #define _PROJECT "project" 540Sstevel@tonic-gate #define _HOSTS "hosts" 550Sstevel@tonic-gate #define _HOSTS6 "hosts" 560Sstevel@tonic-gate #define _NETGROUP "netgroup" 570Sstevel@tonic-gate #define _NETMASKS "netmasks" 580Sstevel@tonic-gate #define _NETWORKS "networks" 590Sstevel@tonic-gate #define _PASSWD "passwd" 600Sstevel@tonic-gate #define _PRINTERS "printers" 610Sstevel@tonic-gate #define _PROFATTR "prof_attr" 620Sstevel@tonic-gate #define _PROTOCOLS "protocols" 630Sstevel@tonic-gate #define _PUBLICKEY "publickey" 640Sstevel@tonic-gate #define _RPC "rpc" 650Sstevel@tonic-gate #define _SERVICES "services" 660Sstevel@tonic-gate #define _SHADOW "shadow" 670Sstevel@tonic-gate #define _USERATTR "user_attr" 681676Sjpk #define _TNRHDB "tnrhdb" 691676Sjpk #define _TNRHTP "tnrhtp" 700Sstevel@tonic-gate 710Sstevel@tonic-gate #define NSS_STR_PARSE_NO_ADDR (NSS_STR_PARSE_ERANGE + 100) 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 89*8040SBaban.Kenkre@Sun.COM /* 90*8040SBaban.Kenkre@Sun.COM * We need to use UID_NOBODY and GID_NOBODY as strings. Therefore we use 91*8040SBaban.Kenkre@Sun.COM * snprintf to convert [U|G]ID_NOBODY into a string. The target buffer 92*8040SBaban.Kenkre@Sun.COM * size was chosen as 21 to allow the largest 64-bit number to be stored 93*8040SBaban.Kenkre@Sun.COM * as string in it. Right now uid_t and gid_t are 32-bit so we don't 94*8040SBaban.Kenkre@Sun.COM * really need 21 characters but it does allow for future expansion 95*8040SBaban.Kenkre@Sun.COM * without having to modify this code. 96*8040SBaban.Kenkre@Sun.COM */ 97*8040SBaban.Kenkre@Sun.COM #define NOBODY_STR_LEN 21 98*8040SBaban.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; 1210Sstevel@tonic-gate int setcalled; 1220Sstevel@tonic-gate const char **attrs; 1230Sstevel@tonic-gate ns_ldap_result_t *result; 1242830Sdjl fnf ldapobj2str; 1250Sstevel@tonic-gate void *netgroup_cookie; 1260Sstevel@tonic-gate void *services_cookie; 1270Sstevel@tonic-gate char *toglue; 1282830Sdjl char *buffer; 1292830Sdjl int buflen; 1302830Sdjl nss_ldap_db_type_t db_type; 1310Sstevel@tonic-gate }; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate extern nss_status_t _nss_ldap_destr(ldap_backend_ptr be, void *a); 1340Sstevel@tonic-gate extern nss_status_t _nss_ldap_endent(ldap_backend_ptr be, void *a); 1350Sstevel@tonic-gate extern nss_status_t _nss_ldap_setent(ldap_backend_ptr be, void *a); 1360Sstevel@tonic-gate extern nss_status_t _nss_ldap_getent(ldap_backend_ptr be, void *a); 1370Sstevel@tonic-gate nss_backend_t *_nss_ldap_constr(ldap_backend_op_t ops[], int nops, 1382830Sdjl char *tablename, const char **attrs, fnf ldapobj2str); 1390Sstevel@tonic-gate extern nss_status_t _nss_ldap_nocb_lookup(ldap_backend_ptr be, 1400Sstevel@tonic-gate nss_XbyY_args_t *argp, char *database, 1410Sstevel@tonic-gate char *searchfilter, char *domain, 1420Sstevel@tonic-gate int (*init_filter_cb)( 1430Sstevel@tonic-gate const ns_ldap_search_desc_t *desc, 1440Sstevel@tonic-gate char **realfilter, const void *userdata), 1450Sstevel@tonic-gate const void *userdata); 1460Sstevel@tonic-gate extern nss_status_t _nss_ldap_lookup(ldap_backend_ptr be, 1470Sstevel@tonic-gate nss_XbyY_args_t *argp, char *database, 1480Sstevel@tonic-gate char *searchfilter, char *domain, 1490Sstevel@tonic-gate int (*init_filter_cb)( 1500Sstevel@tonic-gate const ns_ldap_search_desc_t *desc, 1510Sstevel@tonic-gate char **realfilter, const void *userdata), 1520Sstevel@tonic-gate const void *userdata); 1530Sstevel@tonic-gate extern void _clean_ldap_backend(ldap_backend_ptr be); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i); 1560Sstevel@tonic-gate extern const char *_strip_quotes(char *ipaddress); 1570Sstevel@tonic-gate extern int __nss2herrno(nss_status_t nsstat); 1580Sstevel@tonic-gate extern int propersubdomain(char *domain, char *subdomain); 1590Sstevel@tonic-gate extern int chophostdomain(char *string, char *host, char *domain); 1600Sstevel@tonic-gate extern char *_get_domain_name(char *cdn); 1610Sstevel@tonic-gate extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc, 1620Sstevel@tonic-gate char **realfilter, const void *userdata); 1630Sstevel@tonic-gate extern int _ldap_filter_name(char *filter_name, const char *name, 1640Sstevel@tonic-gate int filter_name_size); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate extern void _nss_services_cookie_free(void **cookieP); 1674953Smichen extern nss_status_t switch_err(int rc, ns_ldap_error_t *error); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #ifdef DEBUG 1700Sstevel@tonic-gate extern int printresult(ns_ldap_result_t *result); 1710Sstevel@tonic-gate #endif /* DEBUG */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate #ifdef __cplusplus 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate #endif 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate #endif /* _LDAP_COMMON_H */ 178