예제 #1
0
int
otp_challenge (OtpContext *ctx, char *user, char *str, size_t len)
{
  void *dbm;
  int ret;

  ctx->challengep = 0;
  ctx->err = NULL;
  ctx->user = strdup(user);
  if (ctx->user == NULL) {
    ctx->err = "Out of memory";
    return -1;
  }
  dbm = otp_db_open ();
  if (dbm == NULL) {
    ctx->err = "Cannot open database";
    return -1;
  }
  ret = otp_get (dbm, ctx);
  otp_db_close (dbm);
  if (ret)
    return ret;
  snprintf (str, len,
	    "[ otp-%s %u %s ]",
	    ctx->alg->name, ctx->n-1, ctx->seed);
  ctx->challengep = 1;
  return 0;
}
예제 #2
0
int
otp_verify_user (OtpContext *ctx, const char *passwd)
{
  void *dbm;
  int ret;

  if (!ctx->challengep)
    return -1;
  ret = otp_verify_user_1 (ctx, passwd);
  dbm = otp_db_open ();
  if (dbm == NULL) {
    free(ctx->user);
    return -1;
  }
  otp_put (dbm, ctx);
  free(ctx->user);
  otp_db_close (dbm);
  return ret;
}