X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Frlm_otp%2Fotp_pw_valid.c;h=914b6e98445e3b848a24e2b5d48008378d721a91;hb=fe4b8e632116c09c62e8480adec1b6e921a5f79c;hp=ab23f1575615774842cb1ef57a131a5f5b91d294;hpb=6c7183010d5227184d1c95d278e354cec4f6cfb2;p=freeradius.git diff --git a/src/modules/rlm_otp/otp_pw_valid.c b/src/modules/rlm_otp/otp_pw_valid.c index ab23f15..914b6e9 100644 --- a/src/modules/rlm_otp/otp_pw_valid.c +++ b/src/modules/rlm_otp/otp_pw_valid.c @@ -18,28 +18,23 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * - * Copyright 2006 TRI-D Systems, Inc. + * Copyright 2006,2007 TRI-D Systems, Inc. */ #include RCSID("$Id$") -#include "autoconf.h" -#include "radiusd.h -#include "modules.h" +#include +#include #include "extern.h" #include "otp.h" #include "otp_pw_valid.h" -#include +#ifdef HAVE_PTHREAD_H #include -#include -#include -#include -#include +#endif #include -#include /* transform otpd return codes into rlm return codes */ @@ -47,13 +42,15 @@ static int otprc2rlmrc(int rc) { switch (rc) { - case OTP_RC_OK: return RLM_MODULE_OK; - case OTP_RC_USER_UNKNOWN: return RLM_MODULE_REJECT; - case OTP_RC_AUTHINFO_UNAVAIL: return RLM_MODULE_REJECT; - case OTP_RC_AUTH_ERR: return RLM_MODULE_REJECT; - case OTP_RC_MAXTRIES: return RLM_MODULE_USERLOCK; - case OTP_RC_SERVICE_ERR: return RLM_MODULE_FAIL; - default: return RLM_MODULE_FAIL; + case OTP_RC_OK: return RLM_MODULE_OK; + case OTP_RC_USER_UNKNOWN: return RLM_MODULE_REJECT; + case OTP_RC_AUTHINFO_UNAVAIL: return RLM_MODULE_REJECT; + case OTP_RC_AUTH_ERR: return RLM_MODULE_REJECT; + case OTP_RC_MAXTRIES: return RLM_MODULE_USERLOCK; + case OTP_RC_NEXTPASSCODE: return RLM_MODULE_USERLOCK; + case OTP_RC_IPIN: return RLM_MODULE_REJECT; + case OTP_RC_SERVICE_ERR: return RLM_MODULE_FAIL; + default: return RLM_MODULE_FAIL; } } @@ -80,7 +77,7 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, otp_request_t otp_request; otp_reply_t otp_reply; VALUE_PAIR *cvp, *rvp; - char *username = request->username->strvalue; + char *username = request->username->vp_strvalue; int rc; if (request->username->length > OTP_MAX_USERNAME_LEN) { @@ -95,8 +92,8 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, otp_request.pwe.pwe = pwe; /* otp_pwe_present() (done by caller) guarantees that both of these exist */ - cvp = pairfind(request->packet->vps, pwattr[pwe - 1]); - rvp = pairfind(request->packet->vps, pwattr[pwe]); + cvp = pairfind(request->packet->vps, pwattr[pwe - 1]->attr, pwattr[pwe - 1]->vendor); + rvp = pairfind(request->packet->vps, pwattr[pwe]->attr, pwattr[pwe]->vendor); /* this is just to quiet Coverity */ if (!rvp || !cvp) return RLM_MODULE_REJECT; @@ -111,7 +108,7 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, (void) radlog(L_AUTH, "rlm_otp: passcode for [%s] too long", username); return RLM_MODULE_REJECT; } - (void) strcpy(otp_request.pwe.u.pap.passcode, rvp->strvalue); + (void) strcpy(otp_request.pwe.u.pap.passcode, rvp->vp_strvalue); break; case PWE_CHAP: @@ -125,10 +122,10 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, username); return RLM_MODULE_INVALID; } - (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->vp_strvalue, cvp->length); otp_request.pwe.u.chap.clen = cvp->length; - (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.response, rvp->vp_strvalue, rvp->length); otp_request.pwe.u.chap.rlen = rvp->length; break; @@ -144,10 +141,10 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, username); return RLM_MODULE_INVALID; } - (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->vp_strvalue, cvp->length); otp_request.pwe.u.chap.clen = cvp->length; - (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.response, rvp->vp_strvalue, rvp->length); otp_request.pwe.u.chap.rlen = rvp->length; break; @@ -163,10 +160,10 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge, username); return RLM_MODULE_INVALID; } - (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->vp_strvalue, cvp->length); otp_request.pwe.u.chap.clen = cvp->length; - (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue, + (void) memcpy(otp_request.pwe.u.chap.response, rvp->vp_strvalue, rvp->length); otp_request.pwe.u.chap.rlen = rvp->length; break; @@ -209,8 +206,8 @@ retry: if (!fdp || fdp->fd == -1) return -1; - if ((rc = otp_write(fdp, (const char *) request, sizeof(*request))) != 0) { - if (rc == EPIPE) + if ((rc = otp_write(fdp, (const char *) request, sizeof(*request))) != sizeof(*request)) { + if (rc == 0) goto retry; /* otpd disconnect */ /*TODO: pause */ else return -1; @@ -287,7 +284,7 @@ otp_write(otp_fd_t *fdp, const char *buf, size_t len) while (nleft) { if ((nwrote = write(fdp->fd, &buf[len - nleft], nleft)) == -1) { - if (errno == EINTR || errno == EPIPE) { + if (errno == EINTR) { continue; } else { (void) radlog(L_ERR, "rlm_otp: %s: write to otpd: %s",