/*
 * scrsh.c -- GNU Screen Shell
 *
 * This "shell" is to be used to restrict a user's usage of login to GNU
 * Screen.  By setting the user's shell to /path/to/scrsh the SSH server will
 * allow the user access to the server by way of a screen session.
 *
 * To use, be certain to change the USER-DEFINED VALUES below to settings
 * appropriate to your system.
 *
 * This and other hacks can be found at: http://oddgeek.info/
 *
 * Copyright (c) 2005 Jason A. Dour
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 *     1. The origin of this software must not be misrepresented; you must not
 *     claim that you wrote the original software. If you use this software in
 *     a product, an acknowledgment in the product documentation would be
 *     appreciated but is not required.
 *
 *     2. Altered source versions must be plainly marked as such, and must not
 *     be misrepresented as being the original software.
 *
 *     3. This notice may not be removed or altered from any source
 *     distribution.
 *
 */

/*
 * Version Information
 *
 * 1.0	2005.05.26
 *
 * 	First public release.  Nothing really changed other than comments and
 * 	adding one include the ensure a -Wall returns no warnings.
 *
 * ooze	2002.02.08
 *
 * 	First documented version.  Only used privately to ensure a user was
 * 	trapped in a very locked down screen config.
 *
 * primordial ooze
 *
 * 	Took sftpsh.c code and used it to meet need of screen-only accounts.  I
 * 	know that sounds silly...screen is full of ways to escape to a
 * 	shell...but this was more of a user interface/continuity thing than a
 * 	security thing.
 *
 */

/*
 * USER DEFINED VALUES
 *
 * Define the path to the GNU Screen binary, as well as its execution name.
 * Supply any command arguments in the form of "arg1", "arg2" with no trailing
 * comma.
 *
 * Lastly, define the message to be printed when there is a problem
 * establishing their screen session.
 *
 */
#define SCREEN_BINARY "/usr/local/bin/screen"
#define SCREEN_EXNAME "screen"
#define SCREEN_ARGS "-xRR", "-l"

#define CUSTOM_MESG "There was a problem creating your terminal environment.\nContact your support personnel for assistance.\n"

/*
 * Necessary includes.
 */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

/* MAIN */
int main (int argc, char **argv) {
	char *screencmd[] = {
		SCREEN_EXNAME,
		SCREEN_ARGS,
		NULL
	};
	
	/* Ignore all arguments and just start screen. */
	execv(SCREEN_BINARY,screencmd);

	/* Should never get this far.  If so, inform user of error. */
	printf(CUSTOM_MESG);

	/* Pause long enough for people to read the message. */
	sleep(3);

	/* Never reached. */
	exit(0);
}
