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 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * 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 */ 21225376fbSJulian Pullen 227c478bd9Sstevel@tonic-gate /* 23225376fbSJulian Pullen * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 2433f5ff17SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <stdio.h> 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <libintl.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/stat.h> 337c478bd9Sstevel@tonic-gate #include <fcntl.h> 347c478bd9Sstevel@tonic-gate #include <unistd.h> 357c478bd9Sstevel@tonic-gate #include <string.h> 367c478bd9Sstevel@tonic-gate #include <strings.h> 377c478bd9Sstevel@tonic-gate #include <lber.h> 387c478bd9Sstevel@tonic-gate #include <ldap.h> 397c478bd9Sstevel@tonic-gate #include <syslog.h> 40dd1104fbSMichen Chang #include <stddef.h> 41dd1104fbSMichen Chang #include <sys/mman.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include "ns_sldap.h" 447c478bd9Sstevel@tonic-gate #include "ns_internal.h" 45e1dd0a2fSth #include "ns_connmgmt.h" 46dd1104fbSMichen Chang #include "ns_cache_door.h" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* Additional headers for addTypedEntry Conversion routines */ 497c478bd9Sstevel@tonic-gate #include <pwd.h> 50e1dd0a2fSth #include <project.h> 517c478bd9Sstevel@tonic-gate #include <shadow.h> 527c478bd9Sstevel@tonic-gate #include <grp.h> 537c478bd9Sstevel@tonic-gate #include <netinet/in.h> 547c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 557c478bd9Sstevel@tonic-gate #include <netdb.h> 567c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h> 577c478bd9Sstevel@tonic-gate #include <auth_attr.h> 587c478bd9Sstevel@tonic-gate #include <exec_attr.h> 597c478bd9Sstevel@tonic-gate #include <prof_attr.h> 607c478bd9Sstevel@tonic-gate #include <user_attr.h> 617c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 6245916cd2Sjpk #include <sys/tsol/tndb.h> 6345916cd2Sjpk #include <tsol/label.h> 647c478bd9Sstevel@tonic-gate 65dd1104fbSMichen Chang static int send_to_cachemgr(const char *, 66dd1104fbSMichen Chang ns_ldap_attr_t **, ns_ldap_error_t **); 6750b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 6850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India static int escape_str(char *, char *); 6950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * If the rdn is a mapped attr: 72*91b658d3SToomas Soome * return NS_LDAP_SUCCESS and a new_dn. 737c478bd9Sstevel@tonic-gate * If no mapped attr is found in the rdn: 74*91b658d3SToomas Soome * return NS_LDAP_SUCCESS and *new_dn == NULL 757c478bd9Sstevel@tonic-gate * For example: 767c478bd9Sstevel@tonic-gate * service = abc 777c478bd9Sstevel@tonic-gate * dn = cn=foo,dc=bar,dc=com 787c478bd9Sstevel@tonic-gate * attributeMapping: abc:cn=sn 797c478bd9Sstevel@tonic-gate * Then: 807c478bd9Sstevel@tonic-gate * new_dn = sn=foo,dc=bar,dc=com 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate static int 847c478bd9Sstevel@tonic-gate replace_mapped_attr_in_dn( 857c478bd9Sstevel@tonic-gate const char *service, const char *dn, char **new_dn) 867c478bd9Sstevel@tonic-gate { 877c478bd9Sstevel@tonic-gate char **mappedattr; 887c478bd9Sstevel@tonic-gate char **dnArray = NULL; 897c478bd9Sstevel@tonic-gate char *rservice; 907c478bd9Sstevel@tonic-gate char *cur = NULL; 917c478bd9Sstevel@tonic-gate int len = 0, orig_len = 0, mapped_len = 0; 927c478bd9Sstevel@tonic-gate int dn_len = 0; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate *new_dn = NULL; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 97da6c28aaSamw * separate dn into individual componets 987c478bd9Sstevel@tonic-gate * e.g. 997c478bd9Sstevel@tonic-gate * "automountKey=user_01" , "automountMapName_test=auto_home", ... 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate dnArray = ldap_explode_dn(dn, 0); 1027c478bd9Sstevel@tonic-gate if (!dnArray || !*dnArray) 1037c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate cur = strchr(dnArray[0], '='); 1067c478bd9Sstevel@tonic-gate if (!cur) { 1077c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1087c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate *cur = '\0'; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* we only check schema mapping for automount, not for auto_* */ 1137c478bd9Sstevel@tonic-gate if (strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT, 1147c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) 1157c478bd9Sstevel@tonic-gate rservice = "automount"; 1167c478bd9Sstevel@tonic-gate else 1177c478bd9Sstevel@tonic-gate rservice = (char *)service; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate mappedattr = __ns_ldap_getMappedAttributes(rservice, dnArray[0]); 1207c478bd9Sstevel@tonic-gate if (!mappedattr || !mappedattr[0]) { 1217c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1227c478bd9Sstevel@tonic-gate if (mappedattr) 1237c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1247c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate orig_len = strlen(dnArray[0]); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * The new length is *dn length + (difference between 1307c478bd9Sstevel@tonic-gate * orig attr and mapped attr) + 1 ; 1317c478bd9Sstevel@tonic-gate * e.g. 1327c478bd9Sstevel@tonic-gate * automountKey=aa,automountMapName=auto_home,dc=foo,dc=com 1337c478bd9Sstevel@tonic-gate * ==> 1347c478bd9Sstevel@tonic-gate * cn=aa,automountMapName=auto_home,dc=foo,dc=com 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate mapped_len = strlen(mappedattr[0]); 1377c478bd9Sstevel@tonic-gate dn_len = strlen(dn); 1387c478bd9Sstevel@tonic-gate len = dn_len - orig_len + mapped_len + 1; 1397c478bd9Sstevel@tonic-gate *new_dn = (char *)calloc(1, len); 1407c478bd9Sstevel@tonic-gate if (*new_dn == NULL) { 1417c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1427c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1437c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate (void) snprintf(*new_dn, len, "%s=%s", mappedattr[0], dn + orig_len +1); 1477c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1487c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * The following function is only used by the 1567c478bd9Sstevel@tonic-gate * "gecos" 1 to N attribute mapping code. It expects 1577c478bd9Sstevel@tonic-gate * and handle only one data/length pair. 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate static int 1607c478bd9Sstevel@tonic-gate init_bval_mod( 1617c478bd9Sstevel@tonic-gate LDAPMod *mod, 1627c478bd9Sstevel@tonic-gate int mop, 1637c478bd9Sstevel@tonic-gate char *mtype, 1647c478bd9Sstevel@tonic-gate char *mvptr, 165*91b658d3SToomas Soome int mvlen) 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate struct berval **bmodval; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* dup attribute name */ 1717c478bd9Sstevel@tonic-gate mod->mod_type = strdup(mtype); 1727c478bd9Sstevel@tonic-gate if (mod->mod_type == NULL) 1737c478bd9Sstevel@tonic-gate return (-1); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * assume single value, 1777c478bd9Sstevel@tonic-gate * since only one value/length pair passed in 1787c478bd9Sstevel@tonic-gate */ 179e1dd0a2fSth bmodval = (struct berval **)calloc(2, sizeof (struct berval *)); 1807c478bd9Sstevel@tonic-gate if (bmodval == NULL) { 1817c478bd9Sstevel@tonic-gate free(mod->mod_type); 1827c478bd9Sstevel@tonic-gate mod->mod_type = NULL; 1837c478bd9Sstevel@tonic-gate return (-1); 1847c478bd9Sstevel@tonic-gate } 185e1dd0a2fSth bmodval[0] = (struct berval *)calloc(1, sizeof (struct berval)); 1867c478bd9Sstevel@tonic-gate if (bmodval[0] == NULL) { 1877c478bd9Sstevel@tonic-gate free(mod->mod_type); 1887c478bd9Sstevel@tonic-gate mod->mod_type = NULL; 1897c478bd9Sstevel@tonic-gate free(bmodval); 1907c478bd9Sstevel@tonic-gate return (-1); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* set pointer to data */ 1947c478bd9Sstevel@tonic-gate bmodval[0]->bv_val = mvptr; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* set length */ 1977c478bd9Sstevel@tonic-gate bmodval[0]->bv_len = mvlen; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * turn on the BVALUE bit to indicate 2017c478bd9Sstevel@tonic-gate * that the length of data is supplied 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate mod->mod_op = mop | LDAP_MOD_BVALUES; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate mod->mod_bvalues = bmodval; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate return (0); 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate static void 2117c478bd9Sstevel@tonic-gate freeModList(LDAPMod **mods) 2127c478bd9Sstevel@tonic-gate { 2137c478bd9Sstevel@tonic-gate int i, j; 2147c478bd9Sstevel@tonic-gate int name_is_oc; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate if (mods == NULL) 2177c478bd9Sstevel@tonic-gate return; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate for (i = 0; mods[i]; i++) { 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* free attribute name */ 2227c478bd9Sstevel@tonic-gate name_is_oc = FALSE; 2237c478bd9Sstevel@tonic-gate if (mods[i]->mod_type) { 224e1dd0a2fSth if (strcasecmp(mods[i]->mod_type, "objectclass") == 0) 2257c478bd9Sstevel@tonic-gate name_is_oc = TRUE; 2267c478bd9Sstevel@tonic-gate free(mods[i]->mod_type); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate if (mods[i]->mod_bvalues == NULL) 2307c478bd9Sstevel@tonic-gate continue; 2317c478bd9Sstevel@tonic-gate /* 2327c478bd9Sstevel@tonic-gate * LDAP_MOD_BVALUES is only set by 2337c478bd9Sstevel@tonic-gate * the "gecos" 1 to N attribute mapping 2347c478bd9Sstevel@tonic-gate * code, and the attribute is single valued. 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate if (mods[i]->mod_op & LDAP_MOD_BVALUES) { 2377c478bd9Sstevel@tonic-gate if (mods[i]->mod_bvalues[0]) 2387c478bd9Sstevel@tonic-gate free(mods[i]->mod_bvalues[0]); 2397c478bd9Sstevel@tonic-gate } else { 2407c478bd9Sstevel@tonic-gate if (name_is_oc) { 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * only values for the "objectclass" 2437c478bd9Sstevel@tonic-gate * were dupped using strdup. 2447c478bd9Sstevel@tonic-gate * other attribute values were 2457c478bd9Sstevel@tonic-gate * not dupped, but via pointer 2467c478bd9Sstevel@tonic-gate * assignment. So here the 2477c478bd9Sstevel@tonic-gate * values for "objectclass" 2487c478bd9Sstevel@tonic-gate * is freed one by one, 2497c478bd9Sstevel@tonic-gate * but the values for other 2507c478bd9Sstevel@tonic-gate * attributes need not be freed. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate for (j = 0; mods[i]->mod_values[j]; j++) 2537c478bd9Sstevel@tonic-gate free(mods[i]->mod_values[j]); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate free(mods[i]->mod_bvalues); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* modlist */ 2617c478bd9Sstevel@tonic-gate free((char *)(mods[0])); 2627c478bd9Sstevel@tonic-gate free(mods); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate static LDAPMod ** 2667c478bd9Sstevel@tonic-gate __s_api_makeModListCount( 2677c478bd9Sstevel@tonic-gate const char *service, 2687c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 2697c478bd9Sstevel@tonic-gate const int mod_op, 2707c478bd9Sstevel@tonic-gate const int count, 2717c478bd9Sstevel@tonic-gate const int flags) 2727c478bd9Sstevel@tonic-gate { 2737c478bd9Sstevel@tonic-gate LDAPMod **mods, *modlist; 2747c478bd9Sstevel@tonic-gate char **modval; 2757c478bd9Sstevel@tonic-gate char **mapping; 2767c478bd9Sstevel@tonic-gate int i; 2777c478bd9Sstevel@tonic-gate int j; 2787c478bd9Sstevel@tonic-gate int k, rc, vlen; 2797c478bd9Sstevel@tonic-gate char *c, *comma1 = NULL, *comma2 = NULL; 2807c478bd9Sstevel@tonic-gate int schema_mapping_existed = FALSE; 2817c478bd9Sstevel@tonic-gate int auto_service = FALSE; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* 2857c478bd9Sstevel@tonic-gate * add 2 for "gecos" 1 to up to 3 attribute mapping 2867c478bd9Sstevel@tonic-gate */ 2877c478bd9Sstevel@tonic-gate mods = (LDAPMod **)calloc((count + 3), sizeof (LDAPMod *)); 2887c478bd9Sstevel@tonic-gate if (mods == NULL) { 2897c478bd9Sstevel@tonic-gate return (NULL); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * add 2 for "gecos" 1 to up to 3 attribute mapping 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate modlist = (LDAPMod *)calloc(count + 2, sizeof (LDAPMod)); 2957c478bd9Sstevel@tonic-gate if (modlist == NULL) { 2967c478bd9Sstevel@tonic-gate free(mods); 2977c478bd9Sstevel@tonic-gate return (NULL); 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate if (service != NULL && strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT, 3017c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) 3027c478bd9Sstevel@tonic-gate auto_service = TRUE; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate /* 3057c478bd9Sstevel@tonic-gate * see if schema mapping existed for the given service 3067c478bd9Sstevel@tonic-gate */ 3077c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getOrigAttribute(service, 3087c478bd9Sstevel@tonic-gate NS_HASH_SCHEMA_MAPPING_EXISTED); 3097c478bd9Sstevel@tonic-gate if (mapping) { 3107c478bd9Sstevel@tonic-gate schema_mapping_existed = TRUE; 3117c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 3127c478bd9Sstevel@tonic-gate mapping = NULL; 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate for (i = 0, k = 0; k < count && attr[k] != NULL; i++, k++) { 3167c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 3177c478bd9Sstevel@tonic-gate mods[i]->mod_op = mod_op; 3187c478bd9Sstevel@tonic-gate /* 3197c478bd9Sstevel@tonic-gate * Perform attribute mapping if necessary. 3207c478bd9Sstevel@tonic-gate */ 321e1dd0a2fSth if (schema_mapping_existed && (flags & NS_LDAP_NOMAP) == 0) { 3227c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getMappedAttributes(service, 3237c478bd9Sstevel@tonic-gate attr[k]->attrname); 3247c478bd9Sstevel@tonic-gate } else 3257c478bd9Sstevel@tonic-gate mapping = NULL; 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate if (mapping == NULL && auto_service && 3287c478bd9Sstevel@tonic-gate (flags & NS_LDAP_NOMAP) == 0) { 3297c478bd9Sstevel@tonic-gate /* 3307c478bd9Sstevel@tonic-gate * if service == auto_xxx and 3317c478bd9Sstevel@tonic-gate * no mapped attribute is found 3327c478bd9Sstevel@tonic-gate * and NS_LDAP_NOMAP is not set 3337c478bd9Sstevel@tonic-gate * then try automount's mapped attribute 3347c478bd9Sstevel@tonic-gate */ 3357c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getMappedAttributes("automount", 3367c478bd9Sstevel@tonic-gate attr[k]->attrname); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate if (mapping == NULL) { 340e1dd0a2fSth mods[i]->mod_type = strdup(attr[k]->attrname); 341e1dd0a2fSth if (mods[i]->mod_type == NULL) 342e1dd0a2fSth goto free_memory; 3437c478bd9Sstevel@tonic-gate } else { 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * 1 to N attribute mapping is only done for "gecos", 3467c478bd9Sstevel@tonic-gate * and only 1 to 3 mapping. 3477c478bd9Sstevel@tonic-gate * nine cases here: 3487c478bd9Sstevel@tonic-gate * 3497c478bd9Sstevel@tonic-gate * A. attrMap=passwd:gecos=a 3507c478bd9Sstevel@tonic-gate * 1. gecos="xx,yy,zz" -> a="xx,yy,zz" 3517c478bd9Sstevel@tonic-gate * 2. gecos="xx,yy" -> a="xx,yy" 3527c478bd9Sstevel@tonic-gate * 3. gecos="xx" -> a="xx" 3537c478bd9Sstevel@tonic-gate * 3547c478bd9Sstevel@tonic-gate * B. attrMap=passwd:gecos=a b 3557c478bd9Sstevel@tonic-gate * 4. gecos="xx,yy,zz" -> a="xx" b="yy,zz" 3567c478bd9Sstevel@tonic-gate * 5. gecos="xx,yy" -> a="xx" b="yy" 3577c478bd9Sstevel@tonic-gate * 6. gecos="xx" -> a="xx" 3587c478bd9Sstevel@tonic-gate * 3597c478bd9Sstevel@tonic-gate * C. attrMap=passwd:gecos=a b c 3607c478bd9Sstevel@tonic-gate * 7. gecos="xx,yy,zz" -> a="xx" b="yy" c="zz" 3617c478bd9Sstevel@tonic-gate * 8. gecos="xx,yy" -> a="xx" b="yy" 3627c478bd9Sstevel@tonic-gate * 9. gecos="xx" -> a="xx" 3637c478bd9Sstevel@tonic-gate * 3647c478bd9Sstevel@tonic-gate * This can be grouped as: 3657c478bd9Sstevel@tonic-gate * 3667c478bd9Sstevel@tonic-gate * c1 cases: 1,2,3,6,9 3677c478bd9Sstevel@tonic-gate * if ((attrMap=passwd:gecos=a) || 3687c478bd9Sstevel@tonic-gate * (no "," in gecos value)) 3697c478bd9Sstevel@tonic-gate * same as other no-mapping attributes, 3707c478bd9Sstevel@tonic-gate * no special processing needed 3717c478bd9Sstevel@tonic-gate * else 3727c478bd9Sstevel@tonic-gate * 3737c478bd9Sstevel@tonic-gate * c2 cases: 4,5,8 3747c478bd9Sstevel@tonic-gate * if ((attrMap=passwd:gecos=a b) || 3757c478bd9Sstevel@tonic-gate * (only one "," in gecos value)) 3767c478bd9Sstevel@tonic-gate * a=xx b=yy[,...] 3777c478bd9Sstevel@tonic-gate * else 3787c478bd9Sstevel@tonic-gate * 3797c478bd9Sstevel@tonic-gate * c3 case: 7 3807c478bd9Sstevel@tonic-gate * a=xx b=yy c=... 3817c478bd9Sstevel@tonic-gate * 3827c478bd9Sstevel@tonic-gate * notes: in case c2 and c3, ... could still contain "," 3837c478bd9Sstevel@tonic-gate */ 384e1dd0a2fSth if (strcasecmp(service, "passwd") == 0 && 385e1dd0a2fSth strcasecmp(attr[k]->attrname, "gecos") == 0 && 386e1dd0a2fSth mapping[1] && attr[k]->attrvalue[0] && 387e1dd0a2fSth (comma1 = strchr(attr[k]->attrvalue[0], 388e1dd0a2fSth COMMATOK)) != NULL) { 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* is there a second comma? */ 3917c478bd9Sstevel@tonic-gate if (*(comma1 + 1) != '\0') 3927c478bd9Sstevel@tonic-gate comma2 = strchr(comma1 + 1, COMMATOK); 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate /* 3957c478bd9Sstevel@tonic-gate * Process case c2 or c3. 3967c478bd9Sstevel@tonic-gate * case c2: mapped to two attributes or just 3977c478bd9Sstevel@tonic-gate * one comma 3987c478bd9Sstevel@tonic-gate */ 399e1dd0a2fSth if (mapping[2] == NULL || comma2 == NULL) { 4007c478bd9Sstevel@tonic-gate /* case c2 */ 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate /* 4037c478bd9Sstevel@tonic-gate * int mod structure for the first attribute 4047c478bd9Sstevel@tonic-gate */ 4057c478bd9Sstevel@tonic-gate vlen = comma1 - attr[k]->attrvalue[0]; 4067c478bd9Sstevel@tonic-gate c = attr[k]->attrvalue[0]; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4097c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 410e1dd0a2fSth mapping[0], c, vlen); 4117c478bd9Sstevel@tonic-gate if (rc != 0) 4127c478bd9Sstevel@tonic-gate goto free_memory; 4137c478bd9Sstevel@tonic-gate } else { 4147c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4157c478bd9Sstevel@tonic-gate mods[i] = NULL; 4167c478bd9Sstevel@tonic-gate i--; 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate /* 4217c478bd9Sstevel@tonic-gate * init mod structure for the 2nd attribute 4227c478bd9Sstevel@tonic-gate */ 4237c478bd9Sstevel@tonic-gate if (*(comma1 + 1) == '\0') { 4247c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 4257c478bd9Sstevel@tonic-gate mapping = NULL; 4267c478bd9Sstevel@tonic-gate continue; 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate i++; 4307c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* 4337c478bd9Sstevel@tonic-gate * get pointer to data. 4347c478bd9Sstevel@tonic-gate * Skip leading spaces. 4357c478bd9Sstevel@tonic-gate */ 436e1dd0a2fSth for (c = comma1 + 1; *c == SPACETOK; c++) { 437e1dd0a2fSth /* empty */ 438e1dd0a2fSth } 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* get data length */ 4417c478bd9Sstevel@tonic-gate vlen = strlen(attr[k]->attrvalue[0]) - 442e1dd0a2fSth (c - attr[k]->attrvalue[0]); 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4457c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 446e1dd0a2fSth mapping[1], c, vlen); 4477c478bd9Sstevel@tonic-gate if (rc != 0) 4487c478bd9Sstevel@tonic-gate goto free_memory; 4497c478bd9Sstevel@tonic-gate } else { 4507c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4517c478bd9Sstevel@tonic-gate mods[i] = NULL; 4527c478bd9Sstevel@tonic-gate i--; 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate /* done with the mapping array */ 4567c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 4577c478bd9Sstevel@tonic-gate mapping = NULL; 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate continue; 4607c478bd9Sstevel@tonic-gate } else { 4617c478bd9Sstevel@tonic-gate /* case c3 */ 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * int mod structure for the first attribute 4657c478bd9Sstevel@tonic-gate */ 4667c478bd9Sstevel@tonic-gate vlen = comma1 - attr[k]->attrvalue[0]; 4677c478bd9Sstevel@tonic-gate c = attr[k]->attrvalue[0]; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4707c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 471e1dd0a2fSth mapping[0], c, vlen); 4727c478bd9Sstevel@tonic-gate if (rc != 0) 4737c478bd9Sstevel@tonic-gate goto free_memory; 4747c478bd9Sstevel@tonic-gate } else { 4757c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4767c478bd9Sstevel@tonic-gate mods[i] = NULL; 4777c478bd9Sstevel@tonic-gate i--; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate /* 4817c478bd9Sstevel@tonic-gate * init mod structure for the 2nd attribute 4827c478bd9Sstevel@tonic-gate */ 4837c478bd9Sstevel@tonic-gate i++; 4847c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* 4877c478bd9Sstevel@tonic-gate * get pointer to data. 4887c478bd9Sstevel@tonic-gate * Skip leading spaces. 4897c478bd9Sstevel@tonic-gate */ 490e1dd0a2fSth for (c = comma1 + 1; *c == SPACETOK; c++) { 491e1dd0a2fSth /* empty */ 492e1dd0a2fSth }; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* get data length */ 4957c478bd9Sstevel@tonic-gate vlen = comma2 - c; 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4987c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 499e1dd0a2fSth mapping[1], c, vlen); 5007c478bd9Sstevel@tonic-gate if (rc != 0) 5017c478bd9Sstevel@tonic-gate goto free_memory; 5027c478bd9Sstevel@tonic-gate } else { 5037c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 5047c478bd9Sstevel@tonic-gate mods[i] = NULL; 5057c478bd9Sstevel@tonic-gate i--; 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* 5097c478bd9Sstevel@tonic-gate * init mod structure for the 3rd attribute 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate if (*(comma2 + 1) == '\0') { 5127c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 5137c478bd9Sstevel@tonic-gate mapping = NULL; 5147c478bd9Sstevel@tonic-gate continue; 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate i++; 5187c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 5197c478bd9Sstevel@tonic-gate /* 5207c478bd9Sstevel@tonic-gate * get pointer to data. 5217c478bd9Sstevel@tonic-gate * Skip leading spaces. 5227c478bd9Sstevel@tonic-gate */ 523e1dd0a2fSth for (c = comma2 + 1; *c == SPACETOK; c++) { 524e1dd0a2fSth /* empty */ 525e1dd0a2fSth } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* get data length */ 5287c478bd9Sstevel@tonic-gate vlen = strlen(attr[k]->attrvalue[0]) - 529e1dd0a2fSth (c - attr[k]->attrvalue[0]); 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 5327c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 533e1dd0a2fSth mapping[2], c, vlen); 5347c478bd9Sstevel@tonic-gate if (rc != 0) 5357c478bd9Sstevel@tonic-gate goto free_memory; 5367c478bd9Sstevel@tonic-gate } else { 5377c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 5387c478bd9Sstevel@tonic-gate mods[i] = NULL; 5397c478bd9Sstevel@tonic-gate i--; 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate /* done with the mapping array */ 5437c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 5447c478bd9Sstevel@tonic-gate mapping = NULL; 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate continue; 547e1dd0a2fSth } 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate 550e1dd0a2fSth /* case c1 */ 551e1dd0a2fSth mods[i]->mod_type = strdup(mapping[0]); 552e1dd0a2fSth if (mods[i]->mod_type == NULL) { 5537c478bd9Sstevel@tonic-gate goto free_memory; 554e1dd0a2fSth } 555e1dd0a2fSth __s_api_free2dArray(mapping); 556e1dd0a2fSth mapping = NULL; 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate modval = (char **)calloc(attr[k]->value_count+1, 560e1dd0a2fSth sizeof (char *)); 5617c478bd9Sstevel@tonic-gate if (modval == NULL) 5627c478bd9Sstevel@tonic-gate goto free_memory; 5637c478bd9Sstevel@tonic-gate /* 5647c478bd9Sstevel@tonic-gate * Perform objectclass mapping. 5657c478bd9Sstevel@tonic-gate * Note that the values for the "objectclass" attribute 5667c478bd9Sstevel@tonic-gate * will be dupped using strdup. Values for other 5677c478bd9Sstevel@tonic-gate * attributes will be referenced via pointer 5687c478bd9Sstevel@tonic-gate * assignments. 5697c478bd9Sstevel@tonic-gate */ 5707c478bd9Sstevel@tonic-gate if (strcasecmp(mods[i]->mod_type, "objectclass") == 0) { 5717c478bd9Sstevel@tonic-gate for (j = 0; j < attr[k]->value_count; j++) { 5727c478bd9Sstevel@tonic-gate if (schema_mapping_existed && 573e1dd0a2fSth (flags & NS_LDAP_NOMAP) == 0) 5747c478bd9Sstevel@tonic-gate mapping = 575e1dd0a2fSth __ns_ldap_getMappedObjectClass( 576e1dd0a2fSth service, attr[k]->attrvalue[j]); 5777c478bd9Sstevel@tonic-gate else 5787c478bd9Sstevel@tonic-gate mapping = NULL; 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate if (mapping == NULL && auto_service && 581e1dd0a2fSth (flags & NS_LDAP_NOMAP) == 0) 5827c478bd9Sstevel@tonic-gate /* 5837c478bd9Sstevel@tonic-gate * if service == auto_xxx and 5847c478bd9Sstevel@tonic-gate * no mapped objectclass is found 5857c478bd9Sstevel@tonic-gate * then try automount 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate mapping = 588e1dd0a2fSth __ns_ldap_getMappedObjectClass( 589e1dd0a2fSth "automount", attr[k]->attrvalue[j]); 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate if (mapping && mapping[0]) { 5927c478bd9Sstevel@tonic-gate /* assume single mapping */ 5937c478bd9Sstevel@tonic-gate modval[j] = strdup(mapping[0]); 5947c478bd9Sstevel@tonic-gate } else { 5957c478bd9Sstevel@tonic-gate modval[j] = strdup(attr[k]-> 596e1dd0a2fSth attrvalue[j]); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate if (modval[j] == NULL) 5997c478bd9Sstevel@tonic-gate goto free_memory; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate } else { 6027c478bd9Sstevel@tonic-gate for (j = 0; j < attr[k]->value_count; j++) { 6037c478bd9Sstevel@tonic-gate /* ASSIGN NOT COPY */ 6047c478bd9Sstevel@tonic-gate modval[j] = attr[k]->attrvalue[j]; 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate mods[i]->mod_values = modval; 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate return (mods); 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate free_memory: 6137c478bd9Sstevel@tonic-gate freeModList(mods); 6147c478bd9Sstevel@tonic-gate if (mapping) 6157c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate return (NULL); 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate static LDAPMod ** 6227c478bd9Sstevel@tonic-gate __s_api_makeModList( 6237c478bd9Sstevel@tonic-gate const char *service, 6247c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 6257c478bd9Sstevel@tonic-gate const int mod_op, 6267c478bd9Sstevel@tonic-gate const int flags) 6277c478bd9Sstevel@tonic-gate { 6287c478bd9Sstevel@tonic-gate ns_ldap_attr_t **aptr = (ns_ldap_attr_t **)attr; 6297c478bd9Sstevel@tonic-gate int count = 0; 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate if (aptr == NULL) 6327c478bd9Sstevel@tonic-gate return (NULL); 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate /* count number of attributes */ 6357c478bd9Sstevel@tonic-gate while (*aptr++) 6367c478bd9Sstevel@tonic-gate count++; 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate return (__s_api_makeModListCount(service, attr, mod_op, count, flags)); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate static void 6427c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(ns_ldap_entry_t **entry, char **rdn) 6437c478bd9Sstevel@tonic-gate { 6447c478bd9Sstevel@tonic-gate if (*entry != NULL) { 6457c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(*entry); 6467c478bd9Sstevel@tonic-gate *entry = NULL; 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate if (*rdn != NULL) { 6497c478bd9Sstevel@tonic-gate free(*rdn); 6507c478bd9Sstevel@tonic-gate *rdn = NULL; 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate /* 6557c478bd9Sstevel@tonic-gate * This state machine performs one or more LDAP add/delete/modify 6567c478bd9Sstevel@tonic-gate * operations to configured LDAP servers. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate static int 6597c478bd9Sstevel@tonic-gate write_state_machine( 660*91b658d3SToomas Soome int ldap_op, 661*91b658d3SToomas Soome char *dn, 6627c478bd9Sstevel@tonic-gate LDAPMod **mods, 6637c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 664*91b658d3SToomas Soome const int flags, 6657c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 6667c478bd9Sstevel@tonic-gate { 6677c478bd9Sstevel@tonic-gate ConnectionID connectionId = -1; 6687c478bd9Sstevel@tonic-gate Connection *conp = NULL; 669*91b658d3SToomas Soome LDAPMessage *res; 6707c478bd9Sstevel@tonic-gate char *target_dn = NULL; 6717c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 6727c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS; 6737c478bd9Sstevel@tonic-gate int return_rc = NS_LDAP_SUCCESS; 6747c478bd9Sstevel@tonic-gate int followRef = FALSE; 6757c478bd9Sstevel@tonic-gate int target_dn_allocated = FALSE; 6767c478bd9Sstevel@tonic-gate int len; 6777c478bd9Sstevel@tonic-gate int msgid; 6787c478bd9Sstevel@tonic-gate int Errno; 67920945219SMichen Chang boolean_t from_get_lderrno = B_FALSE; 6807c478bd9Sstevel@tonic-gate int always = 1; 6817c478bd9Sstevel@tonic-gate char *err, *errmsg = NULL; 6827d575517Ssdussud /* referrals returned by the LDAP operation */ 6837c478bd9Sstevel@tonic-gate char **referrals = NULL; 6847d575517Ssdussud /* 6857d575517Ssdussud * list of referrals used by the state machine, built from 6867d575517Ssdussud * the referrals variable above 6877d575517Ssdussud */ 6887d575517Ssdussud ns_referral_info_t *ref_list = NULL; 6897d575517Ssdussud /* current referral */ 6907d575517Ssdussud ns_referral_info_t *current_ref = NULL; 6917c478bd9Sstevel@tonic-gate ns_write_state_t state = W_INIT, new_state, err_state = W_INIT; 6927c478bd9Sstevel@tonic-gate int do_not_fail_if_new_pwd_reqd = 0; 6937c478bd9Sstevel@tonic-gate ns_ldap_passwd_status_t pwd_status = NS_PASSWD_GOOD; 6947c478bd9Sstevel@tonic-gate int passwd_mgmt = 0; 6957d575517Ssdussud int i = 0; 6967d575517Ssdussud int ldap_error; 69747789246Svv int nopasswd_acct_mgmt = 0; 698e1dd0a2fSth ns_conn_user_t *conn_user = NULL; 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate while (always) { 7017c478bd9Sstevel@tonic-gate switch (state) { 7027c478bd9Sstevel@tonic-gate case W_EXIT: 703e1dd0a2fSth /* return the MT connection and free the conn user */ 704e1dd0a2fSth if (conn_user != NULL) { 705e1dd0a2fSth if (conn_user->use_mt_conn == B_TRUE) { 706e1dd0a2fSth if (conn_user->ns_error != NULL) { 707e1dd0a2fSth *errorp = conn_user->ns_error; 708e1dd0a2fSth conn_user->ns_error = NULL; 709e1dd0a2fSth return_rc = conn_user->ns_rc; 710e1dd0a2fSth } 711e1dd0a2fSth if (conn_user->conn_mt != NULL) 712e1dd0a2fSth __s_api_conn_mt_return( 713e1dd0a2fSth conn_user); 714e1dd0a2fSth } 715e1dd0a2fSth __s_api_conn_user_free(conn_user); 716e1dd0a2fSth } 717e1dd0a2fSth 7187c478bd9Sstevel@tonic-gate if (connectionId > -1) 719cb5caa98Sdjl DropConnection(connectionId, NS_LDAP_NEW_CONN); 7207d575517Ssdussud if (ref_list) 7217d575517Ssdussud __s_api_deleteRefInfo(ref_list); 7227c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) 7237c478bd9Sstevel@tonic-gate free(target_dn); 7247c478bd9Sstevel@tonic-gate return (return_rc); 7257c478bd9Sstevel@tonic-gate case W_INIT: 7267c478bd9Sstevel@tonic-gate /* see if need to follow referrals */ 7277c478bd9Sstevel@tonic-gate rc = __s_api_toFollowReferrals(flags, 728e1dd0a2fSth &followRef, errorp); 7297c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7307c478bd9Sstevel@tonic-gate return_rc = rc; 7317c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7327c478bd9Sstevel@tonic-gate break; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate len = strlen(dn); 7357c478bd9Sstevel@tonic-gate if (dn[len-1] == COMMATOK) 7367c478bd9Sstevel@tonic-gate rc = __s_api_append_default_basedn( 737e1dd0a2fSth dn, &target_dn, &target_dn_allocated, 738e1dd0a2fSth errorp); 7397c478bd9Sstevel@tonic-gate else 7407c478bd9Sstevel@tonic-gate target_dn = dn; 7417c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7427c478bd9Sstevel@tonic-gate return_rc = rc; 7437c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate else 7467c478bd9Sstevel@tonic-gate new_state = GET_CONNECTION; 7477c478bd9Sstevel@tonic-gate break; 7487c478bd9Sstevel@tonic-gate case GET_CONNECTION: 749e1dd0a2fSth /* identify self as a write user */ 750e1dd0a2fSth conn_user = __s_api_conn_user_init(NS_CONN_USER_WRITE, 751e1dd0a2fSth NULL, B_FALSE); 7527c478bd9Sstevel@tonic-gate rc = __s_api_getConnection(NULL, 753e1dd0a2fSth flags, cred, &connectionId, &conp, errorp, 754e1dd0a2fSth do_not_fail_if_new_pwd_reqd, nopasswd_acct_mgmt, 755e1dd0a2fSth conn_user); 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* 7587c478bd9Sstevel@tonic-gate * If password control attached 7597c478bd9Sstevel@tonic-gate * in *errorp, 7607c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 7617c478bd9Sstevel@tonic-gate * free the error structure (we do not need 7627c478bd9Sstevel@tonic-gate * the password management info). 7637c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 7647c478bd9Sstevel@tonic-gate */ 7657c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 766e1dd0a2fSth (void) __ns_ldap_freeError(errorp); 7677c478bd9Sstevel@tonic-gate *errorp = NULL; 7687c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7727c478bd9Sstevel@tonic-gate return_rc = rc; 7737c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7747c478bd9Sstevel@tonic-gate break; 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate if (followRef) 7777c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_ASYNC; 7787c478bd9Sstevel@tonic-gate else 7797c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 7807c478bd9Sstevel@tonic-gate break; 7817c478bd9Sstevel@tonic-gate case SELECT_OPERATION_SYNC: 7827c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7837c478bd9Sstevel@tonic-gate new_state = DO_ADD_SYNC; 7847c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7857c478bd9Sstevel@tonic-gate new_state = DO_DELETE_SYNC; 7867c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7877c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_SYNC; 7887c478bd9Sstevel@tonic-gate break; 7897c478bd9Sstevel@tonic-gate case SELECT_OPERATION_ASYNC: 7907c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7917c478bd9Sstevel@tonic-gate new_state = DO_ADD_ASYNC; 7927c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7937c478bd9Sstevel@tonic-gate new_state = DO_DELETE_ASYNC; 7947c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7957c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_ASYNC; 7967c478bd9Sstevel@tonic-gate break; 7977c478bd9Sstevel@tonic-gate case DO_ADD_SYNC: 7987c478bd9Sstevel@tonic-gate rc = ldap_add_ext_s(conp->ld, target_dn, 799e1dd0a2fSth mods, NULL, NULL); 8007c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 8017c478bd9Sstevel@tonic-gate break; 8027c478bd9Sstevel@tonic-gate case DO_DELETE_SYNC: 8037c478bd9Sstevel@tonic-gate rc = ldap_delete_ext_s(conp->ld, target_dn, 804e1dd0a2fSth NULL, NULL); 8057c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 8067c478bd9Sstevel@tonic-gate break; 8077c478bd9Sstevel@tonic-gate case DO_MODIFY_SYNC: 8087c478bd9Sstevel@tonic-gate rc = ldap_modify_ext_s(conp->ld, target_dn, 809e1dd0a2fSth mods, NULL, NULL); 8107c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 8117c478bd9Sstevel@tonic-gate break; 8127c478bd9Sstevel@tonic-gate case DO_ADD_ASYNC: 8137c478bd9Sstevel@tonic-gate rc = ldap_add_ext(conp->ld, target_dn, 814e1dd0a2fSth mods, NULL, NULL, &msgid); 8157c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 8167c478bd9Sstevel@tonic-gate break; 8177c478bd9Sstevel@tonic-gate case DO_DELETE_ASYNC: 8187c478bd9Sstevel@tonic-gate rc = ldap_delete_ext(conp->ld, target_dn, 819e1dd0a2fSth NULL, NULL, &msgid); 8207c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 8217c478bd9Sstevel@tonic-gate break; 8227c478bd9Sstevel@tonic-gate case DO_MODIFY_ASYNC: 8237c478bd9Sstevel@tonic-gate rc = ldap_modify_ext(conp->ld, target_dn, 824e1dd0a2fSth mods, NULL, NULL, &msgid); 8257c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 8267c478bd9Sstevel@tonic-gate break; 8277c478bd9Sstevel@tonic-gate case GET_RESULT_SYNC: 8287c478bd9Sstevel@tonic-gate if (rc != LDAP_SUCCESS) { 8297c478bd9Sstevel@tonic-gate Errno = rc; 8307c478bd9Sstevel@tonic-gate (void) ldap_get_lderrno(conp->ld, 831e1dd0a2fSth NULL, &errmsg); 83220945219SMichen Chang 8337c478bd9Sstevel@tonic-gate /* 83420945219SMichen Chang * No need to deal with the error message if 83520945219SMichen Chang * it's an empty string. 8367c478bd9Sstevel@tonic-gate */ 83720945219SMichen Chang if (errmsg != NULL && *errmsg == '\0') 8387c478bd9Sstevel@tonic-gate errmsg = NULL; 83920945219SMichen Chang 84020945219SMichen Chang if (errmsg != NULL) { 84120945219SMichen Chang /* 84220945219SMichen Chang * ldap_get_lderrno does not expect 84320945219SMichen Chang * errmsg to be freed after use, while 84420945219SMichen Chang * ldap_parse_result below does, so set 84520945219SMichen Chang * a flag to indicate source. 84620945219SMichen Chang */ 84720945219SMichen Chang from_get_lderrno = B_TRUE; 8487c478bd9Sstevel@tonic-gate } 84920945219SMichen Chang 8507c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8517c478bd9Sstevel@tonic-gate } else { 8527c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 8537c478bd9Sstevel@tonic-gate new_state = W_EXIT; 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate break; 8567c478bd9Sstevel@tonic-gate case GET_RESULT_ASYNC: 8577c478bd9Sstevel@tonic-gate rc = ldap_result(conp->ld, msgid, 1, 858e1dd0a2fSth (struct timeval *)NULL, &res); 8597c478bd9Sstevel@tonic-gate /* if no server response, set Errno */ 8607c478bd9Sstevel@tonic-gate if (rc == -1) { 8617c478bd9Sstevel@tonic-gate (void) ldap_get_option(conp->ld, 8627c478bd9Sstevel@tonic-gate LDAP_OPT_ERROR_NUMBER, &Errno); 8637c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8647c478bd9Sstevel@tonic-gate break; 8657c478bd9Sstevel@tonic-gate } 866e1dd0a2fSth if (rc == LDAP_RES_ADD || rc == LDAP_RES_MODIFY || 867e1dd0a2fSth rc == LDAP_RES_DELETE) { 8687c478bd9Sstevel@tonic-gate new_state = PARSE_RESULT; 8697c478bd9Sstevel@tonic-gate break; 8707c478bd9Sstevel@tonic-gate } else { 8717c478bd9Sstevel@tonic-gate return_rc = rc; 8727c478bd9Sstevel@tonic-gate new_state = W_ERROR; 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate break; 8757c478bd9Sstevel@tonic-gate case PARSE_RESULT: 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * need Errno, referrals, error msg, 8787c478bd9Sstevel@tonic-gate * and the last "1" is to free 8797c478bd9Sstevel@tonic-gate * the result (res) 8807c478bd9Sstevel@tonic-gate */ 881e1dd0a2fSth rc = ldap_parse_result(conp->ld, res, &Errno, 882e1dd0a2fSth NULL, &errmsg, &referrals, NULL, 1); 8837c478bd9Sstevel@tonic-gate /* 8847c478bd9Sstevel@tonic-gate * free errmsg if it is an empty string 8857c478bd9Sstevel@tonic-gate */ 8867c478bd9Sstevel@tonic-gate if (errmsg && *errmsg == '\0') { 8877c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8887c478bd9Sstevel@tonic-gate errmsg = NULL; 8897c478bd9Sstevel@tonic-gate } 8907d575517Ssdussud /* 8917d575517Ssdussud * If we received referral data, process 8927d575517Ssdussud * it if: 8937d575517Ssdussud * - we are configured to follow referrals 8947d575517Ssdussud * - and not already in referral mode (to keep 8957d575517Ssdussud * consistency with search_state_machine() 8967d575517Ssdussud * which follows 1 level of referrals only; 8977d575517Ssdussud * see proc_result_referrals() and 8987d575517Ssdussud * proc_search_references(). 8997d575517Ssdussud */ 9007d575517Ssdussud if (Errno == LDAP_REFERRAL && followRef && !ref_list) { 9017d575517Ssdussud for (i = 0; referrals[i] != NULL; i++) { 9027d575517Ssdussud /* add to referral list */ 9037d575517Ssdussud rc = __s_api_addRefInfo(&ref_list, 904e1dd0a2fSth referrals[i], NULL, NULL, NULL, 905e1dd0a2fSth conp->ld); 9067d575517Ssdussud if (rc != NS_LDAP_SUCCESS) { 9077d575517Ssdussud __s_api_deleteRefInfo(ref_list); 9087d575517Ssdussud ref_list = NULL; 9097d575517Ssdussud break; 9107d575517Ssdussud } 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate ldap_value_free(referrals); 9137d575517Ssdussud if (ref_list == NULL) { 9147c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_MEMORY) 9157c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 9167d575517Ssdussud return_rc = rc; 9177c478bd9Sstevel@tonic-gate new_state = W_ERROR; 9187d575517Ssdussud } else { 9197c478bd9Sstevel@tonic-gate new_state = GET_REFERRAL_CONNECTION; 9207d575517Ssdussud current_ref = ref_list; 9217d575517Ssdussud } 9227c478bd9Sstevel@tonic-gate if (errmsg) { 9237c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 9247c478bd9Sstevel@tonic-gate errmsg = NULL; 9257c478bd9Sstevel@tonic-gate } 9267c478bd9Sstevel@tonic-gate break; 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate if (Errno != LDAP_SUCCESS) { 9297c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 9307c478bd9Sstevel@tonic-gate } else { 9317c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 9327c478bd9Sstevel@tonic-gate new_state = W_EXIT; 9337c478bd9Sstevel@tonic-gate } 9347c478bd9Sstevel@tonic-gate break; 9357c478bd9Sstevel@tonic-gate case GET_REFERRAL_CONNECTION: 9367d575517Ssdussud /* 9377d575517Ssdussud * since we are starting over, 9387d575517Ssdussud * discard the old error info 9397d575517Ssdussud */ 9407d575517Ssdussud return_rc = NS_LDAP_SUCCESS; 9417d575517Ssdussud if (*errorp) 9427d575517Ssdussud (void) __ns_ldap_freeError(errorp); 9437c478bd9Sstevel@tonic-gate if (connectionId > -1) 944cb5caa98Sdjl DropConnection(connectionId, NS_LDAP_NEW_CONN); 945e1dd0a2fSth 946e1dd0a2fSth /* set it up to use a referral connection */ 947e1dd0a2fSth if (conn_user != NULL) { 948e1dd0a2fSth /* 949e1dd0a2fSth * If an MT connection is being used, 950e1dd0a2fSth * return it to the pool. 951e1dd0a2fSth */ 952e1dd0a2fSth if (conn_user->conn_mt != NULL) 953e1dd0a2fSth __s_api_conn_mt_return(conn_user); 954e1dd0a2fSth 955e1dd0a2fSth conn_user->referral = B_TRUE; 956e1dd0a2fSth } 9577d575517Ssdussud rc = __s_api_getConnection(current_ref->refHost, 958e1dd0a2fSth 0, cred, &connectionId, &conp, errorp, 959e1dd0a2fSth do_not_fail_if_new_pwd_reqd, 960e1dd0a2fSth nopasswd_acct_mgmt, conn_user); 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* 9637c478bd9Sstevel@tonic-gate * If password control attached 9647c478bd9Sstevel@tonic-gate * in errorp, 9657c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 9667c478bd9Sstevel@tonic-gate * free the error structure (we do not need 9677c478bd9Sstevel@tonic-gate * the password management info). 9687c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 9697c478bd9Sstevel@tonic-gate */ 9707c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 971e1dd0a2fSth (void) __ns_ldap_freeError(errorp); 9727c478bd9Sstevel@tonic-gate *errorp = NULL; 9737c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 9777c478bd9Sstevel@tonic-gate return_rc = rc; 9787d575517Ssdussud /* 9797d575517Ssdussud * If current referral is not 9807d575517Ssdussud * available for some reason, 9817d575517Ssdussud * try next referral in the list. 9827d575517Ssdussud * Get LDAP error code from errorp. 9837d575517Ssdussud */ 9847d575517Ssdussud if (*errorp != NULL) { 985e1dd0a2fSth ns_write_state_t get_ref = 986e1dd0a2fSth GET_REFERRAL_CONNECTION; 987e1dd0a2fSth 9887d575517Ssdussud ldap_error = (*errorp)->status; 9897d575517Ssdussud if (ldap_error == LDAP_BUSY || 9907d575517Ssdussud ldap_error == LDAP_UNAVAILABLE || 9917d575517Ssdussud ldap_error == 992e1dd0a2fSth LDAP_UNWILLING_TO_PERFORM || 9937d575517Ssdussud ldap_error == LDAP_CONNECT_ERROR || 9947d575517Ssdussud ldap_error == LDAP_SERVER_DOWN) { 9957d575517Ssdussud current_ref = current_ref->next; 9967d575517Ssdussud if (current_ref == NULL) { 997e1dd0a2fSth /* no more referral to follow */ 998e1dd0a2fSth new_state = W_ERROR; 999e1dd0a2fSth } else 1000e1dd0a2fSth new_state = get_ref; 10017d575517Ssdussud /* 10027d575517Ssdussud * free errorp before going to 10037d575517Ssdussud * next referral 10047d575517Ssdussud */ 10057d575517Ssdussud (void) __ns_ldap_freeError( 1006e1dd0a2fSth errorp); 10077d575517Ssdussud *errorp = NULL; 10087d575517Ssdussud break; 10097d575517Ssdussud } 10107d575517Ssdussud /* 10117d575517Ssdussud * free errorp before going to W_ERROR 10127d575517Ssdussud */ 10137d575517Ssdussud (void) __ns_ldap_freeError(errorp); 10147d575517Ssdussud *errorp = NULL; 10157d575517Ssdussud } 10167d575517Ssdussud /* else, exit */ 10177d575517Ssdussud __s_api_deleteRefInfo(ref_list); 10187d575517Ssdussud ref_list = NULL; 10197c478bd9Sstevel@tonic-gate new_state = W_ERROR; 1020e1dd0a2fSth if (conn_user != NULL) 1021e1dd0a2fSth conn_user->referral = B_FALSE; 10227c478bd9Sstevel@tonic-gate break; 10237c478bd9Sstevel@tonic-gate } 10247c478bd9Sstevel@tonic-gate /* target DN may changed due to referrals */ 10257d575517Ssdussud if (current_ref->refDN) { 10267c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) { 10277c478bd9Sstevel@tonic-gate free(target_dn); 10287c478bd9Sstevel@tonic-gate target_dn = NULL; 10297c478bd9Sstevel@tonic-gate target_dn_allocated = FALSE; 10307c478bd9Sstevel@tonic-gate } 10317d575517Ssdussud target_dn = current_ref->refDN; 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 10347c478bd9Sstevel@tonic-gate break; 10357c478bd9Sstevel@tonic-gate case W_LDAP_ERROR: 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * map error code and error message 10387c478bd9Sstevel@tonic-gate * to password status if necessary. 10397c478bd9Sstevel@tonic-gate * This is to see if password updates 10407c478bd9Sstevel@tonic-gate * failed due to password policy or 10417c478bd9Sstevel@tonic-gate * password syntax checking. 10427c478bd9Sstevel@tonic-gate */ 10437c478bd9Sstevel@tonic-gate if (errmsg) { 10447c478bd9Sstevel@tonic-gate /* 10457c478bd9Sstevel@tonic-gate * check if server supports 10467c478bd9Sstevel@tonic-gate * password management 10477c478bd9Sstevel@tonic-gate */ 10487c478bd9Sstevel@tonic-gate passwd_mgmt = 1049e1dd0a2fSth __s_api_contain_passwd_control_oid( 1050e1dd0a2fSth conp->controls); 10517c478bd9Sstevel@tonic-gate if (passwd_mgmt) 10527c478bd9Sstevel@tonic-gate pwd_status = 1053e1dd0a2fSth __s_api_set_passwd_status( 1054e1dd0a2fSth Errno, errmsg); 105520945219SMichen Chang /* 105620945219SMichen Chang * free only if not returned by ldap_get_lderrno 105720945219SMichen Chang */ 105820945219SMichen Chang if (!from_get_lderrno) 105920945219SMichen Chang ldap_memfree(errmsg); 10607c478bd9Sstevel@tonic-gate errmsg = NULL; 106120945219SMichen Chang from_get_lderrno = B_FALSE; 10627c478bd9Sstevel@tonic-gate } 10637c478bd9Sstevel@tonic-gate 1064dd1104fbSMichen Chang (void) snprintf(errstr, sizeof (errstr), 1065dd1104fbSMichen Chang "%s", ldap_err2string(Errno)); 10667c478bd9Sstevel@tonic-gate err = strdup(errstr); 10677c478bd9Sstevel@tonic-gate if (pwd_status != NS_PASSWD_GOOD) { 10687c478bd9Sstevel@tonic-gate MKERROR_PWD_MGMT(*errorp, Errno, err, 1069e1dd0a2fSth pwd_status, 0, NULL); 10707c478bd9Sstevel@tonic-gate } else { 10717c478bd9Sstevel@tonic-gate MKERROR(LOG_INFO, *errorp, Errno, err, NULL); 10727c478bd9Sstevel@tonic-gate } 1073e1dd0a2fSth if (conn_user != NULL && 1074e1dd0a2fSth (Errno == LDAP_SERVER_DOWN || 1075e1dd0a2fSth Errno == LDAP_CONNECT_ERROR)) { 1076e1dd0a2fSth __s_api_conn_mt_close(conn_user, Errno, errorp); 1077e1dd0a2fSth } 10787c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_INTERNAL; 10797c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10807c478bd9Sstevel@tonic-gate break; 10817c478bd9Sstevel@tonic-gate case W_ERROR: 10827c478bd9Sstevel@tonic-gate default: 10837c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 1084e1dd0a2fSth gettext("Internal write State machine exit" 1085e1dd0a2fSth " (state = %d, rc = %d)."), 1086e1dd0a2fSth err_state, return_rc); 10877c478bd9Sstevel@tonic-gate err = strdup(errstr); 10887c478bd9Sstevel@tonic-gate MKERROR(LOG_WARNING, *errorp, return_rc, err, NULL); 10897c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10907c478bd9Sstevel@tonic-gate break; 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate if (new_state == W_ERROR) 10947c478bd9Sstevel@tonic-gate err_state = state; 1095e1dd0a2fSth 1096e1dd0a2fSth if (conn_user != NULL && conn_user->bad_mt_conn == B_TRUE) { 1097e1dd0a2fSth __s_api_conn_mt_close(conn_user, 0, NULL); 1098e1dd0a2fSth new_state = W_EXIT; 1099e1dd0a2fSth } 1100e1dd0a2fSth 11017c478bd9Sstevel@tonic-gate state = new_state; 11027c478bd9Sstevel@tonic-gate } 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate /* 11057c478bd9Sstevel@tonic-gate * should never be here, the next line is to eliminating 11067c478bd9Sstevel@tonic-gate * lint message 11077c478bd9Sstevel@tonic-gate */ 11087c478bd9Sstevel@tonic-gate return (NS_LDAP_INTERNAL); 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11137c478bd9Sstevel@tonic-gate int 11147c478bd9Sstevel@tonic-gate __ns_ldap_addAttr( 11157c478bd9Sstevel@tonic-gate const char *service, 11167c478bd9Sstevel@tonic-gate const char *dn, 11177c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 11187c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11197c478bd9Sstevel@tonic-gate const int flags, 11207c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11217c478bd9Sstevel@tonic-gate { 11227c478bd9Sstevel@tonic-gate LDAPMod **mods; 11237c478bd9Sstevel@tonic-gate int rc = 0; 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate #ifdef DEBUG 11267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addAttr START\n"); 11277c478bd9Sstevel@tonic-gate #endif 11287c478bd9Sstevel@tonic-gate *errorp = NULL; 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate /* Sanity check */ 11317c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11327c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11337c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_ADD, flags); 11367c478bd9Sstevel@tonic-gate if (mods == NULL) { 11377c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11387c478bd9Sstevel@tonic-gate } 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11417c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11427c478bd9Sstevel@tonic-gate freeModList(mods); 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate return (rc); 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11497c478bd9Sstevel@tonic-gate int 11507c478bd9Sstevel@tonic-gate __ns_ldap_delAttr( 11517c478bd9Sstevel@tonic-gate const char *service, 11527c478bd9Sstevel@tonic-gate const char *dn, 11537c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 11547c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11557c478bd9Sstevel@tonic-gate const int flags, 11567c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11577c478bd9Sstevel@tonic-gate { 11587c478bd9Sstevel@tonic-gate LDAPMod **mods; 11597c478bd9Sstevel@tonic-gate int rc = 0; 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate #ifdef DEBUG 11627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delAttr START\n"); 11637c478bd9Sstevel@tonic-gate #endif 11647c478bd9Sstevel@tonic-gate *errorp = NULL; 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* Sanity check */ 11677c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11687c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11697c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_DELETE, flags); 11727c478bd9Sstevel@tonic-gate if (mods == NULL) { 11737c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11747c478bd9Sstevel@tonic-gate } 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11777c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11787c478bd9Sstevel@tonic-gate 11797c478bd9Sstevel@tonic-gate freeModList(mods); 11807c478bd9Sstevel@tonic-gate return (rc); 11817c478bd9Sstevel@tonic-gate } 11827c478bd9Sstevel@tonic-gate 1183dd1104fbSMichen Chang /* Retrieve the admin bind password from the configuration, if allowed. */ 1184dd1104fbSMichen Chang static int 1185dd1104fbSMichen Chang get_admin_passwd(ns_cred_t *cred, ns_ldap_error_t **errorp) 1186dd1104fbSMichen Chang { 1187dd1104fbSMichen Chang void **paramVal = NULL; 1188dd1104fbSMichen Chang int rc, ldaprc; 1189dd1104fbSMichen Chang char *modparamVal = NULL; 1190dd1104fbSMichen Chang 1191dd1104fbSMichen Chang /* 1192dd1104fbSMichen Chang * For GSSAPI/Kerberos, host credential is used, no need to get 1193dd1104fbSMichen Chang * admin bind password 1194dd1104fbSMichen Chang */ 1195dd1104fbSMichen Chang if (cred->auth.saslmech == NS_LDAP_SASL_GSSAPI) 1196dd1104fbSMichen Chang return (NS_LDAP_SUCCESS); 1197dd1104fbSMichen Chang 1198dd1104fbSMichen Chang /* 1199dd1104fbSMichen Chang * Retrieve admin bind password. 1200dd1104fbSMichen Chang * The admin bind password is available 1201dd1104fbSMichen Chang * only in the ldap_cachemgr process as 1202dd1104fbSMichen Chang * they are not exposed outside of that 1203dd1104fbSMichen Chang * process. 1204dd1104fbSMichen Chang */ 1205dd1104fbSMichen Chang paramVal = NULL; 1206dd1104fbSMichen Chang if ((ldaprc = __ns_ldap_getParam(NS_LDAP_ADMIN_BINDPASSWD_P, 1207dd1104fbSMichen Chang ¶mVal, errorp)) != NS_LDAP_SUCCESS) 1208dd1104fbSMichen Chang return (ldaprc); 1209dd1104fbSMichen Chang if (paramVal == NULL || *paramVal == NULL) { 1210dd1104fbSMichen Chang rc = NS_LDAP_CONFIG; 1211dd1104fbSMichen Chang *errorp = __s_api_make_error(NS_CONFIG_NODEFAULT, 1212dd1104fbSMichen Chang gettext("Admin bind password not configured")); 1213dd1104fbSMichen Chang if (*errorp == NULL) 1214dd1104fbSMichen Chang rc = NS_LDAP_MEMORY; 1215dd1104fbSMichen Chang return (rc); 1216dd1104fbSMichen Chang } 1217dd1104fbSMichen Chang modparamVal = dvalue((char *)*paramVal); 1218dd1104fbSMichen Chang (void) memset(*paramVal, 0, strlen((char *)*paramVal)); 1219dd1104fbSMichen Chang (void) __ns_ldap_freeParam(¶mVal); 1220dd1104fbSMichen Chang if (modparamVal == NULL || *((char *)modparamVal) == '\0') { 1221dd1104fbSMichen Chang if (modparamVal != NULL) 1222dd1104fbSMichen Chang free(modparamVal); 1223dd1104fbSMichen Chang rc = NS_LDAP_CONFIG; 1224dd1104fbSMichen Chang *errorp = __s_api_make_error(NS_CONFIG_SYNTAX, 1225dd1104fbSMichen Chang gettext("bind password not valid")); 1226dd1104fbSMichen Chang if (*errorp == NULL) 1227dd1104fbSMichen Chang rc = NS_LDAP_MEMORY; 1228dd1104fbSMichen Chang return (rc); 1229dd1104fbSMichen Chang } 1230dd1104fbSMichen Chang 1231dd1104fbSMichen Chang cred->cred.unix_cred.passwd = modparamVal; 1232dd1104fbSMichen Chang return (NS_LDAP_SUCCESS); 1233dd1104fbSMichen Chang } 1234dd1104fbSMichen Chang 1235dd1104fbSMichen Chang boolean_t 1236225376fbSJulian Pullen __ns_ldap_is_shadow_update_enabled(void) 1237225376fbSJulian Pullen { 1238225376fbSJulian Pullen int **enable_shadow = NULL; 1239225376fbSJulian Pullen ns_ldap_error_t *errorp = NULL; 1240dd1104fbSMichen Chang 1241dd1104fbSMichen Chang if (__ns_ldap_getParam(NS_LDAP_ENABLE_SHADOW_UPDATE_P, 1242225376fbSJulian Pullen (void ***)&enable_shadow, &errorp) != NS_LDAP_SUCCESS) { 1243225376fbSJulian Pullen if (errorp) 1244225376fbSJulian Pullen (void) __ns_ldap_freeError(&errorp); 1245dd1104fbSMichen Chang return (B_FALSE); 1246dd1104fbSMichen Chang } 1247dd1104fbSMichen Chang if ((enable_shadow != NULL && *enable_shadow != NULL) && 1248dd1104fbSMichen Chang (*enable_shadow[0] == NS_LDAP_ENABLE_SHADOW_UPDATE_TRUE)) { 1249dd1104fbSMichen Chang (void) __ns_ldap_freeParam((void ***)&enable_shadow); 1250dd1104fbSMichen Chang return (B_TRUE); 1251dd1104fbSMichen Chang } 1252dd1104fbSMichen Chang if (enable_shadow != NULL) 1253dd1104fbSMichen Chang (void) __ns_ldap_freeParam((void ***)&enable_shadow); 1254dd1104fbSMichen Chang return (B_FALSE); 1255dd1104fbSMichen Chang } 1256dd1104fbSMichen Chang 1257dd1104fbSMichen Chang /* 1258dd1104fbSMichen Chang * __ns_ldap_repAttr modifies ldap attributes of the 'dn' entry stored 1259dd1104fbSMichen Chang * on the LDAP server. 'service' indicates the type of database entries 1260dd1104fbSMichen Chang * to modify. When the Native LDAP client is configured with 'shadow update 1261dd1104fbSMichen Chang * enabled', Shadowshadow(4) entries can only be modified by privileged users. 1262dd1104fbSMichen Chang * Such users use the NS_LDAP_UPDATE_SHADOW flag to indicate the call is 1263dd1104fbSMichen Chang * for such a shadow(4) update, which would be forwarded to ldap_cachemgr 1264dd1104fbSMichen Chang * for performing the LDAP modify operation. ldap_cachemgr would call 1265dd1104fbSMichen Chang * this function again and use the special service NS_ADMIN_SHADOW_UPDATE 1266dd1104fbSMichen Chang * to identify itself, so that admin credential would be obtained and 1267dd1104fbSMichen Chang * the actual LDAP modify operation be done. 1268dd1104fbSMichen Chang */ 12697c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12707c478bd9Sstevel@tonic-gate int 12717c478bd9Sstevel@tonic-gate __ns_ldap_repAttr( 12727c478bd9Sstevel@tonic-gate const char *service, 12737c478bd9Sstevel@tonic-gate const char *dn, 12747c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 12757c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 12767c478bd9Sstevel@tonic-gate const int flags, 12777c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 12787c478bd9Sstevel@tonic-gate { 12797c478bd9Sstevel@tonic-gate LDAPMod **mods; 12807c478bd9Sstevel@tonic-gate int rc = 0; 1281dd1104fbSMichen Chang boolean_t priv; 1282dd1104fbSMichen Chang boolean_t shadow_update_enabled = B_FALSE; 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate #ifdef DEBUG 12857c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_repAttr START\n"); 12867c478bd9Sstevel@tonic-gate #endif 12877c478bd9Sstevel@tonic-gate *errorp = NULL; 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate /* Sanity check */ 1290dd1104fbSMichen Chang if (attr == NULL || *attr == NULL || dn == NULL) 1291dd1104fbSMichen Chang return (NS_LDAP_INVALID_PARAM); 1292dd1104fbSMichen Chang 1293dd1104fbSMichen Chang /* Privileged shadow modify? */ 1294dd1104fbSMichen Chang if ((flags & NS_LDAP_UPDATE_SHADOW) != 0 && 1295dd1104fbSMichen Chang strcmp(service, "shadow") == 0) { 1296dd1104fbSMichen Chang 1297dd1104fbSMichen Chang /* Shadow update enabled ? If not, error out */ 1298dd1104fbSMichen Chang shadow_update_enabled = __ns_ldap_is_shadow_update_enabled(); 1299dd1104fbSMichen Chang if (!shadow_update_enabled) { 1300dd1104fbSMichen Chang *errorp = __s_api_make_error(NS_CONFIG_NOTALLOW, 1301dd1104fbSMichen Chang gettext("Shadow Update is not enabled")); 1302dd1104fbSMichen Chang return (NS_LDAP_CONFIG); 1303dd1104fbSMichen Chang } 1304dd1104fbSMichen Chang 1305dd1104fbSMichen Chang /* privileged shadow modify requires euid 0 or all zone privs */ 1306dd1104fbSMichen Chang priv = (geteuid() == 0); 1307dd1104fbSMichen Chang if (!priv) { 1308dd1104fbSMichen Chang priv_set_t *ps = priv_allocset(); /* caller */ 1309dd1104fbSMichen Chang priv_set_t *zs; /* zone */ 1310dd1104fbSMichen Chang 1311dd1104fbSMichen Chang (void) getppriv(PRIV_EFFECTIVE, ps); 1312dd1104fbSMichen Chang zs = priv_str_to_set("zone", ",", NULL); 1313dd1104fbSMichen Chang priv = priv_isequalset(ps, zs); 1314dd1104fbSMichen Chang priv_freeset(ps); 1315dd1104fbSMichen Chang priv_freeset(zs); 1316dd1104fbSMichen Chang } 1317dd1104fbSMichen Chang if (!priv) 1318dd1104fbSMichen Chang return (NS_LDAP_OP_FAILED); 1319dd1104fbSMichen Chang 1320dd1104fbSMichen Chang rc = send_to_cachemgr(dn, (ns_ldap_attr_t **)attr, errorp); 1321dd1104fbSMichen Chang return (rc); 1322dd1104fbSMichen Chang } 1323dd1104fbSMichen Chang 1324dd1104fbSMichen Chang if (cred == NULL) 13257c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 1326dd1104fbSMichen Chang 1327dd1104fbSMichen Chang /* 1328dd1104fbSMichen Chang * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be 1329dd1104fbSMichen Chang * ldap_cachemgr. We need to get the admin cred to do work. 1330dd1104fbSMichen Chang * If the caller is not ldap_cachemgr, but use the service 1331dd1104fbSMichen Chang * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail, 1332dd1104fbSMichen Chang * as the admin cred is not available to the caller. 1333dd1104fbSMichen Chang */ 1334dd1104fbSMichen Chang if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) { 1335dd1104fbSMichen Chang if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) != 1336dd1104fbSMichen Chang NS_LDAP_SUCCESS) 1337dd1104fbSMichen Chang return (rc); 1338dd1104fbSMichen Chang } 1339dd1104fbSMichen Chang 13407c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_REPLACE, flags); 1341dd1104fbSMichen Chang if (mods == NULL) 13427c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13437c478bd9Sstevel@tonic-gate 13447c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 13457c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate freeModList(mods); 13487c478bd9Sstevel@tonic-gate return (rc); 13497c478bd9Sstevel@tonic-gate } 13507c478bd9Sstevel@tonic-gate 13517c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 13527c478bd9Sstevel@tonic-gate int 13537c478bd9Sstevel@tonic-gate __ns_ldap_addEntry( 13547c478bd9Sstevel@tonic-gate const char *service, 13557c478bd9Sstevel@tonic-gate const char *dn, 13567c478bd9Sstevel@tonic-gate const ns_ldap_entry_t *entry, 13577c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 13587c478bd9Sstevel@tonic-gate const int flags, 13597c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 13607c478bd9Sstevel@tonic-gate { 13617c478bd9Sstevel@tonic-gate char *new_dn = NULL; 13627c478bd9Sstevel@tonic-gate LDAPMod **mods = NULL; 13637c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr; 13647c478bd9Sstevel@tonic-gate int nAttr = 0; 13657c478bd9Sstevel@tonic-gate int rc = 0; 13667c478bd9Sstevel@tonic-gate 13677c478bd9Sstevel@tonic-gate #ifdef DEBUG 13687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addEntry START\n"); 13697c478bd9Sstevel@tonic-gate #endif 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate if ((entry == NULL) || (dn == NULL) || (cred == NULL)) 13727c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 13737c478bd9Sstevel@tonic-gate *errorp = NULL; 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate /* Construct array of LDAPMod representing attributes of new entry. */ 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate nAttr = entry->attr_count; 13787c478bd9Sstevel@tonic-gate attr = (const ns_ldap_attr_t * const *)(entry->attr_pair); 13797c478bd9Sstevel@tonic-gate mods = __s_api_makeModListCount(service, attr, LDAP_MOD_ADD, 13807c478bd9Sstevel@tonic-gate nAttr, flags); 13817c478bd9Sstevel@tonic-gate if (mods == NULL) { 13827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13837c478bd9Sstevel@tonic-gate } 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate rc = replace_mapped_attr_in_dn(service, dn, &new_dn); 13867c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13877c478bd9Sstevel@tonic-gate freeModList(mods); 13887c478bd9Sstevel@tonic-gate return (rc); 13897c478bd9Sstevel@tonic-gate } 13907c478bd9Sstevel@tonic-gate 13917c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_ADD, 13927c478bd9Sstevel@tonic-gate new_dn ? new_dn : (char *)dn, mods, cred, flags, errorp); 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate if (new_dn) 13957c478bd9Sstevel@tonic-gate free(new_dn); 13967c478bd9Sstevel@tonic-gate freeModList(mods); 13977c478bd9Sstevel@tonic-gate return (rc); 13987c478bd9Sstevel@tonic-gate } 13997c478bd9Sstevel@tonic-gate 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 14027c478bd9Sstevel@tonic-gate int 14037c478bd9Sstevel@tonic-gate __ns_ldap_delEntry( 14047c478bd9Sstevel@tonic-gate const char *service, 14057c478bd9Sstevel@tonic-gate const char *dn, 14067c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 14077c478bd9Sstevel@tonic-gate const int flags, 14087c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 14097c478bd9Sstevel@tonic-gate { 14107c478bd9Sstevel@tonic-gate int rc; 14117c478bd9Sstevel@tonic-gate 14127c478bd9Sstevel@tonic-gate #ifdef DEBUG 14137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delEntry START\n"); 14147c478bd9Sstevel@tonic-gate #endif 14157c478bd9Sstevel@tonic-gate if ((dn == NULL) || (cred == NULL)) 14167c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 14177c478bd9Sstevel@tonic-gate 14187c478bd9Sstevel@tonic-gate *errorp = NULL; 14197c478bd9Sstevel@tonic-gate 14207c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_DELETE, 14217c478bd9Sstevel@tonic-gate (char *)dn, NULL, cred, flags, errorp); 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate return (rc); 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate 14267c478bd9Sstevel@tonic-gate /* 14277c478bd9Sstevel@tonic-gate * Add Typed Entry Helper routines 14287c478bd9Sstevel@tonic-gate */ 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate /* 14317c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion routines 14327c478bd9Sstevel@tonic-gate */ 14337c478bd9Sstevel@tonic-gate 14347c478bd9Sstevel@tonic-gate static int 14357c478bd9Sstevel@tonic-gate __s_add_attr(ns_ldap_entry_t *e, char *attrname, char *value) 14367c478bd9Sstevel@tonic-gate { 14377c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 14387c478bd9Sstevel@tonic-gate char *v; 14397c478bd9Sstevel@tonic-gate 14407c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 14417c478bd9Sstevel@tonic-gate if (a == NULL) 14427c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14437c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 14447c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 14457c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14467c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(1, sizeof (char **)); 14477c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 14487c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14497c478bd9Sstevel@tonic-gate a->value_count = 1; 14507c478bd9Sstevel@tonic-gate a->attrvalue[0] = NULL; 14517c478bd9Sstevel@tonic-gate v = strdup(value); 14527c478bd9Sstevel@tonic-gate if (v == NULL) 14537c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14547c478bd9Sstevel@tonic-gate a->attrvalue[0] = v; 14557c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 14567c478bd9Sstevel@tonic-gate e->attr_count++; 14577c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 14587c478bd9Sstevel@tonic-gate } 14597c478bd9Sstevel@tonic-gate 14607c478bd9Sstevel@tonic-gate static int 14617c478bd9Sstevel@tonic-gate __s_add_attrlist(ns_ldap_entry_t *e, char *attrname, char **argv) 14627c478bd9Sstevel@tonic-gate { 14637c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 14647c478bd9Sstevel@tonic-gate char *v; 14657c478bd9Sstevel@tonic-gate char **av; 14667c478bd9Sstevel@tonic-gate int i, j; 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 14697c478bd9Sstevel@tonic-gate if (a == NULL) 14707c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14717c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 14727c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 14737c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate for (i = 0, av = argv; *av != NULL; av++, i++) 14767c478bd9Sstevel@tonic-gate ; 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(i, sizeof (char *)); 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 14817c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14827c478bd9Sstevel@tonic-gate 14837c478bd9Sstevel@tonic-gate a->value_count = i; 14847c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 14857c478bd9Sstevel@tonic-gate v = strdup(argv[j]); 14867c478bd9Sstevel@tonic-gate if (v == NULL) 14877c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14887c478bd9Sstevel@tonic-gate a->attrvalue[j] = v; 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 14917c478bd9Sstevel@tonic-gate e->attr_count++; 14927c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 14937c478bd9Sstevel@tonic-gate } 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate static ns_ldap_entry_t * 14967c478bd9Sstevel@tonic-gate __s_mk_entry(char **objclass, int max_attr) 14977c478bd9Sstevel@tonic-gate { 14987c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 14997c478bd9Sstevel@tonic-gate e = (ns_ldap_entry_t *)calloc(1, sizeof (ns_ldap_entry_t)); 15007c478bd9Sstevel@tonic-gate if (e == NULL) 15017c478bd9Sstevel@tonic-gate return (NULL); 15027c478bd9Sstevel@tonic-gate /* allocate attributes, +1 for objectclass, +1 for NULL terminator */ 15037c478bd9Sstevel@tonic-gate e->attr_pair = (ns_ldap_attr_t **) 15047c478bd9Sstevel@tonic-gate calloc(max_attr + 2, sizeof (ns_ldap_attr_t *)); 15057c478bd9Sstevel@tonic-gate if (e->attr_pair == NULL) { 15067c478bd9Sstevel@tonic-gate free(e); 15077c478bd9Sstevel@tonic-gate return (NULL); 15087c478bd9Sstevel@tonic-gate } 15097c478bd9Sstevel@tonic-gate e->attr_count = 0; 15107c478bd9Sstevel@tonic-gate if (__s_add_attrlist(e, "objectClass", objclass) != NS_LDAP_SUCCESS) { 15117c478bd9Sstevel@tonic-gate free(e->attr_pair); 15127c478bd9Sstevel@tonic-gate free(e); 15137c478bd9Sstevel@tonic-gate return (NULL); 15147c478bd9Sstevel@tonic-gate } 15157c478bd9Sstevel@tonic-gate return (e); 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate /* 15207c478bd9Sstevel@tonic-gate * Conversion: passwd 15217c478bd9Sstevel@tonic-gate * Input format: struct passwd 15227c478bd9Sstevel@tonic-gate * Exported objectclass: posixAccount 15237c478bd9Sstevel@tonic-gate */ 15247c478bd9Sstevel@tonic-gate static int 15257c478bd9Sstevel@tonic-gate __s_cvt_passwd(const void *data, char **rdn, 1526*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 15277c478bd9Sstevel@tonic-gate { 15287c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 15297c478bd9Sstevel@tonic-gate int rc; 15307c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 15317c478bd9Sstevel@tonic-gate /* routine specific */ 15327c478bd9Sstevel@tonic-gate struct passwd *ptr; 15337c478bd9Sstevel@tonic-gate int max_attr = 9; 15347c478bd9Sstevel@tonic-gate char ibuf[10]; 15357c478bd9Sstevel@tonic-gate static char *oclist[] = { 15367c478bd9Sstevel@tonic-gate "posixAccount", 15377c478bd9Sstevel@tonic-gate "shadowAccount", 15387c478bd9Sstevel@tonic-gate "account", 15397c478bd9Sstevel@tonic-gate "top", 15407c478bd9Sstevel@tonic-gate NULL 15417c478bd9Sstevel@tonic-gate }; 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 15447c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 15457c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 15467c478bd9Sstevel@tonic-gate if (e == NULL) 15477c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 15487c478bd9Sstevel@tonic-gate 15497c478bd9Sstevel@tonic-gate /* Convert the structure */ 15507c478bd9Sstevel@tonic-gate ptr = (struct passwd *)data; 15517c478bd9Sstevel@tonic-gate 1552f48205beScasper if (ptr->pw_name == NULL || ptr->pw_uid > MAXUID || 1553f48205beScasper ptr->pw_gid > MAXUID || ptr->pw_dir == NULL) { 15547c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 15557c478bd9Sstevel@tonic-gate *entry = NULL; 15567c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate 15597c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 15607c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->pw_name); 15617c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 15627c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 15637c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 15647c478bd9Sstevel@tonic-gate *entry = NULL; 15657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 15697c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->pw_name); 15707c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15717c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15727c478bd9Sstevel@tonic-gate return (rc); 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->pw_name); 15757c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15767c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15777c478bd9Sstevel@tonic-gate return (rc); 15787c478bd9Sstevel@tonic-gate } 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate if (ptr->pw_passwd != NULL && 1581e1dd0a2fSth ptr->pw_passwd[0] != '\0') { 15827c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->pw_passwd); 15837c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15847c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15857c478bd9Sstevel@tonic-gate return (rc); 15867c478bd9Sstevel@tonic-gate } 15877c478bd9Sstevel@tonic-gate } 15887c478bd9Sstevel@tonic-gate 1589f48205beScasper (void) sprintf(ibuf, "%u", ptr->pw_uid); 15907c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uidNumber", ibuf); 15917c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15927c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15937c478bd9Sstevel@tonic-gate return (rc); 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate 1596f48205beScasper (void) sprintf(ibuf, "%u", ptr->pw_gid); 15977c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 15987c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15997c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16007c478bd9Sstevel@tonic-gate return (rc); 16017c478bd9Sstevel@tonic-gate } 16027c478bd9Sstevel@tonic-gate if (ptr->pw_gecos != NULL && 1603e1dd0a2fSth ptr->pw_gecos[0] != '\0') { 16047c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gecos", ptr->pw_gecos); 16057c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16077c478bd9Sstevel@tonic-gate return (rc); 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "homeDirectory", ptr->pw_dir); 16127c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16147c478bd9Sstevel@tonic-gate return (rc); 16157c478bd9Sstevel@tonic-gate } 16167c478bd9Sstevel@tonic-gate if (ptr->pw_shell != NULL && 1617e1dd0a2fSth ptr->pw_shell[0] != '\0') { 16187c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "loginShell", ptr->pw_shell); 16197c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16207c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16217c478bd9Sstevel@tonic-gate return (rc); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate } 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 16267c478bd9Sstevel@tonic-gate } 16277c478bd9Sstevel@tonic-gate 162850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India /* 162950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * escape_str function escapes special characters in str and 163050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * copies to escstr string. 163150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * 163250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * return 0 for successful 163350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * 1 for fail 163450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India */ 163550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India static int escape_str(char *escstr, char *str) 163650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India { 163750b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India int index = 0; 163850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 163950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India while ((*str != '\0') && (index < (RDNSIZE - 1))) { 164050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India if (*str == '+' || *str == ';' || *str == '>' || 164150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *str == '<' || *str == ',' || *str == '"' || 164250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *str == '\\' || *str == '=' || 164350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India (*str == '#' && index == 0)) { 164450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *escstr++ = '\\'; 164550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *escstr++ = *str++; 164650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India index += 2; 164750b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } else { 164850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *escstr++ = *str++; 164950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India index++; 165050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 165150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 165250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 165350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India if (*str == '\0') { 165450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *escstr = '\0'; 165550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India return (0); 165650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } else { 165750b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India return (1); 165850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 165950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 166050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 1661e1dd0a2fSth /* 1662e1dd0a2fSth * Conversion: project 1663e1dd0a2fSth * Input format: struct project 1664e1dd0a2fSth * Exported objectclass: SolarisProject 1665e1dd0a2fSth */ 1666e1dd0a2fSth static int 1667e1dd0a2fSth __s_cvt_project(const void *data, char **rdn, 1668*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 1669e1dd0a2fSth { 1670e1dd0a2fSth ns_ldap_entry_t *e; 1671e1dd0a2fSth int rc; 1672e1dd0a2fSth char trdn[RDNSIZE]; 1673e1dd0a2fSth 1674e1dd0a2fSth /* routine specific */ 1675e1dd0a2fSth struct project *ptr; 1676e1dd0a2fSth int max_attr = 9; 1677e1dd0a2fSth char ibuf[11]; 1678*91b658d3SToomas Soome static char *oclist[] = { 1679e1dd0a2fSth "SolarisProject", 1680e1dd0a2fSth "top", 1681e1dd0a2fSth NULL 1682e1dd0a2fSth }; 1683e1dd0a2fSth 1684e1dd0a2fSth if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 1685e1dd0a2fSth return (NS_LDAP_OP_FAILED); 1686e1dd0a2fSth 1687e1dd0a2fSth *entry = e = __s_mk_entry(oclist, max_attr); 1688e1dd0a2fSth if (e == NULL) 1689e1dd0a2fSth return (NS_LDAP_MEMORY); 1690e1dd0a2fSth 1691e1dd0a2fSth /* Convert the structure */ 1692e1dd0a2fSth ptr = (struct project *)data; 1693e1dd0a2fSth 1694e1dd0a2fSth if (ptr->pj_name == NULL || ptr->pj_projid > MAXUID) { 1695e1dd0a2fSth __ns_ldap_freeEntry(e); 1696e1dd0a2fSth *entry = NULL; 1697e1dd0a2fSth return (NS_LDAP_INVALID_PARAM); 1698e1dd0a2fSth } 1699e1dd0a2fSth 1700e1dd0a2fSth /* Create an appropriate rdn */ 1701e1dd0a2fSth (void) snprintf(trdn, RDNSIZE, "SolarisProjectName=%s", ptr->pj_name); 1702e1dd0a2fSth *rdn = strdup(trdn); 1703e1dd0a2fSth if (*rdn == NULL) { 1704e1dd0a2fSth __ns_ldap_freeEntry(e); 1705e1dd0a2fSth *entry = NULL; 1706e1dd0a2fSth return (NS_LDAP_MEMORY); 1707e1dd0a2fSth } 1708e1dd0a2fSth 1709e1dd0a2fSth /* Error check the data and add the attributes */ 1710e1dd0a2fSth 1711e1dd0a2fSth /* Project name */ 1712e1dd0a2fSth rc = __s_add_attr(e, "SolarisProjectName", ptr->pj_name); 1713e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1714e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1715e1dd0a2fSth return (rc); 1716e1dd0a2fSth } 1717e1dd0a2fSth 1718e1dd0a2fSth /* 1719e1dd0a2fSth * Project ID: 1720e1dd0a2fSth * ibuf is 11 chars big, which should be enough for string 1721e1dd0a2fSth * representation of 32bit number + nul-car 1722e1dd0a2fSth */ 1723e1dd0a2fSth if (snprintf(ibuf, sizeof (ibuf), "%u", ptr->pj_projid) < 0) { 1724e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1725e1dd0a2fSth return (NS_LDAP_INVALID_PARAM); 1726e1dd0a2fSth } 1727e1dd0a2fSth rc = __s_add_attr(e, "SolarisProjectID", ibuf); 1728e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1729e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1730e1dd0a2fSth return (rc); 1731e1dd0a2fSth } 1732e1dd0a2fSth 1733e1dd0a2fSth /* Comment/Description */ 1734e1dd0a2fSth if (ptr->pj_comment != NULL && ptr->pj_comment[0] != '\0') { 1735e1dd0a2fSth rc = __s_add_attr(e, "description", ptr->pj_comment); 1736e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1737e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1738e1dd0a2fSth return (rc); 1739e1dd0a2fSth } 1740e1dd0a2fSth } 1741e1dd0a2fSth 1742e1dd0a2fSth /* Attributes */ 1743e1dd0a2fSth if (ptr->pj_attr != NULL && ptr->pj_attr[0] != '\0') { 1744e1dd0a2fSth rc = __s_add_attr(e, "SolarisProjectAttr", ptr->pj_attr); 1745e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1746e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1747e1dd0a2fSth return (rc); 1748e1dd0a2fSth } 1749e1dd0a2fSth } 1750e1dd0a2fSth 1751e1dd0a2fSth /* Users */ 1752e1dd0a2fSth if (ptr->pj_users != NULL) { 1753e1dd0a2fSth rc = __s_add_attrlist(e, "memberUid", ptr->pj_users); 1754e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1755e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1756e1dd0a2fSth return (rc); 1757e1dd0a2fSth } 1758e1dd0a2fSth } 1759e1dd0a2fSth 1760e1dd0a2fSth /* Groups */ 1761e1dd0a2fSth if (ptr->pj_groups != NULL) { 1762e1dd0a2fSth rc = __s_add_attrlist(e, "memberGid", ptr->pj_groups); 1763e1dd0a2fSth if (rc != NS_LDAP_SUCCESS) { 1764e1dd0a2fSth __s_cvt_freeEntryRdn(entry, rdn); 1765e1dd0a2fSth return (rc); 1766e1dd0a2fSth } 1767e1dd0a2fSth } 1768e1dd0a2fSth 1769e1dd0a2fSth 1770e1dd0a2fSth 1771e1dd0a2fSth return (NS_LDAP_SUCCESS); 1772e1dd0a2fSth } 17737c478bd9Sstevel@tonic-gate /* 17747c478bd9Sstevel@tonic-gate * Conversion: shadow 17757c478bd9Sstevel@tonic-gate * Input format: struct shadow 17767c478bd9Sstevel@tonic-gate * Exported objectclass: shadowAccount 17777c478bd9Sstevel@tonic-gate */ 17787c478bd9Sstevel@tonic-gate static int 17797c478bd9Sstevel@tonic-gate __s_cvt_shadow(const void *data, char **rdn, 1780*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 17817c478bd9Sstevel@tonic-gate { 17827c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 17837c478bd9Sstevel@tonic-gate int rc; 17847c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 17857c478bd9Sstevel@tonic-gate /* routine specific */ 17867c478bd9Sstevel@tonic-gate struct spwd *ptr; 17877c478bd9Sstevel@tonic-gate int max_attr = 10; 17887c478bd9Sstevel@tonic-gate char ibuf[10]; 17897c478bd9Sstevel@tonic-gate static char *oclist[] = { 17907c478bd9Sstevel@tonic-gate "posixAccount", 17917c478bd9Sstevel@tonic-gate "shadowAccount", 17927c478bd9Sstevel@tonic-gate "account", 17937c478bd9Sstevel@tonic-gate "top", 17947c478bd9Sstevel@tonic-gate NULL 17957c478bd9Sstevel@tonic-gate }; 17967c478bd9Sstevel@tonic-gate 17977c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 17987c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 17997c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 18007c478bd9Sstevel@tonic-gate if (e == NULL) 18017c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate /* Convert the structure */ 18047c478bd9Sstevel@tonic-gate ptr = (struct spwd *)data; 18057c478bd9Sstevel@tonic-gate 18067c478bd9Sstevel@tonic-gate if (ptr->sp_namp == NULL) { 18077c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18087c478bd9Sstevel@tonic-gate *entry = NULL; 18097c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 18107c478bd9Sstevel@tonic-gate } 18117c478bd9Sstevel@tonic-gate 18127c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 18137c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->sp_namp); 18147c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 18157c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 18167c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18177c478bd9Sstevel@tonic-gate *entry = NULL; 18187c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate 18217c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 18227c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->sp_namp); 18237c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18247c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18257c478bd9Sstevel@tonic-gate return (rc); 18267c478bd9Sstevel@tonic-gate } 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate if (ptr->sp_pwdp == NULL) { 18297c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18307c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 18317c478bd9Sstevel@tonic-gate } else { 18327c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->sp_pwdp); 18337c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18347c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18357c478bd9Sstevel@tonic-gate return (rc); 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate } 18387c478bd9Sstevel@tonic-gate if (ptr->sp_lstchg >= 0) { 18397c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_lstchg); 18407c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowLastChange", ibuf); 18417c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18427c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18437c478bd9Sstevel@tonic-gate return (rc); 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate } 18467c478bd9Sstevel@tonic-gate if (ptr->sp_min >= 0) { 18477c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_min); 18487c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMin", ibuf); 18497c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18507c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18517c478bd9Sstevel@tonic-gate return (rc); 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate } 18547c478bd9Sstevel@tonic-gate if (ptr->sp_max >= 0) { 18557c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_max); 18567c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMax", ibuf); 18577c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18587c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18597c478bd9Sstevel@tonic-gate return (rc); 18607c478bd9Sstevel@tonic-gate } 18617c478bd9Sstevel@tonic-gate } 18627c478bd9Sstevel@tonic-gate if (ptr->sp_warn >= 0) { 18637c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_warn); 18647c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowWarning", ibuf); 18657c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18667c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18677c478bd9Sstevel@tonic-gate return (rc); 18687c478bd9Sstevel@tonic-gate } 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate if (ptr->sp_inact >= 0) { 18717c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_inact); 18727c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowInactive", ibuf); 18737c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18747c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18757c478bd9Sstevel@tonic-gate return (rc); 18767c478bd9Sstevel@tonic-gate } 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate if (ptr->sp_expire >= 0) { 18797c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_expire); 18807c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowExpire", ibuf); 18817c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18837c478bd9Sstevel@tonic-gate return (rc); 18847c478bd9Sstevel@tonic-gate } 18857c478bd9Sstevel@tonic-gate } 18867c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_flag); 18877c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowFlag", ibuf); 18887c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18897c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18907c478bd9Sstevel@tonic-gate return (rc); 18917c478bd9Sstevel@tonic-gate } 18927c478bd9Sstevel@tonic-gate 18937c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 18947c478bd9Sstevel@tonic-gate } 18957c478bd9Sstevel@tonic-gate 18967c478bd9Sstevel@tonic-gate 18977c478bd9Sstevel@tonic-gate /* 18987c478bd9Sstevel@tonic-gate * Conversion: group 18997c478bd9Sstevel@tonic-gate * Input format: struct group 19007c478bd9Sstevel@tonic-gate * Exported objectclass: posixGroup 19017c478bd9Sstevel@tonic-gate */ 19027c478bd9Sstevel@tonic-gate static int 19037c478bd9Sstevel@tonic-gate __s_cvt_group(const void *data, char **rdn, 1904*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 19057c478bd9Sstevel@tonic-gate { 19067c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 19077c478bd9Sstevel@tonic-gate int rc; 19087c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 19097c478bd9Sstevel@tonic-gate /* routine specific */ 19107c478bd9Sstevel@tonic-gate struct group *ptr; 19117c478bd9Sstevel@tonic-gate int i, j, k; 19127c478bd9Sstevel@tonic-gate char **nm, **lm; 19137c478bd9Sstevel@tonic-gate int max_attr = 4; 19147c478bd9Sstevel@tonic-gate char ibuf[10]; 19157c478bd9Sstevel@tonic-gate static char *oclist[] = { 19167c478bd9Sstevel@tonic-gate "posixGroup", 19177c478bd9Sstevel@tonic-gate "top", 19187c478bd9Sstevel@tonic-gate NULL 19197c478bd9Sstevel@tonic-gate }; 19207c478bd9Sstevel@tonic-gate 19217c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 19227c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 19237c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 19247c478bd9Sstevel@tonic-gate if (e == NULL) 19257c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate /* Convert the structure */ 19287c478bd9Sstevel@tonic-gate ptr = (struct group *)data; 19297c478bd9Sstevel@tonic-gate 1930f48205beScasper if (ptr->gr_name == NULL || ptr->gr_gid > MAXUID) { 19317c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19327c478bd9Sstevel@tonic-gate *entry = NULL; 19337c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 19377c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->gr_name); 19387c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 19397c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 19407c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19417c478bd9Sstevel@tonic-gate *entry = NULL; 19427c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19437c478bd9Sstevel@tonic-gate } 19447c478bd9Sstevel@tonic-gate 19457c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 19467c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->gr_name); 19477c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19487c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19497c478bd9Sstevel@tonic-gate return (rc); 19507c478bd9Sstevel@tonic-gate } 19517c478bd9Sstevel@tonic-gate 1952f48205beScasper (void) sprintf(ibuf, "%u", ptr->gr_gid); 19537c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 19547c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19557c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19567c478bd9Sstevel@tonic-gate return (rc); 19577c478bd9Sstevel@tonic-gate } 19587c478bd9Sstevel@tonic-gate if (ptr->gr_passwd && ptr->gr_passwd[0] != '\0') { 19597c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->gr_passwd); 19607c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19617c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19627c478bd9Sstevel@tonic-gate return (rc); 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate if (ptr->gr_mem && ptr->gr_mem[0]) { 19677c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 19687c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 19697c478bd9Sstevel@tonic-gate ; 19707c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 19717c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 19727c478bd9Sstevel@tonic-gate if (nm == NULL) { 19737c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19747c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19757c478bd9Sstevel@tonic-gate } 19767c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 19777c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 19787c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 19797c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 19807c478bd9Sstevel@tonic-gate free(nm[k]); 19817c478bd9Sstevel@tonic-gate free(nm); 19827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19837c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate } 19867c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberUid", nm); 19877c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 19887c478bd9Sstevel@tonic-gate free(nm[j]); 19897c478bd9Sstevel@tonic-gate } 19907c478bd9Sstevel@tonic-gate free(nm); 19917c478bd9Sstevel@tonic-gate nm = NULL; 19927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19947c478bd9Sstevel@tonic-gate return (rc); 19957c478bd9Sstevel@tonic-gate } 19967c478bd9Sstevel@tonic-gate } 19977c478bd9Sstevel@tonic-gate 19987c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate /* 20027c478bd9Sstevel@tonic-gate * Conversion: hosts 20037c478bd9Sstevel@tonic-gate * Input format: struct hostent 20047c478bd9Sstevel@tonic-gate * Exported objectclass: ipHost 20057c478bd9Sstevel@tonic-gate */ 20067c478bd9Sstevel@tonic-gate static int 20077c478bd9Sstevel@tonic-gate __s_cvt_hosts(const void *data, char **rdn, 2008*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 20097c478bd9Sstevel@tonic-gate { 20107c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 20117c478bd9Sstevel@tonic-gate int rc; 20127c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 20137c478bd9Sstevel@tonic-gate /* routine specific */ 20147c478bd9Sstevel@tonic-gate struct hostent *ptr; 20157c478bd9Sstevel@tonic-gate int max_attr = 6; 20167c478bd9Sstevel@tonic-gate int i, j, k; 20177c478bd9Sstevel@tonic-gate char **nm, **lm; 20187c478bd9Sstevel@tonic-gate static char *oclist[] = { 20197c478bd9Sstevel@tonic-gate "ipHost", 20207c478bd9Sstevel@tonic-gate "device", 20217c478bd9Sstevel@tonic-gate "top", 20227c478bd9Sstevel@tonic-gate NULL 20237c478bd9Sstevel@tonic-gate }; 20247c478bd9Sstevel@tonic-gate 20257c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 20267c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 20277c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 20287c478bd9Sstevel@tonic-gate if (e == NULL) 20297c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20307c478bd9Sstevel@tonic-gate 20317c478bd9Sstevel@tonic-gate /* Convert the structure */ 20327c478bd9Sstevel@tonic-gate ptr = (struct hostent *)data; 20337c478bd9Sstevel@tonic-gate 20347c478bd9Sstevel@tonic-gate if (ptr->h_name == NULL || 2035*91b658d3SToomas Soome ptr->h_addr_list == NULL || ptr->h_addr_list[0] == NULL) { 20367c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20377c478bd9Sstevel@tonic-gate *entry = NULL; 20387c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 20397c478bd9Sstevel@tonic-gate } 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 20427c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipHostNumber=%s", 20437c478bd9Sstevel@tonic-gate ptr->h_name, ptr->h_addr_list[0]); 20447c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 20457c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 20467c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20477c478bd9Sstevel@tonic-gate *entry = NULL; 20487c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20497c478bd9Sstevel@tonic-gate } 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 20527c478bd9Sstevel@tonic-gate if (ptr->h_aliases && ptr->h_aliases[0]) { 20537c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 20546d3c3c6aSiz /* 20556d3c3c6aSiz * If there is a description, 'i' will contain 20566d3c3c6aSiz * the index of the description in the aliases list 20576d3c3c6aSiz */ 20586d3c3c6aSiz for (i = 0; *lm && (*lm)[0] != '#'; i++, lm++) 20597c478bd9Sstevel@tonic-gate ; 20607c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 20617c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 20627c478bd9Sstevel@tonic-gate if (nm == NULL) { 20637c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20647c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate nm[0] = ptr->h_name; 20677c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 20687c478bd9Sstevel@tonic-gate nm[j+1] = ptr->h_aliases[j]; 20697c478bd9Sstevel@tonic-gate 20707c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 20716d3c3c6aSiz 20726d3c3c6aSiz if (rc != NS_LDAP_SUCCESS) { 20736d3c3c6aSiz __s_cvt_freeEntryRdn(entry, rdn); 20746d3c3c6aSiz free(nm); 20756d3c3c6aSiz return (rc); 20766d3c3c6aSiz } 20776d3c3c6aSiz 20786d3c3c6aSiz if (lm[i] && lm[i][0] == '#') { 20796d3c3c6aSiz nm[0] = &(lm[i][1]); 20806d3c3c6aSiz nm[1] = NULL; 20816d3c3c6aSiz rc = __s_add_attrlist(e, "description", nm); 20826d3c3c6aSiz } 20837c478bd9Sstevel@tonic-gate free(nm); 20847c478bd9Sstevel@tonic-gate nm = NULL; 20857c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20867c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20877c478bd9Sstevel@tonic-gate return (rc); 20887c478bd9Sstevel@tonic-gate } 20897c478bd9Sstevel@tonic-gate } else { 20907c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->h_name); 20917c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20927c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20937c478bd9Sstevel@tonic-gate return (rc); 20947c478bd9Sstevel@tonic-gate } 20957c478bd9Sstevel@tonic-gate } 20967c478bd9Sstevel@tonic-gate 20977c478bd9Sstevel@tonic-gate if (ptr->h_addr_list && ptr->h_addr_list[0]) { 20987c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 20997c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 21007c478bd9Sstevel@tonic-gate ; 21017c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 21027c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 21037c478bd9Sstevel@tonic-gate if (nm == NULL) { 21047c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21057c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 21087c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 21097c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 21107c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 21117c478bd9Sstevel@tonic-gate free(nm[k]); 21127c478bd9Sstevel@tonic-gate free(nm); 21137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21147c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21157c478bd9Sstevel@tonic-gate } 21167c478bd9Sstevel@tonic-gate } 21177c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "ipHostNumber", nm); 21187c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 21197c478bd9Sstevel@tonic-gate free(nm[j]); 21207c478bd9Sstevel@tonic-gate } 21217c478bd9Sstevel@tonic-gate free(nm); 21227c478bd9Sstevel@tonic-gate nm = NULL; 21237c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21247c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21257c478bd9Sstevel@tonic-gate return (rc); 21267c478bd9Sstevel@tonic-gate } 21277c478bd9Sstevel@tonic-gate } else { 21287c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21297c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21307c478bd9Sstevel@tonic-gate } 21317c478bd9Sstevel@tonic-gate 21327c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate /* 21367c478bd9Sstevel@tonic-gate * Conversion: rpc 21377c478bd9Sstevel@tonic-gate * Input format: struct rpcent 21387c478bd9Sstevel@tonic-gate * Exported objectclass: oncRpc 21397c478bd9Sstevel@tonic-gate */ 21407c478bd9Sstevel@tonic-gate static int 21417c478bd9Sstevel@tonic-gate __s_cvt_rpc(const void *data, char **rdn, 2142*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 21437c478bd9Sstevel@tonic-gate { 21447c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 21457c478bd9Sstevel@tonic-gate int rc; 21467c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 21477c478bd9Sstevel@tonic-gate /* routine specific */ 21487c478bd9Sstevel@tonic-gate struct rpcent *ptr; 21497c478bd9Sstevel@tonic-gate int max_attr = 3; 21507c478bd9Sstevel@tonic-gate int i, j; 21517c478bd9Sstevel@tonic-gate char **nm; 21527c478bd9Sstevel@tonic-gate char ibuf[10]; 21537c478bd9Sstevel@tonic-gate static char *oclist[] = { 21547c478bd9Sstevel@tonic-gate "oncRpc", 21557c478bd9Sstevel@tonic-gate "top", 21567c478bd9Sstevel@tonic-gate NULL 21577c478bd9Sstevel@tonic-gate }; 21587c478bd9Sstevel@tonic-gate 21597c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 21607c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 21617c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 21627c478bd9Sstevel@tonic-gate if (e == NULL) 21637c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21647c478bd9Sstevel@tonic-gate 21657c478bd9Sstevel@tonic-gate /* Convert the structure */ 21667c478bd9Sstevel@tonic-gate ptr = (struct rpcent *)data; 21677c478bd9Sstevel@tonic-gate 21687c478bd9Sstevel@tonic-gate if (ptr->r_name == NULL || ptr->r_number < 0) { 21697c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21707c478bd9Sstevel@tonic-gate *entry = NULL; 21717c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21727c478bd9Sstevel@tonic-gate } 21737c478bd9Sstevel@tonic-gate 21747c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 21757c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->r_name); 21767c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 21777c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 21787c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21797c478bd9Sstevel@tonic-gate *entry = NULL; 21807c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21817c478bd9Sstevel@tonic-gate } 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 21847c478bd9Sstevel@tonic-gate if (ptr->r_aliases && ptr->r_aliases[0]) { 21857c478bd9Sstevel@tonic-gate nm = ptr->r_aliases; 21867c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 21877c478bd9Sstevel@tonic-gate ; 21887c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 21897c478bd9Sstevel@tonic-gate if (nm == NULL) { 21907c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21917c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate nm[0] = ptr->r_name; 21947c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 21957c478bd9Sstevel@tonic-gate nm[j+1] = ptr->r_aliases[j]; 21967c478bd9Sstevel@tonic-gate 21977c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 21987c478bd9Sstevel@tonic-gate free(nm); 21997c478bd9Sstevel@tonic-gate nm = NULL; 22007c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22017c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22027c478bd9Sstevel@tonic-gate return (rc); 22037c478bd9Sstevel@tonic-gate } 22047c478bd9Sstevel@tonic-gate } else { 22057c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->r_name); 22067c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22077c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22087c478bd9Sstevel@tonic-gate return (rc); 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate 22127c478bd9Sstevel@tonic-gate if (ptr->r_number >= 0) { 22137c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->r_number); 22147c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "oncRpcNumber", ibuf); 22157c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22167c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22177c478bd9Sstevel@tonic-gate return (rc); 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate } 22207c478bd9Sstevel@tonic-gate 22217c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 22227c478bd9Sstevel@tonic-gate 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate /* 22267c478bd9Sstevel@tonic-gate * Conversion: protocols 22277c478bd9Sstevel@tonic-gate * Input format: struct protoent 22287c478bd9Sstevel@tonic-gate * Exported objectclass: ipProtocol 22297c478bd9Sstevel@tonic-gate */ 22307c478bd9Sstevel@tonic-gate static int 22317c478bd9Sstevel@tonic-gate __s_cvt_protocols(const void *data, char **rdn, 2232*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 22337c478bd9Sstevel@tonic-gate { 22347c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 22357c478bd9Sstevel@tonic-gate int rc; 22367c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 22377c478bd9Sstevel@tonic-gate /* routine specific */ 22387c478bd9Sstevel@tonic-gate struct protoent *ptr; 22397c478bd9Sstevel@tonic-gate int max_attr = 3; 22407c478bd9Sstevel@tonic-gate int i, j; 22417c478bd9Sstevel@tonic-gate char ibuf[10]; 22427c478bd9Sstevel@tonic-gate char **nm; 22437c478bd9Sstevel@tonic-gate static char *oclist[] = { 22447c478bd9Sstevel@tonic-gate "ipProtocol", 22457c478bd9Sstevel@tonic-gate "top", 22467c478bd9Sstevel@tonic-gate NULL 22477c478bd9Sstevel@tonic-gate }; 22487c478bd9Sstevel@tonic-gate 22497c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 22507c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 22517c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 22527c478bd9Sstevel@tonic-gate if (e == NULL) 22537c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22547c478bd9Sstevel@tonic-gate 22557c478bd9Sstevel@tonic-gate /* Convert the structure */ 22567c478bd9Sstevel@tonic-gate ptr = (struct protoent *)data; 22577c478bd9Sstevel@tonic-gate 22587c478bd9Sstevel@tonic-gate if (ptr->p_name == NULL || ptr->p_proto < 0) { 22597c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22607c478bd9Sstevel@tonic-gate *entry = NULL; 22617c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 22627c478bd9Sstevel@tonic-gate } 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 22657c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->p_name); 22667c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 22677c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 22687c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22697c478bd9Sstevel@tonic-gate *entry = NULL; 22707c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22717c478bd9Sstevel@tonic-gate } 22727c478bd9Sstevel@tonic-gate 22737c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 22747c478bd9Sstevel@tonic-gate if (ptr->p_aliases && ptr->p_aliases[0]) { 22757c478bd9Sstevel@tonic-gate nm = ptr->p_aliases; 22767c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 22777c478bd9Sstevel@tonic-gate ; 22787c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 22797c478bd9Sstevel@tonic-gate if (nm == NULL) { 22807c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22817c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22827c478bd9Sstevel@tonic-gate } 22837c478bd9Sstevel@tonic-gate nm[0] = ptr->p_name; 22847c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 22857c478bd9Sstevel@tonic-gate nm[j+1] = ptr->p_aliases[j]; 22867c478bd9Sstevel@tonic-gate 22877c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 22887c478bd9Sstevel@tonic-gate free(nm); 22897c478bd9Sstevel@tonic-gate nm = NULL; 22907c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22927c478bd9Sstevel@tonic-gate return (rc); 22937c478bd9Sstevel@tonic-gate } 22947c478bd9Sstevel@tonic-gate } else { 22957c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->p_name); 22967c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22977c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22987c478bd9Sstevel@tonic-gate return (rc); 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate } 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->p_proto); 23037c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipProtocolNumber", ibuf); 23047c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23057c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23067c478bd9Sstevel@tonic-gate return (rc); 23077c478bd9Sstevel@tonic-gate } 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate } 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate /* 23147c478bd9Sstevel@tonic-gate * Conversion: services 23157c478bd9Sstevel@tonic-gate * Input format: struct servent 23167c478bd9Sstevel@tonic-gate * Exported objectclass: ipService 23177c478bd9Sstevel@tonic-gate */ 23187c478bd9Sstevel@tonic-gate static int 23197c478bd9Sstevel@tonic-gate __s_cvt_services(const void *data, char **rdn, 2320*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 23217c478bd9Sstevel@tonic-gate { 23227c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 23237c478bd9Sstevel@tonic-gate int rc; 23247c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 232550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India char esc_str[RDNSIZE]; 23267c478bd9Sstevel@tonic-gate /* routine specific */ 23277c478bd9Sstevel@tonic-gate struct servent *ptr; 23287c478bd9Sstevel@tonic-gate int max_attr = 4; 23297c478bd9Sstevel@tonic-gate int i, j; 23307c478bd9Sstevel@tonic-gate char ibuf[10]; 23317c478bd9Sstevel@tonic-gate char **nm; 23327c478bd9Sstevel@tonic-gate static char *oclist[] = { 23337c478bd9Sstevel@tonic-gate "ipService", 23347c478bd9Sstevel@tonic-gate "top", 23357c478bd9Sstevel@tonic-gate NULL 23367c478bd9Sstevel@tonic-gate }; 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 23397c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 23407c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 23417c478bd9Sstevel@tonic-gate if (e == NULL) 23427c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23437c478bd9Sstevel@tonic-gate 23447c478bd9Sstevel@tonic-gate /* Convert the structure */ 23457c478bd9Sstevel@tonic-gate ptr = (struct servent *)data; 23467c478bd9Sstevel@tonic-gate 2347*91b658d3SToomas Soome if (ptr->s_name == NULL || ptr->s_port < 0 || ptr->s_proto == NULL) { 23487c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23497c478bd9Sstevel@tonic-gate *entry = NULL; 23507c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 23517c478bd9Sstevel@tonic-gate } 23527c478bd9Sstevel@tonic-gate 235350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India /* 235450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * Escape special characters in service name. 235550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India */ 235650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India if (escape_str(esc_str, ptr->s_name) != 0) { 235750b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India __ns_ldap_freeEntry(e); 235850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *entry = NULL; 235950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India return (NS_LDAP_INVALID_PARAM); 236050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 236150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 23627c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 23637c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipServiceProtocol=%s", 236450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India esc_str, ptr->s_proto); 236550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 23667c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 23677c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 23687c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23697c478bd9Sstevel@tonic-gate *entry = NULL; 23707c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 23747c478bd9Sstevel@tonic-gate if (ptr->s_aliases && ptr->s_aliases[0]) { 23757c478bd9Sstevel@tonic-gate nm = ptr->s_aliases; 23767c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 23777c478bd9Sstevel@tonic-gate ; 23787c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 23797c478bd9Sstevel@tonic-gate if (nm == NULL) { 23807c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23817c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23827c478bd9Sstevel@tonic-gate } 23837c478bd9Sstevel@tonic-gate nm[0] = ptr->s_name; 23847c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 23857c478bd9Sstevel@tonic-gate nm[j+1] = ptr->s_aliases[j]; 23867c478bd9Sstevel@tonic-gate 23877c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 23887c478bd9Sstevel@tonic-gate free(nm); 23897c478bd9Sstevel@tonic-gate nm = NULL; 23907c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23927c478bd9Sstevel@tonic-gate return (rc); 23937c478bd9Sstevel@tonic-gate } 23947c478bd9Sstevel@tonic-gate } else { 23957c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->s_name); 23967c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23977c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23987c478bd9Sstevel@tonic-gate return (rc); 23997c478bd9Sstevel@tonic-gate } 24007c478bd9Sstevel@tonic-gate } 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->s_port); 24037c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServicePort", ibuf); 24047c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24057c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24067c478bd9Sstevel@tonic-gate return (rc); 24077c478bd9Sstevel@tonic-gate } 24087c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServiceProtocol", ptr->s_proto); 24097c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24107c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24117c478bd9Sstevel@tonic-gate return (rc); 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 24157c478bd9Sstevel@tonic-gate } 24167c478bd9Sstevel@tonic-gate 24177c478bd9Sstevel@tonic-gate /* 24187c478bd9Sstevel@tonic-gate * Conversion: networks 24197c478bd9Sstevel@tonic-gate * Input format: struct netent 24207c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 24217c478bd9Sstevel@tonic-gate */ 24227c478bd9Sstevel@tonic-gate static int 24237c478bd9Sstevel@tonic-gate __s_cvt_networks(const void *data, char **rdn, 2424*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 24257c478bd9Sstevel@tonic-gate { 24267c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 24277c478bd9Sstevel@tonic-gate int rc; 24287c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 24297c478bd9Sstevel@tonic-gate /* routine specific */ 24307c478bd9Sstevel@tonic-gate struct netent *ptr; 24317c478bd9Sstevel@tonic-gate int max_attr = 4; 24327c478bd9Sstevel@tonic-gate int i, j; 24337c478bd9Sstevel@tonic-gate char cp[64]; 24347c478bd9Sstevel@tonic-gate char **nm; 24357c478bd9Sstevel@tonic-gate static char *oclist[] = { 24367c478bd9Sstevel@tonic-gate "ipNetwork", 24377c478bd9Sstevel@tonic-gate "top", 24387c478bd9Sstevel@tonic-gate NULL 24397c478bd9Sstevel@tonic-gate }; 24407c478bd9Sstevel@tonic-gate 24417c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 24427c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 24437c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 24447c478bd9Sstevel@tonic-gate if (e == NULL) 24457c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24467c478bd9Sstevel@tonic-gate 24477c478bd9Sstevel@tonic-gate /* Convert the structure */ 24487c478bd9Sstevel@tonic-gate ptr = (struct netent *)data; 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate if (ptr->n_name == NULL || ptr->n_net == 0) { 24517c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24527c478bd9Sstevel@tonic-gate *entry = NULL; 24537c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 24547c478bd9Sstevel@tonic-gate } 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate (void) snprintf(cp, sizeof (cp), "%d.%d.%d.%d", 2457e1dd0a2fSth (ptr->n_net & 0xFF000000) >> 24, 2458e1dd0a2fSth (ptr->n_net & 0x00FF0000) >> 16, 2459e1dd0a2fSth (ptr->n_net & 0x0000FF00) >> 8, 2460e1dd0a2fSth (ptr->n_net & 0x000000FF)); 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 24637c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", cp); 24647c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 24657c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 24667c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24677c478bd9Sstevel@tonic-gate *entry = NULL; 24687c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24697c478bd9Sstevel@tonic-gate } 24707c478bd9Sstevel@tonic-gate 24717c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 24727c478bd9Sstevel@tonic-gate if (ptr->n_aliases && ptr->n_aliases[0]) { 24737c478bd9Sstevel@tonic-gate nm = ptr->n_aliases; 24747c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 24757c478bd9Sstevel@tonic-gate ; 24767c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 24777c478bd9Sstevel@tonic-gate if (nm == NULL) { 24787c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24797c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24807c478bd9Sstevel@tonic-gate } 24817c478bd9Sstevel@tonic-gate nm[0] = ptr->n_name; 24827c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 24837c478bd9Sstevel@tonic-gate nm[j+1] = ptr->n_aliases[j]; 24847c478bd9Sstevel@tonic-gate 24857c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 24867c478bd9Sstevel@tonic-gate free(nm); 24877c478bd9Sstevel@tonic-gate nm = NULL; 24887c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24897c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24907c478bd9Sstevel@tonic-gate return (rc); 24917c478bd9Sstevel@tonic-gate } 24927c478bd9Sstevel@tonic-gate } else { 24937c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->n_name); 24947c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24957c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24967c478bd9Sstevel@tonic-gate return (rc); 24977c478bd9Sstevel@tonic-gate } 24987c478bd9Sstevel@tonic-gate } 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetworkNumber", cp); 25017c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 25027c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 25037c478bd9Sstevel@tonic-gate return (rc); 25047c478bd9Sstevel@tonic-gate } 25057c478bd9Sstevel@tonic-gate 25067c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate } 25097c478bd9Sstevel@tonic-gate /* 25107c478bd9Sstevel@tonic-gate * Conversion: netmasks 25117c478bd9Sstevel@tonic-gate * Input format: struct _ns_netmasks 25127c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 25137c478bd9Sstevel@tonic-gate */ 25147c478bd9Sstevel@tonic-gate static int 25157c478bd9Sstevel@tonic-gate __s_cvt_netmasks(const void *data, char **rdn, 2516*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 25177c478bd9Sstevel@tonic-gate { 25187c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 25197c478bd9Sstevel@tonic-gate int rc; 25207c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 25217c478bd9Sstevel@tonic-gate /* routine specific */ 25227c478bd9Sstevel@tonic-gate struct _ns_netmasks *ptr; 25237c478bd9Sstevel@tonic-gate int max_attr = 4; 25247c478bd9Sstevel@tonic-gate static char *oclist[] = { 25257c478bd9Sstevel@tonic-gate "ipNetwork", 25267c478bd9Sstevel@tonic-gate "top", 25277c478bd9Sstevel@tonic-gate NULL 25287c478bd9Sstevel@tonic-gate }; 25297c478bd9Sstevel@tonic-gate 25307c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 25317c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 25327c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 25337c478bd9Sstevel@tonic-gate if (e == NULL) 25347c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 25357c478bd9Sstevel@tonic-gate 25367c478bd9Sstevel@tonic-gate /* Convert the structure */ 25377c478bd9Sstevel@tonic-gate ptr = (struct _ns_netmasks *)data; 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate if (ptr->netnumber == NULL) { 25407c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 25417c478bd9Sstevel@tonic-gate *entry = NULL; 25427c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 25437c478bd9Sstevel@tonic-gate } 25447c478bd9Sstevel@tonic-gate 25457c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 25467c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", ptr->netnumber); 25477c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 25487c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 25497c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 25507c478bd9Sstevel@tonic-gate *entry = NULL; 25517c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 25527c478bd9Sstevel@tonic-gate } 25537c478bd9Sstevel@tonic-gate 25547c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 2555*91b658d3SToomas Soome rc = __s_add_attr(e, "ipNetworkNumber", ptr->netnumber); 2556*91b658d3SToomas Soome if (rc != NS_LDAP_SUCCESS) { 2557*91b658d3SToomas Soome __s_cvt_freeEntryRdn(entry, rdn); 2558*91b658d3SToomas Soome return (rc); 2559*91b658d3SToomas Soome } 25607c478bd9Sstevel@tonic-gate 2561*91b658d3SToomas Soome if (ptr->netmask != NULL) { 25627c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetmaskNumber", ptr->netmask); 25637c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 25647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 25657c478bd9Sstevel@tonic-gate return (rc); 25667c478bd9Sstevel@tonic-gate } 25677c478bd9Sstevel@tonic-gate } 25687c478bd9Sstevel@tonic-gate 25697c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 25707c478bd9Sstevel@tonic-gate 25717c478bd9Sstevel@tonic-gate } 25727c478bd9Sstevel@tonic-gate /* 25737c478bd9Sstevel@tonic-gate * Conversion: netgroups 25747c478bd9Sstevel@tonic-gate * Input format: struct _ns_netgroups 25757c478bd9Sstevel@tonic-gate * Exported objectclass: nisNetgroup 25767c478bd9Sstevel@tonic-gate */ 25777c478bd9Sstevel@tonic-gate static int 25787c478bd9Sstevel@tonic-gate __s_cvt_netgroups(const void *data, char **rdn, 2579*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 25807c478bd9Sstevel@tonic-gate { 25817c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 25827c478bd9Sstevel@tonic-gate int rc; 25837c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 25847c478bd9Sstevel@tonic-gate /* routine specific */ 25857c478bd9Sstevel@tonic-gate struct _ns_netgroups *ptr; 25867c478bd9Sstevel@tonic-gate int max_attr = 6; 25877c478bd9Sstevel@tonic-gate int i, j; 25887c478bd9Sstevel@tonic-gate char **nm; 25897c478bd9Sstevel@tonic-gate static char *oclist[] = { 25907c478bd9Sstevel@tonic-gate "nisNetgroup", 25917c478bd9Sstevel@tonic-gate "top", 25927c478bd9Sstevel@tonic-gate NULL 25937c478bd9Sstevel@tonic-gate }; 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 25967c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 25977c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 25987c478bd9Sstevel@tonic-gate if (e == NULL) 25997c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26007c478bd9Sstevel@tonic-gate 26017c478bd9Sstevel@tonic-gate /* Convert the structure */ 26027c478bd9Sstevel@tonic-gate ptr = (struct _ns_netgroups *)data; 26037c478bd9Sstevel@tonic-gate 2604*91b658d3SToomas Soome if (ptr->name == NULL || *ptr->name == '\0') { 26057c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26067c478bd9Sstevel@tonic-gate *entry = NULL; 26077c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 26087c478bd9Sstevel@tonic-gate } 26097c478bd9Sstevel@tonic-gate 26107c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 26117c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 26127c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 26137c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 26147c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26157c478bd9Sstevel@tonic-gate *entry = NULL; 26167c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26177c478bd9Sstevel@tonic-gate } 26187c478bd9Sstevel@tonic-gate 2619*91b658d3SToomas Soome rc = __s_add_attr(e, "cn", ptr->name); 2620*91b658d3SToomas Soome if (rc != NS_LDAP_SUCCESS) { 2621*91b658d3SToomas Soome __s_cvt_freeEntryRdn(entry, rdn); 2622*91b658d3SToomas Soome return (rc); 26237c478bd9Sstevel@tonic-gate } 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 26267c478bd9Sstevel@tonic-gate if (ptr->triplet && ptr->triplet[0]) { 26277c478bd9Sstevel@tonic-gate nm = ptr->triplet; 26287c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 26297c478bd9Sstevel@tonic-gate ; 26307c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 26317c478bd9Sstevel@tonic-gate if (nm == NULL) { 26327c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26337c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26347c478bd9Sstevel@tonic-gate } 26357c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 26367c478bd9Sstevel@tonic-gate nm[j] = ptr->triplet[j]; 26377c478bd9Sstevel@tonic-gate 26387c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "nisNetgroupTriple", nm); 26397c478bd9Sstevel@tonic-gate free(nm); 26407c478bd9Sstevel@tonic-gate nm = NULL; 26417c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26427c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26437c478bd9Sstevel@tonic-gate return (rc); 26447c478bd9Sstevel@tonic-gate } 26457c478bd9Sstevel@tonic-gate } 26467c478bd9Sstevel@tonic-gate if (ptr->netgroup && ptr->netgroup[0]) { 26477c478bd9Sstevel@tonic-gate nm = ptr->netgroup; 26487c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 26497c478bd9Sstevel@tonic-gate ; 26507c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 26517c478bd9Sstevel@tonic-gate if (nm == NULL) { 26527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26537c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 26567c478bd9Sstevel@tonic-gate nm[j] = ptr->netgroup[j]; 26577c478bd9Sstevel@tonic-gate 26587c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberNisNetgroup", nm); 26597c478bd9Sstevel@tonic-gate free(nm); 26607c478bd9Sstevel@tonic-gate nm = NULL; 26617c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26627c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26637c478bd9Sstevel@tonic-gate return (rc); 26647c478bd9Sstevel@tonic-gate } 26657c478bd9Sstevel@tonic-gate } 26667c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 26677c478bd9Sstevel@tonic-gate } 26687c478bd9Sstevel@tonic-gate /* 26697c478bd9Sstevel@tonic-gate * Conversion: bootparams 26707c478bd9Sstevel@tonic-gate * Input format: struct _ns_bootp 26717c478bd9Sstevel@tonic-gate * Exported objectclass: bootableDevice, device 26727c478bd9Sstevel@tonic-gate */ 26737c478bd9Sstevel@tonic-gate static int 26747c478bd9Sstevel@tonic-gate __s_cvt_bootparams(const void *data, char **rdn, 2675*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 26767c478bd9Sstevel@tonic-gate { 26777c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 26787c478bd9Sstevel@tonic-gate int rc; 26797c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 26807c478bd9Sstevel@tonic-gate /* routine specific */ 26817c478bd9Sstevel@tonic-gate struct _ns_bootp *ptr; 26827c478bd9Sstevel@tonic-gate int max_attr = 4; 26837c478bd9Sstevel@tonic-gate int i, j; 26847c478bd9Sstevel@tonic-gate char **nm; 26857c478bd9Sstevel@tonic-gate static char *oclist[] = { 26867c478bd9Sstevel@tonic-gate "bootableDevice", 26877c478bd9Sstevel@tonic-gate "device", 26887c478bd9Sstevel@tonic-gate "top", 26897c478bd9Sstevel@tonic-gate NULL 26907c478bd9Sstevel@tonic-gate }; 26917c478bd9Sstevel@tonic-gate 26927c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 26937c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 26947c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 26957c478bd9Sstevel@tonic-gate if (e == NULL) 26967c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26977c478bd9Sstevel@tonic-gate 26987c478bd9Sstevel@tonic-gate /* Convert the structure */ 26997c478bd9Sstevel@tonic-gate ptr = (struct _ns_bootp *)data; 27007c478bd9Sstevel@tonic-gate 2701*91b658d3SToomas Soome if (ptr->name == NULL || *ptr->name == '\0') { 27027c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27037c478bd9Sstevel@tonic-gate *entry = NULL; 27047c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 27057c478bd9Sstevel@tonic-gate } 27067c478bd9Sstevel@tonic-gate 27077c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 27087c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 27097c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 27107c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 27117c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27127c478bd9Sstevel@tonic-gate *entry = NULL; 27137c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27147c478bd9Sstevel@tonic-gate } 27157c478bd9Sstevel@tonic-gate 2716*91b658d3SToomas Soome rc = __s_add_attr(e, "cn", ptr->name); 2717*91b658d3SToomas Soome if (rc != NS_LDAP_SUCCESS) { 2718*91b658d3SToomas Soome __s_cvt_freeEntryRdn(entry, rdn); 2719*91b658d3SToomas Soome return (rc); 27207c478bd9Sstevel@tonic-gate } 27217c478bd9Sstevel@tonic-gate 27227c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 27237c478bd9Sstevel@tonic-gate if (ptr->param && ptr->param[0]) { 27247c478bd9Sstevel@tonic-gate nm = ptr->param; 27257c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 27267c478bd9Sstevel@tonic-gate ; 27277c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 27287c478bd9Sstevel@tonic-gate if (nm == NULL) { 27297c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27307c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27317c478bd9Sstevel@tonic-gate } 27327c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 27337c478bd9Sstevel@tonic-gate nm[j] = ptr->param[j]; 27347c478bd9Sstevel@tonic-gate 27357c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "bootParameter", nm); 27367c478bd9Sstevel@tonic-gate free(nm); 27377c478bd9Sstevel@tonic-gate nm = NULL; 27387c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27397c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27407c478bd9Sstevel@tonic-gate return (rc); 27417c478bd9Sstevel@tonic-gate } 27427c478bd9Sstevel@tonic-gate } 27437c478bd9Sstevel@tonic-gate 27447c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 27457c478bd9Sstevel@tonic-gate 27467c478bd9Sstevel@tonic-gate } 27477c478bd9Sstevel@tonic-gate /* 27487c478bd9Sstevel@tonic-gate * Conversion: ethers 27497c478bd9Sstevel@tonic-gate * Input format: struct _ns_ethers 27507c478bd9Sstevel@tonic-gate * Exported objectclass: ieee802Device, device 27517c478bd9Sstevel@tonic-gate */ 27527c478bd9Sstevel@tonic-gate static int 27537c478bd9Sstevel@tonic-gate __s_cvt_ethers(const void *data, char **rdn, 2754*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 27557c478bd9Sstevel@tonic-gate { 27567c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 27577c478bd9Sstevel@tonic-gate int rc; 27587c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 27597c478bd9Sstevel@tonic-gate /* routine specific */ 27607c478bd9Sstevel@tonic-gate struct _ns_ethers *ptr; 27617c478bd9Sstevel@tonic-gate int max_attr = 4; 27627c478bd9Sstevel@tonic-gate static char *oclist[] = { 27637c478bd9Sstevel@tonic-gate "ieee802Device", 27647c478bd9Sstevel@tonic-gate "device", 27657c478bd9Sstevel@tonic-gate "top", 27667c478bd9Sstevel@tonic-gate NULL 27677c478bd9Sstevel@tonic-gate }; 27687c478bd9Sstevel@tonic-gate 27697c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 27707c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 27717c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 27727c478bd9Sstevel@tonic-gate if (e == NULL) 27737c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27747c478bd9Sstevel@tonic-gate 27757c478bd9Sstevel@tonic-gate /* Convert the structure */ 27767c478bd9Sstevel@tonic-gate ptr = (struct _ns_ethers *)data; 27777c478bd9Sstevel@tonic-gate 2778*91b658d3SToomas Soome if (ptr->name == NULL || *ptr->name == '\0' || ptr->ether == NULL) { 27797c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27807c478bd9Sstevel@tonic-gate *entry = NULL; 27817c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 27827c478bd9Sstevel@tonic-gate } 27837c478bd9Sstevel@tonic-gate 27847c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 27857c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 27867c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 27877c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 27887c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27897c478bd9Sstevel@tonic-gate *entry = NULL; 27907c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27917c478bd9Sstevel@tonic-gate } 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 27947c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 27957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27977c478bd9Sstevel@tonic-gate return (rc); 27987c478bd9Sstevel@tonic-gate } 27997c478bd9Sstevel@tonic-gate 28007c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "macAddress", ptr->ether); 28017c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28027c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28037c478bd9Sstevel@tonic-gate return (rc); 28047c478bd9Sstevel@tonic-gate } 28057c478bd9Sstevel@tonic-gate 28067c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 28077c478bd9Sstevel@tonic-gate } 28087c478bd9Sstevel@tonic-gate /* 28097c478bd9Sstevel@tonic-gate * This function is used when processing an ethers (objectclass: ieee802Device) 28107c478bd9Sstevel@tonic-gate * or a bootparams (objectclass: bootableDevice) entry, and the entry is 28117c478bd9Sstevel@tonic-gate * already found in LDAP. Since both ethers and bootparams share the same 28127c478bd9Sstevel@tonic-gate * LDAP container, we want to check that the entry found in LDAP is: 28137c478bd9Sstevel@tonic-gate * - either the same entry (same cn, same objectclass): we don't do anything 28147c478bd9Sstevel@tonic-gate * in this case 28157c478bd9Sstevel@tonic-gate * - or an entry which does not have the objectclass we are interesting in: 28167c478bd9Sstevel@tonic-gate * in this case, we modify the existing entry by adding the relevant 28177c478bd9Sstevel@tonic-gate * objectclass (ieee802Device or bootableDevice) and the relevant attribute(s) 28187c478bd9Sstevel@tonic-gate * from the attribute list previously computing by the relevant conversion 28197c478bd9Sstevel@tonic-gate * function. 28207c478bd9Sstevel@tonic-gate * Note: from conversion functions __s_cvt_ethers() and __s_cvt_bootparams() 28217c478bd9Sstevel@tonic-gate * we know that there is only 1 more attribute today to add (macAddress 28227c478bd9Sstevel@tonic-gate * or bootParameter) 28237c478bd9Sstevel@tonic-gate */ 28247c478bd9Sstevel@tonic-gate #define _MAX_ATTR_ETHBOOTP 2 28257c478bd9Sstevel@tonic-gate static int 28267c478bd9Sstevel@tonic-gate modify_ethers_bootp( 28277c478bd9Sstevel@tonic-gate const char *service, 28287c478bd9Sstevel@tonic-gate const char *rdn, 28297c478bd9Sstevel@tonic-gate const char *fulldn, 28307c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attrlist, 28317c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 28327c478bd9Sstevel@tonic-gate const int flags, 28337c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 28347c478bd9Sstevel@tonic-gate { 28357c478bd9Sstevel@tonic-gate char filter[BUFSIZ]; 28367c478bd9Sstevel@tonic-gate ns_ldap_result_t *resultp; 28377c478bd9Sstevel@tonic-gate int rc = 0; 28387c478bd9Sstevel@tonic-gate int i; 28397c478bd9Sstevel@tonic-gate ns_ldap_attr_t *new_attrlist[_MAX_ATTR_ETHBOOTP+1]; 28407c478bd9Sstevel@tonic-gate ns_ldap_attr_t new_attrlist0; 28417c478bd9Sstevel@tonic-gate char *new_attrvalue0[1]; 28427c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *aptr = attrlist; 28437c478bd9Sstevel@tonic-gate ns_ldap_attr_t *aptr2; 28447c478bd9Sstevel@tonic-gate ns_ldap_error_t *new_errorp = NULL; 28457c478bd9Sstevel@tonic-gate 28467c478bd9Sstevel@tonic-gate if (rdn == NULL || fulldn == NULL || attrlist == NULL || 2847e1dd0a2fSth errorp == NULL || service == NULL) 28487c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 28497c478bd9Sstevel@tonic-gate 28507c478bd9Sstevel@tonic-gate bzero(&new_attrlist, sizeof (new_attrlist)); 28517c478bd9Sstevel@tonic-gate bzero(&new_attrlist0, sizeof (new_attrlist0)); 28527c478bd9Sstevel@tonic-gate new_attrlist[0] = &new_attrlist0; 28537c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue = new_attrvalue0; 28547c478bd9Sstevel@tonic-gate 28557c478bd9Sstevel@tonic-gate new_attrlist[0]->attrname = "objectclass"; 28567c478bd9Sstevel@tonic-gate new_attrlist[0]->value_count = 1; 28577c478bd9Sstevel@tonic-gate if (strcasecmp(service, "ethers") == NULL) { 28587c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 2859e1dd0a2fSth "(&(objectClass=ieee802Device)(%s))", rdn); 28607c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "ieee802Device"; 28617c478bd9Sstevel@tonic-gate } else { 28627c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 2863e1dd0a2fSth "(&(objectClass=bootableDevice)(%s))", rdn); 28647c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "bootableDevice"; 28657c478bd9Sstevel@tonic-gate } 28667c478bd9Sstevel@tonic-gate 28677c478bd9Sstevel@tonic-gate rc = __ns_ldap_list(service, filter, NULL, (const char **)NULL, 2868e1dd0a2fSth NULL, NS_LDAP_SCOPE_SUBTREE, &resultp, &new_errorp, 2869e1dd0a2fSth NULL, NULL); 28707c478bd9Sstevel@tonic-gate 28717c478bd9Sstevel@tonic-gate switch (rc) { 28727c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 28737c478bd9Sstevel@tonic-gate /* 28747c478bd9Sstevel@tonic-gate * entry already exists for this service 28757c478bd9Sstevel@tonic-gate * return NS_LDAP_INTERNAL and do not modify the incoming errorp 28767c478bd9Sstevel@tonic-gate */ 28777c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 28787c478bd9Sstevel@tonic-gate break; 28797c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 28807c478bd9Sstevel@tonic-gate /* 28817c478bd9Sstevel@tonic-gate * entry not found with the given objectclasss but entry exists 28827c478bd9Sstevel@tonic-gate * hence add the relevant attribute (macAddress or bootparams). 28837c478bd9Sstevel@tonic-gate */ 28847c478bd9Sstevel@tonic-gate i = 1; 28857c478bd9Sstevel@tonic-gate while (*aptr && (i < _MAX_ATTR_ETHBOOTP)) { 28867c478bd9Sstevel@tonic-gate /* aptr2 needed here to avoid lint warning */ 28877c478bd9Sstevel@tonic-gate aptr2 = (ns_ldap_attr_t *)*aptr++; 28887c478bd9Sstevel@tonic-gate if ((strcasecmp(aptr2->attrname, "cn") != 0) && 2889e1dd0a2fSth (strcasecmp(aptr2->attrname, 2890e1dd0a2fSth "objectclass") != 0)) { 2891e1dd0a2fSth new_attrlist[i++] = (ns_ldap_attr_t *)aptr2; 28927c478bd9Sstevel@tonic-gate } 28937c478bd9Sstevel@tonic-gate } 28947c478bd9Sstevel@tonic-gate 28957c478bd9Sstevel@tonic-gate if (i != _MAX_ATTR_ETHBOOTP) { 28967c478bd9Sstevel@tonic-gate /* we haven't found all expected attributes */ 28977c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 28987c478bd9Sstevel@tonic-gate break; 28997c478bd9Sstevel@tonic-gate } 29007c478bd9Sstevel@tonic-gate 29017c478bd9Sstevel@tonic-gate aptr = (const ns_ldap_attr_t * const *) new_attrlist; 29027c478bd9Sstevel@tonic-gate /* clean errorp first */ 29037c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 29047c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, aptr, cred, flags, 2905e1dd0a2fSth errorp); 29067c478bd9Sstevel@tonic-gate break; 29077c478bd9Sstevel@tonic-gate default: 29087c478bd9Sstevel@tonic-gate /* 29097c478bd9Sstevel@tonic-gate * unexpected error happenned 29107c478bd9Sstevel@tonic-gate * returning relevant error 29117c478bd9Sstevel@tonic-gate */ 29127c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 29137c478bd9Sstevel@tonic-gate *errorp = new_errorp; 29147c478bd9Sstevel@tonic-gate break; 29157c478bd9Sstevel@tonic-gate } 29167c478bd9Sstevel@tonic-gate 29177c478bd9Sstevel@tonic-gate return (rc); 29187c478bd9Sstevel@tonic-gate } 29197c478bd9Sstevel@tonic-gate 29207c478bd9Sstevel@tonic-gate /* 29217c478bd9Sstevel@tonic-gate * Conversion: publickey 29227c478bd9Sstevel@tonic-gate * Input format: struct _ns_pubkey 29237c478bd9Sstevel@tonic-gate * Exported objectclass: NisKeyObject 29247c478bd9Sstevel@tonic-gate */ 29257c478bd9Sstevel@tonic-gate static int 29267c478bd9Sstevel@tonic-gate __s_cvt_publickey(const void *data, char **rdn, 2927*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 29287c478bd9Sstevel@tonic-gate { 29297c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 29307c478bd9Sstevel@tonic-gate int rc; 29317c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 29327c478bd9Sstevel@tonic-gate /* routine specific */ 29337c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 29347c478bd9Sstevel@tonic-gate int max_attr = 3; 29357c478bd9Sstevel@tonic-gate static char *oclist[] = { 29367c478bd9Sstevel@tonic-gate "NisKeyObject", 29377c478bd9Sstevel@tonic-gate NULL 29387c478bd9Sstevel@tonic-gate }; 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 29417c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 29427c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 29437c478bd9Sstevel@tonic-gate if (e == NULL) 29447c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 29457c478bd9Sstevel@tonic-gate 29467c478bd9Sstevel@tonic-gate /* Convert the structure */ 29477c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 29487c478bd9Sstevel@tonic-gate 2949*91b658d3SToomas Soome if (ptr->name == NULL || *ptr->name == '\0' || ptr->pubkey == NULL || 2950*91b658d3SToomas Soome ptr->privkey == NULL) { 29517c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 29527c478bd9Sstevel@tonic-gate *entry = NULL; 29537c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 29547c478bd9Sstevel@tonic-gate } 29557c478bd9Sstevel@tonic-gate 29567c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 29577c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_FALSE) 29587c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 29597c478bd9Sstevel@tonic-gate else 29607c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 29617c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 29627c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 29637c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 29647c478bd9Sstevel@tonic-gate *entry = NULL; 29657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 29667c478bd9Sstevel@tonic-gate } 29677c478bd9Sstevel@tonic-gate 29687c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 29697c478bd9Sstevel@tonic-gate 29707c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisPublickey", ptr->pubkey); 29717c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29727c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29737c478bd9Sstevel@tonic-gate return (rc); 29747c478bd9Sstevel@tonic-gate } 29757c478bd9Sstevel@tonic-gate 29767c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisSecretkey", ptr->privkey); 29777c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29787c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29797c478bd9Sstevel@tonic-gate return (rc); 29807c478bd9Sstevel@tonic-gate } 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 29837c478bd9Sstevel@tonic-gate } 29847c478bd9Sstevel@tonic-gate /* 29857c478bd9Sstevel@tonic-gate * Conversion: aliases 29867c478bd9Sstevel@tonic-gate * Input format: struct _ns_alias 29877c478bd9Sstevel@tonic-gate * Exported objectclass: mailGroup 29887c478bd9Sstevel@tonic-gate */ 29897c478bd9Sstevel@tonic-gate static int 29907c478bd9Sstevel@tonic-gate __s_cvt_aliases(const void *data, char **rdn, 2991*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 29927c478bd9Sstevel@tonic-gate { 29937c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 29947c478bd9Sstevel@tonic-gate int rc; 29957c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 29967c478bd9Sstevel@tonic-gate /* routine specific */ 29977c478bd9Sstevel@tonic-gate struct _ns_alias *ptr; 29987c478bd9Sstevel@tonic-gate int max_attr = 4; 29997c478bd9Sstevel@tonic-gate int i, j; 30007c478bd9Sstevel@tonic-gate char **nm; 30017c478bd9Sstevel@tonic-gate static char *oclist[] = { 30027c478bd9Sstevel@tonic-gate "mailGroup", 30037c478bd9Sstevel@tonic-gate "top", 30047c478bd9Sstevel@tonic-gate NULL 30057c478bd9Sstevel@tonic-gate }; 30067c478bd9Sstevel@tonic-gate 30077c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 30087c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 30097c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 30107c478bd9Sstevel@tonic-gate if (e == NULL) 30117c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30127c478bd9Sstevel@tonic-gate 30137c478bd9Sstevel@tonic-gate /* Convert the structure */ 30147c478bd9Sstevel@tonic-gate ptr = (struct _ns_alias *)data; 30157c478bd9Sstevel@tonic-gate 3016*91b658d3SToomas Soome if (ptr->alias == NULL || *ptr->alias == '\0') { 30177c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30187c478bd9Sstevel@tonic-gate *entry = NULL; 30197c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 30207c478bd9Sstevel@tonic-gate } 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 30237c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->alias); 30247c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 30257c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 30267c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30277c478bd9Sstevel@tonic-gate *entry = NULL; 30287c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30297c478bd9Sstevel@tonic-gate } 30307c478bd9Sstevel@tonic-gate 3031*91b658d3SToomas Soome rc = __s_add_attr(e, "mail", (char *)ptr->alias); 3032*91b658d3SToomas Soome if (rc != NS_LDAP_SUCCESS) { 3033*91b658d3SToomas Soome __s_cvt_freeEntryRdn(entry, rdn); 3034*91b658d3SToomas Soome return (rc); 30357c478bd9Sstevel@tonic-gate } 30367c478bd9Sstevel@tonic-gate 30377c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 30387c478bd9Sstevel@tonic-gate if (ptr->member && ptr->member[0]) { 30397c478bd9Sstevel@tonic-gate nm = ptr->member; 30407c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 30417c478bd9Sstevel@tonic-gate ; 30427c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 30437c478bd9Sstevel@tonic-gate if (nm == NULL) { 30447c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30457c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30467c478bd9Sstevel@tonic-gate } 30477c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 30487c478bd9Sstevel@tonic-gate nm[j] = ptr->member[j]; 30497c478bd9Sstevel@tonic-gate 30507c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "mgrpRFC822MailMember", nm); 30517c478bd9Sstevel@tonic-gate free(nm); 30527c478bd9Sstevel@tonic-gate nm = NULL; 30537c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30557c478bd9Sstevel@tonic-gate return (rc); 30567c478bd9Sstevel@tonic-gate } 30577c478bd9Sstevel@tonic-gate } 30587c478bd9Sstevel@tonic-gate 30597c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 30607c478bd9Sstevel@tonic-gate 30617c478bd9Sstevel@tonic-gate } 30627c478bd9Sstevel@tonic-gate /* 30637c478bd9Sstevel@tonic-gate * Conversion: automount 30647c478bd9Sstevel@tonic-gate * Input format: struct _ns_automount 30657c478bd9Sstevel@tonic-gate * Exported objectclass: automount 30667c478bd9Sstevel@tonic-gate */ 30677c478bd9Sstevel@tonic-gate static int 30687c478bd9Sstevel@tonic-gate __s_cvt_auto_mount(const void *data, char **rdn, 3069*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 30707c478bd9Sstevel@tonic-gate { 30717c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 30727c478bd9Sstevel@tonic-gate int rc; 30737c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 30747c478bd9Sstevel@tonic-gate /* routine specific */ 30757c478bd9Sstevel@tonic-gate struct _ns_automount *ptr; 30767c478bd9Sstevel@tonic-gate int max_attr = 6; 30777c478bd9Sstevel@tonic-gate void **paramVal = NULL; 30787c478bd9Sstevel@tonic-gate char **mappedschema = NULL; 30797c478bd9Sstevel@tonic-gate int version1 = 0; 30807c478bd9Sstevel@tonic-gate static char *oclist[] = { 30817c478bd9Sstevel@tonic-gate NULL, 30827c478bd9Sstevel@tonic-gate "top", 30837c478bd9Sstevel@tonic-gate NULL 30847c478bd9Sstevel@tonic-gate }; 30857c478bd9Sstevel@tonic-gate 30867c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 30877c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 30887c478bd9Sstevel@tonic-gate 30897c478bd9Sstevel@tonic-gate /* determine profile version number */ 30907c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, ¶mVal, errorp); 30917c478bd9Sstevel@tonic-gate if (paramVal && *paramVal && 3092e1dd0a2fSth strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0) 30937c478bd9Sstevel@tonic-gate version1 = 1; 30947c478bd9Sstevel@tonic-gate if (paramVal) 30957c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 30967c478bd9Sstevel@tonic-gate if (rc && errorp) 30977c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 30987c478bd9Sstevel@tonic-gate 30997c478bd9Sstevel@tonic-gate /* use old schema for version 1 profiles */ 31007c478bd9Sstevel@tonic-gate if (version1) 31017c478bd9Sstevel@tonic-gate oclist[0] = "nisObject"; 31027c478bd9Sstevel@tonic-gate else 31037c478bd9Sstevel@tonic-gate oclist[0] = "automount"; 31047c478bd9Sstevel@tonic-gate 31057c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 31067c478bd9Sstevel@tonic-gate if (e == NULL) 31077c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31087c478bd9Sstevel@tonic-gate 31097c478bd9Sstevel@tonic-gate /* Convert the structure */ 31107c478bd9Sstevel@tonic-gate ptr = (struct _ns_automount *)data; 31117c478bd9Sstevel@tonic-gate 3112*91b658d3SToomas Soome if (ptr->key == NULL || *ptr->key == '\0' || ptr->value == NULL || 3113*91b658d3SToomas Soome ptr->mapname == NULL) { 31147c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31157c478bd9Sstevel@tonic-gate *entry = NULL; 31167c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 31177c478bd9Sstevel@tonic-gate } 31187c478bd9Sstevel@tonic-gate 31197c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 31207c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, version1 ? "cn=%s" : "automountKey=%s", 3121e1dd0a2fSth ptr->key); 31227c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 31237c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 31247c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31257c478bd9Sstevel@tonic-gate *entry = NULL; 31267c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31277c478bd9Sstevel@tonic-gate } 31287c478bd9Sstevel@tonic-gate 3129*91b658d3SToomas Soome rc = __s_add_attr(e, version1 ? "cn" : "automountKey", 3130*91b658d3SToomas Soome (char *)ptr->key); 3131*91b658d3SToomas Soome if (rc != NS_LDAP_SUCCESS) { 3132*91b658d3SToomas Soome __s_cvt_freeEntryRdn(entry, rdn); 3133*91b658d3SToomas Soome return (rc); 31347c478bd9Sstevel@tonic-gate } 31357c478bd9Sstevel@tonic-gate 31367c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, version1 ? "nisMapEntry" : "automountInformation", 3137e1dd0a2fSth (char *)ptr->value); 31387c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31397c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31407c478bd9Sstevel@tonic-gate return (rc); 31417c478bd9Sstevel@tonic-gate } 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate /* 31447c478bd9Sstevel@tonic-gate * even for version 2, if automount is mapped to nisObject we 31457c478bd9Sstevel@tonic-gate * still need 'nisMapName' attribute 31467c478bd9Sstevel@tonic-gate */ 31477c478bd9Sstevel@tonic-gate mappedschema = __ns_ldap_getMappedObjectClass("automount", "automount"); 31487c478bd9Sstevel@tonic-gate if (mappedschema && mappedschema[0] && 3149e1dd0a2fSth strcasecmp(mappedschema[0], "nisObject") == 0) 31507c478bd9Sstevel@tonic-gate version1 = 1; 31517c478bd9Sstevel@tonic-gate if (mappedschema) 31527c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedschema); 31537c478bd9Sstevel@tonic-gate 31547c478bd9Sstevel@tonic-gate if (version1) { 31557c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisMapName", (char *)ptr->mapname); 31567c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31577c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31587c478bd9Sstevel@tonic-gate return (rc); 31597c478bd9Sstevel@tonic-gate } 31607c478bd9Sstevel@tonic-gate } 31617c478bd9Sstevel@tonic-gate 31627c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 31637c478bd9Sstevel@tonic-gate } 31647c478bd9Sstevel@tonic-gate /* 31657c478bd9Sstevel@tonic-gate * Conversion: auth_attr 31667c478bd9Sstevel@tonic-gate * Input format: authstr_t 31677c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuthAttr 31687c478bd9Sstevel@tonic-gate */ 31697c478bd9Sstevel@tonic-gate static int 31707c478bd9Sstevel@tonic-gate __s_cvt_authattr(const void *data, char **rdn, 3171*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 31727c478bd9Sstevel@tonic-gate { 31737c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 31747c478bd9Sstevel@tonic-gate int rc; 31757c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 31767c478bd9Sstevel@tonic-gate /* routine specific */ 31777c478bd9Sstevel@tonic-gate authstr_t *ptr; 31787c478bd9Sstevel@tonic-gate int max_attr = 6; 31797c478bd9Sstevel@tonic-gate static char *oclist[] = { 31807c478bd9Sstevel@tonic-gate "SolarisAuthAttr", 31817c478bd9Sstevel@tonic-gate "top", 31827c478bd9Sstevel@tonic-gate NULL 31837c478bd9Sstevel@tonic-gate }; 31847c478bd9Sstevel@tonic-gate 31857c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 31867c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 31877c478bd9Sstevel@tonic-gate 31887c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 31897c478bd9Sstevel@tonic-gate if (e == NULL) 31907c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31917c478bd9Sstevel@tonic-gate 31927c478bd9Sstevel@tonic-gate /* Convert the structure */ 31937c478bd9Sstevel@tonic-gate ptr = (authstr_t *)data; 31947c478bd9Sstevel@tonic-gate 31957c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 31967c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31977c478bd9Sstevel@tonic-gate *entry = NULL; 31987c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 31997c478bd9Sstevel@tonic-gate } 32007c478bd9Sstevel@tonic-gate 32017c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 32027c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 32037c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 32047c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 32057c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32067c478bd9Sstevel@tonic-gate *entry = NULL; 32077c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32087c478bd9Sstevel@tonic-gate } 32097c478bd9Sstevel@tonic-gate 32107c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 32117c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32127c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32137c478bd9Sstevel@tonic-gate return (rc); 32147c478bd9Sstevel@tonic-gate } 32157c478bd9Sstevel@tonic-gate 32167c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 32177c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32187c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32197c478bd9Sstevel@tonic-gate return (rc); 32207c478bd9Sstevel@tonic-gate } 32217c478bd9Sstevel@tonic-gate 32227c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 32237c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 32247c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32257c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32267c478bd9Sstevel@tonic-gate return (rc); 32277c478bd9Sstevel@tonic-gate } 32287c478bd9Sstevel@tonic-gate } 32297c478bd9Sstevel@tonic-gate 32307c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 32317c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 32327c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32347c478bd9Sstevel@tonic-gate return (rc); 32357c478bd9Sstevel@tonic-gate } 32367c478bd9Sstevel@tonic-gate } 32377c478bd9Sstevel@tonic-gate 32387c478bd9Sstevel@tonic-gate if (ptr->short_desc != NULL) { 32397c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrShortDesc", ptr->short_desc); 32407c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32417c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32427c478bd9Sstevel@tonic-gate return (rc); 32437c478bd9Sstevel@tonic-gate } 32447c478bd9Sstevel@tonic-gate } 32457c478bd9Sstevel@tonic-gate 32467c478bd9Sstevel@tonic-gate if (ptr->long_desc != NULL) { 32477c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->long_desc); 32487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32507c478bd9Sstevel@tonic-gate return (rc); 32517c478bd9Sstevel@tonic-gate } 32527c478bd9Sstevel@tonic-gate } 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 32557c478bd9Sstevel@tonic-gate } 32567c478bd9Sstevel@tonic-gate /* 32577c478bd9Sstevel@tonic-gate * Conversion: exec_attr 32587c478bd9Sstevel@tonic-gate * Input format: execstr_t 32597c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisExecAttr 32607c478bd9Sstevel@tonic-gate */ 32617c478bd9Sstevel@tonic-gate static int 32627c478bd9Sstevel@tonic-gate __s_cvt_execattr(const void *data, char **rdn, 3263*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 32647c478bd9Sstevel@tonic-gate { 32657c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 32667c478bd9Sstevel@tonic-gate int rc; 32677c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 326850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India char esc_str[RDNSIZE]; 32697c478bd9Sstevel@tonic-gate /* routine specific */ 32707c478bd9Sstevel@tonic-gate execstr_t *ptr; 32717c478bd9Sstevel@tonic-gate int max_attr = 7; 32727c478bd9Sstevel@tonic-gate static char *oclist[] = { 32737c478bd9Sstevel@tonic-gate "SolarisExecAttr", 32747c478bd9Sstevel@tonic-gate "SolarisProfAttr", 32757c478bd9Sstevel@tonic-gate "top", 32767c478bd9Sstevel@tonic-gate NULL 32777c478bd9Sstevel@tonic-gate }; 32787c478bd9Sstevel@tonic-gate 32797c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 32807c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 32817c478bd9Sstevel@tonic-gate 32827c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 32837c478bd9Sstevel@tonic-gate if (e == NULL) 32847c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32857c478bd9Sstevel@tonic-gate 32867c478bd9Sstevel@tonic-gate /* Convert the structure */ 32877c478bd9Sstevel@tonic-gate ptr = (execstr_t *)data; 32887c478bd9Sstevel@tonic-gate 32897c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 32907c478bd9Sstevel@tonic-gate ptr->policy == NULL || ptr->policy[0] == '\0' || 32917c478bd9Sstevel@tonic-gate ptr->type == NULL || ptr->type[0] == '\0' || 32927c478bd9Sstevel@tonic-gate ptr->id == NULL || ptr->id[0] == '\0') { 32937c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32947c478bd9Sstevel@tonic-gate *entry = NULL; 32957c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 32967c478bd9Sstevel@tonic-gate } 32977c478bd9Sstevel@tonic-gate 329850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India /* 329950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * Escape special characters in ProfileID. 330050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India */ 330150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India if (escape_str(esc_str, ptr->id) != 0) { 330250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India __ns_ldap_freeEntry(e); 330350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *entry = NULL; 330450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India return (NS_LDAP_INVALID_PARAM); 330550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 330650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 33077c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 33087c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+SolarisKernelSecurityPolicy=%s" 33097c478bd9Sstevel@tonic-gate "+SolarisProfileType=%s+SolarisProfileId=%s", 331050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India ptr->name, ptr->policy, ptr->type, esc_str); 331150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 33127c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 33137c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 33147c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 33157c478bd9Sstevel@tonic-gate *entry = NULL; 33167c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 33177c478bd9Sstevel@tonic-gate } 33187c478bd9Sstevel@tonic-gate 33197c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 33207c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33217c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33227c478bd9Sstevel@tonic-gate return (rc); 33237c478bd9Sstevel@tonic-gate } 33247c478bd9Sstevel@tonic-gate 33257c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisKernelSecurityPolicy", ptr->policy); 33267c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33277c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33287c478bd9Sstevel@tonic-gate return (rc); 33297c478bd9Sstevel@tonic-gate } 33307c478bd9Sstevel@tonic-gate 33317c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileType", ptr->type); 33327c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33347c478bd9Sstevel@tonic-gate return (rc); 33357c478bd9Sstevel@tonic-gate } 33367c478bd9Sstevel@tonic-gate 33377c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileId", ptr->id); 33387c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33397c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33407c478bd9Sstevel@tonic-gate return (rc); 33417c478bd9Sstevel@tonic-gate } 33427c478bd9Sstevel@tonic-gate 33437c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 33447c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33457c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33467c478bd9Sstevel@tonic-gate return (rc); 33477c478bd9Sstevel@tonic-gate } 33487c478bd9Sstevel@tonic-gate 33497c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 33507c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes1", ptr->res1); 33517c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33537c478bd9Sstevel@tonic-gate return (rc); 33547c478bd9Sstevel@tonic-gate } 33557c478bd9Sstevel@tonic-gate } 33567c478bd9Sstevel@tonic-gate 33577c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 33587c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes2", ptr->res2); 33597c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33607c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 33617c478bd9Sstevel@tonic-gate return (rc); 33627c478bd9Sstevel@tonic-gate } 33637c478bd9Sstevel@tonic-gate } 33647c478bd9Sstevel@tonic-gate 33657c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 33667c478bd9Sstevel@tonic-gate } 33677c478bd9Sstevel@tonic-gate /* 33687c478bd9Sstevel@tonic-gate * Conversion: prof_attr 33697c478bd9Sstevel@tonic-gate * Input format: profstr_t 33707c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisProfAttr 33717c478bd9Sstevel@tonic-gate */ 33727c478bd9Sstevel@tonic-gate static int 33737c478bd9Sstevel@tonic-gate __s_cvt_profattr(const void *data, char **rdn, 3374*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 33757c478bd9Sstevel@tonic-gate { 33767c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 33777c478bd9Sstevel@tonic-gate int rc; 33787c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 33797c478bd9Sstevel@tonic-gate /* routine specific */ 33807c478bd9Sstevel@tonic-gate profstr_t *ptr; 33817c478bd9Sstevel@tonic-gate int max_attr = 5; 33827c478bd9Sstevel@tonic-gate static char *oclist[] = { 33837c478bd9Sstevel@tonic-gate "SolarisProfAttr", 33847c478bd9Sstevel@tonic-gate "top", 33857c478bd9Sstevel@tonic-gate NULL 33867c478bd9Sstevel@tonic-gate }; 33877c478bd9Sstevel@tonic-gate 33887c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 33897c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 33907c478bd9Sstevel@tonic-gate 33917c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 33927c478bd9Sstevel@tonic-gate if (e == NULL) 33937c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 33947c478bd9Sstevel@tonic-gate 33957c478bd9Sstevel@tonic-gate /* Convert the structure */ 33967c478bd9Sstevel@tonic-gate ptr = (profstr_t *)data; 33977c478bd9Sstevel@tonic-gate 33987c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 33997c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 34007c478bd9Sstevel@tonic-gate *entry = NULL; 34017c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 34027c478bd9Sstevel@tonic-gate } 34037c478bd9Sstevel@tonic-gate 34047c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 34057c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 34067c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 34077c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 34087c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 34097c478bd9Sstevel@tonic-gate *entry = NULL; 34107c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34117c478bd9Sstevel@tonic-gate } 34127c478bd9Sstevel@tonic-gate 34137c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 34147c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34157c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 34167c478bd9Sstevel@tonic-gate return (rc); 34177c478bd9Sstevel@tonic-gate } 34187c478bd9Sstevel@tonic-gate 34197c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 34207c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34217c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 34227c478bd9Sstevel@tonic-gate return (rc); 34237c478bd9Sstevel@tonic-gate } 34247c478bd9Sstevel@tonic-gate 34257c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 34267c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 34277c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34287c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 34297c478bd9Sstevel@tonic-gate return (rc); 34307c478bd9Sstevel@tonic-gate } 34317c478bd9Sstevel@tonic-gate } 34327c478bd9Sstevel@tonic-gate 34337c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 34347c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 34357c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34367c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 34377c478bd9Sstevel@tonic-gate return (rc); 34387c478bd9Sstevel@tonic-gate } 34397c478bd9Sstevel@tonic-gate } 34407c478bd9Sstevel@tonic-gate 34417c478bd9Sstevel@tonic-gate if (ptr->desc != NULL) { 34427c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->desc); 34437c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34447c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 34457c478bd9Sstevel@tonic-gate return (rc); 34467c478bd9Sstevel@tonic-gate } 34477c478bd9Sstevel@tonic-gate } 34487c478bd9Sstevel@tonic-gate 34497c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 34507c478bd9Sstevel@tonic-gate } 34517c478bd9Sstevel@tonic-gate /* 34527c478bd9Sstevel@tonic-gate * Conversion: user_attr 34537c478bd9Sstevel@tonic-gate * Input format: userstr_t 34547c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisUserAttr 34557c478bd9Sstevel@tonic-gate */ 34567c478bd9Sstevel@tonic-gate static int 34577c478bd9Sstevel@tonic-gate __s_cvt_userattr(const void *data, char **rdn, 3458*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 34597c478bd9Sstevel@tonic-gate { 34607c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 34617c478bd9Sstevel@tonic-gate int rc; 34627c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 34637c478bd9Sstevel@tonic-gate /* routine specific */ 34647c478bd9Sstevel@tonic-gate userstr_t *ptr; 34657c478bd9Sstevel@tonic-gate int max_attr = 5; 34667c478bd9Sstevel@tonic-gate static char *oclist[] = { 34677c478bd9Sstevel@tonic-gate "SolarisUserAttr", 34687c478bd9Sstevel@tonic-gate NULL 34697c478bd9Sstevel@tonic-gate }; 34707c478bd9Sstevel@tonic-gate 34717c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 34727c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 34737c478bd9Sstevel@tonic-gate 34747c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 34757c478bd9Sstevel@tonic-gate if (e == NULL) 34767c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34777c478bd9Sstevel@tonic-gate 34787c478bd9Sstevel@tonic-gate /* Convert the structure */ 34797c478bd9Sstevel@tonic-gate ptr = (userstr_t *)data; 34807c478bd9Sstevel@tonic-gate 34817c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 34827c478bd9Sstevel@tonic-gate ptr->attr == NULL) { 34837c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 34847c478bd9Sstevel@tonic-gate *entry = NULL; 34857c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 34867c478bd9Sstevel@tonic-gate } 34877c478bd9Sstevel@tonic-gate 34887c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 34897c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 34907c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 34917c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 34927c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 34937c478bd9Sstevel@tonic-gate *entry = NULL; 34947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34957c478bd9Sstevel@tonic-gate } 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate /* 34987c478bd9Sstevel@tonic-gate * SolarisUserAttr has no uid attribute 34997c478bd9Sstevel@tonic-gate */ 35007c478bd9Sstevel@tonic-gate 35017c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 35027c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35037c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35047c478bd9Sstevel@tonic-gate return (rc); 35057c478bd9Sstevel@tonic-gate } 35067c478bd9Sstevel@tonic-gate 35077c478bd9Sstevel@tonic-gate if (ptr->qualifier != NULL) { 35087c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisUserQualifier", ptr->qualifier); 35097c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35107c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35117c478bd9Sstevel@tonic-gate return (rc); 35127c478bd9Sstevel@tonic-gate } 35137c478bd9Sstevel@tonic-gate } 35147c478bd9Sstevel@tonic-gate 35157c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 35167c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 35177c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35187c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35197c478bd9Sstevel@tonic-gate return (rc); 35207c478bd9Sstevel@tonic-gate } 35217c478bd9Sstevel@tonic-gate } 35227c478bd9Sstevel@tonic-gate 35237c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 35247c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 35257c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35267c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35277c478bd9Sstevel@tonic-gate return (rc); 35287c478bd9Sstevel@tonic-gate } 35297c478bd9Sstevel@tonic-gate } 35307c478bd9Sstevel@tonic-gate 35317c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 35327c478bd9Sstevel@tonic-gate } 35337c478bd9Sstevel@tonic-gate /* 35347c478bd9Sstevel@tonic-gate * Conversion: audit_user 35357c478bd9Sstevel@tonic-gate * Input format: au_user_str_t 35367c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuditUser 35377c478bd9Sstevel@tonic-gate */ 35387c478bd9Sstevel@tonic-gate static int 35397c478bd9Sstevel@tonic-gate __s_cvt_audituser(const void *data, char **rdn, 3540*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 35417c478bd9Sstevel@tonic-gate { 35427c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 35437c478bd9Sstevel@tonic-gate int rc; 35447c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 35457c478bd9Sstevel@tonic-gate /* routine specific */ 35467c478bd9Sstevel@tonic-gate au_user_str_t *ptr; 35477c478bd9Sstevel@tonic-gate int max_attr = 3; 35487c478bd9Sstevel@tonic-gate static char *oclist[] = { 35497c478bd9Sstevel@tonic-gate "SolarisAuditUser", 35507c478bd9Sstevel@tonic-gate NULL 35517c478bd9Sstevel@tonic-gate }; 35527c478bd9Sstevel@tonic-gate 35537c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 35547c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 35557c478bd9Sstevel@tonic-gate 35567c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 35577c478bd9Sstevel@tonic-gate if (e == NULL) 35587c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 35597c478bd9Sstevel@tonic-gate 35607c478bd9Sstevel@tonic-gate /* Convert the structure */ 35617c478bd9Sstevel@tonic-gate ptr = (au_user_str_t *)data; 35627c478bd9Sstevel@tonic-gate 35637c478bd9Sstevel@tonic-gate if (ptr->au_name == NULL || ptr->au_name[0] == '\0') { 35647c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 35657c478bd9Sstevel@tonic-gate *entry = NULL; 35667c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 35677c478bd9Sstevel@tonic-gate } 35687c478bd9Sstevel@tonic-gate 35697c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 35707c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->au_name); 35717c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 35727c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 35737c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 35747c478bd9Sstevel@tonic-gate *entry = NULL; 35757c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 35767c478bd9Sstevel@tonic-gate } 35777c478bd9Sstevel@tonic-gate 35787c478bd9Sstevel@tonic-gate /* 35797c478bd9Sstevel@tonic-gate * Solaris AuditUser has no uid attribute 35807c478bd9Sstevel@tonic-gate */ 35817c478bd9Sstevel@tonic-gate 35827c478bd9Sstevel@tonic-gate if (ptr->au_always != NULL) { 35837c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditAlways", ptr->au_always); 35847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35867c478bd9Sstevel@tonic-gate return (rc); 35877c478bd9Sstevel@tonic-gate } 35887c478bd9Sstevel@tonic-gate } 35897c478bd9Sstevel@tonic-gate 35907c478bd9Sstevel@tonic-gate if (ptr->au_never != NULL) { 35917c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditNever", ptr->au_never); 35927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 35937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 35947c478bd9Sstevel@tonic-gate return (rc); 35957c478bd9Sstevel@tonic-gate } 35967c478bd9Sstevel@tonic-gate } 35977c478bd9Sstevel@tonic-gate 35987c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 35997c478bd9Sstevel@tonic-gate } 360045916cd2Sjpk /* 360145916cd2Sjpk * Conversion: tnrhtp 360245916cd2Sjpk * Input format: tsol_tpstr_t 360345916cd2Sjpk * Exported objectclass: ipTnetTemplate 360445916cd2Sjpk */ 360545916cd2Sjpk static int 360645916cd2Sjpk __s_cvt_tnrhtp(const void *data, char **rdn, 3607*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 360845916cd2Sjpk { 360945916cd2Sjpk ns_ldap_entry_t *e; 361045916cd2Sjpk int rc; 361145916cd2Sjpk char trdn[RDNSIZE]; 361250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India char esc_str[RDNSIZE]; 361345916cd2Sjpk /* routine specific */ 361445916cd2Sjpk int max_attr = 2; 361545916cd2Sjpk tsol_tpstr_t *ptr; 361645916cd2Sjpk static char *oclist[] = { 361745916cd2Sjpk "ipTnetTemplate", 361845916cd2Sjpk "top", 361945916cd2Sjpk NULL 362045916cd2Sjpk }; 362145916cd2Sjpk 362245916cd2Sjpk if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 362345916cd2Sjpk return (NS_LDAP_OP_FAILED); 362445916cd2Sjpk 362545916cd2Sjpk *entry = e = __s_mk_entry(oclist, max_attr); 362645916cd2Sjpk if (e == NULL) 362745916cd2Sjpk return (NS_LDAP_MEMORY); 362845916cd2Sjpk 362945916cd2Sjpk /* Convert the structure */ 363045916cd2Sjpk ptr = (tsol_tpstr_t *)data; 363145916cd2Sjpk 363244aa1912Sth if (ptr->template == NULL || *ptr->template == '\0') { 363345916cd2Sjpk __ns_ldap_freeEntry(e); 363445916cd2Sjpk *entry = NULL; 363545916cd2Sjpk return (NS_LDAP_INVALID_PARAM); 363645916cd2Sjpk } 363745916cd2Sjpk 363850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India /* 363950b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India * Escape special characters in Template name. 364050b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India */ 364150b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India if (escape_str(esc_str, ptr->template) != 0) { 364250b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India __ns_ldap_freeEntry(e); 364350b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India *entry = NULL; 364450b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India return (NS_LDAP_INVALID_PARAM); 364550b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India } 364650b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 364745916cd2Sjpk /* Create an appropriate rdn */ 364850b7bd51SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India (void) snprintf(trdn, RDNSIZE, "ipTnetTemplateName=%s", esc_str); 364945916cd2Sjpk *rdn = strdup(trdn); 365045916cd2Sjpk if (*rdn == NULL) { 365145916cd2Sjpk __ns_ldap_freeEntry(e); 365245916cd2Sjpk *entry = NULL; 365345916cd2Sjpk return (NS_LDAP_MEMORY); 365445916cd2Sjpk } 365545916cd2Sjpk 365645916cd2Sjpk rc = __s_add_attr(e, "ipTnetTemplateName", ptr->template); 365745916cd2Sjpk if (rc != NS_LDAP_SUCCESS) { 365845916cd2Sjpk __s_cvt_freeEntryRdn(entry, rdn); 365945916cd2Sjpk return (rc); 366045916cd2Sjpk } 366145916cd2Sjpk 366245916cd2Sjpk rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attrs); 366345916cd2Sjpk if (rc != NS_LDAP_SUCCESS) { 366445916cd2Sjpk __s_cvt_freeEntryRdn(entry, rdn); 366545916cd2Sjpk return (rc); 366645916cd2Sjpk } 36677c478bd9Sstevel@tonic-gate 366845916cd2Sjpk return (NS_LDAP_SUCCESS); 366945916cd2Sjpk } 367045916cd2Sjpk /* 367145916cd2Sjpk * Conversion: tnrhdb 367245916cd2Sjpk * Input format: tsol_rhstr_t 367345916cd2Sjpk * Exported objectclass: ipTnetHost 367445916cd2Sjpk */ 367545916cd2Sjpk static int 367645916cd2Sjpk __s_cvt_tnrhdb(const void *data, char **rdn, 3677*91b658d3SToomas Soome ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 367845916cd2Sjpk { 367945916cd2Sjpk ns_ldap_entry_t *e; 368045916cd2Sjpk int rc; 368145916cd2Sjpk char trdn[RDNSIZE]; 368245916cd2Sjpk /* routine specific */ 368345916cd2Sjpk tsol_rhstr_t *ptr; 368445916cd2Sjpk int max_attr = 2; 368545916cd2Sjpk static char *oclist[] = { 368645916cd2Sjpk "ipTnetHost", 368745916cd2Sjpk "ipTnetTemplate", 368845916cd2Sjpk "top", 368945916cd2Sjpk NULL 369045916cd2Sjpk }; 369145916cd2Sjpk 369245916cd2Sjpk if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 369345916cd2Sjpk return (NS_LDAP_OP_FAILED); 369445916cd2Sjpk 369545916cd2Sjpk *entry = e = __s_mk_entry(oclist, max_attr); 369645916cd2Sjpk if (e == NULL) 369745916cd2Sjpk return (NS_LDAP_MEMORY); 369845916cd2Sjpk 369945916cd2Sjpk /* Convert the structure */ 370045916cd2Sjpk ptr = (tsol_rhstr_t *)data; 370145916cd2Sjpk 370244aa1912Sth if (ptr->address == NULL || *ptr->address == '\0' || 370344aa1912Sth ptr->template == NULL || *ptr->template == '\0') { 370445916cd2Sjpk __ns_ldap_freeEntry(e); 370545916cd2Sjpk *entry = NULL; 370645916cd2Sjpk return (NS_LDAP_INVALID_PARAM); 370745916cd2Sjpk } 370845916cd2Sjpk 370945916cd2Sjpk /* Create an appropriate rdn */ 371045916cd2Sjpk (void) snprintf(trdn, RDNSIZE, "ipTnetNumber=%s", ptr->address); 371145916cd2Sjpk *rdn = strdup(trdn); 371245916cd2Sjpk if (*rdn == NULL) { 371345916cd2Sjpk __ns_ldap_freeEntry(e); 371445916cd2Sjpk *entry = NULL; 371545916cd2Sjpk return (NS_LDAP_MEMORY); 371645916cd2Sjpk } 371745916cd2Sjpk 371845916cd2Sjpk rc = __s_add_attr(e, "ipTnetNumber", ptr->address); 371945916cd2Sjpk if (rc != NS_LDAP_SUCCESS) { 372045916cd2Sjpk __s_cvt_freeEntryRdn(entry, rdn); 372145916cd2Sjpk return (rc); 372245916cd2Sjpk } 372345916cd2Sjpk 372445916cd2Sjpk rc = __s_add_attr(e, "ipTnetTemplateName", ptr->template); 372545916cd2Sjpk if (rc != NS_LDAP_SUCCESS) { 372645916cd2Sjpk __s_cvt_freeEntryRdn(entry, rdn); 372745916cd2Sjpk return (rc); 372845916cd2Sjpk } 372945916cd2Sjpk 373045916cd2Sjpk return (NS_LDAP_SUCCESS); 373145916cd2Sjpk } 37327c478bd9Sstevel@tonic-gate /* 37337c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion data structures 37347c478bd9Sstevel@tonic-gate */ 37357c478bd9Sstevel@tonic-gate 37367c478bd9Sstevel@tonic-gate typedef struct __ns_cvt_type { 37377c478bd9Sstevel@tonic-gate const char *service; 37387c478bd9Sstevel@tonic-gate int flags; 37397c478bd9Sstevel@tonic-gate #define AE 1 /* alway add entries */ 37407c478bd9Sstevel@tonic-gate int (*cvt_rtn)(const void *data, 37417c478bd9Sstevel@tonic-gate char **rdn, 37427c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, 37437c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp); 37447c478bd9Sstevel@tonic-gate } __ns_cvt_type_t; 37457c478bd9Sstevel@tonic-gate 37467c478bd9Sstevel@tonic-gate static __ns_cvt_type_t __s_cvtlist[] = { 37477c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PASSWD, 0, __s_cvt_passwd }, 37487c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_GROUP, 0, __s_cvt_group }, 37497c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_HOSTS, 0, __s_cvt_hosts }, 37507c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_IPNODES, 0, __s_cvt_hosts }, 37517c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_RPC, 0, __s_cvt_rpc }, 37527c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROTOCOLS, 0, __s_cvt_protocols }, 37537c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETWORKS, 0, __s_cvt_networks }, 37547c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETGROUP, 0, __s_cvt_netgroups }, 37557c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ALIASES, 0, __s_cvt_aliases }, 37567c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SERVICES, 0, __s_cvt_services }, 37577c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ETHERS, 0, __s_cvt_ethers }, 37587c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SHADOW, 0, __s_cvt_shadow }, 37597c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETMASKS, 0, __s_cvt_netmasks }, 37607c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_BOOTPARAMS, 0, __s_cvt_bootparams }, 37617c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTHATTR, 0, __s_cvt_authattr }, 37627c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_EXECATTR, 0, __s_cvt_execattr }, 37637c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROFILE, 0, __s_cvt_profattr }, 37647c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_USERATTR, AE, __s_cvt_userattr }, 37657c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTOMOUNT, 0, __s_cvt_auto_mount }, 37667c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PUBLICKEY, AE, __s_cvt_publickey }, 37677c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUUSER, AE, __s_cvt_audituser }, 376845916cd2Sjpk { NS_LDAP_TYPE_TNRHTP, 0, __s_cvt_tnrhtp }, 376945916cd2Sjpk { NS_LDAP_TYPE_TNRHDB, 0, __s_cvt_tnrhdb }, 3770e1dd0a2fSth { NS_LDAP_TYPE_PROJECT, 0, __s_cvt_project }, 37717c478bd9Sstevel@tonic-gate { NULL, 0, NULL }, 37727c478bd9Sstevel@tonic-gate }; 37737c478bd9Sstevel@tonic-gate 37747c478bd9Sstevel@tonic-gate /* 37757c478bd9Sstevel@tonic-gate * Add Typed Entry Routine 37767c478bd9Sstevel@tonic-gate */ 37777c478bd9Sstevel@tonic-gate 37787c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 37797c478bd9Sstevel@tonic-gate int __ns_ldap_addTypedEntry( 37807c478bd9Sstevel@tonic-gate const char *servicetype, 37817c478bd9Sstevel@tonic-gate const char *basedn, 37827c478bd9Sstevel@tonic-gate const void *data, 37837c478bd9Sstevel@tonic-gate const int create, 37847c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 37857c478bd9Sstevel@tonic-gate const int flags, 37867c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 37877c478bd9Sstevel@tonic-gate { 37887c478bd9Sstevel@tonic-gate char *rdn = NULL, *fulldn = NULL; 37897c478bd9Sstevel@tonic-gate void **paramVal = NULL; 3790*91b658d3SToomas Soome ns_ldap_entry_t *entry = NULL; 37917c478bd9Sstevel@tonic-gate const ns_ldap_attr_t *const *modattrlist; 37927c478bd9Sstevel@tonic-gate ns_ldap_search_desc_t **sdlist; 37937c478bd9Sstevel@tonic-gate char **dns = NULL; 37947c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 37957c478bd9Sstevel@tonic-gate char service[BUFSIZE]; 37967c478bd9Sstevel@tonic-gate int rc = 0; 37977c478bd9Sstevel@tonic-gate int automount = 0; 37987c478bd9Sstevel@tonic-gate int i, s; 37997c478bd9Sstevel@tonic-gate 38007c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 38017c478bd9Sstevel@tonic-gate for (s = 0; __s_cvtlist[s].service != NULL; s++) { 38027c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].cvt_rtn == NULL) 38037c478bd9Sstevel@tonic-gate continue; 38047c478bd9Sstevel@tonic-gate if (strcasecmp(__s_cvtlist[s].service, servicetype) == 0) 38057c478bd9Sstevel@tonic-gate break; 38067c478bd9Sstevel@tonic-gate /* Or, check if the servicetype is auto_ */ 38077c478bd9Sstevel@tonic-gate if (strcmp(__s_cvtlist[s].service, 38087c478bd9Sstevel@tonic-gate NS_LDAP_TYPE_AUTOMOUNT) == 0 && 38097c478bd9Sstevel@tonic-gate strncasecmp(servicetype, NS_LDAP_TYPE_AUTOMOUNT, 38107c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) { 38117c478bd9Sstevel@tonic-gate automount++; 38127c478bd9Sstevel@tonic-gate break; 38137c478bd9Sstevel@tonic-gate } 38147c478bd9Sstevel@tonic-gate } 38157c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].service == NULL) 38167c478bd9Sstevel@tonic-gate return (rc); 38177c478bd9Sstevel@tonic-gate 38187c478bd9Sstevel@tonic-gate /* Convert the data */ 38197c478bd9Sstevel@tonic-gate rc = (*__s_cvtlist[s].cvt_rtn)(data, &rdn, &entry, errorp); 38207c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 38217c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38227c478bd9Sstevel@tonic-gate return (rc); 38237c478bd9Sstevel@tonic-gate } 38247c478bd9Sstevel@tonic-gate if (rdn == NULL) { 38257c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(entry); 38267c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 38277c478bd9Sstevel@tonic-gate } 38287c478bd9Sstevel@tonic-gate 38297c478bd9Sstevel@tonic-gate if (strcmp(servicetype, "publickey") == 0) { 38307c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 38317c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 38327c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_TRUE) 38337c478bd9Sstevel@tonic-gate (void) strcpy(service, "hosts"); 38347c478bd9Sstevel@tonic-gate else 38357c478bd9Sstevel@tonic-gate (void) strcpy(service, "passwd"); 38367c478bd9Sstevel@tonic-gate } else 38377c478bd9Sstevel@tonic-gate (void) strcpy(service, servicetype); 38387c478bd9Sstevel@tonic-gate 38397c478bd9Sstevel@tonic-gate /* Create the Full DN */ 38407c478bd9Sstevel@tonic-gate if (basedn == NULL) { 38417c478bd9Sstevel@tonic-gate rc = __s_api_get_SSD_from_SSDtoUse_service(service, 38427c478bd9Sstevel@tonic-gate &sdlist, errorp); 38437c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 38447c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38457c478bd9Sstevel@tonic-gate return (rc); 38467c478bd9Sstevel@tonic-gate } 38477c478bd9Sstevel@tonic-gate 38487c478bd9Sstevel@tonic-gate if (sdlist == NULL) { 38497c478bd9Sstevel@tonic-gate rc = __s_api_getDNs(&dns, service, errorp); 38507c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 38517c478bd9Sstevel@tonic-gate if (dns) { 38527c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 38537c478bd9Sstevel@tonic-gate dns = NULL; 38547c478bd9Sstevel@tonic-gate } 38557c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38567c478bd9Sstevel@tonic-gate return (rc); 38577c478bd9Sstevel@tonic-gate } 38587c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", rdn, dns[0]); 38597c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 38607c478bd9Sstevel@tonic-gate } else { 38617c478bd9Sstevel@tonic-gate if (sdlist[0]->basedn) { 38627c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", 38637c478bd9Sstevel@tonic-gate rdn, sdlist[0]->basedn); 38647c478bd9Sstevel@tonic-gate } else { 38657c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38667c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 38677c478bd9Sstevel@tonic-gate } 38687c478bd9Sstevel@tonic-gate } 38697c478bd9Sstevel@tonic-gate i = strlen(trdn) - 1; 38707c478bd9Sstevel@tonic-gate if (trdn[i] == COMMATOK) { 38717c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 38727c478bd9Sstevel@tonic-gate ¶mVal, errorp); 38737c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 38747c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38757c478bd9Sstevel@tonic-gate return (rc); 38767c478bd9Sstevel@tonic-gate } 38777c478bd9Sstevel@tonic-gate i = strlen(trdn) + strlen((char *)(paramVal[0])) + 1; 38787c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 38797c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 38807c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 38817c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 38837c478bd9Sstevel@tonic-gate } 38847c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s%s", trdn, 38857c478bd9Sstevel@tonic-gate (char *)(paramVal[0])); 38867c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 38877c478bd9Sstevel@tonic-gate } else { 38887c478bd9Sstevel@tonic-gate fulldn = strdup(trdn); 38897c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 38907c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38917c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 38927c478bd9Sstevel@tonic-gate } 38937c478bd9Sstevel@tonic-gate } 38947c478bd9Sstevel@tonic-gate } else { 38957c478bd9Sstevel@tonic-gate i = strlen(rdn) + strlen(basedn) + 2; 38967c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 38977c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 38987c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 38997c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 39007c478bd9Sstevel@tonic-gate } 39017c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s,%s", rdn, basedn); 39027c478bd9Sstevel@tonic-gate } 39037c478bd9Sstevel@tonic-gate 39047c478bd9Sstevel@tonic-gate modattrlist = (const ns_ldap_attr_t * const *)entry->attr_pair; 39057c478bd9Sstevel@tonic-gate /* Check to see if the entry exists already */ 39067c478bd9Sstevel@tonic-gate /* May need to delete or update first */ 39077c478bd9Sstevel@tonic-gate 39087c478bd9Sstevel@tonic-gate if (create != 1) { 39097c478bd9Sstevel@tonic-gate /* Modify the entry */ 391012fbe00aSjs /* 391112fbe00aSjs * To add a shadow-like entry, the addTypedEntry function 391212fbe00aSjs * would call __ns_ldap_repAttr first, and if server says 391312fbe00aSjs * LDAP_NO_SUCH_OBJECT, then it tries __ns_ldap_addEntry. 391412fbe00aSjs * This is to allow a netmask entry to be added even if the 391512fbe00aSjs * base network entry is not in the directory. It would work 391612fbe00aSjs * because the difference between the schema for the network 391712fbe00aSjs * and netmask data contains only MAY attributes. 391812fbe00aSjs * 391912fbe00aSjs * But for shadow data, the attributes do not have MUST 392012fbe00aSjs * attributes the base entry needs, so if the __ns_ldap_addEntry 392112fbe00aSjs * is executed, it would fail. The real reason, however, is that 392212fbe00aSjs * the base entry did not exist. So returning 392312fbe00aSjs * LDAP_OBJECT_CLASS_VIOLATION would just confused. 392412fbe00aSjs */ 39257c478bd9Sstevel@tonic-gate if ((__s_cvtlist[s].flags & AE) != 0) 39267c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, modattrlist, 39277c478bd9Sstevel@tonic-gate cred, flags, errorp); 39287c478bd9Sstevel@tonic-gate else { 39297c478bd9Sstevel@tonic-gate rc = __ns_ldap_repAttr(service, fulldn, modattrlist, 3930e1dd0a2fSth cred, flags, errorp); 39317c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 39327c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_NO_SUCH_OBJECT) { 39337c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 39347c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, 39357c478bd9Sstevel@tonic-gate entry, cred, flags, errorp); 393612fbe00aSjs if (rc == NS_LDAP_INTERNAL && *errorp && 3937e1dd0a2fSth (*errorp)->status == 3938e1dd0a2fSth LDAP_OBJECT_CLASS_VIOLATION) 393912fbe00aSjs (*errorp)->status = LDAP_NO_SUCH_OBJECT; 39407c478bd9Sstevel@tonic-gate } 39417c478bd9Sstevel@tonic-gate } 39427c478bd9Sstevel@tonic-gate } else { 39437c478bd9Sstevel@tonic-gate /* Add the entry */ 39447c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, entry, 39457c478bd9Sstevel@tonic-gate cred, flags, errorp); 39467c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 39477c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_ALREADY_EXISTS && 39487c478bd9Sstevel@tonic-gate ((strcmp(service, "ethers") == 0) || 39497c478bd9Sstevel@tonic-gate (strcmp(service, "bootparams") == 0))) { 39507c478bd9Sstevel@tonic-gate rc = modify_ethers_bootp(service, rdn, fulldn, 39517c478bd9Sstevel@tonic-gate modattrlist, cred, flags, errorp); 39527c478bd9Sstevel@tonic-gate } 39537c478bd9Sstevel@tonic-gate } 39547c478bd9Sstevel@tonic-gate 39557c478bd9Sstevel@tonic-gate /* Free up entry created by conversion routine */ 39567c478bd9Sstevel@tonic-gate if (fulldn != NULL) 39577c478bd9Sstevel@tonic-gate free(fulldn); 39587c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 39597c478bd9Sstevel@tonic-gate return (rc); 39607c478bd9Sstevel@tonic-gate } 39617c478bd9Sstevel@tonic-gate 39627c478bd9Sstevel@tonic-gate 39637c478bd9Sstevel@tonic-gate /* 39647c478bd9Sstevel@tonic-gate * Append the default base dn to the dn 39657c478bd9Sstevel@tonic-gate * when it ends with ','. 39667c478bd9Sstevel@tonic-gate * e.g. 39677c478bd9Sstevel@tonic-gate * SSD = service:ou=foo, 39687c478bd9Sstevel@tonic-gate */ 39697c478bd9Sstevel@tonic-gate int 3970*91b658d3SToomas Soome __s_api_append_default_basedn(const char *dn, char **new_dn, int *allocated, 3971*91b658d3SToomas Soome ns_ldap_error_t **errp) 3972*91b658d3SToomas Soome { 39737c478bd9Sstevel@tonic-gate 39747c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS, len = 0; 39757c478bd9Sstevel@tonic-gate void **param = NULL; 39767c478bd9Sstevel@tonic-gate char *str = NULL; 39777c478bd9Sstevel@tonic-gate 39787c478bd9Sstevel@tonic-gate *allocated = FALSE; 39797c478bd9Sstevel@tonic-gate *new_dn = NULL; 39807c478bd9Sstevel@tonic-gate 39817c478bd9Sstevel@tonic-gate if (dn == NULL) 39827c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 39837c478bd9Sstevel@tonic-gate 39847c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 3985*91b658d3SToomas Soome (void ***)¶m, errp); 39867c478bd9Sstevel@tonic-gate 39877c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 39887c478bd9Sstevel@tonic-gate if (param) 39897c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 39907c478bd9Sstevel@tonic-gate return (rc); 39917c478bd9Sstevel@tonic-gate } 39927c478bd9Sstevel@tonic-gate 39937c478bd9Sstevel@tonic-gate len = strlen(dn); 39947c478bd9Sstevel@tonic-gate str = ((char **)param)[0]; 39957c478bd9Sstevel@tonic-gate len = len + strlen(str) +1; 39967c478bd9Sstevel@tonic-gate *new_dn = (char *)malloc(len); 39977c478bd9Sstevel@tonic-gate if (*new_dn == NULL) { 39987c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 39997c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 40007c478bd9Sstevel@tonic-gate } 40017c478bd9Sstevel@tonic-gate *allocated = TRUE; 40027c478bd9Sstevel@tonic-gate 40037c478bd9Sstevel@tonic-gate (void) strcpy(*new_dn, dn); 40047c478bd9Sstevel@tonic-gate (void) strcat(*new_dn, str); 40057c478bd9Sstevel@tonic-gate 40067c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 40077c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 40087c478bd9Sstevel@tonic-gate } 4009dd1104fbSMichen Chang 4010dd1104fbSMichen Chang /* 4011dd1104fbSMichen Chang * Flatten the input ns_ldap_attr_t list, 'attr', and convert it into an 4012dd1104fbSMichen Chang * ldap_strlist_t structure in buffer 'buf', to be used by ldap_cachemgr. 4013dd1104fbSMichen Chang * The output contains a count, a list of offsets, which show where the 4014dd1104fbSMichen Chang * corresponding copied attribute type and attribute value are located. 4015dd1104fbSMichen Chang * For example, for dn=aaaa, userpassword=bbbb, shadowlastchange=cccc, 4016dd1104fbSMichen Chang * the output is the ldap_strlist_t structure with: ldap_count = 6, 4017dd1104fbSMichen Chang * (buf + ldap_offsets[0]) -> "dn" 4018dd1104fbSMichen Chang * (buf + ldap_offsets[1]) -> "aaaa" 4019dd1104fbSMichen Chang * (buf + ldap_offsets[2]) -> "userPassword" 4020dd1104fbSMichen Chang * (buf + ldap_offsets[3]) -> "bbbb" 4021dd1104fbSMichen Chang * (buf + ldap_offsets[4]) -> "shadowlastchange" 4022dd1104fbSMichen Chang * (buf + ldap_offsets[5]) -> "cccc" 4023dd1104fbSMichen Chang * and all the string data shown above copied into the buffer after 4024dd1104fbSMichen Chang * the offset array. The total length of the data will be the return 4025dd1104fbSMichen Chang * value, or -1 if error. 4026dd1104fbSMichen Chang */ 4027dd1104fbSMichen Chang static int 4028dd1104fbSMichen Chang attr2list(const char *dn, ns_ldap_attr_t **attr, 4029dd1104fbSMichen Chang char *buf, int bufsize) 4030dd1104fbSMichen Chang { 4031dd1104fbSMichen Chang int c = 0; 4032dd1104fbSMichen Chang char *ap; 4033dd1104fbSMichen Chang int ao; 4034dd1104fbSMichen Chang ldap_strlist_t *al = (ldap_strlist_t *)buf; 4035dd1104fbSMichen Chang ns_ldap_attr_t *a = (ns_ldap_attr_t *)*attr; 4036dd1104fbSMichen Chang ns_ldap_attr_t **aptr = (ns_ldap_attr_t **)attr; 4037dd1104fbSMichen Chang 4038dd1104fbSMichen Chang /* bufsize > strlen(dn) + strlen("dn") + 1 ('\0') */ 4039dd1104fbSMichen Chang if ((strlen(dn) + 2 + 1) >= bufsize) 4040dd1104fbSMichen Chang return (-1); 4041dd1104fbSMichen Chang 4042dd1104fbSMichen Chang /* count number of attributes */ 4043dd1104fbSMichen Chang while (*aptr++) 4044dd1104fbSMichen Chang c++; 4045dd1104fbSMichen Chang al->ldap_count = 2 + c * 2; 4046dd1104fbSMichen Chang ao = sizeof (al->ldap_count) + sizeof (al->ldap_offsets[0]) * 4047dd1104fbSMichen Chang al->ldap_count; 4048dd1104fbSMichen Chang if (ao > bufsize) 4049dd1104fbSMichen Chang return (-1); 4050dd1104fbSMichen Chang al->ldap_offsets[0] = ao; 4051dd1104fbSMichen Chang ap = buf + ao; 4052dd1104fbSMichen Chang ao += 3; 4053dd1104fbSMichen Chang 4054dd1104fbSMichen Chang /* copy entry DN */ 4055dd1104fbSMichen Chang if (ao > bufsize) 4056dd1104fbSMichen Chang return (-1); 4057dd1104fbSMichen Chang (void) strlcpy(ap, "dn", bufsize); 4058dd1104fbSMichen Chang ap += 3; 4059dd1104fbSMichen Chang 4060dd1104fbSMichen Chang al->ldap_offsets[1] = ao; 4061dd1104fbSMichen Chang ao += strlen(dn) + 1; 4062dd1104fbSMichen Chang if (ao > bufsize) 4063dd1104fbSMichen Chang return (-1); 4064dd1104fbSMichen Chang (void) strlcpy(ap, dn, bufsize); 4065dd1104fbSMichen Chang ap = buf + ao; 4066dd1104fbSMichen Chang 4067dd1104fbSMichen Chang aptr = attr; 4068dd1104fbSMichen Chang for (c = 2; c < al->ldap_count; c++, aptr++) { 4069dd1104fbSMichen Chang a = *aptr; 4070dd1104fbSMichen Chang if (a->attrname == NULL || a->attrvalue == NULL || 4071dd1104fbSMichen Chang a->value_count != 1 || a->attrvalue[0] == NULL) 4072dd1104fbSMichen Chang return (-1); 4073dd1104fbSMichen Chang al->ldap_offsets[c] = ao; 4074dd1104fbSMichen Chang ao += strlen(a->attrname) + 1; 4075dd1104fbSMichen Chang if (ao > bufsize) 4076dd1104fbSMichen Chang return (-1); 4077dd1104fbSMichen Chang (void) strlcpy(ap, a->attrname, bufsize); 4078dd1104fbSMichen Chang ap = buf + ao; 4079dd1104fbSMichen Chang 4080dd1104fbSMichen Chang c++; 4081dd1104fbSMichen Chang al->ldap_offsets[c] = ao; 4082dd1104fbSMichen Chang ao += strlen(a->attrvalue[0]) + 1; 4083dd1104fbSMichen Chang (void) strlcpy(ap, a->attrvalue[0], bufsize); 4084dd1104fbSMichen Chang ap = buf + ao; 4085dd1104fbSMichen Chang }; 4086dd1104fbSMichen Chang 4087dd1104fbSMichen Chang return (ao); 4088dd1104fbSMichen Chang } 4089dd1104fbSMichen Chang 4090dd1104fbSMichen Chang /* 4091dd1104fbSMichen Chang * Send a modify request to the ldap_cachemgr daemon 4092dd1104fbSMichen Chang * which will use the admin credential to perform the 4093dd1104fbSMichen Chang * operation. 4094dd1104fbSMichen Chang */ 4095dd1104fbSMichen Chang 4096dd1104fbSMichen Chang static int 4097dd1104fbSMichen Chang send_to_cachemgr( 4098dd1104fbSMichen Chang const char *dn, 4099dd1104fbSMichen Chang ns_ldap_attr_t **attr, 4100dd1104fbSMichen Chang ns_ldap_error_t **errorp) 4101dd1104fbSMichen Chang { 4102dd1104fbSMichen Chang union { 4103dd1104fbSMichen Chang ldap_data_t s_d; 4104dd1104fbSMichen Chang char s_b[DOORBUFFERSIZE]; 4105dd1104fbSMichen Chang } space; 4106dd1104fbSMichen Chang 4107dd1104fbSMichen Chang ldap_data_t *sptr; 4108dd1104fbSMichen Chang int ndata; 4109dd1104fbSMichen Chang int adata; 4110dd1104fbSMichen Chang int len; 4111dd1104fbSMichen Chang int rc; 4112dd1104fbSMichen Chang char errstr[MAXERROR]; 4113dd1104fbSMichen Chang ldap_admin_mod_result_t *admin_result; 4114dd1104fbSMichen Chang 4115dd1104fbSMichen Chang *errorp = NULL; 4116dd1104fbSMichen Chang (void) memset(space.s_b, 0, DOORBUFFERSIZE); 4117dd1104fbSMichen Chang len = attr2list(dn, attr, (char *)&space.s_d.ldap_call.ldap_u.strlist, 4118dd1104fbSMichen Chang sizeof (space) - offsetof(ldap_return_t, ldap_u)); 4119dd1104fbSMichen Chang if (len <= 0) 4120dd1104fbSMichen Chang return (NS_LDAP_INVALID_PARAM); 4121dd1104fbSMichen Chang 4122dd1104fbSMichen Chang adata = sizeof (ldap_call_t) + len; 4123dd1104fbSMichen Chang ndata = sizeof (space); 4124dd1104fbSMichen Chang space.s_d.ldap_call.ldap_callnumber = ADMINMODIFY; 4125dd1104fbSMichen Chang sptr = &space.s_d; 4126dd1104fbSMichen Chang 4127dd1104fbSMichen Chang switch (__ns_ldap_trydoorcall(&sptr, &ndata, &adata)) { 4128dd1104fbSMichen Chang case NS_CACHE_SUCCESS: 4129dd1104fbSMichen Chang break; 4130dd1104fbSMichen Chang case NS_CACHE_NOTFOUND: 4131dd1104fbSMichen Chang (void) snprintf(errstr, sizeof (errstr), 4132dd1104fbSMichen Chang gettext("Door call ADMINMODIFY to " 4133dd1104fbSMichen Chang "ldap_cachemgr failed - error: %d"), 4134dd1104fbSMichen Chang space.s_d.ldap_ret.ldap_errno); 4135dd1104fbSMichen Chang MKERROR(LOG_WARNING, *errorp, NS_CONFIG_CACHEMGR, 4136dd1104fbSMichen Chang strdup(errstr), NULL); 4137dd1104fbSMichen Chang return (NS_LDAP_OP_FAILED); 4138dd1104fbSMichen Chang default: 4139dd1104fbSMichen Chang return (NS_LDAP_OP_FAILED); 4140dd1104fbSMichen Chang } 4141dd1104fbSMichen Chang 4142dd1104fbSMichen Chang admin_result = &sptr->ldap_ret.ldap_u.admin_result; 4143dd1104fbSMichen Chang if (admin_result->ns_err == NS_LDAP_SUCCESS) 4144dd1104fbSMichen Chang rc = NS_LDAP_SUCCESS; 4145dd1104fbSMichen Chang else { 4146dd1104fbSMichen Chang rc = admin_result->ns_err; 4147dd1104fbSMichen Chang if (admin_result->msg_size == 0) 4148dd1104fbSMichen Chang *errorp = __s_api_make_error(admin_result->status, 4149dd1104fbSMichen Chang NULL); 4150dd1104fbSMichen Chang else 4151dd1104fbSMichen Chang *errorp = __s_api_make_error(admin_result->status, 4152dd1104fbSMichen Chang admin_result->msg); 4153dd1104fbSMichen Chang } 4154dd1104fbSMichen Chang 4155dd1104fbSMichen Chang /* clean up the door call */ 4156dd1104fbSMichen Chang if (sptr != &space.s_d) { 4157dd1104fbSMichen Chang (void) munmap((char *)sptr, ndata); 4158dd1104fbSMichen Chang } 4159dd1104fbSMichen Chang 4160dd1104fbSMichen Chang return (rc); 4161dd1104fbSMichen Chang } 4162