Code indentation.
[midnight-commander.git] / src / vfs / smbfs / helpers / libsmb / pwd_cache.c
blob09c6b08121e65f0e21b4c37517a5818f467ee23d
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Password cacheing. obfuscation is planned
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8 Copyright (C) 2011
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/>.
27 #include "includes.h"
29 extern int DEBUGLEVEL;
32 /****************************************************************************
33 initialises a password structure
34 ****************************************************************************/
35 void
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;
46 pwd->crypted = False;
49 /****************************************************************************
50 de-obfuscates a password
51 ****************************************************************************/
52 static void
53 pwd_deobfuscate (struct pwd_info *pwd)
55 (void) pwd;
58 /****************************************************************************
59 obfuscates a password
60 ****************************************************************************/
61 static void
62 pwd_obfuscate (struct pwd_info *pwd)
64 (void) pwd;
67 /****************************************************************************
68 sets the obfuscation key info
69 ****************************************************************************/
70 void
71 pwd_obfuscate_key (struct pwd_info *pwd, uint32 int_key, char *str_key)
73 (void) pwd;
74 (void) int_key;
75 (void) str_key;
78 #if 0
79 /****************************************************************************
80 reads a password
81 ****************************************************************************/
82 void
83 pwd_read (struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
85 /* grab a password */
86 char *user_pass;
88 pwd_init (pwd);
90 user_pass = (char *) getpass (passwd_report);
92 if (user_pass == NULL || user_pass[0] == 0)
94 pwd_set_nullpwd (pwd);
96 else if (do_encrypt)
98 pwd_make_lm_nt_16 (pwd, user_pass);
100 else
102 pwd_set_cleartext (pwd, user_pass);
105 #endif
107 /****************************************************************************
108 stores a cleartext password
109 ****************************************************************************/
110 void
111 pwd_set_nullpwd (struct pwd_info *pwd)
113 pwd_init (pwd);
115 pwd->cleartext = False;
116 pwd->null_pwd = True;
117 pwd->crypted = False;
120 /****************************************************************************
121 stores a cleartext password
122 ****************************************************************************/
123 void
124 pwd_set_cleartext (struct pwd_info *pwd, char *clr)
126 pwd_init (pwd);
127 fstrcpy (pwd->password, clr);
128 pwd->cleartext = True;
129 pwd->null_pwd = False;
130 pwd->crypted = False;
132 pwd_obfuscate (pwd);
135 /****************************************************************************
136 gets a cleartext password
137 ****************************************************************************/
138 void
139 pwd_get_cleartext (struct pwd_info *pwd, char *clr)
141 pwd_deobfuscate (pwd);
142 if (pwd->cleartext)
144 fstrcpy (clr, pwd->password);
146 else
148 clr[0] = 0;
150 pwd_obfuscate (pwd);
153 /****************************************************************************
154 stores lm and nt hashed passwords
155 ****************************************************************************/
156 void
157 pwd_set_lm_nt_16 (struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
159 pwd_init (pwd);
161 if (lm_pwd)
163 memcpy (pwd->smb_lm_pwd, lm_pwd, 16);
165 else
167 memset ((char *) pwd->smb_lm_pwd, '\0', 16);
170 if (nt_pwd)
172 memcpy (pwd->smb_nt_pwd, nt_pwd, 16);
174 else
176 memset ((char *) pwd->smb_nt_pwd, '\0', 16);
179 pwd->null_pwd = False;
180 pwd->cleartext = False;
181 pwd->crypted = False;
183 pwd_obfuscate (pwd);
186 /****************************************************************************
187 gets lm and nt hashed passwords
188 ****************************************************************************/
189 void
190 pwd_get_lm_nt_16 (struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
192 pwd_deobfuscate (pwd);
193 if (lm_pwd != NULL)
195 memcpy (lm_pwd, pwd->smb_lm_pwd, 16);
197 if (nt_pwd != NULL)
199 memcpy (nt_pwd, pwd->smb_nt_pwd, 16);
201 pwd_obfuscate (pwd);
204 /****************************************************************************
205 makes lm and nt hashed passwords
206 ****************************************************************************/
207 void
208 pwd_make_lm_nt_16 (struct pwd_info *pwd, char *clr)
210 pwd_init (pwd);
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;
217 pwd_obfuscate (pwd);
220 /****************************************************************************
221 makes lm and nt OWF crypts
222 ****************************************************************************/
223 void
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);
231 #endif
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));
240 #endif
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));
249 #endif
251 pwd->crypted = True;
253 pwd_obfuscate (pwd);
256 /****************************************************************************
257 gets lm and nt crypts
258 ****************************************************************************/
259 void
260 pwd_get_lm_nt_owf (struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
262 pwd_deobfuscate (pwd);
263 if (lm_owf != NULL)
265 memcpy (lm_owf, pwd->smb_lm_owf, 24);
267 if (nt_owf != NULL)
269 memcpy (nt_owf, pwd->smb_nt_owf, 24);
271 pwd_obfuscate (pwd);