From a4237d6c48f7c864bab10e9c451eab5bcbc6a655 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sat, 16 Nov 1996 17:54:17 +0000 Subject: [PATCH] return errors git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@982 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/otp/otp_challenge.c | 6 +++++- lib/otp/otp_db.c | 12 +++++++++--- lib/otp/otp_verify.c | 10 +++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/otp/otp_challenge.c b/lib/otp/otp_challenge.c index 7dee1d44c..dac185e26 100644 --- a/lib/otp/otp_challenge.c +++ b/lib/otp/otp_challenge.c @@ -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; } diff --git a/lib/otp/otp_db.c b/lib/otp/otp_db.c index 3d3d60ffa..6d3c1ee67 100644 --- a/lib/otp/otp_db.c +++ b/lib/otp/otp_db.c @@ -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; diff --git a/lib/otp/otp_verify.c b/lib/otp/otp_verify.c index 8a865102f..e57d95dd4 100644 --- a/lib/otp/otp_verify.c +++ b/lib/otp/otp_verify.c @@ -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;