2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <strings.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30 #include <stdio.h>
31 #include <rpcsvc/nis.h>
32 #include <rpc/xdr.h>
33
34 #include "ldap_util.h"
35 #include "ldap_attr.h"
36 #include "ldap_ruleval.h"
37 #include "ldap_op.h"
38 #include "ldap_map.h"
39 #include "ldap_glob.h"
40 #include "ldap_xdr.h"
41 #include "ldap_val.h"
1223 }
1224
1225 /*
1226 * Return all table mappings that match the column values in 'q'.
1227 * If there's no match, return those alternative mappings that don't
1228 * have an index; if no such mapping exists, return NULL.
1229 *
1230 * If 'wantWrite' is set, we want mappings for writing (i.e., data
1231 * to LDAP); otherwise, we want mappings for reading.
1232 *
1233 * If 'wantObj' is set, we want object mappings only (i.e., _not_
1234 * those used to map entries in tables).
1235 *
1236 * If 'dbId' is non-NULL, we select mappings with a matching dbId field.
1237 */
1238 __nis_table_mapping_t **
1239 selectTableMapping(__nis_table_mapping_t *t, db_query *q,
1240 int wantWrite, int wantObj, char *dbId,
1241 int *numMatches) {
1242 __nis_table_mapping_t *r, *x, **tp;
1243 int i, j, k, nm, numap;
1244 char *myself = "selectTableMapping";
1245
1246 if (numMatches == 0)
1247 numMatches = &nm;
1248
1249 /*
1250 * Count the number of possible mappings, so that we can
1251 * allocate the 'tp' array up front.
1252 */
1253 for (numap = 0, x = t; x != 0; numap++, x = x->next);
1254
1255 if (numap == 0) {
1256 *numMatches = 0;
1257 return (0);
1258 }
1259
1260 tp = am(myself, numap * sizeof (tp[0]));
1261 if (tp == 0) {
1262 *numMatches = -1;
1263 return (0);
1402
1403 if (val != 0)
1404 val = sdup(msg, T, val);
1405
1406 sfree(filter);
1407 freeFilterComp(fc, nfc);
1408
1409 return (val);
1410 }
1411
1412 extern bool_t xdr_nis_object(register XDR *xdrs, nis_object *objp);
1413
1414 /*
1415 * Copy an XDR:ed version of the NIS+ object 'o' (or the one indicated
1416 * by 't->objName' if 'o' is NULL) to the place indicated by
1417 * 't->objectDN->write'. Return an appropriate LDAP status code.
1418 */
1419 int
1420 objToLDAP(__nis_table_mapping_t *t, nis_object *o, entry_obj **ea, int numEa) {
1421 __nis_table_mapping_t **tp;
1422 XDR xdr;
1423 char *objName;
1424 int stat, osize, n, numMatches = 0;
1425 void *buf;
1426 __nis_rule_value_t *rv;
1427 __nis_value_t *val;
1428 __nis_single_value_t *sv;
1429 char **attrName, *dn;
1430 char *myself = "objToLDAP";
1431
1432 if (t == 0)
1433 return (LDAP_PARAM_ERROR);
1434
1435 logmsg(MSG_NOTIMECHECK,
1436 #ifdef NISDB_LDAP_DEBUG
1437 LOG_WARNING,
1438 #else
1439 LOG_INFO,
1440 #endif /* NISDB_LDAP_DEBUG */
1441 "%s: %s", myself, NIL(t->objName));
1442
1443 tp = selectTableMapping(t, 0, 1, 1, 0, &numMatches);
1528 }
1529
1530 sfree(tp);
1531
1532 return (stat);
1533 }
1534
1535 /*
1536 * Retrieve a copy of the 't->objName' object from LDAP, where it's
1537 * stored in XDR:ed form in the place indicated by 't->objectDN->read'.
1538 * Un-XDR the object, and return a pointer to it in '*obj'; it's the
1539 * responsibility of the caller to free the object when it's no
1540 * longer needed.
1541 *
1542 * Returns an appropriate LDAP status.
1543 */
1544 int
1545 objFromLDAP(__nis_table_mapping_t *t, nis_object **obj,
1546 entry_obj ***eaP, int *numEaP) {
1547 __nis_table_mapping_t **tp;
1548 XDR xdr;
1549 nis_object *o;
1550 __nis_rule_value_t *rv;
1551 __nis_ldap_search_t *ls;
1552 char *attrs[2], *filter, **fc = 0;
1553 void *buf;
1554 int i, j, nfc, nrv, blen, stat = LDAP_SUCCESS;
1555 int n, numMatches;
1556 char *myself = "objFromLDAP";
1557
1558 if (t == 0)
1559 return (LDAP_PARAM_ERROR);
1560
1561 /*
1562 * If there's nowhere to store the result, we might as
1563 * well pretend all went well, and return right away.
1564 */
1565 if (obj == 0)
1566 return (LDAP_SUCCESS);
1567
1568 /* Prepare for the worst */
|
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2015 Gary Mills
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <strings.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <errno.h>
31 #include <stdio.h>
32 #include <rpcsvc/nis.h>
33 #include <rpc/xdr.h>
34
35 #include "ldap_util.h"
36 #include "ldap_attr.h"
37 #include "ldap_ruleval.h"
38 #include "ldap_op.h"
39 #include "ldap_map.h"
40 #include "ldap_glob.h"
41 #include "ldap_xdr.h"
42 #include "ldap_val.h"
1224 }
1225
1226 /*
1227 * Return all table mappings that match the column values in 'q'.
1228 * If there's no match, return those alternative mappings that don't
1229 * have an index; if no such mapping exists, return NULL.
1230 *
1231 * If 'wantWrite' is set, we want mappings for writing (i.e., data
1232 * to LDAP); otherwise, we want mappings for reading.
1233 *
1234 * If 'wantObj' is set, we want object mappings only (i.e., _not_
1235 * those used to map entries in tables).
1236 *
1237 * If 'dbId' is non-NULL, we select mappings with a matching dbId field.
1238 */
1239 __nis_table_mapping_t **
1240 selectTableMapping(__nis_table_mapping_t *t, db_query *q,
1241 int wantWrite, int wantObj, char *dbId,
1242 int *numMatches) {
1243 __nis_table_mapping_t *r, *x, **tp;
1244 int i, nm, numap;
1245 char *myself = "selectTableMapping";
1246
1247 if (numMatches == 0)
1248 numMatches = &nm;
1249
1250 /*
1251 * Count the number of possible mappings, so that we can
1252 * allocate the 'tp' array up front.
1253 */
1254 for (numap = 0, x = t; x != 0; numap++, x = x->next);
1255
1256 if (numap == 0) {
1257 *numMatches = 0;
1258 return (0);
1259 }
1260
1261 tp = am(myself, numap * sizeof (tp[0]));
1262 if (tp == 0) {
1263 *numMatches = -1;
1264 return (0);
1403
1404 if (val != 0)
1405 val = sdup(msg, T, val);
1406
1407 sfree(filter);
1408 freeFilterComp(fc, nfc);
1409
1410 return (val);
1411 }
1412
1413 extern bool_t xdr_nis_object(register XDR *xdrs, nis_object *objp);
1414
1415 /*
1416 * Copy an XDR:ed version of the NIS+ object 'o' (or the one indicated
1417 * by 't->objName' if 'o' is NULL) to the place indicated by
1418 * 't->objectDN->write'. Return an appropriate LDAP status code.
1419 */
1420 int
1421 objToLDAP(__nis_table_mapping_t *t, nis_object *o, entry_obj **ea, int numEa) {
1422 __nis_table_mapping_t **tp;
1423 int stat, osize, n, numMatches = 0;
1424 void *buf;
1425 __nis_rule_value_t *rv;
1426 __nis_value_t *val;
1427 __nis_single_value_t *sv;
1428 char **attrName, *dn;
1429 char *myself = "objToLDAP";
1430
1431 if (t == 0)
1432 return (LDAP_PARAM_ERROR);
1433
1434 logmsg(MSG_NOTIMECHECK,
1435 #ifdef NISDB_LDAP_DEBUG
1436 LOG_WARNING,
1437 #else
1438 LOG_INFO,
1439 #endif /* NISDB_LDAP_DEBUG */
1440 "%s: %s", myself, NIL(t->objName));
1441
1442 tp = selectTableMapping(t, 0, 1, 1, 0, &numMatches);
1527 }
1528
1529 sfree(tp);
1530
1531 return (stat);
1532 }
1533
1534 /*
1535 * Retrieve a copy of the 't->objName' object from LDAP, where it's
1536 * stored in XDR:ed form in the place indicated by 't->objectDN->read'.
1537 * Un-XDR the object, and return a pointer to it in '*obj'; it's the
1538 * responsibility of the caller to free the object when it's no
1539 * longer needed.
1540 *
1541 * Returns an appropriate LDAP status.
1542 */
1543 int
1544 objFromLDAP(__nis_table_mapping_t *t, nis_object **obj,
1545 entry_obj ***eaP, int *numEaP) {
1546 __nis_table_mapping_t **tp;
1547 nis_object *o;
1548 __nis_rule_value_t *rv;
1549 __nis_ldap_search_t *ls;
1550 char *attrs[2], *filter, **fc = 0;
1551 void *buf;
1552 int i, j, nfc, nrv, blen, stat = LDAP_SUCCESS;
1553 int n, numMatches;
1554 char *myself = "objFromLDAP";
1555
1556 if (t == 0)
1557 return (LDAP_PARAM_ERROR);
1558
1559 /*
1560 * If there's nowhere to store the result, we might as
1561 * well pretend all went well, and return right away.
1562 */
1563 if (obj == 0)
1564 return (LDAP_SUCCESS);
1565
1566 /* Prepare for the worst */
|