/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
*/
#include "includes.h"
RCSID("$OpenBSD: session.c,v 1.1 2000/03/28 21:15:45 markus Exp $");
#include "xmalloc.h"
#include "ssh.h"
#include "pty.h"
#include "packet.h"
#include "buffer.h"
#include "cipher.h"
#include "mpaux.h"
#include "servconf.h"
#include "uidswap.h"
#include "compat.h"
#include "channels.h"
#include "nchan.h"
/* types */
#define TTYSZ 64
typedef struct Session Session;
struct Session {
int used;
int self;
struct passwd *pw;
pid_t pid;
/* tty */
char *term;
int ptyfd, ttyfd, ptymaster;
int row, col, xpixel, ypixel;
char tty[TTYSZ];
/* X11 */
char *display;
int screen;
char *auth_proto;
char *auth_data;
/* proto 2 */
int chanid;
};
/* func */
Session *session_new(void);
void session_set_fds(Session *s, int fdin, int fdout, int fderr);
void session_pty_cleanup(Session *s);
void do_exec_pty(Session *s, const char *command, struct passwd * pw);
void do_exec_no_pty(Session *s, const char *command, struct passwd * pw);
void
do_child(const char *command, struct passwd * pw, const char *term,
const char *display, const char *auth_proto,
const char *auth_data, const char *ttyname);
/* import */
extern ServerOptions options;
extern char *__progname;
extern int log_stderr;
extern int debug_flag;
/* Local Xauthority file. */
static char *xauthfile;
/* data */
#define MAX_SESSIONS 10
Session sessions[MAX_SESSIONS];
/* Flags set in auth-rsa from authorized_keys flags. These are set in auth-rsa.c. */
int no_port_forwarding_flag = 0;
int no_agent_forwarding_flag = 0;
int no_x11_forwarding_flag = 0;
int no_pty_flag = 0;
/* RSA authentication "command=" option. */
char *forced_command = NULL;
/* RSA authentication "environment=" options. */
struct envstring *custom_environment = NULL;
/*
* Remove local Xauthority file.
*/
void
xauthfile_cleanup_proc(void *ignore)
{
debug("xauthfile_cleanup_proc called");
if (xauthfile != NULL) {
char *p;
unlink(xauthfile);
p = strrchr(xauthfile, '/');
if (p != NULL) {
*p = '\0';
rmdir(xauthfile);
}
xfree(xauthfile);
xauthfile = NULL;
}
}
/*
* Function to perform cleanup if we get aborted abnormally (e.g., due to a
* dropped connection).
*/
void
pty_cleanup_proc(void *session)
{
Session *s=session;
if (s == NULL)
fatal("pty_cleanup_proc: no session");
debug("pty_cleanup_proc: %s", s->tty);
if (s