--- openssh-3.4p1.orig/Makefile.in	Wed Jun 26 01:45:42 2002
+++ openssh-3.4p1/Makefile.in	Fri Aug 16 15:40:02 2002
@@ -56,7 +56,7 @@
 INSTALL_SSH_PRNG_CMDS=@INSTALL_SSH_PRNG_CMDS@
 INSTALL_SSH_RAND_HELPER=@INSTALL_SSH_RAND_HELPER@
 
-@NO_SFTP@SFTP_PROGS=sftp-server$(EXEEXT) sftp$(EXEEXT)
+@NO_SFTP@SFTP_PROGS=sftp-server$(EXEEXT) sftp$(EXEEXT) rssh$(EXEEXT)
 
 TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} $(SFTP_PROGS)
 
@@ -66,8 +66,8 @@
 
 SSHDOBJS= sshd.o auth.o auth1.o auth2.o auth2-hostbased.o auth2-kbdint.o auth2-none.o auth2-passwd.o auth2-pubkey.o auth-chall.o auth2-chall.o auth-rhosts.o auth-options.o auth-krb4.o auth-krb5.o auth-pam.o auth2-pam.o auth-passwd.o auth-rsa.o auth-rh-rsa.o auth-sia.o sshpty.o sshlogin.o loginrec.o servconf.o serverloop.o md5crypt.o session.o groupaccess.o auth-skey.o auth-bsdauth.o monitor_mm.o monitor.o
 
-MANPAGES	= scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out
-MANPAGES_IN	= scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5 ssh_config.5
+MANPAGES	= scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out rssh.1.out ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out
+MANPAGES_IN	= scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 rssh.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5 ssh_config.5
 MANTYPE		= @MANTYPE@
 
 CONFIGFILES=sshd_config.out ssh_config.out moduli.out
@@ -140,6 +140,9 @@
 sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-int.o sftp-common.o sftp-glob.o
 	$(LD) -o $@ sftp.o sftp-client.o sftp-common.o sftp-int.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
 
+rssh$(EXEEXT): rssh.o
+	$(LD) -o $@ rssh.o
+
 ssh-rand-helper${EXEEXT}: $(LIBCOMPAT) libssh.a ssh-rand-helper.o
 	$(LD) -o $@ ssh-rand-helper.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
 
@@ -231,6 +234,7 @@
 	fi
 	$(INSTALL) -m 4711 -s ssh-keysign $(DESTDIR)$(SSH_KEYSIGN)
 	@NO_SFTP@$(INSTALL) -m 0755 -s sftp $(DESTDIR)$(bindir)/sftp
