/* send the file size from server to the client */ static int clipboard_send_file_size(int streamId, int lindex) { struct stream *s; int size; int rv; int file_size; struct cb_file_info *cfi; if (g_files_list == 0) { log_error("clipboard_send_file_size: error g_files_list is nil"); return 1; } cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex); if (cfi == 0) { log_error("clipboard_send_file_size: error cfi is nil"); return 1; } file_size = cfi->size; log_debug("clipboard_send_file_size: streamId %d file_size %d", streamId, file_size); make_stream(s); init_stream(s, 8192); out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */ out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */ out_uint32_le(s, 12); out_uint32_le(s, streamId); out_uint32_le(s, file_size); out_uint32_le(s, 0); out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; }
/* its the responsibility of the caller to free passwd_file */ int env_set_user(const char *username, char **passwd_file, int display, const struct list *env_names, const struct list *env_values) { int error; int pw_uid; int pw_gid; int uid; int index; int len; char *name; char *value; char *pw_shell; char *pw_dir; char text[256]; char hostname[256]; pw_shell = 0; pw_dir = 0; error = g_getuser_info(username, &pw_gid, &pw_uid, &pw_shell, &pw_dir, 0); if (error == 0) { g_rm_temp_dir(); error = g_setgid(pw_gid); if (error == 0) { error = g_initgroups(username, pw_gid); } if (error == 0) { uid = pw_uid; error = g_setuid(uid); } g_mk_socket_path(0); if (error == 0) { g_clearenv(); g_setenv("SHELL", pw_shell, 1); g_setenv("PATH", "/sbin:/bin:/usr/bin:/usr/local/bin", 1); g_setenv("USER", username, 1); g_setenv("LOGNAME", username, 1); g_sprintf(text, "%d", uid); g_setenv("UID", text, 1); g_setenv("HOME", pw_dir, 1); g_set_current_dir(pw_dir); g_sprintf(text, ":%d.0", display); g_setenv("DISPLAY", text, 1); g_setenv("XRDP_SESSION", "1", 1); /* XRDP_SOCKET_PATH should be set even here, chansrv uses this */ g_setenv("XRDP_SOCKET_PATH", XRDP_SOCKET_PATH, 1); /* pulse sink socket */ g_snprintf(text, sizeof(text) - 1, CHANSRV_PORT_OUT_BASE_STR, display); g_setenv("XRDP_PULSE_SINK_SOCKET", text, 1); /* pulse source socket */ g_snprintf(text, sizeof(text) - 1, CHANSRV_PORT_IN_BASE_STR, display); g_setenv("XRDP_PULSE_SOURCE_SOCKET", text, 1); if ((env_names != 0) && (env_values != 0) && (env_names->count == env_values->count)) { for (index = 0; index < env_names->count; index++) { name = (char *) list_get_item(env_names, index), value = (char *) list_get_item(env_values, index), g_setenv(name, value, 1); } } g_gethostname(hostname, 255); hostname[255] = 0; if (passwd_file != 0) { if (0 == g_cfg->auth_file_path) { /* if no auth_file_path is set, then we go for $HOME/.vnc/sesman_passwd-USERNAME@HOSTNAME:DISPLAY */ if (!g_directory_exist(".vnc")) { if (g_mkdir(".vnc") < 0) { log_message(LOG_LEVEL_ERROR, "Error creating .vnc directory: %s", g_get_strerror()); } } len = g_snprintf(NULL, 0, "%s/.vnc/sesman_passwd-%s@%s:%d", pw_dir, username, hostname, display); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { /* Try legacy names first, remove if found */ g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd:%d", pw_dir, username, display); if (g_file_exist(*passwd_file)) { log_message(LOG_LEVEL_WARNING, "Removing old " "password file %s", *passwd_file); g_file_delete(*passwd_file); } g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd", pw_dir, username); if (g_file_exist(*passwd_file)) { log_message(LOG_LEVEL_WARNING, "Removing insecure " "password file %s", *passwd_file); g_file_delete(*passwd_file); } g_sprintf(*passwd_file, "%s/.vnc/sesman_passwd-%s@%s:%d", pw_dir, username, hostname, display); } } else { /* we use auth_file_path as requested */ len = g_snprintf(NULL, 0, g_cfg->auth_file_path, username); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { g_sprintf(*passwd_file, g_cfg->auth_file_path, username); } } if (*passwd_file != NULL) { LOG_DBG("pass file: %s", *passwd_file); } } g_free(pw_dir); g_free(pw_shell); } } else { log_message(LOG_LEVEL_ERROR, "error getting user info for user %s", username); } return error; }
int APP_CC xrdp_mm_connect(struct xrdp_mm* self) { struct list* names = (struct list *)NULL; struct list* values = (struct list *)NULL; int index = 0; int count = 0; int use_sesman = 0; int error = 0; int ok = 0; int rv = 0; char* name = (char *)NULL; char* value = (char *)NULL; char ip[256]; char errstr[256]; char text[256]; char port[8]; g_memset(ip,0,sizeof(char) * 256); g_memset(errstr,0,sizeof(char) * 256); g_memset(text,0,sizeof(char) * 256); g_memset(port,0,sizeof(char) * 8); rv = 0; use_sesman = 0; names = self->login_names; values = self->login_values; count = names->count; for (index = 0; index < count; index++) { name = (char*)list_get_item(names, index); value = (char*)list_get_item(values, index); if (g_strcasecmp(name, "ip") == 0) { g_strncpy(ip, value, 255); } else if (g_strcasecmp(name, "port") == 0) { if (g_strcasecmp(value, "-1") == 0) { use_sesman = 1; } } } if (use_sesman) { ok = 0; errstr[0] = 0; trans_delete(self->sesman_trans); self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); xrdp_mm_get_sesman_port(port, sizeof(port)); g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port); xrdp_wm_log_msg(self->wm, text); self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in; self->sesman_trans->header_size = 8; self->sesman_trans->callback_data = self; /* try to connect up to 4 times */ for (index = 0; index < 4; index++) { if (trans_connect(self->sesman_trans, ip, port, 3000) == 0) { self->sesman_trans_up = 1; ok = 1; break; } g_sleep(1000); g_writeln("xrdp_mm_connect: connect failed " "trying again..."); } if (ok) { /* fully connect */ xrdp_wm_log_msg(self->wm, "sesman connect ok"); self->connected_state = 1; rv = xrdp_mm_send_login(self); } else { xrdp_wm_log_msg(self->wm, errstr); trans_delete(self->sesman_trans); self->sesman_trans = 0; self->sesman_trans_up = 0; rv = 1; } } else /* no sesman */ { if (xrdp_mm_setup_mod1(self) == 0) { if (xrdp_mm_setup_mod2(self) == 0) { xrdp_wm_set_login_mode(self->wm, 10); } } if (self->wm->login_mode != 10) { xrdp_wm_set_login_mode(self->wm, 11); xrdp_mm_module_cleanup(self); } } self->sesman_controlled = use_sesman; return rv; }
static int APP_CC xrdp_mm_setup_mod2(struct xrdp_mm* self) { char text[256]; char* name = (char *)NULL; char* value = (char *)NULL; int i = 0; int rv = 0; int key_flags = 0; int device_flags = 0; g_memset(text,0,sizeof(char) * 256); rv = 1; text[0] = 0; if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event)) { if (self->mod->mod_start(self->mod, self->wm->screen->width, self->wm->screen->height, self->wm->screen->bpp) != 0) { g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */ } } if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event)) { if (self->display > 0) { if (self->code == 0) /* Xvnc */ { g_snprintf(text, 255, "%d", 5900 + self->display); } else if (self->code == 10) /* X11rdp */ { g_snprintf(text, 255, "%d", 6200 + self->display); } else { g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */ } } } if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event)) { /* this adds the port to the end of the list, it will already be in the list as -1 the module should use the last one */ if (g_strlen(text) > 0) { list_add_item(self->login_names, (long)g_strdup("port")); list_add_item(self->login_values, (long)g_strdup(text)); } /* always set these */ name = self->wm->session->client_info->hostname; self->mod->mod_set_param(self->mod, "hostname", name); g_snprintf(text, 255, "%d", self->wm->session->client_info->keylayout); self->mod->mod_set_param(self->mod, "keylayout", text); for (i = 0; i < self->login_names->count; i++) { name = (char*)list_get_item(self->login_names, i); value = (char*)list_get_item(self->login_values, i); self->mod->mod_set_param(self->mod, name, value); } /* connect */ if (self->mod->mod_connect(self->mod) == 0) { rv = 0; } else { // AUDIT connected Failed AUDIT_FAILED_OPEN( self->wm->pro_layer, "" ); } } if (rv == 0) { // AUDIT connected Ok AUDIT_OPEN( self->wm->pro_layer, "" ); /* sync modifiers */ key_flags = 0; device_flags = 0; if (self->wm->scroll_lock) { key_flags |= 1; } if (self->wm->num_lock) { key_flags |= 2; } if (self->wm->caps_lock) { key_flags |= 4; } if (self->mod != 0) { if (self->mod->mod_event != 0) { self->mod->mod_event(self->mod, 17, key_flags, device_flags, key_flags, device_flags); } } } return rv; }
static int APP_CC xrdp_mm_send_login(struct xrdp_mm* self) { struct stream * s = (struct stream *)NULL; int rv = 0; int index = 0; int count = 0; char * username = (char *)NULL; char * password = (char *)NULL; char * name = (char *)NULL; char * value = (char *)NULL; xrdp_wm_log_msg(self->wm, "sending login info to session manager, " "please wait..."); username = 0; password = 0; self->code = 0; count = self->login_names->count; for (index = 0; index < count; index++) { name = (char*)list_get_item(self->login_names, index); value = (char*)list_get_item(self->login_values, index); if (g_strcasecmp(name, "username") == 0) { username = value; } else if (g_strcasecmp(name, "password") == 0) { password = value; } else if (g_strcasecmp(name, "lib") == 0) { if ((g_strcasecmp(value, "libxup.so") == 0) || (g_strcasecmp(value, "xup.dll") == 0)) { self->code = 10; } } } if ((username == 0) || (password == 0)) { xrdp_wm_log_msg(self->wm, "Error finding username and password"); return 1; } s = trans_get_out_s(self->sesman_trans, 8192); s_push_layer(s, channel_hdr, 8); /* this code is either 0 for Xvnc or 10 for X11rdp */ out_uint16_be(s, self->code); index = g_strlen(username); out_uint16_be(s, index); out_uint8a(s, username, index); index = g_strlen(password); out_uint16_be(s, index); out_uint8a(s, password, index); out_uint16_be(s, self->wm->screen->width); out_uint16_be(s, self->wm->screen->height); out_uint16_be(s, self->wm->screen->bpp); /* send domain */ index = g_strlen(self->wm->client_info->domain); out_uint16_be(s, index); out_uint8a(s, self->wm->client_info->domain, index); /* send program / shell */ index = g_strlen(self->wm->client_info->program); out_uint16_be(s, index); out_uint8a(s, self->wm->client_info->program, index); /* send directory */ index = g_strlen(self->wm->client_info->directory); out_uint16_be(s, index); out_uint8a(s, self->wm->client_info->directory, index); /* send client ip */ index = g_strlen(self->wm->client_info->client_ip); out_uint16_be(s, index); out_uint8a(s, self->wm->client_info->client_ip, index); s_mark_end(s); s_pop_layer(s, channel_hdr); out_uint32_be(s, 0); /* version */ index = (int)(s->end - s->data); out_uint32_be(s, index); /* size */ rv = trans_force_write(self->sesman_trans); if (rv != 0) { xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed"); } return rv; }
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; }
void progressive_display_split_and_merge(struct list* self) { int i, j; struct update_rect* item1; struct update_rect* item2; struct xrdp_rect first; struct xrdp_rect second; bool merged = true; bool remove; while (merged) { merged = false; for (i = 0; i < self->count; i++) { item1 = (struct update_rect*) list_get_item(self, i); first = item1->rect; for (j = self->count - 1; j > i; j--) { item2 = (struct update_rect*) list_get_item(self, j); second = item2->rect; if (item1->quality_already_send == item2->quality_already_send) { if (!rect_equal(&first, &second)) { int adj = rect_adjacency(&first, &second); switch (adj) { case 0: break; case 1: // first is at right of second merged = true; if (rect_height(&first) == rect_height(&second)) { item1->rect.left = item2->rect.left; list_remove_item(self, j); } else { progressive_display_rect_split_h(self, item1, item2, &remove); if (remove) { list_remove_item(self, j); list_remove_item(self, i); } else merged = false; } break; case 2: // first is at left of second merged = true; if (rect_height(&first) == rect_height(&second)) { item1->rect.right = item2->rect.right; list_remove_item(self, j); } else { progressive_display_rect_split_h(self, item2, item1, &remove); if (remove) { list_remove_item(self, j); list_remove_item(self, i); } else merged = false; } break; case 3: // first is under second merged = true; if (rect_width(&first) == rect_width(&second)) { item1->rect.top = item2->rect.top; list_remove_item(self, j); } else { progressive_display_rect_split_v(self, item1, item2, &remove); if (remove) { list_remove_item(self, j); list_remove_item(self, i); } else merged = false; } break; case 4: // first is above second merged = true; if (rect_width(&first) == rect_width(&second)) { item1->rect.bottom = item2->rect.bottom; list_remove_item(self, j); } else { progressive_display_rect_split_v(self, item2, item1, &remove); if (remove) { list_remove_item(self, j); list_remove_item(self, i); } else merged = false; } break; } } else { list_remove_item(self, j); merged = true; } } else { merged = false; } if (merged) break; } if (merged) break; } } }
/* called with the main thread */ static int APP_CC session_start_fork(int width, int height, int bpp, char *username, char *password, tbus data, tui8 type, char *domain, char *program, char *directory, char *client_ip) { int display = 0; int pid = 0; int wmpid = 0; int xpid = 0; int i = 0; char geometry[32]; char depth[32]; char screen[32]; char text[256]; char passwd_file[256]; char **pp1 = (char **)NULL; struct session_chain *temp = (struct session_chain *)NULL; 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)); g_memset(&stime, 0, sizeof(struct tm)); g_memset(geometry, 0, sizeof(char) * 32); g_memset(depth, 0, sizeof(char) * 32); g_memset(screen, 0, sizeof(char) * 32); g_memset(text, 0, sizeof(char) * 256); g_memset(passwd_file, 0, sizeof(char) * 256); /* check to limit concurrent sessions */ if (g_session_count >= g_cfg->sess.max_sessions) { log_message(LOG_LEVEL_INFO, "max concurrent session limit " "exceeded. login for user %s denied", username); return 0; } temp = (struct session_chain *)g_malloc(sizeof(struct session_chain), 0); if (temp == 0) { log_message(LOG_LEVEL_ERROR, "cannot create new chain " "element - user %s", username); return 0; } temp->item = (struct session_item *)g_malloc(sizeof(struct session_item), 0); if (temp->item == 0) { g_free(temp); log_message(LOG_LEVEL_ERROR, "cannot create new session " "item - user %s", username); return 0; } display = session_get_aval_display_from_chain(); if (display == 0) { g_free(temp->item); g_free(temp); return 0; } pid = g_fork(); if (pid == -1) { } else if (pid == 0) /* child sesman */ { g_tcp_close(g_sck); g_tcp_close(g_thread_sck); auth_start_session(data, display); g_sprintf(geometry, "%dx%d", width, height); g_sprintf(depth, "%d", bpp); g_sprintf(screen, ":%d", display); wmpid = g_fork(); if (wmpid == -1) { } else if (wmpid == 0) /* child (child sesman) xserver */ { wait_for_xserver(display); env_set_user(username, 0, display); if (x_server_running(display)) { auth_set_env(data); if (directory != 0) { if (directory[0] != 0) { g_set_current_dir(directory); } } if (program != 0) { if (program[0] != 0) { g_execlp3(program, program, 0); log_message(LOG_LEVEL_ALWAYS, "error starting program %s for user %s - pid %d", program, username, g_getpid()); } } /* try to execute user window manager if enabled */ if (g_cfg->enable_user_wm) { g_sprintf(text, "%s/%s", g_getenv("HOME"), g_cfg->user_wm); if (g_file_exist(text)) { g_execlp3(text, g_cfg->user_wm, 0); log_message(LOG_LEVEL_ALWAYS, "error starting user " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, " "description: %s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execlp3 parameter " "list:"); log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->user_wm); } } /* if we're here something happened to g_execlp3 so we try running the default window manager */ g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); g_execlp3(text, g_cfg->default_wm, 0); log_message( LOG_LEVEL_ALWAYS, "error starting default " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message( LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:"); log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); 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(LOG_LEVEL_ALWAYS, "error starting xterm " "for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); } else { log_message(LOG_LEVEL_ERROR, "another Xserver might " "already be active on display %d - see log", display); } log_message(LOG_LEVEL_DEBUG, "aborting connection..."); g_exit(0); } else /* parent (child sesman) */ { xpid = g_fork(); if (xpid == -1) { } else if (xpid == 0) /* child */ { env_set_user(username, passwd_file, display); env_check_password_file(passwd_file, password); if (type == SESMAN_SESSION_TYPE_XVNC) { xserver_params = list_create(); xserver_params->auto_free = 1; /* these are the must have parameters */ list_add_item(xserver_params, (long)g_strdup("Xvnc")); list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (long)g_strdup(depth)); list_add_item(xserver_params, (long)g_strdup("-rfbauth")); list_add_item(xserver_params, (long)g_strdup(passwd_file)); /* additional parameters from sesman.ini file */ //config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC, // xserver_params); list_append_list_strdup(g_cfg->vnc_params, xserver_params, 0); /* 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) { xserver_params = list_create(); xserver_params->auto_free = 1; /* these are the must have parameters */ list_add_item(xserver_params, (long)g_strdup("X11rdp")); list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (long)g_strdup(depth)); /* additional parameters from sesman.ini file */ //config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP, // xserver_params); list_append_list_strdup(g_cfg->rdp_params, xserver_params, 0); /* make sure it ends with a zero */ list_add_item(xserver_params, 0); pp1 = (char **)xserver_params->items; log_message(LOG_LEVEL_INFO, "X11rdp start:%s", dumpItemsToString(xserver_params, execvpparams, 2048)); g_execvp("X11rdp", pp1); } else { log_message(LOG_LEVEL_ALWAYS, "bad session type - " "user %s - pid %d", username, g_getpid()); g_exit(1); } /* should not get here */ log_message(LOG_LEVEL_ALWAYS, "error starting X server " "- user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execve parameter list size: " "%d", (xserver_params)->count); for (i = 0; i < (xserver_params->count); i++) { log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char *)list_get_item(xserver_params, i)); } list_delete(xserver_params); g_exit(1); } else /* parent (child sesman)*/ { wait_for_xserver(display); g_snprintf(text, 255, "%d", display); g_setenv("XRDP_SESSVC_DISPLAY", text, 1); g_snprintf(text, 255, ":%d.0", display); g_setenv("DISPLAY", text, 1); /* new style waiting for clients */ session_start_sessvc(xpid, wmpid, data, username, display); } } } else /* parent sesman process */ { temp->item->pid = pid; temp->item->display = display; temp->item->width = width; temp->item->height = height; temp->item->bpp = bpp; temp->item->data = data; g_strncpy(temp->item->client_ip, client_ip, 255); /* store client ip data */ g_strncpy(temp->item->name, username, 255); ltime = g_time1(); localtime_r(<ime, &stime); temp->item->connect_time.year = (tui16)(stime.tm_year + 1900); temp->item->connect_time.month = (tui8)stime.tm_mon; temp->item->connect_time.day = (tui8)stime.tm_mday; temp->item->connect_time.hour = (tui8)stime.tm_hour; temp->item->connect_time.minute = (tui8)stime.tm_min; zero_time(&(temp->item->disconnect_time)); zero_time(&(temp->item->idle_time)); temp->item->type = type; temp->item->status = SESMAN_SESSION_STATUS_ACTIVE; temp->next = g_sessions; g_sessions = temp; g_session_count++; } return display; }
/* send a chunk of the file from server to client */ static int clipboard_send_file_data(int streamId, int lindex, int nPositionLow, int cbRequested) { struct stream *s; int size; int rv; int fd; char full_fn[256]; struct cb_file_info *cfi; if (g_files_list == 0) { log_error("clipboard_send_file_data: error g_files_list is nil"); return 1; } cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex); if (cfi == 0) { log_error("clipboard_send_file_data: error cfi is nil"); return 1; } log_debug("clipboard_send_file_data: streamId %d lindex %d " "nPositionLow %d cbRequested %d", streamId, lindex, nPositionLow, cbRequested); g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename); fd = g_file_open_ex(full_fn, 1, 0, 0, 0); if (fd == -1) { log_error("clipboard_send_file_data: file open [%s] failed", full_fn); return 1; } if (g_file_seek(fd, nPositionLow) < 0) { log_message(LOG_LEVEL_ERROR, "clipboard_send_file_data: seek error " "in file: %s", full_fn); g_file_close(fd); return 1; } make_stream(s); init_stream(s, cbRequested + 64); size = g_file_read(fd, s->data + 12, cbRequested); if (size < 1) { log_error("clipboard_send_file_data: read error, want %d got %d", cbRequested, size); free_stream(s); g_file_close(fd); return 1; } out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */ out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */ out_uint32_le(s, size + 4); out_uint32_le(s, streamId); s->p += size; out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); g_file_close(fd); return rv; }
/* its the responsibility of the caller to free passwd_file */ int DEFAULT_CC env_set_user(const char *username, char **passwd_file, int display, const struct list *env_names, const struct list *env_values) { int error; int pw_uid; int pw_gid; int uid; int index; int len; char *name; char *value; char *pw_shell; char *pw_dir; char text[256]; pw_shell = 0; pw_dir = 0; error = g_getuser_info(username, &pw_gid, &pw_uid, &pw_shell, &pw_dir, 0); if (error == 0) { g_rm_temp_dir(); error = g_setgid(pw_gid); if (error == 0) { error = g_initgroups(username, pw_gid); } if (error == 0) { uid = pw_uid; error = g_setuid(uid); } g_mk_temp_dir(0); if (error == 0) { g_clearenv(); g_setenv("SHELL", pw_shell, 1); g_setenv("PATH", "/sbin:/bin:/usr/bin:/usr/local/bin", 1); g_setenv("USER", username, 1); g_sprintf(text, "%d", uid); g_setenv("UID", text, 1); g_setenv("HOME", pw_dir, 1); g_set_current_dir(pw_dir); g_sprintf(text, ":%d.0", display); g_setenv("DISPLAY", text, 1); g_setenv("XRDP_SESSION", "1", 1); if ((env_names != 0) && (env_values != 0) && (env_names->count == env_values->count)) { for (index = 0; index < env_names->count; index++) { name = (char *) list_get_item(env_names, index), value = (char *) list_get_item(env_values, index), g_setenv(name, value, 1); } } if (passwd_file != 0) { if (0 == g_cfg->auth_file_path) { /* if no auth_file_path is set, then we go for $HOME/.vnc/sesman_username_passwd:DISPLAY */ if (!g_directory_exist(".vnc")) { if (g_mkdir(".vnc") < 0) { log_message(LOG_LEVEL_ERROR, "Error creating .vnc directory: %s", g_get_strerror()); } } len = g_snprintf(NULL, 0, "%s/.vnc/sesman_%s_passwd:%d", pw_dir, username, display); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { /* Try legacy name first, remove if found */ g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd", pw_dir, username); if (g_file_exist(*passwd_file)) { log_message(LOG_LEVEL_WARNING, "Removing insecure " "password file %s", *passwd_file); g_file_delete(*passwd_file); } g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd:%d", pw_dir, username, display); } } else { /* we use auth_file_path as requested */ len = g_snprintf(NULL, 0, g_cfg->auth_file_path, username); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { g_sprintf(*passwd_file, g_cfg->auth_file_path, username); } } if (*passwd_file != NULL) { LOG_DBG("pass file: %s", *passwd_file); } } g_free(pw_dir); g_free(pw_shell); } } else { log_message(LOG_LEVEL_ERROR, "error getting user info for user %s", username); } return error; }
/* response to client asking for clipboard contents that is file list */ int clipboard_send_data_response_for_file(const char *data, int data_size) { struct stream *s; int size; int rv; int bytes_after_header; int cItems; int flags; int index; tui32 ui32; char fn[256]; struct cb_file_info *cfi; log_debug("clipboard_send_data_response_for_file: data_size %d", data_size); //g_hexdump(data, data_size); if (g_files_list == 0) { g_files_list = list_create(); g_files_list->auto_free = 1; } list_clear(g_files_list); clipboard_get_files(data, data_size); cItems = g_files_list->count; bytes_after_header = cItems * 592 + 4; make_stream(s); init_stream(s, 64 + bytes_after_header); out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */ out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */ out_uint32_le(s, bytes_after_header); out_uint32_le(s, cItems); for (index = 0; index < cItems; index++) { cfi = (struct cb_file_info *)list_get_item(g_files_list, index); flags = CB_FD_ATTRIBUTES | CB_FD_FILESIZE | CB_FD_WRITESTIME | CB_FD_PROGRESSUI; out_uint32_le(s, flags); out_uint8s(s, 32); /* reserved1 */ flags = cfi->flags; out_uint32_le(s, flags); out_uint8s(s, 16); /* reserved2 */ /* file time */ /* 100-nanoseconds intervals since 1 January 1601 */ //out_uint32_le(s, 0x2c305d08); /* 25 October 2009, 21:17 */ //out_uint32_le(s, 0x01ca55f3); ui32 = cfi->time & 0xffffffff; out_uint32_le(s, ui32); ui32 = cfi->time >> 32; out_uint32_le(s, ui32); /* file size */ out_uint32_le(s, 0); out_uint32_le(s, cfi->size); g_snprintf(fn, 255, "%s", cfi->filename); clipboard_out_unicode(s, fn, 256); out_uint8s(s, 8); /* pad */ } out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; }
enum logReturns DEFAULT_CC internal_config_read_logging(int file, struct log_config *lc, struct list *param_n, struct list *param_v, const char *applicationName) { int i; char *buf; char *temp_buf; list_clear(param_v); list_clear(param_n); /* setting defaults */ lc->program_name = applicationName; lc->log_file = 0; lc->fd = 0; lc->log_level = LOG_LEVEL_DEBUG; lc->enable_syslog = 0; lc->syslog_level = LOG_LEVEL_DEBUG; file_read_section(file, SESMAN_CFG_LOGGING, param_n, param_v); for (i = 0; i < param_n->count; i++) { buf = (char *)list_get_item(param_n, i); if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_FILE)) { lc->log_file = g_strdup((char *)list_get_item(param_v, i)); if (lc->log_file != NULL) { if (lc->log_file[0] != '/') { temp_buf = (char *)g_malloc(512, 0); g_snprintf(temp_buf, 511, "%s/%s", XRDP_LOG_PATH, lc->log_file); g_free(lc->log_file); lc->log_file = temp_buf; } } } if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_LEVEL)) { lc->log_level = internal_log_text2level((char *)list_get_item(param_v, i)); } if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG)) { lc->enable_syslog = g_text2bool((char *)list_get_item(param_v, i)); } if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL)) { lc->syslog_level = internal_log_text2level((char *)list_get_item(param_v, i)); } } if (0 == lc->log_file) { lc->log_file = g_strdup("./sesman.log"); } /* try to create path if not exist */ g_create_path(lc->log_file); g_printf("logging configuration:\r\n"); g_printf("\tLogFile: %s\r\n", lc->log_file); g_printf("\tLogLevel: %i\r\n", lc->log_level); g_printf("\tEnableSyslog: %i\r\n", lc->enable_syslog); g_printf("\tSyslogLevel: %i\r\n", lc->syslog_level); return LOG_STARTUP_OK; }
int disk_init() { char filename[256]; char log_filename[256]; struct list* names; struct list* values; char* name; char* value; int index; int display_num; int res; display_num = g_get_display_num_from_display(g_strdup(g_getenv("DISPLAY"))); if(display_num == 0) { g_printf("vchannel_rdpdr[disk_init]: Display must be different of 0\n"); return ERROR; } l_config = g_malloc(sizeof(struct log_config), 1); l_config->program_name = "vchannel_rdpdr"; 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/rdpdr.conf", XRDP_CFG_PATH); if (file_by_name_read_section(filename, RDPDR_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, RDPDR_CFG_NAME)) { if( g_strlen(value) > 1) { l_config->program_name = (char*)g_strdup(value); } } } } if (file_by_name_read_section(filename, RDPDR_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, RDPDR_CFG_LOG_DIR)) { l_config->log_file = (char*)g_strdup(value); } if (0 == g_strcasecmp(name, RDPDR_CFG_LOG_LEVEL)) { l_config->log_level = log_text2level(value); } if (0 == g_strcasecmp(name, RDPDR_CFG_LOG_ENABLE_SYSLOG)) { l_config->enable_syslog = log_text2bool(value); } if (0 == g_strcasecmp(name, RDPDR_CFG_LOG_SYSLOG_LEVEL)) { l_config->syslog_level = log_text2level(value); } } } if( g_strlen(l_config->log_file) > 1 && g_strlen(l_config->program_name) > 1) { g_sprintf(log_filename, "%s/%i/%s.log", l_config->log_file, display_num, l_config->program_name); l_config->log_file = (char*)g_strdup(log_filename); } list_delete(names); list_delete(values); res = log_start(l_config); if( res != LOG_STARTUP_OK) { g_printf("vchannel_rdpdr[rdpdr_init]: Unable to start log system [%i]\n", res); return res; } return LOG_STARTUP_OK; }
int main(int argc, char **argv, char **envp) { char buff[BUFFSIZE]; Toy_Type *any, *result; Toy_Type *script; Toy_Type *err; Bulk *b; Cell *c; Toy_Interp *interp; jmp_buf jmp_env; error_reset: interp = new_interp("main", STACKSIZE, NULL, argc, argv, envp); b = new_bulk(); if (0 == setjmp(jmp_env)) { cstack_set_jmpbuff(0, &jmp_env); } else { fprintf(stderr, "Catch the main co-routine stack overflow, to be restarted.\n"); goto error_reset; } if (argv[1] && (strcmp(argv[1], "-") != 0)) { if (0 == bulk_load_file(b, argv[1])) { fprintf(stderr, "file not open: %s\n", argv[1]); exit(1); } any = toy_parse_start(b); if (NULL == any) { fprintf(stderr, "no memory\n"); exit(1); } switch (GET_TAG(any)) { case EXCEPTION: err = any; fprintf(stderr, "parse error: %s\n", to_string(list_get_item(err->u.exception.msg_list))); exit(0); case SCRIPT: script = any; result = toy_eval_script(interp, script); if (GET_TAG(result) != EXCEPTION) { fprintf(stdout, "result[%s]=> ", toy_get_type_str(result)); fprintf(stdout, "%s\n", to_print(result)); } else { fprintf(stdout, "EXCEPTION: %s\n", to_string(result)); } exit(0); default: fprintf(stderr, "parse error: type=%s\n", toy_get_type_str(any)); exit(1); } } while (! feof(stdin)) { fputs("> ", stderr); if (NULL == fgets(buff, BUFFSIZE, stdin)) break; buff[BUFFSIZE-1] = 0; if (buff[0] == '!') { buff[strlen(buff)-1] = 0; if (0 == bulk_load_file(b, &buff[1])) { fprintf(stderr, "file not open: %s\n", &buff[1]); continue; } } else { bulk_set_string(b, buff); } any = toy_parse_start(b); if (NULL == any) { fprintf(stderr, "no memory\n"); } else { switch (GET_TAG(any)) { case EXCEPTION: err = any; fprintf(stderr, "parse error: %s\n", to_string(list_get_item(err->u.exception.msg_list))); if (cell_eq_str(err->u.exception.code, TE_PARSEBADCHAR) == 0) break; if (buff[0] == '!') break; c = new_cell(buff); while (1) { fputs("=> ", stderr); if (NULL == fgets(buff, BUFFSIZE, stdin)) goto exit_loop; buff[BUFFSIZE-1] = 0; cell_add_str(c, buff); bulk_set_string(b, cell_get_addr(c)); any = toy_parse_start(b); if (GET_TAG(any) == EXCEPTION) { err = any; if (cell_eq_str(err->u.exception.code, TE_PARSEBADCHAR) == 0) { fprintf(stderr, "parse error: %s\n", to_string(list_get_item(err->u.exception.msg_list))); goto next_loop; } } else { break; } } case SCRIPT: script = any; result = toy_eval_script(interp, script); if (GET_TAG(result) != EXCEPTION) { char *p; fprintf(stdout, "result[%s]=> ", toy_get_type_str(result)); p = to_print(result); if (strlen(p) > 512) { fprintf(stdout, "%-.512s ...\n", p); } else { fprintf(stdout, "%s\n", p); } } else { fprintf(stdout, "EXCEPTION: %s\n", to_string(result)); } break; default: fprintf(stderr, "parse error: type=%s\n", toy_get_type_str(any)); } } next_loop: /* dummy */ 0; } exit_loop: return 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)
int cliprdr_init() { char filename[256]; struct list* names; struct list* values; char* name; char* value; int index; int display_num; display_num = g_get_display_num_from_display(g_strdup(g_getenv("DISPLAY"))); if(display_num == 0) { g_printf("cliprdr[cliprdr_init]: Display must be different of 0\n"); return ERROR; } l_config = g_malloc(sizeof(struct log_config), 1); l_config->program_name = "cliprdr"; 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/cliprdr.conf", XRDP_CFG_PATH); if (file_by_name_read_section(filename, CLIPRDR_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, CLIPRDR_CFG_NAME)) { if( g_strlen(value) > 1) { l_config->program_name = (char*)g_strdup(value); } } } } if (file_by_name_read_section(filename, CLIPRDR_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, CLIPRDR_CFG_LOG_LEVEL)) { l_config->log_level = log_text2level(value); } } } list_delete(names); list_delete(values); if(log_start(l_config) != LOG_STARTUP_OK) { g_printf("vchannel[vchannel_init]: Unable to start log system\n"); return ERROR; } else { return LOG_STARTUP_OK; } return 0; }
static void DEFAULT_CC session_start_sessvc(int xpid, int wmpid, long data, char *username, int display) { struct list *sessvc_params = (struct list *)NULL; char wmpid_str[25]; char xpid_str[25]; char exe_path[262]; int i = 0; /* initialize (zero out) local variables: */ g_memset(wmpid_str, 0, sizeof(char) * 25); g_memset(xpid_str, 0, sizeof(char) * 25); g_memset(exe_path, 0, sizeof(char) * 262); /* new style waiting for clients */ g_sprintf(wmpid_str, "%d", wmpid); g_sprintf(xpid_str, "%d", xpid); log_message(LOG_LEVEL_INFO, "starting xrdp-sessvc - xpid=%s - wmpid=%s", xpid_str, wmpid_str); sessvc_params = list_create(); sessvc_params->auto_free = 1; /* building parameters */ g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH); list_add_item(sessvc_params, (long)g_strdup(exe_path)); list_add_item(sessvc_params, (long)g_strdup(xpid_str)); 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(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(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execve parameter list:"); for (i = 0; i < (sessvc_params->count); i++) { log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char *)list_get_item(sessvc_params, i)); } list_delete(sessvc_params); /* keep the old waitpid if some error occurs during execlp */ g_waitpid(wmpid); g_sigterm(xpid); g_sigterm(wmpid); g_sleep(1000); auth_end(data); g_exit(0); }
gg_widget_t *gg_container_get_child(gg_container_t *container, int index) { return list_get_item(container->widget_list, index); }
int APP_CC xrdp_region_subtract_rect(struct xrdp_region* self, struct xrdp_rect* rect) { struct xrdp_rect* r; struct xrdp_rect rect1; int i; for (i = self->rects->count - 1; i >= 0; i--) { r = (struct xrdp_rect*)list_get_item(self->rects, i); rect1 = *r; r = &rect1; if (rect->left <= r->left && rect->top <= r->top && rect->right >= r->right && rect->bottom >= r->bottom) { /* rect is not visible */ list_remove_item(self->rects, i); } else if (rect->right < r->left || rect->bottom < r->top || rect->top > r->bottom || rect->left > r->right) { /* rect are not related */ } else if (rect->left <= r->left && rect->right >= r->right && rect->bottom < r->bottom && rect->top <= r->top) { /* partially covered(whole top) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); } else if (rect->top <= r->top && rect->bottom >= r->bottom && rect->right < r->right && rect->left <= r->left) { /* partially covered(left) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, rect->right, r->top, r->right, r->bottom); } else if (rect->left <= r->left && rect->right >= r->right && rect->top > r->top && rect->bottom >= r->bottom) { /* partially covered(bottom) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); } else if (rect->top <= r->top && rect->bottom >= r->bottom && rect->left > r->left && rect->right >= r->right) { /* partially covered(right) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, rect->left, r->bottom); } else if (rect->left <= r->left && rect->top <= r->top && rect->right < r->right && rect->bottom < r->bottom) { /* partially covered(top left) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, rect->right, r->top, r->right, rect->bottom); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); } else if (rect->left <= r->left && rect->bottom >= r->bottom && rect->right < r->right && rect->top > r->top) { /* partially covered(bottom left) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, rect->right, rect->top, r->right, r->bottom); } else if (rect->left > r->left && rect->right >= r->right && rect->top <= r->top && rect->bottom < r->bottom) { /* partially covered(top right) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, rect->left, r->bottom); xrdp_region_insert_rect(self, i, rect->left, rect->bottom, r->right, r->bottom); } else if (rect->left > r->left && rect->right >= r->right && rect->top > r->top && rect->bottom >= r->bottom) { /* partially covered(bottom right) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, r->left, rect->top, rect->left, r->bottom); } else if (rect->left > r->left && rect->top <= r->top && rect->right < r->right && rect->bottom >= r->bottom) { /* 2 rects, one on each end */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, rect->left, r->bottom); xrdp_region_insert_rect(self, i, rect->right, r->top, r->right, r->bottom); } else if (rect->left <= r->left && rect->top > r->top && rect->right >= r->right && rect->bottom < r->bottom) { /* 2 rects, one on each end */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); } else if (rect->left > r->left && rect->right < r->right && rect->top <= r->top && rect->bottom < r->bottom) { /* partially covered(top) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, rect->left, r->bottom); xrdp_region_insert_rect(self, i, rect->left, rect->bottom, rect->right, r->bottom); xrdp_region_insert_rect(self, i, rect->right, r->top, r->right, r->bottom); } else if (rect->top > r->top && rect->bottom < r->bottom && rect->left <= r->left && rect->right < r->right) { /* partially covered(left) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, rect->right, rect->top, r->right, rect->bottom); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); } else if (rect->left > r->left && rect->right < r->right && rect->bottom >= r->bottom && rect->top > r->top) { /* partially covered(bottom) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, rect->left, r->bottom); xrdp_region_insert_rect(self, i, rect->left, r->top, rect->right, rect->top); xrdp_region_insert_rect(self, i, rect->right, r->top, r->right, r->bottom); } else if (rect->top > r->top && rect->bottom < r->bottom && rect->right >= r->right && rect->left > r->left) { /* partially covered(right) */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, r->left, rect->top, rect->left, rect->bottom); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); } else if (rect->left > r->left && rect->top > r->top && rect->right < r->right && rect->bottom < r->bottom) { /* totally contained, 4 rects */ list_remove_item(self->rects, i); xrdp_region_insert_rect(self, i, r->left, r->top, r->right, rect->top); xrdp_region_insert_rect(self, i, r->left, rect->top, rect->left, rect->bottom); xrdp_region_insert_rect(self, i, r->left, rect->bottom, r->right, r->bottom); xrdp_region_insert_rect(self, i, rect->right, rect->top, r->right, rect->bottom); } else { g_writeln("error in xrdp_region_subtract_rect"); } } return 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; } }