21 #include <sys/types.h> 40 #ifdef HAVE_GNUTLS_GNUTLS_H 41 # include <gnutls/gnutls.h> 44 #include <sys/socket.h> 45 #include <netinet/in.h> 46 #include <netinet/ip.h> 47 #include <arpa/inet.h> 50 #define MAX_TLS_RECV_WAIT 10000 54 static int lrmd_api_disconnect(
lrmd_t * lrmd);
55 static int lrmd_api_is_connected(
lrmd_t * lrmd);
59 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
62 #ifdef HAVE_GNUTLS_GNUTLS_H 64 #define TLS_HANDSHAKE_TIMEOUT 5 66 gnutls_psk_client_credentials_t psk_cred_s;
67 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
68 static int global_remote_msg_id = 0;
69 static void lrmd_tls_connection_destroy(gpointer userdata);
70 static int add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake);
73 static void report_async_connection_result(
lrmd_t * lrmd,
int rc);
75 typedef struct lrmd_private_s {
86 char *remote_nodename;
87 #ifdef HAVE_GNUTLS_GNUTLS_H 90 gnutls_psk_client_credentials_t psk_cred_c;
100 int expected_late_replies;
101 GList *pending_notify;
109 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
110 void *proxy_callback_userdata;
115 lrmd_list_add(
lrmd_list_t * head,
const char *value)
120 p->
val = strdup(value);
123 while (end && end->
next) {
142 char *val = (
char *)head->
val;
157 p->
key = strdup(key);
158 p->
value = strdup(value);
161 while (end && end->
next) {
208 event->interval_ms = interval_ms;
219 copy->
type =
event->type;
229 copy->
call_id =
event->call_id;
230 copy->
timeout =
event->timeout;
234 copy->
rc =
event->rc;
236 copy->
t_run =
event->t_run;
258 free((
void *) event->
rsc_id);
263 if (event->
params != NULL) {
264 g_hash_table_destroy(event->
params);
270 lrmd_dispatch_internal(gpointer
data, gpointer user_data)
281 if (proxy_session != NULL) {
283 lrmd_internal_proxy_dispatch(lrmd, msg);
285 }
else if (!native->callback) {
287 crm_trace(
"notify event received but client has not set callback");
291 event.remote_nodename = native->remote_nodename;
322 event.t_run = (
unsigned int) epoch;
326 event.t_rcchange = (
unsigned int) epoch;
330 event.exec_time = QB_MAX(0, exec_time);
334 event.queue_time = QB_MAX(0, queue_time);
356 native->callback(&event);
359 g_hash_table_destroy(event.params);
366 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
371 if (native->callback != NULL) {
374 lrmd_dispatch_internal(msg, lrmd);
380 #ifdef HAVE_GNUTLS_GNUTLS_H 382 lrmd_free_xml(gpointer userdata)
388 remote_executor_connected(
lrmd_t * lrmd)
392 return (native->remote->tls_session != NULL);
396 handle_remote_msg(xmlNode *xml,
lrmd_t *lrmd)
399 const char *msg_type = NULL;
403 lrmd_dispatch_internal(xml, lrmd);
405 if (native->expected_late_replies > 0) {
406 native->expected_late_replies--;
411 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
417 process_pending_notifies(
lrmd_t *lrmd)
421 if (native->pending_notify == NULL) {
425 crm_trace(
"Processing pending notifies");
426 g_list_foreach(native->pending_notify, lrmd_dispatch_internal, lrmd);
427 g_list_free_full(native->pending_notify, lrmd_free_xml);
428 native->pending_notify = NULL;
443 lrmd_tls_dispatch(gpointer userdata)
450 if (!remote_executor_connected(lrmd)) {
451 crm_trace(
"TLS dispatch triggered after disconnect");
460 process_pending_notifies(lrmd);
469 crm_info(
"Lost %s executor connection while reading data",
470 (native->remote_nodename? native->remote_nodename :
"local"));
471 lrmd_tls_disconnect(lrmd);
484 handle_remote_msg(xml, lrmd);
496 switch (native->type) {
500 #ifdef HAVE_GNUTLS_GNUTLS_H 501 case pcmk__client_tls:
502 if (native->pending_notify) {
518 crm_err(
"Unsupported executor connection type (bug?): %d",
520 return -EPROTONOSUPPORT;
533 switch (private->type) {
539 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
543 #ifdef HAVE_GNUTLS_GNUTLS_H 544 case pcmk__client_tls:
545 lrmd_tls_dispatch(lrmd);
549 crm_err(
"Unsupported executor connection type (bug?): %d",
553 if (lrmd_api_is_connected(lrmd) == FALSE) {
562 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
565 xmlNode *op_msg = NULL;
581 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
582 op, (
long)options, options);
587 lrmd_ipc_connection_destroy(gpointer userdata)
592 switch (native->type) {
594 crm_info(
"Disconnected from local executor");
596 #ifdef HAVE_GNUTLS_GNUTLS_H 597 case pcmk__client_tls:
598 crm_info(
"Disconnected from remote executor on %s",
599 native->remote_nodename);
603 crm_err(
"Unsupported executor connection type %d (bug?)",
609 native->source = NULL;
611 if (native->callback) {
614 event.remote_nodename = native->remote_nodename;
615 native->callback(&event);
619 #ifdef HAVE_GNUTLS_GNUTLS_H 621 lrmd_tls_connection_destroy(gpointer userdata)
626 crm_info(
"TLS connection destroyed");
628 if (native->remote->tls_session) {
629 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
630 gnutls_deinit(*native->remote->tls_session);
631 gnutls_free(native->remote->tls_session);
632 native->remote->tls_session = NULL;
634 if (native->psk_cred_c) {
635 gnutls_psk_free_client_credentials(native->psk_cred_c);
640 if (native->process_notify) {
642 native->process_notify = NULL;
644 if (native->pending_notify) {
645 g_list_free_full(native->pending_notify, lrmd_free_xml);
646 native->pending_notify = NULL;
648 if (native->handshake_trigger != NULL) {
650 native->handshake_trigger = NULL;
653 free(native->remote->buffer);
654 free(native->remote->start_state);
655 native->remote->buffer = NULL;
656 native->remote->start_state = NULL;
659 native->psk_cred_c = NULL;
662 if (native->callback) {
666 native->callback(&event);
674 const char *msg_type)
683 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
687 time_t start = time(NULL);
688 const char *msg_type = NULL;
690 int remaining_timeout = 0;
699 for (*reply = NULL; *reply == NULL; ) {
702 if (*reply == NULL) {
704 if (remaining_timeout) {
705 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
707 remaining_timeout = total_timeout;
709 if (remaining_timeout <= 0) {
719 if (*reply == NULL) {
728 crm_err(
"Empty msg type received while waiting for reply");
734 native->pending_notify = g_list_append(native->pending_notify, *reply);
735 if (native->process_notify) {
742 crm_err(
"Expected a reply, got %s", msg_type);
745 }
else if (reply_id != expected_reply_id) {
746 if (native->expected_late_replies > 0) {
747 native->expected_late_replies--;
749 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
756 if (native->remote->buffer && native->process_notify) {
765 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
770 global_remote_msg_id++;
771 if (global_remote_msg_id <= 0) {
772 global_remote_msg_id = 1;
778 crm_err(
"Disconnecting because TLS message could not be sent to " 780 lrmd_tls_disconnect(lrmd);
786 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
791 if (!remote_executor_connected(lrmd)) {
795 rc = send_remote_message(lrmd, msg);
800 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
802 crm_err(
"Disconnecting remote after request %d reply not received: %s " 803 CRM_XS " rc=%d timeout=%dms",
805 lrmd_tls_disconnect(lrmd);
819 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
824 switch (native->type) {
828 #ifdef HAVE_GNUTLS_GNUTLS_H 829 case pcmk__client_tls:
830 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
834 crm_err(
"Unsupported executor connection type (bug?): %d",
836 rc = -EPROTONOSUPPORT;
843 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
848 switch (native->type) {
852 #ifdef HAVE_GNUTLS_GNUTLS_H 853 case pcmk__client_tls:
854 rc = send_remote_message(lrmd, msg);
859 native->expected_late_replies++;
865 crm_err(
"Unsupported executor connection type (bug?): %d",
867 rc = -EPROTONOSUPPORT;
874 lrmd_api_is_connected(
lrmd_t * lrmd)
878 switch (native->type) {
881 #ifdef HAVE_GNUTLS_GNUTLS_H 882 case pcmk__client_tls:
883 return remote_executor_connected(lrmd);
886 crm_err(
"Unsupported executor connection type (bug?): %d",
911 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
912 xmlNode **output_data,
int timeout,
917 xmlNode *op_msg = NULL;
918 xmlNode *op_reply = NULL;
920 if (!lrmd_api_is_connected(lrmd)) {
925 crm_err(
"No operation specified");
931 crm_trace(
"Sending %s op to executor", op);
933 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
935 if (op_msg == NULL) {
940 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
942 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
947 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op,
timeout, rc);
950 }
else if(op_reply == NULL) {
965 *output_data = op_reply;
970 if (lrmd_api_is_connected(lrmd) == FALSE) {
971 crm_err(
"Executor disconnected");
980 lrmd_api_poke_connection(
lrmd_t * lrmd)
1018 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
1022 xmlNode *reply = NULL;
1031 if (native->proxy_callback) {
1035 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
1038 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
1040 }
else if (reply == NULL) {
1041 crm_err(
"Did not receive registration reply");
1050 long long uptime = -1;
1060 native->remote->uptime = uptime;
1063 native->remote->start_state = strdup(start_state);
1066 if (rc == -EPROTO) {
1067 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
1072 crm_err(
"Invalid registration message: %s", msg_type);
1075 }
else if (tmp_ticket == NULL) {
1076 crm_err(
"No registration token provided");
1080 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1081 native->token = strdup(tmp_ticket);
1091 lrmd_api_disconnect(lrmd);
1097 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1104 .destroy = lrmd_ipc_connection_destroy
1107 crm_info(
"Connecting to executor");
1112 if (native->ipc != NULL) {
1127 if (native->ipc == NULL) {
1128 crm_debug(
"Could not connect to the executor API");
1135 #ifdef HAVE_GNUTLS_GNUTLS_H 1137 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1139 pcmk__assert((dest != NULL) && (source != NULL) && (source->data != NULL));
1141 dest->data = gnutls_malloc(source->size);
1144 memcpy(dest->data, source->data, source->size);
1145 dest->size = source->size;
1149 clear_gnutls_datum(gnutls_datum_t *datum)
1151 gnutls_free(datum->data);
1156 #define KEY_READ_LEN 256 // Chunk size for reading key from file 1160 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1162 FILE *stream = NULL;
1163 size_t buf_len = KEY_READ_LEN;
1165 if ((location == NULL) || (key == NULL)) {
1169 stream = fopen(location,
"r");
1170 if (stream == NULL) {
1174 key->data = gnutls_malloc(buf_len);
1176 while (!feof(stream)) {
1177 int next = fgetc(stream);
1180 if (!feof(stream)) {
1181 crm_warn(
"Pacemaker Remote key read was partially successful " 1182 "(copy in memory may be corrupted)");
1186 if (key->size == buf_len) {
1187 buf_len = key->size + KEY_READ_LEN;
1188 key->data = gnutls_realloc(key->data, buf_len);
1191 key->data[key->size++] = (
unsigned char) next;
1195 if (key->size == 0) {
1196 clear_gnutls_datum(key);
1204 struct key_cache_s {
1206 const char *location;
1211 key_is_cached(
struct key_cache_s *key_cache)
1213 return key_cache->updated != 0;
1217 key_cache_expired(
struct key_cache_s *key_cache)
1219 return (time(NULL) - key_cache->updated) >= 60;
1223 clear_key_cache(
struct key_cache_s *key_cache)
1225 clear_gnutls_datum(&(key_cache->key));
1226 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1227 key_cache->updated = 0;
1228 key_cache->location = NULL;
1229 crm_debug(
"Cleared Pacemaker Remote key cache");
1234 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1236 copy_gnutls_datum(key, &(key_cache->key));
1237 crm_debug(
"Using cached Pacemaker Remote key from %s",
1238 pcmk__s(key_cache->location,
"unknown location"));
1242 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1243 const char *location)
1245 key_cache->updated = time(NULL);
1246 key_cache->location = location;
1247 copy_gnutls_datum(&(key_cache->key), key);
1248 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1249 pcmk__s(location,
"unknown location"));
1263 get_remote_key(
const char *location, gnutls_datum_t *key)
1265 static struct key_cache_s key_cache = { 0, };
1268 if ((location == NULL) || (key == NULL)) {
1272 if (key_is_cached(&key_cache)) {
1273 if (key_cache_expired(&key_cache)) {
1274 clear_key_cache(&key_cache);
1276 get_cached_key(&key_cache, key);
1281 rc = read_gnutls_key(location, key);
1285 cache_key(&key_cache, key, location);
1303 lrmd__init_remote_key(gnutls_datum_t *key)
1305 static const char *env_location = NULL;
1306 static bool need_env =
true;
1312 bool env_is_default =
false;
1313 bool env_is_fallback =
false;
1321 if (env_location != NULL) {
1322 env_rc = get_remote_key(env_location, key);
1341 if (env_is_default) {
1342 default_rc = env_rc;
1349 if (env_is_fallback) {
1360 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1362 env_is_default?
"" :
"or default location ",
1364 !env_is_default && !env_is_fallback?
" " :
"",
1365 env_is_fallback?
"" :
"or fallback location ",
1372 crm_warn(
"Could not read Pacemaker Remote key from %s " 1373 "(using %s location %s instead): %s",
1375 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1378 crm_warn(
"This undocumented behavior is deprecated and unsafe and will " 1379 "be removed in a future release");
1388 crm_warn(
"Read Pacemaker Remote key from alternate location %s",
1390 crm_warn(
"This undocumented behavior is deprecated and unsafe and will " 1391 "be removed in a future release");
1394 crm_warn(
"Could not read Pacemaker Remote key from default location %s" 1395 " (or fallback location %s): %s",
1406 lrmd_gnutls_global_init(
void)
1408 static int gnutls_init = 0;
1411 crm_gnutls_global_init();
1417 tls_handshake_failed(
lrmd_t *lrmd,
int tls_rc,
int rc)
1421 crm_warn(
"Disconnecting after TLS handshake with " 1422 "Pacemaker Remote server %s:%d failed: %s",
1423 native->server, native->port,
1424 (rc == EPROTO)? gnutls_strerror(tls_rc) :
pcmk_rc_str(rc));
1427 gnutls_deinit(*native->remote->tls_session);
1428 gnutls_free(native->remote->tls_session);
1429 native->remote->tls_session = NULL;
1430 lrmd_tls_connection_destroy(lrmd);
1434 tls_handshake_succeeded(
lrmd_t *lrmd)
1439 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1440 native->server, native->port);
1441 rc = add_tls_to_mainloop(lrmd,
true);
1447 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1451 if (native->callback) {
1454 event.remote_nodename = native->remote_nodename;
1455 event.connection_rc = rc;
1456 native->callback(&event);
1460 #ifdef HAVE_GNUTLS_GNUTLS_H 1470 tls_client_handshake(
lrmd_t *lrmd)
1473 int tls_rc = GNUTLS_E_SUCCESS;
1474 int rc = pcmk__tls_client_handshake(native->remote, TLS_HANDSHAKE_TIMEOUT,
1478 tls_handshake_failed(lrmd, tls_rc, rc);
1494 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1500 native->server, native->port);
1504 .destroy = lrmd_tls_connection_destroy,
1508 lrmd_tls_dispatch, lrmd);
1519 rc = lrmd_handshake(lrmd,
name);
1526 struct handshake_data_s {
1533 try_handshake_cb(gpointer user_data)
1535 struct handshake_data_s *hs = user_data;
1541 int tls_rc = GNUTLS_E_SUCCESS;
1543 if (time(NULL) >= hs->start_time + hs->timeout_sec) {
1546 tls_handshake_failed(lrmd, GNUTLS_E_TIMEDOUT, rc);
1551 rc = pcmk__tls_client_try_handshake(remote, &tls_rc);
1554 tls_handshake_succeeded(lrmd);
1557 }
else if (rc == EAGAIN) {
1562 tls_handshake_failed(lrmd, tls_rc, rc);
1569 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1573 gnutls_datum_t psk_key = { NULL, 0 };
1574 int tls_rc = GNUTLS_E_SUCCESS;
1576 native->async_timer = 0;
1579 lrmd_tls_connection_destroy(lrmd);
1580 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1582 native->server, native->port,
pcmk_rc_str(rc), rc);
1589 native->sock = sock;
1591 rc = lrmd__init_remote_key(&psk_key);
1593 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1595 native->server, native->port,
pcmk_rc_str(rc), rc);
1596 lrmd_tls_connection_destroy(lrmd);
1601 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1603 gnutls_free(psk_key.data);
1605 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1607 native->psk_cred_c);
1608 if (native->remote->tls_session == NULL) {
1609 lrmd_tls_connection_destroy(lrmd);
1610 report_async_connection_result(lrmd, -EPROTO);
1618 rc = pcmk__tls_client_try_handshake(native->remote, &tls_rc);
1620 struct handshake_data_s *hs = NULL;
1622 if (native->handshake_trigger != NULL) {
1628 hs->start_time = time(NULL);
1629 hs->timeout_sec = TLS_HANDSHAKE_TIMEOUT;
1635 tls_handshake_succeeded(lrmd);
1638 tls_handshake_failed(lrmd, tls_rc, rc);
1649 lrmd_gnutls_global_init();
1652 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1654 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1656 native->server, native->port,
pcmk_rc_str(rc), rc);
1659 native->async_timer = timer_id;
1664 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1669 gnutls_datum_t psk_key = { NULL, 0 };
1671 lrmd_gnutls_global_init();
1675 &(native->sock), NULL, NULL);
1677 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1679 native->server, native->port,
pcmk_rc_str(rc), rc);
1680 lrmd_tls_connection_destroy(lrmd);
1684 rc = lrmd__init_remote_key(&psk_key);
1686 lrmd_tls_connection_destroy(lrmd);
1690 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1692 gnutls_free(psk_key.data);
1694 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1696 native->psk_cred_c);
1697 if (native->remote->tls_session == NULL) {
1698 lrmd_tls_connection_destroy(lrmd);
1702 if (tls_client_handshake(lrmd) !=
pcmk_rc_ok) {
1706 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1712 rc = add_tls_to_mainloop(lrmd,
false);
1719 lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1724 switch (native->type) {
1726 rc = lrmd_ipc_connect(lrmd, fd);
1729 #ifdef HAVE_GNUTLS_GNUTLS_H 1730 case pcmk__client_tls:
1731 rc = lrmd_tls_connect(lrmd, fd);
1736 crm_err(
"Unsupported executor connection type (bug?): %d",
1738 rc = -EPROTONOSUPPORT;
1742 rc = lrmd_handshake(lrmd,
name);
1754 CRM_CHECK(native && native->callback,
return -EINVAL);
1756 switch (native->type) {
1760 rc = lrmd_api_connect(lrmd,
name, NULL);
1762 report_async_connection_result(lrmd, rc);
1765 #ifdef HAVE_GNUTLS_GNUTLS_H 1766 case pcmk__client_tls:
1767 rc = lrmd_tls_connect_async(lrmd,
timeout);
1771 crm_err(
"Unsupported executor connection type (bug?): %d",
1773 rc = -EPROTONOSUPPORT;
1780 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1784 if (native->source != NULL) {
1787 native->source = NULL;
1790 }
else if (native->ipc) {
1800 #ifdef HAVE_GNUTLS_GNUTLS_H 1802 lrmd_tls_disconnect(
lrmd_t * lrmd)
1806 if (native->remote->tls_session) {
1807 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1808 gnutls_deinit(*native->remote->tls_session);
1809 gnutls_free(native->remote->tls_session);
1810 native->remote->tls_session = NULL;
1813 if (native->async_timer) {
1814 g_source_remove(native->async_timer);
1815 native->async_timer = 0;
1818 if (native->source != NULL) {
1821 native->source = NULL;
1823 }
else if (native->sock) {
1824 close(native->sock);
1828 if (native->pending_notify) {
1829 g_list_free_full(native->pending_notify, lrmd_free_xml);
1830 native->pending_notify = NULL;
1836 lrmd_api_disconnect(
lrmd_t * lrmd)
1841 switch (native->type) {
1843 crm_debug(
"Disconnecting from local executor");
1844 lrmd_ipc_disconnect(lrmd);
1846 #ifdef HAVE_GNUTLS_GNUTLS_H 1847 case pcmk__client_tls:
1848 crm_debug(
"Disconnecting from remote executor on %s",
1849 native->remote_nodename);
1850 lrmd_tls_disconnect(lrmd);
1854 crm_err(
"Unsupported executor connection type (bug?): %d",
1856 rc = -EPROTONOSUPPORT;
1859 free(native->token);
1860 native->token = NULL;
1862 free(native->peer_version);
1863 native->peer_version = NULL;
1868 lrmd_api_register_rsc(
lrmd_t * lrmd,
1874 xmlNode *
data = NULL;
1876 if (!
class || !
type || !rsc_id) {
1880 && (provider == NULL)) {
1913 const char *provider,
const char *
type)
1938 free(rsc_info->
type);
1949 xmlNode *output = NULL;
1950 const char *
class = NULL;
1951 const char *provider = NULL;
1952 const char *
type = NULL;
1967 if (!
class || !
type) {
1994 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1997 xmlNode *
data = NULL;
1998 xmlNode *output_xml = NULL;
2001 if (output == NULL) {
2013 timeout_ms, options, TRUE);
2019 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
2025 (rsc_xml != NULL) && (rc ==
pcmk_ok);
2029 if (rsc_id == NULL) {
2030 crm_err(
"Could not parse recurring operation information from executor");
2040 if (op_info == NULL) {
2044 op_info->
rsc_id = strdup(rsc_id);
2051 *output = g_list_prepend(*output, op_info);
2064 native->callback = callback;
2072 native->proxy_callback = callback;
2073 native->proxy_callback_userdata = userdata;
2077 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
2081 if (native->proxy_callback) {
2083 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
2096 return lrmd_send_xml_no_reply(lrmd, msg);
2100 stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
2105 if (stonith_api == NULL) {
2106 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
2111 provider, output, 0);
2112 if ((rc ==
pcmk_ok) && (*output == NULL)) {
2115 stonith_api->
cmds->
free(stonith_api);
2120 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
2121 const char *
type,
char **output,
2125 output, options, NULL);
2129 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
2130 const char *provider,
const char *
type,
2135 GHashTable *params_table = NULL;
2137 if (!standard || !
type) {
2144 return stonith_get_metadata(provider,
type, output);
2166 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
2167 standard, provider,
type);
2172 if (!
action->stdout_data) {
2173 crm_err(
"Failed to receive meta-data for %s:%s:%s",
2174 standard, provider,
type);
2179 *output = strdup(
action->stdout_data);
2186 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2187 const char *userdata, guint interval_ms,
2205 for (tmp = params; tmp; tmp = tmp->
next) {
2218 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2231 for (tmp = params; tmp; tmp = tmp->
next) {
2244 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2267 if (stonith_api == NULL) {
2268 crm_err(
"Could not list fence agents: API memory allocation failed");
2272 &stonith_resources, 0);
2273 stonith_api->
cmds->
free(stonith_api);
2275 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2278 *resources = lrmd_list_add(*resources, dIter->
value);
2287 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2288 const char *provider)
2291 int stonith_count = 0;
2297 GList *gIter = NULL;
2300 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2301 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2304 g_list_free_full(agents, free);
2311 if (stonith_count) {
2313 stonith_count = list_stonith_agents(resources);
2314 if (stonith_count > 0) {
2315 rc += stonith_count;
2319 crm_notice(
"No agents found for class %s",
class);
2320 rc = -EPROTONOSUPPORT;
2326 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2329 GList *agents = NULL;
2330 GList *gIter2 = NULL;
2333 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2338 g_list_free_full(agents, free);
2343 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2346 char *provider = NULL;
2347 GList *ocf_providers = NULL;
2348 GList *gIter = NULL;
2352 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2353 provider = gIter->data;
2354 if (!agent || does_provider_have_agent(agent, provider,
2356 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2361 g_list_free_full(ocf_providers, free);
2369 GList *standards = NULL;
2370 GList *gIter = NULL;
2374 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2375 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2379 if (list_stonith_agents(NULL) > 0) {
2384 g_list_free_full(standards, free);
2419 *api = calloc(1,
sizeof(
lrmd_t));
2437 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2445 (*api)->cmds->connect_async = lrmd_api_connect_async;
2446 (*api)->cmds->is_connected = lrmd_api_is_connected;
2447 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2448 (*api)->cmds->disconnect = lrmd_api_disconnect;
2449 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2450 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2451 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2452 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2453 (*api)->cmds->set_callback = lrmd_api_set_callback;
2454 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2455 (*api)->cmds->exec = lrmd_api_exec;
2456 (*api)->cmds->cancel = lrmd_api_cancel;
2457 (*api)->cmds->list_agents = lrmd_api_list_agents;
2458 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2459 (*api)->cmds->list_standards = lrmd_api_list_standards;
2460 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2461 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2463 if ((nodename == NULL) && (server == NULL)) {
2466 #ifdef HAVE_GNUTLS_GNUTLS_H 2467 if (nodename == NULL) {
2469 }
else if (server == NULL) {
2472 pvt->type = pcmk__client_tls;
2473 pvt->remote_nodename = strdup(nodename);
2474 pvt->server = strdup(server);
2475 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2481 if (pvt->port == 0) {
2485 crm_err(
"Cannot communicate with Pacemaker Remote " 2486 "because GnuTLS is not enabled for this build");
2519 if (lrmd->
cmds != NULL) {
2528 #ifdef HAVE_GNUTLS_GNUTLS_H 2529 free(native->server);
2531 free(native->remote_nodename);
2532 free(native->remote);
2533 free(native->token);
2534 free(native->peer_version);
2540 struct metadata_cb {
2555 struct metadata_cb *metadata_cb = (
struct metadata_cb *)
action->cb_data;
2562 metadata_cb->callback(0, &
result, metadata_cb->user_data);
2587 void (*callback)(
int pid,
2593 struct metadata_cb *metadata_cb = NULL;
2596 CRM_CHECK(callback != NULL,
return EINVAL);
2598 if ((rsc == NULL) || (rsc->
standard == NULL) || (rsc->
type == NULL)) {
2601 "Invalid resource specification");
2602 callback(0, &
result, user_data);
2610 callback, user_data);
2622 callback(0, &
result, user_data);
2629 callback(0, &
result, user_data);
2635 action->cb_data = calloc(1,
sizeof(
struct metadata_cb));
2636 if (
action->cb_data == NULL) {
2640 callback(0, &
result, user_data);
2645 metadata_cb = (
struct metadata_cb *)
action->cb_data;
2646 metadata_cb->callback = callback;
2647 metadata_cb->user_data = user_data;
2668 const char *exit_reason)
2670 if (event == NULL) {
2690 if (event == NULL) {
2695 event->exit_reason = NULL;
2697 free((
void *) event->
output);
2698 event->output = NULL;
2716 if (native->remote == NULL) {
2719 return native->remote->uptime;
2728 if (native->remote == NULL) {
2731 return native->remote->start_state;
#define CRM_CHECK(expr, failure_action)
#define LRMD_OP_ALERT_EXEC
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
ocf_exitcode
Exit status codes for resource agents.
#define crm_notice(fmt, args...)
#define PCMK__XA_LRMD_IPC_SESSION
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
void services_action_free(svc_action_t *op)
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
int pcmk_rc2legacy(int rc)
int lrmd__metadata_async(const lrmd_rsc_info_t *rsc, void(*callback)(int pid, const pcmk__action_result_t *result, void *user_data), void *user_data)
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
#define LRMD_OP_RSC_CANCEL
#define PCMK__XE_LRMD_RSC_OP
#define PCMK_DEFAULT_METADATA_TIMEOUT_MS
#define PCMK__XA_LRMD_RSC_OUTPUT
void(* lrmd_event_callback)(lrmd_event_data_t *event)
#define PCMK__XA_LRMD_ALERT_ID
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
void void pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
#define PCMK_ACTION_META_DATA
struct stonith_key_value_s * next
void lrmd_key_value_freeall(lrmd_key_value_t *head)
struct mainloop_io_s mainloop_io_t
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
Create a new lrmd_event_data_t object.
#define PCMK__XE_ATTRIBUTES
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void mainloop_set_trigger(crm_trigger_t *source)
#define DEFAULT_REMOTE_USERNAME
#define LRMD_OP_GET_RECURRING
#define PCMK__XA_LRMD_RCCHANGE_TIME
#define MAX_TLS_RECV_WAIT
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
#define PCMK_RESOURCE_CLASS_OCF
#define PCMK__XA_LRMD_REMOTE_MSG_TYPE
#define PCMK__XA_LRMD_PROTOCOL_VERSION
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
#define PCMK__XA_LRMD_RSC_ACTION
#define CRM_LOG_ASSERT(expr)
#define PCMK__XA_LRMD_ORIGIN
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
long crm_ipc_read(crm_ipc_t *client)
enum crm_ais_msg_types type
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
#define PCMK__XA_LRMD_RSC_EXIT_REASON
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Safely add hash table entry to XML as attribute or name-value pair.
const char * pcmk__env_option(const char *option)
Wrappers for and extensions to glib mainloop.
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new TLS connection to a remote executor.
stonith_t * stonith_api_new(void)
#define PCMK__XA_LRMD_EXEC_OP_STATUS
const char * crm_ipc_buffer(crm_ipc_t *client)
#define PCMK__XA_LRMD_EXEC_TIME
#define LRMD_OP_RSC_UNREG
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace_s, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
#define PCMK__XE_LRMD_RSC
#define PCMK__XE_LRMD_ALERT
#define PCMK__XA_LRMD_CALLOPT
#define DEFAULT_REMOTE_KEY_LOCATION
struct trigger_s crm_trigger_t
#define PCMK__XA_LRMD_CLASS
struct lrmd_private_s lrmd_private_t
int pcmk__connect_generic_ipc(crm_ipc_t *ipc)
int(* free)(stonith_t *st)
Destroy a fencer connection.
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
#define PCMK__UNKNOWN_RESULT
#define crm_warn(fmt, args...)
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
#define PCMK__XA_LRMD_RSC_ID
#define PCMK__XA_LRMD_ALERT_PATH
#define PCMK__XA_LRMD_TIMEOUT
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
#define crm_debug(fmt, args...)
struct crm_ipc_s crm_ipc_t
const char * services__exit_reason(const svc_action_t *action)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
#define ALT_REMOTE_KEY_LOCATION
int pcmk__remote_ready(const pcmk__remote_t *remote, int timeout_ms)
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
svc_action_t * services__create_resource_action(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
struct lrmd_list_s * next
gboolean services_action_sync(svc_action_t *op)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
#define LRMD_PROTOCOL_VERSION
#define PCMK__XA_NODE_START_STATE
Parameter invalid (inherently)
void lrmd_free_op_info(lrmd_op_info_t *op_info)
void lrmd_list_freeall(lrmd_list_t *head)
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
#define crm_trace(fmt, args...)
#define PCMK_RESOURCE_CLASS_STONITH
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Object for executing external actions.
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
int pcmk__connect_remote(const char *host, int port, int timeout_ms, int *timer_id, int *sock_fd, void *userdata, void(*callback)(void *userdata, int rc, int sock))
#define PCMK__XA_LRMD_RUN_TIME
void pcmk__str_update(char **str, const char *value)
Wrappers for and extensions to libxml2.
#define PCMK__XA_LRMD_RSC_INTERVAL
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Create a trigger to be used as a mainloop source.
#define LRMD_OP_NEW_CLIENT
#define PCMK__XE_LRMD_CALLDATA
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
int pcmk__remote_send_xml(pcmk__remote_t *remote, const xmlNode *msg)
#define PCMK__XA_LRMD_EXEC_RC
lrmd_rsc_info_t * lrmd_new_rsc_info(const char *rsc_id, const char *standard, const char *provider, const char *type)
void mainloop_del_ipc_client(mainloop_io_t *client)
void crm_ipc_destroy(crm_ipc_t *client)
int pcmk_legacy2rc(int legacy_rc)
GList * resources_list_providers(const char *standard)
Get a list of providers.
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
int(* get_metadata_params)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options, lrmd_key_value_t *params)
Retrieve resource agent metadata synchronously with parameters.
Notify only the client that made the request (rather than all clients)
Execution failed, do not retry anywhere.
#define PCMK__XA_LRMD_TYPE
const char * lrmd__node_start_state(lrmd_t *lrmd)
struct lrmd_key_value_s * next
void free_xml(xmlNode *child)
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace_s, char **output, int timeout_sec)
Retrieve a fence agent's metadata.
CRM_TRACE_INIT_DATA(lrmd)
#define pcmk__str_copy(str)
xmlNode * pcmk__xml_parse(const char *input)
#define PCMK__XE_LRMD_COMMAND
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
#define PCMK__XA_LRMD_REMOTE_MSG_ID
time_t lrmd__uptime(lrmd_t *lrmd)
Wait for request to be completed before returning.
bool crm_ipc_connected(crm_ipc_t *client)
#define pcmk__assert(expr)
int lrmd_poll(lrmd_t *lrmd, int timeout)
Check whether a message is available on an executor connection.
void lrmd__reset_result(lrmd_event_data_t *event)
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
#define crm_log_xml_err(xml, text)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
pcmk__action_result_t result
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
const char * remote_nodename
lrmd_api_operations_t * cmds
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
GList * resources_list_standards(void)
gboolean stonith__watchdog_fencing_enabled_for_node(const char *node)
#define crm_err(fmt, args...)
#define PCMK__XA_LRMD_WATCHDOG
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
enum lrmd_callback_event type
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *head, const char *key, const char *value)
stonith_api_operations_t * cmds
#define PCMK__XA_LRMD_CLIENTID
#define PCMK__XA_LRMD_RSC_START_DELAY
int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
#define pcmk__mem_assert(ptr)
#define PCMK__XA_LRMD_QUEUE_TIME
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
#define PCMK__ENV_AUTHKEY_LOCATION
int lrmd__remote_send_xml(pcmk__remote_t *session, xmlNode *msg, uint32_t id, const char *msg_type)
#define PCMK__XA_LRMD_PROVIDER
void lrmd_internal_set_proxy_callback(lrmd_t *lrmd, void *userdata, void(*callback)(lrmd_t *lrmd, void *userdata, xmlNode *msg))
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define crm_log_xml_trace(xml, text)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define PCMK__XA_LRMD_IS_IPC_PROVIDER
int lrmd__validate_remote_settings(lrmd_t *lrmd, GHashTable *hash)
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
int pcmk__read_remote_message(pcmk__remote_t *remote, int timeout_ms)
#define PCMK__XA_LRMD_CLIENTNAME
#define PCMK__XA_LRMD_RSC_DELETED
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define pcmk__assert_alloc(nmemb, size)
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
void pcmk__reset_result(pcmk__action_result_t *result)
#define PCMK__XA_LRMD_RSC_USERDATA_STR
int crm_ipc_send(crm_ipc_t *client, const xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Send an IPC XML message.
void crm_ipc_close(crm_ipc_t *client)
xmlNode * pcmk__xe_next_same(const xmlNode *node)
#define PCMK__XA_LRMD_CALLID
Execution failed, may be retried.
#define crm_info(fmt, args...)
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
xmlNode * pcmk__remote_message_xml(pcmk__remote_t *remote)
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
int stonith__metadata_async(const char *agent, int timeout_sec, void(*callback)(int pid, const pcmk__action_result_t *result, void *user_data), void *user_data)
#define PCMK_OPT_STONITH_WATCHDOG_TIMEOUT