summaryrefslogtreecommitdiffstats
path: root/contrib/opie/libopie
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/opie/libopie')
-rw-r--r--contrib/opie/libopie/challenge.c13
-rw-r--r--contrib/opie/libopie/generator.c366
-rw-r--r--contrib/opie/libopie/hash.c62
-rw-r--r--contrib/opie/libopie/hashlen.c79
-rw-r--r--contrib/opie/libopie/insecure.c33
-rw-r--r--contrib/opie/libopie/lock.c19
-rw-r--r--contrib/opie/libopie/newseed.c111
7 files changed, 205 insertions, 478 deletions
diff --git a/contrib/opie/libopie/challenge.c b/contrib/opie/libopie/challenge.c
index 149403d..b931714 100644
--- a/contrib/opie/libopie/challenge.c
+++ b/contrib/opie/libopie/challenge.c
@@ -1,7 +1,7 @@
/* challenge.c: The opiechallenge() library function.
%%% portions-copyright-cmetz-96
-Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
+Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
Reserved. The Inner Net License Version 2 applies to these portions of
the software.
You should have received a copy of the license with this software. If
@@ -20,6 +20,9 @@ License Agreement applies to this software.
syslog. Add sha plumbing.
Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
Created at NRL for OPIE 2.2 from opiesubr2.c
+
+$FreeBSD$
+
*/
#include "opie_cfg.h"
#include <stdio.h>
@@ -52,8 +55,6 @@ int opiechallenge FUNCTION((mp, name, ss), struct opie *mp AND char *name AND ch
{
int rval = -1;
- memset(mp, 0, sizeof(*mp));
-
rval = opielookup(mp, name);
#if DEBUG
if (rval) syslog(LOG_DEBUG, "opiechallenge: opielookup(mp, name=%s) returned %d", name, rval);
@@ -66,11 +67,11 @@ int opiechallenge FUNCTION((mp, name, ss), struct opie *mp AND char *name AND ch
#endif /* DEBUG */
}
- if (rval ||
- (snprintf(ss, OPIE_CHALLENGE_MAX, "otp-%s %d %s ext", algids[MDX], mp->opie_n - 1, mp->opie_seed) >= OPIE_CHALLENGE_MAX)) {
+ if (rval) {
opierandomchallenge(ss);
memset(mp, 0, sizeof(*mp));
- }
+ } else
+ sprintf(ss, "otp-%s %d %s ext", algids[MDX], mp->opie_n - 1, mp->opie_seed);
return rval;
}
diff --git a/contrib/opie/libopie/generator.c b/contrib/opie/libopie/generator.c
index 24c6a73..eef7cac 100644
--- a/contrib/opie/libopie/generator.c
+++ b/contrib/opie/libopie/generator.c
@@ -1,7 +1,7 @@
/* generator.c: The opiegenerator() library function.
%%% portions-copyright-cmetz-96
-Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
+Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
Reserved. The Inner Net License Version 2 applies to these portions of
the software.
You should have received a copy of the license with this software. If
@@ -9,9 +9,6 @@ you didn't get a copy, you may request one from <license@inner.net>.
History:
- Modified by cmetz for OPIE 2.4. Added opieauto code based on
- previously released test code. Renamed buffer to challenge.
- Use struct opie_otpkey for keys.
Modified by cmetz for OPIE 2.32. If secret=NULL, always return
as if opieauto returned "get the secret". Renamed
_opieparsechallenge() to __opieparsechallenge(). Check
@@ -28,368 +25,81 @@ you didn't get a copy, you may request one from <license@inner.net>.
Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
Bug fixes.
Created at NRL for OPIE 2.2.
+
+$FreeBSD$
*/
#include "opie_cfg.h"
#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
-#if OPIEAUTO
-#include <errno.h>
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif /* HAVE_STDLIB_H */
-#include <sys/stat.h>
-
-#include <sys/socket.h>
-#include <sys/un.h>
-#endif /* OPIEAUTO */
-#if DEBUG
-#include <syslog.h>
-#endif /* DEBUG */
#include "opie.h"
static char *algids[] = { NULL, NULL, NULL, "sha1", "md4", "md5" };
-#if OPIEAUTO
-#ifndef max
-#define max(x, y) (((x) > (y)) ? (x) : (y))
-#endif /* max */
-
-static int opieauto_connect FUNCTION_NOARGS
-{
- int s;
- struct sockaddr_un sun;
- char buffer[1024];
- char *c, *c2 ="/.opieauto";
- uid_t myuid = getuid(), myeuid = geteuid();
-
- if (!myuid || !myeuid || (myuid != myeuid)) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: superuser and/or setuid not allowed");
-#endif /* DEBUG */
- return -1;
- };
-
- memset(&sun, 0, sizeof(struct sockaddr_un));
- sun.sun_family = AF_UNIX;
-
- if (!(c = getenv("HOME"))) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: no HOME variable?");
-#endif /* DEBUG */
- return -1;
- };
-
- if (strlen(c) > (sizeof(sun.sun_path) - strlen(c2) - 1)) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: HOME is too long: %s", c);
-#endif /* DEBUG */
- return -1;
- };
-
- strcpy(sun.sun_path, c);
- strcat(sun.sun_path, c2);
-
- if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: socket: %s(%d)", strerror(errno), errno);
-#endif /* DEBUG */
- return -1;
- };
-
- {
- struct stat st;
-
- if (stat(sun.sun_path, &st) < 0) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: stat: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- goto ret;
- };
-
- if (connect(s, (struct sockaddr *)&sun, sizeof(struct sockaddr_un))) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: connect: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- goto ret;
- };
-
- if ((st.st_uid != myuid) || (!S_ISSOCK(st.st_mode)) || ((st.st_mode & 07777) != 0600)) {
-#if DEBUG
- syslog(LOG_DEBUG, "opieauto_connect: something's fishy about the socket\n");
-#endif /* DEBUG */
- goto ret;
- };
- };
-
- return s;
-
-ret:
- close(s);
- return -1;
-};
-#endif /* OPIEAUTO */
-
-int opiegenerator FUNCTION((challenge, secret, response), char *challenge AND char *secret AND char *response)
+int opiegenerator FUNCTION((buffer, secret, response), char *buffer AND char *secret AND char *response)
{
int algorithm;
int sequence;
char *seed;
- struct opie_otpkey key;
+ char key[8];
int i;
int exts;
-#if OPIEAUTO
- int s;
- int window;
- char cmd[1+1+1+1+4+1+OPIE_SEED_MAX+1+4+1+4+1+4+1+4+1];
- char *c;
-#endif /* OPIEAUTO */
- if (!(challenge = strstr(challenge, "otp-")))
+ if (!(buffer = strstr(buffer, "otp-")))
return 1;
- challenge += 4;
+ buffer += 4;
- if (__opieparsechallenge(challenge, &algorithm, &sequence, &seed, &exts))
+ if (__opieparsechallenge(buffer, &algorithm, &sequence, &seed, &exts))
return 1;
if ((sequence < 2) || (sequence > 9999))
return 1;
- if (*secret) {
- if (opiepasscheck(secret))
- return -2;
-
- if (i = opiekeycrunch(algorithm, &key, seed, secret))
- return i;
-
- if (sequence <= OPIE_SEQUENCE_RESTRICT) {
- if (!(exts & 1))
- return 1;
-
- {
- char newseed[OPIE_SEED_MAX + 1];
- struct opie_otpkey newkey;
- char *c;
- char buf[OPIE_SEED_MAX + 48 + 1];
-
- while (sequence-- != 0)
- opiehash(&key, algorithm);
-
- if (opienewseed(strcpy(newseed, seed)) < 0)
- return -1;
-
- if (opiekeycrunch(algorithm, &newkey, newseed, secret))
- return -1;
-
- for (i = 0; i < 499; i++)
- opiehash(&newkey, algorithm);
-
- strcpy(response, "init-hex:");
- strcat(response, opiebtoh(buf, &key));
- if (snprintf(buf, sizeof(buf), ":%s 499 %s:", algids[algorithm],
- newseed) >= sizeof(buf)) {
-#ifdef DEBUG
- syslog(LOG_DEBUG, "opiegenerator: snprintf truncation at init-hex");
-#endif /* DEBUG */
- return -1;
- }
- strcat(response, buf);
- strcat(response, opiebtoh(buf, &newkey));
- };
- };
- };
-
-#if OPIEAUTO
- if ((s = opieauto_connect()) >= 0) {
- if ((i = read(s, cmd, sizeof(cmd)-1)) < 0) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: read: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- close(s);
- s = -1;
- goto l0;
- };
- cmd[i] = 0;
- if ((cmd[0] != 'C') || (cmd[1] != '+') || (cmd[2] != ' ')) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: got invalid/failing C+ response: %s\n", cmd);
-#endif /* DEBUG */
- close(s);
- s = -1;
- goto l0;
- };
-
- window = strtoul(&cmd[3], &c, 10);
- if (!window || (window >= (OPIE_SEQUENCE_MAX - OPIE_SEQUENCE_RESTRICT)) || !isspace(*c)) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: got bogus option response: %s\n", cmd);
-#endif /* DEBUG */
- close(s);
- s = -1;
- goto l0;
- };
- };
-
-l0:
- if (*secret) {
- int j;
+ if (!secret[0])
+ return 2;
- if (s < 0) {
- j = 0;
- goto l1;
- };
+ if (opiepasscheck(secret))
+ return -2;
- j = max(sequence - window + 1, OPIE_SEQUENCE_RESTRICT);
+ if (i = opiekeycrunch(algorithm, key, seed, secret))
+ return i;
- for (i = j; i > 0; i--)
- opiehash(&key, algorithm);
+ if (sequence < 10) {
+ if (!(exts & 1))
+ return 1;
{
- char buf[16+1];
+ char newseed[OPIE_SEED_MAX + 1];
+ char newkey[8];
+ char *c;
+ char buf[OPIE_SEED_MAX + 48 + 1];
- opiebtoa8(buf, &key);
+ while (sequence-- != 0)
+ opiehash(key, algorithm);
- if (snprintf(cmd, sizeof(cmd), "S= %d %d %s %s\n", algorithm, sequence,
- seed, buf) >= sizeof(cmd)) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: snprintf truncation at S=\n");
-#endif /* DEBUG */
- goto l1;
- }
- }
+ if (opienewseed(strcpy(newseed, seed)) < 0)
+ return -1;
- if (write(s, cmd, i = strlen(cmd)) != i) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: write: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- goto l1;
- };
+ if (opiekeycrunch(algorithm, newkey, newseed, secret))
+ return -1;
- if ((i = read(s, cmd, sizeof(cmd))) < 0) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: read: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- };
- close(s);
+ for (i = 0; i < 499; i++)
+ opiehash(newkey, algorithm);
- cmd[i] = 0;
- i = strlen(seed);
- if ((cmd[0] != 'S') || (cmd[1] != '+') || (cmd[2] != ' ') || (strtoul(&cmd[3], &c, 10) != algorithm) || (strtoul(c + 1, &c, 10) != sequence) || strncmp(++c, seed, i) || (*(c + i) != '\n')) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: got invalid/failing S+ response: %s\n", cmd);
-#endif /* DEBUG */
+ strcpy(response, "init-hex:");
+ strcat(response, opiebtoh(buf, key));
+ sprintf(buf, ":%s 499 %s:", algids[algorithm], newseed);
+ strcat(response, buf);
+ strcat(response, opiebtoh(buf, newkey));
};
-
-l1:
- for (i = sequence - j; i > 0; i--)
- opiehash(&key, algorithm);
-
- opiebtoh(response, &key);
} else {
- if (s < 0)
- goto l2;
-
- if ((snprintf(cmd, sizeof(cmd), "s= %d %d %s\n", algorithm, sequence,
- seed) >= sizeof(cmd))) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: snprintf truncation at s=\n");
-#endif /* DEBUG */
- goto l2;
- }
-
- if (write(s, cmd, i = strlen(cmd)) != i) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: write: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- goto l2;
- };
-
- if ((i = read(s, cmd, sizeof(cmd))) < 0) {
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: read: %s(%d)\n", strerror(errno), errno);
-#endif /* DEBUG */
- goto l2;
- };
- close(s);
-
- i = strlen(seed);
-
- if ((cmd[0] != 's') || (cmd[2] != ' ') || (strtoul(&cmd[3], &c, 10) != algorithm) || (strtoul(c + 1, &c, 10) != sequence) || strncmp(++c, seed, i)) {
-#if DEBUG
- if (c)
- *c = 0;
- else
- cmd[3] = 0;
-
- syslog(LOG_DEBUG, "opiegenerator: got bogus/invalid s response: %s\n", cmd);
-#endif /* DEBUG */
- goto l2;
- };
-
- c += i;
-
- if (cmd[1] == '-') {
-#if DEBUG
- if (*c != '\n') {
- *c = 0;
- syslog(LOG_DEBUG, "opiegenerator: got invalid s- response: %s\n", cmd);
- };
-#endif /* DEBUG */
- goto l2;
- };
-
- if (cmd[1] != '+') {
-#if DEBUG
- *c = 0;
- syslog(LOG_DEBUG, "opiegenerator: got invalid s response: %s\n", cmd);
-#endif /* DEBUG */
- goto l2;
- };
-
- {
- char *c2;
-
- if (!(c2 = strchr(++c, '\n'))) {
-#if DEBUG
- *c = 0;
- syslog(LOG_DEBUG, "opiegenerator: got invalid s+ response: %s\n", cmd);
-#endif /* DEBUG */
- goto l2;
- };
-
- *c2++ = 0;
- };
-
- if (!opieatob8(&key, c))
- goto l2;
-
- opiebtoh(response, &key);
- };
-
- if (s >= 0)
- close(s);
-#else /* OPIEAUTO */
- if (*secret) {
while (sequence-- != 0)
- opiehash(&key, algorithm);
+ opiehash(key, algorithm);
- opiebtoh(response, &key);
- } else
- return -2;
-#endif /* OPIEAUTO */
+ opiebtoh(response, key);
+ }
return 0;
-
-#if OPIEAUTO
-l2:
-#if DEBUG
- syslog(LOG_DEBUG, "opiegenerator: no opieauto response available.\n");
-#endif /* DEBUG */
- if (s >= 0)
- close(s);
-
- return -2;
-#endif /* OPIEAUTO */
-};
+}
diff --git a/contrib/opie/libopie/hash.c b/contrib/opie/libopie/hash.c
index e89508c..0edbdd1 100644
--- a/contrib/opie/libopie/hash.c
+++ b/contrib/opie/libopie/hash.c
@@ -1,68 +1,66 @@
/* hash.c: The opiehash() library function.
%%% copyright-cmetz-96
-This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
-The Inner Net License Version 3 applies to this software.
+This software is Copyright 1996-1998 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:
- Modified by cmetz for OPIE 2.4. Use struct opie_otpkey for binary arg.
- Modified by cmetz for OPIE 2.31. Added SHA support (which may
+ Updated by cmetz for OPIE 2.31. Added SHA support (which may
not be correct). Backed out previous optimizations as
they killed thread-safety.
Created by cmetz for OPIE 2.3 using the old hash.c as a guide.
+
+$FreeBSD$
*/
#include "opie_cfg.h"
-#if 0
-#include "sha.h"
-#endif /* 0 */
#include "opie.h"
-VOIDRET opiehash FUNCTION((x, algorithm), struct opie_otpkey *results AND
-unsigned algorithm)
+#include <sha.h>
+#include <md4.h>
+#include <md5.h>
+
+VOIDRET opiehash FUNCTION((x, algorithm), VOIDPTR x AND unsigned algorithm)
{
+ UINT4 *results = (UINT4 *)x;
+
switch(algorithm) {
-#if 0
case 3:
{
SHA_CTX sha;
-
- SHAInit(&sha);
- SHAUpdate(&sha, (unsigned char *)results, 8);
- SHAFinal(&sha);
-
- results->words[0] = sha.buffer[0] ^ sha.buffer[2] ^ sha.buffer[4];
- results->words[1] = sha.buffer[1] ^ sha.buffer[3];
+ UINT4 digest[5];
+ SHA1_Init(&sha);
+ SHA1_Update(&sha, (unsigned char *)x, 8);
+ SHA1_Final((unsigned char *)digest, &sha);
+ results[0] = digest[0] ^ digest[2] ^ digest[4];
+ results[1] = digest[1] ^ digest[3];
};
break;
-#endif /* 0 */
case 4:
{
- struct opiemdx_ctx mdx;
+ MD4_CTX mdx;
UINT4 mdx_tmp[4];
- opiemd4init(&mdx);
- opiemd4update(&mdx, (unsigned char *)results, 8);
- opiemd4final((unsigned char *)mdx_tmp, &mdx);
-
- results->words[0] = mdx_tmp[0] ^ mdx_tmp[2];
- results->words[1] = mdx_tmp[1] ^ mdx_tmp[3];
+ MD4Init(&mdx);
+ MD4Update(&mdx, (unsigned char *)x, 8);
+ MD4Final((unsigned char *)mdx_tmp, &mdx);
+ results[0] = mdx_tmp[0] ^ mdx_tmp[2];
+ results[1] = mdx_tmp[1] ^ mdx_tmp[3];
};
break;
case 5:
{
- struct opiemdx_ctx mdx;
+ MD5_CTX mdx;
UINT4 mdx_tmp[4];
- opiemd5init(&mdx);
- opiemd5update(&mdx, (unsigned char *)results, 8);
- opiemd5final((unsigned char *)mdx_tmp, &mdx);
-
- results->words[0] = mdx_tmp[0] ^ mdx_tmp[2];
- results->words[1] = mdx_tmp[1] ^ mdx_tmp[3];
+ MD5Init(&mdx);
+ MD5Update(&mdx, (unsigned char *)x, 8);
+ MD5Final((unsigned char *)mdx_tmp, &mdx);
+ results[0] = mdx_tmp[0] ^ mdx_tmp[2];
+ results[1] = mdx_tmp[1] ^ mdx_tmp[3];
};
break;
}
diff --git a/contrib/opie/libopie/hashlen.c b/contrib/opie/libopie/hashlen.c
index 09390c3..66f7d2c 100644
--- a/contrib/opie/libopie/hashlen.c
+++ b/contrib/opie/libopie/hashlen.c
@@ -1,63 +1,58 @@
/* hashlen.c: The opiehashlen() library function.
%%% copyright-cmetz-96
-This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
-The Inner Net License Version 3 applies to this software.
+This software is Copyright 1996-1998 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:
- Modified by cmetz for OPIE 2.4. Use struct opie_otpkey, isolate variables.
Created by cmetz for OPIE 2.3.
+
+$FreeBSD$
*/
#include "opie_cfg.h"
#include "opie.h"
-VOIDRET opiehashlen FUNCTION((algorithm, in, out, n), int algorithm AND
-VOIDPTR in AND struct opie_otpkey *results AND int n)
+#include <sha.h>
+#include <md4.h>
+#include <md5.h>
+
+VOIDRET opiehashlen FUNCTION((algorithm, in, out, n), int algorithm AND VOIDPTR in AND VOIDPTR out AND int n)
{
+ UINT4 *results = (UINT4 *)out;
+ UINT4 mdx_tmp[4];
+
switch(algorithm) {
-#if 0
- case 3:
- {
- SHA_INFO sha;
-
- sha_init(&sha);
- sha_update(&sha, (BYTE *)in, n);
- sha_final(&sha);
-
- results->words[0] = sha.digest[0] ^ sha.digest[2] ^ sha.digest[4];
- results->words[1] = sha.digest[1] ^ sha.digest[3] ^ sha.digest[5];
- };
+ case 3: {
+ SHA_CTX sha;
+ UINT4 digest[5];
+ SHA1_Init(&sha);
+ SHA1_Update(&sha, (unsigned char *)in, n);
+ SHA1_Final((unsigned char *)digest, &sha);
+ results[0] = digest[0] ^ digest[2] ^ digest[4];
+ results[1] = digest[1] ^ digest[3];
break;
-#endif /* 0 */
- case 4:
- {
- struct opiemdx_ctx mdx;
- UINT4 mdx_tmp[4];
-
- opiemd4init(&mdx);
- opiemd4update(&mdx, (unsigned char *)in, n);
- opiemd4final((unsigned char *)mdx_tmp, &mdx);
-
- results->words[0] = mdx_tmp[0] ^ mdx_tmp[2];
- results->words[1] = mdx_tmp[1] ^ mdx_tmp[3];
- }
+ }
+ case 4: {
+ MD4_CTX mdx;
+ MD4Init(&mdx);
+ MD4Update(&mdx, (unsigned char *)in, n);
+ MD4Final((unsigned char *)mdx_tmp, &mdx);
+ results[0] = mdx_tmp[0] ^ mdx_tmp[2];
+ results[1] = mdx_tmp[1] ^ mdx_tmp[3];
break;
- case 5:
- {
- struct opiemdx_ctx mdx;
- UINT4 mdx_tmp[4];
-
- opiemd5init(&mdx);
- opiemd5update(&mdx, (unsigned char *)in, n);
- opiemd5final((unsigned char *)mdx_tmp, &mdx);
-
- results->words[0] = mdx_tmp[0] ^ mdx_tmp[2];
- results->words[1] = mdx_tmp[1] ^ mdx_tmp[3];
- }
+ }
+ case 5: {
+ MD5_CTX mdx;
+ MD5Init(&mdx);
+ MD5Update(&mdx, (unsigned char *)in, n);
+ MD5Final((unsigned char *)mdx_tmp, &mdx);
+ results[0] = mdx_tmp[0] ^ mdx_tmp[2];
+ results[1] = mdx_tmp[1] ^ mdx_tmp[3];
break;
+ }
}
}
diff --git a/contrib/opie/libopie/insecure.c b/contrib/opie/libopie/insecure.c
index 383206f..e02183a 100644
--- a/contrib/opie/libopie/insecure.c
+++ b/contrib/opie/libopie/insecure.c
@@ -1,7 +1,7 @@
/* insecure.c: The opieinsecure() library function.
%%% portions-copyright-cmetz-96
-Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
+Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
Reserved. The Inner Net License Version 2 applies to these portions of
the software.
You should have received a copy of the license with this software. If
@@ -14,8 +14,6 @@ License Agreement applies to this software.
History:
- Modified by cmetz for OPIE 2.4. Do utmp checks on utmpx systems.
- Handle unterminated ut_host.
Modified by cmetz for OPIE 2.31. Fixed a logic bug. Call endut[x]ent().
Modified by cmetz for OPIE 2.3. Added result caching. Use
__opiegetutmpentry(). Ifdef around ut_host check. Eliminate
@@ -27,6 +25,9 @@ License Agreement applies to this software.
found. Use uname().
Created at NRL for OPIE 2.2 from opiesubr.c. Fixed pointer
assignment that should have been a comparison.
+
+$FreeBSD$
+
*/
#include "opie_cfg.h"
@@ -58,14 +59,16 @@ int opieinsecure FUNCTION_NOARGS
char *s;
char *term_name;
int insecure = 0;
-#if HAVE_UT_HOST || DOUTMPX
+#if HAVE_UT_HOST
struct utmp utmp;
-#endif /* HAVE_UT_HOST || DOUTMPX */
+#endif /* HAVE_UT_HOST */
static int result = -1;
if (result != -1)
return result;
+ if (getenv("SSH_CLIENT") != NULL)
+ return (result = 0);
display_name = (char *) getenv("DISPLAY");
term_name = (char *) getenv("TERM");
@@ -119,34 +122,30 @@ int opieinsecure FUNCTION_NOARGS
return (result = 1);
};
-#if HAVE_UT_HOST || DOUTMPX
+#if HAVE_UT_HOST
if (isatty(0)) {
memset(&utmp, 0, sizeof(struct utmp));
{
int i = __opiegetutmpentry(ttyname(0), &utmp);
endutent();
if (!i && utmp.ut_host[0]) {
- char host[sizeof(utmp.ut_host) + 1];
insecure = 1;
- strncpy(host, utmp.ut_host, sizeof(utmp.ut_host));
- host[sizeof(utmp.ut_host)] = 0;
-
- if (s = strchr(host, ':')) {
- int n = s - host;
+ if (s = strchr(utmp.ut_host, ':')) {
+ int n = s - utmp.ut_host;
if (!n)
insecure = 0;
else
if (display_name) {
- if (!strncmp(host, display_name, n))
+ if (!strncmp(utmp.ut_host, display_name, n))
insecure = 0;
-#if 1 /* def SOLARIS */
+#ifdef SOLARIS
else
- if (s = strchr(host, ' ')) {
+ if (s = strchr(utmp.ut_host, ' ')) {
*s = ':';
if (s = strchr(s + 1, ' '))
*s = '.';
- if (!strncmp(host, display_name, n))
+ if (!strncmp(utmp.ut_host, display_name, n))
insecure = 0;
}
#endif /* SOLARIS */
@@ -155,7 +154,7 @@ int opieinsecure FUNCTION_NOARGS
}
};
};
-#endif /* HAVE_UT_HOST || DOUTMPX */
+#endif /* HAVE_UT_HOST */
if (insecure)
return (result = 1);
diff --git a/contrib/opie/libopie/lock.c b/contrib/opie/libopie/lock.c
index bd92607..0f666a6 100644
--- a/contrib/opie/libopie/lock.c
+++ b/contrib/opie/libopie/lock.c
@@ -1,7 +1,7 @@
/* lock.c: The opielock() library function.
%%% portions-copyright-cmetz-96
-Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
+Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
Reserved. The Inner Net License Version 2 applies to these portions of
the software.
You should have received a copy of the license with this software. If
@@ -14,7 +14,6 @@ License Agreement applies to this software.
History:
- Modified by cmetz for OPIE 2.4. Use snprintf.
Modified by cmetz for OPIE 2.31. Put locks in a separate dir.
Bug fixes.
Modified by cmetz for OPIE 2.3. Do refcounts whether or not we
@@ -28,6 +27,8 @@ License Agreement applies to this software.
error return values. Check open() return value properly.
Avoid NULL.
Created at NRL for OPIE 2.2 from opiesubr2.c
+
+$FreeBSD$
*/
#include "opie_cfg.h"
#if HAVE_STRING_H
@@ -50,12 +51,17 @@ License Agreement applies to this software.
#endif /* !HAVE_LSTAT */
int __opie_lockrefcount = 0;
+static int do_atexit = 1;
+VOIDRET opiedisableaeh FUNCTION_NOARGS
+{
+ do_atexit = 0;
+}
#if USER_LOCKING
char *__opie_lockfilename = (char *)0;
/* atexit() handler for opielock() */
-static VOIDRET opieunlockaeh FUNCTION_NOARGS
+VOIDRET opieunlockaeh FUNCTION_NOARGS
{
if (__opie_lockfilename) {
__opie_lockrefcount = 0;
@@ -195,9 +201,7 @@ int opielock FUNCTION((principal), char *principal)
if (!S_ISREG(statbuf[0].st_mode) || (statbuf[0].st_mode != statbuf[1].st_mode) || (statbuf[0].st_ino != statbuf[1].st_ino))
goto lockret;
- if (snprintf(buffer, sizeof(buffer), "%d\n%d\n", getpid(), time(0)) >= sizeof(buffer))
- goto lockret;
-
+ sprintf(buffer, "%d\n%d\n", getpid(), time(0));
i = strlen(buffer) + 1;
if (lseek(fh, 0, SEEK_SET)) {
close(fh);
@@ -230,7 +234,8 @@ int opielock FUNCTION((principal), char *principal)
__opie_lockrefcount++;
rval = 0;
- atexit(opieunlockaeh);
+ if (do_atexit)
+ atexit(opieunlockaeh);
lockret:
if (fh >= 0)
diff --git a/contrib/opie/libopie/newseed.c b/contrib/opie/libopie/newseed.c
index 0455857..23cdce4 100644
--- a/contrib/opie/libopie/newseed.c
+++ b/contrib/opie/libopie/newseed.c
@@ -1,18 +1,18 @@
/* newseed.c: The opienewseed() library function.
%%% copyright-cmetz-96
-This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
-The Inner Net License Version 3 applies to this software.
+This software is Copyright 1996-1998 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:
- Modified by cmetz for OPIE 2.4. Greatly simplified increment. Now does
- not add digits. Reformatted the code.
Modified by cmetz for OPIE 2.32. Added syslog.h if DEBUG.
Modified by cmetz for OPIE 2.31. Added time.h.
Created by cmetz for OPIE 2.22.
+
+$FreeBSD$
*/
#include "opie_cfg.h"
@@ -37,54 +37,73 @@ you didn't get a copy, you may request one from <license@inner.net>.
int opienewseed FUNCTION((seed), char *seed)
{
- if (!seed)
- return -1;
-
- if (seed[0]) {
- char *c, *end;
- unsigned int i, max;
-
- if ((i = strlen(seed)) > OPIE_SEED_MAX)
- i = OPIE_SEED_MAX;
-
- for (c = end = seed + i - 1, max = 1;
- (c > seed) && isdigit(*c); c--)
- max *= 10;
-
- if ((i = strtoul(++c, (char **)0, 10)) < max) {
- if (++i >= max)
- i = 1;
-
- snprintf(c, end - c, "%d", i);
- seed[OPIE_SEED_MAX] = 0;
- return 0;
- }
+ 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;
}
- {
- time_t now;
+ sprintf(seed, "%s%04ld", buf, j);
+ return 0;
+ }
+ }
+ }
- time(&now);
- srand(now);
- }
+ {
+ {
+ time_t now;
+ time(&now);
+ srand(now);
+ }
- {
- struct utsname utsname;
+ {
+ struct utsname utsname;
- if (uname(&utsname) < 0) {
+ if (uname(&utsname) < 0) {
#if DEBUG
- syslog(LOG_DEBUG, "uname: %s(%d)", strerror(errno),
- errno);
+ syslog(LOG_DEBUG, "uname: %s(%d)", strerror(errno), errno);
#endif /* DEBUG */
- utsname.nodename[0] = 'k';
- utsname.nodename[1] = 'e';
- }
- utsname.nodename[2] = 0;
-
- if (snprintf(seed, OPIE_SEED_MAX+1, "%s%04d", utsname.nodename,
- (rand() % 9999) + 1) >= OPIE_SEED_MAX+1)
- return -1;
- return 0;
- }
+ utsname.nodename[0] = 'k';
+ utsname.nodename[1] = 'e';
+ }
+ utsname.nodename[2] = 0;
+
+ sprintf(seed, "%s%04d", utsname.nodename, (rand() % 9999) + 1);
+ return 0;
+ }
+ }
}
OpenPOWER on IntegriCloud