* keylist.c (list_one): Don't show the keyring filename when in
[gnupg.git] / g10 / keylist.c
index c77ec2d..68d7257 100644 (file)
@@ -1,5 +1,6 @@
 /* keylist.c
- * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
+ *                                             Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -229,16 +230,20 @@ list_all( int secret )
             log_error ("keydb_get_keyblock failed: %s\n", g10_errstr(rc));
             goto leave;
         }
-        resname = keydb_get_resource_name (hd);
-       if (lastresname != resname ) {
-           int i;
-
-           printf("%s\n", resname );
-           for(i=strlen(resname); i; i-- )
-               putchar('-');
-           putchar('\n');
-            lastresname = resname;
-       }
+       if(!opt.with_colons)
+         {
+           resname = keydb_get_resource_name (hd);
+           if (lastresname != resname )
+             {
+               int i;
+
+               printf("%s\n", resname );
+               for(i=strlen(resname); i; i-- )
+                 putchar('-');
+               putchar('\n');
+               lastresname = resname;
+             }
+         }
         merge_keys_and_selfsig( keyblock );
        list_keyblock( keyblock, secret, opt.fingerprint,
                       opt.check_sigs?&stats:NULL);
@@ -264,7 +269,7 @@ list_one( STRLIST names, int secret )
     KBNODE keyblock = NULL;
     GETKEY_CTX ctx;
     const char *resname;
-    char *keyring_str = N_("Keyring");
+    char *keyring_str = _("Keyring");
     int i;
     struct sig_stats stats;
 
@@ -287,7 +292,7 @@ list_one( STRLIST names, int secret )
            return;
        }
        do {
-           if (opt.show_keyring) {
+           if (opt.show_keyring && !opt.with_colons) {
                resname = keydb_get_resource_name (get_ctx_handle(ctx));
                printf("%s: %s\n", keyring_str, resname);
                for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
@@ -307,7 +312,7 @@ list_one( STRLIST names, int secret )
            return;
        }
        do {
-           if (opt.show_keyring) {
+         if (opt.show_keyring && !opt.with_colons) {
                resname = keydb_get_resource_name (get_ctx_handle(ctx));
                printf("%s: %s\n", keyring_str, resname);
                for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
@@ -357,14 +362,18 @@ print_capabilities (PKT_public_key *pk, PKT_secret_key *sk, KBNODE keyblock)
        }
     }
 
-    if ( keyblock ) { /* figure our the usable capabilities */
+    if ( keyblock ) { /* figure out the usable capabilities */
         KBNODE k;
-        int enc=0, sign=0, cert=0;
+        int enc=0, sign=0, cert=0, disabled=0;
 
         for (k=keyblock; k; k = k->next ) {
             if ( k->pkt->pkttype == PKT_PUBLIC_KEY 
                  || k->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
                 pk = k->pkt->pkt.public_key;
+
+               if(pk->is_primary)
+                 disabled=pk_is_disabled(pk);
+
                 if ( pk->is_valid && !pk->is_revoked && !pk->has_expired ) {
                     if ( pk->pubkey_usage & PUBKEY_USAGE_ENC )
                         enc = 1;
@@ -398,17 +407,20 @@ print_capabilities (PKT_public_key *pk, PKT_secret_key *sk, KBNODE keyblock)
             putchar ('S');
         if (cert)
             putchar ('C');
+        if (disabled)
+            putchar ('D');
     }
+
     putchar(':');
 }
 
-static void dump_attribs(const PKT_user_id *uid,
-                        PKT_public_key *pk,PKT_secret_key *sk)
+void
+dump_attribs(const PKT_user_id *uid,PKT_public_key *pk,PKT_secret_key *sk)
 {
   int i;
 
   if(!attrib_fp)
-    BUG();
+    return;
 
   for(i=0;i<uid->numattribs;i++)
     {
@@ -484,8 +496,6 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
 
     for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
        if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
-           if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
-             dump_attribs(node->pkt->pkt.user_id,pk,sk);
             /* don't list revoked or expired UIDS unless we are in
              * verbose mode and signature listing has not been
              * requested */
@@ -494,6 +504,9 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
                  node->pkt->pkt.user_id->is_expired ))
                 continue; 
 
+           if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
+             dump_attribs(node->pkt->pkt.user_id,pk,sk);
+
            if( any ) 
                 printf("uid%*s", 29, "");
 
@@ -738,47 +751,46 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
 
     for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
        if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
+           PKT_user_id *uid=node->pkt->pkt.user_id;
            if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
              dump_attribs(node->pkt->pkt.user_id,pk,sk);
             /*
              * Fixme: We need a is_valid flag here too 
              */
            if( any ) {
-               char *str=node->pkt->pkt.user_id->attrib_data?"uat":"uid";
-                if ( node->pkt->pkt.user_id->is_revoked )
-                   printf("%s:r::::::::",str);
-                else if ( node->pkt->pkt.user_id->is_expired )
-                   printf("%s:e::::::::",str);
+               int i;
+               char *str=uid->attrib_data?"uat":"uid";
+                if ( uid->is_revoked )
+                   printf("%s:r::::",str);
+                else if ( uid->is_expired )
+                   printf("%s:e::::",str);
                else if ( opt.no_expensive_trust_checks ) {
-                   printf("%s:::::::::",str);
+                   printf("%s:::::",str);
                }
                 else {
-                   byte namehash[20];
                    int uid_validity;
 
-                   if( pk && !ulti_hack ) {
-                       if( node->pkt->pkt.user_id->attrib_data )
-                           rmd160_hash_buffer( namehash,
-                                          node->pkt->pkt.user_id->attrib_data,
-                                          node->pkt->pkt.user_id->attrib_len);
-                       else
-                           rmd160_hash_buffer( namehash,
-                                           node->pkt->pkt.user_id->name,
-                                           node->pkt->pkt.user_id->len  );
-                       uid_validity = get_validity_info( pk, namehash );
-                   }
+                   if( pk && !ulti_hack )
+                     uid_validity=get_validity_info (pk, uid);
                    else
                        uid_validity = 'u';
-                   printf("%s:%c::::::::",str,uid_validity);
+                   printf("%s:%c::::",str,uid_validity);
                 }
+
+               printf("%s:",colon_strtime(uid->created));
+               printf("%s:",colon_strtime(uid->expiredate));
+
+               namehash_from_uid(uid);
+
+               for(i=0; i < 20; i++ )
+                 printf("%02X",uid->namehash[i]);
+
+               printf("::");
            }
-           if(node->pkt->pkt.user_id->attrib_data)
-             printf("%u %lu",
-                    node->pkt->pkt.user_id->numattribs,
-                    node->pkt->pkt.user_id->attrib_len);
+           if(uid->attrib_data)
+             printf("%u %lu",uid->numattribs,uid->attrib_len);
             else
-             print_string( stdout,  node->pkt->pkt.user_id->name,
-                           node->pkt->pkt.user_id->len, ':' );
+             print_string(stdout,uid->name,uid->len, ':' );
             putchar(':');
            if (any)
                 putchar('\n');
@@ -925,10 +937,20 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
             putchar(':');
             if( sigrc != ' ' )
                 putchar(sigrc);
-            printf("::%d:%08lX%08lX:%s:%s:::", sig->pubkey_algo,
-                                                (ulong)sig->keyid[0],
-                          (ulong)sig->keyid[1], colon_datestr_from_sig(sig),
-                          colon_expirestr_from_sig(sig));
+            printf("::%d:%08lX%08lX:%s:%s:", sig->pubkey_algo,
+                  (ulong)sig->keyid[0], (ulong)sig->keyid[1],
+                  colon_datestr_from_sig(sig),
+                  colon_expirestr_from_sig(sig));
+
+           if(sig->trust_depth || sig->trust_value)
+             printf("%d %d",sig->trust_depth,sig->trust_value);
+           printf(":");
+
+           if(sig->trust_regexp)
+             print_string(stdout,sig->trust_regexp,
+                          strlen(sig->trust_regexp),':');
+           printf(":");
+
            if( sigrc == '%' )
                printf("[%s] ", g10_errstr(rc) );
            else if( sigrc == '?' )
@@ -955,7 +977,7 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
  * Reorder the keyblock so that the primary user ID (and not attribute
  * packet) comes first.  Fixme: Replace this by a generic sort
  * function.  */
-static void
+void
 reorder_keyblock (KBNODE keyblock)
 {
     KBNODE primary = NULL, primary0 = NULL, primary2 = NULL;