/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <malloc.h>
#include <stdlib.h>
#include <deflt.h>
#include <limits.h>
#include "ldap_parse.h"
#include "ldap_glob.h"
#include "ldap_attr.h"
#include "ldap_util.h"
#include "ldap_map.h"
#include "ldap_ruleval.h"
#include "nis_parse_ldap_conf.h"
int yp2ldap = 0;
/*
* List of mapping structures in original (i.e., as in config file) order.
* Lined on the 'seqNext' field.
*/
/*
* Call the parser for the config file 'ldapConfFile', and command line
* attribute settings per 'ldapCLA'.
*
* Returns
* 0 Success
* 1 No mapping should be used.
*/
int
int ret;
/*
* Establish defaults for ldapDBTableMapping, so that we have
* valid values even if there's no mapping config to parse.
*/
ldapDBTableMapping.expire = 0;
return (ret);
}
/*
* Convert the linked list of __nis_table_mapping_t's (produced by the
* attribute parser) to the 'ldapMappingList', keyed on the objPath.
*
* Once this function has returned, the 'tlist' is invalid, and must
* not be used in any way.
*/
int
#ifdef NISDB_LDAP_DEBUG
char **sdi, *s;
int i, nsdi;
#endif /* NISDB_LDAP_DEBUG */
if (tlist == 0)
return (0);
/* proxyInfo.default_nis_domain must end in a dot */
{
len);
}
}
#ifdef NISDB_LDAP_DEBUG
if (*s != ' ') {
nsdi++;
while (*s != ' ' && *s != '\0')
s++;
if (*s == '\0')
break;
}
}
if (nsdi > 0) {
if (sdi == 0)
"%s: Memory alloc failure for dbId selection",
myself);
else {
for (i = 0, s = selectDbid; *s != '\0'; s++) {
if (*s != ' ') {
sdi[i++] = selectDbid;
while (*s != ' ' && *s != '\0')
s++;
if (*s != '\0') {
*s = '\0';
s++;
} else
break;
selectDbid = s;
}
}
}
}
#endif /* NISDB_LDAP_DEBUG */
__nis_init_hash_table(&dbids, 0);
int len;
#ifdef NISDB_LDAP_DEBUG
/*
* If the dbId doesn't match 'selectDbid', skip this
* mapping. Re-insert on 'tlist', in order to keep memory
* leak checking happy. Note that 'tlist' may end up pointing
* into the real mapping list, so it shouldn't be used once
* this routine has been called.
*/
if (nsdi > 0) {
for (i = 0; i < nsdi; i++) {
break;
}
if (i >= nsdi) {
if (tlist != t)
else
t->next = 0;
tlist = t;
continue;
}
}
#endif /* NISDB_LDAP_DEBUG */
t->next = 0;
/* Make sure t->item.name is set correctly */
/* Remove leading dot in object name, if any */
len -= 1;
}
/*
* Initialize the object path, which is what we'll
* rehash on.
*/
if (yp2ldap) {
t->objPath);
if (!t->objPath) {
"%s: Failed to obtain internal table name for \"%s\"",
return (-1);
}
} else {
if (t->objPath == 0)
return (-1);
if (internal_table_name(t->objName,
t->objPath) == 0) {
"%s: Failed to obtain internal table name for \"%s\"",
return (-1);
}
}
/*
* Initialize the column name array.
*/
if (!yp2ldap) {
if (setColumnsDuringConfig && setColumnNames(t)) {
"%s: Unable to find column names for \"%s\"",
return (-1);
}
}
/*
* If there are multiple mapping target containers, make
* each one into it's own mapping structure. They can all
* be minimal copies (i.e., share pointers to sub-structures
* other than the objectDN).
*
* If objectDN is NULL, we will never use this structure.
* In order to allow the rest of the mapping code to assume
* objectDN != NULL, skip the mapping (even if x == t).
*/
if (o == to) {
x = t;
/*
* Only insert the first mapping for an
* object on the sequential list.
*/
*seqNext = t;
t->seqNext = 0;
} else {
if (x == 0) {
/*
* This happens during rpc.nisd
* initialization, and it's an
* unrecoverable disaster, so don't
* bother cleaning up.
*/
return (-1);
}
memcpy(x, t, sizeof (*x));
x->objectDN = o;
x->next = 0;
}
/*
* If x->objectDN->write.base is NULL, clone it from
* x->objectDN->read.base.
*/
return (-1);
}
return (-1);
}
}
if (o != to) {
/* Insert last on the 't->next' list */
p->next = x;
}
}
/* Insert on dbid hash list */
"%s: Error inserting mapping for \"%s\" on hash list",
#ifdef NISDB_LDAP_DEBUG
abort();
#endif /* NISDB_LDAP_DEBUG */
return (-1);
}
}
/*
* dbids2objs() will remove the entries on 'dbids', so no need
* to clean up that list from this function.
*/
}
int
__nis_table_mapping_t *t, *o;
while ((t = __nis_pop_item_mt(dbids)) != 0) {
/* Previous entry for this object ? */
if (o != 0) {
__nis_table_mapping_t *p = o;
/*
* Mapping already exists, so this is an alternate.
* Find the end of the list of any previous alt's,
* and insert there.
*/
while (p->next != 0) {
p = p->next;
}
p->next = t;
"%s: __nis_release_item error",
myself);
return (-1);
}
} else {
if (!__nis_insert_item_mt(t, objs, 0)) {
"%s: __nis_insert_item error",
myself);
return (-1);
}
}
}
return (0);
}
/*
* internal_table_name()
*
* Removes the local domain part from a fully qualified name
* to create the internal table name for an object. These tables are
*
*/
char *
{
char *s, *t;
int i, j;
if (yp2ldap) {
return (NULL);
return (NULL);
return (res);
}
return (NULL);
/* pointer at the first character of the table name */
s = relative_name(name);
/*
* If s == NULL then either this is a request for a lookup
* in our parents namespace (ILLEGAL), or we're the root
* server and this is a lookup in our namespace.
*/
if (s) {
return (NULL);
}
if (t)
t++; /* Point past the slash */
/* Strip off the quotes if they were used here. */
if (t[0] == '"') {
/* Check for simply a quoted quote. */
if (t[1] != '"') {
j = strlen(t);
/* shift string left by one */
for (i = 0; i < j; i++)
t[i] = t[i+1];
t[j-2] = '\0'; /* Trounce trailing dquote */
}
}
/*
* OK so now we have the unique name for the table.
* At this point we can fix it up to match local
* file system conventions if we so desire. Since it
* is only used in this form by _this_ server we can
* mangle it any way we want, as long as we are consistent
* about it. :-)
*/
return (res);
}
/*
* SYSTEM DEPENDENT
*
* This function makes the table name "legal" for the underlying file system.
*
*/
void
__make_legal(char *s)
{
while (*s) {
if (isupper(*s))
*s = tolower(*s);
s++;
}
}
/*
* relative_name()
* This internal function will remove from the NIS name, the domain
* name of the current server, this will leave the unique part in
* the name this becomes the "internal" version of the name. If this
* function returns NULL then the name we were given to resolve is
* bad somehow.
*
* A dynamically-allocated string is returned.
*
* Imported from rpc.nisd/nis_log_common.c
*/
char *s; /* string with the name in it. */
{
char *d;
char *buf;
name_pos p;
if (s == NULL)
return (NULL);
d = __nis_rpc_domain();
if (d == NULL)
return (NULL);
return (NULL);
return (buf);
}
p = nis_dir_cmp(buf, d);
/* 's' is above 'd' in the tree */
return (NULL);
}
/* Insert a NUL where the domain name starts in the string */
/* Don't return a zero length name */
if (buf[0] == '\0') {
return (NULL);
}
return (buf);
}
/*
* Wrapper for internal_table_name() that allocates a large enough
* buffer for the internal name. Return value must be freed by caller.
* If the input 'name' is NULL, the name of the root directory table
* is returned.
*/
char *
if (buf == 0)
return (0);
if (name == 0) {
return (buf);
}
buf = 0;
}
return (buf);
}
/*
* Return the object mapping for the object indicated either by the
* internal DB name ('intNameArg'; preferred), or the FQ object name
* 'name'. If 'asObj' is non-zero, the caller is interested in the
* object mapping proper, not a mapping of table entries. Optionally,
* also indicate if the object is mapped from (read) or to (write) LDAP.
*
* Note that there may be more than one mapping of the appropriate type.
* Use the selectTableMapping() function in ldap_map.c to get all
* alternatives. However, the function below works as a short-cut if:
*
* You only want an indication that _a_ mapping of the desired
* type exists, or
*
* You want the non-objectDN information for an object-mapping
* proper (i.e., _not_ the mapping for entries in a table).
*/
__nis_table_mapping_t *t, *x;
char *intName;
if (doRead != 0)
*doRead = 0;
if (doWrite != 0)
*doWrite = 0;
if (intNameArg == 0) {
if (name == 0)
return (0);
if (intName == 0)
return (0);
freeIntName = 1;
} else {
}
if (t == 0) {
if (freeIntName)
return (0);
}
for (x = t; x != 0; x = x->next) {
/*
* If we're looking for an object mapping, and this
* one's for entries in a table, skip it.
*/
x->numColumns > 0)
continue;
rd++;
wr++;
}
if (doRead != 0)
if (doWrite != 0)
if (freeIntName)
return (x);
}