Ejemplo n.º 1
0
/* return error */
int DEFAULT_CC
lib_mod_set_param(struct mod* mod, char* name, char* value)
{
  if (g_strcasecmp(name, "username") == 0)
  {
    g_strncpy(mod->username, value, 255);
  }
  else if (g_strcasecmp(name, "password") == 0)
  {
    g_strncpy(mod->password, value, 255);
  }
  else if (g_strcasecmp(name, "ip") == 0)
  {
    g_strncpy(mod->ip, value, 255);
  }
  else if (g_strcasecmp(name, "port") == 0)
  {
    g_strncpy(mod->port, value, 255);
  }
  else if (g_strcasecmp(name, "rfx") == 0)
  {
    mod->rfx = g_atoi(value); 
    g_writeln("mod->rfx = %d",mod->rfx);
  }
  return 0;
}
Ejemplo n.º 2
0
Archivo: rdp.c Proyecto: ArvidNorr/xrdp
/* return error */
int DEFAULT_CC
lib_mod_set_param(struct mod* mod, char* name, char* value)
{
  if (g_strncasecmp(name, "ip", 255) == 0)
  {
    g_strncpy(mod->ip, value, 255);
  }
  else if (g_strncasecmp(name, "port", 255) == 0)
  {
    g_strncpy(mod->port, value, 255);
  }
  else if (g_strncasecmp(name, "username", 255) == 0)
  {
    g_strncpy(mod->username, value, 255);
  }
  else if (g_strncasecmp(name, "password", 255) == 0)
  {
    g_strncpy(mod->password, value, 255);
  }
  else if (g_strncasecmp(name, "hostname", 255) == 0)
  {
    g_strncpy(mod->hostname, value, 255);
  }
  else if (g_strncasecmp(name, "keylayout", 255) == 0)
  {
    mod->keylayout = g_atoi(value);
  }
  return 0;
}
Ejemplo n.º 3
0
static int APP_CC
get_display_num_from_display(char *display_text)
{
    int index;
    int mode;
    int host_index;
    int disp_index;
    int scre_index;
    char host[256];
    char disp[256];
    char scre[256];

    g_memset(host, 0, 256);
    g_memset(disp, 0, 256);
    g_memset(scre, 0, 256);

    index = 0;
    host_index = 0;
    disp_index = 0;
    scre_index = 0;
    mode = 0;

    while (display_text[index] != 0)
    {
        if (display_text[index] == ':')
        {
            mode = 1;
        }
        else if (display_text[index] == '.')
        {
            mode = 2;
        }
        else if (mode == 0)
        {
            host[host_index] = display_text[index];
            host_index++;
        }
        else if (mode == 1)
        {
            disp[disp_index] = display_text[index];
            disp_index++;
        }
        else if (mode == 2)
        {
            scre[scre_index] = display_text[index];
            scre_index++;
        }

        index++;
    }

    host[host_index] = 0;
    disp[disp_index] = 0;
    scre[scre_index] = 0;
    g_display_num = g_atoi(disp);
    return 0;
}
Ejemplo n.º 4
0
static int
xrdp_listen_get_port_address(char* port, int port_bytes,
                             char* address, int address_bytes)
{
  int fd;
  int error;
  int index;
  char* val;
  struct list* names;
  struct list* values;
  char cfg_file[256];

  /* default to port 3389 */
  g_strncpy(port, "3389", port_bytes - 1);
  /* Default to all */
  g_strncpy(address, "0.0.0.0", address_bytes - 1);
  /* see if port or address is in xrdp.ini file */
  file_config_name("xrdp.ini", cfg_file, 255);
  fd = g_file_open(cfg_file);
  if (fd > 0)
  {
    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    if (file_read_section(fd, "globals", names, values) == 0)
    {
      for (index = 0; index < names->count; index++)
      {
        val = (char*)list_get_item(names, index);
        if (val != 0)
        {
          if (g_strcasecmp(val, "port") == 0)
          {
            val = (char*)list_get_item(values, index);
            error = g_atoi(val);
            if ((error > 0) && (error < 65000))
            {
              g_strncpy(port, val, port_bytes - 1);
            }
          }
          if (g_strcasecmp(val, "address") == 0)
          {
            val = (char*)list_get_item(values, index);
            g_strncpy(address, val, address_bytes - 1);
          }
        }
      }
    }
    list_delete(names);
    list_delete(values);
    g_file_close(fd);
  }
  return 0;
}
Ejemplo n.º 5
0
int DEFAULT_CC
main(int argc, char** argv)
{
  int ret=0;

  x_pid = g_atoi(argv[1]);
  wm_pid = g_atoi(argv[2]);

  g_printf("\n[sessvc] Setting signal handler\n"); 
  g_signal(9, signal_handler);   /* SIGKILL */
  g_signal(15, signal_handler);  /* SIGTERM */
  g_signal(17, signal_handler);  /* SIGCHLD */
 
  g_printf("\n[sessvc] Waiting for X (pid %d) and WM (pid %d)\n", x_pid, wm_pid);
  
  ret = g_waitpid(wm_pid);
  g_sigterm(x_pid);

  g_printf("\n[sessvc] WM is dead (waitpid said %d, errno is %d). exiting...\n", ret, errno);
  return 0;
}
Ejemplo n.º 6
0
static int
xrdp_mm_get_sesman_port(char* port, int port_bytes)
{
  int fd = -1;
  int error = 0;
  int index = 0;
  char* val = 0;
  char cfg_file[256];
  struct list* names = (struct list *)NULL;
  struct list* values = (struct list *)NULL;

  g_memset(cfg_file,0,sizeof(char) * 256);
  /* default to port 3350 */
  g_strncpy(port, "3350", port_bytes - 1);
  /* see if port is in xrdp.ini file */
  file_config_name("sesman.ini", cfg_file, 255);
  fd = g_file_open(cfg_file);
  if (fd > 0)
  {
    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    if (file_read_section(fd, "Globals", names, values) == 0)
    {
      for (index = 0; index < names->count; index++)
      {
        val = (char*)list_get_item(names, index);
        if (val != 0)
        {
          if (g_strcasecmp(val, "ListenPort") == 0)
          {
            val = (char*)list_get_item(values, index);
            error = g_atoi(val);
            if ((error > 0) && (error < 65000))
            {
              g_strncpy(port, val, port_bytes - 1);
            }
            break;
          }
        }
      }
    }
    list_delete(names);
    list_delete(values);
    g_file_close(fd);
  }

  return 0;
}
Ejemplo n.º 7
0
int
xrdp_listen_get_port(char* port, int port_bytes)
{
  int fd;
  int error;
  int index;
  char* val;
  struct list* names;
  struct list* values;

  /* default to port 3389 */
  g_strncpy(port, "3389", port_bytes - 1);
  /* see if port is in xrdp.ini file */
  fd = g_file_open(XRDP_CFG_FILE);
  if (fd > 0)
  {
    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    if (file_read_section(fd, "globals", names, values) == 0)
    {
      for (index = 0; index < names->count; index++)
      {
        val = (char*)list_get_item(names, index);
        if (val != 0)
        {
          if (g_strcasecmp(val, "port") == 0)
          {
            val = (char*)list_get_item(values, index);
            error = g_atoi(val);
            if ((error > 0) && (error < 65000))
            {
              g_strncpy(port, val, port_bytes - 1);
            }
            break;
          }
        }
      }
    }
    list_delete(names);
    list_delete(values);
    g_file_close(fd);
  }
  return 0;
}
Ejemplo n.º 8
0
/* returns error */
int APP_CC
read_preamble_packet(struct xrdp_process* self)
{
    // Using the session stream
    int ns_len = 0;
    int idx;
    int len;
    // cache a pointer to client_info
    struct xrdp_client_info *client_info = self->session->client_info; 

    struct stream* s;
    make_stream(s);
    init_stream(s, 10000);

    DEBUG(("in read_preamble_packet"));

    // 5 bytes should include the colon  
    if (trans_force_read_s(self->server_trans, s, 5) == 0)
    {
        idx = g_pos(s->data, ":") + 1; // skip colon
        ns_len = g_atoi(s->data);
        DEBUG(("Preamble length %i", ns_len));
        len = ns_len - 5 + idx + 1; // trailing comma as well 
        DEBUG(("Preamble to read %i", len));
        if (trans_force_read_s(self->server_trans, s, len) == 0)
        {
            DEBUG(("Preamble body %s", s->data));
            // this will be used as a processing buffer when data required
            // so do not assume will exist in this state later on.
            client_info->osirium_preamble_buffer = (char*)g_malloc(ns_len+1, 1);
            in_uint8s(s, idx);    // skip netstring header 
            in_uint8a(s, 
                    client_info->osirium_preamble_buffer, 
                    ns_len);
            DEBUG(("Preamble %s", client_info->osirium_preamble_buffer));
            free_stream(s);
            return 0;
        }
    }
    free_stream(s);
    DEBUG(("out read_preamble_packet"));
    return 0;
}
Ejemplo n.º 9
0
int DEFAULT_CC
main(int argc, char **argv)
{
    int test;
    int host_be;
#if defined(_WIN32)
    WSADATA w;
    SC_HANDLE sc_man;
    SC_HANDLE sc_ser;
    int run_as_service;
    SERVICE_TABLE_ENTRY te[2];
#else
    int pid;
    int fd;
    int no_daemon;
    char text[256];
    char pid_file[256];
#endif

    g_init();
    ssl_init();
    /* check compiled endian with actual endian */
    test = 1;
    host_be = !((int)(*(unsigned char *)(&test)));
#if defined(B_ENDIAN)

    if (!host_be)
#endif
#if defined(L_ENDIAN)
        if (host_be)
#endif
        {
            g_writeln("endian wrong, edit arch.h");
            return 0;
        }

    /* check long, int and void* sizes */
    if (sizeof(int) != 4)
    {
        g_writeln("unusable int size, must be 4");
        return 0;
    }

    if (sizeof(long) != sizeof(void *))
    {
        g_writeln("long size must match void* size");
        return 0;
    }

    if (sizeof(long) != 4 && sizeof(long) != 8)
    {
        g_writeln("unusable long size, must be 4 or 8");
        return 0;
    }

    if (sizeof(tui64) != 8)
    {
        g_writeln("unusable tui64 size, must be 8");
        return 0;
    }

#if defined(_WIN32)
    run_as_service = 1;

    if (argc == 2)
    {
        if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
                g_strncasecmp(argv[1], "--help", 255) == 0 ||
                g_strncasecmp(argv[1], "-h", 255) == 0)
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("");
            g_writeln("Usage: xrdp [options]");
            g_writeln("   -h: show help");
            g_writeln("   -install: install service");
            g_writeln("   -remove: remove service");
            g_writeln("");
            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-install", 255) == 0 ||
                 g_strncasecmp(argv[1], "--install", 255) == 0 ||
                 g_strncasecmp(argv[1], "-i", 255) == 0)
        {
            /* open service manager */
            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);

            if (sc_man == 0)
            {
                g_writeln("error OpenSCManager, do you have rights?");
                g_exit(0);
            }

            /* check if service is allready installed */
            sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);

            if (sc_ser == 0)
            {
                /* install service */
                CreateService(sc_man, "xrdp", "xrdp", SERVICE_ALL_ACCESS,
                              SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
                              SERVICE_ERROR_IGNORE, "c:\\temp\\xrdp\\xrdp.exe",
                              0, 0, 0, 0, 0);

            }
            else
            {
                g_writeln("error service is allready installed");
                CloseServiceHandle(sc_ser);
                CloseServiceHandle(sc_man);
                g_exit(0);
            }

            CloseServiceHandle(sc_man);
            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-remove", 255) == 0 ||
                 g_strncasecmp(argv[1], "--remove", 255) == 0 ||
                 g_strncasecmp(argv[1], "-r", 255) == 0)
        {
            /* open service manager */
            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);

            if (sc_man == 0)
            {
                g_writeln("error OpenSCManager, do you have rights?");
                g_exit(0);
            }

            /* check if service is allready installed */
            sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);

            if (sc_ser == 0)
            {
                g_writeln("error service is not installed");
                CloseServiceHandle(sc_man);
                g_exit(0);
            }

            DeleteService(sc_ser);
            CloseServiceHandle(sc_man);
            g_exit(0);
        }
        else
        {
            g_writeln("Unknown Parameter");
            g_writeln("xrdp -h for help");
            g_writeln("");
            g_exit(0);
        }
    }
    else if (argc > 1)
    {
        g_writeln("Unknown Parameter");
        g_writeln("xrdp -h for help");
        g_writeln("");
        g_exit(0);
    }

    if (run_as_service)
    {
        g_memset(&te, 0, sizeof(te));
        te[0].lpServiceName = "xrdp";
        te[0].lpServiceProc = MyServiceMain;
        StartServiceCtrlDispatcher(&te);
        g_exit(0);
    }

    WSAStartup(2, &w);
