diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-26 19:42:47 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-26 19:42:47 +0000 |
commit | dd246ea1ce8b5105cb2adcddb62635d4f346aa24 (patch) | |
tree | 19eddd8bc7e4d103450dae433b195628722dc483 /lib/libskey | |
parent | 2a7cfb11e4e529ad03696b18410372547caa28c8 (diff) |
- int -> long fixes
- restore priority correctly after setpriority (assumed start pri was 0)
- rfc-compliant challenge when faking it for those w/o a keyfile entry
on machines with short hostnames or non-alphanum hostnames.
Diffstat (limited to 'lib/libskey')
-rw-r--r-- | lib/libskey/put.c | 14 | ||||
-rw-r--r-- | lib/libskey/skeylogin.c | 86 |
2 files changed, 55 insertions, 45 deletions
diff --git a/lib/libskey/put.c b/lib/libskey/put.c index 6daf3688287..fc5d891024c 100644 --- a/lib/libskey/put.c +++ b/lib/libskey/put.c @@ -8,7 +8,7 @@ * * Dictionary lookup and extraction. * - * $Id: put.c,v 1.7 1997/07/24 23:00:25 millert Exp $ + * $Id: put.c,v 1.8 1997/07/26 19:42:44 millert Exp $ */ #include <stdio.h> @@ -18,7 +18,7 @@ #include "skey.h" -static unsigned long extract __P ((char *s, int start, int length)); +static unsigned int extract __P ((char *s, int start, int length)); static void standard __P ((char *word)); static void insert __P ((char *s, int x, int start, int length)); static int wsrch __P ((char *w, int low, int high)); @@ -2251,7 +2251,7 @@ insert(s, x, start, length) unsigned char cl; unsigned char cc; unsigned char cr; - unsigned long y; + unsigned int y; int shift; assert(length <= 11); @@ -2260,7 +2260,7 @@ insert(s, x, start, length) assert(start + length <= 66); shift = ((8 - ((start + length) % 8)) % 8); - y = (long)x << shift; + y = x << shift; cl = (y >> 16) & 0xff; cc = (y >> 8) & 0xff; cr = y & 0xff; @@ -2296,7 +2296,7 @@ standard(word) } /* Extract 'length' bits from the char array 's' starting with bit 'start' */ -static unsigned long +static unsigned int extract(s, start, length) char *s; int start; @@ -2305,7 +2305,7 @@ extract(s, start, length) unsigned char cl; unsigned char cc; unsigned char cr; - unsigned long x; + unsigned int x; assert(length <= 11); assert(start >= 0); @@ -2315,7 +2315,7 @@ extract(s, start, length) cl = s[start / 8]; cc = s[start / 8 + 1]; cr = s[start / 8 + 2]; - x = ((long)(cl << 8 | cc) << 8 | cr); + x = ((int)(cl << 8 | cc) << 8 | cr); x = x >> (24 - (length + (start % 8))); x = (x & (0xffff >> (16 - length))); diff --git a/lib/libskey/skeylogin.c b/lib/libskey/skeylogin.c index 4996f7f3859..db9ba4cd840 100644 --- a/lib/libskey/skeylogin.c +++ b/lib/libskey/skeylogin.c @@ -8,7 +8,7 @@ * * S/KEY verification check, lookups, and authentication. * - * $Id: skeylogin.c,v 1.15 1997/07/23 07:16:57 millert Exp $ + * $Id: skeylogin.c,v 1.16 1997/07/26 19:42:46 millert Exp $ */ #include <sys/param.h> @@ -37,8 +37,8 @@ char *skipspace __P((char *)); int skeylookup __P((struct skey *, char *)); /* Issue a skey challenge for user 'name'. If successful, - * fill in the caller's skey structure and return 0. If unsuccessful - * (e.g., if name is unknown) return -1. + * fill in the caller's skey structure and return(0). If unsuccessful + * (e.g., if name is unknown) return(1). * * The file read/write pointer is left at the start of the * record. @@ -56,22 +56,22 @@ getskeyprompt(mp, name, prompt) (void)strcpy(prompt, "otp-md0 55 latour1\n"); switch (rval) { case -1: /* File error */ - return -1; + return(1); case 0: /* Lookup succeeded, return challenge */ (void)sprintf(prompt, "otp-%.*s %d %.*s\n", SKEY_MAX_HASHNAME_LEN, skey_get_algorithm(), mp->n - 1, SKEY_MAX_SEED_LEN, mp->seed); - return 0; + return(0); case 1: /* User not found */ (void)fclose(mp->keyfile); - return -1; + return(1); } - return -1; /* Can't happen */ + return(1); /* Can't happen */ } /* Return a skey challenge string for user 'name'. If successful, - * fill in the caller's skey structure and return 0. If unsuccessful - * (e.g., if name is unknown) return -1. + * fill in the caller's skey structure and return(0). If unsuccessful + * (e.g., if name is unknown) return(1). * * The file read/write pointer is left at the start of the * record. @@ -87,17 +87,17 @@ skeychallenge(mp, name, ss) rval = skeylookup(mp,name); switch(rval){ case -1: /* File error */ - return -1; + return(1); case 0: /* Lookup succeeded, issue challenge */ (void)sprintf(ss, "otp-%.*s %d %.*s", SKEY_MAX_HASHNAME_LEN, skey_get_algorithm(), mp->n - 1, SKEY_MAX_SEED_LEN, mp->seed); - return 0; + return(0); case 1: /* User not found */ (void)fclose(mp->keyfile); - return -1; + return(1); } - return -1; /* Can't happen */ + return(1); /* Can't happen */ } /* Find an entry in the One-time Password database. @@ -128,7 +128,7 @@ skeylookup(mp, name) fchmod(fileno(mp->keyfile), 0600); } if (mp->keyfile == NULL) - return -1; + return(1); /* Look up user name in database */ while (!feof(mp->keyfile)) { @@ -168,9 +168,9 @@ skeylookup(mp, name) warnx("Unknown hash algorithm %s, using %s", ht, skey_get_algorithm()); } - return 0; + return(0); } else { - return 1; + return(1); } } @@ -201,7 +201,7 @@ skeygetnext(mp) fchmod(fileno(mp->keyfile), 0600); } if (mp->keyfile == NULL) - return -1; + return(1); } /* Look up next user in database */ @@ -254,6 +254,7 @@ skeyverify(mp, response) struct tm *tm; char tbuf[27]; char *cp; + int oldpri; time(&now); tm = localtime(&now); @@ -261,7 +262,7 @@ skeyverify(mp, response) if (response == NULL) { (void)fclose(mp->keyfile); - return -1; + return(1); } rip(response); @@ -269,7 +270,7 @@ skeyverify(mp, response) if (etob(key, response) != 1 && atob8(key, response) != 0) { /* Neither english words or ascii hex */ (void)fclose(mp->keyfile); - return -1; + return(1); } /* Compute fkey = f(key) */ @@ -278,19 +279,20 @@ skeyverify(mp, response) f(fkey); /* - * in order to make the window of update as short as possible + * In order to make the window of update as short as possible * we must do the comparison here and if OK write it back * other wise the same password can be used twice to get in * to the system */ + oldpri = getpriority(PRIO_PROCESS, 0); (void)setpriority(PRIO_PROCESS, 0, -4); /* reread the file record NOW */ (void)fseek(mp->keyfile, mp->recstart, SEEK_SET); if (fgets(mp->buf, sizeof(mp->buf), mp->keyfile) != mp->buf) { - (void)setpriority(PRIO_PROCESS, 0, 0); + (void)setpriority(PRIO_PROCESS, 0, oldpri); (void)fclose(mp->keyfile); - return -1; + return(1); } rip(mp->buf); mp->logname = strtok(mp->buf, " \t"); @@ -305,9 +307,9 @@ skeyverify(mp, response) /* Do actual comparison */ if (memcmp(filekey, fkey, SKEY_BINKEY_SIZE) != 0){ /* Wrong response */ - (void)setpriority(PRIO_PROCESS, 0, 0); + (void)setpriority(PRIO_PROCESS, 0, oldpri); (void)fclose(mp->keyfile); - return 1; + return(1); } /* @@ -329,8 +331,8 @@ skeyverify(mp, response) (void)fclose(mp->keyfile); - (void)setpriority(PRIO_PROCESS, 0, 0); - return 0; + (void)setpriority(PRIO_PROCESS, 0, oldpri); + return(0); } /* @@ -365,9 +367,9 @@ skey_keyinfo(username) i = skeychallenge(&skey, username, str); if (i == -1) - return 0; + return(0); - return str; + return(str); } /* @@ -388,12 +390,12 @@ skey_passcheck(username, passwd) i = skeylookup(&skey, username); if (i == -1 || i == 1) - return -1; + return(1); if (skeyverify(&skey, passwd) == 0) - return skey.n; + return(skey.n); - return -1; + return(1); } /* @@ -420,9 +422,17 @@ skey_authenticate(username) if (i != 0) { char *p, *u; - /* Base first 4 chars of seed on hostname */ - if (gethostname(pbuf, sizeof(pbuf)) < 0) - strcpy(pbuf, "asjd"); + /* + * Base first 4 chars of seed on hostname. + * Add some filler for short hostnames if necessary. + */ + if (gethostname(pbuf, sizeof(pbuf)) == -1) + *(p = pbuf) = '.'; + else + for (p = pbuf; *p && isalnum(*p); p++) + ; + if (*p) + strncpy(p, "asjd", 4 - (pbuf - p)); p = &pbuf[4]; *p = '\0'; @@ -459,9 +469,9 @@ skey_authenticate(username) "\nWarning! Key initialization needed soon. (%d logins left)\n", skey.n); } - return 0; + return(0); } - return -1; + return(1); } /* Comment out user's entry in the s/key database @@ -484,10 +494,10 @@ skeyzero(mp, response) (void)fseek(mp->keyfile, mp->recstart, SEEK_SET); if (fputc('#', mp->keyfile) == EOF) { fclose(mp->keyfile); - return -1; + return(1); } (void)fclose(mp->keyfile); - return 0; + return(0); } |