1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*7c478bd9Sstevel@tonic-gate 8*7c478bd9Sstevel@tonic-gate /* 9*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public 10*7c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file 11*7c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of 12*7c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/ 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS 15*7c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 16*7c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing 17*7c478bd9Sstevel@tonic-gate * rights and limitations under the License. 18*7c478bd9Sstevel@tonic-gate * 19*7c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released 20*7c478bd9Sstevel@tonic-gate * March 31, 1998. 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape 23*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are 24*7c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All 25*7c478bd9Sstevel@tonic-gate * Rights Reserved. 26*7c478bd9Sstevel@tonic-gate * 27*7c478bd9Sstevel@tonic-gate * Contributor(s): 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* ldapsearch.c - generic program to search LDAP */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include "ldaptool.h" 33*7c478bd9Sstevel@tonic-gate #include "fileurl.h" 34*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 35*7c478bd9Sstevel@tonic-gate #include <locale.h> 36*7c478bd9Sstevel@tonic-gate #include "solaris-int.h" 37*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #define VLV_PARAM_SEP ':' 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 42*7c478bd9Sstevel@tonic-gate #define gettext(s) s 43*7c478bd9Sstevel@tonic-gate #endif 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate static void usage( void ); 46*7c478bd9Sstevel@tonic-gate static int dosearch( LDAP *ld, char *base, int scope, char **attrs, 47*7c478bd9Sstevel@tonic-gate int attrsonly, char *filtpatt, char *value); 48*7c478bd9Sstevel@tonic-gate static void write_string_attr_value( char *attrname, char *strval, 49*7c478bd9Sstevel@tonic-gate unsigned long opts ); 50*7c478bd9Sstevel@tonic-gate #define LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME 0x01 51*7c478bd9Sstevel@tonic-gate static int write_ldif_value( char *type, char *value, unsigned long vallen, 52*7c478bd9Sstevel@tonic-gate unsigned long ldifoptions ); 53*7c478bd9Sstevel@tonic-gate static void print_entry( LDAP *ld, LDAPMessage *entry, int attrsonly ); 54*7c478bd9Sstevel@tonic-gate static void options_callback( int option, char *optarg ); 55*7c478bd9Sstevel@tonic-gate static void parse_and_display_reference( LDAP *ld, LDAPMessage *ref ); 56*7c478bd9Sstevel@tonic-gate static char *sortresult2string(unsigned long result); 57*7c478bd9Sstevel@tonic-gate static char *changetype_num2string( int chgtype ); 58*7c478bd9Sstevel@tonic-gate static char *msgtype2str( int msgtype ); 59*7c478bd9Sstevel@tonic-gate static char **get_effectiverights_attrlist(char * optarg); 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 62*7c478bd9Sstevel@tonic-gate static void fill_ldapsearch_msgtypes( void ); 63*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* 66*7c478bd9Sstevel@tonic-gate * Prefix used in names of pseudo attributes added to the entry LDIF 67*7c478bd9Sstevel@tonic-gate * output if we receive an entryChangeNotification control with an entry 68*7c478bd9Sstevel@tonic-gate * (requested using persistent search). 69*7c478bd9Sstevel@tonic-gate */ 70*7c478bd9Sstevel@tonic-gate #define LDAPTOOL_PSEARCH_ATTR_PREFIX "persistentSearch-" 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate static void 74*7c478bd9Sstevel@tonic-gate usage( void ) 75*7c478bd9Sstevel@tonic-gate { 76*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("usage: %s -b basedn [options] filter [attributes...]\n"), ldaptool_progname ); 77*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" %s -b basedn [options] -f file [attributes...]\nwhere:\n"), ldaptool_progname ); 78*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" basedn\tbase dn for search\n") ); 79*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t(if the environment variable LDAP_BASEDN is set,\n") ); 80*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\tthen the -b flag is not required)\n") ); 81*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" filter\tRFC-2254 compliant LDAP search filter\n") ); 82*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" file\tfile containing a sequence of LDAP search filters to use\n") ); 83*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" attributes\twhitespace-separated list of attributes to retrieve\n") ); 84*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t(if no attribute list is given, all are retrieved)\n") ); 85*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("options:\n") ); 86*7c478bd9Sstevel@tonic-gate ldaptool_common_usage( 0 ); 87*7c478bd9Sstevel@tonic-gate #if defined( XP_WIN32 ) 88*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -t\t\twrite values to files in temp directory.\n") ); 89*7c478bd9Sstevel@tonic-gate #else 90*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -t\t\twrite values to files in /tmp\n") ); 91*7c478bd9Sstevel@tonic-gate #endif 92*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -U\t\tproduce file URLs in conjunction with -t\n") ); 93*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -e\t\tminimize base-64 encoding of values\n") ); 94*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -u\t\tinclude User Friendly entry names in the output\n") ); 95*7c478bd9Sstevel@tonic-gate #ifndef HAVE_SASL_OPTIONS 96*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -o\t\tprint entries using old format (default is LDIF)\n") ); 97*7c478bd9Sstevel@tonic-gate #endif 98*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -T\t\tdon't fold (wrap) long lines (default is to fold)\n") ); 99*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -1\t\tomit leading \"version: %d\" line in LDIF output\n"), LDIF_VERSION_ONE ); 100*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -A\t\tretrieve attribute names only (no values)\n") ); 101*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -B\t\tprint non-ASCII values and use old output format (attr=value)\n") ); 102*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -x\t\tperforming sorting on server\n") ); 103*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 104*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -r\t\tprint entries using old format (default is LDIF)\n") ); 105*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 106*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -F sep\tprint `sep' instead of `%s' between attribute names\n"), LDAPTOOL_DEFSEP ); 107*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" \tand values\n") ); 108*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -S attr\tsort the results by attribute `attr'\n") ); 109*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -s scope\tone of base, one, or sub (default is sub)\n") ); 110*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -a deref\tone of never, always, search, or find (default: never)\n") ); 111*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" \t(alias dereferencing)\n") ); 112*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -l timelim\ttime limit (in seconds) for search (default is no limit)\n") ); 113*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -z sizelim\tsize limit (in entries) for search (default is no limit)\n") ); 114*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -C ps:changetype[:changesonly[:entrychgcontrols]]\n") ); 115*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\tchangetypes are add,delete,modify,moddn,any\n") ); 116*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\tchangesonly and entrychgcontrols are boolean values\n") ); 117*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t(default is 1)\n") ); 118*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -G before%cafter%cindex%ccount | before%cafter%cvalue where 'before' and\n"), VLV_PARAM_SEP, VLV_PARAM_SEP, VLV_PARAM_SEP, VLV_PARAM_SEP, VLV_PARAM_SEP ); 119*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t'after' are the number of entries surrounding 'index.'\n")); 120*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t'count' is the content count, 'value' is the search value.\n")); 121*7c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 122*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -c authzid\tspecifies the getEffectiveRights control authzid\n")); 123*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t eg. dn:uid=bjensen,dc=example,dc=com\n")); 124*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t A value of \"\" means \"the authorization id for the operation\".\n")); 125*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t A value of \"dn:\" means \"anonymous\"\n")); 126*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t (The aclRights operational attribute must be requested)\n")); 127*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext(" -X attrlist\tspecifies the getEffectiveRights control specific attribute list.\n")); 128*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("\t\t eg. \"nsroledn userPassword\"\n")); 129*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate exit( LDAP_PARAM_ERROR ); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate static char *base = NULL; 135*7c478bd9Sstevel@tonic-gate static char *sep = LDAPTOOL_DEFSEP; 136*7c478bd9Sstevel@tonic-gate static char **sortattr = NULL; 137*7c478bd9Sstevel@tonic-gate static char *vlv_value = NULL; 138*7c478bd9Sstevel@tonic-gate static int sortsize = 0; 139*7c478bd9Sstevel@tonic-gate static int *skipsortattr = NULL; 140*7c478bd9Sstevel@tonic-gate static int includeufn, allow_binary, vals2tmp, ldif, scope, deref; 141*7c478bd9Sstevel@tonic-gate static int attrsonly, timelimit, sizelimit, server_sort, fold; 142*7c478bd9Sstevel@tonic-gate static int minimize_base64, produce_file_urls; 143*7c478bd9Sstevel@tonic-gate static int use_vlv = 0, vlv_before, vlv_after, vlv_index, vlv_count; 144*7c478bd9Sstevel@tonic-gate static int use_psearch=0; 145*7c478bd9Sstevel@tonic-gate static int write_ldif_version = 1; 146*7c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 147*7c478bd9Sstevel@tonic-gate static char *get_effectiverights_control_target_dn = NULL; /* -c */ 148*7c478bd9Sstevel@tonic-gate static char **get_effectiverights_control_attrlist = NULL; /* -X */ 149*7c478bd9Sstevel@tonic-gate static int do_effective_rights_control = 0; 150*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* Persistent search variables */ 153*7c478bd9Sstevel@tonic-gate static int chgtype=0, changesonly=1, return_echg_ctls=1; 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate int 157*7c478bd9Sstevel@tonic-gate main( int argc, char **argv ) 158*7c478bd9Sstevel@tonic-gate { 159*7c478bd9Sstevel@tonic-gate char *filtpattern, **attrs; 160*7c478bd9Sstevel@tonic-gate int rc, optind, i, first, free_filtpattern; 161*7c478bd9Sstevel@tonic-gate LDAP *ld; 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 164*7c478bd9Sstevel@tonic-gate char *locale = setlocale(LC_ALL, ""); 165*7c478bd9Sstevel@tonic-gate textdomain(TEXT_DOMAIN); 166*7c478bd9Sstevel@tonic-gate ldaptool_require_binddn = 0; 167*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate free_filtpattern = 0; 170*7c478bd9Sstevel@tonic-gate deref = LDAP_DEREF_NEVER; 171*7c478bd9Sstevel@tonic-gate allow_binary = vals2tmp = attrsonly = 0; 172*7c478bd9Sstevel@tonic-gate minimize_base64 = produce_file_urls = 0; 173*7c478bd9Sstevel@tonic-gate ldif = 1; 174*7c478bd9Sstevel@tonic-gate fold = 1; 175*7c478bd9Sstevel@tonic-gate sizelimit = timelimit = 0; 176*7c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_SUBTREE; 177*7c478bd9Sstevel@tonic-gate server_sort = 0; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate #ifdef notdef 181*7c478bd9Sstevel@tonic-gate #ifdef HPUX11 182*7c478bd9Sstevel@tonic-gate #ifndef __LP64__ 183*7c478bd9Sstevel@tonic-gate _main( argc, argv); 184*7c478bd9Sstevel@tonic-gate #endif /* __LP64_ */ 185*7c478bd9Sstevel@tonic-gate #endif /* HPUX11 */ 186*7c478bd9Sstevel@tonic-gate #endif 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate ldaptool_reset_control_array( ldaptool_request_ctrls ); 190*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SASL_OPTIONS 191*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 192*7c478bd9Sstevel@tonic-gate optind = ldaptool_process_args( argc, argv, "ABLTU1etuxra:b:F:G:l:S:s:z:C:", 193*7c478bd9Sstevel@tonic-gate 0, options_callback ); 194*7c478bd9Sstevel@tonic-gate #else 195*7c478bd9Sstevel@tonic-gate optind = ldaptool_process_args( argc, argv, "ABLTU1etuxa:b:F:G:l:S:s:z:C:c:", 196*7c478bd9Sstevel@tonic-gate 0, options_callback ); 197*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 198*7c478bd9Sstevel@tonic-gate #else 199*7c478bd9Sstevel@tonic-gate optind = ldaptool_process_args( argc, argv, "ABLTU1eotuxa:b:F:G:l:S:s:z:C:c:", 200*7c478bd9Sstevel@tonic-gate 0, options_callback ); 201*7c478bd9Sstevel@tonic-gate #endif /* HAVE_SASL_OPTIONS */ 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate if ( optind == -1 ) { 204*7c478bd9Sstevel@tonic-gate usage(); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if ( base == NULL ) { 208*7c478bd9Sstevel@tonic-gate if (( base = getenv( "LDAP_BASEDN" )) == NULL ) { 209*7c478bd9Sstevel@tonic-gate usage(); 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate if ( sortattr ) { 213*7c478bd9Sstevel@tonic-gate for ( sortsize = 0; sortattr[sortsize] != NULL; sortsize++ ) { 214*7c478bd9Sstevel@tonic-gate ; /* NULL */ 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate sortsize++; /* add in the final NULL field */ 217*7c478bd9Sstevel@tonic-gate skipsortattr = (int *) malloc( sortsize * sizeof(int *) ); 218*7c478bd9Sstevel@tonic-gate if ( skipsortattr == NULL ) { 219*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 220*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate memset( (char *) skipsortattr, 0, sortsize * sizeof(int *) ); 223*7c478bd9Sstevel@tonic-gate } else if ( server_sort ) { 224*7c478bd9Sstevel@tonic-gate server_sort = 0; /* ignore this option if no sortattrs were given */ 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate if ( argc - optind < 1 ) { 228*7c478bd9Sstevel@tonic-gate if ( ldaptool_fp == NULL ) { 229*7c478bd9Sstevel@tonic-gate usage(); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate attrs = NULL; 232*7c478bd9Sstevel@tonic-gate filtpattern = "%s"; 233*7c478bd9Sstevel@tonic-gate } else { /* there are additional args (filter + attrs) */ 234*7c478bd9Sstevel@tonic-gate if ( ldaptool_fp == NULL || strstr( argv[ optind ], "%s" ) != NULL ) { 235*7c478bd9Sstevel@tonic-gate filtpattern = ldaptool_local2UTF8( argv[ optind ] ); 236*7c478bd9Sstevel@tonic-gate /* since local2UTF8 always allocates something, we should free it */ 237*7c478bd9Sstevel@tonic-gate free_filtpattern = 1; 238*7c478bd9Sstevel@tonic-gate ++optind; 239*7c478bd9Sstevel@tonic-gate } else { 240*7c478bd9Sstevel@tonic-gate filtpattern = "%s"; 241*7c478bd9Sstevel@tonic-gate } 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate if ( argv[ optind ] == NULL ) { 244*7c478bd9Sstevel@tonic-gate attrs = NULL; 245*7c478bd9Sstevel@tonic-gate } else if ( sortattr == NULL || *sortattr == '\0' || server_sort) { 246*7c478bd9Sstevel@tonic-gate attrs = &argv[ optind ]; 247*7c478bd9Sstevel@tonic-gate } else { 248*7c478bd9Sstevel@tonic-gate attrs = ldap_charray_dup( &argv[ optind ] ); 249*7c478bd9Sstevel@tonic-gate if ( attrs == NULL ) { 250*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 251*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate for ( i = 0; i < (sortsize - 1); i++ ) { 254*7c478bd9Sstevel@tonic-gate if ( !ldap_charray_inlist( attrs, sortattr[i] ) ) { 255*7c478bd9Sstevel@tonic-gate if ( ldap_charray_add( &attrs, sortattr[i] ) != 0 ) { 256*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 257*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 258*7c478bd9Sstevel@tonic-gate } 259*7c478bd9Sstevel@tonic-gate /* 260*7c478bd9Sstevel@tonic-gate * attribute in the search list only for the purpose of 261*7c478bd9Sstevel@tonic-gate * sorting 262*7c478bd9Sstevel@tonic-gate */ 263*7c478bd9Sstevel@tonic-gate skipsortattr[i] = 1; 264*7c478bd9Sstevel@tonic-gate } 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate } 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate ld = ldaptool_ldap_init( 0 ); 270*7c478bd9Sstevel@tonic-gate 271*7c478bd9Sstevel@tonic-gate if ( !ldaptool_not ) { 272*7c478bd9Sstevel@tonic-gate ldap_set_option( ld, LDAP_OPT_DEREF, &deref ); 273*7c478bd9Sstevel@tonic-gate ldap_set_option( ld, LDAP_OPT_TIMELIMIT, &timelimit ); 274*7c478bd9Sstevel@tonic-gate ldap_set_option( ld, LDAP_OPT_SIZELIMIT, &sizelimit ); 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate ldaptool_bind( ld ); 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 280*7c478bd9Sstevel@tonic-gate printf( gettext("filter pattern: %s\nreturning: "), filtpattern ); 281*7c478bd9Sstevel@tonic-gate if ( attrs == NULL ) { 282*7c478bd9Sstevel@tonic-gate printf( gettext("ALL") ); 283*7c478bd9Sstevel@tonic-gate } else { 284*7c478bd9Sstevel@tonic-gate for ( i = 0; attrs[ i ] != NULL; ++i ) { 285*7c478bd9Sstevel@tonic-gate printf( "%s ", attrs[ i ] ); 286*7c478bd9Sstevel@tonic-gate } 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 289*7c478bd9Sstevel@tonic-gate } 290*7c478bd9Sstevel@tonic-gate 291*7c478bd9Sstevel@tonic-gate if ( ldaptool_fp == NULL ) { 292*7c478bd9Sstevel@tonic-gate char *conv; 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate conv = ldaptool_local2UTF8( base ); 295*7c478bd9Sstevel@tonic-gate rc = dosearch( ld, conv, scope, attrs, attrsonly, filtpattern, "" ); 296*7c478bd9Sstevel@tonic-gate if( conv != NULL ) 297*7c478bd9Sstevel@tonic-gate free( conv ); 298*7c478bd9Sstevel@tonic-gate } else { 299*7c478bd9Sstevel@tonic-gate int done = 0; 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate rc = LDAP_SUCCESS; 302*7c478bd9Sstevel@tonic-gate first = 1; 303*7c478bd9Sstevel@tonic-gate while ( rc == LDAP_SUCCESS && !done ) { 304*7c478bd9Sstevel@tonic-gate char *linep = NULL; 305*7c478bd9Sstevel@tonic-gate int increment = 0; 306*7c478bd9Sstevel@tonic-gate int c, index; 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate /* allocate initial block of memory */ 309*7c478bd9Sstevel@tonic-gate if ((linep = (char *)malloc(BUFSIZ)) == NULL) { 310*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 311*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 312*7c478bd9Sstevel@tonic-gate } 313*7c478bd9Sstevel@tonic-gate increment++; 314*7c478bd9Sstevel@tonic-gate index = 0; 315*7c478bd9Sstevel@tonic-gate while ((c = fgetc( ldaptool_fp )) != '\n' && c != EOF) { 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate /* check if we will overflow the buffer */ 318*7c478bd9Sstevel@tonic-gate if ((c != EOF) && (index == ((increment * BUFSIZ) -1))) { 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate /* if we did, add another BUFSIZ worth of bytes */ 321*7c478bd9Sstevel@tonic-gate if ((linep = (char *) 322*7c478bd9Sstevel@tonic-gate realloc(linep, (increment + 1) * BUFSIZ)) == NULL) { 323*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 324*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate increment++; 327*7c478bd9Sstevel@tonic-gate } 328*7c478bd9Sstevel@tonic-gate linep[index++] = c; 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate if (c == EOF) { 332*7c478bd9Sstevel@tonic-gate done = 1; 333*7c478bd9Sstevel@tonic-gate break; 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate linep[index] = '\0'; 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate if ( !first ) { 339*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 340*7c478bd9Sstevel@tonic-gate } else { 341*7c478bd9Sstevel@tonic-gate first = 0; 342*7c478bd9Sstevel@tonic-gate } 343*7c478bd9Sstevel@tonic-gate rc = dosearch( ld, base, scope, attrs, attrsonly, filtpattern, 344*7c478bd9Sstevel@tonic-gate linep ); 345*7c478bd9Sstevel@tonic-gate free (linep); 346*7c478bd9Sstevel@tonic-gate } 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate 349*7c478bd9Sstevel@tonic-gate ldaptool_cleanup( ld ); 350*7c478bd9Sstevel@tonic-gate if (free_filtpattern != 0 && filtpattern != NULL) { 351*7c478bd9Sstevel@tonic-gate free (filtpattern); 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate return( rc ); 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate static void 358*7c478bd9Sstevel@tonic-gate options_callback( int option, char *optarg ) 359*7c478bd9Sstevel@tonic-gate { 360*7c478bd9Sstevel@tonic-gate char *s, *temp_arg, *ps_ptr, *ps_arg; 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate switch( option ) { 363*7c478bd9Sstevel@tonic-gate case 'u': /* include UFN */ 364*7c478bd9Sstevel@tonic-gate ++includeufn; 365*7c478bd9Sstevel@tonic-gate break; 366*7c478bd9Sstevel@tonic-gate case 't': /* write attribute values to /tmp files */ 367*7c478bd9Sstevel@tonic-gate ++vals2tmp; 368*7c478bd9Sstevel@tonic-gate break; 369*7c478bd9Sstevel@tonic-gate case 'U': /* produce file URLs in conjunction with -t */ 370*7c478bd9Sstevel@tonic-gate ++produce_file_urls; 371*7c478bd9Sstevel@tonic-gate break; 372*7c478bd9Sstevel@tonic-gate case 'e': /* minimize base-64 encoding of values */ 373*7c478bd9Sstevel@tonic-gate ++minimize_base64; 374*7c478bd9Sstevel@tonic-gate break; 375*7c478bd9Sstevel@tonic-gate case 'A': /* retrieve attribute names only -- no values */ 376*7c478bd9Sstevel@tonic-gate ++attrsonly; 377*7c478bd9Sstevel@tonic-gate break; 378*7c478bd9Sstevel@tonic-gate case 'L': /* print entries in LDIF format -- now the default */ 379*7c478bd9Sstevel@tonic-gate break; 380*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 381*7c478bd9Sstevel@tonic-gate case 'r': /* print entries in the old format */ 382*7c478bd9Sstevel@tonic-gate ldif = 0; 383*7c478bd9Sstevel@tonic-gate break; 384*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 385*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SASL_OPTIONS 386*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SASL_OPTIONS_2 387*7c478bd9Sstevel@tonic-gate case 'o': /* print entries using old ldapsearch format */ 388*7c478bd9Sstevel@tonic-gate ldif = 0; 389*7c478bd9Sstevel@tonic-gate break; 390*7c478bd9Sstevel@tonic-gate #endif 391*7c478bd9Sstevel@tonic-gate #else 392*7c478bd9Sstevel@tonic-gate case 'o': /* print entries using old ldapsearch format */ 393*7c478bd9Sstevel@tonic-gate ldif = 0; 394*7c478bd9Sstevel@tonic-gate break; 395*7c478bd9Sstevel@tonic-gate #endif 396*7c478bd9Sstevel@tonic-gate case 'B': /* allow binary values to be printed, use old format */ 397*7c478bd9Sstevel@tonic-gate ++allow_binary; 398*7c478bd9Sstevel@tonic-gate ldif = 0; 399*7c478bd9Sstevel@tonic-gate break; 400*7c478bd9Sstevel@tonic-gate case '1': /* omit leading "version: #" line from LDIF output */ 401*7c478bd9Sstevel@tonic-gate write_ldif_version = 0; 402*7c478bd9Sstevel@tonic-gate break; 403*7c478bd9Sstevel@tonic-gate case 's': /* search scope */ 404*7c478bd9Sstevel@tonic-gate if ( strncasecmp( optarg, "base", 4 ) == 0 ) { 405*7c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_BASE; 406*7c478bd9Sstevel@tonic-gate } else if ( strncasecmp( optarg, "one", 3 ) == 0 ) { 407*7c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_ONELEVEL; 408*7c478bd9Sstevel@tonic-gate } else if ( strncasecmp( optarg, "sub", 3 ) == 0 ) { 409*7c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_SUBTREE; 410*7c478bd9Sstevel@tonic-gate } else { 411*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("scope should be base, one, or sub\n") ); 412*7c478bd9Sstevel@tonic-gate usage(); 413*7c478bd9Sstevel@tonic-gate } 414*7c478bd9Sstevel@tonic-gate break; 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate case 'a': /* set alias deref option */ 417*7c478bd9Sstevel@tonic-gate if ( strncasecmp( optarg, "never", 5 ) == 0 ) { 418*7c478bd9Sstevel@tonic-gate deref = LDAP_DEREF_NEVER; 419*7c478bd9Sstevel@tonic-gate } else if ( strncasecmp( optarg, "search", 5 ) == 0 ) { 420*7c478bd9Sstevel@tonic-gate deref = LDAP_DEREF_SEARCHING; 421*7c478bd9Sstevel@tonic-gate } else if ( strncasecmp( optarg, "find", 4 ) == 0 ) { 422*7c478bd9Sstevel@tonic-gate deref = LDAP_DEREF_FINDING; 423*7c478bd9Sstevel@tonic-gate } else if ( strncasecmp( optarg, "always", 6 ) == 0 ) { 424*7c478bd9Sstevel@tonic-gate deref = LDAP_DEREF_ALWAYS; 425*7c478bd9Sstevel@tonic-gate } else { 426*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("alias deref should be never, search, find, or always\n") ); 427*7c478bd9Sstevel@tonic-gate usage(); 428*7c478bd9Sstevel@tonic-gate } 429*7c478bd9Sstevel@tonic-gate break; 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate case 'F': /* field separator */ 432*7c478bd9Sstevel@tonic-gate sep = strdup( optarg ); 433*7c478bd9Sstevel@tonic-gate ldif = 0; 434*7c478bd9Sstevel@tonic-gate break; 435*7c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 436*7c478bd9Sstevel@tonic-gate case 'c': 437*7c478bd9Sstevel@tonic-gate if ( optarg && optarg[0] == '\0' ) { 438*7c478bd9Sstevel@tonic-gate /* -c "" 439*7c478bd9Sstevel@tonic-gate means "This user" 440*7c478bd9Sstevel@tonic-gate */ 441*7c478bd9Sstevel@tonic-gate get_effectiverights_control_target_dn = NULL; 442*7c478bd9Sstevel@tonic-gate do_effective_rights_control = 1; 443*7c478bd9Sstevel@tonic-gate }else if ( strlen(optarg) < 3 || (strncasecmp(optarg, "dn:", 3) != 0) ) { 444*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("-c wrong format--should be \"\" or \"dn:...\".\n" 445*7c478bd9Sstevel@tonic-gate "\"dn:\" means anonymous user.")); 446*7c478bd9Sstevel@tonic-gate usage(); 447*7c478bd9Sstevel@tonic-gate } else { 448*7c478bd9Sstevel@tonic-gate get_effectiverights_control_target_dn = strdup(optarg); 449*7c478bd9Sstevel@tonic-gate do_effective_rights_control = 1; 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate break; 452*7c478bd9Sstevel@tonic-gate case 'X': 453*7c478bd9Sstevel@tonic-gate get_effectiverights_control_attrlist = get_effectiverights_attrlist(optarg); 454*7c478bd9Sstevel@tonic-gate do_effective_rights_control = 1; 455*7c478bd9Sstevel@tonic-gate break; 456*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 457*7c478bd9Sstevel@tonic-gate case 'b': /* searchbase */ 458*7c478bd9Sstevel@tonic-gate base = strdup( optarg ); 459*7c478bd9Sstevel@tonic-gate break; 460*7c478bd9Sstevel@tonic-gate case 'l': /* time limit */ 461*7c478bd9Sstevel@tonic-gate timelimit = atoi( optarg ); 462*7c478bd9Sstevel@tonic-gate break; 463*7c478bd9Sstevel@tonic-gate case 'x': /* server sorting requested */ 464*7c478bd9Sstevel@tonic-gate server_sort = 1; 465*7c478bd9Sstevel@tonic-gate break; 466*7c478bd9Sstevel@tonic-gate case 'z': /* size limit */ 467*7c478bd9Sstevel@tonic-gate sizelimit = atoi( optarg ); 468*7c478bd9Sstevel@tonic-gate break; 469*7c478bd9Sstevel@tonic-gate case 'S': /* sort attribute */ 470*7c478bd9Sstevel@tonic-gate ldap_charray_add( &sortattr, strdup( optarg ) ); 471*7c478bd9Sstevel@tonic-gate break; 472*7c478bd9Sstevel@tonic-gate case 'T': /* don't fold lines */ 473*7c478bd9Sstevel@tonic-gate fold = 0; 474*7c478bd9Sstevel@tonic-gate break; 475*7c478bd9Sstevel@tonic-gate case 'G': /* do the virtual list setup */ 476*7c478bd9Sstevel@tonic-gate use_vlv++; 477*7c478bd9Sstevel@tonic-gate s = strchr(optarg, VLV_PARAM_SEP ); 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate if (s != NULL) 480*7c478bd9Sstevel@tonic-gate { 481*7c478bd9Sstevel@tonic-gate vlv_before = atoi(optarg); 482*7c478bd9Sstevel@tonic-gate s++; 483*7c478bd9Sstevel@tonic-gate vlv_after = atoi( s ); 484*7c478bd9Sstevel@tonic-gate s = strchr(s, VLV_PARAM_SEP ); 485*7c478bd9Sstevel@tonic-gate if (s != NULL) 486*7c478bd9Sstevel@tonic-gate { 487*7c478bd9Sstevel@tonic-gate s++; 488*7c478bd9Sstevel@tonic-gate /* below is a small set of logic to implement the following cases 489*7c478bd9Sstevel@tonic-gate * -G23:23:wilber 490*7c478bd9Sstevel@tonic-gate * -G23:23:"wilber:wright" 491*7c478bd9Sstevel@tonic-gate * -G23:23:'wilber' 492*7c478bd9Sstevel@tonic-gate * -G23:23:wilber wright 493*7c478bd9Sstevel@tonic-gate * all of the above are before, after, value - NOTE: a colon not in a quoted 494*7c478bd9Sstevel@tonic-gate * string will break the parser!!!! 495*7c478bd9Sstevel@tonic-gate * -G23:23:45:600 496*7c478bd9Sstevel@tonic-gate * above is index, count encoding 497*7c478bd9Sstevel@tonic-gate */ 498*7c478bd9Sstevel@tonic-gate 499*7c478bd9Sstevel@tonic-gate if (*s == '\'' || *s == '"') 500*7c478bd9Sstevel@tonic-gate { 501*7c478bd9Sstevel@tonic-gate vlv_value = strdup( s ); 502*7c478bd9Sstevel@tonic-gate } 503*7c478bd9Sstevel@tonic-gate else 504*7c478bd9Sstevel@tonic-gate { 505*7c478bd9Sstevel@tonic-gate if (strchr( s, VLV_PARAM_SEP )) 506*7c478bd9Sstevel@tonic-gate { 507*7c478bd9Sstevel@tonic-gate /* we have an index + count option */ 508*7c478bd9Sstevel@tonic-gate vlv_index = atoi( s ); 509*7c478bd9Sstevel@tonic-gate vlv_count = atoi( strchr( s, VLV_PARAM_SEP) + 1); 510*7c478bd9Sstevel@tonic-gate } 511*7c478bd9Sstevel@tonic-gate else 512*7c478bd9Sstevel@tonic-gate { 513*7c478bd9Sstevel@tonic-gate /* we don't have a quote surrounding the assertion value 514*7c478bd9Sstevel@tonic-gate * do we need to??? 515*7c478bd9Sstevel@tonic-gate */ 516*7c478bd9Sstevel@tonic-gate vlv_value = strdup( s ); 517*7c478bd9Sstevel@tonic-gate } 518*7c478bd9Sstevel@tonic-gate } 519*7c478bd9Sstevel@tonic-gate } 520*7c478bd9Sstevel@tonic-gate else 521*7c478bd9Sstevel@tonic-gate { 522*7c478bd9Sstevel@tonic-gate fprintf( stderr,gettext("Illegal 'after' paramater for virtual list\n") ); 523*7c478bd9Sstevel@tonic-gate exit( LDAP_PARAM_ERROR ); 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate 526*7c478bd9Sstevel@tonic-gate } 527*7c478bd9Sstevel@tonic-gate else 528*7c478bd9Sstevel@tonic-gate { 529*7c478bd9Sstevel@tonic-gate fprintf( stderr,gettext("Illegal 'before' paramater for virtual list\n") ); 530*7c478bd9Sstevel@tonic-gate exit( LDAP_PARAM_ERROR ); 531*7c478bd9Sstevel@tonic-gate } 532*7c478bd9Sstevel@tonic-gate break; 533*7c478bd9Sstevel@tonic-gate case 'C': 534*7c478bd9Sstevel@tonic-gate use_psearch++; 535*7c478bd9Sstevel@tonic-gate if ( (ps_arg = strdup( optarg)) == NULL ) { 536*7c478bd9Sstevel@tonic-gate perror ("strdup"); 537*7c478bd9Sstevel@tonic-gate exit (LDAP_NO_MEMORY); 538*7c478bd9Sstevel@tonic-gate } 539*7c478bd9Sstevel@tonic-gate 540*7c478bd9Sstevel@tonic-gate ps_ptr=strtok(ps_arg, ":"); 541*7c478bd9Sstevel@tonic-gate if (ps_ptr == NULL || (strcasecmp(ps_ptr, "ps")) ) { 542*7c478bd9Sstevel@tonic-gate fprintf (stderr, gettext("Invalid argument for -C\n")); 543*7c478bd9Sstevel@tonic-gate usage(); 544*7c478bd9Sstevel@tonic-gate } 545*7c478bd9Sstevel@tonic-gate if (NULL != (ps_ptr=strtok(NULL, ":"))) { 546*7c478bd9Sstevel@tonic-gate if ( (temp_arg = strdup( ps_ptr )) == NULL ) { 547*7c478bd9Sstevel@tonic-gate perror ("strdup"); 548*7c478bd9Sstevel@tonic-gate exit (LDAP_NO_MEMORY); 549*7c478bd9Sstevel@tonic-gate } 550*7c478bd9Sstevel@tonic-gate } else { 551*7c478bd9Sstevel@tonic-gate fprintf (stderr, gettext("Invalid argument for -C\n")); 552*7c478bd9Sstevel@tonic-gate usage(); 553*7c478bd9Sstevel@tonic-gate } 554*7c478bd9Sstevel@tonic-gate if (NULL != (ps_ptr=strtok(NULL, ":"))) { 555*7c478bd9Sstevel@tonic-gate if ( (changesonly = ldaptool_boolean_str2value(ps_ptr, 0)) == -1) { 556*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Invalid option value: %s\n"), ps_ptr); 557*7c478bd9Sstevel@tonic-gate usage(); 558*7c478bd9Sstevel@tonic-gate } 559*7c478bd9Sstevel@tonic-gate } 560*7c478bd9Sstevel@tonic-gate if (NULL != (ps_ptr=strtok(NULL, ":"))) { 561*7c478bd9Sstevel@tonic-gate if ( (return_echg_ctls = ldaptool_boolean_str2value(ps_ptr, 0)) == -1) { 562*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Invalid option value: %s\n"), ps_ptr); 563*7c478bd9Sstevel@tonic-gate usage(); 564*7c478bd9Sstevel@tonic-gate } 565*7c478bd9Sstevel@tonic-gate } 566*7c478bd9Sstevel@tonic-gate 567*7c478bd9Sstevel@tonic-gate /* Now parse the temp_arg and build chgtype as 568*7c478bd9Sstevel@tonic-gate * the changetypes are encountered */ 569*7c478bd9Sstevel@tonic-gate 570*7c478bd9Sstevel@tonic-gate if ((ps_ptr = strtok( temp_arg, "," )) == NULL) { 571*7c478bd9Sstevel@tonic-gate usage(); 572*7c478bd9Sstevel@tonic-gate } else { 573*7c478bd9Sstevel@tonic-gate while ( ps_ptr ) { 574*7c478bd9Sstevel@tonic-gate if ((strcasecmp(ps_ptr, "add"))==0) 575*7c478bd9Sstevel@tonic-gate chgtype |= LDAP_CHANGETYPE_ADD; 576*7c478bd9Sstevel@tonic-gate else if ((strcasecmp(ps_ptr, "delete"))==0) 577*7c478bd9Sstevel@tonic-gate chgtype |= LDAP_CHANGETYPE_DELETE; 578*7c478bd9Sstevel@tonic-gate else if ((strcasecmp(ps_ptr, "modify"))==0) 579*7c478bd9Sstevel@tonic-gate chgtype |= LDAP_CHANGETYPE_MODIFY; 580*7c478bd9Sstevel@tonic-gate else if ((strcasecmp(ps_ptr, "moddn"))==0) 581*7c478bd9Sstevel@tonic-gate chgtype |= LDAP_CHANGETYPE_MODDN; 582*7c478bd9Sstevel@tonic-gate else if ((strcasecmp(ps_ptr, "any"))==0) 583*7c478bd9Sstevel@tonic-gate chgtype = LDAP_CHANGETYPE_ANY; 584*7c478bd9Sstevel@tonic-gate else { 585*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Unknown changetype: %s\n"), ps_ptr); 586*7c478bd9Sstevel@tonic-gate usage(); 587*7c478bd9Sstevel@tonic-gate } 588*7c478bd9Sstevel@tonic-gate ps_ptr = strtok( NULL, "," ); 589*7c478bd9Sstevel@tonic-gate } 590*7c478bd9Sstevel@tonic-gate } 591*7c478bd9Sstevel@tonic-gate break; 592*7c478bd9Sstevel@tonic-gate default: 593*7c478bd9Sstevel@tonic-gate usage(); 594*7c478bd9Sstevel@tonic-gate break; 595*7c478bd9Sstevel@tonic-gate } 596*7c478bd9Sstevel@tonic-gate } 597*7c478bd9Sstevel@tonic-gate 598*7c478bd9Sstevel@tonic-gate 599*7c478bd9Sstevel@tonic-gate static int 600*7c478bd9Sstevel@tonic-gate dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) 601*7c478bd9Sstevel@tonic-gate LDAP *ld; 602*7c478bd9Sstevel@tonic-gate char *base; 603*7c478bd9Sstevel@tonic-gate int scope; 604*7c478bd9Sstevel@tonic-gate char **attrs; 605*7c478bd9Sstevel@tonic-gate int attrsonly; 606*7c478bd9Sstevel@tonic-gate char *filtpatt; 607*7c478bd9Sstevel@tonic-gate char *value; 608*7c478bd9Sstevel@tonic-gate { 609*7c478bd9Sstevel@tonic-gate char **refs = NULL, filter[ BUFSIZ ], *filterp = NULL; 610*7c478bd9Sstevel@tonic-gate int rc, first, matches; 611*7c478bd9Sstevel@tonic-gate LDAPMessage *res, *e; 612*7c478bd9Sstevel@tonic-gate LDAPControl *ldctrl; 613*7c478bd9Sstevel@tonic-gate LDAPControl **ctrl_response_array = NULL; 614*7c478bd9Sstevel@tonic-gate LDAPVirtualList vlv_data; 615*7c478bd9Sstevel@tonic-gate int msgid = 0; 616*7c478bd9Sstevel@tonic-gate int length = 0; 617*7c478bd9Sstevel@tonic-gate int mallocd_filter = 0; 618*7c478bd9Sstevel@tonic-gate 619*7c478bd9Sstevel@tonic-gate if ( strstr( filtpatt, "%s" ) == NULL ) { /* no need to sprintf() */ 620*7c478bd9Sstevel@tonic-gate filterp = filtpatt; 621*7c478bd9Sstevel@tonic-gate } else { 622*7c478bd9Sstevel@tonic-gate length = strlen( filtpatt ) + strlen ( value ) +1; 623*7c478bd9Sstevel@tonic-gate if ( length > BUFSIZ ) { 624*7c478bd9Sstevel@tonic-gate if ((filterp = (char *) 625*7c478bd9Sstevel@tonic-gate malloc ( length )) == NULL) { 626*7c478bd9Sstevel@tonic-gate perror( gettext("filter and/or pattern too long?") ); 627*7c478bd9Sstevel@tonic-gate exit (LDAP_PARAM_ERROR); 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate mallocd_filter = 1; 630*7c478bd9Sstevel@tonic-gate } else { 631*7c478bd9Sstevel@tonic-gate filterp = filter; 632*7c478bd9Sstevel@tonic-gate } 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SNPRINTF 635*7c478bd9Sstevel@tonic-gate if ( snprintf( filterp, length, filtpatt, value ) < 0 ) { 636*7c478bd9Sstevel@tonic-gate perror( gettext("snprintf filter (filter and/or pattern too long?)") ); 637*7c478bd9Sstevel@tonic-gate exit( LDAP_PARAM_ERROR ); 638*7c478bd9Sstevel@tonic-gate } 639*7c478bd9Sstevel@tonic-gate #else 640*7c478bd9Sstevel@tonic-gate sprintf( filterp, filtpatt, value ); 641*7c478bd9Sstevel@tonic-gate #endif 642*7c478bd9Sstevel@tonic-gate } 643*7c478bd9Sstevel@tonic-gate 644*7c478bd9Sstevel@tonic-gate if ( *filterp == '\0' ) { /* treat empty filter is a shortcut for oc=* */ 645*7c478bd9Sstevel@tonic-gate if (mallocd_filter) { 646*7c478bd9Sstevel@tonic-gate free(filterp); 647*7c478bd9Sstevel@tonic-gate mallocd_filter = 0; 648*7c478bd9Sstevel@tonic-gate } 649*7c478bd9Sstevel@tonic-gate filterp = "(objectclass=*)"; 650*7c478bd9Sstevel@tonic-gate } 651*7c478bd9Sstevel@tonic-gate 652*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 653*7c478bd9Sstevel@tonic-gate /* 654*7c478bd9Sstevel@tonic-gate * Display the filter that will be used. Add surrounding parens. 655*7c478bd9Sstevel@tonic-gate * if they are missing. 656*7c478bd9Sstevel@tonic-gate */ 657*7c478bd9Sstevel@tonic-gate if ( '(' == *filterp ) { 658*7c478bd9Sstevel@tonic-gate printf( "filter is: %s\n", filterp ); 659*7c478bd9Sstevel@tonic-gate } else { 660*7c478bd9Sstevel@tonic-gate printf( "filter is: (%s)\n", filterp ); 661*7c478bd9Sstevel@tonic-gate } 662*7c478bd9Sstevel@tonic-gate } 663*7c478bd9Sstevel@tonic-gate 664*7c478bd9Sstevel@tonic-gate if ( ldaptool_not ) { 665*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 666*7c478bd9Sstevel@tonic-gate return( LDAP_SUCCESS ); 667*7c478bd9Sstevel@tonic-gate } 668*7c478bd9Sstevel@tonic-gate 669*7c478bd9Sstevel@tonic-gate if (( ldctrl = ldaptool_create_manage_dsait_control()) != NULL ) { 670*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 671*7c478bd9Sstevel@tonic-gate } 672*7c478bd9Sstevel@tonic-gate 673*7c478bd9Sstevel@tonic-gate if ((ldctrl = ldaptool_create_proxyauth_control(ld)) !=NULL) { 674*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 675*7c478bd9Sstevel@tonic-gate } 676*7c478bd9Sstevel@tonic-gate 677*7c478bd9Sstevel@tonic-gate #ifndef SOLARIS_LDAP_CMD 678*7c478bd9Sstevel@tonic-gate if ( do_effective_rights_control ) { 679*7c478bd9Sstevel@tonic-gate if ((ldctrl = ldaptool_create_geteffectiveRights_control(ld, 680*7c478bd9Sstevel@tonic-gate get_effectiverights_control_target_dn, 681*7c478bd9Sstevel@tonic-gate (const char**) get_effectiverights_control_attrlist)) !=NULL) { 682*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 683*7c478bd9Sstevel@tonic-gate } 684*7c478bd9Sstevel@tonic-gate } 685*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 686*7c478bd9Sstevel@tonic-gate 687*7c478bd9Sstevel@tonic-gate if (use_psearch) { 688*7c478bd9Sstevel@tonic-gate if ( ldap_create_persistentsearch_control( ld, chgtype, 689*7c478bd9Sstevel@tonic-gate changesonly, return_echg_ctls, 690*7c478bd9Sstevel@tonic-gate 1, &ldctrl ) != LDAP_SUCCESS ) 691*7c478bd9Sstevel@tonic-gate { 692*7c478bd9Sstevel@tonic-gate ldap_perror( ld, "ldap_create_persistentsearch_control" ); 693*7c478bd9Sstevel@tonic-gate return (1); 694*7c478bd9Sstevel@tonic-gate } 695*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 696*7c478bd9Sstevel@tonic-gate } 697*7c478bd9Sstevel@tonic-gate 698*7c478bd9Sstevel@tonic-gate 699*7c478bd9Sstevel@tonic-gate if (server_sort) { 700*7c478bd9Sstevel@tonic-gate /* First make a sort key list from the attribute list we have */ 701*7c478bd9Sstevel@tonic-gate LDAPsortkey **keylist = NULL; 702*7c478bd9Sstevel@tonic-gate int i = 0; 703*7c478bd9Sstevel@tonic-gate char *sortattrs = NULL; 704*7c478bd9Sstevel@tonic-gate char *s = NULL; 705*7c478bd9Sstevel@tonic-gate int string_length = 0; 706*7c478bd9Sstevel@tonic-gate 707*7c478bd9Sstevel@tonic-gate /* Count the sort strings */ 708*7c478bd9Sstevel@tonic-gate for (i = 0; i < sortsize - 1 ; i++) { 709*7c478bd9Sstevel@tonic-gate string_length += strlen(sortattr[i]) + 1; 710*7c478bd9Sstevel@tonic-gate } 711*7c478bd9Sstevel@tonic-gate 712*7c478bd9Sstevel@tonic-gate sortattrs = (char *) malloc(string_length + 1); 713*7c478bd9Sstevel@tonic-gate if (NULL == sortattrs) { 714*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("Out of memory\n") ); 715*7c478bd9Sstevel@tonic-gate exit( LDAP_NO_MEMORY ); 716*7c478bd9Sstevel@tonic-gate } 717*7c478bd9Sstevel@tonic-gate 718*7c478bd9Sstevel@tonic-gate s = sortattrs; 719*7c478bd9Sstevel@tonic-gate for (i = 0; i < sortsize - 1 ; i++) { 720*7c478bd9Sstevel@tonic-gate memcpy(s, sortattr[i], strlen(sortattr[i])); 721*7c478bd9Sstevel@tonic-gate s += strlen(sortattr[i]); 722*7c478bd9Sstevel@tonic-gate *s++ = ' '; 723*7c478bd9Sstevel@tonic-gate } 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate sortattrs[string_length] = '\0'; 726*7c478bd9Sstevel@tonic-gate 727*7c478bd9Sstevel@tonic-gate ldap_create_sort_keylist(&keylist,sortattrs); 728*7c478bd9Sstevel@tonic-gate free(sortattrs); 729*7c478bd9Sstevel@tonic-gate sortattrs = NULL; 730*7c478bd9Sstevel@tonic-gate 731*7c478bd9Sstevel@tonic-gate /* Then make a control for the sort attributes we have */ 732*7c478bd9Sstevel@tonic-gate rc = ldap_create_sort_control(ld,keylist,0,&ldctrl); 733*7c478bd9Sstevel@tonic-gate ldap_free_sort_keylist(keylist); 734*7c478bd9Sstevel@tonic-gate if ( rc != LDAP_SUCCESS ) { 735*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 736*7c478bd9Sstevel@tonic-gate return( ldaptool_print_lderror( ld, "ldap_create_sort_control", 737*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP )); 738*7c478bd9Sstevel@tonic-gate } 739*7c478bd9Sstevel@tonic-gate 740*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 741*7c478bd9Sstevel@tonic-gate 742*7c478bd9Sstevel@tonic-gate } 743*7c478bd9Sstevel@tonic-gate /* remember server side sorting must be available for vlv!!!! */ 744*7c478bd9Sstevel@tonic-gate 745*7c478bd9Sstevel@tonic-gate if (use_vlv) 746*7c478bd9Sstevel@tonic-gate { 747*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_before_count = vlv_before; 748*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_after_count = vlv_after; 749*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 750*7c478bd9Sstevel@tonic-gate printf( gettext("vlv data %lu, %lu, "), 751*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_before_count, 752*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_after_count 753*7c478bd9Sstevel@tonic-gate ); 754*7c478bd9Sstevel@tonic-gate } 755*7c478bd9Sstevel@tonic-gate if (vlv_value) 756*7c478bd9Sstevel@tonic-gate { 757*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_attrvalue = vlv_value; 758*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_size = 0; 759*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_index = 0; 760*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 761*7c478bd9Sstevel@tonic-gate printf( "%s, 0, 0\n", vlv_data.ldvlist_attrvalue); 762*7c478bd9Sstevel@tonic-gate } 763*7c478bd9Sstevel@tonic-gate } 764*7c478bd9Sstevel@tonic-gate else 765*7c478bd9Sstevel@tonic-gate { 766*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_attrvalue = NULL; 767*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_size = vlv_count; 768*7c478bd9Sstevel@tonic-gate vlv_data.ldvlist_index = vlv_index; 769*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 770*7c478bd9Sstevel@tonic-gate printf( "(null), %lu, %lu\n", vlv_data.ldvlist_size, vlv_data.ldvlist_index ); 771*7c478bd9Sstevel@tonic-gate } 772*7c478bd9Sstevel@tonic-gate } 773*7c478bd9Sstevel@tonic-gate 774*7c478bd9Sstevel@tonic-gate if ( rc != LDAP_SUCCESS ) { 775*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 776*7c478bd9Sstevel@tonic-gate return( ldaptool_print_lderror( ld, "ldap_create_sort_control", 777*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP )); 778*7c478bd9Sstevel@tonic-gate } 779*7c478bd9Sstevel@tonic-gate if (LDAP_SUCCESS != (rc = ldap_create_virtuallist_control(ld, 780*7c478bd9Sstevel@tonic-gate &vlv_data, &ldctrl))) 781*7c478bd9Sstevel@tonic-gate { 782*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 783*7c478bd9Sstevel@tonic-gate return( ldaptool_print_lderror( ld, 784*7c478bd9Sstevel@tonic-gate "ldap_create_virtuallist_control", 785*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP )); 786*7c478bd9Sstevel@tonic-gate } 787*7c478bd9Sstevel@tonic-gate 788*7c478bd9Sstevel@tonic-gate ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); 789*7c478bd9Sstevel@tonic-gate 790*7c478bd9Sstevel@tonic-gate } 791*7c478bd9Sstevel@tonic-gate 792*7c478bd9Sstevel@tonic-gate if ( ldap_search_ext( ld, base, scope, filterp, attrs, attrsonly, 793*7c478bd9Sstevel@tonic-gate ldaptool_request_ctrls, NULL, NULL, -1, &msgid ) 794*7c478bd9Sstevel@tonic-gate != LDAP_SUCCESS ) { 795*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 796*7c478bd9Sstevel@tonic-gate return( ldaptool_print_lderror( ld, "ldap_search", 797*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP )); 798*7c478bd9Sstevel@tonic-gate } 799*7c478bd9Sstevel@tonic-gate 800*7c478bd9Sstevel@tonic-gate 801*7c478bd9Sstevel@tonic-gate matches = 0; 802*7c478bd9Sstevel@tonic-gate first = 1; 803*7c478bd9Sstevel@tonic-gate if ( sortattr && !server_sort ) { 804*7c478bd9Sstevel@tonic-gate rc = ldap_result( ld, LDAP_RES_ANY, 1, NULL, &res ); 805*7c478bd9Sstevel@tonic-gate } else { 806*7c478bd9Sstevel@tonic-gate while ( (rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res )) != 807*7c478bd9Sstevel@tonic-gate LDAP_RES_SEARCH_RESULT && rc != -1 ) { 808*7c478bd9Sstevel@tonic-gate if ( rc != LDAP_RES_SEARCH_ENTRY ) { 809*7c478bd9Sstevel@tonic-gate if ( rc == LDAP_RES_SEARCH_REFERENCE ) { 810*7c478bd9Sstevel@tonic-gate parse_and_display_reference( ld, res ); 811*7c478bd9Sstevel@tonic-gate } else if ( rc == LDAP_RES_EXTENDED 812*7c478bd9Sstevel@tonic-gate && ldap_msgid( res ) == LDAP_RES_UNSOLICITED ) { 813*7c478bd9Sstevel@tonic-gate ldaptool_print_extended_response( ld, res, 814*7c478bd9Sstevel@tonic-gate gettext("Unsolicited response") ); 815*7c478bd9Sstevel@tonic-gate } else { 816*7c478bd9Sstevel@tonic-gate fprintf( stderr, gettext("%s: ignoring LDAP response message" 817*7c478bd9Sstevel@tonic-gate " type 0x%x (%s)\n"), 818*7c478bd9Sstevel@tonic-gate ldaptool_progname, rc, msgtype2str( rc )); 819*7c478bd9Sstevel@tonic-gate } 820*7c478bd9Sstevel@tonic-gate ldap_msgfree( res ); 821*7c478bd9Sstevel@tonic-gate continue; 822*7c478bd9Sstevel@tonic-gate } 823*7c478bd9Sstevel@tonic-gate matches++; 824*7c478bd9Sstevel@tonic-gate e = ldap_first_entry( ld, res ); 825*7c478bd9Sstevel@tonic-gate if ( !first ) { 826*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 827*7c478bd9Sstevel@tonic-gate } else { 828*7c478bd9Sstevel@tonic-gate first = 0; 829*7c478bd9Sstevel@tonic-gate } 830*7c478bd9Sstevel@tonic-gate print_entry( ld, e, attrsonly ); 831*7c478bd9Sstevel@tonic-gate ldap_msgfree( res ); 832*7c478bd9Sstevel@tonic-gate } 833*7c478bd9Sstevel@tonic-gate } 834*7c478bd9Sstevel@tonic-gate if ( rc == -1 ) { 835*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 836*7c478bd9Sstevel@tonic-gate return( ldaptool_print_lderror( ld, "ldap_result", 837*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP )); 838*7c478bd9Sstevel@tonic-gate } 839*7c478bd9Sstevel@tonic-gate 840*7c478bd9Sstevel@tonic-gate if ( ldap_parse_result( ld, res, &rc, NULL, NULL, &refs, 841*7c478bd9Sstevel@tonic-gate &ctrl_response_array, 0 ) != LDAP_SUCCESS ) { 842*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror( ld, "ldap_parse_result", 843*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 844*7c478bd9Sstevel@tonic-gate } else if ( rc != LDAP_SUCCESS ) { 845*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror( ld, "ldap_search", 846*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 847*7c478bd9Sstevel@tonic-gate } 848*7c478bd9Sstevel@tonic-gate /* Parse the returned sort control */ 849*7c478bd9Sstevel@tonic-gate if (server_sort) { 850*7c478bd9Sstevel@tonic-gate unsigned long result = 0; 851*7c478bd9Sstevel@tonic-gate char *attribute; 852*7c478bd9Sstevel@tonic-gate 853*7c478bd9Sstevel@tonic-gate if ( LDAP_SUCCESS != ldap_parse_sort_control(ld,ctrl_response_array,&result,&attribute) ) { 854*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror(ld, "ldap_parse_sort_control", 855*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 856*7c478bd9Sstevel@tonic-gate ldap_controls_free(ctrl_response_array); 857*7c478bd9Sstevel@tonic-gate ldap_msgfree(res); 858*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 859*7c478bd9Sstevel@tonic-gate return ( ldap_get_lderrno( ld, NULL, NULL ) ); 860*7c478bd9Sstevel@tonic-gate } 861*7c478bd9Sstevel@tonic-gate 862*7c478bd9Sstevel@tonic-gate if (0 == result) { 863*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 864*7c478bd9Sstevel@tonic-gate printf( gettext("Server indicated results sorted OK\n")); 865*7c478bd9Sstevel@tonic-gate } 866*7c478bd9Sstevel@tonic-gate } else { 867*7c478bd9Sstevel@tonic-gate if (NULL != attribute) { 868*7c478bd9Sstevel@tonic-gate printf(gettext("Server reported sorting error %ld: %s, attribute in error\"%s\"\n"),result,sortresult2string(result),attribute); 869*7c478bd9Sstevel@tonic-gate } else { 870*7c478bd9Sstevel@tonic-gate printf(gettext("Server reported sorting error %ld: %s\n"),result,sortresult2string(result)); 871*7c478bd9Sstevel@tonic-gate } 872*7c478bd9Sstevel@tonic-gate } 873*7c478bd9Sstevel@tonic-gate 874*7c478bd9Sstevel@tonic-gate } 875*7c478bd9Sstevel@tonic-gate 876*7c478bd9Sstevel@tonic-gate if (use_vlv) 877*7c478bd9Sstevel@tonic-gate { 878*7c478bd9Sstevel@tonic-gate unsigned long vpos, vcount; 879*7c478bd9Sstevel@tonic-gate int vresult; 880*7c478bd9Sstevel@tonic-gate if ( LDAP_SUCCESS != ldap_parse_virtuallist_control(ld,ctrl_response_array,&vpos, &vcount,&vresult) ) { 881*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror( ld, "ldap_parse_virtuallist_control", 882*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 883*7c478bd9Sstevel@tonic-gate ldap_controls_free(ctrl_response_array); 884*7c478bd9Sstevel@tonic-gate ldap_msgfree(res); 885*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 886*7c478bd9Sstevel@tonic-gate return ( ldap_get_lderrno( ld, NULL, NULL ) ); 887*7c478bd9Sstevel@tonic-gate } 888*7c478bd9Sstevel@tonic-gate 889*7c478bd9Sstevel@tonic-gate if (0 == vresult) { 890*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 891*7c478bd9Sstevel@tonic-gate printf( gettext("Server indicated virtual list positioning OK\n")); 892*7c478bd9Sstevel@tonic-gate } 893*7c478bd9Sstevel@tonic-gate printf(gettext("index %lu content count %lu\n"), vpos, vcount); 894*7c478bd9Sstevel@tonic-gate 895*7c478bd9Sstevel@tonic-gate } else { 896*7c478bd9Sstevel@tonic-gate printf(gettext("Server reported sorting error %d: %s\n"),vresult,sortresult2string(vresult)); 897*7c478bd9Sstevel@tonic-gate 898*7c478bd9Sstevel@tonic-gate } 899*7c478bd9Sstevel@tonic-gate 900*7c478bd9Sstevel@tonic-gate } 901*7c478bd9Sstevel@tonic-gate 902*7c478bd9Sstevel@tonic-gate ldap_controls_free(ctrl_response_array); 903*7c478bd9Sstevel@tonic-gate 904*7c478bd9Sstevel@tonic-gate if ( sortattr != NULL && !server_sort) { 905*7c478bd9Sstevel@tonic-gate 906*7c478bd9Sstevel@tonic-gate (void) ldap_multisort_entries( ld, &res, 907*7c478bd9Sstevel@tonic-gate ( *sortattr == NULL ) ? NULL : sortattr, 908*7c478bd9Sstevel@tonic-gate (LDAP_CMP_CALLBACK *)strcasecmp ); 909*7c478bd9Sstevel@tonic-gate matches = 0; 910*7c478bd9Sstevel@tonic-gate first = 1; 911*7c478bd9Sstevel@tonic-gate for ( e = ldap_first_entry( ld, res ); e != NULLMSG; 912*7c478bd9Sstevel@tonic-gate e = ldap_next_entry( ld, e ) ) { 913*7c478bd9Sstevel@tonic-gate matches++; 914*7c478bd9Sstevel@tonic-gate if ( !first ) { 915*7c478bd9Sstevel@tonic-gate putchar( '\n' ); 916*7c478bd9Sstevel@tonic-gate } else { 917*7c478bd9Sstevel@tonic-gate first = 0; 918*7c478bd9Sstevel@tonic-gate } 919*7c478bd9Sstevel@tonic-gate print_entry( ld, e, attrsonly ); 920*7c478bd9Sstevel@tonic-gate } 921*7c478bd9Sstevel@tonic-gate } 922*7c478bd9Sstevel@tonic-gate 923*7c478bd9Sstevel@tonic-gate if ( ldaptool_verbose ) { 924*7c478bd9Sstevel@tonic-gate printf( gettext("%d matches\n"), matches ); 925*7c478bd9Sstevel@tonic-gate } 926*7c478bd9Sstevel@tonic-gate 927*7c478bd9Sstevel@tonic-gate if ( refs != NULL ) { 928*7c478bd9Sstevel@tonic-gate ldaptool_print_referrals( refs ); 929*7c478bd9Sstevel@tonic-gate ldap_value_free( refs ); 930*7c478bd9Sstevel@tonic-gate } 931*7c478bd9Sstevel@tonic-gate 932*7c478bd9Sstevel@tonic-gate if (mallocd_filter) free(filterp); 933*7c478bd9Sstevel@tonic-gate 934*7c478bd9Sstevel@tonic-gate ldap_msgfree( res ); 935*7c478bd9Sstevel@tonic-gate return( rc ); 936*7c478bd9Sstevel@tonic-gate } 937*7c478bd9Sstevel@tonic-gate 938*7c478bd9Sstevel@tonic-gate 939*7c478bd9Sstevel@tonic-gate static void 940*7c478bd9Sstevel@tonic-gate print_entry( ld, entry, attrsonly ) 941*7c478bd9Sstevel@tonic-gate LDAP *ld; 942*7c478bd9Sstevel@tonic-gate LDAPMessage *entry; 943*7c478bd9Sstevel@tonic-gate int attrsonly; 944*7c478bd9Sstevel@tonic-gate { 945*7c478bd9Sstevel@tonic-gate char *a, *dn, *ufn, tmpfname[ BUFSIZ ]; 946*7c478bd9Sstevel@tonic-gate int i, notascii; 947*7c478bd9Sstevel@tonic-gate BerElement *ber; 948*7c478bd9Sstevel@tonic-gate struct berval **bvals; 949*7c478bd9Sstevel@tonic-gate FILE *tmpfp; 950*7c478bd9Sstevel@tonic-gate #if defined( XP_WIN32 ) 951*7c478bd9Sstevel@tonic-gate char mode[20] = "w+b"; 952*7c478bd9Sstevel@tonic-gate #else 953*7c478bd9Sstevel@tonic-gate char mode[20] = "w"; 954*7c478bd9Sstevel@tonic-gate #endif 955*7c478bd9Sstevel@tonic-gate 956*7c478bd9Sstevel@tonic-gate dn = ldap_get_dn( ld, entry ); 957*7c478bd9Sstevel@tonic-gate write_string_attr_value( "dn", dn, LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME ); 958*7c478bd9Sstevel@tonic-gate if ( includeufn ) { 959*7c478bd9Sstevel@tonic-gate ufn = ldap_dn2ufn( dn ); 960*7c478bd9Sstevel@tonic-gate write_string_attr_value( "ufn", ufn, 961*7c478bd9Sstevel@tonic-gate LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME ); 962*7c478bd9Sstevel@tonic-gate free( ufn ); 963*7c478bd9Sstevel@tonic-gate } 964*7c478bd9Sstevel@tonic-gate ldap_memfree( dn ); 965*7c478bd9Sstevel@tonic-gate 966*7c478bd9Sstevel@tonic-gate if ( use_psearch ) { 967*7c478bd9Sstevel@tonic-gate LDAPControl **ectrls; 968*7c478bd9Sstevel@tonic-gate int chgtype, chgnumpresent; 969*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 970*7c478bd9Sstevel@tonic-gate ber_int_t chgnum; 971*7c478bd9Sstevel@tonic-gate #else 972*7c478bd9Sstevel@tonic-gate long chgnum; 973*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 974*7c478bd9Sstevel@tonic-gate char *prevdn, longbuf[ 128 ]; 975*7c478bd9Sstevel@tonic-gate 976*7c478bd9Sstevel@tonic-gate if ( ldap_get_entry_controls( ld, entry, &ectrls ) == LDAP_SUCCESS ) { 977*7c478bd9Sstevel@tonic-gate if ( ldap_parse_entrychange_control( ld, ectrls, &chgtype, 978*7c478bd9Sstevel@tonic-gate &prevdn, &chgnumpresent, &chgnum ) == LDAP_SUCCESS ) { 979*7c478bd9Sstevel@tonic-gate write_string_attr_value( 980*7c478bd9Sstevel@tonic-gate LDAPTOOL_PSEARCH_ATTR_PREFIX "changeType", 981*7c478bd9Sstevel@tonic-gate changetype_num2string( chgtype ), 0 ); 982*7c478bd9Sstevel@tonic-gate if ( chgnumpresent ) { 983*7c478bd9Sstevel@tonic-gate sprintf( longbuf, "%d", chgnum ); 984*7c478bd9Sstevel@tonic-gate write_string_attr_value( 985*7c478bd9Sstevel@tonic-gate LDAPTOOL_PSEARCH_ATTR_PREFIX "changeNumber", 986*7c478bd9Sstevel@tonic-gate longbuf, 0 ); 987*7c478bd9Sstevel@tonic-gate } 988*7c478bd9Sstevel@tonic-gate if ( NULL != prevdn ) { 989*7c478bd9Sstevel@tonic-gate write_string_attr_value( 990*7c478bd9Sstevel@tonic-gate LDAPTOOL_PSEARCH_ATTR_PREFIX "previousDN", 991*7c478bd9Sstevel@tonic-gate prevdn, 0 ); 992*7c478bd9Sstevel@tonic-gate ldap_memfree( prevdn ); 993*7c478bd9Sstevel@tonic-gate } 994*7c478bd9Sstevel@tonic-gate } 995*7c478bd9Sstevel@tonic-gate ldap_controls_free (ectrls); 996*7c478bd9Sstevel@tonic-gate } 997*7c478bd9Sstevel@tonic-gate } 998*7c478bd9Sstevel@tonic-gate 999*7c478bd9Sstevel@tonic-gate for ( a = ldap_first_attribute( ld, entry, &ber ); a != NULL; 1000*7c478bd9Sstevel@tonic-gate a = ldap_next_attribute( ld, entry, ber ) ) { 1001*7c478bd9Sstevel@tonic-gate if ( ldap_charray_inlist(sortattr, a) && /* in the list*/ 1002*7c478bd9Sstevel@tonic-gate skipsortattr[ldap_charray_position(sortattr, a)] ) {/* and skip it*/ 1003*7c478bd9Sstevel@tonic-gate continue; /* so skip it! */ 1004*7c478bd9Sstevel@tonic-gate } 1005*7c478bd9Sstevel@tonic-gate if ( attrsonly ) { 1006*7c478bd9Sstevel@tonic-gate if ( ldif ) { 1007*7c478bd9Sstevel@tonic-gate write_ldif_value( a, "", 0, 0 ); 1008*7c478bd9Sstevel@tonic-gate } else { 1009*7c478bd9Sstevel@tonic-gate printf( "%s\n", a ); 1010*7c478bd9Sstevel@tonic-gate } 1011*7c478bd9Sstevel@tonic-gate } else if (( bvals = ldap_get_values_len( ld, entry, a )) != NULL ) { 1012*7c478bd9Sstevel@tonic-gate for ( i = 0; bvals[i] != NULL; i++ ) { 1013*7c478bd9Sstevel@tonic-gate if ( vals2tmp ) { 1014*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SNPRINTF 1015*7c478bd9Sstevel@tonic-gate if ( snprintf( tmpfname, sizeof(tmpfname), 1016*7c478bd9Sstevel@tonic-gate "%s/ldapsearch-%s-XXXXXX", 1017*7c478bd9Sstevel@tonic-gate ldaptool_get_tmp_dir(), a ) < 0 ) { 1018*7c478bd9Sstevel@tonic-gate perror( gettext("snprintf tmpfname (attribute name too long?)") ); 1019*7c478bd9Sstevel@tonic-gate exit( LDAP_PARAM_ERROR ); 1020*7c478bd9Sstevel@tonic-gate } 1021*7c478bd9Sstevel@tonic-gate #else 1022*7c478bd9Sstevel@tonic-gate sprintf( tmpfname, "%s/ldapsearch-%s-XXXXXX", 1023*7c478bd9Sstevel@tonic-gate ldaptool_get_tmp_dir(), a ); 1024*7c478bd9Sstevel@tonic-gate #endif 1025*7c478bd9Sstevel@tonic-gate tmpfp = NULL; 1026*7c478bd9Sstevel@tonic-gate 1027*7c478bd9Sstevel@tonic-gate if ( LDAPTOOL_MKTEMP( tmpfname ) == NULL ) { 1028*7c478bd9Sstevel@tonic-gate perror( tmpfname ); 1029*7c478bd9Sstevel@tonic-gate } else if (( tmpfp = ldaptool_open_file( tmpfname, mode)) == NULL ) { 1030*7c478bd9Sstevel@tonic-gate perror( tmpfname ); 1031*7c478bd9Sstevel@tonic-gate } else if ( bvals[ i ]->bv_len > 0 && 1032*7c478bd9Sstevel@tonic-gate fwrite( bvals[ i ]->bv_val, 1033*7c478bd9Sstevel@tonic-gate bvals[ i ]->bv_len, 1, tmpfp ) == 0 ) { 1034*7c478bd9Sstevel@tonic-gate perror( tmpfname ); 1035*7c478bd9Sstevel@tonic-gate } else if ( ldif ) { 1036*7c478bd9Sstevel@tonic-gate if ( produce_file_urls ) { 1037*7c478bd9Sstevel@tonic-gate char *url; 1038*7c478bd9Sstevel@tonic-gate 1039*7c478bd9Sstevel@tonic-gate if ( ldaptool_path2fileurl( tmpfname, &url ) != 1040*7c478bd9Sstevel@tonic-gate LDAPTOOL_FILEURL_SUCCESS ) { 1041*7c478bd9Sstevel@tonic-gate perror( "ldaptool_path2fileurl" ); 1042*7c478bd9Sstevel@tonic-gate } else { 1043*7c478bd9Sstevel@tonic-gate write_ldif_value( a, url, strlen( url ), 1044*7c478bd9Sstevel@tonic-gate LDIF_OPT_VALUE_IS_URL ); 1045*7c478bd9Sstevel@tonic-gate free( url ); 1046*7c478bd9Sstevel@tonic-gate } 1047*7c478bd9Sstevel@tonic-gate } else { 1048*7c478bd9Sstevel@tonic-gate write_ldif_value( a, tmpfname, strlen( tmpfname ), 1049*7c478bd9Sstevel@tonic-gate 0 ); 1050*7c478bd9Sstevel@tonic-gate } 1051*7c478bd9Sstevel@tonic-gate } else { 1052*7c478bd9Sstevel@tonic-gate printf( "%s%s%s\n", a, sep, tmpfname ); 1053*7c478bd9Sstevel@tonic-gate } 1054*7c478bd9Sstevel@tonic-gate 1055*7c478bd9Sstevel@tonic-gate if ( tmpfp != NULL ) { 1056*7c478bd9Sstevel@tonic-gate fclose( tmpfp ); 1057*7c478bd9Sstevel@tonic-gate } 1058*7c478bd9Sstevel@tonic-gate } else { 1059*7c478bd9Sstevel@tonic-gate notascii = 0; 1060*7c478bd9Sstevel@tonic-gate if ( !ldif && !allow_binary ) { 1061*7c478bd9Sstevel@tonic-gate notascii = !ldaptool_berval_is_ascii( bvals[i] ); 1062*7c478bd9Sstevel@tonic-gate } 1063*7c478bd9Sstevel@tonic-gate 1064*7c478bd9Sstevel@tonic-gate if ( ldif ) { 1065*7c478bd9Sstevel@tonic-gate write_ldif_value( a, bvals[ i ]->bv_val, 1066*7c478bd9Sstevel@tonic-gate bvals[ i ]->bv_len, 0 ); 1067*7c478bd9Sstevel@tonic-gate } else { 1068*7c478bd9Sstevel@tonic-gate printf( "%s%s%s\n", a, sep, 1069*7c478bd9Sstevel@tonic-gate notascii ? gettext("NOT ASCII") : bvals[ i ]->bv_val ); 1070*7c478bd9Sstevel@tonic-gate } 1071*7c478bd9Sstevel@tonic-gate } 1072*7c478bd9Sstevel@tonic-gate } 1073*7c478bd9Sstevel@tonic-gate ber_bvecfree( bvals ); 1074*7c478bd9Sstevel@tonic-gate } 1075*7c478bd9Sstevel@tonic-gate ldap_memfree( a ); 1076*7c478bd9Sstevel@tonic-gate } 1077*7c478bd9Sstevel@tonic-gate 1078*7c478bd9Sstevel@tonic-gate if ( ldap_get_lderrno( ld, NULL, NULL ) != LDAP_SUCCESS ) { 1079*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror( ld, "ldap_first_attribute/ldap_next_attribute", 1080*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 1081*7c478bd9Sstevel@tonic-gate } 1082*7c478bd9Sstevel@tonic-gate 1083*7c478bd9Sstevel@tonic-gate if ( ber != NULL ) { 1084*7c478bd9Sstevel@tonic-gate ber_free( ber, 0 ); 1085*7c478bd9Sstevel@tonic-gate } 1086*7c478bd9Sstevel@tonic-gate } 1087*7c478bd9Sstevel@tonic-gate 1088*7c478bd9Sstevel@tonic-gate 1089*7c478bd9Sstevel@tonic-gate static void 1090*7c478bd9Sstevel@tonic-gate write_string_attr_value( char *attrname, char *strval, unsigned long opts ) 1091*7c478bd9Sstevel@tonic-gate { 1092*7c478bd9Sstevel@tonic-gate if ( strval == NULL ) { 1093*7c478bd9Sstevel@tonic-gate strval = ""; 1094*7c478bd9Sstevel@tonic-gate } 1095*7c478bd9Sstevel@tonic-gate if ( ldif ) { 1096*7c478bd9Sstevel@tonic-gate write_ldif_value( attrname, strval, strlen( strval ), 0 ); 1097*7c478bd9Sstevel@tonic-gate } else if ( 0 != ( opts & LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME )) { 1098*7c478bd9Sstevel@tonic-gate printf( "%s\n", strval ); 1099*7c478bd9Sstevel@tonic-gate } else { 1100*7c478bd9Sstevel@tonic-gate printf( "%s%s%s\n", attrname, sep, strval ); 1101*7c478bd9Sstevel@tonic-gate } 1102*7c478bd9Sstevel@tonic-gate } 1103*7c478bd9Sstevel@tonic-gate 1104*7c478bd9Sstevel@tonic-gate 1105*7c478bd9Sstevel@tonic-gate static int 1106*7c478bd9Sstevel@tonic-gate write_ldif_value( char *type, char *value, unsigned long vallen, 1107*7c478bd9Sstevel@tonic-gate unsigned long ldifoptions ) 1108*7c478bd9Sstevel@tonic-gate { 1109*7c478bd9Sstevel@tonic-gate char *ldif; 1110*7c478bd9Sstevel@tonic-gate static int wrote_version = 0; 1111*7c478bd9Sstevel@tonic-gate 1112*7c478bd9Sstevel@tonic-gate if ( write_ldif_version && !wrote_version ) { 1113*7c478bd9Sstevel@tonic-gate char versionbuf[ 64 ]; 1114*7c478bd9Sstevel@tonic-gate 1115*7c478bd9Sstevel@tonic-gate wrote_version = 1; 1116*7c478bd9Sstevel@tonic-gate sprintf( versionbuf, "%d", LDIF_VERSION_ONE ); 1117*7c478bd9Sstevel@tonic-gate write_ldif_value( "version", versionbuf, strlen( versionbuf ), 0 ); 1118*7c478bd9Sstevel@tonic-gate } 1119*7c478bd9Sstevel@tonic-gate 1120*7c478bd9Sstevel@tonic-gate if ( !fold ) { 1121*7c478bd9Sstevel@tonic-gate ldifoptions |= LDIF_OPT_NOWRAP; 1122*7c478bd9Sstevel@tonic-gate } 1123*7c478bd9Sstevel@tonic-gate if ( minimize_base64 ) { 1124*7c478bd9Sstevel@tonic-gate ldifoptions |= LDIF_OPT_MINIMAL_ENCODING; 1125*7c478bd9Sstevel@tonic-gate } 1126*7c478bd9Sstevel@tonic-gate 1127*7c478bd9Sstevel@tonic-gate if (( ldif = ldif_type_and_value_with_options( type, value, (int)vallen, 1128*7c478bd9Sstevel@tonic-gate ldifoptions )) == NULL ) { 1129*7c478bd9Sstevel@tonic-gate return( -1 ); 1130*7c478bd9Sstevel@tonic-gate } 1131*7c478bd9Sstevel@tonic-gate 1132*7c478bd9Sstevel@tonic-gate fputs( ldif, stdout ); 1133*7c478bd9Sstevel@tonic-gate free( ldif ); 1134*7c478bd9Sstevel@tonic-gate 1135*7c478bd9Sstevel@tonic-gate return( 0 ); 1136*7c478bd9Sstevel@tonic-gate } 1137*7c478bd9Sstevel@tonic-gate 1138*7c478bd9Sstevel@tonic-gate 1139*7c478bd9Sstevel@tonic-gate static char * 1140*7c478bd9Sstevel@tonic-gate sortresult2string(unsigned long result) 1141*7c478bd9Sstevel@tonic-gate { 1142*7c478bd9Sstevel@tonic-gate /* 1143*7c478bd9Sstevel@tonic-gate success (0), -- results are sorted 1144*7c478bd9Sstevel@tonic-gate operationsError (1), -- server internal failure 1145*7c478bd9Sstevel@tonic-gate timeLimitExceeded (3), -- timelimit reached before 1146*7c478bd9Sstevel@tonic-gate -- sorting was completed 1147*7c478bd9Sstevel@tonic-gate strongAuthRequired (8), -- refused to return sorted 1148*7c478bd9Sstevel@tonic-gate -- results via insecure 1149*7c478bd9Sstevel@tonic-gate -- protocol 1150*7c478bd9Sstevel@tonic-gate adminLimitExceeded (11), -- too many matching entries 1151*7c478bd9Sstevel@tonic-gate -- for the server to sort 1152*7c478bd9Sstevel@tonic-gate noSuchAttribute (16), -- unrecognized attribute 1153*7c478bd9Sstevel@tonic-gate -- type in sort key 1154*7c478bd9Sstevel@tonic-gate inappropriateMatching (18), -- unrecognized or inappro- 1155*7c478bd9Sstevel@tonic-gate -- priate matching rule in 1156*7c478bd9Sstevel@tonic-gate -- sort key 1157*7c478bd9Sstevel@tonic-gate insufficientAccessRights (50), -- refused to return sorted 1158*7c478bd9Sstevel@tonic-gate -- results to this client 1159*7c478bd9Sstevel@tonic-gate busy (51), -- too busy to process 1160*7c478bd9Sstevel@tonic-gate unwillingToPerform (53), -- unable to sort 1161*7c478bd9Sstevel@tonic-gate other (80) 1162*7c478bd9Sstevel@tonic-gate */ 1163*7c478bd9Sstevel@tonic-gate 1164*7c478bd9Sstevel@tonic-gate switch (result) { 1165*7c478bd9Sstevel@tonic-gate case 0: return (gettext("success")); 1166*7c478bd9Sstevel@tonic-gate case 1: return (gettext("operations error")); 1167*7c478bd9Sstevel@tonic-gate case 3: return (gettext("time limit exceeded")); 1168*7c478bd9Sstevel@tonic-gate case 8: return (gettext("strong auth required")); 1169*7c478bd9Sstevel@tonic-gate case 11: return (gettext("admin limit exceeded")); 1170*7c478bd9Sstevel@tonic-gate case 16: return (gettext("no such attribute")); 1171*7c478bd9Sstevel@tonic-gate case 18: return (gettext("unrecognized or inappropriate matching rule")); 1172*7c478bd9Sstevel@tonic-gate case 50: return (gettext("insufficient access rights")); 1173*7c478bd9Sstevel@tonic-gate case 51: return (gettext("too busy")); 1174*7c478bd9Sstevel@tonic-gate case 53: return (gettext("unable to sort")); 1175*7c478bd9Sstevel@tonic-gate case 80: 1176*7c478bd9Sstevel@tonic-gate default: return (gettext("Er...Other ?")); 1177*7c478bd9Sstevel@tonic-gate } 1178*7c478bd9Sstevel@tonic-gate } 1179*7c478bd9Sstevel@tonic-gate 1180*7c478bd9Sstevel@tonic-gate 1181*7c478bd9Sstevel@tonic-gate static void 1182*7c478bd9Sstevel@tonic-gate parse_and_display_reference( LDAP *ld, LDAPMessage *ref ) 1183*7c478bd9Sstevel@tonic-gate { 1184*7c478bd9Sstevel@tonic-gate int i; 1185*7c478bd9Sstevel@tonic-gate char **refs; 1186*7c478bd9Sstevel@tonic-gate 1187*7c478bd9Sstevel@tonic-gate if ( ldap_parse_reference( ld, ref, &refs, NULL, 0 ) != LDAP_SUCCESS ) { 1188*7c478bd9Sstevel@tonic-gate ldaptool_print_lderror( ld, "ldap_parse_reference", 1189*7c478bd9Sstevel@tonic-gate LDAPTOOL_CHECK4SSL_IF_APPROP ); 1190*7c478bd9Sstevel@tonic-gate } else if ( refs != NULL && refs[ 0 ] != NULL ) { 1191*7c478bd9Sstevel@tonic-gate fputs( gettext("Unfollowed continuation reference(s):\n"), stderr ); 1192*7c478bd9Sstevel@tonic-gate for ( i = 0; refs[ i ] != NULL; ++i ) { 1193*7c478bd9Sstevel@tonic-gate fprintf( stderr, " %s\n", refs[ i ] ); 1194*7c478bd9Sstevel@tonic-gate } 1195*7c478bd9Sstevel@tonic-gate ldap_value_free( refs ); 1196*7c478bd9Sstevel@tonic-gate } 1197*7c478bd9Sstevel@tonic-gate } 1198*7c478bd9Sstevel@tonic-gate 1199*7c478bd9Sstevel@tonic-gate 1200*7c478bd9Sstevel@tonic-gate /*possible operations a client can invoke -- copied from ldaprot.h */ 1201*7c478bd9Sstevel@tonic-gate 1202*7c478bd9Sstevel@tonic-gate #ifndef LDAP_REQ_BIND 1203*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_BIND 0x60L /* application + constructed */ 1204*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_UNBIND 0x42L /* application + primitive */ 1205*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_SEARCH 0x63L /* application + constructed */ 1206*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_MODIFY 0x66L /* application + constructed */ 1207*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_ADD 0x68L /* application + constructed */ 1208*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_DELETE 0x4aL /* application + primitive */ 1209*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_RENAME 0x6cL /* application + constructed */ 1210*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_COMPARE 0x6eL /* application + constructed */ 1211*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_ABANDON 0x50L /* application + primitive */ 1212*7c478bd9Sstevel@tonic-gate #define LDAP_REQ_EXTENDED 0x77L /* application + constructed */ 1213*7c478bd9Sstevel@tonic-gate #endif /* LDAP_REQ_BIND */ 1214*7c478bd9Sstevel@tonic-gate 1215*7c478bd9Sstevel@tonic-gate 1216*7c478bd9Sstevel@tonic-gate 1217*7c478bd9Sstevel@tonic-gate struct ldapsearch_type2str { 1218*7c478bd9Sstevel@tonic-gate 1219*7c478bd9Sstevel@tonic-gate int ldst2s_type; /* message type */ 1220*7c478bd9Sstevel@tonic-gate char *ldst2s_string; /* descriptive string */ 1221*7c478bd9Sstevel@tonic-gate }; 1222*7c478bd9Sstevel@tonic-gate 1223*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1224*7c478bd9Sstevel@tonic-gate static struct ldapsearch_type2str ldapsearch_msgtypes[] = { 1225*7c478bd9Sstevel@tonic-gate 1226*7c478bd9Sstevel@tonic-gate /* results: */ 1227*7c478bd9Sstevel@tonic-gate { LDAP_RES_BIND, NULL }, 1228*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_REFERENCE, NULL }, 1229*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_ENTRY, NULL }, 1230*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_RESULT, NULL }, 1231*7c478bd9Sstevel@tonic-gate { LDAP_RES_MODIFY, NULL }, 1232*7c478bd9Sstevel@tonic-gate { LDAP_RES_ADD, NULL }, 1233*7c478bd9Sstevel@tonic-gate { LDAP_RES_DELETE, NULL }, 1234*7c478bd9Sstevel@tonic-gate { LDAP_RES_MODDN, NULL }, 1235*7c478bd9Sstevel@tonic-gate { LDAP_RES_COMPARE, NULL }, 1236*7c478bd9Sstevel@tonic-gate { LDAP_RES_EXTENDED, NULL }, 1237*7c478bd9Sstevel@tonic-gate /* requests: */ 1238*7c478bd9Sstevel@tonic-gate { LDAP_REQ_BIND, NULL }, 1239*7c478bd9Sstevel@tonic-gate { LDAP_REQ_UNBIND, NULL }, 1240*7c478bd9Sstevel@tonic-gate { LDAP_REQ_SEARCH, NULL }, 1241*7c478bd9Sstevel@tonic-gate { LDAP_REQ_MODIFY, NULL }, 1242*7c478bd9Sstevel@tonic-gate { LDAP_REQ_ADD, NULL }, 1243*7c478bd9Sstevel@tonic-gate { LDAP_REQ_DELETE, NULL }, 1244*7c478bd9Sstevel@tonic-gate { LDAP_REQ_RENAME, NULL }, 1245*7c478bd9Sstevel@tonic-gate { LDAP_REQ_COMPARE, NULL }, 1246*7c478bd9Sstevel@tonic-gate { LDAP_REQ_ABANDON, NULL }, 1247*7c478bd9Sstevel@tonic-gate { LDAP_REQ_EXTENDED, NULL }, 1248*7c478bd9Sstevel@tonic-gate 1249*7c478bd9Sstevel@tonic-gate }; 1250*7c478bd9Sstevel@tonic-gate #else 1251*7c478bd9Sstevel@tonic-gate static struct ldapsearch_type2str ldapsearch_msgtypes[] = { 1252*7c478bd9Sstevel@tonic-gate 1253*7c478bd9Sstevel@tonic-gate /* results: */ 1254*7c478bd9Sstevel@tonic-gate { LDAP_RES_BIND, "bind result" }, 1255*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_REFERENCE, "continuation reference" }, 1256*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_ENTRY, "entry" }, 1257*7c478bd9Sstevel@tonic-gate { LDAP_RES_SEARCH_RESULT, "search result" }, 1258*7c478bd9Sstevel@tonic-gate { LDAP_RES_MODIFY, "modify result" }, 1259*7c478bd9Sstevel@tonic-gate { LDAP_RES_ADD, "add result" }, 1260*7c478bd9Sstevel@tonic-gate { LDAP_RES_DELETE, "delete result" }, 1261*7c478bd9Sstevel@tonic-gate { LDAP_RES_MODDN, "rename result" }, 1262*7c478bd9Sstevel@tonic-gate { LDAP_RES_COMPARE, "compare result" }, 1263*7c478bd9Sstevel@tonic-gate { LDAP_RES_EXTENDED, "extended operation result" }, 1264*7c478bd9Sstevel@tonic-gate /* requests: */ 1265*7c478bd9Sstevel@tonic-gate { LDAP_REQ_BIND, "bind request" }, 1266*7c478bd9Sstevel@tonic-gate { LDAP_REQ_UNBIND, "unbind request" }, 1267*7c478bd9Sstevel@tonic-gate { LDAP_REQ_SEARCH, "search request" }, 1268*7c478bd9Sstevel@tonic-gate { LDAP_REQ_MODIFY, "modify request" }, 1269*7c478bd9Sstevel@tonic-gate { LDAP_REQ_ADD, "add request" }, 1270*7c478bd9Sstevel@tonic-gate { LDAP_REQ_DELETE, "delete request" }, 1271*7c478bd9Sstevel@tonic-gate { LDAP_REQ_RENAME, "rename request" }, 1272*7c478bd9Sstevel@tonic-gate { LDAP_REQ_COMPARE, "compare request" }, 1273*7c478bd9Sstevel@tonic-gate { LDAP_REQ_ABANDON, "abandon request" }, 1274*7c478bd9Sstevel@tonic-gate { LDAP_REQ_EXTENDED, "extended request" }, 1275*7c478bd9Sstevel@tonic-gate 1276*7c478bd9Sstevel@tonic-gate }; 1277*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1278*7c478bd9Sstevel@tonic-gate 1279*7c478bd9Sstevel@tonic-gate 1280*7c478bd9Sstevel@tonic-gate #define LDAPSEARCHTOOL_NUMTYPES (sizeof(ldapsearch_msgtypes) \ 1281*7c478bd9Sstevel@tonic-gate / sizeof(struct ldapsearch_type2str)) 1282*7c478bd9Sstevel@tonic-gate 1283*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1284*7c478bd9Sstevel@tonic-gate static void 1285*7c478bd9Sstevel@tonic-gate fill_ldapsearch_msgtypes( void ) 1286*7c478bd9Sstevel@tonic-gate { 1287*7c478bd9Sstevel@tonic-gate int i = 0; 1288*7c478bd9Sstevel@tonic-gate if (ldapsearch_msgtypes[LDAPSEARCHTOOL_NUMTYPES - 1].ldst2s_string 1289*7c478bd9Sstevel@tonic-gate != NULL) 1290*7c478bd9Sstevel@tonic-gate return; 1291*7c478bd9Sstevel@tonic-gate 1292*7c478bd9Sstevel@tonic-gate /* results: */ 1293*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1294*7c478bd9Sstevel@tonic-gate "bind result"); 1295*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1296*7c478bd9Sstevel@tonic-gate "continuation reference"); 1297*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1298*7c478bd9Sstevel@tonic-gate "entry"); 1299*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1300*7c478bd9Sstevel@tonic-gate "search result"); 1301*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1302*7c478bd9Sstevel@tonic-gate "modify result"); 1303*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1304*7c478bd9Sstevel@tonic-gate "add result"); 1305*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1306*7c478bd9Sstevel@tonic-gate "delete result"); 1307*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1308*7c478bd9Sstevel@tonic-gate "rename result"); 1309*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1310*7c478bd9Sstevel@tonic-gate "compare result"); 1311*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1312*7c478bd9Sstevel@tonic-gate "extended operation result"); 1313*7c478bd9Sstevel@tonic-gate /* requests: */ 1314*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1315*7c478bd9Sstevel@tonic-gate "bind request"); 1316*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1317*7c478bd9Sstevel@tonic-gate "unbind request"); 1318*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1319*7c478bd9Sstevel@tonic-gate "search request"); 1320*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1321*7c478bd9Sstevel@tonic-gate "modify request"); 1322*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1323*7c478bd9Sstevel@tonic-gate "add request"); 1324*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1325*7c478bd9Sstevel@tonic-gate "delete request"); 1326*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1327*7c478bd9Sstevel@tonic-gate "rename request"); 1328*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1329*7c478bd9Sstevel@tonic-gate "compare request"); 1330*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1331*7c478bd9Sstevel@tonic-gate "abandon request"); 1332*7c478bd9Sstevel@tonic-gate ldapsearch_msgtypes[i++].ldst2s_string = gettext( 1333*7c478bd9Sstevel@tonic-gate "extended request"); 1334*7c478bd9Sstevel@tonic-gate } 1335*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1336*7c478bd9Sstevel@tonic-gate 1337*7c478bd9Sstevel@tonic-gate /* 1338*7c478bd9Sstevel@tonic-gate * Return a descriptive string given an LDAP result message type (tag). 1339*7c478bd9Sstevel@tonic-gate */ 1340*7c478bd9Sstevel@tonic-gate static char * 1341*7c478bd9Sstevel@tonic-gate msgtype2str( int msgtype ) 1342*7c478bd9Sstevel@tonic-gate { 1343*7c478bd9Sstevel@tonic-gate char *s = gettext("unknown"); 1344*7c478bd9Sstevel@tonic-gate int i; 1345*7c478bd9Sstevel@tonic-gate 1346*7c478bd9Sstevel@tonic-gate #ifdef SOLARIS_LDAP_CMD 1347*7c478bd9Sstevel@tonic-gate /* Make sure ldapsearch_msgtypes is initialized */ 1348*7c478bd9Sstevel@tonic-gate if (ldapsearch_msgtypes[LDAPSEARCHTOOL_NUMTYPES - 1].ldst2s_string 1349*7c478bd9Sstevel@tonic-gate == NULL) 1350*7c478bd9Sstevel@tonic-gate (void) fill_ldapsearch_msgtypes(); 1351*7c478bd9Sstevel@tonic-gate #endif /* SOLARIS_LDAP_CMD */ 1352*7c478bd9Sstevel@tonic-gate 1353*7c478bd9Sstevel@tonic-gate for ( i = 0; i < LDAPSEARCHTOOL_NUMTYPES; ++i ) { 1354*7c478bd9Sstevel@tonic-gate if ( msgtype == ldapsearch_msgtypes[ i ].ldst2s_type ) { 1355*7c478bd9Sstevel@tonic-gate s = ldapsearch_msgtypes[ i ].ldst2s_string; 1356*7c478bd9Sstevel@tonic-gate } 1357*7c478bd9Sstevel@tonic-gate } 1358*7c478bd9Sstevel@tonic-gate return( s ); 1359*7c478bd9Sstevel@tonic-gate } 1360*7c478bd9Sstevel@tonic-gate 1361*7c478bd9Sstevel@tonic-gate 1362*7c478bd9Sstevel@tonic-gate /* 1363*7c478bd9Sstevel@tonic-gate * Return a descriptive string given a Persistent Search change type 1364*7c478bd9Sstevel@tonic-gate */ 1365*7c478bd9Sstevel@tonic-gate static char * 1366*7c478bd9Sstevel@tonic-gate changetype_num2string( int chgtype ) 1367*7c478bd9Sstevel@tonic-gate { 1368*7c478bd9Sstevel@tonic-gate char *s = gettext("unknown"); 1369*7c478bd9Sstevel@tonic-gate 1370*7c478bd9Sstevel@tonic-gate switch( chgtype ) { 1371*7c478bd9Sstevel@tonic-gate case LDAP_CHANGETYPE_ADD: 1372*7c478bd9Sstevel@tonic-gate s = gettext("add"); 1373*7c478bd9Sstevel@tonic-gate break; 1374*7c478bd9Sstevel@tonic-gate case LDAP_CHANGETYPE_DELETE: 1375*7c478bd9Sstevel@tonic-gate s = gettext("delete"); 1376*7c478bd9Sstevel@tonic-gate break; 1377*7c478bd9Sstevel@tonic-gate case LDAP_CHANGETYPE_MODIFY: 1378*7c478bd9Sstevel@tonic-gate s = gettext("modify"); 1379*7c478bd9Sstevel@tonic-gate break; 1380*7c478bd9Sstevel@tonic-gate case LDAP_CHANGETYPE_MODDN: 1381*7c478bd9Sstevel@tonic-gate s = gettext("moddn"); 1382*7c478bd9Sstevel@tonic-gate break; 1383*7c478bd9Sstevel@tonic-gate } 1384*7c478bd9Sstevel@tonic-gate 1385*7c478bd9Sstevel@tonic-gate return( s ); 1386*7c478bd9Sstevel@tonic-gate } 1387*7c478bd9Sstevel@tonic-gate 1388*7c478bd9Sstevel@tonic-gate /* returns a null teminated charrary */ 1389*7c478bd9Sstevel@tonic-gate static char **get_effectiverights_attrlist(char * optarg) { 1390*7c478bd9Sstevel@tonic-gate 1391*7c478bd9Sstevel@tonic-gate char * tmp_str = strdup(optarg); 1392*7c478bd9Sstevel@tonic-gate char ** retArray = NULL; 1393*7c478bd9Sstevel@tonic-gate int i = 0; 1394*7c478bd9Sstevel@tonic-gate 1395*7c478bd9Sstevel@tonic-gate retArray = ldap_str2charray( tmp_str, " "); /* takes copies */ 1396*7c478bd9Sstevel@tonic-gate 1397*7c478bd9Sstevel@tonic-gate free(tmp_str); 1398*7c478bd9Sstevel@tonic-gate 1399*7c478bd9Sstevel@tonic-gate /* Oops - somebody left this debug message in for the 1400*7c478bd9Sstevel@tonic-gate getEffectiveRights control 1401*7c478bd9Sstevel@tonic-gate fprintf(stderr, "attrlist: "); */ 1402*7c478bd9Sstevel@tonic-gate i = 0; 1403*7c478bd9Sstevel@tonic-gate while( retArray[i] != NULL ) { 1404*7c478bd9Sstevel@tonic-gate 1405*7c478bd9Sstevel@tonic-gate fprintf(stderr,"%s ", retArray[i]); 1406*7c478bd9Sstevel@tonic-gate i++; 1407*7c478bd9Sstevel@tonic-gate } 1408*7c478bd9Sstevel@tonic-gate fprintf(stderr, "\n"); 1409*7c478bd9Sstevel@tonic-gate 1410*7c478bd9Sstevel@tonic-gate return(retArray); 1411*7c478bd9Sstevel@tonic-gate 1412*7c478bd9Sstevel@tonic-gate } 1413