lib/tdb: sync build system changes and python code from samba4
[samba.git] / source / libsmb / pwd_cache.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password cacheing.  obfuscation is planned
4    Copyright (C) Luke Kenneth Casson Leighton 1996-1998
5    
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 3 of the License, or
9    (at your option) any later version.
10    
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.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21
22 /****************************************************************************
23  Initialises a password structure.
24 ****************************************************************************/
25
26 static void pwd_init(struct pwd_info *pwd)
27 {
28         memset((char *)pwd->password  , '\0', sizeof(pwd->password  ));
29
30         pwd->null_pwd  = True; /* safest option... */
31 }
32
33 /****************************************************************************
34  Stores a cleartext password.
35 ****************************************************************************/
36
37 void pwd_set_cleartext(struct pwd_info *pwd, const char *clr)
38 {
39         pwd_init(pwd);
40         if (clr) {
41                 fstrcpy(pwd->password, clr);
42                 pwd->null_pwd = False;
43         } else {
44                 pwd->null_pwd = True;
45         }
46
47         pwd->cleartext = True;
48 }
49
50 /****************************************************************************
51  Gets a cleartext password.
52 ****************************************************************************/
53
54 void pwd_get_cleartext(struct pwd_info *pwd, fstring clr)
55 {
56         if (pwd->cleartext)
57                 fstrcpy(clr, pwd->password);
58         else
59                 clr[0] = 0;
60
61 }