Print this page
5910 libnisdb won't build with modern GCC
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnisdb/nis_parse_ldap_yp_util.c
+++ new/usr/src/lib/libnisdb/nis_parse_ldap_yp_util.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 + * Copyright 2015 Gary Mills
23 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 */
26 27
27 28 #include <stdio.h>
28 29 #include <string.h>
29 30 #include <stdlib.h>
30 31 #include <ctype.h>
31 32 #include <fcntl.h>
32 33 #include <errno.h>
33 34 #include <syslog.h>
34 35
35 36 #include "ldap_parse.h"
36 37 #include "nis_parse_ldap_conf.h"
37 -#include "nis_parse_ldap_err.h"
38 +#include "nis_parse_ldap_util.h"
38 39 #include "ldap_util.h"
39 40
40 -extern __nis_mapping_rule_t **dup_mapping_rules(
41 - __nis_mapping_rule_t **rules, int n_rules);
42 -extern __nis_mapping_rule_t *dup_mapping_rule(
43 - __nis_mapping_rule_t *in);
41 +/* Forward declarations */
42 +int getfullmapname(char **, const char *);
43 +int checkfullmapname(const char *, const char *, __nis_table_mapping_t **,
44 + __nis_table_mapping_t **);
45 +int append_domainContext(__nis_table_mapping_t **, char *, char *);
44 46
45 47 static int merge_table_mapping(__nis_table_mapping_t *in,
46 48 __nis_table_mapping_t *out);
47 49 __nis_table_mapping_t *new_merged_mapping(const char *,
48 50 __nis_table_mapping_t *intbl);
49 51 static int append_mapping_rule(__nis_mapping_rule_t *src_rule,
50 52 __nis_table_mapping_t *tbl, int flag);
51 53
52 54
53 55 static int copy_object_dn(__nis_object_dn_t *in,
54 56 __nis_object_dn_t *newdn);
55 57
56 58 /*
57 59 * FUNCTION: initialize_table_mapping
58 60 *
59 61 * Initialize the __nis_table_mapping_t structure.
60 62 *
61 63 * INPUT: __nis_table_mapping_t
62 64 *
63 65 */
64 66 void
65 67 initialize_table_mapping(
66 68 __nis_table_mapping_t *mapping)
67 69 {
68 70 if (mapping != NULL) {
69 71 mapping->dbId = NULL;
70 72
71 73 mapping->index.numIndexes = 0;
72 74 mapping->index.name = NULL;
73 75 mapping->index.value = NULL;
74 76
75 77 mapping->numColumns = 0;
76 78 mapping->column = NULL;
77 79
78 80 mapping->initTtlLo = (time_t)NO_VALUE_SET;
79 81 mapping->initTtlHi = (time_t)NO_VALUE_SET;
80 82 mapping->ttl = (time_t)NO_VALUE_SET;
81 83
82 84 mapping->usedns_flag = 0;
83 85 mapping->securemap_flag = 0;
84 86 mapping->commentChar = DEFAULT_COMMENT_CHAR;
85 87 mapping->numSplits = 0;
86 88
87 89 mapping->objectDN = NULL;
88 90
89 91 mapping->separatorStr = DEFAULT_SEP_STRING;
90 92
91 93 mapping->numRulesFromLDAP = 0;
92 94 mapping->numRulesToLDAP = 0;
93 95
94 96 mapping->ruleFromLDAP = NULL;
95 97 mapping->ruleToLDAP = NULL;
96 98
97 99 mapping->e = NULL;
98 100 mapping->objName = NULL;
99 101 mapping->objPath = NULL;
100 102 mapping->obj = NULL;
101 103 mapping->isMaster = 0;
102 104 mapping->seq_num = NO_VALUE_SET;
103 105 }
104 106 }
105 107
106 108 /*
107 109 * FUNCTION: initialize_yp_parse_structs
108 110 *
109 111 * Initialize the __yp_domain_context_t structure.
110 112 *
111 113 * INPUT: __yp_domain_context_t
112 114 *
113 115 */
114 116 void
115 117 initialize_yp_parse_structs(
116 118 __yp_domain_context_t *ypDomains)
117 119 {
118 120 ypDomains->numDomains = 0;
119 121 ypDomains->domainLabels = NULL;
120 122 ypDomains->domains = NULL;
121 123 ypDomains->numYppasswdd = 0;
122 124 ypDomains->yppasswddDomainLabels = NULL;
123 125 }
124 126
125 127 /*
126 128 * FUNCTION: merge_table_mapping
127 129 *
128 130 * Merges information from one table_mapping struct
129 131 * into another
130 132 *
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
131 133 * INPUT: Source and Destination table_mapping structs.
132 134 * RETURN: 0 on success and > 0 on error.
133 135 */
134 136
135 137 static int
136 138 merge_table_mapping(
137 139 __nis_table_mapping_t *in,
138 140 __nis_table_mapping_t *out)
139 141 {
140 142 int i;
141 - int len;
142 143 int orig_num_rules;
143 144 int append;
144 145
145 146 if (in == NULL)
146 147 return (1);
147 148
148 149 if (in->dbId == NULL)
149 150 return (1);
150 151
151 152 /*
152 153 * If 'in' is generic (non-expanded) and 'out' is domain-specific,
153 154 * then rules from 'in' should not be appended to those in 'out'.
154 155 */
155 156 if (!strchr(in->dbId, COMMA_CHAR) && strchr(out->dbId, COMMA_CHAR))
156 157 append = 0;
157 158 else
158 159 append = 1;
159 160
160 161
161 162 if (!out->index.numIndexes && in->index.numIndexes > 0) {
162 163 if (!dup_index(&in->index, &out->index))
163 164 return (1);
164 165 }
165 166
166 167 /* add_column() increments numColumns, so we don't */
167 168 if (!out->numColumns && in->numColumns > 0) {
168 169 for (i = 0; i < in->numColumns; i++) {
169 170 if (!add_column(out, in->column[i]))
170 171 return (1);
171 172 }
172 173 }
173 174
174 175 if (out->commentChar == DEFAULT_COMMENT_CHAR &&
175 176 in->commentChar != DEFAULT_COMMENT_CHAR)
176 177 out->commentChar = in->commentChar;
177 178
178 179 if (out->usedns_flag == 0)
179 180 out->usedns_flag = in->usedns_flag;
180 181
181 182 if (out->securemap_flag == 0)
182 183 out->securemap_flag = in->securemap_flag;
183 184
184 185 if ((strcmp(out->separatorStr, DEFAULT_SEP_STRING) == 0) &&
185 186 (strcmp(in->separatorStr, DEFAULT_SEP_STRING) != 0)) {
186 187 out->separatorStr = s_strdup(in->separatorStr);
187 188 if (!out->separatorStr)
188 189 return (2);
189 190 }
190 191
191 192 if (!out->numSplits && !out->e && in->e) {
192 193 out->numSplits = in->numSplits;
193 194 out->e = (__nis_mapping_element_t *)
194 195 s_calloc(1, (in->numSplits+1) *
195 196 sizeof (__nis_mapping_element_t));
196 197 if (!out->e)
197 198 return (2);
198 199 for (i = 0; i <= in->numSplits; i++) {
199 200 if (!dup_mapping_element(&in->e[i], &out->e[i])) {
200 201 for (; i > 0; i--) {
201 202 free_mapping_element(&out->e[i - 1]);
202 203 }
203 204 out->e = NULL;
204 205 return (1);
205 206 }
206 207 }
207 208 }
208 209
209 210 if (out->initTtlLo == (time_t)NO_VALUE_SET &&
210 211 in->initTtlLo != (time_t)NO_VALUE_SET)
211 212 out->initTtlLo = in->initTtlLo;
212 213
213 214 if (out->initTtlHi == (time_t)NO_VALUE_SET &&
214 215 in->initTtlHi != (time_t)NO_VALUE_SET)
215 216 out->initTtlHi = in->initTtlHi;
216 217
217 218 if (out->ttl == (time_t)NO_VALUE_SET &&
218 219 in->ttl != (time_t)NO_VALUE_SET)
219 220 out->ttl = in->ttl;
220 221
221 222 if (!out->numRulesFromLDAP && in->numRulesFromLDAP) {
222 223 out->ruleFromLDAP = dup_mapping_rules(in->ruleFromLDAP,
223 224 in->numRulesFromLDAP);
224 225 if (!out->ruleFromLDAP)
225 226 return (1);
226 227 out->numRulesFromLDAP = in->numRulesFromLDAP;
227 228 } else if (append && out->numRulesFromLDAP && in->numRulesFromLDAP) {
228 229 orig_num_rules = out->numRulesFromLDAP;
229 230 for (i = 0; i < in->numRulesFromLDAP; i++) {
230 231 if (append_mapping_rule(in->ruleFromLDAP[i], out, 0)) {
231 232 for (i = out->numRulesFromLDAP;
232 233 i > orig_num_rules; i--) {
233 234 free_mapping_rule(out->ruleFromLDAP[i]);
234 235 out->ruleFromLDAP[i] = NULL;
235 236 }
236 237 return (1);
237 238
238 239 }
239 240 }
240 241 }
241 242
242 243 if (!out->numRulesToLDAP && in->numRulesToLDAP) {
243 244 out->ruleToLDAP = dup_mapping_rules(in->ruleToLDAP,
244 245 in->numRulesToLDAP);
245 246 if (!out->ruleToLDAP)
246 247 return (1);
247 248 out->numRulesToLDAP = in->numRulesToLDAP;
248 249 } else if (append && out->numRulesToLDAP && in->numRulesToLDAP) {
249 250 orig_num_rules = out->numRulesToLDAP;
250 251 for (i = 0; i < in->numRulesToLDAP; i++) {
251 252 if (append_mapping_rule(in->ruleToLDAP[i], out, 1)) {
252 253 for (i = out->numRulesToLDAP;
253 254 i > orig_num_rules; i--) {
254 255 free_mapping_rule(out->ruleToLDAP[i]);
255 256 out->ruleToLDAP[i] = NULL;
256 257 }
257 258 return (1);
258 259 }
259 260 }
260 261 }
261 262 if (!out->objectDN && in->objectDN) {
262 263 out->objectDN = (__nis_object_dn_t *)
263 264 s_calloc(1, sizeof (__nis_object_dn_t));
264 265 if (!out->objectDN)
265 266 return (2);
266 267 if (copy_object_dn(in->objectDN, out->objectDN)) {
267 268 free_object_dn(out->objectDN);
268 269 out->objectDN = NULL;
269 270 return (1);
270 271 }
271 272 }
272 273
273 274 if (!out->objName && in->objName) {
274 275 if (!strchr(in->objName, SPACE_CHAR)) {
275 276 /* objName has no space- a single map dbIdMapping */
276 277 out->objName = s_strndup(in->objName,
277 278 strlen(in->objName));
278 279 if (!out->objName)
279 280 return (2);
280 281 }
281 282 }
282 283
283 284 if (!out->objName && out->dbId) {
284 285 out->objName = s_strndup(out->dbId, strlen(out->dbId));
285 286 if (!out->objName)
286 287 return (2);
287 288 }
288 289
289 290 if (out->seq_num == NO_VALUE_SET && in->seq_num >= 0)
290 291 out->seq_num = in->seq_num;
291 292
292 293 return (p_error == no_parse_error ? 0 : 1);
293 294 }
294 295
295 296 /*
296 297 * FUNCTION: copy_object_dn
297 298 *
298 299 * Copies a __nis_object_dn_t structure.
299 300 *
300 301 * RETURN: 0 on success, > 0 on failure.
301 302 *
302 303 * NOTE: The caller MUST free newdn using
303 304 * free_object_dn() if return value != 0 (error condition)
304 305 */
305 306
306 307 static int
307 308 copy_object_dn(__nis_object_dn_t *in, __nis_object_dn_t *newdn)
308 309 {
309 310 if (in == NULL) {
310 311 p_error = parse_no_object_dn;
311 312 return (1);
312 313 }
313 314 while (in != NULL) {
314 315 if (in->read.base == NULL) {
315 316 newdn->read.base = NULL;
316 317 } else {
317 318 newdn->read.base = s_strndup(
318 319 in->read.base, strlen(in->read.base));
319 320 if (newdn->read.base == NULL)
320 321 return (2);
321 322 }
322 323 newdn->read.scope = in->read.scope;
323 324 if (in->read.attrs) {
324 325 newdn->read.attrs = s_strndup(
325 326 in->read.attrs, strlen(in->read.attrs));
326 327 if (newdn->read.attrs == NULL) {
327 328 return (2);
328 329 }
329 330 } else {
330 331 newdn->read.attrs = NULL;
331 332 }
332 333 newdn->read.element = in->read.element;
333 334 if (in->write.base != NULL) {
334 335 newdn->write.base = s_strndup(
335 336 in->write.base, strlen(in->write.base));
336 337 if (newdn->write.base == NULL)
337 338 return (2);
338 339 } else {
339 340 newdn->write.base = NULL;
340 341 }
341 342 newdn->write.scope = in->write.scope;
342 343 if (in->write.attrs != NULL) {
343 344 newdn->write.attrs = s_strndup(
344 345 in->write.attrs, strlen(in->write.attrs));
345 346 if (newdn->write.attrs == NULL) {
346 347 return (2);
347 348 }
348 349 } else {
349 350 newdn->write.attrs = NULL;
350 351 }
351 352 newdn->write.element = in->write.element;
352 353 if (in->dbIdName) {
353 354 newdn->dbIdName = s_strndup(in->dbIdName,
354 355 strlen(in->dbIdName));
355 356 if (newdn->dbIdName == NULL)
356 357 return (2);
357 358 }
358 359
359 360 if (in->delDisp)
360 361 newdn->delDisp = in->delDisp;
361 362
362 363 if (in->dbId && in->numDbIds > 0) {
363 364 newdn->dbId = dup_mapping_rules(in->dbId,
364 365 in->numDbIds);
365 366 if (!newdn->dbId)
366 367 return (1);
367 368 newdn->numDbIds = in->numDbIds;
368 369 }
369 370 if (in->next != NULL) {
370 371 newdn->next = (__nis_object_dn_t *)s_calloc(1,
371 372 sizeof (__nis_object_dn_t));
372 373 if (newdn->next == NULL)
373 374 return (1);
374 375 newdn = newdn->next;
375 376 in = in->next;
376 377 } else {
377 378 return (0);
378 379 }
379 380 } /* End of while on in */
380 381
381 382 return (0);
382 383 }
383 384
384 385 /*
385 386 * FUNCTION: free_yp_domain_context
386 387 *
387 388 * Frees __yp_domain_context_t
388 389 *
389 390 * INPUT: __yp_domain_context_t
390 391 */
391 392 void
392 393 free_yp_domain_context(__yp_domain_context_t *domains)
393 394 {
394 395 int i;
395 396
396 397 if (domains != NULL) {
397 398 for (i = 0; i < domains->numDomains; i++) {
398 399 if (domains->domains[i] != NULL) {
399 400 free(domains->domains[i]);
400 401 domains->domains[i] = NULL;
401 402 }
402 403 if (domains->domainLabels[i] != NULL) {
403 404 free(domains->domainLabels[i]);
404 405 domains->domainLabels[i] = NULL;
405 406 }
406 407 }
407 408 domains->domains = NULL;
408 409 domains->domainLabels = NULL;
409 410 for (i = 0; i < domains->numYppasswdd; i++) {
410 411 if (domains->yppasswddDomainLabels[i] != NULL) {
411 412 free(domains->yppasswddDomainLabels[i]);
412 413 domains->yppasswddDomainLabels[i] =
413 414 NULL;
414 415 }
415 416 }
416 417 domains->yppasswddDomainLabels = NULL;
417 418 domains->numDomains = 0;
418 419 domains = NULL;
419 420 }
420 421 }
421 422
422 423 /*
423 424 * FUNCTION: second_parser_pass
424 425 *
425 426 * Prepares the linked list of table_mappings for processing
426 427 * by finish_parse(), adding, merging and deleting structures
↓ open down ↓ |
275 lines elided |
↑ open up ↑ |
427 428 * as necessary. Also adds dummy objectDN info. for splitField's.
428 429 *
429 430 * RETURN VALUE: 0 on success, > 0 on failure.
430 431 */
431 432 int
432 433 second_parser_pass(__nis_table_mapping_t **table_mapping)
433 434 {
434 435 __nis_table_mapping_t *t, *t2;
435 436 __nis_table_mapping_t *t_new = NULL, *tg;
436 437 __nis_table_mapping_t *prev = NULL;
437 - __nis_object_dn_t *objectDN;
438 438 char *objs, *dom;
439 439 char *objName = NULL;
440 440 char *lasts;
441 441 char *tobj, *alias, *dupalias, *tmp;
442 442 char *myself = "second_parser_pass";
443 443 int i = 0, len;
444 - int remove_t = 0;
445 - int add_t = 0;
446 444
447 445 prev = NULL;
448 446 for (t = *table_mapping; t != NULL; ) {
449 447 /*
450 448 * Temporarily using this field to flag deletion.
451 449 * 0 : don't delete
452 450 * 1 : delete
453 451 * The mapping structure will be deleted in final_parser_pass
454 452 */
455 453 t->isMaster = 0;
456 454
457 455 if (!t->dbId) {
458 456 p_error = parse_bad_map_error;
459 457 logmsg(MSG_NOTIMECHECK, LOG_ERR,
460 458 "%s: no dbId field", myself);
461 459 return (1);
462 460 }
463 461 tg = NULL;
464 462 dom = strchr(t->dbId, COMMA_CHAR);
465 463 if (t->objName != NULL) {
466 464 objName = strdup(t->objName);
467 465 if (objName == NULL) {
468 466 p_error = parse_no_mem_error;
469 467 logmsg(MSG_NOMEM, LOG_ERR,
470 468 "%s: Cannot allocate memory for objName",
471 469 myself);
472 470 return (1);
473 471 }
474 472 objs = (char *)strtok_r(objName, " ", &lasts);
475 473 /* Get the generic mapping */
476 474 if (dom != NULL) {
477 475 tg = find_table_mapping(t->dbId, dom - t->dbId,
478 476 *table_mapping);
479 477 }
480 478 } else {
481 479 objs = NULL;
482 480 if (dom == NULL) {
483 481 t->objName = s_strndup(t->dbId,
484 482 strlen(t->dbId));
485 483 if (!t->objName) {
486 484 logmsg(MSG_NOMEM, LOG_ERR,
487 485 "%s: Cannot allocate memory for "
488 486 "t->objName", myself);
489 487 objs = NULL;
490 488 return (2);
491 489 }
492 490 } else {
493 491 /* Force relationship for domain specific */
494 492
495 493 /* Get the generic mapping */
496 494 tg = find_table_mapping(t->dbId, dom - t->dbId,
497 495 *table_mapping);
498 496 if (tg == NULL || tg->objName == NULL) {
499 497 /* If not found, use dbId for objName */
500 498 t->objName = s_strndup(t->dbId,
501 499 strlen(t->dbId));
502 500 if (t->objName == NULL) {
503 501 logmsg(MSG_NOMEM, LOG_ERR,
504 502 "%s: Cannot allocate memory for t->objName",
505 503 myself);
506 504 return (2);
507 505 }
508 506 } else {
509 507 dom++;
510 508 tobj = s_strndup(tg->objName,
511 509 strlen(tg->objName));
512 510 if (tobj == NULL) {
513 511 logmsg(MSG_NOMEM, LOG_ERR,
514 512 "%s: Cannot allocate memory for t->objName",
515 513 myself);
516 514 return (2);
517 515 }
518 516 alias = (char *)strtok_r(tobj, " ",
519 517 &lasts);
520 518
521 519 /* Loop 'breaks' on errors */
522 520 while (alias) {
523 521 tmp = NULL;
524 522 dupalias = s_strndup(alias,
525 523 strlen(alias));
526 524 if (!dupalias)
527 525 break;
528 526 if (getfullmapname(&dupalias,
529 527 dom)) {
530 528 i = 1;
531 529 break;
532 530 }
533 531 if (t->objName == NULL)
534 532 t->objName = dupalias;
535 533 else {
536 534 len = strlen(t->objName)
537 535 + strlen(dupalias) +
538 536 2;
539 537 tmp = s_calloc(1, len);
540 538 if (tmp == NULL)
541 539 break;
542 540 snprintf(tmp, len,
543 541 "%s %s",
544 542 t->objName,
545 543 dupalias);
546 544 free(dupalias);
547 545 dupalias = NULL;
548 546 free(t->objName);
549 547 t->objName = tmp;
550 548 }
551 549 alias = (char *)strtok_r(NULL,
552 550 " ", &lasts);
553 551 }
554 552
555 553 if (tobj)
556 554 free(tobj);
557 555
558 556 if (alias ||
559 557 (objName = s_strdup(t->objName))
560 558 == NULL) {
561 559 if (i)
562 560 logmsg(MSG_NOTIMECHECK,
563 561 LOG_ERR,
564 562 "%s: getfullmapname failed for %s for domain \"%s\"",
565 563 myself, dupalias,
566 564 dom);
567 565 else {
568 566 p_error =
569 567 parse_no_mem_error;
570 568 logmsg(MSG_NOMEM,
571 569 LOG_ERR,
572 570 "%s: Cannot allocate memory",
573 571 myself);
574 572 }
575 573 if (dupalias)
576 574 free(dupalias);
577 575 if (t->objName)
578 576 free(t->objName);
579 577 return (2);
580 578
581 579 }
582 580 objs = (char *)strtok_r(objName, " ",
583 581 &lasts);
584 582 }
585 583 }
586 584 }
587 585
588 586 if (tg != NULL) {
589 587 if (merge_table_mapping(tg, t)) {
590 588 logmsg(MSG_NOTIMECHECK, LOG_ERR,
591 589 "Error merging information from the %s to the %s mapping structure",
592 590 tg->dbId, t->dbId);
593 591 objs = NULL;
594 592 if (objName)
595 593 free(objName);
596 594 return (1);
597 595 }
598 596 }
599 597
600 598 /*
601 599 * If objName is "map1 map2" then do the second pass.
602 600 * If it is just "map1" however skip the expansion.
603 601 * Also skip it if t->objName is null.
604 602 */
605 603 if (objs && strncasecmp(objs, t->objName,
606 604 strlen(t->objName))) {
607 605 t2 = find_table_mapping(objs, strlen(objs),
608 606 *table_mapping);
609 607 if (t2) {
610 608 if (merge_table_mapping(t, t2)) {
611 609 logmsg(MSG_NOTIMECHECK, LOG_ERR,
612 610 "Error merging information from the %s to the %s mapping structure",
613 611 t->dbId, t2->dbId);
614 612 objs = NULL;
615 613 if (objName)
616 614 free(objName);
617 615 return (1);
618 616 }
619 617 t->isMaster = 1;
620 618 } else {
621 619 t_new = new_merged_mapping(objs, t);
622 620 if (t_new) {
623 621 t->isMaster = 1;
624 622 if (prev != NULL)
625 623 prev->next = t_new;
626 624 else
627 625 *table_mapping = t_new;
628 626 prev = t_new;
629 627 prev->next = t;
630 628 } else {
631 629 logmsg(MSG_NOTIMECHECK, LOG_ERR,
632 630 "Error creating a new mapping structure %s",
633 631 objs);
634 632 objs = NULL;
635 633 if (objName)
636 634 free(objName);
637 635 return (1);
638 636 }
639 637 }
640 638 while ((objs = (char *)strtok_r(NULL, " ", &lasts))
641 639 != NULL) {
642 640 t2 = find_table_mapping(objs, strlen(objs),
643 641 *table_mapping);
644 642 if (t2) {
645 643 if (merge_table_mapping(t, t2)) {
646 644 logmsg(MSG_NOTIMECHECK, LOG_ERR,
647 645 "Error merging information from the %s to the %s mapping structure",
648 646 t->dbId, t2->dbId);
649 647 objs = NULL;
650 648 if (objName)
651 649 free(objName);
652 650 return (1);
653 651 }
654 652 t->isMaster = 1;
655 653 } else {
656 654 /*
657 655 * create a new t_map with dbId = objs
658 656 * and copy t->* into new t_map
659 657 */
660 658 t_new = new_merged_mapping(objs, t);
661 659 if (t_new) {
662 660 t->isMaster = 1;
663 661 if (prev != NULL)
664 662 prev->next = t_new;
665 663 else
666 664 *table_mapping = t_new;
667 665 prev = t_new;
668 666 prev->next = t;
669 667 } else {
670 668 logmsg(MSG_NOTIMECHECK, LOG_ERR,
671 669 "Error creating a new mapping structure %s",
672 670 objs);
673 671 objs = NULL;
674 672 if (objName)
675 673 free(objName);
676 674 return (1);
677 675 }
678 676 }
679 677 }
680 678 } /* if objs!= NULL */
681 679
682 680 prev = t;
683 681 t = t->next;
684 682
685 683 if (objName) {
686 684 free(objName);
687 685 objName = NULL;
688 686 objs = NULL;
689 687 }
690 688 } /* for t = table_mapping loop */
691 689 return (0);
692 690 }
693 691
694 692 __nis_table_mapping_t *
695 693 new_merged_mapping(const char *match,
696 694 __nis_table_mapping_t *intbl)
697 695 {
698 696
699 697 __nis_table_mapping_t *outtable = NULL;
700 698
701 699 outtable = (__nis_table_mapping_t *)
702 700 s_calloc(1, sizeof (__nis_table_mapping_t));
703 701 if (outtable == NULL)
704 702 return (NULL);
705 703 initialize_table_mapping(outtable);
706 704 outtable->dbId = s_strndup(match, strlen(match));
707 705 if (outtable->dbId == NULL) {
708 706 free_table_mapping(outtable);
709 707 outtable = NULL;
710 708 return (NULL);
711 709 }
712 710 if (merge_table_mapping(intbl, outtable)) {
713 711 free_table_mapping(outtable);
714 712 outtable = NULL;
715 713 }
716 714 return (outtable);
717 715 }
718 716
719 717 /*
720 718 * FUNCTION: final_parser_pass
721 719 *
722 720 * completes the final expansion of t_map structures linked list.
723 721 * all structures will have a non-null objPath as well as a objName
724 722 * in the form of "mapname . domainname ." or "splitfieldname .
725 723 * domainname .".
726 724 *
727 725 * RETURN VALUE: 0 on success, -1 on failure, -2 on fatal error.
728 726 */
729 727 int
730 728 final_parser_pass(
731 729 __nis_table_mapping_t **table_mapping,
732 730 __yp_domain_context_t *ypDomains)
733 731 {
734 732 __nis_table_mapping_t *t;
735 733 __nis_table_mapping_t *t1, *returned_map;
736 734 __nis_table_mapping_t *prev = NULL;
737 735 int i;
738 736 char *myself = "final_parser_pass";
739 737 int nm;
740 738 bool_t r;
741 739 int del_tbl_flag = 0;
742 740
743 741 if (ypDomains) {
744 742 if (!ypDomains->numDomains) {
745 743 p_error = parse_internal_error;
746 744 logmsg(MSG_NOTIMECHECK, LOG_ERR,
747 745 "%s:No domains specified.", myself);
748 746 return (-1);
749 747 }
750 748 } else {
751 749 p_error = parse_internal_error;
752 750 logmsg(MSG_NOTIMECHECK, LOG_ERR,
753 751 "%s:No domain structure supplied.", myself);
754 752 return (-1);
755 753 }
756 754 prev = NULL;
757 755
758 756 for (t = *table_mapping; t != NULL; ) {
759 757
760 758 /* Delete if marked for deletion by second_parser_pass */
761 759 if (t->isMaster == 1) {
762 760 if (prev != NULL)
763 761 prev->next = t->next;
764 762 else
765 763 *table_mapping = t->next;
766 764 t1 = t;
767 765 t = t->next;
768 766 free_table_mapping(t1);
769 767 continue;
770 768 }
771 769
772 770 if (!t->objName && t->dbId) {
773 771 t->objName = s_strndup(t->dbId, strlen(t->dbId));
774 772 if (!t->objName) {
775 773 logmsg(MSG_NOMEM, LOG_ERR,
776 774 "%s:Could not allocate.", myself);
777 775 return (-1);
778 776 }
779 777 }
780 778 i = ypDomains->numDomains;
781 779 while (i > 0) {
782 780 if (i == 1) {
783 781 /* modify existing table_mapping's */
784 782 nm = checkfullmapname(t->dbId,
785 783 ypDomains->domainLabels[0],
786 784 table_mapping, &returned_map);
787 785 if (nm == 1) {
788 786 /* delete this mapping structure */
789 787 logmsg(MSG_NOTIMECHECK,
790 788 LOG_WARNING,
791 789 "Mapping structure %s,%s "
792 790 "already exists.",
793 791 t->dbId,
794 792 ypDomains->domainLabels[0]);
795 793 if (merge_table_mapping(t,
796 794 returned_map)) {
797 795 logmsg(MSG_NOTIMECHECK, LOG_ERR,
798 796 "Error merging information "
799 797 "from the %s to the %s "
800 798 "mapping structure.",
801 799 t->dbId,
802 800 returned_map->dbId);
803 801 return (-1);
804 802 }
805 803 if (del_tbl_flag == 0)
806 804 del_tbl_flag = 1;
807 805 } else if (nm == -1) {
808 806 logmsg(MSG_NOTIMECHECK, LOG_ERR,
809 807 "Error searching for %s,%s structure",
810 808 t->dbId,
811 809 ypDomains->domainLabels[0]);
812 810 return (-1);
813 811 } else if (nm == 0 || nm == 2) {
814 812 if ((append_domainContext(&t,
815 813 ypDomains->domainLabels[0],
816 814 ypDomains->domains[0])) != 0) {
817 815 logmsg(MSG_NOTIMECHECK, LOG_ERR,
818 816 "Error appending domainContext %s",
819 817 ypDomains->domainLabels[0]);
820 818 return (-1);
821 819 }
822 820 del_tbl_flag = 0;
823 821 }
824 822 } else { /* if (i > 1) */
825 823 /* need to create new table_mapping's */
826 824 nm = checkfullmapname(t->dbId,
827 825 ypDomains->domainLabels[i - 1],
828 826 table_mapping, &returned_map);
829 827 if (nm == -1) {
830 828 logmsg(MSG_NOTIMECHECK, LOG_ERR,
831 829 "Error searching for %s,%s structure",
832 830 t->dbId,
833 831 ypDomains->domainLabels[i - 1]);
834 832 return (-1);
835 833 } else if (nm == 0) {
836 834 t1 = new_merged_mapping(t->dbId, t);
837 835 /* we clone ourselves */
838 836 if (t1) {
839 837 if ((append_domainContext(&t1,
840 838 ypDomains->domainLabels[i - 1],
841 839 ypDomains->domains[i - 1])) != 0) {
842 840 logmsg(MSG_NOTIMECHECK, LOG_ERR,
843 841 "Error appending domainContext %s",
844 842 ypDomains->domainLabels[i - 1]);
845 843 free(t1);
846 844 return (-1);
847 845 }
848 846 if (prev != NULL) {
849 847 t1->next = prev->next;
850 848 prev->next = t1;
851 849 prev = prev->next;
852 850 } else {
853 851 t1->next =
854 852 *table_mapping;
855 853 *table_mapping = t1;
856 854 prev = t1;
857 855 }
858 856 } else { /* if !t1 */
859 857 p_error = parse_internal_error;
860 858 logmsg(MSG_NOTIMECHECK, LOG_ERR,
861 859 "%s:Could not create new table -"
862 860 " check all instances of %s for errors",
863 861 myself, t->dbId);
864 862 return (-1);
865 863 }
866 864 } else if (nm == 1) {
867 865 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
868 866 "Mapping structure %s,%s already exists.",
869 867 t->dbId,
870 868 ypDomains->domainLabels[i - 1]);
871 869 /*
872 870 * We should be deleting this, but can't
873 871 * really do it here, because we need to
874 872 * match with the domainLabels[0] case
875 873 * too. So we will just flag it for now.
876 874 */
877 875 if (merge_table_mapping(t,
878 876 returned_map)) {
879 877 logmsg(MSG_NOTIMECHECK, LOG_ERR,
880 878 "Error merging information from the %s to the %s mapping structure.",
881 879 t->dbId,
882 880 returned_map->dbId);
883 881 return (-1);
884 882 }
885 883 del_tbl_flag = 1;
886 884 } else if (nm == 2) {
887 885 if ((append_domainContext(&t,
888 886 ypDomains->domainLabels[i - 1],
889 887 ypDomains->domains[i - 1])) != 0) {
890 888 logmsg(MSG_NOTIMECHECK, LOG_ERR,
891 889 "Error appending domainContext %s",
892 890 ypDomains->domainLabels[i - 1]);
893 891 return (-1);
894 892 }
895 893 } /* end of "if (nm == 0)" */
896 894 } /* end of else if (i > 1) */
897 895
898 896
899 897 /*
900 898 * 'merge_table_mapping' only copies unexpanded
901 899 * objectDN values into returned_map. Hence,
902 900 * read.base and write.base in returned_map
903 901 * needs to be expanded.
904 902 */
905 903 if (nm == 1 && returned_map && returned_map->objectDN) {
906 904 r = make_fqdn(
907 905 returned_map->objectDN,
908 906 ypDomains->domains[i - 1]);
909 907 if (r == TRUE &&
910 908 returned_map->objectDN->write.base) {
911 909 r = make_full_dn(
912 910 &returned_map->objectDN->write.base,
913 911 ypDomains->domains[i - 1]);
914 912 }
915 913
916 914 if (r == FALSE) {
917 915 logmsg(MSG_NOTIMECHECK, LOG_ERR,
918 916 "Error appending domainContext "
919 917 "%s to %s",
920 918 ypDomains->domainLabels[i - 1],
921 919 returned_map->dbId);
922 920 return (-2);
923 921 }
924 922 }
925 923 i--;
926 924 } /* end of while i > 0 loop */
927 925
928 926 if (del_tbl_flag == 1) {
929 927 if (prev != NULL) {
930 928 prev->next = t->next;
931 929 free_table_mapping(t);
932 930 t = prev->next;
933 931 } else {
934 932 *table_mapping = t->next;
935 933 free_table_mapping(t);
936 934 t = *table_mapping;
937 935 }
938 936 del_tbl_flag = 0;
939 937 } else {
940 938 prev = t;
941 939 t = t->next;
942 940 }
943 941 } /* end of table mapping loop */
944 942
945 943 for (t = *table_mapping; t != NULL; t = t->next) {
946 944 if (!t->dbId) {
947 945 logmsg(MSG_NOTIMECHECK, LOG_ERR,
948 946 "%s:Fatal error: structure with no dbId found.",
949 947 myself);
950 948 return (-2);
951 949 }
952 950 append_dot(&t->dbId);
953 951 if (!t->objectDN) {
954 952 p_error = parse_internal_error;
955 953 logmsg(MSG_NOTIMECHECK, LOG_ERR,
956 954 "%s:No objectDN for %s.", myself, t->dbId);
957 955 return (-1);
958 956 }
959 957 }
960 958
961 959 return (0);
962 960 }
963 961
964 962 /*
965 963 * FUNCTION: append_mapping_rule
966 964 *
967 965 * Appends mapping rules to a table_mapping structure
968 966 * with previously existing rules. flag controls whether
969 967 * the functions works on the rules From or To LDAP.
970 968 *
971 969 * RETURN VALUE: 0 on success, >= 1 on failure.
972 970 */
973 971
974 972 static int
975 973 append_mapping_rule(__nis_mapping_rule_t *src_rule,
976 974 __nis_table_mapping_t *dst, int flag)
977 975 {
978 976 __nis_mapping_rule_t **rules = NULL;
979 977
980 978 if (flag == 0) {
981 979 if (dst->ruleFromLDAP == NULL) {
982 980 p_error = parse_internal_error;
983 981 return (1);
984 982 }
985 983 rules = (__nis_mapping_rule_t **)
986 984 s_realloc(dst->ruleFromLDAP,
987 985 (dst->numRulesFromLDAP + 1) *
988 986 sizeof (__nis_mapping_rule_t *));
989 987 if (rules == NULL)
990 988 return (2);
991 989 dst->ruleFromLDAP = rules;
992 990 rules[dst->numRulesFromLDAP] = dup_mapping_rule(src_rule);
993 991 if (rules[dst->numRulesFromLDAP] == NULL) {
994 992 p_error = parse_no_mem_error;
995 993 return (2);
996 994 }
997 995 dst->numRulesFromLDAP++;
998 996 } else if (flag == 1) {
999 997 if (dst->ruleToLDAP == NULL) {
1000 998 p_error = parse_internal_error;
1001 999 return (1);
1002 1000 }
1003 1001 rules = (__nis_mapping_rule_t **)
1004 1002 s_realloc(dst->ruleToLDAP,
1005 1003 (dst->numRulesToLDAP + 1) *
1006 1004 sizeof (__nis_mapping_rule_t *));
1007 1005 if (rules == NULL)
1008 1006 return (2);
1009 1007 dst->ruleToLDAP = rules;
1010 1008 rules[dst->numRulesToLDAP] = dup_mapping_rule(src_rule);
1011 1009 if (rules[dst->numRulesToLDAP] == NULL) {
1012 1010 p_error = parse_no_mem_error;
1013 1011 return (2);
1014 1012 }
1015 1013 dst->numRulesToLDAP++;
1016 1014 } else
1017 1015 return (1);
1018 1016
1019 1017 return (0);
1020 1018 }
1021 1019
1022 1020 /*
1023 1021 * FUNCTION: check_domain_specific_order
1024 1022 *
1025 1023 * Makes sure that an attribute with explicitly specified
1026 1024 * nisLDAPdomainContext is found before its non-domain
1027 1025 * specific counterpart.
1028 1026 *
1029 1027 * RETURN VALUE: 0 normal exit
1030 1028 * 1 if domain specific attribute found
1031 1029 * after non-domain specific one.
1032 1030 * -1 some error condition
1033 1031 */
1034 1032
1035 1033 int
1036 1034 check_domain_specific_order(const char *sd,
1037 1035 config_key attrib_num,
1038 1036 __nis_table_mapping_t *table_mapping,
1039 1037 __yp_domain_context_t *ypDomains)
1040 1038 {
1041 1039 __nis_table_mapping_t *t;
1042 1040 char *myself = "check_domain_specific_order";
1043 1041 char *type;
1044 1042 char *dbId = 0;
1045 1043 int i, len;
1046 1044 int match = 0;
1047 1045
1048 1046 if (ypDomains) {
1049 1047 if (!ypDomains->numDomains) {
1050 1048 logmsg(MSG_NOTIMECHECK, LOG_ERR,
1051 1049 "%s:No domains specified.", myself);
1052 1050 return (-1);
1053 1051 }
1054 1052 } else {
1055 1053 logmsg(MSG_NOTIMECHECK, LOG_ERR,
1056 1054 "%s:No domain structure supplied.", myself);
1057 1055 return (-1);
1058 1056 }
1059 1057
1060 1058 for (i = 0; i < ypDomains->numDomains; i++) {
1061 1059 for (t = table_mapping; t != NULL; t = t->next) {
1062 1060 len = strlen(sd);
1063 1061 if ((strcasecmp(t->dbId, sd) == 0) && (len ==
1064 1062 strlen(t->dbId)))
1065 1063 /* prevent from matching against itself */
1066 1064 continue;
1067 1065 dbId = s_strndup(t->dbId, strlen(t->dbId));
1068 1066 if (dbId == NULL) {
1069 1067 logmsg(MSG_NOMEM, LOG_ERR,
1070 1068 "%s:Memory allocation error.", myself);
1071 1069 return (-1);
1072 1070 }
1073 1071
1074 1072 if (getfullmapname(&dbId,
1075 1073 ypDomains->domainLabels[i])) {
1076 1074 logmsg(MSG_NOTIMECHECK, LOG_ERR,
1077 1075 "Error getting fully qualified name for %s",
1078 1076 dbId);
1079 1077 free(dbId);
1080 1078 return (-1);
1081 1079 }
1082 1080 if ((strcasecmp(dbId, sd) == 0) && (len ==
1083 1081 strlen(dbId))) {
1084 1082 match = 0;
1085 1083 switch (attrib_num) {
1086 1084 case key_yp_map_flags:
1087 1085 if (t->usedns_flag != 0 ||
1088 1086 t->securemap_flag != 0)
1089 1087 match = 1;
1090 1088 type = YP_MAP_FLAGS;
1091 1089 break;
1092 1090 case key_yp_comment_char:
1093 1091 if (t->commentChar !=
1094 1092 DEFAULT_COMMENT_CHAR)
1095 1093 match = 1;
1096 1094 type = YP_COMMENT_CHAR;
1097 1095 break;
1098 1096 case key_yp_repeated_field_separators:
1099 1097 if (strcmp(t->separatorStr,
1100 1098 DEFAULT_SEP_STRING) != 0)
1101 1099 match = 1;
1102 1100 type =
1103 1101 YP_REPEATED_FIELD_SEPARATORS;
1104 1102 break;
1105 1103 case key_yp_name_fields:
1106 1104 if (t->e && t->numColumns)
1107 1105 match = 1;
1108 1106 type = YP_NAME_FIELDS;
1109 1107 case key_yp_split_field:
1110 1108 if (t->e && t->numColumns)
1111 1109 match = 1;
1112 1110 type = YP_SPLIT_FIELD;
1113 1111 break;
1114 1112 case key_yp_db_id_map:
1115 1113 if (t->objName)
1116 1114 match = 1;
1117 1115 type = YP_DB_ID_MAP;
1118 1116 break;
1119 1117 case key_yp_entry_ttl:
1120 1118 if (t->initTtlLo !=
1121 1119 (time_t)NO_VALUE_SET)
1122 1120 match = 1;
1123 1121 type = YP_ENTRY_TTL;
1124 1122 break;
1125 1123 case key_yp_ldap_object_dn:
1126 1124 if (t->objectDN)
1127 1125 match = 1;
1128 1126 type = YP_LDAP_OBJECT_DN;
1129 1127 break;
1130 1128 case key_nis_to_ldap_map:
1131 1129 if (t->ruleToLDAP)
1132 1130 match = 1;
1133 1131 type = NIS_TO_LDAP_MAP;
1134 1132 break;
1135 1133 case key_ldap_to_nis_map:
1136 1134 if (t->ruleFromLDAP)
1137 1135 match = 1;
1138 1136 type = LDAP_TO_NIS_MAP;
1139 1137 break;
1140 1138 default:
1141 1139 type = "unknown";
1142 1140 match = 0;
1143 1141 break;
1144 1142 } /* end of switch */
1145 1143 if (match) {
1146 1144 logmsg(MSG_NOTIMECHECK, LOG_ERR,
1147 1145 "Relative attribute '%s' of type '%s' found before fully qualified one '%s'",
1148 1146 t->dbId, type, sd);
1149 1147 free(dbId);
1150 1148 dbId = NULL;
1151 1149 return (1);
1152 1150 }
1153 1151 } /* end of strncasecmp */
1154 1152 free(dbId);
1155 1153 dbId = NULL;
1156 1154 } /* end of t loop */
1157 1155 } /* end of i loop */
1158 1156 if (dbId)
1159 1157 free(dbId);
1160 1158 dbId = NULL;
1161 1159 return (0);
1162 1160 }
1163 1161
1164 1162 int
1165 1163 getfullmapname(char **mapname, const char *domainname)
1166 1164 {
1167 1165 char *maps = *mapname;
1168 1166 int maplen = strlen(maps);
1169 1167 int domainlen = strlen(domainname);
1170 1168
1171 1169 if (!maplen || !domainlen ||
1172 1170 maps[maplen - 1] == PERIOD_CHAR)
1173 1171 return (1);
1174 1172 else if (strchr(maps, COMMA_CHAR)) {
1175 1173 /* map already has a domain part, do nothing */
1176 1174 return (0);
1177 1175 } else {
1178 1176 append_comma(&maps);
1179 1177 maplen = strlen(maps);
1180 1178 maps = realloc(maps, (maplen + domainlen + 1));
1181 1179 if (maps != NULL) {
1182 1180 if (strlcat(maps, domainname, (maplen + domainlen + 1))
1183 1181 >= (maplen + domainlen + 1))
1184 1182 return (1);
1185 1183 *mapname = maps;
1186 1184 return (0);
1187 1185 } else
1188 1186 return (1);
1189 1187 }
1190 1188 }
1191 1189
1192 1190 /*
1193 1191 * FUNCTION: checkfullmapname
1194 1192 *
1195 1193 * Tries to find out if by appending the table mapping structures
1196 1194 * with each of the provided nisLDAPdomainContexts, an already
1197 1195 * existing fqdn table mapping structure results. That would be the
1198 1196 * case when a full qualified domain specific attribute was present.
1199 1197 *
1200 1198 * Note that per NISLDAPmapping(4) such an attribute MUST be listed
1201 1199 * in the mapping file BEFORE its non-fqdn counterpart.
1202 1200 *
1203 1201 * RETURNS: 0 normal exit, 1 if an existing structure found, -1 for all
1204 1202 * errors, 2 if already fqdn. If returning 1 the existing structure is
1205 1203 * in found_map.
1206 1204 */
1207 1205
1208 1206 int
1209 1207 checkfullmapname(const char *mapname, const char *domainname,
1210 1208 __nis_table_mapping_t **table_mapping,
1211 1209 __nis_table_mapping_t **found_map)
1212 1210 {
1213 1211 char *map;
1214 1212
1215 1213 *found_map = NULL;
1216 1214
1217 1215 /* This function does not alter mapname */
1218 1216
1219 1217 if (!mapname || !domainname || *table_mapping == NULL)
1220 1218 return (-1);
1221 1219
1222 1220 if (strchr(mapname, COMMA_CHAR))
1223 1221 return (2);
1224 1222
1225 1223 if ((map = s_strndup(mapname, strlen(mapname))) == 0)
1226 1224 return (-1);
1227 1225
1228 1226 if (getfullmapname(&map, domainname)) {
1229 1227 free(map);
1230 1228 return (-1);
1231 1229 }
1232 1230
1233 1231 *found_map = find_table_mapping(map, strlen(map), *table_mapping);
1234 1232 if (*found_map) {
1235 1233 free(map);
1236 1234 return (1);
1237 1235 }
1238 1236
1239 1237 free(map);
1240 1238 return (0);
1241 1239 }
1242 1240
1243 1241 /*
1244 1242 * FUNCTION: append_domainContext
1245 1243 *
1246 1244 * Higher level function to append the domains to the appropriate
1247 1245 * fields in a table mapping structure. Calls either getfullmapname()
1248 1246 * or make_full_dn() to do the actual append.
1249 1247 *
1250 1248 * RETURNS: 0 on success, -1 on any error.
1251 1249 */
1252 1250
1253 1251 int
1254 1252 append_domainContext(__nis_table_mapping_t **table_map,
1255 1253 char *DomainLabel, char *Domain)
1256 1254 {
1257 1255 __nis_table_mapping_t *tmp_map = *table_map;
1258 1256 char *lasts;
1259 1257 char *tmp_dbId = NULL;
1260 1258 char *id = NULL;
1261 1259 int domain_specific = 0;
1262 1260 char *myself = "append_domainContext";
1263 1261
1264 1262 if (!DomainLabel || !Domain || !tmp_map)
1265 1263 return (-1);
1266 1264 if (tmp_map->dbId == NULL || tmp_map->objName == NULL) {
1267 1265 p_error = parse_bad_map_error;
1268 1266 return (-1);
1269 1267 }
1270 1268 tmp_dbId = s_strndup(tmp_map->dbId, strlen(tmp_map->dbId));
1271 1269 if (!tmp_dbId)
1272 1270 return (-1);
1273 1271 if (strchr(tmp_map->dbId, COMMA_CHAR)) {
1274 1272 domain_specific = 1;
1275 1273 id = (char *)strtok_r(tmp_dbId, COMMA_STRING, &lasts);
1276 1274 if (id)
1277 1275 id = (char *)strtok_r(NULL, COMMA_STRING, &lasts);
1278 1276 else {
1279 1277 free(tmp_dbId);
1280 1278 return (-1);
1281 1279 }
1282 1280 if (!id) {
1283 1281 free(tmp_dbId);
1284 1282 return (-1);
1285 1283 }
1286 1284 if (strcasecmp(id, DomainLabel)) {
1287 1285 free(tmp_dbId);
1288 1286 return (0);
1289 1287 }
1290 1288 } else {
1291 1289 if (getfullmapname(&tmp_map->dbId, DomainLabel)) {
1292 1290 free(tmp_dbId);
1293 1291 return (-1);
1294 1292 }
1295 1293 append_dot(&tmp_map->dbId);
1296 1294 }
1297 1295 if (tmp_dbId)
1298 1296 free(tmp_dbId);
1299 1297 tmp_dbId = NULL;
1300 1298
1301 1299 if (getfullmapname(&tmp_map->objName, DomainLabel))
1302 1300 return (-1);
1303 1301 append_dot(&tmp_map->objName);
1304 1302
1305 1303 /*
1306 1304 * If domain specific mapping doesn't have objectDN,
1307 1305 * then don't touch. Most probably, pass for the generic mapping
1308 1306 * will handle this by coping over it's own objectDN
1309 1307 */
1310 1308 if (domain_specific && tmp_map->objectDN == NULL)
1311 1309 return (0);
1312 1310
1313 1311 if (tmp_map->objectDN == NULL) {
1314 1312 /* Allocate memory to objectDN */
1315 1313 tmp_map->objectDN = (__nis_object_dn_t *)
1316 1314 s_calloc(1, sizeof (__nis_object_dn_t));
1317 1315 if (tmp_map->objectDN == NULL) {
1318 1316 logmsg(MSG_NOMEM, LOG_ERR,
1319 1317 "%s: Cannot allocate memory for objectDN",
1320 1318 myself);
1321 1319 return (2);
1322 1320 }
1323 1321 tmp_map->objectDN->read.base = NULL;
1324 1322 tmp_map->objectDN->write.base = NULL;
1325 1323 tmp_map->objectDN->read.attrs = NULL;
1326 1324 tmp_map->objectDN->write.attrs = NULL;
1327 1325 tmp_map->objectDN->read.scope = LDAP_SCOPE_ONELEVEL;
1328 1326 tmp_map->objectDN->write.scope = LDAP_SCOPE_UNKNOWN;
1329 1327 }
1330 1328
1331 1329 if (!make_fqdn(tmp_map->objectDN, Domain))
1332 1330 return (-1);
1333 1331 if (tmp_map->objectDN->write.base) {
1334 1332 if (!make_full_dn(&tmp_map->objectDN->write.base, Domain))
1335 1333 return (-1);
1336 1334 }
1337 1335
1338 1336 return (0);
1339 1337 }
↓ open down ↓ |
884 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX