s4:libcli/raw: s/SMBchkpth/SMBcheckpath
[Samba/gebeck_regimport.git] / source3 / auth / auth_unix.c
blob6f232ec66ce801694755836f904d6a8424c03b2b
1 /*
2 Unix SMB/CIFS implementation.
3 Password and authentication handling
4 Copyright (C) Andrew Bartlett 2001
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "auth.h"
22 #include "system/passwd.h"
23 #include "../lib/tsocket/tsocket.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_AUTH
28 /** Check a plaintext username/password
30 * Cannot deal with an encrupted password in any manner whatsoever,
31 * unless the account has a null password.
32 **/
34 static NTSTATUS check_unix_security(const struct auth_context *auth_context,
35 void *my_private_data,
36 TALLOC_CTX *mem_ctx,
37 const struct auth_usersupplied_info *user_info,
38 struct auth_serversupplied_info **server_info)
40 NTSTATUS nt_status;
41 struct passwd *pass = NULL;
42 char *rhost;
44 DEBUG(10, ("Check auth for: [%s]\n", user_info->mapped.account_name));
46 rhost = tsocket_address_inet_addr_string(user_info->remote_host,
47 talloc_tos());
48 if (rhost == NULL) {
49 return NT_STATUS_NO_MEMORY;
52 become_root();
53 pass = Get_Pwnam_alloc(talloc_tos(), user_info->mapped.account_name);
55 /** @todo This call assumes a ASCII password, no charset transformation is
56 done. We may need to revisit this **/
57 nt_status = pass_check(pass,
58 pass ? pass->pw_name : user_info->mapped.account_name,
59 rhost,
60 user_info->password.plaintext,
61 true);
63 unbecome_root();
65 if (NT_STATUS_IS_OK(nt_status)) {
66 if (pass) {
67 make_server_info_pw(server_info, pass->pw_name, pass);
68 } else {
69 /* we need to do somthing more useful here */
70 nt_status = NT_STATUS_NO_SUCH_USER;
74 TALLOC_FREE(pass);
75 return nt_status;
78 /* module initialisation */
79 static NTSTATUS auth_init_unix(struct auth_context *auth_context, const char* param, auth_methods **auth_method)
81 struct auth_methods *result;
83 result = talloc_zero(auth_context, struct auth_methods);
84 if (result == NULL) {
85 return NT_STATUS_NO_MEMORY;
87 result->name = "unix";
88 result->auth = check_unix_security;
90 *auth_method = result;
91 return NT_STATUS_OK;
94 NTSTATUS auth_unix_init(void)
96 return smb_register_auth(AUTH_INTERFACE_VERSION, "unix", auth_init_unix);