/*
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "lber.h"
#include "ldap.h"
#define MOD_USE_BVALS
#ifdef NEEDPROTOS
#else
static void handle_result();
static void print_ldap_result();
static void print_search_entry();
static void free_list();
#endif /* NEEDPROTOS */
char *dnsuffix;
static char *
{
return( NULL );
return( line );
}
static char **
{
int num;
char **result;
num = 0;
result = (char **) 0;
while ( 1 ) {
if ( *buf == '\0' )
break;
if ( result == (char **) 0 )
else
sizeof(char *) * (num + 1) );
}
if ( result == (char **) 0 )
return( NULL );
return( result );
}
static void
{
int i;
}
}
}
#ifdef MOD_USE_BVALS
static int
{
long rlen;
int eof;
return( -1 );
}
return( -1 );
}
perror( "malloc" );
return( -1 );
}
return( -1 );
}
return( -1 );
}
}
#endif /* MOD_USE_BVALS */
static LDAPMod **
{
int num;
#ifdef MOD_USE_BVALS
#endif /* MOD_USE_BVALS */
num = 0;
while ( 1 ) {
if ( prompt1 ) {
break;
}
if ( buf[0] == '\0' )
break;
#ifdef MOD_USE_BVALS
int i;
;
sizeof( struct berval *));
sizeof( struct berval ));
6 ) == 0 ) {
bvals[i] ) < 0 ) {
return( NULL );
}
} else {
}
}
}
#endif /* MOD_USE_BVALS */
else
num++;
}
return( NULL );
return( result );
}
int
int freeit )
{
if ( !freeit ) {
#ifdef KERBEROS
"re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
} else {
*authmethodp |= 0x80;
}
#else /* KERBEROS */
#endif /* KERBEROS */
"re-bind password? " );
} else {
passwd[0] = '\0';
}
}
return( LDAP_SUCCESS );
}
int
{
char *mechanism;
char **exdn;
extern char *optarg;
extern int optind;
#ifdef MACOS
exit( 1 );
}
;
}
#endif /* MACOS */
dnsuffix = "";
switch( c ) {
case 'u':
#ifdef CLDAP
cldapflg++;
#else /* CLDAP */
printf( "Compile with -DCLDAP for UDP support\n" );
#endif /* CLDAP */
break;
case 'd':
#ifdef LDAP_DEBUG
if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
}
#else
printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
break;
case 'h':
break;
case 's':
break;
case 'p':
break;
case 't': /* copy ber's to given file */
break;
case 'T': /* only output ber's to given file */
break;
#endif
default:
++errflg;
}
}
++optind;
}
exit( 1 );
}
if ( cldapflg ) {
#ifdef CLDAP
#endif /* CLDAP */
} else {
}
perror( "ldap_init" );
exit(1);
}
0600 )) == -1 ) {
exit ( 1 );
}
}
#endif
bound = 0;
switch ( command1 ) {
case 'a': /* add or abandon */
switch ( command2 ) {
case 'd': /* add */
"value? " )) == NULL )
break;
else
}
else {
else
}
break;
case 'b': /* abandon */
else
printf( "Abandon successful\n" );
break;
default:
printf( "Possibilities: [ad]d, [ab]ort\n" );
}
break;
case 'b': /* asynch bind */
#ifdef KERBEROS
"method (0->simple, 1->krbv41, 2->krbv42)? " );
#else /* KERBEROS */
#endif /* KERBEROS */
"password? " );
else
passwd[0] = '\0';
} else {
printf( "Bind initiated\n" );
bound = 1;
}
break;
case 'B': /* synch bind */
#ifdef KERBEROS
"method 0->simple 1->krbv41 2->krbv42 3->krb? " );
if ( method == 3 )
else
#else /* KERBEROS */
"method 0->simple, 1->SASL? ");
if (method == 1){
"mechanism 0->CRAM_MD5, 1->TLS? ");
if (theInt == 0){
}
else{
}
} else {
}
#endif /* KERBEROS */
if ( dn[0] != '\0' )
"password? " );
else
passwd[0] = '\0';
if (method == LDAP_AUTH_SIMPLE) {
LDAP_SUCCESS ) {
} else {
printf( "Bind successful\n" );
bound = 1;
}
} else {
} else {
printf ( "Bind successful\n");
bound = 1;
}
} else {
}
}
}
break;
case 'c': /* compare */
else
} else {
else
}
break;
case 'd': /* turn on debugging */
#ifdef LDAP_DEBUG
if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
}
#else
printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
break;
case 'E': /* explode a dn */
}
break;
case 'g': /* set next msgid */
break;
case 'v': /* set version number */
break;
case 'm': /* modify or modifyrdn */
if ( (mods = get_modlist(
"mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
"attribute type? ", "attribute value? " ))
== NULL )
break;
else
}
else {
else
}
}
else
}
else {
else
}
} else {
printf( "Possibilities: [modi]fy, [modr]dn\n" );
}
break;
case 'q': /* quit */
#ifdef CLDAP
if ( cldapflg )
cldap_close( ld );
#endif /* CLDAP */
if ( !cldapflg )
ldap_unbind( ld );
exit( 0 );
break;
case 'r': /* result or remove */
switch ( command3 ) {
case 's': /* result */
"msgid (-1=>any)? " );
if ( line[0] == '\0' )
id = -1;
else
"all (0=>any, 1=>all)? " );
if ( line[0] == '\0' )
all = 1;
else
break;
}
printf( "\nresult: msgtype %d msgid %d\n",
resultusetimelimit = 0;
break;
case 'm': /* remove */
else
} else {
else
}
break;
default:
printf( "Possibilities: [rem]ove, [res]ult\n" );
break;
}
break;
case 's': /* search */
"scope (0=Base, 1=One Level, 2=Subtree)? " );
"search filter (e.g. sn=jones)? " );
"attrsonly (0=attrs&values, 1=attrs only)? " );
if ( cldapflg ) {
#ifdef CLDAP
"Requestor DN (for logging)? " );
} else {
printf( "\nresult: msgid %d\n",
}
#endif /* CLDAP */
} else {
theInt = 0;
resultusetimelimit = 1;
"ldap_search_ext (0=>no, 1=>yes - default: yes)? " );
if (line[0] == '\0')
theInt = 1;
else
}
if (theInt){
resultusetimelimit = 1;
} else {
}
} else {
} else {
}
}
}
break;
case 't': /* set timeout value */
break;
case 'U': /* set ufn search prefix */
break;
"attrsonly (0=attrs&values, 1=attrs only)? " );
if ( command2 == 't' ) {
&timeout );
} else {
}
else {
}
break;
case 'l': /* URL search */
"attrsonly (0=attrs&values, 1=attrs only)? " );
== -1 ) {
} else {
}
break;
case 'p': /* parse LDAP URL */
} else {
printf( "\t host: " );
printf( "DEFAULT\n" );
} else {
}
printf( "\t port: " );
printf( "DEFAULT\n" );
} else {
}
printf( "\t attrs:" );
printf( " ALL" );
} else {
}
}
if (ludp->lud_extensions){
printf("\textensions: \n");
}
}
break;
case 'n': /* set dn suffix, for convenience */
break;
case 'e': /* enable cache */
#ifdef NO_CACHE
printf( NOCACHEERRMSG );
#else /* NO_CACHE */
printf( "local cache is on\n" );
} else {
printf( "ldap_enable_cache failed\n" );
}
#endif /* NO_CACHE */
break;
case 'x': /* uncache entry */
#ifdef NO_CACHE
printf( NOCACHEERRMSG );
#else /* NO_CACHE */
#endif /* NO_CACHE */
break;
case 'X': /* uncache request */
#ifdef NO_CACHE
printf( NOCACHEERRMSG );
#else /* NO_CACHE */
#endif /* NO_CACHE */
break;
case 'o': /* set ldap options */
ld->ld_options = 0;
#ifdef STR_TRANSLATION
"Automatic translation of T.61 strings (0=no, 1=yes)?" );
} else {
#ifdef LDAP_CHARSET_8859
}
#endif /* LDAP_CHARSET_8859 */
}
#endif /* STR_TRANSLATION */
#ifdef LDAP_DNS
"Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
}
#endif /* LDAP_DNS */
"Recognize and chase referrals (0=no, 1=yes)?" );
"Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
}
} else {
}
break;
case 'k': /* Set some controls */
"Set control: (0 for none, 1 for ManageDSA, 2 for preferredLang, 3 for BAD)?");
switch (theInt){
case 0:
break;
case 1:
break;
case 2:
"Preferred Language Control : lang ?");
break;
default:
"Bad Control is critical (0=false, 1=true)?");
break;
}
break;
case 'O': /* set cache options */
#ifdef NO_CACHE
printf( NOCACHEERRMSG );
#else /* NO_CACHE */
case 0:
ldap_set_cache_options( ld, 0 );
break;
case 1:
break;
case 2:
break;
default:
printf( "not a valid cache option\n" );
}
#endif /* NO_CACHE */
break;
case '?': /* help */
printf( "Commands: [ad]d [ab]andon [b]ind\n" );
printf( " [B]ind async [c]ompare [l]URL search\n" );
printf( " [modi]fy [modr]dn [rem]ove\n" );
printf( " [u]fn search [ut]fn search with timeout\n" );
printf( " [d]ebug [e]nable cache set ms[g]id\n" );
printf( " d[n]suffix [t]imeout [v]ersion\n" );
printf( " [U]fn prefix [x]uncache entry [X]uncache request\n" );
printf( " [?]help [o]ptions [O]cache options\n" );
printf( " [E]xplode dn [p]arse LDAP URL\n" );
break;
default:
printf( "Invalid command. Type ? for help.\n" );
break;
}
}
return( 0 );
}
static void
{
switch ( lm->lm_msgtype ) {
case LDAP_RES_COMPARE:
printf( "Compare result\n" );
break;
case LDAP_RES_SEARCH_RESULT:
printf( "Search result\n" );
break;
printf( "Search reference\n" );
break;
case LDAP_RES_SEARCH_ENTRY:
printf( "Search entry\n" );
break;
case LDAP_RES_ADD:
printf( "Add result\n" );
break;
case LDAP_RES_DELETE:
printf( "Delete result\n" );
break;
case LDAP_RES_MODIFY:
printf( "Modify result\n" );
break;
case LDAP_RES_MODRDN:
printf( "ModRDN result\n" );
break;
case LDAP_RES_BIND:
printf( "Bind result\n" );
break;
default:
}
}
static void
{
int rc, i;
int errCode;
if ((rc = ldap_parse_result(ld, lm, &errCode, &matched, &errMsg, &referrals, &srvctrls, 0)) != LDAP_SUCCESS){
return;
}
if (errCode == LDAP_REFERRAL){
}
}
fprintf(stderr, "\t\t%s (%s)\n", srvctrls[i]->ldctl_oid, srvctrls[i]->ldctl_iscritical ? "Critical" : "Not critical");
}
return;
}
static void
{
int i;
LDAPMessage *e;
e = ldap_next_message( ld, e ) ) {
if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
break;
if ( e->lm_msgtype == LDAP_RES_SEARCH_REFERENCE ){
} else {
}
} else {
printf( "\t\tATTR: %s\n", a );
== NULL ) {
printf( "\t\t\t(no values)\n" );
} else {
int j, nonascii;
nonascii = 0;
nonascii = 1;
break;
}
if ( nonascii ) {
#ifdef BPRINT_NONASCII
#endif /* BPRINT_NONASCII */
continue;
}
printf( "\t\t\tlength (%ld) %s\n",
}
ber_bvecfree( vals );
}
}
}
}
}