示例#1
0
// Authenticate connection and request the info of a particular sockaddr_in.
// Return 0 on success.
int
citrusleaf_info_host_auth(as_cluster* cluster, struct sockaddr_in *sa_in, char *names, char **values, int timeout_ms, bool send_asis, bool check_bounds)
{
	int fd = cf_socket_create_and_connect_nb(sa_in);
	
	if (fd == -1) {
		return CITRUSLEAF_FAIL_UNAVAILABLE;
	}
	
	if (cluster->user) {
		int status = as_authenticate(fd, cluster->user, cluster->password, timeout_ms);
		
		if (status) {
			cf_error("Authentication failed for %s", cluster->user);
			cf_close(fd);
			return status;
		}
	}
	
	int rv = citrusleaf_info_host_limit(fd, names, values, timeout_ms, send_asis, 0, check_bounds);
	shutdown(fd, SHUT_RDWR);
	cf_close(fd);
	
	if (rv == 0 && strncmp(*values, "security error", 14) == 0) {
		cf_error("%s", *values);
		free(*values);
		return CITRUSLEAF_NOT_AUTHENTICATED;
	}
	return rv;
}
示例#2
0
static int
as_node_authenticate_connection(as_node* node, int* fd)
{
	as_cluster* cluster = node->cluster;
	
	if (cluster->user) {
		int status = as_authenticate(*fd, cluster->user, cluster->password, cluster->conn_timeout_ms);
		
		if (status) {
			cf_debug("Authentication failed for %s", cluster->user);
			cf_close(*fd);
			*fd = -1;
			return status;
		}
	}
	return 0;
}
示例#3
0
/**
 * Parse errors returned from Last.fm and adjust the status if applicable
 */
static void as_parse_error(char *response)
{
	gchar *tmp, *message;
	gushort code;

	tmp = strstr(response, "<error code=\"") + 13;
	code = g_ascii_strtoll(tmp, NULL, 0);

	switch(code) {
		case 4:
			as_conn.status = BADAUTH;
			break;
		case 9:
			as_authenticate();
			break;
		default:
			break;
	}

	tmp = strstr(tmp, "\">") + 2;
	message = g_strndup(tmp, strcspn(tmp, "<"));
	g_warning("%s", message);
	g_free(message);
}
示例#4
0
文件: scmpc.c 项目: theVDude/scmpc
int main(int argc, char *argv[])
{
	pid_t pid;
	struct sigaction sa;

	if (init_preferences(argc, argv) == FALSE)
		g_error("Config file parsing failed");

	/* Open the log file before forking, so that if there is an error, the
	 * user will get some idea what is going on */
	open_log(prefs.log_file);

	g_log_set_default_handler(scmpc_log, NULL);

	/* Check if scmpc is already running */
	if ((pid = scmpc_is_running()) > 0) {
		clear_preferences();
		g_error("Daemon is already running with PID: %ld", (long)pid);
	}

	/* Daemonise if wanted */
	if (prefs.fork)
		daemonise();

	/* Signal handler */
	open_signal_pipe();
	sa.sa_handler = sighandler;
	sigfillset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);

	if (as_connection_init() == FALSE) {
		scmpc_cleanup();
		exit(EXIT_FAILURE);
	}
	as_authenticate();

	queue_init();
	queue_load();

	// submit the loaded queue
	as_check_submit();

	mpd.song_pos = g_timer_new();
	mpd.idle_source = 0;
	if (!mpd_connect()) {
		mpd_disconnect();
		mpd_schedule_reconnect();
	}

	// set up main loop events
	loop = g_main_loop_new(NULL, FALSE);

	// save queue
	if (prefs.cache_interval > 0) {
		cache_save_source = g_timeout_add_seconds(prefs.cache_interval * 60,
				queue_save, NULL);
	}

	g_main_loop_run(loop);

	scmpc_cleanup();
}