#else /* _WIN32 */
    g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
    no_daemon = 0;

    if (argc == 2)
    {
        if ((g_strncasecmp(argv[1], "-kill", 255) == 0) ||
                (g_strncasecmp(argv[1], "--kill", 255) == 0) ||
                (g_strncasecmp(argv[1], "-k", 255) == 0))
        {
            g_writeln("stopping xrdp");
            /* read the xrdp.pid file */
            fd = -1;

            if (g_file_exist(pid_file)) /* xrdp.pid */
            {
                fd = g_file_open(pid_file); /* xrdp.pid */
            }

            if (fd == -1)
            {
                g_writeln("problem opening to xrdp.pid");
                g_writeln("maybe its not running");
            }
            else
            {
                g_memset(text, 0, 32);
                g_file_read(fd, text, 31);
                pid = g_atoi(text);
                g_writeln("stopping process id %d", pid);

                if (pid > 0)
                {
                    g_sigterm(pid);
                }

                g_file_close(fd);
            }

            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 ||
                 g_strncasecmp(argv[1], "--nodaemon", 255) == 0 ||
                 g_strncasecmp(argv[1], "-nd", 255) == 0 ||
                 g_strncasecmp(argv[1], "--nd", 255) == 0 ||
                 g_strncasecmp(argv[1], "-ns", 255) == 0 ||
                 g_strncasecmp(argv[1], "--ns", 255) == 0)
        {
            no_daemon = 1;
        }
        else if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
                 g_strncasecmp(argv[1], "--help", 255) == 0 ||
                 g_strncasecmp(argv[1], "-h", 255) == 0)
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("");
            g_writeln("Usage: xrdp [options]");
            g_writeln("   -h: show help");
            g_writeln("   -nodaemon: don't fork into background");
            g_writeln("   -kill: shut down xrdp");
            g_writeln("");
            g_exit(0);
        }
        else if ((g_strncasecmp(argv[1], "-v", 255) == 0) ||
                 (g_strncasecmp(argv[1], "--version", 255) == 0))
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("Version %s", PACKAGE_VERSION);
            g_writeln("");
            g_exit(0);
        }
        else
        {
            g_writeln("Unknown Parameter");
            g_writeln("xrdp -h for help");
            g_writeln("");
            g_exit(0);
        }
    }
    else if (argc > 1)
    {
        g_writeln("Unknown Parameter");
        g_writeln("xrdp -h for help");
        g_writeln("");
        g_exit(0);
    }

    if (g_file_exist(pid_file)) /* xrdp.pid */
    {
        g_writeln("It looks like xrdp is allready running,");
        g_writeln("if not delete the xrdp.pid file and try again");
        g_exit(0);
    }

    if (!no_daemon)
    {
        /* make sure we can write to pid file */
        fd = g_file_open(pid_file); /* xrdp.pid */

        if (fd == -1)
        {
            g_writeln("running in daemon mode with no access to pid files, quitting");
            g_exit(0);
        }

        if (g_file_write(fd, "0", 1) == -1)
        {
            g_writeln("running in daemon mode with no access to pid files, quitting");
            g_exit(0);
        }

        g_file_close(fd);
        g_file_delete(pid_file);
    }

    if (!no_daemon)
    {
        /* start of daemonizing code */
        pid = g_fork();

        if (pid == -1)
        {
            g_writeln("problem forking");
            g_exit(1);
        }

        if (0 != pid)
        {
            g_writeln("process %d started ok", pid);
            /* exit, this is the main process */
            g_exit(0);
        }

        g_sleep(1000);
        g_file_close(0);
        g_file_close(1);
        g_file_close(2);
        g_file_open("/dev/null");
        g_file_open("/dev/null");
        g_file_open("/dev/null");
        /* end of daemonizing code */
    }

    if (!no_daemon)
    {
        /* write the pid to file */
        pid = g_getpid();
        fd = g_file_open(pid_file); /* xrdp.pid */

        if (fd == -1)
        {
            g_writeln("trying to write process id to xrdp.pid");
            g_writeln("problem opening xrdp.pid");
            g_writeln("maybe no rights");
        }
        else
        {
            g_sprintf(text, "%d", pid);
            g_file_write(fd, text, g_strlen(text));
            g_file_close(fd);
        }
    }

