]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - helpers/digest_auth/LDAP/digest_pw_auth.cc
SourceFormat Enforcement
[thirdparty/squid.git] / helpers / digest_auth / LDAP / digest_pw_auth.cc
index a83ac45bd442da8d6f323eca3ddc092fdaadf173..18dc93d39c68e469a2845039878e6dcc7f7cd359 100644 (file)
@@ -1,8 +1,14 @@
 /*
- * digest_pw_auth.c
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
  *
- * AUTHOR: Robert Collins. Based on ncsa_auth.c by Arjan de Vet
- * <Arjan.deVet@adv.iae.nl>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+/*
+ * AUTHOR: Robert Collins.
+ * Based on ncsa_auth.c by Arjan de Vet <Arjan.deVet@adv.iae.nl>
  * LDAP backend extension by Flavio Pescuma, MARA Systems AB <flavio@marasystems.com>
  *
  * Example digest authentication program for Squid, based on the original
  *
  * Copyright (c) 2003  Robert Collins  <robertc@squid-cache.org>
  */
-#include "config.h"
+
+#include "squid.h"
 #include "digest_common.h"
 #include "helpers/defines.h"
 #include "ldap_backend.h"
 
 #define PROGRAM_NAME "digest_ldap_auth"
 
-
 static void
 GetHHA1(RequestData * requestData)
 {
@@ -49,7 +55,15 @@ ParseBuffer(char *buf, RequestData * requestData)
     char *p;
     requestData->parsed = 0;
     if ((p = strchr(buf, '\n')) != NULL)
-        *p = '\0';             /* strip \n */
+        *p = '\0';      /* strip \n */
+
+    p = NULL;
+    requestData->channelId = strtoll(buf, &p, 10);
+    if (*p != ' ') // not a channel-ID
+        requestData->channelId = -1;
+    else
+        buf = ++p;
+
     if ((requestData->user = strtok(buf, "\"")) == NULL)
         return;
     if ((requestData->realm = strtok(NULL, "\"")) == NULL)
@@ -64,11 +78,13 @@ OutputHHA1(RequestData * requestData)
 {
     requestData->error = 0;
     GetHHA1(requestData);
+    if (requestData->channelId >= 0)
+        printf("%u ", requestData->channelId);
     if (requestData->error) {
-        SEND_ERR("No such user");
+        SEND_ERR("message=\"No such user\"");
         return;
     }
-    printf("%s\n", requestData->HHA1);
+    printf("OK ha1=\"%s\"\n", requestData->HHA1);
 }
 
 static void
@@ -77,7 +93,9 @@ DoOneRequest(char *buf)
     RequestData requestData;
     ParseBuffer(buf, &requestData);
     if (!requestData.parsed) {
-        SEND_ERR("");
+        if (requestData.channelId >= 0)
+            printf("%u ", requestData.channelId);
+        SEND_BH("message=\"Invalid line received\"");
         return;
     }
     OutputHHA1(&requestData);
@@ -102,3 +120,4 @@ main(int argc, char **argv)
         DoOneRequest(buf);
     exit(0);
 }
+