21 #include <sys/types.h> 40 #ifdef HAVE_GNUTLS_GNUTLS_H 42 # include <gnutls/gnutls.h> 45 #include <sys/socket.h> 46 #include <netinet/in.h> 47 #include <netinet/ip.h> 48 #include <arpa/inet.h> 51 #define MAX_TLS_RECV_WAIT 10000 55 static int lrmd_api_disconnect(
lrmd_t * lrmd);
56 static int lrmd_api_is_connected(
lrmd_t * lrmd);
60 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
63 #ifdef HAVE_GNUTLS_GNUTLS_H 64 # define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000 65 gnutls_psk_client_credentials_t psk_cred_s;
66 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
67 static int global_remote_msg_id = 0;
68 static void lrmd_tls_connection_destroy(gpointer userdata);
71 typedef struct lrmd_private_s {
82 char *remote_nodename;
83 #ifdef HAVE_GNUTLS_GNUTLS_H 86 gnutls_psk_client_credentials_t psk_cred_c;
96 int expected_late_replies;
97 GList *pending_notify;
104 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
105 void *proxy_callback_userdata;
110 lrmd_list_add(
lrmd_list_t * head,
const char *value)
115 p->
val = strdup(value);
118 while (end && end->
next) {
137 char *val = (
char *)head->
val;
152 p->
key = strdup(key);
153 p->
value = strdup(value);
156 while (end && end->
next) {
201 if (rsc_id != NULL) {
202 event->rsc_id = strdup(rsc_id);
206 event->op_type = strdup(task);
209 event->interval_ms = interval_ms;
225 copy->
rsc_id =
event->rsc_id ? strdup(event->
rsc_id) : NULL;
228 copy->
output =
event->output ? strdup(event->
output) : NULL;
248 free((
void *) event->
rsc_id);
253 if (event->
params != NULL) {
254 g_hash_table_destroy(event->
params);
260 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
267 if (proxy_session != NULL) {
269 lrmd_internal_proxy_dispatch(lrmd, msg);
271 }
else if (!native->callback) {
273 crm_trace(
"notify event received but client has not set callback");
277 event.remote_nodename = native->remote_nodename;
297 event.t_run = (
unsigned int) epoch;
300 event.t_rcchange = (
unsigned int) epoch;
323 native->callback(&event);
326 g_hash_table_destroy(event.params);
332 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
337 if (native->callback != NULL) {
340 lrmd_dispatch_internal(lrmd, msg);
346 #ifdef HAVE_GNUTLS_GNUTLS_H 348 lrmd_free_xml(gpointer userdata)
354 remote_executor_connected(
lrmd_t * lrmd)
358 return (native->remote->tls_session != NULL);
373 lrmd_tls_dispatch(gpointer userdata)
380 if (!remote_executor_connected(lrmd)) {
381 crm_trace(
"TLS dispatch triggered after disconnect");
389 if (native->pending_notify) {
392 crm_trace(
"Processing pending notifies");
393 for (iter = native->pending_notify; iter; iter = iter->next) {
394 lrmd_dispatch_internal(lrmd, iter->data);
396 g_list_free_full(native->pending_notify, lrmd_free_xml);
397 native->pending_notify = NULL;
417 lrmd_dispatch_internal(lrmd, xml);
419 if (native->expected_late_replies > 0) {
420 native->expected_late_replies--;
425 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
432 if (
rc == ENOTCONN) {
433 crm_info(
"Lost %s executor connection while reading data",
434 (native->remote_nodename? native->remote_nodename :
"local"));
435 lrmd_tls_disconnect(lrmd);
448 switch (native->type) {
452 #ifdef HAVE_GNUTLS_GNUTLS_H 453 case pcmk__client_tls:
454 if (native->pending_notify) {
470 crm_err(
"Unsupported executor connection type (bug?): %d",
472 return -EPROTONOSUPPORT;
485 switch (private->type) {
491 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
495 #ifdef HAVE_GNUTLS_GNUTLS_H 496 case pcmk__client_tls:
497 lrmd_tls_dispatch(lrmd);
501 crm_err(
"Unsupported executor connection type (bug?): %d",
505 if (lrmd_api_is_connected(lrmd) == FALSE) {
514 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
533 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
534 op, (
long)options, options);
539 lrmd_ipc_connection_destroy(gpointer userdata)
544 crm_info(
"IPC connection destroyed");
548 native->source = NULL;
550 if (native->callback) {
553 event.remote_nodename = native->remote_nodename;
554 native->callback(&event);
558 #ifdef HAVE_GNUTLS_GNUTLS_H 560 lrmd_tls_connection_destroy(gpointer userdata)
565 crm_info(
"TLS connection destroyed");
567 if (native->remote->tls_session) {
568 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
569 gnutls_deinit(*native->remote->tls_session);
570 gnutls_free(native->remote->tls_session);
572 if (native->psk_cred_c) {
573 gnutls_psk_free_client_credentials(native->psk_cred_c);
578 if (native->process_notify) {
580 native->process_notify = NULL;
582 if (native->pending_notify) {
583 g_list_free_full(native->pending_notify, lrmd_free_xml);
584 native->pending_notify = NULL;
587 free(native->remote->buffer);
588 native->remote->buffer = NULL;
591 native->psk_cred_c = NULL;
592 native->remote->tls_session = NULL;
595 if (native->callback) {
599 native->callback(&event);
607 const char *msg_type)
616 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
620 time_t start = time(NULL);
621 const char *msg_type = NULL;
623 int remaining_timeout = 0;
632 for (*reply = NULL; *reply == NULL; ) {
635 if (*reply == NULL) {
637 if (remaining_timeout) {
638 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
640 remaining_timeout = total_timeout;
642 if (remaining_timeout <= 0) {
652 if (*reply == NULL) {
661 crm_err(
"Empty msg type received while waiting for reply");
667 native->pending_notify = g_list_append(native->pending_notify, *reply);
668 if (native->process_notify) {
675 crm_err(
"Expected a reply, got %s", msg_type);
678 }
else if (reply_id != expected_reply_id) {
679 if (native->expected_late_replies > 0) {
680 native->expected_late_replies--;
682 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
689 if (native->remote->buffer && native->process_notify) {
698 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
703 global_remote_msg_id++;
704 if (global_remote_msg_id <= 0) {
705 global_remote_msg_id = 1;
711 crm_err(
"Disconnecting because TLS message could not be sent to " 713 lrmd_tls_disconnect(lrmd);
719 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
724 if (!remote_executor_connected(lrmd)) {
728 rc = send_remote_message(lrmd, msg);
733 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
735 crm_err(
"Disconnecting remote after request %d reply not received: %s " 736 CRM_XS " rc=%d timeout=%dms",
738 lrmd_tls_disconnect(lrmd);
752 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
757 switch (native->type) {
761 #ifdef HAVE_GNUTLS_GNUTLS_H 762 case pcmk__client_tls:
763 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
767 crm_err(
"Unsupported executor connection type (bug?): %d",
769 rc = -EPROTONOSUPPORT;
776 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
781 switch (native->type) {
785 #ifdef HAVE_GNUTLS_GNUTLS_H 786 case pcmk__client_tls:
787 rc = send_remote_message(lrmd, msg);
792 native->expected_late_replies++;
798 crm_err(
"Unsupported executor connection type (bug?): %d",
800 rc = -EPROTONOSUPPORT;
807 lrmd_api_is_connected(
lrmd_t * lrmd)
811 switch (native->type) {
814 #ifdef HAVE_GNUTLS_GNUTLS_H 815 case pcmk__client_tls:
816 return remote_executor_connected(lrmd);
819 crm_err(
"Unsupported executor connection type (bug?): %d",
844 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
845 xmlNode **output_data,
int timeout,
850 xmlNode *op_msg = NULL;
851 xmlNode *op_reply = NULL;
853 if (!lrmd_api_is_connected(lrmd)) {
858 crm_err(
"No operation specified");
864 crm_trace(
"Sending %s op to executor", op);
866 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
868 if (op_msg == NULL) {
873 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
875 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
883 }
else if(op_reply == NULL) {
898 *output_data = op_reply;
903 if (lrmd_api_is_connected(lrmd) == FALSE) {
904 crm_err(
"Executor disconnected");
913 lrmd_api_poke_connection(
lrmd_t * lrmd)
938 value = g_hash_table_lookup(hash,
"stonith-watchdog-timeout");
951 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
955 xmlNode *reply = NULL;
964 if (native->proxy_callback) {
968 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
971 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d",
rc);
973 }
else if (reply == NULL) {
974 crm_err(
"Did not receive registration reply");
984 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
989 crm_err(
"Invalid registration message: %s", msg_type);
992 }
else if (tmp_ticket == NULL) {
993 crm_err(
"No registration token provided");
997 crm_trace(
"Obtained registration token: %s", tmp_ticket);
998 native->token = strdup(tmp_ticket);
1008 lrmd_api_disconnect(lrmd);
1014 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1021 .destroy = lrmd_ipc_connection_destroy
1024 crm_info(
"Connecting to executor");
1031 }
else if (native->ipc) {
1032 crm_perror(LOG_ERR,
"Connection to executor failed");
1040 if (native->ipc == NULL) {
1041 crm_debug(
"Could not connect to the executor API");
1048 #ifdef HAVE_GNUTLS_GNUTLS_H 1050 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1052 CRM_ASSERT((dest != NULL) && (source != NULL) && (source->data != NULL));
1054 dest->data = gnutls_malloc(source->size);
1057 memcpy(dest->data, source->data, source->size);
1058 dest->size = source->size;
1062 clear_gnutls_datum(gnutls_datum_t *datum)
1064 gnutls_free(datum->data);
1069 #define KEY_READ_LEN 256 // Chunk size for reading key from file 1073 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1075 FILE *stream = NULL;
1076 size_t buf_len = KEY_READ_LEN;
1078 if ((location == NULL) || (key == NULL)) {
1082 stream = fopen(location,
"r");
1083 if (stream == NULL) {
1087 key->data = gnutls_malloc(buf_len);
1089 while (!feof(stream)) {
1090 int next = fgetc(stream);
1093 if (!feof(stream)) {
1094 crm_warn(
"Pacemaker Remote key read was partially successful " 1095 "(copy in memory may be corrupted)");
1099 if (key->size == buf_len) {
1100 buf_len = key->size + KEY_READ_LEN;
1101 key->data = gnutls_realloc(key->data, buf_len);
1104 key->data[key->size++] = (
unsigned char) next;
1108 if (key->size == 0) {
1109 clear_gnutls_datum(key);
1117 struct key_cache_s {
1119 const char *location;
1124 key_is_cached(
struct key_cache_s *key_cache)
1126 return key_cache->updated != 0;
1130 key_cache_expired(
struct key_cache_s *key_cache)
1132 return (time(NULL) - key_cache->updated) >= 60;
1136 clear_key_cache(
struct key_cache_s *key_cache)
1138 clear_gnutls_datum(&(key_cache->key));
1139 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1140 key_cache->updated = 0;
1141 key_cache->location = NULL;
1142 crm_debug(
"Cleared Pacemaker Remote key cache");
1147 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1149 copy_gnutls_datum(key, &(key_cache->key));
1150 crm_debug(
"Using cached Pacemaker Remote key from %s",
1151 crm_str(key_cache->location));
1155 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1156 const char *location)
1158 key_cache->updated = time(NULL);
1159 key_cache->location = location;
1160 copy_gnutls_datum(&(key_cache->key), key);
1161 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1176 get_remote_key(
const char *location, gnutls_datum_t *key)
1178 static struct key_cache_s key_cache = { 0, };
1181 if ((location == NULL) || (key == NULL)) {
1185 if (key_is_cached(&key_cache)) {
1186 if (key_cache_expired(&key_cache)) {
1187 clear_key_cache(&key_cache);
1189 get_cached_key(&key_cache, key);
1194 rc = read_gnutls_key(location, key);
1198 cache_key(&key_cache, key, location);
1216 lrmd__init_remote_key(gnutls_datum_t *key)
1218 static const char *env_location = NULL;
1219 static bool need_env =
true;
1225 bool env_is_default =
false;
1226 bool env_is_fallback =
false;
1229 env_location = getenv(
"PCMK_authkey_location");
1234 if (env_location != NULL) {
1235 env_rc = get_remote_key(env_location, key);
1252 if (env_is_default) {
1253 default_rc = env_rc;
1259 if (env_is_fallback) {
1270 crm_warn(
"Could not read Pacemaker Remote key from %s (%s%s%s%s%s): %s",
1272 env_is_default?
"" :
"or default location ",
1274 !env_is_default && !env_is_fallback?
" " :
"",
1275 env_is_fallback?
"" :
"or fallback location ",
1282 crm_warn(
"Could not read Pacemaker Remote key from %s " 1283 "(using %s location %s instead): %s",
1285 (default_rc ==
pcmk_rc_ok)?
"default" :
"fallback",
1293 crm_warn(
"Could not read Pacemaker Remote key from default location %s" 1294 " (or fallback location %s): %s",
1304 lrmd_gnutls_global_init(
void)
1306 static int gnutls_init = 0;
1309 crm_gnutls_global_init();
1316 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1320 if (native->callback) {
1323 event.remote_nodename = native->remote_nodename;
1324 event.connection_rc =
rc;
1325 native->callback(&event);
1329 #ifdef HAVE_GNUTLS_GNUTLS_H 1333 return pcmk__tls_client_handshake(remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT);
1346 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_handshake)
1352 native->server, native->port);
1356 .destroy = lrmd_tls_connection_destroy,
1360 lrmd_tls_dispatch, lrmd);
1371 rc = lrmd_handshake(lrmd,
name);
1379 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1383 gnutls_datum_t psk_key = { NULL, 0 };
1385 native->async_timer = 0;
1388 lrmd_tls_connection_destroy(lrmd);
1389 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1400 native->sock = sock;
1402 rc = lrmd__init_remote_key(&psk_key);
1404 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1407 lrmd_tls_connection_destroy(lrmd);
1412 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1414 gnutls_free(psk_key.data);
1416 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1418 native->psk_cred_c);
1419 if (native->remote->tls_session == NULL) {
1420 lrmd_tls_connection_destroy(lrmd);
1421 report_async_connection_result(lrmd, -EPROTO);
1425 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1426 crm_warn(
"Disconnecting after TLS handshake with Pacemaker Remote server %s:%d failed",
1427 native->server, native->port);
1428 gnutls_deinit(*native->remote->tls_session);
1429 gnutls_free(native->remote->tls_session);
1430 native->remote->tls_session = NULL;
1431 lrmd_tls_connection_destroy(lrmd);
1436 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1437 native->server, native->port);
1438 rc = add_tls_to_mainloop(lrmd,
true);
1449 lrmd_gnutls_global_init();
1452 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1454 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1459 native->async_timer = timer_id;
1464 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1469 gnutls_datum_t psk_key = { NULL, 0 };
1471 lrmd_gnutls_global_init();
1475 &(native->sock), NULL, NULL);
1477 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1480 lrmd_tls_connection_destroy(lrmd);
1484 rc = lrmd__init_remote_key(&psk_key);
1486 lrmd_tls_connection_destroy(lrmd);
1490 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1492 gnutls_free(psk_key.data);
1494 native->remote->tls_session = pcmk__new_tls_session(native->sock, GNUTLS_CLIENT,
1496 native->psk_cred_c);
1497 if (native->remote->tls_session == NULL) {
1498 lrmd_tls_connection_destroy(lrmd);
1502 if (lrmd__tls_client_handshake(native->remote) !=
pcmk_rc_ok) {
1503 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1504 gnutls_deinit(*native->remote->tls_session);
1505 gnutls_free(native->remote->tls_session);
1506 native->remote->tls_session = NULL;
1507 lrmd_tls_connection_destroy(lrmd);
1511 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1517 add_tls_to_mainloop(lrmd,
false);
1524 lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1529 switch (native->type) {
1531 rc = lrmd_ipc_connect(lrmd, fd);
1533 #ifdef HAVE_GNUTLS_GNUTLS_H 1534 case pcmk__client_tls:
1535 rc = lrmd_tls_connect(lrmd, fd);
1539 crm_err(
"Unsupported executor connection type (bug?): %d",
1541 rc = -EPROTONOSUPPORT;
1545 rc = lrmd_handshake(lrmd,
name);
1557 CRM_CHECK(native && native->callback,
return -EINVAL);
1559 switch (native->type) {
1563 rc = lrmd_api_connect(lrmd,
name, NULL);
1565 report_async_connection_result(lrmd,
rc);
1568 #ifdef HAVE_GNUTLS_GNUTLS_H 1569 case pcmk__client_tls:
1570 rc = lrmd_tls_connect_async(lrmd,
timeout);
1573 report_async_connection_result(lrmd,
rc);
1578 crm_err(
"Unsupported executor connection type (bug?): %d",
1580 rc = -EPROTONOSUPPORT;
1587 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1591 if (native->source != NULL) {
1594 native->source = NULL;
1597 }
else if (native->ipc) {
1607 #ifdef HAVE_GNUTLS_GNUTLS_H 1609 lrmd_tls_disconnect(
lrmd_t * lrmd)
1613 if (native->remote->tls_session) {
1614 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1615 gnutls_deinit(*native->remote->tls_session);
1616 gnutls_free(native->remote->tls_session);
1617 native->remote->tls_session = 0;
1620 if (native->async_timer) {
1621 g_source_remove(native->async_timer);
1622 native->async_timer = 0;
1625 if (native->source != NULL) {
1628 native->source = NULL;
1630 }
else if (native->sock) {
1631 close(native->sock);
1635 if (native->pending_notify) {
1636 g_list_free_full(native->pending_notify, lrmd_free_xml);
1637 native->pending_notify = NULL;
1643 lrmd_api_disconnect(
lrmd_t * lrmd)
1648 crm_info(
"Disconnecting %s %s executor connection",
1650 (native->remote_nodename? native->remote_nodename :
"local"));
1651 switch (native->type) {
1653 lrmd_ipc_disconnect(lrmd);
1655 #ifdef HAVE_GNUTLS_GNUTLS_H 1656 case pcmk__client_tls:
1657 lrmd_tls_disconnect(lrmd);
1661 crm_err(
"Unsupported executor connection type (bug?): %d",
1663 rc = -EPROTONOSUPPORT;
1666 free(native->token);
1667 native->token = NULL;
1669 free(native->peer_version);
1670 native->peer_version = NULL;
1675 lrmd_api_register_rsc(
lrmd_t * lrmd,
1681 xmlNode *
data = NULL;
1683 if (!
class || !
type || !rsc_id) {
1687 && (provider == NULL)) {
1720 const char *provider,
const char *
type)
1726 rsc_info->
id = strdup(rsc_id);
1730 rsc_info->
standard = strdup(standard);
1734 rsc_info->
provider = strdup(provider);
1758 free(rsc_info->
type);
1769 xmlNode *output = NULL;
1770 const char *
class = NULL;
1771 const char *provider = NULL;
1772 const char *
type = NULL;
1787 if (!
class || !
type) {
1814 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1817 xmlNode *
data = NULL;
1818 xmlNode *output_xml = NULL;
1821 if (output == NULL) {
1833 timeout_ms, options, TRUE);
1839 if ((
rc !=
pcmk_ok) || (output_xml == NULL)) {
1847 if (rsc_id == NULL) {
1848 crm_err(
"Could not parse recurring operation information from executor");
1856 if (op_info == NULL) {
1860 op_info->
rsc_id = strdup(rsc_id);
1866 *output = g_list_prepend(*output, op_info);
1879 native->callback = callback;
1887 native->proxy_callback = callback;
1888 native->proxy_callback_userdata = userdata;
1892 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1896 if (native->proxy_callback) {
1898 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1911 return lrmd_send_xml_no_reply(lrmd, msg);
1915 stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
1920 if (stonith_api == NULL) {
1921 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
1926 provider, output, 0);
1927 if ((
rc ==
pcmk_ok) && (*output == NULL)) {
1930 stonith_api->
cmds->
free(stonith_api);
1935 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
1936 const char *
type,
char **output,
1940 output, options, NULL);
1944 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
1945 const char *provider,
const char *
type,
1950 GHashTable *params_table = NULL;
1952 if (!standard || !
type) {
1959 return stonith_get_metadata(provider,
type, output);
1964 g_hash_table_insert(params_table, strdup(param->key), strdup(param->value));
1981 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
1982 standard, provider,
type);
1987 if (!
action->stdout_data) {
1988 crm_err(
"Failed to receive meta-data for %s:%s:%s",
1989 standard, provider,
type);
1994 *output = strdup(
action->stdout_data);
2001 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2002 const char *userdata, guint interval_ms,
2020 for (tmp = params; tmp; tmp = tmp->
next) {
2033 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2046 for (tmp = params; tmp; tmp = tmp->
next) {
2059 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2082 if (stonith_api == NULL) {
2083 crm_err(
"Could not list fence agents: API memory allocation failed");
2087 &stonith_resources, 0);
2088 stonith_api->
cmds->
free(stonith_api);
2090 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2093 *resources = lrmd_list_add(*resources, dIter->
value);
2102 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2103 const char *provider)
2106 int stonith_count = 0;
2112 GList *gIter = NULL;
2115 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2116 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2119 g_list_free_full(agents, free);
2126 if (stonith_count) {
2128 stonith_count = list_stonith_agents(resources);
2129 if (stonith_count > 0) {
2130 rc += stonith_count;
2134 crm_notice(
"No agents found for class %s",
class);
2135 rc = -EPROTONOSUPPORT;
2141 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2144 GList *agents = NULL;
2145 GList *gIter2 = NULL;
2148 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2153 g_list_free_full(agents, free);
2158 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2161 char *provider = NULL;
2162 GList *ocf_providers = NULL;
2163 GList *gIter = NULL;
2167 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2168 provider = gIter->data;
2169 if (!agent || does_provider_have_agent(agent, provider,
2171 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2176 g_list_free_full(ocf_providers, free);
2184 GList *standards = NULL;
2185 GList *gIter = NULL;
2189 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2190 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2194 if (list_stonith_agents(NULL) > 0) {
2199 g_list_free_full(standards, free);
2234 *api = calloc(1,
sizeof(
lrmd_t));
2252 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2260 (*api)->cmds->connect_async = lrmd_api_connect_async;
2261 (*api)->cmds->is_connected = lrmd_api_is_connected;
2262 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2263 (*api)->cmds->disconnect = lrmd_api_disconnect;
2264 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2265 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2266 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2267 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2268 (*api)->cmds->set_callback = lrmd_api_set_callback;
2269 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2270 (*api)->cmds->exec = lrmd_api_exec;
2271 (*api)->cmds->cancel = lrmd_api_cancel;
2272 (*api)->cmds->list_agents = lrmd_api_list_agents;
2273 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2274 (*api)->cmds->list_standards = lrmd_api_list_standards;
2275 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2276 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2278 if ((nodename == NULL) && (server == NULL)) {
2281 #ifdef HAVE_GNUTLS_GNUTLS_H 2282 if (nodename == NULL) {
2284 }
else if (server == NULL) {
2287 pvt->type = pcmk__client_tls;
2288 pvt->remote_nodename = strdup(nodename);
2289 pvt->server = strdup(server);
2290 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2296 if (pvt->port == 0) {
2300 crm_err(
"Cannot communicate with Pacemaker Remote " 2301 "because GnuTLS is not enabled for this build");
2334 if (lrmd->
cmds != NULL) {
2341 #ifdef HAVE_GNUTLS_GNUTLS_H 2342 free(native->server);
2344 free(native->remote_nodename);
2345 free(native->remote);
2346 free(native->token);
2347 free(native->peer_version);
2364 const char *exit_reason)
2366 if (event == NULL) {
2375 event->exit_reason = (exit_reason == NULL)? NULL : strdup(exit_reason);
2388 if (event == NULL) {
2393 event->exit_reason = NULL;
2395 free((
void *) event->
output);
2396 event->output = NULL;
#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.
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)
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)
#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.
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)
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 mainloop_set_trigger(crm_trigger_t *source)
#define DEFAULT_REMOTE_USERNAME
#define LRMD_OP_GET_RECURRING
#define MAX_TLS_RECV_WAIT
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.
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.
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(* free)(stonith_t *st)
Destroy the stonith api structure.
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
#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
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)
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
#define LRMD_PROTOCOL_VERSION
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...)
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))
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)
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_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)
Get resource metadata for a resource agent, passing parameters.
struct lrmd_key_value_s * next
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.
#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)
bool crm_ipc_connected(crm_ipc_t *client)
int lrmd_poll(lrmd_t *lrmd, int timeout)
Poll for a specified timeout period to determine if a message is ready for dispatch.
#define PCMK_RESOURCE_CLASS_STONITH
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)
#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 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.
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)
#define F_LRMD_RSC_RUN_TIME
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)
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
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
#define F_LRMD_REMOTE_MSG_TYPE
void crm_ipc_close(crm_ipc_t *client)
#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.
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Get next instance of same XML tag.