summaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorJohan Danielsson <joda@pdc.kth.se>2004-09-23 13:26:53 +0000
committerJohan Danielsson <joda@pdc.kth.se>2004-09-23 13:26:53 +0000
commit0323ce1aae5571e374f8246ad284b846082be325 (patch)
tree258b01fd47e30e0d5de87cb5166f80344f6acc49 /admin
parent6765dd6fbe1820a0e5fb94a349077c2e958f77fa (diff)
use rtbl
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14256 ec53bebd-3082-4978-b11e-865c3cabbd6b
Diffstat (limited to 'admin')
-rw-r--r--admin/list.c120
1 files changed, 39 insertions, 81 deletions
diff --git a/admin/list.c b/admin/list.c
index 503033ef0..c93fb4aea 100644
--- a/admin/list.c
+++ b/admin/list.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -32,6 +32,7 @@
*/
#include "ktutil_locl.h"
+#include <rtbl.h>
RCSID("$Id$");
@@ -47,15 +48,6 @@ static struct getargs args[] = {
static int num_args = sizeof(args) / sizeof(args[0]);
-struct key_info {
- char *version;
- char *etype;
- char *principal;
- char *timestamp;
- char *key;
- struct key_info *next;
-};
-
static int
do_list(const char *keytab_string)
{
@@ -63,13 +55,6 @@ do_list(const char *keytab_string)
krb5_keytab keytab;
krb5_keytab_entry entry;
krb5_kt_cursor cursor;
- struct key_info *ki, **kie = &ki, *kp;
-
- int max_version = sizeof("Vno") - 1;
- int max_etype = sizeof("Type") - 1;
- int max_principal = sizeof("Principal") - 1;
- int max_timestamp = sizeof("Date") - 1;
- int max_key = sizeof("Key") - 1;
/* XXX specialcase the ANY type */
if(strncasecmp(keytab_string, "ANY:", 4) == 0) {
@@ -100,84 +85,57 @@ do_list(const char *keytab_string)
printf ("%s:\n\n", keytab_string);
+ rtbl_t table;
+ table = rtbl_create();
+ rtbl_add_column_by_id(table, 0, "Vno", RTBL_ALIGN_RIGHT);
+ rtbl_add_column_by_id(table, 1, "Type", 0);
+ rtbl_add_column_by_id(table, 2, "Principal", 0);
+ if (list_timestamp)
+ rtbl_add_column_by_id(table, 3, "Date", 0);
+ if(list_keys)
+ rtbl_add_column_by_id(table, 4, "Key", 0);
+ rtbl_set_separator(table, " ");
+
while((ret = krb5_kt_next_entry(context, keytab, &entry, &cursor)) == 0){
-#define CHECK_MAX(F) if(max_##F < strlen(kp->F)) max_##F = strlen(kp->F)
-
- kp = malloc(sizeof(*kp));
- if (kp == NULL) {
- krb5_kt_free_entry(context, &entry);
- krb5_kt_end_seq_get(context, keytab, &cursor);
- krb5_warn(context, ret, "malloc failed");
- goto out;
- }
+ char buf[1024], *s;
+
+ snprintf(buf, sizeof(buf), "%d", entry.vno);
+ rtbl_add_column_entry_by_id(table, 0, buf);
- asprintf(&kp->version, "%d", entry.vno);
- CHECK_MAX(version);
ret = krb5_enctype_to_string(context,
- entry.keyblock.keytype, &kp->etype);
- if (ret != 0)
- asprintf(&kp->etype, "unknown (%d)", entry.keyblock.keytype);
- CHECK_MAX(etype);
- krb5_unparse_name(context, entry.principal, &kp->principal);
- CHECK_MAX(principal);
- if (list_timestamp) {
- char tstamp[256];
+ entry.keyblock.keytype, &s);
+ if (ret != 0) {
+ snprintf(buf, sizeof(buf), "unknown (%d)", entry.keyblock.keytype);
+ rtbl_add_column_entry_by_id(table, 1, buf);
+ } else {
+ rtbl_add_column_entry_by_id(table, 1, s);
+ free(s);
+ }
- krb5_format_time(context, entry.timestamp,
- tstamp, sizeof(tstamp), FALSE);
+ krb5_unparse_name_fixed(context, entry.principal, buf, sizeof(buf));
+ rtbl_add_column_entry_by_id(table, 2, buf);
- kp->timestamp = strdup(tstamp);
- CHECK_MAX(timestamp);
+ if (list_timestamp) {
+ krb5_format_time(context, entry.timestamp, buf,
+ sizeof(buf), FALSE);
+ rtbl_add_column_entry_by_id(table, 3, buf);
}
if(list_keys) {
int i;
- kp->key = malloc(2 * entry.keyblock.keyvalue.length + 1);
+ s = malloc(2 * entry.keyblock.keyvalue.length + 1);
for(i = 0; i < entry.keyblock.keyvalue.length; i++)
- snprintf(kp->key + 2 * i, 3, "%02x",
+ snprintf(s + 2 * i, 3, "%02x",
((unsigned char*)entry.keyblock.keyvalue.data)[i]);
- CHECK_MAX(key);
+ rtbl_add_column_entry_by_id(table, 4, s);
+ free(s);
}
- *kie = kp;
- kie = &kp->next;
krb5_kt_free_entry(context, &entry);
}
- *kie = NULL; /* termiate list */
ret = krb5_kt_end_seq_get(context, keytab, &cursor);
+ rtbl_format(table, stdout);
+ rtbl_destroy(table);
- printf("%-*s %-*s %-*s", max_version, "Vno",
- max_etype, "Type",
- max_principal, "Principal");
- if(list_timestamp)
- printf(" %-*s", max_timestamp, "Date");
- if(list_keys)
- printf(" %s", "Key");
- printf("\n");
-
- for(kp = ki; kp; ) {
- printf("%*s %-*s %-*s", max_version, kp->version,
- max_etype, kp->etype,
- max_principal, kp->principal);
- if(list_timestamp)
- printf(" %-*s", max_timestamp, kp->timestamp);
- if(list_keys)
- printf(" %s", kp->key);
- printf("\n");
-
- /* free entries */
- free(kp->version);
- free(kp->etype);
- free(kp->principal);
- if(list_timestamp)
- free(kp->timestamp);
- if(list_keys) {
- memset(kp->key, 0, strlen(kp->key));
- free(kp->key);
- }
- ki = kp;
- kp = kp->next;
- free(ki);
- }
-out:
+ out:
krb5_kt_close(context, keytab);
return 0;
}
@@ -191,7 +149,7 @@ kt_list(int argc, char **argv)
if(verbose_flag)
list_timestamp = 1;
-
+
if(getarg(args, num_args, argc, argv, &optind)){
arg_printusage(args, num_args, "ktutil list", "");
return 1;