totemconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006 RedHat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.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 <stdio.h>
  36. #include <string.h>
  37. #include <stdlib.h>
  38. #include <errno.h>
  39. #include <assert.h>
  40. #include <unistd.h>
  41. #include <sys/socket.h>
  42. #include <sys/types.h>
  43. #include <sys/stat.h>
  44. #include <fcntl.h>
  45. #include <netinet/in.h>
  46. #include <arpa/inet.h>
  47. #include <sys/param.h>
  48. #include "swab.h"
  49. #include "list.h"
  50. #include "util.h"
  51. #include "totem.h"
  52. #include "totemconfig.h"
  53. #include "logsys.h"
  54. #include "objdb.h"
  55. #include "tlist.h" /* for HZ */
  56. #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
  57. #define TOKEN_TIMEOUT 1000
  58. #define TOKEN_RETRANSMIT_TIMEOUT (int)(TOKEN_TIMEOUT / (TOKEN_RETRANSMITS_BEFORE_LOSS_CONST + 0.2))
  59. #define TOKEN_HOLD_TIMEOUT (int)(TOKEN_RETRANSMIT_TIMEOUT * 0.8 - (1000/(int)HZ))
  60. #define JOIN_TIMEOUT 50
  61. #define CONSENSUS_TIMEOUT 800
  62. #define MERGE_TIMEOUT 200
  63. #define DOWNCHECK_TIMEOUT 1000
  64. #define FAIL_TO_RECV_CONST 50
  65. #define SEQNO_UNCHANGED_CONST 30
  66. #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
  67. #define MAX_NETWORK_DELAY 50
  68. #define WINDOW_SIZE 50
  69. #define MAX_MESSAGES 17
  70. #define RRP_PROBLEM_COUNT_TIMEOUT 2000
  71. #define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT 10
  72. #define RRP_PROBLEM_COUNT_THRESHOLD_MIN 5
  73. static char error_string_response[512];
  74. /* These just makes the code below a little neater */
  75. static inline int objdb_get_string (
  76. struct objdb_iface_ver0 *objdb, unsigned int object_service_handle,
  77. char *key, char **value)
  78. {
  79. int res;
  80. *value = NULL;
  81. if ( !(res = objdb->object_key_get (object_service_handle,
  82. key,
  83. strlen (key),
  84. (void *)value,
  85. NULL))) {
  86. if (*value)
  87. return 0;
  88. }
  89. return -1;
  90. }
  91. static inline void objdb_get_int (
  92. struct objdb_iface_ver0 *objdb, unsigned int object_service_handle,
  93. char *key, unsigned int *intvalue)
  94. {
  95. char *value = NULL;
  96. if (!objdb->object_key_get (object_service_handle,
  97. key,
  98. strlen (key),
  99. (void *)&value,
  100. NULL)) {
  101. if (value) {
  102. *intvalue = atoi(value);
  103. }
  104. }
  105. }
  106. extern int totem_config_read (
  107. struct objdb_iface_ver0 *objdb,
  108. struct totem_config *totem_config,
  109. char **error_string)
  110. {
  111. int res = 0;
  112. unsigned int object_totem_handle;
  113. unsigned int object_interface_handle;
  114. char *str;
  115. unsigned int ringnumber = 0;
  116. memset (totem_config, 0, sizeof (struct totem_config));
  117. totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  118. if (totem_config->interfaces == 0) {
  119. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  120. return -1;
  121. }
  122. memset (totem_config->interfaces, 0,
  123. sizeof (struct totem_interface) * INTERFACE_MAX);
  124. totem_config->secauth = 1;
  125. strcpy (totem_config->rrp_mode, "none");
  126. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  127. if (objdb->object_find (
  128. OBJECT_PARENT_HANDLE,
  129. "network",
  130. strlen ("network"),
  131. &object_totem_handle) == 0 ||
  132. objdb->object_find (
  133. OBJECT_PARENT_HANDLE,
  134. "totem",
  135. strlen ("totem"),
  136. &object_totem_handle) == 0) {
  137. if (!objdb_get_string (objdb,object_totem_handle, "version", &str)) {
  138. if (strcmp (str, "2") == 0) {
  139. totem_config->version = 2;
  140. }
  141. }
  142. if (!objdb_get_string (objdb,object_totem_handle, "secauth", &str)) {
  143. if (strcmp (str, "on") == 0) {
  144. totem_config->secauth = 1;
  145. }
  146. if (strcmp (str, "off") == 0) {
  147. totem_config->secauth = 0;
  148. }
  149. }
  150. if (!objdb_get_string (objdb, object_totem_handle, "rrp_mode", &str)) {
  151. strcpy (totem_config->rrp_mode, str);
  152. }
  153. /*
  154. * Get interface node id
  155. */
  156. objdb_get_int (objdb, object_totem_handle, "nodeid", &totem_config->node_id);
  157. objdb_get_int (objdb,object_totem_handle, "threads", &totem_config->threads);
  158. objdb_get_int (objdb,object_totem_handle, "netmtu", &totem_config->net_mtu);
  159. objdb_get_int (objdb,object_totem_handle, "token", &totem_config->token_timeout);
  160. objdb_get_int (objdb,object_totem_handle, "token_retransmit", &totem_config->token_retransmit_timeout);
  161. objdb_get_int (objdb,object_totem_handle, "hold", &totem_config->token_hold_timeout);
  162. objdb_get_int (objdb,object_totem_handle, "token_retransmits_before_loss_const", &totem_config->token_retransmits_before_loss_const);
  163. objdb_get_int (objdb,object_totem_handle, "join", &totem_config->join_timeout);
  164. objdb_get_int (objdb,object_totem_handle, "send_join", &totem_config->send_join_timeout);
  165. objdb_get_int (objdb,object_totem_handle, "consensus", &totem_config->consensus_timeout);
  166. objdb_get_int (objdb,object_totem_handle, "merge", &totem_config->merge_timeout);
  167. objdb_get_int (objdb,object_totem_handle, "downcheck", &totem_config->downcheck_timeout);
  168. objdb_get_int (objdb,object_totem_handle, "fail_recv_const", &totem_config->fail_to_recv_const);
  169. objdb_get_int (objdb,object_totem_handle, "seqno_unchanged_const", &totem_config->seqno_unchanged_const);
  170. objdb_get_int (objdb,object_totem_handle, "rrp_token_expired_timeout", &totem_config->rrp_token_expired_timeout);
  171. objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_timeout", &totem_config->rrp_problem_count_timeout);
  172. objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_threshold", &totem_config->rrp_problem_count_threshold);
  173. objdb_get_int (objdb,object_totem_handle, "heartbeat_failures_allowed", &totem_config->heartbeat_failures_allowed);
  174. objdb_get_int (objdb,object_totem_handle, "max_network_delay", &totem_config->max_network_delay);
  175. objdb_get_int (objdb,object_totem_handle, "window_size", &totem_config->window_size);
  176. objdb_get_string (objdb, object_totem_handle, "vsftype", &totem_config->vsf_type);
  177. objdb_get_int (objdb,object_totem_handle, "max_messages", &totem_config->max_messages);
  178. }
  179. while (objdb->object_find (
  180. object_totem_handle,
  181. "interface",
  182. strlen ("interface"),
  183. &object_interface_handle) == 0) {
  184. objdb_get_int (objdb, object_interface_handle, "ringnumber", &ringnumber);
  185. /*
  186. * Get interface multicast address
  187. */
  188. if (!objdb_get_string (objdb, object_interface_handle, "mcastaddr", &str)) {
  189. res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, 0);
  190. }
  191. /*
  192. * Get mcast port
  193. */
  194. if (!objdb_get_string (objdb, object_interface_handle, "mcastport", &str)) {
  195. totem_config->interfaces[ringnumber].ip_port = atoi (str);
  196. }
  197. /*
  198. * Get the bind net address
  199. */
  200. if (!objdb_get_string (objdb, object_interface_handle, "bindnetaddr", &str)) {
  201. res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
  202. totem_config->interfaces[ringnumber].mcast_addr.family);
  203. }
  204. totem_config->interface_count++;
  205. }
  206. return 0;
  207. return (-1);
  208. }
  209. int totem_config_validate (
  210. struct totem_config *totem_config,
  211. char **error_string)
  212. {
  213. static char local_error_reason[512];
  214. char parse_error[512];
  215. char *error_reason = local_error_reason;
  216. int i;
  217. unsigned int interface_max = INTERFACE_MAX;
  218. if (totem_config->interface_count == 0) {
  219. error_reason = "No interfaces defined";
  220. goto parse_error;
  221. }
  222. for (i = 0; i < totem_config->interface_count; i++) {
  223. /*
  224. * Some error checking of parsed data to make sure its valid
  225. */
  226. if ((int *)&totem_config->interfaces[i].mcast_addr.addr == 0) {
  227. error_reason = "No multicast address specified";
  228. goto parse_error;
  229. }
  230. if (totem_config->interfaces[i].ip_port == 0) {
  231. error_reason = "No multicast port specified";
  232. goto parse_error;
  233. }
  234. if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
  235. totem_config->node_id == 0) {
  236. error_reason = "An IPV6 network requires that a node ID be specified.";
  237. goto parse_error;
  238. }
  239. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  240. error_reason = "Multicast address family does not match bind address family";
  241. goto parse_error;
  242. }
  243. if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
  244. error_reason = "Not all bind address belong to the same IP family";
  245. goto parse_error;
  246. }
  247. }
  248. if (totem_config->version != 2) {
  249. error_reason = "This totem parser can only parse version 2 configurations.";
  250. goto parse_error;
  251. }
  252. if (totem_config->token_retransmits_before_loss_const == 0) {
  253. totem_config->token_retransmits_before_loss_const =
  254. TOKEN_RETRANSMITS_BEFORE_LOSS_CONST;
  255. }
  256. /*
  257. * Setup timeout values that are not setup by user
  258. */
  259. if (totem_config->token_timeout == 0) {
  260. totem_config->token_timeout = TOKEN_TIMEOUT;
  261. if (totem_config->token_retransmits_before_loss_const == 0) {
  262. totem_config->token_retransmits_before_loss_const = TOKEN_RETRANSMITS_BEFORE_LOSS_CONST;
  263. }
  264. if (totem_config->token_retransmit_timeout == 0) {
  265. totem_config->token_retransmit_timeout =
  266. (int)(totem_config->token_timeout /
  267. (totem_config->token_retransmits_before_loss_const + 0.2));
  268. }
  269. if (totem_config->token_hold_timeout == 0) {
  270. totem_config->token_hold_timeout =
  271. (int)(totem_config->token_retransmit_timeout * 0.8 -
  272. (1000/HZ));
  273. }
  274. }
  275. if (totem_config->max_network_delay == 0) {
  276. totem_config->max_network_delay = MAX_NETWORK_DELAY;
  277. }
  278. if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
  279. sprintf (local_error_reason, "The max_network_delay parameter (%d ms) may not be less then (%d ms).",
  280. totem_config->max_network_delay, MINIMUM_TIMEOUT);
  281. goto parse_error;
  282. }
  283. if (totem_config->window_size == 0) {
  284. totem_config->window_size = WINDOW_SIZE;
  285. }
  286. if (totem_config->max_messages == 0) {
  287. totem_config->max_messages = MAX_MESSAGES;
  288. }
  289. if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
  290. sprintf (local_error_reason, "The token timeout parameter (%d ms) may not be less then (%d ms).",
  291. totem_config->token_timeout, MINIMUM_TIMEOUT);
  292. goto parse_error;
  293. }
  294. if (totem_config->token_retransmit_timeout == 0) {
  295. totem_config->token_retransmit_timeout =
  296. (int)(totem_config->token_timeout /
  297. (totem_config->token_retransmits_before_loss_const + 0.2));
  298. }
  299. if (totem_config->token_hold_timeout == 0) {
  300. totem_config->token_hold_timeout =
  301. (int)(totem_config->token_retransmit_timeout * 0.8 -
  302. (1000/HZ));
  303. }
  304. if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
  305. sprintf (local_error_reason, "The token retransmit timeout parameter (%d ms) may not be less then (%d ms).",
  306. totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT);
  307. goto parse_error;
  308. }
  309. if (totem_config->token_hold_timeout == 0) {
  310. totem_config->token_hold_timeout = TOKEN_HOLD_TIMEOUT;
  311. }
  312. if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) {
  313. sprintf (local_error_reason, "The token hold timeout parameter (%d ms) may not be less then (%d ms).",
  314. totem_config->token_hold_timeout, MINIMUM_TIMEOUT);
  315. goto parse_error;
  316. }
  317. if (totem_config->join_timeout == 0) {
  318. totem_config->join_timeout = JOIN_TIMEOUT;
  319. }
  320. if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
  321. sprintf (local_error_reason, "The join timeout parameter (%d ms) may not be less then (%d ms).",
  322. totem_config->join_timeout, MINIMUM_TIMEOUT);
  323. goto parse_error;
  324. }
  325. if (totem_config->consensus_timeout == 0) {
  326. totem_config->consensus_timeout = CONSENSUS_TIMEOUT;
  327. }
  328. if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
  329. sprintf (local_error_reason, "The consensus timeout parameter (%d ms) may not be less then (%d ms).",
  330. totem_config->consensus_timeout, MINIMUM_TIMEOUT);
  331. goto parse_error;
  332. }
  333. if (totem_config->merge_timeout == 0) {
  334. totem_config->merge_timeout = MERGE_TIMEOUT;
  335. }
  336. if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
  337. sprintf (local_error_reason, "The merge timeout parameter (%d ms) may not be less then (%d ms).",
  338. totem_config->merge_timeout, MINIMUM_TIMEOUT);
  339. goto parse_error;
  340. }
  341. if (totem_config->downcheck_timeout == 0) {
  342. totem_config->downcheck_timeout = DOWNCHECK_TIMEOUT;
  343. }
  344. if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
  345. sprintf (local_error_reason, "The downcheck timeout parameter (%d ms) may not be less then (%d ms).",
  346. totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
  347. goto parse_error;
  348. }
  349. /*
  350. * RRP values validation
  351. */
  352. if (strcmp (totem_config->rrp_mode, "none") &&
  353. strcmp (totem_config->rrp_mode, "active") &&
  354. strcmp (totem_config->rrp_mode, "passive")) {
  355. sprintf (local_error_reason, "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
  356. goto parse_error;
  357. }
  358. if (totem_config->rrp_problem_count_timeout == 0) {
  359. totem_config->rrp_problem_count_timeout = RRP_PROBLEM_COUNT_TIMEOUT;
  360. }
  361. if (totem_config->rrp_problem_count_timeout < MINIMUM_TIMEOUT) {
  362. sprintf (local_error_reason, "The RRP problem count timeout parameter (%d ms) may not be less then (%d ms).",
  363. totem_config->rrp_problem_count_timeout, MINIMUM_TIMEOUT);
  364. goto parse_error;
  365. }
  366. if (totem_config->rrp_problem_count_threshold == 0) {
  367. totem_config->rrp_problem_count_threshold = RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT;
  368. }
  369. if (totem_config->rrp_problem_count_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) {
  370. sprintf (local_error_reason, "The RRP problem count threshold (%d problem count) may not be less then (%d problem count).",
  371. totem_config->rrp_problem_count_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN);
  372. goto parse_error;
  373. }
  374. if (totem_config->rrp_token_expired_timeout == 0) {
  375. totem_config->rrp_token_expired_timeout =
  376. totem_config->token_retransmit_timeout;
  377. }
  378. if (totem_config->rrp_token_expired_timeout < MINIMUM_TIMEOUT) {
  379. sprintf (local_error_reason, "The RRP token expired timeout parameter (%d ms) may not be less then (%d ms).",
  380. totem_config->rrp_token_expired_timeout, MINIMUM_TIMEOUT);
  381. goto parse_error;
  382. }
  383. if (strcmp (totem_config->rrp_mode, "none") == 0) {
  384. interface_max = 1;
  385. }
  386. if (interface_max < totem_config->interface_count) {
  387. sprintf (parse_error,
  388. "%d is too many configured interfaces for the rrp_mode setting %s.",
  389. totem_config->interface_count,
  390. totem_config->rrp_mode);
  391. error_reason = parse_error;
  392. goto parse_error;
  393. }
  394. if (totem_config->fail_to_recv_const == 0) {
  395. totem_config->fail_to_recv_const = FAIL_TO_RECV_CONST;
  396. }
  397. if (totem_config->seqno_unchanged_const == 0) {
  398. totem_config->seqno_unchanged_const = SEQNO_UNCHANGED_CONST;
  399. }
  400. if (totem_config->net_mtu == 0) {
  401. totem_config->net_mtu = 1500;
  402. }
  403. if ((MESSAGE_SIZE_MAX / totem_config->net_mtu) < totem_config->max_messages) {
  404. sprintf (local_error_reason, "The max_messages parameter (%d messages) may not be greater then (%d messages).",
  405. totem_config->max_messages, MESSAGE_SIZE_MAX / totem_config->net_mtu);
  406. goto parse_error;
  407. }
  408. if (totem_config->threads > SEND_THREADS_MAX) {
  409. totem_config->threads = SEND_THREADS_MAX;
  410. }
  411. if (totem_config->secauth == 0) {
  412. totem_config->threads = 0;
  413. }
  414. if (totem_config->net_mtu > FRAME_SIZE_MAX) {
  415. error_reason = "This net_mtu parameter is greater then the maximum frame size";
  416. goto parse_error;
  417. }
  418. if (totem_config->vsf_type == NULL) {
  419. totem_config->vsf_type = "none";
  420. }
  421. return (0);
  422. parse_error:
  423. sprintf (error_string_response,
  424. "parse error in config: %s\n", error_reason);
  425. *error_string = error_string_response;
  426. return (-1);
  427. }
  428. static int read_keyfile (
  429. char *key_location,
  430. struct totem_config *totem_config,
  431. char **error_string)
  432. {
  433. int fd;
  434. int res;
  435. fd = open (key_location, O_RDONLY);
  436. if (fd == -1) {
  437. sprintf (error_string_response, "Could not open %s: %s\n",
  438. key_location, strerror (errno));
  439. goto parse_error;
  440. }
  441. res = read (fd, totem_config->private_key, 128);
  442. if (res == -1) {
  443. close (fd);
  444. sprintf (error_string_response, "Could not read %s: %s\n",
  445. key_location, strerror (errno));
  446. goto parse_error;
  447. }
  448. totem_config->private_key_len = 128;
  449. if (res != 128) {
  450. close (fd);
  451. sprintf (error_string_response, "Could only read %d bits of 1024 bits from %s.\n",
  452. res * 8, key_location);
  453. goto parse_error;
  454. }
  455. return 0;
  456. parse_error:
  457. *error_string = error_string_response;
  458. return (-1);
  459. }
  460. int totem_config_keyread (
  461. struct objdb_iface_ver0 *objdb,
  462. struct totem_config *totem_config,
  463. char **error_string)
  464. {
  465. int got_key = 0;
  466. char *key_location = NULL;
  467. unsigned int object_service_handle;
  468. int res;
  469. memset (totem_config->private_key, 0, 128);
  470. totem_config->private_key_len = 128;
  471. if (totem_config->secauth == 0) {
  472. return (0);
  473. }
  474. if (objdb->object_find (
  475. OBJECT_PARENT_HANDLE,
  476. "network",
  477. strlen ("network"),
  478. &object_service_handle) == 0 ||
  479. objdb->object_find (
  480. OBJECT_PARENT_HANDLE,
  481. "totem",
  482. strlen ("totem"),
  483. &object_service_handle) == 0) {
  484. /* objdb may store the location of the key file */
  485. if (!objdb_get_string (objdb,object_service_handle, "keyfile", &key_location)
  486. && key_location) {
  487. res = read_keyfile(key_location, totem_config, error_string);
  488. if (res)
  489. goto key_error;
  490. got_key = 1;
  491. }
  492. else { /* Or the key itself may be in the objdb */
  493. char *key = NULL;
  494. int key_len;
  495. res = objdb->object_key_get (object_service_handle,
  496. "key",
  497. strlen ("key"),
  498. (void *)&key,
  499. &key_len);
  500. if (res == 0 && key) {
  501. memcpy(totem_config->private_key, key, key_len);
  502. totem_config->private_key_len = key_len;
  503. got_key = 1;
  504. }
  505. }
  506. }
  507. /* In desperation we read the default filename */
  508. if (!got_key) {
  509. char *filename = getenv("OPENAIS_TOTEM_AUTHKEY_FILE");
  510. if (!filename)
  511. filename = "/etc/ais/authkey";
  512. res = read_keyfile(filename, totem_config, error_string);
  513. if (res)
  514. goto key_error;
  515. }
  516. return (0);
  517. *error_string = error_string_response;
  518. key_error:
  519. return (-1);
  520. }