#include "serverloop.h"
#include "canohost.h"
#include "session.h"
+#include "monitor.h"
+#include "monitor_wrap.h"
#ifdef HAVE_CYGWIN
#include <windows.h>
#define is_winnt (GetVersion() < 0x80000000)
#endif
-/* types */
-
-#define TTYSZ 64
-typedef struct Session Session;
-struct Session {
- int used;
- int self;
- struct passwd *pw;
- Authctxt *authctxt;
- pid_t pid;
- /* tty */
- char *term;
- int ptyfd, ttyfd, ptymaster;
- int row, col, xpixel, ypixel;
- char tty[TTYSZ];
- /* X11 */
- int display_number;
- char *display;
- int screen;
- char *auth_display;
- char *auth_proto;
- char *auth_data;
- int single_connection;
- /* proto 2 */
- int chanid;
- int is_subsystem;
-};
+/* Imports */
+extern int use_privsep;
+extern int mm_recvfd;
/* func */
Session *session_new(void);
void session_set_fds(Session *, int, int, int);
-static void session_pty_cleanup(void *);
+void session_pty_cleanup(void *);
void session_proctitle(Session *);
int session_setup_x11fwd(Session *);
void do_exec_pty(Session *, const char *);
static void do_authenticated1(Authctxt *);
static void do_authenticated2(Authctxt *);
-static void session_close(Session *);
static int session_pty_req(Session *);
/* import */
{
u_int len;
int n_bytes;
-
+ int res;
+
if (no_pty_flag) {
debug("Allocating a pty not permitted for this authentication.");
return 0;
/* Allocate a pty and open it. */
debug("Allocating pty.");
- if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty))) {
+ if (!use_privsep) {
+ res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
+ sizeof(s->tty));
+ if (res)
+ pty_setowner(s->pw, s->tty);
+ } else
+ res = mm_pty_allocown(mm_recvfd,
+ &s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
+ if (!res) {
if (s->term)
xfree(s->term);
s->term = NULL;
* time in case we call fatal() (e.g., the connection gets closed).
*/
fatal_add_cleanup(session_pty_cleanup, (void *)s);
- pty_setowner(s->pw, s->tty);
/* Set window size from the packet. */
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
* Function to perform pty cleanup. Also called if we get aborted abnormally
* (e.g., due to a dropped connection).
*/
-static void
+void
session_pty_cleanup(void *session)
{
Session *s = session;
s->chanid = -1;
}
-static void
+void
session_close(Session *s)
{
debug("session_close: session %d pid %d", s->self, s->pid);