coroparse.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  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. // coverity[TOCTOU:SUPPRESS] not really problem
  1548. res = stat (filename, &stat_buf);
  1549. if (res == 0 && S_ISREG(stat_buf.st_mode)) {
  1550. fp = fopen (filename, "r");
  1551. if (fp == NULL) continue;
  1552. key_name[0] = 0;
  1553. line_no = 0;
  1554. res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
  1555. uidgid_config_parser_cb, config_map, NULL);
  1556. fclose (fp);
  1557. if (res != 0) {
  1558. goto error_exit;
  1559. }
  1560. }
  1561. }
  1562. error_exit:
  1563. closedir(dp);
  1564. return res;
  1565. }
  1566. /* Read config file and load into icmap */
  1567. static int read_config_file_into_icmap(
  1568. const char **error_string,
  1569. icmap_map_t config_map)
  1570. {
  1571. FILE *fp;
  1572. const char *filename;
  1573. char *error_reason = error_string_response;
  1574. int res;
  1575. char key_name[ICMAP_KEYNAME_MAXLEN];
  1576. struct main_cp_cb_data data;
  1577. enum main_cp_cb_data_state state = MAIN_CP_CB_DATA_STATE_NORMAL;
  1578. int line_no;
  1579. filename = corosync_get_config_file();
  1580. fp = fopen (filename, "r");
  1581. if (fp == NULL) {
  1582. char error_str[100];
  1583. const char *error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
  1584. snprintf (error_reason, sizeof(error_string_response),
  1585. "Can't read file %s: %s",
  1586. filename, error_ptr);
  1587. *error_string = error_reason;
  1588. return -1;
  1589. }
  1590. key_name[0] = 0;
  1591. line_no = 0;
  1592. res = parse_section(fp, filename, &line_no, key_name, error_string, 0, state,
  1593. main_config_parser_cb, config_map, &data);
  1594. fclose(fp);
  1595. if (res == 0) {
  1596. res = read_uidgid_files_into_icmap(error_string, config_map);
  1597. }
  1598. if (res == 0) {
  1599. snprintf (error_reason, sizeof(error_string_response),
  1600. "Successfully read main configuration file '%s'.", filename);
  1601. *error_string = error_reason;
  1602. }
  1603. return res;
  1604. }