add autologin support

This commit is contained in:
jsorg71 2005-09-29 03:21:26 +00:00
parent 0d6afdf52f
commit f90addd436
3 changed files with 205 additions and 43 deletions

View File

@ -290,6 +290,14 @@ remove_char_at(char* text, int index);
int APP_CC
set_string(char** in_str, char* in);
/* xrdp_login_wnd.c */
int APP_CC
xrdp_wm_setup_mod1(struct xrdp_wm* self,
struct xrdp_mod_data* mod_data);
int APP_CC
xrdp_wm_setup_mod2(struct xrdp_wm* self,
struct list* names,
struct list* values);
int APP_CC
xrdp_login_wnd_create(struct xrdp_wm* self);

View File

@ -106,9 +106,9 @@ sync_load(long param1, long param2)
}
/*****************************************************************************/
static int APP_CC
xrdp_wm_setup_mod(struct xrdp_wm* self,
struct xrdp_mod_data* mod_data)
int APP_CC
xrdp_wm_setup_mod1(struct xrdp_wm* self,
struct xrdp_mod_data* mod_data)
{
void* func;
@ -179,12 +179,53 @@ xrdp_wm_setup_mod(struct xrdp_wm* self,
/* id self->mod is null, there must be a problem */
if (self->mod == 0)
{
DEBUG(("problem loading lib in xrdp_wm_setup_mod\n\r"));
DEBUG(("problem loading lib in xrdp_wm_setup_mod1\n\r"));
return 1;
}
return 0;
}
/*****************************************************************************/
int APP_CC
xrdp_wm_setup_mod2(struct xrdp_wm* self,
struct list* names,
struct list* values)
{
char text[256];
int i;
int rv;
rv = 1;
if (!self->pro_layer->term)
{
if (self->mod->mod_start(self->mod, self->screen->width,
self->screen->height, self->screen->bpp) != 0)
{
self->pro_layer->term = 1; /* kill session */
}
}
if (!self->pro_layer->term)
{
/* always set these */
self->mod->mod_set_param(self->mod, "hostname",
self->session->client_info->hostname);
g_sprintf(text, "%d", self->session->client_info->keylayout);
self->mod->mod_set_param(self->mod, "keylayout", text);
for (i = 0; i < names->count; i++)
{
self->mod->mod_set_param(self->mod,
(char*)list_get_item(names, i),
(char*)list_get_item(values, i));
}
/* connect */
if (self->mod->mod_connect(self->mod) == 0)
{
rv = 0;
}
}
return rv;
}
/*****************************************************************************/
static int APP_CC
xrdp_wm_delete_all_childs(struct xrdp_wm* self)
@ -286,7 +327,6 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd)
struct list* values;
struct xrdp_mod_data* mod_data;
int i;
char text[256];
wm = wnd->wm;
combo = xrdp_bitmap_get_child_by_id(wnd, 6);
@ -307,7 +347,7 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd)
label = xrdp_bitmap_get_child_by_id(wnd, i);
edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);
}
if (xrdp_wm_setup_mod(wm, mod_data) == 0)
if (xrdp_wm_setup_mod1(wm, mod_data) == 0)
{
/* gota copy these cause dialog gets freed */
names = list_create();
@ -325,44 +365,24 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd)
(long)g_strdup((char*)list_get_item(mod_data->values, i)));
}
xrdp_wm_delete_all_childs(wm);
if (!wm->pro_layer->term)
if (xrdp_wm_setup_mod2(wm, names, values) != 0)
{
if (wm->mod->mod_start(wm->mod, wm->screen->width,
wm->screen->height, wm->screen->bpp) != 0)
/* totaly free mod */
if (wm->mod_exit != 0)
{
wm->pro_layer->term = 1; /* kill session */
}
}
if (!wm->pro_layer->term)
{
/* always set these */
wm->mod->mod_set_param(wm->mod, "hostname",
wm->session->client_info->hostname);
g_sprintf(text, "%d", wm->session->client_info->keylayout);
wm->mod->mod_set_param(wm->mod, "keylayout", text);
for (i = 0; i < names->count; i++)
{
wm->mod->mod_set_param(wm->mod,
(char*)list_get_item(names, i),
(char*)list_get_item(values, i));
}
/* connect */
if (wm->mod->mod_connect(wm->mod) != 0)
{
/* totaly free mod */
wm->mod_exit(wm->mod);
g_xrdp_sync(sync_unload, wm->mod_handle, 0);
wm->mod = 0;
wm->mod_handle = 0;
wm->mod_init = 0;
wm->mod_exit = 0;
}
else /* close connection log window if connection is ok */
g_xrdp_sync(sync_unload, wm->mod_handle, 0);
wm->mod = 0;
wm->mod_handle = 0;
wm->mod_init = 0;
wm->mod_exit = 0;
}
else /* close connection log window if connection is ok */
{
if (wm->log_wnd != 0)
{
if (wm->log_wnd != 0)
{
xrdp_bitmap_delete(wm->log_wnd);
}
xrdp_bitmap_delete(wm->log_wnd);
}
}
if (!wm->pro_layer->term)
@ -390,11 +410,13 @@ xrdp_wm_show_edits(struct xrdp_wm* self, struct xrdp_bitmap* combo)
int count;
int index;
int insert_index;
int username_set;
char* name;
char* value;
struct xrdp_mod_data* mod;
struct xrdp_bitmap* b;
username_set = 0;
/* free labels and edits, cause we gota create them */
/* creation or combo changed */
for (index = 100; index < 200; index++)
@ -449,9 +471,26 @@ xrdp_wm_show_edits(struct xrdp_wm* self, struct xrdp_bitmap* combo)
{
self->login_window->focused_control = b;
}
if (g_strncmp(name, "username", 255) == 0)
{
g_free(b->caption1);
b->caption1 = g_strdup(self->session->client_info->username);
b->edit_pos = g_strlen(b->caption1);
if (g_strlen(b->caption1) > 0)
{
username_set = 1;
}
}
if (g_strncmp(name, "password", 255) == 0)
{
b->password_char = '*';
if (username_set)
{
if (b->parent != 0)
{
b->parent->focused_control = b;
}
}
}
count++;
}

