Skip to content

Commit

Permalink
Fill passwd structure with dummy user data, where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikushin committed Jan 31, 2020
1 parent 77543db commit f056be7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ getpwnamallow(struct ssh *ssh, const char *user)
aix_restoreauthdb();
#endif
if (pw == NULL) {
#ifdef __ANDROID__
pw = pwdefault();
#else
logit("Invalid user %.100s from %.100s port %d",
user, ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
#ifdef CUSTOM_FAILED_LOGIN
Expand All @@ -595,6 +598,7 @@ getpwnamallow(struct ssh *ssh, const char *user)
audit_event(ssh, SSH_INVALID_USER);
#endif /* SSH_AUDIT_EVENTS */
return (NULL);
#endif
}
if (!allowed_user(ssh, pw))
return (NULL);
Expand Down
12 changes: 11 additions & 1 deletion loginrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
#include "auth.h"
#include "sshbuf.h"
#include "ssherr.h"
#include "misc.h"

#ifdef HAVE_UTIL_H
# include <util.h>
Expand Down Expand Up @@ -312,9 +313,14 @@ login_get_lastlog(struct logininfo *li, const uid_t uid)
* wtmp_get_entry().)
*/
pw = getpwuid(uid);
if (pw == NULL)
if (pw == NULL) {
#ifdef __ANDROID__
pw = pwdefault();
#else
fatal("%s: Cannot find account for uid %ld", __func__,
(long)uid);
#endif
}

if (strlcpy(li->username, pw->pw_name, sizeof(li->username)) >=
sizeof(li->username)) {
Expand Down Expand Up @@ -386,8 +392,12 @@ login_init_entry(struct logininfo *li, pid_t pid, const char *username,
strlcpy(li->username, username, sizeof(li->username));
pw = getpwnam(li->username);
if (pw == NULL) {
#ifdef __ANDROID__
li->uid = 0;
#else
fatal("%s: Cannot find user \"%s\"", __func__,
li->username);
#endif
}
li->uid = pw->pw_uid;
}
Expand Down
9 changes: 8 additions & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,15 @@ tilde_expand_filename(const char *filename, uid_t uid)
user[slash] = '\0';
if ((pw = getpwnam(user)) == NULL)
fatal("tilde_expand_filename: No such user %s", user);
} else if ((pw = getpwuid(uid)) == NULL) /* ~/path */
} else if ((pw = getpwuid(uid)) == NULL) { /* ~/path */
#ifdef __ANDROID__
user[0] = '\0';
pw = pwdefault();
strcpy(user, pw->pw_dir);
#else
fatal("tilde_expand_filename: No such uid %ld", (long)uid);
#endif
}

/* Make sure directory has a trailing '/' */
len = strlen(pw->pw_dir);
Expand Down
4 changes: 4 additions & 0 deletions ssh-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,14 @@ main(int argc, char **argv)
int count = 0;

if ((pw = getpwuid(getuid())) == NULL) {
#ifdef __ANDROID__
pw = pwdefault();
#else
fprintf(stderr, "No user found with uid %u\n",
(u_int)getuid());
ret = 1;
goto done;
#endif
}

for (i = 0; default_files[i]; i++) {
Expand Down
7 changes: 6 additions & 1 deletion ssh-keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3137,8 +3137,13 @@ main(int argc, char **argv)

/* we need this for the home * directory. */
pw = getpwuid(getuid());
if (!pw)
if (!pw) {
#ifdef __ANDROID__
pw = pwdefault();
#else
fatal("No user exists for uid %lu", (u_long)getuid());
#endif
}
if (gethostname(hostname, sizeof(hostname)) == -1)
fatal("gethostname: %s", strerror(errno));

Expand Down
7 changes: 6 additions & 1 deletion ssh-keysign.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,13 @@ main(int argc, char **argv)
key_fd[i++] = open(_PATH_HOST_XMSS_KEY_FILE, O_RDONLY);
key_fd[i++] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);

if ((pw = getpwuid(getuid())) == NULL)
if ((pw = getpwuid(getuid())) == NULL) {
#ifdef __ANDROID__
pw = pwdefault();
#else
fatal("getpwuid failed");
#endif
}
pw = pwcopy(pw);

permanently_set_uid(pw);
Expand Down
4 changes: 4 additions & 0 deletions ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,12 @@ main(int ac, char **av)
/* Get user data. */
pw = getpwuid(getuid());
if (!pw) {
#ifdef __ANDROID__
pw = pwdefault();
#else
logit("No user exists for uid %lu", (u_long)getuid());
exit(255);
#endif
}
/* Take a copy of the returned structure. */
pw = pwcopy(pw);
Expand Down

0 comments on commit f056be7

Please sign in to comment.