]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/digest_auth/LDAP/digest_pw_auth.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
10 * AUTHOR: Robert Collins.
11 * Based on ncsa_auth.c by Arjan de Vet <Arjan.deVet@adv.iae.nl>
12 * LDAP backend extension by Flavio Pescuma, MARA Systems AB <flavio@marasystems.com>
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>.
18 * - comment lines are possible and should start with a '#';
19 * - empty or blank lines are possible;
20 * - file format is username:password
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
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
33 * they allow the user access. Password syncronisation is not tackled
34 * by digest - just preventing on the wire compromise.
36 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
40 #include "digest_common.h"
41 #include "helpers/defines.h"
42 #include "ldap_backend.h"
44 #define PROGRAM_NAME "digest_ldap_auth"
47 GetHHA1(RequestData
* requestData
)
49 LDAPHHA1(requestData
);
53 ParseBuffer(char *buf
, RequestData
* requestData
)
56 requestData
->parsed
= 0;
57 if ((p
= strchr(buf
, '\n')) != NULL
)
58 *p
= '\0'; /* strip \n */
61 requestData
->channelId
= strtoll(buf
, &p
, 10);
62 if (*p
!= ' ') // not a channel-ID
63 requestData
->channelId
= -1;
67 if ((requestData
->user
= strtok(buf
, "\"")) == NULL
)
69 if ((requestData
->realm
= strtok(NULL
, "\"")) == NULL
)
71 if ((requestData
->realm
= strtok(NULL
, "\"")) == NULL
)
73 requestData
->parsed
= -1;
77 OutputHHA1(RequestData
* requestData
)
79 requestData
->error
= 0;
81 if (requestData
->channelId
>= 0)
82 printf("%u ", requestData
->channelId
);
83 if (requestData
->error
) {
84 SEND_ERR("message=\"No such user\"");
87 printf("OK ha1=\"%s\"\n", requestData
->HHA1
);
91 DoOneRequest(char *buf
)
93 RequestData requestData
;
94 ParseBuffer(buf
, &requestData
);
95 if (!requestData
.parsed
) {
96 if (requestData
.channelId
>= 0)
97 printf("%u ", requestData
.channelId
);
98 SEND_BH("message=\"Invalid line received\"");
101 OutputHHA1(&requestData
);
105 ProcessArguments(int argc
, char **argv
)
108 i
= LDAPArguments(argc
, argv
);
114 main(int argc
, char **argv
)
116 char buf
[HELPER_INPUT_BUFFER
];
117 setbuf(stdout
, NULL
);
118 ProcessArguments(argc
, argv
);
119 while (fgets(buf
, HELPER_INPUT_BUFFER
, stdin
) != NULL
)