Esempio n. 1
0
THREAD_RV THREAD_CC
admin_thread(void* param)
{
	int server = g_create_unix_socket(MANAGEMENT_SOCKET_NAME);
	g_chmod_hex(MANAGEMENT_SOCKET_NAME, 0xFFFF);

	log_message(&(g_cfg->log), LOG_LEVEL_INFO, "sesman[admin_thread]: "
			"Create pool thread");
	pool = thread_pool_init_pool(g_cfg->sess.management_thread_count);

	log_message(&(g_cfg->log), LOG_LEVEL_INFO, "sesman[admin_thread]: "
			"Start pool thread");
	thread_pool_start_pool_thread(pool, thread_routine);

	xmlInitParser();
	while(1)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[admin_thread]: "
				"wait connection");
		int client = g_wait_connection(server);
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"New client connection [%i]",client);

		if (client < 0)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
					"Unable to get client from management socket [%s]", strerror(g_get_errno()));
			continue;
		}

		thread_pool_push_job(pool, client);
	}
}
Esempio n. 2
0
void DEFAULT_CC
printerd_main_loop()
{
	int server = g_create_unix_socket(PRINTER_SOCKET_NAME);
	g_chmod_hex(PRINTER_SOCKET_NAME, 0xFFFF);

	log_message(l_config, LOG_LEVEL_INFO, "xrdp_printer[printer_main_loop]: "
					"Create pool thread [%i]", thread_count);
	pool = thread_pool_init_pool(thread_count);

	log_message(l_config, LOG_LEVEL_INFO, "xrdp_printer[printer_main_loop]: "
					"Start pool thread");
	thread_pool_start_pool_thread(pool, thread_routine);

	xmlInitParser();
	printer_purge_all();
	while (stop == 0)
	{
		log_message(l_config, LOG_LEVEL_DEBUG, "xrdp_printer[printer_main_loop]: "
			"wait connection");
		int client = g_wait_connection(server);
		log_message(l_config, LOG_LEVEL_DEBUG_PLUS, "xrdp_printer[printer_main_loop]: "
			"New client connection [%i]",client);

		if (client < 0)
		{
			log_message(l_config, LOG_LEVEL_WARNING, "xrdp_printer[printer_main_loop]: "
				"Unable to get client from management socket [%s]", strerror(g_get_errno()));
			continue;
		}

		thread_pool_push_job(pool, client);
	}
}
Esempio n. 3
0
void APP_CC
logd_main_loop()
{
	int client = 0;
	char buffer[1024];
	int count;

	log_fd = open(LOGGING_FILE, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, S_IRUSR | S_IWUSR);
	g_mkdir("/var/spool/xrdp");
	g_chmod_hex("/var/spool/xrdp", 0775);
	if ( g_directory_exist("/var/spool/xrdp") == 0)
	{
		g_writeln("Unable to create the logging socket");
		g_exit(1);
	}
	g_writeln("xrdp logging spool application\n");
	log_socket = g_create_unix_socket(LOGGING_SOCKET);
	g_chmod_hex(LOGGING_SOCKET, 0xFFFF);
	if ( log_socket == 1)
	{
		g_writeln("Unable to create logging socket");
		return ;
	}
	if (log_fd < 0){
		g_writeln("Unable to create logging instance\n");
	}
	running = 1;
	while(running)
	{
		client = g_wait_connection(log_socket);

		count = g_tcp_recv(client, (char*)buffer, 1024, 0);
		while(count > 0)
		{
			g_file_write(log_fd, buffer, count);
			count = g_tcp_recv(client, (char*)buffer, 1024, 0);
		}
		count = 0;
		g_tcp_close(client);
	}

}
Esempio n. 4
0
File: trans.c Progetto: speidy/xrdp
/**
 * @return 0 on success, 1 on failure
 */
