diff -Naur autologin-1.0.0.orig/README autologin-1.0.0/README --- autologin-1.0.0.orig/README 2011-11-27 17:29:38.732223223 +0200 +++ autologin-1.0.0/README 2011-11-27 17:32:35.315268939 +0200 @@ -29,7 +29,7 @@ EXEC=[script or program] The script or program listed here will be executed as the user specified above. - If this setting is omitted, /usr/X11R6/bin/startx will be used. + If this setting is omitted, /usr/bin/startx will be used. AUTOLOGIN={yes,no} You can use this setting to turn off autologin even if it is installed and the config file exists and is considered safe. diff -Naur autologin-1.0.0.orig/src/autologin.c autologin-1.0.0/src/autologin.c --- autologin-1.0.0.orig/src/autologin.c 2011-11-27 17:29:38.755229828 +0200 +++ autologin-1.0.0/src/autologin.c 2011-11-27 17:31:59.944138000 +0200 @@ -9,13 +9,16 @@ #include #include #include +#include #include #define CONFIG "/etc/sysconfig/autologin" -#define DEFAULT "/usr/X11R6/bin/startx" +#define DEFAULT "/usr/bin/startx" +#define _PATH_DEFPATH "/bin:/usr/bin:/usr/local/bin" #ifdef HAVE_PAM #include #include +#include static int PAM_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) { /* We use PAM to authenticate for pam_console only, we don't need @@ -27,6 +30,13 @@ &PAM_conv, NULL }; + +static pid_t child; + +static void sigterm_handler(int val) +{ + kill(child, SIGTERM); +} #endif char runthis[1024]; @@ -43,36 +53,36 @@ char *dir, *shell; char *user=NULL; char *cmd=NULL; + int outfd; #ifdef HAVE_PAM pam_handle_t *pamh; - pid_t child; int status; #endif runthis[0]=0; runthis[1023]=0; if(getuid()) { - puts("ERROR: This program needs to change user IDs; therefore, it must be run as root."); + puts("autologin ERROR: This program needs to change user IDs; therefore, it must be run as root."); return 1; } if(stat(CONFIG, &st)) { - perror("ERROR: Couldn't stat "CONFIG":"); + perror("autologin ERROR: Couldn't stat "CONFIG":"); return 1; } if(st.st_mode & S_IWGRP) { - puts("ERROR: "CONFIG" must not be group-writable!"); + puts("autologin ERROR: "CONFIG" must not be group-writable!"); return 1; } if(st.st_mode & S_IWOTH) { - puts("ERROR: "CONFIG" must not be world-writable!"); + puts("autologin ERROR: "CONFIG" must not be world-writable!"); return 1; } if(st.st_uid || st.st_gid) { - puts("ERROR: "CONFIG" must be owned by user root, group root!"); + puts("autologin ERROR: "CONFIG" must be owned by user root, group root!"); return 1; } f=fopen(CONFIG, "r"); if(!f) { - perror("ERROR: Couldn't open "CONFIG":"); + perror("autologin ERROR: Couldn't open "CONFIG":"); return 1; } cfg=(char *) malloc(st.st_size+1); @@ -107,10 +117,9 @@ fclose(f); free(cfg); if(user==NULL) { - puts("ERROR: Required variable USER= not found in "CONFIG"."); if(cmd) free(cmd); - return 1; + return 0; } if(cmd==NULL) /* Try a reasonable default... */ cmd=strdup(DEFAULT); @@ -126,7 +135,7 @@ dir=strdup(pw->pw_dir); shell=strdup(pw->pw_shell); } else { - printf("ERROR: No such user %s!\n", user); + printf("autologin ERROR: No such user %s!\n", user); return 1; } @@ -138,6 +147,16 @@ } #endif + outfd = open("/var/log/autologin.log", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + close(1); + close(2); + dup2(outfd, 1); + dup2(outfd, 2); + + setpgrp(); + setsid(); + initgroups(user, pw->pw_gid); + /* Take console ownership and satisfy PAM */ #ifdef HAVE_PAM pam_start("autologin", user, &PAM_conversation, &pamh); @@ -180,6 +199,7 @@ setenv("SHELL", shell, 1); setenv("USER", user, 1); setenv("LOGNAME", user, 1); + setenv("PATH", _PATH_DEFPATH, 1); chdir(dir); free(user); @@ -191,6 +211,7 @@ return 2; #ifdef HAVE_PAM } else { + signal(SIGTERM, sigterm_handler); waitpid(child, &status, 0); pam_close_session(pamh, 0); pam_end(pamh, PAM_SUCCESS);