[PATCH] -o option for scp (Re: -1 and friends)

Ben Lindstrom mouring at pconline.com
Mon Sep 11 04:39:45 EST 2000


Since there was a lot of chatter about -o, -1, and -2 for scp.  I figured
I'll just go ahead and do this.

The following patch includes is to add the -o option to scp.  

It supports a max of 40 -o options at the command line (I picked that
number because there are around 43 current options that readconf.c
supports. However as we know not all of them are valid on the command
line.  This could be lowered).

I also bumped the char *args[100] in do_cmd() to char *args[140] as
another safety measurement.

I'm sure that MAX_SSH_OPTS could be lowered to around 10 - 20.  But
I just felt that 40 would be a good starting point.

Markus.  Feel free to let me know if I overlooked something.
-------------- next part --------------
--- ../openssh/scp.c	Tue Sep  5 00:13:07 2000
+++ scp.c	Sun Sep 10 12:24:18 2000
@@ -117,6 +117,11 @@
 /* This is the program to execute for the secured connection. ("ssh" or -S) */
 char *ssh_program = SSH_PROGRAM;
 
+/* This is the options (-o) to use when starting up ssh for the connection */
+#define MAX_SSH_OPTS 40	/* Rough number of max options in readconfig.c */
+char *ssh_opts[MAX_SSH_OPTS]; /* XXX Careful [but handled in main()] */
+int ssh_opts_cnt = 0;
+
 /*
  * This function executes the given command as the specified user on the
  * given host.  This returns < 0 if execution fails, and >= 0 otherwise. This
@@ -150,16 +155,16 @@
 
 	/* For a child to execute the command on the remote host using ssh. */
 	if (fork() == 0) {
-		char *args[100];	/* XXX careful */
+		char *args[140];	/* XXX careful */
 		unsigned int i;
 
-		/* Child. */
+		/* Child.  */
 		close(pin[1]);
 		close(pout[0]);
 		dup2(pin[0], 0);
 		dup2(pout[1], 1);
 		close(pin[0]);
-		close(pout[1]);
+		close(pout[1]); 
 
 		i = 0;
 		args[i++] = ssh_program;
@@ -175,6 +180,13 @@
 			args[i++] = "-C";
 		if (batchmode)
 			args[i++] = "-oBatchMode yes";
+                if (ssh_opts_cnt > 0) {
+                        int x;
+                        for (x=0;x < ssh_opts_cnt;x++)  {
+				args[i++] = "-o";
+                                args[i++] = ssh_opts[x];
+			}
+                }
 		if (cipher != NULL) {
 			args[i++] = "-c";
 			args[i++] = cipher;
@@ -262,7 +274,7 @@
 	extern int optind;
 
 	fflag = tflag = 0;
-	while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:")) != EOF)
+	while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46So:")) != EOF)
 		switch (ch) {
 		/* User-visible flags. */
 		case '4':
@@ -283,6 +295,13 @@
 		case 'S':
 			ssh_program = optarg;
 			break;
+                case 'o':
+                        if (ssh_opts_cnt != MAX_SSH_OPTS)
+                                ssh_opts[ssh_opts_cnt++] = optarg;
+                        else
+                                fatal("Exceeded max -o options (%d)",
+                                        MAX_SSH_OPTS);
+                        break;
 
 		/* Server options. */
 		case 'd':


More information about the openssh-unix-dev mailing list