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_compress_model(
const char *val,
const char **error_string)
621 "Invalid compression model. Should be ", error_string) == 1) {
628static int main_config_parser_cb(
const char *path,
633 const char **error_string,
639 long long int min_val, max_val;
641 unsigned long long int ull;
644 static char formated_err[256];
647 struct qb_list_head *iter, *tmp_iter;
650 const char *path_prefix;
657 if (strlen(path) >=
sizeof(key_name)) {
658 if (snprintf(formated_err,
sizeof(formated_err),
659 "Can't store path \"%s\" into key_name", path) >=
sizeof(formated_err)) {
660 *error_string =
"Can't format path into key_name error message";
662 *error_string = formated_err;
670 strncpy(key_name, path,
sizeof(key_name) - 1);
689 qb_list_del(&kv_item->
list);
691 free(kv_item->
value);
701 qb_list_del(&kv_item->
list);
703 free(kv_item->
value);
715 if ((strcmp(path,
"pload.count") == 0) ||
716 (strcmp(path,
"pload.size") == 0)) {
718 if (safe_atoq(
value, &val, val_type) != 0) {
719 goto safe_atoq_error;
722 goto icmap_set_error;
728 if ((strcmp(path,
"quorum.expected_votes") == 0) ||
729 (strcmp(path,
"quorum.votes") == 0) ||
730 (strcmp(path,
"quorum.last_man_standing_window") == 0) ||
731 (strcmp(path,
"quorum.leaving_timeout") == 0)) {
733 if (safe_atoq(
value, &val, val_type) != 0) {
734 goto safe_atoq_error;
737 goto icmap_set_error;
742 if ((strcmp(path,
"quorum.two_node") == 0) ||
743 (strcmp(path,
"quorum.expected_votes_tracking") == 0) ||
744 (strcmp(path,
"quorum.allow_downscale") == 0) ||
745 (strcmp(path,
"quorum.wait_for_all") == 0) ||
746 (strcmp(path,
"quorum.auto_tie_breaker") == 0) ||
747 (strcmp(path,
"quorum.last_man_standing") == 0)) {
749 if (safe_atoq(
value, &val, val_type) != 0) {
750 goto safe_atoq_error;
753 goto icmap_set_error;
759 if ((strcmp(path,
"quorum.device.timeout") == 0) ||
760 (strcmp(path,
"quorum.device.sync_timeout") == 0) ||
761 (strcmp(path,
"quorum.device.votes") == 0)) {
763 if (safe_atoq(
value, &val, val_type) != 0) {
764 goto safe_atoq_error;
767 goto icmap_set_error;
771 if ((strcmp(path,
"quorum.device.master_wins") == 0)) {
773 if (safe_atoq(
value, &val, val_type) != 0) {
774 goto safe_atoq_error;
777 goto icmap_set_error;
783 if ((strcmp(path,
"totem.version") == 0) ||
784 (strcmp(path,
"totem.nodeid") == 0) ||
785 (strcmp(path,
"totem.threads") == 0) ||
786 (strcmp(path,
"totem.token") == 0) ||
787 (strcmp(path,
"totem.token_coefficient") == 0) ||
788 (strcmp(path,
"totem.token_retransmit") == 0) ||
789 (strcmp(path,
"totem.token_warning") == 0) ||
790 (strcmp(path,
"totem.hold") == 0) ||
791 (strcmp(path,
"totem.token_retransmits_before_loss_const") == 0) ||
792 (strcmp(path,
"totem.join") == 0) ||
793 (strcmp(path,
"totem.send_join") == 0) ||
794 (strcmp(path,
"totem.consensus") == 0) ||
795 (strcmp(path,
"totem.merge") == 0) ||
796 (strcmp(path,
"totem.downcheck") == 0) ||
797 (strcmp(path,
"totem.fail_recv_const") == 0) ||
798 (strcmp(path,
"totem.seqno_unchanged_const") == 0) ||
799 (strcmp(path,
"totem.heartbeat_failures_allowed") == 0) ||
800 (strcmp(path,
"totem.max_network_delay") == 0) ||
801 (strcmp(path,
"totem.window_size") == 0) ||
802 (strcmp(path,
"totem.max_messages") == 0) ||
803 (strcmp(path,
"totem.miss_count_const") == 0) ||
804 (strcmp(path,
"totem.knet_pmtud_interval") == 0) ||
805 (strcmp(path,
"totem.knet_mtu") == 0) ||
806 (strcmp(path,
"totem.knet_compression_threshold") == 0) ||
807 (strcmp(path,
"totem.netmtu") == 0)) {
809 if (safe_atoq(
value, &val, val_type) != 0) {
810 goto safe_atoq_error;
813 goto icmap_set_error;
817 if (strcmp(path,
"totem.knet_compression_level") == 0) {
819 if (safe_atoq(
value, &val, val_type) != 0) {
820 goto safe_atoq_error;
823 goto icmap_set_error;
827 if (strcmp(path,
"totem.config_version") == 0) {
828 if (str_to_ull(
value, &ull) != 0) {
829 goto str_to_ull_error;
832 goto icmap_set_error;
836 if (strcmp(path,
"totem.ip_version") == 0) {
837 if ((strcmp(
value,
"ipv4") != 0) &&
838 (strcmp(
value,
"ipv6") != 0) &&
839 (strcmp(
value,
"ipv6-4") != 0) &&
840 (strcmp(
value,
"ipv4-6") != 0)) {
841 *error_string =
"Invalid ip_version type";
846 if (strcmp(path,
"totem.crypto_model") == 0) {
847 if (handle_crypto_model(
value, error_string) != 0) {
852 if (strcmp(path,
"totem.crypto_cipher") == 0) {
853 if ((strcmp(
value,
"none") != 0) &&
854 (strcmp(
value,
"aes256") != 0) &&
855 (strcmp(
value,
"aes192") != 0) &&
856 (strcmp(
value,
"aes128") != 0)) {
857 *error_string =
"Invalid cipher type. "
858 "Should be none, aes256, aes192 or aes128";
863 if (strcmp(path,
"totem.crypto_hash") == 0) {
864 if ((strcmp(
value,
"none") != 0) &&
865 (strcmp(
value,
"md5") != 0) &&
866 (strcmp(
value,
"sha1") != 0) &&
867 (strcmp(
value,
"sha256") != 0) &&
868 (strcmp(
value,
"sha384") != 0) &&
869 (strcmp(
value,
"sha512") != 0)) {
870 *error_string =
"Invalid hash type. "
871 "Should be none, md5, sha1, sha256, sha384 or sha512";
877 if (strcmp(path,
"totem.knet_compression_model") == 0) {
878 if (handle_compress_model(
value, error_string) != 0) {
883 if (strcmp(path,
"totem.ip_dscp") == 0) {
884 if (get_dscp_value(
value, &dscp) != 0) {
885 goto str_to_dscp_error;
888 goto icmap_set_error;
896 if (strcmp(path,
"system.qb_ipc_type") == 0) {
897 if ((strcmp(
value,
"native") != 0) &&
898 (strcmp(
value,
"shm") != 0) &&
899 (strcmp(
value,
"socket") != 0)) {
900 *error_string =
"Invalid system.qb_ipc_type";
905 if (strcmp(path,
"system.sched_rr") == 0) {
906 if ((strcmp(
value,
"yes") != 0) &&
907 (strcmp(
value,
"no") != 0)) {
908 *error_string =
"Invalid system.sched_rr value";
913 if (strcmp(path,
"system.move_to_root_cgroup") == 0) {
914 if ((strcmp(
value,
"yes") != 0) &&
915 (strcmp(
value,
"no") != 0) &&
916 (strcmp(
value,
"auto") != 0)) {
917 *error_string =
"Invalid system.move_to_root_cgroup";
922 if (strcmp(path,
"system.allow_knet_handle_fallback") == 0) {
923 if ((strcmp(
value,
"yes") != 0) &&
924 (strcmp(
value,
"no") != 0)) {
925 *error_string =
"Invalid system.allow_knet_handle_fallback";
933 if (strcmp(path,
"totem.interface.linknumber") == 0) {
935 if (safe_atoq(
value, &val, val_type) != 0) {
936 goto safe_atoq_error;
942 if (strcmp(path,
"totem.interface.bindnetaddr") == 0) {
947 if (strcmp(path,
"totem.interface.mcastaddr") == 0) {
952 if (strcmp(path,
"totem.interface.broadcast") == 0) {
957 if (strcmp(path,
"totem.interface.mcastport") == 0) {
959 if (safe_atoq(
value, &val, val_type) != 0) {
960 goto safe_atoq_error;
965 if (strcmp(path,
"totem.interface.ttl") == 0) {
967 if (safe_atoq(
value, &val, val_type) != 0) {
968 goto safe_atoq_error;
973 if (strcmp(path,
"totem.interface.knet_link_priority") == 0) {
975 if (safe_atoq(
value, &val, val_type) != 0) {
976 goto safe_atoq_error;
981 if (strcmp(path,
"totem.interface.knet_ping_interval") == 0) {
983 if (safe_atoq(
value, &val, val_type) != 0) {
984 goto safe_atoq_error;
989 if (strcmp(path,
"totem.interface.knet_ping_timeout") == 0) {
991 if (safe_atoq(
value, &val, val_type) != 0) {
992 goto safe_atoq_error;
997 if (strcmp(path,
"totem.interface.knet_ping_precision") == 0) {
999 if (safe_atoq(
value, &val, val_type) != 0) {
1000 goto safe_atoq_error;
1005 if (strcmp(path,
"totem.interface.knet_pong_count") == 0) {
1007 if (safe_atoq(
value, &val, val_type) != 0) {
1008 goto safe_atoq_error;
1013 if (strcmp(path,
"totem.interface.knet_transport") == 0) {
1020 if (strcmp(path,
"logging.logger_subsys.subsys") == 0) {
1023 if (data->
subsys == NULL) {
1024 *error_string =
"Can't alloc memory";
1029 path_prefix =
"logging.logger_subsys.";
1030 if (strlen(path) < strlen(path_prefix) ||
1031 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1032 *error_string =
"Internal error - incorrect path prefix for logger subsys state";
1037 kv_item = malloc(
sizeof(*kv_item));
1038 if (kv_item == NULL) {
1039 *error_string =
"Can't alloc memory";
1043 memset(kv_item, 0,
sizeof(*kv_item));
1045 kv_item->
key = strdup(path + strlen(path_prefix));
1047 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1049 free(kv_item->
value);
1051 *error_string =
"Can't alloc memory";
1055 qb_list_init(&kv_item->
list);
1061 if (strcmp(path,
"logging.logging_daemon.subsys") == 0) {
1064 if (data->
subsys == NULL) {
1065 *error_string =
"Can't alloc memory";
1069 }
else if (strcmp(path,
"logging.logging_daemon.name") == 0) {
1073 *error_string =
"Can't alloc memory";
1078 path_prefix =
"logging.logging_daemon.";
1079 if (strlen(path) < strlen(path_prefix) ||
1080 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1081 *error_string =
"Internal error - incorrect path prefix for logging daemon state";
1086 kv_item = malloc(
sizeof(*kv_item));
1087 if (kv_item == NULL) {
1088 *error_string =
"Can't alloc memory";
1092 memset(kv_item, 0,
sizeof(*kv_item));
1094 kv_item->
key = strdup(path + strlen(path_prefix));
1096 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1098 free(kv_item->
value);
1100 *error_string =
"Can't alloc memory";
1104 qb_list_init(&kv_item->
list);
1110 if (strcmp(path,
"uidgid.uid") == 0) {
1111 uid = uid_determine(
value);
1113 *error_string = error_string_response;
1119 goto icmap_set_error;
1122 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1123 gid = gid_determine(
value);
1125 *error_string = error_string_response;
1131 goto icmap_set_error;
1135 *error_string =
"uidgid: Only uid and gid are allowed items";
1140 if (strcmp(path,
"totem.interface.member.memberaddr") != 0) {
1141 *error_string =
"Only memberaddr is allowed in member section";
1146 kv_item = malloc(
sizeof(*kv_item));
1147 if (kv_item == NULL) {
1148 *error_string =
"Can't alloc memory";
1152 memset(kv_item, 0,
sizeof(*kv_item));
1154 kv_item->
key = strdup(key);
1156 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1158 free(kv_item->
value);
1160 *error_string =
"Can't alloc memory";
1164 qb_list_init(&kv_item->
list);
1171 path_prefix =
"nodelist.node.";
1172 if (strlen(path) < strlen(path_prefix) ||
1173 strncmp(path, path_prefix, strlen(path_prefix)) != 0) {
1174 *error_string =
"Internal error - incorrect path prefix for nodelist node state";
1180 path + strlen(path_prefix));
1181 if ((strcmp(path,
"nodelist.node.nodeid") == 0) ||
1182 (strcmp(path,
"nodelist.node.quorum_votes") == 0)) {
1184 if (safe_atoq(
value, &val, val_type) != 0) {
1185 goto safe_atoq_error;
1189 goto icmap_set_error;
1194 if (add_as_string) {
1196 goto icmap_set_error;
1202 if (strcmp(key,
"watchdog_timeout") == 0) {
1204 if (safe_atoq(
value, &val, val_type) != 0) {
1205 goto safe_atoq_error;
1208 goto icmap_set_error;
1215 if (strcmp(key,
"poll_period") == 0) {
1216 if (str_to_ull(
value, &ull) != 0) {
1217 goto str_to_ull_error;
1220 goto icmap_set_error;
1227 if (strcmp(key,
"poll_period") == 0) {
1228 if (str_to_ull(
value, &ull) != 0) {
1229 goto str_to_ull_error;
1232 goto icmap_set_error;
1239 if (add_as_string) {
1241 goto icmap_set_error;
1246 if (strcmp(path,
"totem.interface") == 0) {
1259 if (strcmp(path,
"totem") == 0) {
1262 if (strcmp(path,
"system") == 0) {
1265 if (strcmp(path,
"logging.logger_subsys") == 0) {
1270 if (strcmp(path,
"logging.logging_daemon") == 0) {
1276 if (strcmp(path,
"uidgid") == 0) {
1279 if (strcmp(path,
"totem.interface.member") == 0) {
1282 if (strcmp(path,
"quorum") == 0) {
1285 if (strcmp(path,
"quorum.device") == 0) {
1288 if (strcmp(path,
"nodelist") == 0) {
1292 if (strcmp(path,
"nodelist.node") == 0) {
1295 if (strcmp(path,
"resources") == 0) {
1298 if (strcmp(path,
"resources.system") == 0) {
1301 if (strcmp(path,
"resources.system.memory_used") == 0) {
1304 if (strcmp(path,
"resources.process") == 0) {
1307 if (strcmp(path,
"resources.process.memory_used") == 0) {
1312 *error_string =
"Subsections are not allowed within uidgid section";
1318 *error_string =
"Subsections are not allowed within totem.interface.member section";
1326 if (strcmp(path,
"totem.interface") != 0) {
1344 if (cs_err !=
CS_OK) {
1345 goto icmap_set_error;
1357 if (cs_err !=
CS_OK) {
1358 goto icmap_set_error;
1370 if (cs_err !=
CS_OK) {
1371 goto icmap_set_error;
1380 goto icmap_set_error;
1384 if (data->
ttl > -1) {
1388 goto icmap_set_error;
1396 goto icmap_set_error;
1404 goto icmap_set_error;
1412 goto icmap_set_error;
1420 goto icmap_set_error;
1428 goto icmap_set_error;
1438 if (cs_err !=
CS_OK) {
1439 goto icmap_set_error;
1447 qb_list_del(&kv_item->
list);
1453 free(kv_item->
value);
1458 if (cs_err !=
CS_OK) {
1459 goto icmap_set_error;
1467 if (strcmp(path,
"logging.logger_subsys") != 0) {
1474 if (data->
subsys == NULL) {
1475 *error_string =
"No subsys key in logger_subsys directive";
1482 qb_list_del(&kv_item->
list);
1488 free(kv_item->
value);
1492 if (cs_err !=
CS_OK) {
1493 goto icmap_set_error;
1505 if (cs_err !=
CS_OK) {
1506 goto icmap_set_error;
1510 if (strcmp(path,
"logging.logging_daemon") != 0) {
1518 *error_string =
"No name key in logging_daemon directive";
1525 qb_list_del(&kv_item->
list);
1527 if (data->
subsys == NULL) {
1534 "logging.logging_daemon.%s.%s",
1540 "logging.logger_subsys.%s.%s",
1545 "logging.logging_daemon.%s.%s.%s",
1552 free(kv_item->
value);
1556 if (cs_err !=
CS_OK) {
1557 goto icmap_set_error;
1561 if (data->
subsys == NULL) {
1578 if (cs_err !=
CS_OK) {
1579 goto icmap_set_error;
1593 if (cs_err !=
CS_OK) {
1594 goto icmap_set_error;
1598 if (strcmp(path,
"nodelist.node") != 0) {
1632 min_val = max_val = 0;
1637 assert(safe_atoq_range(val_type, &min_val, &max_val) == 0);
1639 if (snprintf(formated_err,
sizeof(formated_err),
1640 "Value of key \"%s\" is expected to be integer in range (%lld..%lld), but \"%s\" was given",
1641 key_name, min_val, max_val,
value) >=
sizeof(formated_err)) {
1642 *error_string =
"Can't format parser error message";
1644 *error_string = formated_err;
1653 if (snprintf(formated_err,
sizeof(formated_err),
1654 "Value of key \"%s\" is expected to be unsigned integer, but \"%s\" was given",
1655 key_name,
value) >=
sizeof(formated_err)) {
1656 *error_string =
"Can't format parser error message";
1658 *error_string = formated_err;
1664 if (snprintf(formated_err,
sizeof(formated_err),
1665 "Value of key \"%s\" is expected to be number (0..63) or symbolical dscp value, "
1666 "but \"%s\" was given", key_name,
value) >=
sizeof(formated_err)) {
1667 *error_string =
"Can't format parser error message";
1669 *error_string = formated_err;
1675 if (snprintf(formated_err,
sizeof(formated_err),
1676 "Can't store key \"%s\" into icmap, returned error is %s",
1677 key_name,
cs_strerror(cs_err)) >=
sizeof(formated_err)) {
1678 *error_string =
"Can't format parser error message";
1680 *error_string = formated_err;
1686static int uidgid_config_parser_cb(
const char *path,
1691 const char **error_string,
1697 static char formated_err[256];
1708 if (strcmp(path,
"uidgid.uid") == 0) {
1709 uid = uid_determine(
value);
1711 *error_string = error_string_response;
1717 goto icmap_set_error;
1719 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1720 gid = gid_determine(
value);
1722 *error_string = error_string_response;
1728 goto icmap_set_error;
1731 *error_string =
"uidgid: Only uid and gid are allowed items";
1736 if (strcmp(path,
"uidgid") != 0) {
1737 *error_string =
"uidgid: Can't add subsection different than uidgid";
1748 if (snprintf(formated_err,
sizeof(formated_err),
1749 "Can't store key \"%s\" into icmap, returned error is %s",
1750 key_name,
cs_strerror(cs_err)) >=
sizeof(formated_err)) {
1751 *error_string =
"Can't format parser error message";
1753 *error_string = formated_err;
1759static int read_uidgid_files_into_icmap(
1760 const char **error_string,
1766 struct dirent *dirent;
1767 char filename[PATH_MAX + FILENAME_MAX + 1];
1768 char uidgid_dirname[PATH_MAX + FILENAME_MAX + 1];
1770 struct stat stat_buf;
1778 res = snprintf(filename,
sizeof(filename),
"%s",
1780 if (res >=
sizeof(filename)) {
1781 *error_string =
"uidgid.d path too long";
1786 dirname_res = dirname(filename);
1788 res = snprintf(uidgid_dirname,
sizeof(uidgid_dirname),
"%s/%s",
1789 dirname_res,
"uidgid.d");
1790 if (res >=
sizeof(uidgid_dirname)) {
1791 *error_string =
"uidgid.d path too long";
1796 dp = opendir (uidgid_dirname);
1801 for (dirent = readdir(dp);
1803 dirent = readdir(dp)) {
1805 res = snprintf(filename,
sizeof (filename),
"%s/%s", uidgid_dirname, dirent->d_name);
1806 if (res >=
sizeof(filename)) {
1808 *error_string =
"uidgid.d dirname path too long";
1813 res = stat (filename, &stat_buf);
1814 if (res == 0 && S_ISREG(stat_buf.st_mode)) {
1816 fp = fopen (filename,
"r");
1817 if (fp == NULL)
continue;
1822 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1823 uidgid_config_parser_cb, config_map, NULL);
1840static int read_config_file_into_icmap(
1841 const char **error_string,
1845 const char *filename;
1846 char *error_reason = error_string_response;
1855 fp = fopen (filename,
"r");
1857 char error_str[100];
1858 const char *error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
1859 snprintf (error_reason,
sizeof(error_string_response),
1860 "Can't read file %s: %s",
1861 filename, error_ptr);
1862 *error_string = error_reason;
1869 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1870 main_config_parser_cb, config_map, &data);
1875 res = read_uidgid_files_into_icmap(error_string, config_map);
1879 snprintf (error_reason,
sizeof(error_string_response),
1880 "Successfully read main configuration file '%s'.", filename);
1881 *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)
struct icmap_map * icmap_map_t
icmap type.
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_compress_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)