import from HEAD:
[freeradius.git] / src / modules / rlm_otp / otp_pw_valid.c
index df8f7c1..ab23f15 100644 (file)
  * Copyright 2006 TRI-D Systems, Inc.
  */
 
-#include "ident.h"
+#include <freeradius-devel/ident.h>
 RCSID("$Id$")
 
 #include "autoconf.h"
-#include "radiusd.h"
+#include "radiusd.h
 #include "modules.h"
 
 #include "extern.h"
@@ -89,7 +89,7 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge,
   }
   /* we already know challenge is short enough */
 
-  otp_request.version = 1;
+  otp_request.version = 2;
   (void) strcpy(otp_request.username, username);
   (void) strcpy(otp_request.challenge, challenge);
   otp_request.pwe.pwe = pwe;
@@ -97,7 +97,9 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge,
   /* 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]);
-  if (!rvp || !cvp) return RLM_MODULE_REJECT;
+  /* this is just to quiet Coverity */
+  if (!rvp || !cvp)
+    return RLM_MODULE_REJECT;
 
   /*
    * Validate available vps based on pwe type.
@@ -109,7 +111,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.passcode, rvp->strvalue);
+    (void) strcpy(otp_request.pwe.u.pap.passcode, rvp->strvalue);
     break;
 
   case PWE_CHAP:
@@ -123,10 +125,12 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge,
                     username);
       return RLM_MODULE_INVALID;
     }
-    (void) memcpy(otp_request.pwe.challenge, cvp->strvalue, cvp->length);
-    otp_request.pwe.clen = cvp->length;
-    (void) memcpy(otp_request.pwe.response, rvp->strvalue, rvp->length);
-    otp_request.pwe.rlen = rvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue,
+                  cvp->length);
+    otp_request.pwe.u.chap.clen = cvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue,
+                  rvp->length);
+    otp_request.pwe.u.chap.rlen = rvp->length;
     break;
 
   case PWE_MSCHAP:
@@ -140,10 +144,12 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge,
                     username);
       return RLM_MODULE_INVALID;
     }
-    (void) memcpy(otp_request.pwe.challenge, cvp->strvalue, cvp->length);
-    otp_request.pwe.clen = cvp->length;
-    (void) memcpy(otp_request.pwe.response, rvp->strvalue, rvp->length);
-    otp_request.pwe.rlen = rvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue,
+                  cvp->length);
+    otp_request.pwe.u.chap.clen = cvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue,
+                  rvp->length);
+    otp_request.pwe.u.chap.rlen = rvp->length;
     break;
 
   case PWE_MSCHAP2:
@@ -157,17 +163,20 @@ otp_pw_valid(REQUEST *request, int pwe, const char *challenge,
                     username);
       return RLM_MODULE_INVALID;
     }
-    (void) memcpy(otp_request.pwe.challenge, cvp->strvalue, cvp->length);
-    otp_request.pwe.clen = cvp->length;
-    (void) memcpy(otp_request.pwe.response, rvp->strvalue, rvp->length);
-    otp_request.pwe.rlen = rvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.challenge, cvp->strvalue,
+                  cvp->length);
+    otp_request.pwe.u.chap.clen = cvp->length;
+    (void) memcpy(otp_request.pwe.u.chap.response, rvp->strvalue,
+                  rvp->length);
+    otp_request.pwe.u.chap.rlen = rvp->length;
     break;
   } /* switch (otp_request.pwe.pwe) */
 
   /* last byte must also be a terminator so otpd can verify length easily */
   otp_request.username[OTP_MAX_USERNAME_LEN] = '\0';
   otp_request.challenge[OTP_MAX_CHALLENGE_LEN] = '\0';
-  otp_request.pwe.passcode[OTP_MAX_PASSCODE_LEN] = '\0';
+  if (otp_request.pwe.pwe == PWE_PAP)
+    otp_request.pwe.u.pap.passcode[OTP_MAX_PASSCODE_LEN] = '\0';
 
   otp_request.allow_sync = opt->allow_sync;
   otp_request.allow_async = opt->allow_async;
@@ -310,7 +319,7 @@ otp_connect(const char *path)
   }
   sa.sun_family = AF_UNIX;
   (void) strcpy(sa.sun_path, path);
-    
+
   /* connect to otpd */
   if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
     (void) radlog(L_ERR, "rlm_otp: %s: socket: %s", __func__, strerror(errno));