Don't fail if can't get the username

This commit is contained in:
Matt Johnston 2016-01-19 00:34:37 +08:00
parent 6453b5b70e
commit de70b02c2f

8
scp.c
View File

@ -289,7 +289,6 @@ int okname(char *);
void run_err(const char *,...); void run_err(const char *,...);
void verifydir(char *); void verifydir(char *);
struct passwd *pwd;
uid_t userid; uid_t userid;
int errs, remin, remout; int errs, remin, remout;
int pflag, iamremote, iamrecursive, targetshouldbedirectory; int pflag, iamremote, iamrecursive, targetshouldbedirectory;
@ -396,9 +395,6 @@ main(int argc, char **argv)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if ((pwd = getpwuid(userid = getuid())) == NULL)
fatal("unknown user %u", (u_int) userid);
if (!isatty(STDERR_FILENO)) if (!isatty(STDERR_FILENO))
showprogress = 0; showprogress = 0;
@ -514,7 +510,7 @@ toremote(char *targ, int argc, char **argv)
host = cleanhostname(host); host = cleanhostname(host);
suser = argv[i]; suser = argv[i];
if (*suser == '\0') if (*suser == '\0')
suser = pwd->pw_name; continue; /* pretend there wasn't any @ at all */
else if (!okname(suser)) else if (!okname(suser))
continue; continue;
addargs(&alist, "-l"); addargs(&alist, "-l");
@ -582,7 +578,7 @@ tolocal(int argc, char **argv)
*host++ = 0; *host++ = 0;
suser = argv[i]; suser = argv[i];
if (*suser == '\0') if (*suser == '\0')
suser = pwd->pw_name; suser = NULL;
} }
host = cleanhostname(host); host = cleanhostname(host);
len = strlen(src) + CMDNEEDS + 20; len = strlen(src) + CMDNEEDS + 20;