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

...
 
Commits (1)
  • Deucе's avatar
    Add support for telnets (Telnet over SSL) · 508b5c96
    Deucе authored
    It's not clear if this is working properly or not since the only
    BBS I know of that supports telnets (fido.beholderbbs.org) doesn't
    seem to do any telnet "stuff".
    508b5c96
......@@ -35,6 +35,7 @@
#include "rlogin.h"
#include "raw.h"
#include "ssh.h"
#include "telnets.h"
#ifndef __HAIKU__
#include "modem.h"
#endif
......@@ -44,13 +45,9 @@
#include "conn_telnet.h"
struct conn_api conn_api;
char *conn_types_enum[]={"Unknown","RLogin","RLoginReversed","Telnet","Raw","SSH","Modem","Serial","Shell","MBBSGhost",NULL};
char *conn_types[]={"Unknown","RLogin","RLogin Reversed","Telnet","Raw","SSH","Modem","Serial","Shell","MBBS GHost",NULL};
short unsigned int conn_ports[]={0,513,513,23,0,22,0,0,0
#ifdef __unix__
,65535
#endif
,0};
char *conn_types_enum[]={"Unknown","RLogin","RLoginReversed","Telnet","Raw","SSH","Modem","Serial","Shell","MBBSGhost","TelnetS", NULL};
char *conn_types[]={"Unknown","RLogin","RLogin Reversed","Telnet","Raw","SSH","Modem","Serial","Shell","MBBS GHost","TelnetS",NULL};
short unsigned int conn_ports[]={0,513,513,23,0,22,0,0,0,65535,992,0};
struct conn_buffer conn_inbuf;
struct conn_buffer conn_outbuf;
......@@ -364,6 +361,12 @@ int conn_connect(struct bbslist *bbs)
conn_api.close=raw_close;
break;
#ifndef WITHOUT_CRYPTLIB
case CONN_TYPE_TELNETS:
conn_api.connect=telnets_connect;
conn_api.close=telnets_close;
conn_api.binary_mode_on=telnet_binary_mode_on;
conn_api.binary_mode_off=telnet_binary_mode_off;
break;
case CONN_TYPE_SSH:
conn_api.connect=ssh_connect;
conn_api.close=ssh_close;
......
......@@ -25,6 +25,7 @@ enum {
,CONN_TYPE_SERIAL
,CONN_TYPE_SHELL
,CONN_TYPE_MBBS_GHOST
,CONN_TYPE_TELNETS
,CONN_TYPE_TERMINATOR
};
......
......@@ -19,7 +19,7 @@
extern int telnet_log_level;
static void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen)
void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen)
{
void *ret = malloc(inlen);
......@@ -30,7 +30,7 @@ static void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen)
return ret;
}
static void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen)
void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen)
{
void *ret = malloc(len * 2);
void *parsed;
......
......@@ -9,6 +9,8 @@ extern SOCKET telnet_sock;
void telnet_binary_mode_on(void);
void telnet_binary_mode_off(void);
int telnet_connect(struct bbslist *bbs);
void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen);
void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen);
#define telnet_close rlogin_close
#endif
......@@ -6,6 +6,7 @@ OBJS = \
$(MTOBJODIR)$(DIRSEP)ripper$(OFILE) \
$(MTOBJODIR)$(DIRSEP)rlogin$(OFILE) \
$(MTOBJODIR)$(DIRSEP)telnet_io$(OFILE) \
$(MTOBJODIR)$(DIRSEP)telnets$(OFILE) \
$(MTOBJODIR)$(DIRSEP)conn_telnet$(OFILE) \
$(MTOBJODIR)$(DIRSEP)conn$(OFILE) \
$(MTOBJODIR)$(DIRSEP)telnet$(OFILE) \
......
......@@ -19,12 +19,12 @@
#include "syncterm.h"
#include "window.h"
static SOCKET sock;
SOCKET ssh_sock;
CRYPT_SESSION ssh_session;
int ssh_active=FALSE;
pthread_mutex_t ssh_mutex;
static void cryptlib_error_message(int status, const char * msg)
void cryptlib_error_message(int status, const char * msg)
{
char str[64];
char str2[64];
......@@ -58,11 +58,11 @@ void ssh_input_thread(void *args)
conn_api.input_thread_running=1;
while(ssh_active && !conn_api.terminate) {
FD_ZERO(&rds);
FD_SET(sock, &rds);
FD_SET(ssh_sock, &rds);
tv.tv_sec = 0;
tv.tv_usec = 100;
rd=select(sock+1, &rds, NULL, NULL, &tv);
rd=select(ssh_sock+1, &rds, NULL, NULL, &tv);
if(rd==-1) {
if(errno==EBADF)
break;
......@@ -175,8 +175,8 @@ int ssh_connect(struct bbslist *bbs)
}
}
sock=conn_socket_connect(bbs);
if(sock==INVALID_SOCKET)
ssh_sock=conn_socket_connect(bbs);
if(ssh_sock==INVALID_SOCKET)
return(-1);
ssh_active=FALSE;
......@@ -196,7 +196,7 @@ int ssh_connect(struct bbslist *bbs)
}
/* we need to disable Nagle on the socket. */
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, ( char * )&off, sizeof ( off ) );
setsockopt(ssh_sock, IPPROTO_TCP, TCP_NODELAY, ( char * )&off, sizeof ( off ) );
SAFECOPY(password,bbs->password);
SAFECOPY(username,bbs->user);
......@@ -256,7 +256,7 @@ int ssh_connect(struct bbslist *bbs)
uifc.pop("Setting Username");
}
/* Pass socket to cryptlib */
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_NETWORKSOCKET, sock);
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_NETWORKSOCKET, ssh_sock);
if(cryptStatusError(status)) {
char str[1024];
sprintf(str,"Error %d passing socket",status);
......@@ -281,14 +281,12 @@ int ssh_connect(struct bbslist *bbs)
uifc.pop(NULL);
uifc.pop("Setting Terminal Width");
}
/* Pass socket to cryptlib */
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_SSH_WIDTH, cols);
if (!bbs->hidepopups) {
uifc.pop(NULL);
uifc.pop("Setting Terminal Height");
}
/* Pass socket to cryptlib */
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_SSH_HEIGHT, rows);
cl.SetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 1);
......@@ -355,8 +353,8 @@ int ssh_close(void)
SLEEP(1);
}
cl.DestroySession(ssh_session);
closesocket(sock);
sock=INVALID_SOCKET;
closesocket(ssh_sock);
ssh_sock=INVALID_SOCKET;
destroy_conn_buf(&conn_inbuf);
destroy_conn_buf(&conn_outbuf);
FREE_AND_NULL(conn_api.rd_buf);
......
......@@ -3,7 +3,16 @@
#ifndef _SSH_H_
#define _SSH_H_
#include "st_crypt.h"
int ssh_connect(struct bbslist *bbs);
int ssh_close(void);
void ssh_input_thread(void *args);
void ssh_output_thread(void *args);
extern SOCKET ssh_sock;
extern CRYPT_SESSION ssh_session;
extern int ssh_active;
extern pthread_mutex_t ssh_mutex;
void cryptlib_error_message(int status, const char * msg);
#endif
/* Copyright (C), 2007 by Stephen Hurd */
#include <stdlib.h>
#include "gen_defs.h"
#include "genwrap.h"
#include "sockwrap.h"
#include "threadwrap.h"
#include "bbslist.h"
#include "conn.h"
#include "uifcinit.h"
#include "ciolib.h"
#include "st_crypt.h"
#include "syncterm.h"
#include "window.h"
#include "conn_telnet.h"
#include "ssh.h"
int telnets_connect(struct bbslist *bbs)
{
int off=1;
int status;
if (!bbs->hidepopups)
init_uifc(TRUE, TRUE);
pthread_mutex_init(&ssh_mutex, NULL);
if(!crypt_loaded) {
if (!bbs->hidepopups) {
uifcmsg("Cannot load cryptlib - TelnetS inoperative", "`Cannot load cryptlib`\n\n"
"Cannot load the file "
#ifdef _WIN32
"cl32.dll"
#else
"libcl.so"
#endif
"\nThis file is required for TLS functionality.\n\n"
"The newest version is always available from:\n"
"http://www.cs.auckland.ac.nz/~pgut001/cryptlib/"
);
return(conn_api.terminate=-1);
}
}
ssh_sock=conn_socket_connect(bbs);
if(ssh_sock==INVALID_SOCKET)
return(-1);
ssh_active=FALSE;
if (!bbs->hidepopups)
uifc.pop("Creating Session");
status=cl.CreateSession(&ssh_session, CRYPT_UNUSED, CRYPT_SESSION_SSL);
if(cryptStatusError(status)) {
char str[1024];
sprintf(str,"Error %d creating session",status);
if (!bbs->hidepopups)
uifcmsg("Error creating session",str);
conn_api.terminate=1;
if (!bbs->hidepopups)
uifc.pop(NULL);
return(-1);
}
/* we need to disable Nagle on the socket. */
setsockopt(ssh_sock, IPPROTO_TCP, TCP_NODELAY, ( char * )&off, sizeof ( off ) );
if (!bbs->hidepopups)
uifc.pop(NULL);
/* Pass socket to cryptlib */
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_NETWORKSOCKET, ssh_sock);
if(cryptStatusError(status)) {
char str[1024];
sprintf(str,"Error %d passing socket",status);
if (!bbs->hidepopups)
uifcmsg("Error passing socket",str);
conn_api.terminate=1;
if (!bbs->hidepopups)
uifc.pop(NULL);
return(-1);
}
cl.SetAttribute(ssh_session, CRYPT_OPTION_NET_READTIMEOUT, 1);
/* Activate the session */
if (!bbs->hidepopups) {
uifc.pop(NULL);
uifc.pop("Activating Session");
}
status=cl.SetAttribute(ssh_session, CRYPT_SESSINFO_ACTIVE, 1);
if(cryptStatusError(status)) {
if (!bbs->hidepopups)
cryptlib_error_message(status, "activating session");
conn_api.terminate=1;
if (!bbs->hidepopups)
uifc.pop(NULL);
return(-1);
}
ssh_active=TRUE;
if (!bbs->hidepopups) {
/* Clear ownership */
uifc.pop(NULL); // TODO: Why is this called twice?
uifc.pop(NULL);
uifc.pop("Clearing Ownership");
}
status=cl.SetAttribute(ssh_session, CRYPT_PROPERTY_OWNER, CRYPT_UNUSED);
if(cryptStatusError(status)) {
if (!bbs->hidepopups)
cryptlib_error_message(status, "clearing session ownership");
conn_api.terminate=1;
if (!bbs->hidepopups)
uifc.pop(NULL);
return(-1);
}
if (!bbs->hidepopups)
uifc.pop(NULL);
create_conn_buf(&conn_inbuf, BUFFER_SIZE);
create_conn_buf(&conn_outbuf, BUFFER_SIZE);
conn_api.rd_buf=(unsigned char *)malloc(BUFFER_SIZE);
conn_api.rd_buf_size=BUFFER_SIZE;
conn_api.wr_buf=(unsigned char *)malloc(BUFFER_SIZE);
conn_api.wr_buf_size=BUFFER_SIZE;
conn_api.rx_parse_cb = telnet_rx_parse_cb;
conn_api.tx_parse_cb = telnet_tx_parse_cb;
_beginthread(ssh_output_thread, 0, NULL);
_beginthread(ssh_input_thread, 0, NULL);
if (!bbs->hidepopups)
uifc.pop(NULL); // TODO: Why is this called twice?
return(0);
}
#ifndef TELNETS_H
#define TELNETS_H
int telnets_connect(struct bbslist *bbs);
#define telnets_close ssh_close
#endif