1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * 3*7c478bd9Sstevel@tonic-gate * Portions Copyright %G% Sun Microsystems, Inc. All Rights Reserved 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate */ 6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*7c478bd9Sstevel@tonic-gate #include <stdio.h> 8*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 9*7c478bd9Sstevel@tonic-gate #include "lber.h" 10*7c478bd9Sstevel@tonic-gate #include "ldap.h" 11*7c478bd9Sstevel@tonic-gate #include "disptmpl.h" 12*7c478bd9Sstevel@tonic-gate #include "srchpref.h" 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate #ifdef MACOS 15*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 16*7c478bd9Sstevel@tonic-gate #include <console.h> 17*7c478bd9Sstevel@tonic-gate #endif /* MACOS */ 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate #ifdef NEEDPROTOS 20*7c478bd9Sstevel@tonic-gate void dump_tmpl( struct ldap_disptmpl *tmpl ); 21*7c478bd9Sstevel@tonic-gate void dump_srchpref( struct ldap_searchobj *sp ); 22*7c478bd9Sstevel@tonic-gate #else /* NEEDPROTOS */ 23*7c478bd9Sstevel@tonic-gate void dump_tmpl(); 24*7c478bd9Sstevel@tonic-gate void dump_srchpref(); 25*7c478bd9Sstevel@tonic-gate #endif /* NEEDPROTOS */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #define NULLSTRINGIFNULL( s ) ( s == NULL ? "(null)" : s ) 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate int 32*7c478bd9Sstevel@tonic-gate main( int argc, char **argv ) 33*7c478bd9Sstevel@tonic-gate { 34*7c478bd9Sstevel@tonic-gate struct ldap_disptmpl *templates, *dtp; 35*7c478bd9Sstevel@tonic-gate struct ldap_searchobj *so, *sop; 36*7c478bd9Sstevel@tonic-gate int err; 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef MACOS 39*7c478bd9Sstevel@tonic-gate ccommand( &argv ); 40*7c478bd9Sstevel@tonic-gate for ( argc = 0; argv[ argc ] != NULL; ++argc ) { 41*7c478bd9Sstevel@tonic-gate ; 42*7c478bd9Sstevel@tonic-gate } 43*7c478bd9Sstevel@tonic-gate cshow( stdout ); 44*7c478bd9Sstevel@tonic-gate #endif /* MACOS */ 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate if (( err = ldap_init_templates( "ldaptemplates.conf", &templates )) 47*7c478bd9Sstevel@tonic-gate != 0 ) { 48*7c478bd9Sstevel@tonic-gate fprintf( stderr, "ldap_init_templates failed (%d)\n", err ); 49*7c478bd9Sstevel@tonic-gate exit( 1 ); 50*7c478bd9Sstevel@tonic-gate } 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate if (( err = ldap_init_searchprefs( "ldapsearchprefs.conf", &so )) 53*7c478bd9Sstevel@tonic-gate != 0 ) { 54*7c478bd9Sstevel@tonic-gate fprintf( stderr, "ldap_init_searchprefs failed (%d)\n", err ); 55*7c478bd9Sstevel@tonic-gate exit( 1 ); 56*7c478bd9Sstevel@tonic-gate } 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate if ( argc == 1 ) { 59*7c478bd9Sstevel@tonic-gate printf( "*** Display Templates:\n" ); 60*7c478bd9Sstevel@tonic-gate for ( dtp = ldap_first_disptmpl( templates ); dtp != NULLDISPTMPL; 61*7c478bd9Sstevel@tonic-gate dtp = ldap_next_disptmpl( templates, dtp )) { 62*7c478bd9Sstevel@tonic-gate dump_tmpl( dtp ); 63*7c478bd9Sstevel@tonic-gate printf( "\n\n" ); 64*7c478bd9Sstevel@tonic-gate } 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate printf( "\n\n*** Search Objects:\n" ); 67*7c478bd9Sstevel@tonic-gate for ( sop = ldap_first_searchobj( so ); sop != NULLSEARCHOBJ; 68*7c478bd9Sstevel@tonic-gate sop = ldap_next_searchobj( so, sop )) { 69*7c478bd9Sstevel@tonic-gate dump_srchpref( sop ); 70*7c478bd9Sstevel@tonic-gate printf( "\n\n" ); 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate } else { 74*7c478bd9Sstevel@tonic-gate if (( dtp = ldap_oc2template( ++argv, templates )) == NULL ) { 75*7c478bd9Sstevel@tonic-gate fprintf( stderr, "no matching template found\n" ); 76*7c478bd9Sstevel@tonic-gate } else { 77*7c478bd9Sstevel@tonic-gate dump_tmpl( dtp ); 78*7c478bd9Sstevel@tonic-gate } 79*7c478bd9Sstevel@tonic-gate } 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate ldap_free_templates( templates ); 83*7c478bd9Sstevel@tonic-gate ldap_free_searchprefs( so ); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate exit( 0 ); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate static char *syn_name[] = { 90*7c478bd9Sstevel@tonic-gate "?", "CIS", "MLS", "DN", "BOOL", "JPEG", "JPEGBTN", "FAX", "FAXBTN", 91*7c478bd9Sstevel@tonic-gate "AUDIOBTN", "TIME", "DATE", "URL", "SEARCHACT", "LINKACT", "ADDDNACT", 92*7c478bd9Sstevel@tonic-gate "VERIFYACT", 93*7c478bd9Sstevel@tonic-gate }; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate static char *syn_type[] = { 96*7c478bd9Sstevel@tonic-gate "?", "txt", "img", "?", "bool", "?", "?", "?", "btn", 97*7c478bd9Sstevel@tonic-gate "?", "?", "?", "?", "?", "?", "?", 98*7c478bd9Sstevel@tonic-gate "action", "?" 99*7c478bd9Sstevel@tonic-gate }; 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate static char *includeattrs[] = { "objectClass", "sn", NULL }; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate static char *item_opts[] = { 104*7c478bd9Sstevel@tonic-gate "ro", "sort", "1val", "hide", "required", "hideiffalse", NULL 105*7c478bd9Sstevel@tonic-gate }; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate static unsigned long item_opt_vals[] = { 108*7c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_READONLY, LDAP_DITEM_OPT_SORTVALUES, 109*7c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_SINGLEVALUED, LDAP_DITEM_OPT_HIDEIFEMPTY, 110*7c478bd9Sstevel@tonic-gate LDAP_DITEM_OPT_VALUEREQUIRED, LDAP_DITEM_OPT_HIDEIFFALSE, 111*7c478bd9Sstevel@tonic-gate }; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate void 115*7c478bd9Sstevel@tonic-gate dump_tmpl( struct ldap_disptmpl *tmpl ) 116*7c478bd9Sstevel@tonic-gate { 117*7c478bd9Sstevel@tonic-gate struct ldap_tmplitem *rowp, *colp; 118*7c478bd9Sstevel@tonic-gate int i, rowcnt, colcnt; 119*7c478bd9Sstevel@tonic-gate char **fetchattrs; 120*7c478bd9Sstevel@tonic-gate struct ldap_oclist *ocp; 121*7c478bd9Sstevel@tonic-gate struct ldap_adddeflist *adp; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate printf( "** Template \"%s\" (plural \"%s\", icon \"%s\")\n", 124*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_name ), 125*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_pluralname ), 126*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( tmpl->dt_iconname )); 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate printf( "object class list:\n" ); 129*7c478bd9Sstevel@tonic-gate for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = ocp->oc_next ) { 130*7c478bd9Sstevel@tonic-gate for ( i = 0; ocp->oc_objclasses[ i ] != NULL; ++i ) { 131*7c478bd9Sstevel@tonic-gate printf( "%s%s", i == 0 ? " " : " & ", 132*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( ocp->oc_objclasses[ i ] )); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate printf( "template options: " ); 139*7c478bd9Sstevel@tonic-gate if ( tmpl->dt_options == 0L ) { 140*7c478bd9Sstevel@tonic-gate printf( "NONE\n" ); 141*7c478bd9Sstevel@tonic-gate } else { 142*7c478bd9Sstevel@tonic-gate printf( "%s %s %s\n", LDAP_IS_DISPTMPL_OPTION_SET( tmpl, 143*7c478bd9Sstevel@tonic-gate LDAP_DTMPL_OPT_ADDABLE ) ? "addable" : "", 144*7c478bd9Sstevel@tonic-gate LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALLOWMODRDN ) 145*7c478bd9Sstevel@tonic-gate ? "modrdn" : "", 146*7c478bd9Sstevel@tonic-gate LDAP_IS_DISPTMPL_OPTION_SET( tmpl, LDAP_DTMPL_OPT_ALTVIEW ) 147*7c478bd9Sstevel@tonic-gate ? "altview" : "" ); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate printf( "authenticate as attribute: %s\n", tmpl->dt_authattrname != NULL ? 151*7c478bd9Sstevel@tonic-gate tmpl->dt_authattrname : "<default>" ); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate printf( "default RDN attribute: %s\n", tmpl->dt_defrdnattrname != NULL ? 154*7c478bd9Sstevel@tonic-gate tmpl->dt_defrdnattrname : "NONE" ); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate printf( "default add location: %s\n", tmpl->dt_defaddlocation != NULL ? 157*7c478bd9Sstevel@tonic-gate tmpl->dt_defaddlocation : "NONE" ); 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate printf( "\nnew entry value default rules:\n" ); 160*7c478bd9Sstevel@tonic-gate for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = adp->ad_next ) { 161*7c478bd9Sstevel@tonic-gate if ( adp->ad_source == LDAP_ADSRC_CONSTANTVALUE ) { 162*7c478bd9Sstevel@tonic-gate printf( " attribute %s <-- constant value \"%s\"\n", 163*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_attrname), 164*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_value )); 165*7c478bd9Sstevel@tonic-gate } else { 166*7c478bd9Sstevel@tonic-gate printf( " attribute %s <-- adder's DN\n", 167*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( adp->ad_attrname )); 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate } 170*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate printf( "\nfetch attributes & values:\n" ); 173*7c478bd9Sstevel@tonic-gate if (( fetchattrs = ldap_tmplattrs( tmpl, includeattrs, 1, 174*7c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER )) == NULL ) { 175*7c478bd9Sstevel@tonic-gate printf( " <none>\n" ); 176*7c478bd9Sstevel@tonic-gate } else { 177*7c478bd9Sstevel@tonic-gate for ( i = 0; fetchattrs[ i ] != NULL; ++i ) { 178*7c478bd9Sstevel@tonic-gate printf( " %s\n", fetchattrs[ i ] ); 179*7c478bd9Sstevel@tonic-gate free( fetchattrs[ i ] ); 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate free( (char *)fetchattrs ); 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate printf( "\nfetch attributes only:\n" ); 185*7c478bd9Sstevel@tonic-gate if (( fetchattrs = ldap_tmplattrs( tmpl, NULL, 0, 186*7c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER )) == NULL ) { 187*7c478bd9Sstevel@tonic-gate printf( " <none>\n" ); 188*7c478bd9Sstevel@tonic-gate } else { 189*7c478bd9Sstevel@tonic-gate for ( i = 0; fetchattrs[ i ] != NULL; ++i ) { 190*7c478bd9Sstevel@tonic-gate printf( " %s\n", fetchattrs[ i ] ); 191*7c478bd9Sstevel@tonic-gate free( fetchattrs[ i ] ); 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate free( (char *)fetchattrs ); 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate printf( "\ntemplate items:\n" ); 197*7c478bd9Sstevel@tonic-gate rowcnt = 0; 198*7c478bd9Sstevel@tonic-gate for ( rowp = ldap_first_tmplrow( tmpl ); rowp != NULLTMPLITEM; 199*7c478bd9Sstevel@tonic-gate rowp = ldap_next_tmplrow( tmpl, rowp )) { 200*7c478bd9Sstevel@tonic-gate ++rowcnt; 201*7c478bd9Sstevel@tonic-gate colcnt = 0; 202*7c478bd9Sstevel@tonic-gate for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULLTMPLITEM; 203*7c478bd9Sstevel@tonic-gate colp = ldap_next_tmplcol( tmpl, rowp, colp )) { 204*7c478bd9Sstevel@tonic-gate ++colcnt; 205*7c478bd9Sstevel@tonic-gate printf( " %2d-%d: %s (%s%s", rowcnt, colcnt, 206*7c478bd9Sstevel@tonic-gate syn_name[ colp->ti_syntaxid & 0x0000FFFF ], 207*7c478bd9Sstevel@tonic-gate syn_type[ LDAP_GET_SYN_TYPE( colp->ti_syntaxid ) >> 24 ], 208*7c478bd9Sstevel@tonic-gate (( LDAP_GET_SYN_OPTIONS( colp->ti_syntaxid ) & 209*7c478bd9Sstevel@tonic-gate LDAP_SYN_OPT_DEFER ) != 0 ) ? ",defer" : "" ); 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate for ( i = 0; item_opts[ i ] != NULL; ++i ) { 212*7c478bd9Sstevel@tonic-gate if ( LDAP_IS_TMPLITEM_OPTION_SET( colp, item_opt_vals[ i ] )) { 213*7c478bd9Sstevel@tonic-gate printf( ",%s", NULLSTRINGIFNULL( item_opts[ i ] )); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate printf( "), %s, %s", NULLSTRINGIFNULL( colp->ti_attrname ), 218*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( colp->ti_label )); 219*7c478bd9Sstevel@tonic-gate if ( colp->ti_args != NULL ) { 220*7c478bd9Sstevel@tonic-gate printf( ",args=" ); 221*7c478bd9Sstevel@tonic-gate for ( i = 0; colp->ti_args[ i ] != NULL; ++i ) { 222*7c478bd9Sstevel@tonic-gate printf( "<%s>", NULLSTRINGIFNULL( colp->ti_args[ i ] )); 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate void 233*7c478bd9Sstevel@tonic-gate dump_srchpref( struct ldap_searchobj *so ) 234*7c478bd9Sstevel@tonic-gate { 235*7c478bd9Sstevel@tonic-gate int i; 236*7c478bd9Sstevel@tonic-gate struct ldap_searchattr *sa; 237*7c478bd9Sstevel@tonic-gate struct ldap_searchmatch *sm; 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate printf( "Object type prompt: %s\n", 240*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_objtypeprompt )); 241*7c478bd9Sstevel@tonic-gate printf( "Options: %s\n", 242*7c478bd9Sstevel@tonic-gate LDAP_IS_SEARCHOBJ_OPTION_SET( so, LDAP_SEARCHOBJ_OPT_INTERNAL ) ? 243*7c478bd9Sstevel@tonic-gate "internal" : "NONE" ); 244*7c478bd9Sstevel@tonic-gate printf( "Prompt: %s\n", NULLSTRINGIFNULL( so->so_prompt )); 245*7c478bd9Sstevel@tonic-gate printf( "Scope: " ); 246*7c478bd9Sstevel@tonic-gate switch ( so->so_defaultscope ) { 247*7c478bd9Sstevel@tonic-gate case LDAP_SCOPE_BASE: 248*7c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_BASE" ); 249*7c478bd9Sstevel@tonic-gate break; 250*7c478bd9Sstevel@tonic-gate case LDAP_SCOPE_ONELEVEL: 251*7c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_ONELEVEL" ); 252*7c478bd9Sstevel@tonic-gate break; 253*7c478bd9Sstevel@tonic-gate case LDAP_SCOPE_SUBTREE: 254*7c478bd9Sstevel@tonic-gate printf( "LDAP_SCOPE_SUBTREE" ); 255*7c478bd9Sstevel@tonic-gate break; 256*7c478bd9Sstevel@tonic-gate default: 257*7c478bd9Sstevel@tonic-gate printf("*** unknown!" ); 258*7c478bd9Sstevel@tonic-gate } 259*7c478bd9Sstevel@tonic-gate puts( "\n" ); 260*7c478bd9Sstevel@tonic-gate printf( "Filter prefix: %s\n", 261*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_filterprefix )); 262*7c478bd9Sstevel@tonic-gate printf( "Filter tag: %s\n", 263*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_filtertag )); 264*7c478bd9Sstevel@tonic-gate printf( "Default select attr: %s\n", 265*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_defaultselectattr )); 266*7c478bd9Sstevel@tonic-gate printf( "Default select text: %s\n", 267*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( so->so_defaultselecttext )); 268*7c478bd9Sstevel@tonic-gate printf( "Searchable attributes ---- \n" ); 269*7c478bd9Sstevel@tonic-gate for ( sa = so->so_salist; sa != NULL; sa = sa->sa_next ) { 270*7c478bd9Sstevel@tonic-gate printf( " Label: %s\n", NULLSTRINGIFNULL( sa->sa_attrlabel )); 271*7c478bd9Sstevel@tonic-gate printf( " Attribute: %s\n", NULLSTRINGIFNULL( sa->sa_attr )); 272*7c478bd9Sstevel@tonic-gate printf( " Select attr: %s\n", NULLSTRINGIFNULL( sa->sa_selectattr )); 273*7c478bd9Sstevel@tonic-gate printf( " Select text: %s\n", NULLSTRINGIFNULL( sa->sa_selecttext )); 274*7c478bd9Sstevel@tonic-gate printf( " Match types ---- \n" ); 275*7c478bd9Sstevel@tonic-gate for ( i = 0, sm = so->so_smlist; sm != NULL; i++, sm = sm->sm_next ) { 276*7c478bd9Sstevel@tonic-gate if (( sa->sa_matchtypebitmap >> i ) & 1 ) { 277*7c478bd9Sstevel@tonic-gate printf( " %s (%s)\n", 278*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( sm->sm_matchprompt ), 279*7c478bd9Sstevel@tonic-gate NULLSTRINGIFNULL( sm->sm_filter )); 280*7c478bd9Sstevel@tonic-gate } 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate } 283*7c478bd9Sstevel@tonic-gate } 284