forked from comotion/cpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.c
192 lines (166 loc) · 6.07 KB
/
configuration.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* #############################################################################
* code for configuration handling
* #############################################################################
* Copyright (C) 2005-2009 Harry Brueckner
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contact: Harry Brueckner <[email protected]>
* Muenchener Strasse 12a
* 85253 Kleinberghofen
* Germany
* #############################################################################
*/
/* #############################################################################
* includes
*/
#include "cpm.h"
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif
#include "configuration.h"
#include "general.h"
#include "listhandler.h"
#include "memory.h"
/* #############################################################################
*
* Description clear the passphrase memory
* Author Harry Brueckner
* Date 2005-04-03
* Arguments int final - if set to 1, the passphrase is cleared under
* all circumstances; otherwise only if the
* keeppassphrase option is not set
* Return void
*/
void clearPassphrase(int final)
{
TRACE(99, "clearPassphrase()", NULL);
if (final || !config -> keeppassphrase)
{
memSet(runtime -> passphrase, 0, PASSPHRASE_LENGTH);
}
}
/* #############################################################################
*
* Description free the configuration
* Author Harry Brueckner
* Date 2005-03-17
* Arguments void
* Return void
*/
void freeConfiguration(void)
{
TRACE(99, "freeConfiguration()", NULL);
if (config)
{
config -> defaultkeys = listFree(config -> defaultkeys);
config -> defaulttemplates = listFree(config -> defaulttemplates);
config -> defaulttemplatestatus =
listFree(config -> defaulttemplatestatus);
config -> searchdata = listFree(config -> searchdata);
#ifdef TEST_OPTION
memFreeString(__FILE__, __LINE__, config -> testrun);
#endif
if (config -> dbfilerc)
{ memFreeString(__FILE__, __LINE__, config -> dbfilerc); }
if (config -> dbfilecmd)
{ memFreeString(__FILE__, __LINE__, config -> dbfilecmd); }
if (config -> rcfile)
{ memFreeString(__FILE__, __LINE__, config -> rcfile); }
if (config -> encoding)
{ memFreeString(__FILE__, __LINE__, config -> encoding); }
if (config -> passwordalphabet)
{ memFreeString(__FILE__, __LINE__, config -> passwordalphabet); }
memFree(__FILE__, __LINE__, config, sizeof(cpmconfig_t));
config = NULL;
}
if (runtime)
{
runtime -> resultpatterns = listFree(runtime -> resultpatterns);
runtime -> searchpatterns = listFree(runtime -> searchpatterns);
clearPassphrase(1);
memFreeString(__FILE__, __LINE__, runtime -> realm);
memFreeString(__FILE__, __LINE__, runtime -> realmhint);
if (runtime -> dbfile)
{ memFreeString(__FILE__, __LINE__, runtime -> dbfile); }
if (runtime -> lockfile)
{ memFreeString(__FILE__, __LINE__, runtime -> lockfile); }
memFree(__FILE__, __LINE__, runtime, sizeof(cpmruntime_t));
config = NULL;
}
}
/* #############################################################################
*
* Description initialize the global configuration structure
* Author Harry Brueckner
* Date 2005-03-17
* Arguments void
* Return void
*/
void initConfiguration(void)
{
TRACE(99, "initConfiguration()", NULL);
config = memAlloc(__FILE__, __LINE__, sizeof(cpmconfig_t));
runtime = memAlloc(__FILE__, __LINE__, sizeof(cpmruntime_t));
config -> defaultkeys = NULL;
config -> defaulttemplates = NULL;
config -> defaulttemplatestatus = NULL;
config -> searchdata = NULL;
config -> dbfilerc = NULL;
config -> dbfilecmd = NULL;
config -> rcfile = NULL;
config -> encoding = NULL;
config -> passwordalphabet = NULL;
clearPassphrase(1);
#ifdef TEST_OPTION
config -> testrun = NULL;
#endif
config -> hidecharacter = '*';
config -> asktoquit = 0;
config -> casesensitive = 1;
config -> compression = Z_BEST_COMPRESSION;
config -> configtest = 0;
config -> cracklibstatus = CRACKLIB_ON;
config -> createbackup = 1;
config -> debuglevel = 0;
config -> encryptdata = 1;
config -> environtmentlist = 0;
config -> help = 0;
config -> infoheight = 5;
config -> keeppassphrase = 0;
config -> passwordlength = 10;
config -> readonly = 0;
config -> searchtype = SEARCH_REGULAR;
config -> security = 0;
config -> templatelock = 0;
config -> version = 0;
runtime -> memlock_limit = -2;
runtime -> resultpatterns = NULL;
runtime -> searchpatterns = NULL;
runtime -> dbfile = NULL;
runtime -> lockfile = NULL;
runtime -> realm = NULL;
runtime -> realmhint = NULL;
runtime -> casesensitive = -1;
runtime -> commandlinekeys = 0;
runtime -> datachanged = 0;
runtime -> guimode = 0;
runtime -> lockfilecreated = 0;
runtime -> max_mem_lock = 0;
runtime -> memory_safe = 0;
runtime -> ptrace_safe = 0;
runtime -> readonly = 0;
runtime -> searchtype = SEARCH_UNDEF;
runtime -> updatestatus = 0;
}
/* #############################################################################
*/