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 /* 23*7d575517Ssdussud * 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; 672*7d575517Ssdussud /* referrals returned by the LDAP operation */ 6737c478bd9Sstevel@tonic-gate char **referrals = NULL; 674*7d575517Ssdussud /* 675*7d575517Ssdussud * list of referrals used by the state machine, built from 676*7d575517Ssdussud * the referrals variable above 677*7d575517Ssdussud */ 678*7d575517Ssdussud ns_referral_info_t *ref_list = NULL; 679*7d575517Ssdussud /* current referral */ 680*7d575517Ssdussud 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; 685*7d575517Ssdussud int i = 0; 686*7d575517Ssdussud int ldap_error; 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate while (always) { 6897c478bd9Sstevel@tonic-gate switch (state) { 6907c478bd9Sstevel@tonic-gate case W_EXIT: 6917c478bd9Sstevel@tonic-gate if (connectionId > -1) 6927c478bd9Sstevel@tonic-gate DropConnection(connectionId, 0); 693*7d575517Ssdussud if (ref_list) 694*7d575517Ssdussud __s_api_deleteRefInfo(ref_list); 6957c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) 6967c478bd9Sstevel@tonic-gate free(target_dn); 6977c478bd9Sstevel@tonic-gate return (return_rc); 6987c478bd9Sstevel@tonic-gate case W_INIT: 6997c478bd9Sstevel@tonic-gate /* see if need to follow referrals */ 7007c478bd9Sstevel@tonic-gate rc = __s_api_toFollowReferrals(flags, 7017c478bd9Sstevel@tonic-gate &followRef, errorp); 7027c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7037c478bd9Sstevel@tonic-gate return_rc = rc; 7047c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7057c478bd9Sstevel@tonic-gate break; 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate len = strlen(dn); 7087c478bd9Sstevel@tonic-gate if (dn[len-1] == COMMATOK) 7097c478bd9Sstevel@tonic-gate rc = __s_api_append_default_basedn( 7107c478bd9Sstevel@tonic-gate dn, &target_dn, 7117c478bd9Sstevel@tonic-gate &target_dn_allocated, 7127c478bd9Sstevel@tonic-gate errorp); 7137c478bd9Sstevel@tonic-gate else 7147c478bd9Sstevel@tonic-gate target_dn = dn; 7157c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7167c478bd9Sstevel@tonic-gate return_rc = rc; 7177c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate else 7207c478bd9Sstevel@tonic-gate new_state = GET_CONNECTION; 7217c478bd9Sstevel@tonic-gate break; 7227c478bd9Sstevel@tonic-gate case GET_CONNECTION: 7237c478bd9Sstevel@tonic-gate rc = __s_api_getConnection(NULL, 7247c478bd9Sstevel@tonic-gate flags, 7257c478bd9Sstevel@tonic-gate cred, 7267c478bd9Sstevel@tonic-gate &connectionId, 7277c478bd9Sstevel@tonic-gate &conp, 7287c478bd9Sstevel@tonic-gate errorp, 7297c478bd9Sstevel@tonic-gate do_not_fail_if_new_pwd_reqd); 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * If password control attached 7337c478bd9Sstevel@tonic-gate * in *errorp, 7347c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 7357c478bd9Sstevel@tonic-gate * free the error structure (we do not need 7367c478bd9Sstevel@tonic-gate * the password management info). 7377c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 7407c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError( 7417c478bd9Sstevel@tonic-gate errorp); 7427c478bd9Sstevel@tonic-gate *errorp = NULL; 7437c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 7477c478bd9Sstevel@tonic-gate return_rc = rc; 7487c478bd9Sstevel@tonic-gate new_state = W_ERROR; 7497c478bd9Sstevel@tonic-gate break; 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate if (followRef) 7527c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_ASYNC; 7537c478bd9Sstevel@tonic-gate else 7547c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 7557c478bd9Sstevel@tonic-gate break; 7567c478bd9Sstevel@tonic-gate case SELECT_OPERATION_SYNC: 7577c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7587c478bd9Sstevel@tonic-gate new_state = DO_ADD_SYNC; 7597c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7607c478bd9Sstevel@tonic-gate new_state = DO_DELETE_SYNC; 7617c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7627c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_SYNC; 7637c478bd9Sstevel@tonic-gate break; 7647c478bd9Sstevel@tonic-gate case SELECT_OPERATION_ASYNC: 7657c478bd9Sstevel@tonic-gate if (ldap_op == LDAP_REQ_ADD) 7667c478bd9Sstevel@tonic-gate new_state = DO_ADD_ASYNC; 7677c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_DELETE) 7687c478bd9Sstevel@tonic-gate new_state = DO_DELETE_ASYNC; 7697c478bd9Sstevel@tonic-gate else if (ldap_op == LDAP_REQ_MODIFY) 7707c478bd9Sstevel@tonic-gate new_state = DO_MODIFY_ASYNC; 7717c478bd9Sstevel@tonic-gate break; 7727c478bd9Sstevel@tonic-gate case DO_ADD_SYNC: 7737c478bd9Sstevel@tonic-gate rc = ldap_add_ext_s(conp->ld, target_dn, 7747c478bd9Sstevel@tonic-gate mods, NULL, NULL); 7757c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7767c478bd9Sstevel@tonic-gate break; 7777c478bd9Sstevel@tonic-gate case DO_DELETE_SYNC: 7787c478bd9Sstevel@tonic-gate rc = ldap_delete_ext_s(conp->ld, target_dn, 7797c478bd9Sstevel@tonic-gate NULL, NULL); 7807c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7817c478bd9Sstevel@tonic-gate break; 7827c478bd9Sstevel@tonic-gate case DO_MODIFY_SYNC: 7837c478bd9Sstevel@tonic-gate rc = ldap_modify_ext_s(conp->ld, target_dn, 7847c478bd9Sstevel@tonic-gate mods, NULL, NULL); 7857c478bd9Sstevel@tonic-gate new_state = GET_RESULT_SYNC; 7867c478bd9Sstevel@tonic-gate break; 7877c478bd9Sstevel@tonic-gate case DO_ADD_ASYNC: 7887c478bd9Sstevel@tonic-gate rc = ldap_add_ext(conp->ld, target_dn, 7897c478bd9Sstevel@tonic-gate mods, NULL, NULL, &msgid); 7907c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 7917c478bd9Sstevel@tonic-gate break; 7927c478bd9Sstevel@tonic-gate case DO_DELETE_ASYNC: 7937c478bd9Sstevel@tonic-gate rc = ldap_delete_ext(conp->ld, target_dn, 7947c478bd9Sstevel@tonic-gate NULL, NULL, &msgid); 7957c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 7967c478bd9Sstevel@tonic-gate break; 7977c478bd9Sstevel@tonic-gate case DO_MODIFY_ASYNC: 7987c478bd9Sstevel@tonic-gate rc = ldap_modify_ext(conp->ld, target_dn, 7997c478bd9Sstevel@tonic-gate mods, NULL, NULL, &msgid); 8007c478bd9Sstevel@tonic-gate new_state = GET_RESULT_ASYNC; 8017c478bd9Sstevel@tonic-gate break; 8027c478bd9Sstevel@tonic-gate case GET_RESULT_SYNC: 8037c478bd9Sstevel@tonic-gate if (rc != LDAP_SUCCESS) { 8047c478bd9Sstevel@tonic-gate Errno = rc; 8057c478bd9Sstevel@tonic-gate (void) ldap_get_lderrno(conp->ld, 8067c478bd9Sstevel@tonic-gate NULL, &errmsg); 8077c478bd9Sstevel@tonic-gate /* 8087c478bd9Sstevel@tonic-gate * free errmsg if it is an empty string 8097c478bd9Sstevel@tonic-gate */ 8107c478bd9Sstevel@tonic-gate if (errmsg && *errmsg == '\0') { 8117c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8127c478bd9Sstevel@tonic-gate errmsg = NULL; 8137c478bd9Sstevel@tonic-gate } 8147c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8157c478bd9Sstevel@tonic-gate } else { 8167c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 8177c478bd9Sstevel@tonic-gate new_state = W_EXIT; 8187c478bd9Sstevel@tonic-gate } 8197c478bd9Sstevel@tonic-gate break; 8207c478bd9Sstevel@tonic-gate case GET_RESULT_ASYNC: 8217c478bd9Sstevel@tonic-gate rc = ldap_result(conp->ld, msgid, 1, 8227c478bd9Sstevel@tonic-gate (struct timeval *)NULL, &res); 8237c478bd9Sstevel@tonic-gate /* if no server response, set Errno */ 8247c478bd9Sstevel@tonic-gate if (rc == -1) { 8257c478bd9Sstevel@tonic-gate (void) ldap_get_option(conp->ld, 8267c478bd9Sstevel@tonic-gate LDAP_OPT_ERROR_NUMBER, &Errno); 8277c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8287c478bd9Sstevel@tonic-gate break; 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate if (rc == LDAP_RES_ADD || 8317c478bd9Sstevel@tonic-gate rc == LDAP_RES_MODIFY || 8327c478bd9Sstevel@tonic-gate rc == LDAP_RES_DELETE) { 8337c478bd9Sstevel@tonic-gate new_state = PARSE_RESULT; 8347c478bd9Sstevel@tonic-gate break; 8357c478bd9Sstevel@tonic-gate } else { 8367c478bd9Sstevel@tonic-gate return_rc = rc; 8377c478bd9Sstevel@tonic-gate new_state = W_ERROR; 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate break; 8407c478bd9Sstevel@tonic-gate case PARSE_RESULT: 8417c478bd9Sstevel@tonic-gate /* 8427c478bd9Sstevel@tonic-gate * need Errno, referrals, error msg, 8437c478bd9Sstevel@tonic-gate * and the last "1" is to free 8447c478bd9Sstevel@tonic-gate * the result (res) 8457c478bd9Sstevel@tonic-gate */ 8467c478bd9Sstevel@tonic-gate rc = ldap_parse_result(conp->ld, 8477c478bd9Sstevel@tonic-gate res, &Errno, 8487c478bd9Sstevel@tonic-gate NULL, &errmsg, 8497c478bd9Sstevel@tonic-gate &referrals, NULL, 1); 8507c478bd9Sstevel@tonic-gate /* 8517c478bd9Sstevel@tonic-gate * free errmsg if it is an empty string 8527c478bd9Sstevel@tonic-gate */ 8537c478bd9Sstevel@tonic-gate if (errmsg && *errmsg == '\0') { 8547c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8557c478bd9Sstevel@tonic-gate errmsg = NULL; 8567c478bd9Sstevel@tonic-gate } 857*7d575517Ssdussud /* 858*7d575517Ssdussud * If we received referral data, process 859*7d575517Ssdussud * it if: 860*7d575517Ssdussud * - we are configured to follow referrals 861*7d575517Ssdussud * - and not already in referral mode (to keep 862*7d575517Ssdussud * consistency with search_state_machine() 863*7d575517Ssdussud * which follows 1 level of referrals only; 864*7d575517Ssdussud * see proc_result_referrals() and 865*7d575517Ssdussud * proc_search_references(). 866*7d575517Ssdussud */ 867*7d575517Ssdussud if (Errno == LDAP_REFERRAL && followRef && !ref_list) { 868*7d575517Ssdussud for (i = 0; referrals[i] != NULL; i++) { 869*7d575517Ssdussud /* add to referral list */ 870*7d575517Ssdussud rc = __s_api_addRefInfo(&ref_list, 871*7d575517Ssdussud referrals[i], 8727c478bd9Sstevel@tonic-gate NULL, NULL, NULL, 8737c478bd9Sstevel@tonic-gate conp->ld); 874*7d575517Ssdussud if (rc != NS_LDAP_SUCCESS) { 875*7d575517Ssdussud __s_api_deleteRefInfo(ref_list); 876*7d575517Ssdussud ref_list = NULL; 877*7d575517Ssdussud break; 878*7d575517Ssdussud } 8797c478bd9Sstevel@tonic-gate } 8807c478bd9Sstevel@tonic-gate ldap_value_free(referrals); 881*7d575517Ssdussud if (ref_list == NULL) { 8827c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_MEMORY) 8837c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 884*7d575517Ssdussud return_rc = rc; 8857c478bd9Sstevel@tonic-gate new_state = W_ERROR; 886*7d575517Ssdussud } else { 8877c478bd9Sstevel@tonic-gate new_state = GET_REFERRAL_CONNECTION; 888*7d575517Ssdussud current_ref = ref_list; 889*7d575517Ssdussud } 8907c478bd9Sstevel@tonic-gate if (errmsg) { 8917c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 8927c478bd9Sstevel@tonic-gate errmsg = NULL; 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate break; 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate if (Errno != LDAP_SUCCESS) { 8977c478bd9Sstevel@tonic-gate new_state = W_LDAP_ERROR; 8987c478bd9Sstevel@tonic-gate } else { 8997c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_SUCCESS; 9007c478bd9Sstevel@tonic-gate new_state = W_EXIT; 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate break; 9037c478bd9Sstevel@tonic-gate case GET_REFERRAL_CONNECTION: 904*7d575517Ssdussud /* 905*7d575517Ssdussud * since we are starting over, 906*7d575517Ssdussud * discard the old error info 907*7d575517Ssdussud */ 908*7d575517Ssdussud return_rc = NS_LDAP_SUCCESS; 909*7d575517Ssdussud if (*errorp) 910*7d575517Ssdussud (void) __ns_ldap_freeError(errorp); 9117c478bd9Sstevel@tonic-gate if (connectionId > -1) 9127c478bd9Sstevel@tonic-gate DropConnection(connectionId, 0); 913*7d575517Ssdussud rc = __s_api_getConnection(current_ref->refHost, 9147c478bd9Sstevel@tonic-gate 0, 9157c478bd9Sstevel@tonic-gate cred, 9167c478bd9Sstevel@tonic-gate &connectionId, 9177c478bd9Sstevel@tonic-gate &conp, 9187c478bd9Sstevel@tonic-gate errorp, 9197c478bd9Sstevel@tonic-gate do_not_fail_if_new_pwd_reqd); 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate /* 9227c478bd9Sstevel@tonic-gate * If password control attached 9237c478bd9Sstevel@tonic-gate * in errorp, 9247c478bd9Sstevel@tonic-gate * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO, 9257c478bd9Sstevel@tonic-gate * free the error structure (we do not need 9267c478bd9Sstevel@tonic-gate * the password management info). 9277c478bd9Sstevel@tonic-gate * Reset rc to NS_LDAP_SUCCESS. 9287c478bd9Sstevel@tonic-gate */ 9297c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS_WITH_INFO) { 9307c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError( 9317c478bd9Sstevel@tonic-gate errorp); 9327c478bd9Sstevel@tonic-gate *errorp = NULL; 9337c478bd9Sstevel@tonic-gate rc = NS_LDAP_SUCCESS; 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 9377c478bd9Sstevel@tonic-gate return_rc = rc; 938*7d575517Ssdussud /* 939*7d575517Ssdussud * If current referral is not 940*7d575517Ssdussud * available for some reason, 941*7d575517Ssdussud * try next referral in the list. 942*7d575517Ssdussud * Get LDAP error code from errorp. 943*7d575517Ssdussud */ 944*7d575517Ssdussud if (*errorp != NULL) { 945*7d575517Ssdussud ldap_error = (*errorp)->status; 946*7d575517Ssdussud if (ldap_error == LDAP_BUSY || 947*7d575517Ssdussud ldap_error == LDAP_UNAVAILABLE || 948*7d575517Ssdussud ldap_error == 949*7d575517Ssdussud LDAP_UNWILLING_TO_PERFORM || 950*7d575517Ssdussud ldap_error == LDAP_CONNECT_ERROR || 951*7d575517Ssdussud ldap_error == LDAP_SERVER_DOWN) { 952*7d575517Ssdussud current_ref = current_ref->next; 953*7d575517Ssdussud if (current_ref == NULL) { 954*7d575517Ssdussud /* no more referral */ 955*7d575517Ssdussud /* to follow */ 956*7d575517Ssdussud new_state = W_ERROR; 957*7d575517Ssdussud } else { 958*7d575517Ssdussud new_state = 959*7d575517Ssdussud GET_REFERRAL_CONNECTION; 960*7d575517Ssdussud } 961*7d575517Ssdussud /* 962*7d575517Ssdussud * free errorp before going to 963*7d575517Ssdussud * next referral 964*7d575517Ssdussud */ 965*7d575517Ssdussud (void) __ns_ldap_freeError( 966*7d575517Ssdussud errorp); 967*7d575517Ssdussud *errorp = NULL; 968*7d575517Ssdussud break; 969*7d575517Ssdussud } 970*7d575517Ssdussud /* 971*7d575517Ssdussud * free errorp before going to W_ERROR 972*7d575517Ssdussud */ 973*7d575517Ssdussud (void) __ns_ldap_freeError(errorp); 974*7d575517Ssdussud *errorp = NULL; 975*7d575517Ssdussud } 976*7d575517Ssdussud /* else, exit */ 977*7d575517Ssdussud __s_api_deleteRefInfo(ref_list); 978*7d575517Ssdussud ref_list = NULL; 9797c478bd9Sstevel@tonic-gate new_state = W_ERROR; 9807c478bd9Sstevel@tonic-gate break; 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate /* target DN may changed due to referrals */ 983*7d575517Ssdussud if (current_ref->refDN) { 9847c478bd9Sstevel@tonic-gate if (target_dn && target_dn_allocated) { 9857c478bd9Sstevel@tonic-gate free(target_dn); 9867c478bd9Sstevel@tonic-gate target_dn = NULL; 9877c478bd9Sstevel@tonic-gate target_dn_allocated = FALSE; 9887c478bd9Sstevel@tonic-gate } 989*7d575517Ssdussud target_dn = current_ref->refDN; 9907c478bd9Sstevel@tonic-gate } 9917c478bd9Sstevel@tonic-gate new_state = SELECT_OPERATION_SYNC; 9927c478bd9Sstevel@tonic-gate break; 9937c478bd9Sstevel@tonic-gate case W_LDAP_ERROR: 9947c478bd9Sstevel@tonic-gate /* 9957c478bd9Sstevel@tonic-gate * map error code and error message 9967c478bd9Sstevel@tonic-gate * to password status if necessary. 9977c478bd9Sstevel@tonic-gate * This is to see if password updates 9987c478bd9Sstevel@tonic-gate * failed due to password policy or 9997c478bd9Sstevel@tonic-gate * password syntax checking. 10007c478bd9Sstevel@tonic-gate */ 10017c478bd9Sstevel@tonic-gate if (errmsg) { 10027c478bd9Sstevel@tonic-gate /* 10037c478bd9Sstevel@tonic-gate * check if server supports 10047c478bd9Sstevel@tonic-gate * password management 10057c478bd9Sstevel@tonic-gate */ 10067c478bd9Sstevel@tonic-gate passwd_mgmt = 10077c478bd9Sstevel@tonic-gate __s_api_contain_passwd_control_oid( 10087c478bd9Sstevel@tonic-gate conp->controls); 10097c478bd9Sstevel@tonic-gate if (passwd_mgmt) 10107c478bd9Sstevel@tonic-gate pwd_status = 10117c478bd9Sstevel@tonic-gate __s_api_set_passwd_status( 10127c478bd9Sstevel@tonic-gate Errno, errmsg); 10137c478bd9Sstevel@tonic-gate ldap_memfree(errmsg); 10147c478bd9Sstevel@tonic-gate errmsg = NULL; 10157c478bd9Sstevel@tonic-gate } 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 10187c478bd9Sstevel@tonic-gate gettext(ldap_err2string(Errno))); 10197c478bd9Sstevel@tonic-gate err = strdup(errstr); 10207c478bd9Sstevel@tonic-gate if (pwd_status != NS_PASSWD_GOOD) { 10217c478bd9Sstevel@tonic-gate MKERROR_PWD_MGMT(*errorp, Errno, err, 10227c478bd9Sstevel@tonic-gate pwd_status, 0, NULL); 10237c478bd9Sstevel@tonic-gate } else { 10247c478bd9Sstevel@tonic-gate MKERROR(LOG_INFO, *errorp, Errno, err, NULL); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate return_rc = NS_LDAP_INTERNAL; 10277c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10287c478bd9Sstevel@tonic-gate break; 10297c478bd9Sstevel@tonic-gate case W_ERROR: 10307c478bd9Sstevel@tonic-gate default: 10317c478bd9Sstevel@tonic-gate (void) sprintf(errstr, 10327c478bd9Sstevel@tonic-gate gettext("Internal write State machine exit" 10337c478bd9Sstevel@tonic-gate " (state = %d, rc = %d)."), 10347c478bd9Sstevel@tonic-gate err_state, return_rc); 10357c478bd9Sstevel@tonic-gate err = strdup(errstr); 10367c478bd9Sstevel@tonic-gate MKERROR(LOG_WARNING, *errorp, return_rc, err, NULL); 10377c478bd9Sstevel@tonic-gate new_state = W_EXIT; 10387c478bd9Sstevel@tonic-gate break; 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate if (new_state == W_ERROR) 10427c478bd9Sstevel@tonic-gate err_state = state; 10437c478bd9Sstevel@tonic-gate state = new_state; 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate /* 10477c478bd9Sstevel@tonic-gate * should never be here, the next line is to eliminating 10487c478bd9Sstevel@tonic-gate * lint message 10497c478bd9Sstevel@tonic-gate */ 10507c478bd9Sstevel@tonic-gate return (NS_LDAP_INTERNAL); 10517c478bd9Sstevel@tonic-gate } 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10557c478bd9Sstevel@tonic-gate int 10567c478bd9Sstevel@tonic-gate __ns_ldap_addAttr( 10577c478bd9Sstevel@tonic-gate const char *service, 10587c478bd9Sstevel@tonic-gate const char *dn, 10597c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 10607c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 10617c478bd9Sstevel@tonic-gate const int flags, 10627c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 10637c478bd9Sstevel@tonic-gate { 10647c478bd9Sstevel@tonic-gate LDAPMod **mods; 10657c478bd9Sstevel@tonic-gate int rc = 0; 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate #ifdef DEBUG 10687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addAttr START\n"); 10697c478bd9Sstevel@tonic-gate #endif 10707c478bd9Sstevel@tonic-gate *errorp = NULL; 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate /* Sanity check */ 10737c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 10747c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 10757c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_ADD, flags); 10787c478bd9Sstevel@tonic-gate if (mods == NULL) { 10797c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 10807c478bd9Sstevel@tonic-gate } 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 10837c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 10847c478bd9Sstevel@tonic-gate freeModList(mods); 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate return (rc); 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10917c478bd9Sstevel@tonic-gate int 10927c478bd9Sstevel@tonic-gate __ns_ldap_delAttr( 10937c478bd9Sstevel@tonic-gate const char *service, 10947c478bd9Sstevel@tonic-gate const char *dn, 10957c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 10967c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 10977c478bd9Sstevel@tonic-gate const int flags, 10987c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 10997c478bd9Sstevel@tonic-gate { 11007c478bd9Sstevel@tonic-gate LDAPMod **mods; 11017c478bd9Sstevel@tonic-gate int rc = 0; 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate #ifdef DEBUG 11047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delAttr START\n"); 11057c478bd9Sstevel@tonic-gate #endif 11067c478bd9Sstevel@tonic-gate *errorp = NULL; 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate /* Sanity check */ 11097c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11107c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11117c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11127c478bd9Sstevel@tonic-gate 11137c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_DELETE, flags); 11147c478bd9Sstevel@tonic-gate if (mods == NULL) { 11157c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11197c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate freeModList(mods); 11227c478bd9Sstevel@tonic-gate return (rc); 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11267c478bd9Sstevel@tonic-gate int 11277c478bd9Sstevel@tonic-gate __ns_ldap_repAttr( 11287c478bd9Sstevel@tonic-gate const char *service, 11297c478bd9Sstevel@tonic-gate const char *dn, 11307c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr, 11317c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11327c478bd9Sstevel@tonic-gate const int flags, 11337c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11347c478bd9Sstevel@tonic-gate { 11357c478bd9Sstevel@tonic-gate LDAPMod **mods; 11367c478bd9Sstevel@tonic-gate int rc = 0; 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate #ifdef DEBUG 11397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_repAttr START\n"); 11407c478bd9Sstevel@tonic-gate #endif 11417c478bd9Sstevel@tonic-gate *errorp = NULL; 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate /* Sanity check */ 11447c478bd9Sstevel@tonic-gate if ((attr == NULL) || (*attr == NULL) || 11457c478bd9Sstevel@tonic-gate (dn == NULL) || (cred == NULL)) 11467c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11477c478bd9Sstevel@tonic-gate mods = __s_api_makeModList(service, attr, LDAP_MOD_REPLACE, flags); 11487c478bd9Sstevel@tonic-gate if (mods == NULL) { 11497c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_MODIFY, 11537c478bd9Sstevel@tonic-gate (char *)dn, mods, cred, flags, errorp); 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate freeModList(mods); 11567c478bd9Sstevel@tonic-gate return (rc); 11577c478bd9Sstevel@tonic-gate } 11587c478bd9Sstevel@tonic-gate 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11617c478bd9Sstevel@tonic-gate int 11627c478bd9Sstevel@tonic-gate __ns_ldap_addEntry( 11637c478bd9Sstevel@tonic-gate const char *service, 11647c478bd9Sstevel@tonic-gate const char *dn, 11657c478bd9Sstevel@tonic-gate const ns_ldap_entry_t *entry, 11667c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 11677c478bd9Sstevel@tonic-gate const int flags, 11687c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 11697c478bd9Sstevel@tonic-gate { 11707c478bd9Sstevel@tonic-gate char *new_dn = NULL; 11717c478bd9Sstevel@tonic-gate LDAPMod **mods = NULL; 11727c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attr; 11737c478bd9Sstevel@tonic-gate int nAttr = 0; 11747c478bd9Sstevel@tonic-gate int rc = 0; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate #ifdef DEBUG 11777c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_addEntry START\n"); 11787c478bd9Sstevel@tonic-gate #endif 11797c478bd9Sstevel@tonic-gate 11807c478bd9Sstevel@tonic-gate if ((entry == NULL) || (dn == NULL) || (cred == NULL)) 11817c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 11827c478bd9Sstevel@tonic-gate *errorp = NULL; 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate /* Construct array of LDAPMod representing attributes of new entry. */ 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate nAttr = entry->attr_count; 11877c478bd9Sstevel@tonic-gate attr = (const ns_ldap_attr_t * const *)(entry->attr_pair); 11887c478bd9Sstevel@tonic-gate mods = __s_api_makeModListCount(service, attr, LDAP_MOD_ADD, 11897c478bd9Sstevel@tonic-gate nAttr, flags); 11907c478bd9Sstevel@tonic-gate if (mods == NULL) { 11917c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate rc = replace_mapped_attr_in_dn(service, dn, &new_dn); 11957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 11967c478bd9Sstevel@tonic-gate freeModList(mods); 11977c478bd9Sstevel@tonic-gate return (rc); 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_ADD, 12017c478bd9Sstevel@tonic-gate new_dn ? new_dn : (char *)dn, mods, cred, flags, errorp); 12027c478bd9Sstevel@tonic-gate 12037c478bd9Sstevel@tonic-gate if (new_dn) 12047c478bd9Sstevel@tonic-gate free(new_dn); 12057c478bd9Sstevel@tonic-gate freeModList(mods); 12067c478bd9Sstevel@tonic-gate return (rc); 12077c478bd9Sstevel@tonic-gate } 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12117c478bd9Sstevel@tonic-gate int 12127c478bd9Sstevel@tonic-gate __ns_ldap_delEntry( 12137c478bd9Sstevel@tonic-gate const char *service, 12147c478bd9Sstevel@tonic-gate const char *dn, 12157c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 12167c478bd9Sstevel@tonic-gate const int flags, 12177c478bd9Sstevel@tonic-gate ns_ldap_error_t ** errorp) 12187c478bd9Sstevel@tonic-gate { 12197c478bd9Sstevel@tonic-gate int rc; 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate #ifdef DEBUG 12227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "__ns_ldap_delEntry START\n"); 12237c478bd9Sstevel@tonic-gate #endif 12247c478bd9Sstevel@tonic-gate if ((dn == NULL) || (cred == NULL)) 12257c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate *errorp = NULL; 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate rc = write_state_machine(LDAP_REQ_DELETE, 12307c478bd9Sstevel@tonic-gate (char *)dn, NULL, cred, flags, errorp); 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate return (rc); 12337c478bd9Sstevel@tonic-gate } 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate /* 12367c478bd9Sstevel@tonic-gate * Add Typed Entry Helper routines 12377c478bd9Sstevel@tonic-gate */ 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate /* 12407c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion routines 12417c478bd9Sstevel@tonic-gate */ 12427c478bd9Sstevel@tonic-gate 12437c478bd9Sstevel@tonic-gate static int 12447c478bd9Sstevel@tonic-gate __s_add_attr(ns_ldap_entry_t *e, char *attrname, char *value) 12457c478bd9Sstevel@tonic-gate { 12467c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 12477c478bd9Sstevel@tonic-gate char *v; 12487c478bd9Sstevel@tonic-gate 12497c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 12507c478bd9Sstevel@tonic-gate if (a == NULL) 12517c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12527c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 12537c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 12547c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12557c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(1, sizeof (char **)); 12567c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 12577c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12587c478bd9Sstevel@tonic-gate a->value_count = 1; 12597c478bd9Sstevel@tonic-gate a->attrvalue[0] = NULL; 12607c478bd9Sstevel@tonic-gate v = strdup(value); 12617c478bd9Sstevel@tonic-gate if (v == NULL) 12627c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12637c478bd9Sstevel@tonic-gate a->attrvalue[0] = v; 12647c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 12657c478bd9Sstevel@tonic-gate e->attr_count++; 12667c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 12677c478bd9Sstevel@tonic-gate } 12687c478bd9Sstevel@tonic-gate 12697c478bd9Sstevel@tonic-gate static int 12707c478bd9Sstevel@tonic-gate __s_add_attrlist(ns_ldap_entry_t *e, char *attrname, char **argv) 12717c478bd9Sstevel@tonic-gate { 12727c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 12737c478bd9Sstevel@tonic-gate char *v; 12747c478bd9Sstevel@tonic-gate char **av; 12757c478bd9Sstevel@tonic-gate int i, j; 12767c478bd9Sstevel@tonic-gate 12777c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 12787c478bd9Sstevel@tonic-gate if (a == NULL) 12797c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12807c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 12817c478bd9Sstevel@tonic-gate if (a->attrname == NULL) 12827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate for (i = 0, av = argv; *av != NULL; av++, i++) 12857c478bd9Sstevel@tonic-gate ; 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(i, sizeof (char *)); 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) 12907c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate a->value_count = i; 12937c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 12947c478bd9Sstevel@tonic-gate v = strdup(argv[j]); 12957c478bd9Sstevel@tonic-gate if (v == NULL) 12967c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 12977c478bd9Sstevel@tonic-gate a->attrvalue[j] = v; 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 13007c478bd9Sstevel@tonic-gate e->attr_count++; 13017c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 13027c478bd9Sstevel@tonic-gate } 13037c478bd9Sstevel@tonic-gate 13047c478bd9Sstevel@tonic-gate static ns_ldap_entry_t * 13057c478bd9Sstevel@tonic-gate __s_mk_entry(char **objclass, int max_attr) 13067c478bd9Sstevel@tonic-gate { 13077c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 13087c478bd9Sstevel@tonic-gate e = (ns_ldap_entry_t *)calloc(1, sizeof (ns_ldap_entry_t)); 13097c478bd9Sstevel@tonic-gate if (e == NULL) 13107c478bd9Sstevel@tonic-gate return (NULL); 13117c478bd9Sstevel@tonic-gate /* allocate attributes, +1 for objectclass, +1 for NULL terminator */ 13127c478bd9Sstevel@tonic-gate e->attr_pair = (ns_ldap_attr_t **) 13137c478bd9Sstevel@tonic-gate calloc(max_attr + 2, sizeof (ns_ldap_attr_t *)); 13147c478bd9Sstevel@tonic-gate if (e->attr_pair == NULL) { 13157c478bd9Sstevel@tonic-gate free(e); 13167c478bd9Sstevel@tonic-gate return (NULL); 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate e->attr_count = 0; 13197c478bd9Sstevel@tonic-gate if (__s_add_attrlist(e, "objectClass", objclass) != NS_LDAP_SUCCESS) { 13207c478bd9Sstevel@tonic-gate free(e->attr_pair); 13217c478bd9Sstevel@tonic-gate free(e); 13227c478bd9Sstevel@tonic-gate return (NULL); 13237c478bd9Sstevel@tonic-gate } 13247c478bd9Sstevel@tonic-gate return (e); 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate 13277c478bd9Sstevel@tonic-gate 13287c478bd9Sstevel@tonic-gate /* 13297c478bd9Sstevel@tonic-gate * Conversion: passwd 13307c478bd9Sstevel@tonic-gate * Input format: struct passwd 13317c478bd9Sstevel@tonic-gate * Exported objectclass: posixAccount 13327c478bd9Sstevel@tonic-gate */ 13337c478bd9Sstevel@tonic-gate static int 13347c478bd9Sstevel@tonic-gate __s_cvt_passwd(const void *data, char **rdn, 13357c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 13367c478bd9Sstevel@tonic-gate { 13377c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 13387c478bd9Sstevel@tonic-gate int rc; 13397c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 13407c478bd9Sstevel@tonic-gate /* routine specific */ 13417c478bd9Sstevel@tonic-gate struct passwd *ptr; 13427c478bd9Sstevel@tonic-gate int max_attr = 9; 13437c478bd9Sstevel@tonic-gate char ibuf[10]; 13447c478bd9Sstevel@tonic-gate static char *oclist[] = { 13457c478bd9Sstevel@tonic-gate "posixAccount", 13467c478bd9Sstevel@tonic-gate "shadowAccount", 13477c478bd9Sstevel@tonic-gate "account", 13487c478bd9Sstevel@tonic-gate "top", 13497c478bd9Sstevel@tonic-gate NULL 13507c478bd9Sstevel@tonic-gate }; 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 13537c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 13547c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 13557c478bd9Sstevel@tonic-gate if (e == NULL) 13567c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13577c478bd9Sstevel@tonic-gate 13587c478bd9Sstevel@tonic-gate /* Convert the structure */ 13597c478bd9Sstevel@tonic-gate ptr = (struct passwd *)data; 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate if (ptr->pw_name == NULL || ptr->pw_uid < 0 || 13627c478bd9Sstevel@tonic-gate ptr->pw_gid < 0 || ptr->pw_dir == NULL) { 13637c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 13647c478bd9Sstevel@tonic-gate *entry = NULL; 13657c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 13667c478bd9Sstevel@tonic-gate } 13677c478bd9Sstevel@tonic-gate 13687c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 13697c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->pw_name); 13707c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 13717c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 13727c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 13737c478bd9Sstevel@tonic-gate *entry = NULL; 13747c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 13757c478bd9Sstevel@tonic-gate } 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 13787c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->pw_name); 13797c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13807c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13817c478bd9Sstevel@tonic-gate return (rc); 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->pw_name); 13847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13867c478bd9Sstevel@tonic-gate return (rc); 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate if (ptr->pw_passwd != NULL && 13907c478bd9Sstevel@tonic-gate ptr->pw_passwd[0] != '\0') { 13917c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->pw_passwd); 13927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 13937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 13947c478bd9Sstevel@tonic-gate return (rc); 13957c478bd9Sstevel@tonic-gate } 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate #ifdef _LP64 13997c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->pw_uid); 14007c478bd9Sstevel@tonic-gate #else 14017c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->pw_uid); 14027c478bd9Sstevel@tonic-gate #endif 14037c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uidNumber", ibuf); 14047c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14057c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14067c478bd9Sstevel@tonic-gate return (rc); 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate #ifdef _LP64 14107c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->pw_gid); 14117c478bd9Sstevel@tonic-gate #else 14127c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->pw_gid); 14137c478bd9Sstevel@tonic-gate #endif 14147c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 14157c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14167c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14177c478bd9Sstevel@tonic-gate return (rc); 14187c478bd9Sstevel@tonic-gate } 14197c478bd9Sstevel@tonic-gate if (ptr->pw_gecos != NULL && 14207c478bd9Sstevel@tonic-gate ptr->pw_gecos[0] != '\0') { 14217c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gecos", ptr->pw_gecos); 14227c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14237c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14247c478bd9Sstevel@tonic-gate return (rc); 14257c478bd9Sstevel@tonic-gate } 14267c478bd9Sstevel@tonic-gate } 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "homeDirectory", ptr->pw_dir); 14297c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14307c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14317c478bd9Sstevel@tonic-gate return (rc); 14327c478bd9Sstevel@tonic-gate } 14337c478bd9Sstevel@tonic-gate if (ptr->pw_shell != NULL && 14347c478bd9Sstevel@tonic-gate ptr->pw_shell[0] != '\0') { 14357c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "loginShell", ptr->pw_shell); 14367c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14377c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14387c478bd9Sstevel@tonic-gate return (rc); 14397c478bd9Sstevel@tonic-gate } 14407c478bd9Sstevel@tonic-gate } 14417c478bd9Sstevel@tonic-gate 14427c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate 14457c478bd9Sstevel@tonic-gate /* 14467c478bd9Sstevel@tonic-gate * Conversion: shadow 14477c478bd9Sstevel@tonic-gate * Input format: struct shadow 14487c478bd9Sstevel@tonic-gate * Exported objectclass: shadowAccount 14497c478bd9Sstevel@tonic-gate */ 14507c478bd9Sstevel@tonic-gate static int 14517c478bd9Sstevel@tonic-gate __s_cvt_shadow(const void *data, char **rdn, 14527c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 14537c478bd9Sstevel@tonic-gate { 14547c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 14557c478bd9Sstevel@tonic-gate int rc; 14567c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 14577c478bd9Sstevel@tonic-gate /* routine specific */ 14587c478bd9Sstevel@tonic-gate struct spwd *ptr; 14597c478bd9Sstevel@tonic-gate int max_attr = 10; 14607c478bd9Sstevel@tonic-gate char ibuf[10]; 14617c478bd9Sstevel@tonic-gate static char *oclist[] = { 14627c478bd9Sstevel@tonic-gate "posixAccount", 14637c478bd9Sstevel@tonic-gate "shadowAccount", 14647c478bd9Sstevel@tonic-gate "account", 14657c478bd9Sstevel@tonic-gate "top", 14667c478bd9Sstevel@tonic-gate NULL 14677c478bd9Sstevel@tonic-gate }; 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 14707c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 14717c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 14727c478bd9Sstevel@tonic-gate if (e == NULL) 14737c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate /* Convert the structure */ 14767c478bd9Sstevel@tonic-gate ptr = (struct spwd *)data; 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate if (ptr->sp_namp == NULL) { 14797c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 14807c478bd9Sstevel@tonic-gate *entry = NULL; 14817c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 14857c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->sp_namp); 14867c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 14877c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 14887c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 14897c478bd9Sstevel@tonic-gate *entry = NULL; 14907c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 14917c478bd9Sstevel@tonic-gate } 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 14947c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "uid", ptr->sp_namp); 14957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 14967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 14977c478bd9Sstevel@tonic-gate return (rc); 14987c478bd9Sstevel@tonic-gate } 14997c478bd9Sstevel@tonic-gate 15007c478bd9Sstevel@tonic-gate if (ptr->sp_pwdp == NULL) { 15017c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15027c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 15037c478bd9Sstevel@tonic-gate } else { 15047c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->sp_pwdp); 15057c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15077c478bd9Sstevel@tonic-gate return (rc); 15087c478bd9Sstevel@tonic-gate } 15097c478bd9Sstevel@tonic-gate } 15107c478bd9Sstevel@tonic-gate if (ptr->sp_lstchg >= 0) { 15117c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_lstchg); 15127c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowLastChange", ibuf); 15137c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15147c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15157c478bd9Sstevel@tonic-gate return (rc); 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate } 15187c478bd9Sstevel@tonic-gate if (ptr->sp_min >= 0) { 15197c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_min); 15207c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMin", ibuf); 15217c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15227c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15237c478bd9Sstevel@tonic-gate return (rc); 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate } 15267c478bd9Sstevel@tonic-gate if (ptr->sp_max >= 0) { 15277c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_max); 15287c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowMax", ibuf); 15297c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15307c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15317c478bd9Sstevel@tonic-gate return (rc); 15327c478bd9Sstevel@tonic-gate } 15337c478bd9Sstevel@tonic-gate } 15347c478bd9Sstevel@tonic-gate if (ptr->sp_warn >= 0) { 15357c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_warn); 15367c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowWarning", ibuf); 15377c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15387c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15397c478bd9Sstevel@tonic-gate return (rc); 15407c478bd9Sstevel@tonic-gate } 15417c478bd9Sstevel@tonic-gate } 15427c478bd9Sstevel@tonic-gate if (ptr->sp_inact >= 0) { 15437c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_inact); 15447c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowInactive", ibuf); 15457c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15467c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15477c478bd9Sstevel@tonic-gate return (rc); 15487c478bd9Sstevel@tonic-gate } 15497c478bd9Sstevel@tonic-gate } 15507c478bd9Sstevel@tonic-gate if (ptr->sp_expire >= 0) { 15517c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_expire); 15527c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowExpire", ibuf); 15537c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15557c478bd9Sstevel@tonic-gate return (rc); 15567c478bd9Sstevel@tonic-gate } 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->sp_flag); 15597c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "shadowFlag", ibuf); 15607c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 15617c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 15627c478bd9Sstevel@tonic-gate return (rc); 15637c478bd9Sstevel@tonic-gate } 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate /* 15707c478bd9Sstevel@tonic-gate * Conversion: group 15717c478bd9Sstevel@tonic-gate * Input format: struct group 15727c478bd9Sstevel@tonic-gate * Exported objectclass: posixGroup 15737c478bd9Sstevel@tonic-gate */ 15747c478bd9Sstevel@tonic-gate static int 15757c478bd9Sstevel@tonic-gate __s_cvt_group(const void *data, char **rdn, 15767c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 15777c478bd9Sstevel@tonic-gate { 15787c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 15797c478bd9Sstevel@tonic-gate int rc; 15807c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 15817c478bd9Sstevel@tonic-gate /* routine specific */ 15827c478bd9Sstevel@tonic-gate struct group *ptr; 15837c478bd9Sstevel@tonic-gate int i, j, k; 15847c478bd9Sstevel@tonic-gate char **nm, **lm; 15857c478bd9Sstevel@tonic-gate int max_attr = 4; 15867c478bd9Sstevel@tonic-gate char ibuf[10]; 15877c478bd9Sstevel@tonic-gate static char *oclist[] = { 15887c478bd9Sstevel@tonic-gate "posixGroup", 15897c478bd9Sstevel@tonic-gate "top", 15907c478bd9Sstevel@tonic-gate NULL 15917c478bd9Sstevel@tonic-gate }; 15927c478bd9Sstevel@tonic-gate 15937c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 15947c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 15957c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 15967c478bd9Sstevel@tonic-gate if (e == NULL) 15977c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 15987c478bd9Sstevel@tonic-gate 15997c478bd9Sstevel@tonic-gate /* Convert the structure */ 16007c478bd9Sstevel@tonic-gate ptr = (struct group *)data; 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate if (ptr->gr_name == NULL || ptr->gr_gid < 0) { 16037c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 16047c478bd9Sstevel@tonic-gate *entry = NULL; 16057c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate 16087c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 16097c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->gr_name); 16107c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 16117c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 16127c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 16137c478bd9Sstevel@tonic-gate *entry = NULL; 16147c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16157c478bd9Sstevel@tonic-gate } 16167c478bd9Sstevel@tonic-gate 16177c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 16187c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->gr_name); 16197c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16207c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16217c478bd9Sstevel@tonic-gate return (rc); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate 16247c478bd9Sstevel@tonic-gate #ifdef _LP64 16257c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->gr_gid); 16267c478bd9Sstevel@tonic-gate #else 16277c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%ld", ptr->gr_gid); 16287c478bd9Sstevel@tonic-gate #endif 16297c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "gidNumber", ibuf); 16307c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16317c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16327c478bd9Sstevel@tonic-gate return (rc); 16337c478bd9Sstevel@tonic-gate } 16347c478bd9Sstevel@tonic-gate if (ptr->gr_passwd && ptr->gr_passwd[0] != '\0') { 16357c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "userPassword", ptr->gr_passwd); 16367c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16377c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16387c478bd9Sstevel@tonic-gate return (rc); 16397c478bd9Sstevel@tonic-gate } 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate if (ptr->gr_mem && ptr->gr_mem[0]) { 16437c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 16447c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 16457c478bd9Sstevel@tonic-gate ; 16467c478bd9Sstevel@tonic-gate lm = ptr->gr_mem; 16477c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 16487c478bd9Sstevel@tonic-gate if (nm == NULL) { 16497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16507c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16517c478bd9Sstevel@tonic-gate } 16527c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 16537c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 16547c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 16557c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 16567c478bd9Sstevel@tonic-gate free(nm[k]); 16577c478bd9Sstevel@tonic-gate free(nm); 16587c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16597c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 16607c478bd9Sstevel@tonic-gate } 16617c478bd9Sstevel@tonic-gate } 16627c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberUid", nm); 16637c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 16647c478bd9Sstevel@tonic-gate free(nm[j]); 16657c478bd9Sstevel@tonic-gate } 16667c478bd9Sstevel@tonic-gate free(nm); 16677c478bd9Sstevel@tonic-gate nm = NULL; 16687c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 16697c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 16707c478bd9Sstevel@tonic-gate return (rc); 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate } 16737c478bd9Sstevel@tonic-gate 16747c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 16757c478bd9Sstevel@tonic-gate } 16767c478bd9Sstevel@tonic-gate 16777c478bd9Sstevel@tonic-gate /* 16787c478bd9Sstevel@tonic-gate * Conversion: hosts 16797c478bd9Sstevel@tonic-gate * Input format: struct hostent 16807c478bd9Sstevel@tonic-gate * Exported objectclass: ipHost 16817c478bd9Sstevel@tonic-gate */ 16827c478bd9Sstevel@tonic-gate static int 16837c478bd9Sstevel@tonic-gate __s_cvt_hosts(const void *data, char **rdn, 16847c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 16857c478bd9Sstevel@tonic-gate { 16867c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 16877c478bd9Sstevel@tonic-gate int rc; 16887c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 16897c478bd9Sstevel@tonic-gate /* routine specific */ 16907c478bd9Sstevel@tonic-gate struct hostent *ptr; 16917c478bd9Sstevel@tonic-gate int max_attr = 6; 16927c478bd9Sstevel@tonic-gate int i, j, k; 16937c478bd9Sstevel@tonic-gate char **nm, **lm; 16947c478bd9Sstevel@tonic-gate static char *oclist[] = { 16957c478bd9Sstevel@tonic-gate "ipHost", 16967c478bd9Sstevel@tonic-gate "device", 16977c478bd9Sstevel@tonic-gate "top", 16987c478bd9Sstevel@tonic-gate NULL 16997c478bd9Sstevel@tonic-gate }; 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 17027c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 17037c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 17047c478bd9Sstevel@tonic-gate if (e == NULL) 17057c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate /* Convert the structure */ 17087c478bd9Sstevel@tonic-gate ptr = (struct hostent *)data; 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate if (ptr->h_name == NULL || 17117c478bd9Sstevel@tonic-gate ptr->h_addr_list == NULL || ptr->h_addr_list[0] == '\0') { 17127c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 17137c478bd9Sstevel@tonic-gate *entry = NULL; 17147c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 17157c478bd9Sstevel@tonic-gate } 17167c478bd9Sstevel@tonic-gate 17177c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 17187c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipHostNumber=%s", 17197c478bd9Sstevel@tonic-gate ptr->h_name, ptr->h_addr_list[0]); 17207c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 17217c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 17227c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 17237c478bd9Sstevel@tonic-gate *entry = NULL; 17247c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17257c478bd9Sstevel@tonic-gate } 17267c478bd9Sstevel@tonic-gate 17277c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 17287c478bd9Sstevel@tonic-gate if (ptr->h_aliases && ptr->h_aliases[0]) { 17297c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 17307c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 17317c478bd9Sstevel@tonic-gate ; 17327c478bd9Sstevel@tonic-gate lm = ptr->h_aliases; 17337c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 17347c478bd9Sstevel@tonic-gate if (nm == NULL) { 17357c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17367c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17377c478bd9Sstevel@tonic-gate } 17387c478bd9Sstevel@tonic-gate nm[0] = ptr->h_name; 17397c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 17407c478bd9Sstevel@tonic-gate nm[j+1] = ptr->h_aliases[j]; 17417c478bd9Sstevel@tonic-gate 17427c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 17437c478bd9Sstevel@tonic-gate free(nm); 17447c478bd9Sstevel@tonic-gate nm = NULL; 17457c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17467c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17477c478bd9Sstevel@tonic-gate return (rc); 17487c478bd9Sstevel@tonic-gate } 17497c478bd9Sstevel@tonic-gate } else { 17507c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->h_name); 17517c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17527c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17537c478bd9Sstevel@tonic-gate return (rc); 17547c478bd9Sstevel@tonic-gate } 17557c478bd9Sstevel@tonic-gate } 17567c478bd9Sstevel@tonic-gate 17577c478bd9Sstevel@tonic-gate if (ptr->h_addr_list && ptr->h_addr_list[0]) { 17587c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 17597c478bd9Sstevel@tonic-gate for (i = 0; *lm; i++, lm++) 17607c478bd9Sstevel@tonic-gate ; 17617c478bd9Sstevel@tonic-gate lm = ptr->h_addr_list; 17627c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 17637c478bd9Sstevel@tonic-gate if (nm == NULL) { 17647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17667c478bd9Sstevel@tonic-gate } 17677c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 17687c478bd9Sstevel@tonic-gate nm[j] = strdup(lm[j]); 17697c478bd9Sstevel@tonic-gate if (nm[j] == NULL) { 17707c478bd9Sstevel@tonic-gate for (k = 0; k < j; k++) 17717c478bd9Sstevel@tonic-gate free(nm[k]); 17727c478bd9Sstevel@tonic-gate free(nm); 17737c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17747c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 17757c478bd9Sstevel@tonic-gate } 17767c478bd9Sstevel@tonic-gate } 17777c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "ipHostNumber", nm); 17787c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 17797c478bd9Sstevel@tonic-gate free(nm[j]); 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate free(nm); 17827c478bd9Sstevel@tonic-gate nm = NULL; 17837c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 17847c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17857c478bd9Sstevel@tonic-gate return (rc); 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate } else { 17887c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 17897c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 17937c478bd9Sstevel@tonic-gate } 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate /* 17967c478bd9Sstevel@tonic-gate * Conversion: rpc 17977c478bd9Sstevel@tonic-gate * Input format: struct rpcent 17987c478bd9Sstevel@tonic-gate * Exported objectclass: oncRpc 17997c478bd9Sstevel@tonic-gate */ 18007c478bd9Sstevel@tonic-gate static int 18017c478bd9Sstevel@tonic-gate __s_cvt_rpc(const void *data, char **rdn, 18027c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 18037c478bd9Sstevel@tonic-gate { 18047c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 18057c478bd9Sstevel@tonic-gate int rc; 18067c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 18077c478bd9Sstevel@tonic-gate /* routine specific */ 18087c478bd9Sstevel@tonic-gate struct rpcent *ptr; 18097c478bd9Sstevel@tonic-gate int max_attr = 3; 18107c478bd9Sstevel@tonic-gate int i, j; 18117c478bd9Sstevel@tonic-gate char **nm; 18127c478bd9Sstevel@tonic-gate char ibuf[10]; 18137c478bd9Sstevel@tonic-gate static char *oclist[] = { 18147c478bd9Sstevel@tonic-gate "oncRpc", 18157c478bd9Sstevel@tonic-gate "top", 18167c478bd9Sstevel@tonic-gate NULL 18177c478bd9Sstevel@tonic-gate }; 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 18207c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 18217c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 18227c478bd9Sstevel@tonic-gate if (e == NULL) 18237c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate /* Convert the structure */ 18267c478bd9Sstevel@tonic-gate ptr = (struct rpcent *)data; 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate if (ptr->r_name == NULL || ptr->r_number < 0) { 18297c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18307c478bd9Sstevel@tonic-gate *entry = NULL; 18317c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 18327c478bd9Sstevel@tonic-gate } 18337c478bd9Sstevel@tonic-gate 18347c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 18357c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->r_name); 18367c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 18377c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 18387c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 18397c478bd9Sstevel@tonic-gate *entry = NULL; 18407c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18417c478bd9Sstevel@tonic-gate } 18427c478bd9Sstevel@tonic-gate 18437c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 18447c478bd9Sstevel@tonic-gate if (ptr->r_aliases && ptr->r_aliases[0]) { 18457c478bd9Sstevel@tonic-gate nm = ptr->r_aliases; 18467c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 18477c478bd9Sstevel@tonic-gate ; 18487c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 18497c478bd9Sstevel@tonic-gate if (nm == NULL) { 18507c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18517c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate nm[0] = ptr->r_name; 18547c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 18557c478bd9Sstevel@tonic-gate nm[j+1] = ptr->r_aliases[j]; 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 18587c478bd9Sstevel@tonic-gate free(nm); 18597c478bd9Sstevel@tonic-gate nm = NULL; 18607c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18617c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18627c478bd9Sstevel@tonic-gate return (rc); 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate } else { 18657c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->r_name); 18667c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18687c478bd9Sstevel@tonic-gate return (rc); 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate } 18717c478bd9Sstevel@tonic-gate 18727c478bd9Sstevel@tonic-gate if (ptr->r_number >= 0) { 18737c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->r_number); 18747c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "oncRpcNumber", ibuf); 18757c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 18767c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 18777c478bd9Sstevel@tonic-gate return (rc); 18787c478bd9Sstevel@tonic-gate } 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate 18817c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 18827c478bd9Sstevel@tonic-gate 18837c478bd9Sstevel@tonic-gate } 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate /* 18867c478bd9Sstevel@tonic-gate * Conversion: protocols 18877c478bd9Sstevel@tonic-gate * Input format: struct protoent 18887c478bd9Sstevel@tonic-gate * Exported objectclass: ipProtocol 18897c478bd9Sstevel@tonic-gate */ 18907c478bd9Sstevel@tonic-gate static int 18917c478bd9Sstevel@tonic-gate __s_cvt_protocols(const void *data, char **rdn, 18927c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 18937c478bd9Sstevel@tonic-gate { 18947c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 18957c478bd9Sstevel@tonic-gate int rc; 18967c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 18977c478bd9Sstevel@tonic-gate /* routine specific */ 18987c478bd9Sstevel@tonic-gate struct protoent *ptr; 18997c478bd9Sstevel@tonic-gate int max_attr = 3; 19007c478bd9Sstevel@tonic-gate int i, j; 19017c478bd9Sstevel@tonic-gate char ibuf[10]; 19027c478bd9Sstevel@tonic-gate char **nm; 19037c478bd9Sstevel@tonic-gate static char *oclist[] = { 19047c478bd9Sstevel@tonic-gate "ipProtocol", 19057c478bd9Sstevel@tonic-gate "top", 19067c478bd9Sstevel@tonic-gate NULL 19077c478bd9Sstevel@tonic-gate }; 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 19107c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 19117c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 19127c478bd9Sstevel@tonic-gate if (e == NULL) 19137c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate /* Convert the structure */ 19167c478bd9Sstevel@tonic-gate ptr = (struct protoent *)data; 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate if (ptr->p_name == NULL || ptr->p_proto < 0) { 19197c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19207c478bd9Sstevel@tonic-gate *entry = NULL; 19217c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 19227c478bd9Sstevel@tonic-gate } 19237c478bd9Sstevel@tonic-gate 19247c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 19257c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->p_name); 19267c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 19277c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 19287c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 19297c478bd9Sstevel@tonic-gate *entry = NULL; 19307c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate 19337c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 19347c478bd9Sstevel@tonic-gate if (ptr->p_aliases && ptr->p_aliases[0]) { 19357c478bd9Sstevel@tonic-gate nm = ptr->p_aliases; 19367c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 19377c478bd9Sstevel@tonic-gate ; 19387c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 19397c478bd9Sstevel@tonic-gate if (nm == NULL) { 19407c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19417c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 19427c478bd9Sstevel@tonic-gate } 19437c478bd9Sstevel@tonic-gate nm[0] = ptr->p_name; 19447c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 19457c478bd9Sstevel@tonic-gate nm[j+1] = ptr->p_aliases[j]; 19467c478bd9Sstevel@tonic-gate 19477c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 19487c478bd9Sstevel@tonic-gate free(nm); 19497c478bd9Sstevel@tonic-gate nm = NULL; 19507c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19517c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19527c478bd9Sstevel@tonic-gate return (rc); 19537c478bd9Sstevel@tonic-gate } 19547c478bd9Sstevel@tonic-gate } else { 19557c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->p_name); 19567c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19577c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19587c478bd9Sstevel@tonic-gate return (rc); 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate 19627c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->p_proto); 19637c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipProtocolNumber", ibuf); 19647c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 19657c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 19667c478bd9Sstevel@tonic-gate return (rc); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate } 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate /* 19747c478bd9Sstevel@tonic-gate * Conversion: services 19757c478bd9Sstevel@tonic-gate * Input format: struct servent 19767c478bd9Sstevel@tonic-gate * Exported objectclass: ipService 19777c478bd9Sstevel@tonic-gate */ 19787c478bd9Sstevel@tonic-gate static int 19797c478bd9Sstevel@tonic-gate __s_cvt_services(const void *data, char **rdn, 19807c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 19817c478bd9Sstevel@tonic-gate { 19827c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 19837c478bd9Sstevel@tonic-gate int rc; 19847c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 19857c478bd9Sstevel@tonic-gate /* routine specific */ 19867c478bd9Sstevel@tonic-gate struct servent *ptr; 19877c478bd9Sstevel@tonic-gate int max_attr = 4; 19887c478bd9Sstevel@tonic-gate int i, j; 19897c478bd9Sstevel@tonic-gate char ibuf[10]; 19907c478bd9Sstevel@tonic-gate char **nm; 19917c478bd9Sstevel@tonic-gate static char *oclist[] = { 19927c478bd9Sstevel@tonic-gate "ipService", 19937c478bd9Sstevel@tonic-gate "top", 19947c478bd9Sstevel@tonic-gate NULL 19957c478bd9Sstevel@tonic-gate }; 19967c478bd9Sstevel@tonic-gate 19977c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 19987c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 19997c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 20007c478bd9Sstevel@tonic-gate if (e == NULL) 20017c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20027c478bd9Sstevel@tonic-gate 20037c478bd9Sstevel@tonic-gate /* Convert the structure */ 20047c478bd9Sstevel@tonic-gate ptr = (struct servent *)data; 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate if (ptr->s_name == NULL || ptr->s_port < 0 || ptr->s_proto == '\0') { 20077c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20087c478bd9Sstevel@tonic-gate *entry = NULL; 20097c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 20107c478bd9Sstevel@tonic-gate } 20117c478bd9Sstevel@tonic-gate 20127c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 20137c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+ipServiceProtocol=%s", 20147c478bd9Sstevel@tonic-gate ptr->s_name, ptr->s_proto); 20157c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 20167c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 20177c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 20187c478bd9Sstevel@tonic-gate *entry = NULL; 20197c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20207c478bd9Sstevel@tonic-gate } 20217c478bd9Sstevel@tonic-gate 20227c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 20237c478bd9Sstevel@tonic-gate if (ptr->s_aliases && ptr->s_aliases[0]) { 20247c478bd9Sstevel@tonic-gate nm = ptr->s_aliases; 20257c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 20267c478bd9Sstevel@tonic-gate ; 20277c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 20287c478bd9Sstevel@tonic-gate if (nm == NULL) { 20297c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20307c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20317c478bd9Sstevel@tonic-gate } 20327c478bd9Sstevel@tonic-gate nm[0] = ptr->s_name; 20337c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 20347c478bd9Sstevel@tonic-gate nm[j+1] = ptr->s_aliases[j]; 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 20377c478bd9Sstevel@tonic-gate free(nm); 20387c478bd9Sstevel@tonic-gate nm = NULL; 20397c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20407c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20417c478bd9Sstevel@tonic-gate return (rc); 20427c478bd9Sstevel@tonic-gate } 20437c478bd9Sstevel@tonic-gate } else { 20447c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->s_name); 20457c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20467c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20477c478bd9Sstevel@tonic-gate return (rc); 20487c478bd9Sstevel@tonic-gate } 20497c478bd9Sstevel@tonic-gate } 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate (void) sprintf(ibuf, "%d", ptr->s_port); 20527c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServicePort", ibuf); 20537c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20547c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20557c478bd9Sstevel@tonic-gate return (rc); 20567c478bd9Sstevel@tonic-gate } 20577c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipServiceProtocol", ptr->s_proto); 20587c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 20597c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 20607c478bd9Sstevel@tonic-gate return (rc); 20617c478bd9Sstevel@tonic-gate } 20627c478bd9Sstevel@tonic-gate 20637c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 20647c478bd9Sstevel@tonic-gate } 20657c478bd9Sstevel@tonic-gate 20667c478bd9Sstevel@tonic-gate /* 20677c478bd9Sstevel@tonic-gate * Conversion: networks 20687c478bd9Sstevel@tonic-gate * Input format: struct netent 20697c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 20707c478bd9Sstevel@tonic-gate */ 20717c478bd9Sstevel@tonic-gate static int 20727c478bd9Sstevel@tonic-gate __s_cvt_networks(const void *data, char **rdn, 20737c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 20747c478bd9Sstevel@tonic-gate { 20757c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 20767c478bd9Sstevel@tonic-gate int rc; 20777c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 20787c478bd9Sstevel@tonic-gate /* routine specific */ 20797c478bd9Sstevel@tonic-gate struct netent *ptr; 20807c478bd9Sstevel@tonic-gate int max_attr = 4; 20817c478bd9Sstevel@tonic-gate int i, j; 20827c478bd9Sstevel@tonic-gate char cp[64]; 20837c478bd9Sstevel@tonic-gate char **nm; 20847c478bd9Sstevel@tonic-gate static char *oclist[] = { 20857c478bd9Sstevel@tonic-gate "ipNetwork", 20867c478bd9Sstevel@tonic-gate "top", 20877c478bd9Sstevel@tonic-gate NULL 20887c478bd9Sstevel@tonic-gate }; 20897c478bd9Sstevel@tonic-gate 20907c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 20917c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 20927c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 20937c478bd9Sstevel@tonic-gate if (e == NULL) 20947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate /* Convert the structure */ 20977c478bd9Sstevel@tonic-gate ptr = (struct netent *)data; 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate if (ptr->n_name == NULL || ptr->n_net == 0) { 21007c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21017c478bd9Sstevel@tonic-gate *entry = NULL; 21027c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21037c478bd9Sstevel@tonic-gate } 21047c478bd9Sstevel@tonic-gate 21057c478bd9Sstevel@tonic-gate (void) snprintf(cp, sizeof (cp), "%d.%d.%d.%d", 21067c478bd9Sstevel@tonic-gate (ptr->n_net & 0xFF000000) >> 24, 21077c478bd9Sstevel@tonic-gate (ptr->n_net & 0x00FF0000) >> 16, 21087c478bd9Sstevel@tonic-gate (ptr->n_net & 0x0000FF00) >> 8, 21097c478bd9Sstevel@tonic-gate (ptr->n_net & 0x000000FF)); 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 21127c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", cp); 21137c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 21147c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 21157c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21167c478bd9Sstevel@tonic-gate *entry = NULL; 21177c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21187c478bd9Sstevel@tonic-gate } 21197c478bd9Sstevel@tonic-gate 21207c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 21217c478bd9Sstevel@tonic-gate if (ptr->n_aliases && ptr->n_aliases[0]) { 21227c478bd9Sstevel@tonic-gate nm = ptr->n_aliases; 21237c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 21247c478bd9Sstevel@tonic-gate ; 21257c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 21267c478bd9Sstevel@tonic-gate if (nm == NULL) { 21277c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21287c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21297c478bd9Sstevel@tonic-gate } 21307c478bd9Sstevel@tonic-gate nm[0] = ptr->n_name; 21317c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 21327c478bd9Sstevel@tonic-gate nm[j+1] = ptr->n_aliases[j]; 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "cn", nm); 21357c478bd9Sstevel@tonic-gate free(nm); 21367c478bd9Sstevel@tonic-gate nm = NULL; 21377c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21387c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21397c478bd9Sstevel@tonic-gate return (rc); 21407c478bd9Sstevel@tonic-gate } 21417c478bd9Sstevel@tonic-gate } else { 21427c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->n_name); 21437c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21447c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21457c478bd9Sstevel@tonic-gate return (rc); 21467c478bd9Sstevel@tonic-gate } 21477c478bd9Sstevel@tonic-gate } 21487c478bd9Sstevel@tonic-gate 21497c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetworkNumber", cp); 21507c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 21517c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 21527c478bd9Sstevel@tonic-gate return (rc); 21537c478bd9Sstevel@tonic-gate } 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 21567c478bd9Sstevel@tonic-gate 21577c478bd9Sstevel@tonic-gate } 21587c478bd9Sstevel@tonic-gate /* 21597c478bd9Sstevel@tonic-gate * Conversion: netmasks 21607c478bd9Sstevel@tonic-gate * Input format: struct _ns_netmasks 21617c478bd9Sstevel@tonic-gate * Exported objectclass: ipNetwork 21627c478bd9Sstevel@tonic-gate */ 21637c478bd9Sstevel@tonic-gate static int 21647c478bd9Sstevel@tonic-gate __s_cvt_netmasks(const void *data, char **rdn, 21657c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 21667c478bd9Sstevel@tonic-gate { 21677c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 21687c478bd9Sstevel@tonic-gate int rc; 21697c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 21707c478bd9Sstevel@tonic-gate /* routine specific */ 21717c478bd9Sstevel@tonic-gate struct _ns_netmasks *ptr; 21727c478bd9Sstevel@tonic-gate int max_attr = 4; 21737c478bd9Sstevel@tonic-gate static char *oclist[] = { 21747c478bd9Sstevel@tonic-gate "ipNetwork", 21757c478bd9Sstevel@tonic-gate "top", 21767c478bd9Sstevel@tonic-gate NULL 21777c478bd9Sstevel@tonic-gate }; 21787c478bd9Sstevel@tonic-gate 21797c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 21807c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 21817c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 21827c478bd9Sstevel@tonic-gate if (e == NULL) 21837c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 21847c478bd9Sstevel@tonic-gate 21857c478bd9Sstevel@tonic-gate /* Convert the structure */ 21867c478bd9Sstevel@tonic-gate ptr = (struct _ns_netmasks *)data; 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate if (ptr->netnumber == NULL) { 21897c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21907c478bd9Sstevel@tonic-gate *entry = NULL; 21917c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 21957c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", ptr->netnumber); 21967c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 21977c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 21987c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 21997c478bd9Sstevel@tonic-gate *entry = NULL; 22007c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate 22037c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 22047c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetworkNumber", ptr->netnumber); 22057c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22077c478bd9Sstevel@tonic-gate return (rc); 22087c478bd9Sstevel@tonic-gate } 22097c478bd9Sstevel@tonic-gate 22107c478bd9Sstevel@tonic-gate if (ptr->netmask != '\0') { 22117c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "ipNetmaskNumber", ptr->netmask); 22127c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22147c478bd9Sstevel@tonic-gate return (rc); 22157c478bd9Sstevel@tonic-gate } 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate } 22217c478bd9Sstevel@tonic-gate /* 22227c478bd9Sstevel@tonic-gate * Conversion: netgroups 22237c478bd9Sstevel@tonic-gate * Input format: struct _ns_netgroups 22247c478bd9Sstevel@tonic-gate * Exported objectclass: nisNetgroup 22257c478bd9Sstevel@tonic-gate */ 22267c478bd9Sstevel@tonic-gate static int 22277c478bd9Sstevel@tonic-gate __s_cvt_netgroups(const void *data, char **rdn, 22287c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 22297c478bd9Sstevel@tonic-gate { 22307c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 22317c478bd9Sstevel@tonic-gate int rc; 22327c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 22337c478bd9Sstevel@tonic-gate /* routine specific */ 22347c478bd9Sstevel@tonic-gate struct _ns_netgroups *ptr; 22357c478bd9Sstevel@tonic-gate int max_attr = 6; 22367c478bd9Sstevel@tonic-gate int i, j; 22377c478bd9Sstevel@tonic-gate char **nm; 22387c478bd9Sstevel@tonic-gate static char *oclist[] = { 22397c478bd9Sstevel@tonic-gate "nisNetgroup", 22407c478bd9Sstevel@tonic-gate "top", 22417c478bd9Sstevel@tonic-gate NULL 22427c478bd9Sstevel@tonic-gate }; 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 22457c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 22467c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 22477c478bd9Sstevel@tonic-gate if (e == NULL) 22487c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22497c478bd9Sstevel@tonic-gate 22507c478bd9Sstevel@tonic-gate /* Convert the structure */ 22517c478bd9Sstevel@tonic-gate ptr = (struct _ns_netgroups *)data; 22527c478bd9Sstevel@tonic-gate 22537c478bd9Sstevel@tonic-gate if (ptr->name == NULL) { 22547c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22557c478bd9Sstevel@tonic-gate *entry = NULL; 22567c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 22577c478bd9Sstevel@tonic-gate } 22587c478bd9Sstevel@tonic-gate 22597c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 22607c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 22617c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 22627c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 22637c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 22647c478bd9Sstevel@tonic-gate *entry = NULL; 22657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22667c478bd9Sstevel@tonic-gate } 22677c478bd9Sstevel@tonic-gate 22687c478bd9Sstevel@tonic-gate if (ptr->name != '\0') { 22697c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 22707c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22717c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22727c478bd9Sstevel@tonic-gate return (rc); 22737c478bd9Sstevel@tonic-gate } 22747c478bd9Sstevel@tonic-gate } 22757c478bd9Sstevel@tonic-gate 22767c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 22777c478bd9Sstevel@tonic-gate if (ptr->triplet && ptr->triplet[0]) { 22787c478bd9Sstevel@tonic-gate nm = ptr->triplet; 22797c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 22807c478bd9Sstevel@tonic-gate ; 22817c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 22827c478bd9Sstevel@tonic-gate if (nm == NULL) { 22837c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22847c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 22877c478bd9Sstevel@tonic-gate nm[j] = ptr->triplet[j]; 22887c478bd9Sstevel@tonic-gate 22897c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "nisNetgroupTriple", nm); 22907c478bd9Sstevel@tonic-gate free(nm); 22917c478bd9Sstevel@tonic-gate nm = NULL; 22927c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 22937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 22947c478bd9Sstevel@tonic-gate return (rc); 22957c478bd9Sstevel@tonic-gate } 22967c478bd9Sstevel@tonic-gate } 22977c478bd9Sstevel@tonic-gate if (ptr->netgroup && ptr->netgroup[0]) { 22987c478bd9Sstevel@tonic-gate nm = ptr->netgroup; 22997c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 23007c478bd9Sstevel@tonic-gate ; 23017c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 23027c478bd9Sstevel@tonic-gate if (nm == NULL) { 23037c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23047c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23057c478bd9Sstevel@tonic-gate } 23067c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 23077c478bd9Sstevel@tonic-gate nm[j] = ptr->netgroup[j]; 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "memberNisNetgroup", nm); 23107c478bd9Sstevel@tonic-gate free(nm); 23117c478bd9Sstevel@tonic-gate nm = NULL; 23127c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23137c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23147c478bd9Sstevel@tonic-gate return (rc); 23157c478bd9Sstevel@tonic-gate } 23167c478bd9Sstevel@tonic-gate } 23177c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 23187c478bd9Sstevel@tonic-gate } 23197c478bd9Sstevel@tonic-gate /* 23207c478bd9Sstevel@tonic-gate * Conversion: bootparams 23217c478bd9Sstevel@tonic-gate * Input format: struct _ns_bootp 23227c478bd9Sstevel@tonic-gate * Exported objectclass: bootableDevice, device 23237c478bd9Sstevel@tonic-gate */ 23247c478bd9Sstevel@tonic-gate static int 23257c478bd9Sstevel@tonic-gate __s_cvt_bootparams(const void *data, char **rdn, 23267c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 23277c478bd9Sstevel@tonic-gate { 23287c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 23297c478bd9Sstevel@tonic-gate int rc; 23307c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 23317c478bd9Sstevel@tonic-gate /* routine specific */ 23327c478bd9Sstevel@tonic-gate struct _ns_bootp *ptr; 23337c478bd9Sstevel@tonic-gate int max_attr = 4; 23347c478bd9Sstevel@tonic-gate int i, j; 23357c478bd9Sstevel@tonic-gate char **nm; 23367c478bd9Sstevel@tonic-gate static char *oclist[] = { 23377c478bd9Sstevel@tonic-gate "bootableDevice", 23387c478bd9Sstevel@tonic-gate "device", 23397c478bd9Sstevel@tonic-gate "top", 23407c478bd9Sstevel@tonic-gate NULL 23417c478bd9Sstevel@tonic-gate }; 23427c478bd9Sstevel@tonic-gate 23437c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 23447c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 23457c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 23467c478bd9Sstevel@tonic-gate if (e == NULL) 23477c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23487c478bd9Sstevel@tonic-gate 23497c478bd9Sstevel@tonic-gate /* Convert the structure */ 23507c478bd9Sstevel@tonic-gate ptr = (struct _ns_bootp *)data; 23517c478bd9Sstevel@tonic-gate 23527c478bd9Sstevel@tonic-gate if (ptr->name == NULL) { 23537c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23547c478bd9Sstevel@tonic-gate *entry = NULL; 23557c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 23567c478bd9Sstevel@tonic-gate } 23577c478bd9Sstevel@tonic-gate 23587c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 23597c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 23607c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 23617c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 23627c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 23637c478bd9Sstevel@tonic-gate *entry = NULL; 23647c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate 23677c478bd9Sstevel@tonic-gate if (ptr->name != '\0') { 23687c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 23697c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23707c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23717c478bd9Sstevel@tonic-gate return (rc); 23727c478bd9Sstevel@tonic-gate } 23737c478bd9Sstevel@tonic-gate } 23747c478bd9Sstevel@tonic-gate 23757c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 23767c478bd9Sstevel@tonic-gate if (ptr->param && ptr->param[0]) { 23777c478bd9Sstevel@tonic-gate nm = ptr->param; 23787c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 23797c478bd9Sstevel@tonic-gate ; 23807c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 23817c478bd9Sstevel@tonic-gate if (nm == NULL) { 23827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23837c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 23847c478bd9Sstevel@tonic-gate } 23857c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 23867c478bd9Sstevel@tonic-gate nm[j] = ptr->param[j]; 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "bootParameter", nm); 23897c478bd9Sstevel@tonic-gate free(nm); 23907c478bd9Sstevel@tonic-gate nm = NULL; 23917c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 23927c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 23937c478bd9Sstevel@tonic-gate return (rc); 23947c478bd9Sstevel@tonic-gate } 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate 23977c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate } 24007c478bd9Sstevel@tonic-gate /* 24017c478bd9Sstevel@tonic-gate * Conversion: ethers 24027c478bd9Sstevel@tonic-gate * Input format: struct _ns_ethers 24037c478bd9Sstevel@tonic-gate * Exported objectclass: ieee802Device, device 24047c478bd9Sstevel@tonic-gate */ 24057c478bd9Sstevel@tonic-gate static int 24067c478bd9Sstevel@tonic-gate __s_cvt_ethers(const void *data, char **rdn, 24077c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 24087c478bd9Sstevel@tonic-gate { 24097c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 24107c478bd9Sstevel@tonic-gate int rc; 24117c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 24127c478bd9Sstevel@tonic-gate /* routine specific */ 24137c478bd9Sstevel@tonic-gate struct _ns_ethers *ptr; 24147c478bd9Sstevel@tonic-gate int max_attr = 4; 24157c478bd9Sstevel@tonic-gate static char *oclist[] = { 24167c478bd9Sstevel@tonic-gate "ieee802Device", 24177c478bd9Sstevel@tonic-gate "device", 24187c478bd9Sstevel@tonic-gate "top", 24197c478bd9Sstevel@tonic-gate NULL 24207c478bd9Sstevel@tonic-gate }; 24217c478bd9Sstevel@tonic-gate 24227c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 24237c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 24247c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 24257c478bd9Sstevel@tonic-gate if (e == NULL) 24267c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate /* Convert the structure */ 24297c478bd9Sstevel@tonic-gate ptr = (struct _ns_ethers *)data; 24307c478bd9Sstevel@tonic-gate 24317c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->ether == '\0') { 24327c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24337c478bd9Sstevel@tonic-gate *entry = NULL; 24347c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 24357c478bd9Sstevel@tonic-gate } 24367c478bd9Sstevel@tonic-gate 24377c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 24387c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 24397c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 24407c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 24417c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 24427c478bd9Sstevel@tonic-gate *entry = NULL; 24437c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 24447c478bd9Sstevel@tonic-gate } 24457c478bd9Sstevel@tonic-gate 24467c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 24477c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 24487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24507c478bd9Sstevel@tonic-gate return (rc); 24517c478bd9Sstevel@tonic-gate } 24527c478bd9Sstevel@tonic-gate 24537c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "macAddress", ptr->ether); 24547c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 24557c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 24567c478bd9Sstevel@tonic-gate return (rc); 24577c478bd9Sstevel@tonic-gate } 24587c478bd9Sstevel@tonic-gate 24597c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 24607c478bd9Sstevel@tonic-gate } 24617c478bd9Sstevel@tonic-gate /* 24627c478bd9Sstevel@tonic-gate * This function is used when processing an ethers (objectclass: ieee802Device) 24637c478bd9Sstevel@tonic-gate * or a bootparams (objectclass: bootableDevice) entry, and the entry is 24647c478bd9Sstevel@tonic-gate * already found in LDAP. Since both ethers and bootparams share the same 24657c478bd9Sstevel@tonic-gate * LDAP container, we want to check that the entry found in LDAP is: 24667c478bd9Sstevel@tonic-gate * - either the same entry (same cn, same objectclass): we don't do anything 24677c478bd9Sstevel@tonic-gate * in this case 24687c478bd9Sstevel@tonic-gate * - or an entry which does not have the objectclass we are interesting in: 24697c478bd9Sstevel@tonic-gate * in this case, we modify the existing entry by adding the relevant 24707c478bd9Sstevel@tonic-gate * objectclass (ieee802Device or bootableDevice) and the relevant attribute(s) 24717c478bd9Sstevel@tonic-gate * from the attribute list previously computing by the relevant conversion 24727c478bd9Sstevel@tonic-gate * function. 24737c478bd9Sstevel@tonic-gate * Note: from conversion functions __s_cvt_ethers() and __s_cvt_bootparams() 24747c478bd9Sstevel@tonic-gate * we know that there is only 1 more attribute today to add (macAddress 24757c478bd9Sstevel@tonic-gate * or bootParameter) 24767c478bd9Sstevel@tonic-gate */ 24777c478bd9Sstevel@tonic-gate #define _MAX_ATTR_ETHBOOTP 2 24787c478bd9Sstevel@tonic-gate static int 24797c478bd9Sstevel@tonic-gate modify_ethers_bootp( 24807c478bd9Sstevel@tonic-gate const char *service, 24817c478bd9Sstevel@tonic-gate const char *rdn, 24827c478bd9Sstevel@tonic-gate const char *fulldn, 24837c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *attrlist, 24847c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 24857c478bd9Sstevel@tonic-gate const int flags, 24867c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 24877c478bd9Sstevel@tonic-gate { 24887c478bd9Sstevel@tonic-gate char filter[BUFSIZ]; 24897c478bd9Sstevel@tonic-gate ns_ldap_result_t *resultp; 24907c478bd9Sstevel@tonic-gate int rc = 0; 24917c478bd9Sstevel@tonic-gate int i; 24927c478bd9Sstevel@tonic-gate ns_ldap_attr_t *new_attrlist[_MAX_ATTR_ETHBOOTP+1]; 24937c478bd9Sstevel@tonic-gate ns_ldap_attr_t new_attrlist0; 24947c478bd9Sstevel@tonic-gate char *new_attrvalue0[1]; 24957c478bd9Sstevel@tonic-gate const ns_ldap_attr_t * const *aptr = attrlist; 24967c478bd9Sstevel@tonic-gate ns_ldap_attr_t *aptr2; 24977c478bd9Sstevel@tonic-gate ns_ldap_error_t *new_errorp = NULL; 24987c478bd9Sstevel@tonic-gate 24997c478bd9Sstevel@tonic-gate if (rdn == NULL || fulldn == NULL || attrlist == NULL || 25007c478bd9Sstevel@tonic-gate errorp == NULL || service == NULL) 25017c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate bzero(&new_attrlist, sizeof (new_attrlist)); 25047c478bd9Sstevel@tonic-gate bzero(&new_attrlist0, sizeof (new_attrlist0)); 25057c478bd9Sstevel@tonic-gate new_attrlist[0] = &new_attrlist0; 25067c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue = new_attrvalue0; 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate new_attrlist[0]->attrname = "objectclass"; 25097c478bd9Sstevel@tonic-gate new_attrlist[0]->value_count = 1; 25107c478bd9Sstevel@tonic-gate if (strcasecmp(service, "ethers") == NULL) { 25117c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 25127c478bd9Sstevel@tonic-gate "(&(objectClass=ieee802Device)(%s))", 25137c478bd9Sstevel@tonic-gate rdn); 25147c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "ieee802Device"; 25157c478bd9Sstevel@tonic-gate } else { 25167c478bd9Sstevel@tonic-gate (void) snprintf(&filter[0], sizeof (filter), 25177c478bd9Sstevel@tonic-gate "(&(objectClass=bootableDevice)(%s))", 25187c478bd9Sstevel@tonic-gate rdn); 25197c478bd9Sstevel@tonic-gate new_attrlist[0]->attrvalue[0] = "bootableDevice"; 25207c478bd9Sstevel@tonic-gate } 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate rc = __ns_ldap_list(service, filter, NULL, (const char **)NULL, 25237c478bd9Sstevel@tonic-gate NULL, NS_LDAP_SCOPE_SUBTREE, &resultp, &new_errorp, 25247c478bd9Sstevel@tonic-gate NULL, NULL); 25257c478bd9Sstevel@tonic-gate 25267c478bd9Sstevel@tonic-gate switch (rc) { 25277c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 25287c478bd9Sstevel@tonic-gate /* 25297c478bd9Sstevel@tonic-gate * entry already exists for this service 25307c478bd9Sstevel@tonic-gate * return NS_LDAP_INTERNAL and do not modify the incoming errorp 25317c478bd9Sstevel@tonic-gate */ 25327c478bd9Sstevel@tonic-gate rc = NS_LDAP_INTERNAL; 25337c478bd9Sstevel@tonic-gate break; 25347c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 25357c478bd9Sstevel@tonic-gate /* 25367c478bd9Sstevel@tonic-gate * entry not found with the given objectclasss but entry exists 25377c478bd9Sstevel@tonic-gate * hence add the relevant attribute (macAddress or bootparams). 25387c478bd9Sstevel@tonic-gate */ 25397c478bd9Sstevel@tonic-gate i = 1; 25407c478bd9Sstevel@tonic-gate while (*aptr && (i < _MAX_ATTR_ETHBOOTP)) { 25417c478bd9Sstevel@tonic-gate /* aptr2 needed here to avoid lint warning */ 25427c478bd9Sstevel@tonic-gate aptr2 = (ns_ldap_attr_t *)*aptr++; 25437c478bd9Sstevel@tonic-gate if ((strcasecmp(aptr2->attrname, "cn") != 0) && 25447c478bd9Sstevel@tonic-gate (strcasecmp(aptr2->attrname, 25457c478bd9Sstevel@tonic-gate "objectclass") != 0)) { 25467c478bd9Sstevel@tonic-gate new_attrlist[i++] = (ns_ldap_attr_t *)aptr2; 25477c478bd9Sstevel@tonic-gate } 25487c478bd9Sstevel@tonic-gate } 25497c478bd9Sstevel@tonic-gate 25507c478bd9Sstevel@tonic-gate if (i != _MAX_ATTR_ETHBOOTP) { 25517c478bd9Sstevel@tonic-gate /* we haven't found all expected attributes */ 25527c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 25537c478bd9Sstevel@tonic-gate break; 25547c478bd9Sstevel@tonic-gate } 25557c478bd9Sstevel@tonic-gate 25567c478bd9Sstevel@tonic-gate aptr = (const ns_ldap_attr_t * const *) new_attrlist; 25577c478bd9Sstevel@tonic-gate /* clean errorp first */ 25587c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 25597c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, aptr, cred, flags, 25607c478bd9Sstevel@tonic-gate errorp); 25617c478bd9Sstevel@tonic-gate break; 25627c478bd9Sstevel@tonic-gate default: 25637c478bd9Sstevel@tonic-gate /* 25647c478bd9Sstevel@tonic-gate * unexpected error happenned 25657c478bd9Sstevel@tonic-gate * returning relevant error 25667c478bd9Sstevel@tonic-gate */ 25677c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 25687c478bd9Sstevel@tonic-gate *errorp = new_errorp; 25697c478bd9Sstevel@tonic-gate break; 25707c478bd9Sstevel@tonic-gate } 25717c478bd9Sstevel@tonic-gate 25727c478bd9Sstevel@tonic-gate return (rc); 25737c478bd9Sstevel@tonic-gate } 25747c478bd9Sstevel@tonic-gate 25757c478bd9Sstevel@tonic-gate /* 25767c478bd9Sstevel@tonic-gate * Conversion: publickey 25777c478bd9Sstevel@tonic-gate * Input format: struct _ns_pubkey 25787c478bd9Sstevel@tonic-gate * Exported objectclass: NisKeyObject 25797c478bd9Sstevel@tonic-gate */ 25807c478bd9Sstevel@tonic-gate static int 25817c478bd9Sstevel@tonic-gate __s_cvt_publickey(const void *data, char **rdn, 25827c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 25837c478bd9Sstevel@tonic-gate { 25847c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 25857c478bd9Sstevel@tonic-gate int rc; 25867c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 25877c478bd9Sstevel@tonic-gate /* routine specific */ 25887c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 25897c478bd9Sstevel@tonic-gate int max_attr = 3; 25907c478bd9Sstevel@tonic-gate static char *oclist[] = { 25917c478bd9Sstevel@tonic-gate "NisKeyObject", 25927c478bd9Sstevel@tonic-gate NULL 25937c478bd9Sstevel@tonic-gate }; 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 25967c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 25977c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 25987c478bd9Sstevel@tonic-gate if (e == NULL) 25997c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26007c478bd9Sstevel@tonic-gate 26017c478bd9Sstevel@tonic-gate /* Convert the structure */ 26027c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->pubkey == '\0' || ptr->privkey == '\0') { 26057c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26067c478bd9Sstevel@tonic-gate *entry = NULL; 26077c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 26087c478bd9Sstevel@tonic-gate } 26097c478bd9Sstevel@tonic-gate 26107c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 26117c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_FALSE) 26127c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 26137c478bd9Sstevel@tonic-gate else 26147c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 26157c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 26167c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 26177c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26187c478bd9Sstevel@tonic-gate *entry = NULL; 26197c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26207c478bd9Sstevel@tonic-gate } 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 26237c478bd9Sstevel@tonic-gate 26247c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisPublickey", ptr->pubkey); 26257c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26267c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26277c478bd9Sstevel@tonic-gate return (rc); 26287c478bd9Sstevel@tonic-gate } 26297c478bd9Sstevel@tonic-gate 26307c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisSecretkey", ptr->privkey); 26317c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26327c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26337c478bd9Sstevel@tonic-gate return (rc); 26347c478bd9Sstevel@tonic-gate } 26357c478bd9Sstevel@tonic-gate 26367c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate /* 26397c478bd9Sstevel@tonic-gate * Conversion: aliases 26407c478bd9Sstevel@tonic-gate * Input format: struct _ns_alias 26417c478bd9Sstevel@tonic-gate * Exported objectclass: mailGroup 26427c478bd9Sstevel@tonic-gate */ 26437c478bd9Sstevel@tonic-gate static int 26447c478bd9Sstevel@tonic-gate __s_cvt_aliases(const void *data, char **rdn, 26457c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 26467c478bd9Sstevel@tonic-gate { 26477c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 26487c478bd9Sstevel@tonic-gate int rc; 26497c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 26507c478bd9Sstevel@tonic-gate /* routine specific */ 26517c478bd9Sstevel@tonic-gate struct _ns_alias *ptr; 26527c478bd9Sstevel@tonic-gate int max_attr = 4; 26537c478bd9Sstevel@tonic-gate int i, j; 26547c478bd9Sstevel@tonic-gate char **nm; 26557c478bd9Sstevel@tonic-gate static char *oclist[] = { 26567c478bd9Sstevel@tonic-gate "mailGroup", 26577c478bd9Sstevel@tonic-gate "top", 26587c478bd9Sstevel@tonic-gate NULL 26597c478bd9Sstevel@tonic-gate }; 26607c478bd9Sstevel@tonic-gate 26617c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 26627c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 26637c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 26647c478bd9Sstevel@tonic-gate if (e == NULL) 26657c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26667c478bd9Sstevel@tonic-gate 26677c478bd9Sstevel@tonic-gate /* Convert the structure */ 26687c478bd9Sstevel@tonic-gate ptr = (struct _ns_alias *)data; 26697c478bd9Sstevel@tonic-gate 26707c478bd9Sstevel@tonic-gate if (ptr->alias == NULL) { 26717c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26727c478bd9Sstevel@tonic-gate *entry = NULL; 26737c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 26747c478bd9Sstevel@tonic-gate } 26757c478bd9Sstevel@tonic-gate 26767c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 26777c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->alias); 26787c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 26797c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 26807c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 26817c478bd9Sstevel@tonic-gate *entry = NULL; 26827c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 26837c478bd9Sstevel@tonic-gate } 26847c478bd9Sstevel@tonic-gate 26857c478bd9Sstevel@tonic-gate if (ptr->alias != '\0') { 26867c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "mail", (char *)ptr->alias); 26877c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 26887c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 26897c478bd9Sstevel@tonic-gate return (rc); 26907c478bd9Sstevel@tonic-gate } 26917c478bd9Sstevel@tonic-gate } 26927c478bd9Sstevel@tonic-gate 26937c478bd9Sstevel@tonic-gate /* Error check the data and add the attributes */ 26947c478bd9Sstevel@tonic-gate if (ptr->member && ptr->member[0]) { 26957c478bd9Sstevel@tonic-gate nm = ptr->member; 26967c478bd9Sstevel@tonic-gate for (i = 0; *nm; i++, nm++) 26977c478bd9Sstevel@tonic-gate ; 26987c478bd9Sstevel@tonic-gate nm = (char **)calloc(i+2, sizeof (char *)); 26997c478bd9Sstevel@tonic-gate if (nm == NULL) { 27007c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27017c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27027c478bd9Sstevel@tonic-gate } 27037c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 27047c478bd9Sstevel@tonic-gate nm[j] = ptr->member[j]; 27057c478bd9Sstevel@tonic-gate 27067c478bd9Sstevel@tonic-gate rc = __s_add_attrlist(e, "mgrpRFC822MailMember", nm); 27077c478bd9Sstevel@tonic-gate free(nm); 27087c478bd9Sstevel@tonic-gate nm = NULL; 27097c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27107c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27117c478bd9Sstevel@tonic-gate return (rc); 27127c478bd9Sstevel@tonic-gate } 27137c478bd9Sstevel@tonic-gate } 27147c478bd9Sstevel@tonic-gate 27157c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 27167c478bd9Sstevel@tonic-gate 27177c478bd9Sstevel@tonic-gate } 27187c478bd9Sstevel@tonic-gate /* 27197c478bd9Sstevel@tonic-gate * Conversion: automount 27207c478bd9Sstevel@tonic-gate * Input format: struct _ns_automount 27217c478bd9Sstevel@tonic-gate * Exported objectclass: automount 27227c478bd9Sstevel@tonic-gate */ 27237c478bd9Sstevel@tonic-gate static int 27247c478bd9Sstevel@tonic-gate __s_cvt_auto_mount(const void *data, char **rdn, 27257c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 27267c478bd9Sstevel@tonic-gate { 27277c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 27287c478bd9Sstevel@tonic-gate int rc; 27297c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 27307c478bd9Sstevel@tonic-gate /* routine specific */ 27317c478bd9Sstevel@tonic-gate struct _ns_automount *ptr; 27327c478bd9Sstevel@tonic-gate int max_attr = 6; 27337c478bd9Sstevel@tonic-gate void **paramVal = NULL; 27347c478bd9Sstevel@tonic-gate char **mappedschema = NULL; 27357c478bd9Sstevel@tonic-gate int version1 = 0; 27367c478bd9Sstevel@tonic-gate static char *oclist[] = { 27377c478bd9Sstevel@tonic-gate NULL, 27387c478bd9Sstevel@tonic-gate "top", 27397c478bd9Sstevel@tonic-gate NULL 27407c478bd9Sstevel@tonic-gate }; 27417c478bd9Sstevel@tonic-gate 27427c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 27437c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 27447c478bd9Sstevel@tonic-gate 27457c478bd9Sstevel@tonic-gate /* determine profile version number */ 27467c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, ¶mVal, errorp); 27477c478bd9Sstevel@tonic-gate if (paramVal && *paramVal && 27487c478bd9Sstevel@tonic-gate strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0) 27497c478bd9Sstevel@tonic-gate version1 = 1; 27507c478bd9Sstevel@tonic-gate if (paramVal) 27517c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 27527c478bd9Sstevel@tonic-gate if (rc && errorp) 27537c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 27547c478bd9Sstevel@tonic-gate 27557c478bd9Sstevel@tonic-gate /* use old schema for version 1 profiles */ 27567c478bd9Sstevel@tonic-gate if (version1) 27577c478bd9Sstevel@tonic-gate oclist[0] = "nisObject"; 27587c478bd9Sstevel@tonic-gate else 27597c478bd9Sstevel@tonic-gate oclist[0] = "automount"; 27607c478bd9Sstevel@tonic-gate 27617c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 27627c478bd9Sstevel@tonic-gate if (e == NULL) 27637c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27647c478bd9Sstevel@tonic-gate 27657c478bd9Sstevel@tonic-gate /* Convert the structure */ 27667c478bd9Sstevel@tonic-gate ptr = (struct _ns_automount *)data; 27677c478bd9Sstevel@tonic-gate 27687c478bd9Sstevel@tonic-gate if (ptr->key == NULL || ptr->value == '\0' || ptr->mapname == '\0') { 27697c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27707c478bd9Sstevel@tonic-gate *entry = NULL; 27717c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 27727c478bd9Sstevel@tonic-gate } 27737c478bd9Sstevel@tonic-gate 27747c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 27757c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, version1 ? "cn=%s" : "automountKey=%s", 27767c478bd9Sstevel@tonic-gate ptr->key); 27777c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 27787c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 27797c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 27807c478bd9Sstevel@tonic-gate *entry = NULL; 27817c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 27827c478bd9Sstevel@tonic-gate } 27837c478bd9Sstevel@tonic-gate 27847c478bd9Sstevel@tonic-gate if (ptr->key != '\0') { 27857c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, version1 ? "cn" : "automountKey", 27867c478bd9Sstevel@tonic-gate (char *)ptr->key); 27877c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27887c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27897c478bd9Sstevel@tonic-gate return (rc); 27907c478bd9Sstevel@tonic-gate } 27917c478bd9Sstevel@tonic-gate } 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, version1 ? "nisMapEntry" : "automountInformation", 27947c478bd9Sstevel@tonic-gate (char *)ptr->value); 27957c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 27967c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 27977c478bd9Sstevel@tonic-gate return (rc); 27987c478bd9Sstevel@tonic-gate } 27997c478bd9Sstevel@tonic-gate 28007c478bd9Sstevel@tonic-gate /* 28017c478bd9Sstevel@tonic-gate * even for version 2, if automount is mapped to nisObject we 28027c478bd9Sstevel@tonic-gate * still need 'nisMapName' attribute 28037c478bd9Sstevel@tonic-gate */ 28047c478bd9Sstevel@tonic-gate mappedschema = __ns_ldap_getMappedObjectClass("automount", "automount"); 28057c478bd9Sstevel@tonic-gate if (mappedschema && mappedschema[0] && 28067c478bd9Sstevel@tonic-gate strcasecmp(mappedschema[0], "nisObject") == 0) 28077c478bd9Sstevel@tonic-gate version1 = 1; 28087c478bd9Sstevel@tonic-gate if (mappedschema) 28097c478bd9Sstevel@tonic-gate __s_api_free2dArray(mappedschema); 28107c478bd9Sstevel@tonic-gate 28117c478bd9Sstevel@tonic-gate if (version1) { 28127c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "nisMapName", (char *)ptr->mapname); 28137c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28147c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28157c478bd9Sstevel@tonic-gate return (rc); 28167c478bd9Sstevel@tonic-gate } 28177c478bd9Sstevel@tonic-gate } 28187c478bd9Sstevel@tonic-gate 28197c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 28207c478bd9Sstevel@tonic-gate } 28217c478bd9Sstevel@tonic-gate /* 28227c478bd9Sstevel@tonic-gate * Conversion: auth_attr 28237c478bd9Sstevel@tonic-gate * Input format: authstr_t 28247c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuthAttr 28257c478bd9Sstevel@tonic-gate */ 28267c478bd9Sstevel@tonic-gate static int 28277c478bd9Sstevel@tonic-gate __s_cvt_authattr(const void *data, char **rdn, 28287c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 28297c478bd9Sstevel@tonic-gate { 28307c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 28317c478bd9Sstevel@tonic-gate int rc; 28327c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 28337c478bd9Sstevel@tonic-gate /* routine specific */ 28347c478bd9Sstevel@tonic-gate authstr_t *ptr; 28357c478bd9Sstevel@tonic-gate int max_attr = 6; 28367c478bd9Sstevel@tonic-gate static char *oclist[] = { 28377c478bd9Sstevel@tonic-gate "SolarisAuthAttr", 28387c478bd9Sstevel@tonic-gate "top", 28397c478bd9Sstevel@tonic-gate NULL 28407c478bd9Sstevel@tonic-gate }; 28417c478bd9Sstevel@tonic-gate 28427c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 28437c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 28447c478bd9Sstevel@tonic-gate 28457c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 28467c478bd9Sstevel@tonic-gate if (e == NULL) 28477c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate /* Convert the structure */ 28507c478bd9Sstevel@tonic-gate ptr = (authstr_t *)data; 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 28537c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 28547c478bd9Sstevel@tonic-gate *entry = NULL; 28557c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 28567c478bd9Sstevel@tonic-gate } 28577c478bd9Sstevel@tonic-gate 28587c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 28597c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 28607c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 28617c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 28627c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 28637c478bd9Sstevel@tonic-gate *entry = NULL; 28647c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 28657c478bd9Sstevel@tonic-gate } 28667c478bd9Sstevel@tonic-gate 28677c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 28687c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28697c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28707c478bd9Sstevel@tonic-gate return (rc); 28717c478bd9Sstevel@tonic-gate } 28727c478bd9Sstevel@tonic-gate 28737c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 28747c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28757c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28767c478bd9Sstevel@tonic-gate return (rc); 28777c478bd9Sstevel@tonic-gate } 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 28807c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 28817c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28837c478bd9Sstevel@tonic-gate return (rc); 28847c478bd9Sstevel@tonic-gate } 28857c478bd9Sstevel@tonic-gate } 28867c478bd9Sstevel@tonic-gate 28877c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 28887c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 28897c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28907c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28917c478bd9Sstevel@tonic-gate return (rc); 28927c478bd9Sstevel@tonic-gate } 28937c478bd9Sstevel@tonic-gate } 28947c478bd9Sstevel@tonic-gate 28957c478bd9Sstevel@tonic-gate if (ptr->short_desc != NULL) { 28967c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrShortDesc", ptr->short_desc); 28977c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 28987c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 28997c478bd9Sstevel@tonic-gate return (rc); 29007c478bd9Sstevel@tonic-gate } 29017c478bd9Sstevel@tonic-gate } 29027c478bd9Sstevel@tonic-gate 29037c478bd9Sstevel@tonic-gate if (ptr->long_desc != NULL) { 29047c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->long_desc); 29057c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29077c478bd9Sstevel@tonic-gate return (rc); 29087c478bd9Sstevel@tonic-gate } 29097c478bd9Sstevel@tonic-gate } 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 29127c478bd9Sstevel@tonic-gate } 29137c478bd9Sstevel@tonic-gate /* 29147c478bd9Sstevel@tonic-gate * Conversion: exec_attr 29157c478bd9Sstevel@tonic-gate * Input format: execstr_t 29167c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisExecAttr 29177c478bd9Sstevel@tonic-gate */ 29187c478bd9Sstevel@tonic-gate static int 29197c478bd9Sstevel@tonic-gate __s_cvt_execattr(const void *data, char **rdn, 29207c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 29217c478bd9Sstevel@tonic-gate { 29227c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 29237c478bd9Sstevel@tonic-gate int rc; 29247c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 29257c478bd9Sstevel@tonic-gate /* routine specific */ 29267c478bd9Sstevel@tonic-gate execstr_t *ptr; 29277c478bd9Sstevel@tonic-gate int max_attr = 7; 29287c478bd9Sstevel@tonic-gate static char *oclist[] = { 29297c478bd9Sstevel@tonic-gate "SolarisExecAttr", 29307c478bd9Sstevel@tonic-gate "SolarisProfAttr", 29317c478bd9Sstevel@tonic-gate "top", 29327c478bd9Sstevel@tonic-gate NULL 29337c478bd9Sstevel@tonic-gate }; 29347c478bd9Sstevel@tonic-gate 29357c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 29367c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 29397c478bd9Sstevel@tonic-gate if (e == NULL) 29407c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate /* Convert the structure */ 29437c478bd9Sstevel@tonic-gate ptr = (execstr_t *)data; 29447c478bd9Sstevel@tonic-gate 29457c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 29467c478bd9Sstevel@tonic-gate ptr->policy == NULL || ptr->policy[0] == '\0' || 29477c478bd9Sstevel@tonic-gate ptr->type == NULL || ptr->type[0] == '\0' || 29487c478bd9Sstevel@tonic-gate ptr->id == NULL || ptr->id[0] == '\0') { 29497c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 29507c478bd9Sstevel@tonic-gate *entry = NULL; 29517c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 29527c478bd9Sstevel@tonic-gate } 29537c478bd9Sstevel@tonic-gate 29547c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 29557c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s+SolarisKernelSecurityPolicy=%s" 29567c478bd9Sstevel@tonic-gate "+SolarisProfileType=%s+SolarisProfileId=%s", 29577c478bd9Sstevel@tonic-gate ptr->name, ptr->policy, ptr->type, ptr->id); 29587c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 29597c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 29607c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 29617c478bd9Sstevel@tonic-gate *entry = NULL; 29627c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 29637c478bd9Sstevel@tonic-gate } 29647c478bd9Sstevel@tonic-gate 29657c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 29667c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29687c478bd9Sstevel@tonic-gate return (rc); 29697c478bd9Sstevel@tonic-gate } 29707c478bd9Sstevel@tonic-gate 29717c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisKernelSecurityPolicy", ptr->policy); 29727c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29737c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29747c478bd9Sstevel@tonic-gate return (rc); 29757c478bd9Sstevel@tonic-gate } 29767c478bd9Sstevel@tonic-gate 29777c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileType", ptr->type); 29787c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29797c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29807c478bd9Sstevel@tonic-gate return (rc); 29817c478bd9Sstevel@tonic-gate } 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisProfileId", ptr->id); 29847c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29857c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29867c478bd9Sstevel@tonic-gate return (rc); 29877c478bd9Sstevel@tonic-gate } 29887c478bd9Sstevel@tonic-gate 29897c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 29907c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29917c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29927c478bd9Sstevel@tonic-gate return (rc); 29937c478bd9Sstevel@tonic-gate } 29947c478bd9Sstevel@tonic-gate 29957c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 29967c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes1", ptr->res1); 29977c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 29987c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 29997c478bd9Sstevel@tonic-gate return (rc); 30007c478bd9Sstevel@tonic-gate } 30017c478bd9Sstevel@tonic-gate } 30027c478bd9Sstevel@tonic-gate 30037c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 30047c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrRes2", ptr->res2); 30057c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30067c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30077c478bd9Sstevel@tonic-gate return (rc); 30087c478bd9Sstevel@tonic-gate } 30097c478bd9Sstevel@tonic-gate } 30107c478bd9Sstevel@tonic-gate 30117c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 30127c478bd9Sstevel@tonic-gate } 30137c478bd9Sstevel@tonic-gate /* 30147c478bd9Sstevel@tonic-gate * Conversion: prof_attr 30157c478bd9Sstevel@tonic-gate * Input format: profstr_t 30167c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisProfAttr 30177c478bd9Sstevel@tonic-gate */ 30187c478bd9Sstevel@tonic-gate static int 30197c478bd9Sstevel@tonic-gate __s_cvt_profattr(const void *data, char **rdn, 30207c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 30217c478bd9Sstevel@tonic-gate { 30227c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 30237c478bd9Sstevel@tonic-gate int rc; 30247c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 30257c478bd9Sstevel@tonic-gate /* routine specific */ 30267c478bd9Sstevel@tonic-gate profstr_t *ptr; 30277c478bd9Sstevel@tonic-gate int max_attr = 5; 30287c478bd9Sstevel@tonic-gate static char *oclist[] = { 30297c478bd9Sstevel@tonic-gate "SolarisProfAttr", 30307c478bd9Sstevel@tonic-gate "top", 30317c478bd9Sstevel@tonic-gate NULL 30327c478bd9Sstevel@tonic-gate }; 30337c478bd9Sstevel@tonic-gate 30347c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 30357c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 30367c478bd9Sstevel@tonic-gate 30377c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 30387c478bd9Sstevel@tonic-gate if (e == NULL) 30397c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30407c478bd9Sstevel@tonic-gate 30417c478bd9Sstevel@tonic-gate /* Convert the structure */ 30427c478bd9Sstevel@tonic-gate ptr = (profstr_t *)data; 30437c478bd9Sstevel@tonic-gate 30447c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) { 30457c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30467c478bd9Sstevel@tonic-gate *entry = NULL; 30477c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 30487c478bd9Sstevel@tonic-gate } 30497c478bd9Sstevel@tonic-gate 30507c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 30517c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name); 30527c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 30537c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 30547c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 30557c478bd9Sstevel@tonic-gate *entry = NULL; 30567c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 30577c478bd9Sstevel@tonic-gate } 30587c478bd9Sstevel@tonic-gate 30597c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "cn", ptr->name); 30607c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30617c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30627c478bd9Sstevel@tonic-gate return (rc); 30637c478bd9Sstevel@tonic-gate } 30647c478bd9Sstevel@tonic-gate 30657c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 30667c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30687c478bd9Sstevel@tonic-gate return (rc); 30697c478bd9Sstevel@tonic-gate } 30707c478bd9Sstevel@tonic-gate 30717c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 30727c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 30737c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30747c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30757c478bd9Sstevel@tonic-gate return (rc); 30767c478bd9Sstevel@tonic-gate } 30777c478bd9Sstevel@tonic-gate } 30787c478bd9Sstevel@tonic-gate 30797c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 30807c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 30817c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30827c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30837c478bd9Sstevel@tonic-gate return (rc); 30847c478bd9Sstevel@tonic-gate } 30857c478bd9Sstevel@tonic-gate } 30867c478bd9Sstevel@tonic-gate 30877c478bd9Sstevel@tonic-gate if (ptr->desc != NULL) { 30887c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->desc); 30897c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 30907c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 30917c478bd9Sstevel@tonic-gate return (rc); 30927c478bd9Sstevel@tonic-gate } 30937c478bd9Sstevel@tonic-gate } 30947c478bd9Sstevel@tonic-gate 30957c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 30967c478bd9Sstevel@tonic-gate } 30977c478bd9Sstevel@tonic-gate /* 30987c478bd9Sstevel@tonic-gate * Conversion: user_attr 30997c478bd9Sstevel@tonic-gate * Input format: userstr_t 31007c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisUserAttr 31017c478bd9Sstevel@tonic-gate */ 31027c478bd9Sstevel@tonic-gate static int 31037c478bd9Sstevel@tonic-gate __s_cvt_userattr(const void *data, char **rdn, 31047c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 31057c478bd9Sstevel@tonic-gate { 31067c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 31077c478bd9Sstevel@tonic-gate int rc; 31087c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 31097c478bd9Sstevel@tonic-gate /* routine specific */ 31107c478bd9Sstevel@tonic-gate userstr_t *ptr; 31117c478bd9Sstevel@tonic-gate int max_attr = 5; 31127c478bd9Sstevel@tonic-gate static char *oclist[] = { 31137c478bd9Sstevel@tonic-gate "SolarisUserAttr", 31147c478bd9Sstevel@tonic-gate NULL 31157c478bd9Sstevel@tonic-gate }; 31167c478bd9Sstevel@tonic-gate 31177c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 31187c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 31197c478bd9Sstevel@tonic-gate 31207c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 31217c478bd9Sstevel@tonic-gate if (e == NULL) 31227c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31237c478bd9Sstevel@tonic-gate 31247c478bd9Sstevel@tonic-gate /* Convert the structure */ 31257c478bd9Sstevel@tonic-gate ptr = (userstr_t *)data; 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate if (ptr->name == NULL || ptr->name[0] == '\0' || 31287c478bd9Sstevel@tonic-gate ptr->attr == NULL) { 31297c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31307c478bd9Sstevel@tonic-gate *entry = NULL; 31317c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 31327c478bd9Sstevel@tonic-gate } 31337c478bd9Sstevel@tonic-gate 31347c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 31357c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name); 31367c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 31377c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 31387c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 31397c478bd9Sstevel@tonic-gate *entry = NULL; 31407c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 31417c478bd9Sstevel@tonic-gate } 31427c478bd9Sstevel@tonic-gate 31437c478bd9Sstevel@tonic-gate /* 31447c478bd9Sstevel@tonic-gate * SolarisUserAttr has no uid attribute 31457c478bd9Sstevel@tonic-gate */ 31467c478bd9Sstevel@tonic-gate 31477c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr); 31487c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31497c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31507c478bd9Sstevel@tonic-gate return (rc); 31517c478bd9Sstevel@tonic-gate } 31527c478bd9Sstevel@tonic-gate 31537c478bd9Sstevel@tonic-gate if (ptr->qualifier != NULL) { 31547c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisUserQualifier", ptr->qualifier); 31557c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31567c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31577c478bd9Sstevel@tonic-gate return (rc); 31587c478bd9Sstevel@tonic-gate } 31597c478bd9Sstevel@tonic-gate } 31607c478bd9Sstevel@tonic-gate 31617c478bd9Sstevel@tonic-gate if (ptr->res1 != NULL) { 31627c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1); 31637c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31647c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31657c478bd9Sstevel@tonic-gate return (rc); 31667c478bd9Sstevel@tonic-gate } 31677c478bd9Sstevel@tonic-gate } 31687c478bd9Sstevel@tonic-gate 31697c478bd9Sstevel@tonic-gate if (ptr->res2 != NULL) { 31707c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2); 31717c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 31727c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 31737c478bd9Sstevel@tonic-gate return (rc); 31747c478bd9Sstevel@tonic-gate } 31757c478bd9Sstevel@tonic-gate } 31767c478bd9Sstevel@tonic-gate 31777c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 31787c478bd9Sstevel@tonic-gate } 31797c478bd9Sstevel@tonic-gate /* 31807c478bd9Sstevel@tonic-gate * Conversion: audit_user 31817c478bd9Sstevel@tonic-gate * Input format: au_user_str_t 31827c478bd9Sstevel@tonic-gate * Exported objectclass: SolarisAuditUser 31837c478bd9Sstevel@tonic-gate */ 31847c478bd9Sstevel@tonic-gate static int 31857c478bd9Sstevel@tonic-gate __s_cvt_audituser(const void *data, char **rdn, 31867c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, ns_ldap_error_t **errorp) 31877c478bd9Sstevel@tonic-gate { 31887c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 31897c478bd9Sstevel@tonic-gate int rc; 31907c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 31917c478bd9Sstevel@tonic-gate /* routine specific */ 31927c478bd9Sstevel@tonic-gate au_user_str_t *ptr; 31937c478bd9Sstevel@tonic-gate int max_attr = 3; 31947c478bd9Sstevel@tonic-gate static char *oclist[] = { 31957c478bd9Sstevel@tonic-gate "SolarisAuditUser", 31967c478bd9Sstevel@tonic-gate NULL 31977c478bd9Sstevel@tonic-gate }; 31987c478bd9Sstevel@tonic-gate 31997c478bd9Sstevel@tonic-gate if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL) 32007c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 32017c478bd9Sstevel@tonic-gate 32027c478bd9Sstevel@tonic-gate *entry = e = __s_mk_entry(oclist, max_attr); 32037c478bd9Sstevel@tonic-gate if (e == NULL) 32047c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate /* Convert the structure */ 32077c478bd9Sstevel@tonic-gate ptr = (au_user_str_t *)data; 32087c478bd9Sstevel@tonic-gate 32097c478bd9Sstevel@tonic-gate if (ptr->au_name == NULL || ptr->au_name[0] == '\0') { 32107c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32117c478bd9Sstevel@tonic-gate *entry = NULL; 32127c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 32137c478bd9Sstevel@tonic-gate } 32147c478bd9Sstevel@tonic-gate 32157c478bd9Sstevel@tonic-gate /* Create an appropriate rdn */ 32167c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->au_name); 32177c478bd9Sstevel@tonic-gate *rdn = strdup(trdn); 32187c478bd9Sstevel@tonic-gate if (*rdn == NULL) { 32197c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(e); 32207c478bd9Sstevel@tonic-gate *entry = NULL; 32217c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 32227c478bd9Sstevel@tonic-gate } 32237c478bd9Sstevel@tonic-gate 32247c478bd9Sstevel@tonic-gate /* 32257c478bd9Sstevel@tonic-gate * Solaris AuditUser has no uid attribute 32267c478bd9Sstevel@tonic-gate */ 32277c478bd9Sstevel@tonic-gate 32287c478bd9Sstevel@tonic-gate if (ptr->au_always != NULL) { 32297c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditAlways", ptr->au_always); 32307c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32317c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32327c478bd9Sstevel@tonic-gate return (rc); 32337c478bd9Sstevel@tonic-gate } 32347c478bd9Sstevel@tonic-gate } 32357c478bd9Sstevel@tonic-gate 32367c478bd9Sstevel@tonic-gate if (ptr->au_never != NULL) { 32377c478bd9Sstevel@tonic-gate rc = __s_add_attr(e, "SolarisAuditNever", ptr->au_never); 32387c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 32397c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(entry, rdn); 32407c478bd9Sstevel@tonic-gate return (rc); 32417c478bd9Sstevel@tonic-gate } 32427c478bd9Sstevel@tonic-gate } 32437c478bd9Sstevel@tonic-gate 32447c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 32457c478bd9Sstevel@tonic-gate } 32467c478bd9Sstevel@tonic-gate 32477c478bd9Sstevel@tonic-gate /* 32487c478bd9Sstevel@tonic-gate * Add Typed Entry Conversion data structures 32497c478bd9Sstevel@tonic-gate */ 32507c478bd9Sstevel@tonic-gate 32517c478bd9Sstevel@tonic-gate typedef struct __ns_cvt_type { 32527c478bd9Sstevel@tonic-gate const char *service; 32537c478bd9Sstevel@tonic-gate int flags; 32547c478bd9Sstevel@tonic-gate #define AE 1 /* alway add entries */ 32557c478bd9Sstevel@tonic-gate int (*cvt_rtn)(const void *data, 32567c478bd9Sstevel@tonic-gate char **rdn, 32577c478bd9Sstevel@tonic-gate ns_ldap_entry_t **entry, 32587c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp); 32597c478bd9Sstevel@tonic-gate } __ns_cvt_type_t; 32607c478bd9Sstevel@tonic-gate 32617c478bd9Sstevel@tonic-gate static __ns_cvt_type_t __s_cvtlist[] = { 32627c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PASSWD, 0, __s_cvt_passwd }, 32637c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_GROUP, 0, __s_cvt_group }, 32647c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_HOSTS, 0, __s_cvt_hosts }, 32657c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_IPNODES, 0, __s_cvt_hosts }, 32667c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_RPC, 0, __s_cvt_rpc }, 32677c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROTOCOLS, 0, __s_cvt_protocols }, 32687c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETWORKS, 0, __s_cvt_networks }, 32697c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETGROUP, 0, __s_cvt_netgroups }, 32707c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ALIASES, 0, __s_cvt_aliases }, 32717c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SERVICES, 0, __s_cvt_services }, 32727c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ETHERS, 0, __s_cvt_ethers }, 32737c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SHADOW, 0, __s_cvt_shadow }, 32747c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETMASKS, 0, __s_cvt_netmasks }, 32757c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_BOOTPARAMS, 0, __s_cvt_bootparams }, 32767c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTHATTR, 0, __s_cvt_authattr }, 32777c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_EXECATTR, 0, __s_cvt_execattr }, 32787c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROFILE, 0, __s_cvt_profattr }, 32797c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_USERATTR, AE, __s_cvt_userattr }, 32807c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTOMOUNT, 0, __s_cvt_auto_mount }, 32817c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PUBLICKEY, AE, __s_cvt_publickey }, 32827c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUUSER, AE, __s_cvt_audituser }, 32837c478bd9Sstevel@tonic-gate { NULL, 0, NULL }, 32847c478bd9Sstevel@tonic-gate }; 32857c478bd9Sstevel@tonic-gate 32867c478bd9Sstevel@tonic-gate /* 32877c478bd9Sstevel@tonic-gate * Add Typed Entry Routine 32887c478bd9Sstevel@tonic-gate */ 32897c478bd9Sstevel@tonic-gate 32907c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 32917c478bd9Sstevel@tonic-gate int __ns_ldap_addTypedEntry( 32927c478bd9Sstevel@tonic-gate const char *servicetype, 32937c478bd9Sstevel@tonic-gate const char *basedn, 32947c478bd9Sstevel@tonic-gate const void *data, 32957c478bd9Sstevel@tonic-gate const int create, 32967c478bd9Sstevel@tonic-gate const ns_cred_t *cred, 32977c478bd9Sstevel@tonic-gate const int flags, 32987c478bd9Sstevel@tonic-gate ns_ldap_error_t **errorp) 32997c478bd9Sstevel@tonic-gate { 33007c478bd9Sstevel@tonic-gate char *rdn = NULL, *fulldn = NULL; 33017c478bd9Sstevel@tonic-gate void **paramVal = NULL; 33027c478bd9Sstevel@tonic-gate ns_ldap_entry_t *entry = NULL; 33037c478bd9Sstevel@tonic-gate const ns_ldap_attr_t *const *modattrlist; 33047c478bd9Sstevel@tonic-gate ns_ldap_search_desc_t **sdlist; 33057c478bd9Sstevel@tonic-gate char **dns = NULL; 33067c478bd9Sstevel@tonic-gate char trdn[RDNSIZE]; 33077c478bd9Sstevel@tonic-gate char service[BUFSIZE]; 33087c478bd9Sstevel@tonic-gate int rc = 0; 33097c478bd9Sstevel@tonic-gate int automount = 0; 33107c478bd9Sstevel@tonic-gate int i, s; 33117c478bd9Sstevel@tonic-gate 33127c478bd9Sstevel@tonic-gate rc = NS_LDAP_OP_FAILED; 33137c478bd9Sstevel@tonic-gate for (s = 0; __s_cvtlist[s].service != NULL; s++) { 33147c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].cvt_rtn == NULL) 33157c478bd9Sstevel@tonic-gate continue; 33167c478bd9Sstevel@tonic-gate if (strcasecmp(__s_cvtlist[s].service, servicetype) == 0) 33177c478bd9Sstevel@tonic-gate break; 33187c478bd9Sstevel@tonic-gate /* Or, check if the servicetype is auto_ */ 33197c478bd9Sstevel@tonic-gate if (strcmp(__s_cvtlist[s].service, 33207c478bd9Sstevel@tonic-gate NS_LDAP_TYPE_AUTOMOUNT) == 0 && 33217c478bd9Sstevel@tonic-gate strncasecmp(servicetype, NS_LDAP_TYPE_AUTOMOUNT, 33227c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) { 33237c478bd9Sstevel@tonic-gate automount++; 33247c478bd9Sstevel@tonic-gate break; 33257c478bd9Sstevel@tonic-gate } 33267c478bd9Sstevel@tonic-gate } 33277c478bd9Sstevel@tonic-gate if (__s_cvtlist[s].service == NULL) 33287c478bd9Sstevel@tonic-gate return (rc); 33297c478bd9Sstevel@tonic-gate 33307c478bd9Sstevel@tonic-gate /* Convert the data */ 33317c478bd9Sstevel@tonic-gate rc = (*__s_cvtlist[s].cvt_rtn)(data, &rdn, &entry, errorp); 33327c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33337c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33347c478bd9Sstevel@tonic-gate return (rc); 33357c478bd9Sstevel@tonic-gate } 33367c478bd9Sstevel@tonic-gate if (rdn == NULL) { 33377c478bd9Sstevel@tonic-gate __ns_ldap_freeEntry(entry); 33387c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 33397c478bd9Sstevel@tonic-gate } 33407c478bd9Sstevel@tonic-gate 33417c478bd9Sstevel@tonic-gate if (strcmp(servicetype, "publickey") == 0) { 33427c478bd9Sstevel@tonic-gate struct _ns_pubkey *ptr; 33437c478bd9Sstevel@tonic-gate ptr = (struct _ns_pubkey *)data; 33447c478bd9Sstevel@tonic-gate if (ptr->hostcred == NS_HOSTCRED_TRUE) 33457c478bd9Sstevel@tonic-gate (void) strcpy(service, "hosts"); 33467c478bd9Sstevel@tonic-gate else 33477c478bd9Sstevel@tonic-gate (void) strcpy(service, "passwd"); 33487c478bd9Sstevel@tonic-gate } else 33497c478bd9Sstevel@tonic-gate (void) strcpy(service, servicetype); 33507c478bd9Sstevel@tonic-gate 33517c478bd9Sstevel@tonic-gate /* Create the Full DN */ 33527c478bd9Sstevel@tonic-gate if (basedn == NULL) { 33537c478bd9Sstevel@tonic-gate rc = __s_api_get_SSD_from_SSDtoUse_service(service, 33547c478bd9Sstevel@tonic-gate &sdlist, errorp); 33557c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33567c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33577c478bd9Sstevel@tonic-gate return (rc); 33587c478bd9Sstevel@tonic-gate } 33597c478bd9Sstevel@tonic-gate 33607c478bd9Sstevel@tonic-gate if (sdlist == NULL) { 33617c478bd9Sstevel@tonic-gate rc = __s_api_getDNs(&dns, service, errorp); 33627c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33637c478bd9Sstevel@tonic-gate if (dns) { 33647c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 33657c478bd9Sstevel@tonic-gate dns = NULL; 33667c478bd9Sstevel@tonic-gate } 33677c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33687c478bd9Sstevel@tonic-gate return (rc); 33697c478bd9Sstevel@tonic-gate } 33707c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", rdn, dns[0]); 33717c478bd9Sstevel@tonic-gate __s_api_free2dArray(dns); 33727c478bd9Sstevel@tonic-gate } else { 33737c478bd9Sstevel@tonic-gate if (sdlist[0]->basedn) { 33747c478bd9Sstevel@tonic-gate (void) snprintf(trdn, RDNSIZE, "%s,%s", 33757c478bd9Sstevel@tonic-gate rdn, sdlist[0]->basedn); 33767c478bd9Sstevel@tonic-gate } else { 33777c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33787c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 33797c478bd9Sstevel@tonic-gate } 33807c478bd9Sstevel@tonic-gate } 33817c478bd9Sstevel@tonic-gate i = strlen(trdn) - 1; 33827c478bd9Sstevel@tonic-gate if (trdn[i] == COMMATOK) { 33837c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 33847c478bd9Sstevel@tonic-gate ¶mVal, errorp); 33857c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 33867c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33877c478bd9Sstevel@tonic-gate return (rc); 33887c478bd9Sstevel@tonic-gate } 33897c478bd9Sstevel@tonic-gate i = strlen(trdn) + strlen((char *)(paramVal[0])) + 1; 33907c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 33917c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 33927c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 33937c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 33947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 33957c478bd9Sstevel@tonic-gate } 33967c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s%s", trdn, 33977c478bd9Sstevel@tonic-gate (char *)(paramVal[0])); 33987c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 33997c478bd9Sstevel@tonic-gate } else { 34007c478bd9Sstevel@tonic-gate fulldn = strdup(trdn); 34017c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 34027c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34037c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34047c478bd9Sstevel@tonic-gate } 34057c478bd9Sstevel@tonic-gate } 34067c478bd9Sstevel@tonic-gate } else { 34077c478bd9Sstevel@tonic-gate i = strlen(rdn) + strlen(basedn) + 2; 34087c478bd9Sstevel@tonic-gate fulldn = (char *)calloc(i, 1); 34097c478bd9Sstevel@tonic-gate if (fulldn == NULL) { 34107c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34117c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34127c478bd9Sstevel@tonic-gate } 34137c478bd9Sstevel@tonic-gate (void) snprintf(fulldn, i, "%s,%s", rdn, basedn); 34147c478bd9Sstevel@tonic-gate } 34157c478bd9Sstevel@tonic-gate 34167c478bd9Sstevel@tonic-gate modattrlist = (const ns_ldap_attr_t * const *)entry->attr_pair; 34177c478bd9Sstevel@tonic-gate /* Check to see if the entry exists already */ 34187c478bd9Sstevel@tonic-gate /* May need to delete or update first */ 34197c478bd9Sstevel@tonic-gate 34207c478bd9Sstevel@tonic-gate if (create != 1) { 34217c478bd9Sstevel@tonic-gate /* Modify the entry */ 34227c478bd9Sstevel@tonic-gate if ((__s_cvtlist[s].flags & AE) != 0) 34237c478bd9Sstevel@tonic-gate rc = __ns_ldap_addAttr(service, fulldn, modattrlist, 34247c478bd9Sstevel@tonic-gate cred, flags, errorp); 34257c478bd9Sstevel@tonic-gate else { 34267c478bd9Sstevel@tonic-gate rc = __ns_ldap_repAttr(service, fulldn, modattrlist, 34277c478bd9Sstevel@tonic-gate cred, flags, errorp); 34287c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 34297c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_NO_SUCH_OBJECT) { 34307c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(errorp); 34317c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, 34327c478bd9Sstevel@tonic-gate entry, cred, flags, errorp); 34337c478bd9Sstevel@tonic-gate } 34347c478bd9Sstevel@tonic-gate } 34357c478bd9Sstevel@tonic-gate } else { 34367c478bd9Sstevel@tonic-gate /* Add the entry */ 34377c478bd9Sstevel@tonic-gate rc = __ns_ldap_addEntry(service, fulldn, entry, 34387c478bd9Sstevel@tonic-gate cred, flags, errorp); 34397c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_INTERNAL && *errorp && 34407c478bd9Sstevel@tonic-gate (*errorp)->status == LDAP_ALREADY_EXISTS && 34417c478bd9Sstevel@tonic-gate ((strcmp(service, "ethers") == 0) || 34427c478bd9Sstevel@tonic-gate (strcmp(service, "bootparams") == 0))) { 34437c478bd9Sstevel@tonic-gate rc = modify_ethers_bootp(service, rdn, fulldn, 34447c478bd9Sstevel@tonic-gate modattrlist, cred, flags, errorp); 34457c478bd9Sstevel@tonic-gate } 34467c478bd9Sstevel@tonic-gate } 34477c478bd9Sstevel@tonic-gate 34487c478bd9Sstevel@tonic-gate /* Free up entry created by conversion routine */ 34497c478bd9Sstevel@tonic-gate if (fulldn != NULL) 34507c478bd9Sstevel@tonic-gate free(fulldn); 34517c478bd9Sstevel@tonic-gate __s_cvt_freeEntryRdn(&entry, &rdn); 34527c478bd9Sstevel@tonic-gate return (rc); 34537c478bd9Sstevel@tonic-gate } 34547c478bd9Sstevel@tonic-gate 34557c478bd9Sstevel@tonic-gate 34567c478bd9Sstevel@tonic-gate /* 34577c478bd9Sstevel@tonic-gate * Append the default base dn to the dn 34587c478bd9Sstevel@tonic-gate * when it ends with ','. 34597c478bd9Sstevel@tonic-gate * e.g. 34607c478bd9Sstevel@tonic-gate * SSD = service:ou=foo, 34617c478bd9Sstevel@tonic-gate */ 34627c478bd9Sstevel@tonic-gate int 34637c478bd9Sstevel@tonic-gate __s_api_append_default_basedn( 34647c478bd9Sstevel@tonic-gate const char *dn, 34657c478bd9Sstevel@tonic-gate char **new_dn, 34667c478bd9Sstevel@tonic-gate int *allocated, 34677c478bd9Sstevel@tonic-gate ns_ldap_error_t **errp) { 34687c478bd9Sstevel@tonic-gate 34697c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS, len = 0; 34707c478bd9Sstevel@tonic-gate void **param = NULL; 34717c478bd9Sstevel@tonic-gate char *str = NULL; 34727c478bd9Sstevel@tonic-gate 34737c478bd9Sstevel@tonic-gate *allocated = FALSE; 34747c478bd9Sstevel@tonic-gate *new_dn = NULL; 34757c478bd9Sstevel@tonic-gate 34767c478bd9Sstevel@tonic-gate if (dn == NULL) 34777c478bd9Sstevel@tonic-gate return (NS_LDAP_INVALID_PARAM); 34787c478bd9Sstevel@tonic-gate 34797c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 34807c478bd9Sstevel@tonic-gate (void ***)¶m, errp); 34817c478bd9Sstevel@tonic-gate 34827c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 34837c478bd9Sstevel@tonic-gate if (param) 34847c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 34857c478bd9Sstevel@tonic-gate return (rc); 34867c478bd9Sstevel@tonic-gate } 34877c478bd9Sstevel@tonic-gate 34887c478bd9Sstevel@tonic-gate len = strlen(dn); 34897c478bd9Sstevel@tonic-gate str = ((char **)param)[0]; 34907c478bd9Sstevel@tonic-gate len = len + strlen(str) +1; 34917c478bd9Sstevel@tonic-gate *new_dn = (char *)malloc(len); 34927c478bd9Sstevel@tonic-gate if (*new_dn == NULL) { 34937c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 34947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 34957c478bd9Sstevel@tonic-gate } 34967c478bd9Sstevel@tonic-gate *allocated = TRUE; 34977c478bd9Sstevel@tonic-gate 34987c478bd9Sstevel@tonic-gate (void) strcpy(*new_dn, dn); 34997c478bd9Sstevel@tonic-gate (void) strcat(*new_dn, str); 35007c478bd9Sstevel@tonic-gate 35017c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶m); 35027c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 35037c478bd9Sstevel@tonic-gate } 3504