Ticket #1649: Prepare for prerelease mc-4.7.0-pre3 (code cleanup)
[midnight-commander.git] / vfs / samba / libsmb / pwd_cache.c
blobe35fd31d5e3db1fe2eccf0cbbfb600209a34bce0
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Password cacheing. obfuscation is planned
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "includes.h"
24 extern int DEBUGLEVEL;
27 /****************************************************************************
28 initialises a password structure
29 ****************************************************************************/
30 void pwd_init(struct pwd_info *pwd)
32 memset((char *)pwd->password , '\0', sizeof(pwd->password ));
33 memset((char *)pwd->smb_lm_pwd, '\0', sizeof(pwd->smb_lm_pwd));
34 memset((char *)pwd->smb_nt_pwd, '\0', sizeof(pwd->smb_nt_pwd));
35 memset((char *)pwd->smb_lm_owf, '\0', sizeof(pwd->smb_lm_owf));
36 memset((char *)pwd->smb_nt_owf, '\0', sizeof(pwd->smb_nt_owf));
38 pwd->null_pwd = True; /* safest option... */
39 pwd->cleartext = False;
40 pwd->crypted = False;
43 /****************************************************************************
44 de-obfuscates a password
45 ****************************************************************************/
46 static void pwd_deobfuscate(struct pwd_info *pwd)
48 (void) pwd;
51 /****************************************************************************
52 obfuscates a password
53 ****************************************************************************/
54 static void pwd_obfuscate(struct pwd_info *pwd)
56 (void) pwd;
59 /****************************************************************************
60 sets the obfuscation key info
61 ****************************************************************************/
62 void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
64 (void) pwd;
65 (void) int_key;
66 (void) str_key;
69 #if 0
70 /****************************************************************************
71 reads a password
72 ****************************************************************************/
73 void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
75 /* grab a password */
76 char *user_pass;
78 pwd_init(pwd);
80 user_pass = (char*)getpass(passwd_report);
82 if (user_pass == NULL || user_pass[0] == 0)
84 pwd_set_nullpwd(pwd);
86 else if (do_encrypt)
88 pwd_make_lm_nt_16(pwd, user_pass);
90 else
92 pwd_set_cleartext(pwd, user_pass);
95 #endif
97 /****************************************************************************
98 stores a cleartext password
99 ****************************************************************************/
100 void pwd_set_nullpwd(struct pwd_info *pwd)
102 pwd_init(pwd);
104 pwd->cleartext = False;
105 pwd->null_pwd = True;
106 pwd->crypted = False;
109 /****************************************************************************
110 stores a cleartext password
111 ****************************************************************************/
112 void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
114 pwd_init(pwd);
115 fstrcpy(pwd->password, clr);
116 pwd->cleartext = True;
117 pwd->null_pwd = False;
118 pwd->crypted = False;
120 pwd_obfuscate(pwd);
123 /****************************************************************************
124 gets a cleartext password
125 ****************************************************************************/
126 void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
128 pwd_deobfuscate(pwd);
129 if (pwd->cleartext)
131 fstrcpy(clr, pwd->password);
133 else
135 clr[0] = 0;
137 pwd_obfuscate(pwd);
140 /****************************************************************************
141 stores lm and nt hashed passwords
142 ****************************************************************************/
143 void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
145 pwd_init(pwd);
147 if (lm_pwd)
149 memcpy(pwd->smb_lm_pwd, lm_pwd, 16);
151 else
153 memset((char *)pwd->smb_lm_pwd, '\0', 16);
156 if (nt_pwd)
158 memcpy(pwd->smb_nt_pwd, nt_pwd, 16);
160 else
162 memset((char *)pwd->smb_nt_pwd, '\0', 16);
165 pwd->null_pwd = False;
166 pwd->cleartext = False;
167 pwd->crypted = False;
169 pwd_obfuscate(pwd);
172 /****************************************************************************
173 gets lm and nt hashed passwords
174 ****************************************************************************/
175 void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
177 pwd_deobfuscate(pwd);
178 if (lm_pwd != NULL)
180 memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
182 if (nt_pwd != NULL)
184 memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
186 pwd_obfuscate(pwd);
189 /****************************************************************************
190 makes lm and nt hashed passwords
191 ****************************************************************************/
192 void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
194 pwd_init(pwd);
196 nt_lm_owf_gen(clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
197 pwd->null_pwd = False;
198 pwd->cleartext = False;
199 pwd->crypted = False;
201 pwd_obfuscate(pwd);
204 /****************************************************************************
205 makes lm and nt OWF crypts
206 ****************************************************************************/
207 void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
209 pwd_deobfuscate(pwd);
211 #ifdef DEBUG_PASSWORD
212 DEBUG(100,("client cryptkey: "));
213 dump_data(100, (char *)cryptkey, 8);
214 #endif
216 SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
218 #ifdef DEBUG_PASSWORD
219 DEBUG(100,("nt_owf_passwd: "));
220 dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf));
221 DEBUG(100,("nt_sess_pwd: "));
222 dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
223 #endif
225 SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
227 #ifdef DEBUG_PASSWORD
228 DEBUG(100,("lm_owf_passwd: "));
229 dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
230 DEBUG(100,("lm_sess_pwd: "));
231 dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
232 #endif
234 pwd->crypted = True;
236 pwd_obfuscate(pwd);
239 /****************************************************************************
240 gets lm and nt crypts
241 ****************************************************************************/
242 void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
244 pwd_deobfuscate(pwd);
245 if (lm_owf != NULL)
247 memcpy(lm_owf, pwd->smb_lm_owf, 24);
249 if (nt_owf != NULL)
251 memcpy(nt_owf, pwd->smb_nt_owf, 24);
253 pwd_obfuscate(pwd);