grclogins = warnvalue;
grclogins = (int)warnvalue;
parse_result( LDAP *ld, LDAPMessage *res, struct berval **servercredp,	char *msg, int freeit ){    int		rc, lderr, errno;    int		pw_days=0, pw_hrs=0, pw_mins=0, pw_secs=0; /* for pwpolicy */    char	**refs = NULL;    LDAPControl	**ctrls;    BerElement *ber = NULL;    static const char *pwpolicy_err2str[] = {	"Password has expired.",	"Account is locked.",	"Password has been reset by an administrator; you must change it.",	"Password change not allowed.",	"Must supply old password.",	"Invalid password syntax.",	"Password too short.",	"Password too young.",	"Password in history."    };    if (( rc = ldap_parse_result( ld, res, &lderr, NULL, NULL, &refs,	    &ctrls, 0 )) != LDAP_SUCCESS ) {	(void)ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP );	ldap_msgfree( res );	return( rc );    }    /* check for authentication response control & PWPOLICY control*/    if ( NULL != ctrls ) {	int		i;	char		*s;	for ( i = 0; NULL != ctrls[i]; ++i ) {	    if ( 0 == strcmp( ctrls[i]->ldctl_oid,			LDAP_CONTROL_AUTH_RESPONSE )) {		    s = ctrls[i]->ldctl_value.bv_val;		    if ( NULL == s ) {			s = "Null";		    } else if ( *s == '\0' ) {			s = "Anonymous";		    }		fprintf( stderr, "%s: bound as %s\n", ldaptool_progname, s );	    }	    if ( 0 == strcmp( ctrls[i]->ldctl_oid,			LDAP_CONTROL_PWEXPIRING )) {		    /* Warn the user his passwd is to expire */		    errno = 0;			    pw_secs = atoi(ctrls[i]->ldctl_value.bv_val);		    if ( pw_secs > 0  && errno != ERANGE ) {			if ( pw_secs > 86400 ) {				pw_days = ( pw_secs / 86400 );				pw_secs = ( pw_secs % 86400 );			} 			if ( pw_secs > 3600 ) {				pw_hrs = ( pw_secs / 3600 );				pw_secs = ( pw_secs % 3600 );			}			if ( pw_secs > 60 ) {				pw_mins = ( pw_secs / 60 );				pw_secs = ( pw_secs % 60 );			}			printf("%s: Warning ! Your password will expire after ", ldaptool_progname);			if ( pw_days ) {				printf ("%d days, ", pw_days);			}			if ( pw_hrs ) {				printf ("%d hrs, ", pw_hrs);			}			if ( pw_mins ) {				printf ("%d mins, ", pw_mins);			}			printf("%d seconds.\n", pw_secs);					   }		}	    if ( 0 == strcmp( ctrls[i]->ldctl_oid,		LDAP_X_CONTROL_PWPOLICY_RESPONSE )) {		unsigned long tag1=0, tag2=0, tag3=0;		int warnvalue=0, grclogins=-1, secsleft=-1, errvalue=-1;		static int err2str_size = sizeof(pwpolicy_err2str)/sizeof(pwpolicy_err2str[0]);		if ( ( ber = ber_init(&(ctrls[i]->ldctl_value)) ) == NULL ) {			fprintf(stderr, "%s: not enough memory\n", ldaptool_progname);			return( LDAP_NO_MEMORY );		}		if ( ber_scanf(ber,"{t", &tag1) == LBER_ERROR ) {			/* error */			ber_free( ber, 1 );			return (ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP ));		} 		switch (tag1) {		case LDAP_TAG_PWP_WARNING:			if ( ber_scanf(ber, "{ti}", &tag2, &warnvalue)					== LBER_ERROR ) {				/* error */				ber_free( ber, 1 );				return(ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP ));			}			switch (tag2) {			case LDAP_TAG_PWP_SECSLEFT:				secsleft = warnvalue;				break;			case LDAP_TAG_PWP_GRCLOGINS:				grclogins = warnvalue;				break;			default:				/* error */				ber_free( ber, 1 );				return(ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP ));			}			/* Now check for the error value if it's present */			if ( ber_scanf(ber, "te", &tag3, &errvalue) != LBER_ERROR ) {				if (tag3 != LDAP_TAG_PWP_ERROR) {					errvalue = -1;				}			}			break;		case LDAP_TAG_PWP_ERROR:			if ( ber_scanf(ber, "e}", &errvalue) 					== LBER_ERROR ) {				/* error */				ber_free( ber, 1 );				return(ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP ));			}			break;		default : /* error */			ber_free( ber, 1 );			return(ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP ));		}				/* Now we have all the values */		if ( secsleft >= 0 ) {			fprintf(stderr, "%s: Password will expire in %d seconds\n",				ldaptool_progname, secsleft);		}		if ( grclogins >= 0 ) {			fprintf(stderr, "%s: %d grace login(s) remain\n",				ldaptool_progname, grclogins);		}		if ( errvalue >= 0 && errvalue < err2str_size ) {			fprintf(stderr, "%s: %s\n",				ldaptool_progname, pwpolicy_err2str[errvalue]);		} else if ( errvalue != -1 ) {			fprintf(stderr, "%s: %s\n",				ldaptool_progname,				"Invalid error value in password policy response control");		}	    } /* end of LDAP_X_CONTROL_PWPOLICY_RESPONSE */	}	ldap_controls_free( ctrls );    }    if ( servercredp != NULL && ( rc = ldap_parse_sasl_bind_result( ld, res,	    servercredp, 0 )) != LDAP_SUCCESS ) {	(void)ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP );	ldap_msgfree( res );	ber_free( ber, 1 );	return( rc );    }    if ( freeit ) {	ldap_msgfree( res );    }    if ( LDAPTOOL_RESULT_IS_AN_ERROR( lderr )) {	(void)ldaptool_print_lderror( ld, msg, LDAPTOOL_CHECK4SSL_IF_APPROP );    }    if ( refs != NULL ) {	ldaptool_print_referrals( refs );	ldap_value_free( refs );    }    ber_free( ber, 1 );    return( lderr );}