changed pam session and env

ulab-original
jsorg71 20 years ago
parent dda4269822
commit c3ff1bcebb

@ -30,9 +30,11 @@
long DEFAULT_CC long DEFAULT_CC
auth_userpass(char* user, char* pass); auth_userpass(char* user, char* pass);
int DEFAULT_CC int DEFAULT_CC
auth_start_session(long in_val); auth_start_session(long in_val, int in_display);
int DEFAULT_CC int DEFAULT_CC
auth_end(long in_val); auth_end(long in_val);
int DEFAULT_CC
auth_set_env(long in_val);
static int g_sck; static int g_sck;
static int g_pid; static int g_pid;
@ -166,7 +168,6 @@ cterm(int s)
{ {
if (session_items[i].pid == pid) if (session_items[i].pid == pid)
{ {
auth_end(session_items[i].data);
g_memset(session_items + i, 0, sizeof(struct session_item)); g_memset(session_items + i, 0, sizeof(struct session_item));
} }
} }
@ -197,45 +198,17 @@ check_password_file(char* filename, char* password)
/******************************************************************************/ /******************************************************************************/
static int DEFAULT_CC static int DEFAULT_CC
start_session(int width, int height, int bpp, char* username, char* password, set_user(char* username, char* passwd_file, int display)
long data)
{ {
int display;
int pid;
int uid;
int wmpid;
int xpid;
int error; int error;
int pw_uid; int pw_uid;
int pw_gid; int pw_gid;
char pw_gecos[256]; int uid;
char pw_dir[256];
char pw_shell[256]; char pw_shell[256];
char pw_dir[256];
char pw_gecos[256];
char text[256]; char text[256];
char passwd_file[256];
char geometry[32];
char depth[32];
char screen[32];
char cur_dir[256];
g_get_current_dir(cur_dir, 255);
display = 10;
while (x_server_running(display) && display < 50)
{
display++;
}
if (display >= 50)
{
return 0;
}
auth_start_session(data);
wmpid = 0;
pid = g_fork();
if (pid == -1)
{
}
else if (pid == 0) /* child */
{
error = g_getuser_info(username, &pw_gid, &pw_uid, pw_shell, pw_dir, error = g_getuser_info(username, &pw_gid, &pw_uid, pw_shell, pw_dir,
pw_gecos); pw_gecos);
if (error == 0) if (error == 0)
@ -258,12 +231,55 @@ start_session(int width, int height, int bpp, char* username, char* password,
g_set_current_dir(pw_dir); g_set_current_dir(pw_dir);
g_sprintf(text, ":%d.0", display); g_sprintf(text, ":%d.0", display);
g_setenv("DISPLAY", text, 1); g_setenv("DISPLAY", text, 1);
if (passwd_file != 0)
{
g_mkdir(".vnc");
g_sprintf(passwd_file, "%s/.vnc/sesman_passwd", pw_dir);
}
}
}
return error;
}
/******************************************************************************/
/* returns 0 if error else the display number the session was started on */
static int DEFAULT_CC
start_session(int width, int height, int bpp, char* username, char* password,
long data)
{
int display;
int pid;
int wmpid;
int xpid;
char geometry[32];
char depth[32];
char screen[32];
char cur_dir[256];
char text[256];
char passwd_file[256];
g_get_current_dir(cur_dir, 255);
display = 10;
while (x_server_running(display) && display < 50)
{
display++;
}
if (display >= 50)
{
return 0;
}
wmpid = 0;
pid = g_fork();
if (pid == -1)
{
}
else if (pid == 0) /* child */
{
g_unset_signals();
auth_start_session(data, display);
g_sprintf(geometry, "%dx%d", width, height); g_sprintf(geometry, "%dx%d", width, height);
g_sprintf(depth, "%d", bpp); g_sprintf(depth, "%d", bpp);
g_sprintf(screen, ":%d", display); g_sprintf(screen, ":%d", display);
g_mkdir(".vnc");
g_sprintf(passwd_file, "%s/.vnc/sesman_passwd", pw_dir);
check_password_file(passwd_file, password);
wmpid = g_fork(); wmpid = g_fork();
if (wmpid == -1) if (wmpid == -1)
{ {
@ -271,9 +287,11 @@ start_session(int width, int height, int bpp, char* username, char* password,
else if (wmpid == 0) /* child */ else if (wmpid == 0) /* child */
{ {
/* give X a bit to start */ /* give X a bit to start */
g_sleep(500); g_sleep(1000);
set_user(username, 0, display);
if (x_server_running(display)) if (x_server_running(display))
{ {
auth_set_env(data);
g_sprintf(text, "%s/startwm.sh", cur_dir); g_sprintf(text, "%s/startwm.sh", cur_dir);
g_execlp3(text, "startwm.sh", 0); g_execlp3(text, "startwm.sh", 0);
/* should not get here */ /* should not get here */
@ -289,6 +307,8 @@ start_session(int width, int height, int bpp, char* username, char* password,
} }
else if (xpid == 0) /* child */ else if (xpid == 0) /* child */
{ {
set_user(username, passwd_file, display);
check_password_file(passwd_file, password);
g_execlp11("Xvnc", "Xvnc", screen, "-geometry", geometry, g_execlp11("Xvnc", "Xvnc", screen, "-geometry", geometry,
"-depth", depth, "-bs", "-rfbauth", passwd_file, 0); "-depth", depth, "-bs", "-rfbauth", passwd_file, 0);
/* should not get here */ /* should not get here */
@ -301,12 +321,11 @@ start_session(int width, int height, int bpp, char* username, char* password,
g_sigterm(xpid); g_sigterm(xpid);
g_sigterm(wmpid); g_sigterm(wmpid);
g_sleep(1000); g_sleep(1000);
auth_end(data);
g_exit(0); g_exit(0);
} }
} }
} }
}
}
else /* parent */ else /* parent */
{ {
session_items[display].pid = pid; session_items[display].pid = pid;

@ -103,3 +103,10 @@ auth_end(void)
{ {
return 0; return 0;
} }
/******************************************************************************/
int DEFAULT_CC
auth_set_env(void)
{
return 0;
}

@ -133,12 +133,20 @@ auth_userpass(char* user, char* pass)
/******************************************************************************/ /******************************************************************************/
/* returns error */ /* returns error */
int DEFAULT_CC int DEFAULT_CC
auth_start_session(long in_val) auth_start_session(long in_val, int in_display)
{ {
struct t_auth_info* auth_info; struct t_auth_info* auth_info;
int error; int error;
char display[256];
g_sprintf(display, ":%d", in_display);
auth_info = (struct t_auth_info*)in_val; auth_info = (struct t_auth_info*)in_val;
error = pam_set_item(auth_info->ph, PAM_TTY, display);
if (error != PAM_SUCCESS)
{
g_printf("pam_set_item failed: %s\n\r", pam_strerror(auth_info->ph, error));
return 1;
}
error = pam_setcred(auth_info->ph, PAM_ESTABLISH_CRED); error = pam_setcred(auth_info->ph, PAM_ESTABLISH_CRED);
if (error != PAM_SUCCESS) if (error != PAM_SUCCESS)
{ {
@ -185,3 +193,40 @@ auth_end(long in_val)
g_free(auth_info); g_free(auth_info);
return 0; return 0;
} }
/******************************************************************************/
/* returns error */
/* set any pam env vars */
int DEFAULT_CC
auth_set_env(long in_val)
{
struct t_auth_info* auth_info;
char** pam_envlist;
char** pam_env;
char item[256];
char value[256];
int eq_pos;
auth_info = (struct t_auth_info*)in_val;
if (auth_info != 0)
{
/* export PAM environment */
pam_envlist = pam_getenvlist(auth_info->ph);
if (pam_envlist != NULL)
{
for (pam_env = pam_envlist; *pam_env != NULL; ++pam_env)
{
eq_pos = g_pos(*pam_env, "=");
if (eq_pos >= 0 && eq_pos < 250)
{
g_strncpy(item, *pam_env, eq_pos);
g_strncpy(value, (*pam_env) + eq_pos + 1, 255);
g_setenv(item, value, 1);
}
g_free(*pam_env);
}
g_free(pam_envlist);
}
}
return 0;
}

@ -83,3 +83,10 @@ auth_end(void)
{ {
return 0; return 0;
} }
/******************************************************************************/
int DEFAULT_CC
auth_set_env(void)
{
return 0;
}

Loading…
Cancel
Save