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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237d575517Ssdussud * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <stdlib.h> 327c478bd9Sstevel@tonic-gate #include <libintl.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/stat.h> 357c478bd9Sstevel@tonic-gate #include <fcntl.h> 367c478bd9Sstevel@tonic-gate #include <unistd.h> 377c478bd9Sstevel@tonic-gate #include <string.h> 387c478bd9Sstevel@tonic-gate #include <strings.h> 397c478bd9Sstevel@tonic-gate #include <lber.h> 407c478bd9Sstevel@tonic-gate #include <ldap.h> 417c478bd9Sstevel@tonic-gate #include <syslog.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include "ns_sldap.h" 447c478bd9Sstevel@tonic-gate #include "ns_internal.h" 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* Additional headers for addTypedEntry Conversion routines */ 477c478bd9Sstevel@tonic-gate #include <pwd.h> 487c478bd9Sstevel@tonic-gate #include <shadow.h> 497c478bd9Sstevel@tonic-gate #include <grp.h> 507c478bd9Sstevel@tonic-gate #include <netinet/in.h> 517c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 527c478bd9Sstevel@tonic-gate #include <netdb.h> 537c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h> 547c478bd9Sstevel@tonic-gate #include <auth_attr.h> 557c478bd9Sstevel@tonic-gate #include <exec_attr.h> 567c478bd9Sstevel@tonic-gate #include <prof_attr.h> 577c478bd9Sstevel@tonic-gate #include <user_attr.h> 587c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * If the rdn is a mapped attr: 637c478bd9Sstevel@tonic-gate * return NS_LDAP_SUCCESS and a new_dn. 647c478bd9Sstevel@tonic-gate * If no mapped attr is found in the rdn: 657c478bd9Sstevel@tonic-gate * return NS_LDAP_SUCCESS and *new_dn == NULL 667c478bd9Sstevel@tonic-gate * For example: 677c478bd9Sstevel@tonic-gate * service = abc 687c478bd9Sstevel@tonic-gate * dn = cn=foo,dc=bar,dc=com 697c478bd9Sstevel@tonic-gate * attributeMapping: abc:cn=sn 707c478bd9Sstevel@tonic-gate * Then: 717c478bd9Sstevel@tonic-gate * new_dn = sn=foo,dc=bar,dc=com 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate static int 757c478bd9Sstevel@tonic-gate replace_mapped_attr_in_dn( 767c478bd9Sstevel@tonic-gate const char *service, const char *dn, char **new_dn) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate char **mappedattr; 797c478bd9Sstevel@tonic-gate char **dnArray = NULL; 807c478bd9Sstevel@tonic-gate char *rservice; 817c478bd9Sstevel@tonic-gate char *cur = NULL; 827c478bd9Sstevel@tonic-gate int len = 0, orig_len = 0, mapped_len = 0; 837c478bd9Sstevel@tonic-gate int dn_len = 0; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate *new_dn = NULL; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * seperate dn into individual componets 897c478bd9Sstevel@tonic-gate * e.g. 907c478bd9Sstevel@tonic-gate * "automountKey=user_01" , "automountMapName_test=auto_home", ... 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate dnArray = ldap_explode_dn(dn, 0); 937c478bd9Sstevel@tonic-gate if (!dnArray || !*dnArray) 947c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate cur = strchr(dnArray[0], '='); 977c478bd9Sstevel@tonic-gate if (!cur) { 987c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 997c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate *cur = '\0'; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* we only check schema mapping for automount, not for auto_* */ 1047c478bd9Sstevel@tonic-gate if (strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT, 1057c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) 1067c478bd9Sstevel@tonic-gate rservice = "automount"; 1077c478bd9Sstevel@tonic-gate else 1087c478bd9Sstevel@tonic-gate rservice = (char *)service; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate mappedattr = __ns_ldap_getMappedAttributes(rservice, dnArray[0]); 1117c478bd9Sstevel@tonic-gate if (!mappedattr || !mappedattr[0]) { 1127c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1137c478bd9Sstevel@tonic-gate if (mappedattr) 1147c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1157c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate orig_len = strlen(dnArray[0]); 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * The new length is *dn length + (difference between 1217c478bd9Sstevel@tonic-gate * orig attr and mapped attr) + 1 ; 1227c478bd9Sstevel@tonic-gate * e.g. 1237c478bd9Sstevel@tonic-gate * automountKey=aa,automountMapName=auto_home,dc=foo,dc=com 1247c478bd9Sstevel@tonic-gate * ==> 1257c478bd9Sstevel@tonic-gate * cn=aa,automountMapName=auto_home,dc=foo,dc=com 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate mapped_len = strlen(mappedattr[0]); 1287c478bd9Sstevel@tonic-gate dn_len = strlen(dn); 1297c478bd9Sstevel@tonic-gate len = dn_len - orig_len + mapped_len + 1; 1307c478bd9Sstevel@tonic-gate *new_dn = (char *)calloc(1, len); 1317c478bd9Sstevel@tonic-gate if (*new_dn == NULL) { 1327c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1337c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1347c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate (void) snprintf(*new_dn, len, "%s=%s", mappedattr[0], dn + orig_len +1); 1387c478bd9Sstevel@tonic-gate __s_api_free2dArray(dnArray); 1397c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedattr); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * The following function is only used by the 1477c478bd9Sstevel@tonic-gate * "gecos" 1 to N attribute mapping code. It expects 1487c478bd9Sstevel@tonic-gate * and handle only one data/length pair. 1497c478bd9Sstevel@tonic-gate */ 1507c478bd9Sstevel@tonic-gate static int 1517c478bd9Sstevel@tonic-gate init_bval_mod( 1527c478bd9Sstevel@tonic-gate LDAPMod *mod, 1537c478bd9Sstevel@tonic-gate int mop, 1547c478bd9Sstevel@tonic-gate char *mtype, 1557c478bd9Sstevel@tonic-gate char *mvptr, 1567c478bd9Sstevel@tonic-gate int mvlen) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate struct berval **bmodval; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* dup attribute name */ 1627c478bd9Sstevel@tonic-gate mod->mod_type = strdup(mtype); 1637c478bd9Sstevel@tonic-gate if (mod->mod_type == NULL) 1647c478bd9Sstevel@tonic-gate return (-1); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * assume single value, 1687c478bd9Sstevel@tonic-gate * since only one value/length pair passed in 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate bmodval = (struct berval **)calloc(2, 1717c478bd9Sstevel@tonic-gate sizeof (struct berval *)); 1727c478bd9Sstevel@tonic-gate if (bmodval == NULL) { 1737c478bd9Sstevel@tonic-gate free(mod->mod_type); 1747c478bd9Sstevel@tonic-gate mod->mod_type = NULL; 1757c478bd9Sstevel@tonic-gate return (-1); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate bmodval[0] = (struct berval *)calloc(1, 1787c478bd9Sstevel@tonic-gate sizeof (struct berval)); 1797c478bd9Sstevel@tonic-gate if (bmodval[0] == NULL) { 1807c478bd9Sstevel@tonic-gate free(mod->mod_type); 1817c478bd9Sstevel@tonic-gate mod->mod_type = NULL; 1827c478bd9Sstevel@tonic-gate free(bmodval); 1837c478bd9Sstevel@tonic-gate return (-1); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* set pointer to data */ 1877c478bd9Sstevel@tonic-gate bmodval[0]->bv_val = mvptr; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* set length */ 1907c478bd9Sstevel@tonic-gate bmodval[0]->bv_len = mvlen; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * turn on the BVALUE bit to indicate 1947c478bd9Sstevel@tonic-gate * that the length of data is supplied 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate mod->mod_op = mop | LDAP_MOD_BVALUES; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate mod->mod_bvalues = bmodval; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate return (0); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate static void 2047c478bd9Sstevel@tonic-gate freeModList(LDAPMod **mods) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate int i, j; 2077c478bd9Sstevel@tonic-gate int name_is_oc; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate if (mods == NULL) 2107c478bd9Sstevel@tonic-gate return; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate for (i = 0; mods[i]; i++) { 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* free attribute name */ 2157c478bd9Sstevel@tonic-gate name_is_oc = FALSE; 2167c478bd9Sstevel@tonic-gate if (mods[i]->mod_type) { 2177c478bd9Sstevel@tonic-gate if (strcasecmp(mods[i]->mod_type, 2187c478bd9Sstevel@tonic-gate "objectclass") == 0) 2197c478bd9Sstevel@tonic-gate name_is_oc = TRUE; 2207c478bd9Sstevel@tonic-gate free(mods[i]->mod_type); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate if (mods[i]->mod_bvalues == NULL) 2247c478bd9Sstevel@tonic-gate continue; 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * LDAP_MOD_BVALUES is only set by 2277c478bd9Sstevel@tonic-gate * the "gecos" 1 to N attribute mapping 2287c478bd9Sstevel@tonic-gate * code, and the attribute is single valued. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate if (mods[i]->mod_op & LDAP_MOD_BVALUES) { 2317c478bd9Sstevel@tonic-gate if (mods[i]->mod_bvalues[0]) 2327c478bd9Sstevel@tonic-gate free(mods[i]->mod_bvalues[0]); 2337c478bd9Sstevel@tonic-gate } else { 2347c478bd9Sstevel@tonic-gate if (name_is_oc) { 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * only values for the "objectclass" 2377c478bd9Sstevel@tonic-gate * were dupped using strdup. 2387c478bd9Sstevel@tonic-gate * other attribute values were 2397c478bd9Sstevel@tonic-gate * not dupped, but via pointer 2407c478bd9Sstevel@tonic-gate * assignment. So here the 2417c478bd9Sstevel@tonic-gate * values for "objectclass" 2427c478bd9Sstevel@tonic-gate * is freed one by one, 2437c478bd9Sstevel@tonic-gate * but the values for other 2447c478bd9Sstevel@tonic-gate * attributes need not be freed. 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate for (j = 0; mods[i]->mod_values[j]; j++) 2477c478bd9Sstevel@tonic-gate free(mods[i]->mod_values[j]); 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate free(mods[i]->mod_bvalues); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate /* modlist */ 2557c478bd9Sstevel@tonic-gate free((char *)(mods[0])); 2567c478bd9Sstevel@tonic-gate free(mods); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate static LDAPMod ** 2607c478bd9Sstevel@tonic-gate __s_api_makeModListCount( 2617c478bd9Sstevel@tonic-gate const char *service, 2627c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 2637c478bd9Sstevel@tonic-gate const int mod_op, 2647c478bd9Sstevel@tonic-gate const int count, 2657c478bd9Sstevel@tonic-gate const int flags) 2667c478bd9Sstevel@tonic-gate { 2677c478bd9Sstevel@tonic-gate LDAPMod **mods, *modlist; 2687c478bd9Sstevel@tonic-gate char **modval; 2697c478bd9Sstevel@tonic-gate char **mapping; 2707c478bd9Sstevel@tonic-gate int i; 2717c478bd9Sstevel@tonic-gate int j; 2727c478bd9Sstevel@tonic-gate int k, rc, vlen; 2737c478bd9Sstevel@tonic-gate char *c, *comma1 = NULL, *comma2 = NULL; 2747c478bd9Sstevel@tonic-gate int schema_mapping_existed = FALSE; 2757c478bd9Sstevel@tonic-gate int auto_service = FALSE; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * add 2 for "gecos" 1 to up to 3 attribute mapping 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate mods = (LDAPMod **)calloc((count + 3), sizeof (LDAPMod *)); 2827c478bd9Sstevel@tonic-gate if (mods == NULL) { 2837c478bd9Sstevel@tonic-gate return (NULL); 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * add 2 for "gecos" 1 to up to 3 attribute mapping 2877c478bd9Sstevel@tonic-gate */ 2887c478bd9Sstevel@tonic-gate modlist = (LDAPMod *)calloc(count + 2, sizeof (LDAPMod)); 2897c478bd9Sstevel@tonic-gate if (modlist == NULL) { 2907c478bd9Sstevel@tonic-gate free(mods); 2917c478bd9Sstevel@tonic-gate return (NULL); 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate if (service != NULL && strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT, 2957c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) 2967c478bd9Sstevel@tonic-gate auto_service = TRUE; 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* 2997c478bd9Sstevel@tonic-gate * see if schema mapping existed for the given service 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getOrigAttribute(service, 3027c478bd9Sstevel@tonic-gate NS_HASH_SCHEMA_MAPPING_EXISTED); 3037c478bd9Sstevel@tonic-gate if (mapping) { 3047c478bd9Sstevel@tonic-gate schema_mapping_existed = TRUE; 3057c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 3067c478bd9Sstevel@tonic-gate mapping = NULL; 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate for (i = 0, k = 0; k < count && attr[k] != NULL; i++, k++) { 3107c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 3117c478bd9Sstevel@tonic-gate mods[i]->mod_op = mod_op; 3127c478bd9Sstevel@tonic-gate /* 3137c478bd9Sstevel@tonic-gate * Perform attribute mapping if necessary. 3147c478bd9Sstevel@tonic-gate */ 3157c478bd9Sstevel@tonic-gate if (schema_mapping_existed && 3167c478bd9Sstevel@tonic-gate (flags & NS_LDAP_NOMAP) == 0) { 3177c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getMappedAttributes(service, 3187c478bd9Sstevel@tonic-gate attr[k]->attrname); 3197c478bd9Sstevel@tonic-gate } else 3207c478bd9Sstevel@tonic-gate mapping = NULL; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate if (mapping == NULL && auto_service && 3237c478bd9Sstevel@tonic-gate (flags & NS_LDAP_NOMAP) == 0) { 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * if service == auto_xxx and 3267c478bd9Sstevel@tonic-gate * no mapped attribute is found 3277c478bd9Sstevel@tonic-gate * and NS_LDAP_NOMAP is not set 3287c478bd9Sstevel@tonic-gate * then try automount's mapped attribute 3297c478bd9Sstevel@tonic-gate */ 3307c478bd9Sstevel@tonic-gate mapping = __ns_ldap_getMappedAttributes("automount", 3317c478bd9Sstevel@tonic-gate attr[k]->attrname); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate if (mapping == NULL) { 3357c478bd9Sstevel@tonic-gate mods[i]->mod_type = strdup(attr[k]->attrname); 3367c478bd9Sstevel@tonic-gate if (mods[i]->mod_type == NULL) { 3377c478bd9Sstevel@tonic-gate goto free_memory; 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate } else { 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * 1 to N attribute mapping is only done for "gecos", 3427c478bd9Sstevel@tonic-gate * and only 1 to 3 mapping. 3437c478bd9Sstevel@tonic-gate * nine cases here: 3447c478bd9Sstevel@tonic-gate * 3457c478bd9Sstevel@tonic-gate * A. attrMap=passwd:gecos=a 3467c478bd9Sstevel@tonic-gate * 1. gecos="xx,yy,zz" -> a="xx,yy,zz" 3477c478bd9Sstevel@tonic-gate * 2. gecos="xx,yy" -> a="xx,yy" 3487c478bd9Sstevel@tonic-gate * 3. gecos="xx" -> a="xx" 3497c478bd9Sstevel@tonic-gate * 3507c478bd9Sstevel@tonic-gate * B. attrMap=passwd:gecos=a b 3517c478bd9Sstevel@tonic-gate * 4. gecos="xx,yy,zz" -> a="xx" b="yy,zz" 3527c478bd9Sstevel@tonic-gate * 5. gecos="xx,yy" -> a="xx" b="yy" 3537c478bd9Sstevel@tonic-gate * 6. gecos="xx" -> a="xx" 3547c478bd9Sstevel@tonic-gate * 3557c478bd9Sstevel@tonic-gate * C. attrMap=passwd:gecos=a b c 3567c478bd9Sstevel@tonic-gate * 7. gecos="xx,yy,zz" -> a="xx" b="yy" c="zz" 3577c478bd9Sstevel@tonic-gate * 8. gecos="xx,yy" -> a="xx" b="yy" 3587c478bd9Sstevel@tonic-gate * 9. gecos="xx" -> a="xx" 3597c478bd9Sstevel@tonic-gate * 3607c478bd9Sstevel@tonic-gate * This can be grouped as: 3617c478bd9Sstevel@tonic-gate * 3627c478bd9Sstevel@tonic-gate * c1 cases: 1,2,3,6,9 3637c478bd9Sstevel@tonic-gate * if ((attrMap=passwd:gecos=a) || 3647c478bd9Sstevel@tonic-gate * (no "," in gecos value)) 3657c478bd9Sstevel@tonic-gate * same as other no-mapping attributes, 3667c478bd9Sstevel@tonic-gate * no special processing needed 3677c478bd9Sstevel@tonic-gate * else 3687c478bd9Sstevel@tonic-gate * 3697c478bd9Sstevel@tonic-gate * c2 cases: 4,5,8 3707c478bd9Sstevel@tonic-gate * if ((attrMap=passwd:gecos=a b) || 3717c478bd9Sstevel@tonic-gate * (only one "," in gecos value)) 3727c478bd9Sstevel@tonic-gate * a=xx b=yy[,...] 3737c478bd9Sstevel@tonic-gate * else 3747c478bd9Sstevel@tonic-gate * 3757c478bd9Sstevel@tonic-gate * c3 case: 7 3767c478bd9Sstevel@tonic-gate * a=xx b=yy c=... 3777c478bd9Sstevel@tonic-gate * 3787c478bd9Sstevel@tonic-gate * notes: in case c2 and c3, ... could still contain "," 3797c478bd9Sstevel@tonic-gate */ 3807c478bd9Sstevel@tonic-gate if (strcasecmp(service, "passwd") == 0 && 3817c478bd9Sstevel@tonic-gate strcasecmp(attr[k]->attrname, "gecos") == 0 && 3827c478bd9Sstevel@tonic-gate mapping[1] && attr[k]->attrvalue[0] && 3837c478bd9Sstevel@tonic-gate (comma1 = strchr(attr[k]->attrvalue[0], 3847c478bd9Sstevel@tonic-gate COMMATOK)) != NULL) { 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate /* is there a second comma? */ 3877c478bd9Sstevel@tonic-gate if (*(comma1 + 1) != '\0') 3887c478bd9Sstevel@tonic-gate comma2 = strchr(comma1 + 1, COMMATOK); 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* 3917c478bd9Sstevel@tonic-gate * Process case c2 or c3. 3927c478bd9Sstevel@tonic-gate * case c2: mapped to two attributes or just 3937c478bd9Sstevel@tonic-gate * one comma 3947c478bd9Sstevel@tonic-gate */ 3957c478bd9Sstevel@tonic-gate if (mapping[2] == NULL || 3967c478bd9Sstevel@tonic-gate comma2 == NULL) { 3977c478bd9Sstevel@tonic-gate /* case c2 */ 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate /* 4007c478bd9Sstevel@tonic-gate * int mod structure for the first attribute 4017c478bd9Sstevel@tonic-gate */ 4027c478bd9Sstevel@tonic-gate vlen = comma1 - attr[k]->attrvalue[0]; 4037c478bd9Sstevel@tonic-gate c = attr[k]->attrvalue[0]; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4067c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 4077c478bd9Sstevel@tonic-gate mapping[0], c, vlen); 4087c478bd9Sstevel@tonic-gate if (rc != 0) 4097c478bd9Sstevel@tonic-gate goto free_memory; 4107c478bd9Sstevel@tonic-gate } else { 4117c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4127c478bd9Sstevel@tonic-gate mods[i] = NULL; 4137c478bd9Sstevel@tonic-gate i--; 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate /* 4187c478bd9Sstevel@tonic-gate * init mod structure for the 2nd attribute 4197c478bd9Sstevel@tonic-gate */ 4207c478bd9Sstevel@tonic-gate if (*(comma1 + 1) == '\0') { 4217c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 4227c478bd9Sstevel@tonic-gate mapping = NULL; 4237c478bd9Sstevel@tonic-gate continue; 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate i++; 4277c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate /* 4307c478bd9Sstevel@tonic-gate * get pointer to data. 4317c478bd9Sstevel@tonic-gate * Skip leading spaces. 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate for (c = comma1 + 1; *c == SPACETOK; c++); 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* get data length */ 4367c478bd9Sstevel@tonic-gate vlen = strlen(attr[k]->attrvalue[0]) - 4377c478bd9Sstevel@tonic-gate (c - attr[k]->attrvalue[0]); 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4407c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 4417c478bd9Sstevel@tonic-gate mapping[1], c, vlen); 4427c478bd9Sstevel@tonic-gate if (rc != 0) 4437c478bd9Sstevel@tonic-gate goto free_memory; 4447c478bd9Sstevel@tonic-gate } else { 4457c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4467c478bd9Sstevel@tonic-gate mods[i] = NULL; 4477c478bd9Sstevel@tonic-gate i--; 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate /* done with the mapping array */ 4517c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 4527c478bd9Sstevel@tonic-gate mapping = NULL; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate continue; 4557c478bd9Sstevel@tonic-gate } else { 4567c478bd9Sstevel@tonic-gate /* case c3 */ 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * int mod structure for the first attribute 4607c478bd9Sstevel@tonic-gate */ 4617c478bd9Sstevel@tonic-gate vlen = comma1 - attr[k]->attrvalue[0]; 4627c478bd9Sstevel@tonic-gate c = attr[k]->attrvalue[0]; 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4657c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 4667c478bd9Sstevel@tonic-gate mapping[0], c, vlen); 4677c478bd9Sstevel@tonic-gate if (rc != 0) 4687c478bd9Sstevel@tonic-gate goto free_memory; 4697c478bd9Sstevel@tonic-gate } else { 4707c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4717c478bd9Sstevel@tonic-gate mods[i] = NULL; 4727c478bd9Sstevel@tonic-gate i--; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* 4767c478bd9Sstevel@tonic-gate * init mod structure for the 2nd attribute 4777c478bd9Sstevel@tonic-gate */ 4787c478bd9Sstevel@tonic-gate i++; 4797c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * get pointer to data. 4837c478bd9Sstevel@tonic-gate * Skip leading spaces. 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate for (c = comma1 + 1; *c == SPACETOK; c++); 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate /* get data length */ 4887c478bd9Sstevel@tonic-gate vlen = comma2 - c; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 4917c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 4927c478bd9Sstevel@tonic-gate mapping[1], c, vlen); 4937c478bd9Sstevel@tonic-gate if (rc != 0) 4947c478bd9Sstevel@tonic-gate goto free_memory; 4957c478bd9Sstevel@tonic-gate } else { 4967c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 4977c478bd9Sstevel@tonic-gate mods[i] = NULL; 4987c478bd9Sstevel@tonic-gate i--; 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * init mod structure for the 3rd attribute 5037c478bd9Sstevel@tonic-gate */ 5047c478bd9Sstevel@tonic-gate if (*(comma2 + 1) == '\0') { 5057c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 5067c478bd9Sstevel@tonic-gate mapping = NULL; 5077c478bd9Sstevel@tonic-gate continue; 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate i++; 5117c478bd9Sstevel@tonic-gate mods[i] = &modlist[i]; 5127c478bd9Sstevel@tonic-gate /* 5137c478bd9Sstevel@tonic-gate * get pointer to data. 5147c478bd9Sstevel@tonic-gate * Skip leading spaces. 5157c478bd9Sstevel@tonic-gate */ 5167c478bd9Sstevel@tonic-gate for (c = comma2 + 1; *c == SPACETOK; c++); 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* get data length */ 5197c478bd9Sstevel@tonic-gate vlen = strlen(attr[k]->attrvalue[0]) - 5207c478bd9Sstevel@tonic-gate (c - attr[k]->attrvalue[0]); 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate if (vlen > 0 && c) { 5237c478bd9Sstevel@tonic-gate rc = init_bval_mod(mods[i], mod_op, 5247c478bd9Sstevel@tonic-gate mapping[2], c, vlen); 5257c478bd9Sstevel@tonic-gate if (rc != 0) 5267c478bd9Sstevel@tonic-gate goto free_memory; 5277c478bd9Sstevel@tonic-gate } else { 5287c478bd9Sstevel@tonic-gate /* don't leave a hole in mods array */ 5297c478bd9Sstevel@tonic-gate mods[i] = NULL; 5307c478bd9Sstevel@tonic-gate i--; 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate /* done with the mapping array */ 5347c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 5357c478bd9Sstevel@tonic-gate mapping = NULL; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate continue; 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* case c1 */ 5427c478bd9Sstevel@tonic-gate mods[i]->mod_type = strdup(mapping[0]); 5437c478bd9Sstevel@tonic-gate if (mods[i]->mod_type == NULL) { 5447c478bd9Sstevel@tonic-gate goto free_memory; 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 5477c478bd9Sstevel@tonic-gate mapping = NULL; 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate modval = (char **)calloc(attr[k]->value_count+1, 5517c478bd9Sstevel@tonic-gate sizeof (char *)); 5527c478bd9Sstevel@tonic-gate if (modval == NULL) 5537c478bd9Sstevel@tonic-gate goto free_memory; 5547c478bd9Sstevel@tonic-gate /* 5557c478bd9Sstevel@tonic-gate * Perform objectclass mapping. 5567c478bd9Sstevel@tonic-gate * Note that the values for the "objectclass" attribute 5577c478bd9Sstevel@tonic-gate * will be dupped using strdup. Values for other 5587c478bd9Sstevel@tonic-gate * attributes will be referenced via pointer 5597c478bd9Sstevel@tonic-gate * assignments. 5607c478bd9Sstevel@tonic-gate */ 5617c478bd9Sstevel@tonic-gate if (strcasecmp(mods[i]->mod_type, "objectclass") == 0) { 5627c478bd9Sstevel@tonic-gate for (j = 0; j < attr[k]->value_count; j++) { 5637c478bd9Sstevel@tonic-gate if (schema_mapping_existed && 5647c478bd9Sstevel@tonic-gate (flags & NS_LDAP_NOMAP) == 0) 5657c478bd9Sstevel@tonic-gate mapping = 5667c478bd9Sstevel@tonic-gate __ns_ldap_getMappedObjectClass( 5677c478bd9Sstevel@tonic-gate service, attr[k]->attrvalue[j]); 5687c478bd9Sstevel@tonic-gate else 5697c478bd9Sstevel@tonic-gate mapping = NULL; 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate if (mapping == NULL && auto_service && 5727c478bd9Sstevel@tonic-gate (flags & NS_LDAP_NOMAP) == 0) 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * if service == auto_xxx and 5757c478bd9Sstevel@tonic-gate * no mapped objectclass is found 5767c478bd9Sstevel@tonic-gate * then try automount 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate mapping = 5797c478bd9Sstevel@tonic-gate __ns_ldap_getMappedObjectClass( 5807c478bd9Sstevel@tonic-gate "automount", attr[k]->attrvalue[j]); 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate if (mapping && mapping[0]) { 5837c478bd9Sstevel@tonic-gate /* assume single mapping */ 5847c478bd9Sstevel@tonic-gate modval[j] = strdup(mapping[0]); 5857c478bd9Sstevel@tonic-gate } else { 5867c478bd9Sstevel@tonic-gate modval[j] = strdup(attr[k]-> 5877c478bd9Sstevel@tonic-gate attrvalue[j]); 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate if (modval[j] == NULL) 5907c478bd9Sstevel@tonic-gate goto free_memory; 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate } else { 5937c478bd9Sstevel@tonic-gate for (j = 0; j < attr[k]->value_count; j++) { 5947c478bd9Sstevel@tonic-gate /* ASSIGN NOT COPY */ 5957c478bd9Sstevel@tonic-gate modval[j] = attr[k]->attrvalue[j]; 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate mods[i]->mod_values = modval; 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate return (mods); 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate free_memory: 6047c478bd9Sstevel@tonic-gate freeModList(mods); 6057c478bd9Sstevel@tonic-gate if (mapping) 6067c478bd9Sstevel@tonic-gate __s_api_free2dArray(mapping); 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate return (NULL); 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate } 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate static LDAPMod ** 6137c478bd9Sstevel@tonic-gate __s_api_makeModList( 6147c478bd9Sstevel@tonic-gate const char *service, 6157c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 6167c478bd9Sstevel@tonic-gate const int mod_op, 6177c478bd9Sstevel@tonic-gate const int flags) 6187c478bd9Sstevel@tonic-gate { 6197c478bd9Sstevel@tonic-gate ns_ldap_attr_t **aptr = (ns_ldap_attr_t **)attr; 6207c478bd9Sstevel@tonic-gate int count = 0; 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate if (aptr == NULL) 6237c478bd9Sstevel@tonic-gate return (NULL); 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate /* count number of attributes */ 6267c478bd9Sstevel@tonic-gate while (*aptr++) 6277c478bd9Sstevel@tonic-gate count++; 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate return (__s_api_makeModListCount(service, attr, mod_op, count, flags)); 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate static void 6337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(ns_ldap_entry_t **entry, char **rdn) 6347c478bd9Sstevel@tonic-gate { 6357c478bd9Sstevel@tonic-gate if (*entry != NULL) { 6367c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(*entry); 6377c478bd9Sstevel@tonic-gate *entry = NULL; 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate if (*rdn != NULL) { 6407c478bd9Sstevel@tonic-gate free(*rdn); 6417c478bd9Sstevel@tonic-gate *rdn = NULL; 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /* 6467c478bd9Sstevel@tonic-gate * This state machine performs one or more LDAP add/delete/modify 6477c478bd9Sstevel@tonic-gate * operations to configured LDAP servers. 6487c478bd9Sstevel@tonic-gate */ 6497c478bd9Sstevel@tonic-gate static int 6507c478bd9Sstevel@tonic-gate write_state_machine( 6517c478bd9Sstevel@tonic-gate int ldap_op, 6527c478bd9Sstevel@tonic-gate char *dn, 6537c478bd9Sstevel@tonic-gate LDAPMod **mods, 6547c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 6557c478bd9Sstevel@tonic-gate const int flags, 6567c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 6577c478bd9Sstevel@tonic-gate { 6587c478bd9Sstevel@tonic-gate ConnectionID connectionId = -1; 6597c478bd9Sstevel@tonic-gate Connection *conp = NULL; 6607c478bd9Sstevel@tonic-gate LDAPMessage *res; 6617c478bd9Sstevel@tonic-gate char *target_dn = NULL; 6627c478bd9Sstevel@tonic-gate char errstr[MAXERROR]; 6637c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS; 6647c478bd9Sstevel@tonic-gate int return_rc = NS_LDAP_SUCCESS; 6657c478bd9Sstevel@tonic-gate int followRef = FALSE; 6667c478bd9Sstevel@tonic-gate int target_dn_allocated = FALSE; 6677c478bd9Sstevel@tonic-gate int len; 6687c478bd9Sstevel@tonic-gate int msgid; 6697c478bd9Sstevel@tonic-gate int Errno; 6707c478bd9Sstevel@tonic-gate int always = 1; 6717c478bd9Sstevel@tonic-gate char *err, *errmsg = NULL; 6727d575517Ssdussud /* referrals returned by the LDAP operation */ 6737c478bd9Sstevel@tonic-gate char **referrals = NULL; 6747d575517Ssdussud /* 6757d575517Ssdussud * list of referrals used by the state machine, built from 6767d575517Ssdussud * the referrals variable above 6777d575517Ssdussud */ 6787d575517Ssdussud ns_referral_info_t *ref_list = NULL; 6797d575517Ssdussud /* current referral */ 6807d575517Ssdussud ns_referral_info_t *current_ref = NULL; 6817c478bd9Sstevel@tonic-gate ns_write_state_t state = W_INIT, new_state, err_state = W_INIT; 6827c478bd9Sstevel@tonic-gate int do_not_fail_if_new_pwd_reqd = 0; 6837c478bd9Sstevel@tonic-gate ns_ldap_passwd_status_t pwd_status = NS_PASSWD_GOOD; 6847c478bd9Sstevel@tonic-gate int passwd_mgmt = 0; 6857d575517Ssdussud int i = 0; 6867d575517Ssdussud int ldap_error; 687*47789246Svv int nopasswd_acct_mgmt = 0; 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate while (always) { 6907c478bd9Sstevel@tonic-gate switch (state) { 6917c478bd9Sstevel@tonic-gate case W_EXIT: 6927c478bd9Sstevel@tonic-gate if (connectionId > -1) 6937c478bd9Sstevel@tonic-gate DropConnection(connectionId, 0); 6947d575517Ssdussud if (ref_list) 6957d575517Ssdussud __s_api_deleteRefInfo(ref_list); 6967c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) 6977c478bd9Sstevel@tonic-gate free(target_dn); 6987c478bd9Sstevel@tonic-gate return (return_rc); 6997c478bd9Sstevel@tonic-gate case W_INIT: 7007c478bd9Sstevel@tonic-gate /* see if need to follow referrals */ 7017c478bd9Sstevel@tonic-gate rc = __s_api_toFollowReferrals(flags, 7027c478bd9Sstevel@tonic-gate &followRef, errorp); 7037c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7047c478bd9Sstevel@tonic-gate return_rc = rc; 7057c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7067c478bd9Sstevel@tonic-gate break; 7077c478bd9Sstevel@tonic-gate } 7087c478bd9Sstevel@tonic-gate len = strlen(dn); 7097c478bd9Sstevel@tonic-gate if (dn[len-1] == COMMATOK) 7107c478bd9Sstevel@tonic-gate rc = __s_api_append_default_basedn( 7117c478bd9Sstevel@tonic-gate dn, &target_dn, 7127c478bd9Sstevel@tonic-gate &target_dn_allocated, 7137c478bd9Sstevel@tonic-gate errorp); 7147c478bd9Sstevel@tonic-gate else 7157c478bd9Sstevel@tonic-gate target_dn = dn; 7167c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7177c478bd9Sstevel@tonic-gate return_rc = rc; 7187c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate else 7217c478bd9Sstevel@tonic-gate new_state = GET_CONNECTION; 7227c478bd9Sstevel@tonic-gate break; 7237c478bd9Sstevel@tonic-gate case GET_CONNECTION: 7247c478bd9Sstevel@tonic-gate rc = __s_api_getConnection(NULL, 7257c478bd9Sstevel@tonic-gate flags, 7267c478bd9Sstevel@tonic-gate cred, 7277c478bd9Sstevel@tonic-gate &connectionId, 7287c478bd9Sstevel@tonic-gate &conp, 7297c478bd9Sstevel@tonic-gate errorp, 730*47789246Svv do_not_fail_if_new_pwd_reqd, 731*47789246Svv nopasswd_acct_mgmt); 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate /* 7347c478bd9Sstevel@tonic-gate * If password control attached 7357c478bd9Sstevel@tonic-gate * in *errorp, 7367c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 7377c478bd9Sstevel@tonic-gate * free the error structure (we do not need 7387c478bd9Sstevel@tonic-gate * the password management info). 7397c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 7407c478bd9Sstevel@tonic-gate */ 7417c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 7427c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError( 7437c478bd9Sstevel@tonic-gate errorp); 7447c478bd9Sstevel@tonic-gate *errorp = NULL; 7457c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7497c478bd9Sstevel@tonic-gate return_rc = rc; 7507c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7517c478bd9Sstevel@tonic-gate break; 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate if (followRef) 7547c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_ASYNC; 7557c478bd9Sstevel@tonic-gate else 7567c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 7577c478bd9Sstevel@tonic-gate break; 7587c478bd9Sstevel@tonic-gate case SELECT_OPERATION_SYNC: 7597c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7607c478bd9Sstevel@tonic-gate new_state = DO_ADD_SYNC; 7617c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7627c478bd9Sstevel@tonic-gate new_state = DO_DELETE_SYNC; 7637c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7647c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_SYNC; 7657c478bd9Sstevel@tonic-gate break; 7667c478bd9Sstevel@tonic-gate case SELECT_OPERATION_ASYNC: 7677c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7687c478bd9Sstevel@tonic-gate new_state = DO_ADD_ASYNC; 7697c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7707c478bd9Sstevel@tonic-gate new_state = DO_DELETE_ASYNC; 7717c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7727c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_ASYNC; 7737c478bd9Sstevel@tonic-gate break; 7747c478bd9Sstevel@tonic-gate case DO_ADD_SYNC: 7757c478bd9Sstevel@tonic-gate rc = ldap_add_ext_s(conp->ld, target_dn, 7767c478bd9Sstevel@tonic-gate mods, NULL, NULL); 7777c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7787c478bd9Sstevel@tonic-gate break; 7797c478bd9Sstevel@tonic-gate case DO_DELETE_SYNC: 7807c478bd9Sstevel@tonic-gate rc = ldap_delete_ext_s(conp->ld, target_dn, 7817c478bd9Sstevel@tonic-gate NULL, NULL); 7827c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7837c478bd9Sstevel@tonic-gate break; 7847c478bd9Sstevel@tonic-gate case DO_MODIFY_SYNC: 7857c478bd9Sstevel@tonic-gate rc = ldap_modify_ext_s(conp->ld, target_dn, 7867c478bd9Sstevel@tonic-gate mods, NULL, NULL); 7877c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7887c478bd9Sstevel@tonic-gate break; 7897c478bd9Sstevel@tonic-gate case DO_ADD_ASYNC: 7907c478bd9Sstevel@tonic-gate rc = ldap_add_ext(conp->ld, target_dn, 7917c478bd9Sstevel@tonic-gate mods, NULL, NULL, &msgid); 7927c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 7937c478bd9Sstevel@tonic-gate break; 7947c478bd9Sstevel@tonic-gate case DO_DELETE_ASYNC: 7957c478bd9Sstevel@tonic-gate rc = ldap_delete_ext(conp->ld, target_dn, 7967c478bd9Sstevel@tonic-gate NULL, NULL, &msgid); 7977c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 7987c478bd9Sstevel@tonic-gate break; 7997c478bd9Sstevel@tonic-gate case DO_MODIFY_ASYNC: 8007c478bd9Sstevel@tonic-gate rc = ldap_modify_ext(conp->ld, target_dn, 8017c478bd9Sstevel@tonic-gate mods, NULL, NULL, &msgid); 8027c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 8037c478bd9Sstevel@tonic-gate break; 8047c478bd9Sstevel@tonic-gate case GET_RESULT_SYNC: 8057c478bd9Sstevel@tonic-gate if (rc != LDAP_SUCCESS) { 8067c478bd9Sstevel@tonic-gate Errno = rc; 8077c478bd9Sstevel@tonic-gate (void) ldap_get_lderrno(conp->ld, 8087c478bd9Sstevel@tonic-gate NULL, &errmsg); 8097c478bd9Sstevel@tonic-gate /* 8107c478bd9Sstevel@tonic-gate * free errmsg if it is an empty string 8117c478bd9Sstevel@tonic-gate */ 8127c478bd9Sstevel@tonic-gate if (errmsg && *errmsg == '\0') { 8137c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8147c478bd9Sstevel@tonic-gate errmsg = NULL; 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8177c478bd9Sstevel@tonic-gate } else { 8187c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 8197c478bd9Sstevel@tonic-gate new_state = W_EXIT; 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate break; 8227c478bd9Sstevel@tonic-gate case GET_RESULT_ASYNC: 8237c478bd9Sstevel@tonic-gate rc = ldap_result(conp->ld, msgid, 1, 8247c478bd9Sstevel@tonic-gate (struct timeval *)NULL, &res); 8257c478bd9Sstevel@tonic-gate /* if no server response, set Errno */ 8267c478bd9Sstevel@tonic-gate if (rc == -1) { 8277c478bd9Sstevel@tonic-gate (void) ldap_get_option(conp->ld, 8287c478bd9Sstevel@tonic-gate LDAP_OPT_ERROR_NUMBER, &Errno); 8297c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8307c478bd9Sstevel@tonic-gate break; 8317c478bd9Sstevel@tonic-gate } 8327c478bd9Sstevel@tonic-gate if (rc == LDAP_RES_ADD || 8337c478bd9Sstevel@tonic-gate rc == LDAP_RES_MODIFY || 8347c478bd9Sstevel@tonic-gate rc == LDAP_RES_DELETE) { 8357c478bd9Sstevel@tonic-gate new_state = PARSE_RESULT; 8367c478bd9Sstevel@tonic-gate break; 8377c478bd9Sstevel@tonic-gate } else { 8387c478bd9Sstevel@tonic-gate return_rc = rc; 8397c478bd9Sstevel@tonic-gate new_state = W_ERROR; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate break; 8427c478bd9Sstevel@tonic-gate case PARSE_RESULT: 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * need Errno, referrals, error msg, 8457c478bd9Sstevel@tonic-gate * and the last "1" is to free 8467c478bd9Sstevel@tonic-gate * the result (res) 8477c478bd9Sstevel@tonic-gate */ 8487c478bd9Sstevel@tonic-gate rc = ldap_parse_result(conp->ld, 8497c478bd9Sstevel@tonic-gate res, &Errno, 8507c478bd9Sstevel@tonic-gate NULL, &errmsg, 8517c478bd9Sstevel@tonic-gate &referrals, NULL, 1); 8527c478bd9Sstevel@tonic-gate /* 8537c478bd9Sstevel@tonic-gate * free errmsg if it is an empty string 8547c478bd9Sstevel@tonic-gate */ 8557c478bd9Sstevel@tonic-gate if (errmsg && *errmsg == '\0') { 8567c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8577c478bd9Sstevel@tonic-gate errmsg = NULL; 8587c478bd9Sstevel@tonic-gate } 8597d575517Ssdussud /* 8607d575517Ssdussud * If we received referral data, process 8617d575517Ssdussud * it if: 8627d575517Ssdussud * - we are configured to follow referrals 8637d575517Ssdussud * - and not already in referral mode (to keep 8647d575517Ssdussud * consistency with search_state_machine() 8657d575517Ssdussud * which follows 1 level of referrals only; 8667d575517Ssdussud * see proc_result_referrals() and 8677d575517Ssdussud * proc_search_references(). 8687d575517Ssdussud */ 8697d575517Ssdussud if (Errno == LDAP_REFERRAL && followRef && !ref_list) { 8707d575517Ssdussud for (i = 0; referrals[i] != NULL; i++) { 8717d575517Ssdussud /* add to referral list */ 8727d575517Ssdussud rc = __s_api_addRefInfo(&ref_list, 8737d575517Ssdussud referrals[i], 8747c478bd9Sstevel@tonic-gate NULL, NULL, NULL, 8757c478bd9Sstevel@tonic-gate conp->ld); 8767d575517Ssdussud if (rc != NS_LDAP_SUCCESS) { 8777d575517Ssdussud __s_api_deleteRefInfo(ref_list); 8787d575517Ssdussud ref_list = NULL; 8797d575517Ssdussud break; 8807d575517Ssdussud } 8817c478bd9Sstevel@tonic-gate } 8827c478bd9Sstevel@tonic-gate ldap_value_free(referrals); 8837d575517Ssdussud if (ref_list == NULL) { 8847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_MEMORY) 8857c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 8867d575517Ssdussud return_rc = rc; 8877c478bd9Sstevel@tonic-gate new_state = W_ERROR; 8887d575517Ssdussud } else { 8897c478bd9Sstevel@tonic-gate new_state = GET_REFERRAL_CONNECTION; 8907d575517Ssdussud current_ref = ref_list; 8917d575517Ssdussud } 8927c478bd9Sstevel@tonic-gate if (errmsg) { 8937c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8947c478bd9Sstevel@tonic-gate errmsg = NULL; 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate break; 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate if (Errno != LDAP_SUCCESS) { 8997c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 9007c478bd9Sstevel@tonic-gate } else { 9017c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 9027c478bd9Sstevel@tonic-gate new_state = W_EXIT; 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate break; 9057c478bd9Sstevel@tonic-gate case GET_REFERRAL_CONNECTION: 9067d575517Ssdussud /* 9077d575517Ssdussud * since we are starting over, 9087d575517Ssdussud * discard the old error info 9097d575517Ssdussud */ 9107d575517Ssdussud return_rc = NS_LDAP_SUCCESS; 9117d575517Ssdussud if (*errorp) 9127d575517Ssdussud (void) __ns_ldap_freeError(errorp); 9137c478bd9Sstevel@tonic-gate if (connectionId > -1) 9147c478bd9Sstevel@tonic-gate DropConnection(connectionId, 0); 9157d575517Ssdussud rc = __s_api_getConnection(current_ref->refHost, 9167c478bd9Sstevel@tonic-gate 0, 9177c478bd9Sstevel@tonic-gate cred, 9187c478bd9Sstevel@tonic-gate &connectionId, 9197c478bd9Sstevel@tonic-gate &conp, 9207c478bd9Sstevel@tonic-gate errorp, 921*47789246Svv do_not_fail_if_new_pwd_reqd, 922*47789246Svv nopasswd_acct_mgmt); 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate /* 9257c478bd9Sstevel@tonic-gate * If password control attached 9267c478bd9Sstevel@tonic-gate * in errorp, 9277c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 9287c478bd9Sstevel@tonic-gate * free the error structure (we do not need 9297c478bd9Sstevel@tonic-gate * the password management info). 9307c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 9337c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError( 9347c478bd9Sstevel@tonic-gate errorp); 9357c478bd9Sstevel@tonic-gate *errorp = NULL; 9367c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 9377c478bd9Sstevel@tonic-gate } 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 9407c478bd9Sstevel@tonic-gate return_rc = rc; 9417d575517Ssdussud /* 9427d575517Ssdussud * If current referral is not 9437d575517Ssdussud * available for some reason, 9447d575517Ssdussud * try next referral in the list. 9457d575517Ssdussud * Get LDAP error code from errorp. 9467d575517Ssdussud */ 9477d575517Ssdussud if (*errorp != NULL) { 9487d575517Ssdussud ldap_error = (*errorp)->status; 9497d575517Ssdussud if (ldap_error == LDAP_BUSY || 9507d575517Ssdussud ldap_error == LDAP_UNAVAILABLE || 9517d575517Ssdussud ldap_error == 9527d575517Ssdussud LDAP_UNWILLING_TO_PERFORM || 9537d575517Ssdussud ldap_error == LDAP_CONNECT_ERROR || 9547d575517Ssdussud ldap_error == LDAP_SERVER_DOWN) { 9557d575517Ssdussud current_ref = current_ref->next; 9567d575517Ssdussud if (current_ref == NULL) { 9577d575517Ssdussud /* no more referral */ 9587d575517Ssdussud /* to follow */ 9597d575517Ssdussud new_state = W_ERROR; 9607d575517Ssdussud } else { 9617d575517Ssdussud new_state = 9627d575517Ssdussud GET_REFERRAL_CONNECTION; 9637d575517Ssdussud } 9647d575517Ssdussud /* 9657d575517Ssdussud * free errorp before going to 9667d575517Ssdussud * next referral 9677d575517Ssdussud */ 9687d575517Ssdussud (void) __ns_ldap_freeError( 9697d575517Ssdussud errorp); 9707d575517Ssdussud *errorp = NULL; 9717d575517Ssdussud break; 9727d575517Ssdussud } 9737d575517Ssdussud /* 9747d575517Ssdussud * free errorp before going to W_ERROR 9757d575517Ssdussud */ 9767d575517Ssdussud (void) __ns_ldap_freeError(errorp); 9777d575517Ssdussud *errorp = NULL; 9787d575517Ssdussud } 9797d575517Ssdussud /* else, exit */ 9807d575517Ssdussud __s_api_deleteRefInfo(ref_list); 9817d575517Ssdussud ref_list = NULL; 9827c478bd9Sstevel@tonic-gate new_state = W_ERROR; 9837c478bd9Sstevel@tonic-gate break; 9847c478bd9Sstevel@tonic-gate } 9857c478bd9Sstevel@tonic-gate /* target DN may changed due to referrals */ 9867d575517Ssdussud if (current_ref->refDN) { 9877c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) { 9887c478bd9Sstevel@tonic-gate free(target_dn); 9897c478bd9Sstevel@tonic-gate target_dn = NULL; 9907c478bd9Sstevel@tonic-gate target_dn_allocated = FALSE; 9917c478bd9Sstevel@tonic-gate } 9927d575517Ssdussud target_dn = current_ref->refDN; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 9957c478bd9Sstevel@tonic-gate break; 9967c478bd9Sstevel@tonic-gate case W_LDAP_ERROR: 9977c478bd9Sstevel@tonic-gate /* 9987c478bd9Sstevel@tonic-gate * map error code and error message 9997c478bd9Sstevel@tonic-gate * to password status if necessary. 10007c478bd9Sstevel@tonic-gate * This is to see if password updates 10017c478bd9Sstevel@tonic-gate * failed due to password policy or 10027c478bd9Sstevel@tonic-gate * password syntax checking. 10037c478bd9Sstevel@tonic-gate */ 10047c478bd9Sstevel@tonic-gate if (errmsg) { 10057c478bd9Sstevel@tonic-gate /* 10067c478bd9Sstevel@tonic-gate * check if server supports 10077c478bd9Sstevel@tonic-gate * password management 10087c478bd9Sstevel@tonic-gate */ 10097c478bd9Sstevel@tonic-gate passwd_mgmt = 10107c478bd9Sstevel@tonic-gate __s_api_contain_passwd_control_oid( 10117c478bd9Sstevel@tonic-gate conp->controls); 10127c478bd9Sstevel@tonic-gate if (passwd_mgmt) 10137c478bd9Sstevel@tonic-gate pwd_status = 10147c478bd9Sstevel@tonic-gate __s_api_set_passwd_status( 10157c478bd9Sstevel@tonic-gate Errno, errmsg); 10167c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 10177c478bd9Sstevel@tonic-gate errmsg = NULL; 10187c478bd9Sstevel@tonic-gate } 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 10217c478bd9Sstevel@tonic-gate gettext(ldap_err2string(Errno))); 10227c478bd9Sstevel@tonic-gate err = strdup(errstr); 10237c478bd9Sstevel@tonic-gate if (pwd_status != NS_PASSWD_GOOD) { 10247c478bd9Sstevel@tonic-gate MKERROR_PWD_MGMT(*errorp, Errno, err, 10257c478bd9Sstevel@tonic-gate pwd_status, 0, NULL); 10267c478bd9Sstevel@tonic-gate } else { 10277c478bd9Sstevel@tonic-gate MKERROR(LOG_INFO, *errorp, Errno, err, NULL); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_INTERNAL; 10307c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10317c478bd9Sstevel@tonic-gate break; 10327c478bd9Sstevel@tonic-gate case W_ERROR: 10337c478bd9Sstevel@tonic-gate default: 10347c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 10357c478bd9Sstevel@tonic-gate gettext("Internal write State machine exit" 10367c478bd9Sstevel@tonic-gate " (state = %d, rc = %d)."), 10377c478bd9Sstevel@tonic-gate err_state, return_rc); 10387c478bd9Sstevel@tonic-gate err = strdup(errstr); 10397c478bd9Sstevel@tonic-gate MKERROR(LOG_WARNING, *errorp, return_rc, err, NULL); 10407c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10417c478bd9Sstevel@tonic-gate break; 10427c478bd9Sstevel@tonic-gate } 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate if (new_state == W_ERROR) 10457c478bd9Sstevel@tonic-gate err_state = state; 10467c478bd9Sstevel@tonic-gate state = new_state; 10477c478bd9Sstevel@tonic-gate } 10487c478bd9Sstevel@tonic-gate 10497c478bd9Sstevel@tonic-gate /* 10507c478bd9Sstevel@tonic-gate * should never be here, the next line is to eliminating 10517c478bd9Sstevel@tonic-gate * lint message 10527c478bd9Sstevel@tonic-gate */ 10537c478bd9Sstevel@tonic-gate return (NS_LDAP_INTERNAL); 10547c478bd9Sstevel@tonic-gate } 10557c478bd9Sstevel@tonic-gate 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10587c478bd9Sstevel@tonic-gate int 10597c478bd9Sstevel@tonic-gate __ns_ldap_addAttr( 10607c478bd9Sstevel@tonic-gate const char *service, 10617c478bd9Sstevel@tonic-gate const char *dn, 10627c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 10637c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 10647c478bd9Sstevel@tonic-gate const int flags, 10657c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 10667c478bd9Sstevel@tonic-gate { 10677c478bd9Sstevel@tonic-gate LDAPMod **mods; 10687c478bd9Sstevel@tonic-gate int rc = 0; 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate #ifdef DEBUG 10717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addAttr START\n"); 10727c478bd9Sstevel@tonic-gate #endif 10737c478bd9Sstevel@tonic-gate *errorp = NULL; 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* Sanity check */ 10767c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 10777c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 10787c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 10797c478bd9Sstevel@tonic-gate 10807c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_ADD, flags); 10817c478bd9Sstevel@tonic-gate if (mods == NULL) { 10827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 10837c478bd9Sstevel@tonic-gate } 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 10867c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 10877c478bd9Sstevel@tonic-gate freeModList(mods); 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate return (rc); 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10947c478bd9Sstevel@tonic-gate int 10957c478bd9Sstevel@tonic-gate __ns_ldap_delAttr( 10967c478bd9Sstevel@tonic-gate const char *service, 10977c478bd9Sstevel@tonic-gate const char *dn, 10987c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 10997c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11007c478bd9Sstevel@tonic-gate const int flags, 11017c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11027c478bd9Sstevel@tonic-gate { 11037c478bd9Sstevel@tonic-gate LDAPMod **mods; 11047c478bd9Sstevel@tonic-gate int rc = 0; 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate #ifdef DEBUG 11077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delAttr START\n"); 11087c478bd9Sstevel@tonic-gate #endif 11097c478bd9Sstevel@tonic-gate *errorp = NULL; 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate /* Sanity check */ 11127c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11137c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11147c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11157c478bd9Sstevel@tonic-gate 11167c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_DELETE, flags); 11177c478bd9Sstevel@tonic-gate if (mods == NULL) { 11187c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11227c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11237c478bd9Sstevel@tonic-gate 11247c478bd9Sstevel@tonic-gate freeModList(mods); 11257c478bd9Sstevel@tonic-gate return (rc); 11267c478bd9Sstevel@tonic-gate } 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11297c478bd9Sstevel@tonic-gate int 11307c478bd9Sstevel@tonic-gate __ns_ldap_repAttr( 11317c478bd9Sstevel@tonic-gate const char *service, 11327c478bd9Sstevel@tonic-gate const char *dn, 11337c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 11347c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11357c478bd9Sstevel@tonic-gate const int flags, 11367c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11377c478bd9Sstevel@tonic-gate { 11387c478bd9Sstevel@tonic-gate LDAPMod **mods; 11397c478bd9Sstevel@tonic-gate int rc = 0; 11407c478bd9Sstevel@tonic-gate 11417c478bd9Sstevel@tonic-gate #ifdef DEBUG 11427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_repAttr START\n"); 11437c478bd9Sstevel@tonic-gate #endif 11447c478bd9Sstevel@tonic-gate *errorp = NULL; 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate /* Sanity check */ 11477c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11487c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11497c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11507c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_REPLACE, flags); 11517c478bd9Sstevel@tonic-gate if (mods == NULL) { 11527c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11537c478bd9Sstevel@tonic-gate } 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11567c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate freeModList(mods); 11597c478bd9Sstevel@tonic-gate return (rc); 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11647c478bd9Sstevel@tonic-gate int 11657c478bd9Sstevel@tonic-gate __ns_ldap_addEntry( 11667c478bd9Sstevel@tonic-gate const char *service, 11677c478bd9Sstevel@tonic-gate const char *dn, 11687c478bd9Sstevel@tonic-gate const ns_ldap_entry_t *entry, 11697c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11707c478bd9Sstevel@tonic-gate const int flags, 11717c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11727c478bd9Sstevel@tonic-gate { 11737c478bd9Sstevel@tonic-gate char *new_dn = NULL; 11747c478bd9Sstevel@tonic-gate LDAPMod **mods = NULL; 11757c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr; 11767c478bd9Sstevel@tonic-gate int nAttr = 0; 11777c478bd9Sstevel@tonic-gate int rc = 0; 11787c478bd9Sstevel@tonic-gate 11797c478bd9Sstevel@tonic-gate #ifdef DEBUG 11807c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addEntry START\n"); 11817c478bd9Sstevel@tonic-gate #endif 11827c478bd9Sstevel@tonic-gate 11837c478bd9Sstevel@tonic-gate if ((entry == NULL) || (dn == NULL) || (cred == NULL)) 11847c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11857c478bd9Sstevel@tonic-gate *errorp = NULL; 11867c478bd9Sstevel@tonic-gate 11877c478bd9Sstevel@tonic-gate /* Construct array of LDAPMod representing attributes of new entry. */ 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate nAttr = entry->attr_count; 11907c478bd9Sstevel@tonic-gate attr = (const ns_ldap_attr_t * const *)(entry->attr_pair); 11917c478bd9Sstevel@tonic-gate mods = __s_api_makeModListCount(service, attr, LDAP_MOD_ADD, 11927c478bd9Sstevel@tonic-gate nAttr, flags); 11937c478bd9Sstevel@tonic-gate if (mods == NULL) { 11947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate rc = replace_mapped_attr_in_dn(service, dn, &new_dn); 11987c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 11997c478bd9Sstevel@tonic-gate freeModList(mods); 12007c478bd9Sstevel@tonic-gate return (rc); 12017c478bd9Sstevel@tonic-gate } 12027c478bd9Sstevel@tonic-gate 12037c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_ADD, 12047c478bd9Sstevel@tonic-gate new_dn ? new_dn : (char *)dn, mods, cred, flags, errorp); 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate if (new_dn) 12077c478bd9Sstevel@tonic-gate free(new_dn); 12087c478bd9Sstevel@tonic-gate freeModList(mods); 12097c478bd9Sstevel@tonic-gate return (rc); 12107c478bd9Sstevel@tonic-gate } 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate 12137c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12147c478bd9Sstevel@tonic-gate int 12157c478bd9Sstevel@tonic-gate __ns_ldap_delEntry( 12167c478bd9Sstevel@tonic-gate const char *service, 12177c478bd9Sstevel@tonic-gate const char *dn, 12187c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 12197c478bd9Sstevel@tonic-gate const int flags, 12207c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 12217c478bd9Sstevel@tonic-gate { 12227c478bd9Sstevel@tonic-gate int rc; 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate #ifdef DEBUG 12257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delEntry START\n"); 12267c478bd9Sstevel@tonic-gate #endif 12277c478bd9Sstevel@tonic-gate if ((dn == NULL) || (cred == NULL)) 12287c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 12297c478bd9Sstevel@tonic-gate 12307c478bd9Sstevel@tonic-gate *errorp = NULL; 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_DELETE, 12337c478bd9Sstevel@tonic-gate (char *)dn, NULL, cred, flags, errorp); 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate return (rc); 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate 12387c478bd9Sstevel@tonic-gate /* 12397c478bd9Sstevel@tonic-gate * Add Typed Entry Helper routines 12407c478bd9Sstevel@tonic-gate */ 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate /* 12437c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion routines 12447c478bd9Sstevel@tonic-gate */ 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate static int 12477c478bd9Sstevel@tonic-gate __s_add_attr(ns_ldap_entry_t *e, char *attrname, char *value) 12487c478bd9Sstevel@tonic-gate { 12497c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 12507c478bd9Sstevel@tonic-gate char *v; 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 12537c478bd9Sstevel@tonic-gate if (a == NULL) 12547c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12557c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 12567c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 12577c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12587c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(1, sizeof (char **)); 12597c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 12607c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12617c478bd9Sstevel@tonic-gate a->value_count = 1; 12627c478bd9Sstevel@tonic-gate a->attrvalue[0] = NULL; 12637c478bd9Sstevel@tonic-gate v = strdup(value); 12647c478bd9Sstevel@tonic-gate if (v == NULL) 12657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12667c478bd9Sstevel@tonic-gate a->attrvalue[0] = v; 12677c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 12687c478bd9Sstevel@tonic-gate e->attr_count++; 12697c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 12707c478bd9Sstevel@tonic-gate } 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate static int 12737c478bd9Sstevel@tonic-gate __s_add_attrlist(ns_ldap_entry_t *e, char *attrname, char **argv) 12747c478bd9Sstevel@tonic-gate { 12757c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 12767c478bd9Sstevel@tonic-gate char *v; 12777c478bd9Sstevel@tonic-gate char **av; 12787c478bd9Sstevel@tonic-gate int i, j; 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 12817c478bd9Sstevel@tonic-gate if (a == NULL) 12827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12837c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 12847c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 12857c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate for (i = 0, av = argv; *av != NULL; av++, i++) 12887c478bd9Sstevel@tonic-gate ; 12897c478bd9Sstevel@tonic-gate 12907c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(i, sizeof (char *)); 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 12937c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate a->value_count = i; 12967c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 12977c478bd9Sstevel@tonic-gate v = strdup(argv[j]); 12987c478bd9Sstevel@tonic-gate if (v == NULL) 12997c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13007c478bd9Sstevel@tonic-gate a->attrvalue[j] = v; 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 13037c478bd9Sstevel@tonic-gate e->attr_count++; 13047c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 13057c478bd9Sstevel@tonic-gate } 13067c478bd9Sstevel@tonic-gate 13077c478bd9Sstevel@tonic-gate static ns_ldap_entry_t * 13087c478bd9Sstevel@tonic-gate __s_mk_entry(char **objclass, int max_attr) 13097c478bd9Sstevel@tonic-gate { 13107c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 13117c478bd9Sstevel@tonic-gate e = (ns_ldap_entry_t *)calloc(1, sizeof (ns_ldap_entry_t)); 13127c478bd9Sstevel@tonic-gate if (e == NULL) 13137c478bd9Sstevel@tonic-gate return (NULL); 13147c478bd9Sstevel@tonic-gate /* allocate attributes, +1 for objectclass, +1 for NULL terminator */ 13157c478bd9Sstevel@tonic-gate e->attr_pair = (ns_ldap_attr_t **) 13167c478bd9Sstevel@tonic-gate calloc(max_attr + 2, sizeof (ns_ldap_attr_t *)); 13177c478bd9Sstevel@tonic-gate if (e->attr_pair == NULL) { 13187c478bd9Sstevel@tonic-gate free(e); 13197c478bd9Sstevel@tonic-gate return (NULL); 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate e->attr_count = 0; 13227c478bd9Sstevel@tonic-gate if (__s_add_attrlist(e, "objectClass", objclass) != NS_LDAP_SUCCESS) { 13237c478bd9Sstevel@tonic-gate free(e->attr_pair); 13247c478bd9Sstevel@tonic-gate free(e); 13257c478bd9Sstevel@tonic-gate return (NULL); 13267c478bd9Sstevel@tonic-gate } 13277c478bd9Sstevel@tonic-gate return (e); 13287c478bd9Sstevel@tonic-gate } 13297c478bd9Sstevel@tonic-gate 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate /* 13327c478bd9Sstevel@tonic-gate * Conversion: passwd 13337c478bd9Sstevel@tonic-gate * Input format: struct passwd 13347c478bd9Sstevel@tonic-gate * Exported objectclass: posixAccount 13357c478bd9Sstevel@tonic-gate */ 13367c478bd9Sstevel@tonic-gate static int 13377c478bd9Sstevel@tonic-gate __s_cvt_passwd(const void *data, char **rdn, 13387c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 13397c478bd9Sstevel@tonic-gate { 13407c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 13417c478bd9Sstevel@tonic-gate int rc; 13427c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 13437c478bd9Sstevel@tonic-gate /* routine specific */ 13447c478bd9Sstevel@tonic-gate struct passwd *ptr; 13457c478bd9Sstevel@tonic-gate int max_attr = 9; 13467c478bd9Sstevel@tonic-gate char ibuf[10]; 13477c478bd9Sstevel@tonic-gate static char *oclist[] = { 13487c478bd9Sstevel@tonic-gate "posixAccount", 13497c478bd9Sstevel@tonic-gate "shadowAccount", 13507c478bd9Sstevel@tonic-gate "account", 13517c478bd9Sstevel@tonic-gate "top", 13527c478bd9Sstevel@tonic-gate NULL 13537c478bd9Sstevel@tonic-gate }; 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 13567c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 13577c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 13587c478bd9Sstevel@tonic-gate if (e == NULL) 13597c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate /* Convert the structure */ 13627c478bd9Sstevel@tonic-gate ptr = (struct passwd *)data; 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate if (ptr->pw_name == NULL || ptr->pw_uid < 0 || 13657c478bd9Sstevel@tonic-gate ptr->pw_gid < 0 || ptr->pw_dir == NULL) { 13667c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 13677c478bd9Sstevel@tonic-gate *entry = NULL; 13687c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 13727c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->pw_name); 13737c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 13747c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 13757c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 13767c478bd9Sstevel@tonic-gate *entry = NULL; 13777c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13787c478bd9Sstevel@tonic-gate } 13797c478bd9Sstevel@tonic-gate 13807c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 13817c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->pw_name); 13827c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13837c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13847c478bd9Sstevel@tonic-gate return (rc); 13857c478bd9Sstevel@tonic-gate } 13867c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->pw_name); 13877c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13887c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13897c478bd9Sstevel@tonic-gate return (rc); 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate if (ptr->pw_passwd != NULL && 13937c478bd9Sstevel@tonic-gate ptr->pw_passwd[0] != '\0') { 13947c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->pw_passwd); 13957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13977c478bd9Sstevel@tonic-gate return (rc); 13987c478bd9Sstevel@tonic-gate } 13997c478bd9Sstevel@tonic-gate } 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate #ifdef _LP64 14027c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->pw_uid); 14037c478bd9Sstevel@tonic-gate #else 14047c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->pw_uid); 14057c478bd9Sstevel@tonic-gate #endif 14067c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uidNumber", ibuf); 14077c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14087c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14097c478bd9Sstevel@tonic-gate return (rc); 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate 14127c478bd9Sstevel@tonic-gate #ifdef _LP64 14137c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->pw_gid); 14147c478bd9Sstevel@tonic-gate #else 14157c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->pw_gid); 14167c478bd9Sstevel@tonic-gate #endif 14177c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 14187c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14197c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14207c478bd9Sstevel@tonic-gate return (rc); 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate if (ptr->pw_gecos != NULL && 14237c478bd9Sstevel@tonic-gate ptr->pw_gecos[0] != '\0') { 14247c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gecos", ptr->pw_gecos); 14257c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14267c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14277c478bd9Sstevel@tonic-gate return (rc); 14287c478bd9Sstevel@tonic-gate } 14297c478bd9Sstevel@tonic-gate } 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "homeDirectory", ptr->pw_dir); 14327c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14347c478bd9Sstevel@tonic-gate return (rc); 14357c478bd9Sstevel@tonic-gate } 14367c478bd9Sstevel@tonic-gate if (ptr->pw_shell != NULL && 14377c478bd9Sstevel@tonic-gate ptr->pw_shell[0] != '\0') { 14387c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "loginShell", ptr->pw_shell); 14397c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14407c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14417c478bd9Sstevel@tonic-gate return (rc); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate 14457c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate /* 14497c478bd9Sstevel@tonic-gate * Conversion: shadow 14507c478bd9Sstevel@tonic-gate * Input format: struct shadow 14517c478bd9Sstevel@tonic-gate * Exported objectclass: shadowAccount 14527c478bd9Sstevel@tonic-gate */ 14537c478bd9Sstevel@tonic-gate static int 14547c478bd9Sstevel@tonic-gate __s_cvt_shadow(const void *data, char **rdn, 14557c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 14567c478bd9Sstevel@tonic-gate { 14577c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 14587c478bd9Sstevel@tonic-gate int rc; 14597c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 14607c478bd9Sstevel@tonic-gate /* routine specific */ 14617c478bd9Sstevel@tonic-gate struct spwd *ptr; 14627c478bd9Sstevel@tonic-gate int max_attr = 10; 14637c478bd9Sstevel@tonic-gate char ibuf[10]; 14647c478bd9Sstevel@tonic-gate static char *oclist[] = { 14657c478bd9Sstevel@tonic-gate "posixAccount", 14667c478bd9Sstevel@tonic-gate "shadowAccount", 14677c478bd9Sstevel@tonic-gate "account", 14687c478bd9Sstevel@tonic-gate "top", 14697c478bd9Sstevel@tonic-gate NULL 14707c478bd9Sstevel@tonic-gate }; 14717c478bd9Sstevel@tonic-gate 14727c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 14737c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 14747c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 14757c478bd9Sstevel@tonic-gate if (e == NULL) 14767c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate /* Convert the structure */ 14797c478bd9Sstevel@tonic-gate ptr = (struct spwd *)data; 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate if (ptr->sp_namp == NULL) { 14827c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 14837c478bd9Sstevel@tonic-gate *entry = NULL; 14847c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 14887c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->sp_namp); 14897c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 14907c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 14917c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 14927c478bd9Sstevel@tonic-gate *entry = NULL; 14937c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14947c478bd9Sstevel@tonic-gate } 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 14977c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->sp_namp); 14987c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14997c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15007c478bd9Sstevel@tonic-gate return (rc); 15017c478bd9Sstevel@tonic-gate } 15027c478bd9Sstevel@tonic-gate 15037c478bd9Sstevel@tonic-gate if (ptr->sp_pwdp == NULL) { 15047c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15057c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 15067c478bd9Sstevel@tonic-gate } else { 15077c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->sp_pwdp); 15087c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15097c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15107c478bd9Sstevel@tonic-gate return (rc); 15117c478bd9Sstevel@tonic-gate } 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate if (ptr->sp_lstchg >= 0) { 15147c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_lstchg); 15157c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowLastChange", ibuf); 15167c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15177c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15187c478bd9Sstevel@tonic-gate return (rc); 15197c478bd9Sstevel@tonic-gate } 15207c478bd9Sstevel@tonic-gate } 15217c478bd9Sstevel@tonic-gate if (ptr->sp_min >= 0) { 15227c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_min); 15237c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMin", ibuf); 15247c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15257c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15267c478bd9Sstevel@tonic-gate return (rc); 15277c478bd9Sstevel@tonic-gate } 15287c478bd9Sstevel@tonic-gate } 15297c478bd9Sstevel@tonic-gate if (ptr->sp_max >= 0) { 15307c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_max); 15317c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMax", ibuf); 15327c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15347c478bd9Sstevel@tonic-gate return (rc); 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate } 15377c478bd9Sstevel@tonic-gate if (ptr->sp_warn >= 0) { 15387c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_warn); 15397c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowWarning", ibuf); 15407c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15417c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15427c478bd9Sstevel@tonic-gate return (rc); 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate } 15457c478bd9Sstevel@tonic-gate if (ptr->sp_inact >= 0) { 15467c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_inact); 15477c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowInactive", ibuf); 15487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15507c478bd9Sstevel@tonic-gate return (rc); 15517c478bd9Sstevel@tonic-gate } 15527c478bd9Sstevel@tonic-gate } 15537c478bd9Sstevel@tonic-gate if (ptr->sp_expire >= 0) { 15547c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_expire); 15557c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowExpire", ibuf); 15567c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15577c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15587c478bd9Sstevel@tonic-gate return (rc); 15597c478bd9Sstevel@tonic-gate } 15607c478bd9Sstevel@tonic-gate } 15617c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_flag); 15627c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowFlag", ibuf); 15637c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15657c478bd9Sstevel@tonic-gate return (rc); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 15697c478bd9Sstevel@tonic-gate } 15707c478bd9Sstevel@tonic-gate 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate /* 15737c478bd9Sstevel@tonic-gate * Conversion: group 15747c478bd9Sstevel@tonic-gate * Input format: struct group 15757c478bd9Sstevel@tonic-gate * Exported objectclass: posixGroup 15767c478bd9Sstevel@tonic-gate */ 15777c478bd9Sstevel@tonic-gate static int 15787c478bd9Sstevel@tonic-gate __s_cvt_group(const void *data, char **rdn, 15797c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 15807c478bd9Sstevel@tonic-gate { 15817c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 15827c478bd9Sstevel@tonic-gate int rc; 15837c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 15847c478bd9Sstevel@tonic-gate /* routine specific */ 15857c478bd9Sstevel@tonic-gate struct group *ptr; 15867c478bd9Sstevel@tonic-gate int i, j, k; 15877c478bd9Sstevel@tonic-gate char **nm, **lm; 15887c478bd9Sstevel@tonic-gate int max_attr = 4; 15897c478bd9Sstevel@tonic-gate char ibuf[10]; 15907c478bd9Sstevel@tonic-gate static char *oclist[] = { 15917c478bd9Sstevel@tonic-gate "posixGroup", 15927c478bd9Sstevel@tonic-gate "top", 15937c478bd9Sstevel@tonic-gate NULL 15947c478bd9Sstevel@tonic-gate }; 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 15977c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 15987c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 15997c478bd9Sstevel@tonic-gate if (e == NULL) 16007c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate /* Convert the structure */ 16037c478bd9Sstevel@tonic-gate ptr = (struct group *)data; 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate if (ptr->gr_name == NULL || ptr->gr_gid < 0) { 16067c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 16077c478bd9Sstevel@tonic-gate *entry = NULL; 16087c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 16127c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->gr_name); 16137c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 16147c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 16157c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 16167c478bd9Sstevel@tonic-gate *entry = NULL; 16177c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16187c478bd9Sstevel@tonic-gate } 16197c478bd9Sstevel@tonic-gate 16207c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 16217c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->gr_name); 16227c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16237c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16247c478bd9Sstevel@tonic-gate return (rc); 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate #ifdef _LP64 16287c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->gr_gid); 16297c478bd9Sstevel@tonic-gate #else 16307c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->gr_gid); 16317c478bd9Sstevel@tonic-gate #endif 16327c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 16337c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16347c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16357c478bd9Sstevel@tonic-gate return (rc); 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate if (ptr->gr_passwd && ptr->gr_passwd[0] != '\0') { 16387c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->gr_passwd); 16397c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16407c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16417c478bd9Sstevel@tonic-gate return (rc); 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate } 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate if (ptr->gr_mem && ptr->gr_mem[0]) { 16467c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 16477c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 16487c478bd9Sstevel@tonic-gate ; 16497c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 16507c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 16517c478bd9Sstevel@tonic-gate if (nm == NULL) { 16527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16537c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 16567c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 16577c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 16587c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 16597c478bd9Sstevel@tonic-gate free(nm[k]); 16607c478bd9Sstevel@tonic-gate free(nm); 16617c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16627c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberUid", nm); 16667c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 16677c478bd9Sstevel@tonic-gate free(nm[j]); 16687c478bd9Sstevel@tonic-gate } 16697c478bd9Sstevel@tonic-gate free(nm); 16707c478bd9Sstevel@tonic-gate nm = NULL; 16717c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16727c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16737c478bd9Sstevel@tonic-gate return (rc); 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate } 16767c478bd9Sstevel@tonic-gate 16777c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 16787c478bd9Sstevel@tonic-gate } 16797c478bd9Sstevel@tonic-gate 16807c478bd9Sstevel@tonic-gate /* 16817c478bd9Sstevel@tonic-gate * Conversion: hosts 16827c478bd9Sstevel@tonic-gate * Input format: struct hostent 16837c478bd9Sstevel@tonic-gate * Exported objectclass: ipHost 16847c478bd9Sstevel@tonic-gate */ 16857c478bd9Sstevel@tonic-gate static int 16867c478bd9Sstevel@tonic-gate __s_cvt_hosts(const void *data, char **rdn, 16877c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 16887c478bd9Sstevel@tonic-gate { 16897c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 16907c478bd9Sstevel@tonic-gate int rc; 16917c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 16927c478bd9Sstevel@tonic-gate /* routine specific */ 16937c478bd9Sstevel@tonic-gate struct hostent *ptr; 16947c478bd9Sstevel@tonic-gate int max_attr = 6; 16957c478bd9Sstevel@tonic-gate int i, j, k; 16967c478bd9Sstevel@tonic-gate char **nm, **lm; 16977c478bd9Sstevel@tonic-gate static char *oclist[] = { 16987c478bd9Sstevel@tonic-gate "ipHost", 16997c478bd9Sstevel@tonic-gate "device", 17007c478bd9Sstevel@tonic-gate "top", 17017c478bd9Sstevel@tonic-gate NULL 17027c478bd9Sstevel@tonic-gate }; 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 17057c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 17067c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 17077c478bd9Sstevel@tonic-gate if (e == NULL) 17087c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate /* Convert the structure */ 17117c478bd9Sstevel@tonic-gate ptr = (struct hostent *)data; 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate if (ptr->h_name == NULL || 17147c478bd9Sstevel@tonic-gate ptr->h_addr_list == NULL || ptr->h_addr_list[0] == '\0') { 17157c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 17167c478bd9Sstevel@tonic-gate *entry = NULL; 17177c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate 17207c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 17217c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipHostNumber=%s", 17227c478bd9Sstevel@tonic-gate ptr->h_name, ptr->h_addr_list[0]); 17237c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 17247c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 17257c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 17267c478bd9Sstevel@tonic-gate *entry = NULL; 17277c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17287c478bd9Sstevel@tonic-gate } 17297c478bd9Sstevel@tonic-gate 17307c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 17317c478bd9Sstevel@tonic-gate if (ptr->h_aliases && ptr->h_aliases[0]) { 17327c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 17337c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 17347c478bd9Sstevel@tonic-gate ; 17357c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 17367c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 17377c478bd9Sstevel@tonic-gate if (nm == NULL) { 17387c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17397c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate nm[0] = ptr->h_name; 17427c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 17437c478bd9Sstevel@tonic-gate nm[j+1] = ptr->h_aliases[j]; 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 17467c478bd9Sstevel@tonic-gate free(nm); 17477c478bd9Sstevel@tonic-gate nm = NULL; 17487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17507c478bd9Sstevel@tonic-gate return (rc); 17517c478bd9Sstevel@tonic-gate } 17527c478bd9Sstevel@tonic-gate } else { 17537c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->h_name); 17547c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17557c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17567c478bd9Sstevel@tonic-gate return (rc); 17577c478bd9Sstevel@tonic-gate } 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate if (ptr->h_addr_list && ptr->h_addr_list[0]) { 17617c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 17627c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 17637c478bd9Sstevel@tonic-gate ; 17647c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 17657c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 17667c478bd9Sstevel@tonic-gate if (nm == NULL) { 17677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17687c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17697c478bd9Sstevel@tonic-gate } 17707c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 17717c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 17727c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 17737c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 17747c478bd9Sstevel@tonic-gate free(nm[k]); 17757c478bd9Sstevel@tonic-gate free(nm); 17767c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17777c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17787c478bd9Sstevel@tonic-gate } 17797c478bd9Sstevel@tonic-gate } 17807c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "ipHostNumber", nm); 17817c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 17827c478bd9Sstevel@tonic-gate free(nm[j]); 17837c478bd9Sstevel@tonic-gate } 17847c478bd9Sstevel@tonic-gate free(nm); 17857c478bd9Sstevel@tonic-gate nm = NULL; 17867c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17877c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17887c478bd9Sstevel@tonic-gate return (rc); 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate } else { 17917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17927c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 17937c478bd9Sstevel@tonic-gate } 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate /* 17997c478bd9Sstevel@tonic-gate * Conversion: rpc 18007c478bd9Sstevel@tonic-gate * Input format: struct rpcent 18017c478bd9Sstevel@tonic-gate * Exported objectclass: oncRpc 18027c478bd9Sstevel@tonic-gate */ 18037c478bd9Sstevel@tonic-gate static int 18047c478bd9Sstevel@tonic-gate __s_cvt_rpc(const void *data, char **rdn, 18057c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 18067c478bd9Sstevel@tonic-gate { 18077c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 18087c478bd9Sstevel@tonic-gate int rc; 18097c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 18107c478bd9Sstevel@tonic-gate /* routine specific */ 18117c478bd9Sstevel@tonic-gate struct rpcent *ptr; 18127c478bd9Sstevel@tonic-gate int max_attr = 3; 18137c478bd9Sstevel@tonic-gate int i, j; 18147c478bd9Sstevel@tonic-gate char **nm; 18157c478bd9Sstevel@tonic-gate char ibuf[10]; 18167c478bd9Sstevel@tonic-gate static char *oclist[] = { 18177c478bd9Sstevel@tonic-gate "oncRpc", 18187c478bd9Sstevel@tonic-gate "top", 18197c478bd9Sstevel@tonic-gate NULL 18207c478bd9Sstevel@tonic-gate }; 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 18237c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 18247c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 18257c478bd9Sstevel@tonic-gate if (e == NULL) 18267c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate /* Convert the structure */ 18297c478bd9Sstevel@tonic-gate ptr = (struct rpcent *)data; 18307c478bd9Sstevel@tonic-gate 18317c478bd9Sstevel@tonic-gate if (ptr->r_name == NULL || ptr->r_number < 0) { 18327c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18337c478bd9Sstevel@tonic-gate *entry = NULL; 18347c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 18357c478bd9Sstevel@tonic-gate } 18367c478bd9Sstevel@tonic-gate 18377c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 18387c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->r_name); 18397c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 18407c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 18417c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18427c478bd9Sstevel@tonic-gate *entry = NULL; 18437c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate 18467c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 18477c478bd9Sstevel@tonic-gate if (ptr->r_aliases && ptr->r_aliases[0]) { 18487c478bd9Sstevel@tonic-gate nm = ptr->r_aliases; 18497c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 18507c478bd9Sstevel@tonic-gate ; 18517c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 18527c478bd9Sstevel@tonic-gate if (nm == NULL) { 18537c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18547c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18557c478bd9Sstevel@tonic-gate } 18567c478bd9Sstevel@tonic-gate nm[0] = ptr->r_name; 18577c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 18587c478bd9Sstevel@tonic-gate nm[j+1] = ptr->r_aliases[j]; 18597c478bd9Sstevel@tonic-gate 18607c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 18617c478bd9Sstevel@tonic-gate free(nm); 18627c478bd9Sstevel@tonic-gate nm = NULL; 18637c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18657c478bd9Sstevel@tonic-gate return (rc); 18667c478bd9Sstevel@tonic-gate } 18677c478bd9Sstevel@tonic-gate } else { 18687c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->r_name); 18697c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18707c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18717c478bd9Sstevel@tonic-gate return (rc); 18727c478bd9Sstevel@tonic-gate } 18737c478bd9Sstevel@tonic-gate } 18747c478bd9Sstevel@tonic-gate 18757c478bd9Sstevel@tonic-gate if (ptr->r_number >= 0) { 18767c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->r_number); 18777c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "oncRpcNumber", ibuf); 18787c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18797c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18807c478bd9Sstevel@tonic-gate return (rc); 18817c478bd9Sstevel@tonic-gate } 18827c478bd9Sstevel@tonic-gate } 18837c478bd9Sstevel@tonic-gate 18847c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 18857c478bd9Sstevel@tonic-gate 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate 18887c478bd9Sstevel@tonic-gate /* 18897c478bd9Sstevel@tonic-gate * Conversion: protocols 18907c478bd9Sstevel@tonic-gate * Input format: struct protoent 18917c478bd9Sstevel@tonic-gate * Exported objectclass: ipProtocol 18927c478bd9Sstevel@tonic-gate */ 18937c478bd9Sstevel@tonic-gate static int 18947c478bd9Sstevel@tonic-gate __s_cvt_protocols(const void *data, char **rdn, 18957c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 18967c478bd9Sstevel@tonic-gate { 18977c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 18987c478bd9Sstevel@tonic-gate int rc; 18997c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 19007c478bd9Sstevel@tonic-gate /* routine specific */ 19017c478bd9Sstevel@tonic-gate struct protoent *ptr; 19027c478bd9Sstevel@tonic-gate int max_attr = 3; 19037c478bd9Sstevel@tonic-gate int i, j; 19047c478bd9Sstevel@tonic-gate char ibuf[10]; 19057c478bd9Sstevel@tonic-gate char **nm; 19067c478bd9Sstevel@tonic-gate static char *oclist[] = { 19077c478bd9Sstevel@tonic-gate "ipProtocol", 19087c478bd9Sstevel@tonic-gate "top", 19097c478bd9Sstevel@tonic-gate NULL 19107c478bd9Sstevel@tonic-gate }; 19117c478bd9Sstevel@tonic-gate 19127c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 19137c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 19147c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 19157c478bd9Sstevel@tonic-gate if (e == NULL) 19167c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate /* Convert the structure */ 19197c478bd9Sstevel@tonic-gate ptr = (struct protoent *)data; 19207c478bd9Sstevel@tonic-gate 19217c478bd9Sstevel@tonic-gate if (ptr->p_name == NULL || ptr->p_proto < 0) { 19227c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19237c478bd9Sstevel@tonic-gate *entry = NULL; 19247c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 19257c478bd9Sstevel@tonic-gate } 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 19287c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->p_name); 19297c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 19307c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 19317c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19327c478bd9Sstevel@tonic-gate *entry = NULL; 19337c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 19377c478bd9Sstevel@tonic-gate if (ptr->p_aliases && ptr->p_aliases[0]) { 19387c478bd9Sstevel@tonic-gate nm = ptr->p_aliases; 19397c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 19407c478bd9Sstevel@tonic-gate ; 19417c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 19427c478bd9Sstevel@tonic-gate if (nm == NULL) { 19437c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19447c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19457c478bd9Sstevel@tonic-gate } 19467c478bd9Sstevel@tonic-gate nm[0] = ptr->p_name; 19477c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 19487c478bd9Sstevel@tonic-gate nm[j+1] = ptr->p_aliases[j]; 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 19517c478bd9Sstevel@tonic-gate free(nm); 19527c478bd9Sstevel@tonic-gate nm = NULL; 19537c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19557c478bd9Sstevel@tonic-gate return (rc); 19567c478bd9Sstevel@tonic-gate } 19577c478bd9Sstevel@tonic-gate } else { 19587c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->p_name); 19597c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19607c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19617c478bd9Sstevel@tonic-gate return (rc); 19627c478bd9Sstevel@tonic-gate } 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->p_proto); 19667c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipProtocolNumber", ibuf); 19677c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19687c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19697c478bd9Sstevel@tonic-gate return (rc); 19707c478bd9Sstevel@tonic-gate } 19717c478bd9Sstevel@tonic-gate 19727c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 19737c478bd9Sstevel@tonic-gate 19747c478bd9Sstevel@tonic-gate } 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate /* 19777c478bd9Sstevel@tonic-gate * Conversion: services 19787c478bd9Sstevel@tonic-gate * Input format: struct servent 19797c478bd9Sstevel@tonic-gate * Exported objectclass: ipService 19807c478bd9Sstevel@tonic-gate */ 19817c478bd9Sstevel@tonic-gate static int 19827c478bd9Sstevel@tonic-gate __s_cvt_services(const void *data, char **rdn, 19837c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 19847c478bd9Sstevel@tonic-gate { 19857c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 19867c478bd9Sstevel@tonic-gate int rc; 19877c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 19887c478bd9Sstevel@tonic-gate /* routine specific */ 19897c478bd9Sstevel@tonic-gate struct servent *ptr; 19907c478bd9Sstevel@tonic-gate int max_attr = 4; 19917c478bd9Sstevel@tonic-gate int i, j; 19927c478bd9Sstevel@tonic-gate char ibuf[10]; 19937c478bd9Sstevel@tonic-gate char **nm; 19947c478bd9Sstevel@tonic-gate static char *oclist[] = { 19957c478bd9Sstevel@tonic-gate "ipService", 19967c478bd9Sstevel@tonic-gate "top", 19977c478bd9Sstevel@tonic-gate NULL 19987c478bd9Sstevel@tonic-gate }; 19997c478bd9Sstevel@tonic-gate 20007c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 20017c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 20027c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 20037c478bd9Sstevel@tonic-gate if (e == NULL) 20047c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate /* Convert the structure */ 20077c478bd9Sstevel@tonic-gate ptr = (struct servent *)data; 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate if (ptr->s_name == NULL || ptr->s_port < 0 || ptr->s_proto == '\0') { 20107c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20117c478bd9Sstevel@tonic-gate *entry = NULL; 20127c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 20137c478bd9Sstevel@tonic-gate } 20147c478bd9Sstevel@tonic-gate 20157c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 20167c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipServiceProtocol=%s", 20177c478bd9Sstevel@tonic-gate ptr->s_name, ptr->s_proto); 20187c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 20197c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 20207c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20217c478bd9Sstevel@tonic-gate *entry = NULL; 20227c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20237c478bd9Sstevel@tonic-gate } 20247c478bd9Sstevel@tonic-gate 20257c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 20267c478bd9Sstevel@tonic-gate if (ptr->s_aliases && ptr->s_aliases[0]) { 20277c478bd9Sstevel@tonic-gate nm = ptr->s_aliases; 20287c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 20297c478bd9Sstevel@tonic-gate ; 20307c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 20317c478bd9Sstevel@tonic-gate if (nm == NULL) { 20327c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20337c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20347c478bd9Sstevel@tonic-gate } 20357c478bd9Sstevel@tonic-gate nm[0] = ptr->s_name; 20367c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 20377c478bd9Sstevel@tonic-gate nm[j+1] = ptr->s_aliases[j]; 20387c478bd9Sstevel@tonic-gate 20397c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 20407c478bd9Sstevel@tonic-gate free(nm); 20417c478bd9Sstevel@tonic-gate nm = NULL; 20427c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20437c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20447c478bd9Sstevel@tonic-gate return (rc); 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate } else { 20477c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->s_name); 20487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20507c478bd9Sstevel@tonic-gate return (rc); 20517c478bd9Sstevel@tonic-gate } 20527c478bd9Sstevel@tonic-gate } 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->s_port); 20557c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServicePort", ibuf); 20567c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20577c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20587c478bd9Sstevel@tonic-gate return (rc); 20597c478bd9Sstevel@tonic-gate } 20607c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServiceProtocol", ptr->s_proto); 20617c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20627c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20637c478bd9Sstevel@tonic-gate return (rc); 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 20677c478bd9Sstevel@tonic-gate } 20687c478bd9Sstevel@tonic-gate 20697c478bd9Sstevel@tonic-gate /* 20707c478bd9Sstevel@tonic-gate * Conversion: networks 20717c478bd9Sstevel@tonic-gate * Input format: struct netent 20727c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 20737c478bd9Sstevel@tonic-gate */ 20747c478bd9Sstevel@tonic-gate static int 20757c478bd9Sstevel@tonic-gate __s_cvt_networks(const void *data, char **rdn, 20767c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 20777c478bd9Sstevel@tonic-gate { 20787c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 20797c478bd9Sstevel@tonic-gate int rc; 20807c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 20817c478bd9Sstevel@tonic-gate /* routine specific */ 20827c478bd9Sstevel@tonic-gate struct netent *ptr; 20837c478bd9Sstevel@tonic-gate int max_attr = 4; 20847c478bd9Sstevel@tonic-gate int i, j; 20857c478bd9Sstevel@tonic-gate char cp[64]; 20867c478bd9Sstevel@tonic-gate char **nm; 20877c478bd9Sstevel@tonic-gate static char *oclist[] = { 20887c478bd9Sstevel@tonic-gate "ipNetwork", 20897c478bd9Sstevel@tonic-gate "top", 20907c478bd9Sstevel@tonic-gate NULL 20917c478bd9Sstevel@tonic-gate }; 20927c478bd9Sstevel@tonic-gate 20937c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 20947c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 20957c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 20967c478bd9Sstevel@tonic-gate if (e == NULL) 20977c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate /* Convert the structure */ 21007c478bd9Sstevel@tonic-gate ptr = (struct netent *)data; 21017c478bd9Sstevel@tonic-gate 21027c478bd9Sstevel@tonic-gate if (ptr->n_name == NULL || ptr->n_net == 0) { 21037c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21047c478bd9Sstevel@tonic-gate *entry = NULL; 21057c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate 21087c478bd9Sstevel@tonic-gate (void) snprintf(cp, sizeof (cp), "%d.%d.%d.%d", 21097c478bd9Sstevel@tonic-gate (ptr->n_net & 0xFF000000) >> 24, 21107c478bd9Sstevel@tonic-gate (ptr->n_net & 0x00FF0000) >> 16, 21117c478bd9Sstevel@tonic-gate (ptr->n_net & 0x0000FF00) >> 8, 21127c478bd9Sstevel@tonic-gate (ptr->n_net & 0x000000FF)); 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 21157c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", cp); 21167c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 21177c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 21187c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21197c478bd9Sstevel@tonic-gate *entry = NULL; 21207c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21217c478bd9Sstevel@tonic-gate } 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 21247c478bd9Sstevel@tonic-gate if (ptr->n_aliases && ptr->n_aliases[0]) { 21257c478bd9Sstevel@tonic-gate nm = ptr->n_aliases; 21267c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 21277c478bd9Sstevel@tonic-gate ; 21287c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 21297c478bd9Sstevel@tonic-gate if (nm == NULL) { 21307c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21317c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21327c478bd9Sstevel@tonic-gate } 21337c478bd9Sstevel@tonic-gate nm[0] = ptr->n_name; 21347c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 21357c478bd9Sstevel@tonic-gate nm[j+1] = ptr->n_aliases[j]; 21367c478bd9Sstevel@tonic-gate 21377c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 21387c478bd9Sstevel@tonic-gate free(nm); 21397c478bd9Sstevel@tonic-gate nm = NULL; 21407c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21417c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21427c478bd9Sstevel@tonic-gate return (rc); 21437c478bd9Sstevel@tonic-gate } 21447c478bd9Sstevel@tonic-gate } else { 21457c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->n_name); 21467c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21477c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21487c478bd9Sstevel@tonic-gate return (rc); 21497c478bd9Sstevel@tonic-gate } 21507c478bd9Sstevel@tonic-gate } 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetworkNumber", cp); 21537c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21557c478bd9Sstevel@tonic-gate return (rc); 21567c478bd9Sstevel@tonic-gate } 21577c478bd9Sstevel@tonic-gate 21587c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 21597c478bd9Sstevel@tonic-gate 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate /* 21627c478bd9Sstevel@tonic-gate * Conversion: netmasks 21637c478bd9Sstevel@tonic-gate * Input format: struct _ns_netmasks 21647c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 21657c478bd9Sstevel@tonic-gate */ 21667c478bd9Sstevel@tonic-gate static int 21677c478bd9Sstevel@tonic-gate __s_cvt_netmasks(const void *data, char **rdn, 21687c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 21697c478bd9Sstevel@tonic-gate { 21707c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 21717c478bd9Sstevel@tonic-gate int rc; 21727c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 21737c478bd9Sstevel@tonic-gate /* routine specific */ 21747c478bd9Sstevel@tonic-gate struct _ns_netmasks *ptr; 21757c478bd9Sstevel@tonic-gate int max_attr = 4; 21767c478bd9Sstevel@tonic-gate static char *oclist[] = { 21777c478bd9Sstevel@tonic-gate "ipNetwork", 21787c478bd9Sstevel@tonic-gate "top", 21797c478bd9Sstevel@tonic-gate NULL 21807c478bd9Sstevel@tonic-gate }; 21817c478bd9Sstevel@tonic-gate 21827c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 21837c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 21847c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 21857c478bd9Sstevel@tonic-gate if (e == NULL) 21867c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate /* Convert the structure */ 21897c478bd9Sstevel@tonic-gate ptr = (struct _ns_netmasks *)data; 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate if (ptr->netnumber == NULL) { 21927c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21937c478bd9Sstevel@tonic-gate *entry = NULL; 21947c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21957c478bd9Sstevel@tonic-gate } 21967c478bd9Sstevel@tonic-gate 21977c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 21987c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", ptr->netnumber); 21997c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 22007c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 22017c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22027c478bd9Sstevel@tonic-gate *entry = NULL; 22037c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22047c478bd9Sstevel@tonic-gate } 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 22077c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetworkNumber", ptr->netnumber); 22087c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22097c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22107c478bd9Sstevel@tonic-gate return (rc); 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate if (ptr->netmask != '\0') { 22147c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetmaskNumber", ptr->netmask); 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 * Conversion: netgroups 22267c478bd9Sstevel@tonic-gate * Input format: struct _ns_netgroups 22277c478bd9Sstevel@tonic-gate * Exported objectclass: nisNetgroup 22287c478bd9Sstevel@tonic-gate */ 22297c478bd9Sstevel@tonic-gate static int 22307c478bd9Sstevel@tonic-gate __s_cvt_netgroups(const void *data, char **rdn, 22317c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 22327c478bd9Sstevel@tonic-gate { 22337c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 22347c478bd9Sstevel@tonic-gate int rc; 22357c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 22367c478bd9Sstevel@tonic-gate /* routine specific */ 22377c478bd9Sstevel@tonic-gate struct _ns_netgroups *ptr; 22387c478bd9Sstevel@tonic-gate int max_attr = 6; 22397c478bd9Sstevel@tonic-gate int i, j; 22407c478bd9Sstevel@tonic-gate char **nm; 22417c478bd9Sstevel@tonic-gate static char *oclist[] = { 22427c478bd9Sstevel@tonic-gate "nisNetgroup", 22437c478bd9Sstevel@tonic-gate "top", 22447c478bd9Sstevel@tonic-gate NULL 22457c478bd9Sstevel@tonic-gate }; 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 22487c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 22497c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 22507c478bd9Sstevel@tonic-gate if (e == NULL) 22517c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22527c478bd9Sstevel@tonic-gate 22537c478bd9Sstevel@tonic-gate /* Convert the structure */ 22547c478bd9Sstevel@tonic-gate ptr = (struct _ns_netgroups *)data; 22557c478bd9Sstevel@tonic-gate 22567c478bd9Sstevel@tonic-gate if (ptr->name == NULL) { 22577c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22587c478bd9Sstevel@tonic-gate *entry = NULL; 22597c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 22607c478bd9Sstevel@tonic-gate } 22617c478bd9Sstevel@tonic-gate 22627c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 22637c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 22647c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 22657c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 22667c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22677c478bd9Sstevel@tonic-gate *entry = NULL; 22687c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22697c478bd9Sstevel@tonic-gate } 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate if (ptr->name != '\0') { 22727c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 22737c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22747c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22757c478bd9Sstevel@tonic-gate return (rc); 22767c478bd9Sstevel@tonic-gate } 22777c478bd9Sstevel@tonic-gate } 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 22807c478bd9Sstevel@tonic-gate if (ptr->triplet && ptr->triplet[0]) { 22817c478bd9Sstevel@tonic-gate nm = ptr->triplet; 22827c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 22837c478bd9Sstevel@tonic-gate ; 22847c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 22857c478bd9Sstevel@tonic-gate if (nm == NULL) { 22867c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22877c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22887c478bd9Sstevel@tonic-gate } 22897c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 22907c478bd9Sstevel@tonic-gate nm[j] = ptr->triplet[j]; 22917c478bd9Sstevel@tonic-gate 22927c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "nisNetgroupTriple", nm); 22937c478bd9Sstevel@tonic-gate free(nm); 22947c478bd9Sstevel@tonic-gate nm = NULL; 22957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22977c478bd9Sstevel@tonic-gate return (rc); 22987c478bd9Sstevel@tonic-gate } 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate if (ptr->netgroup && ptr->netgroup[0]) { 23017c478bd9Sstevel@tonic-gate nm = ptr->netgroup; 23027c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 23037c478bd9Sstevel@tonic-gate ; 23047c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 23057c478bd9Sstevel@tonic-gate if (nm == NULL) { 23067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23077c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23087c478bd9Sstevel@tonic-gate } 23097c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 23107c478bd9Sstevel@tonic-gate nm[j] = ptr->netgroup[j]; 23117c478bd9Sstevel@tonic-gate 23127c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberNisNetgroup", nm); 23137c478bd9Sstevel@tonic-gate free(nm); 23147c478bd9Sstevel@tonic-gate nm = NULL; 23157c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23167c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23177c478bd9Sstevel@tonic-gate return (rc); 23187c478bd9Sstevel@tonic-gate } 23197c478bd9Sstevel@tonic-gate } 23207c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 23217c478bd9Sstevel@tonic-gate } 23227c478bd9Sstevel@tonic-gate /* 23237c478bd9Sstevel@tonic-gate * Conversion: bootparams 23247c478bd9Sstevel@tonic-gate * Input format: struct _ns_bootp 23257c478bd9Sstevel@tonic-gate * Exported objectclass: bootableDevice, device 23267c478bd9Sstevel@tonic-gate */ 23277c478bd9Sstevel@tonic-gate static int 23287c478bd9Sstevel@tonic-gate __s_cvt_bootparams(const void *data, char **rdn, 23297c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 23307c478bd9Sstevel@tonic-gate { 23317c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 23327c478bd9Sstevel@tonic-gate int rc; 23337c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 23347c478bd9Sstevel@tonic-gate /* routine specific */ 23357c478bd9Sstevel@tonic-gate struct _ns_bootp *ptr; 23367c478bd9Sstevel@tonic-gate int max_attr = 4; 23377c478bd9Sstevel@tonic-gate int i, j; 23387c478bd9Sstevel@tonic-gate char **nm; 23397c478bd9Sstevel@tonic-gate static char *oclist[] = { 23407c478bd9Sstevel@tonic-gate "bootableDevice", 23417c478bd9Sstevel@tonic-gate "device", 23427c478bd9Sstevel@tonic-gate "top", 23437c478bd9Sstevel@tonic-gate NULL 23447c478bd9Sstevel@tonic-gate }; 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 23477c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 23487c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 23497c478bd9Sstevel@tonic-gate if (e == NULL) 23507c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23517c478bd9Sstevel@tonic-gate 23527c478bd9Sstevel@tonic-gate /* Convert the structure */ 23537c478bd9Sstevel@tonic-gate ptr = (struct _ns_bootp *)data; 23547c478bd9Sstevel@tonic-gate 23557c478bd9Sstevel@tonic-gate if (ptr->name == NULL) { 23567c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23577c478bd9Sstevel@tonic-gate *entry = NULL; 23587c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 23597c478bd9Sstevel@tonic-gate } 23607c478bd9Sstevel@tonic-gate 23617c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 23627c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 23637c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 23647c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 23657c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23667c478bd9Sstevel@tonic-gate *entry = NULL; 23677c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23687c478bd9Sstevel@tonic-gate } 23697c478bd9Sstevel@tonic-gate 23707c478bd9Sstevel@tonic-gate if (ptr->name != '\0') { 23717c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 23727c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23737c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23747c478bd9Sstevel@tonic-gate return (rc); 23757c478bd9Sstevel@tonic-gate } 23767c478bd9Sstevel@tonic-gate } 23777c478bd9Sstevel@tonic-gate 23787c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 23797c478bd9Sstevel@tonic-gate if (ptr->param && ptr->param[0]) { 23807c478bd9Sstevel@tonic-gate nm = ptr->param; 23817c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 23827c478bd9Sstevel@tonic-gate ; 23837c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 23847c478bd9Sstevel@tonic-gate if (nm == NULL) { 23857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23867c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23877c478bd9Sstevel@tonic-gate } 23887c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 23897c478bd9Sstevel@tonic-gate nm[j] = ptr->param[j]; 23907c478bd9Sstevel@tonic-gate 23917c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "bootParameter", nm); 23927c478bd9Sstevel@tonic-gate free(nm); 23937c478bd9Sstevel@tonic-gate nm = NULL; 23947c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23957c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23967c478bd9Sstevel@tonic-gate return (rc); 23977c478bd9Sstevel@tonic-gate } 23987c478bd9Sstevel@tonic-gate } 23997c478bd9Sstevel@tonic-gate 24007c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate } 24037c478bd9Sstevel@tonic-gate /* 24047c478bd9Sstevel@tonic-gate * Conversion: ethers 24057c478bd9Sstevel@tonic-gate * Input format: struct _ns_ethers 24067c478bd9Sstevel@tonic-gate * Exported objectclass: ieee802Device, device 24077c478bd9Sstevel@tonic-gate */ 24087c478bd9Sstevel@tonic-gate static int 24097c478bd9Sstevel@tonic-gate __s_cvt_ethers(const void *data, char **rdn, 24107c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 24117c478bd9Sstevel@tonic-gate { 24127c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 24137c478bd9Sstevel@tonic-gate int rc; 24147c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 24157c478bd9Sstevel@tonic-gate /* routine specific */ 24167c478bd9Sstevel@tonic-gate struct _ns_ethers *ptr; 24177c478bd9Sstevel@tonic-gate int max_attr = 4; 24187c478bd9Sstevel@tonic-gate static char *oclist[] = { 24197c478bd9Sstevel@tonic-gate "ieee802Device", 24207c478bd9Sstevel@tonic-gate "device", 24217c478bd9Sstevel@tonic-gate "top", 24227c478bd9Sstevel@tonic-gate NULL 24237c478bd9Sstevel@tonic-gate }; 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 24267c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 24277c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 24287c478bd9Sstevel@tonic-gate if (e == NULL) 24297c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24307c478bd9Sstevel@tonic-gate 24317c478bd9Sstevel@tonic-gate /* Convert the structure */ 24327c478bd9Sstevel@tonic-gate ptr = (struct _ns_ethers *)data; 24337c478bd9Sstevel@tonic-gate 24347c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->ether == '\0') { 24357c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24367c478bd9Sstevel@tonic-gate *entry = NULL; 24377c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 24387c478bd9Sstevel@tonic-gate } 24397c478bd9Sstevel@tonic-gate 24407c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 24417c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 24427c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 24437c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 24447c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24457c478bd9Sstevel@tonic-gate *entry = NULL; 24467c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24477c478bd9Sstevel@tonic-gate } 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 24507c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 24517c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24537c478bd9Sstevel@tonic-gate return (rc); 24547c478bd9Sstevel@tonic-gate } 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "macAddress", ptr->ether); 24577c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24587c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24597c478bd9Sstevel@tonic-gate return (rc); 24607c478bd9Sstevel@tonic-gate } 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 24637c478bd9Sstevel@tonic-gate } 24647c478bd9Sstevel@tonic-gate /* 24657c478bd9Sstevel@tonic-gate * This function is used when processing an ethers (objectclass: ieee802Device) 24667c478bd9Sstevel@tonic-gate * or a bootparams (objectclass: bootableDevice) entry, and the entry is 24677c478bd9Sstevel@tonic-gate * already found in LDAP. Since both ethers and bootparams share the same 24687c478bd9Sstevel@tonic-gate * LDAP container, we want to check that the entry found in LDAP is: 24697c478bd9Sstevel@tonic-gate * - either the same entry (same cn, same objectclass): we don't do anything 24707c478bd9Sstevel@tonic-gate * in this case 24717c478bd9Sstevel@tonic-gate * - or an entry which does not have the objectclass we are interesting in: 24727c478bd9Sstevel@tonic-gate * in this case, we modify the existing entry by adding the relevant 24737c478bd9Sstevel@tonic-gate * objectclass (ieee802Device or bootableDevice) and the relevant attribute(s) 24747c478bd9Sstevel@tonic-gate * from the attribute list previously computing by the relevant conversion 24757c478bd9Sstevel@tonic-gate * function. 24767c478bd9Sstevel@tonic-gate * Note: from conversion functions __s_cvt_ethers() and __s_cvt_bootparams() 24777c478bd9Sstevel@tonic-gate * we know that there is only 1 more attribute today to add (macAddress 24787c478bd9Sstevel@tonic-gate * or bootParameter) 24797c478bd9Sstevel@tonic-gate */ 24807c478bd9Sstevel@tonic-gate #define _MAX_ATTR_ETHBOOTP 2 24817c478bd9Sstevel@tonic-gate static int 24827c478bd9Sstevel@tonic-gate modify_ethers_bootp( 24837c478bd9Sstevel@tonic-gate const char *service, 24847c478bd9Sstevel@tonic-gate const char *rdn, 24857c478bd9Sstevel@tonic-gate const char *fulldn, 24867c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attrlist, 24877c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 24887c478bd9Sstevel@tonic-gate const int flags, 24897c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 24907c478bd9Sstevel@tonic-gate { 24917c478bd9Sstevel@tonic-gate char filter[BUFSIZ]; 24927c478bd9Sstevel@tonic-gate ns_ldap_result_t *resultp; 24937c478bd9Sstevel@tonic-gate int rc = 0; 24947c478bd9Sstevel@tonic-gate int i; 24957c478bd9Sstevel@tonic-gate ns_ldap_attr_t *new_attrlist[_MAX_ATTR_ETHBOOTP+1]; 24967c478bd9Sstevel@tonic-gate ns_ldap_attr_t new_attrlist0; 24977c478bd9Sstevel@tonic-gate char *new_attrvalue0[1]; 24987c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *aptr = attrlist; 24997c478bd9Sstevel@tonic-gate ns_ldap_attr_t *aptr2; 25007c478bd9Sstevel@tonic-gate ns_ldap_error_t *new_errorp = NULL; 25017c478bd9Sstevel@tonic-gate 25027c478bd9Sstevel@tonic-gate if (rdn == NULL || fulldn == NULL || attrlist == NULL || 25037c478bd9Sstevel@tonic-gate errorp == NULL || service == NULL) 25047c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 25057c478bd9Sstevel@tonic-gate 25067c478bd9Sstevel@tonic-gate bzero(&new_attrlist, sizeof (new_attrlist)); 25077c478bd9Sstevel@tonic-gate bzero(&new_attrlist0, sizeof (new_attrlist0)); 25087c478bd9Sstevel@tonic-gate new_attrlist[0] = &new_attrlist0; 25097c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue = new_attrvalue0; 25107c478bd9Sstevel@tonic-gate 25117c478bd9Sstevel@tonic-gate new_attrlist[0]->attrname = "objectclass"; 25127c478bd9Sstevel@tonic-gate new_attrlist[0]->value_count = 1; 25137c478bd9Sstevel@tonic-gate if (strcasecmp(service, "ethers") == NULL) { 25147c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 25157c478bd9Sstevel@tonic-gate "(&(objectClass=ieee802Device)(%s))", 25167c478bd9Sstevel@tonic-gate rdn); 25177c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "ieee802Device"; 25187c478bd9Sstevel@tonic-gate } else { 25197c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 25207c478bd9Sstevel@tonic-gate "(&(objectClass=bootableDevice)(%s))", 25217c478bd9Sstevel@tonic-gate rdn); 25227c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "bootableDevice"; 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25257c478bd9Sstevel@tonic-gate rc = __ns_ldap_list(service, filter, NULL, (const char **)NULL, 25267c478bd9Sstevel@tonic-gate NULL, NS_LDAP_SCOPE_SUBTREE, &resultp, &new_errorp, 25277c478bd9Sstevel@tonic-gate NULL, NULL); 25287c478bd9Sstevel@tonic-gate 25297c478bd9Sstevel@tonic-gate switch (rc) { 25307c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 25317c478bd9Sstevel@tonic-gate /* 25327c478bd9Sstevel@tonic-gate * entry already exists for this service 25337c478bd9Sstevel@tonic-gate * return NS_LDAP_INTERNAL and do not modify the incoming errorp 25347c478bd9Sstevel@tonic-gate */ 25357c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 25367c478bd9Sstevel@tonic-gate break; 25377c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 25387c478bd9Sstevel@tonic-gate /* 25397c478bd9Sstevel@tonic-gate * entry not found with the given objectclasss but entry exists 25407c478bd9Sstevel@tonic-gate * hence add the relevant attribute (macAddress or bootparams). 25417c478bd9Sstevel@tonic-gate */ 25427c478bd9Sstevel@tonic-gate i = 1; 25437c478bd9Sstevel@tonic-gate while (*aptr && (i < _MAX_ATTR_ETHBOOTP)) { 25447c478bd9Sstevel@tonic-gate /* aptr2 needed here to avoid lint warning */ 25457c478bd9Sstevel@tonic-gate aptr2 = (ns_ldap_attr_t *)*aptr++; 25467c478bd9Sstevel@tonic-gate if ((strcasecmp(aptr2->attrname, "cn") != 0) && 25477c478bd9Sstevel@tonic-gate (strcasecmp(aptr2->attrname, 25487c478bd9Sstevel@tonic-gate "objectclass") != 0)) { 25497c478bd9Sstevel@tonic-gate new_attrlist[i++] = (ns_ldap_attr_t *)aptr2; 25507c478bd9Sstevel@tonic-gate } 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate 25537c478bd9Sstevel@tonic-gate if (i != _MAX_ATTR_ETHBOOTP) { 25547c478bd9Sstevel@tonic-gate /* we haven't found all expected attributes */ 25557c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 25567c478bd9Sstevel@tonic-gate break; 25577c478bd9Sstevel@tonic-gate } 25587c478bd9Sstevel@tonic-gate 25597c478bd9Sstevel@tonic-gate aptr = (const ns_ldap_attr_t * const *) new_attrlist; 25607c478bd9Sstevel@tonic-gate /* clean errorp first */ 25617c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 25627c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, aptr, cred, flags, 25637c478bd9Sstevel@tonic-gate errorp); 25647c478bd9Sstevel@tonic-gate break; 25657c478bd9Sstevel@tonic-gate default: 25667c478bd9Sstevel@tonic-gate /* 25677c478bd9Sstevel@tonic-gate * unexpected error happenned 25687c478bd9Sstevel@tonic-gate * returning relevant error 25697c478bd9Sstevel@tonic-gate */ 25707c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 25717c478bd9Sstevel@tonic-gate *errorp = new_errorp; 25727c478bd9Sstevel@tonic-gate break; 25737c478bd9Sstevel@tonic-gate } 25747c478bd9Sstevel@tonic-gate 25757c478bd9Sstevel@tonic-gate return (rc); 25767c478bd9Sstevel@tonic-gate } 25777c478bd9Sstevel@tonic-gate 25787c478bd9Sstevel@tonic-gate /* 25797c478bd9Sstevel@tonic-gate * Conversion: publickey 25807c478bd9Sstevel@tonic-gate * Input format: struct _ns_pubkey 25817c478bd9Sstevel@tonic-gate * Exported objectclass: NisKeyObject 25827c478bd9Sstevel@tonic-gate */ 25837c478bd9Sstevel@tonic-gate static int 25847c478bd9Sstevel@tonic-gate __s_cvt_publickey(const void *data, char **rdn, 25857c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 25867c478bd9Sstevel@tonic-gate { 25877c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 25887c478bd9Sstevel@tonic-gate int rc; 25897c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 25907c478bd9Sstevel@tonic-gate /* routine specific */ 25917c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 25927c478bd9Sstevel@tonic-gate int max_attr = 3; 25937c478bd9Sstevel@tonic-gate static char *oclist[] = { 25947c478bd9Sstevel@tonic-gate "NisKeyObject", 25957c478bd9Sstevel@tonic-gate NULL 25967c478bd9Sstevel@tonic-gate }; 25977c478bd9Sstevel@tonic-gate 25987c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 25997c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 26007c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 26017c478bd9Sstevel@tonic-gate if (e == NULL) 26027c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate /* Convert the structure */ 26057c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 26067c478bd9Sstevel@tonic-gate 26077c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->pubkey == '\0' || ptr->privkey == '\0') { 26087c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26097c478bd9Sstevel@tonic-gate *entry = NULL; 26107c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 26117c478bd9Sstevel@tonic-gate } 26127c478bd9Sstevel@tonic-gate 26137c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 26147c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_FALSE) 26157c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 26167c478bd9Sstevel@tonic-gate else 26177c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 26187c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 26197c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 26207c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26217c478bd9Sstevel@tonic-gate *entry = NULL; 26227c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26237c478bd9Sstevel@tonic-gate } 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 26267c478bd9Sstevel@tonic-gate 26277c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisPublickey", ptr->pubkey); 26287c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26297c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26307c478bd9Sstevel@tonic-gate return (rc); 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate 26337c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisSecretkey", ptr->privkey); 26347c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26357c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26367c478bd9Sstevel@tonic-gate return (rc); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate 26397c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate /* 26427c478bd9Sstevel@tonic-gate * Conversion: aliases 26437c478bd9Sstevel@tonic-gate * Input format: struct _ns_alias 26447c478bd9Sstevel@tonic-gate * Exported objectclass: mailGroup 26457c478bd9Sstevel@tonic-gate */ 26467c478bd9Sstevel@tonic-gate static int 26477c478bd9Sstevel@tonic-gate __s_cvt_aliases(const void *data, char **rdn, 26487c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 26497c478bd9Sstevel@tonic-gate { 26507c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 26517c478bd9Sstevel@tonic-gate int rc; 26527c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 26537c478bd9Sstevel@tonic-gate /* routine specific */ 26547c478bd9Sstevel@tonic-gate struct _ns_alias *ptr; 26557c478bd9Sstevel@tonic-gate int max_attr = 4; 26567c478bd9Sstevel@tonic-gate int i, j; 26577c478bd9Sstevel@tonic-gate char **nm; 26587c478bd9Sstevel@tonic-gate static char *oclist[] = { 26597c478bd9Sstevel@tonic-gate "mailGroup", 26607c478bd9Sstevel@tonic-gate "top", 26617c478bd9Sstevel@tonic-gate NULL 26627c478bd9Sstevel@tonic-gate }; 26637c478bd9Sstevel@tonic-gate 26647c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 26657c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 26667c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 26677c478bd9Sstevel@tonic-gate if (e == NULL) 26687c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26697c478bd9Sstevel@tonic-gate 26707c478bd9Sstevel@tonic-gate /* Convert the structure */ 26717c478bd9Sstevel@tonic-gate ptr = (struct _ns_alias *)data; 26727c478bd9Sstevel@tonic-gate 26737c478bd9Sstevel@tonic-gate if (ptr->alias == NULL) { 26747c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26757c478bd9Sstevel@tonic-gate *entry = NULL; 26767c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 26777c478bd9Sstevel@tonic-gate } 26787c478bd9Sstevel@tonic-gate 26797c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 26807c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->alias); 26817c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 26827c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 26837c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26847c478bd9Sstevel@tonic-gate *entry = NULL; 26857c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26867c478bd9Sstevel@tonic-gate } 26877c478bd9Sstevel@tonic-gate 26887c478bd9Sstevel@tonic-gate if (ptr->alias != '\0') { 26897c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "mail", (char *)ptr->alias); 26907c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26927c478bd9Sstevel@tonic-gate return (rc); 26937c478bd9Sstevel@tonic-gate } 26947c478bd9Sstevel@tonic-gate } 26957c478bd9Sstevel@tonic-gate 26967c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 26977c478bd9Sstevel@tonic-gate if (ptr->member && ptr->member[0]) { 26987c478bd9Sstevel@tonic-gate nm = ptr->member; 26997c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 27007c478bd9Sstevel@tonic-gate ; 27017c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 27027c478bd9Sstevel@tonic-gate if (nm == NULL) { 27037c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27047c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27057c478bd9Sstevel@tonic-gate } 27067c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 27077c478bd9Sstevel@tonic-gate nm[j] = ptr->member[j]; 27087c478bd9Sstevel@tonic-gate 27097c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "mgrpRFC822MailMember", nm); 27107c478bd9Sstevel@tonic-gate free(nm); 27117c478bd9Sstevel@tonic-gate nm = NULL; 27127c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27147c478bd9Sstevel@tonic-gate return (rc); 27157c478bd9Sstevel@tonic-gate } 27167c478bd9Sstevel@tonic-gate } 27177c478bd9Sstevel@tonic-gate 27187c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 27197c478bd9Sstevel@tonic-gate 27207c478bd9Sstevel@tonic-gate } 27217c478bd9Sstevel@tonic-gate /* 27227c478bd9Sstevel@tonic-gate * Conversion: automount 27237c478bd9Sstevel@tonic-gate * Input format: struct _ns_automount 27247c478bd9Sstevel@tonic-gate * Exported objectclass: automount 27257c478bd9Sstevel@tonic-gate */ 27267c478bd9Sstevel@tonic-gate static int 27277c478bd9Sstevel@tonic-gate __s_cvt_auto_mount(const void *data, char **rdn, 27287c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 27297c478bd9Sstevel@tonic-gate { 27307c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 27317c478bd9Sstevel@tonic-gate int rc; 27327c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 27337c478bd9Sstevel@tonic-gate /* routine specific */ 27347c478bd9Sstevel@tonic-gate struct _ns_automount *ptr; 27357c478bd9Sstevel@tonic-gate int max_attr = 6; 27367c478bd9Sstevel@tonic-gate void **paramVal = NULL; 27377c478bd9Sstevel@tonic-gate char **mappedschema = NULL; 27387c478bd9Sstevel@tonic-gate int version1 = 0; 27397c478bd9Sstevel@tonic-gate static char *oclist[] = { 27407c478bd9Sstevel@tonic-gate NULL, 27417c478bd9Sstevel@tonic-gate "top", 27427c478bd9Sstevel@tonic-gate NULL 27437c478bd9Sstevel@tonic-gate }; 27447c478bd9Sstevel@tonic-gate 27457c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 27467c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 27477c478bd9Sstevel@tonic-gate 27487c478bd9Sstevel@tonic-gate /* determine profile version number */ 27497c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, ¶mVal, errorp); 27507c478bd9Sstevel@tonic-gate if (paramVal && *paramVal && 27517c478bd9Sstevel@tonic-gate strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0) 27527c478bd9Sstevel@tonic-gate version1 = 1; 27537c478bd9Sstevel@tonic-gate if (paramVal) 27547c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 27557c478bd9Sstevel@tonic-gate if (rc && errorp) 27567c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 27577c478bd9Sstevel@tonic-gate 27587c478bd9Sstevel@tonic-gate /* use old schema for version 1 profiles */ 27597c478bd9Sstevel@tonic-gate if (version1) 27607c478bd9Sstevel@tonic-gate oclist[0] = "nisObject"; 27617c478bd9Sstevel@tonic-gate else 27627c478bd9Sstevel@tonic-gate oclist[0] = "automount"; 27637c478bd9Sstevel@tonic-gate 27647c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 27657c478bd9Sstevel@tonic-gate if (e == NULL) 27667c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27677c478bd9Sstevel@tonic-gate 27687c478bd9Sstevel@tonic-gate /* Convert the structure */ 27697c478bd9Sstevel@tonic-gate ptr = (struct _ns_automount *)data; 27707c478bd9Sstevel@tonic-gate 27717c478bd9Sstevel@tonic-gate if (ptr->key == NULL || ptr->value == '\0' || ptr->mapname == '\0') { 27727c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27737c478bd9Sstevel@tonic-gate *entry = NULL; 27747c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 27757c478bd9Sstevel@tonic-gate } 27767c478bd9Sstevel@tonic-gate 27777c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 27787c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, version1 ? "cn=%s" : "automountKey=%s", 27797c478bd9Sstevel@tonic-gate ptr->key); 27807c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 27817c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 27827c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27837c478bd9Sstevel@tonic-gate *entry = NULL; 27847c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27857c478bd9Sstevel@tonic-gate } 27867c478bd9Sstevel@tonic-gate 27877c478bd9Sstevel@tonic-gate if (ptr->key != '\0') { 27887c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, version1 ? "cn" : "automountKey", 27897c478bd9Sstevel@tonic-gate (char *)ptr->key); 27907c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27927c478bd9Sstevel@tonic-gate return (rc); 27937c478bd9Sstevel@tonic-gate } 27947c478bd9Sstevel@tonic-gate } 27957c478bd9Sstevel@tonic-gate 27967c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, version1 ? "nisMapEntry" : "automountInformation", 27977c478bd9Sstevel@tonic-gate (char *)ptr->value); 27987c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27997c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28007c478bd9Sstevel@tonic-gate return (rc); 28017c478bd9Sstevel@tonic-gate } 28027c478bd9Sstevel@tonic-gate 28037c478bd9Sstevel@tonic-gate /* 28047c478bd9Sstevel@tonic-gate * even for version 2, if automount is mapped to nisObject we 28057c478bd9Sstevel@tonic-gate * still need 'nisMapName' attribute 28067c478bd9Sstevel@tonic-gate */ 28077c478bd9Sstevel@tonic-gate mappedschema = __ns_ldap_getMappedObjectClass("automount", "automount"); 28087c478bd9Sstevel@tonic-gate if (mappedschema && mappedschema[0] && 28097c478bd9Sstevel@tonic-gate strcasecmp(mappedschema[0], "nisObject") == 0) 28107c478bd9Sstevel@tonic-gate version1 = 1; 28117c478bd9Sstevel@tonic-gate if (mappedschema) 28127c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedschema); 28137c478bd9Sstevel@tonic-gate 28147c478bd9Sstevel@tonic-gate if (version1) { 28157c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisMapName", (char *)ptr->mapname); 28167c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28177c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28187c478bd9Sstevel@tonic-gate return (rc); 28197c478bd9Sstevel@tonic-gate } 28207c478bd9Sstevel@tonic-gate } 28217c478bd9Sstevel@tonic-gate 28227c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 28237c478bd9Sstevel@tonic-gate } 28247c478bd9Sstevel@tonic-gate /* 28257c478bd9Sstevel@tonic-gate * Conversion: auth_attr 28267c478bd9Sstevel@tonic-gate * Input format: authstr_t 28277c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuthAttr 28287c478bd9Sstevel@tonic-gate */ 28297c478bd9Sstevel@tonic-gate static int 28307c478bd9Sstevel@tonic-gate __s_cvt_authattr(const void *data, char **rdn, 28317c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 28327c478bd9Sstevel@tonic-gate { 28337c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 28347c478bd9Sstevel@tonic-gate int rc; 28357c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 28367c478bd9Sstevel@tonic-gate /* routine specific */ 28377c478bd9Sstevel@tonic-gate authstr_t *ptr; 28387c478bd9Sstevel@tonic-gate int max_attr = 6; 28397c478bd9Sstevel@tonic-gate static char *oclist[] = { 28407c478bd9Sstevel@tonic-gate "SolarisAuthAttr", 28417c478bd9Sstevel@tonic-gate "top", 28427c478bd9Sstevel@tonic-gate NULL 28437c478bd9Sstevel@tonic-gate }; 28447c478bd9Sstevel@tonic-gate 28457c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 28467c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 28477c478bd9Sstevel@tonic-gate 28487c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 28497c478bd9Sstevel@tonic-gate if (e == NULL) 28507c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate /* Convert the structure */ 28537c478bd9Sstevel@tonic-gate ptr = (authstr_t *)data; 28547c478bd9Sstevel@tonic-gate 28557c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 28567c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 28577c478bd9Sstevel@tonic-gate *entry = NULL; 28587c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 28597c478bd9Sstevel@tonic-gate } 28607c478bd9Sstevel@tonic-gate 28617c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 28627c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 28637c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 28647c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 28657c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 28667c478bd9Sstevel@tonic-gate *entry = NULL; 28677c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 28687c478bd9Sstevel@tonic-gate } 28697c478bd9Sstevel@tonic-gate 28707c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 28717c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28727c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28737c478bd9Sstevel@tonic-gate return (rc); 28747c478bd9Sstevel@tonic-gate } 28757c478bd9Sstevel@tonic-gate 28767c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 28777c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28787c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28797c478bd9Sstevel@tonic-gate return (rc); 28807c478bd9Sstevel@tonic-gate } 28817c478bd9Sstevel@tonic-gate 28827c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 28837c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 28847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28867c478bd9Sstevel@tonic-gate return (rc); 28877c478bd9Sstevel@tonic-gate } 28887c478bd9Sstevel@tonic-gate } 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 28917c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 28927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28947c478bd9Sstevel@tonic-gate return (rc); 28957c478bd9Sstevel@tonic-gate } 28967c478bd9Sstevel@tonic-gate } 28977c478bd9Sstevel@tonic-gate 28987c478bd9Sstevel@tonic-gate if (ptr->short_desc != NULL) { 28997c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrShortDesc", ptr->short_desc); 29007c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29017c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29027c478bd9Sstevel@tonic-gate return (rc); 29037c478bd9Sstevel@tonic-gate } 29047c478bd9Sstevel@tonic-gate } 29057c478bd9Sstevel@tonic-gate 29067c478bd9Sstevel@tonic-gate if (ptr->long_desc != NULL) { 29077c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->long_desc); 29087c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29097c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29107c478bd9Sstevel@tonic-gate return (rc); 29117c478bd9Sstevel@tonic-gate } 29127c478bd9Sstevel@tonic-gate } 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 29157c478bd9Sstevel@tonic-gate } 29167c478bd9Sstevel@tonic-gate /* 29177c478bd9Sstevel@tonic-gate * Conversion: exec_attr 29187c478bd9Sstevel@tonic-gate * Input format: execstr_t 29197c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisExecAttr 29207c478bd9Sstevel@tonic-gate */ 29217c478bd9Sstevel@tonic-gate static int 29227c478bd9Sstevel@tonic-gate __s_cvt_execattr(const void *data, char **rdn, 29237c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 29247c478bd9Sstevel@tonic-gate { 29257c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 29267c478bd9Sstevel@tonic-gate int rc; 29277c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 29287c478bd9Sstevel@tonic-gate /* routine specific */ 29297c478bd9Sstevel@tonic-gate execstr_t *ptr; 29307c478bd9Sstevel@tonic-gate int max_attr = 7; 29317c478bd9Sstevel@tonic-gate static char *oclist[] = { 29327c478bd9Sstevel@tonic-gate "SolarisExecAttr", 29337c478bd9Sstevel@tonic-gate "SolarisProfAttr", 29347c478bd9Sstevel@tonic-gate "top", 29357c478bd9Sstevel@tonic-gate NULL 29367c478bd9Sstevel@tonic-gate }; 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 29397c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 29407c478bd9Sstevel@tonic-gate 29417c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 29427c478bd9Sstevel@tonic-gate if (e == NULL) 29437c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 29447c478bd9Sstevel@tonic-gate 29457c478bd9Sstevel@tonic-gate /* Convert the structure */ 29467c478bd9Sstevel@tonic-gate ptr = (execstr_t *)data; 29477c478bd9Sstevel@tonic-gate 29487c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 29497c478bd9Sstevel@tonic-gate ptr->policy == NULL || ptr->policy[0] == '\0' || 29507c478bd9Sstevel@tonic-gate ptr->type == NULL || ptr->type[0] == '\0' || 29517c478bd9Sstevel@tonic-gate ptr->id == NULL || ptr->id[0] == '\0') { 29527c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 29537c478bd9Sstevel@tonic-gate *entry = NULL; 29547c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 29557c478bd9Sstevel@tonic-gate } 29567c478bd9Sstevel@tonic-gate 29577c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 29587c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+SolarisKernelSecurityPolicy=%s" 29597c478bd9Sstevel@tonic-gate "+SolarisProfileType=%s+SolarisProfileId=%s", 29607c478bd9Sstevel@tonic-gate ptr->name, ptr->policy, ptr->type, ptr->id); 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 rc = __s_add_attr(e, "cn", ptr->name); 29697c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29707c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29717c478bd9Sstevel@tonic-gate return (rc); 29727c478bd9Sstevel@tonic-gate } 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisKernelSecurityPolicy", ptr->policy); 29757c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29767c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29777c478bd9Sstevel@tonic-gate return (rc); 29787c478bd9Sstevel@tonic-gate } 29797c478bd9Sstevel@tonic-gate 29807c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileType", ptr->type); 29817c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29837c478bd9Sstevel@tonic-gate return (rc); 29847c478bd9Sstevel@tonic-gate } 29857c478bd9Sstevel@tonic-gate 29867c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileId", ptr->id); 29877c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29887c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29897c478bd9Sstevel@tonic-gate return (rc); 29907c478bd9Sstevel@tonic-gate } 29917c478bd9Sstevel@tonic-gate 29927c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 29937c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29947c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29957c478bd9Sstevel@tonic-gate return (rc); 29967c478bd9Sstevel@tonic-gate } 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 29997c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes1", ptr->res1); 30007c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30017c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30027c478bd9Sstevel@tonic-gate return (rc); 30037c478bd9Sstevel@tonic-gate } 30047c478bd9Sstevel@tonic-gate } 30057c478bd9Sstevel@tonic-gate 30067c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 30077c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes2", ptr->res2); 30087c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30097c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30107c478bd9Sstevel@tonic-gate return (rc); 30117c478bd9Sstevel@tonic-gate } 30127c478bd9Sstevel@tonic-gate } 30137c478bd9Sstevel@tonic-gate 30147c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 30157c478bd9Sstevel@tonic-gate } 30167c478bd9Sstevel@tonic-gate /* 30177c478bd9Sstevel@tonic-gate * Conversion: prof_attr 30187c478bd9Sstevel@tonic-gate * Input format: profstr_t 30197c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisProfAttr 30207c478bd9Sstevel@tonic-gate */ 30217c478bd9Sstevel@tonic-gate static int 30227c478bd9Sstevel@tonic-gate __s_cvt_profattr(const void *data, char **rdn, 30237c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 30247c478bd9Sstevel@tonic-gate { 30257c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 30267c478bd9Sstevel@tonic-gate int rc; 30277c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 30287c478bd9Sstevel@tonic-gate /* routine specific */ 30297c478bd9Sstevel@tonic-gate profstr_t *ptr; 30307c478bd9Sstevel@tonic-gate int max_attr = 5; 30317c478bd9Sstevel@tonic-gate static char *oclist[] = { 30327c478bd9Sstevel@tonic-gate "SolarisProfAttr", 30337c478bd9Sstevel@tonic-gate "top", 30347c478bd9Sstevel@tonic-gate NULL 30357c478bd9Sstevel@tonic-gate }; 30367c478bd9Sstevel@tonic-gate 30377c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 30387c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 30397c478bd9Sstevel@tonic-gate 30407c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 30417c478bd9Sstevel@tonic-gate if (e == NULL) 30427c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30437c478bd9Sstevel@tonic-gate 30447c478bd9Sstevel@tonic-gate /* Convert the structure */ 30457c478bd9Sstevel@tonic-gate ptr = (profstr_t *)data; 30467c478bd9Sstevel@tonic-gate 30477c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 30487c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30497c478bd9Sstevel@tonic-gate *entry = NULL; 30507c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 30517c478bd9Sstevel@tonic-gate } 30527c478bd9Sstevel@tonic-gate 30537c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 30547c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 30557c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 30567c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 30577c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30587c478bd9Sstevel@tonic-gate *entry = NULL; 30597c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30607c478bd9Sstevel@tonic-gate } 30617c478bd9Sstevel@tonic-gate 30627c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 30637c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30657c478bd9Sstevel@tonic-gate return (rc); 30667c478bd9Sstevel@tonic-gate } 30677c478bd9Sstevel@tonic-gate 30687c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 30697c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30707c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30717c478bd9Sstevel@tonic-gate return (rc); 30727c478bd9Sstevel@tonic-gate } 30737c478bd9Sstevel@tonic-gate 30747c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 30757c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 30767c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30777c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30787c478bd9Sstevel@tonic-gate return (rc); 30797c478bd9Sstevel@tonic-gate } 30807c478bd9Sstevel@tonic-gate } 30817c478bd9Sstevel@tonic-gate 30827c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 30837c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 30847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30867c478bd9Sstevel@tonic-gate return (rc); 30877c478bd9Sstevel@tonic-gate } 30887c478bd9Sstevel@tonic-gate } 30897c478bd9Sstevel@tonic-gate 30907c478bd9Sstevel@tonic-gate if (ptr->desc != NULL) { 30917c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->desc); 30927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30947c478bd9Sstevel@tonic-gate return (rc); 30957c478bd9Sstevel@tonic-gate } 30967c478bd9Sstevel@tonic-gate } 30977c478bd9Sstevel@tonic-gate 30987c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 30997c478bd9Sstevel@tonic-gate } 31007c478bd9Sstevel@tonic-gate /* 31017c478bd9Sstevel@tonic-gate * Conversion: user_attr 31027c478bd9Sstevel@tonic-gate * Input format: userstr_t 31037c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisUserAttr 31047c478bd9Sstevel@tonic-gate */ 31057c478bd9Sstevel@tonic-gate static int 31067c478bd9Sstevel@tonic-gate __s_cvt_userattr(const void *data, char **rdn, 31077c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 31087c478bd9Sstevel@tonic-gate { 31097c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 31107c478bd9Sstevel@tonic-gate int rc; 31117c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 31127c478bd9Sstevel@tonic-gate /* routine specific */ 31137c478bd9Sstevel@tonic-gate userstr_t *ptr; 31147c478bd9Sstevel@tonic-gate int max_attr = 5; 31157c478bd9Sstevel@tonic-gate static char *oclist[] = { 31167c478bd9Sstevel@tonic-gate "SolarisUserAttr", 31177c478bd9Sstevel@tonic-gate NULL 31187c478bd9Sstevel@tonic-gate }; 31197c478bd9Sstevel@tonic-gate 31207c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 31217c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 31227c478bd9Sstevel@tonic-gate 31237c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 31247c478bd9Sstevel@tonic-gate if (e == NULL) 31257c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate /* Convert the structure */ 31287c478bd9Sstevel@tonic-gate ptr = (userstr_t *)data; 31297c478bd9Sstevel@tonic-gate 31307c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 31317c478bd9Sstevel@tonic-gate ptr->attr == NULL) { 31327c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31337c478bd9Sstevel@tonic-gate *entry = NULL; 31347c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 31387c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 31397c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 31407c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 31417c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31427c478bd9Sstevel@tonic-gate *entry = NULL; 31437c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31447c478bd9Sstevel@tonic-gate } 31457c478bd9Sstevel@tonic-gate 31467c478bd9Sstevel@tonic-gate /* 31477c478bd9Sstevel@tonic-gate * SolarisUserAttr has no uid attribute 31487c478bd9Sstevel@tonic-gate */ 31497c478bd9Sstevel@tonic-gate 31507c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 31517c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31537c478bd9Sstevel@tonic-gate return (rc); 31547c478bd9Sstevel@tonic-gate } 31557c478bd9Sstevel@tonic-gate 31567c478bd9Sstevel@tonic-gate if (ptr->qualifier != NULL) { 31577c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisUserQualifier", ptr->qualifier); 31587c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31597c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31607c478bd9Sstevel@tonic-gate return (rc); 31617c478bd9Sstevel@tonic-gate } 31627c478bd9Sstevel@tonic-gate } 31637c478bd9Sstevel@tonic-gate 31647c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 31657c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 31667c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31687c478bd9Sstevel@tonic-gate return (rc); 31697c478bd9Sstevel@tonic-gate } 31707c478bd9Sstevel@tonic-gate } 31717c478bd9Sstevel@tonic-gate 31727c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 31737c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 31747c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31757c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31767c478bd9Sstevel@tonic-gate return (rc); 31777c478bd9Sstevel@tonic-gate } 31787c478bd9Sstevel@tonic-gate } 31797c478bd9Sstevel@tonic-gate 31807c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 31817c478bd9Sstevel@tonic-gate } 31827c478bd9Sstevel@tonic-gate /* 31837c478bd9Sstevel@tonic-gate * Conversion: audit_user 31847c478bd9Sstevel@tonic-gate * Input format: au_user_str_t 31857c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuditUser 31867c478bd9Sstevel@tonic-gate */ 31877c478bd9Sstevel@tonic-gate static int 31887c478bd9Sstevel@tonic-gate __s_cvt_audituser(const void *data, char **rdn, 31897c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 31907c478bd9Sstevel@tonic-gate { 31917c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 31927c478bd9Sstevel@tonic-gate int rc; 31937c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 31947c478bd9Sstevel@tonic-gate /* routine specific */ 31957c478bd9Sstevel@tonic-gate au_user_str_t *ptr; 31967c478bd9Sstevel@tonic-gate int max_attr = 3; 31977c478bd9Sstevel@tonic-gate static char *oclist[] = { 31987c478bd9Sstevel@tonic-gate "SolarisAuditUser", 31997c478bd9Sstevel@tonic-gate NULL 32007c478bd9Sstevel@tonic-gate }; 32017c478bd9Sstevel@tonic-gate 32027c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 32037c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 32047c478bd9Sstevel@tonic-gate 32057c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 32067c478bd9Sstevel@tonic-gate if (e == NULL) 32077c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32087c478bd9Sstevel@tonic-gate 32097c478bd9Sstevel@tonic-gate /* Convert the structure */ 32107c478bd9Sstevel@tonic-gate ptr = (au_user_str_t *)data; 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate if (ptr->au_name == NULL || ptr->au_name[0] == '\0') { 32137c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32147c478bd9Sstevel@tonic-gate *entry = NULL; 32157c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 32167c478bd9Sstevel@tonic-gate } 32177c478bd9Sstevel@tonic-gate 32187c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 32197c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->au_name); 32207c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 32217c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 32227c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32237c478bd9Sstevel@tonic-gate *entry = NULL; 32247c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32257c478bd9Sstevel@tonic-gate } 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate /* 32287c478bd9Sstevel@tonic-gate * Solaris AuditUser has no uid attribute 32297c478bd9Sstevel@tonic-gate */ 32307c478bd9Sstevel@tonic-gate 32317c478bd9Sstevel@tonic-gate if (ptr->au_always != NULL) { 32327c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditAlways", ptr->au_always); 32337c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32347c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32357c478bd9Sstevel@tonic-gate return (rc); 32367c478bd9Sstevel@tonic-gate } 32377c478bd9Sstevel@tonic-gate } 32387c478bd9Sstevel@tonic-gate 32397c478bd9Sstevel@tonic-gate if (ptr->au_never != NULL) { 32407c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditNever", ptr->au_never); 32417c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32427c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32437c478bd9Sstevel@tonic-gate return (rc); 32447c478bd9Sstevel@tonic-gate } 32457c478bd9Sstevel@tonic-gate } 32467c478bd9Sstevel@tonic-gate 32477c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 32487c478bd9Sstevel@tonic-gate } 32497c478bd9Sstevel@tonic-gate 32507c478bd9Sstevel@tonic-gate /* 32517c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion data structures 32527c478bd9Sstevel@tonic-gate */ 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate typedef struct __ns_cvt_type { 32557c478bd9Sstevel@tonic-gate const char *service; 32567c478bd9Sstevel@tonic-gate int flags; 32577c478bd9Sstevel@tonic-gate #define AE 1 /* alway add entries */ 32587c478bd9Sstevel@tonic-gate int (*cvt_rtn)(const void *data, 32597c478bd9Sstevel@tonic-gate char **rdn, 32607c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, 32617c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp); 32627c478bd9Sstevel@tonic-gate } __ns_cvt_type_t; 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate static __ns_cvt_type_t __s_cvtlist[] = { 32657c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PASSWD, 0, __s_cvt_passwd }, 32667c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_GROUP, 0, __s_cvt_group }, 32677c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_HOSTS, 0, __s_cvt_hosts }, 32687c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_IPNODES, 0, __s_cvt_hosts }, 32697c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_RPC, 0, __s_cvt_rpc }, 32707c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROTOCOLS, 0, __s_cvt_protocols }, 32717c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETWORKS, 0, __s_cvt_networks }, 32727c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETGROUP, 0, __s_cvt_netgroups }, 32737c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ALIASES, 0, __s_cvt_aliases }, 32747c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SERVICES, 0, __s_cvt_services }, 32757c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ETHERS, 0, __s_cvt_ethers }, 32767c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SHADOW, 0, __s_cvt_shadow }, 32777c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETMASKS, 0, __s_cvt_netmasks }, 32787c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_BOOTPARAMS, 0, __s_cvt_bootparams }, 32797c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTHATTR, 0, __s_cvt_authattr }, 32807c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_EXECATTR, 0, __s_cvt_execattr }, 32817c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROFILE, 0, __s_cvt_profattr }, 32827c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_USERATTR, AE, __s_cvt_userattr }, 32837c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTOMOUNT, 0, __s_cvt_auto_mount }, 32847c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PUBLICKEY, AE, __s_cvt_publickey }, 32857c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUUSER, AE, __s_cvt_audituser }, 32867c478bd9Sstevel@tonic-gate { NULL, 0, NULL }, 32877c478bd9Sstevel@tonic-gate }; 32887c478bd9Sstevel@tonic-gate 32897c478bd9Sstevel@tonic-gate /* 32907c478bd9Sstevel@tonic-gate * Add Typed Entry Routine 32917c478bd9Sstevel@tonic-gate */ 32927c478bd9Sstevel@tonic-gate 32937c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 32947c478bd9Sstevel@tonic-gate int __ns_ldap_addTypedEntry( 32957c478bd9Sstevel@tonic-gate const char *servicetype, 32967c478bd9Sstevel@tonic-gate const char *basedn, 32977c478bd9Sstevel@tonic-gate const void *data, 32987c478bd9Sstevel@tonic-gate const int create, 32997c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 33007c478bd9Sstevel@tonic-gate const int flags, 33017c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 33027c478bd9Sstevel@tonic-gate { 33037c478bd9Sstevel@tonic-gate char *rdn = NULL, *fulldn = NULL; 33047c478bd9Sstevel@tonic-gate void **paramVal = NULL; 33057c478bd9Sstevel@tonic-gate ns_ldap_entry_t *entry = NULL; 33067c478bd9Sstevel@tonic-gate const ns_ldap_attr_t *const *modattrlist; 33077c478bd9Sstevel@tonic-gate ns_ldap_search_desc_t **sdlist; 33087c478bd9Sstevel@tonic-gate char **dns = NULL; 33097c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 33107c478bd9Sstevel@tonic-gate char service[BUFSIZE]; 33117c478bd9Sstevel@tonic-gate int rc = 0; 33127c478bd9Sstevel@tonic-gate int automount = 0; 33137c478bd9Sstevel@tonic-gate int i, s; 33147c478bd9Sstevel@tonic-gate 33157c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 33167c478bd9Sstevel@tonic-gate for (s = 0; __s_cvtlist[s].service != NULL; s++) { 33177c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].cvt_rtn == NULL) 33187c478bd9Sstevel@tonic-gate continue; 33197c478bd9Sstevel@tonic-gate if (strcasecmp(__s_cvtlist[s].service, servicetype) == 0) 33207c478bd9Sstevel@tonic-gate break; 33217c478bd9Sstevel@tonic-gate /* Or, check if the servicetype is auto_ */ 33227c478bd9Sstevel@tonic-gate if (strcmp(__s_cvtlist[s].service, 33237c478bd9Sstevel@tonic-gate NS_LDAP_TYPE_AUTOMOUNT) == 0 && 33247c478bd9Sstevel@tonic-gate strncasecmp(servicetype, NS_LDAP_TYPE_AUTOMOUNT, 33257c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) { 33267c478bd9Sstevel@tonic-gate automount++; 33277c478bd9Sstevel@tonic-gate break; 33287c478bd9Sstevel@tonic-gate } 33297c478bd9Sstevel@tonic-gate } 33307c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].service == NULL) 33317c478bd9Sstevel@tonic-gate return (rc); 33327c478bd9Sstevel@tonic-gate 33337c478bd9Sstevel@tonic-gate /* Convert the data */ 33347c478bd9Sstevel@tonic-gate rc = (*__s_cvtlist[s].cvt_rtn)(data, &rdn, &entry, errorp); 33357c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33367c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33377c478bd9Sstevel@tonic-gate return (rc); 33387c478bd9Sstevel@tonic-gate } 33397c478bd9Sstevel@tonic-gate if (rdn == NULL) { 33407c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(entry); 33417c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 33427c478bd9Sstevel@tonic-gate } 33437c478bd9Sstevel@tonic-gate 33447c478bd9Sstevel@tonic-gate if (strcmp(servicetype, "publickey") == 0) { 33457c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 33467c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 33477c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_TRUE) 33487c478bd9Sstevel@tonic-gate (void) strcpy(service, "hosts"); 33497c478bd9Sstevel@tonic-gate else 33507c478bd9Sstevel@tonic-gate (void) strcpy(service, "passwd"); 33517c478bd9Sstevel@tonic-gate } else 33527c478bd9Sstevel@tonic-gate (void) strcpy(service, servicetype); 33537c478bd9Sstevel@tonic-gate 33547c478bd9Sstevel@tonic-gate /* Create the Full DN */ 33557c478bd9Sstevel@tonic-gate if (basedn == NULL) { 33567c478bd9Sstevel@tonic-gate rc = __s_api_get_SSD_from_SSDtoUse_service(service, 33577c478bd9Sstevel@tonic-gate &sdlist, errorp); 33587c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33597c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33607c478bd9Sstevel@tonic-gate return (rc); 33617c478bd9Sstevel@tonic-gate } 33627c478bd9Sstevel@tonic-gate 33637c478bd9Sstevel@tonic-gate if (sdlist == NULL) { 33647c478bd9Sstevel@tonic-gate rc = __s_api_getDNs(&dns, service, errorp); 33657c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33667c478bd9Sstevel@tonic-gate if (dns) { 33677c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 33687c478bd9Sstevel@tonic-gate dns = NULL; 33697c478bd9Sstevel@tonic-gate } 33707c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33717c478bd9Sstevel@tonic-gate return (rc); 33727c478bd9Sstevel@tonic-gate } 33737c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", rdn, dns[0]); 33747c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 33757c478bd9Sstevel@tonic-gate } else { 33767c478bd9Sstevel@tonic-gate if (sdlist[0]->basedn) { 33777c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", 33787c478bd9Sstevel@tonic-gate rdn, sdlist[0]->basedn); 33797c478bd9Sstevel@tonic-gate } else { 33807c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33817c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 33827c478bd9Sstevel@tonic-gate } 33837c478bd9Sstevel@tonic-gate } 33847c478bd9Sstevel@tonic-gate i = strlen(trdn) - 1; 33857c478bd9Sstevel@tonic-gate if (trdn[i] == COMMATOK) { 33867c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 33877c478bd9Sstevel@tonic-gate ¶mVal, errorp); 33887c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33897c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33907c478bd9Sstevel@tonic-gate return (rc); 33917c478bd9Sstevel@tonic-gate } 33927c478bd9Sstevel@tonic-gate i = strlen(trdn) + strlen((char *)(paramVal[0])) + 1; 33937c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 33947c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 33957c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 33967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33977c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 33987c478bd9Sstevel@tonic-gate } 33997c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s%s", trdn, 34007c478bd9Sstevel@tonic-gate (char *)(paramVal[0])); 34017c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 34027c478bd9Sstevel@tonic-gate } else { 34037c478bd9Sstevel@tonic-gate fulldn = strdup(trdn); 34047c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 34057c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34067c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34077c478bd9Sstevel@tonic-gate } 34087c478bd9Sstevel@tonic-gate } 34097c478bd9Sstevel@tonic-gate } else { 34107c478bd9Sstevel@tonic-gate i = strlen(rdn) + strlen(basedn) + 2; 34117c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 34127c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 34137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34147c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34157c478bd9Sstevel@tonic-gate } 34167c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s,%s", rdn, basedn); 34177c478bd9Sstevel@tonic-gate } 34187c478bd9Sstevel@tonic-gate 34197c478bd9Sstevel@tonic-gate modattrlist = (const ns_ldap_attr_t * const *)entry->attr_pair; 34207c478bd9Sstevel@tonic-gate /* Check to see if the entry exists already */ 34217c478bd9Sstevel@tonic-gate /* May need to delete or update first */ 34227c478bd9Sstevel@tonic-gate 34237c478bd9Sstevel@tonic-gate if (create != 1) { 34247c478bd9Sstevel@tonic-gate /* Modify the entry */ 34257c478bd9Sstevel@tonic-gate if ((__s_cvtlist[s].flags & AE) != 0) 34267c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, modattrlist, 34277c478bd9Sstevel@tonic-gate cred, flags, errorp); 34287c478bd9Sstevel@tonic-gate else { 34297c478bd9Sstevel@tonic-gate rc = __ns_ldap_repAttr(service, fulldn, modattrlist, 34307c478bd9Sstevel@tonic-gate cred, flags, errorp); 34317c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 34327c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_NO_SUCH_OBJECT) { 34337c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 34347c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, 34357c478bd9Sstevel@tonic-gate entry, cred, flags, errorp); 34367c478bd9Sstevel@tonic-gate } 34377c478bd9Sstevel@tonic-gate } 34387c478bd9Sstevel@tonic-gate } else { 34397c478bd9Sstevel@tonic-gate /* Add the entry */ 34407c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, entry, 34417c478bd9Sstevel@tonic-gate cred, flags, errorp); 34427c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 34437c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_ALREADY_EXISTS && 34447c478bd9Sstevel@tonic-gate ((strcmp(service, "ethers") == 0) || 34457c478bd9Sstevel@tonic-gate (strcmp(service, "bootparams") == 0))) { 34467c478bd9Sstevel@tonic-gate rc = modify_ethers_bootp(service, rdn, fulldn, 34477c478bd9Sstevel@tonic-gate modattrlist, cred, flags, errorp); 34487c478bd9Sstevel@tonic-gate } 34497c478bd9Sstevel@tonic-gate } 34507c478bd9Sstevel@tonic-gate 34517c478bd9Sstevel@tonic-gate /* Free up entry created by conversion routine */ 34527c478bd9Sstevel@tonic-gate if (fulldn != NULL) 34537c478bd9Sstevel@tonic-gate free(fulldn); 34547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34557c478bd9Sstevel@tonic-gate return (rc); 34567c478bd9Sstevel@tonic-gate } 34577c478bd9Sstevel@tonic-gate 34587c478bd9Sstevel@tonic-gate 34597c478bd9Sstevel@tonic-gate /* 34607c478bd9Sstevel@tonic-gate * Append the default base dn to the dn 34617c478bd9Sstevel@tonic-gate * when it ends with ','. 34627c478bd9Sstevel@tonic-gate * e.g. 34637c478bd9Sstevel@tonic-gate * SSD = service:ou=foo, 34647c478bd9Sstevel@tonic-gate */ 34657c478bd9Sstevel@tonic-gate int 34667c478bd9Sstevel@tonic-gate __s_api_append_default_basedn( 34677c478bd9Sstevel@tonic-gate const char *dn, 34687c478bd9Sstevel@tonic-gate char **new_dn, 34697c478bd9Sstevel@tonic-gate int *allocated, 34707c478bd9Sstevel@tonic-gate ns_ldap_error_t **errp) { 34717c478bd9Sstevel@tonic-gate 34727c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS, len = 0; 34737c478bd9Sstevel@tonic-gate void **param = NULL; 34747c478bd9Sstevel@tonic-gate char *str = NULL; 34757c478bd9Sstevel@tonic-gate 34767c478bd9Sstevel@tonic-gate *allocated = FALSE; 34777c478bd9Sstevel@tonic-gate *new_dn = NULL; 34787c478bd9Sstevel@tonic-gate 34797c478bd9Sstevel@tonic-gate if (dn == NULL) 34807c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 34817c478bd9Sstevel@tonic-gate 34827c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 34837c478bd9Sstevel@tonic-gate (void ***)¶m, errp); 34847c478bd9Sstevel@tonic-gate 34857c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34867c478bd9Sstevel@tonic-gate if (param) 34877c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 34887c478bd9Sstevel@tonic-gate return (rc); 34897c478bd9Sstevel@tonic-gate } 34907c478bd9Sstevel@tonic-gate 34917c478bd9Sstevel@tonic-gate len = strlen(dn); 34927c478bd9Sstevel@tonic-gate str = ((char **)param)[0]; 34937c478bd9Sstevel@tonic-gate len = len + strlen(str) +1; 34947c478bd9Sstevel@tonic-gate *new_dn = (char *)malloc(len); 34957c478bd9Sstevel@tonic-gate if (*new_dn == NULL) { 34967c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 34977c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34987c478bd9Sstevel@tonic-gate } 34997c478bd9Sstevel@tonic-gate *allocated = TRUE; 35007c478bd9Sstevel@tonic-gate 35017c478bd9Sstevel@tonic-gate (void) strcpy(*new_dn, dn); 35027c478bd9Sstevel@tonic-gate (void) strcat(*new_dn, str); 35037c478bd9Sstevel@tonic-gate 35047c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 35057c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 35067c478bd9Sstevel@tonic-gate } 3507