17 #include <sys/types.h>
33 #ifdef HAVE_GNUTLS_GNUTLS_H
35 # include <gnutls/gnutls.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/ip.h>
41 #include <arpa/inet.h>
44 #define MAX_TLS_RECV_WAIT 10000
48 static int lrmd_api_disconnect(
lrmd_t * lrmd);
49 static int lrmd_api_is_connected(
lrmd_t * lrmd);
53 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
56 #ifdef HAVE_GNUTLS_GNUTLS_H
57 # define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000
58 gnutls_psk_client_credentials_t psk_cred_s;
59 int lrmd_tls_set_key(gnutls_datum_t * key);
60 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
61 static int global_remote_msg_id = 0;
62 int lrmd_tls_send_msg(
crm_remote_t * session, xmlNode * msg, uint32_t
id,
const char *msg_type);
63 static void lrmd_tls_connection_destroy(gpointer userdata);
66 typedef struct lrmd_private_s {
77 char *remote_nodename;
78 #ifdef HAVE_GNUTLS_GNUTLS_H
81 gnutls_psk_client_credentials_t psk_cred_c;
91 int expected_late_replies;
92 GList *pending_notify;
99 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
100 void *proxy_callback_userdata;
105 lrmd_list_add(
lrmd_list_t * head,
const char *value)
110 p->
val = strdup(value);
113 while (end && end->
next) {
132 char *val = (
char *)head->
val;
147 p->
key = strdup(key);
148 p->
value = strdup(value);
151 while (end && end->
next) {
190 copy->
rsc_id =
event->rsc_id ? strdup(event->
rsc_id) : NULL;
193 copy->
output =
event->output ? strdup(event->
output) : NULL;
209 free((
char *)event->
rsc_id);
212 free((
char *)event->
output);
216 g_hash_table_destroy(event->
params);
222 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
229 if (proxy_session != NULL) {
231 lrmd_internal_proxy_dispatch(lrmd, msg);
233 }
else if (!native->callback) {
235 crm_trace(
"notify event received but client has not set callback");
239 event.remote_nodename = native->remote_nodename;
276 crm_trace(
"op %s notify event received", type);
277 native->callback(&event);
280 g_hash_table_destroy(event.params);
286 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
293 if (!native->callback) {
299 rc = lrmd_dispatch_internal(lrmd, msg);
304 #ifdef HAVE_GNUTLS_GNUTLS_H
306 lrmd_free_xml(gpointer userdata)
312 lrmd_tls_connected(
lrmd_t * lrmd)
316 if (native->remote->tls_session) {
324 lrmd_tls_dispatch(gpointer userdata)
330 int disconnected = 0;
332 if (lrmd_tls_connected(lrmd) == FALSE) {
333 crm_trace(
"TLS dispatch triggered after disconnect");
341 if (native->pending_notify) {
344 crm_trace(
"Processing pending notifies");
345 for (iter = native->pending_notify; iter; iter = iter->next) {
346 lrmd_dispatch_internal(lrmd, iter->data);
348 g_list_free_full(native->pending_notify, lrmd_free_xml);
349 native->pending_notify = NULL;
366 lrmd_dispatch_internal(lrmd, xml);
368 if (native->expected_late_replies > 0) {
369 native->expected_late_replies--;
374 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
382 crm_info(
"Lost %s executor connection while reading data",
383 (native->remote_nodename? native->remote_nodename :
"local"));
384 lrmd_tls_disconnect(lrmd);
397 switch (native->type) {
401 #ifdef HAVE_GNUTLS_GNUTLS_H
403 if (native->pending_notify) {
410 crm_err(
"Unsupported connection type: %d", native->type);
425 switch (private->type) {
431 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
435 #ifdef HAVE_GNUTLS_GNUTLS_H
437 lrmd_tls_dispatch(lrmd);
441 crm_err(
"Unsupported connection type: %d", private->type);
444 if (lrmd_api_is_connected(lrmd) == FALSE) {
453 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
472 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
473 op, (
long)options, options);
478 lrmd_ipc_connection_destroy(gpointer userdata)
483 crm_info(
"IPC connection destroyed");
487 native->source = NULL;
489 if (native->callback) {
492 event.remote_nodename = native->remote_nodename;
493 native->callback(&event);
497 #ifdef HAVE_GNUTLS_GNUTLS_H
499 lrmd_tls_connection_destroy(gpointer userdata)
504 crm_info(
"TLS connection destroyed");
506 if (native->remote->tls_session) {
507 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
508 gnutls_deinit(*native->remote->tls_session);
509 gnutls_free(native->remote->tls_session);
511 if (native->psk_cred_c) {
512 gnutls_psk_free_client_credentials(native->psk_cred_c);
517 if (native->process_notify) {
519 native->process_notify = NULL;
521 if (native->pending_notify) {
522 g_list_free_full(native->pending_notify, lrmd_free_xml);
523 native->pending_notify = NULL;
526 free(native->remote->buffer);
527 native->remote->buffer = NULL;
530 native->psk_cred_c = NULL;
531 native->remote->tls_session = NULL;
534 if (native->callback) {
538 native->callback(&event);
544 lrmd_tls_send_msg(
crm_remote_t * session, xmlNode * msg, uint32_t
id,
const char *msg_type)
552 lrmd_tls_recv_reply(
lrmd_t * lrmd,
int total_timeout,
int expected_reply_id,
int *disconnected)
556 time_t start = time(NULL);
557 const char *msg_type = NULL;
559 int remaining_timeout = 0;
572 if (remaining_timeout) {
573 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
575 remaining_timeout = total_timeout;
577 if (remaining_timeout <= 0) {
578 crm_err(
"Never received the expected reply during the timeout period, disconnecting.");
579 *disconnected = TRUE;
586 crm_err(
"Unable to receive expected reply, disconnecting.");
587 *disconnected = TRUE;
589 }
else if (*disconnected) {
600 crm_err(
"Empty msg type received while waiting for reply");
606 native->pending_notify = g_list_append(native->pending_notify, xml);
607 if (native->process_notify) {
614 crm_err(
"Expected a reply, got %s", msg_type);
617 }
else if (reply_id != expected_reply_id) {
618 if (native->expected_late_replies > 0) {
619 native->expected_late_replies--;
621 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
628 if (native->remote->buffer && native->process_notify) {
636 lrmd_tls_send(
lrmd_t * lrmd, xmlNode * msg)
641 global_remote_msg_id++;
642 if (global_remote_msg_id <= 0) {
643 global_remote_msg_id = 1;
646 rc = lrmd_tls_send_msg(native->remote, msg, global_remote_msg_id,
"request");
648 crm_err(
"Disconnecting because TLS message could not be sent to Pacemaker Remote");
649 lrmd_tls_disconnect(lrmd);
656 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
659 int disconnected = 0;
662 if (lrmd_tls_connected(lrmd) == FALSE) {
666 rc = lrmd_tls_send(lrmd, msg);
671 xml = lrmd_tls_recv_reply(lrmd, timeout, global_remote_msg_id, &disconnected);
674 crm_err(
"Pacemaker Remote disconnected while waiting for reply to request id %d",
675 global_remote_msg_id);
676 lrmd_tls_disconnect(lrmd);
679 crm_err(
"Did not receive reply from Pacemaker Remote for request id %d (timeout %dms)",
680 global_remote_msg_id, timeout);
695 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
700 switch (native->type) {
704 #ifdef HAVE_GNUTLS_GNUTLS_H
706 rc = lrmd_tls_send_recv(lrmd, msg, timeout, reply);
710 crm_err(
"Unsupported connection type: %d", native->type);
717 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
722 switch (native->type) {
726 #ifdef HAVE_GNUTLS_GNUTLS_H
728 rc = lrmd_tls_send(lrmd, msg);
733 native->expected_late_replies++;
738 crm_err(
"Unsupported connection type: %d", native->type);
745 lrmd_api_is_connected(
lrmd_t * lrmd)
749 switch (native->type) {
753 #ifdef HAVE_GNUTLS_GNUTLS_H
755 return lrmd_tls_connected(lrmd);
759 crm_err(
"Unsupported connection type: %d", native->type);
784 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *data,
785 xmlNode **output_data,
int timeout,
790 xmlNode *op_msg = NULL;
791 xmlNode *op_reply = NULL;
793 if (!lrmd_api_is_connected(lrmd)) {
798 crm_err(
"No operation specified");
804 crm_trace(
"Sending %s op to executor", op);
806 op_msg = lrmd_create_op(native->token, op, data, timeout, options);
808 if (op_msg == NULL) {
813 rc = lrmd_send_xml(lrmd, op_msg, timeout, &op_reply);
815 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
820 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op, timeout, rc);
824 }
else if(op_reply == NULL) {
839 *output_data = op_reply;
844 if (lrmd_api_is_connected(lrmd) == FALSE) {
845 crm_err(
"Executor disconnected");
854 lrmd_api_poke_connection(
lrmd_t * lrmd)
877 value = g_hash_table_lookup(hash,
"stonith-watchdog-timeout");
887 lrmd_handshake(
lrmd_t * lrmd,
const char *name)
891 xmlNode *reply = NULL;
900 if (native->proxy_callback) {
904 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
907 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
909 }
else if (reply == NULL) {
910 crm_err(
"Did not receive registration reply");
920 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
925 crm_err(
"Invalid registration message: %s", msg_type);
928 }
else if (tmp_ticket == NULL) {
929 crm_err(
"No registration token provided");
933 crm_trace(
"Obtained registration token: %s", tmp_ticket);
934 native->token = strdup(tmp_ticket);
935 native->peer_version = strdup(version?version:
"1.0");
944 lrmd_api_disconnect(lrmd);
950 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
957 .destroy = lrmd_ipc_connection_destroy
967 }
else if (native->ipc) {
968 crm_perror(LOG_ERR,
"Connection to executor failed");
976 if (native->ipc == NULL) {
977 crm_debug(
"Could not connect to the executor API");
984 #ifdef HAVE_GNUTLS_GNUTLS_H
986 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
988 dest->data = gnutls_malloc(source->size);
990 memcpy(dest->data, source->data, source->size);
991 dest->size = source->size;
995 clear_gnutls_datum(gnutls_datum_t *datum)
997 gnutls_free(datum->data);
1002 #define KEY_READ_LEN 256
1005 set_key(gnutls_datum_t * key,
const char *location)
1008 size_t buf_len = KEY_READ_LEN;
1009 static gnutls_datum_t key_cache = { 0, };
1010 static time_t key_cache_updated = 0;
1012 if (location == NULL) {
1016 if (key_cache.data != NULL) {
1017 if ((time(NULL) - key_cache_updated) < 60) {
1018 copy_gnutls_datum(key, &key_cache);
1019 crm_debug(
"Using cached Pacemaker Remote key");
1022 clear_gnutls_datum(&key_cache);
1023 key_cache_updated = 0;
1024 crm_debug(
"Cleared Pacemaker Remote key cache");
1028 stream = fopen(location,
"r");
1033 key->data = gnutls_malloc(buf_len);
1035 while (!feof(stream)) {
1036 int next = fgetc(stream);
1039 if (!feof(stream)) {
1040 crm_err(
"Error reading Pacemaker Remote key; copy in memory may be corrupted");
1044 if (key->size == buf_len) {
1045 buf_len = key->size + KEY_READ_LEN;
1046 key->data = gnutls_realloc(key->data, buf_len);
1049 key->data[key->size++] = (
unsigned char) next;
1053 if (key->size == 0) {
1054 clear_gnutls_datum(key);
1058 if (key_cache.data == NULL) {
1059 copy_gnutls_datum(&key_cache, key);
1060 key_cache_updated = time(NULL);
1061 crm_debug(
"Cached Pacemaker Remote key");
1068 lrmd_tls_set_key(gnutls_datum_t * key)
1070 const char *specific_location = getenv(
"PCMK_authkey_location");
1072 if (set_key(key, specific_location) == 0) {
1073 crm_debug(
"Using custom authkey location %s", specific_location);
1076 }
else if (specific_location) {
1077 crm_err(
"No valid Pacemaker Remote key found at %s, trying default location", specific_location);
1090 lrmd_gnutls_global_init(
void)
1092 static int gnutls_init = 0;
1095 crm_gnutls_global_init();
1102 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1106 if (native->callback) {
1109 event.remote_nodename = native->remote_nodename;
1110 event.connection_rc = rc;
1111 native->callback(&event);
1115 #ifdef HAVE_GNUTLS_GNUTLS_H
1117 lrmd_tcp_connect_cb(
void *userdata,
int sock)
1124 .destroy = lrmd_tls_connection_destroy,
1127 gnutls_datum_t psk_key = { NULL, 0 };
1129 native->async_timer = 0;
1132 lrmd_tls_connection_destroy(lrmd);
1133 crm_info(
"Could not connect to Pacemaker Remote at %s:%d",
1134 native->server, native->port);
1135 report_async_connection_result(lrmd, rc);
1143 native->sock = sock;
1145 rc = lrmd_tls_set_key(&psk_key);
1147 crm_warn(
"Could not set key for Pacemaker Remote at %s:%d " CRM_XS " rc=%d",
1148 native->server, native->port, rc);
1149 lrmd_tls_connection_destroy(lrmd);
1150 report_async_connection_result(lrmd, rc);
1154 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1156 gnutls_free(psk_key.data);
1158 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1160 native->psk_cred_c);
1161 if (native->remote->tls_session == NULL) {
1162 lrmd_tls_connection_destroy(lrmd);
1163 report_async_connection_result(lrmd, -EPROTO);
1167 if (crm_initiate_client_tls_handshake(native->remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT) != 0) {
1168 crm_warn(
"Disconnecting after TLS handshake with Pacemaker Remote server %s:%d failed",
1169 native->server, native->port);
1170 gnutls_deinit(*native->remote->tls_session);
1171 gnutls_free(native->remote->tls_session);
1172 native->remote->tls_session = NULL;
1173 lrmd_tls_connection_destroy(lrmd);
1178 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1179 native->server, native->port);
1182 native->server, native->port);
1186 mainloop_add_fd(name, G_PRIORITY_HIGH, native->sock, lrmd, &lrmd_tls_callbacks);
1188 rc = lrmd_handshake(lrmd, name);
1191 report_async_connection_result(lrmd, rc);
1196 lrmd_tls_connect_async(
lrmd_t * lrmd,
int timeout )
1202 lrmd_gnutls_global_init();
1204 &timer_id, lrmd, lrmd_tcp_connect_cb);
1208 native->sock = sock;
1209 native->async_timer = timer_id;
1214 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1218 .destroy = lrmd_tls_connection_destroy,
1224 gnutls_datum_t psk_key = { NULL, 0 };
1226 lrmd_gnutls_global_init();
1230 crm_warn(
"Could not establish Pacemaker Remote connection to %s", native->server);
1231 lrmd_tls_connection_destroy(lrmd);
1235 native->sock = sock;
1237 rc = lrmd_tls_set_key(&psk_key);
1239 lrmd_tls_connection_destroy(lrmd);
1243 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1245 gnutls_free(psk_key.data);
1247 native->remote->tls_session = pcmk__new_tls_session(sock, GNUTLS_CLIENT,
1249 native->psk_cred_c);
1250 if (native->remote->tls_session == NULL) {
1251 lrmd_tls_connection_destroy(lrmd);
1255 if (crm_initiate_client_tls_handshake(native->remote, LRMD_CLIENT_HANDSHAKE_TIMEOUT) != 0) {
1256 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1257 gnutls_deinit(*native->remote->tls_session);
1258 gnutls_free(native->remote->tls_session);
1259 native->remote->tls_session = NULL;
1260 lrmd_tls_connection_destroy(lrmd);
1264 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1271 native->server, native->port);
1275 mainloop_add_fd(name, G_PRIORITY_HIGH, native->sock, lrmd, &lrmd_tls_callbacks);
1283 lrmd_api_connect(
lrmd_t * lrmd,
const char *name,
int *fd)
1288 switch (native->type) {
1290 rc = lrmd_ipc_connect(lrmd, fd);
1292 #ifdef HAVE_GNUTLS_GNUTLS_H
1293 case CRM_CLIENT_TLS:
1294 rc = lrmd_tls_connect(lrmd, fd);
1298 crm_err(
"Unsupported connection type: %d", native->type);
1302 rc = lrmd_handshake(lrmd, name);
1309 lrmd_api_connect_async(
lrmd_t * lrmd,
const char *name,
int timeout)
1314 CRM_CHECK(native && native->callback,
return -1);
1316 switch (native->type) {
1320 rc = lrmd_api_connect(lrmd, name, NULL);
1322 report_async_connection_result(lrmd, rc);
1325 #ifdef HAVE_GNUTLS_GNUTLS_H
1326 case CRM_CLIENT_TLS:
1327 rc = lrmd_tls_connect_async(lrmd, timeout);
1330 report_async_connection_result(lrmd, rc);
1335 crm_err(
"Unsupported connection type: %d", native->type);
1342 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1346 if (native->source != NULL) {
1349 native->source = NULL;
1352 }
else if (native->ipc) {
1362 #ifdef HAVE_GNUTLS_GNUTLS_H
1364 lrmd_tls_disconnect(
lrmd_t * lrmd)
1368 if (native->remote->tls_session) {
1369 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1370 gnutls_deinit(*native->remote->tls_session);
1371 gnutls_free(native->remote->tls_session);
1372 native->remote->tls_session = 0;
1375 if (native->async_timer) {
1376 g_source_remove(native->async_timer);
1377 native->async_timer = 0;
1380 if (native->source != NULL) {
1383 native->source = NULL;
1385 }
else if (native->sock) {
1386 close(native->sock);
1390 if (native->pending_notify) {
1391 g_list_free_full(native->pending_notify, lrmd_free_xml);
1392 native->pending_notify = NULL;
1398 lrmd_api_disconnect(
lrmd_t * lrmd)
1402 crm_info(
"Disconnecting %s %s executor connection",
1404 (native->remote_nodename? native->remote_nodename :
"local"));
1405 switch (native->type) {
1407 lrmd_ipc_disconnect(lrmd);
1409 #ifdef HAVE_GNUTLS_GNUTLS_H
1410 case CRM_CLIENT_TLS:
1411 lrmd_tls_disconnect(lrmd);
1415 crm_err(
"Unsupported connection type: %d", native->type);
1418 free(native->token);
1419 native->token = NULL;
1421 free(native->peer_version);
1422 native->peer_version = NULL;
1427 lrmd_api_register_rsc(
lrmd_t * lrmd,
1433 xmlNode *data = NULL;
1435 if (!
class || !type || !rsc_id) {
1449 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_REG, data, NULL, 0, options, TRUE);
1471 const char *provider,
const char *type)
1477 rsc_info->
id = strdup(rsc_id);
1481 rsc_info->
standard = strdup(standard);
1485 rsc_info->
provider = strdup(provider);
1489 rsc_info->
type = strdup(type);
1509 free(rsc_info->
type);
1520 xmlNode *output = NULL;
1521 const char *
class = NULL;
1522 const char *provider = NULL;
1523 const char *type = NULL;
1527 lrmd_send_command(lrmd,
LRMD_OP_RSC_INFO, data, &output, 0, options, TRUE);
1538 if (!
class || !type) {
1565 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1568 xmlNode *data = NULL;
1569 xmlNode *output_xml = NULL;
1572 if (output == NULL) {
1584 timeout_ms, options, TRUE);
1590 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1597 if (rsc_id == NULL) {
1598 crm_err(
"Could not parse recurring operation information from executor");
1607 op_info->
rsc_id = strdup(rsc_id);
1613 *output = g_list_prepend(*output, op_info);
1626 native->callback = callback;
1634 native->proxy_callback = callback;
1635 native->proxy_callback_userdata = userdata;
1639 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1643 if (native->proxy_callback) {
1645 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1658 return lrmd_send_xml_no_reply(lrmd, msg);
1662 stonith_get_metadata(
const char *provider,
const char *type,
char **output)
1669 stonith_api->
cmds->
free(stonith_api);
1671 if (*output == NULL) {
1678 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
1679 const char *type,
char **output,
1683 output, options, NULL);
1687 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
1688 const char *provider,
const char *type,
1693 GHashTable *params_table = NULL;
1695 if (!standard || !type) {
1702 return stonith_get_metadata(provider, type, output);
1705 params_table = crm_str_table_new();
1707 g_hash_table_insert(params_table, strdup(param->key), strdup(param->value));
1715 if (action == NULL) {
1716 crm_err(
"Unable to retrieve meta-data for %s:%s:%s",
1717 standard, provider, type);
1722 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
1723 standard, provider, type);
1729 crm_err(
"Failed to receive meta-data for %s:%s:%s",
1730 standard, provider, type);
1742 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *action,
1743 const char *userdata, guint interval_ms,
1761 for (tmp = params; tmp; tmp = tmp->
next) {
1765 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_EXEC, data, NULL, timeout, options, TRUE);
1774 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
1787 for (tmp = params; tmp; tmp = tmp->
next) {
1800 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *action,
1825 stonith_api->
cmds->
free(stonith_api);
1828 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
1831 *resources = lrmd_list_add(*resources, dIter->
value);
1840 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
1841 const char *provider)
1846 rc += list_stonith_agents(resources);
1852 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
1853 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
1856 g_list_free_full(agents, free);
1859 rc += list_stonith_agents(resources);
1864 crm_notice(
"No agents found for class %s",
class);
1865 rc = -EPROTONOSUPPORT;
1871 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
1874 GList *agents = NULL;
1878 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
1883 g_list_free_full(agents, free);
1889 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
1892 char *provider = NULL;
1893 GList *ocf_providers = NULL;
1898 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
1899 provider = gIter->data;
1900 if (!agent || does_provider_have_agent(agent, provider,
1902 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
1907 g_list_free_full(ocf_providers, free);
1915 GList *standards = NULL;
1920 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
1921 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
1925 if (list_stonith_agents(NULL) > 0) {
1930 g_list_free_full(standards, free);
1940 new_lrmd = calloc(1,
sizeof(
lrmd_t));
1959 new_lrmd->
cmds->
exec = lrmd_api_exec;
1973 #ifdef HAVE_GNUTLS_GNUTLS_H
1977 if (!nodename && !server) {
1982 native->type = CRM_CLIENT_TLS;
1983 native->remote_nodename = nodename ? strdup(nodename) : strdup(server);
1984 native->server = server ? strdup(server) : strdup(nodename);
1985 native->port = port;
1986 if (native->port == 0) {
1992 crm_err(
"Cannot communicate with Pacemaker Remote because GnuTLS is not enabled for this build");
2008 #ifdef HAVE_GNUTLS_GNUTLS_H
2009 free(native->server);
2011 free(native->remote_nodename);
2012 free(native->remote);
2013 free(native->token);
2014 free(native->peer_version);
#define CRM_CHECK(expr, failure_action)
#define LRMD_OP_ALERT_EXEC
#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.
gboolean safe_str_neq(const char *a, const char *b)
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(* cancel)(lrmd_t *lrmd, const char *rsc_id, const char *action, guint interval_ms)
Cancel a recurring command.
int crm_remote_tcp_connect(const char *host, int port)
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
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.
void lrmd_free_event(lrmd_event_data_t *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)
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
#define F_LRMD_ALERT_PATH
long crm_ipc_read(crm_ipc_t *client)
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
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)
const char * crm_client_type_text(enum client_type client_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
int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash)
int crm_remote_send(crm_remote_t *remote, xmlNode *msg)
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...)
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)
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.
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
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)
GList * resources_list_providers(const char *standard)
Get a list of providers.
int crm_remote_ready(crm_remote_t *remote, int total_timeout)
int crm_remote_tcp_connect_async(const char *host, int port, int timeout, int *timer_id, void *userdata, void(*callback)(void *userdata, int sock))
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
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
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
gboolean crm_remote_recv(crm_remote_t *remote, int total_timeout, int *disconnected)
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
#define crm_log_xml_err(xml, text)
#define F_LRMD_REMOTE_MSG_ID
#define crm_perror(level, fmt, args...)
Log a system error message.
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...)
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)
GHashTable * crm_str_table_dup(GHashTable *old_table)
#define CRMD_ACTION_METADATA
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
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.
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.
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)
#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
#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 safe_str_eq(a, b)
#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)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
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)
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of standards supported by this machine/installation.
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
xmlNode * crm_remote_parse_buffer(crm_remote_t *remote)
enum crm_ais_msg_types type
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Get next instance of same XML tag.