38 #include <sys/types.h>
40 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
58 #include <qb/qblist.h>
59 #include <qb/qbutil.h>
60 #define LOGSYS_UTILS_ONLY 1
102 const char **error_string,
109 struct qb_list_head
list;
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];
139 static int uid_determine (
const char *req_user)
142 struct passwd passwd;
143 struct passwd* pwdptr = &passwd;
144 struct passwd* temp_pwd_pt;
150 id = strtol(req_user, &ep, 10);
151 if (*req_user !=
'\0' && *ep ==
'\0' &&
id >= 0 &&
id <= UINT_MAX) {
155 pwdlinelen = sysconf (_SC_GETPW_R_SIZE_MAX);
157 if (pwdlinelen == -1) {
161 pwdbuffer = malloc (pwdlinelen);
163 while ((rc = getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) == ERANGE) {
167 if (pwdlinelen <= 32678) {
168 n = realloc (pwdbuffer, pwdlinelen);
177 sprintf (error_string_response,
"getpwnam_r(): %s", strerror(rc));
180 if (temp_pwd_pt == NULL) {
182 sprintf (error_string_response,
183 "The '%s' user is not found in /etc/passwd, please read the documentation.",
187 pw_uid = passwd.pw_uid;
193 static int gid_determine (
const char *req_group)
195 int corosync_gid = 0;
197 struct group * grpptr = &group;
198 struct group * temp_grp_pt;
204 id = strtol(req_group, &ep, 10);
205 if (*req_group !=
'\0' && *ep ==
'\0' &&
id >= 0 &&
id <= UINT_MAX) {
209 grplinelen = sysconf (_SC_GETGR_R_SIZE_MAX);
211 if (grplinelen == -1) {
215 grpbuffer = malloc (grplinelen);
217 while ((rc = getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) == ERANGE) {
221 if (grplinelen <= 32678) {
222 n = realloc (grpbuffer, grplinelen);
231 sprintf (error_string_response,
"getgrnam_r(): %s", strerror(rc));
234 if (temp_grp_pt == NULL) {
236 sprintf (error_string_response,
237 "The '%s' group is not found in /etc/group, please read the documentation.",
241 corosync_gid = group.gr_gid;
246 static char *strchr_rs (
const char *haystack,
int byte)
248 const char *end_address = strchr (haystack,
byte);
252 while (*end_address ==
' ' || *end_address ==
'\t')
256 return ((
char *) end_address);
261 if (read_config_file_into_icmap(error_string, config_map)) {
268 static char *remove_whitespace(
char *
string,
int remove_colon_and_brace)
277 while (*start ==
' ' || *start ==
'\t')
280 end = start+(strlen(start))-1;
281 while ((*end ==
' ' || *end ==
'\t' || (remove_colon_and_brace && (*end ==
':' || *end ==
'{'))) && end > start)
291 static int parse_section(FILE *fp,
295 const char **error_string,
307 static char formated_err[384];
308 const char *tmp_error_string;
310 if (strcmp(path,
"") == 0) {
314 tmp_error_string = NULL;
316 while (fgets (line,
sizeof (line), fp)) {
319 if (strlen(line) > 0) {
324 if ((line[strlen(line) - 1] !=
'\n') && !feof(fp)) {
325 tmp_error_string =
"Line too long";
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';
337 for (i = strlen (line) - 1; i > -1; i--) {
338 if (line[i] ==
'\t' || line[i] ==
' ') {
346 for (i = 0; i < strlen (line); i++) {
347 if (line[i] !=
'\t' && line[i] !=
' ') {
362 if ((loc = strchr_rs (line,
'{'))) {
368 section = remove_whitespace(line, 1);
369 after_section = remove_whitespace(loc, 0);
371 if (strcmp(section,
"") == 0) {
372 tmp_error_string =
"Missing section name before opening bracket '{'";
376 if (strcmp(after_section,
"") != 0) {
377 tmp_error_string =
"Extra characters after opening bracket '{'";
382 tmp_error_string =
"Start of section makes total cmap path too long";
385 strcpy(new_keyname, path);
386 if (strcmp(path,
"") != 0) {
387 strcat(new_keyname,
".");
389 strcat(new_keyname, section);
394 &tmp_error_string, config_map,
user_data)) {
398 if (parse_section(fp, fname, line_no, new_keyname, error_string, depth + 1, newstate,
406 if ((loc = strchr_rs (line,
':'))) {
411 key = remove_whitespace(line, 1);
412 value = remove_whitespace(loc, 0);
414 if (strlen(key) == 0) {
415 tmp_error_string =
"Key name can't be empty";
420 tmp_error_string =
"New key makes total cmap path too long";
423 strcpy(new_keyname, path);
424 if (strcmp(path,
"") != 0) {
425 strcat(new_keyname,
".");
427 strcat(new_keyname, key);
437 if (strchr_rs (line,
'}')) {
439 trimmed_line = remove_whitespace(line, 0);
441 if (strcmp(trimmed_line,
"}") != 0) {
442 tmp_error_string =
"Extra characters before or after closing bracket '}'";
447 tmp_error_string =
"Unexpected closing brace";
463 tmp_error_string =
"Line is not opening or closing section or key value";
467 if (strcmp(path,
"") != 0) {
468 tmp_error_string =
"Missing closing brace";
472 if (strcmp(path,
"") == 0) {
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";
484 *error_string = formated_err;
492 static int safe_atoq_range(
icmap_value_types_t value_type,
long long int *min_val,
long long int *max_val)
494 switch (value_type) {
516 long long int min_val, max_val;
521 val = strtoll(str, &endptr, 10);
522 if (errno == ERANGE) {
530 if (*endptr !=
'\0') {
534 if (safe_atoq_range(target_type, &min_val, &max_val) != 0) {
538 if (val < min_val || val > max_val) {
546 static int str_to_ull(
const char *str,
unsigned long long int *res)
548 unsigned long long int val;
553 val = strtoull(str, &endptr, 10);
554 if (errno == ERANGE) {
562 if (*endptr !=
'\0') {
570 static int main_config_parser_cb(
const char *path,
575 const char **error_string,
581 long long int min_val, max_val;
583 unsigned long long int ull;
586 static char formated_err[256];
589 struct qb_list_head *iter, *tmp_iter;
592 const char *path_prefix;
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";
604 *error_string = formated_err;
612 strncpy(key_name, path,
sizeof(key_name) - 1);
631 qb_list_del(&kv_item->
list);
633 free(kv_item->
value);
643 qb_list_del(&kv_item->
list);
645 free(kv_item->
value);
657 if ((strcmp(path,
"pload.count") == 0) ||
658 (strcmp(path,
"pload.size") == 0)) {
660 if (safe_atoq(
value, &val, val_type) != 0) {
661 goto safe_atoq_error;
664 goto icmap_set_error;
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)) {
675 if (safe_atoq(
value, &val, val_type) != 0) {
676 goto safe_atoq_error;
679 goto icmap_set_error;
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)) {
691 if (safe_atoq(
value, &val, val_type) != 0) {
692 goto safe_atoq_error;
695 goto icmap_set_error;
701 if ((strcmp(path,
"quorum.device.timeout") == 0) ||
702 (strcmp(path,
"quorum.device.sync_timeout") == 0) ||
703 (strcmp(path,
"quorum.device.votes") == 0)) {
705 if (safe_atoq(
value, &val, val_type) != 0) {
706 goto safe_atoq_error;
709 goto icmap_set_error;
713 if ((strcmp(path,
"quorum.device.master_wins") == 0)) {
715 if (safe_atoq(
value, &val, val_type) != 0) {
716 goto safe_atoq_error;
719 goto icmap_set_error;
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)) {
755 if (safe_atoq(
value, &val, val_type) != 0) {
756 goto safe_atoq_error;
759 goto icmap_set_error;
763 if (strcmp(path,
"totem.knet_compression_level") == 0) {
765 if (safe_atoq(
value, &val, val_type) != 0) {
766 goto safe_atoq_error;
769 goto icmap_set_error;
773 if (strcmp(path,
"totem.config_version") == 0) {
774 if (str_to_ull(
value, &ull) != 0) {
775 goto str_to_ull_error;
778 goto icmap_set_error;
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";
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";
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";
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";
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";
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";
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";
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";
864 if (strcmp(path,
"totem.interface.linknumber") == 0) {
866 if (safe_atoq(
value, &val, val_type) != 0) {
867 goto safe_atoq_error;
873 if (strcmp(path,
"totem.interface.bindnetaddr") == 0) {
878 if (strcmp(path,
"totem.interface.mcastaddr") == 0) {
883 if (strcmp(path,
"totem.interface.broadcast") == 0) {
888 if (strcmp(path,
"totem.interface.mcastport") == 0) {
890 if (safe_atoq(
value, &val, val_type) != 0) {
891 goto safe_atoq_error;
896 if (strcmp(path,
"totem.interface.ttl") == 0) {
898 if (safe_atoq(
value, &val, val_type) != 0) {
899 goto safe_atoq_error;
904 if (strcmp(path,
"totem.interface.knet_link_priority") == 0) {
906 if (safe_atoq(
value, &val, val_type) != 0) {
907 goto safe_atoq_error;
912 if (strcmp(path,
"totem.interface.knet_ping_interval") == 0) {
914 if (safe_atoq(
value, &val, val_type) != 0) {
915 goto safe_atoq_error;
920 if (strcmp(path,
"totem.interface.knet_ping_timeout") == 0) {
922 if (safe_atoq(
value, &val, val_type) != 0) {
923 goto safe_atoq_error;
928 if (strcmp(path,
"totem.interface.knet_ping_precision") == 0) {
930 if (safe_atoq(
value, &val, val_type) != 0) {
931 goto safe_atoq_error;
936 if (strcmp(path,
"totem.interface.knet_pong_count") == 0) {
938 if (safe_atoq(
value, &val, val_type) != 0) {
939 goto safe_atoq_error;
944 if (strcmp(path,
"totem.interface.knet_transport") == 0) {
951 if (strcmp(path,
"logging.logger_subsys.subsys") == 0) {
954 if (data->
subsys == NULL) {
955 *error_string =
"Can't alloc memory";
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";
968 kv_item = malloc(
sizeof(*kv_item));
969 if (kv_item == NULL) {
970 *error_string =
"Can't alloc memory";
974 memset(kv_item, 0,
sizeof(*kv_item));
976 kv_item->
key = strdup(path + strlen(path_prefix));
978 if (kv_item->
key == NULL || kv_item->
value == NULL) {
980 *error_string =
"Can't alloc memory";
984 qb_list_init(&kv_item->
list);
990 if (strcmp(path,
"logging.logging_daemon.subsys") == 0) {
993 if (data->
subsys == NULL) {
994 *error_string =
"Can't alloc memory";
998 }
else if (strcmp(path,
"logging.logging_daemon.name") == 0) {
1002 *error_string =
"Can't alloc memory";
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";
1015 kv_item = malloc(
sizeof(*kv_item));
1016 if (kv_item == NULL) {
1017 *error_string =
"Can't alloc memory";
1021 memset(kv_item, 0,
sizeof(*kv_item));
1023 kv_item->
key = strdup(path + strlen(path_prefix));
1025 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1027 *error_string =
"Can't alloc memory";
1031 qb_list_init(&kv_item->
list);
1037 if (strcmp(path,
"uidgid.uid") == 0) {
1038 uid = uid_determine(
value);
1040 *error_string = error_string_response;
1046 goto icmap_set_error;
1049 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1050 gid = gid_determine(
value);
1052 *error_string = error_string_response;
1058 goto icmap_set_error;
1062 *error_string =
"uidgid: Only uid and gid are allowed items";
1067 if (strcmp(path,
"totem.interface.member.memberaddr") != 0) {
1068 *error_string =
"Only memberaddr is allowed in member section";
1073 kv_item = malloc(
sizeof(*kv_item));
1074 if (kv_item == NULL) {
1075 *error_string =
"Can't alloc memory";
1079 memset(kv_item, 0,
sizeof(*kv_item));
1081 kv_item->
key = strdup(key);
1083 if (kv_item->
key == NULL || kv_item->
value == NULL) {
1085 *error_string =
"Can't alloc memory";
1089 qb_list_init(&kv_item->
list);
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";
1105 path + strlen(path_prefix));
1106 if ((strcmp(path,
"nodelist.node.nodeid") == 0) ||
1107 (strcmp(path,
"nodelist.node.quorum_votes") == 0)) {
1109 if (safe_atoq(
value, &val, val_type) != 0) {
1110 goto safe_atoq_error;
1114 goto icmap_set_error;
1119 if (add_as_string) {
1121 goto icmap_set_error;
1127 if (strcmp(key,
"watchdog_timeout") == 0) {
1129 if (safe_atoq(
value, &val, val_type) != 0) {
1130 goto safe_atoq_error;
1133 goto icmap_set_error;
1140 if (strcmp(key,
"poll_period") == 0) {
1141 if (str_to_ull(
value, &ull) != 0) {
1142 goto str_to_ull_error;
1145 goto icmap_set_error;
1152 if (strcmp(key,
"poll_period") == 0) {
1153 if (str_to_ull(
value, &ull) != 0) {
1154 goto str_to_ull_error;
1157 goto icmap_set_error;
1164 if (add_as_string) {
1166 goto icmap_set_error;
1171 if (strcmp(path,
"totem.interface") == 0) {
1184 if (strcmp(path,
"totem") == 0) {
1187 if (strcmp(path,
"system") == 0) {
1190 if (strcmp(path,
"logging.logger_subsys") == 0) {
1195 if (strcmp(path,
"logging.logging_daemon") == 0) {
1201 if (strcmp(path,
"uidgid") == 0) {
1204 if (strcmp(path,
"totem.interface.member") == 0) {
1207 if (strcmp(path,
"quorum") == 0) {
1210 if (strcmp(path,
"quorum.device") == 0) {
1213 if (strcmp(path,
"nodelist") == 0) {
1217 if (strcmp(path,
"nodelist.node") == 0) {
1220 if (strcmp(path,
"resources") == 0) {
1223 if (strcmp(path,
"resources.system") == 0) {
1226 if (strcmp(path,
"resources.system.memory_used") == 0) {
1229 if (strcmp(path,
"resources.process") == 0) {
1232 if (strcmp(path,
"resources.process.memory_used") == 0) {
1237 *error_string =
"Subsections are not allowed within uidgid section";
1243 *error_string =
"Subsections are not allowed within totem.interface.member section";
1251 if (strcmp(path,
"totem.interface") != 0) {
1269 if (cs_err !=
CS_OK) {
1270 goto icmap_set_error;
1282 if (cs_err !=
CS_OK) {
1283 goto icmap_set_error;
1295 if (cs_err !=
CS_OK) {
1296 goto icmap_set_error;
1305 goto icmap_set_error;
1309 if (data->
ttl > -1) {
1313 goto icmap_set_error;
1321 goto icmap_set_error;
1329 goto icmap_set_error;
1337 goto icmap_set_error;
1345 goto icmap_set_error;
1353 goto icmap_set_error;
1363 if (cs_err !=
CS_OK) {
1364 goto icmap_set_error;
1372 qb_list_del(&kv_item->
list);
1378 free(kv_item->
value);
1383 if (cs_err !=
CS_OK) {
1384 goto icmap_set_error;
1392 if (strcmp(path,
"logging.logger_subsys") != 0) {
1399 if (data->
subsys == NULL) {
1400 *error_string =
"No subsys key in logger_subsys directive";
1407 qb_list_del(&kv_item->
list);
1413 free(kv_item->
value);
1417 if (cs_err !=
CS_OK) {
1418 goto icmap_set_error;
1430 if (cs_err !=
CS_OK) {
1431 goto icmap_set_error;
1435 if (strcmp(path,
"logging.logging_daemon") != 0) {
1443 *error_string =
"No name key in logging_daemon directive";
1450 qb_list_del(&kv_item->
list);
1452 if (data->
subsys == NULL) {
1459 "logging.logging_daemon.%s.%s",
1465 "logging.logger_subsys.%s.%s",
1470 "logging.logging_daemon.%s.%s.%s",
1477 free(kv_item->
value);
1481 if (cs_err !=
CS_OK) {
1482 goto icmap_set_error;
1486 if (data->
subsys == NULL) {
1503 if (cs_err !=
CS_OK) {
1504 goto icmap_set_error;
1518 if (cs_err !=
CS_OK) {
1519 goto icmap_set_error;
1523 if (strcmp(path,
"nodelist.node") != 0) {
1557 min_val = max_val = 0;
1562 assert(safe_atoq_range(val_type, &min_val, &max_val) == 0);
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";
1569 *error_string = formated_err;
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";
1583 *error_string = formated_err;
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";
1594 *error_string = formated_err;
1600 static int uidgid_config_parser_cb(
const char *path,
1605 const char **error_string,
1611 static char formated_err[256];
1622 if (strcmp(path,
"uidgid.uid") == 0) {
1623 uid = uid_determine(
value);
1625 *error_string = error_string_response;
1631 goto icmap_set_error;
1633 }
else if (strcmp(path,
"uidgid.gid") == 0) {
1634 gid = gid_determine(
value);
1636 *error_string = error_string_response;
1642 goto icmap_set_error;
1645 *error_string =
"uidgid: Only uid and gid are allowed items";
1650 if (strcmp(path,
"uidgid") != 0) {
1651 *error_string =
"uidgid: Can't add subsection different than uidgid";
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";
1667 *error_string = formated_err;
1673 static int read_uidgid_files_into_icmap(
1674 const char **error_string,
1680 struct dirent *dirent;
1681 char filename[PATH_MAX + FILENAME_MAX + 1];
1682 char uidgid_dirname[PATH_MAX + FILENAME_MAX + 1];
1684 struct stat stat_buf;
1692 res = snprintf(filename,
sizeof(filename),
"%s",
1694 if (res >=
sizeof(filename)) {
1695 *error_string =
"uidgid.d path too long";
1700 dirname_res = dirname(filename);
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";
1710 dp = opendir (uidgid_dirname);
1715 for (dirent = readdir(dp);
1717 dirent = readdir(dp)) {
1719 res = snprintf(filename,
sizeof (filename),
"%s/%s", uidgid_dirname, dirent->d_name);
1720 if (res >=
sizeof(filename)) {
1722 *error_string =
"uidgid.d dirname path too long";
1726 res = stat (filename, &stat_buf);
1727 if (res == 0 && S_ISREG(stat_buf.st_mode)) {
1729 fp = fopen (filename,
"r");
1730 if (fp == NULL)
continue;
1735 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1736 uidgid_config_parser_cb, config_map, NULL);
1753 static int read_config_file_into_icmap(
1754 const char **error_string,
1758 const char *filename;
1759 char *error_reason = error_string_response;
1768 fp = fopen (filename,
"r");
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;
1782 res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
1783 main_config_parser_cb, config_map, &data);
1788 res = read_uidgid_files_into_icmap(error_string, config_map);
1792 snprintf (error_reason,
sizeof(error_string_response),
1793 "Successfully read main configuration file '%s'.", filename);
1794 *error_string = error_reason;