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