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 63 # define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000 64 gnutls_psk_client_credentials_t psk_cred_s;
65 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
66 static int global_remote_msg_id = 0;
67 static void lrmd_tls_connection_destroy(gpointer userdata);
70 typedef struct lrmd_private_s {
81 char *remote_nodename;
82 #ifdef HAVE_GNUTLS_GNUTLS_H 85 gnutls_psk_client_credentials_t psk_cred_c;
95 int expected_late_replies;
96 GList *pending_notify;
103 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
104 void *proxy_callback_userdata;
109 lrmd_list_add(
lrmd_list_t * head,
const char *value)
114 p->
val = strdup(value);
117 while (end && end->
next) {
136 char *val = (
char *)head->
val;
151 p->
key = strdup(key);
152 p->
value = strdup(value);
155 while (end && end->
next) {
202 event->interval_ms = interval_ms;
213 copy->
type =
event->type;
217 copy->
call_id =
event->call_id;
218 copy->
timeout =
event->timeout;
222 copy->
rc =
event->rc;
225 copy->
t_run =
event->t_run;
249 free((
void *) event->
rsc_id);
254 if (event->
params != NULL) {
255 g_hash_table_destroy(event->
params);
261 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
268 if (proxy_session != NULL) {
270 lrmd_internal_proxy_dispatch(lrmd, msg);
272 }
else if (!native->callback) {
274 crm_trace(
"notify event received but client has not set callback");
278 event.remote_nodename = native->remote_nodename;
298 event.t_run = (
unsigned int) epoch;
301 event.t_rcchange = (
unsigned int) epoch;
325 native->callback(&event);
328 g_hash_table_destroy(event.params);
335 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
340 if (native->callback != NULL) {
343 lrmd_dispatch_internal(lrmd, msg);
349 #ifdef HAVE_GNUTLS_GNUTLS_H 351 lrmd_free_xml(gpointer userdata)
357 remote_executor_connected(
lrmd_t * lrmd)
361 return (native->remote->tls_session != NULL);
376 lrmd_tls_dispatch(gpointer userdata)
383 if (!remote_executor_connected(lrmd)) {
384 crm_trace(
"TLS dispatch triggered after disconnect");
392 if (native->pending_notify) {
395 crm_trace(
"Processing pending notifies");
396 for (iter = native->pending_notify; iter; iter = iter->next) {
397 lrmd_dispatch_internal(lrmd, iter->data);
399 g_list_free_full(native->pending_notify, lrmd_free_xml);
400 native->pending_notify = NULL;
420 lrmd_dispatch_internal(lrmd, xml);
422 if (native->expected_late_replies > 0) {
423 native->expected_late_replies--;
428 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
435 if (rc == ENOTCONN) {
436 crm_info(
"Lost %s executor connection while reading data",
437 (native->remote_nodename? native->remote_nodename :
"local"));
438 lrmd_tls_disconnect(lrmd);
451 switch (native->type) {
455 #ifdef HAVE_GNUTLS_GNUTLS_H 456 case pcmk__client_tls:
457 if (native->pending_notify) {
473 crm_err(
"Unsupported executor connection type (bug?): %d",
475 return -EPROTONOSUPPORT;
488 switch (private->type) {
494 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
498 #ifdef HAVE_GNUTLS_GNUTLS_H 499 case pcmk__client_tls:
500 lrmd_tls_dispatch(lrmd);
504 crm_err(
"Unsupported executor connection type (bug?): %d",
508 if (lrmd_api_is_connected(lrmd) == FALSE) {
517 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
536 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
537 op, (
long)options, options);
542 lrmd_ipc_connection_destroy(gpointer userdata)
547 switch (native->type) {
549 crm_info(
"Disconnected from local executor");
551 #ifdef HAVE_GNUTLS_GNUTLS_H 552 case pcmk__client_tls:
553 crm_info(
"Disconnected from remote executor on %s",
554 native->remote_nodename);
558 crm_err(
"Unsupported executor connection type %d (bug?)",
564 native->source = NULL;
566 if (native->callback) {
569 event.remote_nodename = native->remote_nodename;
570 native->callback(&event);
574 #ifdef HAVE_GNUTLS_GNUTLS_H 576 lrmd_tls_connection_destroy(gpointer userdata)
581 crm_info(
"TLS connection destroyed");
583 if (native->remote->tls_session) {
584 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
585 gnutls_deinit(*native->remote->tls_session);
586 gnutls_free(native->remote->tls_session);
588 if (native->psk_cred_c) {
589 gnutls_psk_free_client_credentials(native->psk_cred_c);
594 if (native->process_notify) {
596 native->process_notify = NULL;
598 if (native->pending_notify) {
599 g_list_free_full(native->pending_notify, lrmd_free_xml);
600 native->pending_notify = NULL;
603 free(native->remote->buffer);
604 free(native->remote->start_state);
605 native->remote->buffer = NULL;
606 native->remote->start_state = NULL;
609 native->psk_cred_c = NULL;
610 native->remote->tls_session = NULL;
613 if (native->callback) {
617 native->callback(&event);
625 const char *msg_type)
634 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
638 time_t start = time(NULL);
639 const char *msg_type = NULL;
641 int remaining_timeout = 0;
650 for (*reply = NULL; *reply == NULL; ) {
653 if (*reply == NULL) {
655 if (remaining_timeout) {
656 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
658 remaining_timeout = total_timeout;
660 if (remaining_timeout <= 0) {
670 if (*reply == NULL) {
679 crm_err(
"Empty msg type received while waiting for reply");
685 native->pending_notify = g_list_append(native->pending_notify, *reply);
686 if (native->process_notify) {
693 crm_err(
"Expected a reply, got %s", msg_type);
696 }
else if (reply_id != expected_reply_id) {
697 if (native->expected_late_replies > 0) {
698 native->expected_late_replies--;
700 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
707 if (native->remote->buffer && native->process_notify) {
716 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
721 global_remote_msg_id++;
722 if (global_remote_msg_id <= 0) {
723 global_remote_msg_id = 1;
729 crm_err(
"Disconnecting because TLS message could not be sent to " 731 lrmd_tls_disconnect(lrmd);
737 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
742 if (!remote_executor_connected(lrmd)) {
746 rc = send_remote_message(lrmd, msg);
751 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
753 crm_err(
"Disconnecting remote after request %d reply not received: %s " 754 CRM_XS " rc=%d timeout=%dms",
756 lrmd_tls_disconnect(lrmd);
770 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
775 switch (native->type) {
779 #ifdef HAVE_GNUTLS_GNUTLS_H 780 case pcmk__client_tls:
781 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
785 crm_err(
"Unsupported executor connection type (bug?): %d",
787 rc = -EPROTONOSUPPORT;
794 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
799 switch (native->type) {
803 #ifdef HAVE_GNUTLS_GNUTLS_H 804 case pcmk__client_tls:
805 rc = send_remote_message(lrmd, msg);
810 native->expected_late_replies++;
816 crm_err(
"Unsupported executor connection type (bug?): %d",
818 rc = -EPROTONOSUPPORT;
825 lrmd_api_is_connected(
lrmd_t * lrmd)
829 switch (native->type) {
832 #ifdef HAVE_GNUTLS_GNUTLS_H 833 case pcmk__client_tls:
834 return remote_executor_connected(lrmd);
837 crm_err(
"Unsupported executor connection type (bug?): %d",
862 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
863 xmlNode **output_data,
int timeout,
868 xmlNode *op_msg = NULL;
869 xmlNode *op_reply = NULL;
871 if (!lrmd_api_is_connected(lrmd)) {
876 crm_err(
"No operation specified");
882 crm_trace(
"Sending %s op to executor", op);
884 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
886 if (op_msg == NULL) {
891 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
893 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
898 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op,
timeout, rc);
901 }
else if(op_reply == NULL) {
916 *output_data = op_reply;
921 if (lrmd_api_is_connected(lrmd) == FALSE) {
922 crm_err(
"Executor disconnected");
931 lrmd_api_poke_connection(
lrmd_t * lrmd)
956 value = g_hash_table_lookup(hash,
"stonith-watchdog-timeout");
969 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
973 xmlNode *reply = NULL;
982 if (native->proxy_callback) {
986 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
989 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
991 }
else if (reply == NULL) {
992 crm_err(
"Did not receive registration reply");
999 long long uptime = -1;
1009 native->remote->uptime = uptime;
1012 native->remote->start_state = strdup(start_state);
1015 if (rc == -EPROTO) {
1016 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
1021 crm_err(
"Invalid registration message: %s", msg_type);
1024 }
else if (tmp_ticket == NULL) {
1025 crm_err(
"No registration token provided");
1029 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1030 native->token = strdup(tmp_ticket);
1040 lrmd_api_disconnect(lrmd);
1046 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1053 .destroy = lrmd_ipc_connection_destroy
1056 crm_info(
"Connecting to executor");
1061 if (native->ipc != NULL) {
1076 if (native->ipc == NULL) {
1077 crm_debug(
"Could not connect to the executor API");
1084 #ifdef HAVE_GNUTLS_GNUTLS_H 1086 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1088 CRM_ASSERT((dest != NULL) && (source != NULL) && (source->data != NULL));
1090 dest->data = gnutls_malloc(source->size);
1093 memcpy(dest->data, source->data, source->size);
1094 dest->size = source->size;
1098 clear_gnutls_datum(gnutls_datum_t *datum)
1100 gnutls_free(datum->data);
1105 #define KEY_READ_LEN 256 // Chunk size for reading key from file 1109 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1111 FILE *stream = NULL;
1112 size_t buf_len = KEY_READ_LEN;
1114 if ((location == NULL) || (key == NULL)) {
1118 stream = fopen(location,
"r");
1119 if (stream == NULL) {
1123 key->data = gnutls_malloc(buf_len);
1125 while (!feof(stream)) {
1126 int next = fgetc(stream);
1129 if (!feof(stream)) {
1130 crm_warn(
"Pacemaker Remote key read was partially successful " 1131 "(copy in memory may be corrupted)");
1135 if (key->size == buf_len) {
1136 buf_len = key->size + KEY_READ_LEN;
1137 key->data = gnutls_realloc(key->data, buf_len);
1140 key->data[key->size++] = (
unsigned char) next;
1144 if (key->size == 0) {
1145 clear_gnutls_datum(key);
1153 struct key_cache_s {
1155 const char *location;
1160 key_is_cached(
struct key_cache_s *key_cache)
1162 return key_cache->updated != 0;
1166 key_cache_expired(
struct key_cache_s *key_cache)
1168 return (time(NULL) - key_cache->updated) >= 60;
1172 clear_key_cache(
struct key_cache_s *key_cache)
1174 clear_gnutls_datum(&(key_cache->key));
1175 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1176 key_cache->updated = 0;
1177 key_cache->location = NULL;
1178 crm_debug(
"Cleared Pacemaker Remote key cache");
1183 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1185 copy_gnutls_datum(key, &(key_cache->key));
1186 crm_debug(
"Using cached Pacemaker Remote key from %s",
1187 pcmk__s(key_cache->location,
"unknown location"));
1191 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1192 const char *location)
1194 key_cache->updated = time(NULL);
1195 key_cache->location = location;
1196 copy_gnutls_datum(&(key_cache->key), key);
1197 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1198 pcmk__s(location,
"unknown location"));
1212 get_remote_key(
const char *location, gnutls_datum_t *key)
1214 static struct key_cache_s key_cache = { 0, };
1217 if ((location == NULL) || (key == NULL)) {
1221 if (key_is_cached(&key_cache)) {
1222 if (key_cache_expired(&key_cache)) {
1223 clear_key_cache(&key_cache);
1225 get_cached_key(&key_cache, key);
1230 rc = read_gnutls_key(location, key);
1234 cache_key(&key_cache, key, location);
1252 lrmd__init_remote_key(gnutls_datum_t *key)
1254 static const char *env_location = NULL;
1255 static bool need_env =
true;
1261 bool env_is_default =
false;
1262 bool env_is_fallback =
false;
1270 if (env_location != NULL) {
1271 env_rc = get_remote_key(env_location, key);
1288 if (env_is_default) {
1289 default_rc = env_rc;
1295 if (env_is_fallback) {
1306 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1308 env_is_default?
"" :
"or default location ",
1310 !env_is_default && !env_is_fallback?
" " :
"",
1311 env_is_fallback?
"" :
"or fallback location ",
1318 crm_warn(
"Could not read Pacemaker Remote key from %s " 1319 "(using %s location %s instead): %s",
1321 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1329 crm_warn(
"Could not read Pacemaker Remote key from default location %s" 1330 " (or fallback location %s): %s",
1340 lrmd_gnutls_global_init(
void)
1342 static int gnutls_init = 0;
1345 crm_gnutls_global_init();
1352 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1356 if (native->callback) {
1359 event.remote_nodename = native->remote_nodename;
1360 event.connection_rc = rc;
1361 native->callback(&event);
1365 #ifdef HAVE_GNUTLS_GNUTLS_H 1369 return pcmk__tls_client_handshake(remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT);
1382 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1388 native->server, native->port);
1392 .destroy = lrmd_tls_connection_destroy,
1396 lrmd_tls_dispatch, lrmd);
1407 rc = lrmd_handshake(lrmd,
name);
1415 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1419 gnutls_datum_t psk_key = { NULL, 0 };
1421 native->async_timer = 0;
1424 lrmd_tls_connection_destroy(lrmd);
1425 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1427 native->server, native->port,
pcmk_rc_str(rc), rc);
1436 native->sock = sock;
1438 rc = lrmd__init_remote_key(&psk_key);
1440 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1442 native->server, native->port,
pcmk_rc_str(rc), rc);
1443 lrmd_tls_connection_destroy(lrmd);
1448 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1450 gnutls_free(psk_key.data);
1452 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1454 native->psk_cred_c);
1455 if (native->remote->tls_session == NULL) {
1456 lrmd_tls_connection_destroy(lrmd);
1457 report_async_connection_result(lrmd, -EPROTO);
1461 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1462 crm_warn(
"Disconnecting after TLS handshake with Pacemaker Remote server %s:%d failed",
1463 native->server, native->port);
1464 gnutls_deinit(*native->remote->tls_session);
1465 gnutls_free(native->remote->tls_session);
1466 native->remote->tls_session = NULL;
1467 lrmd_tls_connection_destroy(lrmd);
1472 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1473 native->server, native->port);
1474 rc = add_tls_to_mainloop(lrmd,
true);
1485 lrmd_gnutls_global_init();
1488 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1490 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1492 native->server, native->port,
pcmk_rc_str(rc), rc);
1495 native->async_timer = timer_id;
1500 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1505 gnutls_datum_t psk_key = { NULL, 0 };
1507 lrmd_gnutls_global_init();
1511 &(native->sock), NULL, NULL);
1513 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1515 native->server, native->port,
pcmk_rc_str(rc), rc);
1516 lrmd_tls_connection_destroy(lrmd);
1520 rc = lrmd__init_remote_key(&psk_key);
1522 lrmd_tls_connection_destroy(lrmd);
1526 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1528 gnutls_free(psk_key.data);
1530 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1532 native->psk_cred_c);
1533 if (native->remote->tls_session == NULL) {
1534 lrmd_tls_connection_destroy(lrmd);
1538 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1539 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1540 gnutls_deinit(*native->remote->tls_session);
1541 gnutls_free(native->remote->tls_session);
1542 native->remote->tls_session = NULL;
1543 lrmd_tls_connection_destroy(lrmd);
1547 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1553 add_tls_to_mainloop(lrmd,
false);
1560 lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1565 switch (native->type) {
1567 rc = lrmd_ipc_connect(lrmd, fd);
1569 #ifdef HAVE_GNUTLS_GNUTLS_H 1570 case pcmk__client_tls:
1571 rc = lrmd_tls_connect(lrmd, fd);
1575 crm_err(
"Unsupported executor connection type (bug?): %d",
1577 rc = -EPROTONOSUPPORT;
1581 rc = lrmd_handshake(lrmd,
name);
1593 CRM_CHECK(native && native->callback,
return -EINVAL);
1595 switch (native->type) {
1599 rc = lrmd_api_connect(lrmd,
name, NULL);
1601 report_async_connection_result(lrmd, rc);
1604 #ifdef HAVE_GNUTLS_GNUTLS_H 1605 case pcmk__client_tls:
1606 rc = lrmd_tls_connect_async(lrmd,
timeout);
1609 report_async_connection_result(lrmd, rc);
1614 crm_err(
"Unsupported executor connection type (bug?): %d",
1616 rc = -EPROTONOSUPPORT;
1623 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1627 if (native->source != NULL) {
1630 native->source = NULL;
1633 }
else if (native->ipc) {
1643 #ifdef HAVE_GNUTLS_GNUTLS_H 1645 lrmd_tls_disconnect(
lrmd_t * lrmd)
1649 if (native->remote->tls_session) {
1650 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1651 gnutls_deinit(*native->remote->tls_session);
1652 gnutls_free(native->remote->tls_session);
1653 native->remote->tls_session = 0;
1656 if (native->async_timer) {
1657 g_source_remove(native->async_timer);
1658 native->async_timer = 0;
1661 if (native->source != NULL) {
1664 native->source = NULL;
1666 }
else if (native->sock) {
1667 close(native->sock);
1671 if (native->pending_notify) {
1672 g_list_free_full(native->pending_notify, lrmd_free_xml);
1673 native->pending_notify = NULL;
1679 lrmd_api_disconnect(
lrmd_t * lrmd)
1684 switch (native->type) {
1686 crm_debug(
"Disconnecting from local executor");
1687 lrmd_ipc_disconnect(lrmd);
1689 #ifdef HAVE_GNUTLS_GNUTLS_H 1690 case pcmk__client_tls:
1691 crm_debug(
"Disconnecting from remote executor on %s",
1692 native->remote_nodename);
1693 lrmd_tls_disconnect(lrmd);
1697 crm_err(
"Unsupported executor connection type (bug?): %d",
1699 rc = -EPROTONOSUPPORT;
1702 free(native->token);
1703 native->token = NULL;
1705 free(native->peer_version);
1706 native->peer_version = NULL;
1711 lrmd_api_register_rsc(
lrmd_t * lrmd,
1717 xmlNode *
data = NULL;
1719 if (!
class || !
type || !rsc_id) {
1723 && (provider == NULL)) {
1756 const char *provider,
const char *
type)
1782 free(rsc_info->
type);
1793 xmlNode *output = NULL;
1794 const char *
class = NULL;
1795 const char *provider = NULL;
1796 const char *
type = NULL;
1811 if (!
class || !
type) {
1838 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1841 xmlNode *
data = NULL;
1842 xmlNode *output_xml = NULL;
1845 if (output == NULL) {
1857 timeout_ms, options, TRUE);
1863 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1867 (rsc_xml != NULL) && (rc ==
pcmk_ok);
1871 if (rsc_id == NULL) {
1872 crm_err(
"Could not parse recurring operation information from executor");
1880 if (op_info == NULL) {
1884 op_info->
rsc_id = strdup(rsc_id);
1890 *output = g_list_prepend(*output, op_info);
1903 native->callback = callback;
1911 native->proxy_callback = callback;
1912 native->proxy_callback_userdata = userdata;
1916 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1920 if (native->proxy_callback) {
1922 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1935 return lrmd_send_xml_no_reply(lrmd, msg);
1939 stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
1944 if (stonith_api == NULL) {
1945 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
1950 provider, output, 0);
1951 if ((rc ==
pcmk_ok) && (*output == NULL)) {
1954 stonith_api->
cmds->
free(stonith_api);
1959 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
1960 const char *
type,
char **output,
1964 output, options, NULL);
1968 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
1969 const char *provider,
const char *
type,
1974 GHashTable *params_table = NULL;
1976 if (!standard || !
type) {
1983 return stonith_get_metadata(provider,
type, output);
1988 g_hash_table_insert(params_table, strdup(param->key), strdup(param->value));
2005 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
2006 standard, provider,
type);
2011 if (!
action->stdout_data) {
2012 crm_err(
"Failed to receive meta-data for %s:%s:%s",
2013 standard, provider,
type);
2018 *output = strdup(
action->stdout_data);
2025 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2026 const char *userdata, guint interval_ms,
2044 for (tmp = params; tmp; tmp = tmp->
next) {
2057 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2070 for (tmp = params; tmp; tmp = tmp->
next) {
2083 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2106 if (stonith_api == NULL) {
2107 crm_err(
"Could not list fence agents: API memory allocation failed");
2111 &stonith_resources, 0);
2112 stonith_api->
cmds->
free(stonith_api);
2114 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2117 *resources = lrmd_list_add(*resources, dIter->
value);
2126 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2127 const char *provider)
2130 int stonith_count = 0;
2136 GList *gIter = NULL;
2139 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2140 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2143 g_list_free_full(agents, free);
2150 if (stonith_count) {
2152 stonith_count = list_stonith_agents(resources);
2153 if (stonith_count > 0) {
2154 rc += stonith_count;
2158 crm_notice(
"No agents found for class %s",
class);
2159 rc = -EPROTONOSUPPORT;
2165 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2168 GList *agents = NULL;
2169 GList *gIter2 = NULL;
2172 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2177 g_list_free_full(agents, free);
2182 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2185 char *provider = NULL;
2186 GList *ocf_providers = NULL;
2187 GList *gIter = NULL;
2191 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2192 provider = gIter->data;
2193 if (!agent || does_provider_have_agent(agent, provider,
2195 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2200 g_list_free_full(ocf_providers, free);
2208 GList *standards = NULL;
2209 GList *gIter = NULL;
2213 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2214 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2218 if (list_stonith_agents(NULL) > 0) {
2223 g_list_free_full(standards, free);
2258 *api = calloc(1,
sizeof(
lrmd_t));
2276 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2284 (*api)->cmds->connect_async = lrmd_api_connect_async;
2285 (*api)->cmds->is_connected = lrmd_api_is_connected;
2286 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2287 (*api)->cmds->disconnect = lrmd_api_disconnect;
2288 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2289 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2290 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2291 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2292 (*api)->cmds->set_callback = lrmd_api_set_callback;
2293 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2294 (*api)->cmds->exec = lrmd_api_exec;
2295 (*api)->cmds->cancel = lrmd_api_cancel;
2296 (*api)->cmds->list_agents = lrmd_api_list_agents;
2297 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2298 (*api)->cmds->list_standards = lrmd_api_list_standards;
2299 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2300 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2302 if ((nodename == NULL) && (server == NULL)) {
2305 #ifdef HAVE_GNUTLS_GNUTLS_H 2306 if (nodename == NULL) {
2308 }
else if (server == NULL) {
2311 pvt->type = pcmk__client_tls;
2312 pvt->remote_nodename = strdup(nodename);
2313 pvt->server = strdup(server);
2314 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2320 if (pvt->port == 0) {
2324 crm_err(
"Cannot communicate with Pacemaker Remote " 2325 "because GnuTLS is not enabled for this build");
2358 if (lrmd->
cmds != NULL) {
2367 #ifdef HAVE_GNUTLS_GNUTLS_H 2368 free(native->server);
2370 free(native->remote_nodename);
2371 free(native->remote);
2372 free(native->token);
2373 free(native->peer_version);
2379 struct metadata_cb {
2394 struct metadata_cb *metadata_cb = (
struct metadata_cb *)
action->cb_data;
2401 metadata_cb->callback(0, &
result, metadata_cb->user_data);
2426 void (*callback)(
int pid,
2432 struct metadata_cb *metadata_cb = NULL;
2435 CRM_CHECK(callback != NULL,
return EINVAL);
2437 if ((rsc == NULL) || (rsc->
standard == NULL) || (rsc->
type == NULL)) {
2440 "Invalid resource specification");
2441 callback(0, &
result, user_data);
2449 callback, user_data);
2461 callback(0, &
result, user_data);
2468 callback(0, &
result, user_data);
2474 action->cb_data = calloc(1,
sizeof(
struct metadata_cb));
2475 if (
action->cb_data == NULL) {
2479 callback(0, &
result, user_data);
2484 metadata_cb = (
struct metadata_cb *)
action->cb_data;
2485 metadata_cb->callback = callback;
2486 metadata_cb->user_data = user_data;
2507 const char *exit_reason)
2509 if (event == NULL) {
2527 if (event == NULL) {
2532 event->exit_reason = NULL;
2534 free((
void *) event->
output);
2535 event->output = NULL;
2553 if (native->remote == NULL) {
2556 return native->remote->uptime;
2565 if (native->remote == NULL) {
2568 return native->remote->start_state;
#define CRM_CHECK(expr, failure_action)
#define LRMD_OP_ALERT_EXEC
ocf_exitcode
Exit status codes for resource agents.
#define crm_notice(fmt, args...)
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)
#define F_LRMD_IS_IPC_PROVIDER
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 F_LRMD_IPC_SESSION
#define F_LRMD_RSC_EXEC_TIME
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
#define F_LRMD_RSC_ACTION
#define LRMD_OP_RSC_CANCEL
#define PCMK_DEFAULT_METADATA_TIMEOUT_MS
#define F_LRMD_RSC_OUTPUT
xmlNode * first_named_child(const xmlNode *parent, const char *name)
void(* lrmd_event_callback)(lrmd_event_data_t *event)
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.
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 MAX_TLS_RECV_WAIT
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
#define PCMK_RESOURCE_CLASS_OCF
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
#define F_LRMD_ALERT_PATH
long crm_ipc_read(crm_ipc_t *client)
enum crm_ais_msg_types type
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
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)
Add hash table entry to XML as (possibly legacy) name/value.
const char * pcmk__env_option(const char *option)
Wrappers for and extensions to glib mainloop.
#define F_LRMD_PROTOCOL_VERSION
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)
xmlNode * string2xml(const char *input)
const char * crm_ipc_buffer(crm_ipc_t *client)
#define LRMD_OP_RSC_UNREG
#define DEFAULT_REMOTE_KEY_LOCATION
struct trigger_s crm_trigger_t
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.
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)
#define F_LRMD_RSC_EXIT_REASON
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)
#define LRMD_PROTOCOL_VERSION
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))
void pcmk__str_update(char **str, const char *value)
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
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define PCMK__XA_NODE_START_STATE
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)
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.
const char * lrmd__node_start_state(lrmd_t *lrmd)
struct lrmd_key_value_s * next
#define F_LRMD_RSC_USERDATA_STR
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void free_xml(xmlNode *child)
#define F_LRMD_RSC_INTERVAL
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
CRM_TRACE_INIT_DATA(lrmd)
#define F_LRMD_RSC_START_DELAY
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
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 F_LRMD_RSC_RCCHANGE_TIME
#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 F_LRMD_REMOTE_MSG_ID
#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...)
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
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace, char **output, int timeout_sec)
Retrieve a fence agent's metadata.
int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
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 F_LRMD_RSC_RUN_TIME
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 F_LRMD_CLIENTNAME
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)
#define F_LRMD_RSC_QUEUE_TIME
int pcmk__read_remote_message(pcmk__remote_t *remote, int timeout_ms)
#define F_LRMD_RSC_DELETED
#define F_LRMD_CALLBACK_TOKEN
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
void pcmk__reset_result(pcmk__action_result_t *result)
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.
#define F_LRMD_REMOTE_MSG_TYPE
void crm_ipc_close(crm_ipc_t *client)
Execution failed, may be retried.
#define crm_info(fmt, args...)
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)
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Get next instance of same XML tag.