diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-08-20 00:29:09 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-08-20 00:29:09 -0500 |
commit | 57029de2707808c3e7d12568af3de87eaca71828 (patch) | |
tree | 0dd7aca471ffddede7d6ec8d54d075e515a9ca9e /sesman/session.c | |
parent | b62256d54dd71705a29da49bc8ee62d6ebd95230 (diff) | |
parent | c5862f367ca68763dd3070598a36ea82db7f3566 (diff) | |
download | xrdp-proprietary-57029de2707808c3e7d12568af3de87eaca71828.tar.gz xrdp-proprietary-57029de2707808c3e7d12568af3de87eaca71828.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'sesman/session.c')
-rw-r--r-- | sesman/session.c | 171 |
1 files changed, 128 insertions, 43 deletions
diff --git a/sesman/session.c b/sesman/session.c index 81484b80..46037187 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -60,6 +60,40 @@ static char* g_sync_client_ip; static tbus g_sync_data; static tui8 g_sync_type; static int g_sync_result; +static int g_sync_cmd; + +/** + * Creates a string consisting of all parameters that is hosted in the param list + * @param self + * @param outstr, allocate this buffer before you use this function + * @param len the allocated len for outstr + * @return + */ +char* APP_CC +dumpItemsToString(struct list* self, char *outstr, int len) +{ + g_memset(outstr,0,len); + int index; + tbus item; + int totalLen= 0; + + if (self->count == 0) + { + g_writeln("List is empty"); + } + for (index = 0; index < self->count; index++) + { + /* +1 = one space*/ + totalLen = totalLen + g_strlen((char*)list_get_item(self, index))+1; + if(len>totalLen) + { + g_strcat(outstr,(char*)list_get_item(self, index)); + g_strcat(outstr," "); + } + } + return outstr ; +} + /******************************************************************************/ struct session_item* DEFAULT_CC @@ -267,7 +301,7 @@ x_server_running(int display) /******************************************************************************/ static void DEFAULT_CC -session_start_sessvc(int xpid, int wmpid, long data) +session_start_sessvc(int xpid, int wmpid, long data, char* username, int display) { struct list * sessvc_params = (struct list *)NULL; char wmpid_str[25]; @@ -283,7 +317,7 @@ session_start_sessvc(int xpid, int wmpid, long data) /* new style waiting for clients */ g_sprintf(wmpid_str, "%d", wmpid); g_sprintf(xpid_str, "%d", xpid); - log_message(&(g_cfg->log), LOG_LEVEL_INFO, + log_message(LOG_LEVEL_INFO, "starting xrdp-sessvc - xpid=%s - wmpid=%s", xpid_str, wmpid_str); @@ -298,23 +332,25 @@ session_start_sessvc(int xpid, int wmpid, long data) list_add_item(sessvc_params, (long)g_strdup(wmpid_str)); list_add_item(sessvc_params, 0); /* mandatory */ + env_set_user(username, 0, display); + /* executing sessvc */ g_execvp(exe_path, ((char**)sessvc_params->items)); /* should not get here */ - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, + log_message(LOG_LEVEL_ALWAYS, "error starting xrdp-sessvc - pid %d - xpid=%s - wmpid=%s", g_getpid(), xpid_str, wmpid_str); /* logging parameters */ /* no problem calling strerror for thread safety: other threads are blocked */ - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", + log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror()); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list:"); + log_message(LOG_LEVEL_DEBUG, "execve parameter list:"); for (i = 0; i < (sessvc_params->count); i++) { - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s", i, + log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(sessvc_params, i)); } list_delete(sessvc_params); @@ -372,7 +408,7 @@ session_get_aval_display_from_chain(void) display++; } lock_chain_release(); - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "X server -- no display in range is available"); + log_message(LOG_LEVEL_ERROR, "X server -- no display in range is available"); return 0; } @@ -391,7 +427,7 @@ wait_for_xserver(int display) i++; if (i > 60) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, + log_message(LOG_LEVEL_ERROR, "X server for display %d startup timeout", display); break; @@ -474,6 +510,7 @@ session_start_fork(int width, int height, int bpp, char* username, struct list * xserver_params = (struct list *)NULL; time_t ltime; struct tm stime; + char execvpparams[2048]; /* initialize (zero out) local variables: */ g_memset(<ime,0,sizeof(time_t)); @@ -489,7 +526,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star /* check to limit concurrent sessions */ if (g_session_count >= g_cfg->sess.max_sessions) { - log_message(&(g_cfg->log), LOG_LEVEL_INFO, "max concurrent session limit " + log_message(LOG_LEVEL_INFO, "max concurrent session limit " "exceeded. login for user %s denied", username); return 0; } @@ -497,7 +534,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0); if (temp == 0) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new chain " + log_message(LOG_LEVEL_ERROR, "cannot create new chain " "element - user %s", username); return 0; } @@ -505,7 +542,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star if (temp->item == 0) { g_free(temp); - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new session " + log_message(LOG_LEVEL_ERROR, "cannot create new session " "item - user %s", username); return 0; } @@ -599,7 +636,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star if (program[0] != 0) { g_execlp3(program, program, 0); - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, + log_message(LOG_LEVEL_ALWAYS, "error starting program %s for user %s - pid %d", program, username, g_getpid()); } @@ -611,16 +648,16 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star if (g_file_exist(text)) { g_execlp3(text, g_cfg->user_wm, 0); - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting user " + log_message(LOG_LEVEL_ALWAYS,"error starting user " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, " + log_message(LOG_LEVEL_DEBUG, "errno: %d, " "description: %s", errno, g_get_strerror()); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter " + log_message(LOG_LEVEL_DEBUG,"execlp3 parameter " "list:"); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", + log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", + log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->user_wm); } } @@ -629,25 +666,25 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); g_execlp3(text, g_cfg->default_wm, 0); - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting default " + log_message( LOG_LEVEL_ALWAYS,"error starting default " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: " + log_message( LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:"); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", + log_message(LOG_LEVEL_DEBUG,"execlp3 parameter list:"); + log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", + log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->default_wm); /* still a problem starting window manager just start xterm */ g_execlp3("xterm", "xterm", 0); /* should not get here */ - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting xterm " + log_message(LOG_LEVEL_ALWAYS,"error starting xterm " "for user %s - pid %d", username, g_getpid()); /* logging parameters */ - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: " + log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); } else @@ -656,7 +693,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "another Xserver is " "already active on display %d", display); } - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"aborting connection..."); + log_message(LOG_LEVEL_DEBUG,"aborting connection..."); g_exit(0); } else /* parent (child sesman) */ @@ -691,6 +728,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star /* make sure it ends with a zero */ list_add_item(xserver_params, 0); pp1 = (char**)xserver_params->items; + log_message(LOG_LEVEL_INFO,"Xvnc start:%s",dumpItemsToString(xserver_params, execvpparams, 2048)); g_execvp("Xvnc", pp1); } else if (type == SESMAN_SESSION_TYPE_XRDP) @@ -743,24 +781,24 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star } else { - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "bad session type - " + log_message(LOG_LEVEL_ALWAYS, "bad session type - " "user %s - pid %d", username, g_getpid()); g_exit(1); } /* should not get here */ - log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "error starting X server " + log_message(LOG_LEVEL_ALWAYS, "error starting X server " "- user %s - pid %d", username, g_getpid()); /* logging parameters */ - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: " + log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list: " + log_message(LOG_LEVEL_DEBUG, "execve parameter list size: " "%d", (xserver_params)->count); for (i=0; i<(xserver_params->count); i++) { - log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s", + log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(xserver_params, i)); } list_delete(xserver_params); @@ -777,7 +815,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star g_snprintf(text, 255, ":%d.0", display); g_setenv("DISPLAY", text, 1); /* new style waiting for clients */ - session_start_sessvc(xpid, wmpid, data); + session_start_sessvc(xpid, wmpid, data, username, display); } } } @@ -813,6 +851,31 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 260.0] In session_star } /******************************************************************************/ +/* called with the main thread */ +static int APP_CC +session_reconnect_fork(int display, char* username) +{ + int pid; + char text[256]; + + pid = g_fork(); + if (pid == -1) + { + } + else if (pid == 0) + { + env_set_user(username, 0, display); + g_snprintf(text, 255, "%s/%s", XRDP_CFG_PATH, "reconnectwm.sh"); + if (g_file_exist(text)) + { + g_execlp3(text, g_cfg->default_wm, 0); + } + g_exit(0); + } + return display; +} + +/******************************************************************************/ /* called by a worker thread, ask the main thread to call session_sync_start and wait till done */ int DEFAULT_CC @@ -826,6 +889,7 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 258.0] In session_star /* lock mutex */ lock_sync_acquire(); /* set shared vars */ + g_sync_cmd = 0; g_sync_width = width; g_sync_height = height; g_sync_bpp = bpp; @@ -849,6 +913,27 @@ log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "[RAJA DEBUG 258.0] In session_star } /******************************************************************************/ +/* called by a worker thread, ask the main thread to call session_sync_start + and wait till done */ +int DEFAULT_CC +session_reconnect(int display, char* username) +{ + /* lock mutex */ + lock_sync_acquire(); + /* set shared vars */ + g_sync_cmd = 1; + g_sync_width = display; + g_sync_username = username; + /* set event for main thread to see */ + g_set_wait_obj(g_sync_event); + /* wait for main thread to get done */ + lock_sync_sem_acquire(); + /* unlock mutex */ + lock_sync_release(); + return 0; +} + +/******************************************************************************/ /* called with the main thread */ int APP_CC session_sync_start(void) @@ -879,7 +964,7 @@ session_kill(int pid) { if (tmp->item == 0) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for " + log_message(LOG_LEVEL_ERROR, "session descriptor for " "pid %d is null!", pid); if (prev == 0) { @@ -899,7 +984,7 @@ session_kill(int pid) if (tmp->item->pid == pid) { /* deleting the session */ - log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip); + log_message(LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip); g_free(tmp->item); if (prev == 0) { @@ -943,7 +1028,7 @@ session_sigkill_all() { if (tmp->item == 0) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "found null session " + log_message(LOG_LEVEL_ERROR, "found null session " "descriptor!"); } else @@ -969,7 +1054,7 @@ session_get_bypid(int pid) dummy = g_malloc(sizeof(struct session_item), 1); if (0 == dummy) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "internal error", pid); + log_message(LOG_LEVEL_ERROR, "internal error", pid); return 0; } @@ -981,7 +1066,7 @@ session_get_bypid(int pid) { if (tmp->item == 0) { - log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for " + log_message(LOG_LEVEL_ERROR, "session descriptor for " "pid %d is null!", pid); /*THREAD-FIX release chain lock */ lock_chain_release(); @@ -1015,7 +1100,7 @@ session_get_byuser(char* user, int* cnt, unsigned char flags) int count; int index; - count=0; + count = 0; /*THREAD-FIX require chain lock */ lock_chain_acquire(); @@ -1023,10 +1108,10 @@ session_get_byuser(char* user, int* cnt, unsigned char flags) tmp = g_sessions; while (tmp != 0) { - LOG_DBG(&(g_cfg->log), "user: %s", user); + LOG_DBG("user: %s", user); if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256))) { - LOG_DBG(&(g_cfg->log), "session_get_byuser: status=%d, flags=%d, " + LOG_DBG("session_get_byuser: status=%d, flags=%d, " "result=%d", (tmp->item->status), flags, ((tmp->item->status) & flags)); if ((tmp->item->status) & flags) @@ -1039,9 +1124,9 @@ session_get_byuser(char* user, int* cnt, unsigned char flags) tmp=tmp->next; } - if (count==0) + if (count == 0) { - (*cnt)=0; + (*cnt) = 0; /*THREAD-FIX release chain lock */ lock_chain_release(); return 0; @@ -1049,9 +1134,9 @@ session_get_byuser(char* user, int* cnt, unsigned char flags) /* malloc() an array of disconnected sessions */ sess=g_malloc(count * sizeof(struct SCP_DISCONNECTED_SESSION),1); - if (sess==0) + if (sess == 0) { - (*cnt)=0; + (*cnt) = 0; /*THREAD-FIX release chain lock */ lock_chain_release(); return 0; |