Move pass_check.c over to NTSTATUS, allowing full NTSTATUS from PAM to wire!
[kai/samba.git] / source3 / auth / auth_unix.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.2
4    Password and authentication handling
5    Copyright (C) Andrew Bartlett              2001
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 extern int DEBUGLEVEL;
25
26 /****************************************************************************
27 update the encrypted smbpasswd file from the plaintext username and password
28
29 this ugly hack needs to die, but not quite yet...
30 *****************************************************************************/
31 static BOOL update_smbpassword_file(char *user, char *password)
32 {
33         SAM_ACCOUNT     *sampass = NULL;
34         BOOL            ret;
35         
36         pdb_init_sam(&sampass);
37         
38         become_root();
39         ret = pdb_getsampwnam(sampass, user);
40         unbecome_root();
41
42         if(ret == False) {
43                 DEBUG(0,("pdb_getsampwnam returned NULL\n"));
44                 pdb_free_sam(sampass);
45                 return False;
46         }
47
48         /*
49          * Remove the account disabled flag - we are updating the
50          * users password from a login.
51          */
52         pdb_set_acct_ctrl(sampass, pdb_get_acct_ctrl(sampass) & ~ACB_DISABLED);
53
54         /* Here, the flag is one, because we want to ignore the
55            XXXXXXX'd out password */
56         ret = change_oem_password( sampass, password, True);
57         if (ret == False) {
58                 DEBUG(3,("change_oem_password returned False\n"));
59         }
60
61         pdb_free_sam(sampass);
62         return ret;
63 }
64
65
66 /****************************************************************************
67 check if a username/password is OK assuming the password 
68 in PLAIN TEXT
69 ****************************************************************************/
70
71 NTSTATUS check_unix_security(const auth_usersupplied_info *user_info, auth_serversupplied_info *server_info)
72 {
73         NTSTATUS nt_status;
74         struct passwd *pass = NULL;
75
76         become_root();
77         
78         pass = Get_Pwnam(user_info->unix_username.str, False);
79
80         nt_status = pass_check(pass,
81                                 pass ? pass->pw_name : user_info->unix_username.str, 
82                                 user_info->plaintext_password.str,
83                                 user_info->plaintext_password.len,
84                                 lp_update_encrypted() ? 
85                                 update_smbpassword_file : NULL,
86                                 True);
87
88         unbecome_root();
89
90         return nt_status;
91 }
92
93