40#include <sys/socket.h>
43#include <netinet/in.h>
60#define LOGSYS_UTILS_ONLY 1
102 const char **error_string,
136static int read_config_file_into_icmap(
137 const char **error_string,
icmap_map_t config_map);
138static char error_string_response[512];
140static int uid_determine (
const char *req_user)
143 struct passwd passwd;
144 struct passwd* pwdptr = &passwd;
145 struct passwd* temp_pwd_pt;
151 id = strtol(req_user, &ep, 10);
152 if (*req_user !=
'\0' && *ep ==
'\0' &&
id >= 0 &&
id <= UINT_MAX) {
156 pwdlinelen = sysconf (_SC_GETPW_R_SIZE_MAX);
158 if (pwdlinelen == -1) {
162 pwdbuffer = malloc (pwdlinelen);
164 while ((rc = getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) == ERANGE) {
168 if (pwdlinelen <= 32678) {
169 n = realloc (pwdbuffer, pwdlinelen);
178 sprintf (error_string_response,
"getpwnam_r(): %s", strerror(rc));
181 if (temp_pwd_pt == NULL) {
183 sprintf (error_string_response,
184 "The '%s' user is not found in /etc/passwd, please read the documentation.",
188 pw_uid = passwd.pw_uid;
194static int gid_determine (
const char *req_group)
196 int corosync_gid = 0;
198 struct group * grpptr = &group;
199 struct group * temp_grp_pt;
205 id = strtol(req_group, &ep, 10);
206 if (*req_group !=
'\0' && *ep ==
'\0' &&
id >= 0 &&
id <= UINT_MAX) {
210 grplinelen = sysconf (_SC_GETGR_R_SIZE_MAX);
212 if (grplinelen == -1) {
216 grpbuffer = malloc (grplinelen);
218 while ((rc = getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) == ERANGE) {
222 if (grplinelen <= 32678) {
223 n = realloc (grpbuffer, grplinelen);
232 sprintf (error_string_response,
"getgrnam_r(): %s", strerror(rc));
235 if (temp_grp_pt == NULL) {
237 sprintf (error_string_response,
238 "The '%s' group is not found in /etc/group, please read the documentation.",
242 corosync_gid = group.gr_gid;
247static char *strchr_rs (
const char *haystack,
int byte)
249 const char *end_address = strchr (haystack,
byte);
253 while (*end_address ==
' ' || *end_address ==
'\t' || (
unsigned char)*end_address == 0xA0)
257 return ((
char *) end_address);
262 if (read_config_file_into_icmap(error_string, config_map)) {
269static char *remove_whitespace(
char *
string,
int remove_colon_and_brace)
278 while (*start ==
' ' || *start ==
'\t' || (
unsigned char)*start == 0xA0)
281 end = start+(strlen(start))-1;
282 while ((*end ==
' ' || *end ==
'\t' || (
unsigned char)*end == 0xA0 || (remove_colon_and_brace && (*end ==
':' || *end ==
'{'))) && end > start)
292static int parse_section(FILE *fp,
296 const char **error_string,
308 static char formated_err[384];
309 const char *tmp_error_string;
311 if (strcmp(path,
"") == 0) {
315 tmp_error_string = NULL;
317 while (fgets (line,
sizeof (line), fp)) {
320 if (strlen(line) > 0) {
325 if ((line[strlen(line) - 1] !=
'\n') && !feof(fp)) {
326 tmp_error_string =
"Line too long";
330 if (line[strlen(line) - 1] ==
'\n')
331 line[strlen(line) - 1] =
'\0';
332 if (strlen (line) > 0 && line[strlen(line) - 1] ==
'\r')
333 line[strlen(line) - 1] =
'\0';
338 for (i = strlen (line) - 1; i > -1; i--) {
339 if (line[i] ==
'\t' || line[i] ==
' ' || (
unsigned char)line[i] == 0xA0) {
347 for (i = 0; i < strlen (line); i++) {
348 if (line[i] !=
'\t' && line[i] !=
' ' && (
unsigned char)line[i] != 0xA0) {
363 if ((loc = strchr_rs (line,
'{'))) {
369 section = remove_whitespace(line, 1);
370 after_section = remove_whitespace(loc, 0);
372 if (strcmp(section,
"") == 0) {
373 tmp_error_string =
"Missing section name before opening bracket '{'";
377 if (strcmp(after_section,
"") != 0) {
378 tmp_error_string =
"Extra characters after opening bracket '{'";
383 tmp_error_string =
"Start of section makes total cmap path too long";
386 strcpy(new_keyname, path);
387 if (strcmp(path,
"") != 0) {
388 strcat(new_keyname,
".");
390 strcat(new_keyname, section);
395 &tmp_error_string, config_map,
user_data)) {
399 if (parse_section(fp, fname, line_no, new_keyname, error_string, depth + 1, newstate,
407 if ((loc = strchr_rs (line,
':'))) {
412 key = remove_whitespace(line, 1);
413 value = remove_whitespace(loc, 0);
415 if (strlen(key) == 0) {
416 tmp_error_string =
"Key name can't be empty";
421 tmp_error_string =
"New key makes total cmap path too long";
424 strcpy(new_keyname, path);
425 if (strcmp(path,
"") != 0) {
426 strcat(new_keyname,
".");
428 strcat(new_keyname, key);
438 if (strchr_rs (line,
'}')) {
440 trimmed_line = remove_whitespace(line, 0);
442 if (strcmp(trimmed_line,
"}") != 0) {
443 tmp_error_string =
"Extra characters before or after closing bracket '}'";
448 tmp_error_string =
"Unexpected closing brace";
464 tmp_error_string =
"Line is not opening or closing section or key value";
468 if (strcmp(path,
"") != 0) {
469 tmp_error_string =
"Missing closing brace";
473 if (strcmp(path,
"") == 0) {
481 if (snprintf(formated_err,
sizeof(formated_err),
"parser error: %s:%u: %s", fname, *line_no,
482 tmp_error_string) >=
sizeof(formated_err)) {
483 *error_string =
"Can't format parser error message";
485 *error_string = formated_err;
493static int safe_atoq_range(
icmap_value_types_t value_type,
long long int *min_val,
long long int *max_val)
495 switch (value_type) {
517 long long int min_val, max_val;
522 val = strtoll(str, &endptr, 10);
523 if (errno == ERANGE) {
531 if (*endptr !=
'\0') {
535 if (safe_atoq_range(target_type, &min_val, &max_val) != 0) {
539 if (val < min_val || val > max_val) {
547static int str_to_ull(
const char *str,
unsigned long long int *res)
549 unsigned long long int val;
554 val = strtoull(str, &endptr, 10);
555 if (errno == ERANGE) {
563 if (*endptr !=
'\0') {
571static int get_dscp_value(
char *str,
int *dscp) {
572 struct dscp_name {
const char *name;
int dscp;} names[] = {
573 {
"cs0", 0}, {
"cs1", 8}, {
"cs2", 16}, {
"cs3", 24},
574 {
"cs4", 32}, {
"cs5", 40}, {
"cs6", 48}, {
"cs7", 56},
575 {
"af11", 10}, {
"af12", 12}, {
"af13", 14}, {
"af21", 18},
576 {
"af22", 20}, {
"af23", 22}, {
"af31", 26}, {
"af32", 28},
577 {
"af33", 30}, {
"af41", 34}, {
"af42", 36}, {
"af43", 38},
578 {
"ef", 46}, {NULL, 0}
588 for (n = names; n->name; n++) {
589 if (strcmp(str, n->name) == 0) {
597 val = strtol(str, &end, 0);
598 if (errno == 0 && *end ==
'\0' && val >= 0 && val <= 63) {
606static int handle_crypto_model(
const char *val,
const char **error_string)
610 "Invalid crypto model. Should be ", error_string) == 1) {
617static int handle_crypto_cipher(
const char *val,
const char **error_string)
621 "Invalid cipher type. Should be ", error_string) == 1) {
628static int handle_crypto_hash(
const char *val,
const char **error_string)
632 "Invalid hash type. Should be ", error_string) == 1) {
639static int handle_compress_model(
const char *val,
const char **error_string)
643 "Invalid compression model. Should be ", error_string) == 1) {
650static int main_config_parser_cb(
const char *path,
655 const char **error_string,
661 long long int min_val, max_val;
663 unsigned long long int ull;
666 static char formated_err[256];
669 struct qb_list_head *iter, *tmp_iter;
672 const char *path_prefix;
679 if (strlen(path) >=
sizeof(key_name)) {
680 *error_string =
"main_config_parser_cb path is longer than key_name";
688 strncpy(key_name, path,
sizeof(key_name) - 1);
707 qb_list_del(&kv_item->
list);
709 free(kv_item->
value);
719 qb_list_del(&kv_item->
list);
721 free(kv_item->
value);
733 if ((strcmp(path,
"pload.count") == 0) ||
734 (strcmp(path,
"pload.size") == 0)) {
736 if (safe_atoq(
value, &val, val_type) != 0) {
737 goto safe_atoq_error;
740 goto icmap_set_error;
746 if ((strcmp(path,
"quorum.expected_votes") == 0) ||
747 (strcmp(path,
"quorum.votes") == 0) ||
748 (strcmp(path,
"quorum.last_man_standing_window") == 0) ||
749 (strcmp(path,
"quorum.leaving_timeout") == 0)) {
751 if (safe_atoq(
value, &val, val_type) != 0) {
752 goto safe_atoq_error;
755 goto icmap_set_error;
760 if ((strcmp(path,
"quorum.two_node") == 0) ||
761 (strcmp(path,
"quorum.expected_votes_tracking") == 0) ||
762 (strcmp(path,
"quorum.allow_downscale") == 0) ||
763 (strcmp(path,
"quorum.wait_for_all") == 0) ||
764 (strcmp(path,
"quorum.auto_tie_breaker") == 0) ||
765 (strcmp(path,
"quorum.last_man_standing") == 0)) {
767 if (safe_atoq(
value, &val, val_type) != 0) {
768 goto safe_atoq_error;
771 goto icmap_set_error;
777 if ((strcmp(path,
"quorum.device.timeout") == 0) ||
778 (strcmp(path,
"quorum.device.sync_timeout") == 0) ||
779 (strcmp(path,
"quorum.device.votes") == 0)) {
781 if (safe_atoq(
value, &val, val_type) != 0) {
782 goto safe_atoq_error;
785 goto icmap_set_error;
789 if ((strcmp(path,
"quorum.device.master_wins") == 0)) {
791 if (safe_atoq(
value, &val, val_type) != 0) {
792 goto safe_atoq_error;
795 goto icmap_set_error;
801 if ((strcmp(path,
"totem.version") == 0) ||
802 (strcmp(path,
"totem.nodeid") == 0) ||
803 (strcmp(path,
"totem.threads") == 0) ||
804 (strcmp(path,
"totem.token") == 0) ||
805 (strcmp(path,
"totem.token_coefficient") == 0) ||
806 (strcmp(path,
"totem.token_retransmit") == 0) ||
807 (strcmp(path,
"totem.token_warning") == 0) ||
808 (strcmp(path,
"totem.hold") == 0) ||
809 (strcmp(path,
"totem.token_retransmits_before_loss_const") == 0) ||
810 (strcmp(path,
"totem.join") == 0) ||
811 (strcmp(path,
"totem.send_join") == 0) ||
812 (strcmp(path,
"totem.consensus") == 0) ||
813 (strcmp(path,
"totem.merge") == 0) ||
814 (strcmp(path,
"totem.downcheck") == 0) ||
815 (strcmp(path,
"totem.fail_recv_const") == 0) ||
816 (strcmp(path,
"totem.seqno_unchanged_const") == 0) ||
817 (strcmp(path,
"totem.heartbeat_failures_allowed") == 0) ||
818 (strcmp(path,
"totem.max_network_delay") == 0) ||
819 (strcmp(path,
"totem.window_size") == 0) ||
820 (strcmp(path,
"totem.max_messages") == 0) ||
821 (strcmp(path,
"totem.miss_count_const") == 0) ||
822 (strcmp(path,
"totem.knet_pmtud_interval") == 0) ||
823 (strcmp(path,
"totem.knet_mtu") == 0) ||
824 (strcmp(path,
"totem.knet_compression_threshold") == 0) ||
825 (strcmp(path,
"totem.netmtu") == 0)) {
827 if (safe_atoq(
value, &val, val_type) != 0) {
828 goto safe_atoq_error;
831 goto icmap_set_error;
835 if (strcmp(path,
"totem.knet_compression_level") == 0) {
837 if (safe_atoq(
value, &val, val_type) != 0) {
838 goto safe_atoq_error;
841 goto icmap_set_error;
845 if (strcmp(path,
"totem.config_version") == 0) {
846 if (str_to_ull(
value, &ull) != 0) {
847 goto str_to_ull_error;
850 goto icmap_set_error;
854 if (strcmp(path,
"totem.ip_version") == 0) {
855 if ((strcmp(
value,
"ipv4") != 0) &&
856 (strcmp(
value,
"ipv6") != 0) &&
857 (strcmp(
value,
"ipv6-4") != 0) &&
858 (strcmp(
value,
"ipv4-6") != 0)) {
859 *error_string =
"Invalid ip_version type";
864 if (strcmp(path,
"totem.crypto_model") == 0) {
865 if (handle_crypto_model(
value, error_string) != 0) {
870 if (strcmp(path,
"totem.crypto_cipher") == 0) {
871 if (handle_crypto_cipher(
value, error_string) != 0) {
875 if (strcmp(path,
"totem.crypto_hash") == 0) {
876 if (handle_crypto_hash(
value, error_string) != 0) {
881 if (strcmp(path,
"totem.knet_compression_model") == 0) {
882 if (handle_compress_model(
value, error_string) != 0) {
887 if (strcmp(path,
"totem.ip_dscp") == 0) {
888 if (get_dscp_value(
value, &dscp) != 0) {
889 goto str_to_dscp_error;
892 goto icmap_set_error;
900 if (strcmp(path,
"system.qb_ipc_type") == 0) {
901 if ((strcmp(
value,
"native") != 0) &&
902 (strcmp(
value,
"shm") != 0) &&
903 (strcmp(
value,
"socket") != 0)) {
904 *error_string =
"Invalid system.qb_ipc_type";
909 if (strcmp(path,
"system.sched_rr") == 0) {
910 if ((strcmp(
value,
"yes") != 0) &&
911 (strcmp(
value,
"no") != 0)) {
912 *error_string =
"Invalid system.sched_rr value";
917 if (strcmp(path,
"system.move_to_root_cgroup") == 0) {
918 if ((strcmp(
value,
"yes") != 0) &&
919 (strcmp(
value,
"no") != 0) &&
920 (strcmp(
value,
"auto") != 0)) {
921 *error_string =
"Invalid system.move_to_root_cgroup";
926 if (strcmp(path,
"system.allow_knet_handle_fallback") == 0) {
927 if ((strcmp(
value,
"yes") != 0) &&
928 (strcmp(
value,
"no") != 0)) {
929 *error_string =
"Invalid system.allow_knet_handle_fallback";
937 if (strcmp(path,
"totem.interface.linknumber") == 0) {
939 if (safe_atoq(
value, &val, val_type) != 0) {
940 goto safe_atoq_error;
946 if (strcmp(path,
"totem.interface.bindnetaddr") == 0) {
951 if (strcmp(path,
"totem.interface.mcastaddr") == 0) {
956 if (strcmp(path,
"totem.interface.broadcast") == 0) {
961 if (strcmp(path,
"totem.interface.mcastport") == 0) {
963 if (safe_atoq(
value, &val, val_type) != 0) {
964 goto safe_atoq_error;
969 if (strcmp(path,
"totem.interface.ttl") == 0) {
971 if (safe_atoq(
value, &val, val_type) != 0) {
972 goto safe_atoq_error;
977 if (strcmp(path,
"totem.interface.knet_link_priority") == 0) {
979 if (safe_atoq(
value, &val, val_type) != 0) {
980 goto safe_atoq_error;
985 if (strcmp(path,
"totem.interface.knet_ping_interval") == 0) {
987 if (safe_atoq(
value, &val, val_type) != 0) {
988 goto safe_atoq_error;
993 if (strcmp(path,
"totem.interface.knet_ping_timeout") == 0) {
995 if (safe_atoq(
value, &val, val_type) != 0) {
996 goto safe_atoq_error;
1001 if (strcmp(path,
"totem.interface.knet_ping_precision") == 0) {
1003 if (safe_atoq(
value, &val, val_type) != 0) {
1004 goto safe_atoq_error;
1009 if (strcmp(path,
"totem.interface.knet_pong_count") == 0) {
1011 if (safe_atoq(
value, &val, val_type) != 0) {
1012 goto safe_atoq_error;
1017 if (strcmp(path,
"totem.interface.knet_transport") == 0) {
1024 if (strcmp(path,
"logging.logger_subsys.subsys") == 0) {
1027 if (data->
subsys == NULL) {
1028 *error_string =
"Can't alloc memory";
1033 path_prefix =
"logging.logger_subsys.";
1034 if (strlen(path) < strlen(path_prefix) ||
1035 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1036 *error_string =
"Internal error - incorrect path prefix for logger subsys state";
1041 kv_item = malloc(
sizeof(*kv_item));
1042 if (kv_item == NULL) {
1043 *error_string =
"Can't alloc memory";
1047 memset(kv_item, 0,
sizeof(*kv_item));
1049 kv_item->
key = strdup(path + strlen(path_prefix));
1051 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1053 free(kv_item->
value);
1055 *error_string =
"Can't alloc memory";
1059 qb_list_init(&kv_item->
list);
1065 if (strcmp(path,
"logging.logging_daemon.subsys") == 0) {
1068 if (data->
subsys == NULL) {
1069 *error_string =
"Can't alloc memory";
1073 }
else if (strcmp(path,
"logging.logging_daemon.name") == 0) {
1077 *error_string =
"Can't alloc memory";
1082 path_prefix =
"logging.logging_daemon.";
1083 if (strlen(path) < strlen(path_prefix) ||
1084 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1085 *error_string =
"Internal error - incorrect path prefix for logging daemon state";
1090 kv_item = malloc(
sizeof(*kv_item));
1091 if (kv_item == NULL) {
1092 *error_string =
"Can't alloc memory";
1096 memset(kv_item, 0,
sizeof(*kv_item));
1098 kv_item->
key = strdup(path + strlen(path_prefix));
1100 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1102 free(kv_item->
value);
1104 *error_string =
"Can't alloc memory";
1108 qb_list_init(&kv_item->
list);
1114 if (strcmp(path,
"uidgid.uid") == 0) {
1115 uid = uid_determine(
value);
1117 *error_string = error_string_response;
1123 goto icmap_set_error;
1126 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1127 gid = gid_determine(
value);
1129 *error_string = error_string_response;
1135 goto icmap_set_error;
1139 *error_string =
"uidgid: Only uid and gid are allowed items";
1144 if (strcmp(path,
"totem.interface.member.memberaddr") != 0) {
1145 *error_string =
"Only memberaddr is allowed in member section";
1150 kv_item = malloc(
sizeof(*kv_item));
1151 if (kv_item == NULL) {
1152 *error_string =
"Can't alloc memory";
1156 memset(kv_item, 0,
sizeof(*kv_item));
1158 kv_item->
key = strdup(key);
1160 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1162 free(kv_item->
value);
1164 *error_string =
"Can't alloc memory";
1168 qb_list_init(&kv_item->
list);
1175 path_prefix =
"nodelist.node.";
1176 if (strlen(path) < strlen(path_prefix) ||
1177 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1178 *error_string =
"Internal error - incorrect path prefix for nodelist node state";
1184 path + strlen(path_prefix));
1185 if ((strcmp(path,
"nodelist.node.nodeid") == 0) ||
1186 (strcmp(path,
"nodelist.node.quorum_votes") == 0)) {
1188 if (safe_atoq(
value, &val, val_type) != 0) {
1189 goto safe_atoq_error;
1193 goto icmap_set_error;
1198 if (add_as_string) {
1200 goto icmap_set_error;
1206 if (strcmp(key,
"watchdog_timeout") == 0) {
1208 if (safe_atoq(
value, &val, val_type) != 0) {
1209 goto safe_atoq_error;
1212 goto icmap_set_error;
1219 if (strcmp(key,
"poll_period") == 0) {
1220 if (str_to_ull(
value, &ull) != 0) {
1221 goto str_to_ull_error;
1224 goto icmap_set_error;
1231 if (strcmp(key,
"poll_period") == 0) {
1232 if (str_to_ull(
value, &ull) != 0) {
1233 goto str_to_ull_error;
1236 goto icmap_set_error;
1243 if (add_as_string) {
1245 goto icmap_set_error;
1250 if (strcmp(path,
"totem.interface") == 0) {
1263 if (strcmp(path,
"totem") == 0) {
1266 if (strcmp(path,
"system") == 0) {
1269 if (strcmp(path,
"logging.logger_subsys") == 0) {
1274 if (strcmp(path,
"logging.logging_daemon") == 0) {
1280 if (strcmp(path,
"uidgid") == 0) {
1283 if (strcmp(path,
"totem.interface.member") == 0) {
1286 if (strcmp(path,
"quorum") == 0) {
1289 if (strcmp(path,
"quorum.device") == 0) {
1292 if (strcmp(path,
"nodelist") == 0) {
1296 if (strcmp(path,
"nodelist.node") == 0) {
1299 if (strcmp(path,
"resources") == 0) {
1302 if (strcmp(path,
"resources.system") == 0) {
1305 if (strcmp(path,
"resources.system.memory_used") == 0) {
1308 if (strcmp(path,
"resources.process") == 0) {
1311 if (strcmp(path,
"resources.process.memory_used") == 0) {
1316 *error_string =
"Subsections are not allowed within uidgid section";
1322 *error_string =
"Subsections are not allowed within totem.interface.member section";
1330 if (strcmp(path,
"totem.interface") != 0) {
1348 if (cs_err !=
CS_OK) {
1349 goto icmap_set_error;
1361 if (cs_err !=
CS_OK) {
1362 goto icmap_set_error;
1374 if (cs_err !=
CS_OK) {
1375 goto icmap_set_error;
1384 goto icmap_set_error;
1388 if (data->
ttl > -1) {
1392 goto icmap_set_error;
1400 goto icmap_set_error;
1408 goto icmap_set_error;
1416 goto icmap_set_error;
1424 goto icmap_set_error;
1432 goto icmap_set_error;
1442 if (cs_err !=
CS_OK) {
1443 goto icmap_set_error;
1451 qb_list_del(&kv_item->
list);
1457 free(kv_item->
value);
1462 if (cs_err !=
CS_OK) {
1463 goto icmap_set_error;
1471 if (strcmp(path,
"logging.logger_subsys") != 0) {
1478 if (data->
subsys == NULL) {
1479 *error_string =
"No subsys key in logger_subsys directive";
1486 qb_list_del(&kv_item->
list);
1492 free(kv_item->
value);
1496 if (cs_err !=
CS_OK) {
1497 goto icmap_set_error;
1509 if (cs_err !=
CS_OK) {
1510 goto icmap_set_error;
1514 if (strcmp(path,
"logging.logging_daemon") != 0) {
1522 *error_string =
"No name key in logging_daemon directive";
1529 qb_list_del(&kv_item->
list);
1531 if (data->
subsys == NULL) {
1538 "logging.logging_daemon.%s.%s",
1544 "logging.logger_subsys.%s.%s",
1549 "logging.logging_daemon.%s.%s.%s",
1556 free(kv_item->
value);
1560 if (cs_err !=
CS_OK) {
1561 goto icmap_set_error;
1565 if (data->
subsys == NULL) {
1582 if (cs_err !=
CS_OK) {
1583 goto icmap_set_error;
1597 if (cs_err !=
CS_OK) {
1598 goto icmap_set_error;
1602 if (strcmp(path,
"nodelist.node") != 0) {
1636 min_val = max_val = 0;
1641 assert(safe_atoq_range(val_type, &min_val, &max_val) == 0);
1643 if (snprintf(formated_err,
sizeof(formated_err),
1644 "Value of key \"%s\" is expected to be integer in range (%lld..%lld), but \"%s\" was given",
1645 key_name, min_val, max_val,
value) >=
sizeof(formated_err)) {
1646 *error_string =
"Can't format parser error message";
1648 *error_string = formated_err;
1657 if (snprintf(formated_err,
sizeof(formated_err),
1658 "Value of key \"%s\" is expected to be unsigned integer, but \"%s\" was given",
1659 key_name,
value) >=
sizeof(formated_err)) {
1660 *error_string =
"Can't format parser error message";
1662 *error_string = formated_err;
1668 if (snprintf(formated_err,
sizeof(formated_err),
1669 "Value of key \"%s\" is expected to be number (0..63) or symbolical dscp value, "
1670 "but \"%s\" was given", key_name,
value) >=
sizeof(formated_err)) {
1671 *error_string =
"Can't format parser error message";
1673 *error_string = formated_err;
1679 if (snprintf(formated_err,
sizeof(formated_err),
1680 "Can't store key \"%s\" into icmap, returned error is %s",
1681 key_name,
cs_strerror(cs_err)) >=
sizeof(formated_err)) {
1682 *error_string =
"Can't format parser error message";
1684 *error_string = formated_err;
1690static int uidgid_config_parser_cb(
const char *path,
1695 const char **error_string,
1701 static char formated_err[256];
1712 if (strcmp(path,
"uidgid.uid") == 0) {
1713 uid = uid_determine(
value);
1715 *error_string = error_string_response;
1721 goto icmap_set_error;
1723 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1724 gid = gid_determine(
value);
1726 *error_string = error_string_response;
1732 goto icmap_set_error;
1735 *error_string =
"uidgid: Only uid and gid are allowed items";
1740 if (strcmp(path,
"uidgid") != 0) {
1741 *error_string =
"uidgid: Can't add subsection different than uidgid";
1752 if (snprintf(formated_err,
sizeof(formated_err),
1753 "Can't store key \"%s\" into icmap, returned error is %s",
1754 key_name,
cs_strerror(cs_err)) >=
sizeof(formated_err)) {
1755 *error_string =
"Can't format parser error message";
1757 *error_string = formated_err;
1763static int read_uidgid_files_into_icmap(
1764 const char **error_string,
1770 struct dirent *dirent;
1771 char filename[PATH_MAX + FILENAME_MAX + 1];
1772 char uidgid_dirname[PATH_MAX + FILENAME_MAX + 1];
1774 struct stat stat_buf;
1782 res = snprintf(filename,
sizeof(filename),
"%s",
1784 if (res >=
sizeof(filename)) {
1785 *error_string =
"uidgid.d path too long";
1790 dirname_res = dirname(filename);
1792 res = snprintf(uidgid_dirname,
sizeof(uidgid_dirname),
"%s/%s",
1793 dirname_res,
"uidgid.d");
1794 if (res >=
sizeof(uidgid_dirname)) {
1795 *error_string =
"uidgid.d path too long";
1800 dp = opendir (uidgid_dirname);
1805 for (dirent = readdir(dp);
1807 dirent = readdir(dp)) {
1809 res = snprintf(filename,
sizeof (filename),
"%s/%s", uidgid_dirname, dirent->d_name);
1810 if (res >=
sizeof(filename)) {
1812 *error_string =
"uidgid.d dirname path too long";
1817 res = stat (filename, &stat_buf);
1818 if (res == 0 && S_ISREG(stat_buf.st_mode)) {
1820 fp = fopen (filename,
"r");
1821 if (fp == NULL)
continue;
1826 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1827 uidgid_config_parser_cb, config_map, NULL);
1844static int read_config_file_into_icmap(
1845 const char **error_string,
1849 const char *filename;
1850 char *error_reason = error_string_response;
1859 fp = fopen (filename,
"r");
1861 char error_str[100];
1862 const char *error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
1863 snprintf (error_reason,
sizeof(error_string_response),
1864 "Can't read file %s: %s",
1865 filename, error_ptr);
1866 *error_string = error_reason;
1873 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1874 main_config_parser_cb, config_map, &data);
1879 res = read_uidgid_files_into_icmap(error_string, config_map);
1883 snprintf (error_reason,
sizeof(error_string_response),
1884 "Successfully read main configuration file '%s'.", filename);
1885 *error_string = error_reason;
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)
@ MAIN_CP_CB_DATA_STATE_LOGGING_DAEMON
@ MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS_MEMUSED
@ MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM_MEMUSED
@ MAIN_CP_CB_DATA_STATE_MEMBER
@ MAIN_CP_CB_DATA_STATE_UIDGID
@ MAIN_CP_CB_DATA_STATE_INTERFACE
@ MAIN_CP_CB_DATA_STATE_NORMAL
@ MAIN_CP_CB_DATA_STATE_PLOAD
@ MAIN_CP_CB_DATA_STATE_LOGGER_SUBSYS
@ MAIN_CP_CB_DATA_STATE_TOTEM
@ MAIN_CP_CB_DATA_STATE_RESOURCES_PROCESS
@ MAIN_CP_CB_DATA_STATE_SYSTEM
@ MAIN_CP_CB_DATA_STATE_QUORUM
@ MAIN_CP_CB_DATA_STATE_QDEVICE
@ MAIN_CP_CB_DATA_STATE_RESOURCES_SYSTEM
@ MAIN_CP_CB_DATA_STATE_NODELIST_NODE
@ MAIN_CP_CB_DATA_STATE_RESOURCES
@ MAIN_CP_CB_DATA_STATE_NODELIST
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
@ PARSER_CB_SECTION_START
const char * cs_strerror(cs_error_t err)
cs_strerror
cs_error_t
The cs_error_t enum.
cs_error_t icmap_set_uint16_r(const icmap_map_t map, const char *key_name, uint16_t value)
cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
icmap_value_types_t
Possible types of value.
cs_error_t icmap_set_uint8_r(const icmap_map_t map, const char *key_name, uint8_t value)
cs_error_t icmap_set_uint64_r(const icmap_map_t map, const char *key_name, uint64_t value)
cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
const char * corosync_get_config_file(void)
struct qb_list_head logger_subsys_items_head
char * logging_daemon_name
struct qb_list_head member_items_head
int util_is_valid_knet_crypto_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
int util_is_valid_knet_crypto_cipher(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
int util_is_valid_knet_crypto_hash(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
int util_is_valid_knet_compress_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)