coroparse.c 49 KB

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