Dynamic username setting

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
Claudio Matsuoka committed 2008-05-02 17:33:32 -03:00
1 parent 0fdf97653f
commit ccd49f2024
1 file changed
+21 -8
+21 -8
View File
@@ -54,7 +54,6 @@ THE SOFTWARE.
#define REMOUNT_ROOTFS_RW #define REMOUNT_ROOTFS_RW
#define MAKE_DEVICES #define MAKE_DEVICES
#define PAM_CONSOLE #define PAM_CONSOLE
#define CHECK_FS
#else /* original Eeepc distribution */ #else /* original Eeepc distribution */
#define RANDOMSEED "/var/lib/urandom/random-seed" #define RANDOMSEED "/var/lib/urandom/random-seed"
#define SYSROOT "/mnt" #define SYSROOT "/mnt"
@@ -103,9 +102,13 @@ int main()
char *x; char *x;
sigset_t nmask, nmask2; sigset_t nmask, nmask2;
int debug = 0; int debug = 0;
char username[16];
char *c, cmd[256];
puts("finit-alt " VERSION " (built " __DATE__ " by " WHOAMI ")"); puts("finit-alt " VERSION " (built " __DATE__ " by " WHOAMI ")");
strncpy(username, DEFUSER, 16);
chdir("/"); chdir("/");
umask(022); umask(022);
@@ -145,9 +148,8 @@ int main()
close(1); close(1);
close(2); close(2);
} }
#ifdef CHECK_FS
if ((x = strstr(line, "CHECKFS="))) { if ((x = strstr(line, "CHECKFS="))) {
char *c, cmd[256]; x += 8;
strcpy(cmd, "e2fsck -C -p "); strcpy(cmd, "e2fsck -C -p ");
c = cmd + strlen(cmd); c = cmd + strlen(cmd);
while (x && *x != ' ') *c++ = *x++; while (x && *x != ' ') *c++ = *x++;
@@ -156,7 +158,11 @@ int main()
sync(); sync();
reboot(RB_AUTOBOOT); reboot(RB_AUTOBOOT);
} }
#endif if ((x = strstr(line, "USERNAME="))) {
x += 9;
c = cmd + strlen(cmd);
while (x && *x != ' ') *c++ = *x++;
}
if ((strstr(line, "DEBUG"))) { if ((strstr(line, "DEBUG"))) {
debug = 1; debug = 1;
} }
@@ -276,11 +282,12 @@ int main()
* Console setup (for X) * Console setup (for X)
*/ */
makepath("/var/run/console"); makepath("/var/run/console");
touch("/var/run/console/" DEFUSER); snprintf(line, LINE_SIZE, "/var/run/console/%s", username);
touch(line);
#ifdef PAM_CONSOLE #ifdef PAM_CONSOLE
if ((fd = open("/var/run/console/console.lock", O_CREAT|O_WRONLY|O_TRUNC, 0644)) >= 0) { if ((fd = open("/var/run/console/console.lock", O_CREAT|O_WRONLY|O_TRUNC, 0644)) >= 0) {
write(fd, DEFUSER, strlen(DEFUSER)); write(fd, username, strlen(username));
close(fd); close(fd);
system("/sbin/pam_console_apply"); system("/sbin/pam_console_apply");
} }
@@ -328,10 +335,16 @@ int main()
while (access("/tmp/shutdown", F_OK) < 0) { while (access("/tmp/shutdown", F_OK) < 0) {
if (debug) { if (debug) {
system("su -c startx -l " DEFUSER); printf("Starting X as %s\n", username);
snprintf(line, LINE_SIZE,
"su -c startx -l %s\n", username);
system(line);
system("/bin/sh"); system("/bin/sh");
} else { } else {
system("su -c startx -l " DEFUSER " &> /dev/null"); snprintf(line, LINE_SIZE,
"su -c startx -l %s\n &> /dev/null",
username);
system(line);
} }
} }