]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#8701 Add account usability to ldapsearch
authorOndřej Kuzník <ondra@mistotebe.net>
Wed, 17 Jun 2020 09:21:16 +0000 (10:21 +0100)
committerOndřej Kuzník <ondra@mistotebe.net>
Tue, 7 Jul 2020 15:43:37 +0000 (16:43 +0100)
clients/tools/common.c
clients/tools/ldapsearch.c

index 8d7de5d202429162b7e5fde4d291e040672a8795..18a7c238faabd1be7827559cca2a7ee2e14831b9 100644 (file)
@@ -159,6 +159,9 @@ static int print_syncdone( LDAP *ld, LDAPControl *ctrl );
 #ifdef LDAP_CONTROL_X_DIRSYNC
 static int print_dirsync( LDAP *ld, LDAPControl *ctrl );
 #endif
+#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
+static int print_account_usability( LDAP *ld, LDAPControl *ctrl );
+#endif
 
 static struct tool_ctrls_t {
        const char      *oid;
@@ -188,6 +191,9 @@ static struct tool_ctrls_t {
        { LDAP_CONTROL_SYNC_DONE,                       TOOL_SEARCH,    print_syncdone },
 #ifdef LDAP_CONTROL_X_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
        { NULL,                                         0,              NULL }
 };
@@ -2568,6 +2574,77 @@ print_ppolicy( LDAP *ld, LDAPControl *ctrl )
 }
 #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(
        LDAP            *ld,
        LDAPControl     **ctrls )
index a89c8b9dfb5cf8ac7e82aa44a7aed13754a4f568..b8a1f661db1230b5782d1c7176089a998d4caa63 100644 (file)
@@ -125,6 +125,9 @@ usage( void )
        fprintf( stderr, _("  -b basedn  base dn for search\n"));
        fprintf( stderr, _("  -c         continuous operation mode (do not stop on errors)\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, _("             !dontUseCopy                (Don't Use Copy)\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 char    *vrFilter = NULL;
 
+#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
+static int accountUsability = 0;
+#endif
+
 #ifdef LDAP_CONTROL_DONTUSECOPY
 static int dontUseCopy = 0;
 #endif
@@ -810,6 +817,22 @@ handle_private_option( int i )
                        serverNotif = 1 + crit;
 #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 ) ) {
                        if ( c != NULL ) {
                                int i;
@@ -1103,6 +1126,9 @@ getNextPage:
        save_nctrls = nctrls;
        i = nctrls;
        if ( nctrls > 0
+#ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
+               || accountUsability
+#endif
 #ifdef LDAP_CONTROL_DONTUSECOPY
                || dontUseCopy
 #endif
@@ -1131,6 +1157,20 @@ getNextPage:
                || 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
                if ( dontUseCopy ) {
                        if ( ctrl_add() ) {