]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/digest/eDirectory/digest_pw_auth.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / auth / digest / eDirectory / digest_pw_auth.cc
CommitLineData
89f77e43 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
89f77e43 3 *
ca02e0ec
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/*
89f77e43 10 * AUTHOR: Robert Collins. Based on ncsa_auth.c by Arjan de Vet
11 * <Arjan.deVet@adv.iae.nl>
12 * LDAP backend extension by Flavio Pescuma, MARA Systems AB <flavio@marasystems.com>
13 *
14 * Example digest authentication program for Squid, based on the original
15 * proxy_auth code from client_side.c, written by
16 * Jon Thackray <jrmt@uk.gdscorp.com>.
17 *
18 * - comment lines are possible and should start with a '#';
19 * - empty or blank lines are possible;
20 * - file format is username:password
26ac0430 21 *
89f77e43 22 * To build a directory integrated backend, you need to be able to
23 * calculate the HA1 returned to squid. To avoid storing a plaintext
24 * password you can calculate MD5(username:realm:password) when the
25 * user changes their password, and store the tuple username:realm:HA1.
26 * then find the matching username:realm when squid asks for the
27 * HA1.
28 *
29 * This implementation could be improved by using such a triple for
30 * the file format. However storing such a triple does little to
31 * improve security: If compromised the username:realm:HA1 combination
32 * is "plaintext equivalent" - for the purposes of digest authentication
2b61af8e 33 * they allow the user access. Password synchronization is not tackled
89f77e43 34 * by digest - just preventing on the wire compromise.
35 *
36 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
37 */
f7f3304a 38#include "squid.h"
d4d7f6dd
AJ
39#include "auth/digest/eDirectory/digest_common.h"
40#include "auth/digest/eDirectory/ldap_backend.h"
079b1d0f 41#include "helper/protocol_defines.h"
89f77e43 42
56ff4687 43#define PROGRAM_NAME "digest_edirectory_auth"
89f77e43 44
e9505fad 45static void
89f77e43 46GetHHA1(RequestData * requestData)
47{
48 LDAPHHA1(requestData);
49}
50
51static void
52ParseBuffer(char *buf, RequestData * requestData)
53{
54 char *p;
55 requestData->parsed = 0;
aee3523a 56 if ((p = strchr(buf, '\n')) != nullptr)
f53969cc 57 *p = '\0'; /* strip \n */
6cb2818d 58
aee3523a 59 p = nullptr;
6cb2818d
AJ
60 requestData->channelId = strtoll(buf, &p, 10);
61 if (*p != ' ') // not a channel-ID
62 requestData->channelId = -1;
63 else
64 buf = ++p;
65
aee3523a 66 if ((requestData->user = strtok(buf, "\"")) == nullptr)
26ac0430 67 return;
aee3523a 68 if ((requestData->realm = strtok(nullptr, "\"")) == nullptr)
26ac0430 69 return;
aee3523a 70 if ((requestData->realm = strtok(nullptr, "\"")) == nullptr)
26ac0430 71 return;
89f77e43 72 requestData->parsed = -1;
73}
74
75static void
76OutputHHA1(RequestData * requestData)
77{
78 requestData->error = 0;
79 GetHHA1(requestData);
6cb2818d
AJ
80 if (requestData->channelId >= 0)
81 printf("%u ", requestData->channelId);
89f77e43 82 if (requestData->error) {
c69199bb 83 SEND_ERR("message=\"No such user\"");
26ac0430 84 return;
89f77e43 85 }
c69199bb 86 printf("OK ha1=\"%s\"\n", requestData->HHA1);
89f77e43 87}
88
89static void
90DoOneRequest(char *buf)
91{
92 RequestData requestData;
93 ParseBuffer(buf, &requestData);
94 if (!requestData.parsed) {
6cb2818d
AJ
95 if (requestData.channelId >= 0)
96 printf("%u ", requestData.channelId);
c69199bb 97 SEND_BH("message=\"Invalid line received\"");
26ac0430 98 return;
89f77e43 99 }
100 OutputHHA1(&requestData);
101}
102
e9505fad 103static void
89f77e43 104ProcessArguments(int argc, char **argv)
105{
24885773 106 if (int i = LDAPArguments(argc, argv))
26ac0430 107 exit(i);
89f77e43 108}
109
110int
111main(int argc, char **argv)
112{
56ff4687 113 char buf[HELPER_INPUT_BUFFER];
aee3523a 114 setbuf(stdout, nullptr);
89f77e43 115 ProcessArguments(argc, argv);
aee3523a 116 while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != nullptr)
26ac0430 117 DoOneRequest(buf);
24885773 118 return EXIT_SUCCESS;
89f77e43 119}
f53969cc 120