]>
Commit | Line | Data |
---|---|---|
2f552719 | 1 | /* |
2ad0cdc8 | 2 | * Copyright (c) 2006-2012 Red Hat, Inc. |
2f552719 SD |
3 | * |
4 | * All rights reserved. | |
5 | * | |
6 | * Author: Patrick Caulfield (pcaulfie@redhat.com) | |
8a45e2b1 | 7 | * Jan Friesse (jfriesse@redhat.com) |
2f552719 SD |
8 | * |
9 | * This software licensed under BSD license, the text of which follows: | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above copyright notice, | |
15 | * this list of conditions and the following disclaimer. | |
16 | * - Redistributions in binary form must reproduce the above copyright notice, | |
17 | * this list of conditions and the following disclaimer in the documentation | |
18 | * and/or other materials provided with the distribution. | |
19 | * - Neither the name of the MontaVista Software, Inc. nor the names of its | |
20 | * contributors may be used to endorse or promote products derived from this | |
21 | * software without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
33 | * THE POSSIBILITY OF SUCH DAMAGE. | |
34 | */ | |
031c02f5 FDN |
35 | |
36 | #include <config.h> | |
37 | ||
2f552719 SD |
38 | #include <sys/types.h> |
39 | #include <sys/uio.h> | |
40 | #include <sys/socket.h> | |
1e0d40cd | 41 | #include <sys/stat.h> |
2f552719 SD |
42 | #include <sys/un.h> |
43 | #include <netinet/in.h> | |
44 | #include <arpa/inet.h> | |
45 | #include <unistd.h> | |
46 | #include <fcntl.h> | |
47 | #include <stdlib.h> | |
48 | #include <stdio.h> | |
49 | #include <errno.h> | |
2f552719 | 50 | #include <string.h> |
ae229831 | 51 | #include <dirent.h> |
6fd822c4 | 52 | #include <limits.h> |
2290913d | 53 | #include <stddef.h> |
8a45e2b1 JF |
54 | #include <grp.h> |
55 | #include <pwd.h> | |
2f552719 | 56 | |
8a45e2b1 | 57 | #include <corosync/list.h> |
37e17e7a | 58 | #include <qb/qbutil.h> |
00434a4f | 59 | #define LOGSYS_UTILS_ONLY 1 |
8ad583a5 | 60 | #include <corosync/logsys.h> |
6f5e3293 | 61 | #include <corosync/icmap.h> |
e1f53138 | 62 | |
f763d3ba | 63 | #include "main.h" |
2f552719 SD |
64 | #include "util.h" |
65 | ||
8a45e2b1 JF |
66 | enum parser_cb_type { |
67 | PARSER_CB_START, | |
68 | PARSER_CB_END, | |
69 | PARSER_CB_SECTION_START, | |
70 | PARSER_CB_SECTION_END, | |
71 | PARSER_CB_ITEM, | |
72 | }; | |
73 | ||
74 | typedef int (*parser_cb_f)(const char *path, | |
75 | char *key, | |
76 | char *value, | |
77 | enum parser_cb_type type, | |
78 | const char **error_string, | |
79 | void *user_data); | |
80 | ||
81 | enum main_cp_cb_data_state { | |
82 | MAIN_CP_CB_DATA_STATE_NORMAL, | |
83 | MAIN_CP_CB_DATA_STATE_TOTEM, | |
84 | MAIN_CP_CB_DATA_STATE_INTERFACE, | |
85 | MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS, | |
86 | MAIN_CP_CB_DATA_STATE_UIDGID, | |
87 | MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON, | |
88 | MAIN_CP_CB_DATA_STATE_MEMBER, | |
89 | MAIN_CP_CB_DATA_STATE_QUORUM, | |
cb5fd775 | 90 | MAIN_CP_CB_DATA_STATE_QDEVICE, |
6d0b0b14 JF |
91 | MAIN_CP_CB_DATA_STATE_NODELIST, |
92 | MAIN_CP_CB_DATA_STATE_NODELIST_NODE, | |
3cd4f9a1 JF |
93 | MAIN_CP_CB_DATA_STATE_PLOAD, |
94 | MAIN_CP_CB_DATA_STATE_QB | |
8a45e2b1 JF |
95 | }; |
96 | ||
97 | struct key_value_list_item { | |
98 | char *key; | |
99 | char *value; | |
100 | struct list_head list; | |
101 | }; | |
102 | ||
103 | struct main_cp_cb_data { | |
104 | enum main_cp_cb_data_state state; | |
105 | ||
106 | int ringnumber; | |
107 | char *bindnetaddr; | |
108 | char *mcastaddr; | |
109 | char *broadcast; | |
110 | int mcastport; | |
111 | int ttl; | |
112 | ||
113 | struct list_head logger_subsys_items_head; | |
114 | char *subsys; | |
115 | char *logging_daemon_name; | |
116 | struct list_head member_items_head; | |
6d0b0b14 JF |
117 | |
118 | int node_number; | |
119 | int ring0_addr_added; | |
8a45e2b1 JF |
120 | }; |
121 | ||
122 | static int read_config_file_into_icmap( | |
23c64c64 | 123 | const char **error_string); |
2f552719 SD |
124 | static char error_string_response[512]; |
125 | ||
8a45e2b1 JF |
126 | static int uid_determine (const char *req_user) |
127 | { | |
128 | int pw_uid = 0; | |
129 | struct passwd passwd; | |
130 | struct passwd* pwdptr = &passwd; | |
131 | struct passwd* temp_pwd_pt; | |
132 | char *pwdbuffer; | |
005e7fd3 | 133 | int pwdlinelen, rc; |
8a45e2b1 JF |
134 | |
135 | pwdlinelen = sysconf (_SC_GETPW_R_SIZE_MAX); | |
136 | ||
137 | if (pwdlinelen == -1) { | |
138 | pwdlinelen = 256; | |
139 | } | |
140 | ||
141 | pwdbuffer = malloc (pwdlinelen); | |
142 | ||
005e7fd3 AB |
143 | while ((rc = getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) == ERANGE) { |
144 | char *n; | |
145 | ||
146 | pwdlinelen *= 2; | |
147 | if (pwdlinelen <= 32678) { | |
148 | n = realloc (pwdbuffer, pwdlinelen); | |
149 | if (n != NULL) { | |
150 | pwdbuffer = n; | |
151 | continue; | |
52f88d04 JF |
152 | } |
153 | } | |
005e7fd3 AB |
154 | } |
155 | if (rc != 0) { | |
156 | free (pwdbuffer); | |
157 | sprintf (error_string_response, "getpwnam_r(): %s", strerror(rc)); | |
158 | return (-1); | |
159 | } | |
160 | if (temp_pwd_pt == NULL) { | |
52f88d04 | 161 | free (pwdbuffer); |
8a45e2b1 JF |
162 | sprintf (error_string_response, |
163 | "The '%s' user is not found in /etc/passwd, please read the documentation.", | |
164 | req_user); | |
165 | return (-1); | |
166 | } | |
167 | pw_uid = passwd.pw_uid; | |
168 | free (pwdbuffer); | |
169 | ||
170 | return pw_uid; | |
171 | } | |
172 | ||
173 | static int gid_determine (const char *req_group) | |
174 | { | |
7c8e83ac | 175 | int corosync_gid = 0; |
8a45e2b1 JF |
176 | struct group group; |
177 | struct group * grpptr = &group; | |
178 | struct group * temp_grp_pt; | |
179 | char *grpbuffer; | |
005e7fd3 | 180 | int grplinelen, rc; |
8a45e2b1 JF |
181 | |
182 | grplinelen = sysconf (_SC_GETGR_R_SIZE_MAX); | |
183 | ||
184 | if (grplinelen == -1) { | |
185 | grplinelen = 256; | |
186 | } | |
187 | ||
188 | grpbuffer = malloc (grplinelen); | |
189 | ||
005e7fd3 AB |
190 | while ((rc = getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) == ERANGE) { |
191 | char *n; | |
192 | ||
193 | grplinelen *= 2; | |
194 | if (grplinelen <= 32678) { | |
195 | n = realloc (grpbuffer, grplinelen); | |
196 | if (n != NULL) { | |
197 | grpbuffer = n; | |
198 | continue; | |
52f88d04 JF |
199 | } |
200 | } | |
005e7fd3 AB |
201 | } |
202 | if (rc != 0) { | |
203 | free (grpbuffer); | |
204 | sprintf (error_string_response, "getgrnam_r(): %s", strerror(rc)); | |
205 | return (-1); | |
206 | } | |
207 | if (temp_grp_pt == NULL) { | |
52f88d04 | 208 | free (grpbuffer); |
8a45e2b1 JF |
209 | sprintf (error_string_response, |
210 | "The '%s' group is not found in /etc/group, please read the documentation.", | |
211 | req_group); | |
212 | return (-1); | |
213 | } | |
7c8e83ac | 214 | corosync_gid = group.gr_gid; |
8a45e2b1 | 215 | free (grpbuffer); |
2f552719 | 216 | |
7c8e83ac | 217 | return corosync_gid; |
8a45e2b1 | 218 | } |
3ffb151a FDN |
219 | static char *strchr_rs (const char *haystack, int byte) |
220 | { | |
221 | const char *end_address = strchr (haystack, byte); | |
222 | if (end_address) { | |
223 | end_address += 1; /* skip past { or = */ | |
8a45e2b1 JF |
224 | |
225 | while (*end_address == ' ' || *end_address == '\t') | |
226 | end_address++; | |
3ffb151a FDN |
227 | } |
228 | ||
229 | return ((char *) end_address); | |
230 | } | |
231 | ||
f763d3ba | 232 | int coroparse_configparse (const char **error_string) |
2f552719 | 233 | { |
8a45e2b1 | 234 | if (read_config_file_into_icmap(error_string)) { |
2f552719 SD |
235 | return -1; |
236 | } | |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
663489d2 | 241 | static char *remove_whitespace(char *string, int remove_colon_and_brace) |
2f552719 | 242 | { |
8a45e2b1 JF |
243 | char *start; |
244 | char *end; | |
2f552719 | 245 | |
8a45e2b1 JF |
246 | start = string; |
247 | while (*start == ' ' || *start == '\t') | |
248 | start++; | |
249 | ||
250 | end = start+(strlen(start))-1; | |
663489d2 | 251 | while ((*end == ' ' || *end == '\t' || (remove_colon_and_brace && (*end == ':' || *end == '{'))) && end > start) |
2f552719 SD |
252 | end--; |
253 | if (end != start) | |
254 | *(end+1) = '\0'; | |
255 | ||
256 | return start; | |
257 | } | |
258 | ||
ae229831 | 259 | |
ae229831 | 260 | |
2f552719 | 261 | static int parse_section(FILE *fp, |
8a45e2b1 | 262 | char *path, |
ae229831 | 263 | const char **error_string, |
66172a50 | 264 | int depth, |
8a45e2b1 JF |
265 | parser_cb_f parser_cb, |
266 | void *user_data) | |
2f552719 SD |
267 | { |
268 | char line[512]; | |
269 | int i; | |
270 | char *loc; | |
99db3567 | 271 | int ignore_line; |
8a45e2b1 JF |
272 | char new_keyname[ICMAP_KEYNAME_MAXLEN]; |
273 | ||
274 | if (strcmp(path, "") == 0) { | |
275 | parser_cb("", NULL, NULL, PARSER_CB_START, error_string, user_data); | |
276 | } | |
2f552719 | 277 | |
94b64352 JF |
278 | while (fgets (line, sizeof (line), fp)) { |
279 | if (strlen(line) > 0) { | |
280 | if (line[strlen(line) - 1] == '\n') | |
281 | line[strlen(line) - 1] = '\0'; | |
282 | if (strlen (line) > 0 && line[strlen(line) - 1] == '\r') | |
283 | line[strlen(line) - 1] = '\0'; | |
284 | } | |
2f552719 SD |
285 | /* |
286 | * Clear out white space and tabs | |
287 | */ | |
288 | for (i = strlen (line) - 1; i > -1; i--) { | |
289 | if (line[i] == '\t' || line[i] == ' ') { | |
290 | line[i] = '\0'; | |
291 | } else { | |
292 | break; | |
293 | } | |
294 | } | |
99db3567 JF |
295 | |
296 | ignore_line = 1; | |
297 | for (i = 0; i < strlen (line); i++) { | |
298 | if (line[i] != '\t' && line[i] != ' ') { | |
299 | if (line[i] != '#') | |
300 | ignore_line = 0; | |
301 | ||
302 | break; | |
303 | } | |
304 | } | |
2f552719 SD |
305 | /* |
306 | * Clear out comments and empty lines | |
307 | */ | |
99db3567 | 308 | if (ignore_line) { |
2f552719 SD |
309 | continue; |
310 | } | |
311 | ||
312 | /* New section ? */ | |
283011c6 | 313 | if ((loc = strchr_rs (line, '{'))) { |
663489d2 | 314 | char *section = remove_whitespace(line, 1); |
2f552719 SD |
315 | |
316 | loc--; | |
317 | *loc = '\0'; | |
8a45e2b1 JF |
318 | |
319 | strcpy(new_keyname, path); | |
320 | if (strcmp(path, "") != 0) { | |
321 | strcat(new_keyname, "."); | |
ae229831 | 322 | } |
8a45e2b1 | 323 | strcat(new_keyname, section); |
ae229831 | 324 | |
8a45e2b1 JF |
325 | if (!parser_cb(new_keyname, NULL, NULL, PARSER_CB_SECTION_START, error_string, user_data)) { |
326 | return -1; | |
327 | } | |
328 | ||
66172a50 | 329 | if (parse_section(fp, new_keyname, error_string, depth + 1, parser_cb, user_data)) |
2f552719 | 330 | return -1; |
663489d2 JF |
331 | |
332 | continue ; | |
2f552719 SD |
333 | } |
334 | ||
335 | /* New key/value */ | |
283011c6 | 336 | if ((loc = strchr_rs (line, ':'))) { |
2f552719 SD |
337 | char *key; |
338 | char *value; | |
339 | ||
340 | *(loc-1) = '\0'; | |
663489d2 JF |
341 | key = remove_whitespace(line, 1); |
342 | value = remove_whitespace(loc, 0); | |
8a45e2b1 JF |
343 | |
344 | strcpy(new_keyname, path); | |
345 | if (strcmp(path, "") != 0) { | |
346 | strcat(new_keyname, "."); | |
347 | } | |
348 | strcat(new_keyname, key); | |
349 | ||
350 | if (!parser_cb(new_keyname, key, value, PARSER_CB_ITEM, error_string, user_data)) { | |
351 | return -1; | |
ae229831 | 352 | } |
663489d2 JF |
353 | |
354 | continue ; | |
2f552719 SD |
355 | } |
356 | ||
8236a087 | 357 | if (strchr_rs (line, '}')) { |
66172a50 JF |
358 | if (depth == 0) { |
359 | *error_string = "parser error: Unexpected closing brace"; | |
360 | ||
361 | return -1; | |
362 | } | |
363 | ||
8a45e2b1 JF |
364 | if (!parser_cb(path, NULL, NULL, PARSER_CB_SECTION_END, error_string, user_data)) { |
365 | return -1; | |
366 | } | |
367 | ||
2f552719 SD |
368 | return 0; |
369 | } | |
370 | } | |
371 | ||
8a45e2b1 | 372 | if (strcmp(path, "") != 0) { |
66172a50 | 373 | *error_string = "parser error: Missing closing brace"; |
2f552719 SD |
374 | return -1; |
375 | } | |
376 | ||
8a45e2b1 JF |
377 | if (strcmp(path, "") == 0) { |
378 | parser_cb("", NULL, NULL, PARSER_CB_END, error_string, user_data); | |
379 | } | |
380 | ||
2f552719 SD |
381 | return 0; |
382 | } | |
383 | ||
0929dcb6 JF |
384 | static int safe_atoi(const char *str, int *res) |
385 | { | |
386 | int val; | |
387 | char *endptr; | |
388 | ||
389 | errno = 0; | |
390 | ||
391 | val = strtol(str, &endptr, 10); | |
392 | if (errno == ERANGE) { | |
393 | return (-1); | |
394 | } | |
395 | ||
396 | if (endptr == str) { | |
397 | return (-1); | |
398 | } | |
399 | ||
400 | if (*endptr != '\0') { | |
401 | return (-1); | |
402 | } | |
403 | ||
404 | *res = val; | |
405 | return (0); | |
406 | } | |
407 | ||
6825c1d3 JF |
408 | static int str_to_ull(const char *str, unsigned long long int *res) |
409 | { | |
410 | unsigned long long int val; | |
411 | char *endptr; | |
412 | ||
413 | errno = 0; | |
414 | ||
415 | val = strtoull(str, &endptr, 10); | |
416 | if (errno == ERANGE) { | |
417 | return (-1); | |
418 | } | |
419 | ||
420 | if (endptr == str) { | |
421 | return (-1); | |
422 | } | |
423 | ||
424 | if (*endptr != '\0') { | |
425 | return (-1); | |
426 | } | |
427 | ||
428 | *res = val; | |
429 | return (0); | |
430 | } | |
0929dcb6 | 431 | |
8a45e2b1 JF |
432 | static int main_config_parser_cb(const char *path, |
433 | char *key, | |
434 | char *value, | |
435 | enum parser_cb_type type, | |
436 | const char **error_string, | |
437 | void *user_data) | |
ae229831 | 438 | { |
8a45e2b1 | 439 | int i; |
6825c1d3 | 440 | unsigned long long int ull; |
8a45e2b1 JF |
441 | int add_as_string; |
442 | char key_name[ICMAP_KEYNAME_MAXLEN]; | |
0929dcb6 | 443 | static char formated_err[256]; |
8a45e2b1 JF |
444 | struct main_cp_cb_data *data = (struct main_cp_cb_data *)user_data; |
445 | struct key_value_list_item *kv_item; | |
446 | struct list_head *iter, *iter_next; | |
447 | int uid, gid; | |
448 | ||
449 | switch (type) { | |
450 | case PARSER_CB_START: | |
451 | memset(data, 0, sizeof(struct main_cp_cb_data)); | |
452 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
453 | break; | |
454 | case PARSER_CB_END: | |
455 | break; | |
456 | case PARSER_CB_ITEM: | |
457 | add_as_string = 1; | |
458 | ||
459 | switch (data->state) { | |
460 | case MAIN_CP_CB_DATA_STATE_NORMAL: | |
461 | break; | |
eb3d49ef FDN |
462 | case MAIN_CP_CB_DATA_STATE_PLOAD: |
463 | if ((strcmp(path, "pload.count") == 0) || | |
464 | (strcmp(path, "pload.size") == 0)) { | |
465 | if (safe_atoi(value, &i) != 0) { | |
466 | goto atoi_error; | |
467 | } | |
468 | icmap_set_uint32(path, i); | |
469 | add_as_string = 0; | |
470 | } | |
471 | break; | |
8a45e2b1 JF |
472 | case MAIN_CP_CB_DATA_STATE_QUORUM: |
473 | if ((strcmp(path, "quorum.expected_votes") == 0) || | |
474 | (strcmp(path, "quorum.votes") == 0) || | |
10098dba | 475 | (strcmp(path, "quorum.last_man_standing_window") == 0) || |
8a45e2b1 | 476 | (strcmp(path, "quorum.leaving_timeout") == 0)) { |
0929dcb6 JF |
477 | if (safe_atoi(value, &i) != 0) { |
478 | goto atoi_error; | |
479 | } | |
8a45e2b1 JF |
480 | icmap_set_uint32(path, i); |
481 | add_as_string = 0; | |
482 | } | |
483 | ||
9589611d | 484 | if ((strcmp(path, "quorum.two_node") == 0) || |
2d7a8ab2 | 485 | (strcmp(path, "quorum.allow_downscale") == 0) || |
e8d0af0b | 486 | (strcmp(path, "quorum.wait_for_all") == 0) || |
b41372c6 | 487 | (strcmp(path, "quorum.auto_tie_breaker") == 0) || |
769fc913 | 488 | (strcmp(path, "quorum.last_man_standing") == 0)) { |
0929dcb6 JF |
489 | if (safe_atoi(value, &i) != 0) { |
490 | goto atoi_error; | |
491 | } | |
8a45e2b1 JF |
492 | icmap_set_uint8(path, i); |
493 | add_as_string = 0; | |
494 | } | |
495 | break; | |
cb5fd775 FDN |
496 | case MAIN_CP_CB_DATA_STATE_QDEVICE: |
497 | if ((strcmp(path, "quorum.device.timeout") == 0) || | |
498 | (strcmp(path, "quorum.device.votes") == 0)) { | |
499 | if (safe_atoi(value, &i) != 0) { | |
500 | goto atoi_error; | |
501 | } | |
502 | icmap_set_uint32(path, i); | |
503 | add_as_string = 0; | |
504 | } | |
86dd11b2 FDN |
505 | if ((strcmp(path, "quorum.device.master_wins") == 0)) { |
506 | if (safe_atoi(value, &i) != 0) { | |
507 | goto atoi_error; | |
508 | } | |
509 | icmap_set_uint8(path, i); | |
510 | add_as_string = 0; | |
511 | } | |
8a45e2b1 JF |
512 | case MAIN_CP_CB_DATA_STATE_TOTEM: |
513 | if ((strcmp(path, "totem.version") == 0) || | |
514 | (strcmp(path, "totem.nodeid") == 0) || | |
515 | (strcmp(path, "totem.threads") == 0) || | |
516 | (strcmp(path, "totem.token") == 0) || | |
517 | (strcmp(path, "totem.token_retransmit") == 0) || | |
518 | (strcmp(path, "totem.hold") == 0) || | |
519 | (strcmp(path, "totem.token_retransmits_before_loss_const") == 0) || | |
520 | (strcmp(path, "totem.join") == 0) || | |
521 | (strcmp(path, "totem.send_join") == 0) || | |
522 | (strcmp(path, "totem.consensus") == 0) || | |
523 | (strcmp(path, "totem.merge") == 0) || | |
524 | (strcmp(path, "totem.downcheck") == 0) || | |
525 | (strcmp(path, "totem.fail_recv_const") == 0) || | |
526 | (strcmp(path, "totem.seqno_unchanged_const") == 0) || | |
527 | (strcmp(path, "totem.rrp_token_expired_timeout") == 0) || | |
528 | (strcmp(path, "totem.rrp_problem_count_timeout") == 0) || | |
529 | (strcmp(path, "totem.rrp_problem_count_threshold") == 0) || | |
530 | (strcmp(path, "totem.rrp_problem_count_mcast_threshold") == 0) || | |
531 | (strcmp(path, "totem.rrp_autorecovery_check_timeout") == 0) || | |
532 | (strcmp(path, "totem.heartbeat_failures_allowed") == 0) || | |
533 | (strcmp(path, "totem.max_network_delay") == 0) || | |
534 | (strcmp(path, "totem.window_size") == 0) || | |
535 | (strcmp(path, "totem.max_messages") == 0) || | |
536 | (strcmp(path, "totem.miss_count_const") == 0) || | |
537 | (strcmp(path, "totem.netmtu") == 0)) { | |
0929dcb6 JF |
538 | if (safe_atoi(value, &i) != 0) { |
539 | goto atoi_error; | |
540 | } | |
8a45e2b1 JF |
541 | icmap_set_uint32(path, i); |
542 | add_as_string = 0; | |
543 | } | |
6825c1d3 JF |
544 | if (strcmp(path, "totem.config_version") == 0) { |
545 | if (str_to_ull(value, &ull) != 0) { | |
546 | goto atoi_error; | |
547 | } | |
548 | icmap_set_uint64(path, ull); | |
549 | add_as_string = 0; | |
550 | } | |
dd588d00 JF |
551 | if (strcmp(path, "totem.ip_version") == 0) { |
552 | if ((strcmp(value, "ipv4") != 0) && | |
553 | (strcmp(value, "ipv6") != 0)) { | |
554 | *error_string = "Invalid ip_version type"; | |
555 | ||
556 | return (0); | |
557 | } | |
558 | } | |
8cdd2fc4 JF |
559 | if (strcmp(path, "totem.crypto_type") == 0) { |
560 | if ((strcmp(value, "nss") != 0) && | |
20c58715 FDN |
561 | (strcmp(value, "aes256") != 0) && |
562 | (strcmp(value, "aes192") != 0) && | |
563 | (strcmp(value, "aes128") != 0) && | |
564 | (strcmp(value, "3des") != 0)) { | |
8cdd2fc4 JF |
565 | *error_string = "Invalid crypto type"; |
566 | ||
567 | return (0); | |
568 | } | |
569 | } | |
ab1675f0 JF |
570 | if (strcmp(path, "totem.crypto_cipher") == 0) { |
571 | if ((strcmp(value, "none") != 0) && | |
20c58715 FDN |
572 | (strcmp(value, "aes256") != 0) && |
573 | (strcmp(value, "aes192") != 0) && | |
574 | (strcmp(value, "aes128") != 0) && | |
575 | (strcmp(value, "3des") != 0)) { | |
ab1675f0 JF |
576 | *error_string = "Invalid cipher type"; |
577 | ||
578 | return (0); | |
579 | } | |
580 | } | |
581 | if (strcmp(path, "totem.crypto_hash") == 0) { | |
582 | if ((strcmp(value, "none") != 0) && | |
e57b5b9e | 583 | (strcmp(value, "md5") != 0) && |
4a2d5036 | 584 | (strcmp(value, "sha1") != 0) && |
4a2d5036 FDN |
585 | (strcmp(value, "sha256") != 0) && |
586 | (strcmp(value, "sha384") != 0) && | |
587 | (strcmp(value, "sha512") != 0)) { | |
ab1675f0 JF |
588 | *error_string = "Invalid hash type"; |
589 | ||
590 | return (0); | |
591 | } | |
592 | } | |
a919908e SD |
593 | break; |
594 | ||
3cd4f9a1 JF |
595 | case MAIN_CP_CB_DATA_STATE_QB: |
596 | if (strcmp(path, "qb.ipc_type") == 0) { | |
597 | if ((strcmp(value, "native") != 0) && | |
598 | (strcmp(value, "shm") != 0) && | |
599 | (strcmp(value, "socket") != 0)) { | |
600 | *error_string = "Invalid qb ipc_type"; | |
601 | ||
602 | return (0); | |
603 | } | |
604 | } | |
605 | break; | |
606 | ||
8a45e2b1 JF |
607 | case MAIN_CP_CB_DATA_STATE_INTERFACE: |
608 | if (strcmp(path, "totem.interface.ringnumber") == 0) { | |
0929dcb6 JF |
609 | if (safe_atoi(value, &i) != 0) { |
610 | goto atoi_error; | |
611 | } | |
612 | ||
613 | data->ringnumber = i; | |
8a45e2b1 JF |
614 | add_as_string = 0; |
615 | } | |
616 | if (strcmp(path, "totem.interface.bindnetaddr") == 0) { | |
617 | data->bindnetaddr = strdup(value); | |
618 | add_as_string = 0; | |
619 | } | |
620 | if (strcmp(path, "totem.interface.mcastaddr") == 0) { | |
621 | data->mcastaddr = strdup(value); | |
622 | add_as_string = 0; | |
623 | } | |
624 | if (strcmp(path, "totem.interface.broadcast") == 0) { | |
625 | data->broadcast = strdup(value); | |
626 | add_as_string = 0; | |
627 | } | |
628 | if (strcmp(path, "totem.interface.mcastport") == 0) { | |
0929dcb6 JF |
629 | if (safe_atoi(value, &i) != 0) { |
630 | goto atoi_error; | |
631 | } | |
632 | data->mcastport = i; | |
8a45e2b1 JF |
633 | if (data->mcastport < 0 || data->mcastport > 65535) { |
634 | *error_string = "Invalid multicast port (should be 0..65535)"; | |
635 | ||
636 | return (0); | |
637 | }; | |
638 | add_as_string = 0; | |
639 | } | |
640 | if (strcmp(path, "totem.interface.ttl") == 0) { | |
0929dcb6 JF |
641 | if (safe_atoi(value, &i) != 0) { |
642 | goto atoi_error; | |
643 | } | |
644 | data->ttl = i; | |
8a45e2b1 JF |
645 | if (data->ttl < 0 || data->ttl > 255) { |
646 | *error_string = "Invalid TTL (should be 0..255)"; | |
647 | ||
648 | return (0); | |
649 | }; | |
650 | add_as_string = 0; | |
651 | } | |
652 | break; | |
653 | case MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS: | |
654 | if (strcmp(key, "subsys") == 0) { | |
655 | data->subsys = strdup(value); | |
656 | if (data->subsys == NULL) { | |
657 | *error_string = "Can't alloc memory"; | |
658 | ||
659 | return (0); | |
660 | } | |
661 | } else { | |
662 | kv_item = malloc(sizeof(*kv_item)); | |
663 | if (kv_item == NULL) { | |
664 | *error_string = "Can't alloc memory"; | |
665 | ||
666 | return (0); | |
667 | } | |
668 | memset(kv_item, 0, sizeof(*kv_item)); | |
669 | ||
670 | kv_item->key = strdup(key); | |
671 | kv_item->value = strdup(value); | |
672 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
673 | free(kv_item); | |
674 | *error_string = "Can't alloc memory"; | |
675 | ||
676 | return (0); | |
677 | } | |
678 | list_init(&kv_item->list); | |
679 | list_add(&kv_item->list, &data->logger_subsys_items_head); | |
680 | } | |
681 | add_as_string = 0; | |
682 | break; | |
683 | case MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON: | |
684 | if (strcmp(key, "subsys") == 0) { | |
685 | data->subsys = strdup(value); | |
686 | if (data->subsys == NULL) { | |
687 | *error_string = "Can't alloc memory"; | |
688 | ||
689 | return (0); | |
690 | } | |
691 | } else if (strcmp(key, "name") == 0) { | |
692 | data->logging_daemon_name = strdup(value); | |
693 | if (data->logging_daemon_name == NULL) { | |
694 | *error_string = "Can't alloc memory"; | |
695 | ||
696 | return (0); | |
697 | } | |
698 | } else { | |
699 | kv_item = malloc(sizeof(*kv_item)); | |
700 | if (kv_item == NULL) { | |
701 | *error_string = "Can't alloc memory"; | |
702 | ||
703 | return (0); | |
704 | } | |
705 | memset(kv_item, 0, sizeof(*kv_item)); | |
706 | ||
707 | kv_item->key = strdup(key); | |
708 | kv_item->value = strdup(value); | |
709 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
710 | free(kv_item); | |
711 | *error_string = "Can't alloc memory"; | |
712 | ||
713 | return (0); | |
714 | } | |
715 | list_init(&kv_item->list); | |
716 | list_add(&kv_item->list, &data->logger_subsys_items_head); | |
717 | } | |
718 | add_as_string = 0; | |
719 | break; | |
720 | case MAIN_CP_CB_DATA_STATE_UIDGID: | |
721 | if (strcmp(key, "uid") == 0) { | |
722 | uid = uid_determine(value); | |
723 | if (uid == -1) { | |
724 | *error_string = error_string_response; | |
725 | return (0); | |
726 | } | |
727 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.uid.%u", | |
728 | uid); | |
729 | icmap_set_uint8(key_name, 1); | |
730 | add_as_string = 0; | |
731 | } else if (strcmp(key, "gid") == 0) { | |
732 | gid = gid_determine(value); | |
733 | if (gid == -1) { | |
734 | *error_string = error_string_response; | |
735 | return (0); | |
736 | } | |
737 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.gid.%u", | |
738 | gid); | |
739 | icmap_set_uint8(key_name, 1); | |
740 | add_as_string = 0; | |
741 | } else { | |
742 | *error_string = "uidgid: Only uid and gid are allowed items"; | |
743 | return (0); | |
744 | } | |
745 | break; | |
746 | case MAIN_CP_CB_DATA_STATE_MEMBER: | |
747 | if (strcmp(key, "memberaddr") != 0) { | |
748 | *error_string = "Only memberaddr is allowed in member section"; | |
749 | ||
750 | return (0); | |
751 | } | |
752 | ||
753 | kv_item = malloc(sizeof(*kv_item)); | |
754 | if (kv_item == NULL) { | |
755 | *error_string = "Can't alloc memory"; | |
756 | ||
757 | return (0); | |
758 | } | |
759 | memset(kv_item, 0, sizeof(*kv_item)); | |
760 | ||
761 | kv_item->key = strdup(key); | |
762 | kv_item->value = strdup(value); | |
763 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
764 | free(kv_item); | |
765 | *error_string = "Can't alloc memory"; | |
766 | ||
767 | return (0); | |
768 | } | |
769 | list_init(&kv_item->list); | |
770 | list_add(&kv_item->list, &data->member_items_head); | |
771 | add_as_string = 0; | |
772 | break; | |
6d0b0b14 JF |
773 | case MAIN_CP_CB_DATA_STATE_NODELIST: |
774 | break; | |
775 | case MAIN_CP_CB_DATA_STATE_NODELIST_NODE: | |
776 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.%s", data->node_number, key); | |
777 | if ((strcmp(key, "nodeid") == 0) || | |
778 | (strcmp(key, "quorum_votes") == 0)) { | |
0929dcb6 JF |
779 | if (safe_atoi(value, &i) != 0) { |
780 | goto atoi_error; | |
781 | } | |
782 | ||
6d0b0b14 JF |
783 | icmap_set_uint32(key_name, i); |
784 | add_as_string = 0; | |
785 | } | |
786 | ||
787 | if (strcmp(key, "ring0_addr") == 0) { | |
788 | data->ring0_addr_added = 1; | |
789 | } | |
790 | ||
791 | if (add_as_string) { | |
792 | icmap_set_string(key_name, value); | |
793 | add_as_string = 0; | |
794 | } | |
795 | break; | |
ae229831 JF |
796 | } |
797 | ||
8a45e2b1 JF |
798 | if (add_as_string) { |
799 | icmap_set_string(path, value); | |
800 | } | |
801 | break; | |
802 | case PARSER_CB_SECTION_START: | |
803 | if (strcmp(path, "totem.interface") == 0) { | |
804 | data->state = MAIN_CP_CB_DATA_STATE_INTERFACE; | |
805 | data->ringnumber = 0; | |
806 | data->mcastport = -1; | |
807 | data->ttl = -1; | |
808 | list_init(&data->member_items_head); | |
809 | }; | |
810 | if (strcmp(path, "totem") == 0) { | |
811 | data->state = MAIN_CP_CB_DATA_STATE_TOTEM; | |
812 | }; | |
3cd4f9a1 JF |
813 | if (strcmp(path, "qb") == 0) { |
814 | data->state = MAIN_CP_CB_DATA_STATE_QB; | |
815 | } | |
8a45e2b1 JF |
816 | if (strcmp(path, "logging.logger_subsys") == 0) { |
817 | data->state = MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS; | |
818 | list_init(&data->logger_subsys_items_head); | |
819 | data->subsys = NULL; | |
820 | } | |
821 | if (strcmp(path, "logging.logging_daemon") == 0) { | |
822 | data->state = MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON; | |
823 | list_init(&data->logger_subsys_items_head); | |
824 | data->subsys = NULL; | |
825 | data->logging_daemon_name = NULL; | |
826 | } | |
827 | if (strcmp(path, "uidgid") == 0) { | |
828 | data->state = MAIN_CP_CB_DATA_STATE_UIDGID; | |
ae229831 | 829 | } |
8a45e2b1 JF |
830 | if (strcmp(path, "totem.interface.member") == 0) { |
831 | data->state = MAIN_CP_CB_DATA_STATE_MEMBER; | |
832 | } | |
833 | if (strcmp(path, "quorum") == 0) { | |
834 | data->state = MAIN_CP_CB_DATA_STATE_QUORUM; | |
835 | } | |
cb5fd775 FDN |
836 | if (strcmp(path, "quorum.device") == 0) { |
837 | data->state = MAIN_CP_CB_DATA_STATE_QDEVICE; | |
838 | } | |
6d0b0b14 JF |
839 | if (strcmp(path, "nodelist") == 0) { |
840 | data->state = MAIN_CP_CB_DATA_STATE_NODELIST; | |
841 | data->node_number = 0; | |
842 | } | |
843 | if (strcmp(path, "nodelist.node") == 0) { | |
844 | data->state = MAIN_CP_CB_DATA_STATE_NODELIST_NODE; | |
845 | data->ring0_addr_added = 0; | |
846 | } | |
8a45e2b1 JF |
847 | break; |
848 | case PARSER_CB_SECTION_END: | |
849 | switch (data->state) { | |
850 | case MAIN_CP_CB_DATA_STATE_NORMAL: | |
851 | break; | |
eb3d49ef FDN |
852 | case MAIN_CP_CB_DATA_STATE_PLOAD: |
853 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
854 | break; | |
8a45e2b1 JF |
855 | case MAIN_CP_CB_DATA_STATE_INTERFACE: |
856 | /* | |
857 | * Create new interface section | |
858 | */ | |
859 | if (data->bindnetaddr != NULL) { | |
860 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", | |
861 | data->ringnumber); | |
862 | icmap_set_string(key_name, data->bindnetaddr); | |
863 | ||
864 | free(data->bindnetaddr); | |
865 | data->bindnetaddr = NULL; | |
8a45e2b1 JF |
866 | } |
867 | ||
868 | if (data->mcastaddr != NULL) { | |
869 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", | |
870 | data->ringnumber); | |
871 | icmap_set_string(key_name, data->mcastaddr); | |
872 | ||
873 | free(data->mcastaddr); | |
874 | data->mcastaddr = NULL; | |
875 | } | |
876 | ||
877 | if (data->broadcast != NULL) { | |
878 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", | |
879 | data->ringnumber); | |
880 | icmap_set_string(key_name, data->broadcast); | |
881 | ||
882 | free(data->broadcast); | |
883 | data->broadcast = NULL; | |
884 | } | |
885 | ||
886 | if (data->mcastport > -1) { | |
887 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", | |
888 | data->ringnumber); | |
889 | icmap_set_uint16(key_name, data->mcastport); | |
890 | } | |
891 | ||
892 | if (data->ttl > -1) { | |
893 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", | |
894 | data->ringnumber); | |
895 | icmap_set_uint8(key_name, data->ttl); | |
896 | } | |
897 | ||
898 | i = 0; | |
899 | for (iter = data->member_items_head.next; | |
900 | iter != &data->member_items_head; iter = iter_next) { | |
901 | kv_item = list_entry(iter, struct key_value_list_item, list); | |
902 | ||
903 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.%u", | |
904 | data->ringnumber, i); | |
905 | icmap_set_string(key_name, kv_item->value); | |
906 | ||
907 | iter_next = iter->next; | |
908 | ||
909 | free(kv_item->value); | |
910 | free(kv_item->key); | |
911 | free(kv_item); | |
912 | i++; | |
913 | } | |
914 | ||
915 | data->state = MAIN_CP_CB_DATA_STATE_TOTEM; | |
916 | break; | |
917 | case MAIN_CP_CB_DATA_STATE_TOTEM: | |
918 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
919 | break; | |
3cd4f9a1 JF |
920 | case MAIN_CP_CB_DATA_STATE_QB: |
921 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
922 | break; | |
8a45e2b1 JF |
923 | case MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS: |
924 | if (data->subsys == NULL) { | |
925 | *error_string = "No subsys key in logger_subsys directive"; | |
926 | ||
927 | return (0); | |
928 | } | |
929 | ||
930 | for (iter = data->logger_subsys_items_head.next; | |
931 | iter != &data->logger_subsys_items_head; iter = iter_next) { | |
932 | kv_item = list_entry(iter, struct key_value_list_item, list); | |
933 | ||
934 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.%s", | |
935 | data->subsys, kv_item->key); | |
936 | icmap_set_string(key_name, kv_item->value); | |
937 | ||
938 | iter_next = iter->next; | |
939 | ||
940 | free(kv_item->value); | |
941 | free(kv_item->key); | |
942 | free(kv_item); | |
943 | } | |
944 | ||
945 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.subsys", | |
946 | data->subsys); | |
947 | icmap_set_string(key_name, data->subsys); | |
948 | ||
949 | free(data->subsys); | |
950 | ||
951 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
952 | break; | |
953 | case MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON: | |
954 | if (data->logging_daemon_name == NULL) { | |
955 | *error_string = "No name key in logging_daemon directive"; | |
956 | ||
957 | return (0); | |
958 | } | |
959 | ||
960 | for (iter = data->logger_subsys_items_head.next; | |
961 | iter != &data->logger_subsys_items_head; iter = iter_next) { | |
962 | kv_item = list_entry(iter, struct key_value_list_item, list); | |
963 | ||
964 | if (data->subsys == NULL) { | |
965 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
966 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
967 | "logging.%s", | |
968 | kv_item->key); | |
969 | } else { | |
970 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
971 | "logging.logging_daemon.%s.%s", | |
972 | data->logging_daemon_name, kv_item->key); | |
973 | } | |
974 | } else { | |
975 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
976 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
977 | "logging.logger_subsys.%s.%s", | |
978 | data->subsys, | |
979 | kv_item->key); | |
980 | } else { | |
981 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
982 | "logging.logging_daemon.%s.%s.%s", | |
983 | data->logging_daemon_name, data->subsys, | |
984 | kv_item->key); | |
985 | } | |
986 | } | |
987 | icmap_set_string(key_name, kv_item->value); | |
988 | ||
989 | iter_next = iter->next; | |
990 | ||
991 | free(kv_item->value); | |
992 | free(kv_item->key); | |
993 | free(kv_item); | |
994 | } | |
995 | ||
996 | if (data->subsys == NULL) { | |
997 | if (strcmp(data->logging_daemon_name, "corosync") != 0) { | |
998 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.name", | |
999 | data->logging_daemon_name); | |
1000 | icmap_set_string(key_name, data->logging_daemon_name); | |
1001 | } | |
1002 | } else { | |
1003 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
1004 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.subsys", | |
1005 | data->subsys); | |
1006 | icmap_set_string(key_name, data->subsys); | |
1007 | ||
1008 | } else { | |
1009 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.%s.subsys", | |
1010 | data->logging_daemon_name, data->subsys); | |
1011 | icmap_set_string(key_name, data->subsys); | |
1012 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.%s.name", | |
1013 | data->logging_daemon_name, data->subsys); | |
1014 | icmap_set_string(key_name, data->logging_daemon_name); | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | free(data->subsys); | |
1019 | free(data->logging_daemon_name); | |
1020 | ||
1021 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
1022 | break; | |
1023 | case MAIN_CP_CB_DATA_STATE_UIDGID: | |
1024 | data->state = MAIN_CP_CB_DATA_STATE_UIDGID; | |
1025 | break; | |
1026 | case MAIN_CP_CB_DATA_STATE_MEMBER: | |
1027 | data->state = MAIN_CP_CB_DATA_STATE_INTERFACE; | |
1028 | break; | |
1029 | case MAIN_CP_CB_DATA_STATE_QUORUM: | |
1030 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
1031 | break; | |
cb5fd775 FDN |
1032 | case MAIN_CP_CB_DATA_STATE_QDEVICE: |
1033 | data->state = MAIN_CP_CB_DATA_STATE_QUORUM; | |
1034 | break; | |
6d0b0b14 JF |
1035 | case MAIN_CP_CB_DATA_STATE_NODELIST: |
1036 | data->state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
1037 | break; | |
1038 | case MAIN_CP_CB_DATA_STATE_NODELIST_NODE: | |
1039 | if (!data->ring0_addr_added) { | |
1040 | *error_string = "No ring0_addr specified for node"; | |
1041 | ||
1042 | return (0); | |
1043 | } | |
1044 | data->node_number++; | |
1045 | data->state = MAIN_CP_CB_DATA_STATE_NODELIST; | |
1046 | break; | |
8a45e2b1 JF |
1047 | } |
1048 | break; | |
ae229831 JF |
1049 | } |
1050 | ||
8a45e2b1 | 1051 | return (1); |
0929dcb6 JF |
1052 | |
1053 | atoi_error: | |
1054 | snprintf(formated_err, sizeof(formated_err), | |
1055 | "Value of key \"%s\" must be integer, but \"%s\" was given", key, value); | |
1056 | *error_string = formated_err; | |
1057 | ||
1058 | return (0); | |
8a45e2b1 JF |
1059 | } |
1060 | ||
1061 | static int uidgid_config_parser_cb(const char *path, | |
1062 | char *key, | |
1063 | char *value, | |
1064 | enum parser_cb_type type, | |
1065 | const char **error_string, | |
1066 | void *user_data) | |
1067 | { | |
1068 | char key_name[ICMAP_KEYNAME_MAXLEN]; | |
1069 | int uid, gid; | |
1070 | ||
1071 | switch (type) { | |
1072 | case PARSER_CB_START: | |
1073 | break; | |
1074 | case PARSER_CB_END: | |
1075 | break; | |
1076 | case PARSER_CB_ITEM: | |
1077 | if (strcmp(path, "uidgid.uid") == 0) { | |
1078 | uid = uid_determine(value); | |
1079 | if (uid == -1) { | |
1080 | *error_string = error_string_response; | |
1081 | return (0); | |
1082 | } | |
1083 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.uid.%u", | |
1084 | uid); | |
1085 | icmap_set_uint8(key_name, 1); | |
92ead610 | 1086 | } else if (strcmp(path, "uidgid.gid") == 0) { |
8a45e2b1 JF |
1087 | gid = gid_determine(value); |
1088 | if (gid == -1) { | |
1089 | *error_string = error_string_response; | |
1090 | return (0); | |
1091 | } | |
1092 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.gid.%u", | |
1093 | gid); | |
1094 | icmap_set_uint8(key_name, 1); | |
1095 | } else { | |
ae229831 | 1096 | *error_string = "uidgid: Only uid and gid are allowed items"; |
8a45e2b1 | 1097 | return (0); |
ae229831 | 1098 | } |
8a45e2b1 JF |
1099 | break; |
1100 | case PARSER_CB_SECTION_START: | |
1101 | if (strcmp(path, "uidgid") != 0) { | |
1102 | *error_string = "uidgid: Can't add subsection different then uidgid"; | |
1103 | return (0); | |
1104 | }; | |
1105 | break; | |
1106 | case PARSER_CB_SECTION_END: | |
1107 | break; | |
ae229831 | 1108 | } |
2f552719 | 1109 | |
8a45e2b1 | 1110 | return (1); |
ae229831 JF |
1111 | } |
1112 | ||
8a45e2b1 | 1113 | static int read_uidgid_files_into_icmap( |
ae229831 JF |
1114 | const char **error_string) |
1115 | { | |
1116 | FILE *fp; | |
1117 | const char *dirname; | |
1118 | DIR *dp; | |
1119 | struct dirent *dirent; | |
2290913d | 1120 | struct dirent *entry; |
1bd8aba6 | 1121 | char filename[PATH_MAX + FILENAME_MAX + 1]; |
ae229831 | 1122 | int res = 0; |
2290913d AS |
1123 | size_t len; |
1124 | int return_code; | |
1e0d40cd | 1125 | struct stat stat_buf; |
8a45e2b1 | 1126 | char key_name[ICMAP_KEYNAME_MAXLEN]; |
ae229831 | 1127 | |
2135d91c | 1128 | dirname = COROSYSCONFDIR "/uidgid.d"; |
ae229831 JF |
1129 | dp = opendir (dirname); |
1130 | ||
1131 | if (dp == NULL) | |
1132 | return 0; | |
1133 | ||
427fdd45 | 1134 | len = offsetof(struct dirent, d_name) + FILENAME_MAX + 1; |
eda1e364 | 1135 | |
2290913d | 1136 | entry = malloc(len); |
eda1e364 | 1137 | if (entry == NULL) { |
c2a39cb8 JF |
1138 | res = 0; |
1139 | goto error_exit; | |
eda1e364 | 1140 | } |
2290913d AS |
1141 | |
1142 | for (return_code = readdir_r(dp, entry, &dirent); | |
1143 | dirent != NULL && return_code == 0; | |
1144 | return_code = readdir_r(dp, entry, &dirent)) { | |
1145 | ||
1e0d40cd SD |
1146 | snprintf(filename, sizeof (filename), "%s/%s", dirname, dirent->d_name); |
1147 | stat (filename, &stat_buf); | |
1148 | if (S_ISREG(stat_buf.st_mode)) { | |
ae229831 JF |
1149 | |
1150 | fp = fopen (filename, "r"); | |
1151 | if (fp == NULL) continue; | |
1152 | ||
8a45e2b1 JF |
1153 | key_name[0] = 0; |
1154 | ||
66172a50 | 1155 | res = parse_section(fp, key_name, error_string, 0, uidgid_config_parser_cb, NULL); |
ae229831 JF |
1156 | |
1157 | fclose (fp); | |
1158 | ||
1159 | if (res != 0) { | |
1160 | goto error_exit; | |
1161 | } | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | error_exit: | |
2290913d | 1166 | free (entry); |
ae229831 JF |
1167 | closedir(dp); |
1168 | ||
1169 | return res; | |
1170 | } | |
2f552719 | 1171 | |
8a45e2b1 JF |
1172 | /* Read config file and load into icmap */ |
1173 | static int read_config_file_into_icmap( | |
23c64c64 | 1174 | const char **error_string) |
2f552719 SD |
1175 | { |
1176 | FILE *fp; | |
23c64c64 | 1177 | const char *filename; |
2f552719 SD |
1178 | char *error_reason = error_string_response; |
1179 | int res; | |
8a45e2b1 JF |
1180 | char key_name[ICMAP_KEYNAME_MAXLEN]; |
1181 | struct main_cp_cb_data data; | |
2f552719 SD |
1182 | |
1183 | filename = getenv ("COROSYNC_MAIN_CONFIG_FILE"); | |
1184 | if (!filename) | |
2135d91c | 1185 | filename = COROSYSCONFDIR "/corosync.conf"; |
2f552719 SD |
1186 | |
1187 | fp = fopen (filename, "r"); | |
23c64c64 | 1188 | if (fp == NULL) { |
20f3331d | 1189 | char error_str[100]; |
37e17e7a | 1190 | const char *error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str)); |
870046d0 | 1191 | snprintf (error_reason, sizeof(error_string_response), |
3131601c | 1192 | "Can't read file %s reason = (%s)", |
00434a4f | 1193 | filename, error_ptr); |
2f552719 SD |
1194 | *error_string = error_reason; |
1195 | return -1; | |
1196 | } | |
1197 | ||
8a45e2b1 JF |
1198 | key_name[0] = 0; |
1199 | ||
66172a50 | 1200 | res = parse_section(fp, key_name, error_string, 0, main_config_parser_cb, &data); |
2f552719 SD |
1201 | |
1202 | fclose(fp); | |
1203 | ||
ae229831 | 1204 | if (res == 0) { |
8a45e2b1 | 1205 | res = read_uidgid_files_into_icmap(error_string); |
ae229831 JF |
1206 | } |
1207 | ||
94b64352 JF |
1208 | if (res == 0) { |
1209 | snprintf (error_reason, sizeof(error_string_response), | |
3131601c | 1210 | "Successfully read main configuration file '%s'.", filename); |
94b64352 JF |
1211 | *error_string = error_reason; |
1212 | } | |
2f552719 SD |
1213 | |
1214 | return res; | |
1215 | } |