#endif
    g_threadid = tc_get_threadid();
    g_listen = xrdp_listen_create();
    g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
    g_signal_kill(xrdp_shutdown); /* SIGKILL */
    g_signal_pipe(pipe_sig); /* SIGPIPE */
    g_signal_terminate(xrdp_shutdown); /* SIGTERM */
    g_sync_mutex = tc_mutex_create();
    g_sync1_mutex = tc_mutex_create();
    pid = g_getpid();
    g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
    g_term_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
    g_sync_event = g_create_wait_obj(text);

    if (g_term_event == 0)
    {
        g_writeln("error creating g_term_event");
    }

    xrdp_listen_main_loop(g_listen);
    xrdp_listen_delete(g_listen);
    tc_mutex_delete(g_sync_mutex);
    tc_mutex_delete(g_sync1_mutex);
    g_delete_wait_obj(g_term_event);
    g_delete_wait_obj(g_sync_event);
#if defined(_WIN32)
    /* I don't think it ever gets here */
    /* when running in win32 app mode, control c exits right away */
    WSACleanup();
#else
    /* delete the xrdp.pid file */
    g_file_delete(pid_file);
#endif
    return 0;
}
Ejemplo n.º 10
0
static int
xrdp_listen_get_port_address(char *port, int port_bytes,
                             char *address, int address_bytes,
                             int *tcp_nodelay, int *tcp_keepalive,
                             struct xrdp_startup_params *startup_param)
{
    int fd;
    int error;
    int index;
    char *val;
    struct list *names;
    struct list *values;
    char cfg_file[256];

