21 #include <sys/types.h>
38 #ifdef HAVE_GNUTLS_GNUTLS_H
40 # include <gnutls/gnutls.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <netinet/ip.h>
46 #include <arpa/inet.h>
49 #define MAX_TLS_RECV_WAIT 10000
53 static int lrmd_api_disconnect(
lrmd_t * lrmd);
54 static int lrmd_api_is_connected(
lrmd_t * lrmd);
58 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
61 #ifdef HAVE_GNUTLS_GNUTLS_H
62 # define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000
63 gnutls_psk_client_credentials_t psk_cred_s;
64 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
65 static int global_remote_msg_id = 0;
66 static void lrmd_tls_connection_destroy(gpointer userdata);
69 typedef struct lrmd_private_s {
80 char *remote_nodename;
81 #ifdef HAVE_GNUTLS_GNUTLS_H
84 gnutls_psk_client_credentials_t psk_cred_c;
94 int expected_late_replies;
95 GList *pending_notify;
102 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
103 void *proxy_callback_userdata;
108 lrmd_list_add(
lrmd_list_t * head,
const char *value)
113 p->
val = strdup(value);
116 while (end && end->
next) {
135 char *val = (
char *)head->
val;
150 p->
key = strdup(key);
151 p->
value = strdup(value);
154 while (end && end->
next) {
199 if (rsc_id != NULL) {
200 event->rsc_id = strdup(rsc_id);
204 event->op_type = strdup(task);
207 event->interval_ms = interval_ms;
223 copy->
rsc_id =
event->rsc_id ? strdup(event->
rsc_id) : NULL;
226 copy->
output =
event->output ? strdup(event->
output) : NULL;
246 free((
void *) event->
rsc_id);
249 free((
void *) event->
output);
252 if (event->
params != NULL) {
253 g_hash_table_destroy(event->
params);
259 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
266 if (proxy_session != NULL) {
268 lrmd_internal_proxy_dispatch(lrmd, msg);
270 }
else if (!native->callback) {
272 crm_trace(
"notify event received but client has not set callback");
276 event.remote_nodename = native->remote_nodename;
296 event.t_run = (
unsigned int) epoch;
299 event.t_rcchange = (
unsigned int) epoch;
319 crm_trace(
"op %s notify event received", type);
320 native->callback(&event);
323 g_hash_table_destroy(event.params);
329 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
334 if (native->callback != NULL) {
337 lrmd_dispatch_internal(lrmd, msg);
343 #ifdef HAVE_GNUTLS_GNUTLS_H
345 lrmd_free_xml(gpointer userdata)
351 remote_executor_connected(
lrmd_t * lrmd)
355 return (native->remote->tls_session != NULL);
370 lrmd_tls_dispatch(gpointer userdata)
377 if (!remote_executor_connected(lrmd)) {
378 crm_trace(
"TLS dispatch triggered after disconnect");
386 if (native->pending_notify) {
389 crm_trace(
"Processing pending notifies");
390 for (iter = native->pending_notify; iter; iter = iter->next) {
391 lrmd_dispatch_internal(lrmd, iter->data);
393 g_list_free_full(native->pending_notify, lrmd_free_xml);
394 native->pending_notify = NULL;
414 lrmd_dispatch_internal(lrmd, xml);
416 if (native->expected_late_replies > 0) {
417 native->expected_late_replies--;
422 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
429 if (rc == ENOTCONN) {
430 crm_info(
"Lost %s executor connection while reading data",
431 (native->remote_nodename? native->remote_nodename :
"local"));
432 lrmd_tls_disconnect(lrmd);
445 switch (native->type) {
449 #ifdef HAVE_GNUTLS_GNUTLS_H
450 case pcmk__client_tls:
451 if (native->pending_notify) {
467 crm_err(
"Unsupported executor connection type (bug?): %d",
469 return -EPROTONOSUPPORT;
482 switch (private->type) {
488 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
492 #ifdef HAVE_GNUTLS_GNUTLS_H
493 case pcmk__client_tls:
494 lrmd_tls_dispatch(lrmd);
498 crm_err(
"Unsupported executor connection type (bug?): %d",
502 if (lrmd_api_is_connected(lrmd) == FALSE) {
511 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
530 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
531 op, (
long)options, options);
536 lrmd_ipc_connection_destroy(gpointer userdata)
541 crm_info(
"IPC connection destroyed");
545 native->source = NULL;
547 if (native->callback) {
550 event.remote_nodename = native->remote_nodename;
551 native->callback(&event);
555 #ifdef HAVE_GNUTLS_GNUTLS_H
557 lrmd_tls_connection_destroy(gpointer userdata)
562 crm_info(
"TLS connection destroyed");
564 if (native->remote->tls_session) {
565 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
566 gnutls_deinit(*native->remote->tls_session);
567 gnutls_free(native->remote->tls_session);
569 if (native->psk_cred_c) {
570 gnutls_psk_free_client_credentials(native->psk_cred_c);
575 if (native->process_notify) {
577 native->process_notify = NULL;
579 if (native->pending_notify) {
580 g_list_free_full(native->pending_notify, lrmd_free_xml);
581 native->pending_notify = NULL;
584 free(native->remote->buffer);
585 native->remote->buffer = NULL;
588 native->psk_cred_c = NULL;
589 native->remote->tls_session = NULL;
592 if (native->callback) {
596 native->callback(&event);
604 const char *msg_type)
613 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
617 time_t start = time(NULL);
618 const char *msg_type = NULL;
620 int remaining_timeout = 0;
629 for (*reply = NULL; *reply == NULL; ) {
632 if (*reply == NULL) {
634 if (remaining_timeout) {
635 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
637 remaining_timeout = total_timeout;
639 if (remaining_timeout <= 0) {
649 if (*reply == NULL) {
658 crm_err(
"Empty msg type received while waiting for reply");
664 native->pending_notify = g_list_append(native->pending_notify, *reply);
665 if (native->process_notify) {
672 crm_err(
"Expected a reply, got %s", msg_type);
675 }
else if (reply_id != expected_reply_id) {
676 if (native->expected_late_replies > 0) {
677 native->expected_late_replies--;
679 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
686 if (native->remote->buffer && native->process_notify) {
695 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
700 global_remote_msg_id++;
701 if (global_remote_msg_id <= 0) {
702 global_remote_msg_id = 1;
708 crm_err(
"Disconnecting because TLS message could not be sent to "
710 lrmd_tls_disconnect(lrmd);
716 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
721 if (!remote_executor_connected(lrmd)) {
725 rc = send_remote_message(lrmd, msg);
730 rc = read_remote_reply(lrmd, timeout, global_remote_msg_id, &xml);
732 crm_err(
"Disconnecting remote after request %d reply not received: %s "
733 CRM_XS " rc=%d timeout=%dms",
734 global_remote_msg_id,
pcmk_rc_str(rc), rc, timeout);
735 lrmd_tls_disconnect(lrmd);
749 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
754 switch (native->type) {
758 #ifdef HAVE_GNUTLS_GNUTLS_H
759 case pcmk__client_tls:
760 rc = lrmd_tls_send_recv(lrmd, msg, timeout, reply);
764 crm_err(
"Unsupported executor connection type (bug?): %d",
766 rc = -EPROTONOSUPPORT;
773 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
778 switch (native->type) {
782 #ifdef HAVE_GNUTLS_GNUTLS_H
783 case pcmk__client_tls:
784 rc = send_remote_message(lrmd, msg);
789 native->expected_late_replies++;
795 crm_err(
"Unsupported executor connection type (bug?): %d",
797 rc = -EPROTONOSUPPORT;
804 lrmd_api_is_connected(
lrmd_t * lrmd)
808 switch (native->type) {
811 #ifdef HAVE_GNUTLS_GNUTLS_H
812 case pcmk__client_tls:
813 return remote_executor_connected(lrmd);
816 crm_err(
"Unsupported executor connection type (bug?): %d",
841 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *data,
842 xmlNode **output_data,
int timeout,
847 xmlNode *op_msg = NULL;
848 xmlNode *op_reply = NULL;
850 if (!lrmd_api_is_connected(lrmd)) {
855 crm_err(
"No operation specified");
861 crm_trace(
"Sending %s op to executor", op);
863 op_msg = lrmd_create_op(native->token, op, data, timeout, options);
865 if (op_msg == NULL) {
870 rc = lrmd_send_xml(lrmd, op_msg, timeout, &op_reply);
872 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
877 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op, timeout, rc);
881 }
else if(op_reply == NULL) {
896 *output_data = op_reply;
901 if (lrmd_api_is_connected(lrmd) == FALSE) {
902 crm_err(
"Executor disconnected");
911 lrmd_api_poke_connection(
lrmd_t * lrmd)
918 rc = lrmd_send_command(lrmd,
LRMD_OP_POKE, data, NULL, 0, 0,
936 value = g_hash_table_lookup(hash,
"stonith-watchdog-timeout");
939 rc = lrmd_send_command(lrmd,
LRMD_OP_CHECK, data, NULL, 0, 0,
946 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
950 xmlNode *reply = NULL;
959 if (native->proxy_callback) {
963 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
966 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
968 }
else if (reply == NULL) {
969 crm_err(
"Did not receive registration reply");
979 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
984 crm_err(
"Invalid registration message: %s", msg_type);
987 }
else if (tmp_ticket == NULL) {
988 crm_err(
"No registration token provided");
992 crm_trace(
"Obtained registration token: %s", tmp_ticket);
993 native->token = strdup(tmp_ticket);
994 native->peer_version = strdup(version?version:
"1.0");
1003 lrmd_api_disconnect(lrmd);
1009 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1016 .destroy = lrmd_ipc_connection_destroy
1019 crm_info(
"Connecting to executor");
1026 }
else if (native->ipc) {
1027 crm_perror(LOG_ERR,
"Connection to executor failed");
1035 if (native->ipc == NULL) {
1036 crm_debug(
"Could not connect to the executor API");
1043 #ifdef HAVE_GNUTLS_GNUTLS_H
1045 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1047 dest->data = gnutls_malloc(source->size);
1049 memcpy(dest->data, source->data, source->size);
1050 dest->size = source->size;
1054 clear_gnutls_datum(gnutls_datum_t *datum)
1056 gnutls_free(datum->data);
1061 #define KEY_READ_LEN 256 // Chunk size for reading key from file
1065 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1067 FILE *stream = NULL;
1068 size_t buf_len = KEY_READ_LEN;
1070 if ((location == NULL) || (key == NULL)) {
1074 stream = fopen(location,
"r");
1075 if (stream == NULL) {
1079 key->data = gnutls_malloc(buf_len);
1081 while (!feof(stream)) {
1082 int next = fgetc(stream);
1085 if (!feof(stream)) {
1086 crm_warn(
"Pacemaker Remote key read was partially successful "
1087 "(copy in memory may be corrupted)");
1091 if (key->size == buf_len) {
1092 buf_len = key->size + KEY_READ_LEN;
1093 key->data = gnutls_realloc(key->data, buf_len);
1096 key->data[key->size++] = (
unsigned char) next;
1100 if (key->size == 0) {
1101 clear_gnutls_datum(key);
1109 struct key_cache_s {
1111 const char *location;
1116 key_is_cached(
struct key_cache_s *key_cache)
1118 return key_cache->updated != 0;
1122 key_cache_expired(
struct key_cache_s *key_cache)
1124 return (time(NULL) - key_cache->updated) >= 60;
1128 clear_key_cache(
struct key_cache_s *key_cache)
1130 clear_gnutls_datum(&(key_cache->key));
1131 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1132 key_cache->updated = 0;
1133 key_cache->location = NULL;
1134 crm_debug(
"Cleared Pacemaker Remote key cache");
1139 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1141 copy_gnutls_datum(key, &(key_cache->key));
1142 crm_debug(
"Using cached Pacemaker Remote key from %s",
1143 crm_str(key_cache->location));
1147 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1148 const char *location)
1150 key_cache->updated = time(NULL);
1151 key_cache->location = location;
1152 copy_gnutls_datum(&(key_cache->key), key);
1153 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1168 get_remote_key(
const char *location, gnutls_datum_t *key)
1170 static struct key_cache_s key_cache = { 0, };
1173 if ((location == NULL) || (key == NULL)) {
1177 if (key_is_cached(&key_cache)) {
1178 if (key_cache_expired(&key_cache)) {
1179 clear_key_cache(&key_cache);
1181 get_cached_key(&key_cache, key);
1186 rc = read_gnutls_key(location, key);
1190 cache_key(&key_cache, key, location);
1208 lrmd__init_remote_key(gnutls_datum_t *key)
1210 static const char *env_location = NULL;
1211 static bool need_env =
true;
1217 bool env_is_default =
false;
1218 bool env_is_fallback =
false;
1221 env_location = getenv(
"PCMK_authkey_location");
1226 if (env_location != NULL) {
1227 env_rc = get_remote_key(env_location, key);
1244 if (env_is_default) {
1245 default_rc = env_rc;
1251 if (env_is_fallback) {
1262 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1264 env_is_default?
"" :
"or default location ",
1266 !env_is_default && !env_is_fallback?
" " :
"",
1267 env_is_fallback?
"" :
"or fallback location ",
1274 crm_warn(
"Could not read Pacemaker Remote key from %s "
1275 "(using %s location %s instead): %s",
1277 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1285 crm_warn(
"Could not read Pacemaker Remote key from default location %s"
1286 " (or fallback location %s): %s",
1296 lrmd_gnutls_global_init(
void)
1298 static int gnutls_init = 0;
1301 crm_gnutls_global_init();
1308 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1312 if (native->callback) {
1315 event.remote_nodename = native->remote_nodename;
1316 event.connection_rc =
rc;
1317 native->callback(&event);
1321 #ifdef HAVE_GNUTLS_GNUTLS_H
1325 return pcmk__tls_client_handshake(remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT);
1338 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1344 native->server, native->port);
1348 .destroy = lrmd_tls_connection_destroy,
1352 lrmd_tls_dispatch, lrmd);
1353 native->source =
mainloop_add_fd(name, G_PRIORITY_HIGH, native->sock, lrmd,
1363 rc = lrmd_handshake(lrmd, name);
1371 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1375 gnutls_datum_t psk_key = { NULL, 0 };
1377 native->async_timer = 0;
1380 lrmd_tls_connection_destroy(lrmd);
1381 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s "
1383 native->server, native->port,
pcmk_rc_str(rc), rc);
1392 native->sock = sock;
1394 rc = lrmd__init_remote_key(&psk_key);
1396 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s "
1398 native->server, native->port,
pcmk_rc_str(rc), rc);
1399 lrmd_tls_connection_destroy(lrmd);
1404 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1406 gnutls_free(psk_key.data);
1408 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1410 native->psk_cred_c);
1411 if (native->remote->tls_session == NULL) {
1412 lrmd_tls_connection_destroy(lrmd);
1413 report_async_connection_result(lrmd, -EPROTO);
1417 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1418 crm_warn(
"Disconnecting after TLS handshake with Pacemaker Remote server %s:%d failed",
1419 native->server, native->port);
1420 gnutls_deinit(*native->remote->tls_session);
1421 gnutls_free(native->remote->tls_session);
1422 native->remote->tls_session = NULL;
1423 lrmd_tls_connection_destroy(lrmd);
1428 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1429 native->server, native->port);
1430 rc = add_tls_to_mainloop(lrmd,
true);
1435 lrmd_tls_connect_async(
lrmd_t * lrmd,
int timeout )
1441 lrmd_gnutls_global_init();
1444 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1446 crm_warn(
"Pacemaker Remote connection to %s:%s failed: %s "
1448 native->server, native->port,
pcmk_rc_str(rc), rc);
1451 native->async_timer = timer_id;
1456 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1461 gnutls_datum_t psk_key = { NULL, 0 };
1463 lrmd_gnutls_global_init();
1467 &(native->sock), NULL, NULL);
1469 crm_warn(
"Pacemaker Remote connection to %s:%s failed: %s "
1471 native->server, native->port,
pcmk_rc_str(rc), rc);
1472 lrmd_tls_connection_destroy(lrmd);
1476 rc = lrmd__init_remote_key(&psk_key);
1478 lrmd_tls_connection_destroy(lrmd);
1482 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1484 gnutls_free(psk_key.data);
1486 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1488 native->psk_cred_c);
1489 if (native->remote->tls_session == NULL) {
1490 lrmd_tls_connection_destroy(lrmd);
1494 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1495 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1496 gnutls_deinit(*native->remote->tls_session);
1497 gnutls_free(native->remote->tls_session);
1498 native->remote->tls_session = NULL;
1499 lrmd_tls_connection_destroy(lrmd);
1503 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1509 add_tls_to_mainloop(lrmd,
false);
1516 lrmd_api_connect(
lrmd_t * lrmd,
const char *name,
int *fd)
1521 switch (native->type) {
1523 rc = lrmd_ipc_connect(lrmd, fd);
1525 #ifdef HAVE_GNUTLS_GNUTLS_H
1526 case pcmk__client_tls:
1527 rc = lrmd_tls_connect(lrmd, fd);
1531 crm_err(
"Unsupported executor connection type (bug?): %d",
1533 rc = -EPROTONOSUPPORT;
1537 rc = lrmd_handshake(lrmd, name);
1544 lrmd_api_connect_async(
lrmd_t * lrmd,
const char *name,
int timeout)
1549 CRM_CHECK(native && native->callback,
return -EINVAL);
1551 switch (native->type) {
1555 rc = lrmd_api_connect(lrmd, name, NULL);
1557 report_async_connection_result(lrmd, rc);
1560 #ifdef HAVE_GNUTLS_GNUTLS_H
1561 case pcmk__client_tls:
1562 rc = lrmd_tls_connect_async(lrmd, timeout);
1565 report_async_connection_result(lrmd, rc);
1570 crm_err(
"Unsupported executor connection type (bug?): %d",
1572 rc = -EPROTONOSUPPORT;
1579 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1583 if (native->source != NULL) {
1586 native->source = NULL;
1589 }
else if (native->ipc) {
1599 #ifdef HAVE_GNUTLS_GNUTLS_H
1601 lrmd_tls_disconnect(
lrmd_t * lrmd)
1605 if (native->remote->tls_session) {
1606 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1607 gnutls_deinit(*native->remote->tls_session);
1608 gnutls_free(native->remote->tls_session);
1609 native->remote->tls_session = 0;
1612 if (native->async_timer) {
1613 g_source_remove(native->async_timer);
1614 native->async_timer = 0;
1617 if (native->source != NULL) {
1620 native->source = NULL;
1622 }
else if (native->sock) {
1623 close(native->sock);
1627 if (native->pending_notify) {
1628 g_list_free_full(native->pending_notify, lrmd_free_xml);
1629 native->pending_notify = NULL;
1635 lrmd_api_disconnect(
lrmd_t * lrmd)
1640 crm_info(
"Disconnecting %s %s executor connection",
1642 (native->remote_nodename? native->remote_nodename :
"local"));
1643 switch (native->type) {
1645 lrmd_ipc_disconnect(lrmd);
1647 #ifdef HAVE_GNUTLS_GNUTLS_H
1648 case pcmk__client_tls:
1649 lrmd_tls_disconnect(lrmd);
1653 crm_err(
"Unsupported executor connection type (bug?): %d",
1655 rc = -EPROTONOSUPPORT;
1658 free(native->token);
1659 native->token = NULL;
1661 free(native->peer_version);
1662 native->peer_version = NULL;
1667 lrmd_api_register_rsc(
lrmd_t * lrmd,
1673 xmlNode *data = NULL;
1675 if (!
class || !type || !rsc_id) {
1679 && (provider == NULL)) {
1690 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_REG, data, NULL, 0, options, TRUE);
1712 const char *provider,
const char *type)
1718 rsc_info->
id = strdup(rsc_id);
1722 rsc_info->
standard = strdup(standard);
1726 rsc_info->
provider = strdup(provider);
1730 rsc_info->
type = strdup(type);
1750 free(rsc_info->
type);
1761 xmlNode *output = NULL;
1762 const char *
class = NULL;
1763 const char *provider = NULL;
1764 const char *type = NULL;
1768 lrmd_send_command(lrmd,
LRMD_OP_RSC_INFO, data, &output, 0, options, TRUE);
1779 if (!
class || !type) {
1806 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1809 xmlNode *data = NULL;
1810 xmlNode *output_xml = NULL;
1813 if (output == NULL) {
1825 timeout_ms, options, TRUE);
1831 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1835 (rsc_xml != NULL) && (rc ==
pcmk_ok);
1839 if (rsc_id == NULL) {
1840 crm_err(
"Could not parse recurring operation information from executor");
1848 if (op_info == NULL) {
1852 op_info->
rsc_id = strdup(rsc_id);
1858 *output = g_list_prepend(*output, op_info);
1871 native->callback = callback;
1879 native->proxy_callback = callback;
1880 native->proxy_callback_userdata = userdata;
1884 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1888 if (native->proxy_callback) {
1890 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1903 return lrmd_send_xml_no_reply(lrmd, msg);
1907 stonith_get_metadata(
const char *provider,
const char *type,
char **output)
1912 if (stonith_api == NULL) {
1913 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
1918 provider, output, 0);
1919 if ((rc ==
pcmk_ok) && (*output == NULL)) {
1922 stonith_api->
cmds->
free(stonith_api);
1927 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
1928 const char *type,
char **output,
1932 output, options, NULL);
1936 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
1937 const char *provider,
const char *type,
1942 GHashTable *params_table = NULL;
1944 if (!standard || !type) {
1951 return stonith_get_metadata(provider, type, output);
1956 g_hash_table_insert(params_table, strdup(param->key), strdup(param->value));
1964 if (action == NULL) {
1965 crm_err(
"Unable to retrieve meta-data for %s:%s:%s",
1966 standard, provider, type);
1971 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
1972 standard, provider, type);
1978 crm_err(
"Failed to receive meta-data for %s:%s:%s",
1979 standard, provider, type);
1991 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *action,
1992 const char *userdata, guint interval_ms,
2010 for (tmp = params; tmp; tmp = tmp->
next) {
2014 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_EXEC, data, NULL, timeout, options, TRUE);
2023 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2036 for (tmp = params; tmp; tmp = tmp->
next) {
2049 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *action,
2072 if (stonith_api == NULL) {
2073 crm_err(
"Could not list fence agents: API memory allocation failed");
2077 &stonith_resources, 0);
2078 stonith_api->
cmds->
free(stonith_api);
2080 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2083 *resources = lrmd_list_add(*resources, dIter->
value);
2092 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2093 const char *provider)
2096 int stonith_count = 0;
2102 GList *gIter = NULL;
2105 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2106 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2109 g_list_free_full(agents, free);
2116 if (stonith_count) {
2118 stonith_count = list_stonith_agents(resources);
2119 if (stonith_count > 0) {
2120 rc += stonith_count;
2124 crm_notice(
"No agents found for class %s",
class);
2125 rc = -EPROTONOSUPPORT;
2131 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2134 GList *agents = NULL;
2135 GList *gIter2 = NULL;
2138 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2143 g_list_free_full(agents, free);
2148 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2151 char *provider = NULL;
2152 GList *ocf_providers = NULL;
2153 GList *gIter = NULL;
2157 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2158 provider = gIter->data;
2159 if (!agent || does_provider_have_agent(agent, provider,
2161 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2166 g_list_free_full(ocf_providers, free);
2174 GList *standards = NULL;
2175 GList *gIter = NULL;
2179 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2180 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2184 if (list_stonith_agents(NULL) > 0) {
2189 g_list_free_full(standards, free);
2199 new_lrmd = calloc(1,
sizeof(
lrmd_t));
2218 new_lrmd->
cmds->
exec = lrmd_api_exec;
2232 #ifdef HAVE_GNUTLS_GNUTLS_H
2236 if (!nodename && !server) {
2241 native->type = pcmk__client_tls;
2242 native->remote_nodename = nodename ? strdup(nodename) : strdup(server);
2243 native->server = server ? strdup(server) : strdup(nodename);
2244 native->port = port;
2245 if (native->port == 0) {
2251 crm_err(
"Cannot communicate with Pacemaker Remote because GnuTLS is not enabled for this build");
2267 #ifdef HAVE_GNUTLS_GNUTLS_H
2268 free(native->server);
2270 free(native->remote_nodename);
2271 free(native->remote);
2272 free(native->token);
2273 free(native->peer_version);
#define CRM_CHECK(expr, failure_action)
#define LRMD_OP_ALERT_EXEC
int pcmk__remote_send_xml(pcmk__remote_t *remote, xmlNode *msg)
#define CRMD_METADATA_CALL_TIMEOUT
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
#define crm_notice(fmt, args...)
int(* get_recurring_ops)(lrmd_t *lrmd, const char *rsc_id, int timeout_ms, enum lrmd_call_options options, GList **output)
Retrieve registered recurring operations.
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(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, guint interval_ms)
Cancel a recurring command.
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
#define F_LRMD_RSC_ACTION
#define LRMD_OP_RSC_CANCEL
int crm_ipc_get_fd(crm_ipc_t *client)
int lrmd__validate_remote_settings(lrmd_t *lrmd, GHashTable *hash)
#define F_LRMD_RSC_OUTPUT
int(* poke_connection)(lrmd_t *lrmd)
Poke executor connection to verify it is still capable of serving requests.
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)
Get resource metadata for a resource agent, passing parameters.
xmlNode * first_named_child(const xmlNode *parent, const char *name)
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Set a callback for executor events.
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
struct stonith_key_value_s * next
void lrmd_free_op_info(lrmd_op_info_t *op_info)
void lrmd_list_freeall(lrmd_list_t *head)
struct mainloop_io_s mainloop_io_t
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int pcmk__remote_ready(pcmk__remote_t *remote, int timeout_ms)
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
void mainloop_set_trigger(crm_trigger_t *source)
#define DEFAULT_REMOTE_USERNAME
svc_action_t * resources_action_create(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.
#define LRMD_OP_GET_RECURRING
#define MAX_TLS_RECV_WAIT
int(* free)(stonith_t *st)
Destroy the stonith api structure.
void(* lrmd_event_callback)(lrmd_event_data_t *event)
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
#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.
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new TLS connection to a remote executor.
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.
Wrappers for and extensions to glib mainloop.
#define F_LRMD_PROTOCOL_VERSION
stonith_t * stonith_api_new(void)
xmlNode * string2xml(const char *input)
int(* exec_alert)(lrmd_t *lrmd, const char *alert_id, const char *alert_path, int timeout, lrmd_key_value_t *params)
Execute an alert agent.
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
const char * crm_ipc_buffer(crm_ipc_t *client)
#define LRMD_OP_RSC_UNREG
#define CRM_TRACE_INIT_DATA(name)
#define DEFAULT_REMOTE_KEY_LOCATION
struct trigger_s crm_trigger_t
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
struct lrmd_private_s lrmd_private_t
lrmd_rsc_info_t * lrmd_new_rsc_info(const char *rsc_id, const char *standard, const char *provider, const char *type)
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
#define crm_warn(fmt, args...)
#define PCMK_RESOURCE_CLASS_OCF
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
#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
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
struct lrmd_list_s * next
gboolean services_action_sync(svc_action_t *op)
#define LRMD_PROTOCOL_VERSION
#define crm_trace(fmt, args...)
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.
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))
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
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.
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
#define LRMD_OP_NEW_CLIENT
xmlNode * create_xml_node(xmlNode *parent, const char *name)
int(* list_agents)(stonith_t *stonith, int call_options, const char *provider, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
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)
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *kvp, const char *key, const char *value)
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.
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
int(* get_metadata)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Get resource metadata for a specified resource agent.
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Initiate an executor connection without blocking.
#define F_LRMD_RSC_START_DELAY
bool crm_ipc_connected(crm_ipc_t *client)
void lrmd_key_value_freeall(lrmd_key_value_t *head)
#define PCMK_RESOURCE_CLASS_STONITH
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
#define F_LRMD_RSC_RCCHANGE_TIME
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
#define crm_log_xml_err(xml, text)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
#define F_LRMD_REMOTE_MSG_ID
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
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)
int(* register_rsc)(lrmd_t *lrmd, const char *rsc_id, const char *standard, const char *provider, const char *agent, enum lrmd_call_options options)
Register a resource with the executor.
#define crm_err(fmt, args...)
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
enum lrmd_callback_event type
stonith_api_operations_t * cmds
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Send an IPC XML message.
#define CRMD_ACTION_METADATA
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
int(* unregister_rsc)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Unregister a resource from the executor.
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
GHashTable * xml2list(xmlNode *parent)
Retrieve XML attributes as a hash table.
int lrmd__remote_send_xml(pcmk__remote_t *session, xmlNode *msg, uint32_t id, const char *msg_type)
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
#define F_LRMD_RSC_RUN_TIME
int(* exec)(lrmd_t *lrmd, const char *rsc_id, const char *action, const char *userdata, guint interval_ms, int timeout, int start_delay, enum lrmd_call_options options, lrmd_key_value_t *params)
Issue a command on a resource.
int lrmd_poll(lrmd_t *lrmd, int timeout)
Poll for a specified timeout period to determine if a message is ready for dispatch.
const char * pcmk__client_type_str(uint64_t client_type)
void lrmd_internal_set_proxy_callback(lrmd_t *lrmd, void *userdata, void(*callback)(lrmd_t *lrmd, void *userdata, xmlNode *msg))
#define crm_log_xml_trace(xml, text)
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define F_LRMD_CLIENTNAME
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
lrmd_rsc_info_t *(* get_rsc_info)(lrmd_t *lrmd, const char *rsc_id, enum lrmd_call_options options)
Retrieve registration info for a rsc.
#define F_LRMD_CALLBACK_TOKEN
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
#define F_LRMD_REMOTE_MSG_TYPE
void crm_ipc_close(crm_ipc_t *client)
int(* list_agents)(lrmd_t *lrmd, lrmd_list_t **agents, const char *standard, const char *provider)
Retrieve a list of installed resource agents.
#define crm_info(fmt, args...)
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of standards supported by this machine/installation.
xmlNode * pcmk__remote_message_xml(pcmk__remote_t *remote)
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Get next instance of same XML tag.