int APP_CC
trans_listen_address(struct trans *self, char *port, const char *address)
{
    if (self->sck != 0)
    {
        g_tcp_close(self->sck);
    }

    if (self->mode == TRANS_MODE_TCP) /* tcp */
    {
        self->sck = g_tcp_socket();
        if (self->sck < 0)
            return 1;

        g_tcp_set_non_blocking(self->sck);

        if (g_tcp_bind_address(self->sck, port, address) == 0)
        {
            if (g_tcp_listen(self->sck) == 0)
            {
                self->status = TRANS_STATUS_UP; /* ok */
                self->type1 = TRANS_TYPE_LISTENER; /* listener */
                return 0;
            }
        }
    }
    else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
    {
        g_free(self->listen_filename);
        self->listen_filename = 0;
        g_file_delete(port);

        self->sck = g_tcp_local_socket();
        if (self->sck < 0)
            return 1;

        g_tcp_set_non_blocking(self->sck);

        if (g_tcp_local_bind(self->sck, port) == 0)
        {
            self->listen_filename = g_strdup(port);

            if (g_tcp_listen(self->sck) == 0)
            {
                g_chmod_hex(port, 0x0660);
                self->status = TRANS_STATUS_UP; /* ok */
                self->type1 = TRANS_TYPE_LISTENER; /* listener */
                return 0;
            }
        }
    }

    return 1;
}
Esempio n. 5
0
int g_mk_temp_dir(const char *app_name)
{
	if (app_name != 0)
	{
		if (app_name[0] != 0)
		{
			if (!g_directory_exist("/tmp/.xrdp"))
			{
				if (!g_create_dir("/tmp/.xrdp"))
				{
					printf("g_mk_temp_dir: g_create_dir failed\n");
					return 1;
				}

				g_chmod_hex("/tmp/.xrdp", 0x1777);
			}

			snprintf(g_temp_base, sizeof(g_temp_base), "/tmp/.xrdp/%s-XXXXXX", app_name);
			snprintf(g_temp_base_org, sizeof(g_temp_base_org), "/tmp/.xrdp/%s-XXXXXX", app_name);

			if (mkdtemp(g_temp_base) == 0)
			{
				printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
				return 1;
			}
		}
		else
		{
			printf("g_mk_temp_dir: bad app name\n");
			return 1;
		}
	}
	else
	{
		if (g_temp_base_org[0] == 0)
		{
			printf("g_mk_temp_dir: g_temp_base_org not set\n");
			return 1;
		}

		g_strncpy(g_temp_base, g_temp_base_org, 127);

		if (mkdtemp(g_temp_base) == 0)
		{
			printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
		}
	}

	return 0;
}
Esempio n. 6
0
int DEFAULT_CC
main(int argc, char** argv)
{
	int fd;
	int error;
	int daemon = 1;
	int pid;
	char pid_s[8];
	char text[256];

	if(g_is_root() != 0){
		g_printf("Error, xrdp-sesman service must be start with root privilege\n");
		return 0;
	}


	g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
	if (1 == argc)
	{
		/* no options on command line. normal startup */
		g_printf("starting sesman...");
		daemon = 1;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
			(0 == g_strcasecmp(argv[1], "-n")) ||
			(0 == g_strcasecmp(argv[1], "-ns"))))
	{
		/* starts sesman not daemonized */
		g_printf("starting sesman in foregroud...");
		daemon = 0;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) ||
			(0 == g_strcasecmp(argv[1], "-h"))))
	{
		/* help screen */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("usage: sesman [command]\n\n");
		g_printf("command can be one of the following:\n");
		g_printf("-n, -ns, --nodaemon	starts sesman in foreground\n");
		g_printf("-k, --kill           kills running sesman\n");
		g_printf("-h, --help           shows this help\n");
		g_printf("if no command is specified, sesman is started in background");
		g_exit(0);
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) ||
			(0 == g_strcasecmp(argv[1], "-k"))))
	{
		/* killing running sesman */
		/* check if sesman is running */
		if (!g_file_exist(pid_file))
		{
			g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
			g_exit(1);
		}

		fd = g_file_open(pid_file);

		if (-1 == fd)
		{
			g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
			return 1;
		}

		error = g_file_read(fd, pid_s, 7);
		if (-1 == error)
		{
			g_printf("error reading pid file: %s\n", g_get_strerror());
			g_file_close(fd);
			g_exit(error);
		}
		g_file_close(fd);
		pid = g_atoi(pid_s);

		error = g_sigterm(pid);
		if (0 != error)
		{
			g_printf("error killing sesman: %s\n", g_get_strerror());
		}
		else
		{
			g_file_delete(pid_file);
		}

		g_exit(error);
	}
	else
	{
		/* there's something strange on the command line */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("error: invalid command line\n");
		g_printf("usage: sesman [ --nodaemon | --kill | --help ]\n");
		g_exit(1);
	}

	if (g_file_exist(pid_file))
	{
		g_printf("sesman is already running.\n");
		g_printf("if it's not running, try removing ");
		g_printf(pid_file);
		g_printf("\n");
		g_exit(1);
	}

	/* reading config */
	g_cfg = g_malloc(sizeof(struct config_sesman), 1);
	if (0 == g_cfg)
	{
		g_printf("error creating config: quitting.\n");
		g_exit(1);
	}
	g_cfg->log.fd = -1; /* don't use logging before reading its config */
	if (0 != config_read(g_cfg))
	{
		g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
		g_exit(1);
	}

	/* starting logging subsystem */
	error = log_start(&(g_cfg->log));

	if (error != LOG_STARTUP_OK)
	{
		switch (error)
		{
			case LOG_ERROR_MALLOC:
				g_printf("error on malloc. cannot start logging. quitting.\n");
				break;
			case LOG_ERROR_FILE_OPEN:
				g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
				break;
		}
		g_exit(1);
	}

	/* libscp initialization */
	scp_init(&(g_cfg->log));

	if (daemon)
	{
		/* start of daemonizing code */
		if (g_daemonize(pid_file) == 0)
		{
			g_writeln("problem daemonize");
			g_exit(1);
		}
	}

	/* initializing locks */
	lock_init();

	/* signal handling */
	g_pid = g_getpid();
	/* old style signal handling is now managed synchronously by a
	 * separate thread. uncomment this block if you need old style
	 * signal handling and comment out thread_sighandler_start()
	 * going back to old style for the time being
	 * problem with the sigaddset functions in sig.c - jts */
