1 |
/* wptGPGParser.cpp - GPG config file parser |
/* wptGPGParser.cpp - GPG config file parser |
2 |
* Copyright (C) 2002, 2003, 2004 Timo Schulz |
* Copyright (C) 2002, 2003, 2004, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
23 |
#endif |
#endif |
24 |
|
|
25 |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdio.h> |
|
26 |
#include <string.h> |
#include <string.h> |
27 |
#include <windows.h> |
#include <windows.h> |
28 |
|
|
32 |
#include "wptErrors.h" |
#include "wptErrors.h" |
33 |
|
|
34 |
static void |
static void |
35 |
add_opaque_option (gpg_optfile_t opt, const char * line, int used) |
add_option (gpg_option_t *list, gpg_option_t n) |
36 |
{ |
{ |
37 |
gpg_option_t e, t; |
gpg_option_t t; |
38 |
|
|
39 |
|
if (!*list) |
40 |
|
*list = n; |
41 |
|
else { |
42 |
|
for (t = *list; t->next; t = t->next) |
43 |
|
; |
44 |
|
t->next = n; |
45 |
|
} |
46 |
|
} |
47 |
|
|
48 |
|
static gpg_option_t |
49 |
|
new_option (void) |
50 |
|
{ |
51 |
|
gpg_option_t e; |
52 |
|
|
53 |
e = new gpg_option_s; |
e = new gpg_option_s; |
54 |
if (!e) |
if (!e) |
55 |
BUG (0); |
BUG (0); |
56 |
memset (e, 0, sizeof *e); |
memset (e, 0, sizeof (e)); |
57 |
|
return e; |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
static void |
62 |
|
add_opaque_option (gpg_optfile_t opt, const char *line, int used) |
63 |
|
{ |
64 |
|
gpg_option_t e; |
65 |
|
|
66 |
|
e = new_option (); |
67 |
e->used = used > 0? 1 : 0; |
e->used = used > 0? 1 : 0; |
68 |
e->name = m_strdup (line); |
e->name = m_strdup (line); |
69 |
e->type = ENTRY_OPAQUE; |
e->type = ENTRY_OPAQUE; |
70 |
if (!opt->list) |
add_option (&opt->list, e); |
71 |
opt->list = e; |
} |
|
else { |
|
|
for (t = opt->list; t->next; t = t->next) |
|
|
; |
|
|
t->next = e; |
|
|
} |
|
|
} /* add_opaque_option */ |
|
72 |
|
|
73 |
|
|
74 |
static void |
static void |
75 |
add_single_option (gpg_optfile_t opt, const char * name, int used) |
add_single_option (gpg_optfile_t opt, const char *name, int used) |
76 |
{ |
{ |
77 |
gpg_option_t e, t; |
gpg_option_t e; |
78 |
|
|
79 |
e = new gpg_option_s; |
e = new_option (); |
|
if (!e) |
|
|
BUG (0); |
|
|
memset (e, 0, sizeof *e); |
|
80 |
e->used = used > 0? 1 : 0; |
e->used = used > 0? 1 : 0; |
81 |
e->name = m_strdup (name); |
e->name = m_strdup (name); |
82 |
e->type = ENTRY_SINGLE; |
e->type = ENTRY_SINGLE; |
83 |
if (!opt->list) |
add_option (&opt->list, e); |
84 |
opt->list = e; |
} |
|
else { |
|
|
for (t = opt->list; t->next; t = t->next) |
|
|
; |
|
|
t->next = e; |
|
|
} |
|
|
} /* add_single_option */ |
|
85 |
|
|
86 |
|
|
87 |
static int |
static int |
88 |
add_group_option( gpg_optfile_t opt, const char *name, int used ) |
add_group_option (gpg_optfile_t opt, const char *name, int used) |
89 |
{ |
{ |
90 |
gpg_option_t e, t; |
gpg_option_t e; |
91 |
|
|
92 |
e = new gpg_option_s; |
e = new_option (); |
|
if( !e ) |
|
|
BUG( NULL ); |
|
|
memset( e, 0, sizeof *e ); |
|
93 |
e->used = used > 0? 1 : 0; |
e->used = used > 0? 1 : 0; |
94 |
e->name = m_strdup( name ); |
e->name = m_strdup (name); |
95 |
e->type = ENTRY_GROUP; |
e->type = ENTRY_GROUP; |
96 |
if( !opt->list ) |
add_option (&opt->list, e); |
|
opt->list = e; |
|
|
else { |
|
|
for( t = opt->list; t->next; t = t->next ) |
|
|
; |
|
|
t->next = e; |
|
|
} |
|
97 |
return 0; |
return 0; |
98 |
} /* add_group_option */ |
} |
99 |
|
|
100 |
|
|
101 |
static size_t |
static size_t |
102 |
count_whitespaces( char *line ) |
count_whitespaces (char *line) |
103 |
{ |
{ |
104 |
size_t i = 0, ncount = 0; |
size_t i; |
105 |
|
size_t ncount = 0; |
106 |
|
|
107 |
if( !strchr( line, ' ' ) ) |
if (!strchr (line, ' ')) |
108 |
return 0; |
return 0; |
109 |
for( i = 0; i < strlen( line ); i++ ) { |
for( i = 0; i < strlen (line); i++) { |
110 |
if( line[i] == ' ' ) |
if (line[i] == ' ') |
111 |
ncount++; |
ncount++; |
112 |
} |
} |
|
|
|
113 |
return ncount; |
return ncount; |
114 |
} /* count_whitespaces */ |
} |
115 |
|
|
116 |
|
|
117 |
static int |
static int |
118 |
add_multi_option( gpg_optfile_t opt, char *line, int used ) |
add_multi_option (gpg_optfile_t opt, char *line, int used) |
119 |
{ |
{ |
120 |
gpg_option_t e ,t; |
gpg_option_t e; |
121 |
char *p; |
char *p; |
122 |
int state = 0; |
int state = 0; |
123 |
|
|
124 |
e = new gpg_option_s; |
e = new_option (); |
125 |
if( !e ) |
if (count_whitespaces (line) == 1) { |
126 |
BUG( NULL ); |
while ((p = strsep (&line, " ")) && state != 2) { |
127 |
memset( e, 0, sizeof *e ); |
switch (state) { |
128 |
if( count_whitespaces( line ) == 1 ) { |
case 0: e->name = m_strdup (p); break; |
129 |
while( (p = strsep( &line, " " )) && state != 2 ) { |
case 1: e->val = m_strdup (p); break; |
|
switch( state ) { |
|
|
case 0: e->name = m_strdup( p ); break; |
|
|
case 1: e->val = m_strdup( p ); break; |
|
130 |
} |
} |
131 |
state++; |
state++; |
132 |
} |
} |
133 |
} |
} |
134 |
else { |
else { |
135 |
p = strchr( line, ' ' ); |
p = strchr (line, ' '); |
136 |
|
if (!p) |
137 |
|
return -1; |
138 |
state = p - line; |
state = p - line; |
139 |
e->name = new char[state + 1]; |
e->name = new char[state + 1]; |
140 |
if( !e->name ) |
if (!e->name) |
141 |
BUG( NULL ); |
BUG (NULL); |
142 |
memcpy( e->name, line, state ); |
memcpy (e->name, line, state); |
143 |
e->name[state] = '\0'; |
e->name[state] = '\0'; |
144 |
strncpy( e->name, line, state ); |
strncpy (e->name, line, state); |
145 |
e->val = m_strdup( line + state + 1 ); |
e->val = m_strdup (line + state + 1); |
146 |
} |
} |
147 |
e->used = used; |
e->used = used; |
148 |
e->type = ENTRY_MULTI; |
e->type = ENTRY_MULTI; |
149 |
if( !opt->list ) |
add_option (&opt->list, e); |
150 |
opt->list = e; |
|
|
else { |
|
|
for( t=opt->list; t->next; t = t->next ) |
|
|
; |
|
|
t->next = e; |
|
|
} |
|
151 |
return 0; |
return 0; |
152 |
} /* add_multi_option */ |
} |
153 |
|
|
154 |
|
|
155 |
static gpg_group_t |
static gpg_group_t |
156 |
new_group (gpg_group_t * grp, const char * name) |
new_group (gpg_group_t *grp, const char *name) |
157 |
{ |
{ |
158 |
gpg_group_t g, t; |
gpg_group_t g, t; |
159 |
|
|
160 |
g = new gpg_group_s; |
g = new gpg_group_s; |
161 |
if( !g ) |
if (!g) |
162 |
BUG( NULL ); |
BUG (NULL); |
163 |
memset( g, 0, sizeof *g ); |
memset (g, 0, sizeof *g); |
164 |
g->used = 1; |
g->used = 1; |
165 |
g->name = m_strdup( name ); |
g->name = m_strdup (name); |
166 |
if( !*grp ) |
if (!*grp) |
167 |
*grp = g; |
*grp = g; |
168 |
else { |
else { |
169 |
for( t = *grp; t->next; t = t->next ) |
for (t = *grp; t->next; t = t->next) |
170 |
; |
; |
171 |
t->next = g; |
t->next = g; |
172 |
} |
} |
173 |
return g; |
return g; |
174 |
} /* new_group */ |
} |
175 |
|
|
176 |
|
|
177 |
static const char* |
static const char* |
178 |
_add_group( gpg_optfile_t opt, const char *line ) |
group_from_cfgfile (gpg_optfile_t opt, const char *line) |
179 |
{ |
{ |
180 |
char *p, *buf, *buf2, *name = NULL; |
char *p, *buf, *buf2, *name = NULL; |
181 |
gpg_group_t g; |
gpg_group_t g; |
182 |
gpg_member_t m = NULL, t; |
gpg_member_t m = NULL, t; |
183 |
|
|
184 |
p = strchr( line, '=' ); |
p = strchr (line, '='); |
185 |
if( p == NULL || strncmp( line, "group ", 6 ) ) |
if (!p || strncmp (line, "group ", 6)) |
186 |
return NULL; |
return NULL; |
187 |
buf = m_strdup( line + (p - line + 1) ); |
buf = m_strdup (line + (p - line + 1)); |
|
if( !buf ) |
|
|
BUG( NULL ); |
|
188 |
line += 6; |
line += 6; |
189 |
p = strchr( line, '=' ); |
p = strchr (line, '='); |
190 |
if( p ) { |
if (p) { |
191 |
size_t pos = p - line; |
size_t pos = p - line; |
192 |
name = new char[pos + 1]; |
name = new char[pos + 1]; |
193 |
if( !name ) |
if (!name) |
194 |
BUG( NULL ); |
BUG( NULL ); |
195 |
memset( name, 0, pos+1 ); |
memset (name, 0, pos+1); |
196 |
strncpy( name, line, pos ); |
strncpy (name, line, pos); |
197 |
} |
} |
198 |
g = new_group( &opt->grp, name ); |
g = new_group (&opt->grp, name); |
199 |
buf2 = buf; |
buf2 = buf; |
200 |
while( (p = strsep( &buf2, " " )) && *p ) { |
while ((p = strsep (&buf2, " ")) && *p) { |
201 |
m = new gpg_member_s; |
m = new gpg_member_s; |
202 |
if( !m ) |
if (!m) |
203 |
BUG( NULL ); |
BUG (0); |
204 |
memset( m, 0, sizeof *m ); |
memset (m, 0, sizeof *m); |
205 |
m->used = 1; |
m->used = 1; |
206 |
m->name = m_strdup( p ); |
m->name = m_strdup (p); |
207 |
if( !g->list ) |
if (!g->list) |
208 |
g->list = m; |
g->list = m; |
209 |
else { |
else { |
210 |
for( t=g->list; t->next; t = t->next ) |
for (t=g->list; t->next; t = t->next) |
211 |
; |
; |
212 |
t->next = m; |
t->next = m; |
213 |
} |
} |
214 |
} |
} |
215 |
free_if_alloc( buf ); |
free_if_alloc (buf); |
216 |
if( !m ) |
if (!m) |
217 |
return NULL; |
return NULL; |
218 |
return g->name; |
return g->name; |
219 |
} /* _add_group */ |
} |
220 |
|
|
221 |
|
|
222 |
void |
void |
223 |
release_group( gpg_group_t grp ) |
release_group (gpg_group_t grp) |
224 |
{ |
{ |
225 |
gpg_member_t m, m2; |
gpg_member_t m, m2; |
226 |
|
|
227 |
m = grp->list; |
m = grp->list; |
228 |
while( m ) { |
while (m) { |
229 |
m2 = m->next; |
m2 = m->next; |
230 |
free_if_alloc( m->name ); |
free_if_alloc (m->name); |
231 |
free_if_alloc( m ); |
free_if_alloc (m); |
232 |
m = m2; |
m = m2; |
233 |
} |
} |
234 |
} /* release_group */ |
} |
235 |
|
|
236 |
|
|
237 |
void |
void |
239 |
{ |
{ |
240 |
if (!opt) |
if (!opt) |
241 |
return; |
return; |
242 |
free_if_alloc( opt->name ); |
free_if_alloc (opt->name); |
243 |
free_if_alloc( opt->val ); |
free_if_alloc (opt->val); |
244 |
free_if_alloc( opt ); |
free_if_alloc (opt ); |
245 |
} |
} |
246 |
|
|
247 |
|
|
248 |
void |
void |
249 |
release_gpg_options( gpg_optfile_t opt ) |
release_gpg_options (gpg_optfile_t opt) |
250 |
{ |
{ |
251 |
gpg_option_t e, e2; |
gpg_option_t e, e2; |
252 |
gpg_group_t g, g2; |
gpg_group_t g, g2; |
253 |
|
|
254 |
e = opt->list; |
e = opt->list; |
255 |
while( e ) { |
while (e) { |
256 |
e2 = e->next; |
e2 = e->next; |
257 |
release_option (e); |
release_option (e); |
258 |
e = e2; |
e = e2; |
259 |
} |
} |
260 |
g = opt->grp; |
g = opt->grp; |
261 |
while( g ) { |
while (g) { |
262 |
g2 = g->next; |
g2 = g->next; |
263 |
release_group( g ); |
release_group (g); |
264 |
g = g2; |
g = g2; |
265 |
} |
} |
266 |
free_if_alloc( opt ); |
free_if_alloc (opt); |
267 |
} /* release_gpg_options */ |
} |
268 |
|
|
269 |
|
|
270 |
int |
int |
271 |
commit_gpg_options (const char * file, gpg_optfile_t opt) |
commit_gpg_options (const char *file, gpg_optfile_t opt) |
272 |
{ |
{ |
273 |
FILE *inp; |
FILE *inp; |
274 |
gpg_option_t e; |
gpg_option_t e; |
276 |
gpg_member_t m; |
gpg_member_t m; |
277 |
|
|
278 |
inp = fopen (file, "w+b"); |
inp = fopen (file, "w+b"); |
279 |
if( !inp ) |
if (!inp) |
280 |
return -1; |
return WPTERR_FILE_OPEN; |
281 |
for( e = opt->list; e; e = e->next ) { |
for (e = opt->list; e; e = e->next) { |
282 |
if( !e->used ) |
if (!e->used) |
283 |
continue; |
continue; |
284 |
switch( e->type ) { |
switch (e->type) { |
285 |
case ENTRY_OPAQUE: |
case ENTRY_OPAQUE: |
286 |
fprintf( inp, "%s", e->name ); |
fprintf (inp, "%s", e->name); |
287 |
break; |
break; |
288 |
|
|
289 |
case ENTRY_MULTI: |
case ENTRY_MULTI: |
290 |
fprintf( inp, "%s %s\r\n", e->name, e->val ); |
fprintf (inp, "%s %s\r\n", e->name, e->val); |
291 |
break; |
break; |
292 |
|
|
293 |
case ENTRY_SINGLE: |
case ENTRY_SINGLE: |
294 |
fprintf( inp, "%s\r\n", e->name ); |
fprintf (inp, "%s\r\n", e->name); |
295 |
break; |
break; |
296 |
|
|
297 |
case ENTRY_GROUP: |
case ENTRY_GROUP: |
298 |
g = find_group( opt, e->name ); |
g = find_group (opt, e->name); |
299 |
if( g && g->used ) { |
if (g && g->used) { |
300 |
fprintf( inp, "group %s=", g->name ); |
fprintf (inp, "group %s=", g->name); |
301 |
for( m = g->list; m; m = m->next ) { |
for (m = g->list; m; m = m->next) { |
302 |
if( m->used ) |
if (m->used) |
303 |
fprintf( inp, "%s ", m->name ); |
fprintf (inp, "%s ", m->name); |
304 |
} |
} |
305 |
fprintf( inp, "\r\n" ); |
fprintf (inp, "\r\n"); |
306 |
} |
} |
307 |
break; |
break; |
308 |
} |
} |
309 |
} |
} |
310 |
fclose (inp); |
fclose (inp); |
311 |
return 0; |
return 0; |
312 |
} /* commit_gpg_options */ |
} |
313 |
|
|
314 |
|
|
315 |
int |
int |
316 |
parse_gpg_options( const char *file, gpg_optfile_t *r_opt ) |
parse_gpg_options (const char *file, gpg_optfile_t *r_opt ) |
317 |
{ |
{ |
318 |
FILE *inp; |
FILE *inp; |
319 |
char buf[1024], *p; |
char buf[1024], *p; |
320 |
gpg_optfile_t opt = NULL; |
gpg_optfile_t opt = NULL; |
321 |
|
|
322 |
inp = fopen( file, "rb" ); |
inp = fopen( file, "rb"); |
323 |
if( inp == NULL ) { |
if( inp == NULL ) { |
324 |
inp = fopen( file, "wb" ); |
inp = fopen( file, "wb" ); |
325 |
if( inp == NULL ) |
if( inp == NULL ) |
344 |
if( !strchr( p, ' ' ) ) |
if( !strchr( p, ' ' ) ) |
345 |
add_single_option( opt, p, 1 ); |
add_single_option( opt, p, 1 ); |
346 |
else if( !strncmp( p, "group", 5 ) ) { |
else if( !strncmp( p, "group", 5 ) ) { |
347 |
const char *s = _add_group( opt, p ); |
const char *s = group_from_cfgfile (opt, p); |
348 |
if( s ) |
if (s) |
349 |
add_group_option( opt, s, 1 ); |
add_group_option (opt, s, 1); |
350 |
} |
} |
351 |
else |
else |
352 |
add_multi_option( opt, p, 1 ); |
add_multi_option (opt, p, 1); |
353 |
} |
} |
354 |
fclose( inp ); |
fclose (inp); |
355 |
if( r_opt ) |
if (r_opt) |
356 |
*r_opt = opt; |
*r_opt = opt; |
357 |
return 0; |
return 0; |
358 |
} /* parse_gpg_options */ |
} |
359 |
|
|
360 |
|
|
361 |
gpg_option_t |
gpg_option_t |
362 |
find_option (gpg_optfile_t opt, const char * str) |
find_option (gpg_optfile_t opt, const char *str) |
363 |
{ |
{ |
364 |
gpg_option_t e; |
gpg_option_t e; |
365 |
|
|
371 |
} |
} |
372 |
|
|
373 |
return e; |
return e; |
374 |
} /* find_option */ |
} |
375 |
|
|
376 |
|
|
377 |
gpg_group_t |
gpg_group_t |
378 |
find_group( gpg_optfile_t opt, const char *str ) |
find_group (gpg_optfile_t opt, const char *str) |
379 |
{ |
{ |
380 |
gpg_group_t g; |
gpg_group_t g; |
381 |
|
|
382 |
for( g = opt->grp; g; g = g->next ) { |
for (g = opt->grp; g; g = g->next) { |
383 |
if( !stricmp( g->name, str ) ) |
if (!stricmp( g->name, str)) |
384 |
break; |
break; |
385 |
} |
} |
386 |
|
|
387 |
return g; |
return g; |
388 |
} /* find_group */ |
} |
389 |
|
|
390 |
|
|
391 |
gpg_member_t |
gpg_member_t |
392 |
find_member( gpg_optfile_t opt, const char *grp, const char *str ) |
find_member (gpg_optfile_t opt, const char *grp, const char *str) |
393 |
{ |
{ |
394 |
gpg_group_t g = find_group( opt, grp ); |
gpg_group_t g = find_group (opt, grp); |
395 |
gpg_member_t m = NULL; |
gpg_member_t m; |
|
if( g ) { |
|
|
for( m = g->list; m; m = m->next ) { |
|
|
if( !stricmp( m->name, str ) ) |
|
|
break; |
|
|
} |
|
|
} |
|
396 |
|
|
397 |
return m; |
if (!g) |
398 |
} /* find_member */ |
return NULL; |
399 |
|
|
400 |
|
for (m = g->list; m; m = m->next) { |
401 |
|
if (!stricmp (m->name, str)) |
402 |
|
return m; |
403 |
|
} |
404 |
|
return NULL; |
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
int |
int |
409 |
delete_group( gpg_optfile_t opt, const char *str ) |
delete_group (gpg_optfile_t opt, const char *str) |
410 |
{ |
{ |
411 |
gpg_group_t g = find_group( opt, str ); |
gpg_group_t g = find_group (opt, str); |
|
if( g ) { |
|
|
g->used = 0; |
|
|
return 0; |
|
|
} |
|
412 |
|
|
413 |
return -1; |
if (g) |
414 |
} /* delete_group */ |
g->used = 0; |
415 |
|
return g? 0 : -1; |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
int |
int |
420 |
delete_member( gpg_optfile_t opt, const char *grp, const char *str ) |
delete_member (gpg_optfile_t opt, const char *grp, const char *str) |
421 |
{ |
{ |
422 |
gpg_member_t m = find_member( opt, grp, str ); |
gpg_member_t m = find_member (opt, grp, str); |
|
if( m ) { |
|
|
m->used = 0; |
|
|
return 0; |
|
|
} |
|
423 |
|
|
424 |
return -1; |
if (m) |
425 |
} /* delete_member */ |
m->used = 0; |
426 |
|
return m? 0 : -1; |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
int |
int |
431 |
delete_option (gpg_optfile_t opt, const char * str) |
delete_option (gpg_optfile_t opt, const char * str) |
432 |
{ |
{ |
433 |
gpg_option_t e = find_option (opt, str); |
gpg_option_t e = find_option (opt, str); |
|
if (e) { |
|
|
e->used = 0; |
|
|
return 0; |
|
|
} |
|
434 |
|
|
435 |
return -1; |
if (e) |
436 |
} /* delete_option */ |
e->used = 0; |
437 |
|
return e? 0 : -1; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
int |
int |
442 |
add_entry( gpg_optfile_t opt, int type, const char *name, const char *val ) |
add_entry (gpg_optfile_t opt, int type, const char *name, const char *val) |
443 |
{ |
{ |
444 |
gpg_option_t e, t; |
gpg_option_t e; |
445 |
|
|
446 |
e = new gpg_option_s; |
e = new_option (); |
|
if( !e ) |
|
|
BUG( NULL ); |
|
|
memset( e, 0, sizeof *e ); |
|
447 |
e->used = 1; |
e->used = 1; |
448 |
e->type = type; |
e->type = type; |
449 |
e->name = m_strdup( name ); |
e->name = m_strdup (name); |
450 |
e->val = val? m_strdup( val ) : NULL; |
e->val = val? m_strdup (val) : NULL; |
451 |
if( !opt->list ) |
add_option (&opt->list, e); |
|
opt->list = e; |
|
|
else { |
|
|
for( t = opt->list; t->next; t = t->next ) |
|
|
; |
|
|
t->next = e; |
|
|
} |
|
452 |
return 0; |
return 0; |
453 |
} /* add_entry */ |
} |
454 |
|
|
455 |
|
|
456 |
int |
int |
457 |
modify_entry( gpg_optfile_t opt, int type, const char *name, const char *val ) |
modify_entry (gpg_optfile_t opt, int type, const char *name, const char *val) |
458 |
{ |
{ |
459 |
gpg_option_t e; |
gpg_option_t e; |
460 |
int rc = 0; |
int rc = 0; |
461 |
|
|
462 |
e = find_option( opt, name ); |
e = find_option (opt, name); |
463 |
if( !e ) |
if (!e) |
464 |
rc = add_entry( opt, type, name, val ); |
rc = add_entry (opt, type, name, val); |
465 |
else if( type != ENTRY_SINGLE ) { |
else if (type != ENTRY_SINGLE) { |
466 |
free_if_alloc( e->val ); |
free_if_alloc (e->val); |
467 |
e->val = m_strdup( val ); |
e->val = m_strdup (val); |
468 |
} |
} |
469 |
|
|
470 |
return rc; |
return rc; |
471 |
} /* modify_entry */ |
} |
472 |
|
|
473 |
|
|
474 |
int |
int |
475 |
add_member( gpg_optfile_t opt, const char *grp, const char *str ) |
add_member (gpg_optfile_t opt, const char *grp, const char *str) |
476 |
{ |
{ |
477 |
gpg_group_t g = find_group( opt, grp ); |
gpg_group_t g = find_group (opt, grp); |
478 |
gpg_member_t m, t; |
gpg_member_t m, t; |
479 |
if( g ) { |
|
480 |
m = new gpg_member_s; |
if (!g) |
481 |
if( !m ) |
return -1; |
482 |
BUG( NULL ); |
|
483 |
memset( m, 0, sizeof *m ); |
m = new gpg_member_s; |
484 |
m->used = 1; |
if (!m) |
485 |
m->name = m_strdup( str ); |
BUG (NULL); |
486 |
if( !m->name ) |
memset (m, 0, sizeof *m); |
487 |
BUG( NULL ); |
m->used = 1; |
488 |
if( !g->list ) |
m->name = m_strdup (str); |
489 |
g->list = m; |
if( !g->list ) |
490 |
else { |
g->list = m; |
491 |
for( t = g->list; t->next; t = t->next ) |
else { |
492 |
; |
for( t = g->list; t->next; t = t->next ) |
493 |
t->next = m; |
; |
494 |
} |
t->next = m; |
495 |
return 0; |
} |
496 |
} |
return 0; |
497 |
return -1; |
} |
|
} /* add_member */ |
|
498 |
|
|
499 |
|
|
500 |
int |
int |
501 |
add_group( gpg_optfile_t opt, const char *str ) |
add_group (gpg_optfile_t opt, const char *str) |
502 |
{ |
{ |
503 |
gpg_group_t g, t; |
gpg_group_t g, t; |
504 |
|
|
505 |
g = new gpg_group_s; |
g = new gpg_group_s; |
506 |
if( !g ) |
if (!g) |
507 |
BUG( NULL ); |
BUG (NULL); |
508 |
memset( g, 0, sizeof *g ); |
memset (g, 0, sizeof *g); |
509 |
g->used = 1; |
g->used = 1; |
510 |
g->name = m_strdup( str ); |
g->name = m_strdup (str); |
511 |
|
|
512 |
if( !opt->grp ) |
if (!opt->grp) |
513 |
opt->grp = g; |
opt->grp = g; |
514 |
else { |
else { |
515 |
for( t = opt->grp; t->next; t = t->next ) |
for (t = opt->grp; t->next; t = t->next) |
516 |
; |
; |
517 |
t->next = g; |
t->next = g; |
518 |
} |
} |
519 |
add_entry( opt, ENTRY_GROUP, str, NULL ); |
add_entry (opt, ENTRY_GROUP, str, NULL); |
|
|
|
520 |
return 0; |
return 0; |
521 |
} /* add_group */ |
} |
522 |
|
|
523 |
|
|
524 |
#if 0 |
#if 0 |