29 #include <sys/types.h>
44 #ifdef HAVE_GNUTLS_GNUTLS_H
46 # include <gnutls/gnutls.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <netinet/ip.h>
52 #include <arpa/inet.h>
55 #define MAX_TLS_RECV_WAIT 10000
59 static int lrmd_api_disconnect(
lrmd_t * lrmd);
60 static int lrmd_api_is_connected(
lrmd_t * lrmd);
64 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
67 #ifdef HAVE_GNUTLS_GNUTLS_H
68 # define LRMD_CLIENT_HANDSHAKE_TIMEOUT 5000
69 gnutls_psk_client_credentials_t psk_cred_s;
70 int lrmd_tls_set_key(gnutls_datum_t * key);
71 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
72 static int global_remote_msg_id = 0;
74 static void lrmd_tls_connection_destroy(gpointer userdata);
77 typedef struct lrmd_private_s {
88 char *remote_nodename;
89 #ifdef HAVE_GNUTLS_GNUTLS_H
92 gnutls_psk_client_credentials_t psk_cred_c;
102 int expected_late_replies;
103 GList *pending_notify;
110 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
111 void *proxy_callback_userdata;
116 lrmd_list_add(
lrmd_list_t * head,
const char *value)
121 p->
val = strdup(value);
124 while (end && end->
next) {
143 char *val = (
char *)head->
val;
158 p->
key = strdup(key);
159 p->
value = strdup(value);
162 while (end && end->
next) {
190 dup_attr(gpointer key, gpointer value, gpointer user_data)
192 g_hash_table_replace(user_data, strdup(key), strdup(value));
207 copy->
rsc_id =
event->rsc_id ? strdup(event->
rsc_id) : NULL;
210 copy->
output =
event->output ? strdup(event->
output) : NULL;
218 if (copy->
params != NULL) {
219 g_hash_table_foreach(event->
params, dup_attr, copy->
params);
234 free((
char *)event->
rsc_id);
237 free((
char *)event->
output);
241 g_hash_table_destroy(event->
params);
247 lrmd_dispatch_internal(
lrmd_t * lrmd, xmlNode * msg)
254 if (proxy_session != NULL) {
256 lrmd_internal_proxy_dispatch(lrmd, msg);
258 }
else if (!native->callback) {
260 crm_trace(
"notify event received but client has not set callback");
264 event.remote_nodename = native->remote_nodename;
301 crm_trace(
"op %s notify event received", type);
302 native->callback(&event);
305 g_hash_table_destroy(event.params);
311 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
318 if (!native->callback) {
324 rc = lrmd_dispatch_internal(lrmd, msg);
329 #ifdef HAVE_GNUTLS_GNUTLS_H
331 lrmd_free_xml(gpointer userdata)
337 lrmd_tls_connected(
lrmd_t * lrmd)
341 if (native->remote->tls_session) {
349 lrmd_tls_dispatch(gpointer userdata)
355 int disconnected = 0;
357 if (lrmd_tls_connected(lrmd) == FALSE) {
358 crm_trace(
"tls dispatch triggered after disconnect");
366 if (native->pending_notify) {
369 crm_trace(
"Processing pending notifies");
370 for (iter = native->pending_notify; iter; iter = iter->next) {
371 lrmd_dispatch_internal(lrmd, iter->data);
373 g_list_free_full(native->pending_notify, lrmd_free_xml);
374 native->pending_notify = NULL;
391 lrmd_dispatch_internal(lrmd, xml);
393 if (native->expected_late_replies > 0) {
394 native->expected_late_replies--;
399 crm_err(
"Got outdated reply %d", reply_id);
407 crm_info(
"Server disconnected while reading remote server msg.");
408 lrmd_tls_disconnect(lrmd);
421 switch (native->type) {
425 #ifdef HAVE_GNUTLS_GNUTLS_H
427 if (native->pending_notify) {
434 crm_err(
"Unsupported connection type: %d", native->type);
449 switch (private->type) {
455 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
459 #ifdef HAVE_GNUTLS_GNUTLS_H
461 lrmd_tls_dispatch(lrmd);
465 crm_err(
"Unsupported connection type: %d", private->type);
468 if (lrmd_api_is_connected(lrmd) == FALSE) {
489 crm_trace(
"Sending call options: %.8lx, %d", (
long)options, options);
500 lrmd_ipc_connection_destroy(gpointer userdata)
505 crm_info(
"IPC connection destroyed");
509 native->source = NULL;
511 if (native->callback) {
514 event.remote_nodename = native->remote_nodename;
515 native->callback(&event);
519 #ifdef HAVE_GNUTLS_GNUTLS_H
521 lrmd_tls_connection_destroy(gpointer userdata)
526 crm_info(
"TLS connection destroyed");
528 if (native->remote->tls_session) {
529 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
530 gnutls_deinit(*native->remote->tls_session);
531 gnutls_free(native->remote->tls_session);
533 if (native->psk_cred_c) {
534 gnutls_psk_free_client_credentials(native->psk_cred_c);
539 if (native->process_notify) {
541 native->process_notify = NULL;
543 if (native->pending_notify) {
544 g_list_free_full(native->pending_notify, lrmd_free_xml);
545 native->pending_notify = NULL;
548 free(native->remote->buffer);
549 native->remote->buffer = NULL;
552 native->psk_cred_c = NULL;
553 native->remote->tls_session = NULL;
556 if (native->callback) {
560 native->callback(&event);
576 crm_err(
"Failed to send remote lrmd tls msg, rc = %d", rc);
584 lrmd_tls_recv_reply(
lrmd_t * lrmd,
int total_timeout,
int expected_reply_id,
int *disconnected)
588 time_t start = time(NULL);
589 const char *msg_type = NULL;
591 int remaining_timeout = 0;
604 if (remaining_timeout) {
605 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
607 remaining_timeout = total_timeout;
609 if (remaining_timeout <= 0) {
610 crm_err(
"Never received the expected reply during the timeout period, disconnecting.");
611 *disconnected = TRUE;
618 crm_err(
"Unable to receive expected reply, disconnecting.");
619 *disconnected = TRUE;
621 }
else if (*disconnected) {
632 crm_err(
"Empty msg type received while waiting for reply");
638 native->pending_notify = g_list_append(native->pending_notify, xml);
639 if (native->process_notify) {
646 crm_err(
"Expected a reply, got %s", msg_type);
649 }
else if (reply_id != expected_reply_id) {
650 if (native->expected_late_replies > 0) {
651 native->expected_late_replies--;
653 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
660 if (native->remote->buffer && native->process_notify) {
668 lrmd_tls_send(
lrmd_t * lrmd, xmlNode * msg)
673 global_remote_msg_id++;
674 if (global_remote_msg_id <= 0) {
675 global_remote_msg_id = 1;
678 rc = lrmd_tls_send_msg(native->remote, msg, global_remote_msg_id,
"request");
680 crm_err(
"Remote lrmd send failed, disconnecting");
681 lrmd_tls_disconnect(lrmd);
688 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
691 int disconnected = 0;
694 if (lrmd_tls_connected(lrmd) == FALSE) {
698 rc = lrmd_tls_send(lrmd, msg);
703 xml = lrmd_tls_recv_reply(lrmd, timeout, global_remote_msg_id, &disconnected);
706 crm_err(
"Remote lrmd server disconnected while waiting for reply with id %d. ",
707 global_remote_msg_id);
708 lrmd_tls_disconnect(lrmd);
711 crm_err(
"Remote lrmd never received reply for request id %d. timeout: %dms ",
712 global_remote_msg_id, timeout);
727 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
732 switch (native->type) {
736 #ifdef HAVE_GNUTLS_GNUTLS_H
738 rc = lrmd_tls_send_recv(lrmd, msg, timeout, reply);
742 crm_err(
"Unsupported connection type: %d", native->type);
749 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
754 switch (native->type) {
758 #ifdef HAVE_GNUTLS_GNUTLS_H
760 rc = lrmd_tls_send(lrmd, msg);
765 native->expected_late_replies++;
770 crm_err(
"Unsupported connection type: %d", native->type);
777 lrmd_api_is_connected(
lrmd_t * lrmd)
781 switch (native->type) {
785 #ifdef HAVE_GNUTLS_GNUTLS_H
787 return lrmd_tls_connected(lrmd);
791 crm_err(
"Unsupported connection type: %d", native->type);
798 lrmd_send_command(
lrmd_t * lrmd,
const char *op, xmlNode * data, xmlNode ** output_data,
int timeout,
804 xmlNode *op_msg = NULL;
805 xmlNode *op_reply = NULL;
807 if (!lrmd_api_is_connected(lrmd)) {
812 crm_err(
"No operation specified");
820 op_msg = lrmd_create_op(native->token, op, data, options);
822 if (op_msg == NULL) {
829 rc = lrmd_send_xml(lrmd, op_msg, timeout, &op_reply);
831 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
836 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op, timeout, rc);
840 }
else if(op_reply == NULL) {
856 *output_data = op_reply;
861 if (lrmd_api_is_connected(lrmd) == FALSE) {
871 lrmd_api_poke_connection(
lrmd_t * lrmd)
894 value = g_hash_table_lookup(hash,
"stonith-watchdog-timeout");
904 lrmd_handshake(
lrmd_t * lrmd,
const char *name)
908 xmlNode *reply = NULL;
917 if (native->proxy_callback) {
921 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
924 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the lrmd API: %d", rc);
926 }
else if (reply == NULL) {
927 crm_err(
"Did not receive registration reply");
937 crm_err(
"LRMD protocol mismatch client version %s, server version %s",
942 crm_err(
"Invalid registration message: %s", msg_type);
945 }
else if (tmp_ticket == NULL) {
946 crm_err(
"No registration token provided");
950 crm_trace(
"Obtained registration token: %s", tmp_ticket);
951 native->token = strdup(tmp_ticket);
952 native->peer_version = strdup(version?version:
"1.0");
961 lrmd_api_disconnect(lrmd);
967 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
974 .destroy = lrmd_ipc_connection_destroy
984 }
else if (native->ipc) {
985 crm_perror(LOG_ERR,
"Connection to local resource manager failed");
993 if (native->ipc == NULL) {
994 crm_debug(
"Could not connect to the LRMD API");
1001 #ifdef HAVE_GNUTLS_GNUTLS_H
1003 set_key(gnutls_datum_t * key,
const char *location)
1008 int buf_len = read_len;
1009 static char *key_cache = NULL;
1010 static size_t key_cache_len = 0;
1011 static time_t key_cache_updated;
1013 if (location == NULL) {
1018 time_t now = time(NULL);
1020 if ((now - key_cache_updated) < 60) {
1021 key->data = gnutls_malloc(key_cache_len + 1);
1022 key->size = key_cache_len;
1023 memcpy(key->data, key_cache, key_cache_len);
1029 key_cache_updated = 0;
1036 stream = fopen(location,
"r");
1041 key->data = gnutls_malloc(read_len);
1042 while (!feof(stream)) {
1045 if (cur_len == buf_len) {
1046 buf_len = cur_len + read_len;
1047 key->data = gnutls_realloc(key->data, buf_len);
1049 next = fgetc(stream);
1050 if (next == EOF && feof(stream)) {
1054 key->data[cur_len] = next;
1059 key->size = cur_len;
1061 gnutls_free(key->data);
1067 key_cache = calloc(1, key->size + 1);
1068 memcpy(key_cache, key->data, key->size);
1070 key_cache_len = key->size;
1071 key_cache_updated = time(NULL);
1078 lrmd_tls_set_key(gnutls_datum_t * key)
1081 const char *specific_location = getenv(
"PCMK_authkey_location");
1083 if (set_key(key, specific_location) == 0) {
1084 crm_debug(
"Using custom authkey location %s", specific_location);
1087 }
else if (specific_location) {
1088 crm_err(
"No valid lrmd remote key found at %s, trying default location", specific_location);
1104 lrmd_gnutls_global_init(
void)
1106 static int gnutls_init = 0;
1109 crm_gnutls_global_init();
1116 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1120 if (native->callback) {
1123 event.remote_nodename = native->remote_nodename;
1124 event.connection_rc = rc;
1125 native->callback(&event);
1129 #ifdef HAVE_GNUTLS_GNUTLS_H
1131 lrmd_tcp_connect_cb(
void *userdata,
int sock)
1135 char name[256] = { 0, };
1138 .destroy = lrmd_tls_connection_destroy,
1141 gnutls_datum_t psk_key = { NULL, 0 };
1143 native->async_timer = 0;
1146 lrmd_tls_connection_destroy(lrmd);
1147 crm_info(
"remote lrmd connect to %s at port %d failed", native->server, native->port);
1148 report_async_connection_result(lrmd, rc);
1154 native->sock = sock;
1156 if (lrmd_tls_set_key(&psk_key) != 0) {
1157 lrmd_tls_connection_destroy(lrmd);
1161 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1163 gnutls_free(psk_key.data);
1168 crm_warn(
"Client tls handshake failed for server %s:%d. Disconnecting", native->server,
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);
1174 report_async_connection_result(lrmd, -1);
1178 crm_info(
"Remote lrmd client TLS connection established with server %s:%d", native->server,
1181 snprintf(name, 128,
"remote-lrmd-%s:%d", native->server, native->port);
1185 mainloop_add_fd(name, G_PRIORITY_HIGH, native->sock, lrmd, &lrmd_tls_callbacks);
1187 rc = lrmd_handshake(lrmd, name);
1188 report_async_connection_result(lrmd, rc);
1194 lrmd_tls_connect_async(
lrmd_t * lrmd,
int timeout )
1202 lrmd_gnutls_global_init();
1205 lrmd_tcp_connect_cb);
1208 native->sock = sock;
1210 native->async_timer = timer_id;
1217 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1221 .destroy = lrmd_tls_connection_destroy,
1226 gnutls_datum_t psk_key = { NULL, 0 };
1228 lrmd_gnutls_global_init();
1232 crm_warn(
"Could not establish remote lrmd connection to %s", native->server);
1233 lrmd_tls_connection_destroy(lrmd);
1237 native->sock = sock;
1239 if (lrmd_tls_set_key(&psk_key) != 0) {
1240 lrmd_tls_connection_destroy(lrmd);
1244 gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
1246 gnutls_free(psk_key.data);
1251 crm_err(
"Session creation for %s:%d failed", native->server, native->port);
1252 gnutls_deinit(*native->remote->tls_session);
1253 gnutls_free(native->remote->tls_session);
1254 native->remote->tls_session = NULL;
1255 lrmd_tls_connection_destroy(lrmd);
1259 crm_info(
"Remote lrmd client TLS connection established with server %s:%d", native->server,
1265 char name[256] = { 0, };
1266 snprintf(name, 128,
"remote-lrmd-%s:%d", native->server, native->port);
1270 mainloop_add_fd(name, G_PRIORITY_HIGH, native->sock, lrmd, &lrmd_tls_callbacks);
1277 lrmd_api_connect(
lrmd_t * lrmd,
const char *name,
int *fd)
1282 switch (native->type) {
1284 rc = lrmd_ipc_connect(lrmd, fd);
1286 #ifdef HAVE_GNUTLS_GNUTLS_H
1287 case CRM_CLIENT_TLS:
1288 rc = lrmd_tls_connect(lrmd, fd);
1292 crm_err(
"Unsupported connection type: %d", native->type);
1296 rc = lrmd_handshake(lrmd, name);
1303 lrmd_api_connect_async(
lrmd_t * lrmd,
const char *name,
int timeout)
1308 if (!native->callback) {
1309 crm_err(
"Async connect not possible, no lrmd client callback set.");
1313 switch (native->type) {
1317 rc = lrmd_api_connect(lrmd, name, NULL);
1319 report_async_connection_result(lrmd, rc);
1322 #ifdef HAVE_GNUTLS_GNUTLS_H
1323 case CRM_CLIENT_TLS:
1324 rc = lrmd_tls_connect_async(lrmd, timeout);
1327 report_async_connection_result(lrmd, rc);
1332 crm_err(
"Unsupported connection type: %d", native->type);
1339 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1343 if (native->source != NULL) {
1346 native->source = NULL;
1349 }
else if (native->ipc) {
1359 #ifdef HAVE_GNUTLS_GNUTLS_H
1361 lrmd_tls_disconnect(
lrmd_t * lrmd)
1365 if (native->remote->tls_session) {
1366 gnutls_bye(*native->remote->tls_session, GNUTLS_SHUT_RDWR);
1367 gnutls_deinit(*native->remote->tls_session);
1368 gnutls_free(native->remote->tls_session);
1369 native->remote->tls_session = 0;
1372 if (native->async_timer) {
1373 g_source_remove(native->async_timer);
1374 native->async_timer = 0;
1377 if (native->source != NULL) {
1380 native->source = NULL;
1382 }
else if (native->sock) {
1383 close(native->sock);
1387 if (native->pending_notify) {
1388 g_list_free_full(native->pending_notify, lrmd_free_xml);
1389 native->pending_notify = NULL;
1395 lrmd_api_disconnect(
lrmd_t * lrmd)
1399 crm_info(
"Disconnecting from %d lrmd service", native->type);
1400 switch (native->type) {
1402 lrmd_ipc_disconnect(lrmd);
1404 #ifdef HAVE_GNUTLS_GNUTLS_H
1405 case CRM_CLIENT_TLS:
1406 lrmd_tls_disconnect(lrmd);
1410 crm_err(
"Unsupported connection type: %d", native->type);
1413 free(native->token);
1414 native->token = NULL;
1416 free(native->peer_version);
1417 native->peer_version = NULL;
1422 lrmd_api_register_rsc(
lrmd_t * lrmd,
1428 xmlNode *data = NULL;
1430 if (!
class || !type || !rsc_id) {
1444 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_REG, data, NULL, 0, options, TRUE);
1471 copy->
id = strdup(rsc_info->
id);
1472 copy->
type = strdup(rsc_info->
type);
1488 free(rsc_info->
type);
1489 free(rsc_info->
class);
1499 xmlNode *output = NULL;
1500 const char *
class = NULL;
1501 const char *provider = NULL;
1502 const char *type = NULL;
1506 lrmd_send_command(lrmd,
LRMD_OP_RSC_INFO, data, &output, 0, options, TRUE);
1517 if (!
class || !type) {
1520 }
else if (
safe_str_eq(
class,
"ocf") && !provider) {
1526 rsc_info->
id = strdup(rsc_id);
1527 rsc_info->
class = strdup(
class);
1529 rsc_info->
provider = strdup(provider);
1531 rsc_info->
type = strdup(type);
1542 native->callback = callback;
1550 native->proxy_callback = callback;
1551 native->proxy_callback_userdata = userdata;
1555 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
1559 if (native->proxy_callback) {
1561 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
1574 return lrmd_send_xml_no_reply(lrmd, msg);
1578 stonith_get_metadata(
const char *provider,
const char *type,
char **output)
1585 stonith_api->
cmds->
free(stonith_api);
1587 if (*output == NULL) {
1593 #define lsb_metadata_template \
1594 "<?xml version='1.0'?>\n" \
1595 "<!DOCTYPE resource-agent SYSTEM 'ra-api-1.dtd'>\n" \
1596 "<resource-agent name='%s' version='0.1'>\n" \
1597 " <version>1.0</version>\n" \
1598 " <longdesc lang='en'>\n" \
1601 " <shortdesc lang='en'>%s</shortdesc>\n" \
1603 " </parameters>\n" \
1605 " <action name='meta-data' timeout='5' />\n" \
1606 " <action name='start' timeout='15' />\n" \
1607 " <action name='stop' timeout='15' />\n" \
1608 " <action name='status' timeout='15' />\n" \
1609 " <action name='restart' timeout='15' />\n" \
1610 " <action name='force-reload' timeout='15' />\n" \
1611 " <action name='monitor' timeout='15' interval='15' />\n" \
1613 " <special tag='LSB'>\n" \
1614 " <Provides>%s</Provides>\n" \
1615 " <Required-Start>%s</Required-Start>\n" \
1616 " <Required-Stop>%s</Required-Stop>\n" \
1617 " <Should-Start>%s</Should-Start>\n" \
1618 " <Should-Stop>%s</Should-Stop>\n" \
1619 " <Default-Start>%s</Default-Start>\n" \
1620 " <Default-Stop>%s</Default-Stop>\n" \
1622 "</resource-agent>\n"
1624 #define LSB_INITSCRIPT_INFOBEGIN_TAG "### BEGIN INIT INFO"
1625 #define LSB_INITSCRIPT_INFOEND_TAG "### END INIT INFO"
1626 #define PROVIDES "# Provides:"
1627 #define REQ_START "# Required-Start:"
1628 #define REQ_STOP "# Required-Stop:"
1629 #define SHLD_START "# Should-Start:"
1630 #define SHLD_STOP "# Should-Stop:"
1631 #define DFLT_START "# Default-Start:"
1632 #define DFLT_STOP "# Default-Stop:"
1633 #define SHORT_DSCR "# Short-Description:"
1634 #define DESCRIPTION "# Description:"
1636 #define lsb_meta_helper_free_value(m) \
1638 if ((m) != NULL) { \
1654 static inline gboolean
1655 lsb_meta_helper_get_value(
const char *line,
char **value,
const char *prefix)
1657 if (!*value && !strncasecmp(line, prefix, strlen(prefix))) {
1658 *value = (
char *)xmlEncodeEntitiesReentrant(NULL, BAD_CAST line+strlen(prefix));
1665 lsb_get_metadata(
const char *type,
char **output)
1667 char ra_pathname[PATH_MAX] = { 0, };
1670 char *provides = NULL;
1671 char *req_start = NULL;
1672 char *req_stop = NULL;
1673 char *shld_start = NULL;
1674 char *shld_stop = NULL;
1675 char *dflt_start = NULL;
1676 char *dflt_stop = NULL;
1677 char *s_dscrpt = NULL;
1678 char *xml_l_dscrpt = NULL;
1681 char description[max];
1683 if(type[0] ==
'/') {
1684 snprintf(ra_pathname,
sizeof(ra_pathname),
"%s", type);
1686 snprintf(ra_pathname,
sizeof(ra_pathname),
"%s/%s",
LSB_ROOT_DIR, type);
1689 crm_trace(
"Looking into %s", ra_pathname);
1690 if (!(fp = fopen(ra_pathname,
"r"))) {
1695 while (fgets(buffer,
sizeof(buffer), fp)) {
1698 if (lsb_meta_helper_get_value(buffer, &provides,
PROVIDES)) {
1701 if (lsb_meta_helper_get_value(buffer, &req_start,
REQ_START)) {
1704 if (lsb_meta_helper_get_value(buffer, &req_stop,
REQ_STOP)) {
1707 if (lsb_meta_helper_get_value(buffer, &shld_start,
SHLD_START)) {
1710 if (lsb_meta_helper_get_value(buffer, &shld_stop,
SHLD_STOP)) {
1713 if (lsb_meta_helper_get_value(buffer, &dflt_start,
DFLT_START)) {
1716 if (lsb_meta_helper_get_value(buffer, &dflt_stop,
DFLT_STOP)) {
1719 if (lsb_meta_helper_get_value(buffer, &s_dscrpt,
SHORT_DSCR)) {
1730 while (fgets(buffer,
sizeof(buffer), fp)) {
1731 if (!strncmp(buffer,
"# ", 3) || !strncmp(buffer,
"#\t", 2)) {
1733 offset += snprintf(description+offset, max-offset,
"%s", buffer);
1743 if (xml_l_dscrpt == NULL && offset > 0) {
1744 xml_l_dscrpt = (
char *)xmlEncodeEntitiesReentrant(NULL, BAD_CAST(description));
1751 if (buffer[0] !=
'#') {
1758 (xml_l_dscrpt == NULL) ? type : xml_l_dscrpt,
1759 (s_dscrpt == NULL) ? type : s_dscrpt, (provides == NULL) ?
"" : provides,
1760 (req_start == NULL) ?
"" : req_start, (req_stop == NULL) ?
"" : req_stop,
1761 (shld_start == NULL) ?
"" : shld_start, (shld_stop == NULL) ?
"" : shld_stop,
1762 (dflt_start == NULL) ?
"" : dflt_start, (dflt_stop == NULL) ?
"" : dflt_stop);
1774 crm_trace(
"Created fake metadata: %llu",
1775 (
unsigned long long) strlen(*output));
1781 nagios_get_metadata(
const char *type,
char **output)
1784 FILE *file_strm = NULL;
1785 int start = 0, length = 0, read_len = 0;
1786 char *metadata_file = NULL;
1790 len += strlen(type);
1791 metadata_file = calloc(1, len);
1792 CRM_CHECK(metadata_file != NULL,
return -ENOMEM);
1795 file_strm = fopen(metadata_file,
"r");
1796 if (file_strm == NULL) {
1797 crm_err(
"Metadata file %s does not exist", metadata_file);
1798 free(metadata_file);
1803 start = ftell(file_strm);
1804 fseek(file_strm, 0L, SEEK_END);
1805 length = ftell(file_strm);
1806 fseek(file_strm, 0L, start);
1812 crm_info(
"%s was not valid", metadata_file);
1818 crm_trace(
"Reading %d bytes from file", length);
1819 *output = calloc(1, (length + 1));
1820 read_len = fread(*output, 1, length, file_strm);
1821 if (read_len != length) {
1822 crm_err(
"Calculated and read bytes differ: %d vs. %d", length, read_len);
1830 free(metadata_file);
1835 #if SUPPORT_HEARTBEAT
1851 static const char hb_metadata_template[] =
1852 "<?xml version='1.0'?>\n"
1853 "<!DOCTYPE resource-agent SYSTEM 'ra-api-1.dtd'>\n"
1854 "<resource-agent name='%s' version='0.1'>\n"
1855 "<version>1.0</version>\n"
1856 "<longdesc lang='en'>\n"
1859 "<shortdesc lang='en'>%s</shortdesc>\n"
1861 "<parameter name='1' unique='1' required='0'>\n"
1862 "<longdesc lang='en'>\n"
1863 "This argument will be passed as the first argument to the "
1864 "heartbeat resource agent (assuming it supports one)\n"
1866 "<shortdesc lang='en'>argv[1]</shortdesc>\n"
1867 "<content type='string' default=' ' />\n"
1869 "<parameter name='2' unique='1' required='0'>\n"
1870 "<longdesc lang='en'>\n"
1871 "This argument will be passed as the second argument to the "
1872 "heartbeat resource agent (assuming it supports one)\n"
1874 "<shortdesc lang='en'>argv[2]</shortdesc>\n"
1875 "<content type='string' default=' ' />\n"
1877 "<parameter name='3' unique='1' required='0'>\n"
1878 "<longdesc lang='en'>\n"
1879 "This argument will be passed as the third argument to the "
1880 "heartbeat resource agent (assuming it supports one)\n"
1882 "<shortdesc lang='en'>argv[3]</shortdesc>\n"
1883 "<content type='string' default=' ' />\n"
1885 "<parameter name='4' unique='1' required='0'>\n"
1886 "<longdesc lang='en'>\n"
1887 "This argument will be passed as the fourth argument to the "
1888 "heartbeat resource agent (assuming it supports one)\n"
1890 "<shortdesc lang='en'>argv[4]</shortdesc>\n"
1891 "<content type='string' default=' ' />\n"
1893 "<parameter name='5' unique='1' required='0'>\n"
1894 "<longdesc lang='en'>\n"
1895 "This argument will be passed as the fifth argument to the "
1896 "heartbeat resource agent (assuming it supports one)\n"
1898 "<shortdesc lang='en'>argv[5]</shortdesc>\n"
1899 "<content type='string' default=' ' />\n"
1903 "<action name='start' timeout='15' />\n"
1904 "<action name='stop' timeout='15' />\n"
1905 "<action name='status' timeout='15' />\n"
1906 "<action name='monitor' timeout='15' interval='15' start-delay='15' />\n"
1907 "<action name='meta-data' timeout='5' />\n"
1909 "<special tag='heartbeat'>\n"
1911 "</resource-agent>\n";
1914 heartbeat_get_metadata(
const char *type,
char **output)
1917 crm_trace(
"Created fake metadata: %llu",
1918 (
unsigned long long) strlen(*output));
1924 generic_get_metadata(
const char *standard,
const char *provider,
const char *type,
char **output)
1929 "meta-data", 0, 30000, NULL, 0);
1930 if (action == NULL) {
1931 crm_err(
"Unable to retrieve meta-data for %s:%s:%s", standard, provider, type);
1937 crm_err(
"Failed to retrieve meta-data for %s:%s:%s", standard, provider, type);
1943 crm_err(
"Failed to receive meta-data for %s:%s:%s", standard, provider, type);
1955 lrmd_api_get_metadata(
lrmd_t * lrmd,
1957 const char *provider,
1960 if (!
class || !type) {
1965 class = resources_find_service_class(type);
1969 return stonith_get_metadata(provider, type, output);
1971 return lsb_get_metadata(type, output);
1974 return nagios_get_metadata(type, output);
1976 #if SUPPORT_HEARTBEAT
1978 return heartbeat_get_metadata(type, output);
1981 return generic_get_metadata(
class, provider, type, output);
1985 lrmd_api_exec(
lrmd_t * lrmd,
const char *rsc_id,
const char *action,
const char *userdata,
int interval,
2003 for (tmp = params; tmp; tmp = tmp->
next) {
2007 rc = lrmd_send_command(lrmd,
LRMD_OP_RSC_EXEC, data, NULL, timeout, options, TRUE);
2015 lrmd_api_cancel(
lrmd_t * lrmd,
const char *rsc_id,
const char *action,
int interval)
2039 stonith_api->
cmds->
free(stonith_api);
2042 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2045 *resources = lrmd_list_add(*resources, dIter->
value);
2054 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2055 const char *provider)
2060 rc += list_stonith_agents(resources);
2066 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2067 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2070 g_list_free_full(agents, free);
2073 rc += list_stonith_agents(resources);
2078 crm_notice(
"No agents found for class %s",
class);
2079 rc = -EPROTONOSUPPORT;
2085 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2088 GList *agents = NULL;
2092 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2097 g_list_free_full(agents, free);
2103 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2106 char *provider = NULL;
2107 GList *ocf_providers = NULL;
2112 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2113 provider = gIter->data;
2114 if (!agent || does_provider_have_agent(agent, provider,
"ocf")) {
2115 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2120 g_list_free_full(ocf_providers, free);
2128 GList *standards = NULL;
2133 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2134 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2138 if (list_stonith_agents(NULL) > 0) {
2139 *supported = lrmd_list_add(*supported,
"stonith");
2143 g_list_free_full(standards, free);
2153 new_lrmd = calloc(1,
sizeof(
lrmd_t));
2171 new_lrmd->
cmds->
exec = lrmd_api_exec;
2183 #ifdef HAVE_GNUTLS_GNUTLS_H
2187 if (!nodename && !server) {
2192 native->type = CRM_CLIENT_TLS;
2193 native->remote_nodename = nodename ? strdup(nodename) : strdup(server);
2194 native->server = server ? strdup(server) : strdup(nodename);
2195 native->port = port;
2196 if (native->port == 0) {
2197 const char *remote_port_str = getenv(
"PCMK_remote_port");
2203 crm_err(
"GNUTLS is not enabled for this build, remote LRMD client can not be created");
2220 #ifdef HAVE_GNUTLS_GNUTLS_H
2221 free(native->server);
2223 free(native->remote_nodename);
2224 free(native->remote);
2225 free(native->token);
2226 free(native->peer_version);
#define CRM_CHECK(expr, failure_action)
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
#define crm_notice(fmt, args...)
GHashTable * xml2list(xmlNode *parent)
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
gboolean safe_str_neq(const char *a, const char *b)
void services_action_free(svc_action_t *op)
int crm_remote_ready(crm_remote_t *remote, int total_timeout)
gboolean crm_remote_recv(crm_remote_t *remote, int total_timeout, int *disconnected)
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, int interval)
Cancel a recurring command.
int(* metadata)(stonith_t *st, int options, const char *device, const char *namespace, char **output, int timeout)
Get the metadata documentation for a resource.
#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(* exec)(lrmd_t *lrmd, const char *rsc_id, const char *action, const char *userdata, int interval, int timeout, int start_delay, enum lrmd_call_options options, lrmd_key_value_t *params)
Issue a command on a resource.
#define F_LRMD_RSC_OUTPUT
int(* poke_connection)(lrmd_t *lrmd)
Poke lrmd connection to verify it is still capable of serving requests.
void(* set_callback)(lrmd_t *lrmd, lrmd_event_callback callback)
Sets the callback to receive lrmd events on.
int(* is_connected)(lrmd_t *lrmd)
Is connected to lrmd daemon?
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, int interval, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
struct stonith_key_value_s * next
void lrmd_key_value_freeall(lrmd_key_value_t *head)
struct mainloop_io_s mainloop_io_t
void mainloop_set_trigger(crm_trigger_t *source)
#define DEFAULT_REMOTE_USERNAME
#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)
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
long crm_ipc_read(crm_ipc_t *client)
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
int crm_remote_tcp_connect(const char *host, int port)
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 remote lrmd connection using tls backend.
stonith_t * stonith_api_new(void)
xmlNode * string2xml(const char *input)
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the lrmd.
const char * crm_ipc_buffer(crm_ipc_t *client)
int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash)
#define LRMD_OP_RSC_UNREG
#define DEFAULT_REMOTE_PORT
#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.
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
struct lrmd_private_s lrmd_private_t
#define crm_warn(fmt, args...)
#define crm_debug(fmt, args...)
int crm_initiate_client_tls_handshake(crm_remote_t *remote, int timeout_ms)
#define lsb_metadata_template
struct crm_ipc_s crm_ipc_t
#define F_LRMD_RSC_EXIT_REASON
int(* get_metadata)(lrmd_t *lrmd, const char *class, const char *provider, const char *agent, char **output, enum lrmd_call_options options)
Get the metadata documentation for a resource.
#define ALT_REMOTE_KEY_LOCATION
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
struct lrmd_list_s * next
gboolean services_action_sync(svc_action_t *op)
#define LRMD_PROTOCOL_VERSION
xmlNode * crm_remote_parse_buffer(crm_remote_t *remote)
void lrmd_list_freeall(lrmd_list_t *head)
#define crm_trace(fmt, args...)
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
#define LRMD_OP_NEW_CLIENT
xmlNode * create_xml_node(xmlNode *parent, const char *name)
int crm_element_value_int(xmlNode *data, const char *name, int *dest)
const char * crm_element_value(xmlNode *data, const char *name)
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
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.
lrmd_t * lrmd_api_new(void)
Create a new local lrmd connection.
#define LSB_INITSCRIPT_INFOEND_TAG
struct lrmd_key_value_s * next
#define F_LRMD_RSC_USERDATA_STR
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void free_xml(xmlNode *child)
#define F_LRMD_RSC_INTERVAL
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
int crm_remote_tcp_connect_async(const char *host, int port, int timeout, int *timer_id, void *userdata, void(*callback)(void *userdata, int sock))
CRM_TRACE_INIT_DATA(lrmd)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
int(* connect_async)(lrmd_t *lrmd, const char *client_name, int timeout)
Establish an connection to lrmd, don't block while connecting.
#define F_LRMD_RSC_START_DELAY
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.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
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 lsb_meta_helper_free_value(m)
#define crm_log_xml_err(xml, text)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy lrmd object.
#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 from the lrmd.
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)
#define crm_err(fmt, args...)
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)
int(* list_agents)(lrmd_t *lrmd, lrmd_list_t **agents, const char *class, const char *provider)
Retrieve a list of installed resource agents.
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 lrmd.
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
void * create_psk_tls_session(int csock, int type, void *credentials)
#define F_LRMD_RSC_RUN_TIME
void lrmd_internal_set_proxy_callback(lrmd_t *lrmd, void *userdata, void(*callback)(lrmd_t *lrmd, void *userdata, xmlNode *msg))
#define crm_log_xml_trace(xml, text)
#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
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
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
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void lrmd_free_event(lrmd_event_data_t *event)
int(* register_rsc)(lrmd_t *lrmd, const char *rsc_id, const char *class, const char *provider, const char *agent, enum lrmd_call_options options)
Register a resource with the lrmd.
#define F_LRMD_REMOTE_MSG_TYPE
void crm_ipc_close(crm_ipc_t *client)
int crm_remote_send(crm_remote_t *remote, xmlNode *msg)
#define crm_info(fmt, args...)
#define NAGIOS_METADATA_DIR
void g_hash_destroy_str(gpointer data)
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.
enum crm_ais_msg_types type