#include "ldap-int.h"
/* local functions */
-#ifndef HAVE_GETLINE
-static char *getline LDAP_P(( char *line, int len, FILE *fp, const char *prompt ));
-#endif
+static char *get_line LDAP_P(( char *line, int len, FILE *fp, const char *prompt ));
static char **get_list LDAP_P(( const char *prompt ));
static int file_read LDAP_P(( const char *path, struct berval *bv ));
static LDAPMod **get_modlist LDAP_P(( const char *prompt1,
static char *dnsuffix;
-#ifndef HAVE_GETLINE
static char *
-getline( char *line, int len, FILE *fp, const char *prompt )
+get_line( char *line, int len, FILE *fp, const char *prompt )
{
printf(prompt);
num = 0;
result = (char **) 0;
while ( 1 ) {
- getline( buf, sizeof(buf), stdin, prompt );
+ get_line( buf, sizeof(buf), stdin, prompt );
if ( *buf == '\0' )
break;
result = NULL;
while ( 1 ) {
if ( prompt1 ) {
- getline( buf, sizeof(buf), stdin, prompt1 );
+ get_line( buf, sizeof(buf), stdin, prompt1 );
tmp.mod_op = atoi( buf );
if ( tmp.mod_op == -1 || buf[0] == '\0' )
break;
}
- getline( buf, sizeof(buf), stdin, prompt2 );
+ get_line( buf, sizeof(buf), stdin, prompt2 );
if ( buf[0] == '\0' )
break;
tmp.mod_type = strdup( buf );
request, (long) msgid, url );
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
- getline( dn, sizeof(dn), stdin,
+ get_line( dn, sizeof(dn), stdin,
"re-bind method (0->simple, 1->krbv41, 2->krbv42, 3->krbv41&2)? " );
if (( authmethod = atoi( dn )) == 3 ) {
authmethod = LDAP_AUTH_KRBV4;
authmethod = LDAP_AUTH_SIMPLE;
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
- getline( dn, sizeof(dn), stdin, "re-bind dn? " );
+ get_line( dn, sizeof(dn), stdin, "re-bind dn? " );
strcat( dn, dnsuffix );
if ( authmethod == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
- getline( passwd, sizeof(passwd), stdin,
+ get_line( passwd, sizeof(passwd), stdin,
"re-bind password? " );
} else {
passwd[0] = '\0';
timeout.tv_usec = 0;
(void) memset( line, '\0', sizeof(line) );
- while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
+ while ( get_line( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
command1 = line[0];
command2 = line[1];
command3 = line[2];
case 'a': /* add or abandon */
switch ( command2 ) {
case 'd': /* add */
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
if ( (attrs = get_modlist( NULL, "attr? ",
"value? " )) == NULL )
break;
case 'b': /* abandon */
- getline( line, sizeof(line), stdin, "msgid? " );
+ get_line( line, sizeof(line), stdin, "msgid? " );
id = atoi( line );
if ( ldap_abandon( ld, id ) != 0 )
ldap_perror( ld, "ldap_abandon" );
case 'b': /* asynch bind */
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"method (0->simple, 1->krbv41, 2->krbv42)? " );
method = atoi( line ) | 0x80;
#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
method = LDAP_AUTH_SIMPLE;
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
- getline( passwd, sizeof(passwd), stdin,
+ get_line( passwd, sizeof(passwd), stdin,
"password? " );
else
passwd[0] = '\0';
case 'B': /* synch bind */
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"method 0->simple 1->krbv41 2->krbv42 3->krb? " );
method = atoi( line );
if ( method == 3 )
#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
method = LDAP_AUTH_SIMPLE;
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
if ( dn[0] != '\0' )
- getline( passwd, sizeof(passwd), stdin,
+ get_line( passwd, sizeof(passwd), stdin,
"password? " );
else
passwd[0] = '\0';
break;
case 'c': /* compare */
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
- getline( attr, sizeof(attr), stdin, "attr? " );
- getline( value, sizeof(value), stdin, "value? " );
+ get_line( attr, sizeof(attr), stdin, "attr? " );
+ get_line( value, sizeof(value), stdin, "value? " );
if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
ldap_perror( ld, "ldap_compare" );
case 'd': /* turn on debugging */
#ifdef LDAP_DEBUG
- getline( line, sizeof(line), stdin, "debug level? " );
+ get_line( line, sizeof(line), stdin, "debug level? " );
ldap_debug = atoi( line );
#ifdef LBER_DEBUG
if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
break;
case 'E': /* explode a dn */
- getline( line, sizeof(line), stdin, "dn? " );
+ get_line( line, sizeof(line), stdin, "dn? " );
exdn = ldap_explode_dn( line, 0 );
for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
printf( "\t%s\n", exdn[i] );
break;
case 'g': /* set next msgid */
- getline( line, sizeof(line), stdin, "msgid? " );
+ get_line( line, sizeof(line), stdin, "msgid? " );
ld->ld_msgid = atoi( line );
break;
case 'v': /* set version number */
- getline( line, sizeof(line), stdin, "version? " );
+ get_line( line, sizeof(line), stdin, "version? " );
ld->ld_version = atoi( line );
break;
case 'm': /* modify or modifyrdn */
if ( strncmp( line, "modify", 4 ) == 0 ) {
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
if ( (mods = get_modlist(
"mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
printf( "Modify initiated with id %d\n",
id );
} else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
- getline( rdn, sizeof(rdn), stdin, "newrdn? " );
+ get_line( rdn, sizeof(rdn), stdin, "newrdn? " );
if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
ldap_perror( ld, "ldap_modrdn" );
else
case 'r': /* result or remove */
switch ( command3 ) {
case 's': /* result */
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"msgid (-1=>any)? " );
if ( line[0] == '\0' )
id = -1;
else
id = atoi( line );
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"all (0=>any, 1=>all)? " );
if ( line[0] == '\0' )
all = 1;
break;
case 'm': /* remove */
- getline( dn, sizeof(dn), stdin, "dn? " );
+ get_line( dn, sizeof(dn), stdin, "dn? " );
strcat( dn, dnsuffix );
if ( (id = ldap_delete( ld, dn )) == -1 )
ldap_perror( ld, "ldap_delete" );
break;
case 's': /* search */
- getline( dn, sizeof(dn), stdin, "searchbase? " );
+ get_line( dn, sizeof(dn), stdin, "searchbase? " );
strcat( dn, dnsuffix );
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"scope (0=Base, 1=One Level, 2=Subtree)? " );
scope = atoi( line );
- getline( filter, sizeof(filter), stdin,
+ get_line( filter, sizeof(filter), stdin,
"search filter (e.g. sn=jones)? " );
types = get_list( "attrs to return? " );
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"attrsonly (0=attrs&values, 1=attrs only)? " );
attrsonly = atoi( line );
break;
case 't': /* set timeout value */
- getline( line, sizeof(line), stdin, "timeout? " );
+ get_line( line, sizeof(line), stdin, "timeout? " );
timeout.tv_sec = atoi( line );
break;
case 'p': /* parse LDAP URL */
- getline( line, sizeof(line), stdin, "LDAP URL? " );
+ get_line( line, sizeof(line), stdin, "LDAP URL? " );
if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
fprintf( stderr, "ldap_url_parse: error %d\n", i );
} else {
break;
case 'n': /* set dn suffix, for convenience */
- getline( line, sizeof(line), stdin, "DN suffix? " );
+ get_line( line, sizeof(line), stdin, "DN suffix? " );
strcpy( dnsuffix, line );
break;
case 'o': /* set ldap options */
- getline( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
+ get_line( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
ld->ld_deref = atoi( line );
- getline( line, sizeof(line), stdin, "timelimit?" );
+ get_line( line, sizeof(line), stdin, "timelimit?" );
ld->ld_timelimit = atoi( line );
- getline( line, sizeof(line), stdin, "sizelimit?" );
+ get_line( line, sizeof(line), stdin, "sizelimit?" );
ld->ld_sizelimit = atoi( line );
LDAP_BOOL_ZERO(&ld->ld_options);
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"Recognize and chase referrals (0=no, 1=yes)?" );
if ( atoi( line ) != 0 ) {
LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
- getline( line, sizeof(line), stdin,
+ get_line( line, sizeof(line), stdin,
"Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
if ( atoi( line ) != 0 ) {
ldap_set_rebind_proc( ld, bind_prompt, NULL );