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 5*36e852a1SRaja Andra * Common Development and Distribution License (the "License"). 6*36e852a1SRaja Andra * 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 /* 227c478bd9Sstevel@tonic-gate * ns_ldap.c 237c478bd9Sstevel@tonic-gate * 24*36e852a1SRaja Andra * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <stdio.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <syslog.h> 317c478bd9Sstevel@tonic-gate #include <string.h> 327c478bd9Sstevel@tonic-gate #include <ctype.h> 337c478bd9Sstevel@tonic-gate #include <nsswitch.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 377c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h> 387c478bd9Sstevel@tonic-gate #include <sys/errno.h> 397c478bd9Sstevel@tonic-gate #include <libintl.h> 407c478bd9Sstevel@tonic-gate #include "automount.h" 417c478bd9Sstevel@tonic-gate #include "../../../lib/libsldap/common/ns_sldap.h" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * LDAP schema used for automounter: 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * automountMapName: mapname i.e. auto_home, etc. 477c478bd9Sstevel@tonic-gate * automountKey: contains the key i.e. the mount point 487c478bd9Sstevel@tonic-gate * automountInformation: contains the mount options and remote mount location 497c478bd9Sstevel@tonic-gate * description: an optional description (not used by automounter) 507c478bd9Sstevel@tonic-gate * 517c478bd9Sstevel@tonic-gate * For example, if auto_direct has the following line of data: 527c478bd9Sstevel@tonic-gate * 537c478bd9Sstevel@tonic-gate * /work -rw,intr,nosuid,noquota hosta:/export/work 547c478bd9Sstevel@tonic-gate * 557c478bd9Sstevel@tonic-gate * Then this would map to the the following LDAP entry: 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * dn: automountKey=/work,automountMapName=auto_direct,... 587c478bd9Sstevel@tonic-gate * automountKey: /work 597c478bd9Sstevel@tonic-gate * automountInformation: -rw,intr,nosuid,noquota hosta:/export/work 607c478bd9Sstevel@tonic-gate * objectclass: top 617c478bd9Sstevel@tonic-gate * objectclass: automount 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * In this container: 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * dn: automountMapName=auto_direct,... 667c478bd9Sstevel@tonic-gate * automountMapName: auto_direct 677c478bd9Sstevel@tonic-gate * objectClass: top 687c478bd9Sstevel@tonic-gate * objectClass: automountMap 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * Note that the schema can be mapped and SSD's can be used to relocate 717c478bd9Sstevel@tonic-gate * the default location of these entries. 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define CAPCHAR '%' 767c478bd9Sstevel@tonic-gate #define MAXERROR 4000 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate static char *automountKey = NULL; 797c478bd9Sstevel@tonic-gate static char *automountInformation = NULL; 807c478bd9Sstevel@tonic-gate static char *defaultFilter = NULL; 817c478bd9Sstevel@tonic-gate static int encode = 0; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate static int mastermap_callback_ldap(); 847c478bd9Sstevel@tonic-gate static int directmap_callback(); 857c478bd9Sstevel@tonic-gate static int ldap_err(int); 867c478bd9Sstevel@tonic-gate static int ldap_match(); 877c478bd9Sstevel@tonic-gate static int readdir_callback(); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate struct loadmaster_cbdata { 907c478bd9Sstevel@tonic-gate char *ptr1; 917c478bd9Sstevel@tonic-gate char **ptr2; 927c478bd9Sstevel@tonic-gate char ***ptr3; 937c478bd9Sstevel@tonic-gate }; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate struct loaddirect_cbdata { 967c478bd9Sstevel@tonic-gate char *ptr1; 977c478bd9Sstevel@tonic-gate char *ptr2; 987c478bd9Sstevel@tonic-gate char **ptr3; 997c478bd9Sstevel@tonic-gate char ***ptr4; 1007c478bd9Sstevel@tonic-gate }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate struct dir_cbdata { 1037c478bd9Sstevel@tonic-gate struct dir_entry **list; 1047c478bd9Sstevel@tonic-gate struct dir_entry *last; 1057c478bd9Sstevel@tonic-gate int error; 1067c478bd9Sstevel@tonic-gate }; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate static char *tosunds_str(char *); 1097c478bd9Sstevel@tonic-gate static char *tounix_str(char *); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate static int 1127c478bd9Sstevel@tonic-gate isAttrMapped(char *orig, char *mapped) 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate char **s; 1157c478bd9Sstevel@tonic-gate char **mappedschema = NULL; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate mappedschema = __ns_ldap_getMappedAttributes("automount", orig); 1187c478bd9Sstevel@tonic-gate if (mappedschema == NULL) 1197c478bd9Sstevel@tonic-gate return (0); 1207c478bd9Sstevel@tonic-gate if (strcasecmp(mappedschema[0], mapped) != 0) { 1217c478bd9Sstevel@tonic-gate for (s = mappedschema; *s != NULL; s++) 1227c478bd9Sstevel@tonic-gate free(*s); 1237c478bd9Sstevel@tonic-gate free(mappedschema); 1247c478bd9Sstevel@tonic-gate return (0); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate for (s = mappedschema; *s != NULL; s++) 1277c478bd9Sstevel@tonic-gate free(*s); 1287c478bd9Sstevel@tonic-gate free(mappedschema); 1297c478bd9Sstevel@tonic-gate return (1); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate static int 1337c478bd9Sstevel@tonic-gate isObjectMapped(char *orig, char *mapped) 1347c478bd9Sstevel@tonic-gate { 1357c478bd9Sstevel@tonic-gate char **s; 1367c478bd9Sstevel@tonic-gate char **mappedschema = NULL; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate mappedschema = __ns_ldap_getMappedObjectClass("automount", orig); 1397c478bd9Sstevel@tonic-gate if (mappedschema == NULL) 1407c478bd9Sstevel@tonic-gate return (0); 1417c478bd9Sstevel@tonic-gate if (strcasecmp(mappedschema[0], mapped) != 0) { 1427c478bd9Sstevel@tonic-gate for (s = mappedschema; *s != NULL; s++) 1437c478bd9Sstevel@tonic-gate free(*s); 1447c478bd9Sstevel@tonic-gate free(mappedschema); 1457c478bd9Sstevel@tonic-gate return (0); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate for (s = mappedschema; *s != NULL; s++) 1487c478bd9Sstevel@tonic-gate free(*s); 1497c478bd9Sstevel@tonic-gate free(mappedschema); 1507c478bd9Sstevel@tonic-gate return (1); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate void 1547c478bd9Sstevel@tonic-gate init_ldap(char **stack, char ***stkptr) 1557c478bd9Sstevel@tonic-gate { 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * Check for version of the profile the client is using 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * For version 1 profiles we do encoding of attributes 1607c478bd9Sstevel@tonic-gate * and use nisMap and nisObject schema for backward compatibility. 1617c478bd9Sstevel@tonic-gate * 1627c478bd9Sstevel@tonic-gate * For version 2 profiles we don't do encoding and use 1637c478bd9Sstevel@tonic-gate * automountMap and automount as default attributes (which can 1647c478bd9Sstevel@tonic-gate * then be overridden in libsldap if schema mapping is configured 1657c478bd9Sstevel@tonic-gate * in the profile). 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * If profile version is not available, use version 2 as default 1687c478bd9Sstevel@tonic-gate * and syslog message. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate int rc, v2 = 1; 1717c478bd9Sstevel@tonic-gate void **paramVal = NULL; 1727c478bd9Sstevel@tonic-gate ns_ldap_error_t *errorp = NULL; 1737c478bd9Sstevel@tonic-gate struct __nsw_switchconfig *conf = NULL; 1747c478bd9Sstevel@tonic-gate struct __nsw_lookup *lkp = NULL; 1757c478bd9Sstevel@tonic-gate enum __nsw_parse_err pserr; 1767c478bd9Sstevel@tonic-gate int ldap_configured = 0; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #ifdef lint 1797c478bd9Sstevel@tonic-gate stack = stack; 1807c478bd9Sstevel@tonic-gate stkptr = stkptr; 1817c478bd9Sstevel@tonic-gate #endif /* lint */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* get nsswitch info of "automount */ 1847c478bd9Sstevel@tonic-gate conf = __nsw_getconfig("automount", &pserr); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* find out if LDAP backend is configured */ 1877c478bd9Sstevel@tonic-gate if (conf != NULL) { 1887c478bd9Sstevel@tonic-gate for (lkp = conf->lookups; lkp != NULL; lkp = lkp->next) { 1897c478bd9Sstevel@tonic-gate if (strcmp(lkp->service_name, "ldap") == 0) { 1907c478bd9Sstevel@tonic-gate ldap_configured = 1; 1917c478bd9Sstevel@tonic-gate break; 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate /* free conf at the end of "if" bracket */ 1957c478bd9Sstevel@tonic-gate (void) __nsw_freeconfig(conf); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* if ldap is not configured, init_ldap is a no op */ 1997c478bd9Sstevel@tonic-gate if (!ldap_configured) 2007c478bd9Sstevel@tonic-gate return; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, ¶mVal, &errorp); 2037c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS || !paramVal || !*paramVal) { 2047c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "Can not determine version of LDAP profile" 2057c478bd9Sstevel@tonic-gate " that is used (%d, %s). Using version 2 profile" 2067c478bd9Sstevel@tonic-gate " defaults", rc, (errorp && errorp->message ? 2077c478bd9Sstevel@tonic-gate errorp->message : "")); 2087c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(&errorp); 2097c478bd9Sstevel@tonic-gate } else { 2107c478bd9Sstevel@tonic-gate if (strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0) 2117c478bd9Sstevel@tonic-gate v2 = 0; 2127c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate if (v2) { 2167c478bd9Sstevel@tonic-gate if (trace > 1) 2177c478bd9Sstevel@tonic-gate trace_prt(1, "init_ldap: setting up for version 2\n"); 2187c478bd9Sstevel@tonic-gate automountKey = "automountKey"; 2197c478bd9Sstevel@tonic-gate automountInformation = "automountInformation"; 2207c478bd9Sstevel@tonic-gate defaultFilter = "(&(objectClass=automount)(automountKey=%s))"; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate /* check for automountMapName mapped to nisMapName */ 2237c478bd9Sstevel@tonic-gate if (!isAttrMapped("automountMapName", "nisMapName")) 2247c478bd9Sstevel@tonic-gate return; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* check for automountKey mapped to cn */ 2277c478bd9Sstevel@tonic-gate if (!isAttrMapped("automountKey", "cn")) 2287c478bd9Sstevel@tonic-gate return; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* check for automountInformation mapped to nisMapEntry */ 2317c478bd9Sstevel@tonic-gate if (!isAttrMapped("automountInformation", "nisMapEntry")) 2327c478bd9Sstevel@tonic-gate return; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* check for automountMap mapped to nisMap */ 2357c478bd9Sstevel@tonic-gate if (!isObjectMapped("automountMap", "nisMap")) 2367c478bd9Sstevel@tonic-gate return; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* check for automount mapped to nisObject */ 2397c478bd9Sstevel@tonic-gate if (!isObjectMapped("automount", "nisObject")) 2407c478bd9Sstevel@tonic-gate return; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate if (trace > 1) 2437c478bd9Sstevel@tonic-gate trace_prt(1, "init_ldap: encode = TRUE\n"); 2447c478bd9Sstevel@tonic-gate encode = 1; 2457c478bd9Sstevel@tonic-gate } else { 2467c478bd9Sstevel@tonic-gate if (trace > 1) { 2477c478bd9Sstevel@tonic-gate trace_prt(1, "init_ldap: setting up for version 1\n"); 2487c478bd9Sstevel@tonic-gate trace_prt(1, "init_ldap: encode = TRUE\n"); 2497c478bd9Sstevel@tonic-gate } 2507c478bd9Sstevel@tonic-gate encode = 1; 2517c478bd9Sstevel@tonic-gate automountKey = "cn"; 2527c478bd9Sstevel@tonic-gate automountInformation = "nisMapEntry"; 2537c478bd9Sstevel@tonic-gate defaultFilter = "(&(objectClass=nisObject)(cn=%s))"; 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2587c478bd9Sstevel@tonic-gate int 2597c478bd9Sstevel@tonic-gate getmapent_ldap(char *key, char *map, struct mapline *ml, 2607c478bd9Sstevel@tonic-gate char **stack, char ***stkptr, bool_t *iswildcard, bool_t isrestricted) 2617c478bd9Sstevel@tonic-gate { 2627c478bd9Sstevel@tonic-gate char *ldap_line = NULL; 2637c478bd9Sstevel@tonic-gate char *lp; 2647c478bd9Sstevel@tonic-gate int ldap_len, len; 2657c478bd9Sstevel@tonic-gate int nserr; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (trace > 1) 2687c478bd9Sstevel@tonic-gate trace_prt(1, "getmapent_ldap called\n"); 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate if (trace > 1) { 2717c478bd9Sstevel@tonic-gate trace_prt(1, "getmapent_ldap: key=[ %s ]\n", key); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if (iswildcard) 2757c478bd9Sstevel@tonic-gate *iswildcard = FALSE; 2767c478bd9Sstevel@tonic-gate nserr = ldap_match(map, key, &ldap_line, &ldap_len); 2777c478bd9Sstevel@tonic-gate if (nserr) { 2787c478bd9Sstevel@tonic-gate if (nserr == __NSW_NOTFOUND) { 2797c478bd9Sstevel@tonic-gate /* Try the default entry "*" */ 2807c478bd9Sstevel@tonic-gate if ((nserr = ldap_match(map, "\\2a", &ldap_line, 2817c478bd9Sstevel@tonic-gate &ldap_len))) 2827c478bd9Sstevel@tonic-gate goto done; 2837c478bd9Sstevel@tonic-gate else { 2847c478bd9Sstevel@tonic-gate if (iswildcard) 2857c478bd9Sstevel@tonic-gate *iswildcard = TRUE; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate } else 2887c478bd9Sstevel@tonic-gate goto done; 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * at this point we are sure that ldap_match 2937c478bd9Sstevel@tonic-gate * succeeded so massage the entry by 2947c478bd9Sstevel@tonic-gate * 1. ignoring # and beyond 2957c478bd9Sstevel@tonic-gate * 2. trim the trailing whitespace 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate if (lp = strchr(ldap_line, '#')) 2987c478bd9Sstevel@tonic-gate *lp = '\0'; 2997c478bd9Sstevel@tonic-gate len = strlen(ldap_line); 3007c478bd9Sstevel@tonic-gate if (len == 0) { 3017c478bd9Sstevel@tonic-gate nserr = __NSW_NOTFOUND; 3027c478bd9Sstevel@tonic-gate goto done; 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate lp = &ldap_line[len - 1]; 3057c478bd9Sstevel@tonic-gate while (lp > ldap_line && isspace(*lp)) 3067c478bd9Sstevel@tonic-gate *lp-- = '\0'; 3077c478bd9Sstevel@tonic-gate if (lp == ldap_line) { 3087c478bd9Sstevel@tonic-gate nserr = __NSW_NOTFOUND; 3097c478bd9Sstevel@tonic-gate goto done; 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate (void) strncpy(ml->linebuf, ldap_line, LINESZ); 3127c478bd9Sstevel@tonic-gate unquote(ml->linebuf, ml->lineqbuf); 3137c478bd9Sstevel@tonic-gate nserr = __NSW_SUCCESS; 3147c478bd9Sstevel@tonic-gate done: 3157c478bd9Sstevel@tonic-gate if (ldap_line) 3167c478bd9Sstevel@tonic-gate free((char *)ldap_line); 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate if (trace > 1) 3197c478bd9Sstevel@tonic-gate trace_prt(1, "getmapent_ldap: exiting ...\n"); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate return (nserr); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static int 3257c478bd9Sstevel@tonic-gate ldap_match(char *map, char *key, char **ldap_line, int *ldap_len) 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate char searchfilter[LDAP_FILT_MAXSIZ]; 3287c478bd9Sstevel@tonic-gate int res, attr_found; 3297c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 3307c478bd9Sstevel@tonic-gate ns_ldap_error_t *errp = NULL; 3317c478bd9Sstevel@tonic-gate ns_ldap_entry_t *entry = NULL; 3327c478bd9Sstevel@tonic-gate char *ldapkey; 3337c478bd9Sstevel@tonic-gate int i; 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate if (trace > 1) { 3367c478bd9Sstevel@tonic-gate trace_prt(1, "ldap_match called\n"); 3377c478bd9Sstevel@tonic-gate trace_prt(1, "ldap_match: key =[ %s ]\n", key); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * need to handle uppercase characters in the key because LDAP 3427c478bd9Sstevel@tonic-gate * searches are case insensitive. Note, key = attribute automountKey. 3437c478bd9Sstevel@tonic-gate */ 3447c478bd9Sstevel@tonic-gate if (encode) 3457c478bd9Sstevel@tonic-gate ldapkey = tosunds_str(key); 3467c478bd9Sstevel@tonic-gate else 3477c478bd9Sstevel@tonic-gate ldapkey = key; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate if (trace > 1) { 3507c478bd9Sstevel@tonic-gate trace_prt(1, "ldap_match: ldapkey =[ %s ]\n", ldapkey); 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate (void) sprintf(searchfilter, defaultFilter, ldapkey); 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate if (trace > 1) 3567c478bd9Sstevel@tonic-gate trace_prt(1, " ldap_match: Requesting list for %s in %s\n", 3577c478bd9Sstevel@tonic-gate searchfilter, map); 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate res = __ns_ldap_list(map, searchfilter, NULL, 3607c478bd9Sstevel@tonic-gate NULL, NULL, 0, &result, &errp, NULL, NULL); 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate if (trace > 1) { 3637c478bd9Sstevel@tonic-gate if (res != NS_LDAP_SUCCESS) 3647c478bd9Sstevel@tonic-gate trace_prt(1, 3657c478bd9Sstevel@tonic-gate " ldap_match: __ns_ldap_list FAILED (%d)\n", res); 3667c478bd9Sstevel@tonic-gate else 3677c478bd9Sstevel@tonic-gate trace_prt(1, " ldap_match: __ns_ldap_list OK\n"); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate if (res != NS_LDAP_SUCCESS && res != NS_LDAP_NOTFOUND) { 3717c478bd9Sstevel@tonic-gate if (errp) { 3727c478bd9Sstevel@tonic-gate if (verbose) { 3737c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 3747c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 3757c478bd9Sstevel@tonic-gate gettext("ldap server can't list map," 3767c478bd9Sstevel@tonic-gate " '%s': '%s' - '%d'."), 3777c478bd9Sstevel@tonic-gate map, errp->message, errp->status); 3787c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errstr); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 3817c478bd9Sstevel@tonic-gate } else { 3827c478bd9Sstevel@tonic-gate if (verbose) { 3837c478bd9Sstevel@tonic-gate char *errmsg; 3847c478bd9Sstevel@tonic-gate __ns_ldap_err2str(res, &errmsg); 3857c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errmsg); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate if (result) 3897c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 3907c478bd9Sstevel@tonic-gate return (ldap_err(res)); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate if (res == NS_LDAP_NOTFOUND || result == NULL || 3947c478bd9Sstevel@tonic-gate result->entries_count == 0 || result->entry->attr_count == 0) { 3957c478bd9Sstevel@tonic-gate if (trace > 1) 3967c478bd9Sstevel@tonic-gate trace_prt(1, " ldap_match: no entries found\n"); 3977c478bd9Sstevel@tonic-gate if (errp) 3987c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 3997c478bd9Sstevel@tonic-gate if (result) 4007c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 4017c478bd9Sstevel@tonic-gate return (__NSW_NOTFOUND); 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * get value of attribute nisMapEntry. This attribute contains a 4067c478bd9Sstevel@tonic-gate * list of mount options AND mount location for a particular mount 4077c478bd9Sstevel@tonic-gate * point (key). 4087c478bd9Sstevel@tonic-gate * For example: 4097c478bd9Sstevel@tonic-gate * 4107c478bd9Sstevel@tonic-gate * key: /work 4117c478bd9Sstevel@tonic-gate * ^^^^^ 4127c478bd9Sstevel@tonic-gate * (mount point) 4137c478bd9Sstevel@tonic-gate * 4147c478bd9Sstevel@tonic-gate * nisMapEntry: -rw,intr,nosuid,noquota hosta:/export/work 4157c478bd9Sstevel@tonic-gate * ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ 4167c478bd9Sstevel@tonic-gate * ( mount options ) (remote mount location) 4177c478bd9Sstevel@tonic-gate * 4187c478bd9Sstevel@tonic-gate */ 4197c478bd9Sstevel@tonic-gate attr_found = 0; 4207c478bd9Sstevel@tonic-gate entry = result->entry; 4217c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 4227c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attr; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate attr = entry->attr_pair[i]; 4257c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, automountInformation) == 0) { 4267c478bd9Sstevel@tonic-gate char *attrval; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate attr_found = 1; 4297c478bd9Sstevel@tonic-gate if (encode) 4307c478bd9Sstevel@tonic-gate attrval = tounix_str(attr->attrvalue[0]); 4317c478bd9Sstevel@tonic-gate else 4327c478bd9Sstevel@tonic-gate attrval = attr->attrvalue[0]; 4337c478bd9Sstevel@tonic-gate *ldap_len = strlen(key) + strlen(attrval); 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* 4367c478bd9Sstevel@tonic-gate * so check for the length; it should be less than 4377c478bd9Sstevel@tonic-gate * LINESZ 4387c478bd9Sstevel@tonic-gate */ 4397c478bd9Sstevel@tonic-gate if ((*ldap_len + 2) > LINESZ) { 4407c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 4417c478bd9Sstevel@tonic-gate "ldap server map %s, entry for %s" 4427c478bd9Sstevel@tonic-gate " is too long %d chars (max %d)", 4437c478bd9Sstevel@tonic-gate map, key, (*ldap_len + 2), LINESZ); 4447c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 4457c478bd9Sstevel@tonic-gate return (__NSW_UNAVAIL); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate *ldap_line = (char *)malloc(*ldap_len + 2); 4487c478bd9Sstevel@tonic-gate if (*ldap_line == NULL) { 4497c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "ldap_match: malloc failed"); 4507c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 4517c478bd9Sstevel@tonic-gate return (__NSW_UNAVAIL); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate (void) sprintf(*ldap_line, "%s", attrval); 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate break; 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 4617c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate if (!attr_found) 4647c478bd9Sstevel@tonic-gate return (__NSW_NOTFOUND); 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate if (trace > 1) 4677c478bd9Sstevel@tonic-gate trace_prt(1, " ldap_match: found: %s\n", *ldap_line); 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate return (__NSW_SUCCESS); 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate 47211606941Sjwahlig int 4737c478bd9Sstevel@tonic-gate loadmaster_ldap(char *mapname, char *defopts, char **stack, char ***stkptr) 4747c478bd9Sstevel@tonic-gate { 4757c478bd9Sstevel@tonic-gate char searchfilter[LDAP_FILT_MAXSIZ]; 4767c478bd9Sstevel@tonic-gate int res; 4777c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 4787c478bd9Sstevel@tonic-gate ns_ldap_error_t *errp = NULL; 4797c478bd9Sstevel@tonic-gate struct loadmaster_cbdata master_cbdata; 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate if (trace > 1) 4827c478bd9Sstevel@tonic-gate trace_prt(1, "loadmaster_ldap called\n"); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate master_cbdata.ptr1 = defopts; 4857c478bd9Sstevel@tonic-gate master_cbdata.ptr2 = stack; 4867c478bd9Sstevel@tonic-gate master_cbdata.ptr3 = stkptr; 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /* filter gets all the entries for the specified mapname */ 4897c478bd9Sstevel@tonic-gate (void) sprintf(searchfilter, defaultFilter, "*"); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate if (trace > 1) 4927c478bd9Sstevel@tonic-gate trace_prt(1, "loadmaster_ldap: Requesting list for %s in %s\n", 4937c478bd9Sstevel@tonic-gate searchfilter, mapname); 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate res = __ns_ldap_list(mapname, searchfilter, NULL, NULL, NULL, 4967c478bd9Sstevel@tonic-gate 0, &result, &errp, mastermap_callback_ldap, 4977c478bd9Sstevel@tonic-gate (void *) &master_cbdata); 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate if (trace > 1) 5007c478bd9Sstevel@tonic-gate trace_prt(1, 5017c478bd9Sstevel@tonic-gate "loadmaster_ldap: __ns_ldap_list just returned: %d\n", 5027c478bd9Sstevel@tonic-gate res); 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate if (res != NS_LDAP_SUCCESS) { 5057c478bd9Sstevel@tonic-gate if (errp) { 5067c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 5077c478bd9Sstevel@tonic-gate if (verbose) { 5087c478bd9Sstevel@tonic-gate (void) sprintf(errstr, gettext( 5097c478bd9Sstevel@tonic-gate "ldap server can't list map," 5107c478bd9Sstevel@tonic-gate "'%s': '%s' - '%d'."), 5117c478bd9Sstevel@tonic-gate mapname, errp->message, errp->status); 5127c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errstr); 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 5157c478bd9Sstevel@tonic-gate } else { 5167c478bd9Sstevel@tonic-gate if (verbose) { 5177c478bd9Sstevel@tonic-gate char *errmsg; 5187c478bd9Sstevel@tonic-gate __ns_ldap_err2str(res, &errmsg); 5197c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errmsg); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate if (result) 5237c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 5247c478bd9Sstevel@tonic-gate return (ldap_err(res)); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate if (trace > 1) 5287c478bd9Sstevel@tonic-gate trace_prt(1, 5297c478bd9Sstevel@tonic-gate "loadmaster_ldap: calling __ns_ldap_freeResult...\n"); 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate if (trace > 1) 5347c478bd9Sstevel@tonic-gate trace_prt(1, 5357c478bd9Sstevel@tonic-gate "loadmaster_ldap: about to return __NSW_SUCCESS...\n"); 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate return (__NSW_SUCCESS); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate 54011606941Sjwahlig int 5417c478bd9Sstevel@tonic-gate loaddirect_ldap(char *nsmap, char *localmap, char *opts, 5427c478bd9Sstevel@tonic-gate char **stack, char ***stkptr) 5437c478bd9Sstevel@tonic-gate { 5447c478bd9Sstevel@tonic-gate char searchfilter[LDAP_FILT_MAXSIZ]; 5457c478bd9Sstevel@tonic-gate int res; 5467c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 5477c478bd9Sstevel@tonic-gate ns_ldap_error_t *errp = NULL; 5487c478bd9Sstevel@tonic-gate struct loaddirect_cbdata direct_cbdata; 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate if (trace > 1) { 5517c478bd9Sstevel@tonic-gate trace_prt(1, "loaddirect_ldap called\n"); 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate direct_cbdata.ptr1 = opts; 5557c478bd9Sstevel@tonic-gate direct_cbdata.ptr2 = localmap; 5567c478bd9Sstevel@tonic-gate direct_cbdata.ptr3 = stack; 5577c478bd9Sstevel@tonic-gate direct_cbdata.ptr4 = stkptr; 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate /* filter gets all the entries for the specified mapname */ 5607c478bd9Sstevel@tonic-gate (void) sprintf(searchfilter, defaultFilter, "*"); 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate if (trace > 1) 5637c478bd9Sstevel@tonic-gate trace_prt(1, "loaddirect_ldap: Requesting list for %s in %s\n", 5647c478bd9Sstevel@tonic-gate searchfilter, nsmap); 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate res = __ns_ldap_list(nsmap, searchfilter, NULL, NULL, 5677c478bd9Sstevel@tonic-gate NULL, 0, &result, &errp, 5687c478bd9Sstevel@tonic-gate directmap_callback, (void *) &direct_cbdata); 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate if (res != NS_LDAP_SUCCESS) { 5727c478bd9Sstevel@tonic-gate if (errp) { 5737c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 5747c478bd9Sstevel@tonic-gate if (verbose) { 5757c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 5767c478bd9Sstevel@tonic-gate gettext("ldap server can't list map," 5777c478bd9Sstevel@tonic-gate " '%s': '%s' - '%d'."), 5787c478bd9Sstevel@tonic-gate nsmap, errp->message, errp->status); 5797c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errstr); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 5827c478bd9Sstevel@tonic-gate } else { 5837c478bd9Sstevel@tonic-gate if (verbose) { 5847c478bd9Sstevel@tonic-gate char *errmsg; 5857c478bd9Sstevel@tonic-gate __ns_ldap_err2str(res, &errmsg); 5867c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errmsg); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate if (result) 5907c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 5917c478bd9Sstevel@tonic-gate return (ldap_err(res)); 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 5957c478bd9Sstevel@tonic-gate return (__NSW_SUCCESS); 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate static int 5997c478bd9Sstevel@tonic-gate ldap_err(int err) 6007c478bd9Sstevel@tonic-gate { 6017c478bd9Sstevel@tonic-gate if (trace > 1) 6027c478bd9Sstevel@tonic-gate trace_prt(1, "ldap_err called\n"); 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate switch (err) { 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 6077c478bd9Sstevel@tonic-gate return (__NSW_SUCCESS); 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 6107c478bd9Sstevel@tonic-gate return (__NSW_NOTFOUND); 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate case NS_LDAP_PARTIAL: 6137c478bd9Sstevel@tonic-gate return (__NSW_TRYAGAIN); 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate default: 6167c478bd9Sstevel@tonic-gate return (__NSW_UNAVAIL); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate static int 6217c478bd9Sstevel@tonic-gate mastermap_callback_ldap(ns_ldap_entry_t *entry, void *udata) 6227c478bd9Sstevel@tonic-gate { 6237c478bd9Sstevel@tonic-gate char *key, *contents, *pmap, *opts; 6247c478bd9Sstevel@tonic-gate char dir[LINESZ], map[LINESZ], qbuff[LINESZ]; 6257c478bd9Sstevel@tonic-gate char cont_temp[LINESZ], key_temp[LINESZ]; 6267c478bd9Sstevel@tonic-gate int key_len, contents_len; 6277c478bd9Sstevel@tonic-gate struct loadmaster_cbdata *temp = (struct loadmaster_cbdata *)udata; 6287c478bd9Sstevel@tonic-gate char *defopts = temp->ptr1; 6297c478bd9Sstevel@tonic-gate char **stack = temp->ptr2; 6307c478bd9Sstevel@tonic-gate char ***stkptr = temp->ptr3; 6317c478bd9Sstevel@tonic-gate int i; 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate if (trace > 1) { 6347c478bd9Sstevel@tonic-gate trace_prt(1, "mastermap_callback_ldap called\n"); 6357c478bd9Sstevel@tonic-gate trace_prt(1, "mastermap_callback_ldap: entry=%x\n", entry); 6367c478bd9Sstevel@tonic-gate if (entry) { 6377c478bd9Sstevel@tonic-gate trace_prt(1, 6387c478bd9Sstevel@tonic-gate "mastermap_callback_ldap: entry->attr_count=[ %d ]\n", 6397c478bd9Sstevel@tonic-gate entry->attr_count); 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate /* 6447c478bd9Sstevel@tonic-gate * For the current entry, obtain the values of the cn and the 6457c478bd9Sstevel@tonic-gate * nisMapEntry attributes and the length of each value (cn=key, 6467c478bd9Sstevel@tonic-gate * nisMapEntry=contents). 6477c478bd9Sstevel@tonic-gate * We skip the description. Even though LDAP allows for multiple 6487c478bd9Sstevel@tonic-gate * values per attribute, we take only the 1st value for each 649*36e852a1SRaja Andra * attribute because the automount data is organized as such. 6507c478bd9Sstevel@tonic-gate */ 6517c478bd9Sstevel@tonic-gate key_len = 0; 6527c478bd9Sstevel@tonic-gate contents_len = 0; 6537c478bd9Sstevel@tonic-gate key = NULL; 6547c478bd9Sstevel@tonic-gate contents = NULL; 6557c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 6567c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attr; 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate attr = entry->attr_pair[i]; 6597c478bd9Sstevel@tonic-gate if (trace > 1) { 6607c478bd9Sstevel@tonic-gate trace_prt(1, 6617c478bd9Sstevel@tonic-gate "mastermap_callback_ldap: attr[%d]: %s=%s\n", 6627c478bd9Sstevel@tonic-gate i, attr->attrname, attr->attrvalue[0]); 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, automountInformation) == 0) { 6657c478bd9Sstevel@tonic-gate if (encode) 6667c478bd9Sstevel@tonic-gate (void) strncpy(cont_temp, 6677c478bd9Sstevel@tonic-gate tounix_str(attr->attrvalue[0]), LINESZ); 6687c478bd9Sstevel@tonic-gate else 6697c478bd9Sstevel@tonic-gate (void) strncpy(cont_temp, attr->attrvalue[0], 6707c478bd9Sstevel@tonic-gate LINESZ); 6717c478bd9Sstevel@tonic-gate contents = cont_temp; 6727c478bd9Sstevel@tonic-gate contents_len = strlen(contents); 6737c478bd9Sstevel@tonic-gate if (trace > 1) { 6747c478bd9Sstevel@tonic-gate trace_prt(1, 675*36e852a1SRaja Andra "mastermap_callback_ldap: contents=[ %s ]," 676*36e852a1SRaja Andra " contents_len=[ %d ]\n", 6777c478bd9Sstevel@tonic-gate contents, contents_len); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, automountKey) == 0) { 6817c478bd9Sstevel@tonic-gate if (encode) 6827c478bd9Sstevel@tonic-gate (void) strncpy(key_temp, 6837c478bd9Sstevel@tonic-gate tounix_str(attr->attrvalue[0]), LINESZ); 6847c478bd9Sstevel@tonic-gate else 6857c478bd9Sstevel@tonic-gate (void) strncpy(key_temp, attr->attrvalue[0], 6867c478bd9Sstevel@tonic-gate LINESZ); 6877c478bd9Sstevel@tonic-gate key = key_temp; 6887c478bd9Sstevel@tonic-gate key_len = strlen(key); 6897c478bd9Sstevel@tonic-gate if (trace > 1) { 6907c478bd9Sstevel@tonic-gate trace_prt(1, 691*36e852a1SRaja Andra "mastermap_callback_ldap: key=[ %s ]," 692*36e852a1SRaja Andra " key_len=[ %d ]\n", 6937c478bd9Sstevel@tonic-gate key, key_len); 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate } 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate if (key_len >= LINESZ || contents_len >= LINESZ) 6997c478bd9Sstevel@tonic-gate return (0); 7007c478bd9Sstevel@tonic-gate if (key_len < 2 || contents_len < 2) 7017c478bd9Sstevel@tonic-gate return (0); 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate while (isspace(*contents)) 7047c478bd9Sstevel@tonic-gate contents++; 7057c478bd9Sstevel@tonic-gate if (contents == NULL) 7067c478bd9Sstevel@tonic-gate return (0); 7077c478bd9Sstevel@tonic-gate if (isspace(*key) || *key == '#') 7087c478bd9Sstevel@tonic-gate return (0); 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate (void) strncpy(dir, key, key_len); 7117c478bd9Sstevel@tonic-gate dir[key_len] = '\0'; 7127c478bd9Sstevel@tonic-gate if (trace > 1) 7137c478bd9Sstevel@tonic-gate trace_prt(1, "mastermap_callback_ldap: dir= [ %s ]\n", dir); 7147c478bd9Sstevel@tonic-gate for (i = 0; i < LINESZ; i++) 7157c478bd9Sstevel@tonic-gate qbuff[i] = ' '; 7167c478bd9Sstevel@tonic-gate if (macro_expand("", dir, qbuff, sizeof (dir))) { 7177c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 7187c478bd9Sstevel@tonic-gate "%s in ldap server map: entry too long (max %d chars)", 7197c478bd9Sstevel@tonic-gate dir, sizeof (dir) - 1); 7207c478bd9Sstevel@tonic-gate return (0); 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate (void) strncpy(map, contents, contents_len); 7237c478bd9Sstevel@tonic-gate map[contents_len] = '\0'; 7247c478bd9Sstevel@tonic-gate if (trace > 1) 7257c478bd9Sstevel@tonic-gate trace_prt(1, "mastermap_callback_ldap: map= [ %s ]\n", map); 7267c478bd9Sstevel@tonic-gate if (macro_expand("", map, qbuff, sizeof (map))) { 7277c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 7287c478bd9Sstevel@tonic-gate "%s in ldap server map: entry too long (max %d chars)", 7297c478bd9Sstevel@tonic-gate map, sizeof (map) - 1); 7307c478bd9Sstevel@tonic-gate return (0); 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate pmap = map; 7337c478bd9Sstevel@tonic-gate while (*pmap && isspace(*pmap)) 7347c478bd9Sstevel@tonic-gate pmap++; /* skip blanks in front of map */ 7357c478bd9Sstevel@tonic-gate opts = pmap; 7367c478bd9Sstevel@tonic-gate while (*opts && !isspace(*opts)) 7377c478bd9Sstevel@tonic-gate opts++; 7387c478bd9Sstevel@tonic-gate if (*opts) { 7397c478bd9Sstevel@tonic-gate *opts++ = '\0'; 7407c478bd9Sstevel@tonic-gate while (*opts && isspace(*opts)) 7417c478bd9Sstevel@tonic-gate opts++; 7427c478bd9Sstevel@tonic-gate if (*opts == '-') 7437c478bd9Sstevel@tonic-gate opts++; 7447c478bd9Sstevel@tonic-gate else 7457c478bd9Sstevel@tonic-gate opts = defopts; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate /* 7487c478bd9Sstevel@tonic-gate * Check for no embedded blanks. 7497c478bd9Sstevel@tonic-gate */ 7507c478bd9Sstevel@tonic-gate if (strcspn(opts, " ") == strlen(opts)) { 7517c478bd9Sstevel@tonic-gate if (trace > 1) 7527c478bd9Sstevel@tonic-gate trace_prt(1, 7537c478bd9Sstevel@tonic-gate "mastermap_callback_ldap: dir=[ %s ], pmap=[ %s ]\n", 7547c478bd9Sstevel@tonic-gate dir, pmap); 7557c478bd9Sstevel@tonic-gate dirinit(dir, pmap, opts, 0, stack, stkptr); 7567c478bd9Sstevel@tonic-gate } else { 7577c478bd9Sstevel@tonic-gate char *dn = NULL; 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate /* get the value for the dn */ 7607c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 7617c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attr; 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate attr = entry->attr_pair[i]; 7647c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, "dn") 7657c478bd9Sstevel@tonic-gate == 0) { 7667c478bd9Sstevel@tonic-gate dn = attr->attrvalue[0]; 7677c478bd9Sstevel@tonic-gate break; 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate pr_msg( 771*36e852a1SRaja Andra "Warning: invalid entry for %s in ldap server" 772*36e852a1SRaja Andra " dn: %s ignored.\n", 7737c478bd9Sstevel@tonic-gate dir, dn); 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate if (trace > 1) 7767c478bd9Sstevel@tonic-gate trace_prt(1, "mastermap_callback_ldap exiting...\n"); 7777c478bd9Sstevel@tonic-gate return (0); 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate static int 7817c478bd9Sstevel@tonic-gate directmap_callback(ns_ldap_entry_t *entry, void *udata) 7827c478bd9Sstevel@tonic-gate { 7837c478bd9Sstevel@tonic-gate char *key; 7847c478bd9Sstevel@tonic-gate char dir[256]; 7857c478bd9Sstevel@tonic-gate int key_len; 7867c478bd9Sstevel@tonic-gate struct loaddirect_cbdata *temp = (struct loaddirect_cbdata *)udata; 7877c478bd9Sstevel@tonic-gate char *opts = temp->ptr1; 7887c478bd9Sstevel@tonic-gate char *localmap = temp->ptr2; 7897c478bd9Sstevel@tonic-gate char **stack = temp->ptr3; 7907c478bd9Sstevel@tonic-gate char ***stkptr = temp->ptr4; 7917c478bd9Sstevel@tonic-gate int i; 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate /* 7947c478bd9Sstevel@tonic-gate * For the current entry, obtain the value and length of the cn i.e. 7957c478bd9Sstevel@tonic-gate * the contents of key and its key length. 7967c478bd9Sstevel@tonic-gate */ 7977c478bd9Sstevel@tonic-gate key_len = 0; 7987c478bd9Sstevel@tonic-gate key = NULL; 7997c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 8007c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attr; 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate attr = entry->attr_pair[i]; 8037c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, automountKey) == 0) { 8047c478bd9Sstevel@tonic-gate if (encode) 8057c478bd9Sstevel@tonic-gate key = tounix_str(attr->attrvalue[0]); 8067c478bd9Sstevel@tonic-gate else 8077c478bd9Sstevel@tonic-gate key = attr->attrvalue[0]; 8087c478bd9Sstevel@tonic-gate key_len = strlen(key); 8097c478bd9Sstevel@tonic-gate break; 8107c478bd9Sstevel@tonic-gate } 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate if (key_len >= 100 || key_len < 2) 8147c478bd9Sstevel@tonic-gate return (0); 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate if (isspace(*key) || *key == '#') 8177c478bd9Sstevel@tonic-gate return (0); 8187c478bd9Sstevel@tonic-gate (void) strncpy(dir, key, key_len); 8197c478bd9Sstevel@tonic-gate dir[key_len] = '\0'; 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate dirinit(dir, localmap, opts, 1, stack, stkptr); 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate return (0); 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate int 8277c478bd9Sstevel@tonic-gate getmapkeys_ldap(char *nsmap, struct dir_entry **list, int *error, 8287c478bd9Sstevel@tonic-gate int *cache_time, char **stack, char ***stkptr) 8297c478bd9Sstevel@tonic-gate { 8307c478bd9Sstevel@tonic-gate char searchfilter[LDAP_FILT_MAXSIZ]; 8317c478bd9Sstevel@tonic-gate int res; 8327c478bd9Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 8337c478bd9Sstevel@tonic-gate ns_ldap_error_t *errp = NULL; 8347c478bd9Sstevel@tonic-gate struct dir_cbdata readdir_cbdata; 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate #ifdef lint 8377c478bd9Sstevel@tonic-gate stack = stack; 8387c478bd9Sstevel@tonic-gate stkptr = stkptr; 8397c478bd9Sstevel@tonic-gate #endif /* lint */ 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate if (trace > 1) 8427c478bd9Sstevel@tonic-gate trace_prt(1, "getmapkeys_ldap called\n"); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate *cache_time = RDDIR_CACHE_TIME; 8457c478bd9Sstevel@tonic-gate *error = 0; 8467c478bd9Sstevel@tonic-gate readdir_cbdata.list = list; 8477c478bd9Sstevel@tonic-gate readdir_cbdata.last = NULL; 8487c478bd9Sstevel@tonic-gate 8497c478bd9Sstevel@tonic-gate /* filter gets all the entries for the specified mapname */ 8507c478bd9Sstevel@tonic-gate (void) sprintf(searchfilter, defaultFilter, "*"); 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate if (trace > 1) 8537c478bd9Sstevel@tonic-gate trace_prt(1, "getmapkeys_ldap: Requesting list for %s in %s\n", 8547c478bd9Sstevel@tonic-gate searchfilter, nsmap); 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate res = __ns_ldap_list(nsmap, searchfilter, NULL, NULL, NULL, 0, 8577c478bd9Sstevel@tonic-gate &result, &errp, readdir_callback, (void *) &readdir_cbdata); 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate if (trace > 1) 8607c478bd9Sstevel@tonic-gate trace_prt(1, " getmapkeys_ldap: __ns_ldap_list returned %d\n", 8617c478bd9Sstevel@tonic-gate res); 8627c478bd9Sstevel@tonic-gate 8637c478bd9Sstevel@tonic-gate if (readdir_cbdata.error) 8647c478bd9Sstevel@tonic-gate *error = readdir_cbdata.error; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate if (res != NS_LDAP_SUCCESS && res != NS_LDAP_NOTFOUND) { 8677c478bd9Sstevel@tonic-gate if (errp) { 8687c478bd9Sstevel@tonic-gate if (verbose) { 8697c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 8707c478bd9Sstevel@tonic-gate (void) sprintf(errstr, gettext( 8717c478bd9Sstevel@tonic-gate "ldap server can't list map," 8727c478bd9Sstevel@tonic-gate " '%s': '%s' - '%d'."), 8737c478bd9Sstevel@tonic-gate nsmap, errp->message, errp->status); 8747c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errstr); 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate __ns_ldap_freeError(&errp); 8777c478bd9Sstevel@tonic-gate } else { 8787c478bd9Sstevel@tonic-gate if (verbose) { 8797c478bd9Sstevel@tonic-gate char *errmsg; 8807c478bd9Sstevel@tonic-gate __ns_ldap_err2str(res, &errmsg); 8817c478bd9Sstevel@tonic-gate syslog(LOG_ERR, errmsg); 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate } 8847c478bd9Sstevel@tonic-gate if (result) 8857c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 8867c478bd9Sstevel@tonic-gate if (*error == 0) 8877c478bd9Sstevel@tonic-gate *error = ECOMM; 8887c478bd9Sstevel@tonic-gate return (ldap_err(res)); 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate if (result) 8917c478bd9Sstevel@tonic-gate __ns_ldap_freeResult(&result); 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate return (__NSW_SUCCESS); 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate static int 8977c478bd9Sstevel@tonic-gate readdir_callback(const ns_ldap_entry_t *entry, const void *udata) 8987c478bd9Sstevel@tonic-gate { 8997c478bd9Sstevel@tonic-gate char *key; 9007c478bd9Sstevel@tonic-gate int key_len; 9017c478bd9Sstevel@tonic-gate struct dir_cbdata *temp = (struct dir_cbdata *)udata; 9027c478bd9Sstevel@tonic-gate struct dir_entry **list = temp->list; 9037c478bd9Sstevel@tonic-gate struct dir_entry *last = temp->last; 9047c478bd9Sstevel@tonic-gate int i; 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate if (trace > 1) 9077c478bd9Sstevel@tonic-gate trace_prt(1, "readdir_callback called\n"); 9087c478bd9Sstevel@tonic-gate /* 9097c478bd9Sstevel@tonic-gate * For the current entry, obtain the value and length of the cn i.e. the 9107c478bd9Sstevel@tonic-gate * contents of key and its key length. 9117c478bd9Sstevel@tonic-gate */ 9127c478bd9Sstevel@tonic-gate key_len = 0; 9137c478bd9Sstevel@tonic-gate key = NULL; 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate if (trace > 1) 9167c478bd9Sstevel@tonic-gate trace_prt(1, "readdir_callback: entry->attr_count=[ %d ]\n", 9177c478bd9Sstevel@tonic-gate entry->attr_count); 9187c478bd9Sstevel@tonic-gate 9197c478bd9Sstevel@tonic-gate for (i = 0; i < entry->attr_count; i++) { 9207c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attr; 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate attr = entry->attr_pair[i]; 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate if (trace > 1) 9257c478bd9Sstevel@tonic-gate trace_prt(1, 9267c478bd9Sstevel@tonic-gate "readdir_callback: attr->attrname=[ %s ]\n", 9277c478bd9Sstevel@tonic-gate attr->attrname); 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate if (strcasecmp(attr->attrname, automountKey) == 0) { 9307c478bd9Sstevel@tonic-gate if (encode) 9317c478bd9Sstevel@tonic-gate key = tounix_str(attr->attrvalue[0]); 9327c478bd9Sstevel@tonic-gate else 9337c478bd9Sstevel@tonic-gate key = attr->attrvalue[0]; 9347c478bd9Sstevel@tonic-gate key_len = strlen(key); 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate if (trace > 1) 9377c478bd9Sstevel@tonic-gate trace_prt(1, 9387c478bd9Sstevel@tonic-gate "readdir_callback: key=[ %s ], key_len=[ %d ]\n", 9397c478bd9Sstevel@tonic-gate key, key_len); 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate break; 9427c478bd9Sstevel@tonic-gate } 9437c478bd9Sstevel@tonic-gate } 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate if (key_len >= 100 || key_len < 2) 9467c478bd9Sstevel@tonic-gate return (0); 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate if (isspace(*key) || *key == '#') 9497c478bd9Sstevel@tonic-gate return (0); 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate /* 9527c478bd9Sstevel@tonic-gate * Wildcard entry should be ignored - following entries should continue 9537c478bd9Sstevel@tonic-gate * to be read to corroborate with the way we search for entries in 9547c478bd9Sstevel@tonic-gate * LDAP, i.e., first for an exact key match and then a wildcard 9557c478bd9Sstevel@tonic-gate * if there's no exact key match. 9567c478bd9Sstevel@tonic-gate */ 9577c478bd9Sstevel@tonic-gate if (key[0] == '*' && key[1] == '\0') 9587c478bd9Sstevel@tonic-gate return (0); 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate if (add_dir_entry(key, list, &last)) { 9617c478bd9Sstevel@tonic-gate temp->error = ENOMEM; 9627c478bd9Sstevel@tonic-gate return (1); 9637c478bd9Sstevel@tonic-gate } 9647c478bd9Sstevel@tonic-gate 9657c478bd9Sstevel@tonic-gate temp->last = last; 9667c478bd9Sstevel@tonic-gate temp->error = 0; 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate if (trace > 1) 9697c478bd9Sstevel@tonic-gate trace_prt(1, "readdir_callback returning 0...\n"); 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate return (0); 9727c478bd9Sstevel@tonic-gate } 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate /* 9757c478bd9Sstevel@tonic-gate * Puts CAPCHAR in front of uppercase characters or surrounds a set of 9767c478bd9Sstevel@tonic-gate * contiguous uppercase characters with CAPCHARS and square brackets. 9777c478bd9Sstevel@tonic-gate * 9787c478bd9Sstevel@tonic-gate * For example (assuming CAPCHAR = '%'): 9797c478bd9Sstevel@tonic-gate * 9807c478bd9Sstevel@tonic-gate * if str = Abc, it returns %Abc 9817c478bd9Sstevel@tonic-gate * if str = ABc, it returns %[AB]c 9827c478bd9Sstevel@tonic-gate * if str = AbC, it returns %Ab%C 9837c478bd9Sstevel@tonic-gate * 9847c478bd9Sstevel@tonic-gate */ 9857c478bd9Sstevel@tonic-gate static char * 9867c478bd9Sstevel@tonic-gate tosunds_str(char *str) 9877c478bd9Sstevel@tonic-gate { 9887c478bd9Sstevel@tonic-gate static char buf[BUFSIZ]; 9897c478bd9Sstevel@tonic-gate int i, j, er = FALSE; 9907c478bd9Sstevel@tonic-gate #ifdef NEWCAP 9917c478bd9Sstevel@tonic-gate int openBracket = FALSE, closeBracket = FALSE; 9927c478bd9Sstevel@tonic-gate #endif 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate (void) memset(buf, 0, BUFSIZ); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate j = 0; 9977c478bd9Sstevel@tonic-gate for (i = 0; i < strlen(str); i++) { 9987c478bd9Sstevel@tonic-gate /* Check the current element */ 9997c478bd9Sstevel@tonic-gate if (isupper(str[i])) { 10007c478bd9Sstevel@tonic-gate #ifdef NEWCAP 10017c478bd9Sstevel@tonic-gate /* check the next element */ 10027c478bd9Sstevel@tonic-gate if (isupper(str[i+1])) { 10037c478bd9Sstevel@tonic-gate if (openBracket == FALSE) { 10047c478bd9Sstevel@tonic-gate openBracket = TRUE; 10057c478bd9Sstevel@tonic-gate buf[j] = CAPCHAR; 10067c478bd9Sstevel@tonic-gate buf[j+1] = '['; 10077c478bd9Sstevel@tonic-gate j += 2; 10087c478bd9Sstevel@tonic-gate } 10097c478bd9Sstevel@tonic-gate } else { 10107c478bd9Sstevel@tonic-gate if (openBracket == FALSE) { 10117c478bd9Sstevel@tonic-gate buf[j] = CAPCHAR; 10127c478bd9Sstevel@tonic-gate j++; 10137c478bd9Sstevel@tonic-gate } else { 10147c478bd9Sstevel@tonic-gate openBracket = FALSE; 10157c478bd9Sstevel@tonic-gate closeBracket = TRUE; 10167c478bd9Sstevel@tonic-gate } 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate #else 10197c478bd9Sstevel@tonic-gate buf[j++] = CAPCHAR; 10207c478bd9Sstevel@tonic-gate #endif 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate buf[j] = str[i]; 10237c478bd9Sstevel@tonic-gate j++; 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate #ifdef NEWCAP 10267c478bd9Sstevel@tonic-gate if (closeBracket == TRUE) { 10277c478bd9Sstevel@tonic-gate closeBracket = FALSE; 10287c478bd9Sstevel@tonic-gate buf[j] = ']'; 10297c478bd9Sstevel@tonic-gate j++; 10307c478bd9Sstevel@tonic-gate } 10317c478bd9Sstevel@tonic-gate #endif 10327c478bd9Sstevel@tonic-gate if (j >= BUFSIZ) { 10337c478bd9Sstevel@tonic-gate er = TRUE; 10347c478bd9Sstevel@tonic-gate break; 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate } 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate if (er) { 10397c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "Buffer size exceeded."); 10407c478bd9Sstevel@tonic-gate (void) memset(buf, 0, BUFSIZ); 10417c478bd9Sstevel@tonic-gate } else 10427c478bd9Sstevel@tonic-gate buf[j] = '\0'; 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate return (buf); 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate } 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate /* 10497c478bd9Sstevel@tonic-gate * Reverses what tosunds_str() did 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate static char * 10527c478bd9Sstevel@tonic-gate tounix_str(char *str) 10537c478bd9Sstevel@tonic-gate { 10547c478bd9Sstevel@tonic-gate static char buf[BUFSIZ]; 10557c478bd9Sstevel@tonic-gate int i, j; 10567c478bd9Sstevel@tonic-gate int openBracket = FALSE; 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate (void) memset(buf, 0, BUFSIZ); 10597c478bd9Sstevel@tonic-gate j = 0; 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate for (i = 0; i < strlen(str); i++) { 10627c478bd9Sstevel@tonic-gate if (str[i] == '%') { 10637c478bd9Sstevel@tonic-gate if (isupper(str[i+1])) { 10647c478bd9Sstevel@tonic-gate i += 1; 10657c478bd9Sstevel@tonic-gate } else if ((str[i+1] == '[') && (isupper(str[i+2]))) { 10667c478bd9Sstevel@tonic-gate i += 2; 10677c478bd9Sstevel@tonic-gate openBracket = TRUE; 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate } else if (str[i] == ']') { 10707c478bd9Sstevel@tonic-gate if ((isupper(str[i-1])) && (openBracket == TRUE)) 10717c478bd9Sstevel@tonic-gate i += 1; 10727c478bd9Sstevel@tonic-gate openBracket = FALSE; 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate buf[j] = str[i]; 10757c478bd9Sstevel@tonic-gate j++; 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate return (buf); 10787c478bd9Sstevel@tonic-gate } 1079