| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | Winbind status program.
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Tim Potter 2000-2003
|
|---|
| 7 | Copyright (C) Andrew Bartlett <[email protected]> 2003-2004
|
|---|
| 8 | Copyright (C) Francesco Chemolli <[email protected]> 2000
|
|---|
| 9 | Copyright (C) Robert O'Callahan 2006 (added cached credential code).
|
|---|
| 10 | Copyright (C) Kai Blin <[email protected]> 2008
|
|---|
| 11 |
|
|---|
| 12 | This program is free software; you can redistribute it and/or modify
|
|---|
| 13 | it under the terms of the GNU General Public License as published by
|
|---|
| 14 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 15 | (at your option) any later version.
|
|---|
| 16 |
|
|---|
| 17 | This program is distributed in the hope that it will be useful,
|
|---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 20 | GNU General Public License for more details.
|
|---|
| 21 |
|
|---|
| 22 | You should have received a copy of the GNU General Public License
|
|---|
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | #include "includes.h"
|
|---|
| 27 | #include "utils/ntlm_auth.h"
|
|---|
| 28 | #include "../libcli/auth/libcli_auth.h"
|
|---|
| 29 | #include "../libcli/auth/spnego.h"
|
|---|
| 30 | #include "smb_krb5.h"
|
|---|
| 31 | #include <iniparser.h>
|
|---|
| 32 |
|
|---|
| 33 | #ifndef PAM_WINBIND_CONFIG_FILE
|
|---|
| 34 | #define PAM_WINBIND_CONFIG_FILE "/etc/security/pam_winbind.conf"
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | #define WINBIND_KRB5_AUTH 0x00000080
|
|---|
| 38 |
|
|---|
| 39 | #undef DBGC_CLASS
|
|---|
| 40 | #define DBGC_CLASS DBGC_WINBIND
|
|---|
| 41 |
|
|---|
| 42 | #define INITIAL_BUFFER_SIZE 300
|
|---|
| 43 | #define MAX_BUFFER_SIZE 630000
|
|---|
| 44 |
|
|---|
| 45 | enum stdio_helper_mode {
|
|---|
| 46 | SQUID_2_4_BASIC,
|
|---|
| 47 | SQUID_2_5_BASIC,
|
|---|
| 48 | SQUID_2_5_NTLMSSP,
|
|---|
| 49 | NTLMSSP_CLIENT_1,
|
|---|
| 50 | GSS_SPNEGO,
|
|---|
| 51 | GSS_SPNEGO_CLIENT,
|
|---|
| 52 | NTLM_SERVER_1,
|
|---|
| 53 | NTLM_CHANGE_PASSWORD_1,
|
|---|
| 54 | NUM_HELPER_MODES
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | enum ntlm_auth_cli_state {
|
|---|
| 58 | CLIENT_INITIAL = 0,
|
|---|
| 59 | CLIENT_RESPONSE,
|
|---|
| 60 | CLIENT_FINISHED,
|
|---|
| 61 | CLIENT_ERROR
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | enum ntlm_auth_svr_state {
|
|---|
| 65 | SERVER_INITIAL = 0,
|
|---|
| 66 | SERVER_CHALLENGE,
|
|---|
| 67 | SERVER_FINISHED,
|
|---|
| 68 | SERVER_ERROR
|
|---|
| 69 | };
|
|---|
| 70 |
|
|---|
| 71 | struct ntlm_auth_state {
|
|---|
| 72 | TALLOC_CTX *mem_ctx;
|
|---|
| 73 | enum stdio_helper_mode helper_mode;
|
|---|
| 74 | enum ntlm_auth_cli_state cli_state;
|
|---|
| 75 | enum ntlm_auth_svr_state svr_state;
|
|---|
| 76 | struct ntlmssp_state *ntlmssp_state;
|
|---|
| 77 | uint32_t neg_flags;
|
|---|
| 78 | char *want_feature_list;
|
|---|
| 79 | bool have_session_key;
|
|---|
| 80 | DATA_BLOB session_key;
|
|---|
| 81 | DATA_BLOB initial_message;
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|
| 84 | typedef void (*stdio_helper_function)(struct ntlm_auth_state *state, char *buf,
|
|---|
| 85 | int length);
|
|---|
| 86 |
|
|---|
| 87 | static void manage_squid_basic_request (struct ntlm_auth_state *state,
|
|---|
| 88 | char *buf, int length);
|
|---|
| 89 |
|
|---|
| 90 | static void manage_squid_ntlmssp_request (struct ntlm_auth_state *state,
|
|---|
| 91 | char *buf, int length);
|
|---|
| 92 |
|
|---|
| 93 | static void manage_client_ntlmssp_request (struct ntlm_auth_state *state,
|
|---|
| 94 | char *buf, int length);
|
|---|
| 95 |
|
|---|
| 96 | static void manage_gss_spnego_request (struct ntlm_auth_state *state,
|
|---|
| 97 | char *buf, int length);
|
|---|
| 98 |
|
|---|
| 99 | static void manage_gss_spnego_client_request (struct ntlm_auth_state *state,
|
|---|
| 100 | char *buf, int length);
|
|---|
| 101 |
|
|---|
| 102 | static void manage_ntlm_server_1_request (struct ntlm_auth_state *state,
|
|---|
| 103 | char *buf, int length);
|
|---|
| 104 |
|
|---|
| 105 | static void manage_ntlm_change_password_1_request(struct ntlm_auth_state *state,
|
|---|
| 106 | char *buf, int length);
|
|---|
| 107 |
|
|---|
| 108 | static const struct {
|
|---|
| 109 | enum stdio_helper_mode mode;
|
|---|
| 110 | const char *name;
|
|---|
| 111 | stdio_helper_function fn;
|
|---|
| 112 | } stdio_helper_protocols[] = {
|
|---|
| 113 | { SQUID_2_4_BASIC, "squid-2.4-basic", manage_squid_basic_request},
|
|---|
| 114 | { SQUID_2_5_BASIC, "squid-2.5-basic", manage_squid_basic_request},
|
|---|
| 115 | { SQUID_2_5_NTLMSSP, "squid-2.5-ntlmssp", manage_squid_ntlmssp_request},
|
|---|
| 116 | { NTLMSSP_CLIENT_1, "ntlmssp-client-1", manage_client_ntlmssp_request},
|
|---|
| 117 | { GSS_SPNEGO, "gss-spnego", manage_gss_spnego_request},
|
|---|
| 118 | { GSS_SPNEGO_CLIENT, "gss-spnego-client", manage_gss_spnego_client_request},
|
|---|
| 119 | { NTLM_SERVER_1, "ntlm-server-1", manage_ntlm_server_1_request},
|
|---|
| 120 | { NTLM_CHANGE_PASSWORD_1, "ntlm-change-password-1", manage_ntlm_change_password_1_request},
|
|---|
| 121 | { NUM_HELPER_MODES, NULL, NULL}
|
|---|
| 122 | };
|
|---|
| 123 |
|
|---|
| 124 | const char *opt_username;
|
|---|
| 125 | const char *opt_domain;
|
|---|
| 126 | const char *opt_workstation;
|
|---|
| 127 | const char *opt_password;
|
|---|
| 128 | static DATA_BLOB opt_challenge;
|
|---|
| 129 | static DATA_BLOB opt_lm_response;
|
|---|
| 130 | static DATA_BLOB opt_nt_response;
|
|---|
| 131 | static int request_lm_key;
|
|---|
| 132 | static int request_user_session_key;
|
|---|
| 133 | static int use_cached_creds;
|
|---|
| 134 |
|
|---|
| 135 | static const char *require_membership_of;
|
|---|
| 136 | static const char *require_membership_of_sid;
|
|---|
| 137 | static const char *opt_pam_winbind_conf;
|
|---|
| 138 |
|
|---|
| 139 | static char winbind_separator(void)
|
|---|
| 140 | {
|
|---|
| 141 | struct winbindd_response response;
|
|---|
| 142 | static bool got_sep;
|
|---|
| 143 | static char sep;
|
|---|
| 144 |
|
|---|
| 145 | if (got_sep)
|
|---|
| 146 | return sep;
|
|---|
| 147 |
|
|---|
| 148 | ZERO_STRUCT(response);
|
|---|
| 149 |
|
|---|
| 150 | /* Send off request */
|
|---|
| 151 |
|
|---|
| 152 | if (winbindd_request_response(WINBINDD_INFO, NULL, &response) !=
|
|---|
| 153 | NSS_STATUS_SUCCESS) {
|
|---|
| 154 | d_printf("could not obtain winbind separator!\n");
|
|---|
| 155 | return *lp_winbind_separator();
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | sep = response.data.info.winbind_separator;
|
|---|
| 159 | got_sep = True;
|
|---|
| 160 |
|
|---|
| 161 | if (!sep) {
|
|---|
| 162 | d_printf("winbind separator was NULL!\n");
|
|---|
| 163 | return *lp_winbind_separator();
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | return sep;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | const char *get_winbind_domain(void)
|
|---|
| 170 | {
|
|---|
| 171 | struct winbindd_response response;
|
|---|
| 172 |
|
|---|
| 173 | static fstring winbind_domain;
|
|---|
| 174 | if (*winbind_domain) {
|
|---|
| 175 | return winbind_domain;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | ZERO_STRUCT(response);
|
|---|
| 179 |
|
|---|
| 180 | /* Send off request */
|
|---|
| 181 |
|
|---|
| 182 | if (winbindd_request_response(WINBINDD_DOMAIN_NAME, NULL, &response) !=
|
|---|
| 183 | NSS_STATUS_SUCCESS) {
|
|---|
| 184 | DEBUG(0, ("could not obtain winbind domain name!\n"));
|
|---|
| 185 | return lp_workgroup();
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | fstrcpy(winbind_domain, response.data.domain_name);
|
|---|
| 189 |
|
|---|
| 190 | return winbind_domain;
|
|---|
| 191 |
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | const char *get_winbind_netbios_name(void)
|
|---|
| 195 | {
|
|---|
| 196 | struct winbindd_response response;
|
|---|
| 197 |
|
|---|
| 198 | static fstring winbind_netbios_name;
|
|---|
| 199 |
|
|---|
| 200 | if (*winbind_netbios_name) {
|
|---|
| 201 | return winbind_netbios_name;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | ZERO_STRUCT(response);
|
|---|
| 205 |
|
|---|
| 206 | /* Send off request */
|
|---|
| 207 |
|
|---|
| 208 | if (winbindd_request_response(WINBINDD_NETBIOS_NAME, NULL, &response) !=
|
|---|
| 209 | NSS_STATUS_SUCCESS) {
|
|---|
| 210 | DEBUG(0, ("could not obtain winbind netbios name!\n"));
|
|---|
| 211 | return global_myname();
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | fstrcpy(winbind_netbios_name, response.data.netbios_name);
|
|---|
| 215 |
|
|---|
| 216 | return winbind_netbios_name;
|
|---|
| 217 |
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | DATA_BLOB get_challenge(void)
|
|---|
| 221 | {
|
|---|
| 222 | static DATA_BLOB chal;
|
|---|
| 223 | if (opt_challenge.length)
|
|---|
| 224 | return opt_challenge;
|
|---|
| 225 |
|
|---|
| 226 | chal = data_blob(NULL, 8);
|
|---|
| 227 |
|
|---|
| 228 | generate_random_buffer(chal.data, chal.length);
|
|---|
| 229 | return chal;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
|
|---|
| 233 | form DOMAIN/user into a domain and a user */
|
|---|
| 234 |
|
|---|
| 235 | static bool parse_ntlm_auth_domain_user(const char *domuser, fstring domain,
|
|---|
| 236 | fstring user)
|
|---|
| 237 | {
|
|---|
| 238 |
|
|---|
| 239 | char *p = strchr(domuser,winbind_separator());
|
|---|
| 240 |
|
|---|
| 241 | if (!p) {
|
|---|
| 242 | return False;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | fstrcpy(user, p+1);
|
|---|
| 246 | fstrcpy(domain, domuser);
|
|---|
| 247 | domain[PTR_DIFF(p, domuser)] = 0;
|
|---|
| 248 | strupper_m(domain);
|
|---|
| 249 |
|
|---|
| 250 | return True;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | static bool get_require_membership_sid(void) {
|
|---|
| 254 | struct winbindd_request request;
|
|---|
| 255 | struct winbindd_response response;
|
|---|
| 256 |
|
|---|
| 257 | if (!require_membership_of) {
|
|---|
| 258 | return True;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | if (require_membership_of_sid) {
|
|---|
| 262 | return True;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | /* Otherwise, ask winbindd for the name->sid request */
|
|---|
| 266 |
|
|---|
| 267 | ZERO_STRUCT(request);
|
|---|
| 268 | ZERO_STRUCT(response);
|
|---|
| 269 |
|
|---|
| 270 | if (!parse_ntlm_auth_domain_user(require_membership_of,
|
|---|
| 271 | request.data.name.dom_name,
|
|---|
| 272 | request.data.name.name)) {
|
|---|
| 273 | DEBUG(0, ("Could not parse %s into seperate domain/name parts!\n",
|
|---|
| 274 | require_membership_of));
|
|---|
| 275 | return False;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
|
|---|
| 279 | NSS_STATUS_SUCCESS) {
|
|---|
| 280 | DEBUG(0, ("Winbindd lookupname failed to resolve %s into a SID!\n",
|
|---|
| 281 | require_membership_of));
|
|---|
| 282 | return False;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | require_membership_of_sid = SMB_STRDUP(response.data.sid.sid);
|
|---|
| 286 |
|
|---|
| 287 | if (require_membership_of_sid)
|
|---|
| 288 | return True;
|
|---|
| 289 |
|
|---|
| 290 | return False;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | /*
|
|---|
| 294 | * Get some configuration from pam_winbind.conf to see if we
|
|---|
| 295 | * need to contact trusted domain
|
|---|
| 296 | */
|
|---|
| 297 |
|
|---|
| 298 | int get_pam_winbind_config()
|
|---|
| 299 | {
|
|---|
| 300 | int ctrl = 0;
|
|---|
| 301 | dictionary *d = NULL;
|
|---|
| 302 |
|
|---|
| 303 | if (!opt_pam_winbind_conf || !*opt_pam_winbind_conf) {
|
|---|
| 304 | opt_pam_winbind_conf = PAM_WINBIND_CONFIG_FILE;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | d = iniparser_load(CONST_DISCARD(char *, opt_pam_winbind_conf));
|
|---|
| 308 |
|
|---|
| 309 | if (!d) {
|
|---|
| 310 | return 0;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | if (iniparser_getboolean(d, CONST_DISCARD(char *, "global:krb5_auth"), false)) {
|
|---|
| 314 | ctrl |= WINBIND_KRB5_AUTH;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | iniparser_freedict(d);
|
|---|
| 318 |
|
|---|
| 319 | return ctrl;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | /* Authenticate a user with a plaintext password */
|
|---|
| 323 |
|
|---|
| 324 | static bool check_plaintext_auth(const char *user, const char *pass,
|
|---|
| 325 | bool stdout_diagnostics)
|
|---|
| 326 | {
|
|---|
| 327 | struct winbindd_request request;
|
|---|
| 328 | struct winbindd_response response;
|
|---|
| 329 | NSS_STATUS result;
|
|---|
| 330 |
|
|---|
| 331 | if (!get_require_membership_sid()) {
|
|---|
| 332 | return False;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | /* Send off request */
|
|---|
| 336 |
|
|---|
| 337 | ZERO_STRUCT(request);
|
|---|
| 338 | ZERO_STRUCT(response);
|
|---|
| 339 |
|
|---|
| 340 | fstrcpy(request.data.auth.user, user);
|
|---|
| 341 | fstrcpy(request.data.auth.pass, pass);
|
|---|
| 342 | if (require_membership_of_sid) {
|
|---|
| 343 | strlcpy(request.data.auth.require_membership_of_sid,
|
|---|
| 344 | require_membership_of_sid,
|
|---|
| 345 | sizeof(request.data.auth.require_membership_of_sid));
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
|
|---|
| 349 |
|
|---|
| 350 | /* Display response */
|
|---|
| 351 |
|
|---|
| 352 | if (stdout_diagnostics) {
|
|---|
| 353 | if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
|
|---|
| 354 | d_printf("Reading winbind reply failed! (0x01)\n");
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | d_printf("%s: %s (0x%x)\n",
|
|---|
| 358 | response.data.auth.nt_status_string,
|
|---|
| 359 | response.data.auth.error_string,
|
|---|
| 360 | response.data.auth.nt_status);
|
|---|
| 361 | } else {
|
|---|
| 362 | if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
|
|---|
| 363 | DEBUG(1, ("Reading winbind reply failed! (0x01)\n"));
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | DEBUG(3, ("%s: %s (0x%x)\n",
|
|---|
| 367 | response.data.auth.nt_status_string,
|
|---|
| 368 | response.data.auth.error_string,
|
|---|
| 369 | response.data.auth.nt_status));
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | return (result == NSS_STATUS_SUCCESS);
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | /* authenticate a user with an encrypted username/password */
|
|---|
| 376 |
|
|---|
| 377 | NTSTATUS contact_winbind_auth_crap(const char *username,
|
|---|
| 378 | const char *domain,
|
|---|
| 379 | const char *workstation,
|
|---|
| 380 | const DATA_BLOB *challenge,
|
|---|
| 381 | const DATA_BLOB *lm_response,
|
|---|
| 382 | const DATA_BLOB *nt_response,
|
|---|
| 383 | uint32 flags,
|
|---|
| 384 | uint8 lm_key[8],
|
|---|
| 385 | uint8 user_session_key[16],
|
|---|
| 386 | char **error_string,
|
|---|
| 387 | char **unix_name)
|
|---|
| 388 | {
|
|---|
| 389 | NTSTATUS nt_status;
|
|---|
| 390 | NSS_STATUS result;
|
|---|
| 391 | struct winbindd_request request;
|
|---|
| 392 | struct winbindd_response response;
|
|---|
| 393 |
|
|---|
| 394 | if (!get_require_membership_sid()) {
|
|---|
| 395 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | ZERO_STRUCT(request);
|
|---|
| 399 | ZERO_STRUCT(response);
|
|---|
| 400 |
|
|---|
| 401 | request.flags = flags;
|
|---|
| 402 |
|
|---|
| 403 | request.data.auth_crap.logon_parameters = MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT | MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
|
|---|
| 404 |
|
|---|
| 405 | if (require_membership_of_sid)
|
|---|
| 406 | fstrcpy(request.data.auth_crap.require_membership_of_sid, require_membership_of_sid);
|
|---|
| 407 |
|
|---|
| 408 | fstrcpy(request.data.auth_crap.user, username);
|
|---|
| 409 | fstrcpy(request.data.auth_crap.domain, domain);
|
|---|
| 410 |
|
|---|
| 411 | fstrcpy(request.data.auth_crap.workstation,
|
|---|
| 412 | workstation);
|
|---|
| 413 |
|
|---|
| 414 | memcpy(request.data.auth_crap.chal, challenge->data, MIN(challenge->length, 8));
|
|---|
| 415 |
|
|---|
| 416 | if (lm_response && lm_response->length) {
|
|---|
| 417 | memcpy(request.data.auth_crap.lm_resp,
|
|---|
| 418 | lm_response->data,
|
|---|
| 419 | MIN(lm_response->length, sizeof(request.data.auth_crap.lm_resp)));
|
|---|
| 420 | request.data.auth_crap.lm_resp_len = lm_response->length;
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | if (nt_response && nt_response->length) {
|
|---|
| 424 | if (nt_response->length > sizeof(request.data.auth_crap.nt_resp)) {
|
|---|
| 425 | request.flags = request.flags | WBFLAG_BIG_NTLMV2_BLOB;
|
|---|
| 426 | request.extra_len = nt_response->length;
|
|---|
| 427 | request.extra_data.data = SMB_MALLOC_ARRAY(char, request.extra_len);
|
|---|
| 428 | if (request.extra_data.data == NULL) {
|
|---|
| 429 | return NT_STATUS_NO_MEMORY;
|
|---|
| 430 | }
|
|---|
| 431 | memcpy(request.extra_data.data, nt_response->data,
|
|---|
| 432 | nt_response->length);
|
|---|
| 433 |
|
|---|
| 434 | } else {
|
|---|
| 435 | memcpy(request.data.auth_crap.nt_resp,
|
|---|
| 436 | nt_response->data, nt_response->length);
|
|---|
| 437 | }
|
|---|
| 438 | request.data.auth_crap.nt_resp_len = nt_response->length;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);
|
|---|
| 442 | SAFE_FREE(request.extra_data.data);
|
|---|
| 443 |
|
|---|
| 444 | /* Display response */
|
|---|
| 445 |
|
|---|
| 446 | if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
|
|---|
| 447 | nt_status = NT_STATUS_UNSUCCESSFUL;
|
|---|
| 448 | if (error_string)
|
|---|
| 449 | *error_string = smb_xstrdup("Reading winbind reply failed!");
|
|---|
| 450 | winbindd_free_response(&response);
|
|---|
| 451 | return nt_status;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | nt_status = (NT_STATUS(response.data.auth.nt_status));
|
|---|
| 455 | if (!NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 456 | if (error_string)
|
|---|
| 457 | *error_string = smb_xstrdup(response.data.auth.error_string);
|
|---|
| 458 | winbindd_free_response(&response);
|
|---|
| 459 | return nt_status;
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | if ((flags & WBFLAG_PAM_LMKEY) && lm_key) {
|
|---|
| 463 | memcpy(lm_key, response.data.auth.first_8_lm_hash,
|
|---|
| 464 | sizeof(response.data.auth.first_8_lm_hash));
|
|---|
| 465 | }
|
|---|
| 466 | if ((flags & WBFLAG_PAM_USER_SESSION_KEY) && user_session_key) {
|
|---|
| 467 | memcpy(user_session_key, response.data.auth.user_session_key,
|
|---|
| 468 | sizeof(response.data.auth.user_session_key));
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | if (flags & WBFLAG_PAM_UNIX_NAME) {
|
|---|
| 472 | *unix_name = SMB_STRDUP(response.data.auth.unix_username);
|
|---|
| 473 | if (!*unix_name) {
|
|---|
| 474 | winbindd_free_response(&response);
|
|---|
| 475 | return NT_STATUS_NO_MEMORY;
|
|---|
| 476 | }
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | winbindd_free_response(&response);
|
|---|
| 480 | return nt_status;
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | /* contact server to change user password using auth crap */
|
|---|
| 484 | static NTSTATUS contact_winbind_change_pswd_auth_crap(const char *username,
|
|---|
| 485 | const char *domain,
|
|---|
| 486 | const DATA_BLOB new_nt_pswd,
|
|---|
| 487 | const DATA_BLOB old_nt_hash_enc,
|
|---|
| 488 | const DATA_BLOB new_lm_pswd,
|
|---|
| 489 | const DATA_BLOB old_lm_hash_enc,
|
|---|
| 490 | char **error_string)
|
|---|
| 491 | {
|
|---|
| 492 | NTSTATUS nt_status;
|
|---|
| 493 | NSS_STATUS result;
|
|---|
| 494 | struct winbindd_request request;
|
|---|
| 495 | struct winbindd_response response;
|
|---|
| 496 |
|
|---|
| 497 | if (!get_require_membership_sid())
|
|---|
| 498 | {
|
|---|
| 499 | if(error_string)
|
|---|
| 500 | *error_string = smb_xstrdup("Can't get membership sid.");
|
|---|
| 501 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | ZERO_STRUCT(request);
|
|---|
| 505 | ZERO_STRUCT(response);
|
|---|
| 506 |
|
|---|
| 507 | if(username != NULL)
|
|---|
| 508 | fstrcpy(request.data.chng_pswd_auth_crap.user, username);
|
|---|
| 509 | if(domain != NULL)
|
|---|
| 510 | fstrcpy(request.data.chng_pswd_auth_crap.domain,domain);
|
|---|
| 511 |
|
|---|
| 512 | if(new_nt_pswd.length)
|
|---|
| 513 | {
|
|---|
| 514 | memcpy(request.data.chng_pswd_auth_crap.new_nt_pswd, new_nt_pswd.data, sizeof(request.data.chng_pswd_auth_crap.new_nt_pswd));
|
|---|
| 515 | request.data.chng_pswd_auth_crap.new_nt_pswd_len = new_nt_pswd.length;
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | if(old_nt_hash_enc.length)
|
|---|
| 519 | {
|
|---|
| 520 | memcpy(request.data.chng_pswd_auth_crap.old_nt_hash_enc, old_nt_hash_enc.data, sizeof(request.data.chng_pswd_auth_crap.old_nt_hash_enc));
|
|---|
| 521 | request.data.chng_pswd_auth_crap.old_nt_hash_enc_len = old_nt_hash_enc.length;
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | if(new_lm_pswd.length)
|
|---|
| 525 | {
|
|---|
| 526 | memcpy(request.data.chng_pswd_auth_crap.new_lm_pswd, new_lm_pswd.data, sizeof(request.data.chng_pswd_auth_crap.new_lm_pswd));
|
|---|
| 527 | request.data.chng_pswd_auth_crap.new_lm_pswd_len = new_lm_pswd.length;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | if(old_lm_hash_enc.length)
|
|---|
| 531 | {
|
|---|
| 532 | memcpy(request.data.chng_pswd_auth_crap.old_lm_hash_enc, old_lm_hash_enc.data, sizeof(request.data.chng_pswd_auth_crap.old_lm_hash_enc));
|
|---|
| 533 | request.data.chng_pswd_auth_crap.old_lm_hash_enc_len = old_lm_hash_enc.length;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | result = winbindd_request_response(WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, &request, &response);
|
|---|
| 537 |
|
|---|
| 538 | /* Display response */
|
|---|
| 539 |
|
|---|
| 540 | if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0))
|
|---|
| 541 | {
|
|---|
| 542 | nt_status = NT_STATUS_UNSUCCESSFUL;
|
|---|
| 543 | if (error_string)
|
|---|
| 544 | *error_string = smb_xstrdup("Reading winbind reply failed!");
|
|---|
| 545 | winbindd_free_response(&response);
|
|---|
| 546 | return nt_status;
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | nt_status = (NT_STATUS(response.data.auth.nt_status));
|
|---|
| 550 | if (!NT_STATUS_IS_OK(nt_status))
|
|---|
| 551 | {
|
|---|
| 552 | if (error_string)
|
|---|
| 553 | *error_string = smb_xstrdup(response.data.auth.error_string);
|
|---|
| 554 | winbindd_free_response(&response);
|
|---|
| 555 | return nt_status;
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | winbindd_free_response(&response);
|
|---|
| 559 |
|
|---|
| 560 | return nt_status;
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
|
|---|
| 564 | {
|
|---|
| 565 | static const char zeros[16] = { 0, };
|
|---|
| 566 | NTSTATUS nt_status;
|
|---|
| 567 | char *error_string = NULL;
|
|---|
| 568 | uint8 lm_key[8];
|
|---|
| 569 | uint8 user_sess_key[16];
|
|---|
| 570 | char *unix_name = NULL;
|
|---|
| 571 |
|
|---|
| 572 | nt_status = contact_winbind_auth_crap(ntlmssp_state->user, ntlmssp_state->domain,
|
|---|
| 573 | ntlmssp_state->workstation,
|
|---|
| 574 | &ntlmssp_state->chal,
|
|---|
| 575 | &ntlmssp_state->lm_resp,
|
|---|
| 576 | &ntlmssp_state->nt_resp,
|
|---|
| 577 | WBFLAG_PAM_LMKEY | WBFLAG_PAM_USER_SESSION_KEY | WBFLAG_PAM_UNIX_NAME,
|
|---|
| 578 | lm_key, user_sess_key,
|
|---|
| 579 | &error_string, &unix_name);
|
|---|
| 580 |
|
|---|
| 581 | if (NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 582 | if (memcmp(lm_key, zeros, 8) != 0) {
|
|---|
| 583 | *lm_session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
|
|---|
| 584 | memcpy(lm_session_key->data, lm_key, 8);
|
|---|
| 585 | memset(lm_session_key->data+8, '\0', 8);
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | if (memcmp(user_sess_key, zeros, 16) != 0) {
|
|---|
| 589 | *user_session_key = data_blob_talloc(ntlmssp_state, user_sess_key, 16);
|
|---|
| 590 | }
|
|---|
| 591 | ntlmssp_state->auth_context = talloc_strdup(ntlmssp_state,
|
|---|
| 592 | unix_name);
|
|---|
| 593 | } else {
|
|---|
| 594 | DEBUG(NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED) ? 0 : 3,
|
|---|
| 595 | ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
|
|---|
| 596 | ntlmssp_state->domain, ntlmssp_state->user,
|
|---|
| 597 | ntlmssp_state->workstation,
|
|---|
| 598 | error_string ? error_string : "unknown error (NULL)"));
|
|---|
| 599 | ntlmssp_state->auth_context = NULL;
|
|---|
| 600 | }
|
|---|
| 601 |
|
|---|
| 602 | SAFE_FREE(error_string);
|
|---|
| 603 | SAFE_FREE(unix_name);
|
|---|
| 604 | return nt_status;
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
|
|---|
| 608 | {
|
|---|
| 609 | NTSTATUS nt_status;
|
|---|
| 610 | struct samr_Password lm_pw, nt_pw;
|
|---|
| 611 |
|
|---|
| 612 | nt_lm_owf_gen (opt_password, nt_pw.hash, lm_pw.hash);
|
|---|
| 613 |
|
|---|
| 614 | nt_status = ntlm_password_check(ntlmssp_state,
|
|---|
| 615 | true, true, 0,
|
|---|
| 616 | &ntlmssp_state->chal,
|
|---|
| 617 | &ntlmssp_state->lm_resp,
|
|---|
| 618 | &ntlmssp_state->nt_resp,
|
|---|
| 619 | ntlmssp_state->user,
|
|---|
| 620 | ntlmssp_state->user,
|
|---|
| 621 | ntlmssp_state->domain,
|
|---|
| 622 | &lm_pw, &nt_pw, user_session_key, lm_session_key);
|
|---|
| 623 |
|
|---|
| 624 | if (NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 625 | ntlmssp_state->auth_context = talloc_asprintf(ntlmssp_state,
|
|---|
| 626 | "%s%c%s", ntlmssp_state->domain,
|
|---|
| 627 | *lp_winbind_separator(),
|
|---|
| 628 | ntlmssp_state->user);
|
|---|
| 629 | } else {
|
|---|
| 630 | DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
|
|---|
| 631 | ntlmssp_state->domain, ntlmssp_state->user, ntlmssp_state->workstation,
|
|---|
| 632 | nt_errstr(nt_status)));
|
|---|
| 633 | ntlmssp_state->auth_context = NULL;
|
|---|
| 634 | }
|
|---|
| 635 | return nt_status;
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | static NTSTATUS ntlm_auth_start_ntlmssp_client(NTLMSSP_STATE **client_ntlmssp_state)
|
|---|
| 639 | {
|
|---|
| 640 | NTSTATUS status;
|
|---|
| 641 | if ( (opt_username == NULL) || (opt_domain == NULL) ) {
|
|---|
| 642 | status = NT_STATUS_UNSUCCESSFUL;
|
|---|
| 643 | DEBUG(1, ("Need username and domain for NTLMSSP\n"));
|
|---|
| 644 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | status = ntlmssp_client_start(client_ntlmssp_state);
|
|---|
| 648 |
|
|---|
| 649 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 650 | DEBUG(1, ("Could not start NTLMSSP client: %s\n",
|
|---|
| 651 | nt_errstr(status)));
|
|---|
| 652 | ntlmssp_end(client_ntlmssp_state);
|
|---|
| 653 | return status;
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | status = ntlmssp_set_username(*client_ntlmssp_state, opt_username);
|
|---|
| 657 |
|
|---|
| 658 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 659 | DEBUG(1, ("Could not set username: %s\n",
|
|---|
| 660 | nt_errstr(status)));
|
|---|
| 661 | ntlmssp_end(client_ntlmssp_state);
|
|---|
| 662 | return status;
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | status = ntlmssp_set_domain(*client_ntlmssp_state, opt_domain);
|
|---|
| 666 |
|
|---|
| 667 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 668 | DEBUG(1, ("Could not set domain: %s\n",
|
|---|
| 669 | nt_errstr(status)));
|
|---|
| 670 | ntlmssp_end(client_ntlmssp_state);
|
|---|
| 671 | return status;
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 | if (opt_password) {
|
|---|
| 675 | status = ntlmssp_set_password(*client_ntlmssp_state, opt_password);
|
|---|
| 676 |
|
|---|
| 677 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 678 | DEBUG(1, ("Could not set password: %s\n",
|
|---|
| 679 | nt_errstr(status)));
|
|---|
| 680 | ntlmssp_end(client_ntlmssp_state);
|
|---|
| 681 | return status;
|
|---|
| 682 | }
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | return NT_STATUS_OK;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | static NTSTATUS ntlm_auth_start_ntlmssp_server(NTLMSSP_STATE **ntlmssp_state)
|
|---|
| 689 | {
|
|---|
| 690 | NTSTATUS status = ntlmssp_server_start(ntlmssp_state);
|
|---|
| 691 |
|
|---|
| 692 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 693 | DEBUG(1, ("Could not start NTLMSSP server: %s\n",
|
|---|
| 694 | nt_errstr(status)));
|
|---|
| 695 | return status;
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | /* Have we been given a local password, or should we ask winbind? */
|
|---|
| 699 | if (opt_password) {
|
|---|
| 700 | (*ntlmssp_state)->check_password = local_pw_check;
|
|---|
| 701 | (*ntlmssp_state)->get_domain = lp_workgroup;
|
|---|
| 702 | (*ntlmssp_state)->get_global_myname = global_myname;
|
|---|
| 703 | } else {
|
|---|
| 704 | (*ntlmssp_state)->check_password = winbind_pw_check;
|
|---|
| 705 | (*ntlmssp_state)->get_domain = get_winbind_domain;
|
|---|
| 706 | (*ntlmssp_state)->get_global_myname = get_winbind_netbios_name;
|
|---|
| 707 | }
|
|---|
| 708 | return NT_STATUS_OK;
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 | /*******************************************************************
|
|---|
| 712 | Used by firefox to drive NTLM auth to IIS servers.
|
|---|
| 713 | *******************************************************************/
|
|---|
| 714 |
|
|---|
| 715 | static NTSTATUS do_ccache_ntlm_auth(DATA_BLOB initial_msg, DATA_BLOB challenge_msg,
|
|---|
| 716 | DATA_BLOB *reply)
|
|---|
| 717 | {
|
|---|
| 718 | struct winbindd_request wb_request;
|
|---|
| 719 | struct winbindd_response wb_response;
|
|---|
| 720 | int ctrl = 0;
|
|---|
| 721 | NSS_STATUS result;
|
|---|
| 722 |
|
|---|
| 723 | /* get winbindd to do the ntlmssp step on our behalf */
|
|---|
| 724 | ZERO_STRUCT(wb_request);
|
|---|
| 725 | ZERO_STRUCT(wb_response);
|
|---|
| 726 |
|
|---|
| 727 | /*
|
|---|
| 728 | * This is tricky here. If we set krb5_auth in pam_winbind.conf
|
|---|
| 729 | * creds for users in trusted domain will be stored the winbindd
|
|---|
| 730 | * child of the trusted domain. If we ask the primary domain for
|
|---|
| 731 | * ntlm_ccache_auth, it will fail. So, we have to ask the trusted
|
|---|
| 732 | * domain's child for ccache_ntlm_auth. that is to say, we have to
|
|---|
| 733 | * set WBFALG_PAM_CONTACT_TRUSTDOM in request.flags.
|
|---|
| 734 | */
|
|---|
| 735 | ctrl = get_pam_winbind_config();
|
|---|
| 736 |
|
|---|
| 737 | if (ctrl | WINBIND_KRB5_AUTH) {
|
|---|
| 738 | wb_request.flags |= WBFLAG_PAM_CONTACT_TRUSTDOM;
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | fstr_sprintf(wb_request.data.ccache_ntlm_auth.user,
|
|---|
| 742 | "%s%c%s", opt_domain, winbind_separator(), opt_username);
|
|---|
| 743 | wb_request.data.ccache_ntlm_auth.uid = geteuid();
|
|---|
| 744 | wb_request.data.ccache_ntlm_auth.initial_blob_len = initial_msg.length;
|
|---|
| 745 | wb_request.data.ccache_ntlm_auth.challenge_blob_len = challenge_msg.length;
|
|---|
| 746 | wb_request.extra_len = initial_msg.length + challenge_msg.length;
|
|---|
| 747 |
|
|---|
| 748 | if (wb_request.extra_len > 0) {
|
|---|
| 749 | wb_request.extra_data.data = SMB_MALLOC_ARRAY(char, wb_request.extra_len);
|
|---|
| 750 | if (wb_request.extra_data.data == NULL) {
|
|---|
| 751 | return NT_STATUS_NO_MEMORY;
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | memcpy(wb_request.extra_data.data, initial_msg.data, initial_msg.length);
|
|---|
| 755 | memcpy(wb_request.extra_data.data + initial_msg.length,
|
|---|
| 756 | challenge_msg.data, challenge_msg.length);
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | result = winbindd_request_response(WINBINDD_CCACHE_NTLMAUTH, &wb_request, &wb_response);
|
|---|
| 760 | SAFE_FREE(wb_request.extra_data.data);
|
|---|
| 761 |
|
|---|
| 762 | if (result != NSS_STATUS_SUCCESS) {
|
|---|
| 763 | winbindd_free_response(&wb_response);
|
|---|
| 764 | return NT_STATUS_UNSUCCESSFUL;
|
|---|
| 765 | }
|
|---|
| 766 |
|
|---|
| 767 | if (reply) {
|
|---|
| 768 | *reply = data_blob(wb_response.extra_data.data,
|
|---|
| 769 | wb_response.data.ccache_ntlm_auth.auth_blob_len);
|
|---|
| 770 | if (wb_response.data.ccache_ntlm_auth.auth_blob_len > 0 &&
|
|---|
| 771 | reply->data == NULL) {
|
|---|
| 772 | winbindd_free_response(&wb_response);
|
|---|
| 773 | return NT_STATUS_NO_MEMORY;
|
|---|
| 774 | }
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | winbindd_free_response(&wb_response);
|
|---|
| 778 | return NT_STATUS_MORE_PROCESSING_REQUIRED;
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | static void manage_squid_ntlmssp_request(struct ntlm_auth_state *state,
|
|---|
| 782 | char *buf, int length)
|
|---|
| 783 | {
|
|---|
| 784 | DATA_BLOB request, reply;
|
|---|
| 785 | NTSTATUS nt_status;
|
|---|
| 786 |
|
|---|
| 787 | if (strlen(buf) < 2) {
|
|---|
| 788 | DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
|
|---|
| 789 | x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
|
|---|
| 790 | return;
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | if (strlen(buf) > 3) {
|
|---|
| 794 | if(strncmp(buf, "SF ", 3) == 0){
|
|---|
| 795 | DEBUG(10, ("Setting flags to negotioate\n"));
|
|---|
| 796 | TALLOC_FREE(state->want_feature_list);
|
|---|
| 797 | state->want_feature_list = talloc_strdup(state->mem_ctx,
|
|---|
| 798 | buf+3);
|
|---|
| 799 | x_fprintf(x_stdout, "OK\n");
|
|---|
| 800 | return;
|
|---|
| 801 | }
|
|---|
| 802 | request = base64_decode_data_blob(buf + 3);
|
|---|
| 803 | } else {
|
|---|
| 804 | request = data_blob_null;
|
|---|
| 805 | }
|
|---|
| 806 |
|
|---|
| 807 | if ((strncmp(buf, "PW ", 3) == 0)) {
|
|---|
| 808 | /* The calling application wants us to use a local password
|
|---|
| 809 | * (rather than winbindd) */
|
|---|
| 810 |
|
|---|
| 811 | opt_password = SMB_STRNDUP((const char *)request.data,
|
|---|
| 812 | request.length);
|
|---|
| 813 |
|
|---|
| 814 | if (opt_password == NULL) {
|
|---|
| 815 | DEBUG(1, ("Out of memory\n"));
|
|---|
| 816 | x_fprintf(x_stdout, "BH Out of memory\n");
|
|---|
| 817 | data_blob_free(&request);
|
|---|
| 818 | return;
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | x_fprintf(x_stdout, "OK\n");
|
|---|
| 822 | data_blob_free(&request);
|
|---|
| 823 | return;
|
|---|
| 824 | }
|
|---|
| 825 |
|
|---|
| 826 | if (strncmp(buf, "YR", 2) == 0) {
|
|---|
| 827 | if (state->ntlmssp_state)
|
|---|
| 828 | ntlmssp_end(&state->ntlmssp_state);
|
|---|
| 829 | state->svr_state = SERVER_INITIAL;
|
|---|
| 830 | } else if (strncmp(buf, "KK", 2) == 0) {
|
|---|
| 831 | /* No special preprocessing required */
|
|---|
| 832 | } else if (strncmp(buf, "GF", 2) == 0) {
|
|---|
| 833 | DEBUG(10, ("Requested negotiated NTLMSSP flags\n"));
|
|---|
| 834 |
|
|---|
| 835 | if (state->svr_state == SERVER_FINISHED) {
|
|---|
| 836 | x_fprintf(x_stdout, "GF 0x%08x\n", state->neg_flags);
|
|---|
| 837 | }
|
|---|
| 838 | else {
|
|---|
| 839 | x_fprintf(x_stdout, "BH\n");
|
|---|
| 840 | }
|
|---|
| 841 | data_blob_free(&request);
|
|---|
| 842 | return;
|
|---|
| 843 | } else if (strncmp(buf, "GK", 2) == 0) {
|
|---|
| 844 | DEBUG(10, ("Requested NTLMSSP session key\n"));
|
|---|
| 845 | if(state->have_session_key) {
|
|---|
| 846 | char *key64 = base64_encode_data_blob(state->mem_ctx,
|
|---|
| 847 | state->session_key);
|
|---|
| 848 | x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
|
|---|
| 849 | TALLOC_FREE(key64);
|
|---|
| 850 | } else {
|
|---|
| 851 | x_fprintf(x_stdout, "BH\n");
|
|---|
| 852 | }
|
|---|
| 853 |
|
|---|
| 854 | data_blob_free(&request);
|
|---|
| 855 | return;
|
|---|
| 856 | } else {
|
|---|
| 857 | DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
|
|---|
| 858 | x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
|
|---|
| 859 | return;
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | if (!state->ntlmssp_state) {
|
|---|
| 863 | nt_status = ntlm_auth_start_ntlmssp_server(
|
|---|
| 864 | &state->ntlmssp_state);
|
|---|
| 865 | if (!NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 866 | x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
|
|---|
| 867 | return;
|
|---|
| 868 | }
|
|---|
| 869 | ntlmssp_want_feature_list(state->ntlmssp_state,
|
|---|
| 870 | state->want_feature_list);
|
|---|
| 871 | }
|
|---|
| 872 |
|
|---|
| 873 | DEBUG(10, ("got NTLMSSP packet:\n"));
|
|---|
| 874 | dump_data(10, request.data, request.length);
|
|---|
| 875 |
|
|---|
| 876 | nt_status = ntlmssp_update(state->ntlmssp_state, request, &reply);
|
|---|
| 877 |
|
|---|
| 878 | if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
|
|---|
| 879 | char *reply_base64 = base64_encode_data_blob(state->mem_ctx,
|
|---|
| 880 | reply);
|
|---|
| 881 | x_fprintf(x_stdout, "TT %s\n", reply_base64);
|
|---|
| 882 | TALLOC_FREE(reply_base64);
|
|---|
| 883 | data_blob_free(&reply);
|
|---|
| 884 | state->svr_state = SERVER_CHALLENGE;
|
|---|
| 885 | DEBUG(10, ("NTLMSSP challenge\n"));
|
|---|
| 886 | } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
|
|---|
| 887 | x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
|
|---|
| 888 | DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
|
|---|
| 889 |
|
|---|
| 890 | ntlmssp_end(&state->ntlmssp_state);
|
|---|
| 891 | } else if (!NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 892 | x_fprintf(x_stdout, "NA %s\n", nt_errstr(nt_status));
|
|---|
| 893 | DEBUG(10, ("NTLMSSP %s\n", nt_errstr(nt_status)));
|
|---|
| 894 | } else {
|
|---|
| 895 | x_fprintf(x_stdout, "AF %s\n",
|
|---|
| 896 | (char *)state->ntlmssp_state->auth_context);
|
|---|
| 897 | DEBUG(10, ("NTLMSSP OK!\n"));
|
|---|
| 898 |
|
|---|
| 899 | if(state->have_session_key)
|
|---|
| 900 | data_blob_free(&state->session_key);
|
|---|
| 901 | state->session_key = data_blob(
|
|---|
| 902 | state->ntlmssp_state->session_key.data,
|
|---|
| 903 | state->ntlmssp_state->session_key.length);
|
|---|
| 904 | state->neg_flags = state->ntlmssp_state->neg_flags;
|
|---|
| 905 | state->have_session_key = true;
|
|---|
| 906 | state->svr_state = SERVER_FINISHED;
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | data_blob_free(&request);
|
|---|
| 910 | }
|
|---|
| 911 |
|
|---|
| 912 | static void manage_client_ntlmssp_request(struct ntlm_auth_state *state,
|
|---|
| 913 | char *buf, int length)
|
|---|
| 914 | {
|
|---|
| 915 | DATA_BLOB request, reply;
|
|---|
| 916 | NTSTATUS nt_status;
|
|---|
| 917 |
|
|---|
| 918 | if (!opt_username || !*opt_username) {
|
|---|
| 919 | x_fprintf(x_stderr, "username must be specified!\n\n");
|
|---|
| 920 | exit(1);
|
|---|
| 921 | }
|
|---|
| 922 |
|
|---|
| 923 | if (strlen(buf) < 2) {
|
|---|
| 924 | DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
|
|---|
| 925 | x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
|
|---|
| 926 | return;
|
|---|
| 927 | }
|
|---|
| 928 |
|
|---|
| 929 | if (strlen(buf) > 3) {
|
|---|
| 930 | if(strncmp(buf, "SF ", 3) == 0) {
|
|---|
| 931 | DEBUG(10, ("Looking for flags to negotiate\n"));
|
|---|
| 932 | talloc_free(state->want_feature_list);
|
|---|
| 933 | state->want_feature_list = talloc_strdup(state->mem_ctx,
|
|---|
| 934 | buf+3);
|
|---|
| 935 | x_fprintf(x_stdout, "OK\n");
|
|---|
| 936 | return;
|
|---|
| 937 | }
|
|---|
| 938 | request = base64_decode_data_blob(buf + 3);
|
|---|
| 939 | } else {
|
|---|
| 940 | request = data_blob_null;
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 | if (strncmp(buf, "PW ", 3) == 0) {
|
|---|
| 944 | /* We asked for a password and obviously got it :-) */
|
|---|
| 945 |
|
|---|
| 946 | opt_password = SMB_STRNDUP((const char *)request.data,
|
|---|
| 947 | request.length);
|
|---|
| 948 |
|
|---|
| 949 | if (opt_password == NULL) {
|
|---|
| 950 | DEBUG(1, ("Out of memory\n"));
|
|---|
| 951 | x_fprintf(x_stdout, "BH Out of memory\n");
|
|---|
| 952 | data_blob_free(&request);
|
|---|
| 953 | return;
|
|---|
| 954 | }
|
|---|
| 955 |
|
|---|
| 956 | x_fprintf(x_stdout, "OK\n");
|
|---|
| 957 | data_blob_free(&request);
|
|---|
| 958 | return;
|
|---|
| 959 | }
|
|---|
| 960 |
|
|---|
| 961 | if (!state->ntlmssp_state && use_cached_creds) {
|
|---|
| 962 | /* check whether cached credentials are usable. */
|
|---|
| 963 | DATA_BLOB empty_blob = data_blob_null;
|
|---|
| 964 |
|
|---|
| 965 | nt_status = do_ccache_ntlm_auth(empty_blob, empty_blob, NULL);
|
|---|
| 966 | if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
|
|---|
| 967 | /* failed to use cached creds */
|
|---|
| 968 | use_cached_creds = False;
|
|---|
| 969 | }
|
|---|
| 970 | }
|
|---|
| 971 |
|
|---|
| 972 | if (opt_password == NULL && !use_cached_creds) {
|
|---|
| 973 | /* Request a password from the calling process. After
|
|---|
| 974 | sending it, the calling process should retry asking for the
|
|---|
| 975 | negotiate. */
|
|---|
| 976 |
|
|---|
| 977 | DEBUG(10, ("Requesting password\n"));
|
|---|
| 978 | x_fprintf(x_stdout, "PW\n");
|
|---|
| 979 | return;
|
|---|
| 980 | }
|
|---|
| 981 |
|
|---|
| 982 | if (strncmp(buf, "YR", 2) == 0) {
|
|---|
| 983 | if (state->ntlmssp_state)
|
|---|
| 984 | ntlmssp_end(&state->ntlmssp_state);
|
|---|
| 985 | state->cli_state = CLIENT_INITIAL;
|
|---|
| 986 | } else if (strncmp(buf, "TT", 2) == 0) {
|
|---|
| 987 | /* No special preprocessing required */
|
|---|
| 988 | } else if (strncmp(buf, "GF", 2) == 0) {
|
|---|
| 989 | DEBUG(10, ("Requested negotiated NTLMSSP flags\n"));
|
|---|
| 990 |
|
|---|
| 991 | if(state->cli_state == CLIENT_FINISHED) {
|
|---|
| 992 | x_fprintf(x_stdout, "GF 0x%08x\n", state->neg_flags);
|
|---|
| 993 | }
|
|---|
| 994 | else {
|
|---|
| 995 | x_fprintf(x_stdout, "BH\n");
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| 998 | data_blob_free(&request);
|
|---|
| 999 | return;
|
|---|
| 1000 | } else if (strncmp(buf, "GK", 2) == 0 ) {
|
|---|
| 1001 | DEBUG(10, ("Requested session key\n"));
|
|---|
| 1002 |
|
|---|
| 1003 | if(state->cli_state == CLIENT_FINISHED) {
|
|---|
| 1004 | char *key64 = base64_encode_data_blob(state->mem_ctx,
|
|---|
| 1005 | state->session_key);
|
|---|
| 1006 | x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
|
|---|
| 1007 | TALLOC_FREE(key64);
|
|---|
| 1008 | }
|
|---|
| 1009 | else {
|
|---|
| 1010 | x_fprintf(x_stdout, "BH\n");
|
|---|
| 1011 | }
|
|---|
| 1012 |
|
|---|
| 1013 | data_blob_free(&request);
|
|---|
| 1014 | return;
|
|---|
| 1015 | } else {
|
|---|
| 1016 | DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
|
|---|
| 1017 | x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
|
|---|
| 1018 | return;
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | if (!state->ntlmssp_state) {
|
|---|
| 1022 | nt_status = ntlm_auth_start_ntlmssp_client(
|
|---|
| 1023 | &state->ntlmssp_state);
|
|---|
| 1024 | if (!NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 1025 | x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
|
|---|
| 1026 | return;
|
|---|
| 1027 | }
|
|---|
| 1028 | ntlmssp_want_feature_list(state->ntlmssp_state,
|
|---|
| 1029 | state->want_feature_list);
|
|---|
| 1030 | state->initial_message = data_blob_null;
|
|---|
| 1031 | }
|
|---|
| 1032 |
|
|---|
| 1033 | DEBUG(10, ("got NTLMSSP packet:\n"));
|
|---|
| 1034 | dump_data(10, request.data, request.length);
|
|---|
| 1035 |
|
|---|
| 1036 | if (use_cached_creds && !opt_password &&
|
|---|
| 1037 | (state->cli_state == CLIENT_RESPONSE)) {
|
|---|
| 1038 | nt_status = do_ccache_ntlm_auth(state->initial_message, request,
|
|---|
| 1039 | &reply);
|
|---|
| 1040 | } else {
|
|---|
| 1041 | nt_status = ntlmssp_update(state->ntlmssp_state, request,
|
|---|
| 1042 | &reply);
|
|---|
| 1043 | }
|
|---|
| 1044 |
|
|---|
| 1045 | if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
|
|---|
| 1046 | char *reply_base64 = base64_encode_data_blob(state->mem_ctx,
|
|---|
| 1047 | reply);
|
|---|
| 1048 | if (state->cli_state == CLIENT_INITIAL) {
|
|---|
| 1049 | x_fprintf(x_stdout, "YR %s\n", reply_base64);
|
|---|
| 1050 | state->initial_message = reply;
|
|---|
| 1051 | state->cli_state = CLIENT_RESPONSE;
|
|---|
| 1052 | } else {
|
|---|
| 1053 | x_fprintf(x_stdout, "KK %s\n", reply_base64);
|
|---|
| 1054 | data_blob_free(&reply);
|
|---|
| 1055 | }
|
|---|
| 1056 | TALLOC_FREE(reply_base64);
|
|---|
| 1057 | DEBUG(10, ("NTLMSSP challenge\n"));
|
|---|
| 1058 | } else if (NT_STATUS_IS_OK(nt_status)) {
|
|---|
| 1059 | char *reply_base64 = base64_encode_data_blob(talloc_tos(),
|
|---|
| 1060 | reply);
|
|---|
| 1061 | x_fprintf(x_stdout, "AF %s\n", reply_base64);
|
|---|
| 1062 | TALLOC_FREE(reply_base64);
|
|---|
| 1063 |
|
|---|
| 1064 | if(state->have_session_key)
|
|---|
| 1065 | data_blob_free(&state->session_key);
|
|---|
| 1066 |
|
|---|
| 1067 | state->session_key = data_blob(
|
|---|
| 1068 | state->ntlmssp_state->session_key.data,
|
|---|
| 1069 | state->ntlmssp_state->session_key.length);
|
|---|
| 1070 | state->neg_flags = state->ntlmssp_state->neg_flags;
|
|---|
| 1071 | state->have_session_key = true;
|
|---|
| 1072 |
|
|---|
| 1073 | DEBUG(10, ("NTLMSSP OK!\n"));
|
|---|
| 1074 | state->cli_state = CLIENT_FINISHED;
|
|---|
| 1075 | if (state->ntlmssp_state)
|
|---|
| 1076 | ntlmssp_end(&state->ntlmssp_state);
|
|---|
| 1077 | } else {
|
|---|
| 1078 | x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
|
|---|
| 1079 | DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
|
|---|
| 1080 | state->cli_state = CLIENT_ERROR;
|
|---|
| 1081 | if (state->ntlmssp_state)
|
|---|
| 1082 | ntlmssp_end(&state->ntlmssp_state);
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | data_blob_free(&request);
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | static void manage_squid_basic_request(struct ntlm_auth_state *state,
|
|---|
| 1089 | char *buf, int length)
|
|---|
| 1090 | {
|
|---|
| 1091 | char *user, *pass;
|
|---|
| 1092 | user=buf;
|
|---|
| 1093 |
|
|---|
| 1094 | pass=(char *)memchr(buf,' ',length);
|
|---|
| 1095 | if (!pass) {
|
|---|
| 1096 | DEBUG(2, ("Password not found. Denying access\n"));
|
|---|
| 1097 | x_fprintf(x_stdout, "ERR\n");
|
|---|
| 1098 | return;
|
|---|
| 1099 | }
|
|---|
| 1100 | *pass='\0';
|
|---|
| 1101 | pass++;
|
|---|
| 1102 |
|
|---|
| 1103 | if (state->helper_mode == SQUID_2_5_BASIC) {
|
|---|
| 1104 | rfc1738_unescape(user);
|
|---|
| 1105 | rfc1738_unescape(pass);
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 | if (check_plaintext_auth(user, pass, False)) {
|
|---|
| 1109 | x_fprintf(x_stdout, "OK\n");
|
|---|
| 1110 | } else {
|
|---|
| 1111 | x_fprintf(x_stdout, "ERR\n");
|
|---|
| 1112 | }
|
|---|
| 1113 | }
|
|---|
| 1114 |
|
|---|
| 1115 | static void offer_gss_spnego_mechs(void) {
|
|---|
| 1116 |
|
|---|
| 1117 | DATA_BLOB token;
|
|---|
| 1118 | struct spnego_data spnego;
|
|---|
| 1119 | ssize_t len;
|
|---|
| 1120 | char *reply_base64;
|
|---|
| 1121 | TALLOC_CTX *ctx = talloc_tos();
|
|---|
| 1122 | char *principal;
|
|---|
| 1123 | char *myname_lower;
|
|---|
| 1124 |
|
|---|
| 1125 | ZERO_STRUCT(spnego);
|
|---|
| 1126 |
|
|---|
| 1127 | myname_lower = talloc_strdup(ctx, global_myname());
|
|---|
| 1128 | if (!myname_lower) {
|
|---|
| 1129 | return;
|
|---|
| 1130 | }
|
|---|
| 1131 | strlower_m(myname_lower);
|
|---|
| 1132 |
|
|---|
| 1133 | principal = talloc_asprintf(ctx, "%s$@%s", myname_lower, lp_realm());
|
|---|
| 1134 | if (!principal) {
|
|---|
| 1135 | return;
|
|---|
| 1136 | }
|
|---|
| 1137 |
|
|---|
| 1138 | /* Server negTokenInit (mech offerings) */
|
|---|
| 1139 | spnego.type = SPNEGO_NEG_TOKEN_INIT;
|
|---|
| 1140 | spnego.negTokenInit.mechTypes = talloc_array(ctx, const char *, 2);
|
|---|
| 1141 | #ifdef HAVE_KRB5
|
|---|
| 1142 | spnego.negTokenInit.mechTypes[0] = talloc_strdup(ctx, OID_KERBEROS5_OLD);
|
|---|
| 1143 | spnego.negTokenInit.mechTypes[1] = talloc_strdup(ctx, OID_NTLMSSP);
|
|---|
| 1144 | spnego.negTokenInit.mechTypes[2] = NULL;
|
|---|
| 1145 | #else
|
|---|
| 1146 | spnego.negTokenInit.mechTypes[0] = talloc_strdup(ctx, OID_NTLMSSP);
|
|---|
| 1147 | spnego.negTokenInit.mechTypes[1] = NULL;
|
|---|
| 1148 | #endif
|
|---|
| 1149 |
|
|---|
| 1150 |
|
|---|
| 1151 | spnego.negTokenInit.mechListMIC = data_blob_talloc(ctx, principal,
|
|---|
| 1152 | strlen(principal));
|
|---|
| 1153 |
|
|---|
| 1154 | len = spnego_write_data(ctx, &token, &spnego);
|
|---|
| 1155 | spnego_free_data(&spnego);
|
|---|
| 1156 |
|
|---|
| 1157 | if (len == -1) {
|
|---|
| 1158 | DEBUG(1, ("Could not write SPNEGO data blob\n"));
|
|---|
| 1159 | x_fprintf(x_stdout, "BH Could not write SPNEGO data blob\n");
|
|---|
| 1160 | return;
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | reply_base64 = base64_encode_data_blob(talloc_tos(), token);
|
|---|
| 1164 | x_fprintf(x_stdout, "TT %s *\n", reply_base64);
|
|---|
| 1165 |
|
|---|
| 1166 | TALLOC_FREE(reply_base64);
|
|---|
| 1167 | data_blob_free(&token);
|
|---|
| 1168 | DEBUG(10, ("sent SPNEGO negTokenInit\n"));
|
|---|
| 1169 | return;
|
|---|
| 1170 | }
|
|---|
| 1171 |
|
|---|
| 1172 | static void manage_gss_spnego_request(struct ntlm_auth_state *state,
|
|---|
| 1173 | char *buf, int length)
|
|---|
| 1174 | {
|
|---|
| 1175 | static NTLMSSP_STATE *ntlmssp_state = NULL;
|
|---|
| 1176 | struct spnego_data request, response;
|
|---|
| 1177 | DATA_BLOB token;
|
|---|
| 1178 | NTSTATUS status;
|
|---|
| 1179 | ssize_t len;
|
|---|
| 1180 | TALLOC_CTX *ctx = talloc_tos();
|
|---|
| 1181 |
|
|---|
| 1182 | char *user = NULL;
|
|---|
| 1183 | char *domain = NULL;
|
|---|
| 1184 |
|
|---|
| 1185 | const char *reply_code;
|
|---|
| 1186 | char *reply_base64;
|
|---|
| 1187 | char *reply_argument = NULL;
|
|---|
| 1188 |
|
|---|
| 1189 | if (strlen(buf) < 2) {
|
|---|
| 1190 | DEBUG(1, ("SPENGO query [%s] invalid", buf));
|
|---|
| 1191 | x_fprintf(x_stdout, "BH SPENGO query invalid\n");
|
|---|
| 1192 | return;
|
|---|
| 1193 | }
|
|---|
| 1194 |
|
|---|
| 1195 | if (strncmp(buf, "YR", 2) == 0) {
|
|---|
| 1196 | if (ntlmssp_state)
|
|---|
| 1197 | ntlmssp_end(&ntlmssp_state);
|
|---|
| 1198 | } else if (strncmp(buf, "KK", 2) == 0) {
|
|---|
| 1199 | ;
|
|---|
| 1200 | } else {
|
|---|
| 1201 | DEBUG(1, ("SPENGO query [%s] invalid", buf));
|
|---|
| 1202 | x_fprintf(x_stdout, "BH SPENGO query invalid\n");
|
|---|
| 1203 | return;
|
|---|
| 1204 | }
|
|---|
| 1205 |
|
|---|
| 1206 | if ( (strlen(buf) == 2)) {
|
|---|
| 1207 |
|
|---|
| 1208 | /* no client data, get the negTokenInit offering
|
|---|
| 1209 | mechanisms */
|
|---|
| 1210 |
|
|---|
| 1211 | offer_gss_spnego_mechs();
|
|---|
| 1212 | return;
|
|---|
| 1213 | }
|
|---|
| 1214 |
|
|---|
| 1215 | /* All subsequent requests have a blob. This might be negTokenInit or negTokenTarg */
|
|---|
| 1216 |
|
|---|
| 1217 | if (strlen(buf) <= 3) {
|
|---|
| 1218 | DEBUG(1, ("GSS-SPNEGO query [%s] invalid\n", buf));
|
|---|
| 1219 | x_fprintf(x_stdout, "BH GSS-SPNEGO query invalid\n");
|
|---|
| 1220 | return;
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | token = base64_decode_data_blob(buf + 3);
|
|---|
| 1224 | len = spnego_read_data(ctx, token, &request);
|
|---|
| 1225 | data_blob_free(&token);
|
|---|
| 1226 |
|
|---|
| 1227 | if (len == -1) {
|
|---|
| 1228 | DEBUG(1, ("GSS-SPNEGO query [%s] invalid", buf));
|
|---|
| 1229 | x_fprintf(x_stdout, "BH GSS-SPNEGO query invalid\n");
|
|---|
| 1230 | return;
|
|---|
| 1231 | }
|
|---|
| 1232 |
|
|---|
| 1233 | if (request.type == SPNEGO_NEG_TOKEN_INIT) {
|
|---|
| 1234 |
|
|---|
| 1235 | /* Second request from Client. This is where the
|
|---|
| 1236 | client offers its mechanism to use. */
|
|---|
| 1237 |
|
|---|
| 1238 | if ( (request.negTokenInit.mechTypes == NULL) ||
|
|---|
| 1239 | (request.negTokenInit.mechTypes[0] == NULL) ) {
|
|---|
| 1240 | DEBUG(1, ("Client did not offer any mechanism"));
|
|---|
| 1241 | x_fprintf(x_stdout, "BH Client did not offer any "
|
|---|
| 1242 | "mechanism\n");
|
|---|
| 1243 | return;
|
|---|
| 1244 | }
|
|---|
| 1245 |
|
|---|
| 1246 | status = NT_STATUS_UNSUCCESSFUL;
|
|---|
| 1247 | if (strcmp(request.negTokenInit.mechTypes[0], OID_NTLMSSP) == 0) {
|
|---|
| 1248 |
|
|---|
| 1249 | if ( request.negTokenInit.mechToken.data == NULL ) {
|
|---|
| 1250 | DEBUG(1, ("Client did not provide NTLMSSP data\n"));
|
|---|
| 1251 | x_fprintf(x_stdout, "BH Client did not provide "
|
|---|
| 1252 | "NTLMSSP data\n");
|
|---|
| 1253 | return;
|
|---|
| 1254 | }
|
|---|
| 1255 |
|
|---|
| 1256 | if ( ntlmssp_state != NULL ) {
|
|---|
| 1257 | DEBUG(1, ("Client wants a new NTLMSSP challenge, but "
|
|---|
| 1258 | "already got one\n"));
|
|---|
| 1259 | x_fprintf(x_stdout, "BH Client wants a new "
|
|---|
| 1260 | "NTLMSSP challenge, but "
|
|---|
| 1261 | "already got one\n");
|
|---|
| 1262 | ntlmssp_end(&ntlmssp_state);
|
|---|
| 1263 | return;
|
|---|
| 1264 | }
|
|---|
| 1265 |
|
|---|
| 1266 | if (!NT_STATUS_IS_OK(status = ntlm_auth_start_ntlmssp_server(&ntlmssp_state))) {
|
|---|
| 1267 | x_fprintf(x_stdout, "BH %s\n", nt_errstr(status));
|
|---|
| 1268 | return;
|
|---|
| 1269 | }
|
|---|
| 1270 |
|
|---|
| 1271 | DEBUG(10, ("got NTLMSSP packet:\n"));
|
|---|
| 1272 | dump_data(10, request.negTokenInit.mechToken.data,
|
|---|
| 1273 | request.negTokenInit.mechToken.length);
|
|---|
| 1274 |
|
|---|
| 1275 | response.type = SPNEGO_NEG_TOKEN_TARG;
|
|---|
| 1276 | response.negTokenTarg.supportedMech = talloc_strdup(ctx, OID_NTLMSSP);
|
|---|
| 1277 | response.negTokenTarg.mechListMIC = data_blob_talloc(ctx, NULL, 0);
|
|---|
| 1278 |
|
|---|
| 1279 | status = ntlmssp_update(ntlmssp_state,
|
|---|
| 1280 | request.negTokenInit.mechToken,
|
|---|
| 1281 | &response.negTokenTarg.responseToken);
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | #ifdef HAVE_KRB5
|
|---|
| 1285 | if (strcmp(request.negTokenInit.mechTypes[0], OID_KERBEROS5_OLD) == 0) {
|
|---|
| 1286 |
|
|---|
| 1287 | TALLOC_CTX *mem_ctx = talloc_init("manage_gss_spnego_request");
|
|---|
| 1288 | char *principal;
|
|---|
| 1289 | DATA_BLOB ap_rep;
|
|---|
| 1290 | DATA_BLOB session_key;
|
|---|
| 1291 | struct PAC_DATA *pac_data = NULL;
|
|---|
| 1292 |
|
|---|
| 1293 | if ( request.negTokenInit.mechToken.data == NULL ) {
|
|---|
| 1294 | DEBUG(1, ("Client did not provide Kerberos data\n"));
|
|---|
| 1295 | x_fprintf(x_stdout, "BH Client did not provide "
|
|---|
| 1296 | "Kerberos data\n");
|
|---|
| 1297 | return;
|
|---|
| 1298 | }
|
|---|
| 1299 |
|
|---|
| 1300 | response.type = SPNEGO_NEG_TOKEN_TARG;
|
|---|
| 1301 | response.negTokenTarg.supportedMech = talloc_strdup(ctx, OID_KERBEROS5_OLD);
|
|---|
| 1302 | response.negTokenTarg.mechListMIC = data_blob_talloc(ctx, NULL, 0);
|
|---|
| 1303 | response.negTokenTarg.responseToken = data_blob_talloc(ctx, NULL, 0);
|
|---|
| 1304 |
|
|---|
|
|---|