1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #include "ldap_util.h" 28 #include "ldap_print.h" 29 30 31 void 32 printMappingFormat(__nis_mapping_format_t *f) { 33 __nis_value_t *val = getMappingFormat(f, 0, fa_any, 0, 0); 34 int i; 35 char *myself = "printMappingFormat"; 36 37 if (val == 0) 38 return; 39 40 for (i = 0; i < val->numVals; i++) { 41 c2buf(myself, val->val[i].value, val->val[i].length); 42 } 43 freeValue(val, 1); 44 } 45 46 void 47 printMappingFormatArray(__nis_mapping_format_t *a) { 48 __nis_value_t *val = getMappingFormatArray(a, 0, fa_any, 0, 0); 49 char *myself = "printMappingFormatArray"; 50 51 if (val != 0) { 52 if (val->type == vt_string) { 53 int i; 54 55 if (a[0].type != mmt_begin) 56 p2buf(myself, "\""); 57 for (i = 0; i < val->numVals; i++) { 58 sc2buf(myself, val->val[i].value, 59 val->val[i].length); 60 } 61 } else { 62 p2buf(myself, "<illegal>"); 63 } 64 freeValue(val, 1); 65 } else { 66 p2buf(myself, "<novals>"); 67 } 68 } 69 70 void 71 printIndex(__nis_index_t *i) { 72 int len = 0; 73 char *str = getIndex(i, &len); 74 char *myself = "printIndex"; 75 76 sc2buf(myself, str, len); 77 sfree(str); 78 } 79 80 void 81 printObjSpec(__nis_obj_spec_t *o) { 82 int len = 0; 83 char *str = getObjSpec(o, &len); 84 char *myself = "printObjSpec"; 85 86 sc2buf(myself, str, len); 87 sfree(str); 88 } 89 90 void 91 printSearchTriple(__nis_search_triple_t *s) { 92 int len = 0; 93 char *str = getSearchTriple(s, &len); 94 char *myself = "printSearchTriple"; 95 96 sc2buf(myself, str, len); 97 sfree(str); 98 } 99 100 void 101 printMappingItem(__nis_mapping_item_t *i, __nis_mapping_item_type_t native) { 102 __nis_value_t *val = getMappingItem(i, native, 0, 0, NULL); 103 int j; 104 char *myself = "printMappingItem"; 105 106 if (val == 0) 107 return; 108 109 if (i->repeat) 110 p2buf(myself, "("); 111 for (j = 0; j < val->numVals; j++) { 112 c2buf(myself, val->val[j].value, val->val[j].length); 113 } 114 if (i->repeat) 115 p2buf(myself, ")"); 116 freeValue(val, 1); 117 } 118 119 void 120 printMappingSubElement(__nis_mapping_sub_element_t *e, 121 __nis_mapping_item_type_t native) { 122 int i; 123 char *myself = "printMappingSubElement"; 124 125 switch (e->type) { 126 case me_item: 127 printMappingItem(&e->element.item, native); 128 break; 129 case me_print: 130 p2buf(myself, "("); 131 printMappingFormatArray(e->element.print.fmt); 132 for (i = 0; i < e->element.print.numItems; i++) { 133 p2buf(myself, ", "); 134 printMappingItem(&e->element.print.item[i], native); 135 } 136 if (e->element.print.doElide) { 137 p2buf(myself, ", \"%c\"", e->element.print.elide); 138 } 139 p2buf(myself, ")"); 140 break; 141 case me_split: 142 p2buf(myself, "("); 143 printMappingItem(&e->element.split.item, native); 144 p2buf(myself, ", \"%c\")", e->element.split.delim); 145 break; 146 case me_match: 147 p2buf(myself, "<me_match>"); 148 break; 149 case me_extract: 150 p2buf(myself, "("); 151 printMappingItem(&e->element.extract.item, native); 152 p2buf(myself, ", "); 153 printMappingFormatArray(e->element.extract.fmt); 154 p2buf(myself, ")"); 155 break; 156 default: 157 p2buf(myself, "(<unknown>)"); 158 break; 159 } 160 } 161 162 void 163 printMappingElement(__nis_mapping_element_t *e, 164 __nis_mapping_item_type_t native) { 165 int i; 166 char *myself = "printMappingElement"; 167 168 switch (e->type) { 169 case me_item: 170 printMappingItem(&e->element.item, native); 171 break; 172 case me_print: 173 p2buf(myself, "("); 174 printMappingFormatArray(e->element.print.fmt); 175 for (i = 0; i < e->element.print.numSubElements; i++) { 176 p2buf(myself, ", "); 177 printMappingSubElement( 178 &e->element.print.subElement[i], native); 179 } 180 if (e->element.print.doElide) { 181 p2buf(myself, ", \"%c\"", e->element.print.elide); 182 } 183 p2buf(myself, ")"); 184 break; 185 case me_split: 186 p2buf(myself, "("); 187 printMappingItem(&e->element.split.item, native); 188 p2buf(myself, ", \"%c\")", e->element.split.delim); 189 break; 190 case me_match: 191 p2buf(myself, "("); 192 printMappingFormatArray(e->element.match.fmt); 193 for (i = 0; i < e->element.match.numItems; i++) { 194 p2buf(myself, ", "); 195 printMappingItem(&e->element.match.item[i], native); 196 } 197 p2buf(myself, ")"); 198 break; 199 case me_extract: 200 p2buf(myself, "("); 201 printMappingItem(&e->element.extract.item, native); 202 p2buf(myself, ", "); 203 printMappingFormatArray(e->element.extract.fmt); 204 p2buf(myself, ")"); 205 break; 206 default: 207 p2buf(myself, "(<unknown>)"); 208 break; 209 } 210 } 211 212 void 213 printMappingRLHS(__nis_mapping_rlhs_t *m, __nis_mapping_item_type_t native) { 214 int i; 215 char *myself = "printMappingRLHS"; 216 217 if (m->numElements > 1) 218 p2buf(myself, "("); 219 for (i = 0; i < m->numElements; i++) { 220 printMappingElement(&m->element[i], native); 221 } 222 if (m->numElements > 1) 223 p2buf(myself, ")"); 224 } 225 226 void 227 printMappingRule(__nis_mapping_rule_t *r, 228 __nis_mapping_item_type_t nativeLhs, 229 __nis_mapping_item_type_t nativeRhs) { 230 char *myself = "printMappingRule"; 231 232 printMappingRLHS(&r->lhs, nativeLhs); 233 p2buf(myself, "="); 234 printMappingRLHS(&r->rhs, nativeRhs); 235 } 236 237 void 238 printObjName(__nis_index_t *index, char *name) { 239 char *myself = "printObjName"; 240 241 printIndex(index); 242 p2buf(myself, "%s", NIL(name)); 243 } 244 245 void 246 printobjectDN(__nis_object_dn_t *o) { 247 char *myself = "printobjectDN"; 248 int i; 249 250 p2buf(myself, "\t"); 251 printSearchTriple(&o->read); 252 p2buf(myself, ":\n\t"); 253 printSearchTriple(&o->write); 254 switch (o->delDisp) { 255 case dd_always: 256 p2buf(myself, ":\n\t\talways"); 257 break; 258 case dd_perDbId: 259 p2buf(myself, ":\n\t\tdbid=%s\n", NIL(o->dbIdName)); 260 for (i = 0; i < o->numDbIds; i++) { 261 p2buf(myself, "\t\t\t"); 262 printMappingRule(o->dbId[i], mit_ldap, mit_nisplus); 263 } 264 break; 265 case dd_never: 266 p2buf(myself, ":\n\t\tnever"); 267 break; 268 default: 269 p2buf(myself, ":\n\t\t<unknown>"); 270 } 271 } 272 273 void 274 printTableMapping(__nis_table_mapping_t *t) { 275 __nis_object_dn_t *o; 276 int i; 277 char *myself = "printTableMapping"; 278 279 p2buf(myself, "\n%s:", NIL(t->dbId)); 280 printObjName(&t->index, t->objName); 281 p2buf(myself, "\n\t%s \t%s", NIL(t->objName), NIL(t->objPath)); 282 p2buf(myself, "\n\tTTL = (%d - %d) -> %d\n", 283 t->initTtlLo, t->initTtlHi, t->ttl); 284 285 for (o = t->objectDN; o != 0; o = o->next) { 286 printobjectDN(o); 287 p2buf(myself, "\n"); 288 } 289 290 p2buf(myself, "\tLDAP -> NIS+\n"); 291 p2buf(myself, "\tRules:\n"); 292 for (i = 0; i < t->numRulesFromLDAP; i++) { 293 p2buf(myself, "\t\t"); 294 printMappingRule(t->ruleFromLDAP[i], mit_nisplus, mit_ldap); 295 p2buf(myself, "\n"); 296 } 297 298 p2buf(myself, "\tNIS+ -> LDAP\n"); 299 p2buf(myself, "\tRules:\n"); 300 for (i = 0; i < t->numRulesToLDAP; i++) { 301 p2buf(myself, "\t\t"); 302 printMappingRule(t->ruleToLDAP[i], mit_ldap, mit_nisplus); 303 p2buf(myself, "\n"); 304 } 305 } 306 307 void 308 printRuleValue(__nis_rule_value_t *rv) { 309 int i, j; 310 __nis_buffer_t b = {0, 0}; 311 char *myself = "printRuleValue"; 312 313 if (rv == 0) 314 return; 315 316 if (rv->colName != 0) { 317 bp2buf(myself, &b, "Columns:\n"); 318 for (i = 0; i < rv->numColumns; i++) { 319 bp2buf(myself, &b, "\t%s", NIL(rv->colName[i])); 320 if (rv->colVal[i].numVals == 1) { 321 bp2buf(myself, &b, "="); 322 if (rv->colVal[i].type == vt_string) 323 sbc2buf(myself, 324 rv->colVal[i].val[0].value, 325 rv->colVal[i].val[0].length, &b); 326 else 327 bc2buf(myself, 328 rv->colVal[i].val[0].value, 329 rv->colVal[i].val[0].length, &b); 330 bp2buf(myself, &b, "\n"); 331 } else { 332 bp2buf(myself, &b, "\n"); 333 for (j = 0; j < rv->colVal[i].numVals; j++) { 334 bp2buf(myself, &b, "\t\t"); 335 if (rv->colVal[i].type == vt_string) 336 sbc2buf(myself, 337 rv->colVal[i].val[j].value, 338 rv->colVal[i].val[j].length, 339 &b); 340 else 341 bc2buf(myself, 342 rv->colVal[i].val[j].value, 343 rv->colVal[i].val[j].length, 344 &b); 345 bp2buf(myself, &b, "\n"); 346 } 347 } 348 } 349 } 350 351 if (rv->attrName != 0) { 352 bp2buf(myself, &b, "Attributes:\n"); 353 for (i = 0; i < rv->numAttrs; i++) { 354 bp2buf(myself, &b, "\t%s", NIL(rv->attrName[i])); 355 if (rv->attrVal[i].numVals == 1) { 356 bp2buf(myself, &b, "="); 357 if (rv->attrVal[i].type == vt_string) 358 sbc2buf(myself, 359 rv->attrVal[i].val[0].value, 360 rv->attrVal[i].val[0].length, 361 &b); 362 else 363 bc2buf(myself, 364 rv->attrVal[i].val[0].value, 365 rv->attrVal[i].val[0].length, 366 &b); 367 bp2buf(myself, &b, "\n"); 368 } else { 369 bp2buf(myself, &b, "\n"); 370 for (j = 0; j < rv->attrVal[i].numVals; j++) { 371 bp2buf(myself, &b, "\t\t"); 372 if (rv->attrVal[i].type == vt_string) 373 sbc2buf(myself, 374 rv->attrVal[i].val[j].value, 375 rv->attrVal[i].val[j].length, 376 &b); 377 else 378 bc2buf(myself, 379 rv->attrVal[i].val[j].value, 380 rv->attrVal[i].val[j].length, 381 &b); 382 bp2buf(myself, &b, "\n"); 383 } 384 } 385 } 386 } 387 388 c2buf(myself, b.buf, b.len); 389 sfree(b.buf); 390 printbuf(); 391 } 392 393 void 394 printLdapMod(LDAPMod **mods, __nis_buffer_t *b) { 395 LDAPMod *m; 396 char *s; 397 char *myself = "printLdapMod"; 398 399 if (mods == 0) 400 return; 401 402 if (b == 0) 403 b = &pb; 404 405 while ((m = *mods) != 0) { 406 if ((m->mod_op & LDAP_MOD_ADD) != 0 || 407 (m->mod_op & ~LDAP_MOD_BVALUES) == 0) { 408 s = "ADD "; 409 } else if ((m->mod_op & LDAP_MOD_DELETE) != 0) { 410 s = "DELETE "; 411 } else if ((m->mod_op & LDAP_MOD_REPLACE) != 0) { 412 s = "REPLACE"; 413 } else { 414 s = "UNKNOWN"; 415 } 416 bp2buf(myself, b, "%s: %s\n", s, m->mod_type); 417 if ((m->mod_op & LDAP_MOD_BVALUES) == 0) { 418 char **v = m->mod_values; 419 420 if (v != 0) { 421 while (*v != 0) { 422 bp2buf(myself, b, "\t%s\n", *v); 423 v++; 424 } 425 } 426 } else { 427 struct berval **bv = m->mod_bvalues; 428 429 if (bv != 0) { 430 while (*bv != 0) { 431 bp2buf(myself, b, "\t<ber> %d bytes\n", 432 (*bv)->bv_len); 433 bv++; 434 } 435 } 436 } 437 mods++; 438 } 439 } 440 441 static void 442 printObjRights(char *msg, void *access) { 443 uchar_t *a = access; 444 int i; 445 446 if (a == 0) 447 return; 448 449 for (i = 0; i < 4; i++) { 450 p2buf(msg, "%s", (a[i] & NIS_READ_ACC) ? "r" : "-"); 451 p2buf(msg, "%s", (a[i] & NIS_MODIFY_ACC) ? "m" : "-"); 452 p2buf(msg, "%s", (a[i] & NIS_CREATE_ACC) ? "c" : "-"); 453 p2buf(msg, "%s", (a[i] & NIS_DESTROY_ACC) ? "d" : "-"); 454 } 455 } 456 457 void 458 printObjAttr(__nis_obj_attr_t *attr) { 459 char *myself = "printObjAttr"; 460 461 if (attr == 0) 462 return; 463 464 p2buf(myself, "\tzo_owner = %s\n", NIL(attr->zo_owner)); 465 p2buf(myself, "\tzo_group = %s\n", NIL(attr->zo_group)); 466 p2buf(myself, "\tzo_domain = %s\n", NIL(attr->zo_domain)); 467 p2buf(myself, "\tzo_access = "); 468 printObjRights(myself, &attr->zo_access); 469 p2buf(myself, " (0x%08x)\n", attr->zo_access); 470 p2buf(myself, "\tzo_ttl = %d\n", attr->zo_ttl); 471 } 472