    /* default to port 3389 */
    g_strncpy(port, "3389", port_bytes - 1);
    /* Default to all */
    g_strncpy(address, "0.0.0.0", address_bytes - 1);
    /* see if port or address is in xrdp.ini file */
    g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
    fd = g_file_open(cfg_file);
    *tcp_nodelay = 0 ;
    *tcp_keepalive = 0 ;

    if (fd != -1)
    {
        names = list_create();
        names->auto_free = 1;
        values = list_create();
        values->auto_free = 1;

        if (file_read_section(fd, "globals", names, values) == 0)
        {
            for (index = 0; index < names->count; index++)
            {
                val = (char *)list_get_item(names, index);

                if (val != 0)
                {
                    if (g_strcasecmp(val, "port") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        if (val[0] == '/')
                        {
                            g_strncpy(port, val, port_bytes - 1);
                        }
                        else
                        {
                            error = g_atoi(val);
                            if ((error > 0) && (error < 65000))
                            {
                                g_strncpy(port, val, port_bytes - 1);
                            }
                        }
                    }

                    if (g_strcasecmp(val, "address") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        g_strncpy(address, val, address_bytes - 1);
                    }

                    if (g_strcasecmp(val, "fork") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        startup_param->fork = g_text2bool(val);
                    }

                    if (g_strcasecmp(val, "tcp_nodelay") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        *tcp_nodelay = g_text2bool(val);
                    }

                    if (g_strcasecmp(val, "tcp_keepalive") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        *tcp_keepalive = g_text2bool(val);
                    }

                    if (g_strcasecmp(val, "tcp_send_buffer_bytes") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        startup_param->send_buffer_bytes = g_atoi(val);
                    }

                    if (g_strcasecmp(val, "tcp_recv_buffer_bytes") == 0)
                    {
                        val = (char *)list_get_item(values, index);
                        startup_param->recv_buffer_bytes = g_atoi(val);
                    }
                }
            }
        }

        list_delete(names);
        list_delete(values);
    }

    if (fd != -1)
        g_file_close(fd);

    /* startup_param overrides */
    if (startup_param->port[0] != 0)
    {
        g_strncpy(port, startup_param->port, port_bytes - 1);
    }

    return 0;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
int
process_request(int client)
{
	int session_id = 0;
	char request_type[128];
	char request_action[128];
	char session_id_string[12];
	char username[256];
	xmlDocPtr doc;

	doc = xml_receive_message(client);
	if ( doc == NULL)
	{
		return close_management_connection(NULL, client);
	}

	if (xml_get_xpath(doc, "/request/@type", request_type) == 1)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Unable to get the request type");
		xml_send_error(client, "Unable to get the request type");
		return close_management_connection(doc, client);
	}

