Exemplo n.º 1
0
IPC_Channel *
init_client_ipc_comms_nodispatch(const char *channel_name)
{
	IPC_Channel *ch;
	GHashTable  *attrs;
	static char  path[] = IPC_PATH_ATTR;

	char *commpath = NULL;
	int local_socket_len = 2; /* 2 = '/' + '\0' */

	local_socket_len += strlen(channel_name);
	local_socket_len += strlen(CRM_STATE_DIR);

	crm_malloc0(commpath, local_socket_len);

	sprintf(commpath, CRM_STATE_DIR "/%s", channel_name);
	commpath[local_socket_len - 1] = '\0';
	crm_debug("Attempting to talk on: %s", commpath);
	
	attrs = g_hash_table_new(g_str_hash,g_str_equal);
	g_hash_table_insert(attrs, path, commpath);

	ch = ipc_channel_constructor(IPC_ANYTYPE, attrs);
	g_hash_table_destroy(attrs);

	if (ch == NULL) {
		crm_err("Could not access channel on: %s", commpath);
		crm_free(commpath);
		return NULL;
		
	} else if (ch->ops->initiate_connection(ch) != IPC_OK) {
		crm_debug("Could not init comms on: %s", commpath);
		ch->ops->destroy(ch);
		crm_free(commpath);
		return NULL;
	}

	ch->ops->set_recv_qlen(ch, 512);
	ch->ops->set_send_qlen(ch, 512);
 	ch->should_send_block = TRUE;

	crm_debug_3("Processing of %s complete", commpath);

	crm_free(commpath);
	return ch;
}
Exemplo n.º 2
0
static IPC_Channel* 
create_logging_channel(void)
{
	GHashTable*	attrs;
	char		path[] = IPC_PATH_ATTR;
	char		sockpath[] = HA_LOGDAEMON_IPC;	
	IPC_Channel*	chan;
	static gboolean	complained_yet = FALSE;
	
	attrs = g_hash_table_new(g_str_hash, g_str_equal);
	g_hash_table_insert(attrs, path, sockpath);	

	chan =ipc_channel_constructor(IPC_ANYTYPE, attrs);       	
	
	g_hash_table_destroy(attrs);	
	
	if (chan == NULL) {
		cl_log(LOG_ERR, "create_logging_channel:"
		       "contructing ipc channel failed");
		return NULL;
	}
			
	if (chan->ops->initiate_connection(chan) != IPC_OK) {
		if (!complained_yet) {
			complained_yet = TRUE;
			cl_log(LOG_WARNING, "Initializing connection"
			       " to logging daemon failed."
			       " Logging daemon may not be running");
		}
		if (!logging_chan_in_main_loop){
			chan->ops->destroy(chan);
		}
		
		return NULL;
	}
	complained_yet = FALSE;

	if (create_logging_channel_callback){
		create_logging_channel_callback(chan);
	}		
	
	
	return chan;
	
}
Exemplo n.º 3
0
int
stonithd_signon(const char * client_name)
{
	int     rc = ST_FAIL;
	char	path[] = IPC_PATH_ATTR;
	char	sock[] = STONITHD_SOCK;
	char	cbsock[] = STONITHD_CALLBACK_SOCK;
	struct  ha_msg * request;
	struct  ha_msg * reply;
	GHashTable *	 wchanattrs;
	uid_t	my_euid;
	gid_t	my_egid;
	const char * tmpstr;
	int 	rc_tmp;
	gboolean connected = TRUE;
 	cl_uuid_t cookie, *cptr = NULL;

	if (chan == NULL || chan->ch_status != IPC_CONNECT) {
	    connected = FALSE;
	} else if (cbchan == NULL || cbchan->ch_status != IPC_CONNECT) {
	    connected = FALSE;
	}

	if(!connected) {
		/* cleanup */
		if (NULL != chan) {
		    chan->ops->destroy(chan);
		    chan = NULL;
		}
		if (NULL != cbchan) {
		    cbchan->ops->destroy(cbchan);
		    cbchan = NULL;
		}
		stdlib_log(LOG_DEBUG, "stonithd_signon: creating connection");
		wchanattrs = g_hash_table_new(g_str_hash, g_str_equal);
        	g_hash_table_insert(wchanattrs, path, sock);
		/* Connect to the stonith deamon */
		chan = ipc_channel_constructor(IPC_ANYTYPE, wchanattrs);
		g_hash_table_destroy(wchanattrs);
	
		if (chan == NULL) {
			stdlib_log(LOG_ERR, "stonithd_signon: Can't connect "
				   " to stonithd");
			rc = ST_FAIL;
			goto end;
		}

	        if (chan->ops->initiate_connection(chan) != IPC_OK) {
			stdlib_log(LOG_ERR, "stonithd_signon: Can't initiate "
				   "connection to stonithd");
			rc = ST_FAIL;
			goto end;
       		}
	}

	CLIENT_PID = getpid();
	snprintf(CLIENT_PID_STR, sizeof(CLIENT_PID_STR), "%d", CLIENT_PID);
	if ( client_name != NULL ) {
		CLIENT_NAME = client_name;
	} else {
		CLIENT_NAME = CLIENT_PID_STR;
	}

	if ( (request = create_basic_reqmsg_fields(ST_SIGNON)) == NULL) {
		rc = ST_FAIL;
		goto end;
	}

	/* important error check client name length */
	my_euid = geteuid();
	my_egid = getegid();
	if (  (	ha_msg_add_int(request, F_STONITHD_CEUID, my_euid) != HA_OK )
	    ||(	ha_msg_add_int(request, F_STONITHD_CEGID, my_egid) != HA_OK )
	    ||( ha_msg_add(request, F_STONITHD_COOKIE, "") != HA_OK )
	   ) {
		stdlib_log(LOG_ERR, "stonithd_signon: "
			   "cannot add field to ha_msg.");
		ZAPMSG(request);
		rc = ST_FAIL;
		goto end;
	}

	stdlib_log(LOG_DEBUG, "sending out the signon msg.");
	/* Send the registration request message */
	if (msg2ipcchan(request, chan) != HA_OK) {
		ZAPMSG(request);
		stdlib_log(LOG_ERR, "can't send signon message to IPC");
		rc = ST_FAIL;
		goto end;
	}

	/* waiting for the output to finish */
	do { 
		rc_tmp= chan_waitout_timeout(chan, DEFAULT_TIMEOUT);
	} while (rc_tmp == IPC_INTR);

	ZAPMSG(request);
	if (IPC_OK != rc_tmp) {
		stdlib_log(LOG_ERR, "%s:%d: waitout failed."
			   , __FUNCTION__, __LINE__);
		rc = ST_FAIL;
		goto end;
	}

	/* Read the reply... */
        if ( IPC_OK != chan_waitin_timeout(chan, DEFAULT_TIMEOUT) ) {
		stdlib_log(LOG_ERR, "%s:%d: waitin failed."
			   , __FUNCTION__, __LINE__);
		rc = ST_FAIL;
		goto end;
	}

	if ( (reply = msgfromIPC_noauth(chan)) == NULL ) {
		stdlib_log(LOG_ERR, "stonithd_signon: failed to fetch reply.");
		rc = ST_FAIL;
		goto end;
	}
	
	if ( TRUE == is_expected_msg(reply, F_STONITHD_TYPE, ST_APIRPL, 
			     F_STONITHD_APIRPL, ST_RSIGNON, TRUE) ) {
		if ( ((tmpstr=cl_get_string(reply, F_STONITHD_APIRET)) != NULL)
	   	    && (STRNCMP_CONST(tmpstr, ST_APIOK) == 0) ) {
			rc = ST_OK;
			stdlib_log(LOG_DEBUG, "signed on to stonithd.");
			/* get cookie if any */
			if( cl_get_uuid(reply, F_STONITHD_COOKIE, &cookie) == HA_OK ) {
				cptr = &cookie;
			}
		} else {
			stdlib_log(LOG_WARNING, "failed to signon to the "
				   "stonithd.");
		}
	} else {
		stdlib_log(LOG_ERR, "stonithd_signon: "
			   "Got an unexpected message.");
	}
	ZAPMSG(reply);

	if (ST_OK != rc) { /* Something wrong when try to sign on to stonithd */
		goto end;
	}

	/* Connect to the stonith deamon via callback channel */
	wchanattrs = g_hash_table_new(g_str_hash, g_str_equal);
        g_hash_table_insert(wchanattrs, path, cbsock);
	cbchan = ipc_channel_constructor(IPC_ANYTYPE, wchanattrs);
	g_hash_table_destroy(wchanattrs);

	if (cbchan == NULL) {
		stdlib_log(LOG_ERR, "stonithd_signon: Can't construct "
			   "callback channel to stonithd.");
		rc = ST_FAIL;
		goto end;
	}

        if (cbchan->ops->initiate_connection(cbchan) != IPC_OK) {
		stdlib_log(LOG_ERR, "stonithd_signon: Can't initiate "
			   "connection with the callback channel");
		rc = ST_FAIL;
		goto end;
 	}

	if ( (reply = msgfromIPC_noauth(cbchan)) == NULL ) {
		stdlib_log(LOG_ERR, "%s:%d: failed to fetch reply via the "
			   " callback channel"
			   , __FUNCTION__, __LINE__);
		rc = ST_FAIL;
		goto end;
	}
	
	if ( TRUE == is_expected_msg(reply, F_STONITHD_TYPE, ST_APIRPL, 
			     F_STONITHD_APIRPL, ST_RSIGNON, TRUE) ) {
		tmpstr=cl_get_string(reply, F_STONITHD_APIRET);
		if ( !STRNCMP_CONST(tmpstr, ST_APIOK) ) {
			/* 
			 * If the server directly authenticates us (probably 
			 * via pid-auth), go ahead.
			 */
			stdlib_log(LOG_DEBUG, "%s:%d: Got a good signon reply "
				  "via the callback channel."
				   , __FUNCTION__, __LINE__);
		} else if ( !STRNCMP_CONST(tmpstr, ST_COOKIE) ) {
			/*
			 * If the server asks for a cookie to identify myself,
			 * initiate cookie authentication.
			 */
			if (cptr == NULL) {
				stdlib_log(LOG_ERR, "server requested cookie auth on "
					"the callback channel, but it didn't "
					"provide the cookie on the main channel.");
				rc = ST_FAIL;
			} else {
				rc = authenticate_with_cookie(cbchan, cptr);
			}
		} else {
			/* Unknown response. */
			rc = ST_FAIL;
			stdlib_log(LOG_ERR, "%s:%d: Got a bad signon reply "
				  "via the callback channel."
				   , __FUNCTION__, __LINE__);
		}
	} else {
		rc = ST_FAIL;
		stdlib_log(LOG_ERR, "stonithd_signon: "
			   "Got an unexpected message via the callback chan.");
	}
	ZAPMSG(reply);

end:
	if (ST_OK != rc) {
		/* Something wrong when confirm via callback channel */
		stonithd_signoff();
	}

	return rc;
}