Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit eb811e9f authored by deuce's avatar deuce

What's good for the client is good for the server - serialize access to the

ssh session.
parent e0463309
......@@ -189,9 +189,11 @@ bool sbbs_t::answer()
}
#ifdef USE_CRYPTLIB
if(sys_status&SS_SSH) {
pthread_mutex_lock(&ssh_mutex);
cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, rlogin_name, &i);
rlogin_name[i]=0;
cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, rlogin_pass, &i);
pthread_mutex_unlock(&ssh_mutex);
rlogin_pass[i]=0;
lprintf(LOG_DEBUG,"Node %d SSH login: '%s'"
,cfg.node_num, rlogin_name);
......
......@@ -71,7 +71,7 @@
#endif // _WIN32
#ifdef USE_CRYPTLIB
#define SSH_END() if(ssh) cryptDestroySession(sbbs->ssh_session);
#define SSH_END() if(ssh) { pthread_mutex_lock(&sbbs->ssh_mutex); cryptDestroySession(sbbs->ssh_session); pthread_mutex_unlock(&sbbs->ssh_mutex); }
#else
#define SSH_END()
#endif
......@@ -1521,6 +1521,7 @@ void input_thread(void *arg)
#endif
pthread_mutex_init(&sbbs->input_thread_mutex,NULL);
pthread_mutex_init(&sbbs->ssh_mutex,NULL);
sbbs->input_thread_running = true;
sbbs->console|=CON_R_INPUT;
......@@ -1641,7 +1642,9 @@ void input_thread(void *arg)
#ifdef USE_CRYPTLIB
if(sbbs->ssh_mode && sock==sbbs->client_socket) {
int err;
pthread_mutex_lock(&sbbs->ssh_mutex);
if(!cryptStatusOK((err=cryptPopData(sbbs->ssh_session, (char*)inbuf, rd, &i)))) {
pthread_mutex_unlock(&sbbs->ssh_mutex);
if(pthread_mutex_unlock(&sbbs->input_thread_mutex)!=0)
sbbs->errormsg(WHERE,ERR_UNLOCK,"input_thread_mutex",0);
if(err==CRYPT_ERROR_TIMEOUT)
......@@ -1651,6 +1654,7 @@ void input_thread(void *arg)
break;
}
else {
pthread_mutex_unlock(&sbbs->ssh_mutex);
if(!i) {
if(pthread_mutex_unlock(&sbbs->input_thread_mutex)!=0)
sbbs->errormsg(WHERE,ERR_UNLOCK,"input_thread_mutex",0);
......@@ -1756,6 +1760,8 @@ void input_thread(void *arg)
if(node_socket[sbbs->cfg.node_num-1]==INVALID_SOCKET) // Shutdown locally
sbbs->terminated = true; // Signal JS to stop execution
while(pthread_mutex_destroy(&sbbs->ssh_mutex)==EBUSY)
mswait(1);
while(pthread_mutex_destroy(&sbbs->input_thread_mutex)==EBUSY)
mswait(1);
......@@ -1834,13 +1840,17 @@ void passthru_output_thread(void* arg)
#ifdef USE_CRYPTLIB
if(sbbs->ssh_mode) {
pthread_mutex_lock(&sbbs->ssh_mutex);
if(!cryptStatusOK(cryptPopData(sbbs->ssh_session, (char*)inbuf, rd, &i)))
rd=0;
else {
if(!i)
if(!i) {
pthread_mutex_unlock(&sbbs->ssh_mutex);
continue;
}
rd=i;
}
pthread_mutex_unlock(&sbbs->ssh_mutex);
}
else
#endif
......@@ -2106,6 +2116,7 @@ void output_thread(void* arg)
#ifdef USE_CRYPTLIB
if(sbbs->ssh_mode) {
int err;
pthread_mutex_lock(&sbbs->ssh_mutex);
if(!cryptStatusOK((err=cryptPushData(sbbs->ssh_session, (char*)buf+bufbot, buftop-bufbot, &i)))) {
/* Handle the SSH error here... */
lprintf(LOG_WARNING,"%s !ERROR %d sending on Cryptlib session", node, err);
......@@ -2114,6 +2125,7 @@ void output_thread(void* arg)
}
else
cryptFlushData(sbbs->ssh_session);
pthread_mutex_unlock(&sbbs->ssh_mutex);
}
else
#endif
......
......@@ -226,6 +226,7 @@ public:
HANDLE input_thread;
pthread_mutex_t input_thread_mutex;
bool input_thread_mutex_locked; // by someone other than the input_thread
pthread_mutex_t ssh_mutex;
int outcom(uchar ch); // send character
int incom(unsigned long timeout=0); // receive character
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment