Protocol 2 and fork

Jarno Huuskonen jhuuskon at messi.uku.fi
Sat Aug 5 21:05:03 EST 2000


Hello !

Like Edmund EVANS reported openssh-2.1.1p4 won't fork to background when
using protocol 2.

I managed to hack a little patch that might work ... 

What is the -N command line option supposed to do ? I gather it should work
only with protocol2 and without any command to run on the server (and with
some port forwardings ??)

Anyway in the patch I put some code to check that -N is used with port 
forwards (and if used -f user doesn't have enter command). (If my assumptions
about what -N is supposed to do are way off just rip out the unnecessary code 
from the patch).

Also there seems to be a incompatibility issue with commercial ssh-2.2.0 
and openssh when openssh client uses -N. If I press enter on the openssh
client then the commercial server sends "Window overflow received channel
data." and disconnects. This doesn't happen when both the client and server
are openssh.

Cheers,
-Jarno

PS. I haven't done much testing with the patch so it'll propably break 
    something. 
    It works now for 'ssh -f -n -N -L5000:server:110 server' and fetchmail.

Patch:
diff -u -r openssh-2.1.1p4/ssh.c openssh-2.1.1p4-ruined/ssh.c
--- openssh-2.1.1p4/ssh.c	Sat Jul 15 07:14:17 2000
+++ openssh-2.1.1p4-ruined/ssh.c	Fri Aug  4 20:54:10 2000
@@ -460,10 +460,6 @@
 		}
 	}
 
-	/* Cannot fork to background if no command. */
-	if (fork_after_authentication_flag && buffer_len(&command) == 0)
-		fatal("Cannot fork into background without a command to execute.");
-
 	/* Allocate a tty by default if no command specified. */
 	if (buffer_len(&command) == 0)
 		tty_flag = 1;
@@ -511,6 +507,29 @@
 	/* reinit */
 	log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 0);
 
+	/* -N option only makes sense with protocol 2. It doesn't make sense
+		 without port forwarding ??????
+	*/
+	if ( options.num_local_forwards == 0 && options.num_remote_forwards == 0 &&
+			 no_shell_flag ) {
+		fprintf(stderr, "-N makes sense only with port forwardings\n");
+		usage();
+		/* NOT REACHED */
+	}
+	if ((options.protocol & SSH_PROTO_2) && no_shell_flag && 
+			buffer_len(&command) > 0) {
+		fprintf(stderr,"-N option works only with protocol version 2 and w/out a command\n");
+		usage();
+		/* NOT REACHED */
+	}
+
+	/* Cannot fork to background if no command.
+		 Command not needed for protocol 2 & -N
+	*/
+	if ((options.protocol & SSH_PROTO_1) && !(options.protocol & SSH_PROTO_2) && 
+			fork_after_authentication_flag && buffer_len(&command) == 0)
+			fatal("Cannot fork into background without a command to execute.");
+
 	/* check if RSA support exists */
 	if ((options.protocol & SSH_PROTO_1) &&
 	    rsa_alive() == 0) {
@@ -979,6 +998,12 @@
 
 	channel_open(id);
 	channel_register_callback(id, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, client_init, (void *)0);
+
+	/* Jarno: hack to get -f working with protocol 2 */
+	if (fork_after_authentication_flag) {
+		if (daemon(1, 1) < 0)
+			fatal("daemon() failed: %.200s", strerror(errno));
+	}
 
 	return client_loop(tty_flag, tty_flag ? options.escape_char : -1);
 }

-- 
Jarno Huuskonen - System Administrator   |  Jarno.Huuskonen at uku.fi
University of Kuopio - Computer Center   |  Work:   +358 17 162822
PL 1627, 70211 Kuopio, Finland           |  Mobile: +358 40 5388169





More information about the openssh-unix-dev mailing list