gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12710 - libmicrohttpd/src/daemon


From: gnunet
Subject: [GNUnet-SVN] r12710 - libmicrohttpd/src/daemon
Date: Sun, 22 Aug 2010 16:57:21 +0200

Author: grothoff
Date: 2010-08-22 16:57:21 +0200 (Sun, 22 Aug 2010)
New Revision: 12710

Modified:
   libmicrohttpd/src/daemon/digestauth.c
Log:
some cleanup

Modified: libmicrohttpd/src/daemon/digestauth.c
===================================================================
--- libmicrohttpd/src/daemon/digestauth.c       2010-08-22 14:49:48 UTC (rev 
12709)
+++ libmicrohttpd/src/daemon/digestauth.c       2010-08-22 14:57:21 UTC (rev 
12710)
@@ -36,12 +36,7 @@
 #define HASH_MD5_HEX_LEN 32
 #define HASH_SHA1_HEX_LEN 40
 
-#define _OPAQUE        "opaque=\"11733b200778ce33060f31c9af70a870ba96ddd4\""
-#define _QOP           "qop=\"auth\""
-#define _STALE         "stale=true"
 #define _BASE          "Digest "
-#define _REALM         "realm="
-#define _NONCE         "nonce="
 
 /* convert bin to hex */
 static void
@@ -552,45 +547,32 @@
        /*
         * Building the authentication header
         */
-
-       /* 4(single quotes) + 3(commas) + NULL = 8 */
-       hlen = strlen(_BASE) + strlen(_REALM) + strlen(realm) +
-               strlen(_QOP) + strlen(_NONCE) + strlen(nonce) +
-               strlen(_OPAQUE) + 8;
-
-       /* 1(comma for stale=true) */
-       if (signal_stale)
-               hlen += strlen(_STALE) + 1;
-
-       header = malloc(hlen);
-
-       if (header == NULL) return MHD_NO;
-
-       snprintf(header, hlen,
-                       "%s%s\"%s\",%s,%s\"%s\",%s",
-                       _BASE, _REALM, realm, _QOP,
-                       _NONCE, nonce, _OPAQUE);
-
-       /* Add "stale=true" to the authentication header if nonce is invalid */
-       if (signal_stale) {
-               strncat(header, ",", 1);
-               strncat(header, _STALE, strlen(_STALE));
+       hlen = snprintf(NULL,
+                       0,
+                       "Digest 
realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s",
+                       realm, 
+                       nonce,
+                       opaque,
+                       signal_stale ? ",stale=true" : "");
+       {
+         char header[hlen + 1];
+         snprintf(header,
+                  sizeof(header),
+                  "Digest 
realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s",
+                  realm, 
+                  nonce,
+                  opaque,
+                  signal_stale ? ",stale=true" : "");
+         ret = MHD_add_response_header(response,
+                                       MHD_HTTP_HEADER_WWW_AUTHENTICATE, 
+                                       header);
        }
+       if(!ret) 
+         {
+           MHD_destroy_response(response);
+           return MHD_NO;
+         }
 
-       /*
-        * Sending response with authentication header
-        */
-
-       ret = MHD_add_response_header(response,
-                       MHD_HTTP_HEADER_WWW_AUTHENTICATE, header);
-
-       free(header);
-
-       if(!ret) {
-               MHD_destroy_response(response);
-               return MHD_NO;
-       }
-
        ret = MHD_queue_response(connection, MHD_HTTP_UNAUTHORIZED, response);
 
        MHD_destroy_response(response);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]