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
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.
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]
23 * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "ldap_util.h"
30 #include "ldap_print.h"
34 printMappingFormat(__nis_mapping_format_t
*f
) {
35 __nis_value_t
*val
= getMappingFormat(f
, 0, fa_any
, 0, 0);
37 char *myself
= "printMappingFormat";
42 for (i
= 0; i
< val
->numVals
; i
++) {
43 c2buf(myself
, val
->val
[i
].value
, val
->val
[i
].length
);
49 printMappingFormatArray(__nis_mapping_format_t
*a
) {
50 __nis_value_t
*val
= getMappingFormatArray(a
, 0, fa_any
, 0, 0);
51 char *myself
= "printMappingFormatArray";
54 if (val
->type
== vt_string
) {
57 if (a
[0].type
!= mmt_begin
)
59 for (i
= 0; i
< val
->numVals
; i
++) {
60 sc2buf(myself
, val
->val
[i
].value
,
64 p2buf(myself
, "<illegal>");
68 p2buf(myself
, "<novals>");
73 printIndex(__nis_index_t
*i
) {
75 char *str
= getIndex(i
, &len
);
76 char *myself
= "printIndex";
78 sc2buf(myself
, str
, len
);
83 printObjSpec(__nis_obj_spec_t
*o
) {
85 char *str
= getObjSpec(o
, &len
);
86 char *myself
= "printObjSpec";
88 sc2buf(myself
, str
, len
);
93 printSearchTriple(__nis_search_triple_t
*s
) {
95 char *str
= getSearchTriple(s
, &len
);
96 char *myself
= "printSearchTriple";
98 sc2buf(myself
, str
, len
);
103 printMappingItem(__nis_mapping_item_t
*i
, __nis_mapping_item_type_t native
) {
104 __nis_value_t
*val
= getMappingItem(i
, native
, 0, 0, NULL
);
106 char *myself
= "printMappingItem";
113 for (j
= 0; j
< val
->numVals
; j
++) {
114 c2buf(myself
, val
->val
[j
].value
, val
->val
[j
].length
);
122 printMappingSubElement(__nis_mapping_sub_element_t
*e
,
123 __nis_mapping_item_type_t native
) {
125 char *myself
= "printMappingSubElement";
129 printMappingItem(&e
->element
.item
, native
);
133 printMappingFormatArray(e
->element
.print
.fmt
);
134 for (i
= 0; i
< e
->element
.print
.numItems
; i
++) {
136 printMappingItem(&e
->element
.print
.item
[i
], native
);
138 if (e
->element
.print
.doElide
) {
139 p2buf(myself
, ", \"%c\"", e
->element
.print
.elide
);
145 printMappingItem(&e
->element
.split
.item
, native
);
146 p2buf(myself
, ", \"%c\")", e
->element
.split
.delim
);
149 p2buf(myself
, "<me_match>");
153 printMappingItem(&e
->element
.extract
.item
, native
);
155 printMappingFormatArray(e
->element
.extract
.fmt
);
159 p2buf(myself
, "(<unknown>)");
165 printMappingElement(__nis_mapping_element_t
*e
,
166 __nis_mapping_item_type_t native
) {
168 char *myself
= "printMappingElement";
172 printMappingItem(&e
->element
.item
, native
);
176 printMappingFormatArray(e
->element
.print
.fmt
);
177 for (i
= 0; i
< e
->element
.print
.numSubElements
; i
++) {
179 printMappingSubElement(
180 &e
->element
.print
.subElement
[i
], native
);
182 if (e
->element
.print
.doElide
) {
183 p2buf(myself
, ", \"%c\"", e
->element
.print
.elide
);
189 printMappingItem(&e
->element
.split
.item
, native
);
190 p2buf(myself
, ", \"%c\")", e
->element
.split
.delim
);
194 printMappingFormatArray(e
->element
.match
.fmt
);
195 for (i
= 0; i
< e
->element
.match
.numItems
; i
++) {
197 printMappingItem(&e
->element
.match
.item
[i
], native
);
203 printMappingItem(&e
->element
.extract
.item
, native
);
205 printMappingFormatArray(e
->element
.extract
.fmt
);
209 p2buf(myself
, "(<unknown>)");
215 printMappingRLHS(__nis_mapping_rlhs_t
*m
, __nis_mapping_item_type_t native
) {
217 char *myself
= "printMappingRLHS";
219 if (m
->numElements
> 1)
221 for (i
= 0; i
< m
->numElements
; i
++) {
222 printMappingElement(&m
->element
[i
], native
);
224 if (m
->numElements
> 1)
229 printMappingRule(__nis_mapping_rule_t
*r
,
230 __nis_mapping_item_type_t nativeLhs
,
231 __nis_mapping_item_type_t nativeRhs
) {
232 char *myself
= "printMappingRule";
234 printMappingRLHS(&r
->lhs
, nativeLhs
);
236 printMappingRLHS(&r
->rhs
, nativeRhs
);
240 printObjName(__nis_index_t
*index
, char *name
) {
241 char *myself
= "printObjName";
244 p2buf(myself
, "%s", NIL(name
));
248 printobjectDN(__nis_object_dn_t
*o
) {
249 char *myself
= "printobjectDN";
253 printSearchTriple(&o
->read
);
254 p2buf(myself
, ":\n\t");
255 printSearchTriple(&o
->write
);
256 switch (o
->delDisp
) {
258 p2buf(myself
, ":\n\t\talways");
261 p2buf(myself
, ":\n\t\tdbid=%s\n", NIL(o
->dbIdName
));
262 for (i
= 0; i
< o
->numDbIds
; i
++) {
263 p2buf(myself
, "\t\t\t");
264 printMappingRule(o
->dbId
[i
], mit_ldap
, mit_nisplus
);
268 p2buf(myself
, ":\n\t\tnever");
271 p2buf(myself
, ":\n\t\t<unknown>");
276 printTableMapping(__nis_table_mapping_t
*t
) {
277 __nis_object_dn_t
*o
;
279 char *myself
= "printTableMapping";
281 p2buf(myself
, "\n%s:", NIL(t
->dbId
));
282 printObjName(&t
->index
, t
->objName
);
283 p2buf(myself
, "\n\t%s \t%s", NIL(t
->objName
), NIL(t
->objPath
));
284 p2buf(myself
, "\n\tTTL = (%d - %d) -> %d\n",
285 t
->initTtlLo
, t
->initTtlHi
, t
->ttl
);
287 for (o
= t
->objectDN
; o
!= 0; o
= o
->next
) {
292 p2buf(myself
, "\tLDAP -> NIS+\n");
293 p2buf(myself
, "\tRules:\n");
294 for (i
= 0; i
< t
->numRulesFromLDAP
; i
++) {
295 p2buf(myself
, "\t\t");
296 printMappingRule(t
->ruleFromLDAP
[i
], mit_nisplus
, mit_ldap
);
300 p2buf(myself
, "\tNIS+ -> LDAP\n");
301 p2buf(myself
, "\tRules:\n");
302 for (i
= 0; i
< t
->numRulesToLDAP
; i
++) {
303 p2buf(myself
, "\t\t");
304 printMappingRule(t
->ruleToLDAP
[i
], mit_ldap
, mit_nisplus
);
310 printRuleValue(__nis_rule_value_t
*rv
) {
312 __nis_buffer_t b
= {0, 0};
313 char *myself
= "printRuleValue";
318 if (rv
->colName
!= 0) {
319 bp2buf(myself
, &b
, "Columns:\n");
320 for (i
= 0; i
< rv
->numColumns
; i
++) {
321 bp2buf(myself
, &b
, "\t%s", NIL(rv
->colName
[i
]));
322 if (rv
->colVal
[i
].numVals
== 1) {
323 bp2buf(myself
, &b
, "=");
324 if (rv
->colVal
[i
].type
== vt_string
)
326 rv
->colVal
[i
].val
[0].value
,
327 rv
->colVal
[i
].val
[0].length
, &b
);
330 rv
->colVal
[i
].val
[0].value
,
331 rv
->colVal
[i
].val
[0].length
, &b
);
332 bp2buf(myself
, &b
, "\n");
334 bp2buf(myself
, &b
, "\n");
335 for (j
= 0; j
< rv
->colVal
[i
].numVals
; j
++) {
336 bp2buf(myself
, &b
, "\t\t");
337 if (rv
->colVal
[i
].type
== vt_string
)
339 rv
->colVal
[i
].val
[j
].value
,
340 rv
->colVal
[i
].val
[j
].length
,
344 rv
->colVal
[i
].val
[j
].value
,
345 rv
->colVal
[i
].val
[j
].length
,
347 bp2buf(myself
, &b
, "\n");
353 if (rv
->attrName
!= 0) {
354 bp2buf(myself
, &b
, "Attributes:\n");
355 for (i
= 0; i
< rv
->numAttrs
; i
++) {
356 bp2buf(myself
, &b
, "\t%s", NIL(rv
->attrName
[i
]));
357 if (rv
->attrVal
[i
].numVals
== 1) {
358 bp2buf(myself
, &b
, "=");
359 if (rv
->attrVal
[i
].type
== vt_string
)
361 rv
->attrVal
[i
].val
[0].value
,
362 rv
->attrVal
[i
].val
[0].length
,
366 rv
->attrVal
[i
].val
[0].value
,
367 rv
->attrVal
[i
].val
[0].length
,
369 bp2buf(myself
, &b
, "\n");
371 bp2buf(myself
, &b
, "\n");
372 for (j
= 0; j
< rv
->attrVal
[i
].numVals
; j
++) {
373 bp2buf(myself
, &b
, "\t\t");
374 if (rv
->attrVal
[i
].type
== vt_string
)
376 rv
->attrVal
[i
].val
[j
].value
,
377 rv
->attrVal
[i
].val
[j
].length
,
381 rv
->attrVal
[i
].val
[j
].value
,
382 rv
->attrVal
[i
].val
[j
].length
,
384 bp2buf(myself
, &b
, "\n");
390 c2buf(myself
, b
.buf
, b
.len
);
396 printLdapMod(LDAPMod
**mods
, __nis_buffer_t
*b
) {
399 char *myself
= "printLdapMod";
407 while ((m
= *mods
) != 0) {
408 if ((m
->mod_op
& LDAP_MOD_ADD
) != 0 ||
409 (m
->mod_op
& ~LDAP_MOD_BVALUES
) == 0) {
411 } else if ((m
->mod_op
& LDAP_MOD_DELETE
) != 0) {
413 } else if ((m
->mod_op
& LDAP_MOD_REPLACE
) != 0) {
418 bp2buf(myself
, b
, "%s: %s\n", s
, m
->mod_type
);
419 if ((m
->mod_op
& LDAP_MOD_BVALUES
) == 0) {
420 char **v
= m
->mod_values
;
424 bp2buf(myself
, b
, "\t%s\n", *v
);
429 struct berval
**bv
= m
->mod_bvalues
;
433 bp2buf(myself
, b
, "\t<ber> %d bytes\n",
444 printObjRights(char *msg
, void *access
) {
451 for (i
= 0; i
< 4; i
++) {
452 p2buf(msg
, "%s", (a
[i
] & NIS_READ_ACC
) ? "r" : "-");
453 p2buf(msg
, "%s", (a
[i
] & NIS_MODIFY_ACC
) ? "m" : "-");
454 p2buf(msg
, "%s", (a
[i
] & NIS_CREATE_ACC
) ? "c" : "-");
455 p2buf(msg
, "%s", (a
[i
] & NIS_DESTROY_ACC
) ? "d" : "-");
460 printObjAttr(__nis_obj_attr_t
*attr
) {
461 char *myself
= "printObjAttr";
466 p2buf(myself
, "\tzo_owner = %s\n", NIL(attr
->zo_owner
));
467 p2buf(myself
, "\tzo_group = %s\n", NIL(attr
->zo_group
));
468 p2buf(myself
, "\tzo_domain = %s\n", NIL(attr
->zo_domain
));
469 p2buf(myself
, "\tzo_access = ");
470 printObjRights(myself
, &attr
->zo_access
);
471 p2buf(myself
, " (0x%08x)\n", attr
->zo_access
);
472 p2buf(myself
, "\tzo_ttl = %d\n", attr
->zo_ttl
);