ITS#8701 Add account usability to ldapsearch

This commit is contained in:
Ondřej Kuzník 2020-06-17 10:21:16 +01:00
parent 1129df533d
commit 63440f0379
2 changed files with 117 additions and 0 deletions

View File

@ -159,6 +159,9 @@ static int print_syncdone( LDAP *ld, LDAPControl *ctrl );
#ifdef LDAP_CONTROL_X_DIRSYNC #ifdef LDAP_CONTROL_X_DIRSYNC
static int print_dirsync( LDAP *ld, LDAPControl *ctrl ); static int print_dirsync( LDAP *ld, LDAPControl *ctrl );
#endif #endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int print_account_usability( LDAP *ld, LDAPControl *ctrl );
#endif
static struct tool_ctrls_t { static struct tool_ctrls_t {
const char *oid; const char *oid;
@ -188,6 +191,9 @@ static struct tool_ctrls_t {
{ LDAP_CONTROL_SYNC_DONE, TOOL_SEARCH, print_syncdone }, { LDAP_CONTROL_SYNC_DONE, TOOL_SEARCH, print_syncdone },
#ifdef LDAP_CONTROL_X_DIRSYNC #ifdef LDAP_CONTROL_X_DIRSYNC
{ LDAP_CONTROL_X_DIRSYNC, TOOL_SEARCH, print_dirsync }, { LDAP_CONTROL_X_DIRSYNC, TOOL_SEARCH, print_dirsync },
#endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
{ LDAP_CONTROL_X_ACCOUNT_USABILITY, TOOL_SEARCH, print_account_usability },
#endif #endif
{ NULL, 0, NULL } { NULL, 0, NULL }
}; };
@ -2568,6 +2574,77 @@ print_ppolicy( LDAP *ld, LDAPControl *ctrl )
} }
#endif #endif
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int
print_account_usability( LDAP *ld, LDAPControl *ctrl )
{
LDAPAccountUsability usability;
ber_int_t available = 0;
int rc;
rc = ldap_parse_accountusability_control( ld, ctrl, &available, &usability );
if ( rc == LDAP_SUCCESS ) {
char buf[ BUFSIZ ], *ptr = buf;
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"%savailable", available ? "" : "not " );
if ( available ) {
if ( usability.seconds_remaining == -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" and does not expire" );
} else {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" expire=%d", usability.seconds_remaining );
}
} else {
int added = 0;
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
" (" /* ')' */ );
if ( usability.more_info.inactive ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"inactive " );
added++;
}
if ( usability.more_info.reset ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"reset " );
added++;
}
if ( usability.more_info.expired ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"expired " );
added++;
}
if ( added ) {
ptr[-1] = ')';
*ptr++ = ' ';
} else {
*(--ptr) = '\0';
}
if ( usability.more_info.remaining_grace != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"grace=%d ", usability.more_info.remaining_grace );
}
if ( usability.more_info.seconds_before_unlock != -1 ) {
ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
"seconds_before_unlock=%d ", usability.more_info.seconds_before_unlock );
}
*(--ptr) = '\0';
}
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
ldif ? "accountUsability: " : "accountUsability", buf, ptr - buf );
}
return rc;
}
#endif
void tool_print_ctrls( void tool_print_ctrls(
LDAP *ld, LDAP *ld,
LDAPControl **ctrls ) LDAPControl **ctrls )

View File

@ -125,6 +125,9 @@ usage( void )
fprintf( stderr, _(" -b basedn base dn for search\n")); fprintf( stderr, _(" -b basedn base dn for search\n"));
fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n")); fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n")); fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
fprintf( stderr, _(" [!]accountUsability (NetScape Account usability)\n"));
#endif
fprintf( stderr, _(" [!]domainScope (domain scope)\n")); fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n")); fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
fprintf( stderr, _(" [!]mv=<filter> (RFC 3876 matched values filter)\n")); fprintf( stderr, _(" [!]mv=<filter> (RFC 3876 matched values filter)\n"));
@ -221,6 +224,10 @@ static int includeufn, vals2tmp = 0;
static int subentries = 0, valuesReturnFilter = 0; static int subentries = 0, valuesReturnFilter = 0;
static char *vrFilter = NULL; static char *vrFilter = NULL;
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
static int accountUsability = 0;
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY #ifdef LDAP_CONTROL_DONTUSECOPY
static int dontUseCopy = 0; static int dontUseCopy = 0;
#endif #endif
@ -810,6 +817,22 @@ handle_private_option( int i )
serverNotif = 1 + crit; serverNotif = 1 + crit;
#endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */ #endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
} else if ( strcasecmp( control, "accountUsability" ) == 0 ) {
if( accountUsability ) {
fprintf( stderr,
_("accountUsability control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
fprintf( stderr,
_("accountUsability: no control value expected\n") );
usage();
}
accountUsability = 1 + crit;
#endif /* LDAP_CONTROL_X_ACCOUNT_USABILITY */
} else if ( tool_is_oid( control ) ) { } else if ( tool_is_oid( control ) ) {
if ( c != NULL ) { if ( c != NULL ) {
int i; int i;
@ -1103,6 +1126,9 @@ getNextPage:
save_nctrls = nctrls; save_nctrls = nctrls;
i = nctrls; i = nctrls;
if ( nctrls > 0 if ( nctrls > 0
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
|| accountUsability
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY #ifdef LDAP_CONTROL_DONTUSECOPY
|| dontUseCopy || dontUseCopy
#endif #endif
@ -1131,6 +1157,20 @@ getNextPage:
|| vlv ) || vlv )
{ {
#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
if ( accountUsability ) {
if ( ctrl_add() ) {
tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_ACCOUNT_USABILITY;
c[i].ldctl_value.bv_val = NULL;
c[i].ldctl_value.bv_len = 0;
c[i].ldctl_iscritical = accountUsability == 2;
i++;
}
#endif
#ifdef LDAP_CONTROL_DONTUSECOPY #ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) { if ( dontUseCopy ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {