]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
add -a and -n arguments for printing ticket addresses
authorMarc Horowitz <marc@mit.edu>
Sat, 22 Aug 1998 02:28:40 +0000 (02:28 +0000)
committerMarc Horowitz <marc@mit.edu>
Sat, 22 Aug 1998 02:28:40 +0000 (02:28 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/marc-3des@10865 dc483132-0cff-0310-8789-dd5450dbe970

src/clients/klist/klist.c

index 005c05760337b92f51450f78e4537487c9d1a41d..671316b2c8cc2ac992cfdc1aa3ba268da64b25b9 100644 (file)
 #include <string.h>
 #include <stdio.h>
 #include <time.h>
+#include <sys/socket.h>
+#include <netdb.h>
 
 extern int optind;
 extern char *optarg;
 int show_flags = 0, show_time = 0, status_only = 0, show_keys = 0;
-int show_etype = 0;
+int show_etype = 0, show_addresses = 0, no_resolve = 0;
 char *defname;
 char *progname;
 krb5_int32 now;
@@ -50,6 +52,7 @@ void show_credential KRB5_PROTOTYPE((char *,
 void do_ccache KRB5_PROTOTYPE((char *));
 void do_keytab KRB5_PROTOTYPE((char *));
 void printtime KRB5_PROTOTYPE((time_t));
+void one_addr KRB5_PROTOTYPE((krb5_address *));
 void fillit KRB5_PROTOTYPE((FILE *, int, int));
        
 #define DEFAULT 0
@@ -58,7 +61,7 @@ void fillit KRB5_PROTOTYPE((FILE *, int, int));
 
 void usage()
 {
-     fprintf(stderr, "Usage: %s [[-c] [-f] [-e] [-s]] [-k [-t] [-K]] [name]\n",
+     fprintf(stderr, "Usage: %s [[-c] [-f] [-e] [-s] [-a] [-n]] [-k [-t] [-K]] [name]\n",
             progname); 
      fprintf(stderr, "\t-c specifies credentials cache, -k specifies keytab");
      fprintf(stderr, ", -c is default\n");
@@ -66,6 +69,8 @@ void usage()
      fprintf(stderr, "\t\t-f shows credentials flags\n");
      fprintf(stderr, "\t\t-e shows the encryption type\n");
      fprintf(stderr, "\t\t-s sets exit status based on valid tgt existence\n");
+     fprintf(stderr, "\t\t-a displays the address list\n");
+     fprintf(stderr, "\t\t\t-n do not reverse-resolve\n");
      fprintf(stderr, "\toptions for keytabs:\n");
      fprintf(stderr, "\t\t-t shows keytab entry timestamps\n");
      fprintf(stderr, "\t\t-K shows keytab entry DES keys\n");
@@ -114,6 +119,12 @@ main(argc, argv)
        case 's':
            status_only = 1;
            break;
+       case 'n':
+           no_resolve = 1;
+           break;
+       case 'a':
+           show_addresses = 1;
+           break;
        case 'c':
            if (mode != DEFAULT) usage();
            mode = CCACHE;
@@ -498,10 +509,52 @@ show_credential(progname, kcontext, cred)
     /* if any additional info was printed, extra_field is non-zero */
     if (extra_field)
        putchar('\n');
+
+
+    if (show_addresses) {
+       if (!cred->addresses || !cred->addresses[0]) {
+           printf("\tAddresses: (none)\n");
+       } else {
+           int i;
+
+           printf("\tAddresses: ");
+           one_addr(cred->addresses[0]);
+
+           for (i=1; cred->addresses[i]; i++) {
+               printf(", ");
+               one_addr(cred->addresses[1]);
+           }
+
+           printf("\n");
+       }
+    }
+
     free(name);
     free(sname);
 }
 
+void one_addr(a)
+    krb5_address *a;
+{
+    struct hostent *h;
+
+    if ((a->addrtype == ADDRTYPE_INET) &&
+       (a->length == 4)) {
+       if (!no_resolve) {
+           h = gethostbyaddr(a->contents, 4, AF_INET);
+           if (h) {
+               printf("%s", h->h_name);
+           }
+       }
+       if (no_resolve || !h) {
+           printf("%d.%d.%d.%d", a->contents[0], a->contents[1],
+                  a->contents[2], a->contents[3]);
+       }
+    } else {
+       printf("unknown addr type %d", a->addrtype);
+    }
+}
+
 void
 fillit(f, num, c)
     FILE       *f;