qdevice-advanced-settings.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Copyright (c) 2015-2017 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdlib.h>
  35. #include <sys/types.h>
  36. #include <sys/stat.h>
  37. #include <errno.h>
  38. #include <limits.h>
  39. #include <string.h>
  40. #include "dynar.h"
  41. #include "dynar-getopt-lex.h"
  42. #include "dynar-str.h"
  43. #include "qdevice-config.h"
  44. #include "qnet-config.h"
  45. #include "qdevice-advanced-settings.h"
  46. #include "utils.h"
  47. int
  48. qdevice_advanced_settings_init(struct qdevice_advanced_settings *settings)
  49. {
  50. memset(settings, 0, sizeof(*settings));
  51. if ((settings->lock_file = strdup(QDEVICE_DEFAULT_LOCK_FILE)) == NULL) {
  52. return (-1);
  53. }
  54. if ((settings->local_socket_file = strdup(QDEVICE_DEFAULT_LOCAL_SOCKET_FILE)) == NULL) {
  55. return (-1);
  56. }
  57. settings->set_local_socket_umask = 0;
  58. settings->local_socket_gid = -1;
  59. settings->local_socket_backlog = QDEVICE_DEFAULT_LOCAL_SOCKET_BACKLOG;
  60. settings->max_cs_try_again = QDEVICE_DEFAULT_MAX_CS_TRY_AGAIN;
  61. if ((settings->votequorum_device_name = strdup(QDEVICE_DEFAULT_VOTEQUORUM_DEVICE_NAME)) == NULL) {
  62. return (-1);
  63. }
  64. settings->ipc_max_clients = QDEVICE_DEFAULT_IPC_MAX_CLIENTS;
  65. settings->ipc_max_receive_size = QDEVICE_DEFAULT_IPC_MAX_RECEIVE_SIZE;
  66. settings->ipc_max_send_size = QDEVICE_DEFAULT_IPC_MAX_SEND_SIZE;
  67. settings->heuristics_ipc_max_send_buffers = QDEVICE_DEFAULT_HEURISTICS_IPC_MAX_SEND_BUFFERS;
  68. settings->heuristics_ipc_max_send_receive_size = QDEVICE_DEFAULT_HEURISTICS_IPC_MAX_SEND_RECEIVE_SIZE;
  69. settings->heuristics_min_timeout = QDEVICE_DEFAULT_HEURISTICS_MIN_TIMEOUT;
  70. settings->heuristics_max_timeout = QDEVICE_DEFAULT_HEURISTICS_MAX_TIMEOUT;
  71. settings->heuristics_min_interval = QDEVICE_DEFAULT_HEURISTICS_MIN_INTERVAL;
  72. settings->heuristics_max_interval = QDEVICE_DEFAULT_HEURISTICS_MAX_INTERVAL;
  73. settings->heuristics_max_execs = QDEVICE_DEFAULT_HEURISTICS_MAX_EXECS;
  74. settings->heuristics_use_execvp = QDEVICE_DEFAULT_HEURISTICS_USE_EXECVP;
  75. settings->heuristics_max_processes = QDEVICE_DEFAULT_HEURISTICS_MAX_PROCESSES;
  76. settings->heuristics_kill_list_interval = QDEVICE_DEFAULT_HEURISTICS_KILL_LIST_INTERVAL;
  77. if ((settings->net_nss_db_dir = strdup(QDEVICE_NET_DEFAULT_NSS_DB_DIR)) == NULL) {
  78. return (-1);
  79. }
  80. settings->net_initial_msg_receive_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_RECEIVE_SIZE;
  81. settings->net_initial_msg_send_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_SEND_SIZE;
  82. settings->net_min_msg_send_size = QDEVICE_NET_DEFAULT_MIN_MSG_SEND_SIZE;
  83. settings->net_max_msg_receive_size = QDEVICE_NET_DEFAULT_MAX_MSG_RECEIVE_SIZE;
  84. settings->net_max_send_buffers = QDEVICE_NET_DEFAULT_MAX_SEND_BUFFERS;
  85. if ((settings->net_nss_qnetd_cn = strdup(QDEVICE_NET_DEFAULT_NSS_QNETD_CN)) == NULL) {
  86. return (-1);
  87. }
  88. if ((settings->net_nss_client_cert_nickname =
  89. strdup(QDEVICE_NET_DEFAULT_NSS_CLIENT_CERT_NICKNAME)) == NULL) {
  90. return (-1);
  91. }
  92. settings->net_heartbeat_interval_min = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MIN;
  93. settings->net_heartbeat_interval_max = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MAX;
  94. settings->net_min_connect_timeout = QDEVICE_NET_DEFAULT_MIN_CONNECT_TIMEOUT;
  95. settings->net_max_connect_timeout = QDEVICE_NET_DEFAULT_MAX_CONNECT_TIMEOUT;
  96. settings->net_test_algorithm_enabled = QDEVICE_NET_DEFAULT_TEST_ALGORITHM_ENABLED;
  97. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
  98. return (0);
  99. }
  100. void
  101. qdevice_advanced_settings_destroy(struct qdevice_advanced_settings *settings)
  102. {
  103. free(settings->local_socket_file);
  104. free(settings->lock_file);
  105. free(settings->votequorum_device_name);
  106. free(settings->net_nss_db_dir);
  107. free(settings->net_nss_qnetd_cn);
  108. free(settings->net_nss_client_cert_nickname);
  109. }
  110. /*
  111. * 0 - No error
  112. * -1 - Unknown option
  113. * -2 - Incorrect value
  114. */
  115. int
  116. qdevice_advanced_settings_set(struct qdevice_advanced_settings *settings,
  117. const char *option, const char *value)
  118. {
  119. long long int tmpll;
  120. if (strcasecmp(option, "lock_file") == 0) {
  121. free(settings->lock_file);
  122. if ((settings->lock_file = strdup(value)) == NULL) {
  123. return (-1);
  124. }
  125. } else if (strcasecmp(option, "local_socket_file") == 0) {
  126. free(settings->local_socket_file);
  127. if ((settings->local_socket_file = strdup(value)) == NULL) {
  128. return (-1);
  129. }
  130. } else if (strcasecmp(option, "local_socket_umask") == 0) {
  131. if (utils_parse_umask(value, &settings->set_local_socket_umask,
  132. &settings->local_socket_umask) != 0) {
  133. return (-2);
  134. }
  135. } else if (strcasecmp(option, "local_socket_gid") == 0) {
  136. if (utils_get_group_gid(value, &settings->local_socket_gid) != 0) {
  137. return (-2);
  138. }
  139. } else if (strcasecmp(option, "local_socket_backlog") == 0) {
  140. if (utils_strtonum(value, QDEVICE_MIN_LOCAL_SOCKET_BACKLOG, INT_MAX, &tmpll) == -1) {
  141. return (-2);
  142. }
  143. settings->local_socket_backlog = (int)tmpll;
  144. } else if (strcasecmp(option, "max_cs_try_again") == 0) {
  145. if (utils_strtonum(value, QDEVICE_MIN_MAX_CS_TRY_AGAIN, INT_MAX, &tmpll) == -1) {
  146. return (-2);
  147. }
  148. settings->max_cs_try_again = (int)tmpll;
  149. } else if (strcasecmp(option, "votequorum_device_name") == 0) {
  150. free(settings->votequorum_device_name);
  151. if ((settings->votequorum_device_name = strdup(value)) == NULL) {
  152. return (-1);
  153. }
  154. } else if (strcasecmp(option, "ipc_max_clients") == 0) {
  155. if (utils_strtonum(value, QDEVICE_MIN_IPC_MAX_CLIENTS, LLONG_MAX, &tmpll) == -1) {
  156. return (-2);
  157. }
  158. settings->ipc_max_clients = (size_t)tmpll;
  159. } else if (strcasecmp(option, "ipc_max_receive_size") == 0) {
  160. if (utils_strtonum(value, QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE, LLONG_MAX,
  161. &tmpll) == -1) {
  162. return (-2);
  163. }
  164. settings->ipc_max_receive_size = (size_t)tmpll;
  165. } else if (strcasecmp(option, "ipc_max_send_size") == 0) {
  166. if (utils_strtonum(value, QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE, LLONG_MAX,
  167. &tmpll) == -1) {
  168. return (-2);
  169. }
  170. settings->ipc_max_send_size = (size_t)tmpll;
  171. } else if (strcasecmp(option, "heuristics_ipc_max_send_buffers") == 0) {
  172. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_IPC_MAX_SEND_BUFFERS, LLONG_MAX,
  173. &tmpll) == -1) {
  174. return (-2);
  175. }
  176. settings->heuristics_ipc_max_send_buffers = (size_t)tmpll;
  177. } else if (strcasecmp(option, "heuristics_ipc_max_send_receive_size") == 0) {
  178. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_IPC_MAX_SEND_RECEIVE_SIZE, LLONG_MAX,
  179. &tmpll) == -1) {
  180. return (-2);
  181. }
  182. settings->heuristics_ipc_max_send_receive_size = (size_t)tmpll;
  183. } else if (strcasecmp(option, "heuristics_min_timeout") == 0) {
  184. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_TIMEOUT, UINT32_MAX,
  185. &tmpll) == -1) {
  186. return (-2);
  187. }
  188. settings->heuristics_min_timeout = (uint32_t)tmpll;
  189. } else if (strcasecmp(option, "heuristics_max_timeout") == 0) {
  190. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_TIMEOUT, UINT32_MAX,
  191. &tmpll) == -1) {
  192. return (-2);
  193. }
  194. settings->heuristics_max_timeout = (uint32_t)tmpll;
  195. } else if (strcasecmp(option, "heuristics_min_interval") == 0) {
  196. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_INTERVAL, UINT32_MAX,
  197. &tmpll) == -1) {
  198. return (-2);
  199. }
  200. settings->heuristics_min_interval = (uint32_t)tmpll;
  201. } else if (strcasecmp(option, "heuristics_max_interval") == 0) {
  202. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_INTERVAL, UINT32_MAX,
  203. &tmpll) == -1) {
  204. return (-2);
  205. }
  206. settings->heuristics_max_interval = (uint32_t)tmpll;
  207. } else if (strcasecmp(option, "heuristics_max_execs") == 0) {
  208. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_MAX_EXECS, LLONG_MAX,
  209. &tmpll) == -1) {
  210. return (-2);
  211. }
  212. settings->heuristics_max_execs = (size_t)tmpll;
  213. } else if (strcasecmp(option, "heuristics_use_execvp") == 0) {
  214. if ((tmpll = utils_parse_bool_str(value)) == -1) {
  215. return (-2);
  216. }
  217. settings->heuristics_use_execvp = (uint8_t)tmpll;
  218. } else if (strcasecmp(option, "heuristics_max_processes") == 0) {
  219. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_MAX_PROCESSES, LLONG_MAX,
  220. &tmpll) == -1) {
  221. return (-2);
  222. }
  223. settings->heuristics_max_processes = (size_t)tmpll;
  224. } else if (strcasecmp(option, "heuristics_kill_list_interval") == 0) {
  225. if (utils_strtonum(value, QDEVICE_MIN_HEURISTICS_KILL_LIST_INTERVAL, UINT32_MAX,
  226. &tmpll) == -1) {
  227. return (-2);
  228. }
  229. settings->heuristics_kill_list_interval = (uint32_t)tmpll;
  230. } else if (strcasecmp(option, "net_nss_db_dir") == 0) {
  231. free(settings->net_nss_db_dir);
  232. if ((settings->net_nss_db_dir = strdup(value)) == NULL) {
  233. return (-1);
  234. }
  235. } else if (strcasecmp(option, "net_initial_msg_receive_size") == 0) {
  236. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  237. &tmpll) == -1) {
  238. return (-2);
  239. }
  240. settings->net_initial_msg_receive_size = (size_t)tmpll;
  241. } else if (strcasecmp(option, "net_initial_msg_send_size") == 0) {
  242. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  243. &tmpll) == -1) {
  244. return (-2);
  245. }
  246. settings->net_initial_msg_send_size = (size_t)tmpll;
  247. } else if (strcasecmp(option, "net_min_msg_send_size") == 0) {
  248. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  249. &tmpll) == -1) {
  250. return (-2);
  251. }
  252. settings->net_min_msg_send_size = (size_t)tmpll;
  253. } else if (strcasecmp(option, "net_max_msg_receive_size") == 0) {
  254. if (utils_strtonum(value, QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE, LLONG_MAX,
  255. &tmpll) == -1) {
  256. return (-2);
  257. }
  258. settings->net_max_msg_receive_size = (size_t)tmpll;
  259. } else if (strcasecmp(option, "net_max_send_buffers") == 0) {
  260. if (utils_strtonum(value, QDEVICE_NET_MIN_MAX_SEND_BUFFERS, LLONG_MAX,
  261. &tmpll) == -1) {
  262. return (-2);
  263. }
  264. settings->net_max_send_buffers = (size_t)tmpll;
  265. } else if (strcasecmp(option, "net_nss_qnetd_cn") == 0) {
  266. free(settings->net_nss_qnetd_cn);
  267. if ((settings->net_nss_qnetd_cn = strdup(value)) == NULL) {
  268. return (-1);
  269. }
  270. } else if (strcasecmp(option, "net_nss_client_cert_nickname") == 0) {
  271. free(settings->net_nss_client_cert_nickname);
  272. if ((settings->net_nss_client_cert_nickname = strdup(value)) == NULL) {
  273. return (-1);
  274. }
  275. } else if (strcasecmp(option, "net_heartbeat_interval_min") == 0) {
  276. if (utils_strtonum(value, QDEVICE_NET_MIN_HEARTBEAT_INTERVAL, UINT32_MAX,
  277. &tmpll) == -1) {
  278. return (-2);
  279. }
  280. settings->net_heartbeat_interval_min = (uint32_t)tmpll;
  281. } else if (strcasecmp(option, "net_heartbeat_interval_max") == 0) {
  282. if (utils_strtonum(value, QDEVICE_NET_MIN_HEARTBEAT_INTERVAL, UINT32_MAX,
  283. &tmpll) == -1) {
  284. return (-2);
  285. }
  286. settings->net_heartbeat_interval_max = (uint32_t)tmpll;
  287. } else if (strcasecmp(option, "net_min_connect_timeout") == 0) {
  288. if (utils_strtonum(value, QDEVICE_NET_MIN_CONNECT_TIMEOUT, UINT32_MAX,
  289. &tmpll) == -1) {
  290. return (-2);
  291. }
  292. settings->net_min_connect_timeout = (uint32_t)tmpll;
  293. } else if (strcasecmp(option, "net_max_connect_timeout") == 0) {
  294. if (utils_strtonum(value, QDEVICE_NET_MIN_CONNECT_TIMEOUT, UINT32_MAX,
  295. &tmpll) == -1) {
  296. return (-2);
  297. }
  298. settings->net_max_connect_timeout = (uint32_t)tmpll;
  299. } else if (strcasecmp(option, "net_test_algorithm_enabled") == 0) {
  300. if ((tmpll = utils_parse_bool_str(value)) == -1) {
  301. return (-2);
  302. }
  303. settings->net_test_algorithm_enabled = (uint8_t)tmpll;
  304. } else if (strcasecmp(option, "master_wins") == 0) {
  305. tmpll = utils_parse_bool_str(value);
  306. if (tmpll == 0) {
  307. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_OFF;
  308. } else if (tmpll == 1) {
  309. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON;
  310. } else if (strcasecmp(value, "model") == 0) {
  311. settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
  312. } else {
  313. return (-2);
  314. }
  315. } else {
  316. return (-1);
  317. }
  318. return (0);
  319. }