diff options
author | pst <pst@FreeBSD.org> | 1997-02-06 17:52:29 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1997-02-06 17:52:29 +0000 |
commit | 2dfcbf193123fd16b26454eeffa4bbd014e52c53 (patch) | |
tree | ec9d150c9da4390c2d223a04ac002523cbfd7f36 /contrib/opie/libopie/newseed.c | |
download | FreeBSD-src-2dfcbf193123fd16b26454eeffa4bbd014e52c53.zip FreeBSD-src-2dfcbf193123fd16b26454eeffa4bbd014e52c53.tar.gz |
Initial import of OPIE v2.3 from
ftp://ftp.nrl.navy.mil/pub/security/opie/
Diffstat (limited to 'contrib/opie/libopie/newseed.c')
-rw-r--r-- | contrib/opie/libopie/newseed.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/contrib/opie/libopie/newseed.c b/contrib/opie/libopie/newseed.c new file mode 100644 index 0000000..af4cac7 --- /dev/null +++ b/contrib/opie/libopie/newseed.c @@ -0,0 +1,99 @@ +/* newseed.c: The opienewseed() library function. + +%%% copyright-cmetz +This software is Copyright 1996 by Craig Metz, All Rights Reserved. +The Inner Net License Version 2 applies to this software. +You should have received a copy of the license with this software. If +you didn't get a copy, you may request one from <license@inner.net>. + + History: + + Created by cmetz for OPIE 2.22. +*/ + +#include "opie_cfg.h" +#if HAVE_STRING_H +#include <string.h> +#endif /* HAVE_STRING_H */ +#include <ctype.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#if HAVE_SYS_UTSNAME_H +#include <sys/utsname.h> +#endif /* HAVE_SYS_UTSNAME_H */ +#include <errno.h> +#include "opie.h" + +int opienewseed FUNCTION((seed), char *seed) +{ + if (!seed) + return -1; + + if (seed[0]) { + int i; + + if ((i = strlen(seed)) >= OPIE_SEED_MIN) { + long j; + char *c; + + if (i > OPIE_SEED_MAX) + i = OPIE_SEED_MAX; + + c = seed + i - 1; + + while(c != seed) { + if (!isdigit(*c)) + break; + c--; + } + + c++; + + if (j = strtol(c, (char **)0, 10)) { + char buf[OPIE_SEED_MAX]; + + *c = 0; + strcpy(buf, seed); + + if (errno == ERANGE) { + j = 1; + } else { + int k = 1, l = OPIE_SEED_MAX - strlen(buf); + while(l--) k *= 10; + + if (++j >= k) + j = 1; + } + + sprintf(seed, "%s%04d", buf, j); + return 0; + } + } + } + + { + { + time_t now; + time(&now); + srand(now); + } + + { + struct utsname utsname; + + if (uname(&utsname) < 0) { +#if 0 + perror("uname"); +#endif /* 0 */ + utsname.nodename[0] = 'k'; + utsname.nodename[1] = 'e'; + } + utsname.nodename[2] = 0; + + sprintf(seed, "%s%04d", utsname.nodename, (rand() % 9999) + 1); + return 0; + } + } +} + |