2 * Copyright (C) 1996-2023 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 * MSNT - Microsoft Windows NT domain squid authenticator module
11 * Version 2.0 by Stellar-X Pty Ltd, Antonino Iannella
12 * Sun Sep 2 14:39:53 CST 2001
14 * Modified to act as a Squid authenticator module.
15 * Removed all Pike stuff.
16 * Returns OK for a successful authentication, or ERR upon error.
19 * Andrew Tridgell 1997
22 * Duane Wessels 2000 (wessels@squid-cache.org)
24 * Released under GNU Public License
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51 #include "auth/basic/SMB_LM/msntauth.h"
52 #include "auth/basic/SMB_LM/valid.h"
54 static char msntauth_version
[] = "Msntauth v3.0.0 (C) 2 Sep 2001 Stellar-X Antonino Iannella.\nModified by the Squid HTTP Proxy team 2002-2014";
56 struct domaincontroller
{
60 typedef std::vector
<domaincontroller
> domaincontrollers_t
;
61 domaincontrollers_t domaincontrollers
;
64 validate_user(char *username
, char *password
)
66 for (domaincontrollers_t::iterator dc
= domaincontrollers
.begin(); dc
!= domaincontrollers
.end(); ++dc
) {
67 //std::cerr << "testing against " << dc->server << std::endl;
68 const int rv
= Valid_User(username
, password
, dc
->server
.c_str(), NULL
, dc
->domain
.c_str());
69 //std::cerr << "check result: " << rv << std::endl;
70 if (rv
== NTV_NO_ERROR
)
76 static char instructions
[] = "Usage instructions: basic_nsnt_auth <domainname>/<domaincontroller> [<domainname>/<domaincontroller> ...]";
78 display_usage_instructions()
81 std::cerr
<< msntauth_version
<< endl
<< instructions
<< endl
<< endl
;
84 // arguments: domain/server_name [domain/server_name ...]
86 main(int argc
, char **argv
)
93 openlog("basic_smb_lm_auth", LOG_PID
, LOG_USER
);
96 for (int j
= 1; j
< argc
; ++j
) {
97 std::string arg
= argv
[j
];
98 size_t pos
=arg
.find('/');
99 if (arg
.find('/',pos
+1) != std::string::npos
) {
100 std::cerr
<< "Error: can't understand domain controller specification '"
101 << arg
<< "'. Ignoring" << std::endl
;
104 dc
.domain
= arg
.substr(0,pos
);
105 dc
.server
= arg
.substr(pos
+1);
106 if (dc
.domain
.length() == 0 || dc
.server
.length() == 0) {
107 std::cerr
<< "Error: invalid domain specification in '" << arg
<<
108 "'. Ignoring." << std::endl
;
111 domaincontrollers
.push_back(dc
);
113 if (domaincontrollers
.empty()) {
114 display_usage_instructions();
115 std::cerr
<< "Error: no domain controllers specified" << std::endl
;
121 /* Read whole line from standard input. Terminate on break. */
122 memset(wstr
, '\0', sizeof(wstr
));
123 if (fgets(wstr
, 255, stdin
) == NULL
)
125 /* ignore this line if we didn't get the end-of-line marker */
126 if (NULL
== strchr(wstr
, '\n')) {
131 syslog(LOG_WARNING
, "oversized message");
138 * extract username and password.
142 n
= sscanf(wstr
, "%s %[^\n]", username
, password
);
147 /* Check for invalid or blank entries */
148 if ((username
[0] == '\0') || (password
[0] == '\0')) {
153 rfc1738_unescape(username
);
154 rfc1738_unescape(password
);
156 if (validate_user(username
, password
)) {
159 syslog(LOG_INFO
, "'%s' login failed", username
);