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);
72 typedef struct lrmd_private_s {
83 char *remote_nodename;
84 #ifdef HAVE_GNUTLS_GNUTLS_H 87 gnutls_psk_client_credentials_t psk_cred_c;
97 int expected_late_replies;
98 GList *pending_notify;
105 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
106 void *proxy_callback_userdata;
111 lrmd_list_add(
lrmd_list_t * head,
const char *value)
116 p->
val = strdup(value);
119 while (end && end->
next) {
138 char *val = (
char *)head->
val;
153 p->
key = strdup(key);
154 p->
value = strdup(value);
157 while (end && end->
next) {
204 event->interval_ms = interval_ms;
215 copy->
type =
event->type;
225 copy->
call_id =
event->call_id;
226 copy->
timeout =
event->timeout;
230 copy->
rc =
event->rc;
232 copy->
t_run =
event->t_run;
254 free((
void *) event->
rsc_id);
259 if (event->
params != NULL) {
260 g_hash_table_destroy(event->
params);
266 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
274 if (proxy_session != NULL) {
276 lrmd_internal_proxy_dispatch(lrmd, msg);
278 }
else if (!native->callback) {
280 crm_trace(
"notify event received but client has not set callback");
284 event.remote_nodename = native->remote_nodename;
314 event.t_run = (
unsigned int) epoch;
317 event.t_rcchange = (
unsigned int) epoch;
321 event.exec_time = QB_MAX(0, exec_time);
325 event.queue_time = QB_MAX(0, queue_time);
347 native->callback(&event);
350 g_hash_table_destroy(event.params);
357 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
362 if (native->callback != NULL) {
365 lrmd_dispatch_internal(lrmd, msg);
371 #ifdef HAVE_GNUTLS_GNUTLS_H 373 lrmd_free_xml(gpointer userdata)
379 remote_executor_connected(
lrmd_t * lrmd)
383 return (native->remote->tls_session != NULL);
398 lrmd_tls_dispatch(gpointer userdata)
405 if (!remote_executor_connected(lrmd)) {
406 crm_trace(
"TLS dispatch triggered after disconnect");
414 if (native->pending_notify) {
417 crm_trace(
"Processing pending notifies");
418 for (iter = native->pending_notify; iter; iter = iter->next) {
419 lrmd_dispatch_internal(lrmd, iter->data);
421 g_list_free_full(native->pending_notify, lrmd_free_xml);
422 native->pending_notify = NULL;
443 lrmd_dispatch_internal(lrmd, xml);
445 if (native->expected_late_replies > 0) {
446 native->expected_late_replies--;
451 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
458 if (rc == ENOTCONN) {
459 crm_info(
"Lost %s executor connection while reading data",
460 (native->remote_nodename? native->remote_nodename :
"local"));
461 lrmd_tls_disconnect(lrmd);
474 switch (native->type) {
478 #ifdef HAVE_GNUTLS_GNUTLS_H 479 case pcmk__client_tls:
480 if (native->pending_notify) {
496 crm_err(
"Unsupported executor connection type (bug?): %d",
498 return -EPROTONOSUPPORT;
511 switch (private->type) {
517 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
521 #ifdef HAVE_GNUTLS_GNUTLS_H 522 case pcmk__client_tls:
523 lrmd_tls_dispatch(lrmd);
527 crm_err(
"Unsupported executor connection type (bug?): %d",
531 if (lrmd_api_is_connected(lrmd) == FALSE) {
540 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
543 xmlNode *op_msg = NULL;
559 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
560 op, (
long)options, options);
565 lrmd_ipc_connection_destroy(gpointer userdata)
570 switch (native->type) {
572 crm_info(
"Disconnected from local executor");
574 #ifdef HAVE_GNUTLS_GNUTLS_H 575 case pcmk__client_tls:
576 crm_info(
"Disconnected from remote executor on %s",
577 native->remote_nodename);
581 crm_err(
"Unsupported executor connection type %d (bug?)",
587 native->source = NULL;
589 if (native->callback) {
592 event.remote_nodename = native->remote_nodename;
593 native->callback(&event);
597 #ifdef HAVE_GNUTLS_GNUTLS_H 599 lrmd_tls_connection_destroy(gpointer userdata)
604 crm_info(
"TLS connection destroyed");
606 if (native->remote->tls_session) {
607 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
608 gnutls_deinit(*native->remote->tls_session);
609 gnutls_free(native->remote->tls_session);
610 native->remote->tls_session = NULL;
612 if (native->psk_cred_c) {
613 gnutls_psk_free_client_credentials(native->psk_cred_c);
618 if (native->process_notify) {
620 native->process_notify = NULL;
622 if (native->pending_notify) {
623 g_list_free_full(native->pending_notify, lrmd_free_xml);
624 native->pending_notify = NULL;
627 free(native->remote->buffer);
628 free(native->remote->start_state);
629 native->remote->buffer = NULL;
630 native->remote->start_state = NULL;
633 native->psk_cred_c = NULL;
636 if (native->callback) {
640 native->callback(&event);
648 const char *msg_type)
657 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
661 time_t start = time(NULL);
662 const char *msg_type = NULL;
664 int remaining_timeout = 0;
673 for (*reply = NULL; *reply == NULL; ) {
676 if (*reply == NULL) {
678 if (remaining_timeout) {
679 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
681 remaining_timeout = total_timeout;
683 if (remaining_timeout <= 0) {
693 if (*reply == NULL) {
702 crm_err(
"Empty msg type received while waiting for reply");
708 native->pending_notify = g_list_append(native->pending_notify, *reply);
709 if (native->process_notify) {
716 crm_err(
"Expected a reply, got %s", msg_type);
719 }
else if (reply_id != expected_reply_id) {
720 if (native->expected_late_replies > 0) {
721 native->expected_late_replies--;
723 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
730 if (native->remote->buffer && native->process_notify) {
739 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
744 global_remote_msg_id++;
745 if (global_remote_msg_id <= 0) {
746 global_remote_msg_id = 1;
752 crm_err(
"Disconnecting because TLS message could not be sent to " 754 lrmd_tls_disconnect(lrmd);
760 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
765 if (!remote_executor_connected(lrmd)) {
769 rc = send_remote_message(lrmd, msg);
774 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
776 crm_err(
"Disconnecting remote after request %d reply not received: %s " 777 CRM_XS " rc=%d timeout=%dms",
779 lrmd_tls_disconnect(lrmd);
793 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
798 switch (native->type) {
802 #ifdef HAVE_GNUTLS_GNUTLS_H 803 case pcmk__client_tls:
804 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
808 crm_err(
"Unsupported executor connection type (bug?): %d",
810 rc = -EPROTONOSUPPORT;
817 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
822 switch (native->type) {
826 #ifdef HAVE_GNUTLS_GNUTLS_H 827 case pcmk__client_tls:
828 rc = send_remote_message(lrmd, msg);
833 native->expected_late_replies++;
839 crm_err(
"Unsupported executor connection type (bug?): %d",
841 rc = -EPROTONOSUPPORT;
848 lrmd_api_is_connected(
lrmd_t * lrmd)
852 switch (native->type) {
855 #ifdef HAVE_GNUTLS_GNUTLS_H 856 case pcmk__client_tls:
857 return remote_executor_connected(lrmd);
860 crm_err(
"Unsupported executor connection type (bug?): %d",
885 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
886 xmlNode **output_data,
int timeout,
891 xmlNode *op_msg = NULL;
892 xmlNode *op_reply = NULL;
894 if (!lrmd_api_is_connected(lrmd)) {
899 crm_err(
"No operation specified");
905 crm_trace(
"Sending %s op to executor", op);
907 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
909 if (op_msg == NULL) {
914 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
916 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
921 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op,
timeout, rc);
924 }
else if(op_reply == NULL) {
939 *output_data = op_reply;
944 if (lrmd_api_is_connected(lrmd) == FALSE) {
945 crm_err(
"Executor disconnected");
954 lrmd_api_poke_connection(
lrmd_t * lrmd)
992 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
996 xmlNode *reply = NULL;
1005 if (native->proxy_callback) {
1009 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
1012 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
1014 }
else if (reply == NULL) {
1015 crm_err(
"Did not receive registration reply");
1024 long long uptime = -1;
1034 native->remote->uptime = uptime;
1037 native->remote->start_state = strdup(start_state);
1040 if (rc == -EPROTO) {
1041 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
1046 crm_err(
"Invalid registration message: %s", msg_type);
1049 }
else if (tmp_ticket == NULL) {
1050 crm_err(
"No registration token provided");
1054 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1055 native->token = strdup(tmp_ticket);
1065 lrmd_api_disconnect(lrmd);
1071 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1078 .destroy = lrmd_ipc_connection_destroy
1081 crm_info(
"Connecting to executor");
1086 if (native->ipc != NULL) {
1101 if (native->ipc == NULL) {
1102 crm_debug(
"Could not connect to the executor API");
1109 #ifdef HAVE_GNUTLS_GNUTLS_H 1111 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1113 CRM_ASSERT((dest != NULL) && (source != NULL) && (source->data != NULL));
1115 dest->data = gnutls_malloc(source->size);
1118 memcpy(dest->data, source->data, source->size);
1119 dest->size = source->size;
1123 clear_gnutls_datum(gnutls_datum_t *datum)
1125 gnutls_free(datum->data);
1130 #define KEY_READ_LEN 256 // Chunk size for reading key from file 1134 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1136 FILE *stream = NULL;
1137 size_t buf_len = KEY_READ_LEN;
1139 if ((location == NULL) || (key == NULL)) {
1143 stream = fopen(location,
"r");
1144 if (stream == NULL) {
1148 key->data = gnutls_malloc(buf_len);
1150 while (!feof(stream)) {
1151 int next = fgetc(stream);
1154 if (!feof(stream)) {
1155 crm_warn(
"Pacemaker Remote key read was partially successful " 1156 "(copy in memory may be corrupted)");
1160 if (key->size == buf_len) {
1161 buf_len = key->size + KEY_READ_LEN;
1162 key->data = gnutls_realloc(key->data, buf_len);
1165 key->data[key->size++] = (
unsigned char) next;
1169 if (key->size == 0) {
1170 clear_gnutls_datum(key);
1178 struct key_cache_s {
1180 const char *location;
1185 key_is_cached(
struct key_cache_s *key_cache)
1187 return key_cache->updated != 0;
1191 key_cache_expired(
struct key_cache_s *key_cache)
1193 return (time(NULL) - key_cache->updated) >= 60;
1197 clear_key_cache(
struct key_cache_s *key_cache)
1199 clear_gnutls_datum(&(key_cache->key));
1200 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1201 key_cache->updated = 0;
1202 key_cache->location = NULL;
1203 crm_debug(
"Cleared Pacemaker Remote key cache");
1208 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1210 copy_gnutls_datum(key, &(key_cache->key));
1211 crm_debug(
"Using cached Pacemaker Remote key from %s",
1212 pcmk__s(key_cache->location,
"unknown location"));
1216 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1217 const char *location)
1219 key_cache->updated = time(NULL);
1220 key_cache->location = location;
1221 copy_gnutls_datum(&(key_cache->key), key);
1222 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1223 pcmk__s(location,
"unknown location"));
1237 get_remote_key(
const char *location, gnutls_datum_t *key)
1239 static struct key_cache_s key_cache = { 0, };
1242 if ((location == NULL) || (key == NULL)) {
1246 if (key_is_cached(&key_cache)) {
1247 if (key_cache_expired(&key_cache)) {
1248 clear_key_cache(&key_cache);
1250 get_cached_key(&key_cache, key);
1255 rc = read_gnutls_key(location, key);
1259 cache_key(&key_cache, key, location);
1277 lrmd__init_remote_key(gnutls_datum_t *key)
1279 static const char *env_location = NULL;
1280 static bool need_env =
true;
1286 bool env_is_default =
false;
1287 bool env_is_fallback =
false;
1295 if (env_location != NULL) {
1296 env_rc = get_remote_key(env_location, key);
1315 if (env_is_default) {
1316 default_rc = env_rc;
1323 if (env_is_fallback) {
1334 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1336 env_is_default?
"" :
"or default location ",
1338 !env_is_default && !env_is_fallback?
" " :
"",
1339 env_is_fallback?
"" :
"or fallback location ",
1346 crm_warn(
"Could not read Pacemaker Remote key from %s " 1347 "(using %s location %s instead): %s",
1349 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1352 crm_warn(
"This undocumented behavior is deprecated and unsafe and will " 1353 "be removed in a future release");
1362 crm_warn(
"Read Pacemaker Remote key from alternate location %s",
1364 crm_warn(
"This undocumented behavior is deprecated and unsafe and will " 1365 "be removed in a future release");
1368 crm_warn(
"Could not read Pacemaker Remote key from default location %s" 1369 " (or fallback location %s): %s",
1380 lrmd_gnutls_global_init(
void)
1382 static int gnutls_init = 0;
1385 crm_gnutls_global_init();
1392 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1396 if (native->callback) {
1399 event.remote_nodename = native->remote_nodename;
1400 event.connection_rc = rc;
1401 native->callback(&event);
1405 #ifdef HAVE_GNUTLS_GNUTLS_H 1415 tls_client_handshake(
lrmd_t *lrmd)
1418 int tls_rc = GNUTLS_E_SUCCESS;
1419 int rc = pcmk__tls_client_handshake(native->remote, TLS_HANDSHAKE_TIMEOUT,
1423 crm_warn(
"Disconnecting after TLS handshake with " 1424 "Pacemaker Remote server %s:%d failed: %s",
1425 native->server, native->port,
1426 (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);
1445 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1451 native->server, native->port);
1455 .destroy = lrmd_tls_connection_destroy,
1459 lrmd_tls_dispatch, lrmd);
1470 rc = lrmd_handshake(lrmd,
name);
1478 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1482 gnutls_datum_t psk_key = { NULL, 0 };
1484 native->async_timer = 0;
1487 lrmd_tls_connection_destroy(lrmd);
1488 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1490 native->server, native->port,
pcmk_rc_str(rc), rc);
1499 native->sock = sock;
1501 rc = lrmd__init_remote_key(&psk_key);
1503 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1505 native->server, native->port,
pcmk_rc_str(rc), rc);
1506 lrmd_tls_connection_destroy(lrmd);
1511 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1513 gnutls_free(psk_key.data);
1515 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1517 native->psk_cred_c);
1518 if (native->remote->tls_session == NULL) {
1519 lrmd_tls_connection_destroy(lrmd);
1520 report_async_connection_result(lrmd, -EPROTO);
1524 if (tls_client_handshake(lrmd) !=
pcmk_rc_ok) {
1529 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1530 native->server, native->port);
1531 rc = add_tls_to_mainloop(lrmd,
true);
1542 lrmd_gnutls_global_init();
1545 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1547 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1549 native->server, native->port,
pcmk_rc_str(rc), rc);
1552 native->async_timer = timer_id;
1557 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1562 gnutls_datum_t psk_key = { NULL, 0 };
1564 lrmd_gnutls_global_init();
1568 &(native->sock), NULL, NULL);
1570 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1572 native->server, native->port,
pcmk_rc_str(rc), rc);
1573 lrmd_tls_connection_destroy(lrmd);
1577 rc = lrmd__init_remote_key(&psk_key);
1579 lrmd_tls_connection_destroy(lrmd);
1583 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1585 gnutls_free(psk_key.data);
1587 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1589 native->psk_cred_c);
1590 if (native->remote->tls_session == NULL) {
1591 lrmd_tls_connection_destroy(lrmd);
1595 if (tls_client_handshake(lrmd) !=
pcmk_rc_ok) {
1599 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1605 add_tls_to_mainloop(lrmd,
false);
1612 lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1617 switch (native->type) {
1619 rc = lrmd_ipc_connect(lrmd, fd);
1621 #ifdef HAVE_GNUTLS_GNUTLS_H 1622 case pcmk__client_tls:
1623 rc = lrmd_tls_connect(lrmd, fd);
1627 crm_err(
"Unsupported executor connection type (bug?): %d",
1629 rc = -EPROTONOSUPPORT;
1633 rc = lrmd_handshake(lrmd,
name);
1645 CRM_CHECK(native && native->callback,
return -EINVAL);
1647 switch (native->type) {
1651 rc = lrmd_api_connect(lrmd,
name, NULL);
1653 report_async_connection_result(lrmd, rc);
1656 #ifdef HAVE_GNUTLS_GNUTLS_H 1657 case pcmk__client_tls:
1658 rc = lrmd_tls_connect_async(lrmd,
timeout);
1661 report_async_connection_result(lrmd, rc);
1666 crm_err(
"Unsupported executor connection type (bug?): %d",
1668 rc = -EPROTONOSUPPORT;
1675 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1679 if (native->source != NULL) {
1682 native->source = NULL;
1685 }
else if (native->ipc) {
1695 #ifdef HAVE_GNUTLS_GNUTLS_H 1697 lrmd_tls_disconnect(
lrmd_t * lrmd)
1701 if (native->remote->tls_session) {
1702 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1703 gnutls_deinit(*native->remote->tls_session);
1704 gnutls_free(native->remote->tls_session);
1705 native->remote->tls_session = NULL;
1708 if (native->async_timer) {
1709 g_source_remove(native->async_timer);
1710 native->async_timer = 0;
1713 if (native->source != NULL) {
1716 native->source = NULL;
1718 }
else if (native->sock) {
1719 close(native->sock);
1723 if (native->pending_notify) {
1724 g_list_free_full(native->pending_notify, lrmd_free_xml);
1725 native->pending_notify = NULL;
1731 lrmd_api_disconnect(
lrmd_t * lrmd)
1736 switch (native->type) {
1738 crm_debug(
"Disconnecting from local executor");
1739 lrmd_ipc_disconnect(lrmd);
1741 #ifdef HAVE_GNUTLS_GNUTLS_H 1742 case pcmk__client_tls:
1743 crm_debug(
"Disconnecting from remote executor on %s",
1744 native->remote_nodename);
1745 lrmd_tls_disconnect(lrmd);
1749 crm_err(
"Unsupported executor connection type (bug?): %d",
1751 rc = -EPROTONOSUPPORT;
1754 free(native->token);
1755 native->token = NULL;
1757 free(native->peer_version);
1758 native->peer_version = NULL;
1763 lrmd_api_register_rsc(
lrmd_t * lrmd,
1769 xmlNode *
data = NULL;
1771 if (!
class || !
type || !rsc_id) {
1775 && (provider == NULL)) {
1808 const char *provider,
const char *
type)
1833 free(rsc_info->
type);
1844 xmlNode *output = NULL;
1845 const char *
class = NULL;
1846 const char *provider = NULL;
1847 const char *
type = NULL;
1862 if (!
class || !
type) {
1889 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1892 xmlNode *
data = NULL;
1893 xmlNode *output_xml = NULL;
1896 if (output == NULL) {
1908 timeout_ms, options, TRUE);
1914 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1920 (rsc_xml != NULL) && (rc ==
pcmk_ok);
1924 if (rsc_id == NULL) {
1925 crm_err(
"Could not parse recurring operation information from executor");
1935 if (op_info == NULL) {
1939 op_info->
rsc_id = strdup(rsc_id);
1946 *output = g_list_prepend(*output, op_info);
1959 native->callback = callback;
1967 native->proxy_callback = callback;
1968 native->proxy_callback_userdata = userdata;
1972 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1976 if (native->proxy_callback) {
1978 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1991 return lrmd_send_xml_no_reply(lrmd, msg);
1995 stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
2000 if (stonith_api == NULL) {
2001 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
2006 provider, output, 0);
2007 if ((rc ==
pcmk_ok) && (*output == NULL)) {
2010 stonith_api->
cmds->
free(stonith_api);
2015 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
2016 const char *
type,
char **output,
2020 output, options, NULL);
2024 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
2025 const char *provider,
const char *
type,
2030 GHashTable *params_table = NULL;
2032 if (!standard || !
type) {
2039 return stonith_get_metadata(provider,
type, output);
2061 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
2062 standard, provider,
type);
2067 if (!
action->stdout_data) {
2068 crm_err(
"Failed to receive meta-data for %s:%s:%s",
2069 standard, provider,
type);
2074 *output = strdup(
action->stdout_data);
2081 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2082 const char *userdata, guint interval_ms,
2100 for (tmp = params; tmp; tmp = tmp->
next) {
2113 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2126 for (tmp = params; tmp; tmp = tmp->
next) {
2139 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2162 if (stonith_api == NULL) {
2163 crm_err(
"Could not list fence agents: API memory allocation failed");
2167 &stonith_resources, 0);
2168 stonith_api->
cmds->
free(stonith_api);
2170 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2173 *resources = lrmd_list_add(*resources, dIter->
value);
2182 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2183 const char *provider)
2186 int stonith_count = 0;
2192 GList *gIter = NULL;
2195 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2196 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2199 g_list_free_full(agents, free);
2206 if (stonith_count) {
2208 stonith_count = list_stonith_agents(resources);
2209 if (stonith_count > 0) {
2210 rc += stonith_count;
2214 crm_notice(
"No agents found for class %s",
class);
2215 rc = -EPROTONOSUPPORT;
2221 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2224 GList *agents = NULL;
2225 GList *gIter2 = NULL;
2228 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2233 g_list_free_full(agents, free);
2238 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2241 char *provider = NULL;
2242 GList *ocf_providers = NULL;
2243 GList *gIter = NULL;
2247 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2248 provider = gIter->data;
2249 if (!agent || does_provider_have_agent(agent, provider,
2251 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2256 g_list_free_full(ocf_providers, free);
2264 GList *standards = NULL;
2265 GList *gIter = NULL;
2269 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2270 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2274 if (list_stonith_agents(NULL) > 0) {
2279 g_list_free_full(standards, free);
2314 *api = calloc(1,
sizeof(
lrmd_t));
2332 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2340 (*api)->cmds->connect_async = lrmd_api_connect_async;
2341 (*api)->cmds->is_connected = lrmd_api_is_connected;
2342 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2343 (*api)->cmds->disconnect = lrmd_api_disconnect;
2344 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2345 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2346 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2347 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2348 (*api)->cmds->set_callback = lrmd_api_set_callback;
2349 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2350 (*api)->cmds->exec = lrmd_api_exec;
2351 (*api)->cmds->cancel = lrmd_api_cancel;
2352 (*api)->cmds->list_agents = lrmd_api_list_agents;
2353 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2354 (*api)->cmds->list_standards = lrmd_api_list_standards;
2355 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2356 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2358 if ((nodename == NULL) && (server == NULL)) {
2361 #ifdef HAVE_GNUTLS_GNUTLS_H 2362 if (nodename == NULL) {
2364 }
else if (server == NULL) {
2367 pvt->type = pcmk__client_tls;
2368 pvt->remote_nodename = strdup(nodename);
2369 pvt->server = strdup(server);
2370 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2376 if (pvt->port == 0) {
2380 crm_err(
"Cannot communicate with Pacemaker Remote " 2381 "because GnuTLS is not enabled for this build");
2414 if (lrmd->
cmds != NULL) {
2423 #ifdef HAVE_GNUTLS_GNUTLS_H 2424 free(native->server);
2426 free(native->remote_nodename);
2427 free(native->remote);
2428 free(native->token);
2429 free(native->peer_version);
2435 struct metadata_cb {
2450 struct metadata_cb *metadata_cb = (
struct metadata_cb *)
action->cb_data;
2457 metadata_cb->callback(0, &
result, metadata_cb->user_data);
2482 void (*callback)(
int pid,
2488 struct metadata_cb *metadata_cb = NULL;
2491 CRM_CHECK(callback != NULL,
return EINVAL);
2493 if ((rsc == NULL) || (rsc->
standard == NULL) || (rsc->
type == NULL)) {
2496 "Invalid resource specification");
2497 callback(0, &
result, user_data);
2505 callback, user_data);
2517 callback(0, &
result, user_data);
2524 callback(0, &
result, user_data);
2530 action->cb_data = calloc(1,
sizeof(
struct metadata_cb));
2531 if (
action->cb_data == NULL) {
2535 callback(0, &
result, user_data);
2540 metadata_cb = (
struct metadata_cb *)
action->cb_data;
2541 metadata_cb->callback = callback;
2542 metadata_cb->user_data = user_data;
2563 const char *exit_reason)
2565 if (event == NULL) {
2585 if (event == NULL) {
2590 event->exit_reason = NULL;
2592 free((
void *) event->
output);
2593 event->output = NULL;
2611 if (native->remote == NULL) {
2614 return native->remote->uptime;
2623 if (native->remote == NULL) {
2626 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)
bool crm_ipc_connected(crm_ipc_t *client)
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