[PATCH 09/16] scp: Use `get_user_name()' more often

Michael Witten mfwitten at gmail.com
Tue Dec 8 06:58:25 AWST 2015


Date: Thu, 5 Nov 2015 07:13:01 -0000
Whenever the user name is not specified, try to use the current user's name.
---
 scp.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/scp.c b/scp.c
index 9a24490..a19d28f 100644
--- a/scp.c
+++ b/scp.c
@@ -482,7 +482,9 @@ toremote(char *targ, int argc, char **argv)
 		tuser = NULL;
 	}
 
-	if (tuser != NULL && !okname(tuser)) {
+	if (tuser == NULL)
+		tuser = get_user_name();
+	else if (!okname(tuser)) {
 		xfree(arg);
 		return;
 	}
@@ -514,14 +516,17 @@ toremote(char *targ, int argc, char **argv)
 				host = cleanhostname(host);
 				suser = argv[i];
 				if (*suser == '\0')
-					suser = get_user_name();
+					suser = NULL;
-				else if (!okname(suser))
-					continue;
-				addargs(&alist, "-l");
-				addargs(&alist, "%s", suser);
 			} else {
 				host = cleanhostname(argv[i]);
+				suser = NULL;
 			}
+			if (suser == NULL)
+				suser = get_user_name();
+			else if (!okname(suser))
+				continue;
+			addargs(&alist, "-l");
+			addargs(&alist, "%s", suser);
 			addargs(&alist, "%s", host);
 			addargs(&alist, "%s", cmd);
 			addargs(&alist, "%s", src);
@@ -583,8 +588,12 @@ tolocal(int argc, char **argv)
 			*host++ = 0;
 			suser = argv[i];
 			if (*suser == '\0')
-				suser = get_user_name();
+				suser = NULL;
 		}
+		if (suser == NULL)
+			suser = get_user_name();
+		else if (!okname(suser))
+			continue;
 		host = cleanhostname(host);
 		len = strlen(src) + CMDNEEDS + 20;
 		bp = xmalloc(len);
-- 
2.4.3



More information about the Dropbear mailing list