X-Git-Url: https://git.hcoop.net/hcoop/debian/courier-authlib.git/blobdiff_plain/d9898ee81388d1eff40cf71e85d9ce9b5c1401fe..0e333c05cada796fa75ceebdfc4b3e20d48f87ec:/cramlib.c diff --git a/cramlib.c b/cramlib.c index 72eb426..a068479 100644 --- a/cramlib.c +++ b/cramlib.c @@ -1,5 +1,5 @@ /* -** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for +** Copyright 1998 - 2008 Double Precision, Inc. See COPYING for ** distribution information. */ @@ -11,13 +11,9 @@ #include #include #include "courierauthsasl.h" -#include "cramlib.h" +#include "courierauth.h" #include "courierauthdebug.h" - -#if HAVE_HMACLIB - #include "libhmac/hmac.h" -#include "cramlib.h" static int nybble(int c) { @@ -82,8 +78,8 @@ int rc; return rc; } -int auth_get_cram(const char *authtype, char *authdata, - struct cram_callback_info *craminfo) +static int do_auth_get_cram(const char *authtype, char *authdata, + struct cram_callback_info *craminfo, int logerr) { int i; int challenge_l; @@ -93,7 +89,10 @@ int response_l; (craminfo->challenge=strtok(authdata, "\n")) == 0 || (craminfo->response=strtok(0, "\n")) == 0) { - DPRINTF("cram: only supports authtype=cram-*"); + if (logerr) + { + DPRINTF("Unsupported authentication type: %s", authtype); + } errno=EPERM; return (-1); } @@ -102,15 +101,21 @@ int response_l; if (strcmp(hmac_list[i]->hh_name, authtype+5) == 0) break; - DPRINTF("cram: challenge=%s, response=%s", craminfo->challenge, - craminfo->response); + if (logerr) + { + DPRINTF("cram: challenge=%s, response=%s", craminfo->challenge, + craminfo->response); + } if (hmac_list[i] == 0 || (challenge_l=authsasl_frombase64(craminfo->challenge)) < 0 || (response_l=authsasl_frombase64(craminfo->response)) < 0) { - DPRINTF("cram: invalid base64 encoding, or unknown method: %s", - authtype); + if (logerr) + { + DPRINTF("cram: invalid base64 encoding, or unknown method: %s", + authtype); + } errno=EACCES; return (-1); } @@ -125,7 +130,10 @@ int response_l; if (i == 0) { - DPRINTF("cram: invalid base64 encoding"); + if (logerr) + { + DPRINTF("cram: invalid base64 encoding"); + } errno=EACCES; return (-1); } @@ -140,9 +148,12 @@ int response_l; craminfo->challenge[challenge_l]=0; craminfo->response[response_l]=0; - /* we rely on DPRINTF doing a "safe" print here */ - DPRINTF("cram: decoded challenge/response, username '%s'", - craminfo->user); + if (logerr) + { + /* we rely on DPRINTF doing a "safe" print here */ + DPRINTF("cram: decoded challenge/response, username '%s'", + craminfo->user); + } return (0); } @@ -195,5 +206,14 @@ int rc; return (*cci->callback_func)(a, cci->callback_arg); } +int auth_get_cram(const char *authtype, char *authdata, + struct cram_callback_info *craminfo) +{ + return do_auth_get_cram(authtype, authdata, craminfo, 1); +} -#endif +int auth_get_cram_silent(const char *authtype, char *authdata, + struct cram_callback_info *craminfo) +{ + return do_auth_get_cram(authtype, authdata, craminfo, 0); +}