New interface to find out whether a key has expired. Also, a bug fix
authormdw <mdw>
Fri, 22 Jun 2001 19:39:12 +0000 (19:39 +0000)
committermdw <mdw>
Fri, 22 Jun 2001 19:39:12 +0000 (19:39 +0000)
to @key_bytag@ so that it finds expired keys correctly.

key-misc.c

index 12a5f21..afd0a4b 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: key-misc.c,v 1.2 2000/02/12 18:21:02 mdw Exp $
+ * $Id: key-misc.c,v 1.3 2001/06/22 19:39:12 mdw Exp $
  *
  * Simple key management
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: key-misc.c,v $
+ * Revision 1.3  2001/06/22 19:39:12  mdw
+ * New interface to find out whether a key has expired.  Also, a bug fix
+ * to @key_bytag@ so that it finds expired keys correctly.
+ *
  * Revision 1.2  2000/02/12 18:21:02  mdw
  * Overhaul of key management (again).
  *
@@ -174,7 +178,7 @@ key *key_bytag(key_file *f, const char *tag)
   uint32 id;
   key_ref *kr = sym_find(&f->bytag, tag, -1, 0, 0);
 
-  if (kr && !(KEY_EXPIRED(t, kr->k->exp) && KEY_EXPIRED(t, kr->k->exp)))
+  if (kr && !(KEY_EXPIRED(t, kr->k->exp) && KEY_EXPIRED(t, kr->k->del)))
     return (kr->k);
   id = strtoul(tag, &p, 16);
   if (!*p)
@@ -294,6 +298,19 @@ int key_delete(key_file *f, key *k)
   return (0);
 }
 
+/* --- @key_expired@ --- *
+ *
+ * Arguments:  @key *k@ = pointer to key block
+ *
+ * Returns:    Zero if the key is OK, nonzero if it's expired.
+ */
+
+int key_expired(key *k)
+{
+  time_t now = time(0);
+  return (KEY_EXPIRED(now, k->exp) || KEY_EXPIRED(now, k->del));
+}
+
 /* --- @key_expire@ --- *
  *
  * Arguments:  @key_file *f@ = pointer to file block