2 Unix SMB/Netbios implementation.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
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;
43 /****************************************************************************
44 de-obfuscates a password
45 ****************************************************************************/
46 static void pwd_deobfuscate(struct pwd_info *pwd)
50 /****************************************************************************
52 ****************************************************************************/
53 static void pwd_obfuscate(struct pwd_info *pwd)
57 /****************************************************************************
58 sets the obfuscation key info
59 ****************************************************************************/
60 void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
64 /****************************************************************************
65 compares two passwords. hmm, not as trivial as expected. hmm.
66 ****************************************************************************/
67 BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2)
69 pwd_deobfuscate(pwd1);
70 pwd_deobfuscate(pwd2);
71 if (pwd1->cleartext && pwd2->cleartext)
73 if (strequal(pwd1->password, pwd2->password))
80 if (pwd1->null_pwd && pwd2->null_pwd)
87 if (!pwd1->null_pwd && !pwd2->null_pwd &&
88 !pwd1->cleartext && !pwd2->cleartext)
91 DEBUG(100,("pwd compare: nt#\n"));
92 dump_data(100, pwd1->smb_nt_pwd, 16);
93 dump_data(100, pwd2->smb_nt_pwd, 16);
95 if (memcmp(pwd1->smb_nt_pwd, pwd2->smb_nt_pwd, 16) == 0)
101 #ifdef DEBUG_PASSWORD
102 DEBUG(100,("pwd compare: lm#\n"));
103 dump_data(100, pwd1->smb_lm_pwd, 16);
104 dump_data(100, pwd2->smb_lm_pwd, 16);
106 if (memcmp(pwd1->smb_lm_pwd, pwd2->smb_lm_pwd, 16) == 0)
118 /****************************************************************************
120 ****************************************************************************/
121 void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
123 /* grab a password */
128 user_pass = (char*)getpass(passwd_report);
130 if (user_pass == NULL || user_pass[0] == 0)
132 pwd_set_nullpwd(pwd);
136 pwd_make_lm_nt_16(pwd, user_pass);
140 pwd_set_cleartext(pwd, user_pass);
144 /****************************************************************************
145 stores a cleartext password
146 ****************************************************************************/
147 void pwd_set_nullpwd(struct pwd_info *pwd)
151 pwd->cleartext = False;
152 pwd->null_pwd = True;
153 pwd->crypted = False;
156 /****************************************************************************
157 stores a cleartext password
158 ****************************************************************************/
159 void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
162 fstrcpy(pwd->password, clr);
163 unix_to_dos(pwd->password,True);
164 pwd->cleartext = True;
165 pwd->null_pwd = False;
166 pwd->crypted = False;
171 /****************************************************************************
172 gets a cleartext password
173 ****************************************************************************/
174 void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
176 pwd_deobfuscate(pwd);
179 fstrcpy(clr, pwd->password);
180 dos_to_unix(clr, True);
189 /****************************************************************************
190 stores lm and nt hashed passwords
191 ****************************************************************************/
192 void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
198 memcpy(pwd->smb_lm_pwd, lm_pwd, 16);
202 memset((char *)pwd->smb_lm_pwd, '\0', 16);
207 memcpy(pwd->smb_nt_pwd, nt_pwd, 16);
211 memset((char *)pwd->smb_nt_pwd, '\0', 16);
214 pwd->null_pwd = False;
215 pwd->cleartext = False;
216 pwd->crypted = False;
221 /****************************************************************************
222 gets lm and nt hashed passwords
223 ****************************************************************************/
224 void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
226 pwd_deobfuscate(pwd);
229 memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
233 memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
238 /****************************************************************************
239 makes lm and nt hashed passwords
240 ****************************************************************************/
241 void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
247 pstrcpy(dos_passwd, clr);
248 unix_to_dos(dos_passwd, True);
250 nt_lm_owf_gen(dos_passwd, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
251 pwd->null_pwd = False;
252 pwd->cleartext = False;
253 pwd->crypted = False;
258 /****************************************************************************
259 makes lm and nt OWF crypts
260 ****************************************************************************/
261 void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
263 pwd_deobfuscate(pwd);
265 #ifdef DEBUG_PASSWORD
266 DEBUG(100,("client cryptkey: "));
267 dump_data(100, (char *)cryptkey, 8);
270 SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
272 #ifdef DEBUG_PASSWORD
273 DEBUG(100,("nt_owf_passwd: "));
274 dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf));
275 DEBUG(100,("nt_sess_pwd: "));
276 dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
279 SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
281 #ifdef DEBUG_PASSWORD
282 DEBUG(100,("lm_owf_passwd: "));
283 dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
284 DEBUG(100,("lm_sess_pwd: "));
285 dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
293 /****************************************************************************
294 gets lm and nt crypts
295 ****************************************************************************/
296 void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
298 pwd_deobfuscate(pwd);
301 memcpy(lm_owf, pwd->smb_lm_owf, 24);
305 memcpy(nt_owf, pwd->smb_nt_owf, 24);