s3-auth: Remove obsolete 'update encrypted' option.
[ira/wip.git] / source3 / auth / auth_unix.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password and authentication handling
4    Copyright (C) Andrew Bartlett              2001
5
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.
10
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.
15
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/>.
18 */
19
20 #include "includes.h"
21 #include "../librpc/gen_ndr/samr.h"
22
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_AUTH
25
26 /** Check a plaintext username/password
27  *
28  * Cannot deal with an encrupted password in any manner whatsoever,
29  * unless the account has a null password.
30  **/
31
32 static NTSTATUS check_unix_security(const struct auth_context *auth_context,
33                              void *my_private_data, 
34                              TALLOC_CTX *mem_ctx,
35                              const struct auth_usersupplied_info *user_info,
36                              struct auth_serversupplied_info **server_info)
37 {
38         NTSTATUS nt_status;
39         struct passwd *pass = NULL;
40
41         DEBUG(10, ("Check auth for: [%s]\n", user_info->mapped.account_name));
42
43         become_root();
44         pass = Get_Pwnam_alloc(talloc_tos(), user_info->mapped.account_name);
45
46         /** @todo This call assumes a ASCII password, no charset transformation is 
47             done.  We may need to revisit this **/
48         nt_status = pass_check(pass,
49                                 pass ? pass->pw_name : user_info->mapped.account_name,
50                                 user_info->password.plaintext,
51                                 true);
52
53         unbecome_root();
54
55         if (NT_STATUS_IS_OK(nt_status)) {
56                 if (pass) {
57                         /* if a real user check pam account restrictions */
58                         /* only really perfomed if "obey pam restriction" is true */
59                         nt_status = smb_pam_accountcheck(pass->pw_name);
60                         if (  !NT_STATUS_IS_OK(nt_status)) {
61                                 DEBUG(1, ("PAM account restriction prevents user login\n"));
62                         } else {
63                                 make_server_info_pw(server_info, pass->pw_name, pass);
64                         }
65                 } else {
66                         /* we need to do somthing more useful here */
67                         nt_status = NT_STATUS_NO_SUCH_USER;
68                 }
69         }
70
71         TALLOC_FREE(pass);
72         return nt_status;
73 }
74
75 /* module initialisation */
76 static NTSTATUS auth_init_unix(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
77 {
78         struct auth_methods *result;
79
80         result = TALLOC_ZERO_P(auth_context, struct auth_methods);
81         if (result == NULL) {
82                 return NT_STATUS_NO_MEMORY;
83         }
84         result->name = "unix";
85         result->auth = check_unix_security;
86
87         *auth_method = result;
88         return NT_STATUS_OK;
89 }
90
91 NTSTATUS auth_unix_init(void)
92 {
93         return smb_register_auth(AUTH_INTERFACE_VERSION, "unix", auth_init_unix);
94 }