mainconfig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@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 <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <sys/socket.h>
  41. #include <netinet/in.h>
  42. #include <arpa/inet.h>
  43. #include <pwd.h>
  44. #include <grp.h>
  45. #include <limits.h>
  46. #include <corosync/corotypes.h>
  47. #include <corosync/list.h>
  48. #include <corosync/totem/totem.h>
  49. #include <corosync/engine/logsys.h>
  50. #include "util.h"
  51. #include "mainconfig.h"
  52. static char error_string_response[512];
  53. static struct objdb_iface_ver0 *global_objdb;
  54. /* This just makes the code below a little neater */
  55. static inline int objdb_get_string (
  56. const struct objdb_iface_ver0 *objdb,
  57. hdb_handle_t object_service_handle,
  58. const char *key, char **value)
  59. {
  60. int res;
  61. *value = NULL;
  62. if ( !(res = objdb->object_key_get (object_service_handle,
  63. key,
  64. strlen (key),
  65. (void *)value,
  66. NULL))) {
  67. if (*value) {
  68. return 0;
  69. }
  70. }
  71. return -1;
  72. }
  73. static inline void objdb_get_int (
  74. const struct objdb_iface_ver0 *objdb,
  75. hdb_handle_t object_service_handle,
  76. char *key, unsigned int *intvalue)
  77. {
  78. char *value = NULL;
  79. if (!objdb->object_key_get (object_service_handle,
  80. key,
  81. strlen (key),
  82. (void *)&value,
  83. NULL)) {
  84. if (value) {
  85. *intvalue = atoi(value);
  86. }
  87. }
  88. }
  89. /**
  90. * insert_into_buffer
  91. * @target_buffer: a buffer where to write results
  92. * @bufferlen: tell us the size of the buffer to avoid overflows
  93. * @entry: entry that needs to be added to the buffer
  94. * @after: can either be NULL or set to a string.
  95. * if NULL, @entry is prependend to logsys_format_get buffer.
  96. * if set, @entry is added immediately after @after.
  97. *
  98. * Since the function is specific to logsys_format_get handling, it is implicit
  99. * that source is logsys_format_get();
  100. *
  101. * In case of failure, target_buffer could be left dirty. So don't trust
  102. * any data leftover in it.
  103. *
  104. * Searching for "after" assumes that there is only entry of "after"
  105. * in the source. Afterall we control the string here and for logging format
  106. * it makes little to no sense to have duplicate format entries.
  107. *
  108. * Returns: 0 on success, -1 on failure
  109. **/
  110. static int insert_into_buffer(
  111. char *target_buffer,
  112. size_t bufferlen,
  113. const char *entry,
  114. const char *after)
  115. {
  116. const char *current_format = NULL;
  117. current_format = logsys_format_get();
  118. /* if the entry is already in the format we don't add it again */
  119. if (strstr(current_format, entry) != NULL) {
  120. return -1;
  121. }
  122. /* if there is no "after", simply prepend the requested entry
  123. * otherwise go for beautiful string manipulation.... </sarcasm> */
  124. if (!after) {
  125. if (snprintf(target_buffer, bufferlen - 1, "%s%s",
  126. entry,
  127. current_format) >= bufferlen - 1) {
  128. return -1;
  129. }
  130. } else {
  131. const char *afterpos;
  132. size_t afterlen;
  133. size_t templen;
  134. /* check if after is contained in the format
  135. * and afterlen has a meaning or return an error */
  136. afterpos = strstr(current_format, after);
  137. afterlen = strlen(after);
  138. if ((!afterpos) || (!afterlen)) {
  139. return -1;
  140. }
  141. templen = afterpos - current_format + afterlen;
  142. if (snprintf(target_buffer, templen + 1, "%s", current_format)
  143. >= bufferlen - 1) {
  144. return -1;
  145. }
  146. if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
  147. "%s%s", entry, current_format + templen)
  148. >= bufferlen - ( templen + 1 )) {
  149. return -1;
  150. }
  151. }
  152. return 0;
  153. }
  154. /*
  155. * format set is the only global specific option that
  156. * doesn't apply at system/subsystem level.
  157. */
  158. static int corosync_main_config_format_set (
  159. struct objdb_iface_ver0 *objdb,
  160. hdb_handle_t object_handle,
  161. const char **error_string)
  162. {
  163. const char *error_reason;
  164. char new_format_buffer[PATH_MAX];
  165. char *value;
  166. int err = 0;
  167. if (!objdb_get_string (objdb,object_handle, "fileline", &value)) {
  168. if (strcmp (value, "on") == 0) {
  169. if (!insert_into_buffer(new_format_buffer,
  170. sizeof(new_format_buffer),
  171. " %f:%l", "s]")) {
  172. err = logsys_format_set(new_format_buffer);
  173. } else
  174. if (!insert_into_buffer(new_format_buffer,
  175. sizeof(new_format_buffer),
  176. "%f:%l", NULL)) {
  177. err = logsys_format_set(new_format_buffer);
  178. }
  179. } else
  180. if (strcmp (value, "off") == 0) {
  181. /* nothing to do here */
  182. } else {
  183. error_reason = "unknown value for fileline";
  184. goto parse_error;
  185. }
  186. }
  187. if (!objdb_get_string (objdb,object_handle, "function_name", &value)) {
  188. if (strcmp (value, "on") == 0) {
  189. if (!insert_into_buffer(new_format_buffer,
  190. sizeof(new_format_buffer),
  191. "%n:", "f:")) {
  192. err = logsys_format_set(new_format_buffer);
  193. } else
  194. if (!insert_into_buffer(new_format_buffer,
  195. sizeof(new_format_buffer),
  196. " %n", "s]")) {
  197. err = logsys_format_set(new_format_buffer);
  198. }
  199. } else
  200. if (strcmp (value, "off") == 0) {
  201. /* nothing to do here */
  202. } else {
  203. error_reason = "unknown value for function_name";
  204. goto parse_error;
  205. }
  206. }
  207. if (!objdb_get_string (objdb,object_handle, "timestamp", &value)) {
  208. if (strcmp (value, "on") == 0) {
  209. if(!insert_into_buffer(new_format_buffer,
  210. sizeof(new_format_buffer),
  211. "%t ", NULL)) {
  212. err = logsys_format_set(new_format_buffer);
  213. }
  214. } else
  215. if (strcmp (value, "off") == 0) {
  216. /* nothing to do here */
  217. } else {
  218. error_reason = "unknown value for timestamp";
  219. goto parse_error;
  220. }
  221. }
  222. if (err) {
  223. error_reason = "exhausted virtual memory";
  224. goto parse_error;
  225. }
  226. return (0);
  227. parse_error:
  228. *error_string = error_reason;
  229. return (-1);
  230. }
  231. static char * strsep_cs(char **stringp, const char *delim)
  232. {
  233. char *s;
  234. const char *spanp;
  235. int c, sc;
  236. char *tok;
  237. if ((s = *stringp) == NULL) {
  238. return (NULL);
  239. }
  240. for (tok = s; ; ) {
  241. c = *s++;
  242. spanp = delim;
  243. do {
  244. if ((sc = *spanp++) == c) {
  245. if (c == 0) {
  246. s = NULL;
  247. }
  248. else {
  249. s[-1] = 0;
  250. }
  251. *stringp = s;
  252. return (tok);
  253. }
  254. } while (sc != 0);
  255. }
  256. }
  257. static int corosync_main_config_set (
  258. struct objdb_iface_ver0 *objdb,
  259. hdb_handle_t object_handle,
  260. const char *subsys,
  261. const char **error_string)
  262. {
  263. const char *error_reason = error_string_response;
  264. char *value;
  265. unsigned int mode;
  266. /*
  267. * this bit abuses the internal logsys exported API
  268. * to guarantee that all configured subsystems are
  269. * initialized too.
  270. *
  271. * using this approach avoids some headaches caused
  272. * by IPC and TOTEM that have a special logging
  273. * handling requirements
  274. */
  275. if (subsys != NULL) {
  276. if (_logsys_subsys_create(subsys) < 0) {
  277. error_reason = "unable to create new logging subsystem";
  278. goto parse_error;
  279. }
  280. }
  281. mode = logsys_config_mode_get(subsys);
  282. if (mode < 0) {
  283. error_reason = "unable to get mode";
  284. goto parse_error;
  285. }
  286. if (!objdb_get_string (objdb,object_handle, "to_file", &value)) {
  287. log_printf(LOGSYS_LEVEL_WARNING,
  288. "Warning: the to_file config paramater has been obsoleted."
  289. " See corosync.conf man page to_logfile directive.");
  290. if (strcmp (value, "yes") == 0) {
  291. mode |= LOGSYS_MODE_OUTPUT_FILE;
  292. if (logsys_config_mode_set(subsys, mode) < 0) {
  293. error_reason = "unable to set mode to_file";
  294. goto parse_error;
  295. }
  296. } else
  297. if (strcmp (value, "no") == 0) {
  298. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  299. if (logsys_config_mode_set(subsys, mode) < 0) {
  300. error_reason = "unable to unset mode to_file";
  301. goto parse_error;
  302. }
  303. } else {
  304. error_reason = "unknown value for to_file";
  305. goto parse_error;
  306. }
  307. }
  308. if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
  309. if (strcmp (value, "yes") == 0) {
  310. mode |= LOGSYS_MODE_OUTPUT_FILE;
  311. if (logsys_config_mode_set(subsys, mode) < 0) {
  312. error_reason = "unable to set mode to_logfile";
  313. goto parse_error;
  314. }
  315. } else
  316. if (strcmp (value, "no") == 0) {
  317. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  318. if (logsys_config_mode_set(subsys, mode) < 0) {
  319. error_reason = "unable to unset mode to_logfile";
  320. goto parse_error;
  321. }
  322. } else {
  323. error_reason = "unknown value for to_logfile";
  324. goto parse_error;
  325. }
  326. }
  327. if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
  328. if (strcmp (value, "yes") == 0) {
  329. mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
  330. if (logsys_config_mode_set(subsys, mode) < 0) {
  331. error_reason = "unable to set mode to_syslog";
  332. goto parse_error;
  333. }
  334. } else
  335. if (strcmp (value, "no") == 0) {
  336. mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
  337. if (logsys_config_mode_set(subsys, mode) < 0) {
  338. error_reason = "unable to unset mode to_syslog";
  339. goto parse_error;
  340. }
  341. } else {
  342. error_reason = "unknown value for to_syslog";
  343. goto parse_error;
  344. }
  345. }
  346. if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
  347. if (strcmp (value, "yes") == 0) {
  348. mode |= LOGSYS_MODE_OUTPUT_STDERR;
  349. if (logsys_config_mode_set(subsys, mode) < 0) {
  350. error_reason = "unable to set mode to_stderr";
  351. goto parse_error;
  352. }
  353. } else
  354. if (strcmp (value, "no") == 0) {
  355. mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
  356. if (logsys_config_mode_set(subsys, mode) < 0) {
  357. error_reason = "unable to unset mode to_stderr";
  358. goto parse_error;
  359. }
  360. } else {
  361. error_reason = "unknown value for to_syslog";
  362. goto parse_error;
  363. }
  364. }
  365. if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
  366. int syslog_facility;
  367. syslog_facility = logsys_facility_id_get(value);
  368. if (syslog_facility < 0) {
  369. error_reason = "unknown syslog facility specified";
  370. goto parse_error;
  371. }
  372. if (logsys_config_syslog_facility_set(subsys,
  373. syslog_facility) < 0) {
  374. error_reason = "unable to set syslog facility";
  375. goto parse_error;
  376. }
  377. }
  378. if (!objdb_get_string (objdb,object_handle, "syslog_level", &value)) {
  379. int syslog_priority;
  380. log_printf(LOGSYS_LEVEL_WARNING,
  381. "Warning: the syslog_level config paramater has been obsoleted."
  382. " See corosync.conf man page syslog_priority directive.");
  383. syslog_priority = logsys_priority_id_get(value);
  384. if (syslog_priority < 0) {
  385. error_reason = "unknown syslog level specified";
  386. goto parse_error;
  387. }
  388. if (logsys_config_syslog_priority_set(subsys,
  389. syslog_priority) < 0) {
  390. error_reason = "unable to set syslog level";
  391. goto parse_error;
  392. }
  393. }
  394. if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
  395. int syslog_priority;
  396. syslog_priority = logsys_priority_id_get(value);
  397. if (syslog_priority < 0) {
  398. error_reason = "unknown syslog priority specified";
  399. goto parse_error;
  400. }
  401. if (logsys_config_syslog_priority_set(subsys,
  402. syslog_priority) < 0) {
  403. error_reason = "unable to set syslog priority";
  404. goto parse_error;
  405. }
  406. }
  407. if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
  408. if (logsys_config_file_set (subsys, error_string, value) < 0) {
  409. goto parse_error;
  410. }
  411. }
  412. if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
  413. int logfile_priority;
  414. logfile_priority = logsys_priority_id_get(value);
  415. if (logfile_priority < 0) {
  416. error_reason = "unknown logfile priority specified";
  417. goto parse_error;
  418. }
  419. if (logsys_config_logfile_priority_set(subsys,
  420. logfile_priority) < 0) {
  421. error_reason = "unable to set logfile priority";
  422. goto parse_error;
  423. }
  424. }
  425. if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
  426. if (strcmp (value, "on") == 0) {
  427. if (logsys_config_debug_set (subsys, 1) < 0) {
  428. error_reason = "unable to set debug on";
  429. goto parse_error;
  430. }
  431. } else
  432. if (strcmp (value, "off") == 0) {
  433. if (logsys_config_debug_set (subsys, 0) < 0) {
  434. error_reason = "unable to set debug off";
  435. goto parse_error;
  436. }
  437. } else {
  438. error_reason = "unknown value for debug";
  439. goto parse_error;
  440. }
  441. }
  442. if (!objdb_get_string (objdb, object_handle, "tags", &value)) {
  443. char *temp, *token;
  444. unsigned int tags = 0;
  445. temp = strdup(value);
  446. if (temp == NULL) {
  447. error_reason = "exhausted virtual memory";
  448. goto parse_error;
  449. }
  450. while ((token = strsep_cs(&temp, "|")) != NULL) {
  451. int val;
  452. val = logsys_tag_id_get(token);
  453. if (val < 0) {
  454. error_reason = "bad tags value";
  455. goto parse_error;
  456. }
  457. tags |= val;
  458. }
  459. free(temp);
  460. tags |= LOGSYS_TAG_LOG;
  461. if (logsys_config_tags_set (subsys, tags) < 0) {
  462. error_reason = "unable to set tags";
  463. goto parse_error;
  464. }
  465. }
  466. return (0);
  467. parse_error:
  468. *error_string = error_reason;
  469. return (-1);
  470. }
  471. static int corosync_main_config_read_logging (
  472. struct objdb_iface_ver0 *objdb,
  473. const char **error_string)
  474. {
  475. hdb_handle_t object_service_handle;
  476. hdb_handle_t object_logger_subsys_handle;
  477. hdb_handle_t object_find_handle;
  478. hdb_handle_t object_find_logsys_handle;
  479. const char *error_reason;
  480. char *value;
  481. objdb->object_find_create (
  482. OBJECT_PARENT_HANDLE,
  483. "logging",
  484. strlen ("logging"),
  485. &object_find_handle);
  486. if (objdb->object_find_next (
  487. object_find_handle,
  488. &object_service_handle) == 0) {
  489. /* format set is supported only for toplevel */
  490. if (corosync_main_config_format_set (objdb,
  491. object_service_handle,
  492. &error_reason) < 0) {
  493. goto parse_error;
  494. }
  495. if (corosync_main_config_set (objdb,
  496. object_service_handle,
  497. NULL,
  498. &error_reason) < 0) {
  499. goto parse_error;
  500. }
  501. /* we will need 2 of these to compensate for new logging
  502. * config format */
  503. objdb->object_find_create (
  504. object_service_handle,
  505. "logger_subsys",
  506. strlen ("logger_subsys"),
  507. &object_find_logsys_handle);
  508. while (objdb->object_find_next (
  509. object_find_logsys_handle,
  510. &object_logger_subsys_handle) == 0) {
  511. if (!objdb_get_string (objdb,
  512. object_logger_subsys_handle,
  513. "subsys", &value)) {
  514. if (corosync_main_config_set (objdb,
  515. object_logger_subsys_handle,
  516. value,
  517. &error_reason) < 0) {
  518. goto parse_error;
  519. }
  520. }
  521. else {
  522. error_reason = "subsys required for logger directive";
  523. goto parse_error;
  524. }
  525. }
  526. objdb->object_find_destroy (object_find_logsys_handle);
  527. objdb->object_find_create (
  528. object_service_handle,
  529. "logging_daemon",
  530. strlen ("logging_daemon"),
  531. &object_find_logsys_handle);
  532. while (objdb->object_find_next (
  533. object_find_logsys_handle,
  534. &object_logger_subsys_handle) == 0) {
  535. if (!objdb_get_string (objdb,
  536. object_logger_subsys_handle,
  537. "name", &value)) {
  538. if ((strcmp(value, "corosync") == 0) &&
  539. (!objdb_get_string (objdb,
  540. object_logger_subsys_handle,
  541. "subsys", &value))) {
  542. if (corosync_main_config_set (objdb,
  543. object_logger_subsys_handle,
  544. value,
  545. &error_reason) < 0) {
  546. goto parse_error;
  547. }
  548. }
  549. else {
  550. error_reason = "subsys required for logging_daemon directive";
  551. goto parse_error;
  552. }
  553. }
  554. else {
  555. error_reason = "name required for logging_daemon directive";
  556. goto parse_error;
  557. }
  558. }
  559. objdb->object_find_destroy (object_find_logsys_handle);
  560. }
  561. objdb->object_find_destroy (object_find_handle);
  562. return 0;
  563. parse_error:
  564. *error_string = error_reason;
  565. return (-1);
  566. }
  567. static int uid_determine (const char *req_user)
  568. {
  569. struct passwd *passwd;
  570. int ais_uid = 0;
  571. passwd = getpwnam(req_user);
  572. if (passwd == 0) {
  573. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
  574. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  575. }
  576. ais_uid = passwd->pw_uid;
  577. endpwent ();
  578. return ais_uid;
  579. }
  580. static int gid_determine (const char *req_group)
  581. {
  582. struct group *group;
  583. int ais_gid = 0;
  584. group = getgrnam (req_group);
  585. if (group == 0) {
  586. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
  587. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  588. }
  589. ais_gid = group->gr_gid;
  590. endgrent ();
  591. return ais_gid;
  592. }
  593. static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
  594. void *priv_data_pt)
  595. {
  596. const char *error_string;
  597. if (type == OBJDB_RELOAD_NOTIFY_END) {
  598. /*
  599. * Reload the logsys configuration
  600. */
  601. logsys_format_set(NULL);
  602. corosync_main_config_read_logging(global_objdb,
  603. &error_string);
  604. }
  605. }
  606. static void add_logsys_config_notification(
  607. struct objdb_iface_ver0 *objdb)
  608. {
  609. global_objdb = objdb;
  610. objdb->object_track_start(OBJECT_PARENT_HANDLE,
  611. 1,
  612. NULL,
  613. NULL,
  614. NULL,
  615. main_objdb_reload_notify,
  616. NULL);
  617. }
  618. static int corosync_main_config_read_uidgid (
  619. struct objdb_iface_ver0 *objdb,
  620. const char **error_string,
  621. struct ug_config *ug_config)
  622. {
  623. hdb_handle_t object_find_handle;
  624. hdb_handle_t object_service_handle;
  625. char *value;
  626. int uid, gid;
  627. struct uidgid_item *ugi;
  628. list_init (&ug_config->uidgid_list);
  629. objdb->object_find_create (
  630. OBJECT_PARENT_HANDLE,
  631. "uidgid",
  632. strlen ("uidgid"),
  633. &object_find_handle);
  634. while (objdb->object_find_next (
  635. object_find_handle,
  636. &object_service_handle) == 0) {
  637. uid = -1;
  638. gid = -1;
  639. if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
  640. uid = uid_determine(value);
  641. }
  642. if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
  643. gid = gid_determine(value);
  644. }
  645. if (uid > -1 || gid > -1) {
  646. ugi = malloc (sizeof (*ugi));
  647. if (ugi == NULL) {
  648. _corosync_out_of_memory_error();
  649. }
  650. ugi->uid = uid;
  651. ugi->gid = gid;
  652. list_add (&ugi->list, &ug_config->uidgid_list);
  653. }
  654. }
  655. objdb->object_find_destroy (object_find_handle);
  656. return 0;
  657. }
  658. int corosync_main_config_read (
  659. struct objdb_iface_ver0 *objdb,
  660. const char **error_string,
  661. struct ug_config *ug_config)
  662. {
  663. hdb_handle_t object_service_handle;
  664. char *value;
  665. const char *error_reason = error_string_response;
  666. hdb_handle_t object_find_handle;
  667. memset (ug_config, 0, sizeof (struct ug_config));
  668. if (corosync_main_config_read_logging(objdb, error_string) < 0) {
  669. error_reason = *error_string;
  670. goto parse_error;
  671. }
  672. ug_config->uid = -1;
  673. ug_config->gid = -1;
  674. objdb->object_find_create (
  675. OBJECT_PARENT_HANDLE,
  676. "aisexec",
  677. strlen ("aisexec"),
  678. &object_find_handle);
  679. if (objdb->object_find_next (
  680. object_find_handle,
  681. &object_service_handle) == 0) {
  682. if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
  683. ug_config->uid = uid_determine(value);
  684. }
  685. if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
  686. ug_config->gid = gid_determine(value);
  687. }
  688. }
  689. objdb->object_find_destroy (object_find_handle);
  690. if (ug_config->uid < 0) {
  691. ug_config->uid = uid_determine("ais");
  692. }
  693. if (ug_config->gid < 0) {
  694. ug_config->gid = gid_determine("ais");
  695. }
  696. corosync_main_config_read_uidgid (objdb, error_string, ug_config);
  697. add_logsys_config_notification(objdb);
  698. return 0;
  699. parse_error:
  700. snprintf (error_string_response, sizeof(error_string_response),
  701. "parse error in config: %s.\n",
  702. error_reason);
  703. *error_string = error_string_response;
  704. return (-1);
  705. }