auth.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 540 行 · 第 1/2 页
C
540 行
auth_method->name, user_info->smb_name.str, nt_errstr(nt_status))); } talloc_destroy(mem_ctx); if ( NT_STATUS_IS_OK(nt_status)) { break; } } /* successful authentication */ if (NT_STATUS_IS_OK(nt_status)) { unix_username = (*server_info)->unix_name; if (!(*server_info)->guest) { /* We might not be root if we are an RPC call */ become_root(); nt_status = smb_pam_accountcheck(unix_username); unbecome_root(); if (NT_STATUS_IS_OK(nt_status)) { DEBUG(5, ("check_ntlm_password: PAM Account for user [%s] succeeded\n", unix_username)); } else { DEBUG(3, ("check_ntlm_password: PAM Account for user [%s] FAILED with error %s\n", unix_username, nt_errstr(nt_status))); } } if (NT_STATUS_IS_OK(nt_status)) { DEBUG((*server_info)->guest ? 5 : 2, ("check_ntlm_password: %sauthentication for user [%s] -> [%s] -> [%s] succeeded\n", (*server_info)->guest ? "guest " : "", user_info->smb_name.str, user_info->internal_username.str, unix_username)); } return nt_status; } /* failed authentication; check for guest lapping */ DEBUG(2, ("check_ntlm_password: Authentication for user [%s] -> [%s] FAILED with error %s\n", user_info->smb_name.str, user_info->internal_username.str, nt_errstr(nt_status))); ZERO_STRUCTP(server_info); return nt_status;}/*************************************************************************** Clear out a auth_context, and destroy the attached TALLOC_CTX***************************************************************************/static void free_auth_context(struct auth_context **auth_context){ auth_methods *auth_method; if (*auth_context) { /* Free private data of context's authentication methods */ for (auth_method = (*auth_context)->auth_method_list; auth_method; auth_method = auth_method->next) { if (auth_method->free_private_data) { auth_method->free_private_data (&auth_method->private_data); auth_method->private_data = NULL; } } talloc_destroy((*auth_context)->mem_ctx); *auth_context = NULL; }}/*************************************************************************** Make a auth_info struct***************************************************************************/static NTSTATUS make_auth_context(struct auth_context **auth_context) { TALLOC_CTX *mem_ctx; mem_ctx = talloc_init("authentication context"); *auth_context = TALLOC_P(mem_ctx, struct auth_context); if (!*auth_context) { DEBUG(0,("make_auth_context: talloc failed!\n")); talloc_destroy(mem_ctx); return NT_STATUS_NO_MEMORY; } ZERO_STRUCTP(*auth_context); (*auth_context)->mem_ctx = mem_ctx; (*auth_context)->check_ntlm_password = check_ntlm_password; (*auth_context)->get_ntlm_challenge = get_ntlm_challenge; (*auth_context)->free = free_auth_context; return NT_STATUS_OK;}BOOL load_auth_module(struct auth_context *auth_context, const char *module, auth_methods **ret) { static BOOL initialised_static_modules = False; struct auth_init_function_entry *entry; char *module_name = smb_xstrdup(module); char *module_params = NULL; char *p; BOOL good = False; /* Initialise static modules if not done so yet */ if(!initialised_static_modules) { static_init_auth; initialised_static_modules = True; } DEBUG(5,("load_auth_module: Attempting to find an auth method to match %s\n", module)); p = strchr(module_name, ':'); if (p) { *p = 0; module_params = p+1; trim_char(module_params, ' ', ' '); } trim_char(module_name, ' ', ' '); entry = auth_find_backend_entry(module_name); if (entry == NULL) { if (NT_STATUS_IS_OK(smb_probe_module("auth", module_name))) { entry = auth_find_backend_entry(module_name); } } if (entry != NULL) { if (!NT_STATUS_IS_OK(entry->init(auth_context, module_params, ret))) { DEBUG(0,("load_auth_module: auth method %s did not correctly init\n", module_name)); } else { DEBUG(5,("load_auth_module: auth method %s has a valid init\n", module_name)); good = True; } } else { DEBUG(0,("load_auth_module: can't find auth method %s!\n", module_name)); } SAFE_FREE(module_name); return good;}/*************************************************************************** Make a auth_info struct for the auth subsystem***************************************************************************/static NTSTATUS make_auth_context_text_list(struct auth_context **auth_context, char **text_list) { auth_methods *list = NULL; auth_methods *t = NULL; auth_methods *tmp; NTSTATUS nt_status; if (!text_list) { DEBUG(2,("make_auth_context_text_list: No auth method list!?\n")); return NT_STATUS_UNSUCCESSFUL; } if (!NT_STATUS_IS_OK(nt_status = make_auth_context(auth_context))) return nt_status; for (;*text_list; text_list++) { if (load_auth_module(*auth_context, *text_list, &t)) { DLIST_ADD_END(list, t, tmp); } } (*auth_context)->auth_method_list = list; return nt_status;}/*************************************************************************** Make a auth_context struct for the auth subsystem***************************************************************************/NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context) { char **auth_method_list = NULL; NTSTATUS nt_status; if (lp_auth_methods() && !str_list_copy(&auth_method_list, lp_auth_methods())) { return NT_STATUS_NO_MEMORY; } if (auth_method_list == NULL) { switch (lp_security()) { case SEC_DOMAIN: DEBUG(5,("Making default auth method list for security=domain\n")); auth_method_list = str_list_make("guest sam winbind:ntdomain", NULL); break; case SEC_SERVER: DEBUG(5,("Making default auth method list for security=server\n")); auth_method_list = str_list_make("guest sam smbserver", NULL); break; case SEC_USER: if (lp_encrypted_passwords()) { if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) { DEBUG(5,("Making default auth method list for DC, security=user, encrypt passwords = yes\n")); auth_method_list = str_list_make("guest sam winbind:trustdomain", NULL); } else { DEBUG(5,("Making default auth method list for standalone security=user, encrypt passwords = yes\n")); auth_method_list = str_list_make("guest sam", NULL); } } else { DEBUG(5,("Making default auth method list for security=user, encrypt passwords = no\n")); auth_method_list = str_list_make("guest unix", NULL); } break; case SEC_SHARE: if (lp_encrypted_passwords()) { DEBUG(5,("Making default auth method list for security=share, encrypt passwords = yes\n")); auth_method_list = str_list_make("guest sam", NULL); } else { DEBUG(5,("Making default auth method list for security=share, encrypt passwords = no\n")); auth_method_list = str_list_make("guest unix", NULL); } break; case SEC_ADS: DEBUG(5,("Making default auth method list for security=ADS\n")); auth_method_list = str_list_make("guest sam winbind:ntdomain", NULL); break; default: DEBUG(5,("Unknown auth method!\n")); return NT_STATUS_UNSUCCESSFUL; } } else { DEBUG(5,("Using specified auth order\n")); } if (!NT_STATUS_IS_OK(nt_status = make_auth_context_text_list(auth_context, auth_method_list))) { str_list_free(&auth_method_list); return nt_status; } str_list_free(&auth_method_list); return nt_status;}/*************************************************************************** Make a auth_info struct with a fixed challenge***************************************************************************/NTSTATUS make_auth_context_fixed(struct auth_context **auth_context, uchar chal[8]) { NTSTATUS nt_status; if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(auth_context))) { return nt_status; } (*auth_context)->challenge = data_blob_talloc((*auth_context)->mem_ctx, chal, 8); (*auth_context)->challenge_set_by = "fixed"; return nt_status;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?