From 7799fc532f62863c8cb41d89b27d57bc96ee7123 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Fri, 27 Jun 1997 13:32:55 +0000 Subject: [PATCH] List lock-time with `-l'. New option `-o' to open an locked entry. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1930 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/otp/otp.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/appl/otp/otp.c b/appl/otp/otp.c index 2f17261f2..7d5f7ddd9 100644 --- a/appl/otp/otp.c +++ b/appl/otp/otp.c @@ -42,7 +42,7 @@ RCSID("$Id$"); #define USAGE_STRING \ "Usage: %s [-r] [-f alg] [-u user] num seed\n" \ - " or -[d|l] [-u user]\n" \ + " or -[d|l|o] [-u user]\n" \ " or -h\n" #define HELP_STRING \ @@ -52,6 +52,7 @@ RCSID("$Id$"); "\t-d: delete OTP\n" \ "\t-l: list OTP status\n" \ "\t-h: help!\n" \ + "\t-o: open up the locked OTP\n" \ "\t-u user: specify a user, default is the current user.\n" \ "\t only root can use this option.\n" \ "\t-f alg: encryption algorithm (md4|md5|sha), default is md5.\n" \ @@ -243,11 +244,40 @@ print_otp_entry_for_name (void *db, char *user) ctx.user = user; if (!otp_simple_get(db, &ctx)) { - fprintf(stdout, "%s\totp-%s %d %s\n", + fprintf(stdout, + "%s\totp-%s %d", ctx.user, ctx.alg->name, ctx.n, ctx.seed); + if (ctx.lock_time) + fprintf(stdout, + "\tlocked since %s", + ctime(&ctx.lock_time)); + else + fprintf(stdout, "\n"); } } +static int +open_otp (int argc, char **argv, char *user) +{ + void *db; + OtpContext ctx; + int ret; + + if (argc != 0) + usage (); + + db = otp_db_open (); + if (db == NULL) + errx (1, "otp_db_open failed"); + + ctx.user = user; + ret = otp_simple_get (db, &ctx); + if (ret == 0) + ret = otp_put (db, &ctx); + otp_db_close (db); + return ret; +} + /* * Print otp entries for one or all users */ @@ -280,14 +310,14 @@ int main (int argc, char **argv) { int c; - int renewp = 0, listp = 0, deletep = 0, defaultp = 0; + int renewp = 0, listp = 0, deletep = 0, defaultp = 0, openp = 0; int uid = getuid(); OtpAlgorithm *alg = otp_find_alg (OTP_ALG_DEFAULT); char *user = NULL; set_progname (argv[0]); - while ((c = getopt (argc, argv, "hrf:u:ld")) != EOF) + while ((c = getopt (argc, argv, "hrf:u:ldo")) != EOF) switch (c) { case 'h' : help(); @@ -300,6 +330,9 @@ main (int argc, char **argv) errx (1, "Only root can delete OTPs"); deletep = 1; break; + case 'o': + openp = 1; + break; case 'r' : renewp = 1; break; @@ -320,10 +353,10 @@ main (int argc, char **argv) argc -= optind; argv += optind; - if (!(listp || deletep || renewp)) + if (!(listp || deletep || renewp || openp)) defaultp = 1; - if ( listp + deletep + renewp + defaultp != 1) + if ( listp + deletep + renewp + defaultp + openp != 1) usage(); /* one of -d or -l or -r or none */ if (listp) @@ -357,6 +390,8 @@ main (int argc, char **argv) return delete_otp (argc, argv, user); else if (renewp) return renew (argc, argv, alg, user); + else if (openp) + return open_otp (argc, argv, user); else return set (argc, argv, alg, user); }