mainconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 int corosync_main_config_set (
  232. struct objdb_iface_ver0 *objdb,
  233. hdb_handle_t object_handle,
  234. const char *subsys,
  235. const char **error_string)
  236. {
  237. const char *error_reason = error_string_response;
  238. char *value;
  239. unsigned int mode;
  240. /*
  241. * this bit abuses the internal logsys exported API
  242. * to guarantee that all configured subsystems are
  243. * initialized too.
  244. *
  245. * using this approach avoids some headaches caused
  246. * by IPC and TOTEM that have a special logging
  247. * handling requirements
  248. */
  249. if (subsys != NULL) {
  250. if (_logsys_subsys_create(subsys) < 0) {
  251. error_reason = "unable to create new logging subsystem";
  252. goto parse_error;
  253. }
  254. }
  255. mode = logsys_config_mode_get(subsys);
  256. if (mode < 0) {
  257. error_reason = "unable to get mode";
  258. goto parse_error;
  259. }
  260. if (!objdb_get_string (objdb,object_handle, "to_file", &value)) {
  261. log_printf(LOGSYS_LEVEL_WARNING,
  262. "Warning: the to_file config paramater has been obsoleted."
  263. " See corosync.conf man page to_logfile directive.");
  264. if (strcmp (value, "yes") == 0) {
  265. mode |= LOGSYS_MODE_OUTPUT_FILE;
  266. if (logsys_config_mode_set(subsys, mode) < 0) {
  267. error_reason = "unable to set mode to_file";
  268. goto parse_error;
  269. }
  270. } else
  271. if (strcmp (value, "no") == 0) {
  272. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  273. if (logsys_config_mode_set(subsys, mode) < 0) {
  274. error_reason = "unable to unset mode to_file";
  275. goto parse_error;
  276. }
  277. } else {
  278. error_reason = "unknown value for to_file";
  279. goto parse_error;
  280. }
  281. }
  282. if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
  283. if (strcmp (value, "yes") == 0) {
  284. mode |= LOGSYS_MODE_OUTPUT_FILE;
  285. if (logsys_config_mode_set(subsys, mode) < 0) {
  286. error_reason = "unable to set mode to_logfile";
  287. goto parse_error;
  288. }
  289. } else
  290. if (strcmp (value, "no") == 0) {
  291. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  292. if (logsys_config_mode_set(subsys, mode) < 0) {
  293. error_reason = "unable to unset mode to_logfile";
  294. goto parse_error;
  295. }
  296. } else {
  297. error_reason = "unknown value for to_logfile";
  298. goto parse_error;
  299. }
  300. }
  301. if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
  302. if (strcmp (value, "yes") == 0) {
  303. mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
  304. if (logsys_config_mode_set(subsys, mode) < 0) {
  305. error_reason = "unable to set mode to_syslog";
  306. goto parse_error;
  307. }
  308. } else
  309. if (strcmp (value, "no") == 0) {
  310. mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
  311. if (logsys_config_mode_set(subsys, mode) < 0) {
  312. error_reason = "unable to unset mode to_syslog";
  313. goto parse_error;
  314. }
  315. } else {
  316. error_reason = "unknown value for to_syslog";
  317. goto parse_error;
  318. }
  319. }
  320. if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
  321. if (strcmp (value, "yes") == 0) {
  322. mode |= LOGSYS_MODE_OUTPUT_STDERR;
  323. if (logsys_config_mode_set(subsys, mode) < 0) {
  324. error_reason = "unable to set mode to_stderr";
  325. goto parse_error;
  326. }
  327. } else
  328. if (strcmp (value, "no") == 0) {
  329. mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
  330. if (logsys_config_mode_set(subsys, mode) < 0) {
  331. error_reason = "unable to unset mode to_stderr";
  332. goto parse_error;
  333. }
  334. } else {
  335. error_reason = "unknown value for to_syslog";
  336. goto parse_error;
  337. }
  338. }
  339. if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
  340. int syslog_facility;
  341. syslog_facility = logsys_facility_id_get(value);
  342. if (syslog_facility < 0) {
  343. error_reason = "unknown syslog facility specified";
  344. goto parse_error;
  345. }
  346. if (logsys_config_syslog_facility_set(subsys,
  347. syslog_facility) < 0) {
  348. error_reason = "unable to set syslog facility";
  349. goto parse_error;
  350. }
  351. }
  352. if (!objdb_get_string (objdb,object_handle, "syslog_level", &value)) {
  353. int syslog_priority;
  354. log_printf(LOGSYS_LEVEL_WARNING,
  355. "Warning: the syslog_level config paramater has been obsoleted."
  356. " See corosync.conf man page syslog_priority directive.");
  357. syslog_priority = logsys_priority_id_get(value);
  358. if (syslog_priority < 0) {
  359. error_reason = "unknown syslog level specified";
  360. goto parse_error;
  361. }
  362. if (logsys_config_syslog_priority_set(subsys,
  363. syslog_priority) < 0) {
  364. error_reason = "unable to set syslog level";
  365. goto parse_error;
  366. }
  367. }
  368. if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
  369. int syslog_priority;
  370. syslog_priority = logsys_priority_id_get(value);
  371. if (syslog_priority < 0) {
  372. error_reason = "unknown syslog priority specified";
  373. goto parse_error;
  374. }
  375. if (logsys_config_syslog_priority_set(subsys,
  376. syslog_priority) < 0) {
  377. error_reason = "unable to set syslog priority";
  378. goto parse_error;
  379. }
  380. }
  381. if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
  382. if (logsys_config_file_set (subsys, error_string, value) < 0) {
  383. goto parse_error;
  384. }
  385. }
  386. if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
  387. int logfile_priority;
  388. logfile_priority = logsys_priority_id_get(value);
  389. if (logfile_priority < 0) {
  390. error_reason = "unknown logfile priority specified";
  391. goto parse_error;
  392. }
  393. if (logsys_config_logfile_priority_set(subsys,
  394. logfile_priority) < 0) {
  395. error_reason = "unable to set logfile priority";
  396. goto parse_error;
  397. }
  398. }
  399. if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
  400. if (strcmp (value, "on") == 0) {
  401. if (logsys_config_debug_set (subsys, 1) < 0) {
  402. error_reason = "unable to set debug on";
  403. goto parse_error;
  404. }
  405. } else
  406. if (strcmp (value, "off") == 0) {
  407. if (logsys_config_debug_set (subsys, 0) < 0) {
  408. error_reason = "unable to set debug off";
  409. goto parse_error;
  410. }
  411. } else {
  412. error_reason = "unknown value for debug";
  413. goto parse_error;
  414. }
  415. }
  416. return (0);
  417. parse_error:
  418. *error_string = error_reason;
  419. return (-1);
  420. }
  421. static int corosync_main_config_read_logging (
  422. struct objdb_iface_ver0 *objdb,
  423. const char **error_string)
  424. {
  425. hdb_handle_t object_service_handle;
  426. hdb_handle_t object_logger_subsys_handle;
  427. hdb_handle_t object_find_handle;
  428. hdb_handle_t object_find_logsys_handle;
  429. const char *error_reason;
  430. char *value;
  431. objdb->object_find_create (
  432. OBJECT_PARENT_HANDLE,
  433. "logging",
  434. strlen ("logging"),
  435. &object_find_handle);
  436. if (objdb->object_find_next (
  437. object_find_handle,
  438. &object_service_handle) == 0) {
  439. /* format set is supported only for toplevel */
  440. if (corosync_main_config_format_set (objdb,
  441. object_service_handle,
  442. &error_reason) < 0) {
  443. goto parse_error;
  444. }
  445. if (corosync_main_config_set (objdb,
  446. object_service_handle,
  447. NULL,
  448. &error_reason) < 0) {
  449. goto parse_error;
  450. }
  451. /* we will need 2 of these to compensate for new logging
  452. * config format */
  453. objdb->object_find_create (
  454. object_service_handle,
  455. "logger_subsys",
  456. strlen ("logger_subsys"),
  457. &object_find_logsys_handle);
  458. while (objdb->object_find_next (
  459. object_find_logsys_handle,
  460. &object_logger_subsys_handle) == 0) {
  461. if (!objdb_get_string (objdb,
  462. object_logger_subsys_handle,
  463. "subsys", &value)) {
  464. if (corosync_main_config_set (objdb,
  465. object_logger_subsys_handle,
  466. value,
  467. &error_reason) < 0) {
  468. goto parse_error;
  469. }
  470. }
  471. else {
  472. error_reason = "subsys required for logger directive";
  473. goto parse_error;
  474. }
  475. }
  476. objdb->object_find_destroy (object_find_logsys_handle);
  477. objdb->object_find_create (
  478. object_service_handle,
  479. "logging_daemon",
  480. strlen ("logging_daemon"),
  481. &object_find_logsys_handle);
  482. while (objdb->object_find_next (
  483. object_find_logsys_handle,
  484. &object_logger_subsys_handle) == 0) {
  485. if (!objdb_get_string (objdb,
  486. object_logger_subsys_handle,
  487. "name", &value)) {
  488. if ((strcmp(value, "corosync") == 0) &&
  489. (!objdb_get_string (objdb,
  490. object_logger_subsys_handle,
  491. "subsys", &value))) {
  492. if (corosync_main_config_set (objdb,
  493. object_logger_subsys_handle,
  494. value,
  495. &error_reason) < 0) {
  496. goto parse_error;
  497. }
  498. }
  499. else {
  500. error_reason = "subsys required for logging_daemon directive";
  501. goto parse_error;
  502. }
  503. }
  504. else {
  505. error_reason = "name required for logging_daemon directive";
  506. goto parse_error;
  507. }
  508. }
  509. objdb->object_find_destroy (object_find_logsys_handle);
  510. }
  511. objdb->object_find_destroy (object_find_handle);
  512. return 0;
  513. parse_error:
  514. *error_string = error_reason;
  515. return (-1);
  516. }
  517. static int uid_determine (const char *req_user)
  518. {
  519. struct passwd *passwd;
  520. int ais_uid = 0;
  521. passwd = getpwnam(req_user);
  522. if (passwd == 0) {
  523. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
  524. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  525. }
  526. ais_uid = passwd->pw_uid;
  527. endpwent ();
  528. return ais_uid;
  529. }
  530. static int gid_determine (const char *req_group)
  531. {
  532. struct group *group;
  533. int ais_gid = 0;
  534. group = getgrnam (req_group);
  535. if (group == 0) {
  536. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
  537. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  538. }
  539. ais_gid = group->gr_gid;
  540. endgrent ();
  541. return ais_gid;
  542. }
  543. static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
  544. void *priv_data_pt)
  545. {
  546. const char *error_string;
  547. if (type == OBJDB_RELOAD_NOTIFY_END) {
  548. /*
  549. * Reload the logsys configuration
  550. */
  551. logsys_format_set(NULL);
  552. corosync_main_config_read_logging(global_objdb,
  553. &error_string);
  554. }
  555. }
  556. static void add_logsys_config_notification(
  557. struct objdb_iface_ver0 *objdb)
  558. {
  559. global_objdb = objdb;
  560. objdb->object_track_start(OBJECT_PARENT_HANDLE,
  561. 1,
  562. NULL,
  563. NULL,
  564. NULL,
  565. main_objdb_reload_notify,
  566. NULL);
  567. }
  568. static int corosync_main_config_read_uidgid (
  569. struct objdb_iface_ver0 *objdb,
  570. const char **error_string,
  571. struct ug_config *ug_config)
  572. {
  573. hdb_handle_t object_find_handle;
  574. hdb_handle_t object_service_handle;
  575. char *value;
  576. int uid, gid;
  577. struct uidgid_item *ugi;
  578. list_init (&ug_config->uidgid_list);
  579. objdb->object_find_create (
  580. OBJECT_PARENT_HANDLE,
  581. "uidgid",
  582. strlen ("uidgid"),
  583. &object_find_handle);
  584. while (objdb->object_find_next (
  585. object_find_handle,
  586. &object_service_handle) == 0) {
  587. uid = -1;
  588. gid = -1;
  589. if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
  590. uid = uid_determine(value);
  591. }
  592. if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
  593. gid = gid_determine(value);
  594. }
  595. if (uid > -1 || gid > -1) {
  596. ugi = malloc (sizeof (*ugi));
  597. if (ugi == NULL) {
  598. _corosync_out_of_memory_error();
  599. }
  600. ugi->uid = uid;
  601. ugi->gid = gid;
  602. list_add (&ugi->list, &ug_config->uidgid_list);
  603. }
  604. }
  605. objdb->object_find_destroy (object_find_handle);
  606. return 0;
  607. }
  608. int corosync_main_config_read (
  609. struct objdb_iface_ver0 *objdb,
  610. const char **error_string,
  611. struct ug_config *ug_config)
  612. {
  613. hdb_handle_t object_service_handle;
  614. char *value;
  615. const char *error_reason = error_string_response;
  616. hdb_handle_t object_find_handle;
  617. memset (ug_config, 0, sizeof (struct ug_config));
  618. if (corosync_main_config_read_logging(objdb, error_string) < 0) {
  619. error_reason = *error_string;
  620. goto parse_error;
  621. }
  622. ug_config->uid = -1;
  623. ug_config->gid = -1;
  624. objdb->object_find_create (
  625. OBJECT_PARENT_HANDLE,
  626. "aisexec",
  627. strlen ("aisexec"),
  628. &object_find_handle);
  629. if (objdb->object_find_next (
  630. object_find_handle,
  631. &object_service_handle) == 0) {
  632. if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
  633. ug_config->uid = uid_determine(value);
  634. }
  635. if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
  636. ug_config->gid = gid_determine(value);
  637. }
  638. }
  639. objdb->object_find_destroy (object_find_handle);
  640. if (ug_config->uid < 0) {
  641. ug_config->uid = uid_determine("ais");
  642. }
  643. if (ug_config->gid < 0) {
  644. ug_config->gid = gid_determine("ais");
  645. }
  646. corosync_main_config_read_uidgid (objdb, error_string, ug_config);
  647. add_logsys_config_notification(objdb);
  648. return 0;
  649. parse_error:
  650. snprintf (error_string_response, sizeof(error_string_response),
  651. "parse error in config: %s.\n",
  652. error_reason);
  653. *error_string = error_string_response;
  654. return (-1);
  655. }