View File

@ -357,13 +357,128 @@ xrdp_wm_load_static_pointers(struct xrdp_wm* self)
int APP_CC
xrdp_wm_init(struct xrdp_wm* self)
{
int fd;
int index;
struct xrdp_mod_data* mod_data;
struct list* names;
struct list* values;
char* q;
char* r;
xrdp_wm_load_static_colors(self);
xrdp_wm_load_static_pointers(self);
xrdp_login_wnd_create(self);
/* clear screen */
self->screen->bg_color = self->black;
xrdp_bitmap_invalidate(self->screen, 0);
xrdp_wm_set_focused(self, self->login_window);
if (self->session->client_info->rdp_autologin)
{
fd = g_file_open("xrdp.ini");
if (fd > 0)
{
names = list_create();
names->auto_free = 1;
values = list_create();
values->auto_free = 1;
mod_data = (struct xrdp_mod_data*)
g_malloc(sizeof(struct xrdp_mod_data), 1);
mod_data->names = list_create();
mod_data->names->auto_free = 1;
mod_data->values = list_create();
mod_data->values->auto_free = 1;
if (file_read_section(fd, self->session->client_info->domain,
names, values) == 0)
{
for (index = 0; index < names->count; index++)
{
q = (char*)list_get_item(names, index);
r = (char*)list_get_item(values, index);
if (g_strncmp("name", q, 255) == 0)
{
g_strcpy(mod_data->name, r);
}
else if (g_strncmp("lib", q, 255) == 0)
{
g_strcpy(mod_data->lib, r);
}
else
{
if (g_strncmp("password", q, 255) == 0)
{
list_add_item(mod_data->names, (long)g_strdup("password"));
list_add_item(mod_data->values,
(long)g_strdup(self->session->client_info->password));
}
else if (g_strncmp("username", q, 255) == 0)
{
list_add_item(mod_data->names, (long)g_strdup("username"));
list_add_item(mod_data->values,
(long)g_strdup(self->session->client_info->username));
}
else
{
list_add_item(mod_data->names, (long)g_strdup(q));
list_add_item(mod_data->values, (long)g_strdup(r));
}
}
}
if (xrdp_wm_setup_mod1(self, mod_data) != 0)
{
/* totaly free mod */
if (self->mod_exit != 0)
{
self->mod_exit(self->mod);
}
g_xrdp_sync(sync_unload, self->mod_handle, 0);
self->mod = 0;
self->mod_handle = 0;
self->mod_init = 0;
self->mod_exit = 0;
}
else if (xrdp_wm_setup_mod2(self, mod_data->names, mod_data->values) != 0)
{
/* totaly free mod */
if (self->mod_exit != 0)
{
self->mod_exit(self->mod);
}
g_xrdp_sync(sync_unload, self->mod_handle, 0);
self->mod = 0;
self->mod_handle = 0;
self->mod_init = 0;
self->mod_exit = 0;
/* don't close here so user can see error */
}
else /* close connection log window if connection is ok */
{
if (self->log_wnd != 0)
{
xrdp_bitmap_delete(self->log_wnd);
}
}
if (!self->pro_layer->term)
{
if (self->mod != 0)
{
if (self->mod->sck != 0)
{
self->pro_layer->app_sck = self->mod->sck;
}
}
}
}
list_delete(mod_data->names);
list_delete(mod_data->values);
list_delete(names);
list_delete(values);
g_free(mod_data);
g_file_close(fd);
}
}
else
{
xrdp_login_wnd_create(self);
/* clear screen */
xrdp_bitmap_invalidate(self->screen, 0);
xrdp_wm_set_focused(self, self->login_window);
}
return 0;
}