ldap_nisplus.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <lber.h>
#include <ldap.h>
#include <strings.h>
#include "ldap_nisplus.h"
#include "ldap_util.h"
#include "ldap_val.h"
#include "ldap_attr.h"
#include "ldap_glob.h"
static void
int i;
if (name == 0)
return;
for (i = 0; i < numCols; i++) {
}
}
/*
* Convert the object attributes (zo_owner, etc.) fields of 'o' to
* the corresponding char **'s and __nis_value_t's. The 'name' and
* 'val' arrays are each assumed to have (at least) 'numVals' elements,
* and 'numVals' must be at least five.
*
* Returns zero if successful, non-zero otherwise. Whether successful
* or not, the caller must clean up 'name' and 'val', which may be
* partially allocated even after a failure.
*/
static int
int i, err;
char *myself = "objAttr2Value";
return (-1);
for (err = 0, i = 0; i < 5; i++) {
if (name[i] == 0)
err++;
err++;
}
if (err > 0) {
for (i = 0; i < 5; i++) {
name[i] = 0;
}
return (-2);
}
for (err = 0, i = 0; i < 5; i++) {
err++;
}
if (err > 0) {
for (i = 0; i < 5; i++) {
name[i] = 0;
}
return (-3);
}
return (0);
}
/*
* Convert a __nis_index_t to a string, using the supplied rule-value
* to evaluate any expressions in the index components.
*
* The 'table' is used only to produce a more meaningful error message.
*/
static char *
char *table) {
__nis_buffer_t b = {0, 0};
int i, frv = 0;
char *myself = "index2string";
if (index == 0)
return (0);
if (rvIn == 0) {
if (rvIn == 0)
return (0);
frv = 1;
}
if (msg == 0)
for (i = 0; i < index->numIndexes; i++) {
char *fmt;
"%s: index spec error for component \"%s\"%s",
", <nil> value" : "");
if (frv)
return (0);
}
/* Derive a value for this index */
fa_item, 0, 0);
char *ival;
0, fa_item, 0, 0);
if (tmpval == 0)
ival = "<unknown>";
ival = "<non-string>";
ival = "<# val error>";
else
"%s: No value for index \"%s = %s\" (table = \"%s\")",
if (frv)
return (0);
}
/*
* There should only be one value, so we ignore
* any excess values.
*/
if (i == 0)
fmt = "%s=%s";
else
fmt = ",%s=%s";
} else {
}
}
if (frv)
return (b.buf);
}
/*
* Return the rule-value representation of the the entry (or entries)
* specified by 'index' and 'table'.
*
* If 'index' is non-NULL, we evaluate the index->value format using
* the supplied 'rvIn'; should 'index' be NULL, 'rvIn' is unused. In either
* case, 'rvIn' isn't modified.
*/
int *numVals) {
__nis_buffer_t b = {0, 0};
char *myself = "getNisPlusEntry";
if (table == 0)
return (0);
} else {
/* Special case: want the zo_* attributes for the 'table' */
nis_result *res = 0;
int stat;
if (stat != LDAP_SUCCESS)
return (0);
if (rv == 0) {
return (0);
}
/* Allocate space for the object attributes */
return (0);
}
if (numVals != 0)
*numVals = 1;
} else {
rv = 0;
}
}
return (rv);
}
/*
* Simple NIS+ entry lookup routine, which accepts an indexed name, and
* returns the corresponding rule-value array, and number of elements in
* said array.
*/
char *table;
nis_object *o;
char **col = 0;
char *myself = "getNisPlusEntrySimple";
if (name == 0)
return (0);
/* Find the table name proper */
if (table != 0) {
/* Point to the start of the table name */
table++;
} else {
/*
* Presumably no indices; this implies enumeration, and
* that's not the intended use of this function, so return
* failure.
*/
"%s: un-indexed name \"%s\" used for table entry lookup",
return (0);
}
0)) {
"%s: unable to get column names for \"%s\"",
return (0);
}
if (ttype != NIS_TABLE_OBJ) {
"%s: \"%s\" is object type %d, not a table",
return (0);
}
/* col!=0 and nc==0 is possible, so free the column array */
"%s: %s for \"%s\"",
"no column name elements",
table);
return (0);
}
if (res == 0) {
"%s: NIS+ lookup error (no result) for \"%s\"",
return (0);
}
/*
* Not really an error from the POV of this function; we
* have no way of knowing if the entry should exist or not.
*/
return (0);
"%s: NIS+ lookup error (%d) for \"%s\"",
return (0);
}
/* One rule-value element for each entry object */
if (rv == 0) {
return (0);
}
unsigned int nec;
int j;
continue;
if (nec == 0)
continue;
continue;
/*
* 'nec+5' to account for the object attributes
* (zo_owner. etc), of which there are five.
*/
return (0);
}
for (j = 0; j < nec; j++) {
int len;
return (0);
}
/* What's the type of column value ? */
else
return (0);
}
if (len > 0 &&
/* Don't count NUL in the value length */
len -= 1;
}
/*
* Always allocate memory so that there's a NUL at
* the end.
*/
return (0);
}
}
/* Now the object attributes */
5) != 0) {
return (0);
}
nv++;
}
if (numVals != 0)
return (rv);
}
/*
* Retrieve a copy of the specified NIS+ object. Upon successful return,
* the return value is LDAP_SUCCESS, *outRes contains the nis_result
* pointer, and there's at least one object in the result.
*
* On error, return a status other than LDAP_SUCCESS.
*/
int
char *objName;
char *myself = "getNisPlusObj";
if (objName == 0) {
}
if (msg == 0)
if (res == 0) {
return (LDAP_NO_MEMORY);
}
int msgtype = MSG_NOTIMECHECK;
"%s: nis_lookup(\"%s\", 0) => %d (%s)",
return (LDAP_OPERATIONS_ERROR);
}
"%s: nis_lookup(\"%s\", 0) => no objects",
return (LDAP_OPERATIONS_ERROR);
}
if (verbose)
"%s: Ignoring excess objects (%d) for \"%s\"",
}
if (outRes != 0) {
} else {
return (LDAP_PARAM_ERROR);
}
return (LDAP_SUCCESS);
}
char *objname;
int i, nv;
char *myself = "lookupNisPlus";
return (0);
if (objname == 0)
return (0);
if (rv == 0)
return (0);
if (val == 0) {
return (0);
}
int j;
for (j = 0; j < rv[i].numColumns; j++) {
break;
}
if (j >= rv[i].numColumns)
continue;
if (val == 0) {
return (0);
}
}
val = 0;
}
return (val);
}
/*
* The 'table' is used if the 'item->searchSpec.obj.name' is
* unspecified. If the 'item' doesn't contain an index spec (and
* hence indication of the exact NIS+ entry to update), an index
* spec is constructed from 'rv'.
*/
__nis_buffer_t b = {0, 0};
char **col = 0;
nis_object *o;
entry_obj *e;
char *orgEcVal;
char *myself = "storeNisPlus";
return (NIS_BADREQUEST);
/* Check that the table has column with the desired name */
return (NIS_NOMEMORY);
0) || ttype != NIS_TABLE_OBJ) {
return (NIS_NOSUCHTABLE);
}
break;
}
return (NIS_BADATTRIBUTE);
}
/* Construct the index entry object name */
table);
return (NIS_NOMEMORY);
}
/* Construct index value from rule-value */
for (i = 0; i < rv->numColumns; i++) {
continue;
if (i == 0)
else
}
} else {
/* Can't identify entry to modify */
return (NIS_NOTFOUND);
}
return (NIS_NOTFOUND);
}
/* Look it up */
if (res == 0) {
return (NIS_NOMEMORY); /* Likely guess */
return (err);
}
/* We only want one object, and it must be an entry */
return (NIS_BADOBJECT);
}
/* Verify that the column index 'ic' is in range */
return (NIS_TYPEMISMATCH);
}
/*
* Replace the indicated column value, and set the EN_MODIFIED flag.
* We keep track of the original value, so that we can restore it
* before destroying 'res'.
*/
/*
* We always make sure that the val->val[].value's have a NUL
* at the end. However, the 'length' usually doesn't include
* the NUL. Since NIS+ wants the NUL counted, we increase the
* length by one if:
* (a) the val->type is vt_string, and
* (b) val->val[].value[val->val[].length-1] isn't already
* NUL, and
* (c) val->val[].value[val->val[].length] is NUL.
*/
/* Restore 'res', and destroy it */
/* Don't need the indexed name anymore */
/* Set the return status, and destroy the modification result */
if (mres != 0) {
} else {
err = NIS_NOMEMORY;
}
return (err);
}
int
char **name;
char *myself = "copyColumnNames";
if (o == 0 || column == 0 || numColumns == 0)
return (LDAP_PARAM_ERROR);
if (*column == 0 && *numColumns < 0) {
/*
* This table mapping is used to map the table object
* itself. Since that's indicated by t->column == 0 and
* t->numColumns == -1, we definitely don't want to set
* the column names.
*/
return (LDAP_SUCCESS);
}
*column = 0;
*numColumns = 0;
/*
* Since we can map non-table objects, this isn't really
* an error, but we return a special value to tell our
* caller that this isn't a table (as opposed to a table
* with zero columns).
*/
return (LDAP_OBJECT_CLASS_VIOLATION);
}
if (nc < 0) {
"%s: negative column count (%d) for \"%s.%s\"",
return (LDAP_DECODING_ERROR);
}
return (LDAP_SUCCESS);
}
if (name == 0) {
return (LDAP_NO_MEMORY);
}
for (i = 0; i < nc; i++) {
ta_cols_val[i].tc_name == 0)
continue;
ta_cols_val[i].tc_name);
if (name[i] == 0) {
for (--i; i >= 0; i--)
return (LDAP_NO_MEMORY);
}
}
*numColumns = nc;
return (LDAP_SUCCESS);
}
/*
* Initialize the column name list for the specified table name
* (which must be fully qualified).
*
* Returns an LDAP error status
*/
int
nis_result *res = 0;
int stat;
char *myself = "initializeColumnNames";
return (LDAP_PARAM_ERROR);
if (stat != LDAP_SUCCESS)
return (stat);
*column = 0;
*numColumns = 0;
return (stat);
}
/*
* Sets the oid (i.e., the creation and modification times) for the
* specified object. In order to avoid retrieving the old incarnation
* (if any) from the DB first, we're punting and setting both mtime
* and ctime to the current time.
*/
void
if (obj != 0) {
}
}