forked from certnanny/sscep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
236 lines (216 loc) · 4.98 KB
/
init.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* sscep -- Simple SCEP client implementation
* Copyright (c) Jarkko Turkulainen 2003. All rights reserved.
* See the file COPYRIGHT for licensing information.
*/
/* Configuration file initialization */
#include "sscep.h"
#ifdef WIN32
#define strdup(str) _strdup(str)
#endif
void
init_config(FILE *conf) {
char buff[1024];
char *str1, *str2;
int i, lines;
lines = 0;
while (fgets(buff, 1024, conf)) {
lines++;
/* null-terminate: */
buff[strlen(buff)-1] = '\0';
/* skip leading white space: */
for ( i = 0 ; isspace(buff[i]) ; i++)
;
/* empty line? */
if (!strlen(&buff[i]))
continue;
/* comment? */
if (!strncmp("#", &buff[i], 1))
continue;
/* fetch key and value: */
str1 = get_string(&buff[i]);
i += strlen(&buff[i])+1;
for ( ; isspace(buff[i]) ; i++ )
;
str2 = get_string(&buff[i]);
/* if not found... */
if (!strlen(str2) && v_flag) {
fprintf(stderr, "%s: config file parse"
" error, line %d\n", pname, lines);
/* Parse configuration keys */
} else {
if (!strncmp(str1, "CACertFile", 10)) {
if (!c_flag) {
c_flag = 1;
if (!(c_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "CAIdentifier", 12)) {
if (!i_flag) {
i_flag = 1;
if (!(i_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "CertReqFile", 11)) {
if (!r_flag) {
r_flag = 1;
if (!(r_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "Debug", 5)) {
if (!strncmp(str2, "yes", 3) && !d_flag)
d_flag = 1;
} else if (!strncmp(str1, "EncCertFile", 11)) {
if (!e_flag) {
e_flag = 1;
if (!(e_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "EncAlgorithm", 11)) {
if (!E_flag) {
E_flag = 1;
if (!(E_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "FingerPrint", 10)) {
if (!F_flag) {
F_flag = 1;
if (!(F_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "GetCertFile", 11) &&
(operation_flag == SCEP_OPERATION_GETCERT)) {
if (!w_flag) {
w_flag = 1;
if (!(w_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "GetCrlFile", 10) &&
(operation_flag == SCEP_OPERATION_GETCRL)) {
if (!w_flag) {
w_flag = 1;
if (!(w_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "GetCertSerial", 13)) {
if (!s_flag) {
s_flag = 1;
if (!(s_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "LocalCertFile", 13)) {
if (!l_flag) {
l_flag = 1;
if (!(l_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "SignCertFile", 12)) {
if (!O_flag) {
O_flag = 1;
if (!(O_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "MaxPollCount", 12)) {
if (!n_flag) {
n_flag = 1;
n_num = atoi(str2);
}
} else if (!strncmp(str1, "MaxPollTime", 11)) {
if (!T_flag) {
T_flag = 1;
T_num = atoi(str2);
}
} else if (!strncmp(str1, "PrivateKeyFile", 15)) {
if (!k_flag) {
k_flag = 1;
if (!(k_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "SignKeyFile", 11)) {
if (!K_flag) {
K_flag = 1;
if (!(K_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "SelfSignedFile", 15)) {
if (!L_flag) {
L_flag = 1;
if (!(L_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "SigAlgorithm", 11)) {
if (!S_flag) {
S_flag = 1;
if (!(S_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "Proxy", 5)) {
if (!p_flag) {
p_flag = 1;
if (!(p_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "PollInterval", 11)) {
if (!t_flag) {
t_flag = 1;
t_num = atoi(str2);
}
} else if (!strncmp(str1, "URL", 3)) {
if (!u_flag) {
u_flag = 1;
if (!(url_char = strdup(str2)))
error_memory();
}
} else if (!strncmp(str1, "Verbose", 7)) {
if (!strncmp(str2, "yes", 3) && !v_flag)
v_flag = 1;
}
}
}
}
/*
* Find string, strip off '"'s.
*/
char *
get_string(char *str) {
char *tmpstr;
char *retstr;
int c;
/* Malloc space for string: */
if (!(tmpstr = malloc(strlen(str))))
error_memory();
/* check for '"': */
if (*str != '"') c = 0;
else c = 1;
/* not '"': */
if (!c) {
retstr = str;
free(tmpstr);
while (*str++ != '\0') {
if (isspace(*str)) {
break;
}
}
*str = '\0';
/* starts with '"': */
} else {
retstr = tmpstr;
while (*str++ != '\0') {
if (*str == '\\' && *(str+1) && *(str+1) == '"') {
*tmpstr++ = *(str+1);
str++;
} else if (*str == '"')
break;
else
*tmpstr++ = *str;
}
*tmpstr = '\0';
}
return retstr;
}
/*void
error_memory() {
fprintf(stderr, "%s: memory allocation failure, errno: %d\n",
pname, errno);
exit(1);
}*/