#if 1
	g_signal_hang_up(sig_sesman_reload_cfg); /* SIGHUP	*/
	g_signal_user_interrupt(sig_sesman_shutdown); /* SIGINT	*/
	g_signal_kill(sig_sesman_shutdown); /* SIGKILL */
	g_signal_terminate(sig_sesman_shutdown); /* SIGTERM */
//	g_signal_child_stop(sig_sesman_session_end); /* SIGCHLD */
#endif
#if 0
	thread_sighandler_start();
#endif

	/* start program main loop */
	log_message(&(g_cfg->log), LOG_LEVEL_INFO,
			"starting sesman with pid %d", g_pid);

	/* make sure the /tmp/.X11-unix directory exist */
	if (!g_directory_exist("/tmp/.X11-unix"))
	{
		g_create_dir("/tmp/.X11-unix");
		g_chmod_hex("/tmp/.X11-unix", 0x1777);
	}

	if (!g_directory_exist(XRDP_SOCKET_PATH))
	{
		g_create_dir(XRDP_SOCKET_PATH);
		g_chmod_hex(XRDP_SOCKET_PATH, 0x1777);
	}

	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
	g_term_event = g_create_wait_obj(text);
	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_sync", g_pid);
	g_sync_event = g_create_wait_obj(text);

	scp_init_mutex();
	tc_thread_create(admin_thread, 0);
	tc_thread_create(monit_thread, 0);
	sesman_main_loop();
	scp_remove_mutex();

	g_delete_wait_obj(g_term_event);
	g_delete_wait_obj(g_sync_event);

	if (!daemon)
	{
		log_end(&(g_cfg->log));
	}

	return 0;
}
Esempio n. 7
0
int DEFAULT_CC
main(int argc, char** argv)
{
	int fd = 0;
	int error = 0;
	int daemon = 1;
	int pid = 0;
	char pid_s[8] = {0};

	if(g_is_root() != 0)
	{
		g_printf("Error, xrdp-printerd service must be start with root privilege\n");
		return 0;
	}


	g_snprintf(pid_file, 255, "%s/xrdp-printerd.pid", XRDP_PID_PATH);
	if (1 == argc)
	{
		/* no options on command line. normal startup */
		g_printf("starting xrdp-printerd...");
		daemon = 1;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
                           (0 == g_strcasecmp(argv[1], "-n")) ||
                           (0 == g_strcasecmp(argv[1], "-ns"))))
	{
		/* starts xrdp-printerd not daemonized */
		g_printf("starting xrdp-printerd in foregroud...");
		daemon = 0;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) ||
                           (0 == g_strcasecmp(argv[1], "-h"))))
	{
		/* help screen */
		g_printf("xrdp-printerd - xrdp printer manager\n\n");
		g_printf("usage: xrdp-printerd [command]\n\n");
		g_printf("command can be one of the following:\n");
		g_printf("-n, -ns, --nodaemon  starts xrdp-printerd in foreground\n");
		g_printf("-k, --kill           kills running xrdp-printerd\n");
		g_printf("-h, --help           shows this help\n");
		g_printf("if no command is specified, xrdp-printerd is started in background");
		g_exit(0);
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) || (0 == g_strcasecmp(argv[1], "-k"))))
	{
		/* killing running xrdp-printerd */
		/* check if xrdp-printerd is running */
		if (!g_file_exist(pid_file))
		{
			g_printf("xrdp-printerd is not running (pid file not found - %s)\n", pid_file);
			g_exit(1);
		}

		fd = g_file_open(pid_file);

		if (-1 == fd)
		{
			g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
			return 1;
		}

		error = g_file_read(fd, pid_s, 7);
		if (-1 == error)
		{
			g_printf("error reading pid file: %s\n", g_get_strerror());
			g_file_close(fd);
			g_exit(error);
		}
		g_file_close(fd);
		pid = g_atoi(pid_s);

		error = g_sigterm(pid);
		if (0 != error)
		{
			g_printf("error killing xrdp-printerd: %s\n", g_get_strerror());
		}
		else
		{
			g_file_delete(pid_file);
		}

		g_exit(error);
	}
	else
	{
		/* there's something strange on the command line */
		g_printf("xrdp-printerd - xrdp printer manager\n\n");
		g_printf("error: invalid command line\n");
		g_printf("usage: xrdp-printerd [ --nodaemon | --kill | --help ]\n");
		g_exit(1);
	}

	if (g_file_exist(pid_file))
	{
		g_printf("xrdp-printerd is already running.\n");
		g_printf("if it's not running, try removing ");
		g_printf(pid_file);
		g_printf("\n");
		g_exit(1);
	}

	if (printerd_init() != LOG_STARTUP_OK)
	{
		switch (error)
		{
		case LOG_ERROR_MALLOC:
			g_printf("error on malloc. cannot start logging. quitting.\n");
			break;
		case LOG_ERROR_FILE_OPEN:
			g_printf("error opening log file [%s]. quitting.\n", l_config->log_file);
			break;
		}
		g_exit(1);
	}

	if (daemon)
	{
		/* start of daemonizing code */
		if (g_daemonize(pid_file) == 0)
		{
			g_writeln("problem daemonize");
			g_exit(1);
		}
	}

	/* signal handling */
	g_pid = g_getpid();

	g_signal_user_interrupt(sig_printerd_shutdown);		/* SIGINT  */
	g_signal_kill(sig_printerd_shutdown);				/* SIGKILL */
	g_signal_terminate(sig_printerd_shutdown);			/* SIGTERM */
	g_signal_pipe(sig_printerd_pipe);			/* SIGPIPE */

	/* start program main loop */
	log_message(l_config, LOG_LEVEL_INFO,
              "starting xrdp-printerd with pid %d", g_pid);


	if (!g_directory_exist(XRDP_SOCKET_PATH))
	{
		g_create_dir(XRDP_SOCKET_PATH);
		g_chmod_hex(XRDP_SOCKET_PATH, 0x1777);
	}

	printerd_main_loop();


	log_end(l_config);

	return 0;
}