]>
Commit | Line | Data |
---|---|---|
2f552719 | 1 | /* |
d05636b7 | 2 | * Copyright (c) 2006-2019 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> |
2f9aaefb | 52 | #include <libgen.h> |
6fd822c4 | 53 | #include <limits.h> |
2290913d | 54 | #include <stddef.h> |
8a45e2b1 JF |
55 | #include <grp.h> |
56 | #include <pwd.h> | |
2f552719 | 57 | |
b4c06e52 | 58 | #include <qb/qblist.h> |
37e17e7a | 59 | #include <qb/qbutil.h> |
00434a4f | 60 | #define LOGSYS_UTILS_ONLY 1 |
8ad583a5 | 61 | #include <corosync/logsys.h> |
6f5e3293 | 62 | #include <corosync/icmap.h> |
e1f53138 | 63 | |
f763d3ba | 64 | #include "main.h" |
2f552719 SD |
65 | #include "util.h" |
66 | ||
8a45e2b1 JF |
67 | enum parser_cb_type { |
68 | PARSER_CB_START, | |
69 | PARSER_CB_END, | |
70 | PARSER_CB_SECTION_START, | |
71 | PARSER_CB_SECTION_END, | |
72 | PARSER_CB_ITEM, | |
73 | }; | |
74 | ||
8a45e2b1 JF |
75 | enum main_cp_cb_data_state { |
76 | MAIN_CP_CB_DATA_STATE_NORMAL, | |
77 | MAIN_CP_CB_DATA_STATE_TOTEM, | |
78 | MAIN_CP_CB_DATA_STATE_INTERFACE, | |
79 | MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS, | |
80 | MAIN_CP_CB_DATA_STATE_UIDGID, | |
81 | MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON, | |
82 | MAIN_CP_CB_DATA_STATE_MEMBER, | |
83 | MAIN_CP_CB_DATA_STATE_QUORUM, | |
cb5fd775 | 84 | MAIN_CP_CB_DATA_STATE_QDEVICE, |
6d0b0b14 JF |
85 | MAIN_CP_CB_DATA_STATE_NODELIST, |
86 | MAIN_CP_CB_DATA_STATE_NODELIST_NODE, | |
3cd4f9a1 | 87 | MAIN_CP_CB_DATA_STATE_PLOAD, |
cd4d5fd3 | 88 | MAIN_CP_CB_DATA_STATE_SYSTEM, |
39cd6b3d | 89 | MAIN_CP_CB_DATA_STATE_RESOURCES, |
90 | MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM, | |
91 | MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS, | |
92 | MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM_MEMUSED, | |
93 | MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS_MEMUSED | |
8a45e2b1 JF |
94 | }; |
95 | ||
aab55a00 CC |
96 | typedef int (*parser_cb_f)(const char *path, |
97 | char *key, | |
98 | char *value, | |
99 | enum main_cp_cb_data_state *state, | |
100 | enum parser_cb_type type, | |
101 | const char **error_string, | |
102 | icmap_map_t config_map, | |
103 | void *user_data); | |
104 | ||
8a45e2b1 JF |
105 | struct key_value_list_item { |
106 | char *key; | |
107 | char *value; | |
b4c06e52 | 108 | struct qb_list_head list; |
8a45e2b1 JF |
109 | }; |
110 | ||
111 | struct main_cp_cb_data { | |
268cde6e | 112 | int linknumber; |
8a45e2b1 JF |
113 | char *bindnetaddr; |
114 | char *mcastaddr; | |
115 | char *broadcast; | |
116 | int mcastport; | |
117 | int ttl; | |
268cde6e CC |
118 | int knet_link_priority; |
119 | int knet_ping_interval; | |
120 | int knet_ping_timeout; | |
121 | int knet_ping_precision; | |
7cec6a13 CC |
122 | int knet_pong_count; |
123 | int knet_pmtud_interval; | |
c0f1d576 | 124 | char *knet_transport; |
8a45e2b1 | 125 | |
b4c06e52 | 126 | struct qb_list_head logger_subsys_items_head; |
8a45e2b1 JF |
127 | char *subsys; |
128 | char *logging_daemon_name; | |
b4c06e52 | 129 | struct qb_list_head member_items_head; |
6d0b0b14 JF |
130 | |
131 | int node_number; | |
8a45e2b1 JF |
132 | }; |
133 | ||
134 | static int read_config_file_into_icmap( | |
bc47c583 | 135 | const char **error_string, icmap_map_t config_map); |
2f552719 SD |
136 | static char error_string_response[512]; |
137 | ||
8a45e2b1 JF |
138 | static int uid_determine (const char *req_user) |
139 | { | |
140 | int pw_uid = 0; | |
141 | struct passwd passwd; | |
142 | struct passwd* pwdptr = &passwd; | |
143 | struct passwd* temp_pwd_pt; | |
144 | char *pwdbuffer; | |
005e7fd3 | 145 | int pwdlinelen, rc; |
86b074dc JF |
146 | long int id; |
147 | char *ep; | |
148 | ||
149 | id = strtol(req_user, &ep, 10); | |
f05d1c92 | 150 | if (*req_user != '\0' && *ep == '\0' && id >= 0 && id <= UINT_MAX) { |
86b074dc JF |
151 | return (id); |
152 | } | |
8a45e2b1 JF |
153 | |
154 | pwdlinelen = sysconf (_SC_GETPW_R_SIZE_MAX); | |
155 | ||
156 | if (pwdlinelen == -1) { | |
157 | pwdlinelen = 256; | |
158 | } | |
159 | ||
160 | pwdbuffer = malloc (pwdlinelen); | |
161 | ||
005e7fd3 AB |
162 | while ((rc = getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) == ERANGE) { |
163 | char *n; | |
164 | ||
165 | pwdlinelen *= 2; | |
166 | if (pwdlinelen <= 32678) { | |
167 | n = realloc (pwdbuffer, pwdlinelen); | |
168 | if (n != NULL) { | |
169 | pwdbuffer = n; | |
170 | continue; | |
52f88d04 JF |
171 | } |
172 | } | |
005e7fd3 AB |
173 | } |
174 | if (rc != 0) { | |
175 | free (pwdbuffer); | |
176 | sprintf (error_string_response, "getpwnam_r(): %s", strerror(rc)); | |
177 | return (-1); | |
178 | } | |
179 | if (temp_pwd_pt == NULL) { | |
52f88d04 | 180 | free (pwdbuffer); |
8a45e2b1 JF |
181 | sprintf (error_string_response, |
182 | "The '%s' user is not found in /etc/passwd, please read the documentation.", | |
183 | req_user); | |
184 | return (-1); | |
185 | } | |
186 | pw_uid = passwd.pw_uid; | |
187 | free (pwdbuffer); | |
188 | ||
189 | return pw_uid; | |
190 | } | |
191 | ||
192 | static int gid_determine (const char *req_group) | |
193 | { | |
7c8e83ac | 194 | int corosync_gid = 0; |
8a45e2b1 JF |
195 | struct group group; |
196 | struct group * grpptr = &group; | |
197 | struct group * temp_grp_pt; | |
198 | char *grpbuffer; | |
005e7fd3 | 199 | int grplinelen, rc; |
86b074dc JF |
200 | long int id; |
201 | char *ep; | |
202 | ||
203 | id = strtol(req_group, &ep, 10); | |
f05d1c92 | 204 | if (*req_group != '\0' && *ep == '\0' && id >= 0 && id <= UINT_MAX) { |
86b074dc JF |
205 | return (id); |
206 | } | |
8a45e2b1 JF |
207 | |
208 | grplinelen = sysconf (_SC_GETGR_R_SIZE_MAX); | |
209 | ||
210 | if (grplinelen == -1) { | |
211 | grplinelen = 256; | |
212 | } | |
213 | ||
214 | grpbuffer = malloc (grplinelen); | |
215 | ||
005e7fd3 AB |
216 | while ((rc = getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) == ERANGE) { |
217 | char *n; | |
218 | ||
219 | grplinelen *= 2; | |
220 | if (grplinelen <= 32678) { | |
221 | n = realloc (grpbuffer, grplinelen); | |
222 | if (n != NULL) { | |
223 | grpbuffer = n; | |
224 | continue; | |
52f88d04 JF |
225 | } |
226 | } | |
005e7fd3 AB |
227 | } |
228 | if (rc != 0) { | |
229 | free (grpbuffer); | |
230 | sprintf (error_string_response, "getgrnam_r(): %s", strerror(rc)); | |
231 | return (-1); | |
232 | } | |
233 | if (temp_grp_pt == NULL) { | |
52f88d04 | 234 | free (grpbuffer); |
8a45e2b1 JF |
235 | sprintf (error_string_response, |
236 | "The '%s' group is not found in /etc/group, please read the documentation.", | |
237 | req_group); | |
238 | return (-1); | |
239 | } | |
7c8e83ac | 240 | corosync_gid = group.gr_gid; |
8a45e2b1 | 241 | free (grpbuffer); |
2f552719 | 242 | |
7c8e83ac | 243 | return corosync_gid; |
8a45e2b1 | 244 | } |
3ffb151a FDN |
245 | static char *strchr_rs (const char *haystack, int byte) |
246 | { | |
247 | const char *end_address = strchr (haystack, byte); | |
248 | if (end_address) { | |
249 | end_address += 1; /* skip past { or = */ | |
8a45e2b1 JF |
250 | |
251 | while (*end_address == ' ' || *end_address == '\t') | |
252 | end_address++; | |
3ffb151a FDN |
253 | } |
254 | ||
255 | return ((char *) end_address); | |
256 | } | |
257 | ||
bc47c583 | 258 | int coroparse_configparse (icmap_map_t config_map, const char **error_string) |
2f552719 | 259 | { |
bc47c583 | 260 | if (read_config_file_into_icmap(error_string, config_map)) { |
2f552719 SD |
261 | return -1; |
262 | } | |
263 | ||
264 | return 0; | |
265 | } | |
266 | ||
663489d2 | 267 | static char *remove_whitespace(char *string, int remove_colon_and_brace) |
2f552719 | 268 | { |
8a45e2b1 JF |
269 | char *start; |
270 | char *end; | |
2f552719 | 271 | |
8a45e2b1 JF |
272 | start = string; |
273 | while (*start == ' ' || *start == '\t') | |
274 | start++; | |
275 | ||
276 | end = start+(strlen(start))-1; | |
663489d2 | 277 | while ((*end == ' ' || *end == '\t' || (remove_colon_and_brace && (*end == ':' || *end == '{'))) && end > start) |
2f552719 | 278 | end--; |
7a4725f9 JF |
279 | if (*end != '\0') |
280 | *(end + 1) = '\0'; | |
2f552719 SD |
281 | |
282 | return start; | |
283 | } | |
284 | ||
ae229831 | 285 | |
ae229831 | 286 | |
2f552719 | 287 | static int parse_section(FILE *fp, |
f6262e57 JF |
288 | const char *fname, |
289 | int *line_no, | |
290 | char *path, | |
291 | const char **error_string, | |
292 | int depth, | |
293 | enum main_cp_cb_data_state state, | |
294 | parser_cb_f parser_cb, | |
295 | icmap_map_t config_map, | |
296 | void *user_data) | |
2f552719 SD |
297 | { |
298 | char line[512]; | |
299 | int i; | |
300 | char *loc; | |
99db3567 | 301 | int ignore_line; |
8a45e2b1 | 302 | char new_keyname[ICMAP_KEYNAME_MAXLEN]; |
f6262e57 JF |
303 | static char formated_err[384]; |
304 | const char *tmp_error_string; | |
8a45e2b1 JF |
305 | |
306 | if (strcmp(path, "") == 0) { | |
aab55a00 | 307 | parser_cb("", NULL, NULL, &state, PARSER_CB_START, error_string, config_map, user_data); |
8a45e2b1 | 308 | } |
2f552719 | 309 | |
f6262e57 JF |
310 | tmp_error_string = NULL; |
311 | ||
94b64352 | 312 | while (fgets (line, sizeof (line), fp)) { |
f6262e57 JF |
313 | (*line_no)++; |
314 | ||
94b64352 | 315 | if (strlen(line) > 0) { |
20bd68b3 JF |
316 | /* |
317 | * Check if complete line was read. Use feof to handle files | |
318 | * without ending \n at the end of the file | |
319 | */ | |
320 | if ((line[strlen(line) - 1] != '\n') && !feof(fp)) { | |
f6262e57 JF |
321 | tmp_error_string = "Line too long"; |
322 | goto parse_error; | |
20bd68b3 JF |
323 | } |
324 | ||
94b64352 JF |
325 | if (line[strlen(line) - 1] == '\n') |
326 | line[strlen(line) - 1] = '\0'; | |
327 | if (strlen (line) > 0 && line[strlen(line) - 1] == '\r') | |
328 | line[strlen(line) - 1] = '\0'; | |
329 | } | |
2f552719 SD |
330 | /* |
331 | * Clear out white space and tabs | |
332 | */ | |
333 | for (i = strlen (line) - 1; i > -1; i--) { | |
334 | if (line[i] == '\t' || line[i] == ' ') { | |
335 | line[i] = '\0'; | |
336 | } else { | |
337 | break; | |
338 | } | |
339 | } | |
99db3567 JF |
340 | |
341 | ignore_line = 1; | |
342 | for (i = 0; i < strlen (line); i++) { | |
343 | if (line[i] != '\t' && line[i] != ' ') { | |
344 | if (line[i] != '#') | |
345 | ignore_line = 0; | |
346 | ||
347 | break; | |
348 | } | |
349 | } | |
2f552719 SD |
350 | /* |
351 | * Clear out comments and empty lines | |
352 | */ | |
99db3567 | 353 | if (ignore_line) { |
2f552719 SD |
354 | continue; |
355 | } | |
356 | ||
357 | /* New section ? */ | |
283011c6 | 358 | if ((loc = strchr_rs (line, '{'))) { |
80701845 JF |
359 | char *section; |
360 | char *after_section; | |
aab55a00 | 361 | enum main_cp_cb_data_state newstate; |
2f552719 | 362 | |
80701845 JF |
363 | *(loc-1) = '\0'; |
364 | section = remove_whitespace(line, 1); | |
365 | after_section = remove_whitespace(loc, 0); | |
366 | ||
367 | if (strcmp(section, "") == 0) { | |
f6262e57 JF |
368 | tmp_error_string = "Missing section name before opening bracket '{'"; |
369 | goto parse_error; | |
80701845 JF |
370 | } |
371 | ||
372 | if (strcmp(after_section, "") != 0) { | |
f6262e57 JF |
373 | tmp_error_string = "Extra characters after opening bracket '{'"; |
374 | goto parse_error; | |
80701845 | 375 | } |
8a45e2b1 | 376 | |
675da757 | 377 | if (strlen(path) + strlen(section) + 1 >= ICMAP_KEYNAME_MAXLEN) { |
f6262e57 JF |
378 | tmp_error_string = "Start of section makes total cmap path too long"; |
379 | goto parse_error; | |
675da757 | 380 | } |
8a45e2b1 JF |
381 | strcpy(new_keyname, path); |
382 | if (strcmp(path, "") != 0) { | |
383 | strcat(new_keyname, "."); | |
ae229831 | 384 | } |
8a45e2b1 | 385 | strcat(new_keyname, section); |
ae229831 | 386 | |
aab55a00 CC |
387 | /* Only use the new state for items further down the stack */ |
388 | newstate = state; | |
f6262e57 JF |
389 | if (!parser_cb(new_keyname, NULL, NULL, &newstate, PARSER_CB_SECTION_START, |
390 | &tmp_error_string, config_map, user_data)) { | |
391 | goto parse_error; | |
8a45e2b1 JF |
392 | } |
393 | ||
f6262e57 JF |
394 | if (parse_section(fp, fname, line_no, new_keyname, error_string, depth + 1, newstate, |
395 | parser_cb, config_map, user_data)) | |
2f552719 | 396 | return -1; |
663489d2 JF |
397 | |
398 | continue ; | |
2f552719 SD |
399 | } |
400 | ||
401 | /* New key/value */ | |
283011c6 | 402 | if ((loc = strchr_rs (line, ':'))) { |
2f552719 SD |
403 | char *key; |
404 | char *value; | |
405 | ||
406 | *(loc-1) = '\0'; | |
663489d2 JF |
407 | key = remove_whitespace(line, 1); |
408 | value = remove_whitespace(loc, 0); | |
8a45e2b1 | 409 | |
675da757 | 410 | if (strlen(path) + strlen(key) + 1 >= ICMAP_KEYNAME_MAXLEN) { |
f6262e57 JF |
411 | tmp_error_string = "New key makes total cmap path too long"; |
412 | goto parse_error; | |
675da757 | 413 | } |
8a45e2b1 JF |
414 | strcpy(new_keyname, path); |
415 | if (strcmp(path, "") != 0) { | |
416 | strcat(new_keyname, "."); | |
417 | } | |
418 | strcat(new_keyname, key); | |
419 | ||
f6262e57 JF |
420 | if (!parser_cb(new_keyname, key, value, &state, PARSER_CB_ITEM, &tmp_error_string, |
421 | config_map, user_data)) { | |
422 | goto parse_error; | |
ae229831 | 423 | } |
663489d2 JF |
424 | |
425 | continue ; | |
2f552719 SD |
426 | } |
427 | ||
8236a087 | 428 | if (strchr_rs (line, '}')) { |
80701845 JF |
429 | char *trimmed_line; |
430 | trimmed_line = remove_whitespace(line, 0); | |
431 | ||
432 | if (strcmp(trimmed_line, "}") != 0) { | |
f6262e57 JF |
433 | tmp_error_string = "Extra characters before or after closing bracket '}'"; |
434 | goto parse_error; | |
80701845 JF |
435 | } |
436 | ||
66172a50 | 437 | if (depth == 0) { |
f6262e57 | 438 | tmp_error_string = "Unexpected closing brace"; |
66172a50 | 439 | |
f6262e57 | 440 | goto parse_error; |
66172a50 JF |
441 | } |
442 | ||
f6262e57 | 443 | if (!parser_cb(path, NULL, NULL, &state, PARSER_CB_SECTION_END, &tmp_error_string, |
80701845 | 444 | config_map, user_data)) { |
f6262e57 | 445 | goto parse_error; |
8a45e2b1 JF |
446 | } |
447 | ||
2f552719 SD |
448 | return 0; |
449 | } | |
80701845 JF |
450 | |
451 | /* | |
452 | * Line is not opening section, ending section or value -> error | |
453 | */ | |
f6262e57 JF |
454 | tmp_error_string = "Line is not opening or closing section or key value"; |
455 | goto parse_error; | |
2f552719 SD |
456 | } |
457 | ||
8a45e2b1 | 458 | if (strcmp(path, "") != 0) { |
f6262e57 JF |
459 | tmp_error_string = "Missing closing brace"; |
460 | goto parse_error; | |
2f552719 SD |
461 | } |
462 | ||
8a45e2b1 | 463 | if (strcmp(path, "") == 0) { |
aab55a00 | 464 | parser_cb("", NULL, NULL, &state, PARSER_CB_END, error_string, config_map, user_data); |
8a45e2b1 JF |
465 | } |
466 | ||
2f552719 | 467 | return 0; |
f6262e57 JF |
468 | |
469 | parse_error: | |
470 | if (snprintf(formated_err, sizeof(formated_err), "parser error: %s:%u: %s", fname, *line_no, | |
471 | tmp_error_string) >= sizeof(formated_err)) { | |
472 | *error_string = "Can't format parser error message"; | |
473 | } else { | |
474 | *error_string = formated_err; | |
475 | } | |
476 | ||
477 | return -1; | |
2f552719 SD |
478 | } |
479 | ||
4e9716ed | 480 | static int safe_atoq_range(icmap_value_types_t value_type, long long int *min_val, long long int *max_val) |
0929dcb6 | 481 | { |
4e9716ed JF |
482 | switch (value_type) { |
483 | case ICMAP_VALUETYPE_INT8: *min_val = INT8_MIN; *max_val = INT8_MAX; break; | |
484 | case ICMAP_VALUETYPE_UINT8: *min_val = 0; *max_val = UINT8_MAX; break; | |
485 | case ICMAP_VALUETYPE_INT16: *min_val = INT16_MIN; *max_val = INT16_MAX; break; | |
486 | case ICMAP_VALUETYPE_UINT16: *min_val = 0; *max_val = UINT16_MAX; break; | |
487 | case ICMAP_VALUETYPE_INT32: *min_val = INT32_MIN; *max_val = INT32_MAX; break; | |
488 | case ICMAP_VALUETYPE_UINT32: *min_val = 0; *max_val = UINT32_MAX; break; | |
489 | default: | |
490 | return (-1); | |
491 | } | |
492 | ||
493 | return (0); | |
494 | } | |
495 | ||
496 | /* | |
497 | * Convert string str to long long int res. Type of result is target_type and currently only | |
498 | * ICMAP_VALUETYPE_[U]INT[8|16|32] is supported. | |
499 | * Return 0 on success, -1 on failure. | |
500 | */ | |
501 | static int safe_atoq(const char *str, long long int *res, icmap_value_types_t target_type) | |
502 | { | |
503 | long long int val; | |
504 | long long int min_val, max_val; | |
0929dcb6 JF |
505 | char *endptr; |
506 | ||
507 | errno = 0; | |
508 | ||
4e9716ed | 509 | val = strtoll(str, &endptr, 10); |
0929dcb6 JF |
510 | if (errno == ERANGE) { |
511 | return (-1); | |
512 | } | |
513 | ||
514 | if (endptr == str) { | |
515 | return (-1); | |
516 | } | |
517 | ||
518 | if (*endptr != '\0') { | |
519 | return (-1); | |
520 | } | |
521 | ||
4e9716ed JF |
522 | if (safe_atoq_range(target_type, &min_val, &max_val) != 0) { |
523 | return (-1); | |
524 | } | |
525 | ||
526 | if (val < min_val || val > max_val) { | |
527 | return (-1); | |
528 | } | |
529 | ||
0929dcb6 JF |
530 | *res = val; |
531 | return (0); | |
532 | } | |
533 | ||
6825c1d3 JF |
534 | static int str_to_ull(const char *str, unsigned long long int *res) |
535 | { | |
536 | unsigned long long int val; | |
537 | char *endptr; | |
538 | ||
539 | errno = 0; | |
540 | ||
541 | val = strtoull(str, &endptr, 10); | |
542 | if (errno == ERANGE) { | |
543 | return (-1); | |
544 | } | |
545 | ||
546 | if (endptr == str) { | |
547 | return (-1); | |
548 | } | |
549 | ||
550 | if (*endptr != '\0') { | |
551 | return (-1); | |
552 | } | |
553 | ||
554 | *res = val; | |
555 | return (0); | |
556 | } | |
0929dcb6 | 557 | |
8a45e2b1 JF |
558 | static int main_config_parser_cb(const char *path, |
559 | char *key, | |
560 | char *value, | |
aab55a00 | 561 | enum main_cp_cb_data_state *state, |
8a45e2b1 JF |
562 | enum parser_cb_type type, |
563 | const char **error_string, | |
bc47c583 | 564 | icmap_map_t config_map, |
8a45e2b1 | 565 | void *user_data) |
ae229831 | 566 | { |
4e9716ed JF |
567 | int ii; |
568 | long long int val; | |
569 | long long int min_val, max_val; | |
570 | icmap_value_types_t val_type = ICMAP_VALUETYPE_BINARY; | |
6825c1d3 | 571 | unsigned long long int ull; |
8a45e2b1 | 572 | int add_as_string; |
0ac65960 | 573 | char key_name[ICMAP_KEYNAME_MAXLEN + 1]; |
0929dcb6 | 574 | static char formated_err[256]; |
8a45e2b1 JF |
575 | struct main_cp_cb_data *data = (struct main_cp_cb_data *)user_data; |
576 | struct key_value_list_item *kv_item; | |
1f90c31b | 577 | struct qb_list_head *iter, *tmp_iter; |
8a45e2b1 | 578 | int uid, gid; |
ffb759cd JF |
579 | cs_error_t cs_err; |
580 | ||
581 | cs_err = CS_OK; | |
8a45e2b1 | 582 | |
0ac65960 JF |
583 | /* |
584 | * Formally this check is not needed because length is checked by parse_section | |
585 | */ | |
586 | if (strlen(path) >= sizeof(key_name)) { | |
587 | if (snprintf(formated_err, sizeof(formated_err), | |
588 | "Can't store path \"%s\" into key_name", path) >= sizeof(formated_err)) { | |
589 | *error_string = "Can't format path into key_name error message"; | |
590 | } else { | |
591 | *error_string = formated_err; | |
592 | } | |
593 | return (0); | |
594 | } | |
595 | /* | |
596 | * Key_name is used in atoi_error/icmap_set_error, but many of icmap_set* | |
597 | * are using path, so initialize key_name to valid value | |
598 | */ | |
7c825173 | 599 | strncpy(key_name, path, sizeof(key_name) - 1); |
0ac65960 | 600 | |
8a45e2b1 JF |
601 | switch (type) { |
602 | case PARSER_CB_START: | |
603 | memset(data, 0, sizeof(struct main_cp_cb_data)); | |
aab55a00 | 604 | *state = MAIN_CP_CB_DATA_STATE_NORMAL; |
8a45e2b1 JF |
605 | break; |
606 | case PARSER_CB_END: | |
607 | break; | |
608 | case PARSER_CB_ITEM: | |
609 | add_as_string = 1; | |
610 | ||
aab55a00 | 611 | switch (*state) { |
8a45e2b1 JF |
612 | case MAIN_CP_CB_DATA_STATE_NORMAL: |
613 | break; | |
eb3d49ef FDN |
614 | case MAIN_CP_CB_DATA_STATE_PLOAD: |
615 | if ((strcmp(path, "pload.count") == 0) || | |
616 | (strcmp(path, "pload.size") == 0)) { | |
4e9716ed JF |
617 | val_type = ICMAP_VALUETYPE_UINT32; |
618 | if (safe_atoq(value, &val, val_type) != 0) { | |
eb3d49ef FDN |
619 | goto atoi_error; |
620 | } | |
ffb759cd JF |
621 | if ((cs_err = icmap_set_uint32_r(config_map, path, val)) != CS_OK) { |
622 | goto icmap_set_error; | |
623 | } | |
eb3d49ef FDN |
624 | add_as_string = 0; |
625 | } | |
626 | break; | |
8a45e2b1 JF |
627 | case MAIN_CP_CB_DATA_STATE_QUORUM: |
628 | if ((strcmp(path, "quorum.expected_votes") == 0) || | |
629 | (strcmp(path, "quorum.votes") == 0) || | |
10098dba | 630 | (strcmp(path, "quorum.last_man_standing_window") == 0) || |
8a45e2b1 | 631 | (strcmp(path, "quorum.leaving_timeout") == 0)) { |
4e9716ed JF |
632 | val_type = ICMAP_VALUETYPE_UINT32; |
633 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
634 | goto atoi_error; |
635 | } | |
ffb759cd JF |
636 | if ((cs_err = icmap_set_uint32_r(config_map, path, val)) != CS_OK) { |
637 | goto icmap_set_error; | |
638 | } | |
8a45e2b1 JF |
639 | add_as_string = 0; |
640 | } | |
641 | ||
9589611d | 642 | if ((strcmp(path, "quorum.two_node") == 0) || |
ff6a43ed | 643 | (strcmp(path, "quorum.expected_votes_tracking") == 0) || |
2d7a8ab2 | 644 | (strcmp(path, "quorum.allow_downscale") == 0) || |
e8d0af0b | 645 | (strcmp(path, "quorum.wait_for_all") == 0) || |
b41372c6 | 646 | (strcmp(path, "quorum.auto_tie_breaker") == 0) || |
769fc913 | 647 | (strcmp(path, "quorum.last_man_standing") == 0)) { |
4e9716ed JF |
648 | val_type = ICMAP_VALUETYPE_UINT8; |
649 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
650 | goto atoi_error; |
651 | } | |
ffb759cd JF |
652 | if ((cs_err = icmap_set_uint8_r(config_map, path, val)) != CS_OK) { |
653 | goto icmap_set_error; | |
654 | } | |
8a45e2b1 JF |
655 | add_as_string = 0; |
656 | } | |
657 | break; | |
cb5fd775 FDN |
658 | case MAIN_CP_CB_DATA_STATE_QDEVICE: |
659 | if ((strcmp(path, "quorum.device.timeout") == 0) || | |
17488909 | 660 | (strcmp(path, "quorum.device.sync_timeout") == 0) || |
cb5fd775 | 661 | (strcmp(path, "quorum.device.votes") == 0)) { |
4e9716ed JF |
662 | val_type = ICMAP_VALUETYPE_UINT32; |
663 | if (safe_atoq(value, &val, val_type) != 0) { | |
cb5fd775 FDN |
664 | goto atoi_error; |
665 | } | |
ffb759cd JF |
666 | if ((cs_err = icmap_set_uint32_r(config_map, path, val)) != CS_OK) { |
667 | goto icmap_set_error; | |
668 | } | |
cb5fd775 FDN |
669 | add_as_string = 0; |
670 | } | |
86dd11b2 | 671 | if ((strcmp(path, "quorum.device.master_wins") == 0)) { |
4e9716ed JF |
672 | val_type = ICMAP_VALUETYPE_UINT8; |
673 | if (safe_atoq(value, &val, val_type) != 0) { | |
86dd11b2 FDN |
674 | goto atoi_error; |
675 | } | |
ffb759cd JF |
676 | if ((cs_err = icmap_set_uint8_r(config_map, path, val)) != CS_OK) { |
677 | goto icmap_set_error; | |
678 | } | |
86dd11b2 FDN |
679 | add_as_string = 0; |
680 | } | |
ce9c69da | 681 | break; |
8a45e2b1 JF |
682 | case MAIN_CP_CB_DATA_STATE_TOTEM: |
683 | if ((strcmp(path, "totem.version") == 0) || | |
684 | (strcmp(path, "totem.nodeid") == 0) || | |
685 | (strcmp(path, "totem.threads") == 0) || | |
686 | (strcmp(path, "totem.token") == 0) || | |
58176d67 | 687 | (strcmp(path, "totem.token_coefficient") == 0) || |
8a45e2b1 | 688 | (strcmp(path, "totem.token_retransmit") == 0) || |
3f7d2cf6 | 689 | (strcmp(path, "totem.token_warning") == 0) || |
8a45e2b1 JF |
690 | (strcmp(path, "totem.hold") == 0) || |
691 | (strcmp(path, "totem.token_retransmits_before_loss_const") == 0) || | |
692 | (strcmp(path, "totem.join") == 0) || | |
693 | (strcmp(path, "totem.send_join") == 0) || | |
694 | (strcmp(path, "totem.consensus") == 0) || | |
695 | (strcmp(path, "totem.merge") == 0) || | |
696 | (strcmp(path, "totem.downcheck") == 0) || | |
697 | (strcmp(path, "totem.fail_recv_const") == 0) || | |
698 | (strcmp(path, "totem.seqno_unchanged_const") == 0) || | |
699 | (strcmp(path, "totem.rrp_token_expired_timeout") == 0) || | |
700 | (strcmp(path, "totem.rrp_problem_count_timeout") == 0) || | |
701 | (strcmp(path, "totem.rrp_problem_count_threshold") == 0) || | |
702 | (strcmp(path, "totem.rrp_problem_count_mcast_threshold") == 0) || | |
703 | (strcmp(path, "totem.rrp_autorecovery_check_timeout") == 0) || | |
704 | (strcmp(path, "totem.heartbeat_failures_allowed") == 0) || | |
705 | (strcmp(path, "totem.max_network_delay") == 0) || | |
706 | (strcmp(path, "totem.window_size") == 0) || | |
707 | (strcmp(path, "totem.max_messages") == 0) || | |
708 | (strcmp(path, "totem.miss_count_const") == 0) || | |
7cec6a13 | 709 | (strcmp(path, "totem.knet_pmtud_interval") == 0) || |
16f616b6 | 710 | (strcmp(path, "totem.knet_compression_threshold") == 0) || |
8a45e2b1 | 711 | (strcmp(path, "totem.netmtu") == 0)) { |
4e9716ed JF |
712 | val_type = ICMAP_VALUETYPE_UINT32; |
713 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
714 | goto atoi_error; |
715 | } | |
ffb759cd JF |
716 | if ((cs_err = icmap_set_uint32_r(config_map,path, val)) != CS_OK) { |
717 | goto icmap_set_error; | |
718 | } | |
8a45e2b1 JF |
719 | add_as_string = 0; |
720 | } | |
16f616b6 CC |
721 | if (strcmp(path, "totem.knet_compression_level") == 0) { |
722 | val_type = ICMAP_VALUETYPE_INT32; | |
723 | if (safe_atoq(value, &val, val_type) != 0) { | |
724 | goto atoi_error; | |
725 | } | |
ffb759cd JF |
726 | if ((cs_err = icmap_set_int32_r(config_map, path, val)) != CS_OK) { |
727 | goto icmap_set_error; | |
728 | } | |
16f616b6 CC |
729 | add_as_string = 0; |
730 | } | |
6825c1d3 JF |
731 | if (strcmp(path, "totem.config_version") == 0) { |
732 | if (str_to_ull(value, &ull) != 0) { | |
733 | goto atoi_error; | |
734 | } | |
ffb759cd JF |
735 | if ((cs_err = icmap_set_uint64_r(config_map, path, ull)) != CS_OK) { |
736 | goto icmap_set_error; | |
737 | } | |
6825c1d3 JF |
738 | add_as_string = 0; |
739 | } | |
dd588d00 JF |
740 | if (strcmp(path, "totem.ip_version") == 0) { |
741 | if ((strcmp(value, "ipv4") != 0) && | |
a84ade70 JF |
742 | (strcmp(value, "ipv6") != 0) && |
743 | (strcmp(value, "ipv6-4") != 0) && | |
744 | (strcmp(value, "ipv4-6") != 0)) { | |
dd588d00 JF |
745 | *error_string = "Invalid ip_version type"; |
746 | ||
747 | return (0); | |
748 | } | |
749 | } | |
d05636b7 | 750 | if (strcmp(path, "totem.crypto_model") == 0) { |
8cdd2fc4 | 751 | if ((strcmp(value, "nss") != 0) && |
d05636b7 JF |
752 | (strcmp(value, "openssl") != 0)) { |
753 | *error_string = "Invalid crypto model. " | |
754 | "Should be nss or openssl"; | |
8cdd2fc4 JF |
755 | |
756 | return (0); | |
757 | } | |
758 | } | |
ab1675f0 JF |
759 | if (strcmp(path, "totem.crypto_cipher") == 0) { |
760 | if ((strcmp(value, "none") != 0) && | |
20c58715 FDN |
761 | (strcmp(value, "aes256") != 0) && |
762 | (strcmp(value, "aes192") != 0) && | |
d05636b7 JF |
763 | (strcmp(value, "aes128") != 0)) { |
764 | *error_string = "Invalid cipher type. " | |
765 | "Should be none, aes256, aes192 or aes128"; | |
ab1675f0 JF |
766 | |
767 | return (0); | |
768 | } | |
769 | } | |
770 | if (strcmp(path, "totem.crypto_hash") == 0) { | |
771 | if ((strcmp(value, "none") != 0) && | |
e57b5b9e | 772 | (strcmp(value, "md5") != 0) && |
4a2d5036 | 773 | (strcmp(value, "sha1") != 0) && |
4a2d5036 FDN |
774 | (strcmp(value, "sha256") != 0) && |
775 | (strcmp(value, "sha384") != 0) && | |
776 | (strcmp(value, "sha512") != 0)) { | |
d05636b7 JF |
777 | *error_string = "Invalid hash type. " |
778 | "Should be none, md5, sha1, sha256, sha384 or sha512"; | |
ab1675f0 JF |
779 | |
780 | return (0); | |
781 | } | |
782 | } | |
a919908e SD |
783 | break; |
784 | ||
cd4d5fd3 JF |
785 | case MAIN_CP_CB_DATA_STATE_SYSTEM: |
786 | if (strcmp(path, "system.qb_ipc_type") == 0) { | |
3cd4f9a1 JF |
787 | if ((strcmp(value, "native") != 0) && |
788 | (strcmp(value, "shm") != 0) && | |
789 | (strcmp(value, "socket") != 0)) { | |
cd4d5fd3 JF |
790 | *error_string = "Invalid system.qb_ipc_type"; |
791 | ||
792 | return (0); | |
793 | } | |
794 | } | |
795 | if (strcmp(path, "system.sched_rr") == 0) { | |
796 | if ((strcmp(value, "yes") != 0) && | |
797 | (strcmp(value, "no") != 0)) { | |
798 | *error_string = "Invalid system.sched_rr value"; | |
799 | ||
800 | return (0); | |
801 | } | |
802 | } | |
803 | if (strcmp(path, "system.move_to_root_cgroup") == 0) { | |
804 | if ((strcmp(value, "yes") != 0) && | |
805 | (strcmp(value, "no") != 0)) { | |
806 | *error_string = "Invalid system.move_to_root_cgroup"; | |
3cd4f9a1 JF |
807 | |
808 | return (0); | |
809 | } | |
810 | } | |
4f171ea5 DS |
811 | if (strcmp(path, "system.allow_knet_handle_fallback") == 0) { |
812 | if ((strcmp(value, "yes") != 0) && | |
813 | (strcmp(value, "no") != 0)) { | |
814 | *error_string = "Invalid system.allow_knet_handle_fallback"; | |
815 | ||
816 | return (0); | |
817 | } | |
818 | } | |
3cd4f9a1 JF |
819 | break; |
820 | ||
8a45e2b1 | 821 | case MAIN_CP_CB_DATA_STATE_INTERFACE: |
268cde6e | 822 | if (strcmp(path, "totem.interface.linknumber") == 0) { |
4e9716ed JF |
823 | val_type = ICMAP_VALUETYPE_UINT8; |
824 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
825 | goto atoi_error; |
826 | } | |
827 | ||
268cde6e | 828 | data->linknumber = val; |
8a45e2b1 JF |
829 | add_as_string = 0; |
830 | } | |
831 | if (strcmp(path, "totem.interface.bindnetaddr") == 0) { | |
832 | data->bindnetaddr = strdup(value); | |
833 | add_as_string = 0; | |
834 | } | |
835 | if (strcmp(path, "totem.interface.mcastaddr") == 0) { | |
836 | data->mcastaddr = strdup(value); | |
837 | add_as_string = 0; | |
838 | } | |
839 | if (strcmp(path, "totem.interface.broadcast") == 0) { | |
840 | data->broadcast = strdup(value); | |
841 | add_as_string = 0; | |
842 | } | |
843 | if (strcmp(path, "totem.interface.mcastport") == 0) { | |
4e9716ed JF |
844 | val_type = ICMAP_VALUETYPE_UINT16; |
845 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
846 | goto atoi_error; |
847 | } | |
4e9716ed | 848 | data->mcastport = val; |
8a45e2b1 JF |
849 | add_as_string = 0; |
850 | } | |
851 | if (strcmp(path, "totem.interface.ttl") == 0) { | |
4e9716ed JF |
852 | val_type = ICMAP_VALUETYPE_UINT8; |
853 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
854 | goto atoi_error; |
855 | } | |
4e9716ed | 856 | data->ttl = val; |
8a45e2b1 JF |
857 | add_as_string = 0; |
858 | } | |
268cde6e CC |
859 | if (strcmp(path, "totem.interface.knet_link_priority") == 0) { |
860 | val_type = ICMAP_VALUETYPE_UINT8; | |
861 | if (safe_atoq(value, &val, val_type) != 0) { | |
862 | goto atoi_error; | |
863 | } | |
864 | data->knet_link_priority = val; | |
865 | add_as_string = 0; | |
866 | } | |
867 | if (strcmp(path, "totem.interface.knet_ping_interval") == 0) { | |
868 | val_type = ICMAP_VALUETYPE_UINT32; | |
869 | if (safe_atoq(value, &val, val_type) != 0) { | |
870 | goto atoi_error; | |
871 | } | |
872 | data->knet_ping_interval = val; | |
873 | add_as_string = 0; | |
874 | } | |
875 | if (strcmp(path, "totem.interface.knet_ping_timeout") == 0) { | |
876 | val_type = ICMAP_VALUETYPE_UINT32; | |
877 | if (safe_atoq(value, &val, val_type) != 0) { | |
878 | goto atoi_error; | |
879 | } | |
880 | data->knet_ping_timeout = val; | |
881 | add_as_string = 0; | |
882 | } | |
883 | if (strcmp(path, "totem.interface.knet_ping_precision") == 0) { | |
884 | val_type = ICMAP_VALUETYPE_UINT32; | |
885 | if (safe_atoq(value, &val, val_type) != 0) { | |
886 | goto atoi_error; | |
887 | } | |
888 | data->knet_ping_precision = val; | |
889 | add_as_string = 0; | |
890 | } | |
7cec6a13 CC |
891 | if (strcmp(path, "totem.interface.knet_pong_count") == 0) { |
892 | val_type = ICMAP_VALUETYPE_UINT32; | |
893 | if (safe_atoq(value, &val, val_type) != 0) { | |
894 | goto atoi_error; | |
895 | } | |
896 | data->knet_pong_count = val; | |
897 | add_as_string = 0; | |
898 | } | |
c0f1d576 CC |
899 | if (strcmp(path, "totem.interface.knet_transport") == 0) { |
900 | val_type = ICMAP_VALUETYPE_STRING; | |
901 | data->knet_transport = strdup(value); | |
902 | add_as_string = 0; | |
903 | } | |
8a45e2b1 JF |
904 | break; |
905 | case MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS: | |
906 | if (strcmp(key, "subsys") == 0) { | |
907 | data->subsys = strdup(value); | |
908 | if (data->subsys == NULL) { | |
909 | *error_string = "Can't alloc memory"; | |
910 | ||
911 | return (0); | |
912 | } | |
913 | } else { | |
914 | kv_item = malloc(sizeof(*kv_item)); | |
915 | if (kv_item == NULL) { | |
916 | *error_string = "Can't alloc memory"; | |
917 | ||
918 | return (0); | |
919 | } | |
920 | memset(kv_item, 0, sizeof(*kv_item)); | |
921 | ||
922 | kv_item->key = strdup(key); | |
923 | kv_item->value = strdup(value); | |
924 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
925 | free(kv_item); | |
926 | *error_string = "Can't alloc memory"; | |
927 | ||
928 | return (0); | |
929 | } | |
b4c06e52 MJ |
930 | qb_list_init(&kv_item->list); |
931 | qb_list_add(&kv_item->list, &data->logger_subsys_items_head); | |
8a45e2b1 JF |
932 | } |
933 | add_as_string = 0; | |
934 | break; | |
935 | case MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON: | |
936 | if (strcmp(key, "subsys") == 0) { | |
937 | data->subsys = strdup(value); | |
938 | if (data->subsys == NULL) { | |
939 | *error_string = "Can't alloc memory"; | |
940 | ||
941 | return (0); | |
942 | } | |
943 | } else if (strcmp(key, "name") == 0) { | |
944 | data->logging_daemon_name = strdup(value); | |
945 | if (data->logging_daemon_name == NULL) { | |
946 | *error_string = "Can't alloc memory"; | |
947 | ||
948 | return (0); | |
949 | } | |
950 | } else { | |
951 | kv_item = malloc(sizeof(*kv_item)); | |
952 | if (kv_item == NULL) { | |
953 | *error_string = "Can't alloc memory"; | |
954 | ||
955 | return (0); | |
956 | } | |
957 | memset(kv_item, 0, sizeof(*kv_item)); | |
958 | ||
959 | kv_item->key = strdup(key); | |
960 | kv_item->value = strdup(value); | |
961 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
962 | free(kv_item); | |
963 | *error_string = "Can't alloc memory"; | |
964 | ||
965 | return (0); | |
966 | } | |
b4c06e52 MJ |
967 | qb_list_init(&kv_item->list); |
968 | qb_list_add(&kv_item->list, &data->logger_subsys_items_head); | |
8a45e2b1 JF |
969 | } |
970 | add_as_string = 0; | |
971 | break; | |
972 | case MAIN_CP_CB_DATA_STATE_UIDGID: | |
973 | if (strcmp(key, "uid") == 0) { | |
974 | uid = uid_determine(value); | |
975 | if (uid == -1) { | |
976 | *error_string = error_string_response; | |
977 | return (0); | |
978 | } | |
f837f95d | 979 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.config.uid.%u", |
8a45e2b1 | 980 | uid); |
ffb759cd JF |
981 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, 1)) != CS_OK) { |
982 | goto icmap_set_error; | |
983 | } | |
8a45e2b1 JF |
984 | add_as_string = 0; |
985 | } else if (strcmp(key, "gid") == 0) { | |
986 | gid = gid_determine(value); | |
987 | if (gid == -1) { | |
988 | *error_string = error_string_response; | |
989 | return (0); | |
990 | } | |
f837f95d | 991 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.config.gid.%u", |
8a45e2b1 | 992 | gid); |
ffb759cd JF |
993 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, 1)) != CS_OK) { |
994 | goto icmap_set_error; | |
995 | } | |
8a45e2b1 JF |
996 | add_as_string = 0; |
997 | } else { | |
998 | *error_string = "uidgid: Only uid and gid are allowed items"; | |
999 | return (0); | |
1000 | } | |
1001 | break; | |
1002 | case MAIN_CP_CB_DATA_STATE_MEMBER: | |
1003 | if (strcmp(key, "memberaddr") != 0) { | |
1004 | *error_string = "Only memberaddr is allowed in member section"; | |
1005 | ||
1006 | return (0); | |
1007 | } | |
1008 | ||
1009 | kv_item = malloc(sizeof(*kv_item)); | |
1010 | if (kv_item == NULL) { | |
1011 | *error_string = "Can't alloc memory"; | |
1012 | ||
1013 | return (0); | |
1014 | } | |
1015 | memset(kv_item, 0, sizeof(*kv_item)); | |
1016 | ||
1017 | kv_item->key = strdup(key); | |
1018 | kv_item->value = strdup(value); | |
1019 | if (kv_item->key == NULL || kv_item->value == NULL) { | |
1020 | free(kv_item); | |
1021 | *error_string = "Can't alloc memory"; | |
1022 | ||
1023 | return (0); | |
1024 | } | |
b4c06e52 MJ |
1025 | qb_list_init(&kv_item->list); |
1026 | qb_list_add(&kv_item->list, &data->member_items_head); | |
8a45e2b1 JF |
1027 | add_as_string = 0; |
1028 | break; | |
6d0b0b14 JF |
1029 | case MAIN_CP_CB_DATA_STATE_NODELIST: |
1030 | break; | |
1031 | case MAIN_CP_CB_DATA_STATE_NODELIST_NODE: | |
1032 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.%s", data->node_number, key); | |
1033 | if ((strcmp(key, "nodeid") == 0) || | |
1034 | (strcmp(key, "quorum_votes") == 0)) { | |
4e9716ed JF |
1035 | val_type = ICMAP_VALUETYPE_UINT32; |
1036 | if (safe_atoq(value, &val, val_type) != 0) { | |
0929dcb6 JF |
1037 | goto atoi_error; |
1038 | } | |
1039 | ||
ffb759cd JF |
1040 | if ((cs_err = icmap_set_uint32_r(config_map, key_name, val)) != CS_OK) { |
1041 | goto icmap_set_error; | |
1042 | } | |
6d0b0b14 JF |
1043 | add_as_string = 0; |
1044 | } | |
1045 | ||
6d0b0b14 | 1046 | if (add_as_string) { |
ffb759cd JF |
1047 | if ((cs_err = icmap_set_string_r(config_map, key_name, value)) != CS_OK) { |
1048 | goto icmap_set_error; | |
1049 | }; | |
6d0b0b14 JF |
1050 | add_as_string = 0; |
1051 | } | |
1052 | break; | |
39cd6b3d | 1053 | case MAIN_CP_CB_DATA_STATE_RESOURCES: |
1054 | if (strcmp(key, "watchdog_timeout") == 0) { | |
1055 | val_type = ICMAP_VALUETYPE_UINT32; | |
1056 | if (safe_atoq(value, &val, val_type) != 0) { | |
1057 | goto atoi_error; | |
1058 | } | |
ffb759cd JF |
1059 | if ((cs_err = icmap_set_uint32_r(config_map,path, val)) != CS_OK) { |
1060 | goto icmap_set_error; | |
1061 | } | |
39cd6b3d | 1062 | add_as_string = 0; |
1063 | } | |
1064 | break; | |
1065 | case MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM: | |
39cd6b3d | 1066 | case MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM_MEMUSED: |
1067 | if (strcmp(key, "poll_period") == 0) { | |
1068 | if (str_to_ull(value, &ull) != 0) { | |
1069 | goto atoi_error; | |
1070 | } | |
ffb759cd JF |
1071 | if ((cs_err = icmap_set_uint64_r(config_map,path, ull)) != CS_OK) { |
1072 | goto icmap_set_error; | |
1073 | } | |
39cd6b3d | 1074 | add_as_string = 0; |
1075 | } | |
1076 | break; | |
1077 | case MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS: | |
39cd6b3d | 1078 | case MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS_MEMUSED: |
1079 | if (strcmp(key, "poll_period") == 0) { | |
1080 | if (str_to_ull(value, &ull) != 0) { | |
1081 | goto atoi_error; | |
1082 | } | |
ffb759cd JF |
1083 | if ((cs_err = icmap_set_uint64_r(config_map,path, ull)) != CS_OK) { |
1084 | goto icmap_set_error; | |
1085 | } | |
39cd6b3d | 1086 | add_as_string = 0; |
1087 | } | |
1088 | break; | |
ae229831 JF |
1089 | } |
1090 | ||
8a45e2b1 | 1091 | if (add_as_string) { |
ffb759cd JF |
1092 | if ((cs_err = icmap_set_string_r(config_map, path, value)) != CS_OK) { |
1093 | goto icmap_set_error; | |
1094 | } | |
8a45e2b1 JF |
1095 | } |
1096 | break; | |
1097 | case PARSER_CB_SECTION_START: | |
1098 | if (strcmp(path, "totem.interface") == 0) { | |
aab55a00 | 1099 | *state = MAIN_CP_CB_DATA_STATE_INTERFACE; |
268cde6e | 1100 | data->linknumber = 0; |
8a45e2b1 JF |
1101 | data->mcastport = -1; |
1102 | data->ttl = -1; | |
268cde6e CC |
1103 | data->knet_link_priority = -1; |
1104 | data->knet_ping_interval = -1; | |
1105 | data->knet_ping_timeout = -1; | |
1106 | data->knet_ping_precision = -1; | |
7cec6a13 | 1107 | data->knet_pong_count = -1; |
c0f1d576 | 1108 | data->knet_transport = NULL; |
b4c06e52 | 1109 | qb_list_init(&data->member_items_head); |
8a45e2b1 JF |
1110 | }; |
1111 | if (strcmp(path, "totem") == 0) { | |
aab55a00 | 1112 | *state = MAIN_CP_CB_DATA_STATE_TOTEM; |
8a45e2b1 | 1113 | }; |
cd4d5fd3 JF |
1114 | if (strcmp(path, "system") == 0) { |
1115 | *state = MAIN_CP_CB_DATA_STATE_SYSTEM; | |
3cd4f9a1 | 1116 | } |
8a45e2b1 | 1117 | if (strcmp(path, "logging.logger_subsys") == 0) { |
aab55a00 | 1118 | *state = MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS; |
b4c06e52 | 1119 | qb_list_init(&data->logger_subsys_items_head); |
8a45e2b1 JF |
1120 | data->subsys = NULL; |
1121 | } | |
1122 | if (strcmp(path, "logging.logging_daemon") == 0) { | |
aab55a00 | 1123 | *state = MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON; |
b4c06e52 | 1124 | qb_list_init(&data->logger_subsys_items_head); |
8a45e2b1 JF |
1125 | data->subsys = NULL; |
1126 | data->logging_daemon_name = NULL; | |
1127 | } | |
1128 | if (strcmp(path, "uidgid") == 0) { | |
aab55a00 | 1129 | *state = MAIN_CP_CB_DATA_STATE_UIDGID; |
ae229831 | 1130 | } |
8a45e2b1 | 1131 | if (strcmp(path, "totem.interface.member") == 0) { |
aab55a00 | 1132 | *state = MAIN_CP_CB_DATA_STATE_MEMBER; |
8a45e2b1 JF |
1133 | } |
1134 | if (strcmp(path, "quorum") == 0) { | |
aab55a00 | 1135 | *state = MAIN_CP_CB_DATA_STATE_QUORUM; |
8a45e2b1 | 1136 | } |
cb5fd775 | 1137 | if (strcmp(path, "quorum.device") == 0) { |
aab55a00 | 1138 | *state = MAIN_CP_CB_DATA_STATE_QDEVICE; |
cb5fd775 | 1139 | } |
6d0b0b14 | 1140 | if (strcmp(path, "nodelist") == 0) { |
aab55a00 | 1141 | *state = MAIN_CP_CB_DATA_STATE_NODELIST; |
6d0b0b14 JF |
1142 | data->node_number = 0; |
1143 | } | |
1144 | if (strcmp(path, "nodelist.node") == 0) { | |
aab55a00 | 1145 | *state = MAIN_CP_CB_DATA_STATE_NODELIST_NODE; |
6d0b0b14 | 1146 | } |
39cd6b3d | 1147 | if (strcmp(path, "resources") == 0) { |
1148 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES; | |
1149 | } | |
1150 | if (strcmp(path, "resources.system") == 0) { | |
1151 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM; | |
1152 | } | |
1153 | if (strcmp(path, "resources.system.memory_used") == 0) { | |
1154 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM_MEMUSED; | |
1155 | } | |
1156 | if (strcmp(path, "resources.process") == 0) { | |
1157 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS; | |
1158 | } | |
1159 | if (strcmp(path, "resources.process.memory_used") == 0) { | |
1160 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS_MEMUSED; | |
1161 | } | |
8a45e2b1 JF |
1162 | break; |
1163 | case PARSER_CB_SECTION_END: | |
aab55a00 | 1164 | switch (*state) { |
8a45e2b1 JF |
1165 | case MAIN_CP_CB_DATA_STATE_INTERFACE: |
1166 | /* | |
1167 | * Create new interface section | |
1168 | */ | |
1169 | if (data->bindnetaddr != NULL) { | |
1170 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", | |
268cde6e | 1171 | data->linknumber); |
ffb759cd | 1172 | cs_err = icmap_set_string_r(config_map, key_name, data->bindnetaddr); |
8a45e2b1 JF |
1173 | |
1174 | free(data->bindnetaddr); | |
1175 | data->bindnetaddr = NULL; | |
ffb759cd JF |
1176 | |
1177 | if (cs_err != CS_OK) { | |
1178 | goto icmap_set_error; | |
1179 | } | |
8a45e2b1 JF |
1180 | } |
1181 | ||
1182 | if (data->mcastaddr != NULL) { | |
1183 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", | |
268cde6e | 1184 | data->linknumber); |
ffb759cd | 1185 | cs_err = icmap_set_string_r(config_map, key_name, data->mcastaddr); |
8a45e2b1 JF |
1186 | |
1187 | free(data->mcastaddr); | |
1188 | data->mcastaddr = NULL; | |
ffb759cd JF |
1189 | |
1190 | if (cs_err != CS_OK) { | |
1191 | goto icmap_set_error; | |
1192 | } | |
8a45e2b1 JF |
1193 | } |
1194 | ||
1195 | if (data->broadcast != NULL) { | |
1196 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", | |
268cde6e | 1197 | data->linknumber); |
ffb759cd | 1198 | cs_err = icmap_set_string_r(config_map, key_name, data->broadcast); |
8a45e2b1 JF |
1199 | |
1200 | free(data->broadcast); | |
1201 | data->broadcast = NULL; | |
ffb759cd JF |
1202 | |
1203 | if (cs_err != CS_OK) { | |
1204 | goto icmap_set_error; | |
1205 | } | |
8a45e2b1 JF |
1206 | } |
1207 | ||
1208 | if (data->mcastport > -1) { | |
1209 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", | |
268cde6e | 1210 | data->linknumber); |
ffb759cd JF |
1211 | if ((cs_err = icmap_set_uint16_r(config_map, key_name, |
1212 | data->mcastport)) != CS_OK) { | |
1213 | goto icmap_set_error; | |
1214 | } | |
8a45e2b1 JF |
1215 | } |
1216 | ||
1217 | if (data->ttl > -1) { | |
1218 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", | |
268cde6e | 1219 | data->linknumber); |
ffb759cd JF |
1220 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, data->ttl)) != CS_OK) { |
1221 | goto icmap_set_error; | |
1222 | } | |
8a45e2b1 | 1223 | } |
268cde6e CC |
1224 | if (data->knet_link_priority > -1) { |
1225 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_link_priority", | |
1226 | data->linknumber); | |
ffb759cd JF |
1227 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, |
1228 | data->knet_link_priority)) != CS_OK) { | |
1229 | goto icmap_set_error; | |
1230 | } | |
268cde6e CC |
1231 | } |
1232 | if (data->knet_ping_interval > -1) { | |
1233 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_interval", | |
1234 | data->linknumber); | |
ffb759cd JF |
1235 | if ((cs_err = icmap_set_uint32_r(config_map, key_name, |
1236 | data->knet_ping_interval)) != CS_OK) { | |
1237 | goto icmap_set_error; | |
1238 | } | |
268cde6e CC |
1239 | } |
1240 | if (data->knet_ping_timeout > -1) { | |
1241 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_timeout", | |
1242 | data->linknumber); | |
ffb759cd JF |
1243 | if ((cs_err = icmap_set_uint32_r(config_map, key_name, |
1244 | data->knet_ping_timeout)) != CS_OK) { | |
1245 | goto icmap_set_error; | |
1246 | } | |
268cde6e CC |
1247 | } |
1248 | if (data->knet_ping_precision > -1) { | |
1249 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_precision", | |
1250 | data->linknumber); | |
ffb759cd JF |
1251 | if ((cs_err = icmap_set_uint32_r(config_map, key_name, |
1252 | data->knet_ping_precision)) != CS_OK) { | |
1253 | goto icmap_set_error; | |
1254 | } | |
268cde6e | 1255 | } |
7cec6a13 CC |
1256 | if (data->knet_pong_count > -1) { |
1257 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_pong_count", | |
1258 | data->linknumber); | |
ffb759cd JF |
1259 | if ((cs_err = icmap_set_uint32_r(config_map, key_name, |
1260 | data->knet_pong_count)) != CS_OK) { | |
1261 | goto icmap_set_error; | |
1262 | } | |
7cec6a13 | 1263 | } |
c0f1d576 CC |
1264 | if (data->knet_transport) { |
1265 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_transport", | |
1266 | data->linknumber); | |
ffb759cd | 1267 | cs_err = icmap_set_string_r(config_map, key_name, data->knet_transport); |
c0f1d576 | 1268 | free(data->knet_transport); |
ffb759cd JF |
1269 | |
1270 | if (cs_err != CS_OK) { | |
1271 | goto icmap_set_error; | |
1272 | } | |
c0f1d576 | 1273 | } |
8a45e2b1 | 1274 | |
4e9716ed | 1275 | ii = 0; |
b4c06e52 | 1276 | |
1f90c31b | 1277 | qb_list_for_each_safe(iter, tmp_iter, &(data->member_items_head)) { |
b4c06e52 | 1278 | kv_item = qb_list_entry(iter, struct key_value_list_item, list); |
8a45e2b1 JF |
1279 | |
1280 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.%u", | |
268cde6e | 1281 | data->linknumber, ii); |
ffb759cd | 1282 | cs_err = icmap_set_string_r(config_map, key_name, kv_item->value); |
8a45e2b1 | 1283 | |
8a45e2b1 JF |
1284 | free(kv_item->value); |
1285 | free(kv_item->key); | |
1286 | free(kv_item); | |
4e9716ed | 1287 | ii++; |
ffb759cd JF |
1288 | |
1289 | if (cs_err != CS_OK) { | |
1290 | goto icmap_set_error; | |
1291 | } | |
8a45e2b1 JF |
1292 | } |
1293 | ||
3cd4f9a1 | 1294 | break; |
8a45e2b1 JF |
1295 | case MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS: |
1296 | if (data->subsys == NULL) { | |
1297 | *error_string = "No subsys key in logger_subsys directive"; | |
1298 | ||
1299 | return (0); | |
1300 | } | |
1301 | ||
1f90c31b | 1302 | qb_list_for_each_safe(iter, tmp_iter, &(data->logger_subsys_items_head)) { |
b4c06e52 | 1303 | kv_item = qb_list_entry(iter, struct key_value_list_item, list); |
8a45e2b1 JF |
1304 | |
1305 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.%s", | |
aab55a00 | 1306 | data->subsys, kv_item->key); |
ffb759cd | 1307 | cs_err = icmap_set_string_r(config_map, key_name, kv_item->value); |
8a45e2b1 JF |
1308 | |
1309 | free(kv_item->value); | |
1310 | free(kv_item->key); | |
1311 | free(kv_item); | |
ffb759cd JF |
1312 | |
1313 | if (cs_err != CS_OK) { | |
1314 | goto icmap_set_error; | |
1315 | } | |
8a45e2b1 JF |
1316 | } |
1317 | ||
1318 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.subsys", | |
1319 | data->subsys); | |
ffb759cd | 1320 | cs_err = icmap_set_string_r(config_map, key_name, data->subsys); |
8a45e2b1 JF |
1321 | |
1322 | free(data->subsys); | |
1323 | ||
ffb759cd JF |
1324 | if (cs_err != CS_OK) { |
1325 | goto icmap_set_error; | |
1326 | } | |
8a45e2b1 JF |
1327 | break; |
1328 | case MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON: | |
1329 | if (data->logging_daemon_name == NULL) { | |
1330 | *error_string = "No name key in logging_daemon directive"; | |
1331 | ||
1332 | return (0); | |
1333 | } | |
1334 | ||
1f90c31b | 1335 | qb_list_for_each_safe(iter, tmp_iter, &(data->logger_subsys_items_head)) { |
b4c06e52 | 1336 | kv_item = qb_list_entry(iter, struct key_value_list_item, list); |
8a45e2b1 JF |
1337 | |
1338 | if (data->subsys == NULL) { | |
1339 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
1340 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
1341 | "logging.%s", | |
1342 | kv_item->key); | |
1343 | } else { | |
1344 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
1345 | "logging.logging_daemon.%s.%s", | |
1346 | data->logging_daemon_name, kv_item->key); | |
1347 | } | |
1348 | } else { | |
1349 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
1350 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
1351 | "logging.logger_subsys.%s.%s", | |
1352 | data->subsys, | |
1353 | kv_item->key); | |
1354 | } else { | |
1355 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, | |
1356 | "logging.logging_daemon.%s.%s.%s", | |
1357 | data->logging_daemon_name, data->subsys, | |
1358 | kv_item->key); | |
1359 | } | |
1360 | } | |
ffb759cd | 1361 | cs_err = icmap_set_string_r(config_map, key_name, kv_item->value); |
8a45e2b1 | 1362 | |
8a45e2b1 JF |
1363 | free(kv_item->value); |
1364 | free(kv_item->key); | |
1365 | free(kv_item); | |
ffb759cd JF |
1366 | |
1367 | if (cs_err != CS_OK) { | |
1368 | goto icmap_set_error; | |
1369 | } | |
8a45e2b1 JF |
1370 | } |
1371 | ||
1372 | if (data->subsys == NULL) { | |
1373 | if (strcmp(data->logging_daemon_name, "corosync") != 0) { | |
1374 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.name", | |
1375 | data->logging_daemon_name); | |
ffb759cd | 1376 | cs_err = icmap_set_string_r(config_map, key_name, data->logging_daemon_name); |
8a45e2b1 JF |
1377 | } |
1378 | } else { | |
1379 | if (strcmp(data->logging_daemon_name, "corosync") == 0) { | |
1380 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s.subsys", | |
1381 | data->subsys); | |
ffb759cd | 1382 | cs_err = icmap_set_string_r(config_map, key_name, data->subsys); |
8a45e2b1 JF |
1383 | |
1384 | } else { | |
1385 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.%s.subsys", | |
1386 | data->logging_daemon_name, data->subsys); | |
ffb759cd JF |
1387 | cs_err = icmap_set_string_r(config_map, key_name, data->subsys); |
1388 | ||
1389 | if (cs_err != CS_OK) { | |
1390 | free(data->subsys); | |
1391 | free(data->logging_daemon_name); | |
1392 | ||
1393 | goto icmap_set_error; | |
1394 | } | |
8a45e2b1 JF |
1395 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "logging.logging_daemon.%s.%s.name", |
1396 | data->logging_daemon_name, data->subsys); | |
ffb759cd | 1397 | cs_err = icmap_set_string_r(config_map, key_name, data->logging_daemon_name); |
8a45e2b1 JF |
1398 | } |
1399 | } | |
1400 | ||
1401 | free(data->subsys); | |
1402 | free(data->logging_daemon_name); | |
1403 | ||
ffb759cd JF |
1404 | if (cs_err != CS_OK) { |
1405 | goto icmap_set_error; | |
1406 | } | |
6d0b0b14 JF |
1407 | break; |
1408 | case MAIN_CP_CB_DATA_STATE_NODELIST_NODE: | |
6d0b0b14 | 1409 | data->node_number++; |
aab55a00 CC |
1410 | break; |
1411 | case MAIN_CP_CB_DATA_STATE_NORMAL: | |
1412 | case MAIN_CP_CB_DATA_STATE_PLOAD: | |
1413 | case MAIN_CP_CB_DATA_STATE_UIDGID: | |
1414 | case MAIN_CP_CB_DATA_STATE_MEMBER: | |
1415 | case MAIN_CP_CB_DATA_STATE_QUORUM: | |
1416 | case MAIN_CP_CB_DATA_STATE_QDEVICE: | |
1417 | case MAIN_CP_CB_DATA_STATE_NODELIST: | |
1418 | case MAIN_CP_CB_DATA_STATE_TOTEM: | |
cd4d5fd3 | 1419 | case MAIN_CP_CB_DATA_STATE_SYSTEM: |
6d0b0b14 | 1420 | break; |
39cd6b3d | 1421 | case MAIN_CP_CB_DATA_STATE_RESOURCES: |
1422 | *state = MAIN_CP_CB_DATA_STATE_NORMAL; | |
1423 | break; | |
1424 | case MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM: | |
1425 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES; | |
1426 | break; | |
1427 | case MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM_MEMUSED: | |
1428 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM; | |
1429 | break; | |
1430 | case MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS: | |
1431 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES; | |
1432 | break; | |
1433 | case MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS_MEMUSED: | |
1434 | *state = MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS; | |
1435 | break; | |
8a45e2b1 JF |
1436 | } |
1437 | break; | |
ae229831 JF |
1438 | } |
1439 | ||
8a45e2b1 | 1440 | return (1); |
0929dcb6 JF |
1441 | |
1442 | atoi_error: | |
4e9716ed JF |
1443 | min_val = max_val = 0; |
1444 | /* | |
1445 | * This is really assert, because developer ether doesn't set val_type correctly or | |
1446 | * we've got here after some nasty memory overwrite | |
1447 | */ | |
1448 | assert(safe_atoq_range(val_type, &min_val, &max_val) == 0); | |
1449 | ||
e3989c2b | 1450 | if (snprintf(formated_err, sizeof(formated_err), |
4e9716ed | 1451 | "Value of key \"%s\" is expected to be integer in range (%lld..%lld), but \"%s\" was given", |
e3989c2b JF |
1452 | key_name, min_val, max_val, value) >= sizeof(formated_err)) { |
1453 | *error_string = "Can't format parser error message"; | |
1454 | } else { | |
1455 | *error_string = formated_err; | |
1456 | } | |
0929dcb6 | 1457 | |
ffb759cd JF |
1458 | return (0); |
1459 | ||
1460 | icmap_set_error: | |
1461 | if (snprintf(formated_err, sizeof(formated_err), | |
1462 | "Can't store key \"%s\" into icmap, returned error is %s", | |
0ac65960 | 1463 | key_name, cs_strerror(cs_err)) >= sizeof(formated_err)) { |
ffb759cd JF |
1464 | *error_string = "Can't format parser error message"; |
1465 | } else { | |
1466 | *error_string = formated_err; | |
1467 | } | |
1468 | ||
0929dcb6 | 1469 | return (0); |
8a45e2b1 JF |
1470 | } |
1471 | ||
1472 | static int uidgid_config_parser_cb(const char *path, | |
1473 | char *key, | |
1474 | char *value, | |
aab55a00 | 1475 | enum main_cp_cb_data_state *state, |
8a45e2b1 JF |
1476 | enum parser_cb_type type, |
1477 | const char **error_string, | |
bc47c583 | 1478 | icmap_map_t config_map, |
8a45e2b1 JF |
1479 | void *user_data) |
1480 | { | |
1481 | char key_name[ICMAP_KEYNAME_MAXLEN]; | |
1482 | int uid, gid; | |
ffb759cd JF |
1483 | static char formated_err[256]; |
1484 | cs_error_t cs_err; | |
1485 | ||
8a45e2b1 JF |
1486 | switch (type) { |
1487 | case PARSER_CB_START: | |
1488 | break; | |
1489 | case PARSER_CB_END: | |
1490 | break; | |
1491 | case PARSER_CB_ITEM: | |
1492 | if (strcmp(path, "uidgid.uid") == 0) { | |
1493 | uid = uid_determine(value); | |
1494 | if (uid == -1) { | |
1495 | *error_string = error_string_response; | |
1496 | return (0); | |
1497 | } | |
f837f95d | 1498 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.config.uid.%u", |
8a45e2b1 | 1499 | uid); |
ffb759cd JF |
1500 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, 1)) != CS_OK) { |
1501 | goto icmap_set_error; | |
1502 | } | |
92ead610 | 1503 | } else if (strcmp(path, "uidgid.gid") == 0) { |
8a45e2b1 JF |
1504 | gid = gid_determine(value); |
1505 | if (gid == -1) { | |
1506 | *error_string = error_string_response; | |
1507 | return (0); | |
1508 | } | |
f837f95d | 1509 | snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "uidgid.config.gid.%u", |
8a45e2b1 | 1510 | gid); |
ffb759cd JF |
1511 | if ((cs_err = icmap_set_uint8_r(config_map, key_name, 1)) != CS_OK) { |
1512 | goto icmap_set_error; | |
1513 | } | |
8a45e2b1 | 1514 | } else { |
ae229831 | 1515 | *error_string = "uidgid: Only uid and gid are allowed items"; |
8a45e2b1 | 1516 | return (0); |
ae229831 | 1517 | } |
8a45e2b1 JF |
1518 | break; |
1519 | case PARSER_CB_SECTION_START: | |
1520 | if (strcmp(path, "uidgid") != 0) { | |
3b8365e8 | 1521 | *error_string = "uidgid: Can't add subsection different than uidgid"; |
8a45e2b1 JF |
1522 | return (0); |
1523 | }; | |
1524 | break; | |
1525 | case PARSER_CB_SECTION_END: | |
1526 | break; | |
ae229831 | 1527 | } |
2f552719 | 1528 | |
8a45e2b1 | 1529 | return (1); |
ffb759cd JF |
1530 | |
1531 | icmap_set_error: | |
1532 | if (snprintf(formated_err, sizeof(formated_err), | |
1533 | "Can't store key \"%s\" into icmap, returned error is %s", | |
0ac65960 | 1534 | key_name, cs_strerror(cs_err)) >= sizeof(formated_err)) { |
ffb759cd JF |
1535 | *error_string = "Can't format parser error message"; |
1536 | } else { | |
1537 | *error_string = formated_err; | |
1538 | } | |
1539 | ||
1540 | return (0); | |
ae229831 JF |
1541 | } |
1542 | ||
8a45e2b1 | 1543 | static int read_uidgid_files_into_icmap( |
bc47c583 CC |
1544 | const char **error_string, |
1545 | icmap_map_t config_map) | |
ae229831 JF |
1546 | { |
1547 | FILE *fp; | |
2f9aaefb | 1548 | char *dirname_res; |
ae229831 JF |
1549 | DIR *dp; |
1550 | struct dirent *dirent; | |
1bd8aba6 | 1551 | char filename[PATH_MAX + FILENAME_MAX + 1]; |
2f9aaefb | 1552 | char uidgid_dirname[PATH_MAX + FILENAME_MAX + 1]; |
ae229831 | 1553 | int res = 0; |
1e0d40cd | 1554 | struct stat stat_buf; |
aab55a00 | 1555 | enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL; |
8a45e2b1 | 1556 | char key_name[ICMAP_KEYNAME_MAXLEN]; |
f6262e57 | 1557 | int line_no; |
ae229831 | 1558 | |
2f9aaefb JF |
1559 | /* |
1560 | * Build uidgid directory based on corosync.conf file location | |
1561 | */ | |
1562 | res = snprintf(filename, sizeof(filename), "%s", | |
1563 | corosync_get_config_file()); | |
1564 | if (res >= sizeof(filename)) { | |
1565 | *error_string = "uidgid.d path too long"; | |
1566 | ||
1567 | return (-1); | |
1568 | } | |
1569 | ||
1570 | dirname_res = dirname(filename); | |
1571 | ||
1572 | res = snprintf(uidgid_dirname, sizeof(uidgid_dirname), "%s/%s", | |
1573 | dirname_res, "uidgid.d"); | |
1574 | if (res >= sizeof(uidgid_dirname)) { | |
1575 | *error_string = "uidgid.d path too long"; | |
1576 | ||
1577 | return (-1); | |
1578 | } | |
1579 | ||
1580 | dp = opendir (uidgid_dirname); | |
ae229831 JF |
1581 | |
1582 | if (dp == NULL) | |
1583 | return 0; | |
1584 | ||
c83e6c7e BL |
1585 | for (dirent = readdir(dp); |
1586 | dirent != NULL; | |
1587 | dirent = readdir(dp)) { | |
2290913d | 1588 | |
2f9aaefb JF |
1589 | res = snprintf(filename, sizeof (filename), "%s/%s", uidgid_dirname, dirent->d_name); |
1590 | if (res >= sizeof(filename)) { | |
1591 | res = -1; | |
1592 | *error_string = "uidgid.d dirname path too long"; | |
1593 | ||
1594 | goto error_exit; | |
1595 | } | |
966f461b JF |
1596 | res = stat (filename, &stat_buf); |
1597 | if (res == 0 && S_ISREG(stat_buf.st_mode)) { | |
ae229831 JF |
1598 | |
1599 | fp = fopen (filename, "r"); | |
1600 | if (fp == NULL) continue; | |
1601 | ||
8a45e2b1 JF |
1602 | key_name[0] = 0; |
1603 | ||
f6262e57 JF |
1604 | line_no = 0; |
1605 | res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state, | |
1606 | uidgid_config_parser_cb, config_map, NULL); | |
ae229831 JF |
1607 | |
1608 | fclose (fp); | |
1609 | ||
1610 | if (res != 0) { | |
1611 | goto error_exit; | |
1612 | } | |
1613 | } | |
1614 | } | |
1615 | ||
1616 | error_exit: | |
1617 | closedir(dp); | |
1618 | ||
1619 | return res; | |
1620 | } | |
2f552719 | 1621 | |
8a45e2b1 JF |
1622 | /* Read config file and load into icmap */ |
1623 | static int read_config_file_into_icmap( | |
bc47c583 CC |
1624 | const char **error_string, |
1625 | icmap_map_t config_map) | |
2f552719 SD |
1626 | { |
1627 | FILE *fp; | |
23c64c64 | 1628 | const char *filename; |
2f552719 SD |
1629 | char *error_reason = error_string_response; |
1630 | int res; | |
8a45e2b1 JF |
1631 | char key_name[ICMAP_KEYNAME_MAXLEN]; |
1632 | struct main_cp_cb_data data; | |
aab55a00 | 1633 | enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL; |
f6262e57 | 1634 | int line_no; |
2f552719 | 1635 | |
2f9aaefb | 1636 | filename = corosync_get_config_file(); |
2f552719 SD |
1637 | |
1638 | fp = fopen (filename, "r"); | |
23c64c64 | 1639 | if (fp == NULL) { |
20f3331d | 1640 | char error_str[100]; |
37e17e7a | 1641 | const char *error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str)); |
870046d0 | 1642 | snprintf (error_reason, sizeof(error_string_response), |
ba24bef8 | 1643 | "Can't read file %s: %s", |
00434a4f | 1644 | filename, error_ptr); |
2f552719 SD |
1645 | *error_string = error_reason; |
1646 | return -1; | |
1647 | } | |
1648 | ||
8a45e2b1 JF |
1649 | key_name[0] = 0; |
1650 | ||
f6262e57 JF |
1651 | line_no = 0; |
1652 | res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state, | |
1653 | main_config_parser_cb, config_map, &data); | |
2f552719 SD |
1654 | |
1655 | fclose(fp); | |
1656 | ||
ae229831 | 1657 | if (res == 0) { |
bc47c583 | 1658 | res = read_uidgid_files_into_icmap(error_string, config_map); |
ae229831 JF |
1659 | } |
1660 | ||
94b64352 JF |
1661 | if (res == 0) { |
1662 | snprintf (error_reason, sizeof(error_string_response), | |
3131601c | 1663 | "Successfully read main configuration file '%s'.", filename); |
94b64352 JF |
1664 | *error_string = error_reason; |
1665 | } | |
2f552719 SD |
1666 | |
1667 | return res; | |
1668 | } |