+	@NO_SFTP@$(INSTALL) -m 0755 -s rssh $(DESTDIR)$(bindir)/rssh
 	@NO_SFTP@$(INSTALL) -m 0755 -s sftp-server $(DESTDIR)$(SFTP_SERVER)
 	$(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
 	$(INSTALL) -m 644 scp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1
@@ -245,6 +249,7 @@
 		$(INSTALL) -m 644 ssh-rand-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8 ; \
 	fi
 	@NO_SFTP@$(INSTALL) -m 644 sftp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1
+	@NO_SFTP@$(INSTALL) -m 644 rssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/rssh.1
 	@NO_SFTP@$(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
 	$(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
 	-rm -f $(DESTDIR)$(bindir)/slogin
@@ -328,6 +333,7 @@
 	-rm -f $(DESTDIR)$(bindir)/ssh-keygen$(EXEEXT)
 	-rm -f $(DESTDIR)$(bindir)/ssh-keyscan$(EXEEXT)
 	-rm -f $(DESTDIR)$(bindir)/sftp$(EXEEXT)
+	-rm -f $(DESTDIR)$(bindir)/rssh$(EXEEXT)
 	-rm -f $(DESTDIR)$(sbindir)/sshd$(EXEEXT)
 	-rm -r $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
 	-rm -f $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT)
@@ -338,6 +344,7 @@
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-agent.1
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1
+	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/rssh.1
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8
--- openssh-3.4p1.orig/rssh.c	Fri Aug 16 14:06:03 2002
+++ openssh-3.4p1/rssh.c	Fri Aug 16 14:04:43 2002
@@ -0,0 +1,153 @@
+/*
+ * rssh.c - restricted shell for ssh to allow scp or sftp only
+ * 
+ * Copyright 2002 Derek D. Martin <ddm@pizzashack.org>.
+ *
+ * This program is licensed under a BSD-style license, as follows: 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <libgen.h>
+#include <wordexp.h>
+
+#include "pathnames.h"
+
+#define _ALLOW_SCP 1
+#define _ALLOW_SFTP (1 << 1)
+
+void do_exit_message( int flags );
+char **build_arg_vector( char *str );
+
+extern int errno;
+
+int main( int argc, char **argv )
+{
+
+    char **argvec;
+    int  allowed_command = 0;
+    int  flag = 0;
+
+    /* convert argv[2] into an arg vector suitable for execvp() */
+    argvec = build_arg_vector(argv[2]);
+
+    /*  check argv[0] for scp or sftp to see what's allowed */
+    if ( !strcmp(basename(argv[0]), "scpsh") ) 
+        allowed_command = _ALLOW_SCP;
+    if ( !strcmp(basename(argv[0]), "sftpsh") )
+        allowed_command = _ALLOW_SFTP;
+    if ( !strcmp(basename(argv[0]), "rssh") ) 
+        allowed_command = _ALLOW_SFTP | _ALLOW_SCP;
+
+    /* q&d arg count check */
+    if ( argc < 3 ) do_exit_message(allowed_command);
+
+    /* if first arg is anything but -c, it's no good */
+    if ( strcmp("-c", argv[1]) ) do_exit_message(allowed_command);
+
+    /* check to see if we got an allowed command */
+    if ( (!strcmp(argvec[0], _PATH_SFTP_SERVER)) && 
+        (allowed_command & _ALLOW_SFTP ) )
+        flag = 1;
+    if ( (!strcmp(argvec[0], "scp") && (allowed_command & _ALLOW_SCP)) )
+        flag = 1;
+
+    /* if no allowed command, print message and exit */
+    if ( !flag )
+        do_exit_message(allowed_command);
+
+    /* if all that passed, exec the relevant command */
+    execvp(argvec[0], argvec);
+
+    /* we only get here if the exec fails */
+    fprintf(stderr, "rssh: excecvp() failed.  ");
+
+    switch (errno){
+
+        case EACCES:
+        case ENOTDIR:
+        case ENOENT:
+            fprintf(stderr, "%s is not an executable file, or permission denied.\n\n", argv[2]);
+            break;
+        case EPERM:
+            fprintf(stderr, "FS mounted nosuid or process is being traced\n"
+                    "(and you are not root)\n\n");
+            break;
+        default:
+            fprintf(stderr, "an unknown error occurred.\n\n");
+    }
+    
+    exit(1);
+}
+
+
+char **build_arg_vector( char *str )
+{
+
+    wordexp_t   result;
+
+    if ( (wordexp(str, &result, 0)) ){
+        fprintf(stderr, "rssh: error expanding arguments\n");
+        exit(1);
+    }
+
+    return result.we_wordv;
+}
+
+
+void do_exit_message( int flags )
+{
+
+    if ( !flags ){
+        fprintf(stderr, "\nrssh is not installed correctly!\n");
+        exit(1);
+    }
+
+    fprintf( stderr, "\nThis account is restricted, for the use of ");
+
+    switch (flags){
+        case (_ALLOW_SCP | _ALLOW_SFTP):
+            fprintf(stderr, "scp or sftp");
+            break;
+        case _ALLOW_SCP:
+            fprintf(stderr, "scp");
+            break;
+        case _ALLOW_SFTP:
+            fprintf(stderr, "sftp");
+            break;
+        default:
+            fprintf(stderr, "\n\nrssh error!  This can only happen if rssh"
+                    " is not installed correctly.\n  Please see your "
+                    "system administrator.\n\n");
+    }
+
+    fprintf(stderr, " only.\nIf you believe this is in error, please contact"
+             " your system\nadministrator.\n\n" );
+    exit(0);
+}
+
+
--- openssh-3.4p1.orig/rssh.1	Thu Jan  1 01:00:00 1970
+++ openssh-3.4p1/rssh.1	Fri Aug 16 15:37:06 2002
@@ -0,0 +1,80 @@
+.\"  -*- nroff -*-
+.\"
+.\" rssh.1
+.\"
+.\" Author: Jan Iven
+.\"
+.\" Created: Fri Aug 16 14:13:00 2002 iven
+.\"
+.\" $OpenBSD: $
+.\"
+.Dd August 16, 2002
+.Dt RSSH 1
+.Os
+.Sh NAME
+.Nm rssh
+.Nd restricted secure shell
+.Sh SYNOPSIS
+.Nm rssh 
+.Ar -c
+.Op scp |  /usr/libexec/openssh/sftp-server 
+.Op Ar ...
+.Nm scpsh 
+.Ar   -c \ scp \ 
+.Op Ar ...
+.Nm sftpsh \ 
+.Ar   -c \ /usr/libexec/openssh/sftp-server \  
+.Op Ar ...
+.Sh DESCRIPTION
+.Nm
+allows to give secure ftp-like file transfer capabilities without giving full
+shell access to individual users.
+It uses
+.Xr scp 1
+or
+.Xr sftp 1
+for the actual data transfer.
+.Sm off
+.Nm  
+ is supposed to be the login shell for these users as returned from the 
+.Xr getpwnam 3
+  function call.
+.Pp 
+The executable may be installed and referenced as
+.Bl -tag -width Ds
+.It \fB scpsh
+which limits the user to 
+.Xr scp 1 
+ (SSH protocol 1),
+.It \fB sftpsh
+which limits the user to 
+.Xr sftp 1 
+ (SSH protocol 2), or
+.It \fB rssh
+which allows to use both
+.Xr scp 1 
+ and
+.Xr sftp 1
+.El
+.Pp
+Anything else will cause an error at runtime.  
+.Pp
+The first argument on invocation has to be
+.Fl c
+, the second has to be either 
+\fBscp\fP or the full path to the 
+.Xr sftp-server 8 
+ executable and has to match the compiled-in value..
+.Sh DIAGNOSTICS
+.Nm
+ exits with 0 on success or >0 if an error occurred. A verbose error
+message is provided.
+.Sh BUGS
+.Nm 
+ is only part of such a solution, special care must be taken to prevent
+users from changing their 
+.Xr ssh_config 5
+ client configuration files.
+.Sh AUTHOR
+Derek D. Martin (2002)
+.Sh SEE
 ALSO
+.Xr sftp 1 
 , 
+.Xr scp 1

