3 * Various handy server-only utilities
5 * (c) 2001 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Trivial IP Encryption (TrIPE).
12 * TrIPE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * TrIPE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
31 /*----- Global variables --------------------------------------------------*/
33 octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ], buf_u[PKBUFSZ];
35 /*----- Main code ---------------------------------------------------------*/
37 /* --- @timestr@ --- *
39 * Arguments: @time_t t@ = a time to convert
41 * Returns: A pointer to a textual representation of the time.
43 * Use: Converts a time to a textual representation. Corrupts
47 const char *timestr(time_t t)
53 strftime((char *)buf_u, sizeof(buf_u), "%Y-%m-%dT%H:%M:%S", tm);
54 return ((const char *)buf_u);
57 /* --- @mystrieq@ --- *
59 * Arguments: @const char *x, *y@ = two strings
61 * Returns: True if @x@ and @y are equal, up to case.
64 int mystrieq(const char *x, const char *y)
67 if (!*x && !*y) return (1);
68 if (tolower((unsigned char)*x) != tolower((unsigned char)*y))
74 /* --- @seq_reset@ --- *
76 * Arguments: @seqwin *s@ = sequence-checking window
80 * Use: Resets a sequence number window.
83 void seq_reset(seqwin *s) { s->seq = 0; s->win = 0; }
85 /* --- @seq_check@ --- *
87 * Arguments: @seqwin *s@ = sequence-checking window
88 * @uint32 q@ = sequence number to check
89 * @const char *service@ = service to report message from
91 * Returns: Zero on success, nonzero if the sequence number was bad.
93 * Use: Checks a sequence number against the window, updating things
97 int seq_check(seqwin *s, uint32 q, const char *service)
103 a_warn(service, "replay", "old-sequence", A_END);
106 if (q >= s->seq + SEQ_WINSZ) {
107 n = q - (s->seq + SEQ_WINSZ - 1);
114 qbit = 1 << (q - s->seq);
116 a_warn(service, "replay", "duplicated-sequence", A_END);
123 /*----- That's all, folks -------------------------------------------------*/