	if (xml_get_xpath(doc, "/request/@action", request_action) == 1)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Unable to get the request action");
		xml_send_error(client, "Unable to get the request type");
		return close_management_connection(doc, client);
	}
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Request_type : '%s' ", request_type);
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Request_action : '%s' ", request_action);

	if( g_strcmp(request_type, "sessions") == 0)
	{
		if( g_strcmp(request_action, "list") != 0)
		{
			xml_send_error(client, "For session request type only"
					"the list action is supported");
			return close_management_connection(doc, client);
		}
		send_sessions(client);
		//xml_send_error(client,"test");
		return close_management_connection(doc, client);
	}

	if( g_strcmp(request_type, "session") == 0)
	{
		if (xml_get_xpath(doc, "/request/@id", session_id_string) == 1)
		{
			session_id_string[0] = '\0';
		}
		if (xml_get_xpath(doc, "/request/@username", username) == 1)
		{
			username[0] = '\0';
		}
		if (session_id_string[0] != '\0')
		{
			session_id = g_atoi(session_id_string);
			if(session_id == 0)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"%i is not a numeric value", session_id);
				xml_send_error(client, "Unable to convert the session id");
				return close_management_connection(doc, client);
			}
		}
		if( g_strcmp(request_action, "status") == 0)
		{
			send_session(client, session_id, username);
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "logoff") == 0)
		{
			send_logoff(client, session_id);
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for session");
		return close_management_connection(doc, client);
	}
	if( g_strcmp(request_type, "internal") == 0)
	{
		char username[256];
		if( g_strcmp(request_action, "disconnect") == 0)
		{
			if (xml_get_xpath(doc, "/request/@username", username) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the username\n");
				xml_send_error(client, "Unable to get the username");
				return close_management_connection(doc, client);
			}
			session_update_status_by_user(username, SESMAN_SESSION_STATUS_DISCONNECTED);
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "logoff") == 0)
		{
			if (xml_get_xpath(doc, "/request/@username", username) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the username\n");
				xml_send_error(client, "Unable to get the username");
				return close_management_connection(doc, client);
			}
			session_update_status_by_user(username, SESMAN_SESSION_STATUS_TO_DESTROY);
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for internal");
		return close_management_connection(doc, client);
	}
	if( g_strcmp(request_type, "user_conf") == 0)
	{
		char username[256];
		char key[128];
		char value[256];
		if (xml_get_xpath(doc, "/request/@username", username) == 1)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
					"Unable to get the username\n");
			xml_send_error(client, "Unable to get the username");
			return close_management_connection(doc, client);
		}
		if (xml_get_xpath(doc, "/request/@key", key) == 1)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
					"Unable to get the key in the request");
			xml_send_error(client, "Unable to get the key in the request");
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "set") == 0)
		{
			if (xml_get_xpath(doc, "/request/@value", value) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the value int the request\n");
				xml_send_error(client, "Unable to get the value in the request");
				return close_management_connection(doc, client);
			}
			if (session_set_user_pref(username, key, value) == 0 )
			{
				xml_send_success(client, "SUCCESS");
			}
			else
			{
				xml_send_error(client, "Unable to set preference");
			}
			return close_management_connection(doc, client);
		}

		if( g_strcmp(request_action, "get") == 0)
		{
			if(session_get_user_pref(username, key, value) == 0)
			{
				xml_send_key_value(client, username, key, value);
			}
			else
			{
				xml_send_error(client, "Unable to get preference");
			}
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for internal");
		return close_management_connection(doc, client);
	}
	xml_send_error(client, "Unknown message");
	return close_management_connection(doc, client);
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
int DEFAULT_CC
main(int argc, char** argv)
{
  int fd;
  int error;
  int daemon = 1;
  int pid;
  char pid_s[8];

  if (1 == argc)
  {
    /* no options on command line. normal startup */
    g_printf("starting sesman...\n");
    daemon = 1;
  }
  else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
                           (0 == g_strcasecmp(argv[1], "-n")) ) )
  {
    /* starts sesman not daemonized */
    g_printf("starting sesman in foregroud...\n");
    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, --nodaemon  starts sesman in foregroun\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(SESMAN_PID_FILE))
    {
      g_printf("sesman is not running (pid file not found - %s)\n",
               SESMAN_PID_FILE);
      g_exit(1);
    }

    fd = g_file_open(SESMAN_PID_FILE);

    if (-1 == fd)
    {
      g_printf("error opening pid file: %s\n", 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(SESMAN_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(SESMAN_PID_FILE))
  {
    g_printf("sesman is already running.\n");
    g_printf("if it's not running, try removing ");
    g_printf(SESMAN_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. quitting.\n");
        break;
    }
    g_exit(1);
  }

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

  if (daemon)
  {
    /* start of daemonizing code */
    g_pid = g_fork();

    if (0 != g_pid)
    {
      g_exit(0);
    }

    g_file_close(0);
    g_file_close(1);
    g_file_close(2);

    g_file_open("/dev/null");
    g_file_open("/dev/null");
    g_file_open("/dev/null");
  }

  /* 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() */
  /*
  g_signal(1, sig_sesman_reload_cfg); / * SIGHUP  * /
  g_signal(2, sig_sesman_shutdown);   / * SIGINT  * /
  g_signal(9, sig_sesman_shutdown);   / * SIGKILL * /
  g_signal(15, sig_sesman_shutdown);  / * SIGTERM * /
  g_signal_child_stop(cterm);         / * SIGCHLD * /
  */
  thread_sighandler_start();

  /* writing pid file */
  fd = g_file_open(SESMAN_PID_FILE);
  if (-1 == fd)
  {
    log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "error opening pid file: %s",
                g_get_strerror());
    log_end(&(g_cfg->log));
    g_exit(1);
  }
  g_sprintf(pid_s, "%d", g_pid);
  g_file_write(fd, pid_s, g_strlen(pid_s) + 1);
  g_file_close(fd);

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

  sesman_main_loop();

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

  return 0;
}
Ejemplo n.º 15
0
int DEFAULT_CC
main(int argc, char** argv)
{
  int sck;
  int code;
  int i;
  int size;
  int version;
  int width;
  int height;
  int bpp;
  int keylayout;
  int display;
  struct stream* in_s;
  struct stream* out_s;
  char* username;
  char* password;
  char* exec;
  long data;

  if (0 != config_read(&g_cfg))
  {
    g_printf("sesrun: error reading config. quitting.\n");
    return 1;
  }

  g_pid = g_getpid();
  if (argc == 1)
  {
    g_printf("xrdp session starter v0.2\n");
    g_printf("\nusage:\n");
    g_printf("sesrun <server> <username> <password> <exec> <width> <height> <bpp> <keylayout>\n");
  }
  else if (argc == 9)
  {
    username = argv[2];
    password = argv[3];
    exec = argv[4];
    width = g_atoi(argv[5]);
    height = g_atoi(argv[6]);
    bpp = g_atoi(argv[7]);
    keylayout = g_atoi(argv[8]);
    make_stream(in_s);
    init_stream(in_s, 8192);
    make_stream(out_s);
    init_stream(out_s, 8192);
    sck = g_tcp_socket();
    if (g_tcp_connect(sck, argv[1], "3350") == 0)
    {
      s_push_layer(out_s, channel_hdr, 8);
      out_uint16_be(out_s, 20); /* code */
      i = g_strlen(username);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, username, i);
      i = g_strlen(password);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, password, i);
      i = g_strlen(exec);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, exec, i);
      out_uint16_be(out_s, width);
      out_uint16_be(out_s, height);
      out_uint16_be(out_s, bpp);
      out_uint16_be(out_s, keylayout);
      s_mark_end(out_s);
      s_pop_layer(out_s, channel_hdr);
      out_uint32_be(out_s, 0); /* version */
      out_uint32_be(out_s, out_s->end - out_s->data); /* size */
      tcp_force_send(sck, out_s->data, out_s->end - out_s->data);
      if (tcp_force_recv(sck, in_s->data, 8) == 0)
      {
        in_uint32_be(in_s, version);
        in_uint32_be(in_s, size);
        init_stream(in_s, 8192);
        if (tcp_force_recv(sck, in_s->data, size - 8) == 0)
        {
          if (version == 0)
          {
            in_uint16_be(in_s, code);
            if (code == 3)
            {
              in_uint16_be(in_s, data);
              in_uint16_be(in_s, display);
              g_printf("ok %d display %d\n", data, display);
            }
          }
        }
      }
    }
    else
    {
      g_printf("connect error\n");
    }
    g_tcp_close(sck);
    free_stream(in_s);
    free_stream(out_s);
  }
  return 0;
}
Ejemplo n.º 16
0
Archivo: xrdp.c Proyecto: dlinz/xrdp-ng
int main(int argc, char **argv)
{
	int fd;
	int pid;
	int no_daemon;
	char text[256];
	char pid_file[256];
	char cfg_file[256];
	enum logReturns error;
	xrdpStartupParams* startup_params;

	g_init("xrdp");

	g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);

	/* starting logging subsystem */
	error = log_start(cfg_file, "XRDP");

	if (error != LOG_STARTUP_OK)
	{
		switch (error)
		{
			case LOG_ERROR_MALLOC:
				g_writeln("error on malloc. cannot start logging. quitting.");
				break;

			case LOG_ERROR_FILE_OPEN:
				g_writeln("error opening log file [%s]. quitting.", getLogFile(text, 255));
				break;

			default:
				g_writeln("log_start error");
				break;
		}

		g_deinit();
		g_exit(1);
	}

	startup_params = (xrdpStartupParams *) g_malloc(sizeof(xrdpStartupParams), 1);

	if (xrdp_process_params(argc, argv, startup_params) != 0)
	{
		g_writeln("Unknown Parameter");
		g_writeln("xrdp -h for help");
		g_writeln("");
		g_deinit();
		g_exit(0);
	}

	g_snprintf(pid_file, 255, "%s/xrdp-ng.pid", XRDP_PID_PATH);
	no_daemon = 0;

	if (startup_params->kill)
	{
		g_writeln("stopping xrdp");
		/* read the xrdp.pid file */
		fd = -1;

		if (g_file_exist(pid_file)) /* xrdp-ng.pid */
		{
			fd = g_file_open(pid_file); /* xrdp-ng.pid */
		}

		if (fd == -1)
		{
			g_writeln("problem opening to xrdp-ng.pid [%s]", pid_file);
			g_writeln("maybe its not running");
		}
		else
		{
			g_memset(text, 0, 32);
			g_file_read(fd, (unsigned char*) text, 31);
			pid = g_atoi(text);
			g_writeln("stopping process id %d", pid);

			if (pid > 0)
			{
				g_sigterm(pid);
			}

			g_file_close(fd);
		}

		g_deinit();
		g_exit(0);
	}

	if (startup_params->no_daemon)
	{
		no_daemon = 1;
	}

	if (startup_params->help)
	{
		g_writeln("");
		g_writeln("xrdp: A Remote Desktop Protocol server.");
		g_writeln("Copyright (C) Jay Sorg 2004-2011");
		g_writeln("See http://xrdp.sourceforge.net for more information.");
		g_writeln("");
		g_writeln("Usage: xrdp [options]");
		g_writeln("   --help: show help");
		g_writeln("   --nodaemon: don't fork into background");
		g_writeln("   --kill: shut down xrdp");
		g_writeln("   --port: tcp listen port");
		g_writeln("   --fork: fork on new connection");
		g_writeln("");
		g_deinit();
		g_exit(0);
	}

	if (startup_params->version)
	{
		g_writeln("");
		g_writeln("xrdp: A Remote Desktop Protocol server.");
		g_writeln("Copyright (C) Jay Sorg 2004-2011");
		g_writeln("See http://xrdp.sourceforge.net for more information.");
		g_writeln("Version %s", XRDP_NG_VERSION_FULL);
		g_writeln("");
		g_deinit();
		g_exit(0);
	}

	if (g_file_exist(pid_file)) /* xrdp-ng.pid */
	{
		g_writeln("It looks like xrdp is already running,");
		g_writeln("if not delete the xrdp-ng.pid file and try again");
		g_deinit();
		g_exit(0);
	}

	if (!no_daemon)
	{

		/* make sure containing directory exists */
		g_create_path(pid_file);

		/* make sure we can write to pid file */
		fd = g_file_open(pid_file); /* xrdp-ng.pid */

		if (fd == -1)
		{
			g_writeln("running in daemon mode with no access to pid files, quitting");
			g_deinit();
			g_exit(0);
		}

		if (g_file_write(fd, (unsigned char*) "0", 1) == -1)
		{
			g_writeln("running in daemon mode with no access to pid files, quitting");
			g_deinit();
			g_exit(0);
		}

		g_file_close(fd);
		g_file_delete(pid_file);
	}

	if (!no_daemon)
	{
		/* start of daemonizing code */
		pid = g_fork();

		if (pid == -1)
		{
			g_writeln("problem forking");
			g_deinit();
			g_exit(1);
		}

		if (0 != pid)
		{
			g_writeln("process %d started ok", pid);
			/* exit, this is the main process */
			g_deinit();
			g_exit(0);
		}

		g_sleep(1000);
		/* write the pid to file */
		pid = g_getpid();
		fd = g_file_open(pid_file); /* xrdp-ng.pid */

		if (fd == -1)
		{
			g_writeln("trying to write process id to xrdp-ng.pid");
			g_writeln("problem opening xrdp-ng.pid");
			g_writeln("maybe no rights");
		}
		else
		{
			g_sprintf(text, "%d", pid);
			g_file_write(fd, (unsigned char*) text, g_strlen(text));
			g_file_close(fd);
		}

		g_sleep(1000);
		g_file_close(0);
		g_file_close(1);
		g_file_close(2);
		g_file_open("/dev/null");
		g_file_open("/dev/null");
		g_file_open("/dev/null");
		/* end of daemonizing code */
	}

	g_threadid = tc_get_threadid();
	g_listen = xrdp_listen_create();
	g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
	g_signal_kill(xrdp_shutdown); /* SIGKILL */
	g_signal_pipe(pipe_sig); /* SIGPIPE */
	g_signal_terminate(xrdp_shutdown); /* SIGTERM */
	g_signal_child_stop(xrdp_child); /* SIGCHLD */
	g_sync_mutex = tc_mutex_create();
	g_sync1_mutex = tc_mutex_create();
	pid = g_getpid();

	g_TermEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	g_SyncEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	xrdp_listen_main_loop(g_listen);
	xrdp_listen_delete(g_listen);

	tc_mutex_delete(g_sync_mutex);
	tc_mutex_delete(g_sync1_mutex);

	CloseHandle(g_TermEvent);
	CloseHandle(g_SyncEvent);

	/* only main process should delete pid file */
	if ((!no_daemon) && (pid == g_getpid()))
	{
		/* delete the xrdp-ng.pid file */
		g_file_delete(pid_file);
	}

	free(startup_params);
	g_deinit();

	return 0;
}
Ejemplo n.º 17
0
int APP_CC
main(int argc, char** argv)
{
	int pid;
	int fd;
	int no_daemon;
	char text[256];
	char pid_file[256];

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

	g_snprintf(pid_file, 255, "%s/xrdp-logd.pid", XRDP_PID_PATH);
	no_daemon = 0;
	if (argc == 2)
	{
	if ((g_strncasecmp(argv[1], "-kill", 255) == 0) ||
		(g_strncasecmp(argv[1], "--kill", 255) == 0) ||
		(g_strncasecmp(argv[1], "-k", 255) == 0))
	{
		g_writeln("stopping xrdp-logd");
		/* read the xrdp.pid file */
		fd = -1;
		if (g_file_exist(pid_file)) /* xrdp.pid */
		{
			fd = g_file_open(pid_file); /* xrdp.pid */
		}
		if (fd == -1)
		{
			g_writeln("problem opening to xrdp-logd.pid");
			g_writeln("maybe its not running");
		}
		else
		{
			g_memset(text, 0, 32);
			g_file_read(fd, text, 31);
			pid = g_atoi(text);
			g_writeln("stopping process id %d", pid);
			if (pid > 0)
			{
				g_sigterm(pid);
			}
			g_file_close(fd);
		}
		g_exit(0);
	}
	else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 ||
			 g_strncasecmp(argv[1], "--nodaemon", 255) == 0 ||
			 g_strncasecmp(argv[1], "-nd", 255) == 0 ||
			 g_strncasecmp(argv[1], "--nd", 255) == 0 ||
			 g_strncasecmp(argv[1], "-ns", 255) == 0 ||
			 g_strncasecmp(argv[1], "--ns", 255) == 0)
	{
		no_daemon = 1;
	}
	else if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
			 g_strncasecmp(argv[1], "--help", 255) == 0 ||
			 g_strncasecmp(argv[1], "-h", 255) == 0)
	{
		g_writeln("");
		g_writeln("xrdp: A Remote Desktop Protocol server.");
		g_writeln("Copyright (C) Jay Sorg 2004-2009");
		g_writeln("See http://xrdp.sourceforge.net for more information.");
		g_writeln("");
		g_writeln("Usage: xrdp-logd [options]");
		g_writeln("   -h: show help");
		g_writeln("   --nodaemon: don't fork into background");
		g_writeln("   -kill: shut down xrdp-logd");
		g_writeln("");
		g_exit(0);
		}
		else if ((g_strncasecmp(argv[1], "-v", 255) == 0) ||
			 (g_strncasecmp(argv[1], "--version", 255) == 0))
		{
			g_writeln("");
			g_writeln("xrdp: A Remote Desktop Protocol server.");
			g_writeln("Copyright (C) Jay Sorg 2004-2009");
			g_writeln("See http://xrdp.sourceforge.net for more information.");
			g_writeln("Version 0.5.0");
			g_writeln("");
			g_exit(0);
		}
		else
		{
			g_writeln("Unknown Parameter");
			g_writeln("xrdp-logd -h for help");
			g_writeln("");
			g_exit(0);
		}
	}
	else if (argc > 1)
	{
		g_writeln("Unknown Parameter");
		g_writeln("xrdp-logd -h for help");
		g_writeln("");
		g_exit(0);
	}
	if (g_file_exist(pid_file)) /* xrdp-logd.pid */
	{
		g_writeln("It looks like xrdp-logd is allready running,");
		g_writeln("if not delete the xrdp-logd.pid file and try again");
		g_exit(0);
	}
	if (!no_daemon)
	{
	/* start of daemonizing code */

		if (g_daemonize(pid_file) == 0)
		{
			g_writeln("problem daemonize");
			g_exit(1);
		}
	}
  g_signal_user_interrupt(logd_shutdown); /* SIGINT */
  g_signal_kill(logd_shutdown); /* SIGKILL */
  g_signal_terminate(logd_shutdown); /* SIGTERM */

	pid = g_getpid();
	logd_main_loop();
	/* delete the xrdp-logd.pid file */
	g_file_delete(pid_file);

	return 0;
}
Ejemplo n.º 18
0
static int
xrdp_rdp_read_config(struct xrdp_client_info *client_info)
{
    int index = 0;
    struct list *items = (struct list *)NULL;
    struct list *values = (struct list *)NULL;
    char *item = NULL;
    char *value = NULL;
    char cfg_file[256];
    int pos;
    char *tmp = NULL;
    int tmp_length = 0;

    /* initialize (zero out) local variables: */
    g_memset(cfg_file, 0, sizeof(char) * 256);

    items = list_create();
    items->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
    DEBUG(("cfg_file %s", cfg_file));
    file_by_name_read_section(cfg_file, "globals", items, values);

    for (index = 0; index < items->count; index++)
    {
        item = (char *)list_get_item(items, index);
        value = (char *)list_get_item(values, index);
        DEBUG(("item %s value %s", item, value));

        if (g_strcasecmp(item, "bitmap_cache") == 0)
        {
            client_info->use_bitmap_cache = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "bitmap_compression") == 0)
        {
            client_info->use_bitmap_comp = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "bulk_compression") == 0)
        {
            client_info->use_bulk_comp = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "crypt_level") == 0)
        {
            if (g_strcasecmp(value, "none") == 0)
            {
                client_info->crypt_level = 0;
            }
            else if (g_strcasecmp(value, "low") == 0)
            {
                client_info->crypt_level = 1;
            }
            else if (g_strcasecmp(value, "medium") == 0)
            {
                client_info->crypt_level = 2;
            }
            else if (g_strcasecmp(value, "high") == 0)
            {
                client_info->crypt_level = 3;
            }
            else if (g_strcasecmp(value, "fips") == 0)
            {
                client_info->crypt_level = 4;
            }
            else
            {
                log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured crypt level is "
                          "undefined, 'high' will be used");
                client_info->crypt_level = 3;
            }
        }
        else if (g_strcasecmp(item, "allow_channels") == 0)
        {
            client_info->channels_allowed = g_text2bool(value);
            if (client_info->channels_allowed == 0)
            {
                log_message(LOG_LEVEL_DEBUG,"Info - All channels are disabled");
            }
        }
        else if (g_strcasecmp(item, "allow_multimon") == 0)
                {
                    client_info->multimon = g_text2bool(value);
                    if (client_info->multimon == 0)
                    {
                        log_message(LOG_LEVEL_DEBUG,"Info - Multi monitor server support disabled");
                    }
                }
        else if (g_strcasecmp(item, "max_bpp") == 0)
        {
            client_info->max_bpp = g_atoi(value);
        }
        else if (g_strcasecmp(item, "rfx_min_pixel") == 0)
        {
            client_info->rfx_min_pixel = g_atoi(value);
        }
        else if (g_strcasecmp(item, "new_cursors") == 0)
        {
            client_info->pointer_flags = g_text2bool(value) == 0 ? 2 : 0;
        }
        else if (g_strcasecmp(item, "require_credentials") == 0)
        {
            client_info->require_credentials = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "use_fastpath") == 0)
        {
            if (g_strcasecmp(value, "output") == 0)
            {
                client_info->use_fast_path = 1;
            }
            else if (g_strcasecmp(value, "input") == 0)
            {
                client_info->use_fast_path = 2;
            }
            else if (g_strcasecmp(value, "both") == 0)
            {
                client_info->use_fast_path = 3;
            }
            else if (g_strcasecmp(value, "none") == 0)
            {
                client_info->use_fast_path = 0;
            }
            else
            {
                log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured fastpath level is "
                          "undefined, fastpath will not be used");
                client_info->use_fast_path = 0;
            }
        }
        else if (g_strcasecmp(item, "ssl_protocols") == 0)
        {
            /* put leading/trailing comma to properly detect "TLSv1" without regex */
            tmp_length = g_strlen(value) + 3;
            tmp = g_new(char, tmp_length);
            g_snprintf(tmp, tmp_length, "%s%s%s", ",", value, ",");
            /* replace all spaces with comma */
            /* to accept space after comma */
            while ((pos = g_pos(tmp, " ")) != -1)
            {
                tmp[pos] = ',';
            }
            ssl_get_protocols_from_string(tmp, &(client_info->ssl_protocols));
            g_free(tmp);
        }
        else if (g_strcasecmp(item, "tls_ciphers") == 0)
