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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 /*
26 * DESCRIPTION: Contains dit_access interface support functions.
27 */
28 #include <sys/systeminfo.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/systeminfo.h>
34 #include <unistd.h>
35 #include <stdlib.h>
36 #include <syslog.h>
37 #include <ndbm.h>
38 #include <strings.h>
39 #include <errno.h>
40 #include "../ldap_util.h"
41 #include "../ldap_map.h"
42 #include "../ldap_parse.h"
43 #include "../ldap_structs.h"
44 #include "../ldap_val.h"
45 #include "../ldap_ruleval.h"
46 #include "../ldap_op.h"
47 #include "../ldap_attr.h"
48 #include "../ldap_nisdbquery.h"
49 #include "../nisdb_mt.h"
50 #include "shim.h"
51 #include "yptol.h"
52 #include "dit_access_utils.h"
53
54 #define YPMULTI "YP_MULTI_"
55 #define YPMULTISZ 9 /* == strlen(YPMULTI) */
56
57 /*
58 * Returns 'map,domain.'
59 */
107 val->val->value = am(myself, val->val->length);
108 if (val->val->value == 0) {
109 freeValue(val, 1);
110 return (0);
111 }
112 (void) memcpy(val->val->value, dptr, dsize);
113
114 return (val);
115 }
116
117 /*
118 * Returns an array of rule-values corresponding to the
119 * splitfields.
120 */
121 __nis_rule_value_t *
122 processSplitField(__nis_table_mapping_t *sf, __nis_value_t *inVal,
123 int *nv, int *statP) {
124
125 char *sepset;
126 __nis_rule_value_t *rvq;
127 __nis_mapping_format_t *ftmp;
128 __nis_value_t **valA, *tempVal;
129 int i, j, res, numVals, oldlen, count;
130 char *str, *oldstr;
131 char *myself = "processSplitField";
132
133 /* sf will be non NULL */
134
135 if (inVal == 0 || inVal->type != vt_string) {
136 *statP = MAP_PARAM_ERROR;
137 return (0);
138 }
139
140 /* Get the separator list */
141 sepset = sf->separatorStr;
142
143 /* Initialize rule-value */
144 rvq = 0;
145 count = 0;
146
147 if ((tempVal = stringToValue(inVal->val->value,
148 inVal->val->length)) == 0) {
149 *statP = MAP_NO_MEMORY;
150 return (0);
151 }
237 }
238
239 if (nv != 0)
240 *nv = count;
241
242 return (rvq);
243 }
244
245 /*
246 * Convert the datum to an array of RuleValues
247 */
248 __nis_rule_value_t *
249 datumToRuleValue(datum *key, datum *value, __nis_table_mapping_t *t,
250 int *nv, char *domain, bool_t readonly, int *statP) {
251
252 __nis_rule_value_t *rvq, *subrvq, *newrvq;
253 __nis_value_t *val;
254 __nis_value_t **valA;
255 __nis_table_mapping_t *sf;
256 int valueLen, comLen, numVals, nr, count = 1;
257 int i, j, k, l, af;
258 char *ipaddr, *ipvalue;
259
260 /* At this point, 't' is always non NULL */
261
262 /* Initialize rule-value */
263 if ((rvq = initRuleValue(1, 0)) == 0) {
264 *statP = MAP_INTERNAL_ERROR;
265 return (0);
266 }
267
268 /* Add domainname to rule-value */
269 if (addCol2RuleValue(vt_string, N2LDOMAIN, domain, strlen(domain),
270 rvq)) {
271 freeRuleValue(rvq, 1);
272 *statP = MAP_INTERNAL_ERROR;
273 return (0);
274 }
275
276 /* Handle key */
277 if (key != 0) {
628
629 if (res == -1) {
630 return (MAP_INTERNAL_ERROR);
631 }
632 }
633
634 return (SUCCESS);
635 }
636
637 /*
638 * Updates 'rv' with NIS name=value pairs suitable to
639 * construct datum from namefield information.
640 * Some part based on createNisPlusEntry (from ldap_nisdbquery.c)
641 * This code assumes that from a given LDAP entry, applying the
642 * mapping rules, would give us one or more NIS entries, differing
643 * only in key.
644 */
645 suc_code
646 buildNISRuleValue(__nis_table_mapping_t *t, __nis_rule_value_t *rv,
647 char *domain) {
648 int r, i, j, k, l, index, nrq, res, len;
649 int numItems, splitname, count, statP;
650 __nis_value_t *rval;
651 __nis_mapping_item_t *litem;
652 __nis_mapping_rule_t *rl;
653 __nis_rule_value_t *rvq;
654 char *value, *emptystr = "";
655
656 statP = SUCCESS;
657
658 /* Initialize default base */
659 __nisdb_get_tsd()->searchBase = t->objectDN->read.base;
660
661 /* Initialize rule-value rvq */
662 rvq = 0;
663 count = 0;
664
665 /* Add domainname to rule-value */
666 if (addCol2RuleValue(vt_string, N2LDOMAIN, domain, strlen(domain),
667 rv)) {
668 return (MAP_INTERNAL_ERROR);
993 }
994 }
995 sfree(sipkey);
996 }
997 return (0);
998 }
999 }
1000 return (-1);
1001 }
1002
1003 /*
1004 * Read (i.e get and map) a single NIS entry from the LDAP DIT
1005 */
1006 bool_t
1007 singleReadFromDIT(char *map, char *domain, datum *key, datum *value,
1008 int *statP) {
1009 __nis_table_mapping_t *t;
1010 __nis_rule_value_t *rv_request = 0, *rv_result = 0;
1011 __nis_ldap_search_t *ls;
1012 __nis_object_dn_t *objectDN = NULL;
1013 int i, rc, nr = 0, nv = 0;
1014 datum *datval = 0;
1015 char *skey, *str, *sipkey;
1016 char *myself = "singleReadFromDIT";
1017
1018 *statP = SUCCESS;
1019
1020 if (!map || !domain || !key || !value) {
1021 *statP = MAP_PARAM_ERROR;
1022 return (FALSE);
1023 }
1024
1025
1026 /* Get the mapping information for the map */
1027 if ((t = mappingFromMap(map, domain, statP)) == 0) {
1028 /*
1029 * No problem. We don't handle this map and domain. Maybe it's
1030 * handled by a service other than NIS.
1031 */
1032 return (FALSE);
1033 }
1034
1035 /* NULL-terminated version of datum key for logging */
|
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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * DESCRIPTION: Contains dit_access interface support functions.
28 */
29 #include <sys/systeminfo.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <sys/systeminfo.h>
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <syslog.h>
38 #include <ndbm.h>
39 #include <strings.h>
40 #include <errno.h>
41 #include <ctype.h>
42 #include "../ldap_util.h"
43 #include "../ldap_map.h"
44 #include "../ldap_parse.h"
45 #include "../ldap_structs.h"
46 #include "../ldap_val.h"
47 #include "../ldap_ruleval.h"
48 #include "../ldap_op.h"
49 #include "../ldap_attr.h"
50 #include "../ldap_nisdbquery.h"
51 #include "../nisdb_mt.h"
52 #include "shim.h"
53 #include "yptol.h"
54 #include "dit_access_utils.h"
55
56 #define YPMULTI "YP_MULTI_"
57 #define YPMULTISZ 9 /* == strlen(YPMULTI) */
58
59 /*
60 * Returns 'map,domain.'
61 */
109 val->val->value = am(myself, val->val->length);
110 if (val->val->value == 0) {
111 freeValue(val, 1);
112 return (0);
113 }
114 (void) memcpy(val->val->value, dptr, dsize);
115
116 return (val);
117 }
118
119 /*
120 * Returns an array of rule-values corresponding to the
121 * splitfields.
122 */
123 __nis_rule_value_t *
124 processSplitField(__nis_table_mapping_t *sf, __nis_value_t *inVal,
125 int *nv, int *statP) {
126
127 char *sepset;
128 __nis_rule_value_t *rvq;
129 __nis_value_t **valA, *tempVal;
130 int i, j, res, numVals, oldlen, count;
131 char *str, *oldstr;
132
133 /* sf will be non NULL */
134
135 if (inVal == 0 || inVal->type != vt_string) {
136 *statP = MAP_PARAM_ERROR;
137 return (0);
138 }
139
140 /* Get the separator list */
141 sepset = sf->separatorStr;
142
143 /* Initialize rule-value */
144 rvq = 0;
145 count = 0;
146
147 if ((tempVal = stringToValue(inVal->val->value,
148 inVal->val->length)) == 0) {
149 *statP = MAP_NO_MEMORY;
150 return (0);
151 }
237 }
238
239 if (nv != 0)
240 *nv = count;
241
242 return (rvq);
243 }
244
245 /*
246 * Convert the datum to an array of RuleValues
247 */
248 __nis_rule_value_t *
249 datumToRuleValue(datum *key, datum *value, __nis_table_mapping_t *t,
250 int *nv, char *domain, bool_t readonly, int *statP) {
251
252 __nis_rule_value_t *rvq, *subrvq, *newrvq;
253 __nis_value_t *val;
254 __nis_value_t **valA;
255 __nis_table_mapping_t *sf;
256 int valueLen, comLen, numVals, nr, count = 1;
257 int i, j, k, l;
258 char *ipaddr, *ipvalue;
259
260 /* At this point, 't' is always non NULL */
261
262 /* Initialize rule-value */
263 if ((rvq = initRuleValue(1, 0)) == 0) {
264 *statP = MAP_INTERNAL_ERROR;
265 return (0);
266 }
267
268 /* Add domainname to rule-value */
269 if (addCol2RuleValue(vt_string, N2LDOMAIN, domain, strlen(domain),
270 rvq)) {
271 freeRuleValue(rvq, 1);
272 *statP = MAP_INTERNAL_ERROR;
273 return (0);
274 }
275
276 /* Handle key */
277 if (key != 0) {
628
629 if (res == -1) {
630 return (MAP_INTERNAL_ERROR);
631 }
632 }
633
634 return (SUCCESS);
635 }
636
637 /*
638 * Updates 'rv' with NIS name=value pairs suitable to
639 * construct datum from namefield information.
640 * Some part based on createNisPlusEntry (from ldap_nisdbquery.c)
641 * This code assumes that from a given LDAP entry, applying the
642 * mapping rules, would give us one or more NIS entries, differing
643 * only in key.
644 */
645 suc_code
646 buildNISRuleValue(__nis_table_mapping_t *t, __nis_rule_value_t *rv,
647 char *domain) {
648 int r, i, j, k, l, nrq, res, len;
649 int numItems, splitname, count, statP;
650 __nis_value_t *rval;
651 __nis_mapping_item_t *litem;
652 __nis_mapping_rule_t *rl;
653 __nis_rule_value_t *rvq;
654 char *value, *emptystr = "";
655
656 statP = SUCCESS;
657
658 /* Initialize default base */
659 __nisdb_get_tsd()->searchBase = t->objectDN->read.base;
660
661 /* Initialize rule-value rvq */
662 rvq = 0;
663 count = 0;
664
665 /* Add domainname to rule-value */
666 if (addCol2RuleValue(vt_string, N2LDOMAIN, domain, strlen(domain),
667 rv)) {
668 return (MAP_INTERNAL_ERROR);
993 }
994 }
995 sfree(sipkey);
996 }
997 return (0);
998 }
999 }
1000 return (-1);
1001 }
1002
1003 /*
1004 * Read (i.e get and map) a single NIS entry from the LDAP DIT
1005 */
1006 bool_t
1007 singleReadFromDIT(char *map, char *domain, datum *key, datum *value,
1008 int *statP) {
1009 __nis_table_mapping_t *t;
1010 __nis_rule_value_t *rv_request = 0, *rv_result = 0;
1011 __nis_ldap_search_t *ls;
1012 __nis_object_dn_t *objectDN = NULL;
1013 int i, rc, nr = 0;
1014 datum *datval = 0;
1015 char *skey, *str;
1016 char *myself = "singleReadFromDIT";
1017
1018 *statP = SUCCESS;
1019
1020 if (!map || !domain || !key || !value) {
1021 *statP = MAP_PARAM_ERROR;
1022 return (FALSE);
1023 }
1024
1025
1026 /* Get the mapping information for the map */
1027 if ((t = mappingFromMap(map, domain, statP)) == 0) {
1028 /*
1029 * No problem. We don't handle this map and domain. Maybe it's
1030 * handled by a service other than NIS.
1031 */
1032 return (FALSE);
1033 }
1034
1035 /* NULL-terminated version of datum key for logging */
|