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