2 Unix SMB/Netbios implementation.
4 Password cacheing. obfuscation is planned
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
9 The Free Software Foundation, Inc.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 extern int DEBUGLEVEL
;
32 /****************************************************************************
33 initialises a password structure
34 ****************************************************************************/
36 pwd_init (struct pwd_info
*pwd
)
38 memset ((char *) pwd
->password
, '\0', sizeof (pwd
->password
));
39 memset ((char *) pwd
->smb_lm_pwd
, '\0', sizeof (pwd
->smb_lm_pwd
));
40 memset ((char *) pwd
->smb_nt_pwd
, '\0', sizeof (pwd
->smb_nt_pwd
));
41 memset ((char *) pwd
->smb_lm_owf
, '\0', sizeof (pwd
->smb_lm_owf
));
42 memset ((char *) pwd
->smb_nt_owf
, '\0', sizeof (pwd
->smb_nt_owf
));
44 pwd
->null_pwd
= True
; /* safest option... */
45 pwd
->cleartext
= False
;
49 /****************************************************************************
50 de-obfuscates a password
51 ****************************************************************************/
53 pwd_deobfuscate (struct pwd_info
*pwd
)
58 /****************************************************************************
60 ****************************************************************************/
62 pwd_obfuscate (struct pwd_info
*pwd
)
67 /****************************************************************************
68 sets the obfuscation key info
69 ****************************************************************************/
71 pwd_obfuscate_key (struct pwd_info
*pwd
, uint32 int_key
, char *str_key
)
79 /****************************************************************************
81 ****************************************************************************/
83 pwd_read (struct pwd_info
*pwd
, char *passwd_report
, BOOL do_encrypt
)
90 user_pass
= (char *) getpass (passwd_report
);
92 if (user_pass
== NULL
|| user_pass
[0] == 0)
94 pwd_set_nullpwd (pwd
);
98 pwd_make_lm_nt_16 (pwd
, user_pass
);
102 pwd_set_cleartext (pwd
, user_pass
);
107 /****************************************************************************
108 stores a cleartext password
109 ****************************************************************************/
111 pwd_set_nullpwd (struct pwd_info
*pwd
)
115 pwd
->cleartext
= False
;
116 pwd
->null_pwd
= True
;
117 pwd
->crypted
= False
;
120 /****************************************************************************
121 stores a cleartext password
122 ****************************************************************************/
124 pwd_set_cleartext (struct pwd_info
*pwd
, char *clr
)
127 fstrcpy (pwd
->password
, clr
);
128 pwd
->cleartext
= True
;
129 pwd
->null_pwd
= False
;
130 pwd
->crypted
= False
;
135 /****************************************************************************
136 gets a cleartext password
137 ****************************************************************************/
139 pwd_get_cleartext (struct pwd_info
*pwd
, char *clr
)
141 pwd_deobfuscate (pwd
);
144 fstrcpy (clr
, pwd
->password
);
153 /****************************************************************************
154 stores lm and nt hashed passwords
155 ****************************************************************************/
157 pwd_set_lm_nt_16 (struct pwd_info
*pwd
, uchar lm_pwd
[16], uchar nt_pwd
[16])
163 memcpy (pwd
->smb_lm_pwd
, lm_pwd
, 16);
167 memset ((char *) pwd
->smb_lm_pwd
, '\0', 16);
172 memcpy (pwd
->smb_nt_pwd
, nt_pwd
, 16);
176 memset ((char *) pwd
->smb_nt_pwd
, '\0', 16);
179 pwd
->null_pwd
= False
;
180 pwd
->cleartext
= False
;
181 pwd
->crypted
= False
;
186 /****************************************************************************
187 gets lm and nt hashed passwords
188 ****************************************************************************/
190 pwd_get_lm_nt_16 (struct pwd_info
*pwd
, uchar lm_pwd
[16], uchar nt_pwd
[16])
192 pwd_deobfuscate (pwd
);
195 memcpy (lm_pwd
, pwd
->smb_lm_pwd
, 16);
199 memcpy (nt_pwd
, pwd
->smb_nt_pwd
, 16);
204 /****************************************************************************
205 makes lm and nt hashed passwords
206 ****************************************************************************/
208 pwd_make_lm_nt_16 (struct pwd_info
*pwd
, char *clr
)
212 nt_lm_owf_gen (clr
, pwd
->smb_nt_pwd
, pwd
->smb_lm_pwd
);
213 pwd
->null_pwd
= False
;
214 pwd
->cleartext
= False
;
215 pwd
->crypted
= False
;
220 /****************************************************************************
221 makes lm and nt OWF crypts
222 ****************************************************************************/
224 pwd_make_lm_nt_owf (struct pwd_info
*pwd
, uchar cryptkey
[8])
226 pwd_deobfuscate (pwd
);
228 #ifdef DEBUG_PASSWORD
229 DEBUG (100, ("client cryptkey: "));
230 dump_data (100, (char *) cryptkey
, 8);
233 SMBOWFencrypt (pwd
->smb_nt_pwd
, cryptkey
, pwd
->smb_nt_owf
);
235 #ifdef DEBUG_PASSWORD
236 DEBUG (100, ("nt_owf_passwd: "));
237 dump_data (100, (char *) pwd
->smb_nt_owf
, sizeof (pwd
->smb_nt_owf
));
238 DEBUG (100, ("nt_sess_pwd: "));
239 dump_data (100, (char *) pwd
->smb_nt_pwd
, sizeof (pwd
->smb_nt_pwd
));
242 SMBOWFencrypt (pwd
->smb_lm_pwd
, cryptkey
, pwd
->smb_lm_owf
);
244 #ifdef DEBUG_PASSWORD
245 DEBUG (100, ("lm_owf_passwd: "));
246 dump_data (100, (char *) pwd
->smb_lm_owf
, sizeof (pwd
->smb_lm_owf
));
247 DEBUG (100, ("lm_sess_pwd: "));
248 dump_data (100, (char *) pwd
->smb_lm_pwd
, sizeof (pwd
->smb_lm_pwd
));
256 /****************************************************************************
257 gets lm and nt crypts
258 ****************************************************************************/
260 pwd_get_lm_nt_owf (struct pwd_info
*pwd
, uchar lm_owf
[24], uchar nt_owf
[24])
262 pwd_deobfuscate (pwd
);
265 memcpy (lm_owf
, pwd
->smb_lm_owf
, 24);
269 memcpy (nt_owf
, pwd
->smb_nt_owf
, 24);