return errors

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@982 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1996-11-16 17:54:17 +00:00
parent 7a2f2857d5
commit a4237d6c48
3 changed files with 21 additions and 7 deletions

View File

@@ -51,12 +51,16 @@ otp_challenge (OtpContext *ctx, char *user, char *str, size_t len)
ctx->user = strdup(user);
dbm = otp_db_open ();
if (dbm == NULL)
if (dbm == NULL) {
ctx->err = "Cannot open database";
return -1;
}
ret = otp_get (dbm, ctx);
otp_db_close (dbm);
if (ret)
return ret;
sprintf (str, "[ otp-%s %u %s ]", ctx->alg->name, ctx->n-1, ctx->seed);
ctx->err = NULL;
ctx->challengep = 1;
return 0;
}

View File

@@ -89,18 +89,24 @@ otp_get (void *v, OtpContext *ctx)
key.dptr = ctx->user;
dat = dbm_fetch (dbm, key);
if (dat.dptr == NULL)
if (dat.dptr == NULL) {
ctx->err = "Entry not found";
return -1;
}
p = dat.dptr;
time(&now);
memcpy (&then, p, sizeof(then));
if (then && now - then < OTP_USER_TIMEOUT)
if (then && now - then < OTP_USER_TIMEOUT) {
ctx->err = "Entry locked";
return -1;
}
memcpy (p, &now, sizeof(now));
p += sizeof(now);
ctx->alg = otp_find_alg (p);
if (ctx->alg == NULL)
if (ctx->alg == NULL) {
ctx->err = "Bad algorithm";
return -1;
}
p += strlen(p) + 1;
ctx->n = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
p += 4;

View File

@@ -48,8 +48,10 @@ otp_verify_user_1 (OtpContext *ctx, char *passwd)
{
OtpKey key1, key2;
if (otp_parse (key1, passwd, ctx->alg))
if (otp_parse (key1, passwd, ctx->alg)) {
ctx->err = "Syntax error in reply";
return -1;
}
memcpy (key2, key1, sizeof(key1));
ctx->alg->next (key2);
if (memcmp (ctx->key, key2, sizeof(key2)) == 0) {
@@ -66,13 +68,15 @@ otp_verify_user (OtpContext *ctx, char *passwd)
void *dbm;
int ret;
otp_verify_user_1 (ctx, passwd);
if (!ctx->challengep)
return -1;
ret = otp_verify_user_1 (ctx, passwd);
dbm = otp_db_open ();
if (dbm == NULL) {
free(ctx->user);
return -1;
}
ret = otp_put (dbm, ctx);
otp_put (dbm, ctx);
free(ctx->user);
otp_db_close (dbm);
return ret;