4
0

mainconfig.c 18 KB

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