3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
12 #include <ac/socket.h>
17 #endif /* HAVE_CONSOLE_H */
23 static void dump_tmpl ( struct ldap_disptmpl *tmpl );
24 static void dump_srchpref( struct ldap_searchobj *sp );
26 #define NULLSTRINGIFNULL( s ) ( (s) == NULL ? "(null)" : (s) )
29 main( int argc, char **argv )
31 struct ldap_disptmpl *templates, *dtp;
32 struct ldap_searchobj *so, *sop;
37 for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
43 if (( err = ldap_init_templates( "ldaptemplates.conf", &templates ))
45 fprintf( stderr, "ldap_init_templates failed (%d)\n", err );
49 if (( err = ldap_init_searchprefs( "ldapsearchprefs.conf", &so ))
51 fprintf( stderr, "ldap_init_searchprefs failed (%d)\n", err );
56 printf( "*** Display Templates:\n" );
57 for ( dtp = ldap_first_disptmpl( templates ); dtp != NULL;
58 dtp = ldap_next_disptmpl( templates, dtp )) {
63 printf( "\n\n*** Search Objects:\n" );
64 for ( sop = ldap_first_searchobj( so ); sop != NULL;
65 sop = ldap_next_searchobj( so, sop )) {
71 if (( dtp = ldap_oc2template( ++argv, templates )) == NULL ) {
72 fprintf( stderr, "no matching template found\n" );
79 ldap_free_templates( templates );
80 ldap_free_searchprefs( so );
86 static const char *const syn_name[] = {
87 "?", "CIS", "MLS", "DN", "BOOL", "JPEG", "JPEGBTN", "FAX", "FAXBTN",
88 "AUDIOBTN", "TIME", "DATE", "URL", "SEARCHACT", "LINKACT", "ADDDNACT",
92 static const char *const syn_type[] = {
93 "?", "txt", "img", "?", "bool", "?", "?", "?", "btn",
94 "?", "?", "?", "?", "?", "?", "?",
98 static char *includeattrs[] = { "objectClass", "sn", NULL };
100 static const char *const item_opts[] = {
101 "ro", "sort", "1val", "hide", "required", "hideiffalse", NULL
104 static const unsigned long item_opt_vals[] = {
105 LDAP_DITEM_OPT_READONLY, LDAP_DITEM_OPT_SORTVALUES,
106 LDAP_DITEM_OPT_SINGLEVALUED, LDAP_DITEM_OPT_HIDEIFEMPTY,
107 LDAP_DITEM_OPT_VALUEREQUIRED, LDAP_DITEM_OPT_HIDEIFFALSE,
112 dump_tmpl( struct ldap_disptmpl *tmpl )
114 struct ldap_tmplitem *rowp, *colp;
115 int i, rowcnt, colcnt;
117 struct ldap_oclist *ocp;
118 struct ldap_adddeflist *adp;
120 printf( "** Template \"%s\" (plural \"%s\", icon \"%s\")\n",
121 NULLSTRINGIFNULL( tmpl->dt_name ),
122 NULLSTRINGIFNULL( tmpl->dt_pluralname ),
123 NULLSTRINGIFNULL( tmpl->dt_iconname ));
125 printf( "object class list:\n" );
126 for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = ocp->oc_next ) {
127 for ( i = 0; ocp->oc_objclasses[ i ] != NULL; ++i ) {
128 printf( "%s%s", i == 0 ? " " : " & ",
129 NULLSTRINGIFNULL( ocp->oc_objclasses[ i ] ));
135 printf( "template options: " );
136 if ( tmpl->dt_options == 0L ) {
139 printf( "%s %s %s\n", LDAP_IS_DISPTMPL_OPTION_SET( tmpl,
140 LDAP_DTMPL_OPT_ADDABLE ) ? "addable" : "",
141 LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALLOWMODRDN )
143 LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALTVIEW )
147 printf( "authenticate as attribute: %s\n", tmpl->dt_authattrname != NULL ?
148 tmpl->dt_authattrname : "<default>" );
150 printf( "default RDN attribute: %s\n", tmpl->dt_defrdnattrname != NULL ?
151 tmpl->dt_defrdnattrname : "NONE" );
153 printf( "default add location: %s\n", tmpl->dt_defaddlocation != NULL ?
154 tmpl->dt_defaddlocation : "NONE" );
156 printf( "\nnew entry value default rules:\n" );
157 for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = adp->ad_next ) {
158 if ( adp->ad_source == LDAP_ADSRC_CONSTANTVALUE ) {
159 printf( " attribute %s <-- constant value \"%s\"\n",
160 NULLSTRINGIFNULL( adp->ad_attrname),
161 NULLSTRINGIFNULL( adp->ad_value ));
163 printf( " attribute %s <-- adder's DN\n",
164 NULLSTRINGIFNULL( adp->ad_attrname ));
169 printf( "\nfetch attributes & values:\n" );
170 if (( fetchattrs = ldap_tmplattrs( tmpl, includeattrs, 1,
171 LDAP_SYN_OPT_DEFER )) == NULL ) {
172 printf( " <none>\n" );
174 for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
175 printf( " %s\n", fetchattrs[ i ] );
176 free( fetchattrs[ i ] );
178 free( (char *)fetchattrs );
181 printf( "\nfetch attributes only:\n" );
182 if (( fetchattrs = ldap_tmplattrs( tmpl, NULL, 0,
183 LDAP_SYN_OPT_DEFER )) == NULL ) {
184 printf( " <none>\n" );
186 for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
187 printf( " %s\n", fetchattrs[ i ] );
188 free( fetchattrs[ i ] );
190 free( (char *)fetchattrs );
193 printf( "\ntemplate items:\n" );
195 for ( rowp = ldap_first_tmplrow( tmpl ); rowp != NULL;
196 rowp = ldap_next_tmplrow( tmpl, rowp )) {
199 for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULL;
200 colp = ldap_next_tmplcol( tmpl, rowp, colp )) {
202 printf( " %2d-%d: %s (%s%s", rowcnt, colcnt,
203 syn_name[ colp->ti_syntaxid & 0x0000FFFF ],
204 syn_type[ LDAP_GET_SYN_TYPE( colp->ti_syntaxid ) >> 24 ],
205 (( LDAP_GET_SYN_OPTIONS( colp->ti_syntaxid ) &
206 LDAP_SYN_OPT_DEFER ) != 0 ) ? ",defer" : "" );
208 for ( i = 0; item_opts[ i ] != NULL; ++i ) {
209 if ( LDAP_IS_TMPLITEM_OPTION_SET( colp, item_opt_vals[ i ] )) {
210 printf( ",%s", NULLSTRINGIFNULL( item_opts[ i ] ));
214 printf( "), %s, %s", NULLSTRINGIFNULL( colp->ti_attrname ),
215 NULLSTRINGIFNULL( colp->ti_label ));
216 if ( colp->ti_args != NULL ) {
218 for ( i = 0; colp->ti_args[ i ] != NULL; ++i ) {
219 printf( "<%s>", NULLSTRINGIFNULL( colp->ti_args[ i ] ));
230 dump_srchpref( struct ldap_searchobj *so )
233 struct ldap_searchattr *sa;
234 struct ldap_searchmatch *sm;
236 printf( "Object type prompt: %s\n",
237 NULLSTRINGIFNULL( so->so_objtypeprompt ));
238 printf( "Options: %s\n",
239 LDAP_IS_SEARCHOBJ_OPTION_SET( so, LDAP_SEARCHOBJ_OPT_INTERNAL ) ?
240 "internal" : "NONE" );
241 printf( "Prompt: %s\n", NULLSTRINGIFNULL( so->so_prompt ));
243 switch ( so->so_defaultscope ) {
244 case LDAP_SCOPE_BASE:
245 printf( "LDAP_SCOPE_BASE" );
247 case LDAP_SCOPE_ONELEVEL:
248 printf( "LDAP_SCOPE_ONELEVEL" );
250 case LDAP_SCOPE_SUBTREE:
251 printf( "LDAP_SCOPE_SUBTREE" );
254 printf("*** unknown!" );
257 printf( "Filter prefix: %s\n",
258 NULLSTRINGIFNULL( so->so_filterprefix ));
259 printf( "Filter tag: %s\n",
260 NULLSTRINGIFNULL( so->so_filtertag ));
261 printf( "Default select attr: %s\n",
262 NULLSTRINGIFNULL( so->so_defaultselectattr ));
263 printf( "Default select text: %s\n",
264 NULLSTRINGIFNULL( so->so_defaultselecttext ));
265 printf( "Searchable attributes ---- \n" );
266 for ( sa = so->so_salist; sa != NULL; sa = sa->sa_next ) {
267 printf( " Label: %s\n", NULLSTRINGIFNULL( sa->sa_attrlabel ));
268 printf( " Attribute: %s\n", NULLSTRINGIFNULL( sa->sa_attr ));
269 printf( " Select attr: %s\n", NULLSTRINGIFNULL( sa->sa_selectattr ));
270 printf( " Select text: %s\n", NULLSTRINGIFNULL( sa->sa_selecttext ));
271 printf( " Match types ---- \n" );
272 for ( i = 0, sm = so->so_smlist; sm != NULL; i++, sm = sm->sm_next ) {
273 if (( sa->sa_matchtypebitmap >> i ) & 1 ) {
274 printf( " %s (%s)\n",
275 NULLSTRINGIFNULL( sm->sm_matchprompt ),
276 NULLSTRINGIFNULL( sm->sm_filter ));