Skip to content

Commit e3ad6f1

Browse files
committed
Handle parameters and some output messages.
1 parent 0b55122 commit e3ad6f1

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

scp.c

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ char *port = NULL;
251251
/* This is set password if given on the command line. */
252252
char *password = NULL;
253253

254+
/* This is set ssh_config if given on the command line. */
255+
char *ssh_config = NULL;
256+
254257
int ipv_restrict = 0;
255258

256259
#define ONLY_IPV4 1
@@ -811,6 +814,10 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
811814
args[i++] = "-p";
812815
args[i++] = port;
813816
}
817+
if (ssh_config) {
818+
args[i++] = "-F";
819+
args[i++] = ssh_config;
820+
}
814821
if (remuser != NULL) {
815822
args[i++] = "-l";
816823
args[i++] = remuser;
@@ -893,6 +900,18 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
893900
NULL
894901
);
895902

903+
if (port)
904+
free(port);
905+
906+
if (cipher)
907+
free(cipher);
908+
909+
if (identity)
910+
free(identity);
911+
912+
if (ssh_config)
913+
free(ssh_config);
914+
896915
if (!rc) {
897916
printf("%s could not be started\n", ssh_program);
898917
exit(1);
@@ -1100,32 +1119,67 @@ main(int argc, char **argv)
11001119
case '1':
11011120
case '2':
11021121
case '4':
1122+
ipv_restrict = ONLY_IPV4;
1123+
break;
11031124
case '6':
1125+
ipv_restrict = ONLY_IPV6;
1126+
break;
11041127
case 'C':
11051128
addargs(&args, "-%c", ch);
11061129
addargs(&remote_remote_args, "-%c", ch);
1130+
1131+
compress = ch;
1132+
11071133
break;
11081134
case '3':
11091135
throughlocal = 1;
11101136
break;
11111137
case 'o':
11121138
case 'c':
1139+
addargs(&remote_remote_args, "-%c", ch);
1140+
addargs(&remote_remote_args, "%s", optarg);
1141+
addargs(&args, "-%c", ch);
1142+
addargs(&args, "%s", optarg);
1143+
1144+
cipher = malloc(strlen(optarg) + 1);
1145+
if (cipher)
1146+
strcpy(cipher, optarg);
1147+
break;
11131148
case 'i':
1114-
case 'F':
1149+
addargs(&remote_remote_args, "-%c", ch);
1150+
addargs(&remote_remote_args, "%s", optarg);
1151+
addargs(&args, "-%c", ch);
1152+
addargs(&args, "%s", optarg);
1153+
1154+
identity = malloc(strlen(optarg) + 1);
1155+
if (identity)
1156+
strcpy(identity, optarg);
1157+
break;
1158+
case 'F':
11151159
addargs(&remote_remote_args, "-%c", ch);
11161160
addargs(&remote_remote_args, "%s", optarg);
11171161
addargs(&args, "-%c", ch);
11181162
addargs(&args, "%s", optarg);
1119-
break;
1163+
1164+
ssh_config = malloc(strlen(optarg) + 1);
1165+
if (ssh_config)
1166+
strcpy(ssh_config, optarg);
1167+
break;
11201168
case 'P':
11211169
addargs(&remote_remote_args, "-p");
11221170
addargs(&remote_remote_args, "%s", optarg);
11231171
addargs(&args, "-p");
11241172
addargs(&args, "%s", optarg);
1173+
1174+
port = malloc(strlen(optarg) + 1);
1175+
if (port)
1176+
strcpy(port, optarg);
11251177
break;
11261178
case 'B':
11271179
addargs(&remote_remote_args, "\"-oBatchmode yes\"");
11281180
addargs(&args, "\"-oBatchmode yes\"");
1181+
1182+
batchmode = 1;
11291183
break;
11301184
case 'l':
11311185
limit_kbps = strtonum(optarg, 1, 100 * 1024 * 1024,
@@ -1590,7 +1644,17 @@ rsource(char *name, struct stat *statp)
15901644
(void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
15911645
(u_int) (statp->st_mode & FILEMODEMASK), 0, last);
15921646
if (verbose_mode)
1593-
fprintf(stderr, "Entering directory: %s", path);
1647+
#ifdef WINDOWS
1648+
{
1649+
printf("Entering directory: ");
1650+
wchar_t* wtmp = utf8_to_utf16(path);
1651+
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1652+
free(wtmp);
1653+
}
1654+
#else
1655+
fprintf(stderr, "Entering directory: %s", path);
1656+
#endif
1657+
15941658
(void) atomicio(vwrite, remout, path, strlen(path));
15951659
if (response() < 0) {
15961660
closedir(dirp);
@@ -1665,8 +1729,16 @@ sink(int argc, char **argv)
16651729
} while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
16661730
*cp = 0;
16671731
if (verbose_mode)
1668-
fprintf(stderr, "Sink: %s", buf);
1669-
1732+
#ifdef WINDOWS
1733+
{
1734+
printf("Sink: ");
1735+
wchar_t* wtmp = utf8_to_utf16(buf);
1736+
WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), wtmp, wcslen(wtmp), 0, 0);
1737+
free(wtmp);
1738+
}
1739+
#else
1740+
fprintf(stderr, "Sink: %s", buf);
1741+
#endif
16701742
if (buf[0] == '\01' || buf[0] == '\02') {
16711743
if (iamremote == 0)
16721744
(void) atomicio(vwrite, STDERR_FILENO,

0 commit comments

Comments
 (0)