From 1c8fadc0af515500e458b02812c1721f5121c79f Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sun, 10 Mar 2002 23:13:10 +0000 Subject: [PATCH] handle LR_PW_EXPTIME and LR_ACCT_EXPTIME in the same way git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10870 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/init_creds_pw.c | 57 ++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/lib/krb5/init_creds_pw.c b/lib/krb5/init_creds_pw.c index 2d4319a21..0288a6a34 100644 --- a/lib/krb5/init_creds_pw.c +++ b/lib/krb5/init_creds_pw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -124,6 +124,24 @@ out: return ret; } +/* + * Print a message (str) to the user about the expiration in `lr' + */ + +static void +report_expiration (krb5_context context, + krb5_prompter_fct prompter, + krb5_data *data, + const char *str, + time_t time) +{ + char *p; + + asprintf (&p, "%s%s", str, ctime(&time)); + (*prompter) (context, data, NULL, p, 0, NULL); + free (p); +} + /* * Parse the last_req data and show it to the user if it's interesting */ @@ -139,6 +157,7 @@ print_expire (krb5_context context, LastReq *lr = &rep->enc_part.last_req; krb5_timestamp sec; time_t t; + krb5_boolean reported = FALSE; krb5_timeofday (context, &sec); @@ -148,26 +167,30 @@ print_expire (krb5_context context, 7 * 24 * 60 * 60); for (i = 0; i < lr->len; ++i) { - if (abs(lr->val[i].lr_type) == LR_PW_EXPTIME - && lr->val[i].lr_value <= t) { - char *p; - time_t tmp = lr->val[i].lr_value; - - asprintf (&p, "Your password will expire at %s", ctime(&tmp)); - (*prompter) (context, data, NULL, p, 0, NULL); - free (p); - return; + if (lr->val[i].lr_value <= t) { + switch (abs(lr->val[i].lr_type)) { + case LR_PW_EXPTIME : + report_expiration(context, prompter, data, + "Your password will expire at ", + lr->val[i].lr_value); + reported = TRUE; + break; + case LR_ACCT_EXPTIME : + report_expiration(context, prompter, data, + "Your account will expire at ", + lr->val[i].lr_value); + reported = TRUE; + break; + } } } - if (rep->enc_part.key_expiration + if (!reported + && rep->enc_part.key_expiration && *rep->enc_part.key_expiration <= t) { - char *p; - time_t t = *rep->enc_part.key_expiration; - - asprintf (&p, "Your password/account will expire at %s", ctime(&t)); - (*prompter) (context, data, NULL, p, 0, NULL); - free (p); + report_expiration(context, prompter, data, + "Your password/account will expire at ", + *rep->enc_part.key_expiration); } }