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 /* 22*36e852a1SRaja Andra * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <lber.h> 287c478bd9Sstevel@tonic-gate #include <ldap.h> 297c478bd9Sstevel@tonic-gate #include <strings.h> 307c478bd9Sstevel@tonic-gate #include <errno.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include "nisdb_mt.h" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include "ldap_util.h" 357c478bd9Sstevel@tonic-gate #include "ldap_op.h" 367c478bd9Sstevel@tonic-gate #include "ldap_ruleval.h" 377c478bd9Sstevel@tonic-gate #include "ldap_attr.h" 387c478bd9Sstevel@tonic-gate #include "ldap_val.h" 397c478bd9Sstevel@tonic-gate #include "ldap_ldap.h" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate extern int yp2ldap; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate __nis_mapping_format_t * 457c478bd9Sstevel@tonic-gate cloneMappingFormat(__nis_mapping_format_t *m) { 467c478bd9Sstevel@tonic-gate __nis_mapping_format_t *new; 477c478bd9Sstevel@tonic-gate int i, nf, err; 487c478bd9Sstevel@tonic-gate char *myself = "cloneMappingFormat"; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate if (m == 0) 517c478bd9Sstevel@tonic-gate return (0); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate for (nf = 0; m[nf].type != mmt_end; nf++); 547c478bd9Sstevel@tonic-gate nf++; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate new = am(myself, nf * sizeof (new[0])); 577c478bd9Sstevel@tonic-gate if (new == 0) 587c478bd9Sstevel@tonic-gate return (0); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* Copy the whole array */ 617c478bd9Sstevel@tonic-gate memcpy(new, m, nf * sizeof (new[0])); 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* Make copies of allocated stuff */ 647c478bd9Sstevel@tonic-gate for (i = 0, err = 0; i < nf; i++) { 657c478bd9Sstevel@tonic-gate switch (m[i].type) { 667c478bd9Sstevel@tonic-gate case mmt_string: 677c478bd9Sstevel@tonic-gate new[i].match.string = sdup(myself, T, 687c478bd9Sstevel@tonic-gate m[i].match.string); 697c478bd9Sstevel@tonic-gate if (new[i].match.string == 0 && m[i].match.string != 0) 707c478bd9Sstevel@tonic-gate err++; 717c478bd9Sstevel@tonic-gate break; 727c478bd9Sstevel@tonic-gate case mmt_single: 737c478bd9Sstevel@tonic-gate new[i].match.single.lo = 747c478bd9Sstevel@tonic-gate am(myself, m[i].match.single.numRange * 757c478bd9Sstevel@tonic-gate sizeof (new[i].match.single.lo[0])); 767c478bd9Sstevel@tonic-gate new[i].match.single.hi = 777c478bd9Sstevel@tonic-gate am(myself, m[i].match.single.numRange * 787c478bd9Sstevel@tonic-gate sizeof (new[i].match.single.hi[0])); 797c478bd9Sstevel@tonic-gate if (new[i].match.single.lo != 0) 807c478bd9Sstevel@tonic-gate memcpy(new[i].match.single.lo, 817c478bd9Sstevel@tonic-gate m[i].match.single.lo, 827c478bd9Sstevel@tonic-gate m[i].match.single.numRange); 837c478bd9Sstevel@tonic-gate else if (m[i].match.single.lo != 0) 847c478bd9Sstevel@tonic-gate err++; 857c478bd9Sstevel@tonic-gate if (new[i].match.single.hi != 0) 867c478bd9Sstevel@tonic-gate memcpy(new[i].match.single.hi, 877c478bd9Sstevel@tonic-gate m[i].match.single.hi, 887c478bd9Sstevel@tonic-gate m[i].match.single.numRange); 897c478bd9Sstevel@tonic-gate else if (m[i].match.single.hi != 0) 907c478bd9Sstevel@tonic-gate err++; 917c478bd9Sstevel@tonic-gate break; 927c478bd9Sstevel@tonic-gate case mmt_berstring: 937c478bd9Sstevel@tonic-gate new[i].match.berString = sdup(myself, T, 947c478bd9Sstevel@tonic-gate m[i].match.berString); 957c478bd9Sstevel@tonic-gate if (new[i].match.berString == 0 && 967c478bd9Sstevel@tonic-gate m[i].match.berString != 0) 977c478bd9Sstevel@tonic-gate err++; 987c478bd9Sstevel@tonic-gate break; 997c478bd9Sstevel@tonic-gate case mmt_item: 1007c478bd9Sstevel@tonic-gate case mmt_limit: 1017c478bd9Sstevel@tonic-gate case mmt_any: 1027c478bd9Sstevel@tonic-gate case mmt_begin: 1037c478bd9Sstevel@tonic-gate case mmt_end: 1047c478bd9Sstevel@tonic-gate default: 1057c478bd9Sstevel@tonic-gate break; 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* If there were memory allocation errors, free the copy */ 1107c478bd9Sstevel@tonic-gate if (err > 0) { 1117c478bd9Sstevel@tonic-gate freeMappingFormat(new); 1127c478bd9Sstevel@tonic-gate new = 0; 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate return (new); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate void 1197c478bd9Sstevel@tonic-gate freeMappingFormat(__nis_mapping_format_t *m) { 1207c478bd9Sstevel@tonic-gate int i; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate if (m == 0) 1237c478bd9Sstevel@tonic-gate return; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate for (i = 0; m[i].type != mmt_end; i++) { 1267c478bd9Sstevel@tonic-gate switch (m[i].type) { 1277c478bd9Sstevel@tonic-gate case mmt_string: 1287c478bd9Sstevel@tonic-gate sfree(m[i].match.string); 1297c478bd9Sstevel@tonic-gate break; 1307c478bd9Sstevel@tonic-gate case mmt_single: 1317c478bd9Sstevel@tonic-gate sfree(m[i].match.single.lo); 1327c478bd9Sstevel@tonic-gate sfree(m[i].match.single.hi); 1337c478bd9Sstevel@tonic-gate break; 1347c478bd9Sstevel@tonic-gate case mmt_berstring: 1357c478bd9Sstevel@tonic-gate sfree(m[i].match.berString); 1367c478bd9Sstevel@tonic-gate break; 1377c478bd9Sstevel@tonic-gate case mmt_item: 1387c478bd9Sstevel@tonic-gate case mmt_limit: 1397c478bd9Sstevel@tonic-gate case mmt_any: 1407c478bd9Sstevel@tonic-gate case mmt_begin: 1417c478bd9Sstevel@tonic-gate case mmt_end: 1427c478bd9Sstevel@tonic-gate default: 1437c478bd9Sstevel@tonic-gate break; 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate free(m); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate void 1527c478bd9Sstevel@tonic-gate copyIndex(__nis_index_t *old, __nis_index_t *new, int *err) { 1537c478bd9Sstevel@tonic-gate int i; 1547c478bd9Sstevel@tonic-gate char *myself = "copyIndex"; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate if (old == 0 || new == 0) { 1577c478bd9Sstevel@tonic-gate *err = EINVAL; 1587c478bd9Sstevel@tonic-gate return; 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate for (i = 0; i < old->numIndexes; i++) { 1627c478bd9Sstevel@tonic-gate new->name[i] = sdup(myself, T, old->name[i]); 1637c478bd9Sstevel@tonic-gate if (new->name[i] == 0 && old->name[i] != 0) { 1647c478bd9Sstevel@tonic-gate *err = ENOMEM; 1657c478bd9Sstevel@tonic-gate return; 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate new->value[i] = cloneMappingFormat(old->value[i]); 1687c478bd9Sstevel@tonic-gate if (new->value[i] == 0 && old->value[i] != 0) { 1697c478bd9Sstevel@tonic-gate *err = ENOMEM; 1707c478bd9Sstevel@tonic-gate return; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate new->numIndexes = old->numIndexes; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate __nis_index_t * 1787c478bd9Sstevel@tonic-gate cloneIndex(__nis_index_t *old) { 1797c478bd9Sstevel@tonic-gate char *myself = "cloneIndex"; 1807c478bd9Sstevel@tonic-gate int err = 0; 1817c478bd9Sstevel@tonic-gate __nis_index_t *new = am(myself, sizeof (*new)); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate if (old == 0) 1847c478bd9Sstevel@tonic-gate return (0); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate if (new != 0) { 1877c478bd9Sstevel@tonic-gate copyIndex(old, new, &err); 1887c478bd9Sstevel@tonic-gate if (err != 0) { 1897c478bd9Sstevel@tonic-gate freeIndex(new, 1); 1907c478bd9Sstevel@tonic-gate new = 0; 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate return (new); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate void 1987c478bd9Sstevel@tonic-gate freeIndex(__nis_index_t *old, bool_t doFree) { 1997c478bd9Sstevel@tonic-gate int i; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate if (old == 0) 2027c478bd9Sstevel@tonic-gate return; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate for (i = 0; i < old->numIndexes; i++) { 2057c478bd9Sstevel@tonic-gate sfree(old->name[i]); 2067c478bd9Sstevel@tonic-gate freeMappingFormat(old->value[i]); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate if (doFree) 2107c478bd9Sstevel@tonic-gate free(old); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate char ** 2147c478bd9Sstevel@tonic-gate cloneName(char **name, int numNames) { 2157c478bd9Sstevel@tonic-gate char **new; 2167c478bd9Sstevel@tonic-gate int i; 2177c478bd9Sstevel@tonic-gate char *myself = "cloneName"; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if (name == 0 || numNames <= 0) 2207c478bd9Sstevel@tonic-gate return (0); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate new = am(myself, numNames * sizeof (new[0])); 2237c478bd9Sstevel@tonic-gate if (new == 0) 2247c478bd9Sstevel@tonic-gate return (0); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate for (i = 0; i < numNames; i++) { 2277c478bd9Sstevel@tonic-gate if (name[i] != 0) { 2287c478bd9Sstevel@tonic-gate new[i] = sdup(myself, T, name[i]); 2297c478bd9Sstevel@tonic-gate if (new[i] == 0) { 2307c478bd9Sstevel@tonic-gate for (i--; i >= 0; i--) { 2317c478bd9Sstevel@tonic-gate sfree(new[i]); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate sfree(new); 2347c478bd9Sstevel@tonic-gate return (0); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate } else { 2377c478bd9Sstevel@tonic-gate new[i] = 0; 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate return (new); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate void 2457c478bd9Sstevel@tonic-gate freeValue(__nis_value_t *val, int count) { 2467c478bd9Sstevel@tonic-gate int c, i; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate if (val == 0) 2497c478bd9Sstevel@tonic-gate return; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate for (c = 0; c < count; c++) { 2527c478bd9Sstevel@tonic-gate if (val[c].val != 0) { 2537c478bd9Sstevel@tonic-gate for (i = 0; i < val[c].numVals; i++) { 2547c478bd9Sstevel@tonic-gate sfree(val[c].val[i].value); 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate free(val[c].val); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate free(val); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate __nis_value_t * 2647c478bd9Sstevel@tonic-gate cloneValue(__nis_value_t *val, int count) { 2657c478bd9Sstevel@tonic-gate __nis_value_t *n; 2667c478bd9Sstevel@tonic-gate int c, i; 2677c478bd9Sstevel@tonic-gate char *myself = "cloneValue"; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (count <= 0 || val == 0) 2707c478bd9Sstevel@tonic-gate return (0); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate n = am(myself, count * sizeof (*n)); 2737c478bd9Sstevel@tonic-gate if (n == 0) 2747c478bd9Sstevel@tonic-gate return (0); 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate for (c = 0; c < count; c++) { 2777c478bd9Sstevel@tonic-gate n[c].type = val[c].type; 2787c478bd9Sstevel@tonic-gate n[c].repeat = val[c].repeat; 2797c478bd9Sstevel@tonic-gate n[c].numVals = val[c].numVals; 2807c478bd9Sstevel@tonic-gate if (n[c].numVals > 0) { 2817c478bd9Sstevel@tonic-gate n[c].val = am(myself, n[c].numVals * 2827c478bd9Sstevel@tonic-gate sizeof (n[c].val[0])); 2837c478bd9Sstevel@tonic-gate if (n[c].val == 0) { 2847c478bd9Sstevel@tonic-gate freeValue(n, c); 2857c478bd9Sstevel@tonic-gate return (0); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate } else { 2887c478bd9Sstevel@tonic-gate n[c].val = 0; 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate for (i = 0; i < n[c].numVals; i++) { 2917c478bd9Sstevel@tonic-gate int amlen = val[c].val[i].length; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * The functions that create string values try to 2957c478bd9Sstevel@tonic-gate * make sure that there's a NUL at the end. However, 2967c478bd9Sstevel@tonic-gate * both NIS+ and LDAP have a tendency to store strings 2977c478bd9Sstevel@tonic-gate * without a NUL, so the value length may not include 2987c478bd9Sstevel@tonic-gate * the NUL (even though it's there). In order to 2997c478bd9Sstevel@tonic-gate * preserve that NUL, we add a byte to the length if 3007c478bd9Sstevel@tonic-gate * the type is vt_string, and there isn't already a 3017c478bd9Sstevel@tonic-gate * NUL at the end. The memory allocation function 3027c478bd9Sstevel@tonic-gate * (am()) will take care of actually putting the NUL 3037c478bd9Sstevel@tonic-gate * in place, since it allocates zero-initialized 3047c478bd9Sstevel@tonic-gate * memory. 3057c478bd9Sstevel@tonic-gate */ 3067c478bd9Sstevel@tonic-gate n[c].val[i].length = val[c].val[i].length; 3077c478bd9Sstevel@tonic-gate if (n[c].type == vt_string && amlen > 0 && 3087c478bd9Sstevel@tonic-gate ((char *)val[c].val[i].value)[amlen-1] != 3097c478bd9Sstevel@tonic-gate '\0') { 3107c478bd9Sstevel@tonic-gate amlen++; 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate n[c].val[i].value = am(myself, amlen); 3137c478bd9Sstevel@tonic-gate if (amlen > 0 && n[c].val[i].value == 0) { 3147c478bd9Sstevel@tonic-gate freeValue(n, c); 3157c478bd9Sstevel@tonic-gate return (0); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate memcpy(n[c].val[i].value, val[c].val[i].value, 3187c478bd9Sstevel@tonic-gate n[c].val[i].length); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate return (n); 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* Define LBER_USE_DER per ber_decode(3LDAP) */ 3267c478bd9Sstevel@tonic-gate #ifndef LBER_USE_DER 3277c478bd9Sstevel@tonic-gate #define LBER_USE_DER 0x01 3287c478bd9Sstevel@tonic-gate #endif /* LBER_USE_DER */ 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* 3317c478bd9Sstevel@tonic-gate * Return a copy of 'valIn' where each value has been replaced by the 3327c478bd9Sstevel@tonic-gate * BER encoded equivalent specified by 'berstring'. 'valIn' is unchanged. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate __nis_value_t * 3357c478bd9Sstevel@tonic-gate berEncode(__nis_value_t *valIn, char *berstring) { 3367c478bd9Sstevel@tonic-gate char *myself = "berEncode"; 3377c478bd9Sstevel@tonic-gate __nis_value_t *val; 3387c478bd9Sstevel@tonic-gate int i; 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate if (valIn == 0 || berstring == 0) 3417c478bd9Sstevel@tonic-gate return (0); 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate val = cloneValue(valIn, 1); 3447c478bd9Sstevel@tonic-gate if (val == 0) 3457c478bd9Sstevel@tonic-gate return (0); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate for (i = 0; i < val->numVals; i++) { 3487c478bd9Sstevel@tonic-gate BerElement *ber = ber_alloc(); 3497c478bd9Sstevel@tonic-gate struct berval *bv = 0; 3507c478bd9Sstevel@tonic-gate int ret; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate if (ber == 0) { 3537c478bd9Sstevel@tonic-gate logmsg(MSG_NOMEM, LOG_ERR, "%s: ber_alloc() => NULL", 3547c478bd9Sstevel@tonic-gate myself); 3557c478bd9Sstevel@tonic-gate freeValue(val, 1); 3567c478bd9Sstevel@tonic-gate return (0); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate if ((strcmp("b", berstring) == 0 || 3607c478bd9Sstevel@tonic-gate strcmp("i", berstring) == 0)) { 3617c478bd9Sstevel@tonic-gate if (val->val[i].length >= sizeof (int)) { 3627c478bd9Sstevel@tonic-gate ret = ber_printf(ber, berstring, 3637c478bd9Sstevel@tonic-gate *((int *)(val->val[i].value))); 3647c478bd9Sstevel@tonic-gate } else { 3657c478bd9Sstevel@tonic-gate ret = -1; 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate } else if (strcmp("B", berstring) == 0) { 3687c478bd9Sstevel@tonic-gate ret = ber_printf(ber, berstring, 3697c478bd9Sstevel@tonic-gate val->val[i].value, 3707c478bd9Sstevel@tonic-gate val->val[i].length * 8); 3717c478bd9Sstevel@tonic-gate } else if (strcmp("n", berstring) == 0) { 3727c478bd9Sstevel@tonic-gate ret = ber_printf(ber, berstring); 3737c478bd9Sstevel@tonic-gate } else if (strcmp("o", berstring) == 0) { 3747c478bd9Sstevel@tonic-gate ret = ber_printf(ber, berstring, 3757c478bd9Sstevel@tonic-gate val->val[i].value, val->val[i].length); 3767c478bd9Sstevel@tonic-gate } else if (strcmp("s", berstring) == 0) { 3777c478bd9Sstevel@tonic-gate char *str = am(myself, val->val[i].length + 1); 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate if (str != 0) { 3807c478bd9Sstevel@tonic-gate ret = ber_printf(ber, berstring, str); 3817c478bd9Sstevel@tonic-gate free(str); 3827c478bd9Sstevel@tonic-gate } else { 3837c478bd9Sstevel@tonic-gate ret = -1; 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate } else { 3867c478bd9Sstevel@tonic-gate ret = -1; 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate if (ret == -1) { 3907c478bd9Sstevel@tonic-gate reportError(NPL_BERENCODE, "%s: BER encoding error", 3917c478bd9Sstevel@tonic-gate myself); 3927c478bd9Sstevel@tonic-gate ber_free(ber, 1); 3937c478bd9Sstevel@tonic-gate freeValue(val, 1); 3947c478bd9Sstevel@tonic-gate return (0); 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if (ber_flatten(ber, &bv) != 0 || bv == 0) { 3987c478bd9Sstevel@tonic-gate reportError(NPL_BERENCODE, "%s: ber_flatten() error", 3997c478bd9Sstevel@tonic-gate myself); 4007c478bd9Sstevel@tonic-gate ber_free(ber, 1); 4017c478bd9Sstevel@tonic-gate freeValue(val, 1); 4027c478bd9Sstevel@tonic-gate return (0); 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate sfree(val->val[i].value); 4067c478bd9Sstevel@tonic-gate val->val[i].length = bv->bv_len; 4077c478bd9Sstevel@tonic-gate val->val[i].value = bv->bv_val; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate ber_free(ber, 1); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate val->type = vt_ber; 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate return (val); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate __nis_value_t * 4187c478bd9Sstevel@tonic-gate berDecode(__nis_value_t *valIn, char *berstring) { 4197c478bd9Sstevel@tonic-gate __nis_value_t *val; 4207c478bd9Sstevel@tonic-gate int i; 4217c478bd9Sstevel@tonic-gate char *myself = "berDecode"; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate if (valIn == 0 || berstring == 0) 4247c478bd9Sstevel@tonic-gate return (0); 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate val = cloneValue(valIn, 1); 4277c478bd9Sstevel@tonic-gate if (val == 0) 4287c478bd9Sstevel@tonic-gate return (0); 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate for (i = 0; i < val->numVals; i++) { 4317c478bd9Sstevel@tonic-gate void *v = 0; 4327c478bd9Sstevel@tonic-gate int ret, len = 0; 4337c478bd9Sstevel@tonic-gate struct berval bv; 4347c478bd9Sstevel@tonic-gate BerElement *ber; 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate if (val->val[i].value == 0 || val->val[i].length <= 0) 4377c478bd9Sstevel@tonic-gate continue; 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate bv.bv_val = val->val[i].value; 4407c478bd9Sstevel@tonic-gate bv.bv_len = val->val[i].length; 4417c478bd9Sstevel@tonic-gate ber = ber_init(&bv); 4427c478bd9Sstevel@tonic-gate if (ber == 0) { 4437c478bd9Sstevel@tonic-gate reportError(NPL_BERDECODE, "%s: ber_init() error", 4447c478bd9Sstevel@tonic-gate myself); 4457c478bd9Sstevel@tonic-gate freeValue(val, 1); 4467c478bd9Sstevel@tonic-gate return (0); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate if ((strcmp("b", berstring) == 0 || 4507c478bd9Sstevel@tonic-gate strcmp("i", berstring) == 0)) { 4517c478bd9Sstevel@tonic-gate len = sizeof (int); 4527c478bd9Sstevel@tonic-gate v = am(myself, len); 4537c478bd9Sstevel@tonic-gate if (v != 0) { 4547c478bd9Sstevel@tonic-gate ret = ber_scanf(ber, berstring, v); 4557c478bd9Sstevel@tonic-gate } else { 4567c478bd9Sstevel@tonic-gate ret = -1; 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate } else if (strcmp("B", berstring) == 0) { 4597c478bd9Sstevel@tonic-gate long llen; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate ret = ber_scanf(ber, berstring, &v, &llen); 4627c478bd9Sstevel@tonic-gate if (ret != -1) { 4637c478bd9Sstevel@tonic-gate len = llen/8; 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate } else if (strcmp("n", berstring) == 0) { 4667c478bd9Sstevel@tonic-gate ret = 0; 4677c478bd9Sstevel@tonic-gate } else if (strcmp("o", berstring) == 0) { 4687c478bd9Sstevel@tonic-gate struct berval *bv = am(myself, sizeof (*bv)); 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate if (bv != 0) { 4717c478bd9Sstevel@tonic-gate ret = ber_scanf(ber, "O", &bv); 4727c478bd9Sstevel@tonic-gate if (ret != -1 && bv != 0) { 4737c478bd9Sstevel@tonic-gate v = bv->bv_val; 4747c478bd9Sstevel@tonic-gate len = bv->bv_len; 4757c478bd9Sstevel@tonic-gate } else { 4767c478bd9Sstevel@tonic-gate ret = -1; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate /* Only free 'bv' itself */ 4797c478bd9Sstevel@tonic-gate free(bv); 4807c478bd9Sstevel@tonic-gate } else { 4817c478bd9Sstevel@tonic-gate ret = -1; 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate } else if (strcmp("s", berstring) == 0) { 4847c478bd9Sstevel@tonic-gate ret = ber_scanf(ber, "a", &v); 4857c478bd9Sstevel@tonic-gate if (ret != -1) { 4867c478bd9Sstevel@tonic-gate len = slen(v); 4877c478bd9Sstevel@tonic-gate } 4887c478bd9Sstevel@tonic-gate } else { 4897c478bd9Sstevel@tonic-gate ret = -1; 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate if (ret == -1) { 4937c478bd9Sstevel@tonic-gate reportError(NPL_BERDECODE, "%s: BER decoding error", 4947c478bd9Sstevel@tonic-gate myself); 4957c478bd9Sstevel@tonic-gate freeValue(val, 1); 4967c478bd9Sstevel@tonic-gate return (0); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate /* Free the old value, and replace it with the decoded one */ 5007c478bd9Sstevel@tonic-gate sfree(val->val[i].value); 5017c478bd9Sstevel@tonic-gate val->val[i].value = v; 5027c478bd9Sstevel@tonic-gate val->val[i].length = len; 5037c478bd9Sstevel@tonic-gate } 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate return (val); 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* 5097c478bd9Sstevel@tonic-gate * Return the value of the specified item. 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate __nis_value_t * 5127c478bd9Sstevel@tonic-gate getMappingItemVal(__nis_mapping_item_t *item, __nis_mapping_item_type_t native, 5137c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv, char *berstring, int *np_ldap_stat) { 5147c478bd9Sstevel@tonic-gate __nis_value_t *val = 0, *nameVal, *exVal = 0; 5157c478bd9Sstevel@tonic-gate int numName, caseInsens, cmp; 5167c478bd9Sstevel@tonic-gate int i, j, k; 5177c478bd9Sstevel@tonic-gate char **name; 5187c478bd9Sstevel@tonic-gate enum {rvOnly, rvThenLookup, lookupOnly} check; 5197c478bd9Sstevel@tonic-gate unsigned char fromldap = '\0'; 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate if (item == 0) 5227c478bd9Sstevel@tonic-gate return (0); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate /* 5257c478bd9Sstevel@tonic-gate * First, we decide if we should look for the value in 'rv', 5267c478bd9Sstevel@tonic-gate * directly from NIS+/LDAP, or both. 5277c478bd9Sstevel@tonic-gate */ 5287c478bd9Sstevel@tonic-gate switch (item->type) { 5297c478bd9Sstevel@tonic-gate case mit_nisplus: 5307c478bd9Sstevel@tonic-gate /* Do we have a valid index/object spec ? */ 5317c478bd9Sstevel@tonic-gate if (item->searchSpec.obj.index.numIndexes <= 0 && 5327c478bd9Sstevel@tonic-gate item->searchSpec.obj.name == 0) { 5337c478bd9Sstevel@tonic-gate /* 5347c478bd9Sstevel@tonic-gate * No valid index/object. If we have a rule-value, 5357c478bd9Sstevel@tonic-gate * use it. Otherwise, return error. 5367c478bd9Sstevel@tonic-gate */ 5377c478bd9Sstevel@tonic-gate if (rv != 0) { 5387c478bd9Sstevel@tonic-gate name = rv->colName; 5397c478bd9Sstevel@tonic-gate nameVal = rv->colVal; 5407c478bd9Sstevel@tonic-gate numName = rv->numColumns; 5417c478bd9Sstevel@tonic-gate caseInsens = 0; 5427c478bd9Sstevel@tonic-gate check = rvOnly; 5437c478bd9Sstevel@tonic-gate } else { 5447c478bd9Sstevel@tonic-gate return (0); 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate } else { 5477c478bd9Sstevel@tonic-gate /* 5487c478bd9Sstevel@tonic-gate * Valid index, so skip the rule-value and do 5497c478bd9Sstevel@tonic-gate * a direct NIS+ lookup. 5507c478bd9Sstevel@tonic-gate */ 5517c478bd9Sstevel@tonic-gate check = lookupOnly; 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate break; 5547c478bd9Sstevel@tonic-gate case mit_ldap: 5557c478bd9Sstevel@tonic-gate if (rv != 0) { 5567c478bd9Sstevel@tonic-gate name = rv->attrName; 5577c478bd9Sstevel@tonic-gate nameVal = rv->attrVal; 5587c478bd9Sstevel@tonic-gate numName = rv->numAttrs; 5597c478bd9Sstevel@tonic-gate caseInsens = 1; 5607c478bd9Sstevel@tonic-gate fromldap = '1'; 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate /* Do we have a valid triple ? */ 5637c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.scope == LDAP_SCOPE_UNKNOWN) { 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * No valid triple. If we have a rule-value, use it. 5667c478bd9Sstevel@tonic-gate * Otherwise, return error. 5677c478bd9Sstevel@tonic-gate */ 5687c478bd9Sstevel@tonic-gate if (rv != 0) { 5697c478bd9Sstevel@tonic-gate check = rvOnly; 5707c478bd9Sstevel@tonic-gate } else { 5717c478bd9Sstevel@tonic-gate return (0); 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate } else if (item->searchSpec.triple.base == 0 && 5747c478bd9Sstevel@tonic-gate item->searchSpec.triple.scope == 5757c478bd9Sstevel@tonic-gate LDAP_SCOPE_ONELEVEL && 5767c478bd9Sstevel@tonic-gate item->searchSpec.triple.attrs == 0 && 5777c478bd9Sstevel@tonic-gate item->searchSpec.triple.element == 0) { 5787c478bd9Sstevel@tonic-gate /* 5797c478bd9Sstevel@tonic-gate * We have a valid triple, but it points to the 5807c478bd9Sstevel@tonic-gate * current LDAP container. Thus, first look in 5817c478bd9Sstevel@tonic-gate * the rule-value; if that fails, perform a direct 5827c478bd9Sstevel@tonic-gate * LDAP lookup. 5837c478bd9Sstevel@tonic-gate */ 5847c478bd9Sstevel@tonic-gate if (rv != 0) { 5857c478bd9Sstevel@tonic-gate check = rvThenLookup; 5867c478bd9Sstevel@tonic-gate } else { 5877c478bd9Sstevel@tonic-gate check = lookupOnly; 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate } else { 5907c478bd9Sstevel@tonic-gate /* 5917c478bd9Sstevel@tonic-gate * Valid triple, and it's not the current container 5927c478bd9Sstevel@tonic-gate * (at least not in the trivial sense). Hence, do 5937c478bd9Sstevel@tonic-gate * a direct LDAP lookup. 5947c478bd9Sstevel@tonic-gate */ 5957c478bd9Sstevel@tonic-gate check = lookupOnly; 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate break; 5987c478bd9Sstevel@tonic-gate default: 5997c478bd9Sstevel@tonic-gate return (0); 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* Check the rule-value */ 6037c478bd9Sstevel@tonic-gate if (check == rvOnly || check == rvThenLookup) { 6047c478bd9Sstevel@tonic-gate for (i = 0; i < numName; i++) { 6057c478bd9Sstevel@tonic-gate if (caseInsens) 6067c478bd9Sstevel@tonic-gate cmp = strcasecmp(item->name, name[i]); 6077c478bd9Sstevel@tonic-gate else 6087c478bd9Sstevel@tonic-gate cmp = strcmp(item->name, name[i]); 6097c478bd9Sstevel@tonic-gate if (cmp == 0) { 6107c478bd9Sstevel@tonic-gate if (nameVal[i].numVals <= 0) 6117c478bd9Sstevel@tonic-gate break; 6127c478bd9Sstevel@tonic-gate if (berstring == 0) { 6137c478bd9Sstevel@tonic-gate val = cloneValue(&nameVal[i], 1); 6147c478bd9Sstevel@tonic-gate } else if (yp2ldap && berstring[0] == 'a') { 6157c478bd9Sstevel@tonic-gate val = cloneValue(&nameVal[i], 1); 6167c478bd9Sstevel@tonic-gate } else { 6177c478bd9Sstevel@tonic-gate val = berDecode(&nameVal[i], 6187c478bd9Sstevel@tonic-gate berstring); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate if (val != 0) { 6217c478bd9Sstevel@tonic-gate val->repeat = item->repeat; 6227c478bd9Sstevel@tonic-gate /* 6237c478bd9Sstevel@tonic-gate * If value for nis+ column is 6247c478bd9Sstevel@tonic-gate * passed with value, val is 6257c478bd9Sstevel@tonic-gate * manipulated in cloneValue(). 6267c478bd9Sstevel@tonic-gate * To decide whether there are 6277c478bd9Sstevel@tonic-gate * enough nis+ column values 6287c478bd9Sstevel@tonic-gate * for rule to produce a value, 6297c478bd9Sstevel@tonic-gate * we need nis+ column values 6307c478bd9Sstevel@tonic-gate * as well as nis_mapping_element 6317c478bd9Sstevel@tonic-gate * from the rule. If we are here, 6327c478bd9Sstevel@tonic-gate * it indicates that the 'val has 6337c478bd9Sstevel@tonic-gate * an valid value for the column 6347c478bd9Sstevel@tonic-gate * item-> name. So set 6357c478bd9Sstevel@tonic-gate * NP_LDAP_MAP_SUCCESS 6367c478bd9Sstevel@tonic-gate * to np_ldap-stat. 6377c478bd9Sstevel@tonic-gate */ 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate if (np_ldap_stat != NULL) 6407c478bd9Sstevel@tonic-gate *np_ldap_stat = 6417c478bd9Sstevel@tonic-gate NP_LDAP_MAP_SUCCESS; 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate break; 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* Do a direct lookup ? */ 6497c478bd9Sstevel@tonic-gate if (val == 0 && (check == rvThenLookup || check == lookupOnly)) { 650*36e852a1SRaja Andra if (item->type == mit_ldap) { 6517c478bd9Sstevel@tonic-gate int err = 0; 6527c478bd9Sstevel@tonic-gate __nis_search_triple_t triple; 6537c478bd9Sstevel@tonic-gate char *baseDN; 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate /* 6567c478bd9Sstevel@tonic-gate * If item->searchSpec.triple.base is NULL, or ends 6577c478bd9Sstevel@tonic-gate * in a comma, append the current search base from 6587c478bd9Sstevel@tonic-gate * the TSD (put there by an upper layer). 6597c478bd9Sstevel@tonic-gate * 6607c478bd9Sstevel@tonic-gate * Special case for N2L mode: 6617c478bd9Sstevel@tonic-gate * if item->searchSpec.triple.base ends in a comma, 6627c478bd9Sstevel@tonic-gate * the current domain Context is used. 6637c478bd9Sstevel@tonic-gate */ 6647c478bd9Sstevel@tonic-gate if (yp2ldap && item->searchSpec.triple.base && 6657c478bd9Sstevel@tonic-gate strlen(item->searchSpec.triple.base) > 0) { 6667c478bd9Sstevel@tonic-gate baseDN = __nisdb_get_tsd()->domainContext; 6677c478bd9Sstevel@tonic-gate } else { 6687c478bd9Sstevel@tonic-gate baseDN = __nisdb_get_tsd()->searchBase; 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate triple.base = appendBase(item->searchSpec.triple.base, 6717c478bd9Sstevel@tonic-gate baseDN, &err, 0); 6727c478bd9Sstevel@tonic-gate if (err == 0) { 6737c478bd9Sstevel@tonic-gate triple.scope = item->searchSpec.triple.scope; 6747c478bd9Sstevel@tonic-gate triple.attrs = item->searchSpec.triple.attrs; 6757c478bd9Sstevel@tonic-gate triple.element = 6767c478bd9Sstevel@tonic-gate item->searchSpec.triple.element; 6777c478bd9Sstevel@tonic-gate val = lookupLDAP(&triple, item->name, rv, 0, 6787c478bd9Sstevel@tonic-gate np_ldap_stat); 6797c478bd9Sstevel@tonic-gate fromldap = '1'; 6807c478bd9Sstevel@tonic-gate } else { 6817c478bd9Sstevel@tonic-gate val = 0; 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate sfree(triple.base); 6847c478bd9Sstevel@tonic-gate } 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* Special processing for NIS to LDAP mode */ 6897c478bd9Sstevel@tonic-gate if (yp2ldap && val != 0) { 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate /* 6927c478bd9Sstevel@tonic-gate * Escape special chars from dn before sending to DIT, 6937c478bd9Sstevel@tonic-gate * provided val is not ldap-based 6947c478bd9Sstevel@tonic-gate */ 6957c478bd9Sstevel@tonic-gate if (fromldap == '\0' && __nisdb_get_tsd()->escapeFlag == '1') { 6967c478bd9Sstevel@tonic-gate if (escapeSpecialChars(val) < 0) { 6977c478bd9Sstevel@tonic-gate freeValue(val, 1); 6987c478bd9Sstevel@tonic-gate return (0); 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate } else if (__nisdb_get_tsd()->escapeFlag == '2') { 7017c478bd9Sstevel@tonic-gate /* Remove escape chars from data received from DIT */ 7027c478bd9Sstevel@tonic-gate (void) removeEscapeChars(val); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * Remove from 'val', any values obtained using 7077c478bd9Sstevel@tonic-gate * the 'removespec' syntax 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate /* Obtain exVal */ 7117c478bd9Sstevel@tonic-gate if (item->exItem) 7127c478bd9Sstevel@tonic-gate exVal = getMappingItemVal(item->exItem, native, rv, 7137c478bd9Sstevel@tonic-gate berstring, NULL); 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* delete */ 7167c478bd9Sstevel@tonic-gate if (exVal != 0) { 7177c478bd9Sstevel@tonic-gate for (i = 0; i < val->numVals; ) { 7187c478bd9Sstevel@tonic-gate for (j = 0; j < exVal->numVals; j++) { 7197c478bd9Sstevel@tonic-gate if (sstrncmp(val->val[i].value, 7207c478bd9Sstevel@tonic-gate exVal->val[j].value, 7217c478bd9Sstevel@tonic-gate MAX(val->val[i].length, 7227c478bd9Sstevel@tonic-gate exVal->val[j].length)) 7237c478bd9Sstevel@tonic-gate == 0) 7247c478bd9Sstevel@tonic-gate break; 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate if (j < exVal->numVals) { 7277c478bd9Sstevel@tonic-gate sfree(val->val[i].value); 7287c478bd9Sstevel@tonic-gate val->val[i].value = 0; 7297c478bd9Sstevel@tonic-gate val->val[i].length = 0; 7307c478bd9Sstevel@tonic-gate for (k = i; k < val->numVals - 1; k++) { 7317c478bd9Sstevel@tonic-gate val->val[k] = val->val[k + 1]; 7327c478bd9Sstevel@tonic-gate val->val[k + 1].value = 0; 7337c478bd9Sstevel@tonic-gate val->val[k + 1].length = 0; 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate val->numVals--; 7367c478bd9Sstevel@tonic-gate } else 7377c478bd9Sstevel@tonic-gate i++; 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate freeValue(exVal, 1); 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate /* 7437c478bd9Sstevel@tonic-gate * If val->numVals <= 0, then we have no val to 7447c478bd9Sstevel@tonic-gate * return. So free up stuff. 7457c478bd9Sstevel@tonic-gate */ 7467c478bd9Sstevel@tonic-gate if (val->numVals <= 0) { 7477c478bd9Sstevel@tonic-gate free(val->val); 7487c478bd9Sstevel@tonic-gate val->val = 0; 7497c478bd9Sstevel@tonic-gate free(val); 7507c478bd9Sstevel@tonic-gate return (0); 7517c478bd9Sstevel@tonic-gate } 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate return (val); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate __nis_value_t * 7597c478bd9Sstevel@tonic-gate getMappingFormat(__nis_mapping_format_t *f, __nis_rule_value_t *rv, 7607c478bd9Sstevel@tonic-gate __nis_format_arg_t at, void *a, int *numArg) { 7617c478bd9Sstevel@tonic-gate char *myself = "getMappingFormat"; 7627c478bd9Sstevel@tonic-gate __nis_value_t *val = 0; 7637c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 7647c478bd9Sstevel@tonic-gate int i; 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate if (f == 0) 7677c478bd9Sstevel@tonic-gate return (0); 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate if (rv == 0) { 7707c478bd9Sstevel@tonic-gate val = am(myself, sizeof (*val)); 7717c478bd9Sstevel@tonic-gate if (val == 0) 7727c478bd9Sstevel@tonic-gate return (0); 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate switch (f->type) { 7757c478bd9Sstevel@tonic-gate case mmt_item: 7767c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%%s"); 7777c478bd9Sstevel@tonic-gate break; 7787c478bd9Sstevel@tonic-gate case mmt_string: 7797c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%s", NIL(f->match.string)); 7807c478bd9Sstevel@tonic-gate break; 7817c478bd9Sstevel@tonic-gate case mmt_single: 7827c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "["); 7837c478bd9Sstevel@tonic-gate for (i = 0; i < f->match.single.numRange; i++) { 7847c478bd9Sstevel@tonic-gate if (f->match.single.lo[i] == 7857c478bd9Sstevel@tonic-gate f->match.single.hi[i]) 7867c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%c", 7877c478bd9Sstevel@tonic-gate f->match.single.lo[i]); 7887c478bd9Sstevel@tonic-gate else 7897c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%c-%c", 7907c478bd9Sstevel@tonic-gate f->match.single.lo[i], 7917c478bd9Sstevel@tonic-gate f->match.single.hi[i]); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "]"); 7947c478bd9Sstevel@tonic-gate break; 7957c478bd9Sstevel@tonic-gate case mmt_limit: 7967c478bd9Sstevel@tonic-gate break; 7977c478bd9Sstevel@tonic-gate case mmt_any: 7987c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "*"); 7997c478bd9Sstevel@tonic-gate break; 8007c478bd9Sstevel@tonic-gate case mmt_berstring: 8017c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%s", NIL(f->match.berString)); 8027c478bd9Sstevel@tonic-gate break; 8037c478bd9Sstevel@tonic-gate case mmt_begin: 8047c478bd9Sstevel@tonic-gate case mmt_end: 8057c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "\""); 8067c478bd9Sstevel@tonic-gate break; 8077c478bd9Sstevel@tonic-gate default: 8087c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "<unknown>"); 8097c478bd9Sstevel@tonic-gate } 8107c478bd9Sstevel@tonic-gate val->type = vt_string; 8117c478bd9Sstevel@tonic-gate val->numVals = 1; 8127c478bd9Sstevel@tonic-gate val->val = am(myself, sizeof (val->val[0])); 8137c478bd9Sstevel@tonic-gate if (val->val == 0) { 8147c478bd9Sstevel@tonic-gate sfree(val); 8157c478bd9Sstevel@tonic-gate return (0); 8167c478bd9Sstevel@tonic-gate } 8177c478bd9Sstevel@tonic-gate val->val[0].value = b.buf; 8187c478bd9Sstevel@tonic-gate val->val[0].length = b.len; 8197c478bd9Sstevel@tonic-gate } else { 8207c478bd9Sstevel@tonic-gate switch (f->type) { 8217c478bd9Sstevel@tonic-gate case mmt_item: 8227c478bd9Sstevel@tonic-gate case mmt_berstring: 8237c478bd9Sstevel@tonic-gate if (a != 0) { 8247c478bd9Sstevel@tonic-gate if (at == fa_item) { 8257c478bd9Sstevel@tonic-gate val = getMappingItemVal( 8267c478bd9Sstevel@tonic-gate (__nis_mapping_item_t *)a, 8277c478bd9Sstevel@tonic-gate mit_any, rv, 8287c478bd9Sstevel@tonic-gate (f->type == mmt_berstring) ? f->match.berString : 0, NULL); 8297c478bd9Sstevel@tonic-gate if (numArg != 0) 8307c478bd9Sstevel@tonic-gate (*numArg)++; 8317c478bd9Sstevel@tonic-gate } else { 8327c478bd9Sstevel@tonic-gate val = cloneValue( 8337c478bd9Sstevel@tonic-gate (__nis_value_t *)a, 1); 8347c478bd9Sstevel@tonic-gate if (numArg != 0) 8357c478bd9Sstevel@tonic-gate (*numArg)++; 8367c478bd9Sstevel@tonic-gate } 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate break; 8397c478bd9Sstevel@tonic-gate case mmt_string: 8407c478bd9Sstevel@tonic-gate val = am(myself, sizeof (*val)); 8417c478bd9Sstevel@tonic-gate if (val == 0) 8427c478bd9Sstevel@tonic-gate return (0); 8437c478bd9Sstevel@tonic-gate val->type = vt_string; 8447c478bd9Sstevel@tonic-gate val->numVals = 1; 8457c478bd9Sstevel@tonic-gate val->val = am(myself, sizeof (val->val[0])); 8467c478bd9Sstevel@tonic-gate if (val->val == 0) { 8477c478bd9Sstevel@tonic-gate sfree(val); 8487c478bd9Sstevel@tonic-gate return (0); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate val->val[0].value = sdup(myself, T, f->match.string); 8517c478bd9Sstevel@tonic-gate val->val[0].length = strlen(val->val[0].value); 8527c478bd9Sstevel@tonic-gate break; 8537c478bd9Sstevel@tonic-gate case mmt_single: 8547c478bd9Sstevel@tonic-gate case mmt_limit: 8557c478bd9Sstevel@tonic-gate case mmt_any: 8567c478bd9Sstevel@tonic-gate case mmt_begin: 8577c478bd9Sstevel@tonic-gate case mmt_end: 8587c478bd9Sstevel@tonic-gate /* Not an error, so return an empty value */ 8597c478bd9Sstevel@tonic-gate val = am(myself, sizeof (*val)); 8607c478bd9Sstevel@tonic-gate if (val == 0) 8617c478bd9Sstevel@tonic-gate return (0); 8627c478bd9Sstevel@tonic-gate val->type = vt_string; 8637c478bd9Sstevel@tonic-gate val->numVals = 0; 8647c478bd9Sstevel@tonic-gate val->val = 0; 8657c478bd9Sstevel@tonic-gate break; 8667c478bd9Sstevel@tonic-gate default: 8677c478bd9Sstevel@tonic-gate /* Do nothing */ 8687c478bd9Sstevel@tonic-gate val = 0; 8697c478bd9Sstevel@tonic-gate break; 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate return (val); 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate /* 8767c478bd9Sstevel@tonic-gate * Used when evaluating an expression. Typically, the value of the 8777c478bd9Sstevel@tonic-gate * expression so far will be kept in 'v1', and 'v2' is the value 8787c478bd9Sstevel@tonic-gate * of the current component of the expression. In the general case, 8797c478bd9Sstevel@tonic-gate * both will be multi-valued, and the result is an "explosion" 8807c478bd9Sstevel@tonic-gate * resulting in N*M new values (if 'v1' had N values, and 'v2' 8817c478bd9Sstevel@tonic-gate * M ditto). 8827c478bd9Sstevel@tonic-gate * 8837c478bd9Sstevel@tonic-gate * For example, if v1 = {"ab", "cd", "ef"}, and v2 = {"gh", "ij", "kl"}, 8847c478bd9Sstevel@tonic-gate * the result will be {"abgh", "abij", "abkl", "cdgh", "cdij", "cdkl", 8857c478bd9Sstevel@tonic-gate * "efgh", "efij", "efkl"}. 8867c478bd9Sstevel@tonic-gate * 8877c478bd9Sstevel@tonic-gate * There are special cases when v1->repeat and/or v2->repeat are set. 8887c478bd9Sstevel@tonic-gate * Repeat mostly makes sense with single values; for example, if 8897c478bd9Sstevel@tonic-gate * v1 = {"x="} with repeat on, and v2 = {"1", "2", "3"}, the result 8907c478bd9Sstevel@tonic-gate * is {"x=1", "x=2", "x=3"}. 8917c478bd9Sstevel@tonic-gate * 8927c478bd9Sstevel@tonic-gate * The result if v2 also had repeat on would be {"x=1x=2x=3"}. It's 8937c478bd9Sstevel@tonic-gate * not clear if there's a useful application for this, but the code's 8947c478bd9Sstevel@tonic-gate * there for the sake of orthogonality. 8957c478bd9Sstevel@tonic-gate */ 8967c478bd9Sstevel@tonic-gate __nis_value_t * 8977c478bd9Sstevel@tonic-gate explodeValues(__nis_value_t *v1, __nis_value_t *v2) { 8987c478bd9Sstevel@tonic-gate int i1, i2, n, nv; 8997c478bd9Sstevel@tonic-gate __nis_value_t *v; 9007c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 9017c478bd9Sstevel@tonic-gate char *myself = "explodeValues"; 9027c478bd9Sstevel@tonic-gate 9037c478bd9Sstevel@tonic-gate if (v1 == 0 || v1->numVals <= 0) 9047c478bd9Sstevel@tonic-gate return (cloneValue(v2, 1)); 9057c478bd9Sstevel@tonic-gate if (v2 == 0 || v2->numVals <= 0) 9067c478bd9Sstevel@tonic-gate return (cloneValue(v1, 1)); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate /* 9097c478bd9Sstevel@tonic-gate * XXX What should we do if (v1->type != v2->type) ? 9107c478bd9Sstevel@tonic-gate * Policy: Just explode anyway, even though the result is 9117c478bd9Sstevel@tonic-gate * unlikely to be very useful. 9127c478bd9Sstevel@tonic-gate */ 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate v = am(myself, sizeof (*v)); 9157c478bd9Sstevel@tonic-gate if (v == 0) 9167c478bd9Sstevel@tonic-gate return (0); 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate if (!v1->repeat && !v2->repeat) 9197c478bd9Sstevel@tonic-gate nv = v1->numVals * v2->numVals; 9207c478bd9Sstevel@tonic-gate else if (v1->repeat && !v2->repeat) 9217c478bd9Sstevel@tonic-gate nv = v2->numVals; 9227c478bd9Sstevel@tonic-gate else if (!v1->repeat && v2->repeat) 9237c478bd9Sstevel@tonic-gate nv = v1->numVals; 9247c478bd9Sstevel@tonic-gate else /* v1->repeat && v2->repeat */ 9257c478bd9Sstevel@tonic-gate nv = 1; 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate v->val = am(myself, nv * sizeof (v->val[0])); 9287c478bd9Sstevel@tonic-gate if (v->val == 0) { 9297c478bd9Sstevel@tonic-gate free(v); 9307c478bd9Sstevel@tonic-gate return (0); 9317c478bd9Sstevel@tonic-gate } 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate /* 9347c478bd9Sstevel@tonic-gate * Four different cases, depending on the 'repeat' flags. 9357c478bd9Sstevel@tonic-gate */ 9367c478bd9Sstevel@tonic-gate if (!v1->repeat && !v2->repeat) { 9377c478bd9Sstevel@tonic-gate for (i1 = 0, n = 0; i1 < v1->numVals; i1++) { 9387c478bd9Sstevel@tonic-gate for (i2 = 0; i2 < v2->numVals; i2++) { 9397c478bd9Sstevel@tonic-gate if (v1->type == vt_string) 9407c478bd9Sstevel@tonic-gate sbc2buf(myself, v1->val[i1].value, 9417c478bd9Sstevel@tonic-gate v1->val[i1].length, 9427c478bd9Sstevel@tonic-gate &b); 9437c478bd9Sstevel@tonic-gate else 9447c478bd9Sstevel@tonic-gate bc2buf(myself, v1->val[i1].value, 9457c478bd9Sstevel@tonic-gate v1->val[i1].length, 9467c478bd9Sstevel@tonic-gate &b); 9477c478bd9Sstevel@tonic-gate if (v2->type == vt_string) 9487c478bd9Sstevel@tonic-gate sbc2buf(myself, v2->val[i2].value, 9497c478bd9Sstevel@tonic-gate v2->val[i2].length, 9507c478bd9Sstevel@tonic-gate &b); 9517c478bd9Sstevel@tonic-gate else 9527c478bd9Sstevel@tonic-gate bc2buf(myself, v2->val[i2].value, 9537c478bd9Sstevel@tonic-gate v2->val[i2].length, 9547c478bd9Sstevel@tonic-gate &b); 9557c478bd9Sstevel@tonic-gate v->val[n].value = b.buf; 9567c478bd9Sstevel@tonic-gate v->val[n].length = b.len; 9577c478bd9Sstevel@tonic-gate n++; 9587c478bd9Sstevel@tonic-gate b.buf = 0; 9597c478bd9Sstevel@tonic-gate b.len = 0; 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate } 9627c478bd9Sstevel@tonic-gate } else if (v1->repeat && !v2->repeat) { 9637c478bd9Sstevel@tonic-gate for (i2 = 0; i2 < v2->numVals; i2++) { 9647c478bd9Sstevel@tonic-gate for (i1 = 0, n = 0; i1 < v1->numVals; i1++) { 9657c478bd9Sstevel@tonic-gate if (v1->type == vt_string) 9667c478bd9Sstevel@tonic-gate sbc2buf(myself, v1->val[i1].value, 9677c478bd9Sstevel@tonic-gate v1->val[i1].length, 9687c478bd9Sstevel@tonic-gate &b); 9697c478bd9Sstevel@tonic-gate else 9707c478bd9Sstevel@tonic-gate bc2buf(myself, v1->val[i1].value, 9717c478bd9Sstevel@tonic-gate v1->val[i1].length, 9727c478bd9Sstevel@tonic-gate &b); 9737c478bd9Sstevel@tonic-gate if (v2->type == vt_string) 9747c478bd9Sstevel@tonic-gate sbc2buf(myself, v2->val[i2].value, 9757c478bd9Sstevel@tonic-gate v2->val[i2].length, 9767c478bd9Sstevel@tonic-gate &b); 9777c478bd9Sstevel@tonic-gate else 9787c478bd9Sstevel@tonic-gate bc2buf(myself, v2->val[i2].value, 9797c478bd9Sstevel@tonic-gate v2->val[i2].length, 9807c478bd9Sstevel@tonic-gate &b); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate v->val[n].value = b.buf; 9837c478bd9Sstevel@tonic-gate v->val[n].length = b.len; 9847c478bd9Sstevel@tonic-gate n++; 9857c478bd9Sstevel@tonic-gate b.buf = 0; 9867c478bd9Sstevel@tonic-gate b.len = 0; 9877c478bd9Sstevel@tonic-gate } 9887c478bd9Sstevel@tonic-gate } else if (!v1->repeat && v2->repeat) { 9897c478bd9Sstevel@tonic-gate for (i1 = 0, n = 0; i1 < v1->numVals; i1++) { 9907c478bd9Sstevel@tonic-gate for (i2 = 0; i2 < v2->numVals; i2++) { 9917c478bd9Sstevel@tonic-gate if (v1->type == vt_string) 9927c478bd9Sstevel@tonic-gate sbc2buf(myself, v1->val[i1].value, 9937c478bd9Sstevel@tonic-gate v1->val[i1].length, 9947c478bd9Sstevel@tonic-gate &b); 9957c478bd9Sstevel@tonic-gate else 9967c478bd9Sstevel@tonic-gate bc2buf(myself, v1->val[i1].value, 9977c478bd9Sstevel@tonic-gate v1->val[i1].length, 9987c478bd9Sstevel@tonic-gate &b); 9997c478bd9Sstevel@tonic-gate if (v2->type == vt_string) 10007c478bd9Sstevel@tonic-gate sbc2buf(myself, v2->val[i2].value, 10017c478bd9Sstevel@tonic-gate v2->val[i2].length, 10027c478bd9Sstevel@tonic-gate &b); 10037c478bd9Sstevel@tonic-gate else 10047c478bd9Sstevel@tonic-gate bc2buf(myself, v2->val[i2].value, 10057c478bd9Sstevel@tonic-gate v2->val[i2].length, 10067c478bd9Sstevel@tonic-gate &b); 10077c478bd9Sstevel@tonic-gate } 10087c478bd9Sstevel@tonic-gate v->val[n].value = b.buf; 10097c478bd9Sstevel@tonic-gate v->val[n].length = b.len; 10107c478bd9Sstevel@tonic-gate n++; 10117c478bd9Sstevel@tonic-gate b.buf = 0; 10127c478bd9Sstevel@tonic-gate b.len = 0; 10137c478bd9Sstevel@tonic-gate } 10147c478bd9Sstevel@tonic-gate } else { /* v1->repeat && v2->repeat */ 10157c478bd9Sstevel@tonic-gate for (i1 = 0, n = 0; i1 < v1->numVals; i1++) { 10167c478bd9Sstevel@tonic-gate for (i2 = 0; i2 < v2->numVals; i2++) { 10177c478bd9Sstevel@tonic-gate if (v1->type == vt_string) 10187c478bd9Sstevel@tonic-gate sbc2buf(myself, v1->val[i1].value, 10197c478bd9Sstevel@tonic-gate v1->val[i1].length, 10207c478bd9Sstevel@tonic-gate &b); 10217c478bd9Sstevel@tonic-gate else 10227c478bd9Sstevel@tonic-gate bc2buf(myself, v1->val[i1].value, 10237c478bd9Sstevel@tonic-gate v1->val[i1].length, 10247c478bd9Sstevel@tonic-gate &b); 10257c478bd9Sstevel@tonic-gate if (v2->type == vt_string) 10267c478bd9Sstevel@tonic-gate sbc2buf(myself, v2->val[i2].value, 10277c478bd9Sstevel@tonic-gate v2->val[i2].length, 10287c478bd9Sstevel@tonic-gate &b); 10297c478bd9Sstevel@tonic-gate else 10307c478bd9Sstevel@tonic-gate bc2buf(myself, v2->val[i2].value, 10317c478bd9Sstevel@tonic-gate v2->val[i2].length, 10327c478bd9Sstevel@tonic-gate &b); 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate } 10357c478bd9Sstevel@tonic-gate v->val[n].value = b.buf; 10367c478bd9Sstevel@tonic-gate v->val[n].length = b.len; 10377c478bd9Sstevel@tonic-gate n++; 10387c478bd9Sstevel@tonic-gate b.buf = 0; 10397c478bd9Sstevel@tonic-gate b.len = 0; 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate #ifdef NISDB_LDAP_DEBUG 10437c478bd9Sstevel@tonic-gate /* Sanity check */ 10447c478bd9Sstevel@tonic-gate if (n != nv) 10457c478bd9Sstevel@tonic-gate abort(); 10467c478bd9Sstevel@tonic-gate #endif /* NISD__LDAP_DEBUG */ 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate v->type = (v1->type == vt_string) ? 10497c478bd9Sstevel@tonic-gate ((v2->type == vt_string) ? 10507c478bd9Sstevel@tonic-gate vt_string : vt_ber) : vt_ber; 10517c478bd9Sstevel@tonic-gate v->repeat = 0; 10527c478bd9Sstevel@tonic-gate v->numVals = n; 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate return (v); 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate __nis_value_t * 10587c478bd9Sstevel@tonic-gate getMappingFormatArray(__nis_mapping_format_t *a, __nis_rule_value_t *rv, 10597c478bd9Sstevel@tonic-gate __nis_format_arg_t at, int numArgs, void *arg) { 10607c478bd9Sstevel@tonic-gate int i, ia = 0; 10617c478bd9Sstevel@tonic-gate __nis_value_t *val, *v = 0; 10627c478bd9Sstevel@tonic-gate bool_t moreFormat = (a != 0); 10637c478bd9Sstevel@tonic-gate bool_t moreArgs = (numArgs > 0); 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate while (moreFormat && (arg == 0 || ia < numArgs)) { 10667c478bd9Sstevel@tonic-gate for (i = 0; moreFormat; i++) { 10677c478bd9Sstevel@tonic-gate moreFormat = (a[i].type != mmt_end); 10687c478bd9Sstevel@tonic-gate if (at == fa_item) { 10697c478bd9Sstevel@tonic-gate __nis_mapping_item_t *item = arg; 10707c478bd9Sstevel@tonic-gate val = getMappingFormat(&a[i], rv, at, 10717c478bd9Sstevel@tonic-gate ((item != 0) ? &item[ia] : 0), &ia); 10727c478bd9Sstevel@tonic-gate } else { 10737c478bd9Sstevel@tonic-gate __nis_value_t **ival = arg; 10747c478bd9Sstevel@tonic-gate val = getMappingFormat(&a[i], rv, at, 10757c478bd9Sstevel@tonic-gate ((ival != 0) ? ival[ia] : 0), &ia); 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate if (val != 0) { 10787c478bd9Sstevel@tonic-gate __nis_value_t *new = explodeValues(v, val); 10797c478bd9Sstevel@tonic-gate 10807c478bd9Sstevel@tonic-gate freeValue(v, 1); 10817c478bd9Sstevel@tonic-gate freeValue(val, 1); 10827c478bd9Sstevel@tonic-gate if (new == 0) 10837c478bd9Sstevel@tonic-gate return (0); 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate v = new; 10867c478bd9Sstevel@tonic-gate } else { 10877c478bd9Sstevel@tonic-gate freeValue(v, 1); 10887c478bd9Sstevel@tonic-gate return (0); 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate /* 10917c478bd9Sstevel@tonic-gate * If we run out of arguments, but still have format 10927c478bd9Sstevel@tonic-gate * remaining, repeat the last argument. Keep track of 10937c478bd9Sstevel@tonic-gate * the fact that we've really consumed all arguments. 10947c478bd9Sstevel@tonic-gate */ 10957c478bd9Sstevel@tonic-gate if (moreFormat && ia >= numArgs) { 10967c478bd9Sstevel@tonic-gate ia = (numArgs > 0) ? numArgs - 1 : 0; 10977c478bd9Sstevel@tonic-gate moreArgs = FALSE; 10987c478bd9Sstevel@tonic-gate } 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate /* 11017c478bd9Sstevel@tonic-gate * We've run out of format, so if we still have arguments 11027c478bd9Sstevel@tonic-gate * left, start over on the format. 11037c478bd9Sstevel@tonic-gate */ 11047c478bd9Sstevel@tonic-gate if (ia < numArgs && moreArgs) { 11057c478bd9Sstevel@tonic-gate /* 11067c478bd9Sstevel@tonic-gate * However, if we didn't consume any arguments going 11077c478bd9Sstevel@tonic-gate * through the format once, abort to avoid an infinite 11087c478bd9Sstevel@tonic-gate * loop. 11097c478bd9Sstevel@tonic-gate */ 11107c478bd9Sstevel@tonic-gate if (numArgs > 0 && ia <= 0) { 11117c478bd9Sstevel@tonic-gate freeValue(v, 1); 11127c478bd9Sstevel@tonic-gate return (0); 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate moreFormat = 1; 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate return (v); 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate /* 11227c478bd9Sstevel@tonic-gate * Returns a string representation (such as "[name=foo, value=bar]") 11237c478bd9Sstevel@tonic-gate * of a nis_index_t. 11247c478bd9Sstevel@tonic-gate */ 11257c478bd9Sstevel@tonic-gate char * 11267c478bd9Sstevel@tonic-gate getIndex(__nis_index_t *i, int *len) { 11277c478bd9Sstevel@tonic-gate int n; 11287c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 11297c478bd9Sstevel@tonic-gate char *myself = "getIndex"; 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate if (i == 0) 11327c478bd9Sstevel@tonic-gate return (0); 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate if (i->numIndexes > 0) { 11357c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "["); 11367c478bd9Sstevel@tonic-gate for (n = 0; n < i->numIndexes; n++) { 11377c478bd9Sstevel@tonic-gate __nis_value_t *val; 11387c478bd9Sstevel@tonic-gate int j; 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate val = getMappingFormatArray(i->value[n], 11417c478bd9Sstevel@tonic-gate 0, fa_any, 0, 0); 11427c478bd9Sstevel@tonic-gate if (n > 0) 11437c478bd9Sstevel@tonic-gate bp2buf(myself, &b, ", "); 11447c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%s=", i->name[n]); 11457c478bd9Sstevel@tonic-gate if (val != 0) { 11467c478bd9Sstevel@tonic-gate for (j = 0; j < val->numVals; j++) { 11477c478bd9Sstevel@tonic-gate bc2buf(myself, val->val[j].value, 11487c478bd9Sstevel@tonic-gate val->val[j].length, &b); 11497c478bd9Sstevel@tonic-gate } 11507c478bd9Sstevel@tonic-gate } else { 11517c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "<no-vals>"); 11527c478bd9Sstevel@tonic-gate } 11537c478bd9Sstevel@tonic-gate freeValue(val, 1); 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "]"); 11567c478bd9Sstevel@tonic-gate } 11577c478bd9Sstevel@tonic-gate if (len != 0) 11587c478bd9Sstevel@tonic-gate *len = b.len; 11597c478bd9Sstevel@tonic-gate return (b.buf); 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate char * 11637c478bd9Sstevel@tonic-gate getObjSpec(__nis_obj_spec_t *o, int *len) { 11647c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 11657c478bd9Sstevel@tonic-gate char *myself = "getObjSpec"; 11667c478bd9Sstevel@tonic-gate 11677c478bd9Sstevel@tonic-gate if (o == 0) 11687c478bd9Sstevel@tonic-gate return (0); 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate b.buf = getIndex(&o->index, &b.len); 11717c478bd9Sstevel@tonic-gate sbc2buf(myself, o->name, slen(o->name), &b); 11727c478bd9Sstevel@tonic-gate if (len != 0) 11737c478bd9Sstevel@tonic-gate *len = b.len; 11747c478bd9Sstevel@tonic-gate return (b.buf); 11757c478bd9Sstevel@tonic-gate } 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate /* 11787c478bd9Sstevel@tonic-gate * Returns a string representation of the LDAP scope. Note that the 11797c478bd9Sstevel@tonic-gate * returned value is a static entity, and must be copied by the 11807c478bd9Sstevel@tonic-gate * caller (but, obviously, must not be freed). 11817c478bd9Sstevel@tonic-gate */ 11827c478bd9Sstevel@tonic-gate char * 11837c478bd9Sstevel@tonic-gate getScope(int scope) { 11847c478bd9Sstevel@tonic-gate switch (scope) { 11857c478bd9Sstevel@tonic-gate case LDAP_SCOPE_BASE: 11867c478bd9Sstevel@tonic-gate return ("base"); 11877c478bd9Sstevel@tonic-gate case LDAP_SCOPE_ONELEVEL: 11887c478bd9Sstevel@tonic-gate return ("one"); 11897c478bd9Sstevel@tonic-gate case LDAP_SCOPE_SUBTREE: 11907c478bd9Sstevel@tonic-gate return ("sub"); 11917c478bd9Sstevel@tonic-gate default: 11927c478bd9Sstevel@tonic-gate return ("one"); 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate } 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate /* 11977c478bd9Sstevel@tonic-gate * Return a string representation of an LDAP search triple (such as 11987c478bd9Sstevel@tonic-gate * "ou=Hosts,dc=eng,dc=sun,dc=com?one?cn=xyzzy"). 11997c478bd9Sstevel@tonic-gate */ 12007c478bd9Sstevel@tonic-gate char * 12017c478bd9Sstevel@tonic-gate getSearchTriple(__nis_search_triple_t *s, int *len) { 12027c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 12037c478bd9Sstevel@tonic-gate char *a; 12047c478bd9Sstevel@tonic-gate int l; 12057c478bd9Sstevel@tonic-gate char *myself = "getSearchTriple"; 12067c478bd9Sstevel@tonic-gate 12077c478bd9Sstevel@tonic-gate /* If the scope is LDAP_SCOPE_UNKNOWN, the search triple is unused */ 12087c478bd9Sstevel@tonic-gate if (s == 0 || s->scope == LDAP_SCOPE_UNKNOWN) { 12097c478bd9Sstevel@tonic-gate if (len != 0) 12107c478bd9Sstevel@tonic-gate *len = 0; 12117c478bd9Sstevel@tonic-gate return (0); 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate 12147c478bd9Sstevel@tonic-gate if (s->base != 0) 12157c478bd9Sstevel@tonic-gate sbc2buf(myself, s->base, slen(s->base), &b); 12167c478bd9Sstevel@tonic-gate if (!(s->scope == LDAP_SCOPE_ONELEVEL && 12177c478bd9Sstevel@tonic-gate (s->base == 0 || s->base[0] == '\0'))) { 12187c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "?%s?", getScope(s->scope)); 12197c478bd9Sstevel@tonic-gate } 12207c478bd9Sstevel@tonic-gate if ((l = slen(s->attrs)) > 0) { 12217c478bd9Sstevel@tonic-gate /* 12227c478bd9Sstevel@tonic-gate * Remove white space from the filter/attribute list. 12237c478bd9Sstevel@tonic-gate * The parser usually keeps any white space from the 12247c478bd9Sstevel@tonic-gate * config file (or LDAP/command line), but we don't 12257c478bd9Sstevel@tonic-gate * want it. 12267c478bd9Sstevel@tonic-gate */ 12277c478bd9Sstevel@tonic-gate a = am(myself, l+1); 12287c478bd9Sstevel@tonic-gate if (a != 0) { 12297c478bd9Sstevel@tonic-gate int i, la; 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate for (i = 0, la = 0; i < l; i++) { 12327c478bd9Sstevel@tonic-gate if (s->attrs[i] != ' ' && 12337c478bd9Sstevel@tonic-gate s->attrs[i] != '\t') 12347c478bd9Sstevel@tonic-gate a[la++] = s->attrs[i]; 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate sbc2buf(myself, a, la, &b); 12377c478bd9Sstevel@tonic-gate sfree(a); 12387c478bd9Sstevel@tonic-gate } else { 12397c478bd9Sstevel@tonic-gate sbc2buf(myself, s->attrs, slen(s->attrs), &b); 12407c478bd9Sstevel@tonic-gate } 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate 12437c478bd9Sstevel@tonic-gate if (len != 0) 12447c478bd9Sstevel@tonic-gate *len = b.len; 12457c478bd9Sstevel@tonic-gate return (b.buf); 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate __nis_value_t * 12497c478bd9Sstevel@tonic-gate getMappingItem(__nis_mapping_item_t *i, __nis_mapping_item_type_t native, 12507c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv, char *berstring, int *np_ldap_stat) { 12517c478bd9Sstevel@tonic-gate char *myself = "getMappingItem"; 12527c478bd9Sstevel@tonic-gate __nis_value_t *val = 0; 12537c478bd9Sstevel@tonic-gate __nis_buffer_t b = {0, 0}; 12547c478bd9Sstevel@tonic-gate int len = 0; 12557c478bd9Sstevel@tonic-gate char *buf; 12567c478bd9Sstevel@tonic-gate 12577c478bd9Sstevel@tonic-gate if (i == 0) 12587c478bd9Sstevel@tonic-gate return (0); 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate if (rv != 0) 12617c478bd9Sstevel@tonic-gate return (getMappingItemVal(i, native, rv, berstring, 12627c478bd9Sstevel@tonic-gate np_ldap_stat)); 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate val = am(myself, sizeof (*val)); 12657c478bd9Sstevel@tonic-gate if (val == 0) 12667c478bd9Sstevel@tonic-gate return (0); 12677c478bd9Sstevel@tonic-gate 12687c478bd9Sstevel@tonic-gate switch (i->type) { 12697c478bd9Sstevel@tonic-gate case mit_nisplus: 12707c478bd9Sstevel@tonic-gate if (native != mit_nisplus) 12717c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "nis+:"); 12727c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%s", NIL(i->name)); 12737c478bd9Sstevel@tonic-gate buf = getObjSpec(&i->searchSpec.obj, &len); 12747c478bd9Sstevel@tonic-gate if (buf != 0 && len > 0) { 12757c478bd9Sstevel@tonic-gate bc2buf(myself, ":", 1, &b); 12767c478bd9Sstevel@tonic-gate sbc2buf(myself, buf, len, &b); 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate sfree(buf); 12797c478bd9Sstevel@tonic-gate val->type = vt_string; 12807c478bd9Sstevel@tonic-gate val->repeat = i->repeat; 12817c478bd9Sstevel@tonic-gate val->numVals = 1; 12827c478bd9Sstevel@tonic-gate val->val = am(myself, sizeof (val->val[0])); 12837c478bd9Sstevel@tonic-gate if (val->val == 0) { 12847c478bd9Sstevel@tonic-gate sfree(b.buf); 12857c478bd9Sstevel@tonic-gate free(val); 12867c478bd9Sstevel@tonic-gate return (0); 12877c478bd9Sstevel@tonic-gate } 12887c478bd9Sstevel@tonic-gate val->val[0].value = b.buf; 12897c478bd9Sstevel@tonic-gate val->val[0].length = b.len; 12907c478bd9Sstevel@tonic-gate break; 12917c478bd9Sstevel@tonic-gate case mit_ldap: 12927c478bd9Sstevel@tonic-gate if (native != mit_ldap) 12937c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "ldap:"); 12947c478bd9Sstevel@tonic-gate bp2buf(myself, &b, "%s", NIL(i->name)); 12957c478bd9Sstevel@tonic-gate buf = getSearchTriple(&i->searchSpec.triple, &len); 12967c478bd9Sstevel@tonic-gate if (buf != 0 && len > 0) { 12977c478bd9Sstevel@tonic-gate bc2buf(myself, ":", 1, &b); 12987c478bd9Sstevel@tonic-gate sbc2buf(myself, buf, len, &b); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate sfree(buf); 13017c478bd9Sstevel@tonic-gate val->type = vt_string; 13027c478bd9Sstevel@tonic-gate val->repeat = i->repeat; 13037c478bd9Sstevel@tonic-gate val->numVals = 1; 13047c478bd9Sstevel@tonic-gate val->val = am(myself, sizeof (val->val[0])); 13057c478bd9Sstevel@tonic-gate if (val->val == 0) { 13067c478bd9Sstevel@tonic-gate sfree(b.buf); 13077c478bd9Sstevel@tonic-gate free(val); 13087c478bd9Sstevel@tonic-gate return (0); 13097c478bd9Sstevel@tonic-gate } 13107c478bd9Sstevel@tonic-gate val->val[0].value = b.buf; 13117c478bd9Sstevel@tonic-gate val->val[0].length = b.len; 13127c478bd9Sstevel@tonic-gate break; 13137c478bd9Sstevel@tonic-gate default: 13147c478bd9Sstevel@tonic-gate p2buf(myself, "<unknown>:"); 13157c478bd9Sstevel@tonic-gate p2buf(myself, "%s", NIL(i->name)); 13167c478bd9Sstevel@tonic-gate break; 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate 13197c478bd9Sstevel@tonic-gate return (val); 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate void 13237c478bd9Sstevel@tonic-gate copyObjSpec(__nis_obj_spec_t *old, __nis_obj_spec_t *new, int *err) { 13247c478bd9Sstevel@tonic-gate char *myself = "copyObjSpec"; 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate if (old == 0 || new == 0) { 13277c478bd9Sstevel@tonic-gate *err = EINVAL; 13287c478bd9Sstevel@tonic-gate return; 13297c478bd9Sstevel@tonic-gate } 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate if (new->index.name == 0) { 13327c478bd9Sstevel@tonic-gate new->index.name = am(myself, old->index.numIndexes * 13337c478bd9Sstevel@tonic-gate sizeof (new->index.name[0])); 13347c478bd9Sstevel@tonic-gate if (old->index.numIndexes > 0 && new->index.name == 0) { 13357c478bd9Sstevel@tonic-gate *err = ENOMEM; 13367c478bd9Sstevel@tonic-gate return; 13377c478bd9Sstevel@tonic-gate } 13387c478bd9Sstevel@tonic-gate new->index.value = am(myself, old->index.numIndexes * 13397c478bd9Sstevel@tonic-gate sizeof (new->index.value[0])); 13407c478bd9Sstevel@tonic-gate if (old->index.numIndexes > 0 && new->index.value == 0) { 13417c478bd9Sstevel@tonic-gate *err = ENOMEM; 13427c478bd9Sstevel@tonic-gate return; 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate } 13457c478bd9Sstevel@tonic-gate new->name = sdup(myself, T, old->name); 13467c478bd9Sstevel@tonic-gate if (new->name == 0 && old->name != 0) { 13477c478bd9Sstevel@tonic-gate *err = ENOMEM; 13487c478bd9Sstevel@tonic-gate return; 13497c478bd9Sstevel@tonic-gate } 13507c478bd9Sstevel@tonic-gate copyIndex(&old->index, &new->index, err); 13517c478bd9Sstevel@tonic-gate } 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate __nis_obj_spec_t * 13547c478bd9Sstevel@tonic-gate cloneObjSpec(__nis_obj_spec_t *old) { 13557c478bd9Sstevel@tonic-gate char *myself = "cloneObjSpec"; 13567c478bd9Sstevel@tonic-gate int err = 0; 13577c478bd9Sstevel@tonic-gate __nis_obj_spec_t *new = am(myself, sizeof (*new)); 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate if (new != 0) { 13607c478bd9Sstevel@tonic-gate copyObjSpec(old, new, &err); 13617c478bd9Sstevel@tonic-gate if (err != 0) { 13627c478bd9Sstevel@tonic-gate freeObjSpec(new, 1); 13637c478bd9Sstevel@tonic-gate new = 0; 13647c478bd9Sstevel@tonic-gate } 13657c478bd9Sstevel@tonic-gate } 13667c478bd9Sstevel@tonic-gate 13677c478bd9Sstevel@tonic-gate return (new); 13687c478bd9Sstevel@tonic-gate } 13697c478bd9Sstevel@tonic-gate 13707c478bd9Sstevel@tonic-gate void 13717c478bd9Sstevel@tonic-gate freeObjSpec(__nis_obj_spec_t *old, bool_t doFree) { 13727c478bd9Sstevel@tonic-gate 13737c478bd9Sstevel@tonic-gate if (old == 0) 13747c478bd9Sstevel@tonic-gate return; 13757c478bd9Sstevel@tonic-gate 13767c478bd9Sstevel@tonic-gate sfree(old->name); 13777c478bd9Sstevel@tonic-gate freeIndex(&old->index, FALSE); 13787c478bd9Sstevel@tonic-gate if (doFree) 13797c478bd9Sstevel@tonic-gate free(old); 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate void 13837c478bd9Sstevel@tonic-gate copySearchTriple(__nis_search_triple_t *old, __nis_search_triple_t *new, 13847c478bd9Sstevel@tonic-gate int *err) { 13857c478bd9Sstevel@tonic-gate char *myself = "copySearchTriple"; 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate *err = 0; 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate if (old == 0 || new == 0) { 13907c478bd9Sstevel@tonic-gate *err = EINVAL; 13917c478bd9Sstevel@tonic-gate return; 13927c478bd9Sstevel@tonic-gate } 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate if (old->base != NULL) 13957c478bd9Sstevel@tonic-gate new->base = sdup(myself, T, old->base); 13967c478bd9Sstevel@tonic-gate else 13977c478bd9Sstevel@tonic-gate new->base = NULL; 13987c478bd9Sstevel@tonic-gate if (old->attrs != NULL) 13997c478bd9Sstevel@tonic-gate new->attrs = sdup(myself, T, old->attrs); 14007c478bd9Sstevel@tonic-gate else 14017c478bd9Sstevel@tonic-gate new->attrs = NULL; 14027c478bd9Sstevel@tonic-gate if ((new->base == 0 && old->base != 0) || 14037c478bd9Sstevel@tonic-gate (new->attrs == 0 && old->attrs != 0)) { 14047c478bd9Sstevel@tonic-gate sfree(new->base); 14057c478bd9Sstevel@tonic-gate new->base = 0; 14067c478bd9Sstevel@tonic-gate sfree(new->attrs); 14077c478bd9Sstevel@tonic-gate new->attrs = 0; 14087c478bd9Sstevel@tonic-gate *err = ENOMEM; 14097c478bd9Sstevel@tonic-gate return; 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate new->scope = old->scope; 14127c478bd9Sstevel@tonic-gate /* 14137c478bd9Sstevel@tonic-gate * XXX Really should have a cloneMappingElement() function. 14147c478bd9Sstevel@tonic-gate * However, since whatever the 'element' field points to 14157c478bd9Sstevel@tonic-gate * is allocated at parse time, and never is freed or modified, 14167c478bd9Sstevel@tonic-gate * it's sufficient to copy the pointer value. 14177c478bd9Sstevel@tonic-gate */ 14187c478bd9Sstevel@tonic-gate new->element = old->element; 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate __nis_search_triple_t * 14227c478bd9Sstevel@tonic-gate cloneSearchTriple(__nis_search_triple_t *old) { 14237c478bd9Sstevel@tonic-gate char *myself = "cloneSearchTriple"; 14247c478bd9Sstevel@tonic-gate int err = 0; 14257c478bd9Sstevel@tonic-gate __nis_search_triple_t *new = am(myself, sizeof (*new)); 14267c478bd9Sstevel@tonic-gate 14277c478bd9Sstevel@tonic-gate if (new != 0) { 14287c478bd9Sstevel@tonic-gate copySearchTriple(old, new, &err); 14297c478bd9Sstevel@tonic-gate if (err != 0) { 14307c478bd9Sstevel@tonic-gate freeSearchTriple(new, 1); 14317c478bd9Sstevel@tonic-gate new = 0; 14327c478bd9Sstevel@tonic-gate } 14337c478bd9Sstevel@tonic-gate } 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate return (new); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate void 14397c478bd9Sstevel@tonic-gate freeSearchTriple(__nis_search_triple_t *old, bool_t doFree) { 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate if (old == 0) 14427c478bd9Sstevel@tonic-gate return; 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate sfree(old->base); 14457c478bd9Sstevel@tonic-gate sfree(old->attrs); 14467c478bd9Sstevel@tonic-gate /* 14477c478bd9Sstevel@tonic-gate * Since we only copied the element pointer when this structure 14487c478bd9Sstevel@tonic-gate * was created, we don't free old->element. 14497c478bd9Sstevel@tonic-gate */ 14507c478bd9Sstevel@tonic-gate if (doFree) 14517c478bd9Sstevel@tonic-gate free(old); 14527c478bd9Sstevel@tonic-gate } 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate void 14557c478bd9Sstevel@tonic-gate copyTripleOrObj(__nis_mapping_item_type_t type, 14567c478bd9Sstevel@tonic-gate __nis_triple_or_obj_t *old, __nis_triple_or_obj_t *new, 14577c478bd9Sstevel@tonic-gate int *err) { 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate *err = 0; 14607c478bd9Sstevel@tonic-gate 14617c478bd9Sstevel@tonic-gate if (old == 0 || new == 0) { 14627c478bd9Sstevel@tonic-gate *err = EINVAL; 14637c478bd9Sstevel@tonic-gate return; 14647c478bd9Sstevel@tonic-gate } 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate if (type == mit_nisplus) { 14677c478bd9Sstevel@tonic-gate copyObjSpec(&old->obj, &new->obj, err); 14687c478bd9Sstevel@tonic-gate } else if (type == mit_ldap) { 14697c478bd9Sstevel@tonic-gate copySearchTriple(&old->triple, &new->triple, err); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate } 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate __nis_triple_or_obj_t * 14747c478bd9Sstevel@tonic-gate cloneTripleOrObj(__nis_mapping_item_type_t type, __nis_triple_or_obj_t *old) { 14757c478bd9Sstevel@tonic-gate char *myself = "cloneTripleOrObj"; 14767c478bd9Sstevel@tonic-gate int err = 0; 14777c478bd9Sstevel@tonic-gate __nis_triple_or_obj_t *new = am(myself, sizeof (*new)); 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate if (new != 0) { 14807c478bd9Sstevel@tonic-gate copyTripleOrObj(type, old, new, &err); 14817c478bd9Sstevel@tonic-gate if (err != 0) { 14827c478bd9Sstevel@tonic-gate freeTripleOrObj(type, new, 1); 14837c478bd9Sstevel@tonic-gate new = 0; 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate return (new); 14887c478bd9Sstevel@tonic-gate } 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate void 14917c478bd9Sstevel@tonic-gate freeTripleOrObj(__nis_mapping_item_type_t type, __nis_triple_or_obj_t *old, 14927c478bd9Sstevel@tonic-gate bool_t doFree) { 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate if (old == 0) 14957c478bd9Sstevel@tonic-gate return; 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate if (type == mit_nisplus) 14987c478bd9Sstevel@tonic-gate freeObjSpec(&old->obj, doFree); 14997c478bd9Sstevel@tonic-gate else if (type == mit_ldap) 15007c478bd9Sstevel@tonic-gate freeSearchTriple(&old->triple, doFree); 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate if (doFree) 15037c478bd9Sstevel@tonic-gate free(old); 15047c478bd9Sstevel@tonic-gate } 15057c478bd9Sstevel@tonic-gate 15067c478bd9Sstevel@tonic-gate void 15077c478bd9Sstevel@tonic-gate copyItem(__nis_mapping_item_t *old, __nis_mapping_item_t *new, int *err) { 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate *err = 0; 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate if (old == 0 || new == 0) { 15127c478bd9Sstevel@tonic-gate *err = EINVAL; 15137c478bd9Sstevel@tonic-gate return; 15147c478bd9Sstevel@tonic-gate } 15157c478bd9Sstevel@tonic-gate 15167c478bd9Sstevel@tonic-gate new->type = old->type; 15177c478bd9Sstevel@tonic-gate new->repeat = old->repeat; 15187c478bd9Sstevel@tonic-gate if (old->name != 0) { 15197c478bd9Sstevel@tonic-gate new->name = strdup(old->name); 15207c478bd9Sstevel@tonic-gate if (new->name == 0) { 15217c478bd9Sstevel@tonic-gate *err = ENOMEM; 15227c478bd9Sstevel@tonic-gate return; 15237c478bd9Sstevel@tonic-gate } 15247c478bd9Sstevel@tonic-gate } else { 15257c478bd9Sstevel@tonic-gate new->name = 0; 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate if (old->type == mit_nisplus || old->type == mit_ldap) 15287c478bd9Sstevel@tonic-gate copyTripleOrObj(old->type, &old->searchSpec, &new->searchSpec, 15297c478bd9Sstevel@tonic-gate err); 15307c478bd9Sstevel@tonic-gate else 15317c478bd9Sstevel@tonic-gate memset(&new->searchSpec, 0, sizeof (new->searchSpec)); 15327c478bd9Sstevel@tonic-gate } 15337c478bd9Sstevel@tonic-gate 15347c478bd9Sstevel@tonic-gate __nis_mapping_item_t * 15357c478bd9Sstevel@tonic-gate cloneItem(__nis_mapping_item_t *old) { 15367c478bd9Sstevel@tonic-gate __nis_mapping_item_t *new; 15377c478bd9Sstevel@tonic-gate int err = 0; 15387c478bd9Sstevel@tonic-gate char *myself = "cloneItem"; 15397c478bd9Sstevel@tonic-gate 15407c478bd9Sstevel@tonic-gate if (old == 0) 15417c478bd9Sstevel@tonic-gate return (0); 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate new = am(myself, sizeof (*new)); 15447c478bd9Sstevel@tonic-gate if (new == 0) 15457c478bd9Sstevel@tonic-gate return (0); 15467c478bd9Sstevel@tonic-gate 15477c478bd9Sstevel@tonic-gate copyItem(old, new, &err); 15487c478bd9Sstevel@tonic-gate if (err != 0) { 15497c478bd9Sstevel@tonic-gate freeMappingItem(new, 1); 15507c478bd9Sstevel@tonic-gate return (0); 15517c478bd9Sstevel@tonic-gate } 15527c478bd9Sstevel@tonic-gate 15537c478bd9Sstevel@tonic-gate return (new); 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate 15567c478bd9Sstevel@tonic-gate void 15577c478bd9Sstevel@tonic-gate freeMappingItem(__nis_mapping_item_t *item, int numItems) { 15587c478bd9Sstevel@tonic-gate int i; 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate if (item == 0) 15617c478bd9Sstevel@tonic-gate return; 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate for (i = 0; i < numItems; i++) { 15647c478bd9Sstevel@tonic-gate sfree(item[i].name); 15657c478bd9Sstevel@tonic-gate freeTripleOrObj(item[i].type, &item[i].searchSpec, FALSE); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate sfree(item); 15687c478bd9Sstevel@tonic-gate } 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate __nis_mapping_item_t * 15717c478bd9Sstevel@tonic-gate concatenateMappingItem(__nis_mapping_item_t *old, int numItems, 15727c478bd9Sstevel@tonic-gate __nis_mapping_item_t *cat) { 15737c478bd9Sstevel@tonic-gate __nis_mapping_item_t *new; 15747c478bd9Sstevel@tonic-gate int i, err = 0; 15757c478bd9Sstevel@tonic-gate char *myself = "concatenateMappingItem"; 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate if (old == 0 || numItems < 1) 15787c478bd9Sstevel@tonic-gate return (cloneItem(cat)); 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate new = am(myself, (numItems + 1) * sizeof (*new)); 15817c478bd9Sstevel@tonic-gate if (new == 0) 15827c478bd9Sstevel@tonic-gate return (0); 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate for (i = 0; i < numItems; i++) { 15857c478bd9Sstevel@tonic-gate copyItem(&old[i], &new[i], &err); 15867c478bd9Sstevel@tonic-gate if (err != 0) { 15877c478bd9Sstevel@tonic-gate freeMappingItem(new, i); 15887c478bd9Sstevel@tonic-gate return (0); 15897c478bd9Sstevel@tonic-gate } 15907c478bd9Sstevel@tonic-gate } 15917c478bd9Sstevel@tonic-gate copyItem(cat, &new[numItems], &err); 15927c478bd9Sstevel@tonic-gate if (err != 0) { 15937c478bd9Sstevel@tonic-gate freeMappingItem(new, numItems); 15947c478bd9Sstevel@tonic-gate new = 0; 15957c478bd9Sstevel@tonic-gate } 15967c478bd9Sstevel@tonic-gate 15977c478bd9Sstevel@tonic-gate return (new); 15987c478bd9Sstevel@tonic-gate } 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate __nis_value_t * 16017c478bd9Sstevel@tonic-gate concatenateValues(__nis_value_t *v1, __nis_value_t *v2) { 16027c478bd9Sstevel@tonic-gate int i, n, a; 16037c478bd9Sstevel@tonic-gate __nis_value_t *v; 16047c478bd9Sstevel@tonic-gate char *myself = "concatenateValues"; 16057c478bd9Sstevel@tonic-gate 16067c478bd9Sstevel@tonic-gate if (v1 == 0 || v1->numVals <= 0) 16077c478bd9Sstevel@tonic-gate return (cloneValue(v2, 1)); 16087c478bd9Sstevel@tonic-gate if (v2 == 0 || v2->numVals <= 0) 16097c478bd9Sstevel@tonic-gate return (cloneValue(v1, 1)); 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate if (v1->type != v2->type) 16127c478bd9Sstevel@tonic-gate return (0); 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate n = v1->numVals + v2->numVals; 16157c478bd9Sstevel@tonic-gate v = am(myself, sizeof (*v)); 16167c478bd9Sstevel@tonic-gate if (v == 0) 16177c478bd9Sstevel@tonic-gate return (0); 16187c478bd9Sstevel@tonic-gate v->val = am(myself, n * sizeof (v->val[0])); 16197c478bd9Sstevel@tonic-gate if (v->val == 0) { 16207c478bd9Sstevel@tonic-gate free(v); 16217c478bd9Sstevel@tonic-gate return (0); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate v->type = v1->type; 16247c478bd9Sstevel@tonic-gate v->numVals = 0; 16257c478bd9Sstevel@tonic-gate 16267c478bd9Sstevel@tonic-gate for (a = 0; a < 2; a++) { 16277c478bd9Sstevel@tonic-gate __nis_single_value_t *val = (a == 0) ? v1->val : v2->val; 16287c478bd9Sstevel@tonic-gate int numv = (a == 0) ? v1->numVals : 16297c478bd9Sstevel@tonic-gate v2->numVals; 16307c478bd9Sstevel@tonic-gate for (i = 0; i < numv; i++) { 16317c478bd9Sstevel@tonic-gate int clen, alen = val[i].length; 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate clen = alen; 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate /* 16367c478bd9Sstevel@tonic-gate * Make sure there's a NUL at the end of a string, 16377c478bd9Sstevel@tonic-gate * but avoid adding to the allocated length if there's 16387c478bd9Sstevel@tonic-gate * already a NUL at the end. 16397c478bd9Sstevel@tonic-gate */ 16407c478bd9Sstevel@tonic-gate if (alen > 0 && v->type == vt_string && 16417c478bd9Sstevel@tonic-gate ((char *)val[i].value)[alen-1] != '\0') 16427c478bd9Sstevel@tonic-gate alen += 1; 16437c478bd9Sstevel@tonic-gate v->val[v->numVals].value = am(myself, alen); 16447c478bd9Sstevel@tonic-gate if (v->val[v->numVals].value == 0) { 16457c478bd9Sstevel@tonic-gate freeValue(v, 1); 16467c478bd9Sstevel@tonic-gate return (0); 16477c478bd9Sstevel@tonic-gate } 16487c478bd9Sstevel@tonic-gate memcpy(v->val[v->numVals].value, val[i].value, clen); 16497c478bd9Sstevel@tonic-gate v->val[v->numVals].length = val[i].length; 16507c478bd9Sstevel@tonic-gate v->numVals++; 16517c478bd9Sstevel@tonic-gate } 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate return (v); 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate __nis_value_t * 16587c478bd9Sstevel@tonic-gate splitMappingItem(__nis_mapping_item_t *item, char delim, 16597c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv) { 16607c478bd9Sstevel@tonic-gate __nis_value_t *val = getMappingItem(item, mit_any, 16617c478bd9Sstevel@tonic-gate rv, 0, NULL); 16627c478bd9Sstevel@tonic-gate __nis_single_value_t *nval; 16637c478bd9Sstevel@tonic-gate int i, n, nv; 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate if (val == 0) 16667c478bd9Sstevel@tonic-gate return (0); 16677c478bd9Sstevel@tonic-gate else if (delim == 0 || val->val == 0 || val->numVals <= 0 || 16687c478bd9Sstevel@tonic-gate val->type != vt_string) { 16697c478bd9Sstevel@tonic-gate freeValue(val, 1); 16707c478bd9Sstevel@tonic-gate return (0); 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate nval = val->val; 16747c478bd9Sstevel@tonic-gate nv = val->numVals; 16757c478bd9Sstevel@tonic-gate val->repeat = FALSE; 16767c478bd9Sstevel@tonic-gate val->val = 0; 16777c478bd9Sstevel@tonic-gate val->numVals = 0; 16787c478bd9Sstevel@tonic-gate 16797c478bd9Sstevel@tonic-gate /* In N2L, space and tab delimiters are treated the same */ 16807c478bd9Sstevel@tonic-gate if (yp2ldap && delim == '\t') 16817c478bd9Sstevel@tonic-gate delim = ' '; 16827c478bd9Sstevel@tonic-gate 16837c478bd9Sstevel@tonic-gate /* If the item has multiple values, we split each one independently */ 16847c478bd9Sstevel@tonic-gate for (i = 0; i < nv; i++) { 16857c478bd9Sstevel@tonic-gate char *str; 16867c478bd9Sstevel@tonic-gate int s, e; 16877c478bd9Sstevel@tonic-gate char *newstr; 16887c478bd9Sstevel@tonic-gate __nis_single_value_t *newval; 16897c478bd9Sstevel@tonic-gate 16907c478bd9Sstevel@tonic-gate if (yp2ldap && delim == ' ') 16917c478bd9Sstevel@tonic-gate nval[i].value = trimWhiteSpaces(nval[i].value, 16927c478bd9Sstevel@tonic-gate &nval[i].length, 1); 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate str = nval[i].value; 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate if (nval[i].value == 0) 16977c478bd9Sstevel@tonic-gate continue; 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate for (s = 0; s < nval[i].length; s = e+1) { 17007c478bd9Sstevel@tonic-gate /* Find the next delimiter, or end-of-string */ 17017c478bd9Sstevel@tonic-gate for (e = s; str[e] != '\0' && str[e] != delim; e++); 17027c478bd9Sstevel@tonic-gate /* 17037c478bd9Sstevel@tonic-gate * 'str[e]' is either a delimiter, or the concluding 17047c478bd9Sstevel@tonic-gate * NUL. Make sure it's NUL. 17057c478bd9Sstevel@tonic-gate */ 17067c478bd9Sstevel@tonic-gate str[e] = '\0'; 17077c478bd9Sstevel@tonic-gate /* Add to val->val */ 17087c478bd9Sstevel@tonic-gate newstr = strdup(&str[s]); 17097c478bd9Sstevel@tonic-gate newval = realloc(val->val, 17107c478bd9Sstevel@tonic-gate (val->numVals+1) * 17117c478bd9Sstevel@tonic-gate sizeof (val->val[0])); 17127c478bd9Sstevel@tonic-gate if (newval != 0) 17137c478bd9Sstevel@tonic-gate val->val = newval; 17147c478bd9Sstevel@tonic-gate if (newstr == 0 || newval == 0) { 17157c478bd9Sstevel@tonic-gate freeValue(val, 1); 17167c478bd9Sstevel@tonic-gate for (n = i; n < nv; n++) { 17177c478bd9Sstevel@tonic-gate sfree(nval[n].value); 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate free(nval); 17207c478bd9Sstevel@tonic-gate sfree(newstr); 17217c478bd9Sstevel@tonic-gate return (0); 17227c478bd9Sstevel@tonic-gate } 17237c478bd9Sstevel@tonic-gate val->val[val->numVals].value = newstr; 17247c478bd9Sstevel@tonic-gate val->val[val->numVals].length = strlen(newstr) + 1; 17257c478bd9Sstevel@tonic-gate val->numVals++; 17267c478bd9Sstevel@tonic-gate } 17277c478bd9Sstevel@tonic-gate free(nval[i].value); 17287c478bd9Sstevel@tonic-gate nval[i].value = 0; 17297c478bd9Sstevel@tonic-gate } 17307c478bd9Sstevel@tonic-gate /* Already freed the nval[i].value's as we traversed nval */ 17317c478bd9Sstevel@tonic-gate free(nval); 17327c478bd9Sstevel@tonic-gate 17337c478bd9Sstevel@tonic-gate return (val); 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate /* 17377c478bd9Sstevel@tonic-gate * Match the format spec 'f[curf]' to the input value string 'str'. 17387c478bd9Sstevel@tonic-gate * 17397c478bd9Sstevel@tonic-gate * If successful, returns the updated position in the value string 'str'. 17407c478bd9Sstevel@tonic-gate * Otherwise, NULL is returned. 17417c478bd9Sstevel@tonic-gate * 17427c478bd9Sstevel@tonic-gate * curf Current index (i.e., the one we should look at) in 'f' 17437c478bd9Sstevel@tonic-gate * nf Number of elements in 'f', including 'mmt_end' 17447c478bd9Sstevel@tonic-gate * str The value string we're scanning 17457c478bd9Sstevel@tonic-gate * val Pointer to where an item value (if any) should be returned 17467c478bd9Sstevel@tonic-gate * Set to NULL if not an 'mmt_item'. 17477c478bd9Sstevel@tonic-gate * fmtstart If non-zero on entry, skip characters in 'str' until we find 17487c478bd9Sstevel@tonic-gate * the f[curf].type data, if doing so makes any sense. On exit, 17497c478bd9Sstevel@tonic-gate * set to the start of the fmt element data (which will be 'str', 17507c478bd9Sstevel@tonic-gate * unless we did skip characters) 17517c478bd9Sstevel@tonic-gate * sepset List of separators 17527c478bd9Sstevel@tonic-gate */ 17537c478bd9Sstevel@tonic-gate char * 17547c478bd9Sstevel@tonic-gate scanMappingFormat(__nis_mapping_format_t *f, int curf, int nf, char *str, 17557c478bd9Sstevel@tonic-gate char **val, char **fmtstart, char *sepset) { 17567c478bd9Sstevel@tonic-gate char *mstr, *next, *start = 0, *tmpstr; 17577c478bd9Sstevel@tonic-gate int i, len; 17587c478bd9Sstevel@tonic-gate bool_t match; 17597c478bd9Sstevel@tonic-gate char *myself = "scanMappingFormat"; 17607c478bd9Sstevel@tonic-gate /* N2L variables */ 17617c478bd9Sstevel@tonic-gate int af, skipspaces = 0; 17627c478bd9Sstevel@tonic-gate bool_t ipaddr = FALSE; 17637c478bd9Sstevel@tonic-gate char *spacestr = " ", *emptystr = ""; 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate 17667c478bd9Sstevel@tonic-gate if (f == 0 || curf < 0 || nf <= 0 || str == 0) 17677c478bd9Sstevel@tonic-gate return (0); 17687c478bd9Sstevel@tonic-gate 17697c478bd9Sstevel@tonic-gate /* 17707c478bd9Sstevel@tonic-gate * If separator list is NULL (which will be the case for 17717c478bd9Sstevel@tonic-gate * nis+2ldap), then simply use empty string 17727c478bd9Sstevel@tonic-gate */ 17737c478bd9Sstevel@tonic-gate if (sepset == 0) 17747c478bd9Sstevel@tonic-gate sepset = emptystr; 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate if (curf >= nf) { 17777c478bd9Sstevel@tonic-gate /* OK if the string also is exhausted */ 17787c478bd9Sstevel@tonic-gate if (strchr(sepset, *str) != 0) 17797c478bd9Sstevel@tonic-gate return (str); 17807c478bd9Sstevel@tonic-gate else 17817c478bd9Sstevel@tonic-gate return (0); 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate switch (f[curf].type) { 17857c478bd9Sstevel@tonic-gate case mmt_berstring: 17867c478bd9Sstevel@tonic-gate if (f[curf].match.berString[0] != 'a') { 17877c478bd9Sstevel@tonic-gate /* Not a matchable element */ 17887c478bd9Sstevel@tonic-gate return (0); 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate /* 17927c478bd9Sstevel@tonic-gate * If here, it means it's an IP address (N2L case) 17937c478bd9Sstevel@tonic-gate * So continue processing as if it was mmt_item 17947c478bd9Sstevel@tonic-gate */ 17957c478bd9Sstevel@tonic-gate ipaddr = TRUE; 17967c478bd9Sstevel@tonic-gate 17977c478bd9Sstevel@tonic-gate case mmt_item: 17987c478bd9Sstevel@tonic-gate /* 17997c478bd9Sstevel@tonic-gate * In order to find the end of the item value, we must look 18007c478bd9Sstevel@tonic-gate * ahead and determine the start of the next formatting element. 18017c478bd9Sstevel@tonic-gate * If successful, 'next' will be the start of the fmt element 18027c478bd9Sstevel@tonic-gate * after the next one; we don't care about that, other than to 18037c478bd9Sstevel@tonic-gate * check for error. 18047c478bd9Sstevel@tonic-gate * 18057c478bd9Sstevel@tonic-gate * Since an item match is somewhat like an any match, in that 18067c478bd9Sstevel@tonic-gate * we don't know a priori if the first occurence of the next 18077c478bd9Sstevel@tonic-gate * element really is the one we want, we have to scan ahead 18087c478bd9Sstevel@tonic-gate * until we've reached the end. 18097c478bd9Sstevel@tonic-gate */ 18107c478bd9Sstevel@tonic-gate tmpstr = str; 18117c478bd9Sstevel@tonic-gate while ((next = scanMappingFormat(f, curf+1, nf, tmpstr, 0, 18127c478bd9Sstevel@tonic-gate &start, sepset)) != 0) { 18137c478bd9Sstevel@tonic-gate char *tmp = next; 18147c478bd9Sstevel@tonic-gate int cf; 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate for (cf = curf+2; cf < nf; cf++) { 18177c478bd9Sstevel@tonic-gate tmp = scanMappingFormat(f, cf, nf, tmp, 0, 18187c478bd9Sstevel@tonic-gate 0, sepset); 18197c478bd9Sstevel@tonic-gate if (tmp == 0) 18207c478bd9Sstevel@tonic-gate break; 18217c478bd9Sstevel@tonic-gate } 18227c478bd9Sstevel@tonic-gate if (tmp == 0) { 18237c478bd9Sstevel@tonic-gate tmpstr = next; 18247c478bd9Sstevel@tonic-gate } else if (strchr(sepset, *tmp) != 0) { 18257c478bd9Sstevel@tonic-gate break; 18267c478bd9Sstevel@tonic-gate } else { 18277c478bd9Sstevel@tonic-gate return (0); 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate 18307c478bd9Sstevel@tonic-gate } 18317c478bd9Sstevel@tonic-gate if (next == 0 || start == 0) 18327c478bd9Sstevel@tonic-gate return (0); 18337c478bd9Sstevel@tonic-gate 18347c478bd9Sstevel@tonic-gate if (val != 0) { 18357c478bd9Sstevel@tonic-gate len = (int)((long)start - (long)str); 18367c478bd9Sstevel@tonic-gate *val = am(myself, len + 1); 18377c478bd9Sstevel@tonic-gate if (*val == 0) 18387c478bd9Sstevel@tonic-gate return (0); 18397c478bd9Sstevel@tonic-gate memcpy(*val, str, len); 18407c478bd9Sstevel@tonic-gate (*val)[len] = '\0'; 18417c478bd9Sstevel@tonic-gate 18427c478bd9Sstevel@tonic-gate if (ipaddr == TRUE) { 18437c478bd9Sstevel@tonic-gate /* 18447c478bd9Sstevel@tonic-gate * In N2L, we need to check if *val is truly an 18457c478bd9Sstevel@tonic-gate * IP address 18467c478bd9Sstevel@tonic-gate */ 18477c478bd9Sstevel@tonic-gate af = checkIPaddress(*val, len, &tmpstr); 18487c478bd9Sstevel@tonic-gate 18497c478bd9Sstevel@tonic-gate if (af == -2) { 18507c478bd9Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_WARNING, 18517c478bd9Sstevel@tonic-gate "%s:Internal error while " 18527c478bd9Sstevel@tonic-gate "processing IPaddress %s", 18537c478bd9Sstevel@tonic-gate myself, *val); 18547c478bd9Sstevel@tonic-gate sfree(*val); 18557c478bd9Sstevel@tonic-gate return (0); 18567c478bd9Sstevel@tonic-gate } else if (af == -1) { 18577c478bd9Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_WARNING, 18587c478bd9Sstevel@tonic-gate "%s:%s is not an IP address", 18597c478bd9Sstevel@tonic-gate myself, *val); 18607c478bd9Sstevel@tonic-gate sfree(*val); 18617c478bd9Sstevel@tonic-gate return (0); 18627c478bd9Sstevel@tonic-gate } else if (af == 0) { 18637c478bd9Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_WARNING, 18647c478bd9Sstevel@tonic-gate "%s:IP address %s is not " 18657c478bd9Sstevel@tonic-gate "supported by rfc2307bis", 18667c478bd9Sstevel@tonic-gate myself, *val); 18677c478bd9Sstevel@tonic-gate sfree(*val); 18687c478bd9Sstevel@tonic-gate return (0); 18697c478bd9Sstevel@tonic-gate } else if (sstrncmp(*val, tmpstr, len) != 0) { 18707c478bd9Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_WARNING, 18717c478bd9Sstevel@tonic-gate "%s:IPaddress %s converted " 18727c478bd9Sstevel@tonic-gate "to %s", myself, *val, tmpstr); 18737c478bd9Sstevel@tonic-gate } 18747c478bd9Sstevel@tonic-gate 18757c478bd9Sstevel@tonic-gate sfree(*val); 18767c478bd9Sstevel@tonic-gate *val = tmpstr; 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate } 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate if (fmtstart != 0) 18817c478bd9Sstevel@tonic-gate *fmtstart = str; 18827c478bd9Sstevel@tonic-gate 18837c478bd9Sstevel@tonic-gate return (start); 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate case mmt_string: 18867c478bd9Sstevel@tonic-gate if ((mstr = f[curf].match.string) == 0 || *mstr == '\0') { 18877c478bd9Sstevel@tonic-gate /* 18887c478bd9Sstevel@tonic-gate * Count this as a successful match of an empty 18897c478bd9Sstevel@tonic-gate * string. 18907c478bd9Sstevel@tonic-gate */ 18917c478bd9Sstevel@tonic-gate if (fmtstart != 0) 18927c478bd9Sstevel@tonic-gate *fmtstart = str; 18937c478bd9Sstevel@tonic-gate return (str); 18947c478bd9Sstevel@tonic-gate } 18957c478bd9Sstevel@tonic-gate 18967c478bd9Sstevel@tonic-gate /* 18977c478bd9Sstevel@tonic-gate * In N2L, if the format string 'mstr' contains only 18987c478bd9Sstevel@tonic-gate * whitespaces (spaces and tabs), then it should 18997c478bd9Sstevel@tonic-gate * match one or more whitespaces from the input 19007c478bd9Sstevel@tonic-gate * string 'str'. 19017c478bd9Sstevel@tonic-gate */ 19027c478bd9Sstevel@tonic-gate if (yp2ldap && strspn(mstr, " \t") == strlen(mstr)) { 19037c478bd9Sstevel@tonic-gate mstr = spacestr; 19047c478bd9Sstevel@tonic-gate skipspaces = 1; 19057c478bd9Sstevel@tonic-gate next = str + strcspn(str, " \t"); 19067c478bd9Sstevel@tonic-gate /* 19077c478bd9Sstevel@tonic-gate * Even if there is no whitespace in 'str', 19087c478bd9Sstevel@tonic-gate * it's OK. This is to allow formats like 19097c478bd9Sstevel@tonic-gate * "%s %s %s" to match inputs like "foo bar". 19107c478bd9Sstevel@tonic-gate */ 19117c478bd9Sstevel@tonic-gate if (*next == '\0') 19127c478bd9Sstevel@tonic-gate mstr = emptystr; 19137c478bd9Sstevel@tonic-gate } else { 19147c478bd9Sstevel@tonic-gate /* No match string in 'str' => failure */ 19157c478bd9Sstevel@tonic-gate if ((next = strstr(str, mstr)) == 0) 19167c478bd9Sstevel@tonic-gate return (0); 19177c478bd9Sstevel@tonic-gate } 19187c478bd9Sstevel@tonic-gate 19197c478bd9Sstevel@tonic-gate /* If 'fmtstart' == 0, we require 'next' == 'str' */ 19207c478bd9Sstevel@tonic-gate if (fmtstart == 0 && next != str) 19217c478bd9Sstevel@tonic-gate return (0); 19227c478bd9Sstevel@tonic-gate /* Success; save start of match string if requested */ 19237c478bd9Sstevel@tonic-gate if (fmtstart != 0) 19247c478bd9Sstevel@tonic-gate *fmtstart = next; 19257c478bd9Sstevel@tonic-gate /* Update position in the value string */ 19267c478bd9Sstevel@tonic-gate str = (char *)((long)next + (long)strlen(mstr)); 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate /* Skip whitespaces for N2L */ 19297c478bd9Sstevel@tonic-gate if (skipspaces == 1) 19307c478bd9Sstevel@tonic-gate for (; *str == ' ' || *str == '\t'; str++); 19317c478bd9Sstevel@tonic-gate 19327c478bd9Sstevel@tonic-gate return (str); 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate case mmt_single: 19357c478bd9Sstevel@tonic-gate if (fmtstart != 0) { 19367c478bd9Sstevel@tonic-gate match = FALSE; 19377c478bd9Sstevel@tonic-gate /* Skip ahead until we match */ 19387c478bd9Sstevel@tonic-gate for (next = str; *next != '\0'; next++) { 19397c478bd9Sstevel@tonic-gate unsigned char *lo = f[curf].match.single.lo; 19407c478bd9Sstevel@tonic-gate unsigned char *hi = f[curf].match.single.hi; 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate for (i = 0; i < f[curf].match.single.numRange; 19437c478bd9Sstevel@tonic-gate i++) { 19447c478bd9Sstevel@tonic-gate if (*next >= lo[i] && *next <= hi[i]) { 19457c478bd9Sstevel@tonic-gate match = TRUE; 19467c478bd9Sstevel@tonic-gate break; 19477c478bd9Sstevel@tonic-gate } 19487c478bd9Sstevel@tonic-gate } 19497c478bd9Sstevel@tonic-gate if (match) 19507c478bd9Sstevel@tonic-gate break; 19517c478bd9Sstevel@tonic-gate } 19527c478bd9Sstevel@tonic-gate if (!match) 19537c478bd9Sstevel@tonic-gate return (0); 19547c478bd9Sstevel@tonic-gate *fmtstart = next; 19557c478bd9Sstevel@tonic-gate str = next; 19567c478bd9Sstevel@tonic-gate } else { 19577c478bd9Sstevel@tonic-gate match = FALSE; 19587c478bd9Sstevel@tonic-gate for (i = 0; i < f[curf].match.single.numRange; i++) { 19597c478bd9Sstevel@tonic-gate if (*str >= f[curf].match.single.lo[i] && 19607c478bd9Sstevel@tonic-gate *str <= f[curf].match.single.hi[i]) { 19617c478bd9Sstevel@tonic-gate match = TRUE; 19627c478bd9Sstevel@tonic-gate break; 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate if (!match) 19667c478bd9Sstevel@tonic-gate return (0); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate /* Step over the matched character */ 19697c478bd9Sstevel@tonic-gate str++; 19707c478bd9Sstevel@tonic-gate return (str); 19717c478bd9Sstevel@tonic-gate 19727c478bd9Sstevel@tonic-gate case mmt_any: 19737c478bd9Sstevel@tonic-gate /* 19747c478bd9Sstevel@tonic-gate * Look ahead to find the beginning of the next element. 19757c478bd9Sstevel@tonic-gate * Because a wildcard-match isn't necessarily uniquely 19767c478bd9Sstevel@tonic-gate * determined until we've reached the end, we then continue 19777c478bd9Sstevel@tonic-gate * to scan ahead. 19787c478bd9Sstevel@tonic-gate */ 19797c478bd9Sstevel@tonic-gate while ((next = scanMappingFormat(f, curf+1, nf, str, 0, 19807c478bd9Sstevel@tonic-gate &start, sepset)) != 0) { 19817c478bd9Sstevel@tonic-gate char *tmp = next; 19827c478bd9Sstevel@tonic-gate int cf; 19837c478bd9Sstevel@tonic-gate 19847c478bd9Sstevel@tonic-gate for (cf = curf+2; cf < nf; cf++) { 19857c478bd9Sstevel@tonic-gate tmp = scanMappingFormat(f, cf, nf, tmp, 0, 19867c478bd9Sstevel@tonic-gate 0, sepset); 19877c478bd9Sstevel@tonic-gate if (tmp == 0) 19887c478bd9Sstevel@tonic-gate break; 19897c478bd9Sstevel@tonic-gate } 19907c478bd9Sstevel@tonic-gate if (tmp == 0) { 19917c478bd9Sstevel@tonic-gate str = next; 19927c478bd9Sstevel@tonic-gate } else if (*tmp == '\0') { 19937c478bd9Sstevel@tonic-gate break; 19947c478bd9Sstevel@tonic-gate } else { 19957c478bd9Sstevel@tonic-gate return (0); 19967c478bd9Sstevel@tonic-gate } 19977c478bd9Sstevel@tonic-gate } 19987c478bd9Sstevel@tonic-gate if (next == 0 || start == 0) 19997c478bd9Sstevel@tonic-gate return (0); 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate if (fmtstart != 0) 20027c478bd9Sstevel@tonic-gate *fmtstart = str; 20037c478bd9Sstevel@tonic-gate 20047c478bd9Sstevel@tonic-gate return (start); 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate case mmt_limit: 20077c478bd9Sstevel@tonic-gate if (f[curf].match.limit == eos) { 20087c478bd9Sstevel@tonic-gate if (fmtstart != 0) { 20097c478bd9Sstevel@tonic-gate /* Skip to the end */ 20107c478bd9Sstevel@tonic-gate str = str + strcspn(str, sepset); 20117c478bd9Sstevel@tonic-gate *fmtstart = str; 20127c478bd9Sstevel@tonic-gate } else if (strchr(sepset, *str) == 0) { 20137c478bd9Sstevel@tonic-gate return (0); 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate } 20167c478bd9Sstevel@tonic-gate return (str); 20177c478bd9Sstevel@tonic-gate 20187c478bd9Sstevel@tonic-gate case mmt_begin: 20197c478bd9Sstevel@tonic-gate if (fmtstart != 0) 20207c478bd9Sstevel@tonic-gate *fmtstart = str; 20217c478bd9Sstevel@tonic-gate return (str); 20227c478bd9Sstevel@tonic-gate 20237c478bd9Sstevel@tonic-gate case mmt_end: 20247c478bd9Sstevel@tonic-gate if (fmtstart != 0) { 20257c478bd9Sstevel@tonic-gate /* Skip to the end */ 20267c478bd9Sstevel@tonic-gate str = str + strcspn(str, sepset); 20277c478bd9Sstevel@tonic-gate *fmtstart = str; 20287c478bd9Sstevel@tonic-gate return (str); 20297c478bd9Sstevel@tonic-gate } 20307c478bd9Sstevel@tonic-gate /* No skipping, so we must be at the end of the value */ 20317c478bd9Sstevel@tonic-gate if (strchr(sepset, *str) == 0) 20327c478bd9Sstevel@tonic-gate return (0); 20337c478bd9Sstevel@tonic-gate return (str); 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate default: 20367c478bd9Sstevel@tonic-gate break; 20377c478bd9Sstevel@tonic-gate } 20387c478bd9Sstevel@tonic-gate 20397c478bd9Sstevel@tonic-gate return (0); 20407c478bd9Sstevel@tonic-gate } 20417c478bd9Sstevel@tonic-gate 20427c478bd9Sstevel@tonic-gate /* 20437c478bd9Sstevel@tonic-gate * Verify that the string 'str' matches the mapping format array 'f'. 20447c478bd9Sstevel@tonic-gate * Returns 1 in case of a match, 0 otherwise. 20457c478bd9Sstevel@tonic-gate */ 20467c478bd9Sstevel@tonic-gate int 20477c478bd9Sstevel@tonic-gate verifyMappingMatch(__nis_mapping_format_t *f, char *str) { 20487c478bd9Sstevel@tonic-gate int n, nf; 20497c478bd9Sstevel@tonic-gate __nis_mapping_format_t *ftmp; 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate /* Count the number of format elements in the format */ 20527c478bd9Sstevel@tonic-gate for (nf = 0, ftmp = f; ftmp->type != mmt_end; ftmp++) { 20537c478bd9Sstevel@tonic-gate nf++; 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate /* Count the mmt_end as well */ 20567c478bd9Sstevel@tonic-gate nf++; 20577c478bd9Sstevel@tonic-gate 20587c478bd9Sstevel@tonic-gate for (n = 0; n < nf; n++) { 20597c478bd9Sstevel@tonic-gate str = scanMappingFormat(f, n, nf, str, 0, 0, 0); 20607c478bd9Sstevel@tonic-gate if (str == 0) 20617c478bd9Sstevel@tonic-gate break; 20627c478bd9Sstevel@tonic-gate } 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate return ((str != 0) ? 1 : 0); 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate 20677c478bd9Sstevel@tonic-gate /* 20687c478bd9Sstevel@tonic-gate * Perform a match operation. For example, given the rule 20697c478bd9Sstevel@tonic-gate * ("{%s}%s", auth_name, public_data)=nisPublicKey 20707c478bd9Sstevel@tonic-gate * and assuming that 'nisPublicKey' has the value "{dh640-0}abcdef12345", 20717c478bd9Sstevel@tonic-gate * assign "dh640-0" to 'auth_name' and "abcdef12345" to 'public_data'. 20727c478bd9Sstevel@tonic-gate * 20737c478bd9Sstevel@tonic-gate * Note that this function doesn't perform the actual assignment. Rather, 20747c478bd9Sstevel@tonic-gate * it returns an array of __nis_value_t's, with element zero of the value 20757c478bd9Sstevel@tonic-gate * array being the new value of the first matched item, element one the 20767c478bd9Sstevel@tonic-gate * value of the second matched item, etc. In the example above, we'd 20777c478bd9Sstevel@tonic-gate * return a value array with two elements. 20787c478bd9Sstevel@tonic-gate * 20797c478bd9Sstevel@tonic-gate * If there is more than one input value (inVal->numVals > 1), the 20807c478bd9Sstevel@tonic-gate * output array elements will also be multi-valued. 20817c478bd9Sstevel@tonic-gate * 20827c478bd9Sstevel@tonic-gate * f The match format 20837c478bd9Sstevel@tonic-gate * inVal Input value(s) 20847c478bd9Sstevel@tonic-gate * numVal Number of elements in the output value array 20857c478bd9Sstevel@tonic-gate * sepset List of separators 20867c478bd9Sstevel@tonic-gate * outstr Points to the updated position upto which the 20877c478bd9Sstevel@tonic-gate * input string has been matched 20887c478bd9Sstevel@tonic-gate */ 20897c478bd9Sstevel@tonic-gate __nis_value_t ** 20907c478bd9Sstevel@tonic-gate matchMappingItem(__nis_mapping_format_t *f, __nis_value_t *inVal, 20917c478bd9Sstevel@tonic-gate int *numVals, char *sepset, char **outstr) { 20927c478bd9Sstevel@tonic-gate __nis_value_t **v = 0; 20937c478bd9Sstevel@tonic-gate int i, n, ni, numItems, nf, nv = 0; 20947c478bd9Sstevel@tonic-gate char *str, *valstr; 20957c478bd9Sstevel@tonic-gate __nis_mapping_format_t *ftmp; 20967c478bd9Sstevel@tonic-gate char *myself = "matchMappingItem"; 20977c478bd9Sstevel@tonic-gate 20987c478bd9Sstevel@tonic-gate if (f == 0 || 20997c478bd9Sstevel@tonic-gate inVal == 0 || inVal->numVals < 1 || inVal->type != vt_string) 21007c478bd9Sstevel@tonic-gate return (0); 21017c478bd9Sstevel@tonic-gate 21027c478bd9Sstevel@tonic-gate /* Count the number of format elements and items in the format */ 21037c478bd9Sstevel@tonic-gate for (nf = numItems = 0, ftmp = f; ftmp->type != mmt_end; ftmp++) { 21047c478bd9Sstevel@tonic-gate nf++; 21057c478bd9Sstevel@tonic-gate 21067c478bd9Sstevel@tonic-gate /* 21077c478bd9Sstevel@tonic-gate * Count mmt_item and mmt_berstring (used by N2L to 21087c478bd9Sstevel@tonic-gate * represent address %a) 21097c478bd9Sstevel@tonic-gate */ 21107c478bd9Sstevel@tonic-gate if (ftmp->type == mmt_item) 21117c478bd9Sstevel@tonic-gate numItems++; 21127c478bd9Sstevel@tonic-gate else if (ftmp->type == mmt_berstring && ftmp->match.berString && 21137c478bd9Sstevel@tonic-gate ftmp->match.berString[0] == 'a') 21147c478bd9Sstevel@tonic-gate numItems++; 21157c478bd9Sstevel@tonic-gate } 21167c478bd9Sstevel@tonic-gate /* Count the mmt_end as well */ 21177c478bd9Sstevel@tonic-gate nf++; 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate /* 21207c478bd9Sstevel@tonic-gate * If no items, there will be no values. This isn't exactly an error 21217c478bd9Sstevel@tonic-gate * from the limited point of view of this function, so we return a 21227c478bd9Sstevel@tonic-gate * __nis_value_t with zero values. 21237c478bd9Sstevel@tonic-gate */ 21247c478bd9Sstevel@tonic-gate if (numItems <= 0) { 21257c478bd9Sstevel@tonic-gate v = am(myself, sizeof (v[0])); 21267c478bd9Sstevel@tonic-gate if (v == 0) 21277c478bd9Sstevel@tonic-gate return (0); 21287c478bd9Sstevel@tonic-gate v[0] = am(myself, sizeof (*v[0])); 21297c478bd9Sstevel@tonic-gate if (v[0] == 0) { 21307c478bd9Sstevel@tonic-gate sfree(v); 21317c478bd9Sstevel@tonic-gate return (0); 21327c478bd9Sstevel@tonic-gate } 21337c478bd9Sstevel@tonic-gate v[0]->type = vt_string; 21347c478bd9Sstevel@tonic-gate v[0]->numVals = 0; 21357c478bd9Sstevel@tonic-gate v[0]->val = 0; 21367c478bd9Sstevel@tonic-gate if (numVals != 0) 21377c478bd9Sstevel@tonic-gate *numVals = 1; 21387c478bd9Sstevel@tonic-gate return (v); 21397c478bd9Sstevel@tonic-gate } 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate /* Allocate and initialize the return array */ 21427c478bd9Sstevel@tonic-gate v = am(myself, numItems * sizeof (v[0])); 21437c478bd9Sstevel@tonic-gate if (v == 0) 21447c478bd9Sstevel@tonic-gate return (0); 21457c478bd9Sstevel@tonic-gate for (n = 0; n < numItems; n++) { 21467c478bd9Sstevel@tonic-gate v[n] = am(myself, sizeof (*v[n])); 21477c478bd9Sstevel@tonic-gate if (v[n] == 0) { 21487c478bd9Sstevel@tonic-gate int j; 21497c478bd9Sstevel@tonic-gate 21507c478bd9Sstevel@tonic-gate for (j = 0; j < n; j++) 21517c478bd9Sstevel@tonic-gate freeValue(v[j], 1); 21527c478bd9Sstevel@tonic-gate sfree(v); 21537c478bd9Sstevel@tonic-gate return (0); 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate v[n]->type = vt_string; 21567c478bd9Sstevel@tonic-gate v[n]->numVals = 0; 21577c478bd9Sstevel@tonic-gate v[n]->val = am(myself, inVal->numVals * sizeof (v[n]->val[0])); 21587c478bd9Sstevel@tonic-gate if (v[n]->val == 0) { 21597c478bd9Sstevel@tonic-gate int j; 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate for (j = 0; j < n; j++) 21627c478bd9Sstevel@tonic-gate freeValue(v[j], 1); 21637c478bd9Sstevel@tonic-gate sfree(v); 21647c478bd9Sstevel@tonic-gate return (0); 21657c478bd9Sstevel@tonic-gate } 21667c478bd9Sstevel@tonic-gate for (i = 0; i < inVal->numVals; i++) { 21677c478bd9Sstevel@tonic-gate v[n]->val[i].length = 0; 21687c478bd9Sstevel@tonic-gate v[n]->val[i].value = 0; 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate } 21717c478bd9Sstevel@tonic-gate 21727c478bd9Sstevel@tonic-gate /* For each input value, perform the match operation */ 21737c478bd9Sstevel@tonic-gate for (i = 0; i < inVal->numVals; i++) { 21747c478bd9Sstevel@tonic-gate str = inVal->val[i].value; 21757c478bd9Sstevel@tonic-gate if (str == 0) 21767c478bd9Sstevel@tonic-gate continue; 21777c478bd9Sstevel@tonic-gate for (n = 0, ni = 0; n < nf; n++) { 21787c478bd9Sstevel@tonic-gate valstr = 0; 21797c478bd9Sstevel@tonic-gate str = scanMappingFormat(f, n, nf, str, &valstr, 21807c478bd9Sstevel@tonic-gate 0, sepset); 21817c478bd9Sstevel@tonic-gate if (str == 0) 21827c478bd9Sstevel@tonic-gate break; 21837c478bd9Sstevel@tonic-gate if (valstr != 0 && ni < numItems && 21847c478bd9Sstevel@tonic-gate v[ni]->numVals < inVal->numVals) { 21857c478bd9Sstevel@tonic-gate v[ni]->val[v[ni]->numVals].value = valstr; 21867c478bd9Sstevel@tonic-gate v[ni]->val[v[ni]->numVals].length = 21877c478bd9Sstevel@tonic-gate strlen(valstr) + 1; 21887c478bd9Sstevel@tonic-gate v[ni]->numVals++; 21897c478bd9Sstevel@tonic-gate ni++; 21907c478bd9Sstevel@tonic-gate } else if (valstr != 0) { 21917c478bd9Sstevel@tonic-gate sfree(valstr); 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate } 21947c478bd9Sstevel@tonic-gate if (str == 0) { 21957c478bd9Sstevel@tonic-gate for (n = 0; n < numItems; n++) 21967c478bd9Sstevel@tonic-gate freeValue(v[n], 1); 21977c478bd9Sstevel@tonic-gate sfree(v); 21987c478bd9Sstevel@tonic-gate return (0); 21997c478bd9Sstevel@tonic-gate } 22007c478bd9Sstevel@tonic-gate } 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate if (numVals != 0) 22037c478bd9Sstevel@tonic-gate *numVals = numItems; 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate /* 22067c478bd9Sstevel@tonic-gate * Update the return string upto the point it has been matched 22077c478bd9Sstevel@tonic-gate * This string will be used by the N2L code in its next call 22087c478bd9Sstevel@tonic-gate * to this function 22097c478bd9Sstevel@tonic-gate */ 22107c478bd9Sstevel@tonic-gate if (outstr != 0) 22117c478bd9Sstevel@tonic-gate *outstr = str; 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate return (v); 22147c478bd9Sstevel@tonic-gate } 22157c478bd9Sstevel@tonic-gate 22167c478bd9Sstevel@tonic-gate /* 22177c478bd9Sstevel@tonic-gate * Perform an extract operation. For example, given the expression 22187c478bd9Sstevel@tonic-gate * (name, "%s.*") 22197c478bd9Sstevel@tonic-gate * and assuming 'name' is an item with the value "some.thing", the 22207c478bd9Sstevel@tonic-gate * value returned by the extract is "some". 22217c478bd9Sstevel@tonic-gate */ 22227c478bd9Sstevel@tonic-gate __nis_value_t * 22237c478bd9Sstevel@tonic-gate extractMappingItem(__nis_mapping_item_t *item, __nis_mapping_format_t *f, 22247c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv, int *stat) { 22257c478bd9Sstevel@tonic-gate __nis_value_t *val = getMappingItem(item, mit_any, 22267c478bd9Sstevel@tonic-gate rv, 0, stat); 22277c478bd9Sstevel@tonic-gate __nis_single_value_t *nval; 22287c478bd9Sstevel@tonic-gate int i, n, nv, nf; 22297c478bd9Sstevel@tonic-gate __nis_mapping_format_t *ftmp; 22307c478bd9Sstevel@tonic-gate 22317c478bd9Sstevel@tonic-gate if (val == 0) 22327c478bd9Sstevel@tonic-gate return (0); 22337c478bd9Sstevel@tonic-gate else if (f == 0 || rv == 0 || val->val == 0 || 22347c478bd9Sstevel@tonic-gate val->numVals <= 0 || val->type != vt_string) { 22357c478bd9Sstevel@tonic-gate freeValue(val, 1); 22367c478bd9Sstevel@tonic-gate return (0); 22377c478bd9Sstevel@tonic-gate } 22387c478bd9Sstevel@tonic-gate 22397c478bd9Sstevel@tonic-gate /* Sanity check the format; it must have one and only one mmt_item */ 22407c478bd9Sstevel@tonic-gate { 22417c478bd9Sstevel@tonic-gate int numitem; 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate for (nf = numitem = 0, ftmp = f; ftmp->type != mmt_end; 22447c478bd9Sstevel@tonic-gate ftmp++) { 22457c478bd9Sstevel@tonic-gate nf++; 22467c478bd9Sstevel@tonic-gate if (ftmp->type == mmt_item) 22477c478bd9Sstevel@tonic-gate numitem++; 22487c478bd9Sstevel@tonic-gate } 22497c478bd9Sstevel@tonic-gate /* Count the mmt_end as well */ 22507c478bd9Sstevel@tonic-gate nf++; 22517c478bd9Sstevel@tonic-gate if (numitem != 1) { 22527c478bd9Sstevel@tonic-gate freeValue(val, 1); 22537c478bd9Sstevel@tonic-gate return (0); 22547c478bd9Sstevel@tonic-gate } 22557c478bd9Sstevel@tonic-gate } 22567c478bd9Sstevel@tonic-gate 22577c478bd9Sstevel@tonic-gate nval = val->val; 22587c478bd9Sstevel@tonic-gate nv = val->numVals; 22597c478bd9Sstevel@tonic-gate val->repeat = FALSE; 22607c478bd9Sstevel@tonic-gate val->val = 0; 22617c478bd9Sstevel@tonic-gate val->numVals = 0; 22627c478bd9Sstevel@tonic-gate 22637c478bd9Sstevel@tonic-gate /* If the item has multiple values, we extract each one independently */ 22647c478bd9Sstevel@tonic-gate for (i = 0; i < nv; i++) { 22657c478bd9Sstevel@tonic-gate char *str = nval[i].value; 22667c478bd9Sstevel@tonic-gate char *newstr = 0; 22677c478bd9Sstevel@tonic-gate __nis_single_value_t *newval; 22687c478bd9Sstevel@tonic-gate 22697c478bd9Sstevel@tonic-gate if (nval[i].value == 0) 22707c478bd9Sstevel@tonic-gate continue; 22717c478bd9Sstevel@tonic-gate 22727c478bd9Sstevel@tonic-gate /* 22737c478bd9Sstevel@tonic-gate * We match the whole string, even if we find a value for 22747c478bd9Sstevel@tonic-gate * the item before exhausting all format elements. By doing 22757c478bd9Sstevel@tonic-gate * this, we ensure that the string really matches the complete 22767c478bd9Sstevel@tonic-gate * format specification. 22777c478bd9Sstevel@tonic-gate */ 22787c478bd9Sstevel@tonic-gate for (n = 0; n < nf; n++) { 22797c478bd9Sstevel@tonic-gate str = scanMappingFormat(f, n, nf, str, &newstr, 0, 0); 22807c478bd9Sstevel@tonic-gate if (str == 0) 22817c478bd9Sstevel@tonic-gate break; 22827c478bd9Sstevel@tonic-gate } 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate /* 22857c478bd9Sstevel@tonic-gate * *str should now be NUL, meaning we've reached the end of 22867c478bd9Sstevel@tonic-gate * the string (value), and it completely matched the format. 22877c478bd9Sstevel@tonic-gate * If 'str' is NULL, there was an error, and if 'newstr' is 22887c478bd9Sstevel@tonic-gate * 0, we somehow failed to obtain a value. 22897c478bd9Sstevel@tonic-gate */ 22907c478bd9Sstevel@tonic-gate if (str == 0 || *str != '\0' || newstr == 0 || 22917c478bd9Sstevel@tonic-gate (newval = realloc(val->val, 22927c478bd9Sstevel@tonic-gate (val->numVals+1) * 22937c478bd9Sstevel@tonic-gate sizeof (val->val[0]))) == 0) { 22947c478bd9Sstevel@tonic-gate freeValue(val, 1); 22957c478bd9Sstevel@tonic-gate for (n = 0; n < nv; n++) { 22967c478bd9Sstevel@tonic-gate sfree(nval[n].value); 22977c478bd9Sstevel@tonic-gate } 22987c478bd9Sstevel@tonic-gate free(nval); 22997c478bd9Sstevel@tonic-gate sfree(newstr); 23007c478bd9Sstevel@tonic-gate return (0); 23017c478bd9Sstevel@tonic-gate } 23027c478bd9Sstevel@tonic-gate 23037c478bd9Sstevel@tonic-gate val->val = newval; 23047c478bd9Sstevel@tonic-gate val->val[val->numVals].value = newstr; 23057c478bd9Sstevel@tonic-gate val->val[val->numVals].length = strlen(newstr) + 1; 23067c478bd9Sstevel@tonic-gate val->numVals++; 23077c478bd9Sstevel@tonic-gate 23087c478bd9Sstevel@tonic-gate free(nval[i].value); 23097c478bd9Sstevel@tonic-gate nval[i].value = 0; 23107c478bd9Sstevel@tonic-gate } 23117c478bd9Sstevel@tonic-gate free(nval); 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate return (val); 23147c478bd9Sstevel@tonic-gate } 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate /* 23177c478bd9Sstevel@tonic-gate * For each value in 'val', remove the last character, provided that 23187c478bd9Sstevel@tonic-gate * it matches 'elide'. 23197c478bd9Sstevel@tonic-gate */ 23207c478bd9Sstevel@tonic-gate void 23217c478bd9Sstevel@tonic-gate stringElide(__nis_value_t *val, char elide) { 23227c478bd9Sstevel@tonic-gate 23237c478bd9Sstevel@tonic-gate if (val != 0 && val->type == vt_string) { 23247c478bd9Sstevel@tonic-gate int i; 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate for (i = 0; i < val->numVals; i++) { 23277c478bd9Sstevel@tonic-gate int end = val->val[i].length; 23287c478bd9Sstevel@tonic-gate char *str = val->val[i].value; 23297c478bd9Sstevel@tonic-gate 23307c478bd9Sstevel@tonic-gate if (str == 0 || end <= 0) 23317c478bd9Sstevel@tonic-gate continue; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate /* 23347c478bd9Sstevel@tonic-gate * If the NUL was counted in the length, step back 23357c478bd9Sstevel@tonic-gate * over it. 23367c478bd9Sstevel@tonic-gate */ 23377c478bd9Sstevel@tonic-gate if (str[end-1] == '\0') 23387c478bd9Sstevel@tonic-gate end--; 23397c478bd9Sstevel@tonic-gate if (end > 0 && str[end-1] == elide) { 23407c478bd9Sstevel@tonic-gate str[end-1] = '\0'; 23417c478bd9Sstevel@tonic-gate val->val[i].length--; 23427c478bd9Sstevel@tonic-gate } 23437c478bd9Sstevel@tonic-gate } 23447c478bd9Sstevel@tonic-gate } 23457c478bd9Sstevel@tonic-gate } 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate /* 23487c478bd9Sstevel@tonic-gate * Obtain the value for the mapping sub-element 'e', given the input 23497c478bd9Sstevel@tonic-gate * rule-value 'rv'. 23507c478bd9Sstevel@tonic-gate */ 23517c478bd9Sstevel@tonic-gate __nis_value_t * 23527c478bd9Sstevel@tonic-gate getMappingSubElement(__nis_mapping_sub_element_t *e, 23537c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv, int *np_ldap_stat) { 23547c478bd9Sstevel@tonic-gate __nis_value_t *val; 23557c478bd9Sstevel@tonic-gate 23567c478bd9Sstevel@tonic-gate if (e == 0) 23577c478bd9Sstevel@tonic-gate return (0); 23587c478bd9Sstevel@tonic-gate 23597c478bd9Sstevel@tonic-gate switch (e->type) { 23607c478bd9Sstevel@tonic-gate case me_item: 23617c478bd9Sstevel@tonic-gate val = getMappingItem(&e->element.item, mit_any, rv, 0, 23627c478bd9Sstevel@tonic-gate np_ldap_stat); 23637c478bd9Sstevel@tonic-gate break; 23647c478bd9Sstevel@tonic-gate case me_print: 23657c478bd9Sstevel@tonic-gate val = getMappingFormatArray(e->element.print.fmt, rv, 23667c478bd9Sstevel@tonic-gate fa_item, 23677c478bd9Sstevel@tonic-gate e->element.print.numItems, 23687c478bd9Sstevel@tonic-gate e->element.print.item); 23697c478bd9Sstevel@tonic-gate if (e->element.print.doElide) 23707c478bd9Sstevel@tonic-gate stringElide(val, e->element.print.elide); 23717c478bd9Sstevel@tonic-gate break; 23727c478bd9Sstevel@tonic-gate case me_split: 23737c478bd9Sstevel@tonic-gate val = splitMappingItem(&e->element.split.item, 23747c478bd9Sstevel@tonic-gate e->element.split.delim, 23757c478bd9Sstevel@tonic-gate rv); 23767c478bd9Sstevel@tonic-gate break; 23777c478bd9Sstevel@tonic-gate case me_extract: 23787c478bd9Sstevel@tonic-gate val = extractMappingItem(&e->element.extract.item, 23797c478bd9Sstevel@tonic-gate e->element.extract.fmt, 23807c478bd9Sstevel@tonic-gate rv, np_ldap_stat); 23817c478bd9Sstevel@tonic-gate break; 23827c478bd9Sstevel@tonic-gate case me_match: 23837c478bd9Sstevel@tonic-gate default: 23847c478bd9Sstevel@tonic-gate val = 0; 23857c478bd9Sstevel@tonic-gate break; 23867c478bd9Sstevel@tonic-gate } 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate return (val); 23897c478bd9Sstevel@tonic-gate } 23907c478bd9Sstevel@tonic-gate 23917c478bd9Sstevel@tonic-gate /* 23927c478bd9Sstevel@tonic-gate * Obtain the value of the mapping element 'e', given the input rule- 23937c478bd9Sstevel@tonic-gate * value 'rv'. The 'native' mapping type is used when 'rv' is NULL, 23947c478bd9Sstevel@tonic-gate * and the result is a string representation of the mapping element; 23957c478bd9Sstevel@tonic-gate * in that case, items of the 'native' type are printed without their 23967c478bd9Sstevel@tonic-gate * type designation ("nis+" or "ldap"). 23977c478bd9Sstevel@tonic-gate */ 23987c478bd9Sstevel@tonic-gate __nis_value_t * 23997c478bd9Sstevel@tonic-gate getMappingElement(__nis_mapping_element_t *e, __nis_mapping_item_type_t native, 24007c478bd9Sstevel@tonic-gate __nis_rule_value_t *rv, int *stat) { 24017c478bd9Sstevel@tonic-gate __nis_value_t *val, **tv; 24027c478bd9Sstevel@tonic-gate int i, success = 0, novalue = 0; 24037c478bd9Sstevel@tonic-gate int *np_ldap_stat; 24047c478bd9Sstevel@tonic-gate char *myself = "getMappingElement"; 24057c478bd9Sstevel@tonic-gate 24067c478bd9Sstevel@tonic-gate switch (e->type) { 24077c478bd9Sstevel@tonic-gate case me_item: 24087c478bd9Sstevel@tonic-gate val = getMappingItem(&e->element.item, native, rv, 0, NULL); 24097c478bd9Sstevel@tonic-gate break; 24107c478bd9Sstevel@tonic-gate case me_print: 24117c478bd9Sstevel@tonic-gate tv = am(myself, e->element.print.numSubElements * 24127c478bd9Sstevel@tonic-gate sizeof (tv[0])); 24137c478bd9Sstevel@tonic-gate np_ldap_stat = am(myself, 24147c478bd9Sstevel@tonic-gate e->element.print.numSubElements * sizeof (int)); 24157c478bd9Sstevel@tonic-gate if ((e->element.print.numSubElements > 0) && 24167c478bd9Sstevel@tonic-gate (tv == 0 || np_ldap_stat == 0)) { 24177c478bd9Sstevel@tonic-gate val = 0; 24187c478bd9Sstevel@tonic-gate sfree(tv); 24197c478bd9Sstevel@tonic-gate sfree(np_ldap_stat); 24207c478bd9Sstevel@tonic-gate break; 24217c478bd9Sstevel@tonic-gate } 24227c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.print.numSubElements; i++) { 24237c478bd9Sstevel@tonic-gate np_ldap_stat[i] = 0; 24247c478bd9Sstevel@tonic-gate tv[i] = getMappingSubElement( 24257c478bd9Sstevel@tonic-gate &e->element.print.subElement[i], 24267c478bd9Sstevel@tonic-gate rv, &np_ldap_stat[i]); 24277c478bd9Sstevel@tonic-gate } 24287c478bd9Sstevel@tonic-gate /* 24297c478bd9Sstevel@tonic-gate * if we get NP_LDAP_NO_VALUE to any of the subelement 24307c478bd9Sstevel@tonic-gate * and we get NP_LDAP_MAP_SUCCESS to all other subelement 24317c478bd9Sstevel@tonic-gate * then we had enough nis+ column values which can 24327c478bd9Sstevel@tonic-gate * produce value for this rule, but didn't. So return 24337c478bd9Sstevel@tonic-gate * NP_LDAP_RULES_NO_VALUE to indicate to proceed to 24347c478bd9Sstevel@tonic-gate * next database id. 24357c478bd9Sstevel@tonic-gate */ 24367c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.print.numSubElements; i++) { 24377c478bd9Sstevel@tonic-gate if (np_ldap_stat[i] == NP_LDAP_MAP_SUCCESS) 24387c478bd9Sstevel@tonic-gate success++; 24397c478bd9Sstevel@tonic-gate if (np_ldap_stat[i] == NP_LDAP_NO_VALUE) 24407c478bd9Sstevel@tonic-gate novalue++; 24417c478bd9Sstevel@tonic-gate } 24427c478bd9Sstevel@tonic-gate if (stat != NULL && novalue > 0 && 24437c478bd9Sstevel@tonic-gate ((novalue+success) == 24447c478bd9Sstevel@tonic-gate e->element.print.numSubElements)) 24457c478bd9Sstevel@tonic-gate *stat = NP_LDAP_RULES_NO_VALUE; 24467c478bd9Sstevel@tonic-gate val = getMappingFormatArray(e->element.print.fmt, rv, 24477c478bd9Sstevel@tonic-gate fa_value, 24487c478bd9Sstevel@tonic-gate e->element.print.numSubElements, 24497c478bd9Sstevel@tonic-gate tv); 24507c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.print.numSubElements; i++) { 24517c478bd9Sstevel@tonic-gate freeValue(tv[i], 1); 24527c478bd9Sstevel@tonic-gate } 24537c478bd9Sstevel@tonic-gate sfree(tv); 24547c478bd9Sstevel@tonic-gate sfree(np_ldap_stat); 24557c478bd9Sstevel@tonic-gate if (e->element.print.doElide) 24567c478bd9Sstevel@tonic-gate stringElide(val, e->element.print.elide); 24577c478bd9Sstevel@tonic-gate break; 24587c478bd9Sstevel@tonic-gate case me_split: 24597c478bd9Sstevel@tonic-gate val = splitMappingItem(&e->element.split.item, 24607c478bd9Sstevel@tonic-gate e->element.split.delim, 24617c478bd9Sstevel@tonic-gate rv); 24627c478bd9Sstevel@tonic-gate break; 24637c478bd9Sstevel@tonic-gate case me_match: 24647c478bd9Sstevel@tonic-gate /* 24657c478bd9Sstevel@tonic-gate * A match doesn't produce an assignable value per se, 24667c478bd9Sstevel@tonic-gate * so we shouldn't get one here. 24677c478bd9Sstevel@tonic-gate */ 24687c478bd9Sstevel@tonic-gate val = 0; 24697c478bd9Sstevel@tonic-gate break; 24707c478bd9Sstevel@tonic-gate case me_extract: 24717c478bd9Sstevel@tonic-gate val = extractMappingItem(&e->element.extract.item, 24727c478bd9Sstevel@tonic-gate e->element.extract.fmt, 24737c478bd9Sstevel@tonic-gate rv, NULL); 24747c478bd9Sstevel@tonic-gate break; 24757c478bd9Sstevel@tonic-gate default: 24767c478bd9Sstevel@tonic-gate val = 0; 24777c478bd9Sstevel@tonic-gate break; 24787c478bd9Sstevel@tonic-gate } 24797c478bd9Sstevel@tonic-gate 24807c478bd9Sstevel@tonic-gate return (val); 24817c478bd9Sstevel@tonic-gate } 2482