19 #include <sys/socket.h> 31 #ifdef HAVE_GNUTLS_GNUTLS_H 33 # include <gnutls/gnutls.h> 34 gnutls_anon_client_credentials_t anon_cred_c;
36 #define TLS_HANDSHAKE_TIMEOUT_MS 5000 38 const int kx_prio[] = {
43 static gboolean remote_gnutls_credentials_init = FALSE;
48 #include <arpa/inet.h> 52 typedef struct cib_remote_opaque_s {
74 xmlNode *
data, xmlNode ** output_data,
int call_options,
78 cib_remote_inputfd(
cib_t * cib)
82 return private->callback.tcp_socket;
86 cib_remote_set_connection_dnotify(
cib_t * cib,
void (*dnotify) (gpointer user_data))
88 return -EPROTONOSUPPORT;
92 cib_remote_register_notification(
cib_t * cib,
const char *callback,
int enabled)
106 cib_remote_new(
const char *server,
const char *user,
const char *passwd,
int port,
118 if (
private == NULL) {
127 private->server = strdup(server);
131 private->user = strdup(user);
135 private->passwd = strdup(passwd);
138 private->port = port;
139 private->encrypted = encrypted;
155 cib_tls_close(
cib_t * cib)
159 #ifdef HAVE_GNUTLS_GNUTLS_H 160 if (private->encrypted) {
161 if (private->command.tls_session) {
162 gnutls_bye(*(private->command.tls_session), GNUTLS_SHUT_RDWR);
163 gnutls_deinit(*(private->command.tls_session));
164 gnutls_free(private->command.tls_session);
167 if (private->callback.tls_session) {
168 gnutls_bye(*(private->callback.tls_session), GNUTLS_SHUT_RDWR);
169 gnutls_deinit(*(private->callback.tls_session));
170 gnutls_free(private->callback.tls_session);
172 private->command.tls_session = NULL;
173 private->callback.tls_session = NULL;
174 if (remote_gnutls_credentials_init) {
175 gnutls_anon_free_client_credentials(anon_cred_c);
176 gnutls_global_deinit();
177 remote_gnutls_credentials_init = FALSE;
182 if (private->command.tcp_socket) {
183 shutdown(private->command.tcp_socket, SHUT_RDWR);
184 close(private->command.tcp_socket);
186 if (private->callback.tcp_socket) {
187 shutdown(private->callback.tcp_socket, SHUT_RDWR);
188 close(private->callback.tcp_socket);
190 private->command.tcp_socket = 0;
191 private->callback.tcp_socket = 0;
193 free(private->command.buffer);
194 free(private->callback.buffer);
195 private->command.buffer = NULL;
196 private->callback.buffer = NULL;
207 xmlNode *answer = NULL;
208 xmlNode *login = NULL;
217 #ifdef HAVE_GNUTLS_GNUTLS_H 218 connection->tls_session = NULL;
223 crm_info(
"Remote connection to %s:%d failed: %s " CRM_XS " rc=%d",
228 if (private->encrypted) {
230 #ifdef HAVE_GNUTLS_GNUTLS_H 231 if (remote_gnutls_credentials_init == FALSE) {
232 crm_gnutls_global_init();
233 gnutls_anon_allocate_client_credentials(&anon_cred_c);
234 remote_gnutls_credentials_init = TRUE;
238 connection->tls_session = pcmk__new_tls_session(connection->
tcp_socket,
242 if (connection->tls_session == NULL) {
247 if (pcmk__tls_client_handshake(connection, TLS_HANDSHAKE_TIMEOUT_MS)
249 crm_err(
"Session creation for %s:%d failed", private->server, private->port);
251 gnutls_deinit(*connection->tls_session);
252 gnutls_free(connection->tls_session);
253 connection->tls_session = NULL;
258 return -EPROTONOSUPPORT;
280 if (answer == NULL) {
289 crm_err(
"Invalid registration message: %s", msg_type);
292 }
else if (tmp_ticket == NULL) {
296 connection->
token = strdup(tmp_ticket);
307 crm_trace(
"remote client connection established");
317 crm_err(
"Connection destroyed");
318 #ifdef HAVE_GNUTLS_GNUTLS_H 319 cib_tls_close(user_data);
328 cib_t *cib = user_data;
333 free(private->command.buffer);
334 private->command.buffer = NULL;
335 crm_err(
"received late reply for remote cib connection, discarding");
337 if (
rc == ENOTCONN) {
347 cib_t *cib = user_data;
352 crm_info(
"Message on callback channel");
376 if (
rc == ENOTCONN) {
389 if (private->passwd == NULL) {
390 if (private->out == NULL) {
396 private->out->prompt(
"Password",
false, &(private->passwd));
400 if (private->server == NULL || private->user == NULL) {
405 rc = cib_tls_signon(cib, &(private->command), FALSE);
409 rc = cib_tls_signon(cib, &(private->callback), TRUE);
421 crm_info(
"Opened connection to %s:%d for %s",
422 private->server, private->port,
name);
427 crm_info(
"Connection to %s:%d for %s failed: %s\n",
441 crm_debug(
"Disconnecting from the CIB manager");
442 #ifdef HAVE_GNUTLS_GNUTLS_H 463 free(private->server);
465 free(private->passwd);
477 xmlNode *
data, xmlNode ** output_data,
int call_options,
const char *
name)
480 int remaining_time = 0;
483 xmlNode *op_msg = NULL;
484 xmlNode *op_reply = NULL;
492 if (output_data != NULL) {
497 crm_err(
"No operation specified");
509 if (op_msg == NULL) {
513 crm_trace(
"Sending %s message to the CIB manager", op);
529 crm_trace(
"Waiting for a synchronous reply");
531 start_time = time(NULL);
535 while (remaining_time > 0 && (
rc != ENOTCONN)) {
540 remaining_time * 1000);
549 if (reply_id == msg_id) {
552 }
else if (reply_id < msg_id) {
553 crm_debug(
"Received old reply: %d (wanted %d)", reply_id, msg_id);
556 }
else if ((reply_id - 10000) > msg_id) {
558 crm_debug(
"Received old reply: %d (wanted %d)", reply_id, msg_id);
561 crm_err(
"Received a __future__ reply:" " %d (wanted %d)", reply_id, msg_id);
568 remaining_time = time(NULL) - start_time;
577 if (
rc == ENOTCONN) {
578 crm_err(
"Disconnected while waiting for reply.");
580 }
else if (op_reply == NULL) {
581 crm_err(
"No reply message - empty");
606 if (output_data == NULL) {
void cib__set_output(cib_t *cib, pcmk__output_t *out)
int pcmk__remote_send_xml(pcmk__remote_t *remote, xmlNode *msg)
xmlNode * get_message_xml(xmlNode *msg, const char *field)
const char * pcmk_strerror(int rc)
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
void cib_remote_connection_destroy(gpointer user_data)
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
void(* destroy)(gpointer userdata)
Destroy function for mainloop file descriptor client data.
int(* signoff)(cib_t *cib)
int cib_remote_command_dispatch(gpointer user_data)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
int(* inputfd)(cib_t *cib)
enum crm_ais_msg_types type
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Wrappers for and extensions to glib mainloop.
#define F_CIB_NOTIFY_ACTIVATE
xmlNode * cib_create_op(int call_id, const char *token, const char *op, const char *host, const char *section, xmlNode *data, int call_options, const char *user_name)
void cib_native_notify(gpointer data, gpointer user_data)
xmlNode * copy_xml(xmlNode *src_node)
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
cib_t * cib_new_variant(void)
int(* set_connection_dnotify)(cib_t *cib, void(*dnotify)(gpointer user_data))
#define crm_warn(fmt, args...)
Formatted output for pacemaker tools.
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
int cib_remote_callback_dispatch(gpointer user_data)
int(* signon)(cib_t *cib, const char *name, enum cib_conn_type type)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define crm_trace(fmt, args...)
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))
#define crm_log_xml_debug(xml, text)
struct cib_remote_opaque_s cib_remote_opaque_t
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
int cib_remote_free(cib_t *cib)
void free_xml(xmlNode *child)
int(* register_notification)(cib_t *cib, const char *callback, int enabled)
#define F_CIB_NOTIFY_TYPE
#define pcmk_err_diff_resync
#define crm_err(fmt, args...)
This structure contains everything that makes up a single output formatter.
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
#define crm_log_xml_trace(xml, text)
int cib_remote_perform_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *name)
int cib_remote_signoff(cib_t *cib)
int pcmk__read_remote_message(pcmk__remote_t *remote, int timeout_ms)
cib_t * cib_remote_new(const char *server, const char *user, const char *passwd, int port, gboolean encrypted)
#define crm_info(fmt, args...)
xmlNode * pcmk__remote_message_xml(pcmk__remote_t *remote)
int cib_remote_signon(cib_t *cib, const char *name, enum cib_conn_type type)