chiark / gitweb /
server/keyset.c, server/keymgmt.c: Variable data limits.
[tripe] / server / servutil.c
index 92a5f775f03b456a0068317508db70294bedcb77..dbca451d4ca920b9447359a3676aef6810f2cf2e 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Various handy server-only utilities
  *
  * (c) 2001 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * TrIPE is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with TrIPE; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -32,7 +30,7 @@
 
 /*----- Global variables --------------------------------------------------*/
 
-octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
+octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ], buf_u[PKBUFSZ];
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -43,14 +41,14 @@ octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
  * Returns:    A pointer to the integer's textual representation.
  *
  * Use:                Converts a multiprecision integer to a string.  Corrupts
- *             @buf_t@.
+ *             @buf_u@.
  */
 
 const char *mpstr(mp *m)
 {
-  if (mp_writestring(m, (char *)buf_t, sizeof(buf_t), 10))
+  if (mp_writestring(m, (char *)buf_u, sizeof(buf_u), 10))
     return ("<failed>");
-  return ((const char *)buf_t);
+  return ((const char *)buf_u);
 }
 
 /* --- @gestr@ --- *
@@ -61,14 +59,14 @@ const char *mpstr(mp *m)
  * Returns:    A pointer to the element's textual representation.
  *
  * Use:                Converts a group element to a string.  Corrupts
- *             @buf_t@.
+ *             @buf_u@.
  */
 
 const char *gestr(group *g, ge *x)
 {
-  if (group_writestring(g, x, (char *)buf_t, sizeof(buf_t)))
+  if (group_writestring(g, x, (char *)buf_u, sizeof(buf_u)))
     return ("<failed>");
-  return ((const char *)buf_t);
+  return ((const char *)buf_u);
 }
 
 /* --- @timestr@ --- *
@@ -78,7 +76,7 @@ const char *gestr(group *g, ge *x)
  * Returns:    A pointer to a textual representation of the time.
  *
  * Use:                Converts a time to a textual representation.  Corrupts
- *             @buf_t@.
+ *             @buf_u@.
  */
 
 const char *timestr(time_t t)
@@ -87,8 +85,25 @@ const char *timestr(time_t t)
   if (!t)
     return ("NEVER");
   tm = localtime(&t);
-  strftime((char *)buf_t, sizeof(buf_t), "%Y-%m-%dT%H:%M:%S", tm);
-  return ((const char *)buf_t);
+  strftime((char *)buf_u, sizeof(buf_u), "%Y-%m-%dT%H:%M:%S", tm);
+  return ((const char *)buf_u);
+}
+
+/* --- @mystrieq@ --- *
+ *
+ * Arguments:  @const char *x, *y@ = two strings
+ *
+ * Returns:    True if @x@ and @y are equal, up to case.
+ */
+
+int mystrieq(const char *x, const char *y)
+{
+  for (;;) {
+    if (!*x && !*y) return (1);
+    if (tolower((unsigned char)*x) != tolower((unsigned char)*y))
+      return (0);
+    x++; y++;
+  }
 }
 
 /* --- @seq_reset@ --- *