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>
50#define MAX_TLS_RECV_WAIT 10000
54static int lrmd_api_disconnect(
lrmd_t * lrmd);
55static int lrmd_api_is_connected(
lrmd_t * lrmd);
59static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
62#ifdef HAVE_GNUTLS_GNUTLS_H
63# define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000
64gnutls_psk_client_credentials_t psk_cred_s;
65static void lrmd_tls_disconnect(
lrmd_t * lrmd);
66static int global_remote_msg_id = 0;
67static void lrmd_tls_connection_destroy(gpointer userdata);
70typedef 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;
109lrmd_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;
223 copy->
call_id =
event->call_id;
224 copy->
timeout =
event->timeout;
228 copy->
rc =
event->rc;
230 copy->
t_run =
event->t_run;
252 free((
void *) event->
rsc_id);
257 if (event->
params != NULL) {
258 g_hash_table_destroy(event->
params);
264lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
272 if (proxy_session != NULL) {
274 lrmd_internal_proxy_dispatch(lrmd, msg);
276 }
else if (!native->callback) {
278 crm_trace(
"notify event received but client has not set callback");
282 event.remote_nodename = native->remote_nodename;
312 event.t_run = (
unsigned int) epoch;
315 event.t_rcchange = (
unsigned int) epoch;
319 event.exec_time = QB_MAX(0, exec_time);
323 event.queue_time = QB_MAX(0, queue_time);
345 native->callback(&event);
348 g_hash_table_destroy(event.params);
355lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
360 if (native->callback != NULL) {
363 lrmd_dispatch_internal(lrmd, msg);
369#ifdef HAVE_GNUTLS_GNUTLS_H
371lrmd_free_xml(gpointer userdata)
377remote_executor_connected(
lrmd_t * lrmd)
381 return (native->remote->tls_session != NULL);
396lrmd_tls_dispatch(gpointer userdata)
403 if (!remote_executor_connected(lrmd)) {
404 crm_trace(
"TLS dispatch triggered after disconnect");
412 if (native->pending_notify) {
415 crm_trace(
"Processing pending notifies");
416 for (iter = native->pending_notify; iter; iter = iter->next) {
417 lrmd_dispatch_internal(lrmd, iter->data);
419 g_list_free_full(native->pending_notify, lrmd_free_xml);
420 native->pending_notify = NULL;
441 lrmd_dispatch_internal(lrmd, xml);
443 if (native->expected_late_replies > 0) {
444 native->expected_late_replies--;
449 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
456 if (rc == ENOTCONN) {
457 crm_info(
"Lost %s executor connection while reading data",
458 (native->remote_nodename? native->remote_nodename :
"local"));
459 lrmd_tls_disconnect(lrmd);
472 switch (native->type) {
476#ifdef HAVE_GNUTLS_GNUTLS_H
477 case pcmk__client_tls:
478 if (native->pending_notify) {
494 crm_err(
"Unsupported executor connection type (bug?): %d",
496 return -EPROTONOSUPPORT;
509 switch (private->type) {
515 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
519#ifdef HAVE_GNUTLS_GNUTLS_H
520 case pcmk__client_tls:
521 lrmd_tls_dispatch(lrmd);
525 crm_err(
"Unsupported executor connection type (bug?): %d",
529 if (lrmd_api_is_connected(lrmd) == FALSE) {
538lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
541 xmlNode *op_msg = NULL;
557 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
558 op, (
long)options, options);
563lrmd_ipc_connection_destroy(gpointer userdata)
568 switch (native->type) {
570 crm_info(
"Disconnected from local executor");
572#ifdef HAVE_GNUTLS_GNUTLS_H
573 case pcmk__client_tls:
574 crm_info(
"Disconnected from remote executor on %s",
575 native->remote_nodename);
579 crm_err(
"Unsupported executor connection type %d (bug?)",
585 native->source = NULL;
587 if (native->callback) {
590 event.remote_nodename = native->remote_nodename;
591 native->callback(&event);
595#ifdef HAVE_GNUTLS_GNUTLS_H
597lrmd_tls_connection_destroy(gpointer userdata)
602 crm_info(
"TLS connection destroyed");
604 if (native->remote->tls_session) {
605 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
606 gnutls_deinit(*native->remote->tls_session);
607 gnutls_free(native->remote->tls_session);
608 native->remote->tls_session = NULL;
610 if (native->psk_cred_c) {
611 gnutls_psk_free_client_credentials(native->psk_cred_c);
616 if (native->process_notify) {
618 native->process_notify = NULL;
620 if (native->pending_notify) {
621 g_list_free_full(native->pending_notify, lrmd_free_xml);
622 native->pending_notify = NULL;
625 free(native->remote->buffer);
626 free(native->remote->start_state);
627 native->remote->buffer = NULL;
628 native->remote->start_state = NULL;
631 native->psk_cred_c = NULL;
634 if (native->callback) {
638 native->callback(&event);
646 const char *msg_type)
655read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
659 time_t start = time(NULL);
660 const char *msg_type = NULL;
662 int remaining_timeout = 0;
671 for (*reply = NULL; *reply == NULL; ) {
674 if (*reply == NULL) {
676 if (remaining_timeout) {
677 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
679 remaining_timeout = total_timeout;
681 if (remaining_timeout <= 0) {
691 if (*reply == NULL) {
700 crm_err(
"Empty msg type received while waiting for reply");
706 native->pending_notify = g_list_append(native->pending_notify, *reply);
707 if (native->process_notify) {
714 crm_err(
"Expected a reply, got %s", msg_type);
717 }
else if (reply_id != expected_reply_id) {
718 if (native->expected_late_replies > 0) {
719 native->expected_late_replies--;
721 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
728 if (native->remote->buffer && native->process_notify) {
737send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
742 global_remote_msg_id++;
743 if (global_remote_msg_id <= 0) {
744 global_remote_msg_id = 1;
750 crm_err(
"Disconnecting because TLS message could not be sent to "
752 lrmd_tls_disconnect(lrmd);
758lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
763 if (!remote_executor_connected(lrmd)) {
767 rc = send_remote_message(lrmd, msg);
772 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
774 crm_err(
"Disconnecting remote after request %d reply not received: %s "
775 CRM_XS " rc=%d timeout=%dms",
777 lrmd_tls_disconnect(lrmd);
791lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
796 switch (native->type) {
800#ifdef HAVE_GNUTLS_GNUTLS_H
801 case pcmk__client_tls:
802 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
806 crm_err(
"Unsupported executor connection type (bug?): %d",
808 rc = -EPROTONOSUPPORT;
815lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
820 switch (native->type) {
824#ifdef HAVE_GNUTLS_GNUTLS_H
825 case pcmk__client_tls:
826 rc = send_remote_message(lrmd, msg);
831 native->expected_late_replies++;
837 crm_err(
"Unsupported executor connection type (bug?): %d",
839 rc = -EPROTONOSUPPORT;
846lrmd_api_is_connected(
lrmd_t * lrmd)
850 switch (native->type) {
853#ifdef HAVE_GNUTLS_GNUTLS_H
854 case pcmk__client_tls:
855 return remote_executor_connected(lrmd);
858 crm_err(
"Unsupported executor connection type (bug?): %d",
883lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
884 xmlNode **output_data,
int timeout,
889 xmlNode *op_msg = NULL;
890 xmlNode *op_reply = NULL;
892 if (!lrmd_api_is_connected(lrmd)) {
897 crm_err(
"No operation specified");
903 crm_trace(
"Sending %s op to executor", op);
905 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
907 if (op_msg == NULL) {
912 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
914 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
919 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op,
timeout, rc);
922 }
else if(op_reply == NULL) {
937 *output_data = op_reply;
942 if (lrmd_api_is_connected(lrmd) == FALSE) {
943 crm_err(
"Executor disconnected");
952lrmd_api_poke_connection(
lrmd_t * lrmd)
990lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
994 xmlNode *reply = NULL;
1003 if (native->proxy_callback) {
1007 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
1010 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
1012 }
else if (reply == NULL) {
1013 crm_err(
"Did not receive registration reply");
1022 long long uptime = -1;
1032 native->remote->uptime = uptime;
1035 native->remote->start_state = strdup(start_state);
1038 if (rc == -EPROTO) {
1039 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
1044 crm_err(
"Invalid registration message: %s", msg_type);
1047 }
else if (tmp_ticket == NULL) {
1048 crm_err(
"No registration token provided");
1052 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1053 native->token = strdup(tmp_ticket);
1063 lrmd_api_disconnect(lrmd);
1069lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1076 .destroy = lrmd_ipc_connection_destroy
1079 crm_info(
"Connecting to executor");
1084 if (native->ipc != NULL) {
1099 if (native->ipc == NULL) {
1100 crm_debug(
"Could not connect to the executor API");
1107#ifdef HAVE_GNUTLS_GNUTLS_H
1109copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1111 CRM_ASSERT((dest != NULL) && (source != NULL) && (source->data != NULL));
1113 dest->data = gnutls_malloc(source->size);
1116 memcpy(dest->data, source->data, source->size);
1117 dest->size = source->size;
1121clear_gnutls_datum(gnutls_datum_t *datum)
1123 gnutls_free(datum->data);
1128#define KEY_READ_LEN 256
1132read_gnutls_key(
const char *location, gnutls_datum_t *key)
1134 FILE *stream = NULL;
1135 size_t buf_len = KEY_READ_LEN;
1137 if ((location == NULL) || (key == NULL)) {
1141 stream = fopen(location,
"r");
1142 if (stream == NULL) {
1146 key->data = gnutls_malloc(buf_len);
1148 while (!feof(stream)) {
1149 int next = fgetc(stream);
1152 if (!feof(stream)) {
1153 crm_warn(
"Pacemaker Remote key read was partially successful "
1154 "(copy in memory may be corrupted)");
1158 if (key->size == buf_len) {
1159 buf_len = key->size + KEY_READ_LEN;
1160 key->data = gnutls_realloc(key->data, buf_len);
1163 key->data[key->size++] = (
unsigned char) next;
1167 if (key->size == 0) {
1168 clear_gnutls_datum(key);
1178 const char *location;
1183key_is_cached(
struct key_cache_s *key_cache)
1185 return key_cache->updated != 0;
1189key_cache_expired(
struct key_cache_s *key_cache)
1191 return (time(NULL) - key_cache->updated) >= 60;
1195clear_key_cache(
struct key_cache_s *key_cache)
1197 clear_gnutls_datum(&(key_cache->key));
1198 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1199 key_cache->updated = 0;
1200 key_cache->location = NULL;
1201 crm_debug(
"Cleared Pacemaker Remote key cache");
1206get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1208 copy_gnutls_datum(key, &(key_cache->key));
1209 crm_debug(
"Using cached Pacemaker Remote key from %s",
1210 pcmk__s(key_cache->location,
"unknown location"));
1214cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1215 const char *location)
1217 key_cache->updated = time(NULL);
1218 key_cache->location = location;
1219 copy_gnutls_datum(&(key_cache->key), key);
1220 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1221 pcmk__s(location,
"unknown location"));
1235get_remote_key(
const char *location, gnutls_datum_t *key)
1237 static struct key_cache_s key_cache = { 0, };
1240 if ((location == NULL) || (key == NULL)) {
1244 if (key_is_cached(&key_cache)) {
1245 if (key_cache_expired(&key_cache)) {
1246 clear_key_cache(&key_cache);
1248 get_cached_key(&key_cache, key);
1253 rc = read_gnutls_key(location, key);
1257 cache_key(&key_cache, key, location);
1275lrmd__init_remote_key(gnutls_datum_t *key)
1277 static const char *env_location = NULL;
1278 static bool need_env =
true;
1284 bool env_is_default =
false;
1285 bool env_is_fallback =
false;
1293 if (env_location != NULL) {
1294 env_rc = get_remote_key(env_location, key);
1313 if (env_is_default) {
1314 default_rc = env_rc;
1321 if (env_is_fallback) {
1332 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1334 env_is_default?
"" :
"or default location ",
1336 !env_is_default && !env_is_fallback?
" " :
"",
1337 env_is_fallback?
"" :
"or fallback location ",
1344 crm_warn(
"Could not read Pacemaker Remote key from %s "
1345 "(using %s location %s instead): %s",
1347 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1350 crm_warn(
"This undocumented behavior is deprecated and unsafe and will "
1351 "be removed in a future release");
1360 crm_warn(
"Read Pacemaker Remote key from alternate location %s",
1362 crm_warn(
"This undocumented behavior is deprecated and unsafe and will "
1363 "be removed in a future release");
1366 crm_warn(
"Could not read Pacemaker Remote key from default location %s"
1367 " (or fallback location %s): %s",
1378lrmd_gnutls_global_init(
void)
1380 static int gnutls_init = 0;
1383 crm_gnutls_global_init();
1390report_async_connection_result(
lrmd_t * lrmd,
int rc)
1394 if (native->callback) {
1397 event.remote_nodename = native->remote_nodename;
1398 event.connection_rc = rc;
1399 native->callback(&event);
1403#ifdef HAVE_GNUTLS_GNUTLS_H
1407 return pcmk__tls_client_handshake(remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT);
1420add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1426 native->server, native->port);
1430 .destroy = lrmd_tls_connection_destroy,
1434 lrmd_tls_dispatch, lrmd);
1445 rc = lrmd_handshake(lrmd,
name);
1453lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1457 gnutls_datum_t psk_key = { NULL, 0 };
1459 native->async_timer = 0;
1462 lrmd_tls_connection_destroy(lrmd);
1463 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s "
1465 native->server, native->port,
pcmk_rc_str(rc), rc);
1474 native->sock = sock;
1476 rc = lrmd__init_remote_key(&psk_key);
1478 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s "
1480 native->server, native->port,
pcmk_rc_str(rc), rc);
1481 lrmd_tls_connection_destroy(lrmd);
1486 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1488 gnutls_free(psk_key.data);
1490 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1492 native->psk_cred_c);
1493 if (native->remote->tls_session == NULL) {
1494 lrmd_tls_connection_destroy(lrmd);
1495 report_async_connection_result(lrmd, -EPROTO);
1499 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1500 crm_warn(
"Disconnecting after TLS handshake with Pacemaker Remote server %s:%d failed",
1501 native->server, native->port);
1502 gnutls_deinit(*native->remote->tls_session);
1503 gnutls_free(native->remote->tls_session);
1504 native->remote->tls_session = NULL;
1505 lrmd_tls_connection_destroy(lrmd);
1510 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1511 native->server, native->port);
1512 rc = add_tls_to_mainloop(lrmd,
true);
1523 lrmd_gnutls_global_init();
1526 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1528 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s "
1530 native->server, native->port,
pcmk_rc_str(rc), rc);
1533 native->async_timer = timer_id;
1538lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1543 gnutls_datum_t psk_key = { NULL, 0 };
1545 lrmd_gnutls_global_init();
1549 &(native->sock), NULL, NULL);
1551 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s "
1553 native->server, native->port,
pcmk_rc_str(rc), rc);
1554 lrmd_tls_connection_destroy(lrmd);
1558 rc = lrmd__init_remote_key(&psk_key);
1560 lrmd_tls_connection_destroy(lrmd);
1564 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1566 gnutls_free(psk_key.data);
1568 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1570 native->psk_cred_c);
1571 if (native->remote->tls_session == NULL) {
1572 lrmd_tls_connection_destroy(lrmd);
1576 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1577 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1578 gnutls_deinit(*native->remote->tls_session);
1579 gnutls_free(native->remote->tls_session);
1580 native->remote->tls_session = NULL;
1581 lrmd_tls_connection_destroy(lrmd);
1585 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1591 add_tls_to_mainloop(lrmd,
false);
1598lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1603 switch (native->type) {
1605 rc = lrmd_ipc_connect(lrmd, fd);
1607#ifdef HAVE_GNUTLS_GNUTLS_H
1608 case pcmk__client_tls:
1609 rc = lrmd_tls_connect(lrmd, fd);
1613 crm_err(
"Unsupported executor connection type (bug?): %d",
1615 rc = -EPROTONOSUPPORT;
1619 rc = lrmd_handshake(lrmd,
name);
1631 CRM_CHECK(native && native->callback,
return -EINVAL);
1633 switch (native->type) {
1637 rc = lrmd_api_connect(lrmd,
name, NULL);
1639 report_async_connection_result(lrmd, rc);
1642#ifdef HAVE_GNUTLS_GNUTLS_H
1643 case pcmk__client_tls:
1644 rc = lrmd_tls_connect_async(lrmd,
timeout);
1647 report_async_connection_result(lrmd, rc);
1652 crm_err(
"Unsupported executor connection type (bug?): %d",
1654 rc = -EPROTONOSUPPORT;
1661lrmd_ipc_disconnect(
lrmd_t * lrmd)
1665 if (native->source != NULL) {
1668 native->source = NULL;
1671 }
else if (native->ipc) {
1681#ifdef HAVE_GNUTLS_GNUTLS_H
1683lrmd_tls_disconnect(
lrmd_t * lrmd)
1687 if (native->remote->tls_session) {
1688 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1689 gnutls_deinit(*native->remote->tls_session);
1690 gnutls_free(native->remote->tls_session);
1691 native->remote->tls_session = NULL;
1694 if (native->async_timer) {
1695 g_source_remove(native->async_timer);
1696 native->async_timer = 0;
1699 if (native->source != NULL) {
1702 native->source = NULL;
1704 }
else if (native->sock) {
1705 close(native->sock);
1709 if (native->pending_notify) {
1710 g_list_free_full(native->pending_notify, lrmd_free_xml);
1711 native->pending_notify = NULL;
1717lrmd_api_disconnect(
lrmd_t * lrmd)
1722 switch (native->type) {
1724 crm_debug(
"Disconnecting from local executor");
1725 lrmd_ipc_disconnect(lrmd);
1727#ifdef HAVE_GNUTLS_GNUTLS_H
1728 case pcmk__client_tls:
1729 crm_debug(
"Disconnecting from remote executor on %s",
1730 native->remote_nodename);
1731 lrmd_tls_disconnect(lrmd);
1735 crm_err(
"Unsupported executor connection type (bug?): %d",
1737 rc = -EPROTONOSUPPORT;
1740 free(native->token);
1741 native->token = NULL;
1743 free(native->peer_version);
1744 native->peer_version = NULL;
1749lrmd_api_register_rsc(
lrmd_t * lrmd,
1755 xmlNode *
data = NULL;
1757 if (!
class || !
type || !rsc_id) {
1761 && (provider == NULL)) {
1794 const char *provider,
const char *
type)
1819 free(rsc_info->
type);
1830 xmlNode *output = NULL;
1831 const char *
class = NULL;
1832 const char *provider = NULL;
1833 const char *
type = NULL;
1848 if (!
class || !
type) {
1875lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1878 xmlNode *
data = NULL;
1879 xmlNode *output_xml = NULL;
1882 if (output == NULL) {
1894 timeout_ms, options, TRUE);
1900 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1906 (rsc_xml != NULL) && (rc ==
pcmk_ok);
1910 if (rsc_id == NULL) {
1911 crm_err(
"Could not parse recurring operation information from executor");
1921 if (op_info == NULL) {
1925 op_info->
rsc_id = strdup(rsc_id);
1932 *output = g_list_prepend(*output, op_info);
1945 native->callback = callback;
1953 native->proxy_callback = callback;
1954 native->proxy_callback_userdata = userdata;
1958lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1962 if (native->proxy_callback) {
1964 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1977 return lrmd_send_xml_no_reply(lrmd, msg);
1981stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
1986 if (stonith_api == NULL) {
1987 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
1992 provider, output, 0);
1993 if ((rc ==
pcmk_ok) && (*output == NULL)) {
1996 stonith_api->
cmds->
free(stonith_api);
2001lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
2002 const char *
type,
char **output,
2006 output, options, NULL);
2010lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
2011 const char *provider,
const char *
type,
2016 GHashTable *params_table = NULL;
2018 if (!standard || !
type) {
2025 return stonith_get_metadata(provider,
type, output);
2047 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
2048 standard, provider,
type);
2053 if (!
action->stdout_data) {
2054 crm_err(
"Failed to receive meta-data for %s:%s:%s",
2055 standard, provider,
type);
2060 *output = strdup(
action->stdout_data);
2067lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2068 const char *userdata, guint interval_ms,
2086 for (tmp = params; tmp; tmp = tmp->
next) {
2099lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2112 for (tmp = params; tmp; tmp = tmp->
next) {
2125lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2148 if (stonith_api == NULL) {
2149 crm_err(
"Could not list fence agents: API memory allocation failed");
2153 &stonith_resources, 0);
2154 stonith_api->
cmds->
free(stonith_api);
2156 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2159 *resources = lrmd_list_add(*resources, dIter->
value);
2169 const char *provider)
2172 int stonith_count = 0;
2178 GList *gIter = NULL;
2181 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2182 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2185 g_list_free_full(agents, free);
2192 if (stonith_count) {
2194 stonith_count = list_stonith_agents(resources);
2195 if (stonith_count > 0) {
2196 rc += stonith_count;
2200 crm_notice(
"No agents found for class %s",
class);
2201 rc = -EPROTONOSUPPORT;
2207does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2210 GList *agents = NULL;
2211 GList *gIter2 = NULL;
2214 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2219 g_list_free_full(agents, free);
2224lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2227 char *provider = NULL;
2228 GList *ocf_providers = NULL;
2229 GList *gIter = NULL;
2233 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2234 provider = gIter->data;
2235 if (!agent || does_provider_have_agent(agent, provider,
2237 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2242 g_list_free_full(ocf_providers, free);
2250 GList *standards = NULL;
2251 GList *gIter = NULL;
2255 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2256 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2260 if (list_stonith_agents(NULL) > 0) {
2265 g_list_free_full(standards, free);
2300 *api = calloc(1,
sizeof(
lrmd_t));
2318 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2326 (*api)->cmds->connect_async = lrmd_api_connect_async;
2327 (*api)->cmds->is_connected = lrmd_api_is_connected;
2328 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2329 (*api)->cmds->disconnect = lrmd_api_disconnect;
2330 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2331 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2332 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2333 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2334 (*api)->cmds->set_callback = lrmd_api_set_callback;
2335 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2336 (*api)->cmds->exec = lrmd_api_exec;
2337 (*api)->cmds->cancel = lrmd_api_cancel;
2338 (*api)->cmds->list_agents = lrmd_api_list_agents;
2339 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2340 (*api)->cmds->list_standards = lrmd_api_list_standards;
2341 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2342 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2344 if ((nodename == NULL) && (server == NULL)) {
2347#ifdef HAVE_GNUTLS_GNUTLS_H
2348 if (nodename == NULL) {
2350 }
else if (server == NULL) {
2353 pvt->type = pcmk__client_tls;
2354 pvt->remote_nodename = strdup(nodename);
2355 pvt->server = strdup(server);
2356 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2362 if (pvt->port == 0) {
2366 crm_err(
"Cannot communicate with Pacemaker Remote "
2367 "because GnuTLS is not enabled for this build");
2400 if (lrmd->
cmds != NULL) {
2409#ifdef HAVE_GNUTLS_GNUTLS_H
2410 free(native->server);
2412 free(native->remote_nodename);
2413 free(native->remote);
2414 free(native->token);
2415 free(native->peer_version);
2436 struct metadata_cb *metadata_cb = (
struct metadata_cb *)
action->cb_data;
2443 metadata_cb->callback(0, &
result, metadata_cb->user_data);
2468 void (*callback)(
int pid,
2474 struct metadata_cb *metadata_cb = NULL;
2477 CRM_CHECK(callback != NULL,
return EINVAL);
2479 if ((rsc == NULL) || (rsc->
standard == NULL) || (rsc->
type == NULL)) {
2482 "Invalid resource specification");
2483 callback(0, &
result, user_data);
2491 callback, user_data);
2503 callback(0, &
result, user_data);
2510 callback(0, &
result, user_data);
2516 action->cb_data = calloc(1,
sizeof(
struct metadata_cb));
2517 if (
action->cb_data == NULL) {
2521 callback(0, &
result, user_data);
2526 metadata_cb = (
struct metadata_cb *)
action->cb_data;
2527 metadata_cb->callback = callback;
2528 metadata_cb->user_data = user_data;
2549 const char *exit_reason)
2551 if (event == NULL) {
2571 if (event == NULL) {
2576 event->exit_reason = NULL;
2578 free((
void *) event->
output);
2579 event->output = NULL;
2597 if (native->remote == NULL) {
2600 return native->remote->uptime;
2609 if (native->remote == NULL) {
2612 return native->remote->start_state;
#define PCMK_ACTION_META_DATA
#define PCMK_DEFAULT_METADATA_TIMEOUT_MS
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define PCMK_RESOURCE_CLASS_STONITH
#define PCMK_RESOURCE_CLASS_OCF
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
#define pcmk__assert_alloc(nmemb, size)
int pcmk__remote_ready(const pcmk__remote_t *remote, int timeout_ms)
int pcmk__remote_send_xml(pcmk__remote_t *remote, const xmlNode *msg)
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))
xmlNode * pcmk__remote_message_xml(pcmk__remote_t *remote)
int pcmk__read_remote_message(pcmk__remote_t *remote, int timeout_ms)
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
enum crm_ais_msg_types type
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)
gboolean stonith__watchdog_fencing_enabled_for_node(const char *node)
void crm_ipc_destroy(crm_ipc_t *client)
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.
long crm_ipc_read(crm_ipc_t *client)
@ crm_ipc_client_response
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
bool crm_ipc_connected(crm_ipc_t *client)
void crm_ipc_close(crm_ipc_t *client)
const char * crm_ipc_buffer(crm_ipc_t *client)
struct crm_ipc_s crm_ipc_t
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
int pcmk__connect_generic_ipc(crm_ipc_t *ipc)
int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
@ pcmk__client_ipc
Client uses plain IPC.
#define CRM_TRACE_INIT_DATA(name)
#define crm_info(fmt, args...)
#define crm_warn(fmt, args...)
#define CRM_LOG_ASSERT(expr)
#define crm_log_xml_err(xml, text)
#define crm_notice(fmt, args...)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define CRM_CHECK(expr, failure_action)
#define crm_debug(fmt, args...)
#define crm_err(fmt, args...)
#define crm_log_xml_trace(xml, text)
#define crm_trace(fmt, args...)
#define LRMD_OP_NEW_CLIENT
#define DEFAULT_REMOTE_USERNAME
#define LRMD_OP_GET_RECURRING
#define DEFAULT_REMOTE_KEY_LOCATION
@ lrmd_opt_notify_orig_only
Notify only the client that made the request (rather than all clients)
#define ALT_REMOTE_KEY_LOCATION
#define LRMD_OP_RSC_UNREG
#define LRMD_PROTOCOL_VERSION
void(* lrmd_event_callback)(lrmd_event_data_t *event)
#define LRMD_OP_RSC_CANCEL
#define LRMD_OP_ALERT_EXEC
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)
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
struct lrmd_private_s lrmd_private_t
#define MAX_TLS_RECV_WAIT
void lrmd__reset_result(lrmd_event_data_t *event)
void lrmd_key_value_freeall(lrmd_key_value_t *head)
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
void lrmd_free_op_info(lrmd_op_info_t *op_info)
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
time_t lrmd__uptime(lrmd_t *lrmd)
void lrmd_list_freeall(lrmd_list_t *head)
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new TLS connection to a remote executor.
lrmd_rsc_info_t * lrmd_new_rsc_info(const char *rsc_id, const char *standard, const char *provider, const char *type)
const char * lrmd__node_start_state(lrmd_t *lrmd)
void lrmd_internal_set_proxy_callback(lrmd_t *lrmd, void *userdata, void(*callback)(lrmd_t *lrmd, void *userdata, xmlNode *msg))
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *head, const char *key, const char *value)
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.
int lrmd__validate_remote_settings(lrmd_t *lrmd, GHashTable *hash)
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
int lrmd_poll(lrmd_t *lrmd, int timeout)
Check whether a message is available on an executor connection.
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
@ lrmd_event_exec_complete
int lrmd__remote_send_xml(pcmk__remote_t *session, xmlNode *msg, uint32_t id, const char *msg_type)
Wrappers for and extensions to glib mainloop.
void mainloop_set_trigger(crm_trigger_t *source)
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
struct mainloop_io_s mainloop_io_t
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.
struct trigger_s crm_trigger_t
void mainloop_del_ipc_client(mainloop_io_t *client)
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the 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.
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
#define PCMK_OPT_STONITH_WATCHDOG_TIMEOUT
#define PCMK__ENV_AUTHKEY_LOCATION
const char * pcmk__env_option(const char *option)
pcmk__action_result_t result
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
ocf_exitcode
Exit status codes for resource agents.
@ PCMK_OCF_NOT_CONFIGURED
Parameter invalid (inherently)
@ PCMK_OCF_UNKNOWN_ERROR
Unspecified error.
@ PCMK_OCF_UNKNOWN
Action is pending.
int pcmk_rc2legacy(int rc)
@ PCMK_EXEC_ERROR_FATAL
Execution failed, do not retry anywhere.
@ PCMK_EXEC_ERROR
Execution failed, may be retried.
int pcmk_legacy2rc(int legacy_rc)
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define PCMK__UNKNOWN_RESULT
void void pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
#define pcmk__mem_assert(ptr)
void pcmk__reset_result(pcmk__action_result_t *result)
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
gboolean services_action_sync(svc_action_t *op)
GList * resources_list_standards(void)
void services_action_free(svc_action_t *op)
GList * resources_list_providers(const char *standard)
Get a list of providers.
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.
const char * services__exit_reason(const svc_action_t *action)
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
stonith_t * stonith_api_new(void)
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
void pcmk__str_update(char **str, const char *value)
#define pcmk__str_copy(str)
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
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.
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
const char * remote_nodename
enum lrmd_callback_event type
struct lrmd_key_value_s * next
struct lrmd_list_s * next
lrmd_api_operations_t * cmds
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
int(* free)(stonith_t *st)
Destroy a fencer connection.
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.
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.
struct stonith_key_value_s * next
stonith_api_operations_t * cmds
Object for executing external actions.
Wrappers for and extensions to libxml2.
void free_xml(xmlNode *child)
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
xmlNode * pcmk__xe_next_same(const xmlNode *node)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
xmlNode * pcmk__xml_parse(const char *input)
#define PCMK__XA_LRMD_RSC_USERDATA_STR
#define PCMK__XA_LRMD_RSC_START_DELAY
#define PCMK__XA_LRMD_RSC_DELETED
#define PCMK__XA_LRMD_RSC_INTERVAL
#define PCMK__XA_LRMD_TYPE
#define PCMK__XA_LRMD_RSC_ACTION
#define PCMK__XA_LRMD_EXEC_TIME
#define PCMK__XA_LRMD_PROTOCOL_VERSION
#define PCMK__XA_LRMD_REMOTE_MSG_ID
#define PCMK__XA_LRMD_CLIENTNAME
#define PCMK__XA_LRMD_IPC_SESSION
#define PCMK__XA_LRMD_EXEC_OP_STATUS
#define PCMK__XA_LRMD_CALLID
#define PCMK__XA_LRMD_REMOTE_MSG_TYPE
#define PCMK__XA_LRMD_WATCHDOG
#define PCMK__XA_LRMD_CLASS
#define PCMK__XE_LRMD_ALERT
#define PCMK__XA_LRMD_ALERT_PATH
#define PCMK__XE_LRMD_CALLDATA
#define PCMK__XA_LRMD_TIMEOUT
#define PCMK__XA_LRMD_RUN_TIME
#define PCMK__XA_NODE_START_STATE
#define PCMK__XA_LRMD_RSC_ID
#define PCMK__XA_LRMD_RCCHANGE_TIME
#define PCMK__XA_LRMD_QUEUE_TIME
#define PCMK__XA_LRMD_IS_IPC_PROVIDER
#define PCMK__XA_LRMD_RSC_EXIT_REASON
#define PCMK__XA_LRMD_CALLOPT
#define PCMK__XA_LRMD_RSC_OUTPUT
#define PCMK__XE_LRMD_COMMAND
#define PCMK__XA_LRMD_PROVIDER
#define PCMK__XA_LRMD_EXEC_RC
#define PCMK__XA_LRMD_ALERT_ID
#define PCMK__XA_LRMD_ORIGIN
#define PCMK__XE_ATTRIBUTES
#define PCMK__XE_LRMD_RSC_OP
#define PCMK__XA_LRMD_CLIENTID
#define PCMK__XE_LRMD_RSC