[Openvas-commits] r5678 - in trunk/gsa: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 23 07:56:32 CEST 2009


Author: jan
Date: 2009-10-23 07:56:31 +0200 (Fri, 23 Oct 2009)
New Revision: 5678

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad.c
Log:
* src/gsad.c (send_http_authenticate_header): New.



Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2009-10-22 22:31:08 UTC (rev 5677)
+++ trunk/gsa/ChangeLog	2009-10-23 05:56:31 UTC (rev 5678)
@@ -1,3 +1,7 @@
+2009-10-23  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
+
+	* src/gsad.c (send_http_authenticate_header): New.
+
 2009-10-22  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
 
 	* src/gsad.c (gsad_cleanup, main): Factored out pidfile management.

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2009-10-22 22:31:08 UTC (rev 5677)
+++ trunk/gsa/src/gsad.c	2009-10-23 05:56:31 UTC (rev 5678)
@@ -44,6 +44,48 @@
 #include <openvas/base/pidfile.h>
 
 /**
+ * @brief Sends HTTP header requesting the browser to authenticate itself.
+ *
+ * @param connection The connection object.
+ *
+ * @param realm Name of the realm that was authenticated for.
+ *
+ * @return MHD_NO in case of an error. Else the result of queueing
+ *         the response.
+ */
+int
+send_http_authenticate_header (struct MHD_Connection *connection,
+                               const char *realm)
+{
+  int ret;
+  gchar *headervalue;
+  struct MHD_Response *response =
+    MHD_create_response_from_data (0, NULL, MHD_NO, MHD_NO);
+
+  if (!response)
+    return MHD_NO;
+
+  headervalue = g_strconcat ("Basic realm=", realm, NULL);
+  if (!headervalue)
+    {
+      MHD_destroy_response (response);
+      return MHD_NO;
+    }
+
+  ret = MHD_add_response_header (response, "WWW-Authenticate", headervalue);
+  g_free (headervalue);
+  if (!ret)
+    {
+      MHD_destroy_response (response);
+      return MHD_NO;
+    }
+
+  ret = MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response);
+  MHD_destroy_response (response);
+  return ret;
+}
+
+/**
  * @brief HTTP request handler for GSAD.
  *
  * @param[in]  cls              Not used for this callback. 



More information about the Openvas-commits mailing list