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 99a6e198 authored by rswindell's avatar rswindell

Created set_socket_options function that parses ctrl/sockopts.cfg for flexible

control of socket options for all open and accepted sockets.
parent ffc970d9
......@@ -229,12 +229,15 @@ static void thread_down(void)
static SOCKET ftp_open_socket(int type)
{
SOCKET sock;
SOCKET sock;
char error[256];
sock=socket(AF_INET, type, IPPROTO_IP);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(TRUE);
if(sock!=INVALID_SOCKET) {
if(set_socket_options(&scfg, sock, error))
lprintf("%04d !ERROR %s",sock, error);
sockets++;
#ifdef _DEBUG
lprintf("%04d Socket opened (%u sockets in use)",sock,sockets);
......@@ -1778,6 +1781,7 @@ static void filexfer(SOCKADDR_IN* addr, SOCKET ctrl_sock, SOCKET pasv_sock, SOCK
,BOOL append
,char* desc)
{
char error[256];
int result;
socklen_t addr_len;
SOCKADDR_IN server_addr;
......@@ -1906,6 +1910,9 @@ static void filexfer(SOCKADDR_IN* addr, SOCKET ctrl_sock, SOCKET pasv_sock, SOCK
if(startup->options&FTP_OPT_DEBUG_DATA)
lprintf("%04d PASV DATA socket %d connected to %s port %u"
,ctrl_sock,*data_sock,inet_ntoa(addr->sin_addr),ntohs(addr->sin_port));
if(set_socket_options(&scfg, *data_sock, error))
lprintf("%04d !PASV DATA ERROR %s for socket %d"
,ctrl_sock,error,*data_sock);
}
if((xfer=malloc(sizeof(xfer_t)))==NULL) {
......@@ -4542,6 +4549,9 @@ void DLLCALL ftp_server(void* arg)
startup->socket_open(TRUE);
sockets++;
if(set_socket_options(&scfg, client_socket, error))
lprintf("%04d !ERROR %s",client_socket, error);
if(active_clients>=startup->max_clients) {
lprintf("%04d !MAXMIMUM CLIENTS (%d) reached, access denied"
,client_socket, startup->max_clients);
......
......@@ -211,12 +211,16 @@ static void thread_down(void)
SOCKET mail_open_socket(int type)
{
SOCKET sock;
char error[256];
SOCKET sock;
sock=socket(AF_INET, type, IPPROTO_IP);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(TRUE);
if(sock!=INVALID_SOCKET) {
if(set_socket_options(&scfg, sock,error))
lprintf("%04d !ERROR %s",sock,error);
sockets++;
#if 0 /*def _DEBUG */
lprintf("%04d Socket opened (%d sockets in use)",sock,sockets);
......@@ -3017,6 +3021,9 @@ void DLLCALL mail_server(void* arg)
startup->socket_open(TRUE);
sockets++;
if(set_socket_options(&scfg, client_socket, error))
lprintf("%04d !ERROR %s",client_socket, error);
if(active_clients>=startup->max_clients) {
lprintf("%04d !MAXMIMUM CLIENTS (%u) reached, access denied"
,client_socket, startup->max_clients);
......@@ -3065,6 +3072,9 @@ void DLLCALL mail_server(void* arg)
startup->socket_open(TRUE);
sockets++;
if(set_socket_options(&scfg, client_socket, error))
lprintf("%04d !ERROR %s",client_socket, error);
if(active_clients>=startup->max_clients) {
lprintf("%04d !MAXMIMUM CLIENTS (%u) reached, access denied"
,client_socket, startup->max_clients);
......
......@@ -175,11 +175,15 @@ int eprintf(char *fmt, ...)
SOCKET open_socket(int type)
{
SOCKET sock;
SOCKET sock;
char error[256];
sock=socket(AF_INET, type, IPPROTO_IP);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(TRUE);
if(sock!=INVALID_SOCKET && set_socket_options(&scfg, sock, error))
lprintf("%04d !ERROR %s",sock,error);
return(sock);
}
......@@ -3551,6 +3555,9 @@ void DLLCALL bbs_thread(void* arg)
continue;
}
if(set_socket_options(&scfg, client_socket, logstr))
lprintf("%04d !ERROR %s",client_socket, logstr);
sbbs->client_socket=client_socket; // required for output to the user
sbbs->online=ON_REMOTE;
......
......@@ -394,6 +394,10 @@ SOURCE=.\smbtxt.c
# End Source File
# Begin Source File
SOURCE=.\sockopts.c
# End Source File
# Begin Source File
SOURCE=.\sortdir.cpp
# End Source File
# Begin Source File
......
......@@ -815,6 +815,9 @@ extern "C" {
DLLEXPORT BOOL DLLCALL getmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan);
DLLEXPORT BOOL DLLCALL putmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan);
/* sockopt.c */
DLLEXPORT int DLLCALL set_socket_options(scfg_t* cfg, SOCKET sock, char* error);
#ifdef JAVASCRIPT
/* js_global.c */
......
......@@ -183,13 +183,17 @@ static void thread_down(void)
static SOCKET open_socket(int type)
{
SOCKET sock;
char error[256];
SOCKET sock;
sock=socket(AF_INET, type, IPPROTO_IP);
if(sock!=INVALID_SOCKET && startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(TRUE);
if(sock!=INVALID_SOCKET) {
sockets++;
if(set_socket_options(&scfg, sock, error))
lprintf("%04d !ERROR %s",sock, error);
#if 0 /*def _DEBUG */
lprintf("%04d Socket opened (%d sockets in use)",sock,sockets);
#endif
......@@ -1214,6 +1218,9 @@ void DLLCALL services_thread(void* arg)
,client_socket
,service[i].protocol, host_ip, ntohs(client_addr.sin_port));
if(set_socket_options(&scfg, client_socket, error))
lprintf("%04d !ERROR %s",client_socket, error);
if(service[i].max_clients && service[i].clients+1>service[i].max_clients) {
lprintf("%04d !%s MAXMIMUM CLIENTS (%u) reached, access denied"
,client_socket, service[i].protocol, service[i].max_clients);
......
/* sockopts.c */
/* Set socket options based on contents of ctrl/sockopts.cfg */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "sbbs.h"
typedef struct {
char* name;
int value;
} sockopt_name;
static const sockopt_name option_names[] = {
{ "DEBUG", SO_DEBUG },
{ "ACCEPTCONN", SO_ACCEPTCONN },
{ "REUSEADDR", SO_REUSEADDR },
{ "KEEPALIVE", SO_KEEPALIVE },
{ "DONTROUTE", SO_DONTROUTE },
{ "BROADCAST", SO_BROADCAST },
{ "USELOOPBACK", SO_USELOOPBACK },
{ "OOBINLINE", SO_OOBINLINE },
{ "SNDBUF", SO_SNDBUF },
{ "RCVBUF", SO_RCVBUF },
{ "SNDLOWAT", SO_SNDLOWAT },
{ "RCVLOWAT", SO_RCVLOWAT },
{ "SNDTIMEO", SO_SNDTIMEO },
{ "RCVTIMEO", SO_RCVTIMEO },
{ NULL }
};
static int sockopt(char* str)
{
int i;
for(i=0;option_names[i].name;i++) {
if(stricmp(str,option_names[i].name))
return(option_names[i].value);
}
return(strtoul(str,NULL,0));
}
int DLLCALL set_socket_options(scfg_t* cfg, SOCKET sock, char* error)
{
char cfgfile[MAX_PATH+1];
char str[256];
char* p;
FILE* fp;
int option;
int value;
int result=0;
sprintf(cfgfile,"%ssockopts.cfg",cfg->ctrl_dir);
if((fp=fopen(cfgfile,"r"))==NULL)
return(0);
while(!feof(fp)) {
if(!fgets(str,sizeof(str)-1,fp))
break;
if(str[0]==';')
continue;
p=str;
while(*p && *p>' ') p++;
if(*p) *p=0;
option=sockopt(str);
p++;
while(*p && *p<=' ') p++;
value=strtoul(p,NULL,0);
#if 0
lprintf("%04d setting socket option: %s to %d", sock, str, value);
#endif
result=setsockopt(sock,SOL_SOCKET,option,(char*)&value,sizeof(value));
if(result) {
sprintf(error,"%d (%d) setting socket option (%s) to %d"
,result, ERROR_VALUE, str, value);
break;
}
#if 0
getsockopt(sock,SOL_SOCKET,option,(char*)&value,&len);
lprintf("%04d socket option: %s set to %d", sock, str, value);
#endif
}
fclose(fp);
return(result);
}
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