From c93694ae418a1e24e2ef521b840388d528935202 Mon Sep 17 00:00:00 2001 From: Ørjan Malde Date: Sep 26 2022 21:55:03 +0000 Subject: style correction Signed-off-by: Ørjan Malde --- diff --git a/login.c b/login.c index 533ce67..051b6b6 100644 --- a/login.c +++ b/login.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -22,7 +21,7 @@ #include "motd.h" #include "os/os.h" -static bool do_login(struct passwd* pwd, int pflag) +static int do_login(struct passwd *pwd, int pflag) { char * comspec; size_t envlen; @@ -32,14 +31,14 @@ static bool do_login(struct passwd* pwd, int pflag) char envbuff[3072]; if(*pwd->pw_shell == '\0') - pwd->pw_shell = "/bin/sh"; /* if /bin/sh doesn't exist, I do not care. blow up. */ + pwd->pw_shell = "/bin/sh"; if(chdir(pwd->pw_dir) < 0) { printf("no home directory %s!\n", pwd->pw_dir); /* handle -EPERM, -ENOMEM, -ESYMLNK */ if(chdir("/") == -1) { printf("chdir failed with %s", strerror(errno)); - return false; + return 0; } else { pwd->pw_dir = "/"; } @@ -50,7 +49,7 @@ static bool do_login(struct passwd* pwd, int pflag) (void)setenv("HOME", pwd->pw_dir, 1); (void)setenv("SHELL", pwd->pw_shell, 1); - (void)setenv("TERM", "xterm", 0); /* rrrr. needs researching */ + (void)setenv("TERM", "xterm", 0); /* TODO: this is 500% incorrect */ (void)setenv("LOGNAME", pwd->pw_name, 1); (void)setenv("USER", pwd->pw_name, 1); (void)setenv("PATH", "/local/sbin:/local/bin:/sbin:/bin", 0); @@ -71,7 +70,7 @@ static bool do_login(struct passwd* pwd, int pflag) } else if ((envstrs = calloc(envlen,1))) { envp = envptrs; } else { - return false; + return 0; } envp[0] = envstrs; @@ -112,21 +111,20 @@ static bool do_login(struct passwd* pwd, int pflag) (char *[]){pwd->pw_shell,"-l",0}, envp); - return false; + return 0; } int main(int argc, char **argv) { + struct passwd *pwd; + char *username = NULL; + int c, pflag, iflag = 0; + /* we don't want ^D etc to mess up the logic */ (void)signal(SIGTSTP, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); (void)signal(SIGINT, SIG_IGN); - struct passwd *pwd; - char* username = NULL; - int c; - int pflag, iflag = 0; - while((c = getopt(argc, argv, "pfh:iw")) != -1) switch(c) { case 'p': @@ -158,23 +156,24 @@ int main(int argc, char **argv) /* guard against account probing */ if(!pwd) { - char* pw = getpass("Password: "); + char *pw = getpass("Password: "); explicit_bzero(pw, strlen(pw)); endpwent(); puts("Login incorrect."); - exit(1); + return 1; } /* midipix: are we spawning a shell? */ if(!iflag) { - char* pw = getpass("Password: "); - if(!(*pwd->pw_passwd == '\0' && !strlen(pw))) { /* TODO: check for shadow passwords and locked accounts */ - char* pw_encrypted = crypt(pw, pwd->pw_passwd); + char *pw = getpass("Password: "); + /* TODO: shadow and locked account support */ + if(!(*pwd->pw_passwd == '\0' && !strlen(pw))) { + char *pw_encrypted = crypt(pw, pwd->pw_passwd); /* if(timingsafe_memcmp(pw_encrypted, pwd->pw_passwd, strlen(pw_encrypted))) { */ if(memcmp(pw_encrypted, pwd->pw_passwd, strlen(pw_encrypted)) != 0) { puts("Login incorrect."); explicit_bzero(pw, strlen(pw)); - exit(1); + return 1; } explicit_bzero(pw, strlen(pw)); } @@ -189,6 +188,8 @@ int main(int argc, char **argv) } } puts("could not switch to specified user."); + + return 2; } void usage(void) diff --git a/os/linux.c b/os/linux.c index db01bd8..85000c9 100644 --- a/os/linux.c +++ b/os/linux.c @@ -3,9 +3,10 @@ /* Copyright (c) 2019 Ørjan Malde */ /* Released under LGPL, see COPYRIGHT.MLOGIN */ +#include +#include - -int switch_user_context(struct passwd* pwd, const char* username) +int switch_user_context(struct passwd *pwd, const char *username) { if(!getuid()) { if(initgroups(username, pwd->pw_gid) == -1) { @@ -14,9 +15,8 @@ int switch_user_context(struct passwd* pwd, const char* username) } } - /* is this safe? not sure. */ if(setgid(pwd->pw_gid)) - return false; + return 1; if(setuid(pwd->pw_uid)) return 1; return 0; diff --git a/os/midipix.c b/os/midipix.c index b93db13..0abc98d 100644 --- a/os/midipix.c +++ b/os/midipix.c @@ -6,7 +6,7 @@ #include #include -int switch_user_context(struct passwd* pwd, const char* username) +int switch_user_context(struct passwd *pwd, const char *username) { (void)username; diff --git a/os/os.h b/os/os.h index a40dbae..53edf61 100644 --- a/os/os.h +++ b/os/os.h @@ -1 +1 @@ -int switch_user_context(struct passwd* pwd, const char* username); +int switch_user_context(struct passwd *pwd, const char *username); diff --git a/os/unknown.c b/os/unknown.c index 1a67a88..702302d 100644 --- a/os/unknown.c +++ b/os/unknown.c @@ -6,7 +6,7 @@ #include #include -int switch_user_context(struct passwd* pwd, const char* username) +int switch_user_context(struct passwd *pwd, const char *username) { #warning port me!