mainconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. if (!objdb_get_string (objdb, object_handle, "tags", &value)) {
  417. char *temp, *token;
  418. unsigned int tags = 0;
  419. temp = strdup(value);
  420. if (temp == NULL) {
  421. error_reason = "exhausted virtual memory";
  422. goto parse_error;
  423. }
  424. while ((token = strsep(&temp, "|")) != NULL) {
  425. int val;
  426. val = logsys_tag_id_get(token);
  427. if (val < 0) {
  428. error_reason = "bad tags value";
  429. goto parse_error;
  430. }
  431. tags |= val;
  432. }
  433. free(temp);
  434. tags |= LOGSYS_TAG_LOG;
  435. if (logsys_config_tags_set (subsys, tags) < 0) {
  436. error_reason = "unable to set tags";
  437. goto parse_error;
  438. }
  439. }
  440. return (0);
  441. parse_error:
  442. *error_string = error_reason;
  443. return (-1);
  444. }
  445. static int corosync_main_config_read_logging (
  446. struct objdb_iface_ver0 *objdb,
  447. const char **error_string)
  448. {
  449. hdb_handle_t object_service_handle;
  450. hdb_handle_t object_logger_subsys_handle;
  451. hdb_handle_t object_find_handle;
  452. hdb_handle_t object_find_logsys_handle;
  453. const char *error_reason;
  454. char *value;
  455. objdb->object_find_create (
  456. OBJECT_PARENT_HANDLE,
  457. "logging",
  458. strlen ("logging"),
  459. &object_find_handle);
  460. if (objdb->object_find_next (
  461. object_find_handle,
  462. &object_service_handle) == 0) {
  463. /* format set is supported only for toplevel */
  464. if (corosync_main_config_format_set (objdb,
  465. object_service_handle,
  466. &error_reason) < 0) {
  467. goto parse_error;
  468. }
  469. if (corosync_main_config_set (objdb,
  470. object_service_handle,
  471. NULL,
  472. &error_reason) < 0) {
  473. goto parse_error;
  474. }
  475. /* we will need 2 of these to compensate for new logging
  476. * config format */
  477. objdb->object_find_create (
  478. object_service_handle,
  479. "logger_subsys",
  480. strlen ("logger_subsys"),
  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. "subsys", &value)) {
  488. if (corosync_main_config_set (objdb,
  489. object_logger_subsys_handle,
  490. value,
  491. &error_reason) < 0) {
  492. goto parse_error;
  493. }
  494. }
  495. else {
  496. error_reason = "subsys required for logger directive";
  497. goto parse_error;
  498. }
  499. }
  500. objdb->object_find_destroy (object_find_logsys_handle);
  501. objdb->object_find_create (
  502. object_service_handle,
  503. "logging_daemon",
  504. strlen ("logging_daemon"),
  505. &object_find_logsys_handle);
  506. while (objdb->object_find_next (
  507. object_find_logsys_handle,
  508. &object_logger_subsys_handle) == 0) {
  509. if (!objdb_get_string (objdb,
  510. object_logger_subsys_handle,
  511. "name", &value)) {
  512. if ((strcmp(value, "corosync") == 0) &&
  513. (!objdb_get_string (objdb,
  514. object_logger_subsys_handle,
  515. "subsys", &value))) {
  516. if (corosync_main_config_set (objdb,
  517. object_logger_subsys_handle,
  518. value,
  519. &error_reason) < 0) {
  520. goto parse_error;
  521. }
  522. }
  523. else {
  524. error_reason = "subsys required for logging_daemon directive";
  525. goto parse_error;
  526. }
  527. }
  528. else {
  529. error_reason = "name required for logging_daemon directive";
  530. goto parse_error;
  531. }
  532. }
  533. objdb->object_find_destroy (object_find_logsys_handle);
  534. }
  535. objdb->object_find_destroy (object_find_handle);
  536. return 0;
  537. parse_error:
  538. *error_string = error_reason;
  539. return (-1);
  540. }
  541. static int uid_determine (const char *req_user)
  542. {
  543. struct passwd *passwd;
  544. int ais_uid = 0;
  545. passwd = getpwnam(req_user);
  546. if (passwd == 0) {
  547. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
  548. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  549. }
  550. ais_uid = passwd->pw_uid;
  551. endpwent ();
  552. return ais_uid;
  553. }
  554. static int gid_determine (const char *req_group)
  555. {
  556. struct group *group;
  557. int ais_gid = 0;
  558. group = getgrnam (req_group);
  559. if (group == 0) {
  560. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
  561. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  562. }
  563. ais_gid = group->gr_gid;
  564. endgrent ();
  565. return ais_gid;
  566. }
  567. static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
  568. void *priv_data_pt)
  569. {
  570. const char *error_string;
  571. if (type == OBJDB_RELOAD_NOTIFY_END) {
  572. /*
  573. * Reload the logsys configuration
  574. */
  575. logsys_format_set(NULL);
  576. corosync_main_config_read_logging(global_objdb,
  577. &error_string);
  578. }
  579. }
  580. static void add_logsys_config_notification(
  581. struct objdb_iface_ver0 *objdb)
  582. {
  583. global_objdb = objdb;
  584. objdb->object_track_start(OBJECT_PARENT_HANDLE,
  585. 1,
  586. NULL,
  587. NULL,
  588. NULL,
  589. main_objdb_reload_notify,
  590. NULL);
  591. }
  592. static int corosync_main_config_read_uidgid (
  593. struct objdb_iface_ver0 *objdb,
  594. const char **error_string,
  595. struct ug_config *ug_config)
  596. {
  597. hdb_handle_t object_find_handle;
  598. hdb_handle_t object_service_handle;
  599. char *value;
  600. int uid, gid;
  601. struct uidgid_item *ugi;
  602. list_init (&ug_config->uidgid_list);
  603. objdb->object_find_create (
  604. OBJECT_PARENT_HANDLE,
  605. "uidgid",
  606. strlen ("uidgid"),
  607. &object_find_handle);
  608. while (objdb->object_find_next (
  609. object_find_handle,
  610. &object_service_handle) == 0) {
  611. uid = -1;
  612. gid = -1;
  613. if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
  614. uid = uid_determine(value);
  615. }
  616. if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
  617. gid = gid_determine(value);
  618. }
  619. if (uid > -1 || gid > -1) {
  620. ugi = malloc (sizeof (*ugi));
  621. if (ugi == NULL) {
  622. _corosync_out_of_memory_error();
  623. }
  624. ugi->uid = uid;
  625. ugi->gid = gid;
  626. list_add (&ugi->list, &ug_config->uidgid_list);
  627. }
  628. }
  629. objdb->object_find_destroy (object_find_handle);
  630. return 0;
  631. }
  632. int corosync_main_config_read (
  633. struct objdb_iface_ver0 *objdb,
  634. const char **error_string,
  635. struct ug_config *ug_config)
  636. {
  637. hdb_handle_t object_service_handle;
  638. char *value;
  639. const char *error_reason = error_string_response;
  640. hdb_handle_t object_find_handle;
  641. memset (ug_config, 0, sizeof (struct ug_config));
  642. if (corosync_main_config_read_logging(objdb, error_string) < 0) {
  643. error_reason = *error_string;
  644. goto parse_error;
  645. }
  646. ug_config->uid = -1;
  647. ug_config->gid = -1;
  648. objdb->object_find_create (
  649. OBJECT_PARENT_HANDLE,
  650. "aisexec",
  651. strlen ("aisexec"),
  652. &object_find_handle);
  653. if (objdb->object_find_next (
  654. object_find_handle,
  655. &object_service_handle) == 0) {
  656. if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
  657. ug_config->uid = uid_determine(value);
  658. }
  659. if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
  660. ug_config->gid = gid_determine(value);
  661. }
  662. }
  663. objdb->object_find_destroy (object_find_handle);
  664. if (ug_config->uid < 0) {
  665. ug_config->uid = uid_determine("ais");
  666. }
  667. if (ug_config->gid < 0) {
  668. ug_config->gid = gid_determine("ais");
  669. }
  670. corosync_main_config_read_uidgid (objdb, error_string, ug_config);
  671. add_logsys_config_notification(objdb);
  672. return 0;
  673. parse_error:
  674. snprintf (error_string_response, sizeof(error_string_response),
  675. "parse error in config: %s.\n",
  676. error_reason);
  677. *error_string = error_string_response;
  678. return (-1);
  679. }