diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2012-02-02 18:49:06 -0800 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2012-02-02 18:49:06 -0800 |
commit | b36f7d346ccb504547e675b6a0bf31bce75cc175 (patch) | |
tree | 240e897250f1e7adf675cdc233b66e88dca55268 | |
parent | 946d9b257b85d93f13a07453655331427168fdf1 (diff) | |
download | xrdp-proprietary-b36f7d346ccb504547e675b6a0bf31bce75cc175.tar.gz xrdp-proprietary-b36f7d346ccb504547e675b6a0bf31bce75cc175.zip |
add --port command line override
-rw-r--r-- | xrdp/xrdp.c | 201 | ||||
-rw-r--r-- | xrdp/xrdp.h | 3 | ||||
-rw-r--r-- | xrdp/xrdp_listen.c | 18 | ||||
-rw-r--r-- | xrdp/xrdp_types.h | 9 |
4 files changed, 154 insertions, 77 deletions
diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index e10193a9..951a2f12 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -151,11 +151,84 @@ g_loop(void) } /*****************************************************************************/ +int APP_CC +xrdp_process_params(int argc, char** argv, + struct xrdp_startup_params* startup_params) +{ + int index; + char option[128]; + char value[128]; + + index = 1; + while (index < argc) + { + g_strncpy(option, argv[index], 127); + if (index + 1 < argc) + { + g_strncpy(value, argv[index + 1], 127); + } + else + { + value[0] = 0; + } + if ((g_strncasecmp(option, "-help", 255)) == 0 || + (g_strncasecmp(option, "--help", 255)) == 0 || + (g_strncasecmp(option, "-h", 255)) == 0) + { + startup_params->help = 1; + } + else if ((g_strncasecmp(option, "-kill", 255) == 0) || + (g_strncasecmp(option, "--kill", 255) == 0) || + (g_strncasecmp(option, "-k", 255) == 0)) + { + startup_params->kill = 1; + } + else if ((g_strncasecmp(option, "-nodaemon", 255) == 0) || + (g_strncasecmp(option, "--nodaemon", 255) == 0) || + (g_strncasecmp(option, "-nd", 255) == 0) || + (g_strncasecmp(option, "--nd", 255) == 0) || + (g_strncasecmp(option, "-ns", 255) == 0) || + (g_strncasecmp(option, "--ns", 255) == 0)) + { + startup_params->no_daemon = 1; + } + else if ((g_strncasecmp(option, "-v", 255) == 0) || + (g_strncasecmp(option, "--version", 255) == 0)) + { + startup_params->version = 1; + } + else if ((g_strncasecmp(option, "-p", 255) == 0) || + (g_strncasecmp(option, "--port", 255) == 0)) + { + index++; + g_strncpy(startup_params->port, value, 127); + if (g_strlen(startup_params->port) < 1) + { + g_writeln("error processing params, port [%s]", startup_params->port); + return 1; + } + else + { + g_writeln("--port parameter found, ini override [%s]", + startup_params->port); + } + } + else + { + return 1; + } + index++; + } + return 0; +} + +/*****************************************************************************/ int DEFAULT_CC main(int argc, char** argv) { int test; int host_be; + struct xrdp_startup_params* startup_params; int pid; int fd; int no_daemon; @@ -198,88 +271,73 @@ main(int argc, char** argv) g_writeln("unusable tui64 size, must be 8"); return 0; } + + startup_params = (struct xrdp_startup_params*) + g_malloc(sizeof(struct xrdp_startup_params), 1); + if (xrdp_process_params(argc, argv, startup_params) != 0) + { + g_writeln("Unknown Parameter"); + g_writeln("xrdp -h for help"); + g_writeln(""); + g_exit(0); + } + g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH); no_daemon = 0; - if (argc == 2) + + if (startup_params->kill) { - 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("stopping xrdp"); + /* read the xrdp.pid file */ + fd = -1; + if (g_file_exist(pid_file)) /* xrdp.pid */ { - 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); + fd = g_file_open(pid_file); /* xrdp.pid */ } - else if ((g_strncasecmp(argv[1], "-v", 255) == 0) || - (g_strncasecmp(argv[1], "--version", 255) == 0)) + if (fd == -1) { - 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); + g_writeln("problem opening to xrdp.pid"); + g_writeln("maybe its not running"); } else { - g_writeln("Unknown Parameter"); - g_writeln("xrdp -h for help"); - g_writeln(""); - g_exit(0); + 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 (argc > 1) + if (startup_params->no_daemon) { - g_writeln("Unknown Parameter"); - g_writeln("xrdp -h for help"); + 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(" -h: show help"); + g_writeln(" -nodaemon: don't fork into background"); + g_writeln(" -kill: shut down xrdp"); + g_writeln(""); + 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",PACKAGE_VERSION); g_writeln(""); g_exit(0); } @@ -365,7 +423,7 @@ main(int argc, char** argv) { g_writeln("error creating g_term_event"); } - xrdp_listen_main_loop(g_listen); + xrdp_listen_main_loop(g_listen, startup_params); xrdp_listen_delete(g_listen); tc_mutex_delete(g_sync_mutex); tc_mutex_delete(g_sync1_mutex); @@ -373,5 +431,6 @@ main(int argc, char** argv) g_delete_wait_obj(g_sync_event); /* delete the xrdp.pid file */ g_file_delete(pid_file); + g_free(startup_params); return 0; } diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h index 0c91f52a..094fd4bd 100644 --- a/xrdp/xrdp.h +++ b/xrdp/xrdp.h @@ -150,7 +150,8 @@ xrdp_listen_create(void); void APP_CC xrdp_listen_delete(struct xrdp_listen* self); int APP_CC -xrdp_listen_main_loop(struct xrdp_listen* self); +xrdp_listen_main_loop(struct xrdp_listen* self, + struct xrdp_startup_params* startup_param); /* xrdp_region.c */ struct xrdp_region* APP_CC diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 7edaddcb..23f532a8 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -47,7 +47,7 @@ xrdp_listen_create(void) self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16); if (self->listen_trans == 0) { - g_writeln("xrdp_listen_main_loop: trans_create failed"); + g_writeln("xrdp_listen_create: trans_create failed"); } return self; } @@ -120,7 +120,8 @@ xrdp_process_run(void* in_val) /*****************************************************************************/ static int xrdp_listen_get_port_address(char* port, int port_bytes, - char* address, int address_bytes) + char* address, int address_bytes, + struct xrdp_startup_params* startup_param) { int fd; int error; @@ -171,6 +172,11 @@ xrdp_listen_get_port_address(char* port, int port_bytes, list_delete(values); g_file_close(fd); } + /* startup_param overrides */ + if (startup_param->port[0] != 0) + { + g_strncpy(port, startup_param->port, port_bytes - 1); + } return 0; } @@ -202,13 +208,14 @@ xrdp_listen_conn_in(struct trans* self, struct trans* new_self) /*****************************************************************************/ /* wait for incoming connections */ int APP_CC -xrdp_listen_main_loop(struct xrdp_listen* self) +xrdp_listen_main_loop(struct xrdp_listen* self, + struct xrdp_startup_params* startup_param) { int error; int robjs_count; int cont; int timeout = 0; - char port[8]; + char port[128]; char address[256]; tbus robjs[8]; tbus term_obj; @@ -218,7 +225,8 @@ xrdp_listen_main_loop(struct xrdp_listen* self) self->status = 1; if (xrdp_listen_get_port_address(port, sizeof(port), - address, sizeof(address)) != 0) + address, sizeof(address), + startup_param) != 0) { g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed"); self->status = -1; diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index eb4d0ad0..1a16e1be 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -402,3 +402,12 @@ struct xrdp_mod_data struct list* names; struct list* values; }; + +struct xrdp_startup_params +{ + char port[128]; + int kill; + int no_daemon; + int help; + int version; +}; |