17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate *
3*5e45752aSstevel * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved.
4*5e45752aSstevel * Use is subject to license terms.
57c478bd9Sstevel@tonic-gate *
67c478bd9Sstevel@tonic-gate */
77c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
87c478bd9Sstevel@tonic-gate #include <stdio.h>
97c478bd9Sstevel@tonic-gate #include <sys/types.h>
107c478bd9Sstevel@tonic-gate #include "lber.h"
117c478bd9Sstevel@tonic-gate #include "ldap.h"
127c478bd9Sstevel@tonic-gate #include "disptmpl.h"
137c478bd9Sstevel@tonic-gate #include "srchpref.h"
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate #ifdef MACOS
167c478bd9Sstevel@tonic-gate #include <stdlib.h>
177c478bd9Sstevel@tonic-gate #include <console.h>
187c478bd9Sstevel@tonic-gate #endif /* MACOS */
197c478bd9Sstevel@tonic-gate
207c478bd9Sstevel@tonic-gate #ifdef NEEDPROTOS
217c478bd9Sstevel@tonic-gate void dump_tmpl( struct ldap_disptmpl *tmpl );
227c478bd9Sstevel@tonic-gate void dump_srchpref( struct ldap_searchobj *sp );
237c478bd9Sstevel@tonic-gate #else /* NEEDPROTOS */
247c478bd9Sstevel@tonic-gate void dump_tmpl();
257c478bd9Sstevel@tonic-gate void dump_srchpref();
267c478bd9Sstevel@tonic-gate #endif /* NEEDPROTOS */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #define NULLSTRINGIFNULL( s ) ( s == NULL ? "(null)" : s )
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)337c478bd9Sstevel@tonic-gate main( int argc, char **argv )
347c478bd9Sstevel@tonic-gate {
357c478bd9Sstevel@tonic-gate struct ldap_disptmpl *templates, *dtp;
367c478bd9Sstevel@tonic-gate struct ldap_searchobj *so, *sop;
377c478bd9Sstevel@tonic-gate int err;
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #ifdef MACOS
407c478bd9Sstevel@tonic-gate ccommand( &argv );
417c478bd9Sstevel@tonic-gate for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
427c478bd9Sstevel@tonic-gate ;
437c478bd9Sstevel@tonic-gate }
447c478bd9Sstevel@tonic-gate cshow( stdout );
457c478bd9Sstevel@tonic-gate #endif /* MACOS */
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate if (( err = ldap_init_templates( "ldaptemplates.conf", &templates ))
487c478bd9Sstevel@tonic-gate != 0 ) {
497c478bd9Sstevel@tonic-gate fprintf( stderr, "ldap_init_templates failed (%d)\n", err );
507c478bd9Sstevel@tonic-gate exit( 1 );
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate if (( err = ldap_init_searchprefs( "ldapsearchprefs.conf", &so ))
547c478bd9Sstevel@tonic-gate != 0 ) {
557c478bd9Sstevel@tonic-gate fprintf( stderr, "ldap_init_searchprefs failed (%d)\n", err );
567c478bd9Sstevel@tonic-gate exit( 1 );
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate if ( argc == 1 ) {
607c478bd9Sstevel@tonic-gate printf( "*** Display Templates:\n" );
617c478bd9Sstevel@tonic-gate for ( dtp = ldap_first_disptmpl( templates ); dtp != NULLDISPTMPL;
627c478bd9Sstevel@tonic-gate dtp = ldap_next_disptmpl( templates, dtp )) {
637c478bd9Sstevel@tonic-gate dump_tmpl( dtp );
647c478bd9Sstevel@tonic-gate printf( "\n\n" );
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate printf( "\n\n*** Search Objects:\n" );
687c478bd9Sstevel@tonic-gate for ( sop = ldap_first_searchobj( so ); sop != NULLSEARCHOBJ;
697c478bd9Sstevel@tonic-gate sop = ldap_next_searchobj( so, sop )) {
707c478bd9Sstevel@tonic-gate dump_srchpref( sop );
717c478bd9Sstevel@tonic-gate printf( "\n\n" );
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate } else {
757c478bd9Sstevel@tonic-gate if (( dtp = ldap_oc2template( ++argv, templates )) == NULL ) {
767c478bd9Sstevel@tonic-gate fprintf( stderr, "no matching template found\n" );
777c478bd9Sstevel@tonic-gate } else {
787c478bd9Sstevel@tonic-gate dump_tmpl( dtp );
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate ldap_free_templates( templates );
847c478bd9Sstevel@tonic-gate ldap_free_searchprefs( so );
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate exit( 0 );
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate static char *syn_name[] = {
917c478bd9Sstevel@tonic-gate "?", "CIS", "MLS", "DN", "BOOL", "JPEG", "JPEGBTN", "FAX", "FAXBTN",
927c478bd9Sstevel@tonic-gate "AUDIOBTN", "TIME", "DATE", "URL", "SEARCHACT", "LINKACT", "ADDDNACT",
937c478bd9Sstevel@tonic-gate "VERIFYACT",
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate static char *syn_type[] = {
977c478bd9Sstevel@tonic-gate "?", "txt", "img", "?", "bool", "?", "?", "?", "btn",
987c478bd9Sstevel@tonic-gate "?", "?", "?", "?", "?", "?", "?",
997c478bd9Sstevel@tonic-gate "action", "?"
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate static char *includeattrs[] = { "objectClass", "sn", NULL };
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate static char *item_opts[] = {
1057c478bd9Sstevel@tonic-gate "ro", "sort", "1val", "hide", "required", "hideiffalse", NULL
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate static unsigned long item_opt_vals[] = {
1097c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_READONLY, LDAP_DITEM_OPT_SORTVALUES,
1107c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_SINGLEVALUED, LDAP_DITEM_OPT_HIDEIFEMPTY,
1117c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_VALUEREQUIRED, LDAP_DITEM_OPT_HIDEIFFALSE,
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate void
dump_tmpl(struct ldap_disptmpl * tmpl)1167c478bd9Sstevel@tonic-gate dump_tmpl( struct ldap_disptmpl *tmpl )
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate struct ldap_tmplitem *rowp, *colp;
1197c478bd9Sstevel@tonic-gate int i, rowcnt, colcnt;
1207c478bd9Sstevel@tonic-gate char **fetchattrs;
1217c478bd9Sstevel@tonic-gate struct ldap_oclist *ocp;
1227c478bd9Sstevel@tonic-gate struct ldap_adddeflist *adp;
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate printf( "** Template \"%s\" (plural \"%s\", icon \"%s\")\n",
1257c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_name ),
1267c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_pluralname ),
1277c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_iconname ));
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate printf( "object class list:\n" );
1307c478bd9Sstevel@tonic-gate for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = ocp->oc_next ) {
1317c478bd9Sstevel@tonic-gate for ( i = 0; ocp->oc_objclasses[ i ] != NULL; ++i ) {
1327c478bd9Sstevel@tonic-gate printf( "%s%s", i == 0 ? " " : " & ",
1337c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( ocp->oc_objclasses[ i ] ));
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate putchar( '\n' );
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate putchar( '\n' );
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate printf( "template options: " );
1407c478bd9Sstevel@tonic-gate if ( tmpl->dt_options == 0L ) {
1417c478bd9Sstevel@tonic-gate printf( "NONE\n" );
1427c478bd9Sstevel@tonic-gate } else {
1437c478bd9Sstevel@tonic-gate printf( "%s %s %s\n", LDAP_IS_DISPTMPL_OPTION_SET( tmpl,
1447c478bd9Sstevel@tonic-gate LDAP_DTMPL_OPT_ADDABLE ) ? "addable" : "",
1457c478bd9Sstevel@tonic-gate LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALLOWMODRDN )
1467c478bd9Sstevel@tonic-gate ? "modrdn" : "",
1477c478bd9Sstevel@tonic-gate LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALTVIEW )
1487c478bd9Sstevel@tonic-gate ? "altview" : "" );
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate printf( "authenticate as attribute: %s\n", tmpl->dt_authattrname != NULL ?
1527c478bd9Sstevel@tonic-gate tmpl->dt_authattrname : "<default>" );
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate printf( "default RDN attribute: %s\n", tmpl->dt_defrdnattrname != NULL ?
1557c478bd9Sstevel@tonic-gate tmpl->dt_defrdnattrname : "NONE" );
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate printf( "default add location: %s\n", tmpl->dt_defaddlocation != NULL ?
1587c478bd9Sstevel@tonic-gate tmpl->dt_defaddlocation : "NONE" );
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate printf( "\nnew entry value default rules:\n" );
1617c478bd9Sstevel@tonic-gate for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = adp->ad_next ) {
1627c478bd9Sstevel@tonic-gate if ( adp->ad_source == LDAP_ADSRC_CONSTANTVALUE ) {
1637c478bd9Sstevel@tonic-gate printf( " attribute %s <-- constant value \"%s\"\n",
1647c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_attrname),
1657c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_value ));
1667c478bd9Sstevel@tonic-gate } else {
1677c478bd9Sstevel@tonic-gate printf( " attribute %s <-- adder's DN\n",
1687c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_attrname ));
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate putchar( '\n' );
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate printf( "\nfetch attributes & values:\n" );
1747c478bd9Sstevel@tonic-gate if (( fetchattrs = ldap_tmplattrs( tmpl, includeattrs, 1,
1757c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER )) == NULL ) {
1767c478bd9Sstevel@tonic-gate printf( " <none>\n" );
1777c478bd9Sstevel@tonic-gate } else {
1787c478bd9Sstevel@tonic-gate for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
1797c478bd9Sstevel@tonic-gate printf( " %s\n", fetchattrs[ i ] );
1807c478bd9Sstevel@tonic-gate free( fetchattrs[ i ] );
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate free( (char *)fetchattrs );
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate printf( "\nfetch attributes only:\n" );
1867c478bd9Sstevel@tonic-gate if (( fetchattrs = ldap_tmplattrs( tmpl, NULL, 0,
1877c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER )) == NULL ) {
1887c478bd9Sstevel@tonic-gate printf( " <none>\n" );
1897c478bd9Sstevel@tonic-gate } else {
1907c478bd9Sstevel@tonic-gate for ( i = 0; fetchattrs[ i ] != NULL; ++i ) {
1917c478bd9Sstevel@tonic-gate printf( " %s\n", fetchattrs[ i ] );
1927c478bd9Sstevel@tonic-gate free( fetchattrs[ i ] );
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate free( (char *)fetchattrs );
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate printf( "\ntemplate items:\n" );
1987c478bd9Sstevel@tonic-gate rowcnt = 0;
1997c478bd9Sstevel@tonic-gate for ( rowp = ldap_first_tmplrow( tmpl ); rowp != NULLTMPLITEM;
2007c478bd9Sstevel@tonic-gate rowp = ldap_next_tmplrow( tmpl, rowp )) {
2017c478bd9Sstevel@tonic-gate ++rowcnt;
2027c478bd9Sstevel@tonic-gate colcnt = 0;
2037c478bd9Sstevel@tonic-gate for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULLTMPLITEM;
2047c478bd9Sstevel@tonic-gate colp = ldap_next_tmplcol( tmpl, rowp, colp )) {
2057c478bd9Sstevel@tonic-gate ++colcnt;
2067c478bd9Sstevel@tonic-gate printf( " %2d-%d: %s (%s%s", rowcnt, colcnt,
2077c478bd9Sstevel@tonic-gate syn_name[ colp->ti_syntaxid & 0x0000FFFF ],
2087c478bd9Sstevel@tonic-gate syn_type[ LDAP_GET_SYN_TYPE( colp->ti_syntaxid ) >> 24 ],
2097c478bd9Sstevel@tonic-gate (( LDAP_GET_SYN_OPTIONS( colp->ti_syntaxid ) &
2107c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER ) != 0 ) ? ",defer" : "" );
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate for ( i = 0; item_opts[ i ] != NULL; ++i ) {
2137c478bd9Sstevel@tonic-gate if ( LDAP_IS_TMPLITEM_OPTION_SET( colp, item_opt_vals[ i ] )) {
2147c478bd9Sstevel@tonic-gate printf( ",%s", NULLSTRINGIFNULL( item_opts[ i ] ));
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate printf( "), %s, %s", NULLSTRINGIFNULL( colp->ti_attrname ),
2197c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( colp->ti_label ));
2207c478bd9Sstevel@tonic-gate if ( colp->ti_args != NULL ) {
2217c478bd9Sstevel@tonic-gate printf( ",args=" );
2227c478bd9Sstevel@tonic-gate for ( i = 0; colp->ti_args[ i ] != NULL; ++i ) {
2237c478bd9Sstevel@tonic-gate printf( "<%s>", NULLSTRINGIFNULL( colp->ti_args[ i ] ));
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate putchar( '\n' );
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate void
dump_srchpref(struct ldap_searchobj * so)2347c478bd9Sstevel@tonic-gate dump_srchpref( struct ldap_searchobj *so )
2357c478bd9Sstevel@tonic-gate {
2367c478bd9Sstevel@tonic-gate int i;
2377c478bd9Sstevel@tonic-gate struct ldap_searchattr *sa;
2387c478bd9Sstevel@tonic-gate struct ldap_searchmatch *sm;
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate printf( "Object type prompt: %s\n",
2417c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_objtypeprompt ));
2427c478bd9Sstevel@tonic-gate printf( "Options: %s\n",
2437c478bd9Sstevel@tonic-gate LDAP_IS_SEARCHOBJ_OPTION_SET( so, LDAP_SEARCHOBJ_OPT_INTERNAL ) ?
2447c478bd9Sstevel@tonic-gate "internal" : "NONE" );
2457c478bd9Sstevel@tonic-gate printf( "Prompt: %s\n", NULLSTRINGIFNULL( so->so_prompt ));
2467c478bd9Sstevel@tonic-gate printf( "Scope: " );
2477c478bd9Sstevel@tonic-gate switch ( so->so_defaultscope ) {
2487c478bd9Sstevel@tonic-gate case LDAP_SCOPE_BASE:
2497c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_BASE" );
2507c478bd9Sstevel@tonic-gate break;
2517c478bd9Sstevel@tonic-gate case LDAP_SCOPE_ONELEVEL:
2527c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_ONELEVEL" );
2537c478bd9Sstevel@tonic-gate break;
2547c478bd9Sstevel@tonic-gate case LDAP_SCOPE_SUBTREE:
2557c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_SUBTREE" );
2567c478bd9Sstevel@tonic-gate break;
2577c478bd9Sstevel@tonic-gate default:
2587c478bd9Sstevel@tonic-gate printf("*** unknown!" );
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate puts( "\n" );
2617c478bd9Sstevel@tonic-gate printf( "Filter prefix: %s\n",
2627c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_filterprefix ));
2637c478bd9Sstevel@tonic-gate printf( "Filter tag: %s\n",
2647c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_filtertag ));
2657c478bd9Sstevel@tonic-gate printf( "Default select attr: %s\n",
2667c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_defaultselectattr ));
2677c478bd9Sstevel@tonic-gate printf( "Default select text: %s\n",
2687c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_defaultselecttext ));
2697c478bd9Sstevel@tonic-gate printf( "Searchable attributes ---- \n" );
2707c478bd9Sstevel@tonic-gate for ( sa = so->so_salist; sa != NULL; sa = sa->sa_next ) {
2717c478bd9Sstevel@tonic-gate printf( " Label: %s\n", NULLSTRINGIFNULL( sa->sa_attrlabel ));
2727c478bd9Sstevel@tonic-gate printf( " Attribute: %s\n", NULLSTRINGIFNULL( sa->sa_attr ));
2737c478bd9Sstevel@tonic-gate printf( " Select attr: %s\n", NULLSTRINGIFNULL( sa->sa_selectattr ));
2747c478bd9Sstevel@tonic-gate printf( " Select text: %s\n", NULLSTRINGIFNULL( sa->sa_selecttext ));
2757c478bd9Sstevel@tonic-gate printf( " Match types ---- \n" );
2767c478bd9Sstevel@tonic-gate for ( i = 0, sm = so->so_smlist; sm != NULL; i++, sm = sm->sm_next ) {
2777c478bd9Sstevel@tonic-gate if (( sa->sa_matchtypebitmap >> i ) & 1 ) {
2787c478bd9Sstevel@tonic-gate printf( " %s (%s)\n",
2797c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( sm->sm_matchprompt ),
2807c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( sm->sm_filter ));
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate }
285