X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/ef8ad44b9b5d9c6d8c0fa5b5494f449fb6717387..381af97e8c14a91b535443f88337e4c77362f7ac:/login.tproj/login.c diff --git a/login.tproj/login.c b/login.tproj/login.c index a765c89..2b0d828 100644 --- a/login.tproj/login.c +++ b/login.tproj/login.c @@ -56,6 +56,8 @@ __FBSDID("$FreeBSD: src/usr.bin/login/login.c,v 1.106 2007/07/04 00:00:40 scf Ex #ifndef __APPLE__ #include +#endif +#ifdef __APPLE__ #include #endif #include @@ -494,20 +496,22 @@ main(int argc, char *argv[]) rval = 0; #endif /* !USE_PAM */ #endif /* __APPLE__ */ - } else { + } else if( pwd ) { fflag = 0; (void)setpriority(PRIO_PROCESS, 0, -4); #ifdef USE_PAM rval = auth_pam(); #else { - char* salt = pwd ? pwd->pw_passwd : "xx"; + char* salt = pwd->pw_passwd; char* p = getpass(passwd_prompt); - rval = strcmp(crypt(p, salt), pwd->pw_passwd); + rval = strcmp(crypt(p, salt), salt); memset(p, 0, strlen(p)); } #endif (void)setpriority(PRIO_PROCESS, 0, 0); + } else { + rval = -1; } #ifdef __APPLE__ @@ -658,12 +662,6 @@ main(int argc, char *argv[]) syslog(LOG_NOTICE, "strdup(): %m"); bail(SLEEP_EXIT, 1); } - if (*shell == '\0') /* Not overridden */ - shell = pwd->pw_shell; - if ((shell = strdup(shell)) == NULL) { - syslog(LOG_NOTICE, "strdup(): %m"); - bail(SLEEP_EXIT, 1); - } #if defined(__APPLE__) && TARGET_OS_EMBEDDED /* on embedded, allow a shell to live in /var/debug_mount/bin/sh */ @@ -675,6 +673,13 @@ main(int argc, char *argv[]) } #endif + if (*shell == '\0') /* Not overridden */ + shell = pwd->pw_shell; + if ((shell = strdup(shell)) == NULL) { + syslog(LOG_NOTICE, "strdup(): %m"); + bail(SLEEP_EXIT, 1); + } + #ifdef __APPLE__ dolastlog(quietlog); #endif @@ -867,6 +872,7 @@ main(int argc, char *argv[]) (void)setgid(pwd->pw_gid); if (initgroups(username, pwd->pw_gid) == -1) syslog(LOG_ERR, "login: initgroups() failed"); + pwd = getpwnam(username); // 7258548 (void) setuid(rootlogin ? 0 : pwd->pw_uid); #else /* !__APPLE__ */ if (setusercontext(lc, pwd, pwd->pw_uid,