Selaa lähdekoodia

Modified public Digest Username struct to include the algorithm

Evgeny Grin (Karlson2k) 3 vuotta sitten
vanhempi
sitoutus
2a9071b862
3 muutettua tiedostoa jossa 27 lisäystä ja 16 poistoa
  1. 10 2
      src/include/microhttpd.h
  2. 7 12
      src/microhttpd/digestauth.c
  3. 10 2
      src/testcurl/test_digestauth2.c

+ 10 - 2
src/include/microhttpd.h

@@ -96,7 +96,7 @@ extern "C"
  * they are parsed as decimal numbers.
  * Example: 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00097533
+#define MHD_VERSION 0x00097534
 
 /* If generic headers don't work on your platform, include headers
    which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t',
@@ -4911,10 +4911,18 @@ MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection);
  *
  * Application may modify buffers as needed until #MHD_free() is called for
  * pointer to this structure
- * @note Available since #MHD_VERSION 0x00097525
+ * @note Available since #MHD_VERSION 0x00097534
  */
 struct MHD_DigestAuthUsernameInfo
 {
+  /**
+   * The algorithm as defined by client.
+   * Set automatically to MD5 if not specified by client.
+   * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
+   *          which uses other values!
+   */
+  enum MHD_DigestAuthAlgo3 algo3;
+
   /**
    * The type of username used by client.
    * The 'invalid' and 'missing' types are not used in this structure,

+ 7 - 12
src/microhttpd/digestauth.c

@@ -780,7 +780,7 @@ get_rq_extended_uname_copy_z (const char *uname_ext, size_t uname_ext_len,
  * Get copy of username used by the client.
  * @param params the Digest Authorization parameters
  * @param uname_type the type of username
- * @param[out] unames the pointer to the structure to be filled
+ * @param[out] uname_info the pointer to the structure to be filled
  * @param buf the buffer to be used for usernames
  * @param buf_size the size of the @a buf
  * @return the size of the @a buf used by pointers in @a unames structure
@@ -975,17 +975,11 @@ MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection)
 
   if ( (MHD_DIGEST_AUTH_UNAME_TYPE_MISSING != uname_type) &&
        (MHD_DIGEST_AUTH_UNAME_TYPE_INVALID != uname_type) )
-  {
-    struct MHD_DigestAuthUsernameInfo uname_strct;
-    memset (&uname_strct, 0, sizeof(uname_strct));
-    unif_buf_used += get_rq_uname (params, uname_type, &uname_strct,
-                                   unif_buf_ptr + unif_buf_used,
-                                   unif_buf_size - unif_buf_used);
-    info->uname_type = uname_strct.uname_type;
-    info->username = uname_strct.username;
-    info->username_len = uname_strct.username_len;
-    info->userhash_bin = uname_strct.userhash_bin;
-  }
+    unif_buf_used +=
+      get_rq_uname (params, uname_type,
+                    (struct MHD_DigestAuthUsernameInfo *) info,
+                    unif_buf_ptr + unif_buf_used,
+                    unif_buf_size - unif_buf_used);
   else
     info->uname_type = uname_type;
 
@@ -1072,6 +1066,7 @@ MHD_digest_auth_get_username3 (struct MHD_Connection *connection)
     return NULL;
   }
   mhd_assert (uname_type == uname_info->uname_type);
+  uname_info->algo3 = params->algo3;
 
   return uname_info;
 }

+ 10 - 2
src/testcurl/test_digestauth2.c

@@ -550,11 +550,11 @@ ahc_echo (void *cls,
       }
       if (algo3 != dinfo->algo3)
       {
-        fprintf (stderr, "Unexpected 'algo'.\n"
+        fprintf (stderr, "Unexpected 'algo3'.\n"
                  "Expected: %d\tRecieved: %d. ",
                  (int) algo3,
                  (int) dinfo->algo3);
-        mhdErrorExitDesc ("Wrong 'algo'");
+        mhdErrorExitDesc ("Wrong 'algo3'");
       }
       if (! test_rfc2069)
       {
@@ -692,6 +692,14 @@ ahc_echo (void *cls,
         else if (NULL != uname->userhash_bin)
           mhdErrorExitDesc ("'userhash_bin' is NOT NULL");
       }
+      if (algo3 != uname->algo3)
+      {
+        fprintf (stderr, "Unexpected 'algo3'.\n"
+                 "Expected: %d\tRecieved: %d. ",
+                 (int) algo3,
+                 (int) uname->algo3);
+        mhdErrorExitDesc ("Wrong 'algo3'");
+      }
       MHD_free (uname);
 
       if (! test_userdigest)