Print this page
OS-2204 SunSSH has a maximum of 10 multiplexed sessions

*** 33,42 **** --- 33,45 ---- */ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* + * Copyright (c) 2013, Joyent, Inc. All rights reserved. + */ #include "includes.h" RCSID("$OpenBSD: session.c,v 1.150 2002/09/16 19:55:33 stevesk Exp $"); #ifdef HAVE_DEFOPEN
*** 52,61 **** --- 55,65 ---- #include "ssh.h" #include "ssh1.h" #include "ssh2.h" #include "xmalloc.h" + #include "sys-queue.h" #include "sshpty.h" #include "packet.h" #include "buffer.h" #include "mpaux.h" #include "uidswap.h"
*** 137,147 **** /* original command from peer. */ const char *original_command = NULL; /* data */ #define MAX_SESSIONS 10 ! Session sessions[MAX_SESSIONS]; #define SUBSYSTEM_NONE 0 #define SUBSYSTEM_EXT 1 #define SUBSYSTEM_INT_SFTP 2 --- 141,153 ---- /* original command from peer. */ const char *original_command = NULL; /* data */ #define MAX_SESSIONS 10 ! static int sessions_next_id = 0; ! static LIST_HEAD(sessions_head, Session) sessions = ! LIST_HEAD_INITIALIZER(sessions); #define SUBSYSTEM_NONE 0 #define SUBSYSTEM_EXT 1 #define SUBSYSTEM_INT_SFTP 2
*** 1525,1568 **** } Session * session_new(void) { ! int i; ! static int did_init = 0; ! if (!did_init) { debug("session_new: init"); ! for (i = 0; i < MAX_SESSIONS; i++) { ! sessions[i].used = 0; ! } ! did_init = 1; ! } ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (! s->used) { memset(s, 0, sizeof(*s)); s->chanid = -1; s->ptyfd = -1; s->ttyfd = -1; ! s->used = 1; ! s->self = i; s->env = NULL; ! debug("session_new: session %d", i); ! return s; ! } ! } ! return NULL; } static void session_dump(void) { ! int i; ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! debug("dump: used %d session %d %p channel %d pid %ld", ! s->used, s->self, s, s->chanid, (long)s->pid); } --- 1531,1564 ---- } Session * session_new(void) { ! Session *s; ! debug("session_new: init"); ! ! s = xmalloc(sizeof (*s)); memset(s, 0, sizeof(*s)); s->chanid = -1; s->ptyfd = -1; s->ttyfd = -1; ! s->self = sessions_next_id++; s->env = NULL; ! LIST_INSERT_HEAD(&sessions, s, list_entry); ! ! debug("session_new: session %d", s->self); ! ! return (s); } static void session_dump(void) { ! Session *s; ! LIST_FOREACH(s, &sessions, list_entry) { ! debug("dump: session %d %p channel %d pid %ld", s->self, s, s->chanid, (long)s->pid); }
*** 1588,1602 **** #ifndef lint Session * session_by_tty(char *tty) { ! int i; ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (s->used && s->ttyfd != -1 && strcmp(s->tty, tty) == 0) { ! debug("session_by_tty: session %d tty %s", i, tty); return s; } } debug("session_by_tty: unknown tty %.100s", tty); session_dump(); --- 1584,1597 ---- #ifndef lint Session * session_by_tty(char *tty) { ! Session *s; ! LIST_FOREACH(s, &sessions, list_entry) { ! if (s->ttyfd != -1 && strcmp(s->tty, tty) == 0) { ! debug("session_by_tty: session %d tty %s", s->self, tty); return s; } } debug("session_by_tty: unknown tty %.100s", tty); session_dump();
*** 1605,1619 **** #endif /* lint */ static Session * session_by_channel(int id) { ! int i; ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (s->used && s->chanid == id) { ! debug("session_by_channel: session %d channel %d", i, id); return s; } } debug("session_by_channel: unknown channel %d", id); session_dump(); --- 1600,1613 ---- #endif /* lint */ static Session * session_by_channel(int id) { ! Session *s; ! LIST_FOREACH(s, &sessions, list_entry) { ! if (s->chanid == id) { ! debug("session_by_channel: session %d channel %d", s->self, id); return s; } } debug("session_by_channel: unknown channel %d", id); session_dump();
*** 1621,1635 **** } static Session * session_by_pid(pid_t pid) { ! int i; debug("session_by_pid: pid %ld", (long)pid); ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (s->used && s->pid == pid) return s; } error("session_by_pid: unknown pid %ld", (long)pid); session_dump(); return NULL; --- 1615,1628 ---- } static Session * session_by_pid(pid_t pid) { ! Session *s; debug("session_by_pid: pid %ld", (long)pid); ! LIST_FOREACH(s, &sessions, list_entry) { ! if (s->pid == pid) return s; } error("session_by_pid: unknown pid %ld", (long)pid); session_dump(); return NULL;
*** 2285,2296 **** if (s->auth_proto) xfree(s->auth_proto); if (s->command) xfree(s->command); session_free_env(&s->env); ! s->used = 0; session_proctitle(s); } void session_close_by_pid(pid_t pid, int status) { --- 2278,2291 ---- if (s->auth_proto) xfree(s->auth_proto); if (s->command) xfree(s->command); session_free_env(&s->env); ! ! LIST_REMOVE(s, list_entry); session_proctitle(s); + xfree(s); } void session_close_by_pid(pid_t pid, int status) {
*** 2339,2369 **** } void session_destroy_all(void (*closefunc)(Session *)) { ! int i; ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (s->used) { if (closefunc != NULL) closefunc(s); else session_close(s); } - } } static char * session_tty_list(void) { static char buf[1024]; - int i; buf[0] = '\0'; ! for (i = 0; i < MAX_SESSIONS; i++) { ! Session *s = &sessions[i]; ! if (s->used && s->ttyfd != -1) { if (buf[0] != '\0') strlcat(buf, ",", sizeof buf); strlcat(buf, strrchr(s->tty, '/') + 1, sizeof buf); } } --- 2334,2360 ---- } void session_destroy_all(void (*closefunc)(Session *)) { ! Session *s; ! LIST_FOREACH(s, &sessions, list_entry) { if (closefunc != NULL) closefunc(s); else session_close(s); } } static char * session_tty_list(void) { + Session *s; static char buf[1024]; buf[0] = '\0'; ! LIST_FOREACH(s, &sessions, list_entry) { ! if (s->ttyfd != -1) { if (buf[0] != '\0') strlcat(buf, ",", sizeof buf); strlcat(buf, strrchr(s->tty, '/') + 1, sizeof buf); } }