AC_PROG_CC
AC_PROG_INSTALL
-# FIXME: Replace `main' with a function in `-lXau':
-AC_CHECK_LIB([Xau], [main], ,
- AC_MSG_ERROR([libXau is required but was not found]))
# FIXME: Replace `main' with a function in `-lpam':
AC_CHECK_LIB([pam], [main], ,
AC_MSG_ERROR([libpam is required but was not found]))
extern char displaydev[];
extern char displayname[];
-extern char xauth_cookie_file[];
-extern Xauth x_auth;
-extern char user_xauth_path[];
extern int tty;
extern char session[];
extern void switch_to_user(void);
extern void setup_user_environment(void);
extern void set_tty(void);
-extern void setup_xauth(void);
extern void start_X_server(void);
extern void wait_for_X_signal(void);
extern void wait_for_session_exit(void);
static int uid;
struct passwd *pass;
-char user_xauth_path[PATH_MAX];
-
static void do_env(void)
{
char buf[PATH_MAX];
setenv("DISPLAY", displayname, 1);
snprintf(buf, PATH_MAX, "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:%s/bin", pass->pw_dir);
setenv("PATH", buf, 1);
- snprintf(user_xauth_path, PATH_MAX, "%s/.Xauthority", pass->pw_dir);
- setenv("XAUTHORITY", user_xauth_path, 1);
file = popen("/bin/bash -l -c export", "r");
if (!file)
ret = chdir(pass->pw_dir);
- setup_xauth();
-
- fp = fopen(user_xauth_path, "w");
- if (fp) {
- if (XauWriteAuth(fp, &x_auth) != 1)
- lprintf("Unable to write .Xauthority");
- fclose(fp);
- }
-
d_out();
}
#include "user-session.h"
-#include <X11/Xauth.h>
-
char displaydev[PATH_MAX]; /* "/dev/tty1" */
char displayname[256] = ":0"; /* ":0" */
-char xauth_cookie_file[PATH_MAX];
-Xauth x_auth;
static pthread_mutex_t notify_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t notify_condition = PTHREAD_COND_INITIALIZER;
d_out();
}
-void setup_xauth(void)
-{
- FILE *fp;
- int fd;
- static char cookie[16];
- struct utsname uts;
-
- static char xau_address[80];
- static char xau_number[] = "0"; // FIXME, detect correct displaynum
- static char xau_name[] = "MIT-MAGIC-COOKIE-1";
-
- d_in();
-
- fp = fopen("/dev/urandom", "r");
- if (!fp)
- return;
- if (fgets(cookie, sizeof(cookie), fp) == NULL) {
- fclose(fp);
- return;
- }
- fclose(fp);
-
- /* construct xauth data */
- if (uname(&uts) < 0) {
- lprintf("uname failed");
- return;
- }
-
- sprintf(xau_address, "%s", uts.nodename);
- x_auth.family = FamilyLocal;
- x_auth.address = xau_address;
- x_auth.number = xau_number;
- x_auth.name = xau_name;
- x_auth.address_length = strlen(xau_address);
- x_auth.number_length = strlen(xau_number);
- x_auth.name_length = strlen(xau_name);
- x_auth.data = (char *) cookie;
- x_auth.data_length = sizeof(cookie);
-
- snprintf(xauth_cookie_file, PATH_MAX, "/run/user/%s/Xauth-XXXXXX",
- pass->pw_name);
-
- fd = mkstemp(xauth_cookie_file);
- if (fd < 0) {
- lprintf("unable to make tmp file for xauth");
- return;
- }
-
- lprintf("Xauth cookie file: %s", xauth_cookie_file);
-
- fp = fdopen(fd, "a");
- if (!fp) {
- lprintf("unable to open xauth fp");
- close(fd);
- return;
- }
-
- /* write it out to disk */
- if (XauWriteAuth(fp, &x_auth) != 1)
- lprintf("unable to write xauth data to disk");
-
- fclose(fp);
-
- d_out();
-}
-
static void usr1handler(int foo)
{
/* Got the signal from the X server that it's ready */
ptrs[++count] = strdup("-noreset");
- ptrs[++count] = strdup("-auth");
- ptrs[++count] = user_xauth_path;
-
opt = strtok(addn_xopts, " ");
while (opt) {
dprintf("adding xopt: \"%s\"", opt);