2016-02-07 01:10:44 +08:00
|
|
|
/* Constants */
|
|
|
|
|
|
|
|
static int const RINETD_BUFFER_SIZE = 16384;
|
|
|
|
static int const RINETD_LISTEN_BACKLOG = 128;
|
|
|
|
|
|
|
|
#define RINETD_CONFIG_FILE "/etc/rinetd.conf"
|
|
|
|
#define RINETD_PID_FILE "/var/run/rinetd.pid"
|
|
|
|
|
|
|
|
/* Program state */
|
|
|
|
|
|
|
|
enum ruleType {
|
|
|
|
allowRule,
|
|
|
|
denyRule,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _rule Rule;
|
|
|
|
struct _rule
|
|
|
|
{
|
|
|
|
char *pattern;
|
|
|
|
int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _server_info ServerInfo;
|
|
|
|
struct _server_info {
|
|
|
|
SOCKET fd;
|
|
|
|
|
|
|
|
/* In network order, for network purposes */
|
|
|
|
struct in_addr localAddr;
|
|
|
|
unsigned short localPort;
|
|
|
|
|
|
|
|
/* In ASCII and local byte order, for logging purposes */
|
|
|
|
char *fromHost, *toHost;
|
2017-09-05 07:45:00 +08:00
|
|
|
int fromPort, fromProto, toPort, toProto;
|
2016-02-07 01:10:44 +08:00
|
|
|
|
|
|
|
/* Offset and count into list of allow and deny rules. Any rules
|
|
|
|
prior to globalAllowRules and globalDenyRules are global rules. */
|
|
|
|
int rulesStart, rulesCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _socket Socket;
|
|
|
|
struct _socket
|
|
|
|
{
|
|
|
|
SOCKET fd;
|
2017-09-05 07:45:00 +08:00
|
|
|
int proto;
|
2016-02-07 01:10:44 +08:00
|
|
|
/* recv: received on this socket
|
|
|
|
sent: sent to this socket from the other buffer */
|
|
|
|
int recvPos, sentPos;
|
|
|
|
int recvBytes, sentBytes;
|
|
|
|
char *buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _connection_info ConnectionInfo;
|
|
|
|
struct _connection_info
|
|
|
|
{
|
|
|
|
Socket remote, local;
|
|
|
|
struct in_addr reAddresses;
|
|
|
|
int coClosing;
|
|
|
|
int coLog;
|
2016-02-08 09:36:23 +08:00
|
|
|
ServerInfo const *server; // only useful for logEvent
|
2016-02-07 01:10:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Option parsing */
|
|
|
|
|
|
|
|
typedef struct _rinetd_options RinetdOptions;
|
|
|
|
struct _rinetd_options
|
|
|
|
{
|
|
|
|
char const *conf_file;
|
|
|
|
int foreground;
|
|
|
|
};
|
|
|
|
|