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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DBGC_CLASS DBGC_AUTH
27 * update the encrypted smbpasswd file from the plaintext username and password
29 * this ugly hack needs to die, but not quite yet, I think people still use it...
31 static BOOL update_smbpassword_file(const char *user, const char *password)
36 if ( !(sampass = samu_new( NULL )) ) {
41 ret = pdb_getsampwnam(sampass, user);
45 DEBUG(0,("pdb_getsampwnam returned NULL\n"));
51 * Remove the account disabled flag - we are updating the
52 * users password from a login.
54 if (!pdb_set_acct_ctrl(sampass, pdb_get_acct_ctrl(sampass) & ~ACB_DISABLED, PDB_CHANGED)) {
59 if (!pdb_set_plaintext_passwd (sampass, password)) {
64 /* Now write it into the file. */
67 ret = NT_STATUS_IS_OK(pdb_update_sam_account (sampass));
72 DEBUG(3,("pdb_update_sam_account returned %d\n",ret));
80 /** Check a plaintext username/password
82 * Cannot deal with an encrupted password in any manner whatsoever,
83 * unless the account has a null password.
86 static NTSTATUS check_unix_security(const struct auth_context *auth_context,
87 void *my_private_data,
89 const auth_usersupplied_info *user_info,
90 auth_serversupplied_info **server_info)
93 struct passwd *pass = NULL;
96 pass = Get_Pwnam(user_info->internal_username);
99 /** @todo This call assumes a ASCII password, no charset transformation is
100 done. We may need to revisit this **/
101 nt_status = pass_check(pass,
102 pass ? pass->pw_name : user_info->internal_username,
103 (char *)user_info->plaintext_password.data,
104 user_info->plaintext_password.length-1,
105 lp_update_encrypted() ?
106 update_smbpassword_file : NULL,
111 if (NT_STATUS_IS_OK(nt_status)) {
113 make_server_info_pw(server_info, pass->pw_name, pass);
115 /* we need to do somthing more useful here */
116 nt_status = NT_STATUS_NO_SUCH_USER;
123 /* module initialisation */
124 static NTSTATUS auth_init_unix(struct auth_context *auth_context, const char* param, auth_methods **auth_method)
126 if (!make_auth_methods(auth_context, auth_method)) {
127 return NT_STATUS_NO_MEMORY;
130 (*auth_method)->name = "unix";
131 (*auth_method)->auth = check_unix_security;
135 NTSTATUS auth_unix_init(void)
137 return smb_register_auth(AUTH_INTERFACE_VERSION, "unix", auth_init_unix);