Print this page
5910 libnisdb won't build with modern GCC
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnisdb/ldap_xdr.c
+++ new/usr/src/lib/libnisdb/ldap_xdr.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 (c) 2001 by Sun Microsystems, Inc.
24 25 * All rights reserved.
25 26 */
26 27
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 28 #include <string.h>
30 29 #include <sys/syslog.h>
31 30 #include <sys/types.h>
32 31 #include <rpc/types.h>
33 32 #include <rpc/xdr.h>
34 33 #include <rpcsvc/nis.h>
35 34
36 35 #include "db_mindex_c.h"
37 36
38 37 #include "ldap_xdr.h"
39 38 #include "ldap_util.h"
40 39
41 -extern bool_t xdr_nis_object();
40 +#include "nis_clnt.h"
42 41
43 42 /*
44 43 * In order not to change the on-disk NIS+ DB format, we need make sure
45 44 * that XDR does nothing for the new structures added to various C++
46 45 * classes.
47 46 */
48 47
49 48 bool_t
50 49 xdr___nis_table_mapping_t(XDR *xdrs, void *t) {
51 50 return (TRUE);
52 51 }
53 52
54 53 bool_t
55 54 xdr___nisdb_ptr_t(XDR *xdrs, void *ptr) {
56 55 return (TRUE);
57 56 }
58 57
59 58 bool_t
60 59 xdr___nisdb_dictionary_defer_t(XDR *xdrs, void *defer) {
61 60 return (TRUE);
62 61 }
63 62
64 63 bool_t
65 64 xdr___nisdb_rwlock_t(XDR *xdrs, void *rw) {
66 65 return (TRUE);
67 66 }
68 67
69 68 bool_t
70 69 xdr___nisdb_flag_t(XDR *xdrs, void *flag) {
71 70 return (TRUE);
72 71 }
73 72
74 73 /*
75 74 * Imported from rpc.nisd/nis_db.c
76 75 *
77 76 * Special abbreviated XDR string which knows that the namep parameter (mainly
78 77 * owner and group) has a trailing end which matches the last 'n' characters
79 78 * in the domainname part. It makes use of those common characters to
80 79 * encode/decode this information. We append an integer string to the
81 80 * name to be encoded which denotes the place in the domainname from where the
82 81 * common string starts. For example, if the name was "foo.my.domain." and the
83 82 * domainname was "my.domain.", the name would be encoded as "foo.10" because
84 83 * the length of the common part "my.domain." is 10.
85 84 */
86 85 bool_t
87 86 xdr_nis_name_abbrev(
88 87 XDR *xdrs,
89 88 nis_name *namep,
90 89 nis_name domainname) /* domainname field from the table */
91 90 {
92 91 size_t name_len, dom_len, min_len;
93 92 char buf[NIS_MAXNAMELEN];
94 93 char *name;
95 94 char *lenstr, *tmp;
96 95 int i;
97 96
98 97 switch (xdrs->x_op) {
99 98 case XDR_ENCODE:
100 99 /* Get the start of the common part */
101 100 name = *namep;
102 101 name_len = strlen(name);
103 102 if (name_len == 0)
104 103 return (xdr_nis_name(xdrs, namep));
105 104 dom_len = strlen(domainname);
106 105 min_len = (name_len < dom_len) ? name_len : dom_len;
107 106 for (i = 1; i <= min_len; i++) {
108 107 if (name[name_len - i] != domainname[dom_len - i])
109 108 break;
110 109 }
111 110 i--;
112 111 memcpy(buf, name, name_len - i);
113 112 sprintf(buf + name_len - i, ".%d", dom_len - i);
114 113 tmp = buf;
115 114 return (xdr_nis_name(xdrs, &tmp));
116 115
117 116 case XDR_DECODE:
118 117 tmp = buf;
119 118 if (!xdr_nis_name(xdrs, &tmp))
120 119 return (FALSE);
121 120 if ((buf[0] == NULL) || buf[strlen(buf) - 1] == '.') {
122 121 /* It is either a FQN or a NULL string */
123 122 if (*namep) {
124 123 strcpy(*namep, buf);
125 124 return (TRUE);
126 125 } else {
127 126 if ((*namep = strdup(buf)) == NULL)
128 127 return (FALSE);
129 128 else
130 129 return (TRUE);
131 130 }
132 131 }
133 132 /* Now concoct the new name */
134 133 if ((lenstr = strrchr(buf, '.')) == NULL) {
135 134 /* something went wrong here */
136 135 syslog(LOG_ERR,
137 136 "xdr_nis_name_abbrev: no dot found in %s", buf);
138 137 return (FALSE);
139 138 }
140 139 i = atoi(lenstr + 1);
141 140 strcpy(lenstr, domainname + i);
142 141 if (*namep) {
143 142 strcpy(*namep, buf);
144 143 } else {
145 144 if ((*namep = strdup(buf)) == NULL)
146 145 return (FALSE);
147 146 }
148 147 return (TRUE);
149 148
150 149 default:
151 150 return (xdr_nis_name(xdrs, namep));
152 151 }
153 152 }
154 153
155 154 /*
156 155 * Imported from rpc.nisd/nis_db.c
157 156 *
158 157 * special XDR for fetus object. We create the actual object from the
159 158 * "forming" object plus the table object. We create this special object to
160 159 * save the following components of the nis_object:
161 160 * zo_name and zo_domain: replaced by just the length field of 0. We had
162 161 * to keep the length field for backward compatibility. If we
163 162 * ever change the object format, we should fix this.
164 163 * zo_owner and zo_group: we condensed it by abbreviating the common part
165 164 * shared between the table object and the entry object
166 165 * en_type: Avoided altogether
167 166 * zo_type and other en_data: Avoided altogether.
168 167 *
169 168 * XXX: If the definition of nis_object ever changes, this should be changed.
170 169 */
171 170 bool_t
172 171 xdr_nis_fetus_object(
173 172 XDR *xdrs,
174 173 nis_object *objp, /* Entry object */
175 174 nis_object *tobj) /* Table object */
176 175 {
177 176 uint_t size;
178 177
179 178 if (xdrs->x_op == XDR_FREE)
180 179 return (xdr_nis_object(xdrs, objp));
181 180 if (!xdr_nis_oid(xdrs, &objp->zo_oid))
182 181 return (FALSE);
183 182
184 183 /*
185 184 * While encoding of zo_name, we put 0 in the length field, while for
186 185 * decoding, we get the name from the table object.
187 186 */
188 187 if (xdrs->x_op == XDR_ENCODE) {
189 188 size = 0;
190 189 if (!xdr_u_int(xdrs, &size))
191 190 return (FALSE);
192 191 } else {
193 192 if (!xdr_u_int(xdrs, &size))
194 193 return (FALSE);
195 194 if (size == 0) { /* shrinked format */
196 195 /* get the name from the table object */
197 196 if ((objp->zo_name = strdup(tobj->zo_name)) == NULL)
198 197 return (FALSE);
199 198 } else {
200 199 /*
201 200 * We are opening up the xdr_string implementation here
202 201 * because we called xdr_u_int() earlier.
203 202 */
204 203 if ((objp->zo_name = (char *)malloc(size + 1)) == NULL)
205 204 return (FALSE);
206 205 if (!xdr_opaque(xdrs, objp->zo_name, size))
207 206 return (FALSE);
208 207 }
209 208 }
210 209
211 210 /*
212 211 * We use the xdr_nis_name_abbrev() function for both owner
213 212 * and group which constructs the name from the domain name.
214 213 */
215 214 if (!xdr_nis_name_abbrev(xdrs, &objp->zo_owner, tobj->zo_domain))
216 215 return (FALSE);
217 216 if (!xdr_nis_name_abbrev(xdrs, &objp->zo_group, tobj->zo_domain))
218 217 return (FALSE);
219 218
220 219 /*
221 220 * While encoding of zo_domain, we put 0 in the length field, while for
222 221 * decoding, we get the name from the table object. Same as above for
223 222 * the name. Could have used a function instead.
224 223 */
225 224 if (xdrs->x_op == XDR_ENCODE) {
226 225 size = 0;
227 226 if (!xdr_u_int(xdrs, &size))
228 227 return (FALSE);
229 228 } else {
230 229 if (!xdr_u_int(xdrs, &size))
231 230 return (FALSE);
232 231 if (size == 0) { /* shrinked format */
233 232 /* get the name from the table object */
234 233 if ((objp->zo_domain = strdup(tobj->zo_domain)) == NULL)
235 234 return (FALSE);
236 235 } else {
237 236 /*
238 237 * We are opening up the xdr_string implementation here
239 238 * because we called xdr_u_int() earlier.
240 239 */
241 240 if ((objp->zo_domain = (char *)malloc(size + 1))
242 241 == NULL)
243 242 return (FALSE);
244 243 if (!xdr_opaque(xdrs, objp->zo_domain, size))
245 244 return (FALSE);
246 245 }
247 246 }
248 247
249 248 if (!xdr_u_int(xdrs, &objp->zo_access))
250 249 return (FALSE);
251 250 if (!xdr_u_int(xdrs, &objp->zo_ttl))
252 251 return (FALSE);
253 252
254 253 /*
255 254 * We know that this is an entry object, so we'll save all the entry_obj
256 255 * space because we can recreate it later.
257 256 */
258 257 if (xdrs->x_op == XDR_ENCODE)
259 258 return (TRUE);
260 259 /* Now for the DECODE case, just handcraft the entries and ignore XDR */
261 260 objp->zo_data.zo_type = NIS_ENTRY_OBJ;
262 261 if ((objp->zo_data.objdata_u.en_data.en_type =
263 262 strdup(tobj->zo_data.objdata_u.ta_data.ta_type)) == NULL)
264 263 return (FALSE);
265 264 objp->zo_data.objdata_u.en_data.en_cols.en_cols_val = NULL;
266 265 objp->zo_data.objdata_u.en_data.en_cols.en_cols_len = 0;
267 266 return (TRUE);
268 267 }
269 268
270 269 static const char *in_directory = "IN_DIRECTORY";
271 270
272 271 /*
273 272 * Given an input NIS+ object, create the kind
274 273 * of pseudo-entry_obj (with an XDR-encoded nis_object in the
275 274 * first column) that's stored in the DB. Note that:
276 275 *
277 276 * If the input object is an entry, it's assumed to have the
278 277 * columns moved up one step (col 0 in en_cols.en_cols_val[1],
279 278 * etc.). en_cols.en_cols_val[0] will be overwritten. The
280 279 * input object will be changed (some pointers set to zero,
281 280 * etc.) on exit.
282 281 *
283 282 * 'eo' is assumed to be a pointer to an empty entry_obj (or,
284 283 * at least, one that can be overwritten). It must not be a
285 284 * pointer to the entry_obj in 'obj'. If the input object is
286 285 * of a type other than entry, the 'eo' pointer must have
287 286 * en_cols.en_cols_val appropriately initialized to an array of
288 287 * (at least) length one.
289 288 *
290 289 * 'tobj' is a pointer to the table object for the table for
291 290 * which the entry_obj is destined. It's needed for entry objects,
292 291 * but unused for other object types.
293 292 */
294 293 entry_obj *
295 294 makePseudoEntryObj(nis_object *obj, entry_obj *eo, nis_object *tobj) {
296 295 int bufsize;
297 296 char *buf;
298 297 XDR xdrs;
299 298 bool_t xret;
300 299 uint_t ecl;
301 300 entry_col *ecv;
302 301 char *myself = "makePseudoEntryObj";
303 302
304 303 if (obj == 0 || eo == 0)
305 304 return (0);
306 305
307 306 if (obj->zo_data.zo_type == NIS_ENTRY_OBJ) {
308 307 *eo = obj->zo_data.objdata_u.en_data;
309 308 eo->en_type = 0;
310 309
311 310 /*
312 311 * To prevent the XDR function from making a copy of
313 312 * the entry columns, we set the columns structure to
314 313 * 0 (ie no column data)
315 314 */
316 315 ecl = obj->EN_data.en_cols.en_cols_len;
317 316 ecv = obj->EN_data.en_cols.en_cols_val;
318 317 obj->EN_data.en_cols.en_cols_len = 0;
319 318 obj->EN_data.en_cols.en_cols_val = 0;
320 319 } else {
321 320 eo->en_type = (char *)in_directory;
322 321 }
323 322
324 323 bufsize = xdr_sizeof(xdr_nis_object, obj);
325 324 buf = am(myself, bufsize);
326 325 if (buf == 0) {
327 326 if (obj->zo_data.zo_type == NIS_ENTRY_OBJ) {
328 327 obj->EN_data.en_cols.en_cols_len = ecl;
329 328 obj->EN_data.en_cols.en_cols_val = ecv;
330 329 }
331 330 return (0);
332 331 }
333 332
334 333 xdrmem_create(&xdrs, (char *)buf, bufsize, XDR_ENCODE);
335 334
336 335 if (obj->zo_data.zo_type == NIS_ENTRY_OBJ) {
337 336 xret = xdr_nis_fetus_object(&xdrs, obj, tobj);
338 337 } else {
339 338 xret = xdr_nis_object(&xdrs, obj);
340 339 }
341 340
342 341 /* Restore the 'obj' */
343 342 if (obj->zo_data.zo_type == NIS_ENTRY_OBJ) {
344 343 obj->EN_data.en_cols.en_cols_len = ecl;
345 344 obj->EN_data.en_cols.en_cols_val = ecv;
346 345 }
347 346
348 347 if (!xret) {
349 348 logmsg(MSG_NOTIMECHECK, LOG_ERR,
350 349 "%s: XDR encode failure", myself);
351 350 sfree(buf);
352 351 return (0);
353 352 }
354 353
355 354 eo->en_cols.en_cols_val[0].ec_value.ec_value_val = buf;
356 355 eo->en_cols.en_cols_val[0].ec_value.ec_value_len = xdr_getpos(&xdrs);
357 356 eo->en_cols.en_cols_val[0].ec_flags = EN_BINARY+EN_XDR;
358 357
359 358 return (eo);
360 359 }
361 360
362 361 nis_object *
363 362 unmakePseudoEntryObj(entry_obj *e, nis_object *tobj) {
364 363 nis_object *o;
365 364 XDR xdrs;
366 365 bool_t stat;
367 366 char *myself = "unmakePseudoEntryObj";
368 367
369 368 if (e == 0 || e->en_cols.en_cols_val == 0 ||
370 369 e->en_cols.en_cols_len == 0)
371 370 return (0);
372 371
373 372 o = am(myself, sizeof (*o));
374 373 if (o == 0)
375 374 return (0);
376 375
377 376 xdrmem_create(&xdrs, e->en_cols.en_cols_val[0].ec_value.ec_value_val,
378 377 e->en_cols.en_cols_val[0].ec_value.ec_value_len,
379 378 XDR_DECODE);
380 379
381 380 if (tobj != 0 && (e->en_type == 0 || e->en_type[0] == '\0')) {
382 381 stat = xdr_nis_fetus_object(&xdrs, o, tobj);
383 382 } else {
384 383 stat = xdr_nis_object(&xdrs, o);
385 384 }
386 385
387 386 if (!stat) {
388 387 sfree(o);
389 388 o = 0;
390 389 }
391 390
392 391 /*
393 392 * If it's an entry object, construct the column information.
394 393 * We make this a copy, so that 'o' can be freed using
395 394 * nis_destroy_object().
396 395 */
397 396 if (o != 0 && o->zo_data.zo_type == NIS_ENTRY_OBJ &&
398 397 o->zo_data.objdata_u.en_data.en_cols.en_cols_val == 0 &&
399 398 e->en_cols.en_cols_len > 1) {
400 399 entry_col *ec, *oec;
401 400 uint_t i, *ocl;
402 401
403 402 ec = am(myself, (e->en_cols.en_cols_len - 1) * sizeof (ec[0]));
404 403 if (ec == 0) {
405 404 nis_destroy_object(o);
406 405 return (0);
407 406 }
408 407
409 408 o->zo_data.objdata_u.en_data.en_cols.en_cols_val = ec;
410 409 o->zo_data.objdata_u.en_data.en_cols.en_cols_len = 0;
411 410 ocl = &o->zo_data.objdata_u.en_data.en_cols.en_cols_len;
412 411 oec = e->en_cols.en_cols_val;
413 412
414 413 for (i = 1; i < e->en_cols.en_cols_len; i++) {
415 414 uint_t len;
416 415
417 416 if (oec[i].ec_value.ec_value_val != 0) {
418 417 len = oec[i].ec_value.ec_value_len;
419 418 if (len == 0)
420 419 len++;
421 420 ec[i-1].ec_value.ec_value_val = am(myself, len);
422 421 if (ec[i-1].ec_value.ec_value_val == 0) {
423 422 nis_destroy_object(o);
424 423 return (0);
425 424 }
426 425 (void) memcpy(ec[i-1].ec_value.ec_value_val,
427 426 oec[i].ec_value.ec_value_val,
428 427 oec[i].ec_value.ec_value_len);
429 428 ec[i-1].ec_value.ec_value_len =
430 429 oec[i].ec_value.ec_value_len;
431 430 } else {
432 431 ec[i-1].ec_value.ec_value_val = 0;
433 432 ec[i-1].ec_value.ec_value_len = 0;
434 433 }
435 434 *ocl += 1;
436 435 }
437 436 }
438 437
439 438 /*
440 439 * If it's an entry, and we have the table object, make sure
441 440 * zo_name and en_type either already are set, or get them
442 441 * from the table.
443 442 */
444 443 if (o != 0 && o->zo_data.zo_type == NIS_ENTRY_OBJ && tobj != 0) {
445 444 if (o->zo_name == 0)
446 445 o->zo_name = sdup(myself, T, tobj->zo_name);
447 446 if (o->zo_data.objdata_u.en_data.en_type == 0)
448 447 o->zo_data.objdata_u.en_data.en_type = sdup(myself, T,
449 448 tobj->zo_data.objdata_u.ta_data.ta_type);
450 449 }
451 450
452 451 return (o);
453 452 }
454 453
455 454 /*
456 455 * Input: A (nis_object *), and (optionally) an (entry_obj *) array.
457 456 * Output: Pointer to an XDR:ed version of an (xdr_nis_object_t).
458 457 */
459 458 void *
460 459 xdrNisObject(nis_object *obj, entry_obj **ea, int numEa, int *xdrLenP) {
461 460 xdr_nis_object_t xno;
462 461 void *buf;
463 462 int xdrLen;
464 463 XDR xdrs;
465 464 bool_t xret;
466 465 char *myself = "xdrNisObject";
467 466
468 467 if (obj == 0)
469 468 return (0);
470 469
471 470 /*
472 471 * The version tells us what the XDR:ed buffer contains.
473 472 * Should be incremented whenever xdr_nis_object_t changes
474 473 * incompatibly.
475 474 */
476 475 xno.xversion = 1;
477 476
478 477 xno.obj = obj;
479 478
480 479 if (obj->zo_data.zo_type == NIS_DIRECTORY_OBJ &&
481 480 ea != 0 && numEa > 0) {
482 481 int i;
483 482
484 483 /*
485 484 * The ea[] array is expected to contain the kind of
486 485 * pseudo-entry object stored in the nisdb incarnation
487 486 * of a NIS+ directory. Column zero contains the XDR:ed
488 487 * directory entry object (which we ignore), while column
489 488 * one contains the name of said entry. It's the latter
490 489 * that we borrow for use in the dirEntry[] list of the
491 490 * xdr_nis_object_t.
492 491 */
493 492
494 493 xno.dirEntry.dirEntry_len = 0;
495 494 xno.dirEntry.dirEntry_val = am(myself, numEa *
496 495 sizeof (xno.dirEntry.dirEntry_val[0]));
497 496 if (xno.dirEntry.dirEntry_val == 0)
498 497 return (0);
499 498
500 499 for (i = 0; i < numEa; i++) {
501 500 if (ea[i] == 0 || ea[i]->en_cols.en_cols_val == 0 ||
502 501 ea[i]->en_cols.en_cols_len != 2 ||
503 502 ea[i]->en_cols.en_cols_val[1].
504 503 ec_value.ec_value_len == 0)
505 504 continue;
506 505 /*
507 506 * Yes, there's a NUL at the end of the dir entry
508 507 * name.
509 508 */
510 509 xno.dirEntry.dirEntry_val[xno.dirEntry.dirEntry_len] =
511 510 ea[i]->en_cols.en_cols_val[1].
512 511 ec_value.ec_value_val;
513 512 xno.dirEntry.dirEntry_len++;
514 513 }
515 514 } else {
516 515 /* No directory entries */
517 516 xno.dirEntry.dirEntry_len = 0;
518 517 xno.dirEntry.dirEntry_val = 0;
519 518 }
520 519
521 520 xdrLen = xdr_sizeof(xdr_xdr_nis_object_t, &xno);
522 521 buf = am(myself, xdrLen);
523 522 if (buf == 0)
524 523 return (0);
525 524
526 525 xdrmem_create(&xdrs, (char *)buf, xdrLen, XDR_ENCODE);
527 526
528 527 xret = xdr_xdr_nis_object_t(&xdrs, &xno);
529 528
530 529 sfree(xno.dirEntry.dirEntry_val);
531 530
532 531 if (!xret) {
533 532 sfree(buf);
534 533 return (0);
535 534 }
536 535
537 536 if (xdrLenP != 0)
538 537 *xdrLenP = xdrLen;
539 538
540 539 return (buf);
541 540 }
542 541
543 542 /*
544 543 * Input: Pointer to an XDR:ed version of an (xdr_nis_object_t).
545 544 * Output: Pointer to a (nis_object *) and (if the object is a
546 545 * directory) a pointer to an array of (entry_obj *).
547 546 */
548 547 nis_object *
549 548 unXdrNisObject(void *buf, int bufLen, entry_obj ***eaP, int *numEaP) {
550 549 xdr_nis_object_t *xno;
551 550 XDR xdrs;
552 551 bool_t xret;
553 552 entry_obj **ea;
554 553 int numEa;
555 554 nis_object *o;
556 555 char *myself = "unXdrNisObject";
557 556
558 557 if (buf == 0 || bufLen <= 0)
559 558 return (0);
560 559
561 560 xno = am(myself, sizeof (*xno));
562 561 if (xno == 0)
563 562 return (0);
564 563
565 564 xdrmem_create(&xdrs, buf, bufLen, XDR_DECODE);
566 565 xret = xdr_xdr_nis_object_t(&xdrs, xno);
567 566
568 567 if (!xret) {
569 568 sfree(xno);
570 569 return (0);
571 570 }
572 571
573 572 switch (xno->xversion) {
574 573 case 1:
575 574 break;
576 575 default:
577 576 xdr_free(xdr_xdr_nis_object_t, (char *)xno);
578 577 sfree(xno);
579 578 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
580 579 "%s: Unknown xdr_nis_object_t version %d",
581 580 myself, xno->xversion);
582 581 return (0);
583 582 }
584 583
585 584 if (eaP != 0 && numEaP != 0 && xno->dirEntry.dirEntry_len > 0 &&
586 585 xno->dirEntry.dirEntry_val != 0) {
587 586 ea = am(myself, xno->dirEntry.dirEntry_len * sizeof (ea[0]));
588 587 if (ea == 0) {
589 588 xdr_free(xdr_xdr_nis_object_t, (char *)xno);
590 589 sfree(xno);
591 590 return (0);
592 591 }
593 592 for (numEa = 0; numEa < xno->dirEntry.dirEntry_len; numEa++) {
594 593 ea[numEa] = am(myself, sizeof (*ea[numEa]));
595 594 if (ea[numEa] != 0) {
596 595 ea[numEa]->en_cols.en_cols_len = 2;
597 596 ea[numEa]->en_cols.en_cols_val = am(myself,
598 597 ea[numEa]->en_cols.en_cols_len *
599 598 sizeof (ea[numEa]->en_cols.en_cols_val[0]));
600 599 }
601 600 if (ea[numEa] == 0 ||
602 601 ea[numEa]->en_cols.en_cols_val == 0) {
603 602 int i;
604 603 for (i = 0; i < numEa; i++) {
605 604 sfree(ea[i]->en_cols.en_cols_val);
606 605 sfree(ea[i]);
607 606 }
608 607 sfree(ea);
609 608 xdr_free(xdr_xdr_nis_object_t, (char *)xno);
610 609 sfree(xno);
611 610 return (0);
612 611 }
613 612 /* Leave column 0 (XDR:ed object) empty */
614 613 ea[numEa]->en_cols.en_cols_val[0].
615 614 ec_value.ec_value_len = 0;
616 615 ea[numEa]->en_cols.en_cols_val[0].
617 616 ec_value.ec_value_val = 0;
618 617 /*
619 618 * Fill in name of dir entry. The DB counts the NUL
620 619 * as part of the dir entry name; hence, add one
621 620 * to the string length.
622 621 */
623 622 ea[numEa]->en_cols.en_cols_val[1].
624 623 ec_value.ec_value_len = slen(xno->dirEntry.
625 624 dirEntry_val[numEa]) + 1;
626 625 ea[numEa]->en_cols.en_cols_val[1].
627 626 ec_value.ec_value_val =
628 627 xno->dirEntry.dirEntry_val[numEa];
629 628 }
630 629 *eaP = ea;
631 630 *numEaP = numEa;
632 631 /*
633 632 * The xno->dirEntry.dirEntry_val[] pointers are duplicated
634 633 * in 'ea'. Set the xno pointers to zero, so that the xdr_free
635 634 * doesn't free the 'ea' data.
636 635 */
637 636 if (numEa > 0) {
638 637 int i;
639 638 for (i = 0; i < numEa; i++) {
640 639 xno->dirEntry.dirEntry_val[i] = 0;
641 640 }
642 641 }
643 642 } else {
644 643 if (eaP != 0)
645 644 *eaP = 0;
646 645 if (numEaP != 0)
647 646 *numEaP = 0;
648 647 }
649 648
650 649 o = xno->obj;
651 650 xno->obj = 0;
652 651 xdr_free(xdr_xdr_nis_object_t, (char *)xno);
653 652 sfree(xno);
654 653
655 654 return (o);
656 655 }
657 656
658 657 void
659 658 freeEntryObjArray(entry_obj **ea, int numEa) {
660 659 int i;
661 660
662 661 if (ea == 0)
663 662 return;
664 663
665 664 for (i = 0; i < numEa; i++) {
666 665 int j;
667 666
668 667 for (j = 0; j < ea[i]->en_cols.en_cols_len; j++) {
669 668 sfree(ea[i]->en_cols.en_cols_val[j].
670 669 ec_value.ec_value_val);
671 670 }
672 671
673 672 sfree(ea[i]->en_cols.en_cols_val);
674 673 }
675 674
676 675 sfree(ea);
677 676 }
678 677
679 678 /*
680 679 * Return TRUE if 'o1' and 'o2' are the same, FALSE otherwise.
681 680 * We perform the comparison by XDR encoding the objects, and then
682 681 * checking the XDR buffers for equality. However, we don't want to
683 682 * include the zo_oid (i.e., ctime and mtime) in the comparison.
684 683 */
685 684 bool_t
686 685 sameNisPlusObj(nis_object *o1, nis_object *o2) {
687 686 XDR x1, x2;
688 687 void *b1, *b2;
689 688 int l1, l2;
690 689 bool_t ret;
691 690 nis_object obj1, obj2;
692 691 char *myself = "sameNisPlusObj";
693 692
694 693 if (o1 == o2)
695 694 return (TRUE);
696 695 else if (o1 == 0 || o2 == 0)
697 696 return (FALSE);
698 697
699 698 /*
700 699 * We want to exclude the zo_oid from the comparison. In order
701 700 * not to modify the objects (even very briefly), we do this by
702 701 * making copies (nis_object itself only, not the underlying
703 702 * structures accessed through pointers), and setting the zo_oid
704 703 * to zero in the copies.
705 704 */
706 705 obj1 = *o1;
707 706 obj2 = *o2;
708 707 obj1.zo_oid.ctime = obj1.zo_oid.mtime = 0;
709 708 obj2.zo_oid.ctime = obj2.zo_oid.mtime = 0;
710 709
711 710 l1 = xdr_sizeof(xdr_nis_object, &obj1);
712 711 l2 = xdr_sizeof(xdr_nis_object, &obj2);
713 712 if (l1 != l2)
714 713 return (FALSE);
715 714
716 715 b1 = am(myself, l1);
717 716 b2 = am(myself, l2);
718 717 if (b1 == 0 || b2 == 0) {
719 718 sfree(b1);
720 719 sfree(b2);
721 720 return (FALSE);
722 721 }
723 722
724 723 xdrmem_create(&x1, (char *)b1, l1, XDR_ENCODE);
725 724 xdrmem_create(&x2, (char *)b2, l2, XDR_ENCODE);
726 725
727 726 if (xdr_nis_object(&x1, &obj1) && xdr_nis_object(&x2, &obj2)) {
728 727 ret = (memcmp(b1, b2, l1) == 0);
729 728 } else {
730 729 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
731 730 "%s: xdr_nis_object() error",
732 731 myself);
733 732 ret = FALSE;
734 733 }
735 734
736 735 sfree(b1);
737 736 sfree(b2);
738 737
739 738 return (ret);
740 739 }
741 740
742 741 /*
743 742 * A wrapper/convenience function for sameNisPlusObj() that extracts
744 743 * the object in column zero of 'e2'.
745 744 */
746 745 bool_t
747 746 sameNisPlusPseudoObj(nis_object *o1, entry_obj *e2) {
748 747 nis_object *o2;
749 748 bool_t res;
750 749
751 750 if (o1 == 0 && e2 == 0)
752 751 return (TRUE);
753 752 else if (e2 == 0)
754 753 return (FALSE);
755 754
756 755 o2 = unmakePseudoEntryObj(e2, 0);
757 756 if (o2 == 0)
758 757 return ((o1 == 0) ? TRUE : FALSE);
759 758
760 759 res = sameNisPlusObj(o1, o2);
761 760
762 761 nis_destroy_object(o2);
763 762
764 763 return (res);
765 764 }
↓ open down ↓ |
714 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX