Changeset 740 for vendor/current/source3/auth/auth.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/auth/auth.c
r414 r740 19 19 20 20 #include "includes.h" 21 #include "auth.h" 22 #include "smbd/globals.h" 21 23 22 24 #undef DBGC_CLASS … … 25 27 static_decl_auth; 26 28 27 static struct auth_init_function_entry * backends = NULL;29 static struct auth_init_function_entry *auth_backends = NULL; 28 30 29 31 static struct auth_init_function_entry *auth_find_backend_entry(const char *name); … … 31 33 NTSTATUS smb_register_auth(int version, const char *name, auth_init_function init) 32 34 { 33 struct auth_init_function_entry *entry = backends;35 struct auth_init_function_entry *entry = auth_backends; 34 36 35 37 if (version != AUTH_INTERFACE_VERSION) { … … 55 57 entry->init = init; 56 58 57 DLIST_ADD( backends, entry);59 DLIST_ADD(auth_backends, entry); 58 60 DEBUG(5,("Successfully added auth method '%s'\n", name)); 59 61 return NT_STATUS_OK; … … 62 64 static struct auth_init_function_entry *auth_find_backend_entry(const char *name) 63 65 { 64 struct auth_init_function_entry *entry = backends;66 struct auth_init_function_entry *entry = auth_backends; 65 67 66 68 while(entry) { … … 77 79 ****************************************************************************/ 78 80 79 static voidget_ntlm_challenge(struct auth_context *auth_context,81 static NTSTATUS get_ntlm_challenge(struct auth_context *auth_context, 80 82 uint8_t chal[8]) 81 83 { … … 88 90 auth_context->challenge_set_by)); 89 91 memcpy(chal, auth_context->challenge.data, 8); 90 return ;92 return NT_STATUS_OK; 91 93 } 92 94 … … 107 109 108 110 challenge = auth_method->get_chal(auth_context, &auth_method->private_data, 109 auth_context->mem_ctx);111 auth_context); 110 112 if (!challenge.length) { 111 113 DEBUG(3, ("auth_get_challenge: getting challenge from authentication method %s FAILED.\n", … … 123 125 124 126 generate_random_buffer(tmp, sizeof(tmp)); 125 auth_context->challenge = data_blob_talloc(auth_context ->mem_ctx,127 auth_context->challenge = data_blob_talloc(auth_context, 126 128 tmp, sizeof(tmp)); 127 129 … … 139 141 140 142 memcpy(chal, auth_context->challenge.data, 8); 143 return NT_STATUS_OK; 141 144 } 142 145 … … 214 217 215 218 DEBUG(3, ("check_ntlm_password: Checking password for unmapped user [%s]\\[%s]@[%s] with the new password interface\n", 216 user_info->client _domain, user_info->smb_name, user_info->wksta_name));219 user_info->client.domain_name, user_info->client.account_name, user_info->workstation_name)); 217 220 218 221 DEBUG(3, ("check_ntlm_password: mapped user is: [%s]\\[%s]@[%s]\n", 219 user_info-> domain, user_info->internal_username, user_info->wksta_name));222 user_info->mapped.domain_name, user_info->mapped.account_name, user_info->workstation_name)); 220 223 221 224 if (auth_context->challenge.length != 8) { … … 233 236 #ifdef DEBUG_PASSWORD 234 237 DEBUG(100, ("user_info has passwords of length %d and %d\n", 235 (int)user_info-> lm_resp.length, (int)user_info->nt_resp.length));238 (int)user_info->password.response.lanman.length, (int)user_info->password.response.nt.length)); 236 239 DEBUG(100, ("lm:\n")); 237 dump_data(100, user_info-> lm_resp.data, user_info->lm_resp.length);240 dump_data(100, user_info->password.response.lanman.data, user_info->password.response.lanman.length); 238 241 DEBUG(100, ("nt:\n")); 239 dump_data(100, user_info-> nt_resp.data, user_info->nt_resp.length);242 dump_data(100, user_info->password.response.nt.data, user_info->password.response.nt.length); 240 243 #endif 241 244 242 245 /* This needs to be sorted: If it doesn't match, what should we do? */ 243 if (!check_domain_match(user_info->smb_name, user_info->domain))246 if (!check_domain_match(user_info->client.account_name, user_info->mapped.domain_name)) 244 247 return NT_STATUS_LOGON_FAILURE; 245 248 … … 247 250 NTSTATUS result; 248 251 249 mem_ctx = talloc_init("%s authentication for user %s\\%s", auth_method->name, 250 user_info->domain, user_info->smb_name);252 mem_ctx = talloc_init("%s authentication for user %s\\%s", auth_method->name, 253 user_info->mapped.domain_name, user_info->client.account_name); 251 254 252 255 result = auth_method->auth(auth_context, auth_method->private_data, mem_ctx, user_info, server_info); … … 263 266 if (NT_STATUS_IS_OK(nt_status)) { 264 267 DEBUG(3, ("check_ntlm_password: %s authentication for user [%s] succeeded\n", 265 auth_method->name, user_info-> smb_name));268 auth_method->name, user_info->client.account_name)); 266 269 } else { 267 270 DEBUG(5, ("check_ntlm_password: %s authentication for user [%s] FAILED with error %s\n", 268 auth_method->name, user_info-> smb_name, nt_errstr(nt_status)));271 auth_method->name, user_info->client.account_name, nt_errstr(nt_status))); 269 272 } 270 273 … … 284 287 /* We might not be root if we are an RPC call */ 285 288 become_root(); 286 nt_status = smb_pam_accountcheck(unix_username); 289 nt_status = smb_pam_accountcheck( 290 unix_username, 291 smbd_server_conn->client_id.name); 287 292 unbecome_root(); 288 293 … … 298 303 if (NT_STATUS_IS_OK(nt_status)) { 299 304 DEBUG((*server_info)->guest ? 5 : 2, 300 ("check_ntlm_password: %sauthentication for user [%s] -> [%s] -> [%s] succeeded\n", 301 (*server_info)->guest ? "guest " : "", 302 user_info-> smb_name,303 user_info-> internal_username,305 ("check_ntlm_password: %sauthentication for user [%s] -> [%s] -> [%s] succeeded\n", 306 (*server_info)->guest ? "guest " : "", 307 user_info->client.account_name, 308 user_info->mapped.account_name, 304 309 unix_username)); 305 310 } … … 310 315 /* failed authentication; check for guest lapping */ 311 316 312 DEBUG(2, ("check_ntlm_password: Authentication for user [%s] -> [%s] FAILED with error %s\n", 313 user_info-> smb_name, user_info->internal_username,317 DEBUG(2, ("check_ntlm_password: Authentication for user [%s] -> [%s] FAILED with error %s\n", 318 user_info->client.account_name, user_info->mapped.account_name, 314 319 nt_errstr(nt_status))); 315 ZERO_STRUCTP(server_info); 320 ZERO_STRUCTP(server_info); 316 321 317 322 return nt_status; … … 322 327 ***************************************************************************/ 323 328 324 static void free_auth_context(struct auth_context **auth_context) 325 { 326 auth_methods *auth_method; 327 328 if (*auth_context) { 329 /* Free private data of context's authentication methods */ 330 for (auth_method = (*auth_context)->auth_method_list; auth_method; auth_method = auth_method->next) { 331 TALLOC_FREE(auth_method->private_data); 332 } 333 334 talloc_destroy((*auth_context)->mem_ctx); 335 *auth_context = NULL; 336 } 329 static int auth_context_destructor(void *ptr) 330 { 331 struct auth_context *ctx = talloc_get_type(ptr, struct auth_context); 332 struct auth_methods *am; 333 334 335 /* Free private data of context's authentication methods */ 336 for (am = ctx->auth_method_list; am; am = am->next) { 337 TALLOC_FREE(am->private_data); 338 } 339 340 return 0; 337 341 } 338 342 … … 341 345 ***************************************************************************/ 342 346 343 static NTSTATUS make_auth_context(struct auth_context **auth_context) 344 { 345 TALLOC_CTX *mem_ctx; 346 347 mem_ctx = talloc_init("authentication context"); 348 349 *auth_context = TALLOC_P(mem_ctx, struct auth_context); 350 if (!*auth_context) { 347 static NTSTATUS make_auth_context(TALLOC_CTX *mem_ctx, 348 struct auth_context **auth_context) 349 { 350 struct auth_context *ctx; 351 352 ctx = talloc_zero(mem_ctx, struct auth_context); 353 if (!ctx) { 351 354 DEBUG(0,("make_auth_context: talloc failed!\n")); 352 talloc_destroy(mem_ctx);353 355 return NT_STATUS_NO_MEMORY; 354 356 } 355 ZERO_STRUCTP(*auth_context); 356 357 (*auth_context)->mem_ctx = mem_ctx;358 (*auth_context)->check_ntlm_password = check_ntlm_password; 359 (*auth_context)->get_ntlm_challenge = get_ntlm_challenge;360 (*auth_context)->free = free_auth_context; 361 357 358 ctx->check_ntlm_password = check_ntlm_password; 359 ctx->get_ntlm_challenge = get_ntlm_challenge; 360 361 talloc_set_destructor((TALLOC_CTX *)ctx, auth_context_destructor); 362 363 *auth_context = ctx; 362 364 return NT_STATUS_OK; 363 365 } … … 421 423 ***************************************************************************/ 422 424 423 static NTSTATUS make_auth_context_text_list(struct auth_context **auth_context, char **text_list) 425 static NTSTATUS make_auth_context_text_list(TALLOC_CTX *mem_ctx, 426 struct auth_context **auth_context, 427 char **text_list) 424 428 { 425 429 auth_methods *list = NULL; … … 432 436 } 433 437 434 if (!NT_STATUS_IS_OK(nt_status = make_auth_context(auth_context))) 438 nt_status = make_auth_context(mem_ctx, auth_context); 439 440 if (!NT_STATUS_IS_OK(nt_status)) { 435 441 return nt_status; 442 } 436 443 437 444 for (;*text_list; text_list++) { … … 450 457 ***************************************************************************/ 451 458 452 NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context) 459 NTSTATUS make_auth_context_subsystem(TALLOC_CTX *mem_ctx, 460 struct auth_context **auth_context) 453 461 { 454 462 char **auth_method_list = NULL; … … 521 529 } 522 530 523 nt_status = make_auth_context_text_list( auth_context,531 nt_status = make_auth_context_text_list(mem_ctx, auth_context, 524 532 auth_method_list); 525 533 … … 532 540 ***************************************************************************/ 533 541 534 NTSTATUS make_auth_context_fixed(struct auth_context **auth_context, uchar chal[8]) 542 NTSTATUS make_auth_context_fixed(TALLOC_CTX *mem_ctx, 543 struct auth_context **auth_context, 544 uchar chal[8]) 535 545 { 536 546 NTSTATUS nt_status; 537 if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(auth_context))) { 547 nt_status = make_auth_context_subsystem(mem_ctx, auth_context); 548 if (!NT_STATUS_IS_OK(nt_status)) { 538 549 return nt_status; 539 550 } 540 551 541 (*auth_context)->challenge = data_blob_talloc( (*auth_context)->mem_ctx, chal, 8);552 (*auth_context)->challenge = data_blob_talloc(*auth_context, chal, 8); 542 553 (*auth_context)->challenge_set_by = "fixed"; 543 554 return nt_status;
Note:
See TracChangeset
for help on using the changeset viewer.