2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <sys/types.h>
2N/A#include <stdlib.h>
2N/A#include <libintl.h>
2N/A
2N/A#include <sys/stat.h>
2N/A#include <fcntl.h>
2N/A#include <unistd.h>
2N/A#include <string.h>
2N/A#include <strings.h>
2N/A#include <lber.h>
2N/A#include <ldap.h>
2N/A#include <syslog.h>
2N/A#include <stddef.h>
2N/A#include <sys/mman.h>
2N/A
2N/A#include "ns_sldap.h"
2N/A#include "ns_internal.h"
2N/A#include "ns_connmgmt.h"
2N/A#include "ns_cache_door.h"
2N/A
2N/A/* Additional headers for addTypedEntry Conversion routines */
2N/A#include <pwd.h>
2N/A#include <project.h>
2N/A#include <shadow.h>
2N/A#include <grp.h>
2N/A#include <netinet/in.h>
2N/A#include <arpa/inet.h>
2N/A#include <netdb.h>
2N/A#include <rpc/rpcent.h>
2N/A#include <auth_attr.h>
2N/A#include <exec_attr.h>
2N/A#include <prof_attr.h>
2N/A#include <user_attr.h>
2N/A#include <bsm/libbsm.h>
2N/A#include <sys/tsol/tndb.h>
2N/A#include <tsol/label.h>
2N/A
2N/Astatic int send_to_cachemgr(const char *,
2N/A ns_ldap_attr_t **, ns_ldap_error_t **, int, ldap_service_t);
2N/A
2N/Astatic int do_cachemgr_operation(const char *, ns_ldap_attr_t **,
2N/A ns_ldap_error_t **, int, ldap_service_t);
2N/A
2N/Astatic int escape_str(char *, char *);
2N/Astatic int get_admin_passwd(ns_cred_t *, ns_ldap_error_t **);
2N/A
2N/A/*
2N/A * Check to see if the UPDATE_SHADOW flag is set and the
2N/A * service is one of the services that are allowed to be modified
2N/A * with the UPDATE_SHADOW privilege.
2N/A */
2N/Astatic boolean_t
2N/Aprivileged_operation_check(const int flags, const char *service)
2N/A{
2N/A return ((flags & NS_LDAP_UPDATE_SHADOW) != 0 &&
2N/A (strcmp(service, "shadow") == 0 ||
2N/A strcmp(service, "passwd") == 0 ||
2N/A strcmp(service, "user_attr") == 0 ||
2N/A strcmp(service, "auth_attr") == 0 ||
2N/A strcmp(service, "exec_attr") == 0 ||
2N/A strcmp(service, "prof_attr") == 0 ||
2N/A strcmp(service, "project") == 0 ||
2N/A strcmp(service, "group") == 0 ||
2N/A strncmp(service, NS_LDAP_TYPE_AUTOMOUNT,
2N/A sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0 ||
2N/A strcmp(service, "tnrhdb") == 0 ||
2N/A strcmp(service, "tnrhtp") == 0));
2N/A}
2N/A
2N/Astatic ldap_service_t
2N/Amap_service_to_type(const char *service)
2N/A{
2N/A ldap_service_t svc;
2N/A
2N/A if (strcmp(service, "shadow") == 0)
2N/A svc = LDAP_SVC_SHADOW;
2N/A else if (strcmp(service, "passwd") == 0)
2N/A svc = LDAP_SVC_PASSWD;
2N/A else if (strcmp(service, "user_attr") == 0)
2N/A svc = LDAP_SVC_USERATTR;
2N/A else if (strcmp(service, "auth_attr") == 0)
2N/A svc = LDAP_SVC_AUTHATTR;
2N/A else if (strcmp(service, "exec_attr") == 0)
2N/A svc = LDAP_SVC_EXECATTR;
2N/A else if (strcmp(service, "prof_attr") == 0)
2N/A svc = LDAP_SVC_PROFATTR;
2N/A else if (strcmp(service, "project") == 0)
2N/A svc = LDAP_SVC_PROJECT;
2N/A else if (strcmp(service, "group") == 0)
2N/A svc = LDAP_SVC_GROUP;
2N/A else
2N/A svc = LDAP_SVC_OTHER;
2N/A
2N/A return (svc);
2N/A}
2N/A
2N/A/*
2N/A * If the rdn is a mapped attr:
2N/A * return NS_LDAP_SUCCESS and a new_dn.
2N/A * If no mapped attr is found in the rdn:
2N/A * return NS_LDAP_SUCCESS and *new_dn == NULL
2N/A * For example:
2N/A * service = abc
2N/A * dn = cn=foo,dc=bar,dc=com
2N/A * attributeMapping: abc:cn=sn
2N/A * Then:
2N/A * new_dn = sn=foo,dc=bar,dc=com
2N/A *
2N/A */
2N/Astatic int
2N/Areplace_mapped_attr_in_dn(
2N/A const char *service, const char *dn, char **new_dn)
2N/A{
2N/A char **mappedattr;
2N/A char **dnArray = NULL;
2N/A char *rservice;
2N/A char *cur = NULL;
2N/A int len = 0, orig_len = 0, mapped_len = 0;
2N/A int dn_len = 0;
2N/A
2N/A *new_dn = NULL;
2N/A
2N/A /*
2N/A * separate dn into individual components
2N/A * e.g.
2N/A * "automountKey=user_01" , "automountMapName_test=auto_home", ...
2N/A */
2N/A dnArray = ldap_explode_dn(dn, 0);
2N/A if (!dnArray || !*dnArray)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A cur = strchr(dnArray[0], '=');
2N/A if (!cur) {
2N/A __s_api_free2dArray(dnArray);
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A *cur = '\0';
2N/A
2N/A /* we only check schema mapping for automount, not for auto_* */
2N/A if (strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT,
2N/A sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0)
2N/A rservice = "automount";
2N/A else
2N/A rservice = (char *)service;
2N/A
2N/A mappedattr = __ns_ldap_getMappedAttributes(rservice, dnArray[0]);
2N/A if (!mappedattr || !mappedattr[0]) {
2N/A __s_api_free2dArray(dnArray);
2N/A if (mappedattr)
2N/A __s_api_free2dArray(mappedattr);
2N/A return (NS_LDAP_SUCCESS);
2N/A }
2N/A orig_len = strlen(dnArray[0]);
2N/A
2N/A /*
2N/A * The new length is *dn length + (difference between
2N/A * orig attr and mapped attr) + 1 ;
2N/A * e.g.
2N/A * automountKey=aa,automountMapName=auto_home,dc=foo,dc=com
2N/A * ==>
2N/A * cn=aa,automountMapName=auto_home,dc=foo,dc=com
2N/A */
2N/A mapped_len = strlen(mappedattr[0]);
2N/A dn_len = strlen(dn);
2N/A len = dn_len - orig_len + mapped_len + 1;
2N/A *new_dn = (char *)calloc(1, len);
2N/A if (*new_dn == NULL) {
2N/A __s_api_free2dArray(dnArray);
2N/A __s_api_free2dArray(mappedattr);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A (void) snprintf(*new_dn, len, "%s=%s", mappedattr[0], dn + orig_len +1);
2N/A __s_api_free2dArray(dnArray);
2N/A __s_api_free2dArray(mappedattr);
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * The following function is only used by the
2N/A * "gecos" 1 to N attribute mapping code. It expects
2N/A * and handle only one data/length pair.
2N/A */
2N/Astatic int
2N/Ainit_bval_mod(
2N/A LDAPMod *mod,
2N/A int mop,
2N/A char *mtype,
2N/A char *mvptr,
2N/A int mvlen)
2N/A{
2N/A
2N/A struct berval **bmodval;
2N/A
2N/A /* dup attribute name */
2N/A mod->mod_type = strdup(mtype);
2N/A if (mod->mod_type == NULL)
2N/A return (-1);
2N/A
2N/A /*
2N/A * assume single value,
2N/A * since only one value/length pair passed in
2N/A */
2N/A bmodval = (struct berval **)calloc(2, sizeof (struct berval *));
2N/A if (bmodval == NULL) {
2N/A free(mod->mod_type);
2N/A mod->mod_type = NULL;
2N/A return (-1);
2N/A }
2N/A bmodval[0] = (struct berval *)calloc(1, sizeof (struct berval));
2N/A if (bmodval[0] == NULL) {
2N/A free(mod->mod_type);
2N/A mod->mod_type = NULL;
2N/A free(bmodval);
2N/A return (-1);
2N/A }
2N/A
2N/A /* set pointer to data */
2N/A bmodval[0]->bv_val = mvptr;
2N/A
2N/A /* set length */
2N/A bmodval[0]->bv_len = mvlen;
2N/A
2N/A /*
2N/A * turn on the BVALUE bit to indicate
2N/A * that the length of data is supplied
2N/A */
2N/A mod->mod_op = mop | LDAP_MOD_BVALUES;
2N/A
2N/A mod->mod_bvalues = bmodval;
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Astatic void
2N/AfreeModList(LDAPMod **mods)
2N/A{
2N/A int i, j;
2N/A int name_is_oc;
2N/A
2N/A if (mods == NULL)
2N/A return;
2N/A
2N/A for (i = 0; mods[i]; i++) {
2N/A
2N/A /* free attribute name */
2N/A name_is_oc = FALSE;
2N/A if (mods[i]->mod_type) {
2N/A if (strcasecmp(mods[i]->mod_type, "objectclass") == 0)
2N/A name_is_oc = TRUE;
2N/A free(mods[i]->mod_type);
2N/A }
2N/A
2N/A if (mods[i]->mod_bvalues == NULL)
2N/A continue;
2N/A /*
2N/A * LDAP_MOD_BVALUES is only set by
2N/A * the "gecos" 1 to N attribute mapping
2N/A * code, and the attribute is single valued.
2N/A */
2N/A if (mods[i]->mod_op & LDAP_MOD_BVALUES) {
2N/A if (mods[i]->mod_bvalues[0])
2N/A free(mods[i]->mod_bvalues[0]);
2N/A } else {
2N/A if (name_is_oc) {
2N/A /*
2N/A * only values for the "objectclass"
2N/A * were dupped using strdup.
2N/A * other attribute values were
2N/A * not dupped, but via pointer
2N/A * assignment. So here the
2N/A * values for "objectclass"
2N/A * is freed one by one,
2N/A * but the values for other
2N/A * attributes need not be freed.
2N/A */
2N/A for (j = 0; mods[i]->mod_values[j]; j++)
2N/A free(mods[i]->mod_values[j]);
2N/A }
2N/A
2N/A }
2N/A free(mods[i]->mod_bvalues);
2N/A }
2N/A
2N/A /* modlist */
2N/A free((char *)(mods[0]));
2N/A free(mods);
2N/A}
2N/A
2N/Astatic LDAPMod **
2N/A__s_api_makeModListCount(
2N/A const char *service,
2N/A const ns_ldap_attr_t * const *attr,
2N/A const int mod_op,
2N/A const int count,
2N/A const int flags)
2N/A{
2N/A LDAPMod **mods, *modlist;
2N/A char **modval;
2N/A char **mapping;
2N/A int i;
2N/A int j;
2N/A int k, rc, vlen;
2N/A char *c, *comma1 = NULL, *comma2 = NULL;
2N/A int schema_mapping_existed = FALSE;
2N/A int auto_service = FALSE;
2N/A
2N/A /*
2N/A * add 2 for "gecos" 1 to up to 3 attribute mapping
2N/A */
2N/A mods = (LDAPMod **)calloc((count + 3), sizeof (LDAPMod *));
2N/A if (mods == NULL) {
2N/A return (NULL);
2N/A }
2N/A /*
2N/A * add 2 for "gecos" 1 to up to 3 attribute mapping
2N/A */
2N/A modlist = (LDAPMod *)calloc(count + 2, sizeof (LDAPMod));
2N/A if (modlist == NULL) {
2N/A free(mods);
2N/A return (NULL);
2N/A }
2N/A
2N/A if (service != NULL && strncasecmp(service, NS_LDAP_TYPE_AUTOMOUNT,
2N/A sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0)
2N/A auto_service = TRUE;
2N/A
2N/A /*
2N/A * see if schema mapping existed for the given service
2N/A */
2N/A mapping = __ns_ldap_getOrigAttribute(service,
2N/A NS_HASH_SCHEMA_MAPPING_EXISTED);
2N/A if (mapping) {
2N/A schema_mapping_existed = TRUE;
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A }
2N/A
2N/A for (i = 0, k = 0; k < count && attr[k] != NULL; i++, k++) {
2N/A mods[i] = &modlist[i];
2N/A mods[i]->mod_op = mod_op;
2N/A /*
2N/A * Perform attribute mapping if necessary.
2N/A */
2N/A if (schema_mapping_existed && (flags & NS_LDAP_NOMAP) == 0) {
2N/A mapping = __ns_ldap_getMappedAttributes(service,
2N/A attr[k]->attrname);
2N/A } else
2N/A mapping = NULL;
2N/A
2N/A if (mapping == NULL && auto_service &&
2N/A (flags & NS_LDAP_NOMAP) == 0) {
2N/A /*
2N/A * if service == auto_xxx and
2N/A * no mapped attribute is found
2N/A * and NS_LDAP_NOMAP is not set
2N/A * then try automount's mapped attribute
2N/A */
2N/A mapping = __ns_ldap_getMappedAttributes("automount",
2N/A attr[k]->attrname);
2N/A }
2N/A
2N/A if (mapping == NULL) {
2N/A mods[i]->mod_type = strdup(attr[k]->attrname);
2N/A if (mods[i]->mod_type == NULL)
2N/A goto free_memory;
2N/A } else {
2N/A /*
2N/A * 1 to N attribute mapping is only done for "gecos",
2N/A * and only 1 to 3 mapping.
2N/A * nine cases here:
2N/A *
2N/A * A. attrMap=passwd:gecos=a
2N/A * 1. gecos="xx,yy,zz" -> a="xx,yy,zz"
2N/A * 2. gecos="xx,yy" -> a="xx,yy"
2N/A * 3. gecos="xx" -> a="xx"
2N/A *
2N/A * B. attrMap=passwd:gecos=a b
2N/A * 4. gecos="xx,yy,zz" -> a="xx" b="yy,zz"
2N/A * 5. gecos="xx,yy" -> a="xx" b="yy"
2N/A * 6. gecos="xx" -> a="xx"
2N/A *
2N/A * C. attrMap=passwd:gecos=a b c
2N/A * 7. gecos="xx,yy,zz" -> a="xx" b="yy" c="zz"
2N/A * 8. gecos="xx,yy" -> a="xx" b="yy"
2N/A * 9. gecos="xx" -> a="xx"
2N/A *
2N/A * This can be grouped as:
2N/A *
2N/A * c1 cases: 1,2,3,6,9
2N/A * if ((attrMap=passwd:gecos=a) ||
2N/A * (no "," in gecos value))
2N/A * same as other no-mapping attributes,
2N/A * no special processing needed
2N/A * else
2N/A *
2N/A * c2 cases: 4,5,8
2N/A * if ((attrMap=passwd:gecos=a b) ||
2N/A * (only one "," in gecos value))
2N/A * a=xx b=yy[,...]
2N/A * else
2N/A *
2N/A * c3 case: 7
2N/A * a=xx b=yy c=...
2N/A *
2N/A * notes: in case c2 and c3, ... could still contain ","
2N/A */
2N/A if (strcasecmp(service, "passwd") == 0 &&
2N/A strcasecmp(attr[k]->attrname, "gecos") == 0 &&
2N/A mapping[1] && attr[k]->attrvalue[0] &&
2N/A (comma1 = strchr(attr[k]->attrvalue[0],
2N/A COMMATOK)) != NULL) {
2N/A
2N/A /* is there a second comma? */
2N/A if (*(comma1 + 1) != '\0')
2N/A comma2 = strchr(comma1 + 1, COMMATOK);
2N/A
2N/A /*
2N/A * Process case c2 or c3.
2N/A * case c2: mapped to two attributes or just
2N/A * one comma
2N/A */
2N/A if (mapping[2] == NULL || comma2 == NULL) {
2N/A /* case c2 */
2N/A
2N/A /*
2N/A * int mod structure for the first attribute
2N/A */
2N/A vlen = comma1 - attr[k]->attrvalue[0];
2N/A c = attr[k]->attrvalue[0];
2N/A
2N/A if (vlen > 0 && c) {
2N/A rc = init_bval_mod(mods[i], mod_op,
2N/A mapping[0], c, vlen);
2N/A if (rc != 0)
2N/A goto free_memory;
2N/A } else {
2N/A /* don't leave a hole in mods array */
2N/A mods[i] = NULL;
2N/A i--;
2N/A }
2N/A
2N/A
2N/A /*
2N/A * init mod structure for the 2nd attribute
2N/A */
2N/A if (*(comma1 + 1) == '\0') {
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A continue;
2N/A }
2N/A
2N/A i++;
2N/A mods[i] = &modlist[i];
2N/A
2N/A /*
2N/A * get pointer to data.
2N/A * Skip leading spaces.
2N/A */
2N/A for (c = comma1 + 1; *c == SPACETOK; c++) {
2N/A /* empty */
2N/A }
2N/A
2N/A /* get data length */
2N/A vlen = strlen(attr[k]->attrvalue[0]) -
2N/A (c - attr[k]->attrvalue[0]);
2N/A
2N/A if (vlen > 0 && c) {
2N/A rc = init_bval_mod(mods[i], mod_op,
2N/A mapping[1], c, vlen);
2N/A if (rc != 0)
2N/A goto free_memory;
2N/A } else {
2N/A /* don't leave a hole in mods array */
2N/A mods[i] = NULL;
2N/A i--;
2N/A }
2N/A
2N/A /* done with the mapping array */
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A
2N/A continue;
2N/A } else {
2N/A /* case c3 */
2N/A
2N/A /*
2N/A * int mod structure for the first attribute
2N/A */
2N/A vlen = comma1 - attr[k]->attrvalue[0];
2N/A c = attr[k]->attrvalue[0];
2N/A
2N/A if (vlen > 0 && c) {
2N/A rc = init_bval_mod(mods[i], mod_op,
2N/A mapping[0], c, vlen);
2N/A if (rc != 0)
2N/A goto free_memory;
2N/A } else {
2N/A /* don't leave a hole in mods array */
2N/A mods[i] = NULL;
2N/A i--;
2N/A }
2N/A
2N/A /*
2N/A * init mod structure for the 2nd attribute
2N/A */
2N/A i++;
2N/A mods[i] = &modlist[i];
2N/A
2N/A /*
2N/A * get pointer to data.
2N/A * Skip leading spaces.
2N/A */
2N/A for (c = comma1 + 1; *c == SPACETOK; c++) {
2N/A /* empty */
2N/A };
2N/A
2N/A /* get data length */
2N/A vlen = comma2 - c;
2N/A
2N/A if (vlen > 0 && c) {
2N/A rc = init_bval_mod(mods[i], mod_op,
2N/A mapping[1], c, vlen);
2N/A if (rc != 0)
2N/A goto free_memory;
2N/A } else {
2N/A /* don't leave a hole in mods array */
2N/A mods[i] = NULL;
2N/A i--;
2N/A }
2N/A
2N/A /*
2N/A * init mod structure for the 3rd attribute
2N/A */
2N/A if (*(comma2 + 1) == '\0') {
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A continue;
2N/A }
2N/A
2N/A i++;
2N/A mods[i] = &modlist[i];
2N/A /*
2N/A * get pointer to data.
2N/A * Skip leading spaces.
2N/A */
2N/A for (c = comma2 + 1; *c == SPACETOK; c++) {
2N/A /* empty */
2N/A }
2N/A
2N/A /* get data length */
2N/A vlen = strlen(attr[k]->attrvalue[0]) -
2N/A (c - attr[k]->attrvalue[0]);
2N/A
2N/A if (vlen > 0 && c) {
2N/A rc = init_bval_mod(mods[i], mod_op,
2N/A mapping[2], c, vlen);
2N/A if (rc != 0)
2N/A goto free_memory;
2N/A } else {
2N/A /* don't leave a hole in mods array */
2N/A mods[i] = NULL;
2N/A i--;
2N/A }
2N/A
2N/A /* done with the mapping array */
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A /* case c1 */
2N/A mods[i]->mod_type = strdup(mapping[0]);
2N/A if (mods[i]->mod_type == NULL) {
2N/A goto free_memory;
2N/A }
2N/A __s_api_free2dArray(mapping);
2N/A mapping = NULL;
2N/A }
2N/A
2N/A modval = (char **)calloc(attr[k]->value_count+1,
2N/A sizeof (char *));
2N/A if (modval == NULL)
2N/A goto free_memory;
2N/A
2N/A mods[i]->mod_values = modval;
2N/A
2N/A /*
2N/A * Perform objectclass mapping.
2N/A * Note that the values for the "objectclass" attribute
2N/A * will be dupped using strdup. Values for other
2N/A * attributes will be referenced via pointer
2N/A * assignments.
2N/A */
2N/A if (strcasecmp(mods[i]->mod_type, "objectclass") == 0) {
2N/A for (j = 0; j < attr[k]->value_count; j++) {
2N/A if (schema_mapping_existed &&
2N/A (flags & NS_LDAP_NOMAP) == 0)
2N/A mapping =
2N/A __ns_ldap_getMappedObjectClass(
2N/A service, attr[k]->attrvalue[j]);
2N/A else
2N/A mapping = NULL;
2N/A
2N/A if (mapping == NULL && auto_service &&
2N/A (flags & NS_LDAP_NOMAP) == 0)
2N/A /*
2N/A * if service == auto_xxx and
2N/A * no mapped objectclass is found
2N/A * then try automount
2N/A */
2N/A mapping =
2N/A __ns_ldap_getMappedObjectClass(
2N/A "automount", attr[k]->attrvalue[j]);
2N/A
2N/A if (mapping && mapping[0]) {
2N/A /* assume single mapping */
2N/A modval[j] = strdup(mapping[0]);
2N/A } else {
2N/A modval[j] = strdup(attr[k]->
2N/A attrvalue[j]);
2N/A }
2N/A if (modval[j] == NULL)
2N/A goto free_memory;
2N/A }
2N/A } else {
2N/A for (j = 0; j < attr[k]->value_count; j++) {
2N/A /* ASSIGN NOT COPY */
2N/A modval[j] = attr[k]->attrvalue[j];
2N/A }
2N/A }
2N/A }
2N/A
2N/A return (mods);
2N/A
2N/Afree_memory:
2N/A freeModList(mods);
2N/A if (mapping)
2N/A __s_api_free2dArray(mapping);
2N/A
2N/A return (NULL);
2N/A
2N/A}
2N/A
2N/Astatic LDAPMod **
2N/A__s_api_makeModList(
2N/A const char *service,
2N/A const ns_ldap_attr_t * const *attr,
2N/A const int mod_op,
2N/A const int flags)
2N/A{
2N/A ns_ldap_attr_t **aptr = (ns_ldap_attr_t **)attr;
2N/A int count = 0;
2N/A
2N/A if (aptr == NULL)
2N/A return (NULL);
2N/A
2N/A /* count number of attributes */
2N/A while (*aptr++)
2N/A count++;
2N/A
2N/A return (__s_api_makeModListCount(service, attr, mod_op, count, flags));
2N/A}
2N/A
2N/Astatic void
2N/A__s_cvt_freeEntryRdn(ns_ldap_entry_t **entry, char **rdn)
2N/A{
2N/A if (*entry != NULL) {
2N/A __ns_ldap_freeEntry(*entry);
2N/A *entry = NULL;
2N/A }
2N/A if (*rdn != NULL) {
2N/A free(*rdn);
2N/A *rdn = NULL;
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * This state machine performs one or more LDAP add/delete/modify
2N/A * operations to configured LDAP servers.
2N/A */
2N/Astatic int
2N/Awrite_state_machine(
2N/A int ldap_op,
2N/A char *dn,
2N/A LDAPMod **mods,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A ConnectionID connectionId = -1;
2N/A Connection *conp = NULL;
2N/A LDAPMessage *res;
2N/A char *target_dn = NULL;
2N/A char errstr[MAXERROR];
2N/A int rc = NS_LDAP_SUCCESS;
2N/A int return_rc = NS_LDAP_SUCCESS;
2N/A int followRef = FALSE;
2N/A int target_dn_allocated = FALSE;
2N/A int len;
2N/A int msgid;
2N/A int Errno;
2N/A boolean_t from_get_lderrno = B_FALSE;
2N/A int always = 1;
2N/A char *err, *errmsg = NULL;
2N/A /* referrals returned by the LDAP operation */
2N/A char **referrals = NULL;
2N/A /*
2N/A * There can be only one referral from the an LDAP write
2N/A * operation. The write state machine only allows one level
2N/A * referral. If a referral server returns a further referral
2N/A * it is ignored. The referral is stored in the referral_list
2N/A * for the state machine. The returned referral can have
2N/A * multiple references to other servers. (ref_info(s))
2N/A * These multiple references can represent master-slave(s) or
2N/A * multi-masters configurations. These multiple references
2N/A * are tried until one is successful.
2N/A */
2N/A ns_referral_t *referral_list = NULL;
2N/A ns_ref_info_t *ref_info = NULL;
2N/A ns_write_state_t state = W_INIT, new_state, err_state = W_INIT;
2N/A int do_not_fail_if_new_pwd_reqd = 0;
2N/A ns_ldap_passwd_status_t pwd_status = NS_PASSWD_GOOD;
2N/A int passwd_mgmt = 0;
2N/A int ldap_error;
2N/A int nopasswd_acct_mgmt = 0;
2N/A ns_conn_user_t *conn_user = NULL;
2N/A
2N/A while (always) {
2N/A switch (state) {
2N/A case W_EXIT:
2N/A /* return the MT connection and free the conn user */
2N/A if (conn_user != NULL) {
2N/A if (conn_user->use_mt_conn == B_TRUE) {
2N/A if (conn_user->ns_error != NULL) {
2N/A *errorp = conn_user->ns_error;
2N/A conn_user->ns_error = NULL;
2N/A return_rc = conn_user->ns_rc;
2N/A }
2N/A if (conn_user->conn_mt != NULL)
2N/A __s_api_conn_mt_return(
2N/A conn_user);
2N/A }
2N/A __s_api_conn_user_free(conn_user);
2N/A }
2N/A
2N/A if (connectionId > -1)
2N/A DropConnection(connectionId, NS_LDAP_NEW_CONN);
2N/A if (referral_list)
2N/A __s_api_deleteReferral(referral_list);
2N/A if (target_dn && target_dn_allocated)
2N/A free(target_dn);
2N/A return (return_rc);
2N/A case W_INIT:
2N/A /* see if need to follow referrals */
2N/A rc = __s_api_toFollowReferrals(flags,
2N/A &followRef, errorp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A return_rc = rc;
2N/A new_state = W_ERROR;
2N/A break;
2N/A }
2N/A len = strlen(dn);
2N/A if (dn[len-1] == COMMATOK)
2N/A rc = __s_api_append_default_basedn(
2N/A dn, &target_dn, &target_dn_allocated,
2N/A errorp);
2N/A else
2N/A target_dn = dn;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A return_rc = rc;
2N/A new_state = W_ERROR;
2N/A }
2N/A else
2N/A new_state = GET_CONNECTION;
2N/A break;
2N/A case GET_CONNECTION:
2N/A /* identify self as a write user */
2N/A conn_user = __s_api_conn_user_init(NS_CONN_USER_WRITE,
2N/A NULL, B_FALSE);
2N/A rc = __s_api_getConnection(NULL,
2N/A flags, cred, &connectionId, &conp, errorp,
2N/A do_not_fail_if_new_pwd_reqd, nopasswd_acct_mgmt,
2N/A conn_user);
2N/A
2N/A /*
2N/A * If password control attached
2N/A * in *errorp,
2N/A * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO,
2N/A * free the error structure (we do not need
2N/A * the password management info).
2N/A * Reset rc to NS_LDAP_SUCCESS.
2N/A */
2N/A if (rc == NS_LDAP_SUCCESS_WITH_INFO) {
2N/A (void) __ns_ldap_freeError(errorp);
2N/A *errorp = NULL;
2N/A rc = NS_LDAP_SUCCESS;
2N/A }
2N/A
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A return_rc = rc;
2N/A new_state = W_ERROR;
2N/A break;
2N/A }
2N/A if (followRef)
2N/A new_state = SELECT_OPERATION_ASYNC;
2N/A else
2N/A new_state = SELECT_OPERATION_SYNC;
2N/A break;
2N/A case SELECT_OPERATION_SYNC:
2N/A if (ldap_op == LDAP_REQ_ADD)
2N/A new_state = DO_ADD_SYNC;
2N/A else if (ldap_op == LDAP_REQ_DELETE)
2N/A new_state = DO_DELETE_SYNC;
2N/A else if (ldap_op == LDAP_REQ_MODIFY)
2N/A new_state = DO_MODIFY_SYNC;
2N/A break;
2N/A case SELECT_OPERATION_ASYNC:
2N/A if (ldap_op == LDAP_REQ_ADD)
2N/A new_state = DO_ADD_ASYNC;
2N/A else if (ldap_op == LDAP_REQ_DELETE)
2N/A new_state = DO_DELETE_ASYNC;
2N/A else if (ldap_op == LDAP_REQ_MODIFY)
2N/A new_state = DO_MODIFY_ASYNC;
2N/A break;
2N/A case DO_ADD_SYNC:
2N/A rc = ldap_add_ext_s(conp->ld, target_dn,
2N/A mods, NULL, NULL);
2N/A new_state = GET_RESULT_SYNC;
2N/A break;
2N/A case DO_DELETE_SYNC:
2N/A rc = ldap_delete_ext_s(conp->ld, target_dn,
2N/A NULL, NULL);
2N/A new_state = GET_RESULT_SYNC;
2N/A break;
2N/A case DO_MODIFY_SYNC:
2N/A rc = ldap_modify_ext_s(conp->ld, target_dn,
2N/A mods, NULL, NULL);
2N/A new_state = GET_RESULT_SYNC;
2N/A break;
2N/A case DO_ADD_ASYNC:
2N/A rc = ldap_add_ext(conp->ld, target_dn,
2N/A mods, NULL, NULL, &msgid);
2N/A new_state = GET_RESULT_ASYNC;
2N/A break;
2N/A case DO_DELETE_ASYNC:
2N/A rc = ldap_delete_ext(conp->ld, target_dn,
2N/A NULL, NULL, &msgid);
2N/A new_state = GET_RESULT_ASYNC;
2N/A break;
2N/A case DO_MODIFY_ASYNC:
2N/A rc = ldap_modify_ext(conp->ld, target_dn,
2N/A mods, NULL, NULL, &msgid);
2N/A new_state = GET_RESULT_ASYNC;
2N/A break;
2N/A case GET_RESULT_SYNC:
2N/A if (rc != LDAP_SUCCESS) {
2N/A if (ref_info != NULL &&
2N/A ref_info->next != NULL &&
2N/A (rc == LDAP_BUSY ||
2N/A rc == LDAP_UNAVAILABLE ||
2N/A rc == LDAP_UNWILLING_TO_PERFORM ||
2N/A rc == LDAP_CONNECT_ERROR ||
2N/A rc == LDAP_SERVER_DOWN ||
2N/A rc == LDAP_REFERRAL ||
2N/A rc == LDAP_TIMEOUT)) {
2N/A /* Try the next refered server */
2N/A new_state = GET_REFERRAL_CONNECTION;
2N/A break;
2N/A }
2N/A Errno = rc;
2N/A (void) ldap_get_lderrno(conp->ld,
2N/A NULL, &errmsg);
2N/A /*
2N/A * No need to deal with the error message if
2N/A * it's an empty string.
2N/A */
2N/A if (errmsg != NULL && *errmsg == '\0')
2N/A errmsg = NULL;
2N/A
2N/A if (errmsg != NULL) {
2N/A /*
2N/A * ldap_get_lderrno does not expect
2N/A * errmsg to be freed after use, while
2N/A * ldap_parse_result below does, so set
2N/A * a flag to indicate source.
2N/A */
2N/A from_get_lderrno = B_TRUE;
2N/A }
2N/A
2N/A new_state = W_LDAP_ERROR;
2N/A } else {
2N/A return_rc = NS_LDAP_SUCCESS;
2N/A new_state = W_EXIT;
2N/A }
2N/A break;
2N/A case GET_RESULT_ASYNC:
2N/A rc = ldap_result(conp->ld, msgid, 1,
2N/A (struct timeval *)NULL, &res);
2N/A /* if no server response, set Errno */
2N/A if (rc == -1) {
2N/A (void) ldap_get_option(conp->ld,
2N/A LDAP_OPT_ERROR_NUMBER, &Errno);
2N/A new_state = W_LDAP_ERROR;
2N/A break;
2N/A }
2N/A if (rc == LDAP_RES_ADD || rc == LDAP_RES_MODIFY ||
2N/A rc == LDAP_RES_DELETE) {
2N/A new_state = PARSE_RESULT;
2N/A break;
2N/A } else {
2N/A return_rc = rc;
2N/A new_state = W_ERROR;
2N/A }
2N/A break;
2N/A case PARSE_RESULT:
2N/A /*
2N/A * need Errno, referrals, error msg,
2N/A * and the last "1" is to free
2N/A * the result (res)
2N/A */
2N/A rc = ldap_parse_result(conp->ld, res, &Errno,
2N/A NULL, &errmsg, &referrals, NULL, 1);
2N/A /*
2N/A * free errmsg if it is an empty string
2N/A */
2N/A if (errmsg && *errmsg == '\0') {
2N/A ldap_memfree(errmsg);
2N/A errmsg = NULL;
2N/A }
2N/A /*
2N/A * If we received referral data, process
2N/A * it if:
2N/A * - we are configured to follow referrals
2N/A * - and not already in referral mode (to keep
2N/A * consistency with search_state_machine()
2N/A * which follows 1 level of referrals only;
2N/A * see proc_result_referrals() and
2N/A * proc_search_references().
2N/A */
2N/A if (Errno == LDAP_REFERRAL && followRef &&
2N/A referral_list == NULL) {
2N/A /* add to referral list */
2N/A rc = __s_api_addReferral(&referral_list,
2N/A referrals, NULL, NULL, NULL,
2N/A conp->ld);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_api_deleteReferral(referral_list);
2N/A referral_list = NULL;
2N/A }
2N/A ldap_value_free(referrals);
2N/A if (referral_list == NULL) {
2N/A if (rc != NS_LDAP_MEMORY)
2N/A rc = NS_LDAP_INTERNAL;
2N/A return_rc = rc;
2N/A new_state = W_ERROR;
2N/A } else {
2N/A new_state = GET_REFERRAL_CONNECTION;
2N/A }
2N/A if (errmsg) {
2N/A ldap_memfree(errmsg);
2N/A errmsg = NULL;
2N/A }
2N/A break;
2N/A }
2N/A if (Errno != LDAP_SUCCESS) {
2N/A new_state = W_LDAP_ERROR;
2N/A } else {
2N/A return_rc = NS_LDAP_SUCCESS;
2N/A new_state = W_EXIT;
2N/A }
2N/A break;
2N/A case GET_REFERRAL_CONNECTION:
2N/A /*
2N/A * since we are starting over,
2N/A * discard the old error info
2N/A */
2N/A return_rc = NS_LDAP_SUCCESS;
2N/A if (*errorp)
2N/A (void) __ns_ldap_freeError(errorp);
2N/A if (connectionId > -1)
2N/A DropConnection(connectionId, NS_LDAP_NEW_CONN);
2N/A
2N/A /* set it up to use a referral connection */
2N/A if (conn_user != NULL) {
2N/A /*
2N/A * If an MT connection is being used,
2N/A * return it to the pool.
2N/A */
2N/A if (conn_user->conn_mt != NULL)
2N/A __s_api_conn_mt_return(conn_user);
2N/A
2N/A conn_user->referral = B_TRUE;
2N/A }
2N/A
2N/A /* Find a referral ref that works */
2N/A if (ref_info == NULL)
2N/A ref_info = referral_list->ref;
2N/A else
2N/A ref_info = ref_info->next;
2N/A
2N/A rc = __s_api_getConnection(ref_info->refHost,
2N/A 0, cred, &connectionId, &conp, errorp,
2N/A do_not_fail_if_new_pwd_reqd,
2N/A nopasswd_acct_mgmt, conn_user);
2N/A
2N/A /*
2N/A * If password control attached
2N/A * in errorp,
2N/A * e.g. rc == NS_LDAP_SUCCESS_WITH_INFO,
2N/A * free the error structure (we do not need
2N/A * the password management info).
2N/A * Reset rc to NS_LDAP_SUCCESS.
2N/A */
2N/A if (rc == NS_LDAP_SUCCESS_WITH_INFO) {
2N/A (void) __ns_ldap_freeError(errorp);
2N/A *errorp = NULL;
2N/A rc = NS_LDAP_SUCCESS;
2N/A }
2N/A
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A return_rc = rc;
2N/A /*
2N/A * If current referral is not
2N/A * available for some reason,
2N/A * try next server in the ref_info list.
2N/A * Get LDAP error code from errorp.
2N/A */
2N/A if (*errorp != NULL) {
2N/A ns_write_state_t get_ref =
2N/A GET_REFERRAL_CONNECTION;
2N/A
2N/A ldap_error = (*errorp)->status;
2N/A if (ldap_error == LDAP_BUSY ||
2N/A ldap_error == LDAP_UNAVAILABLE ||
2N/A ldap_error ==
2N/A LDAP_UNWILLING_TO_PERFORM ||
2N/A ldap_error == LDAP_CONNECT_ERROR ||
2N/A ldap_error == LDAP_SERVER_DOWN) {
2N/A if (ref_info->next == NULL) {
2N/A /*
2N/A * no more ref_info to
2N/A * follow
2N/A */
2N/A new_state = W_ERROR;
2N/A } else
2N/A new_state = get_ref;
2N/A /*
2N/A * free errorp before going to
2N/A * next ref_info
2N/A */
2N/A (void) __ns_ldap_freeError(
2N/A errorp);
2N/A *errorp = NULL;
2N/A break;
2N/A }
2N/A /*
2N/A * free errorp before going to W_ERROR
2N/A */
2N/A (void) __ns_ldap_freeError(errorp);
2N/A *errorp = NULL;
2N/A }
2N/A /* else, exit */
2N/A __s_api_deleteReferral(referral_list);
2N/A referral_list = NULL;
2N/A new_state = W_ERROR;
2N/A if (conn_user != NULL)
2N/A conn_user->referral = B_FALSE;
2N/A break;
2N/A }
2N/A /* target DN may changed due to referrals */
2N/A if (ref_info->refDN) {
2N/A if (target_dn && target_dn_allocated) {
2N/A free(target_dn);
2N/A target_dn = NULL;
2N/A target_dn_allocated = FALSE;
2N/A }
2N/A target_dn = ref_info->refDN;
2N/A }
2N/A new_state = SELECT_OPERATION_SYNC;
2N/A break;
2N/A case W_LDAP_ERROR:
2N/A /*
2N/A * map error code and error message
2N/A * to password status if necessary.
2N/A * This is to see if password updates
2N/A * failed due to password policy or
2N/A * password syntax checking.
2N/A */
2N/A if (errmsg) {
2N/A /*
2N/A * check if server supports
2N/A * password management
2N/A */
2N/A passwd_mgmt =
2N/A __s_api_contain_passwd_control_oid(
2N/A conp->controls);
2N/A if (passwd_mgmt)
2N/A pwd_status =
2N/A __s_api_set_passwd_status(
2N/A Errno, errmsg);
2N/A /*
2N/A * free only if not returned by ldap_get_lderrno
2N/A */
2N/A if (!from_get_lderrno)
2N/A ldap_memfree(errmsg);
2N/A errmsg = NULL;
2N/A from_get_lderrno = B_FALSE;
2N/A }
2N/A
2N/A (void) snprintf(errstr, sizeof (errstr),
2N/A "%s", ldap_err2string(Errno));
2N/A err = strdup(errstr);
2N/A if (pwd_status != NS_PASSWD_GOOD) {
2N/A MKERROR_PWD_MGMT(*errorp, Errno, err,
2N/A pwd_status, 0, NULL);
2N/A } else {
2N/A MKERROR(LOG_INFO, *errorp, Errno, err, NULL);
2N/A }
2N/A if (conn_user != NULL &&
2N/A (Errno == LDAP_SERVER_DOWN ||
2N/A Errno == LDAP_CONNECT_ERROR)) {
2N/A __s_api_conn_mt_close(conn_user, Errno, errorp);
2N/A }
2N/A return_rc = NS_LDAP_INTERNAL;
2N/A new_state = W_EXIT;
2N/A break;
2N/A case W_ERROR:
2N/A default:
2N/A (void) sprintf(errstr,
2N/A gettext("Internal write State machine exit"
2N/A " (state = %d, rc = %d)."),
2N/A err_state, return_rc);
2N/A err = strdup(errstr);
2N/A MKERROR(LOG_WARNING, *errorp, return_rc, err, NULL);
2N/A new_state = W_EXIT;
2N/A break;
2N/A }
2N/A
2N/A if (new_state == W_ERROR)
2N/A err_state = state;
2N/A
2N/A if (conn_user != NULL && conn_user->bad_mt_conn == B_TRUE) {
2N/A __s_api_conn_mt_close(conn_user, 0, NULL);
2N/A new_state = W_EXIT;
2N/A }
2N/A
2N/A state = new_state;
2N/A }
2N/A
2N/A /*
2N/A * should never be here, the next line is to eliminating
2N/A * lint message
2N/A */
2N/A return (NS_LDAP_INTERNAL);
2N/A}
2N/A
2N/Astatic int
2N/Ado_cachemgr_operation(const char *dn, ns_ldap_attr_t **attr,
2N/A ns_ldap_error_t ** errorp, int opcode, ldap_service_t svc)
2N/A{
2N/A boolean_t priv;
2N/A boolean_t shadow_update_enabled = B_FALSE;
2N/A
2N/A /* Shadow update enabled ? If not, error out */
2N/A shadow_update_enabled = __ns_ldap_is_shadow_update_enabled();
2N/A if (!shadow_update_enabled) {
2N/A *errorp = __s_api_make_error(NS_CONFIG_NOTALLOW,
2N/A gettext("Shadow Update is not enabled"));
2N/A return (NS_LDAP_CONFIG);
2N/A }
2N/A
2N/A /* privileged modify requires euid 0 or all zone privs */
2N/A priv = (geteuid() == 0);
2N/A if (!priv) {
2N/A priv_set_t *ps = priv_allocset(); /* caller */
2N/A priv_set_t *zs; /* zone */
2N/A
2N/A (void) getppriv(PRIV_EFFECTIVE, ps);
2N/A zs = priv_str_to_set("zone", ",", NULL);
2N/A priv = priv_isequalset(ps, zs);
2N/A priv_freeset(ps);
2N/A priv_freeset(zs);
2N/A }
2N/A
2N/A if (!priv)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A return (send_to_cachemgr(dn, attr, errorp, opcode, svc));
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/A__ns_ldap_addAttr(
2N/A const char *service,
2N/A const char *dn,
2N/A const ns_ldap_attr_t * const *attr,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A LDAPMod **mods;
2N/A int rc = 0;
2N/A
2N/A#ifdef DEBUG
2N/A (void) fprintf(stderr, "__ns_ldap_addAttr START\n");
2N/A#endif
2N/A *errorp = NULL;
2N/A
2N/A /* Sanity check */
2N/A if ((attr == NULL) || (*attr == NULL) || (dn == NULL))
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /* Privileged modify? */
2N/A if (privileged_operation_check(flags, service)) {
2N/A rc = do_cachemgr_operation(dn, (ns_ldap_attr_t **)attr, errorp,
2N/A ADMINMODIFY_ADD, map_service_to_type(service));
2N/A return (rc);
2N/A }
2N/A
2N/A if (cred == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /*
2N/A * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be
2N/A * ldap_cachemgr. We need to get the admin cred to do work.
2N/A * If the caller is not ldap_cachemgr, but use the service
2N/A * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail,
2N/A * as the admin cred is not available to the caller.
2N/A */
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) !=
2N/A NS_LDAP_SUCCESS)
2N/A return (rc);
2N/A }
2N/A
2N/A mods = __s_api_makeModList(service, attr, LDAP_MOD_ADD, flags);
2N/A if (mods == NULL) {
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = write_state_machine(LDAP_REQ_MODIFY,
2N/A (char *)dn, mods, cred, flags, errorp);
2N/A freeModList(mods);
2N/A
2N/A return (rc);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/A__ns_ldap_delAttr(
2N/A const char *service,
2N/A const char *dn,
2N/A const ns_ldap_attr_t * const *attr,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A LDAPMod **mods;
2N/A int rc = 0;
2N/A
2N/A#ifdef DEBUG
2N/A (void) fprintf(stderr, "__ns_ldap_delAttr START\n");
2N/A#endif
2N/A *errorp = NULL;
2N/A
2N/A /* Sanity check */
2N/A if ((attr == NULL) || (*attr == NULL) || (dn == NULL))
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /* Privileged modify? */
2N/A if (privileged_operation_check(flags, service)) {
2N/A rc = do_cachemgr_operation(dn, (ns_ldap_attr_t **)attr, errorp,
2N/A ADMINMODIFY_DEL, map_service_to_type(service));
2N/A return (rc);
2N/A }
2N/A
2N/A if (cred == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /*
2N/A * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be
2N/A * ldap_cachemgr. We need to get the admin cred to do work.
2N/A * If the caller is not ldap_cachemgr, but use the service
2N/A * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail,
2N/A * as the admin cred is not available to the caller.
2N/A */
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) !=
2N/A NS_LDAP_SUCCESS)
2N/A return (rc);
2N/A }
2N/A
2N/A mods = __s_api_makeModList(service, attr, LDAP_MOD_DELETE, flags);
2N/A if (mods == NULL) {
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = write_state_machine(LDAP_REQ_MODIFY,
2N/A (char *)dn, mods, cred, flags, errorp);
2N/A
2N/A freeModList(mods);
2N/A return (rc);
2N/A}
2N/A
2N/A/* Retrieve the admin bind password from the configuration, if allowed. */
2N/Astatic int
2N/Aget_admin_passwd(ns_cred_t *cred, ns_ldap_error_t **errorp)
2N/A{
2N/A void **paramVal = NULL;
2N/A int rc, ldaprc;
2N/A char *modparamVal = NULL;
2N/A
2N/A /*
2N/A * For GSSAPI/Kerberos, host credential is used, no need to get
2N/A * admin bind password
2N/A */
2N/A if (cred->auth.saslmech == NS_LDAP_SASL_GSSAPI)
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A /*
2N/A * Retrieve admin bind password.
2N/A * The admin bind password is available
2N/A * only in the ldap_cachemgr process as
2N/A * they are not exposed outside of that
2N/A * process.
2N/A */
2N/A paramVal = NULL;
2N/A if ((ldaprc = __ns_ldap_getParam(NS_LDAP_ADMIN_BINDPASSWD_P,
2N/A &paramVal, errorp)) != NS_LDAP_SUCCESS)
2N/A return (ldaprc);
2N/A if (paramVal == NULL || *paramVal == NULL) {
2N/A rc = NS_LDAP_CONFIG;
2N/A *errorp = __s_api_make_error(NS_CONFIG_NODEFAULT,
2N/A gettext("Admin bind password not configured"));
2N/A if (*errorp == NULL)
2N/A rc = NS_LDAP_MEMORY;
2N/A return (rc);
2N/A }
2N/A modparamVal = dvalue((char *)*paramVal);
2N/A (void) memset(*paramVal, 0, strlen((char *)*paramVal));
2N/A (void) __ns_ldap_freeParam(&paramVal);
2N/A if (modparamVal == NULL || *((char *)modparamVal) == '\0') {
2N/A if (modparamVal != NULL)
2N/A free(modparamVal);
2N/A rc = NS_LDAP_CONFIG;
2N/A *errorp = __s_api_make_error(NS_CONFIG_SYNTAX,
2N/A gettext("bind password not valid"));
2N/A if (*errorp == NULL)
2N/A rc = NS_LDAP_MEMORY;
2N/A return (rc);
2N/A }
2N/A
2N/A cred->cred.unix_cred.passwd = modparamVal;
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/Aboolean_t
2N/A__ns_ldap_is_shadow_update_enabled(void)
2N/A{
2N/A int **enable_shadow = NULL;
2N/A ns_ldap_error_t *errorp = NULL;
2N/A
2N/A if (__ns_ldap_getParam(NS_LDAP_ENABLE_SHADOW_UPDATE_P,
2N/A (void ***)&enable_shadow, &errorp) != NS_LDAP_SUCCESS) {
2N/A if (errorp)
2N/A (void) __ns_ldap_freeError(&errorp);
2N/A return (B_FALSE);
2N/A }
2N/A if ((enable_shadow != NULL && *enable_shadow != NULL) &&
2N/A (*enable_shadow[0] == NS_LDAP_ENABLE_SHADOW_UPDATE_TRUE)) {
2N/A (void) __ns_ldap_freeParam((void ***)&enable_shadow);
2N/A return (B_TRUE);
2N/A }
2N/A if (enable_shadow != NULL)
2N/A (void) __ns_ldap_freeParam((void ***)&enable_shadow);
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * __ns_ldap_repAttr modifies ldap attributes of the 'dn' entry stored
2N/A * on the LDAP server. 'service' indicates the type of database entries
2N/A * to modify. When the Native LDAP client is configured with 'shadow update
2N/A * enabled', RBAC related entries can only be modified by privileged users.
2N/A * Such users use the NS_LDAP_UPDATE_SHADOW flag to indicate the call is
2N/A * for such an update, which would be forwarded to ldap_cachemgr
2N/A * for performing the LDAP modify operation. ldap_cachemgr would call
2N/A * this function again and use the special service NS_ADMIN_SHADOW_UPDATE
2N/A * to identify itself, so that admin credential would be obtained and
2N/A * the actual LDAP modify operation be done.
2N/A */
2N/A/*ARGSUSED*/
2N/Aint
2N/A__ns_ldap_repAttr(
2N/A const char *service,
2N/A const char *dn,
2N/A const ns_ldap_attr_t * const *attr,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A LDAPMod **mods;
2N/A int rc = 0;
2N/A
2N/A#ifdef DEBUG
2N/A (void) fprintf(stderr, "__ns_ldap_repAttr START\n");
2N/A#endif
2N/A *errorp = NULL;
2N/A
2N/A /* Sanity check */
2N/A if (attr == NULL || *attr == NULL || dn == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /* Privileged modify? */
2N/A if (privileged_operation_check(flags, service)) {
2N/A rc = do_cachemgr_operation(dn, (ns_ldap_attr_t **)attr, errorp,
2N/A ADMINMODIFY_REP, map_service_to_type(service));
2N/A return (rc);
2N/A }
2N/A
2N/A if (cred == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /*
2N/A * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be
2N/A * ldap_cachemgr. We need to get the admin cred to do work.
2N/A * If the caller is not ldap_cachemgr, but use the service
2N/A * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail,
2N/A * as the admin cred is not available to the caller.
2N/A */
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) !=
2N/A NS_LDAP_SUCCESS)
2N/A return (rc);
2N/A }
2N/A
2N/A mods = __s_api_makeModList(service, attr, LDAP_MOD_REPLACE, flags);
2N/A if (mods == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A rc = write_state_machine(LDAP_REQ_MODIFY,
2N/A (char *)dn, mods, cred, flags, errorp);
2N/A
2N/A freeModList(mods);
2N/A return (rc);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/A__ns_ldap_addEntry(
2N/A const char *service,
2N/A const char *dn,
2N/A const ns_ldap_entry_t *entry,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A char *new_dn = NULL;
2N/A LDAPMod **mods = NULL;
2N/A const ns_ldap_attr_t * const *attr;
2N/A int rc = 0;
2N/A int nAttr = 0;
2N/A
2N/A#ifdef DEBUG
2N/A (void) fprintf(stderr, "__ns_ldap_addEntry START\n");
2N/A#endif
2N/A
2N/A if ((entry == NULL) || (dn == NULL))
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A *errorp = NULL;
2N/A
2N/A attr = (const ns_ldap_attr_t * const *)(entry->attr_pair);
2N/A
2N/A /* Privileged modify? */
2N/A if (privileged_operation_check(flags, service)) {
2N/A rc = do_cachemgr_operation(dn, (ns_ldap_attr_t **)attr,
2N/A errorp, ADMIN_ADDENTRY, map_service_to_type(service));
2N/A return (rc);
2N/A }
2N/A
2N/A if (cred == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /*
2N/A * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be
2N/A * ldap_cachemgr. We need to get the admin cred to do work.
2N/A * If the caller is not ldap_cachemgr, but use the service
2N/A * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail,
2N/A * as the admin cred is not available to the caller.
2N/A */
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) !=
2N/A NS_LDAP_SUCCESS)
2N/A return (rc);
2N/A }
2N/A
2N/A /* Construct array of LDAPMod representing attributes of new entry. */
2N/A
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A mods = __s_api_makeModList(service, attr, LDAP_MOD_ADD, flags);
2N/A } else {
2N/A nAttr = entry->attr_count;
2N/A mods = __s_api_makeModListCount(service, attr, LDAP_MOD_ADD,
2N/A nAttr, flags);
2N/A }
2N/A if (mods == NULL) {
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = replace_mapped_attr_in_dn(service, dn, &new_dn);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A freeModList(mods);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = write_state_machine(LDAP_REQ_ADD,
2N/A new_dn ? new_dn : (char *)dn, mods, cred, flags, errorp);
2N/A
2N/A if (new_dn)
2N/A free(new_dn);
2N/A freeModList(mods);
2N/A return (rc);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/A__ns_ldap_delEntry(
2N/A const char *service,
2N/A const char *dn,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t ** errorp)
2N/A{
2N/A int rc;
2N/A
2N/A#ifdef DEBUG
2N/A (void) fprintf(stderr, "__ns_ldap_delEntry START\n");
2N/A#endif
2N/A if (dn == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A *errorp = NULL;
2N/A /* Privileged modify? */
2N/A if (privileged_operation_check(flags, service)) {
2N/A rc = do_cachemgr_operation(dn, NULL, errorp,
2N/A ADMIN_DELENTRY, map_service_to_type(service));
2N/A return (rc);
2N/A }
2N/A
2N/A if (cred == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A /*
2N/A * If service is NS_ADMIN_SHADOW_UPDATE, the caller should be
2N/A * ldap_cachemgr. We need to get the admin cred to do work.
2N/A * If the caller is not ldap_cachemgr, but use the service
2N/A * NS_ADMIN_SHADOW_UPDATE, get_admin_passwd() will fail,
2N/A * as the admin cred is not available to the caller.
2N/A */
2N/A if (strcmp(service, NS_ADMIN_SHADOW_UPDATE) == 0) {
2N/A if ((rc = get_admin_passwd((ns_cred_t *)cred, errorp)) !=
2N/A NS_LDAP_SUCCESS)
2N/A return (rc);
2N/A }
2N/A
2N/A rc = write_state_machine(LDAP_REQ_DELETE,
2N/A (char *)dn, NULL, cred, flags, errorp);
2N/A
2N/A return (rc);
2N/A}
2N/A
2N/A/*
2N/A * Add Typed Entry Helper routines
2N/A */
2N/A
2N/A/*
2N/A * Add Typed Entry Conversion routines
2N/A */
2N/A
2N/Astatic int
2N/A__s_add_attr(ns_ldap_entry_t *e, char *attrname, char *value)
2N/A{
2N/A ns_ldap_attr_t *a;
2N/A char *v;
2N/A
2N/A a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t));
2N/A if (a == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A a->attrname = strdup(attrname);
2N/A if (a->attrname == NULL) {
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A a->attrvalue = (char **)calloc(1, sizeof (char **));
2N/A if (a->attrvalue == NULL) {
2N/A free(a->attrname);
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A a->value_count = 1;
2N/A v = strdup(value);
2N/A if (v == NULL) {
2N/A free(a->attrname);
2N/A free(a->attrvalue);
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A a->attrvalue[0] = v;
2N/A e->attr_pair[e->attr_count] = a;
2N/A e->attr_count++;
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/Astatic int
2N/A__s_add_attrlist(ns_ldap_entry_t *e, char *attrname, char **argv)
2N/A{
2N/A ns_ldap_attr_t *a;
2N/A char *v;
2N/A char **av;
2N/A int i, j;
2N/A
2N/A a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t));
2N/A if (a == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A a->attrname = strdup(attrname);
2N/A if (a->attrname == NULL) {
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A for (i = 0, av = argv; *av != NULL; av++, i++)
2N/A ;
2N/A
2N/A a->attrvalue = (char **)calloc(i, sizeof (char *));
2N/A
2N/A if (a->attrvalue == NULL) {
2N/A free(a->attrname);
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A a->value_count = i;
2N/A for (j = 0; j < i; j++) {
2N/A v = strdup(argv[j]);
2N/A if (v == NULL) {
2N/A free(a->attrname);
2N/A for (i = 0; i < j; i++)
2N/A free(a->attrvalue[i]);
2N/A free(a->attrvalue);
2N/A free(a);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A a->attrvalue[j] = v;
2N/A }
2N/A e->attr_pair[e->attr_count] = a;
2N/A e->attr_count++;
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/Astatic ns_ldap_entry_t *
2N/A__s_mk_entry(char **objclass, int max_attr)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A e = (ns_ldap_entry_t *)calloc(1, sizeof (ns_ldap_entry_t));
2N/A if (e == NULL)
2N/A return (NULL);
2N/A /* allocate attributes, +1 for objectclass, +1 for NULL terminator */
2N/A e->attr_pair = (ns_ldap_attr_t **)
2N/A calloc(max_attr + 2, sizeof (ns_ldap_attr_t *));
2N/A if (e->attr_pair == NULL) {
2N/A free(e);
2N/A return (NULL);
2N/A }
2N/A e->attr_count = 0;
2N/A if (__s_add_attrlist(e, "objectClass", objclass) != NS_LDAP_SUCCESS) {
2N/A free(e->attr_pair);
2N/A free(e);
2N/A return (NULL);
2N/A }
2N/A return (e);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Conversion: passwd
2N/A * Input format: struct passwd
2N/A * Exported objectclass: posixAccount
2N/A */
2N/Astatic int
2N/A__s_cvt_passwd(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct passwd *ptr;
2N/A int max_attr = 9;
2N/A char ibuf[10];
2N/A static char *oclist[] = {
2N/A "posixAccount",
2N/A "shadowAccount",
2N/A "account",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct passwd *)data;
2N/A
2N/A if (ptr->pw_name == NULL || ptr->pw_uid > MAXUID ||
2N/A ptr->pw_gid > MAXUID || ptr->pw_dir == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->pw_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A rc = __s_add_attr(e, "uid", ptr->pw_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A rc = __s_add_attr(e, "cn", ptr->pw_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->pw_passwd != NULL &&
2N/A ptr->pw_passwd[0] != '\0') {
2N/A rc = __s_add_attr(e, "userPassword", ptr->pw_passwd);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%u", ptr->pw_uid);
2N/A rc = __s_add_attr(e, "uidNumber", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%u", ptr->pw_gid);
2N/A rc = __s_add_attr(e, "gidNumber", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A if (ptr->pw_gecos != NULL &&
2N/A ptr->pw_gecos[0] != '\0') {
2N/A rc = __s_add_attr(e, "gecos", ptr->pw_gecos);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "homeDirectory", ptr->pw_dir);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A if (ptr->pw_shell != NULL &&
2N/A ptr->pw_shell[0] != '\0') {
2N/A rc = __s_add_attr(e, "loginShell", ptr->pw_shell);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * escape_str function escapes special characters in str and
2N/A * copies to escstr string.
2N/A *
2N/A * return 0 for successful
2N/A * 1 for fail
2N/A */
2N/Astatic int escape_str(char *escstr, char *str)
2N/A{
2N/A int index = 0;
2N/A
2N/A while ((*str != '\0') && (index < (RDNSIZE - 1))) {
2N/A if (*str == '+' || *str == ';' || *str == '>' ||
2N/A *str == '<' || *str == ',' || *str == '"' ||
2N/A *str == '\\' || *str == '=' ||
2N/A (*str == '#' && index == 0)) {
2N/A *escstr++ = '\\';
2N/A *escstr++ = *str++;
2N/A index += 2;
2N/A } else {
2N/A *escstr++ = *str++;
2N/A index++;
2N/A }
2N/A }
2N/A
2N/A if (*str == '\0') {
2N/A *escstr = '\0';
2N/A return (0);
2N/A } else {
2N/A return (1);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Conversion: project
2N/A * Input format: struct project
2N/A * Exported objectclass: SolarisProject
2N/A */
2N/Astatic int
2N/A__s_cvt_project(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A
2N/A /* routine specific */
2N/A struct project *ptr;
2N/A int max_attr = 9;
2N/A char ibuf[11];
2N/A static char *oclist[] = {
2N/A "SolarisProject",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct project *)data;
2N/A
2N/A if (ptr->pj_name == NULL || ptr->pj_projid > MAXUID) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "SolarisProjectName=%s", ptr->pj_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A
2N/A /* Project name */
2N/A rc = __s_add_attr(e, "SolarisProjectName", ptr->pj_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A /*
2N/A * Project ID:
2N/A * ibuf is 11 chars big, which should be enough for string
2N/A * representation of 32bit number + nul-car
2N/A */
2N/A if (snprintf(ibuf, sizeof (ibuf), "%u", ptr->pj_projid) < 0) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A rc = __s_add_attr(e, "SolarisProjectID", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A /* Comment/Description */
2N/A if (ptr->pj_comment != NULL && ptr->pj_comment[0] != '\0') {
2N/A rc = __s_add_attr(e, "description", ptr->pj_comment);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Attributes */
2N/A if (ptr->pj_attr != NULL && ptr->pj_attr[0] != '\0') {
2N/A rc = __s_add_attr(e, "SolarisProjectAttr", ptr->pj_attr);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Users */
2N/A if (ptr->pj_users != NULL) {
2N/A rc = __s_add_attrlist(e, "memberUid", ptr->pj_users);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Groups */
2N/A if (ptr->pj_groups != NULL) {
2N/A rc = __s_add_attrlist(e, "memberGid", ptr->pj_groups);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: shadow
2N/A * Input format: struct shadow
2N/A * Exported objectclass: shadowAccount
2N/A */
2N/Astatic int
2N/A__s_cvt_shadow(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct spwd *ptr;
2N/A int max_attr = 10;
2N/A char ibuf[10];
2N/A static char *oclist[] = {
2N/A "posixAccount",
2N/A "shadowAccount",
2N/A "account",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct spwd *)data;
2N/A
2N/A if (ptr->sp_namp == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->sp_namp);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A rc = __s_add_attr(e, "uid", ptr->sp_namp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->sp_pwdp == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A } else {
2N/A rc = __s_add_attr(e, "userPassword", ptr->sp_pwdp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->sp_lstchg >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_lstchg);
2N/A rc = __s_add_attr(e, "shadowLastChange", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->sp_min >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_min);
2N/A rc = __s_add_attr(e, "shadowMin", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->sp_max >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_max);
2N/A rc = __s_add_attr(e, "shadowMax", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->sp_warn >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_warn);
2N/A rc = __s_add_attr(e, "shadowWarning", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->sp_inact >= -1) {
2N/A if (ptr->sp_inact >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_inact);
2N/A } else {
2N/A ibuf[0] = '\0';
2N/A }
2N/A rc = __s_add_attr(e, "shadowInactive", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->sp_expire >= -1) {
2N/A if (ptr->sp_expire >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->sp_expire);
2N/A } else {
2N/A ibuf[0] = '\0';
2N/A }
2N/A rc = __s_add_attr(e, "shadowExpire", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%d", ptr->sp_flag);
2N/A rc = __s_add_attr(e, "shadowFlag", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Conversion: group
2N/A * Input format: struct group
2N/A * Exported objectclass: posixGroup
2N/A */
2N/Astatic int
2N/A__s_cvt_group(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct group *ptr;
2N/A int i, j, k;
2N/A char **nm, **lm;
2N/A int max_attr = 4;
2N/A char ibuf[10];
2N/A static char *oclist[] = {
2N/A "posixGroup",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct group *)data;
2N/A
2N/A if (ptr->gr_name == NULL || ptr->gr_gid > MAXUID) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->gr_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A rc = __s_add_attr(e, "cn", ptr->gr_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%u", ptr->gr_gid);
2N/A rc = __s_add_attr(e, "gidNumber", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A if (ptr->gr_passwd && ptr->gr_passwd[0] != '\0') {
2N/A rc = __s_add_attr(e, "userPassword", ptr->gr_passwd);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->gr_mem && ptr->gr_mem[0]) {
2N/A lm = ptr->gr_mem;
2N/A for (i = 0; *lm; i++, lm++)
2N/A ;
2N/A lm = ptr->gr_mem;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++) {
2N/A nm[j] = strdup(lm[j]);
2N/A if (nm[j] == NULL) {
2N/A for (k = 0; k < j; k++)
2N/A free(nm[k]);
2N/A free(nm);
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A }
2N/A rc = __s_add_attrlist(e, "memberUid", nm);
2N/A for (j = 0; j < i; j++) {
2N/A free(nm[j]);
2N/A }
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * Conversion: hosts
2N/A * Input format: struct hostent
2N/A * Exported objectclass: ipHost
2N/A */
2N/Astatic int
2N/A__s_cvt_hosts(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct hostent *ptr;
2N/A int max_attr = 6;
2N/A int i, j, k;
2N/A char **nm, **lm;
2N/A static char *oclist[] = {
2N/A "ipHost",
2N/A "device",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct hostent *)data;
2N/A
2N/A if (ptr->h_name == NULL ||
2N/A ptr->h_addr_list == NULL || ptr->h_addr_list[0] == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s+ipHostNumber=%s",
2N/A ptr->h_name, ptr->h_addr_list[0]);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->h_aliases && ptr->h_aliases[0]) {
2N/A lm = ptr->h_aliases;
2N/A /*
2N/A * If there is a description, 'i' will contain
2N/A * the index of the description in the aliases list
2N/A */
2N/A for (i = 0; *lm && (*lm)[0] != '#'; i++, lm++)
2N/A ;
2N/A lm = ptr->h_aliases;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A nm[0] = ptr->h_name;
2N/A for (j = 0; j < i; j++)
2N/A nm[j+1] = ptr->h_aliases[j];
2N/A
2N/A rc = __s_add_attrlist(e, "cn", nm);
2N/A
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A free(nm);
2N/A return (rc);
2N/A }
2N/A
2N/A if (lm[i] && lm[i][0] == '#') {
2N/A nm[0] = &(lm[i][1]);
2N/A nm[1] = NULL;
2N/A rc = __s_add_attrlist(e, "description", nm);
2N/A }
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A rc = __s_add_attr(e, "cn", ptr->h_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->h_addr_list && ptr->h_addr_list[0]) {
2N/A lm = ptr->h_addr_list;
2N/A for (i = 0; *lm; i++, lm++)
2N/A ;
2N/A lm = ptr->h_addr_list;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++) {
2N/A nm[j] = strdup(lm[j]);
2N/A if (nm[j] == NULL) {
2N/A for (k = 0; k < j; k++)
2N/A free(nm[k]);
2N/A free(nm);
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A }
2N/A rc = __s_add_attrlist(e, "ipHostNumber", nm);
2N/A for (j = 0; j < i; j++) {
2N/A free(nm[j]);
2N/A }
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * Conversion: rpc
2N/A * Input format: struct rpcent
2N/A * Exported objectclass: oncRpc
2N/A */
2N/Astatic int
2N/A__s_cvt_rpc(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct rpcent *ptr;
2N/A int max_attr = 3;
2N/A int i, j;
2N/A char **nm;
2N/A char ibuf[10];
2N/A static char *oclist[] = {
2N/A "oncRpc",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct rpcent *)data;
2N/A
2N/A if (ptr->r_name == NULL || ptr->r_number < 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->r_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->r_aliases && ptr->r_aliases[0]) {
2N/A nm = ptr->r_aliases;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A nm[0] = ptr->r_name;
2N/A for (j = 0; j < i; j++)
2N/A nm[j+1] = ptr->r_aliases[j];
2N/A
2N/A rc = __s_add_attrlist(e, "cn", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A rc = __s_add_attr(e, "cn", ptr->r_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->r_number >= 0) {
2N/A (void) sprintf(ibuf, "%d", ptr->r_number);
2N/A rc = __s_add_attr(e, "oncRpcNumber", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A
2N/A/*
2N/A * Conversion: protocols
2N/A * Input format: struct protoent
2N/A * Exported objectclass: ipProtocol
2N/A */
2N/Astatic int
2N/A__s_cvt_protocols(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct protoent *ptr;
2N/A int max_attr = 3;
2N/A int i, j;
2N/A char ibuf[10];
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "ipProtocol",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct protoent *)data;
2N/A
2N/A if (ptr->p_name == NULL || ptr->p_proto < 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->p_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->p_aliases && ptr->p_aliases[0]) {
2N/A nm = ptr->p_aliases;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A nm[0] = ptr->p_name;
2N/A for (j = 0; j < i; j++)
2N/A nm[j+1] = ptr->p_aliases[j];
2N/A
2N/A rc = __s_add_attrlist(e, "cn", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A rc = __s_add_attr(e, "cn", ptr->p_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%d", ptr->p_proto);
2N/A rc = __s_add_attr(e, "ipProtocolNumber", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A
2N/A/*
2N/A * Conversion: services
2N/A * Input format: struct servent
2N/A * Exported objectclass: ipService
2N/A */
2N/Astatic int
2N/A__s_cvt_services(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A char esc_str[RDNSIZE];
2N/A /* routine specific */
2N/A struct servent *ptr;
2N/A int max_attr = 4;
2N/A int i, j;
2N/A char ibuf[10];
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "ipService",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct servent *)data;
2N/A
2N/A if (ptr->s_name == NULL || ptr->s_port < 0 || ptr->s_proto == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /*
2N/A * Escape special characters in service name.
2N/A */
2N/A if (escape_str(esc_str, ptr->s_name) != 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s+ipServiceProtocol=%s",
2N/A esc_str, ptr->s_proto);
2N/A
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->s_aliases && ptr->s_aliases[0]) {
2N/A nm = ptr->s_aliases;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A nm[0] = ptr->s_name;
2N/A for (j = 0; j < i; j++)
2N/A nm[j+1] = ptr->s_aliases[j];
2N/A
2N/A rc = __s_add_attrlist(e, "cn", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A rc = __s_add_attr(e, "cn", ptr->s_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A (void) sprintf(ibuf, "%d", ptr->s_port);
2N/A rc = __s_add_attr(e, "ipServicePort", ibuf);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A rc = __s_add_attr(e, "ipServiceProtocol", ptr->s_proto);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * Conversion: networks
2N/A * Input format: struct netent
2N/A * Exported objectclass: ipNetwork
2N/A */
2N/Astatic int
2N/A__s_cvt_networks(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct netent *ptr;
2N/A int max_attr = 4;
2N/A int i, j;
2N/A char cp[64];
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "ipNetwork",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct netent *)data;
2N/A
2N/A if (ptr->n_name == NULL || ptr->n_net == 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A (void) snprintf(cp, sizeof (cp), "%d.%d.%d.%d",
2N/A (ptr->n_net & 0xFF000000) >> 24,
2N/A (ptr->n_net & 0x00FF0000) >> 16,
2N/A (ptr->n_net & 0x0000FF00) >> 8,
2N/A (ptr->n_net & 0x000000FF));
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", cp);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->n_aliases && ptr->n_aliases[0]) {
2N/A nm = ptr->n_aliases;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A nm[0] = ptr->n_name;
2N/A for (j = 0; j < i; j++)
2N/A nm[j+1] = ptr->n_aliases[j];
2N/A
2N/A rc = __s_add_attrlist(e, "cn", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A } else {
2N/A rc = __s_add_attr(e, "cn", ptr->n_name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "ipNetworkNumber", cp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A/*
2N/A * Conversion: netmasks
2N/A * Input format: struct _ns_netmasks
2N/A * Exported objectclass: ipNetwork
2N/A */
2N/Astatic int
2N/A__s_cvt_netmasks(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_netmasks *ptr;
2N/A int max_attr = 4;
2N/A static char *oclist[] = {
2N/A "ipNetwork",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_netmasks *)data;
2N/A
2N/A if (ptr->netnumber == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "ipNetworkNumber=%s", ptr->netnumber);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A rc = __s_add_attr(e, "ipNetworkNumber", ptr->netnumber);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->netmask != '\0') {
2N/A rc = __s_add_attr(e, "ipNetmaskNumber", ptr->netmask);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A/*
2N/A * Conversion: netgroups
2N/A * Input format: struct _ns_netgroups
2N/A * Exported objectclass: nisNetgroup
2N/A */
2N/Astatic int
2N/A__s_cvt_netgroups(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_netgroups *ptr;
2N/A int max_attr = 6;
2N/A int i, j;
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "nisNetgroup",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_netgroups *)data;
2N/A
2N/A if (ptr->name == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A if (ptr->name != '\0') {
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->triplet && ptr->triplet[0]) {
2N/A nm = ptr->triplet;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++)
2N/A nm[j] = ptr->triplet[j];
2N/A
2N/A rc = __s_add_attrlist(e, "nisNetgroupTriple", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A if (ptr->netgroup && ptr->netgroup[0]) {
2N/A nm = ptr->netgroup;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++)
2N/A nm[j] = ptr->netgroup[j];
2N/A
2N/A rc = __s_add_attrlist(e, "memberNisNetgroup", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: bootparams
2N/A * Input format: struct _ns_bootp
2N/A * Exported objectclass: bootableDevice, device
2N/A */
2N/Astatic int
2N/A__s_cvt_bootparams(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_bootp *ptr;
2N/A int max_attr = 4;
2N/A int i, j;
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "bootableDevice",
2N/A "device",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_bootp *)data;
2N/A
2N/A if (ptr->name == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A if (ptr->name != '\0') {
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->param && ptr->param[0]) {
2N/A nm = ptr->param;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++)
2N/A nm[j] = ptr->param[j];
2N/A
2N/A rc = __s_add_attrlist(e, "bootParameter", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A/*
2N/A * Conversion: ethers
2N/A * Input format: struct _ns_ethers
2N/A * Exported objectclass: ieee802Device, device
2N/A */
2N/Astatic int
2N/A__s_cvt_ethers(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_ethers *ptr;
2N/A int max_attr = 4;
2N/A static char *oclist[] = {
2N/A "ieee802Device",
2N/A "device",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_ethers *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->ether == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "macAddress", ptr->ether);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * This function is used when processing an ethers (objectclass: ieee802Device)
2N/A * or a bootparams (objectclass: bootableDevice) entry, and the entry is
2N/A * already found in LDAP. Since both ethers and bootparams share the same
2N/A * LDAP container, we want to check that the entry found in LDAP is:
2N/A * - either the same entry (same cn, same objectclass): we don't do anything
2N/A * in this case
2N/A * - or an entry which does not have the objectclass we are interesting in:
2N/A * in this case, we modify the existing entry by adding the relevant
2N/A * objectclass (ieee802Device or bootableDevice) and the relevant attribute(s)
2N/A * from the attribute list previously computing by the relevant conversion
2N/A * function.
2N/A * Note: from conversion functions __s_cvt_ethers() and __s_cvt_bootparams()
2N/A * we know that there is only 1 more attribute today to add (macAddress
2N/A * or bootParameter)
2N/A */
2N/A#define _MAX_ATTR_ETHBOOTP 2
2N/Astatic int
2N/Amodify_ethers_bootp(
2N/A const char *service,
2N/A const char *rdn,
2N/A const char *fulldn,
2N/A const ns_ldap_attr_t * const *attrlist,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t **errorp)
2N/A{
2N/A char filter[BUFSIZ];
2N/A ns_ldap_result_t *resultp;
2N/A int rc = 0;
2N/A int i;
2N/A ns_ldap_attr_t *new_attrlist[_MAX_ATTR_ETHBOOTP+1];
2N/A ns_ldap_attr_t new_attrlist0;
2N/A char *new_attrvalue0[1];
2N/A const ns_ldap_attr_t * const *aptr = attrlist;
2N/A ns_ldap_attr_t *aptr2;
2N/A ns_ldap_error_t *new_errorp = NULL;
2N/A
2N/A if (rdn == NULL || fulldn == NULL || attrlist == NULL ||
2N/A errorp == NULL || service == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A bzero(&new_attrlist, sizeof (new_attrlist));
2N/A bzero(&new_attrlist0, sizeof (new_attrlist0));
2N/A new_attrlist[0] = &new_attrlist0;
2N/A new_attrlist[0]->attrvalue = new_attrvalue0;
2N/A
2N/A new_attrlist[0]->attrname = "objectclass";
2N/A new_attrlist[0]->value_count = 1;
2N/A if (strcasecmp(service, "ethers") == NULL) {
2N/A (void) snprintf(&filter[0], sizeof (filter),
2N/A "(&(objectClass=ieee802Device)(%s))", rdn);
2N/A new_attrlist[0]->attrvalue[0] = "ieee802Device";
2N/A } else {
2N/A (void) snprintf(&filter[0], sizeof (filter),
2N/A "(&(objectClass=bootableDevice)(%s))", rdn);
2N/A new_attrlist[0]->attrvalue[0] = "bootableDevice";
2N/A }
2N/A
2N/A rc = __ns_ldap_list(service, filter, NULL, (const char **)NULL,
2N/A NULL, NS_LDAP_SCOPE_SUBTREE, &resultp, &new_errorp,
2N/A NULL, NULL);
2N/A
2N/A switch (rc) {
2N/A case NS_LDAP_SUCCESS:
2N/A /*
2N/A * entry already exists for this service
2N/A * return NS_LDAP_INTERNAL and do not modify the incoming errorp
2N/A */
2N/A rc = NS_LDAP_INTERNAL;
2N/A break;
2N/A case NS_LDAP_NOTFOUND:
2N/A /*
2N/A * entry not found with the given objectclasss but entry exists
2N/A * hence add the relevant attribute (macAddress or bootparams).
2N/A */
2N/A i = 1;
2N/A while (*aptr && (i < _MAX_ATTR_ETHBOOTP)) {
2N/A /* aptr2 needed here to avoid lint warning */
2N/A aptr2 = (ns_ldap_attr_t *)*aptr++;
2N/A if ((strcasecmp(aptr2->attrname, "cn") != 0) &&
2N/A (strcasecmp(aptr2->attrname,
2N/A "objectclass") != 0)) {
2N/A new_attrlist[i++] = (ns_ldap_attr_t *)aptr2;
2N/A }
2N/A }
2N/A
2N/A if (i != _MAX_ATTR_ETHBOOTP) {
2N/A /* we haven't found all expected attributes */
2N/A rc = NS_LDAP_OP_FAILED;
2N/A break;
2N/A }
2N/A
2N/A aptr = (const ns_ldap_attr_t * const *) new_attrlist;
2N/A /* clean errorp first */
2N/A (void) __ns_ldap_freeError(errorp);
2N/A rc = __ns_ldap_addAttr(service, fulldn, aptr, cred, flags,
2N/A errorp);
2N/A break;
2N/A default:
2N/A /*
2N/A * unexpected error happenned
2N/A * returning relevant error
2N/A */
2N/A (void) __ns_ldap_freeError(errorp);
2N/A *errorp = new_errorp;
2N/A break;
2N/A }
2N/A
2N/A return (rc);
2N/A}
2N/A
2N/A/*
2N/A * Conversion: publickey
2N/A * Input format: struct _ns_pubkey
2N/A * Exported objectclass: NisKeyObject
2N/A */
2N/Astatic int
2N/A__s_cvt_publickey(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_pubkey *ptr;
2N/A int max_attr = 3;
2N/A static char *oclist[] = {
2N/A "NisKeyObject",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_pubkey *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->pubkey == '\0' || ptr->privkey == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A if (ptr->hostcred == NS_HOSTCRED_FALSE)
2N/A (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name);
2N/A else
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A
2N/A rc = __s_add_attr(e, "nisPublickey", ptr->pubkey);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "nisSecretkey", ptr->privkey);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: aliases
2N/A * Input format: struct _ns_alias
2N/A * Exported objectclass: mailGroup
2N/A */
2N/Astatic int
2N/A__s_cvt_aliases(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_alias *ptr;
2N/A int max_attr = 4;
2N/A int i, j;
2N/A char **nm;
2N/A static char *oclist[] = {
2N/A "mailGroup",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_alias *)data;
2N/A
2N/A if (ptr->alias == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->alias);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A if (ptr->alias != '\0') {
2N/A rc = __s_add_attr(e, "mail", (char *)ptr->alias);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A /* Error check the data and add the attributes */
2N/A if (ptr->member && ptr->member[0]) {
2N/A nm = ptr->member;
2N/A for (i = 0; *nm; i++, nm++)
2N/A ;
2N/A nm = (char **)calloc(i+2, sizeof (char *));
2N/A if (nm == NULL) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A for (j = 0; j < i; j++)
2N/A nm[j] = ptr->member[j];
2N/A
2N/A rc = __s_add_attrlist(e, "mgrpRFC822MailMember", nm);
2N/A free(nm);
2N/A nm = NULL;
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A
2N/A}
2N/A/*
2N/A * Conversion: automount
2N/A * Input format: struct _ns_automount
2N/A * Exported objectclass: automount
2N/A */
2N/Astatic int
2N/A__s_cvt_auto_mount(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A struct _ns_automount *ptr;
2N/A int max_attr = 6;
2N/A void **paramVal = NULL;
2N/A char **mappedschema = NULL;
2N/A int version1 = 0;
2N/A static char *oclist[] = {
2N/A NULL,
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A /* determine profile version number */
2N/A rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, &paramVal, errorp);
2N/A if (paramVal && *paramVal &&
2N/A strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0)
2N/A version1 = 1;
2N/A if (paramVal)
2N/A (void) __ns_ldap_freeParam(&paramVal);
2N/A if (rc && errorp)
2N/A (void) __ns_ldap_freeError(errorp);
2N/A
2N/A /* use old schema for version 1 profiles */
2N/A if (version1)
2N/A oclist[0] = "nisObject";
2N/A else
2N/A oclist[0] = "automount";
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (struct _ns_automount *)data;
2N/A
2N/A if (ptr->key == NULL || ptr->value == '\0' || ptr->mapname == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, version1 ? "cn=%s" : "automountKey=%s",
2N/A ptr->key);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A if (ptr->key != '\0') {
2N/A rc = __s_add_attr(e, version1 ? "cn" : "automountKey",
2N/A (char *)ptr->key);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A rc = __s_add_attr(e, version1 ? "nisMapEntry" : "automountInformation",
2N/A (char *)ptr->value);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A /*
2N/A * even for version 2, if automount is mapped to nisObject we
2N/A * still need 'nisMapName' attribute
2N/A */
2N/A mappedschema = __ns_ldap_getMappedObjectClass("automount", "automount");
2N/A if (mappedschema && mappedschema[0] &&
2N/A strcasecmp(mappedschema[0], "nisObject") == 0)
2N/A version1 = 1;
2N/A if (mappedschema)
2N/A __s_api_free2dArray(mappedschema);
2N/A
2N/A if (version1) {
2N/A rc = __s_add_attr(e, "nisMapName", (char *)ptr->mapname);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: auth_attr
2N/A * Input format: authstr_t
2N/A * Exported objectclass: SolarisAuthAttr
2N/A */
2N/Astatic int
2N/A__s_cvt_authattr(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A authstr_t *ptr;
2N/A int max_attr = 6;
2N/A static char *oclist[] = {
2N/A "SolarisAuthAttr",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (authstr_t *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->res1 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->res2 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->short_desc != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrShortDesc", ptr->short_desc);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->long_desc != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->long_desc);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: exec_attr
2N/A * Input format: execstr_t
2N/A * Exported objectclass: SolarisExecAttr
2N/A */
2N/Astatic int
2N/A__s_cvt_execattr(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A char esc_str[RDNSIZE];
2N/A /* routine specific */
2N/A execstr_t *ptr;
2N/A int max_attr = 7;
2N/A static char *oclist[] = {
2N/A "SolarisExecAttr",
2N/A "SolarisProfAttr",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (execstr_t *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->name[0] == '\0' ||
2N/A ptr->policy == NULL || ptr->policy[0] == '\0' ||
2N/A ptr->type == NULL || ptr->type[0] == '\0' ||
2N/A ptr->id == NULL || ptr->id[0] == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /*
2N/A * Escape special characters in ProfileID.
2N/A */
2N/A if (escape_str(esc_str, ptr->id) != 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s+SolarisKernelSecurityPolicy=%s"
2N/A "+SolarisProfileType=%s+SolarisProfileId=%s",
2N/A ptr->name, ptr->policy, ptr->type, esc_str);
2N/A
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisKernelSecurityPolicy", ptr->policy);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisProfileType", ptr->type);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisProfileId", ptr->id);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->res1 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrRes1", ptr->res1);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->res2 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrRes2", ptr->res2);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: prof_attr
2N/A * Input format: profstr_t
2N/A * Exported objectclass: SolarisProfAttr
2N/A */
2N/Astatic int
2N/A__s_cvt_profattr(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A profstr_t *ptr;
2N/A int max_attr = 5;
2N/A static char *oclist[] = {
2N/A "SolarisProfAttr",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (profstr_t *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->name[0] == '\0' || ptr->attr == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "cn=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "cn", ptr->name);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->res1 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->res2 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->desc != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrLongDesc", ptr->desc);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: user_attr
2N/A * Input format: userstr_t
2N/A * Exported objectclass: SolarisUserAttr
2N/A */
2N/Astatic int
2N/A__s_cvt_userattr(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A userstr_t *ptr;
2N/A int max_attr = 5;
2N/A static char *oclist[] = {
2N/A "SolarisUserAttr",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (userstr_t *)data;
2N/A
2N/A if (ptr->name == NULL || ptr->name[0] == '\0' ||
2N/A ptr->attr == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /*
2N/A * SolarisUserAttr has no uid attribute
2N/A */
2N/A
2N/A rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attr);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (ptr->qualifier != NULL) {
2N/A rc = __s_add_attr(e, "SolarisUserQualifier", ptr->qualifier);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->res1 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved1", ptr->res1);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->res2 != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAttrReserved2", ptr->res2);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: audit_user
2N/A * Input format: au_user_str_t
2N/A * Exported objectclass: SolarisAuditUser
2N/A */
2N/Astatic int
2N/A__s_cvt_audituser(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A au_user_str_t *ptr;
2N/A int max_attr = 3;
2N/A static char *oclist[] = {
2N/A "SolarisAuditUser",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (au_user_str_t *)data;
2N/A
2N/A if (ptr->au_name == NULL || ptr->au_name[0] == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "uid=%s", ptr->au_name);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A /*
2N/A * Solaris AuditUser has no uid attribute
2N/A */
2N/A
2N/A if (ptr->au_always != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAuditAlways", ptr->au_always);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A if (ptr->au_never != NULL) {
2N/A rc = __s_add_attr(e, "SolarisAuditNever", ptr->au_never);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: tnrhtp
2N/A * Input format: tsol_tpstr_t
2N/A * Exported objectclass: ipTnetTemplate
2N/A */
2N/Astatic int
2N/A__s_cvt_tnrhtp(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A char esc_str[RDNSIZE];
2N/A /* routine specific */
2N/A int max_attr = 2;
2N/A tsol_tpstr_t *ptr;
2N/A static char *oclist[] = {
2N/A "ipTnetTemplate",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (tsol_tpstr_t *)data;
2N/A
2N/A if (ptr->tpstr_template == NULL || *ptr->tpstr_template == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /*
2N/A * Escape special characters in Template name.
2N/A */
2N/A if (escape_str(esc_str, ptr->tpstr_template) != 0) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "ipTnetTemplateName=%s", esc_str);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "ipTnetTemplateName", ptr->tpstr_template);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "SolarisAttrKeyValue", ptr->attrs);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Conversion: tnrhdb
2N/A * Input format: tsol_rhstr_t
2N/A * Exported objectclass: ipTnetHost
2N/A */
2N/Astatic int
2N/A__s_cvt_tnrhdb(const void *data, char **rdn,
2N/A ns_ldap_entry_t **entry, ns_ldap_error_t **errorp)
2N/A{
2N/A ns_ldap_entry_t *e;
2N/A int rc;
2N/A char trdn[RDNSIZE];
2N/A /* routine specific */
2N/A tsol_rhstr_t *ptr;
2N/A int max_attr = 2;
2N/A static char *oclist[] = {
2N/A "ipTnetHost",
2N/A "ipTnetTemplate",
2N/A "top",
2N/A NULL
2N/A };
2N/A
2N/A if (data == NULL || rdn == NULL || entry == NULL || errorp == NULL)
2N/A return (NS_LDAP_OP_FAILED);
2N/A
2N/A *entry = e = __s_mk_entry(oclist, max_attr);
2N/A if (e == NULL)
2N/A return (NS_LDAP_MEMORY);
2N/A
2N/A /* Convert the structure */
2N/A ptr = (tsol_rhstr_t *)data;
2N/A
2N/A if (ptr->address == NULL || *ptr->address == '\0' ||
2N/A ptr->rhstr_template == NULL || *ptr->rhstr_template == '\0') {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A }
2N/A
2N/A /* Create an appropriate rdn */
2N/A (void) snprintf(trdn, RDNSIZE, "ipTnetNumber=%s", ptr->address);
2N/A *rdn = strdup(trdn);
2N/A if (*rdn == NULL) {
2N/A __ns_ldap_freeEntry(e);
2N/A *entry = NULL;
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "ipTnetNumber", ptr->address);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A rc = __s_add_attr(e, "ipTnetTemplateName", ptr->rhstr_template);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(entry, rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A/*
2N/A * Add Typed Entry Conversion data structures
2N/A */
2N/A
2N/Atypedef struct __ns_cvt_type {
2N/A const char *service;
2N/A int flags;
2N/A#define AE 1 /* alway add entries */
2N/A int (*cvt_rtn)(const void *data,
2N/A char **rdn,
2N/A ns_ldap_entry_t **entry,
2N/A ns_ldap_error_t **errorp);
2N/A} __ns_cvt_type_t;
2N/A
2N/Astatic __ns_cvt_type_t __s_cvtlist[] = {
2N/A { NS_LDAP_TYPE_PASSWD, 0, __s_cvt_passwd },
2N/A { NS_LDAP_TYPE_GROUP, 0, __s_cvt_group },
2N/A { NS_LDAP_TYPE_HOSTS, 0, __s_cvt_hosts },
2N/A { NS_LDAP_TYPE_IPNODES, 0, __s_cvt_hosts },
2N/A { NS_LDAP_TYPE_RPC, 0, __s_cvt_rpc },
2N/A { NS_LDAP_TYPE_PROTOCOLS, 0, __s_cvt_protocols },
2N/A { NS_LDAP_TYPE_NETWORKS, 0, __s_cvt_networks },
2N/A { NS_LDAP_TYPE_NETGROUP, 0, __s_cvt_netgroups },
2N/A { NS_LDAP_TYPE_ALIASES, 0, __s_cvt_aliases },
2N/A { NS_LDAP_TYPE_SERVICES, 0, __s_cvt_services },
2N/A { NS_LDAP_TYPE_ETHERS, 0, __s_cvt_ethers },
2N/A { NS_LDAP_TYPE_SHADOW, 0, __s_cvt_shadow },
2N/A { NS_LDAP_TYPE_NETMASKS, 0, __s_cvt_netmasks },
2N/A { NS_LDAP_TYPE_BOOTPARAMS, 0, __s_cvt_bootparams },
2N/A { NS_LDAP_TYPE_AUTHATTR, 0, __s_cvt_authattr },
2N/A { NS_LDAP_TYPE_EXECATTR, 0, __s_cvt_execattr },
2N/A { NS_LDAP_TYPE_PROFILE, 0, __s_cvt_profattr },
2N/A { NS_LDAP_TYPE_USERATTR, AE, __s_cvt_userattr },
2N/A { NS_LDAP_TYPE_AUTOMOUNT, 0, __s_cvt_auto_mount },
2N/A { NS_LDAP_TYPE_PUBLICKEY, AE, __s_cvt_publickey },
2N/A { NS_LDAP_TYPE_AUUSER, AE, __s_cvt_audituser },
2N/A { NS_LDAP_TYPE_TNRHTP, 0, __s_cvt_tnrhtp },
2N/A { NS_LDAP_TYPE_TNRHDB, 0, __s_cvt_tnrhdb },
2N/A { NS_LDAP_TYPE_PROJECT, 0, __s_cvt_project },
2N/A { NULL, 0, NULL },
2N/A};
2N/A
2N/A/*
2N/A * Add Typed Entry Routine
2N/A */
2N/A
2N/A/*ARGSUSED*/
2N/Aint __ns_ldap_addTypedEntry(
2N/A const char *servicetype,
2N/A const char *basedn,
2N/A const void *data,
2N/A const int create,
2N/A const ns_cred_t *cred,
2N/A const int flags,
2N/A ns_ldap_error_t **errorp)
2N/A{
2N/A char *rdn = NULL, *fulldn = NULL;
2N/A void **paramVal = NULL;
2N/A ns_ldap_entry_t *entry = NULL;
2N/A const ns_ldap_attr_t *const *modattrlist;
2N/A ns_ldap_search_desc_t **sdlist;
2N/A char **dns = NULL;
2N/A char trdn[RDNSIZE];
2N/A char service[BUFSIZE];
2N/A int rc = 0;
2N/A int automount = 0;
2N/A int i, s;
2N/A
2N/A rc = NS_LDAP_OP_FAILED;
2N/A for (s = 0; __s_cvtlist[s].service != NULL; s++) {
2N/A if (__s_cvtlist[s].cvt_rtn == NULL)
2N/A continue;
2N/A if (strcasecmp(__s_cvtlist[s].service, servicetype) == 0)
2N/A break;
2N/A /* Or, check if the servicetype is auto_ */
2N/A if (strcmp(__s_cvtlist[s].service,
2N/A NS_LDAP_TYPE_AUTOMOUNT) == 0 &&
2N/A strncasecmp(servicetype, NS_LDAP_TYPE_AUTOMOUNT,
2N/A sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) {
2N/A automount++;
2N/A break;
2N/A }
2N/A }
2N/A if (__s_cvtlist[s].service == NULL)
2N/A return (rc);
2N/A
2N/A /* Convert the data */
2N/A rc = (*__s_cvtlist[s].cvt_rtn)(data, &rdn, &entry, errorp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (rc);
2N/A }
2N/A if (rdn == NULL) {
2N/A __ns_ldap_freeEntry(entry);
2N/A return (NS_LDAP_OP_FAILED);
2N/A }
2N/A
2N/A if (strcmp(servicetype, "publickey") == 0) {
2N/A struct _ns_pubkey *ptr;
2N/A ptr = (struct _ns_pubkey *)data;
2N/A if (ptr->hostcred == NS_HOSTCRED_TRUE)
2N/A (void) strcpy(service, "hosts");
2N/A else
2N/A (void) strcpy(service, "passwd");
2N/A } else
2N/A (void) strcpy(service, servicetype);
2N/A
2N/A /* Create the Full DN */
2N/A if (basedn == NULL) {
2N/A rc = __s_api_get_SSD_from_SSDtoUse_service(service,
2N/A &sdlist, errorp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (rc);
2N/A }
2N/A
2N/A if (sdlist == NULL) {
2N/A rc = __s_api_getDNs(&dns, service, errorp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A if (dns) {
2N/A __s_api_free2dArray(dns);
2N/A dns = NULL;
2N/A }
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (rc);
2N/A }
2N/A (void) snprintf(trdn, RDNSIZE, "%s,%s", rdn, dns[0]);
2N/A __s_api_free2dArray(dns);
2N/A } else {
2N/A if (sdlist[0]->basedn) {
2N/A (void) snprintf(trdn, RDNSIZE, "%s,%s",
2N/A rdn, sdlist[0]->basedn);
2N/A } else {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (NS_LDAP_OP_FAILED);
2N/A }
2N/A }
2N/A i = strlen(trdn) - 1;
2N/A if (trdn[i] == COMMATOK) {
2N/A rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P,
2N/A &paramVal, errorp);
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (rc);
2N/A }
2N/A i = strlen(trdn) + strlen((char *)(paramVal[0])) + 1;
2N/A fulldn = (char *)calloc(i, 1);
2N/A if (fulldn == NULL) {
2N/A (void) __ns_ldap_freeParam(&paramVal);
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A (void) snprintf(fulldn, i, "%s%s", trdn,
2N/A (char *)(paramVal[0]));
2N/A (void) __ns_ldap_freeParam(&paramVal);
2N/A } else {
2N/A fulldn = strdup(trdn);
2N/A if (fulldn == NULL) {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A }
2N/A } else {
2N/A i = strlen(rdn) + strlen(basedn) + 2;
2N/A fulldn = (char *)calloc(i, 1);
2N/A if (fulldn == NULL) {
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A (void) snprintf(fulldn, i, "%s,%s", rdn, basedn);
2N/A }
2N/A
2N/A modattrlist = (const ns_ldap_attr_t * const *)entry->attr_pair;
2N/A /* Check to see if the entry exists already */
2N/A /* May need to delete or update first */
2N/A
2N/A if (create != 1) {
2N/A /* Modify the entry */
2N/A /*
2N/A * To add a shadow-like entry, the addTypedEntry function
2N/A * would call __ns_ldap_repAttr first, and if server says
2N/A * LDAP_NO_SUCH_OBJECT, then it tries __ns_ldap_addEntry.
2N/A * This is to allow a netmask entry to be added even if the
2N/A * base network entry is not in the directory. It would work
2N/A * because the difference between the schema for the network
2N/A * and netmask data contains only MAY attributes.
2N/A *
2N/A * But for shadow data, the attributes do not have MUST
2N/A * attributes the base entry needs, so if the __ns_ldap_addEntry
2N/A * is executed, it would fail. The real reason, however, is that
2N/A * the base entry did not exist. So returning
2N/A * LDAP_OBJECT_CLASS_VIOLATION would just confused.
2N/A */
2N/A if ((__s_cvtlist[s].flags & AE) != 0) {
2N/A if (flags & NS_LDAP_UPDATE_ATTR) {
2N/A rc = __ns_ldap_repAttr(service, fulldn,
2N/A modattrlist, cred, flags, errorp);
2N/A } else {
2N/A rc = __ns_ldap_addAttr(service, fulldn, modattrlist,
2N/A cred, flags, errorp);
2N/A }
2N/A } else {
2N/A rc = __ns_ldap_repAttr(service, fulldn, modattrlist,
2N/A cred, flags, errorp);
2N/A if (rc == NS_LDAP_INTERNAL && *errorp &&
2N/A (*errorp)->status == LDAP_NO_SUCH_OBJECT) {
2N/A (void) __ns_ldap_freeError(errorp);
2N/A rc = __ns_ldap_addEntry(service, fulldn,
2N/A entry, cred, flags, errorp);
2N/A if (rc == NS_LDAP_INTERNAL && *errorp &&
2N/A (*errorp)->status ==
2N/A LDAP_OBJECT_CLASS_VIOLATION)
2N/A (*errorp)->status = LDAP_NO_SUCH_OBJECT;
2N/A }
2N/A }
2N/A } else {
2N/A /* Add the entry */
2N/A rc = __ns_ldap_addEntry(service, fulldn, entry,
2N/A cred, flags, errorp);
2N/A if (rc == NS_LDAP_INTERNAL && *errorp &&
2N/A (*errorp)->status == LDAP_ALREADY_EXISTS &&
2N/A ((strcmp(service, "ethers") == 0) ||
2N/A (strcmp(service, "bootparams") == 0))) {
2N/A rc = modify_ethers_bootp(service, rdn, fulldn,
2N/A modattrlist, cred, flags, errorp);
2N/A }
2N/A }
2N/A
2N/A /* Free up entry created by conversion routine */
2N/A if (fulldn != NULL)
2N/A free(fulldn);
2N/A __s_cvt_freeEntryRdn(&entry, &rdn);
2N/A return (rc);
2N/A}
2N/A
2N/A/*
2N/A * Append the default base dn to the dn
2N/A * when it ends with ','.
2N/A * e.g.
2N/A * SSD = service:ou=foo,
2N/A */
2N/Aint
2N/A__s_api_append_default_basedn(
2N/A const char *dn,
2N/A char **new_dn,
2N/A int *allocated,
2N/A ns_ldap_error_t **errp) {
2N/A
2N/A int rc = NS_LDAP_SUCCESS, len = 0;
2N/A void **param = NULL;
2N/A char *str = NULL;
2N/A
2N/A *allocated = FALSE;
2N/A *new_dn = NULL;
2N/A
2N/A if (dn == NULL)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P,
2N/A (void ***)&param, errp);
2N/A
2N/A if (rc != NS_LDAP_SUCCESS) {
2N/A if (param)
2N/A (void) __ns_ldap_freeParam(&param);
2N/A return (rc);
2N/A }
2N/A
2N/A len = strlen(dn);
2N/A str = ((char **)param)[0];
2N/A len = len + strlen(str) +1;
2N/A *new_dn = (char *)malloc(len);
2N/A if (*new_dn == NULL) {
2N/A (void) __ns_ldap_freeParam(&param);
2N/A return (NS_LDAP_MEMORY);
2N/A }
2N/A *allocated = TRUE;
2N/A
2N/A (void) strcpy(*new_dn, dn);
2N/A (void) strcat(*new_dn, str);
2N/A
2N/A (void) __ns_ldap_freeParam(&param);
2N/A return (NS_LDAP_SUCCESS);
2N/A}
2N/A
2N/A/*
2N/A * Flatten the input ns_ldap_attr_t list, 'attr', and convert it into an
2N/A * ldap_strlist_t structure in buffer 'buf', to be used by ldap_cachemgr.
2N/A * The output contains a count, a list of offsets, which show where the
2N/A * corresponding copied attribute type and attribute value are located.
2N/A * For example, for dn=aaaa, userpassword=bbbb, shadowlastchange=cccc,
2N/A * the output is the ldap_strlist_t structure with: ldap_count = 6,
2N/A * (buf + ldap_offsets[0]) -> "dn"
2N/A * (buf + ldap_offsets[1]) -> "aaaa"
2N/A * (buf + ldap_offsets[2]) -> "userPassword"
2N/A * (buf + ldap_offsets[3]) -> "bbbb"
2N/A * (buf + ldap_offsets[4]) -> "shadowlastchange"
2N/A * (buf + ldap_offsets[5]) -> "cccc"
2N/A * and all the string data shown above copied into the buffer after
2N/A * the offset array. The total length of the data will be the return
2N/A * value, or -1 if error.
2N/A */
2N/Astatic int
2N/Aattr2list(const char *dn, int opcode, ns_ldap_attr_t **attr,
2N/A char *buf, int bufsize)
2N/A{
2N/A int c = 0;
2N/A char *ap;
2N/A int ao;
2N/A ldap_strlist_t *al = (ldap_strlist_t *)buf;
2N/A ns_ldap_attr_t **aptr = (ns_ldap_attr_t **)attr;
2N/A ns_ldap_attr_t *a;
2N/A
2N/A if (attr != NULL)
2N/A a = (ns_ldap_attr_t *)*attr;
2N/A
2N/A /* bufsize > strlen(dn) + strlen("dn") + 1 ('\0') */
2N/A if ((strlen(dn) + 2 + 1) >= bufsize)
2N/A return (-1);
2N/A
2N/A /* count number of attributes */
2N/A while (aptr != NULL && *aptr != NULL) {
2N/A a = *aptr;
2N/A /*
2N/A * Some attributes have multiple values (ex: objectClass)
2N/A * For some operations we do not send ObjectClass attributes
2N/A * because the server will not let it be modified.
2N/A */
2N/A if (!(opcode == ADMINMODIFY_REP &&
2N/A strcasecmp(a->attrname, "objectclass") == 0))
2N/A c += a->value_count;
2N/A aptr++;
2N/A }
2N/A al->ldap_count = 2 + c * 2;
2N/A ao = sizeof (al->ldap_count) + sizeof (al->ldap_offsets[0]) *
2N/A al->ldap_count;
2N/A if (ao > bufsize)
2N/A return (-1);
2N/A al->ldap_offsets[0] = ao;
2N/A ap = buf + ao;
2N/A ao += 3;
2N/A
2N/A /* copy entry DN */
2N/A if (ao > bufsize)
2N/A return (-1);
2N/A (void) strlcpy(ap, "dn", bufsize);
2N/A ap += 3;
2N/A
2N/A al->ldap_offsets[1] = ao;
2N/A ao += strlen(dn) + 1;
2N/A if (ao > bufsize)
2N/A return (-1);
2N/A (void) strlcpy(ap, dn, bufsize);
2N/A ap = buf + ao;
2N/A
2N/A aptr = attr;
2N/A for (c = 2; c < al->ldap_count && aptr && *aptr != NULL; aptr++) {
2N/A int i;
2N/A
2N/A a = *aptr;
2N/A if (a->attrname == NULL || a->attrvalue == NULL ||
2N/A a->attrvalue[0] == NULL)
2N/A return (-1);
2N/A
2N/A /*
2N/A * Don't pass objectClass attributes when modifying
2N/A * an existing entry.
2N/A */
2N/A if (opcode == ADMINMODIFY_REP &&
2N/A strcasecmp(a->attrname, "objectclass") == 0)
2N/A continue;
2N/A
2N/A /*
2N/A * For each value, write the attrname + attrvalue
2N/A * so they can be parsed later by the cachemgr.
2N/A */
2N/A for (i = 0; i < a->value_count; i++) {
2N/A al->ldap_offsets[c] = ao;
2N/A c++;
2N/A ao += strlen(a->attrname) + 1;
2N/A if (ao > bufsize)
2N/A return (-1);
2N/A
2N/A (void) strlcpy(ap, a->attrname, bufsize);
2N/A ap = buf + ao;
2N/A
2N/A al->ldap_offsets[c] = ao;
2N/A c++;
2N/A ao += strlen(a->attrvalue[i]) + 1;
2N/A (void) strlcpy(ap, a->attrvalue[i], bufsize);
2N/A ap = buf + ao;
2N/A }
2N/A
2N/A };
2N/A
2N/A return (ao);
2N/A}
2N/A
2N/A/*
2N/A * Send a modify request to the ldap_cachemgr daemon
2N/A * which will use the admin credential to perform the
2N/A * operation.
2N/A */
2N/A
2N/Astatic int
2N/Asend_to_cachemgr(
2N/A const char *dn,
2N/A ns_ldap_attr_t **attr,
2N/A ns_ldap_error_t **errorp,
2N/A int opcode,
2N/A ldap_service_t svc)
2N/A{
2N/A union {
2N/A ldap_data_t s_d;
2N/A char s_b[DOORBUFFERSIZE];
2N/A } space;
2N/A
2N/A ldap_data_t *sptr;
2N/A int ndata;
2N/A int adata;
2N/A int len = 0;
2N/A int rc;
2N/A char errstr[MAXERROR];
2N/A ldap_admin_mod_result_t *admin_result;
2N/A
2N/A *errorp = NULL;
2N/A (void) memset(space.s_b, 0, DOORBUFFERSIZE);
2N/A len = attr2list(dn, opcode, attr,
2N/A (char *)&space.s_d.ldap_call.ldap_u.ldap_admin.strlist,
2N/A sizeof (space) - offsetof(ldap_return_t, ldap_u));
2N/A if (len <= 0)
2N/A return (NS_LDAP_INVALID_PARAM);
2N/A
2N/A adata = sizeof (ldap_call_t) + len;
2N/A ndata = sizeof (space);
2N/A space.s_d.ldap_call.ldap_callnumber = opcode;
2N/A space.s_d.ldap_call.ldap_u.ldap_admin.ldap_service = svc;
2N/A sptr = &space.s_d;
2N/A
2N/A switch (__ns_ldap_trydoorcall(&sptr, &ndata, &adata)) {
2N/A case NS_CACHE_SUCCESS:
2N/A break;
2N/A case NS_CACHE_NOTFOUND:
2N/A (void) snprintf(errstr, sizeof (errstr),
2N/A gettext("Door call %d to "
2N/A "ldap_cachemgr failed - error: %d"),
2N/A opcode, space.s_d.ldap_ret.ldap_errno);
2N/A MKERROR(LOG_WARNING, *errorp, NS_CONFIG_CACHEMGR,
2N/A strdup(errstr), NULL);
2N/A return (NS_LDAP_OP_FAILED);
2N/A /* NOTREACHED */
2N/A break;
2N/A default:
2N/A return (NS_LDAP_OP_FAILED);
2N/A }
2N/A
2N/A admin_result = &sptr->ldap_ret.ldap_u.admin_result;
2N/A if (admin_result->ns_err == NS_LDAP_SUCCESS)
2N/A rc = NS_LDAP_SUCCESS;
2N/A else {
2N/A rc = admin_result->ns_err;
2N/A if (admin_result->msg_size == 0)
2N/A *errorp = __s_api_make_error(admin_result->status,
2N/A NULL);
2N/A else
2N/A *errorp = __s_api_make_error(admin_result->status,
2N/A admin_result->msg);
2N/A }
2N/A
2N/A /* clean up the door call */
2N/A if (sptr != &space.s_d) {
2N/A (void) munmap((char *)sptr, ndata);
2N/A }
2N/A
2N/A return (rc);
2N/A}