Ejemplo n.º 19
0
int DEFAULT_CC
printerd_init()
{
	char filename[256];
	struct list *names;
	struct list *values;
	char *name;
	char *value;
	int index;
	int res;

	l_config = g_malloc(sizeof(struct log_config), 1);
	l_config->program_name = g_strdup("printerd");
	l_config->log_file = 0;
	l_config->fd = 0;
	l_config->log_level = LOG_LEVEL_DEBUG;
	l_config->enable_syslog = 0;
	l_config->syslog_level = LOG_LEVEL_DEBUG;

	names = list_create();
	names->auto_free = 1;
	values = list_create();
	values->auto_free = 1;
	g_snprintf(filename, 255, "%s/printerd.ini", XRDP_CFG_PATH);

	if (file_by_name_read_section (filename, PRINTERD_CFG_LOGGING, names, values) == 0) {
		for (index = 0; index < names->count; index++) {
			name = (char *)list_get_item(names, index);
			value = (char *)list_get_item(values, index);
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_DIR)) {
				l_config->log_file = (char *)g_strdup(value);
			}
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_LEVEL)) {
				l_config->log_level = log_text2level(value);
			}
			if (0 ==
			    g_strcasecmp(name, PRINTERD_CFG_LOG_ENABLE_SYSLOG)) {
				l_config->enable_syslog = log_text2bool(value);
			}
			if (0 == g_strcasecmp(name, PRINTERD_CFG_LOG_SYSLOG_LEVEL)) {
				l_config->syslog_level = log_text2level(value);
			}
		}
	}

	if (file_by_name_read_section
	    (filename, PRINTERD_CFG_GLOBAL, names, values) == 0) {
		for (index = 0; index < names->count; index++) {
			name = (char *)list_get_item(names, index);
			value = (char *)list_get_item(values, index);
			if (0 == g_strcasecmp(name, PRINTERD_CFG_GLOBAL_THREAD_COUNT)) {
				thread_count = g_atoi(value);
			}
		}
	}
	list_delete(names);
	list_delete(values);
	res = log_start(l_config);

	if (res != LOG_STARTUP_OK)
	{
		g_printf("xrdp-printerd[printerd_init]: Unable to start log system[%i]\n", res);
		return res;
	}
	else
	{
		return LOG_STARTUP_OK;
	}
}