summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Sławiński2006-02-05 15:14:03 +0100
committerJoshua Judson Rosen2014-07-17 21:15:02 +0200
commitb457fec36399c1f7de093d5e92bb4fa453b79c86 (patch)
tree2084c9a78d40213015e6f10e3e9e01bc4c0c51f1
parentUpdate copyright statements. (diff)
downloadapf-b457fec36399c1f7de093d5e92bb4fa453b79c86.tar.gz
v0.8
- Fixed: infinite loop after buffering message - Fixed: corrupt packets after closing connections in the stopped state - Fixed: bug in mapping user numbers between afclient and afserver - Fixed: premature close of the service connection - Fixed: invalid buffering when the connection is closing - Added: Multiple tunnels in one afclient<->afserver connection
-rw-r--r--ChangeLog8
-rw-r--r--NEWS11
-rw-r--r--README40
-rw-r--r--configure.ac16
-rw-r--r--doc/afclient.12
-rw-r--r--doc/afclient.conf.52
-rw-r--r--doc/afserver.12
-rw-r--r--doc/afserver.conf.52
-rw-r--r--doc/en/README40
-rw-r--r--src/Makefile.am3
-rw-r--r--src/activefor.h103
-rw-r--r--src/afclient.c203
-rw-r--r--src/afclient.h1
-rw-r--r--src/afserver.c300
-rw-r--r--src/ar_options_struct.c17
-rw-r--r--src/audit_list_node_struct.c18
-rw-r--r--src/audit_list_struct.c12
-rw-r--r--src/buf_list_node_struct.c41
-rw-r--r--src/buf_list_struct.c18
-rw-r--r--src/client_configuration_struct.c16
-rw-r--r--src/client_initialization.c2
-rw-r--r--src/client_realm_struct.c215
-rw-r--r--src/client_realm_struct.h9
-rw-r--r--src/client_remoteadmin.c12
-rw-r--r--src/client_reverse_udp.c29
-rw-r--r--src/client_shutdown.c7
-rw-r--r--src/clientnames.c43
-rw-r--r--src/connect_client_struct.c160
-rw-r--r--src/connect_client_struct.h6
-rw-r--r--src/connect_user_struct.c24
-rw-r--r--src/daemon.c12
-rw-r--r--src/file.c11
-rw-r--r--src/file_client.c29
-rw-r--r--src/file_server.c10
-rw-r--r--src/first_run.c69
-rw-r--r--src/header_buffer_struct.c9
-rw-r--r--src/http_proxy_client.c22
-rw-r--r--src/http_proxy_functions.c70
-rw-r--r--src/http_proxy_options_struct.c15
-rw-r--r--src/http_proxy_server.c32
-rw-r--r--src/logging.c82
-rw-r--r--src/make_ssl_handshake.c24
-rw-r--r--src/module_struct.c7
-rw-r--r--src/network.c100
-rw-r--r--src/port_list_node_struct.c140
-rw-r--r--src/port_list_node_struct.h40
-rw-r--r--src/port_list_struct.c167
-rw-r--r--src/port_list_struct.h42
-rw-r--r--src/realmnames.c22
-rw-r--r--src/server_check.c34
-rw-r--r--src/server_configuration_struct.c16
-rw-r--r--src/server_eval.c77
-rw-r--r--src/server_eval.h1
-rw-r--r--src/server_find.c77
-rw-r--r--src/server_find.h1
-rw-r--r--src/server_get.c17
-rw-r--r--src/server_realm_struct.c76
-rw-r--r--src/server_remoteadmin.c70
-rw-r--r--src/server_remove.c36
-rw-r--r--src/server_set.c12
-rw-r--r--src/server_signals.c8
-rw-r--r--src/ssl_fd_struct.c20
-rw-r--r--src/ssl_routines.c31
-rw-r--r--src/stats.c24
-rw-r--r--src/string_functions.c8
-rw-r--r--src/thread_management.c32
-rw-r--r--src/usage.c38
-rw-r--r--src/user_stats_struct.c23
-rw-r--r--src/usernames.c20
-rw-r--r--src/usr_cli_struct.c53
-rw-r--r--src/usr_cli_struct.h3
71 files changed, 2556 insertions, 386 deletions
diff --git a/ChangeLog b/ChangeLog
index 5a6a361..b9aeb51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+04.02.2006 (v0.8):
+ - Fixed: infinite loop after buffering message
+ - Fixed: corrupt packets after closing connections in the stopped state
+ - Fixed: bug in mapping user numbers between afclient and afserver
+ - Fixed: premature close of the service connection
+ - Fixed: invalid buffering when the connection is closing
+ - Added: Multiple tunnels in one afclient<->afserver connection
+
16.11.2005 (v0.7.5):
- Fixed: manageport option in the afclient config file
- Fixed: severe bug in string_cp
diff --git a/NEWS b/NEWS
index d042273..15a5a0c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+05.02.2006:
+ * debug feature (default is NO) has been added to the configure
+ script
+
+31.01.2006:
+ * a lot of bugs have been found and fixed due to automatic tests
+
+18.12.2005:
+ * the exemption to the license has been added in order to allow
+ linking with OpenSSL library
+
16.11.2005:
* it's time for new release containing several bugfixes
diff --git a/README b/README
index a9fcbce..cea4c66 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-AF - Active Port Forwarder 0.7.5 - README
+AF - Active Port Forwarder 0.8 - README
Copyright (C) 2003-2006 jeremian - <jeremian [at] poczta.fm>
=================================================================
@@ -39,10 +39,11 @@ INTRO
4. HTTP PROXY TUNNELS
5. LOGGING
6. MODULES
-7. EXAMPLES
- 7.1 tcp mode
- 7.2 reverse udp mode
-8. BUGS/PROBLEMS
+7. MULTI TUNNELS
+8. EXAMPLES
+ 8.1 tcp mode
+ 8.2 reverse udp mode
+9. BUGS/PROBLEMS
NOTES
@@ -517,11 +518,28 @@ Modules have to be compiled with '-fPIC -shared' options.
================================================================================
+================
+7. MULTI TUNNELS
+================
+
+Since version 0.8 it's possible to transfer multiple tunnels in the one
+afclient <-> afserver connection.
+
+On the afserver we have to specify multiple listen ports with the same manage
+port.
+
+When we set several '-p' options on the afclient, the new user connections will
+be distributed according to the sequence of the options, i.e. new user
+connecting to the second UsrCli pair (with the same manage ports) will be
+transferred to the destination pointed by the second '-p' option.
+
+================================================================================
+
===========
-7. EXAMPLES
+8. EXAMPLES
===========
- 7.1 tcp mode
+ 8.1 tcp mode
------------
local network |FireWall| Internet
@@ -570,7 +588,7 @@ on our computer and we are behind a masquerade or a firewall:
6) We can now enter with a web-browser to: <name of the server>:50127 and we
will enter to our computer in the fact.
- 7.2 reverse udp mode
+ 8.2 reverse udp mode
--------------------
local network |FireWall| Internet
@@ -609,7 +627,7 @@ server on our computer (udp port 27960 on our machine):
================================================================================
================
-8. BUGS/PROBLEMS
+9. BUGS/PROBLEMS
================
There are no known/open bugs at the moment.
@@ -652,3 +670,7 @@ LICENSE
Public License v2.0 and is copyright (C) 2003-2006 jeremian <jeremian
[at] poczta.fm>. See the file COPYING for details.
+ In addition, as a special exception, the copyright holders give permission to
+ link the code of portions of this program with the OpenSSL library under
+ certain conditions as described in each individual source file, and distribute
+ linked combinations including the two.
diff --git a/configure.ac b/configure.ac
index 88f591c..761e9fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,8 +2,8 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([Active port forwarder], [0.7.5], [jeremian@poczta.fm], [apf])
-AM_INIT_AUTOMAKE([apf], [0.7.5])
+AC_INIT([Active port forwarder], [0.8], [jeremian@poczta.fm], [apf])
+AM_INIT_AUTOMAKE([apf], [0.8])
AC_COPYRIGHT([
Copyright (C) 2003-2006 jeremian - <jeremian [[at]] poczta.fm>
===================
@@ -30,6 +30,18 @@ AC_CONFIG_FILES([Makefile
CFLAGS="-pedantic -Wall -O2"
+# Enabling/disabling asserts and debugging
+AC_MSG_CHECKING(whether to enable debugging)
+AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging
+ [default=no]],, enable_debug=no)
+if test "x$enable_debug" = "xyes"; then
+ CFLAGS="$CFLAGS -g"
+ AC_MSG_RESULT(yes)
+else
+ CFLAGS="$CFLAGS -DNDEBUG"
+ AC_MSG_RESULT(no)
+fi
+
# Checks for programs.
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
diff --git a/doc/afclient.1 b/doc/afclient.1
index c59816e..a7833b1 100644
--- a/doc/afclient.1
+++ b/doc/afclient.1
@@ -1,4 +1,4 @@
-.TH afclient 1 "apf 0.7.5" Jeremian
+.TH afclient 1 "apf 0.8" Jeremian
.SH NAME
afclient \- active port forwarder client
.SH SYNOPSIS
diff --git a/doc/afclient.conf.5 b/doc/afclient.conf.5
index d7cf75b..abd9dd2 100644
--- a/doc/afclient.conf.5
+++ b/doc/afclient.conf.5
@@ -1,4 +1,4 @@
-.TH afclient.conf 5 "apf 0.7.5" Jeremian
+.TH afclient.conf 5 "apf 0.8" Jeremian
.SH NAME
afclient.conf \- Configuration File for afclient
.SH INTRODUCTION
diff --git a/doc/afserver.1 b/doc/afserver.1
index 217509f..0691ebd 100644
--- a/doc/afserver.1
+++ b/doc/afserver.1
@@ -1,4 +1,4 @@
-.TH afserver 1 "apf 0.7.5" Jeremian
+.TH afserver 1 "apf 0.8" Jeremian
.SH NAME
afserver \- active port forwarder server
.SH SYNOPSIS
diff --git a/doc/afserver.conf.5 b/doc/afserver.conf.5
index e60e8b5..a86ff78 100644
--- a/doc/afserver.conf.5
+++ b/doc/afserver.conf.5
@@ -1,4 +1,4 @@
-.TH afserver.conf 5 "apf 0.7.5" Jeremian
+.TH afserver.conf 5 "apf 0.8" Jeremian
.SH NAME
afserver.conf \- Configuration File for afserver
.SH INTRODUCTION
diff --git a/doc/en/README b/doc/en/README
index a9fcbce..cea4c66 100644
--- a/doc/en/README
+++ b/doc/en/README
@@ -1,4 +1,4 @@
-AF - Active Port Forwarder 0.7.5 - README
+AF - Active Port Forwarder 0.8 - README
Copyright (C) 2003-2006 jeremian - <jeremian [at] poczta.fm>
=================================================================
@@ -39,10 +39,11 @@ INTRO
4. HTTP PROXY TUNNELS
5. LOGGING
6. MODULES
-7. EXAMPLES
- 7.1 tcp mode
- 7.2 reverse udp mode
-8. BUGS/PROBLEMS
+7. MULTI TUNNELS
+8. EXAMPLES
+ 8.1 tcp mode
+ 8.2 reverse udp mode
+9. BUGS/PROBLEMS
NOTES
@@ -517,11 +518,28 @@ Modules have to be compiled with '-fPIC -shared' options.
================================================================================
+================
+7. MULTI TUNNELS
+================
+
+Since version 0.8 it's possible to transfer multiple tunnels in the one
+afclient <-> afserver connection.
+
+On the afserver we have to specify multiple listen ports with the same manage
+port.
+
+When we set several '-p' options on the afclient, the new user connections will
+be distributed according to the sequence of the options, i.e. new user
+connecting to the second UsrCli pair (with the same manage ports) will be
+transferred to the destination pointed by the second '-p' option.
+
+================================================================================
+
===========
-7. EXAMPLES
+8. EXAMPLES
===========
- 7.1 tcp mode
+ 8.1 tcp mode
------------
local network |FireWall| Internet
@@ -570,7 +588,7 @@ on our computer and we are behind a masquerade or a firewall:
6) We can now enter with a web-browser to: <name of the server>:50127 and we
will enter to our computer in the fact.
- 7.2 reverse udp mode
+ 8.2 reverse udp mode
--------------------
local network |FireWall| Internet
@@ -609,7 +627,7 @@ server on our computer (udp port 27960 on our machine):
================================================================================
================
-8. BUGS/PROBLEMS
+9. BUGS/PROBLEMS
================
There are no known/open bugs at the moment.
@@ -652,3 +670,7 @@ LICENSE
Public License v2.0 and is copyright (C) 2003-2006 jeremian <jeremian
[at] poczta.fm>. See the file COPYING for details.
+ In addition, as a special exception, the copyright holders give permission to
+ link the code of portions of this program with the OpenSSL library under
+ certain conditions as described in each individual source file, and distribute
+ linked combinations including the two.
diff --git a/src/Makefile.am b/src/Makefile.am
index 6f8b46b..68e6679 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,4 +17,5 @@ afclient_SOURCES = afclient.c network.c file.c stats.c buf_list_node_struct.c bu
string_functions.c ar_options_struct.c audit_list_node_struct.c audit_list_struct.c \
ssl_fd_struct.c timeval_functions.c server_realm_struct.c server_configuration_struct.c \
usr_cli_struct.c connect_client_struct.c header_buffer_struct.c \
- client_configuration_struct.c file_client.c client_realm_struct.c
+ client_configuration_struct.c file_client.c client_realm_struct.c \
+ port_list_node_struct.c port_list_struct.c
diff --git a/src/activefor.h b/src/activefor.h
index 71a605a..9ce940b 100644
--- a/src/activefor.h
+++ b/src/activefor.h
@@ -29,62 +29,69 @@
#include "ssl_fd_struct.h"
#include "connect_client_struct.h"
-#define AF_S_CONCLOSED 1
-#define AF_S_CONOPEN 2
-#define AF_S_MESSAGE 3
-#define AF_S_CLOSING 4
-#define AF_S_LOGIN 8
-#define AF_S_DONT_SEND 9
-#define AF_S_CAN_SEND 10
-#define AF_S_CANT_OPEN 12
+#define AF_S_CONCLOSED 1
+#define AF_S_CONOPEN 2
+#define AF_S_MESSAGE 3
+#define AF_S_CLOSING 4
+#define AF_S_LOGIN 8
+#define AF_S_DONT_SEND 9
+#define AF_S_CAN_SEND 10
+#define AF_S_CANT_OPEN 12
+#define AF_S_ENABLE_MULTI 18
-#define AF_S_WRONG 13
-#define AF_S_ADMIN_LOGIN 14
-#define AF_S_ADMIN_CMD 15
+#define AF_S_WRONG 13
+#define AF_S_ADMIN_LOGIN 14
+#define AF_S_ADMIN_CMD 15
-#define AF_S_KEEP_ALIVE 16
+#define AF_S_KEEP_ALIVE 16
-#define S_STATE_CLEAR 0
-#define S_STATE_CLOSING 5
-#define S_STATE_OPENING 6
-#define S_STATE_OPEN 7
-#define S_STATE_STOPPED 11
-#define S_STATE_OPENING_CLOSED 17
+#define S_STATE_CLEAR 0
+#define S_STATE_CLOSING 5
+#define S_STATE_OPENING 6
+#define S_STATE_OPEN 7
+#define S_STATE_STOPPED 11
+#define S_STATE_OPENING_CLOSED 17
+#define S_STATE_KICKING 19
-#define AF_VER(info) info" v0.7.5"
+#define AF_VER(info) info" v0.8"
-#define TYPE_TCP 1
-#define TYPE_UDP 3
-#define TYPE_SSL 4
-#define TYPE_ZLIB 8
-#define TYPE_IPV4 16
-#define TYPE_IPV6 32
-#define TYPE_COMP 0x4000
+#define TYPE_TCP 1
+#define TYPE_UDP 3
+#define TYPE_SSL 4
+#define TYPE_ZLIB 8
+#define TYPE_IPV4 16
+#define TYPE_IPV6 32
+#define TYPE_SUPPORTS_MULTI 64
+#define TYPE_COMP 0x4000
-#define TYPE_SET_ZERO(type) (type=0)
-#define TYPE_IS_SET(type) (type&1)
-#define TYPE_IS_UDP(type) TYPE_IS_SET(type)&&(type&2)
-#define TYPE_IS_TCP(type) TYPE_IS_SET(type)&&(!(type&2))
-#define TYPE_SET_UDP(type) (type|=TYPE_UDP)
-#define TYPE_SET_TCP(type) (type|=TYPE_TCP)
-#define TYPE_SET_SSL(type) (type|=TYPE_SSL)
-#define TYPE_UNSET_SSL(type) (type&=(~TYPE_SSL))
-#define TYPE_IS_SSL(type) (type&TYPE_SSL)
-#define TYPE_SET_ZLIB(type) (type|=TYPE_ZLIB)
-#define TYPE_UNSET_ZLIB(type) (type&=(~TYPE_ZLIB))
-#define TYPE_IS_ZLIB(type) (type&TYPE_ZLIB)
+#define TYPE_SET_ZERO(type) (type=0)
+#define TYPE_IS_SET(type) (type&1)
+#define TYPE_IS_UDP(type) TYPE_IS_SET(type)&&(type&2)
+#define TYPE_IS_TCP(type) TYPE_IS_SET(type)&&(!(type&2))
+#define TYPE_SET_UDP(type) (type|=TYPE_UDP)
+#define TYPE_SET_TCP(type) (type|=TYPE_TCP)
+#define TYPE_SET_SSL(type) (type|=TYPE_SSL)
+#define TYPE_UNSET_SSL(type) (type&=(~TYPE_SSL))
+#define TYPE_IS_SSL(type) (type&TYPE_SSL)
+#define TYPE_SET_ZLIB(type) (type|=TYPE_ZLIB)
+#define TYPE_UNSET_ZLIB(type) (type&=(~TYPE_ZLIB))
+#define TYPE_IS_ZLIB(type) (type&TYPE_ZLIB)
-#define TYPE_SET_IPV4(type) (type|=TYPE_IPV4)
-#define TYPE_UNSET_IPV4(type) (type&=(~TYPE_IPV4))
-#define TYPE_IS_IPV4(type) (type&TYPE_IPV4)
-#define TYPE_SET_IPV6(type) (type|=TYPE_IPV6)
-#define TYPE_UNSET_IPV6(type) (type&=(~TYPE_IPV6))
-#define TYPE_IS_IPV6(type) (type&TYPE_IPV6)
-#define TYPE_SET_UNSPEC(type) (type&=(~(TYPE_IPV4|TYPE_IPV6)))
-#define TYPE_IS_UNSPEC(type) (!(type&(TYPE_IPV4|TYPE_IPV6)))
+#define TYPE_SET_IPV4(type) (type|=TYPE_IPV4)
+#define TYPE_UNSET_IPV4(type) (type&=(~TYPE_IPV4))
+#define TYPE_IS_IPV4(type) (type&TYPE_IPV4)
+#define TYPE_SET_IPV6(type) (type|=TYPE_IPV6)
+#define TYPE_UNSET_IPV6(type) (type&=(~TYPE_IPV6))
+#define TYPE_IS_IPV6(type) (type&TYPE_IPV6)
+#define TYPE_SET_UNSPEC(type) (type&=(~(TYPE_IPV4|TYPE_IPV6)))
+#define TYPE_IS_UNSPEC(type) (!(type&(TYPE_IPV4|TYPE_IPV6)))
-#define TYPE_SET_COMP(type) (type|=TYPE_COMP)
-#define TYPE_IS_COMP(type) (type&TYPE_COMP)
+#define TYPE_SET_SUPPORTED_MULTI(type) (type|=TYPE_SUPPORTS_MULTI)
+#define TYPE_UNSET_SUPPORTED_MULTI(type) (type&=(~TYPE_SUPPORTS_MULTI))
+#define TYPE_IS_SUPPORTED_MULTI(type) (type&TYPE_SUPPORTS_MULTI)
+
+#define TYPE_SET_COMP(type) (type|=TYPE_COMP)
+#define TYPE_IS_COMP(type) (type&TYPE_COMP)
#endif
diff --git a/src/afclient.c b/src/afclient.c
index 697e708..ec02e36 100644
--- a/src/afclient.c
+++ b/src/afclient.c
@@ -78,12 +78,16 @@ main(int argc, char **argv)
* variables
*/
- int i, n, numofcon, length, buflength, notsent, temp, temp2;
+ int i, n, numofcon, length, buflength, temp, temp2 = 0;
+#ifdef HAVE_LINUX_SOCKIOS_H
+ int notsent;
+ socklen_t aLength;
+#endif
ConnectUser** usersTable = NULL;
unsigned char buff[9000];
char hostname[100];
- int maxfdp1, usercon;
- socklen_t aLength, addressLength;
+ int maxfdp1;
+ socklen_t addressLength;
struct sockaddr* clientAddress;
fd_set rset, allset, wset, tmpset;
struct timeval keepAlive;
@@ -98,7 +102,7 @@ main(int argc, char **argv)
char* serverName = NULL;
char* managePort = NULL;
char* hostName = NULL;
- char* destinationPort = NULL;
+ PortList* destinationPorts = PortList_new();
char* localName = NULL;
char* localPort = NULL;
char* localDestinationName = NULL;
@@ -225,7 +229,7 @@ main(int argc, char **argv)
break;
}
case 'p': {
- destinationPort = optarg;
+ PortList_insert_back(destinationPorts, PortListNode_new(optarg));
break;
}
case 'v': {
@@ -426,8 +430,9 @@ main(int argc, char **argv)
if ((hostName != NULL) && (ClientRealm_get_hostName(pointer) == NULL)) {
ClientRealm_set_hostName(pointer, hostName);
}
- if ((destinationPort != NULL) && (ClientRealm_get_destinationPort(pointer) == NULL)) {
- ClientRealm_set_destinationPort(pointer, destinationPort);
+ if ((PortList_get_size(destinationPorts) != 0) &&
+ (PortList_get_size(ClientRealm_get_destinationPorts(pointer)) == 0)) {
+ ClientRealm_set_destinationPorts(pointer, destinationPorts);
}
if ((realmId != NULL) && (ClientRealm_get_realmId(pointer) == NULL)) {
ClientRealm_set_realmId(pointer, realmId);
@@ -510,7 +515,7 @@ main(int argc, char **argv)
ClientRealm_set_serverName(pointer, serverName);
ClientRealm_set_managePort(pointer, managePort);
ClientRealm_set_hostName(pointer, hostName);
- ClientRealm_set_destinationPort(pointer, destinationPort);
+ ClientRealm_set_destinationPorts(pointer, destinationPorts);
ClientRealm_set_realmId(pointer, realmId);
ClientRealm_set_httpProxyOptions(pointer, hpo);
ClientRealm_set_arOptions(pointer, ao);
@@ -591,7 +596,7 @@ main(int argc, char **argv)
ClientRealm_set_hostName(pointer, hostname);
}
if ((ClientRealm_get_clientMode(pointer) != CLIENTREALM_MODE_REMOTE) &&
- (ClientRealm_get_destinationPort(pointer) == NULL)) {
+ (PortList_get_size(ClientRealm_get_destinationPorts(pointer)) == 0)) {
client_short_usage("Destination port number is required");
}
@@ -695,9 +700,9 @@ main(int argc, char **argv)
if (ClientRealm_get_clientMode(pointer) == CLIENTREALM_MODE_REMOTE) {
temp2 = -1;
- if (ClientRealm_get_destinationPort(pointer)) {
+ if (PortList_get_size(ClientRealm_get_destinationPorts(pointer)) > 0) {
if (ip_listen(&n, ClientRealm_get_serverName(pointer),
- ClientRealm_get_destinationPort(pointer),
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(pointer), 0)),
&addressLength,
ClientRealm_get_ipFamily(pointer))) {
#ifdef AF_INET6
@@ -709,11 +714,11 @@ main(int argc, char **argv)
"ipv6" :
"unspec",
ClientRealm_get_serverName(pointer),
- ClientRealm_get_destinationPort(pointer));
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(pointer), 0)));
#else
aflog(LOG_T_INIT, LOG_I_CRIT,
"tcp_listen error for %s, %s", ClientRealm_get_serverName(pointer),
- ClientRealm_get_destinationPort(pointer));
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(pointer), 0)));
#endif
exit(1);
}
@@ -806,6 +811,8 @@ main(int argc, char **argv)
"SERVER SSL: %s, ZLIB: %s, MODE: %s", (TYPE_IS_SSL(ClientRealm_get_realmType(pointer))) ? "yes" : "no",
(TYPE_IS_ZLIB(ClientRealm_get_realmType(pointer))) ? "yes" : "no",
(TYPE_IS_TCP(ClientRealm_get_realmType(pointer))) ? "tcp" : "udp");
+ aflog(LOG_T_CLIENT, LOG_I_INFO,
+ "SERVER MULTI: %s", (TYPE_IS_SUPPORTED_MULTI(ClientRealm_get_realmType(pointer))) ? "yes" : "no");
aflog(LOG_T_CLIENT, LOG_I_NOTICE,
"CIPHER: %s VER: %s", SSL_get_cipher_name(SslFd_get_ssl(ClientRealm_get_masterSslFd(pointer))),
SSL_get_cipher_version(SslFd_get_ssl(ClientRealm_get_masterSslFd(pointer))));
@@ -821,18 +828,9 @@ main(int argc, char **argv)
Module_function_info(ClientRealm_get_serviceModule(pointer)));
}
#endif
- if (ClientRealm_get_realmId(pointer) != NULL) {
- buff[0] = AF_S_LOGIN;
- buff[1] = buff[2] = 0;
- n = strlen(ClientRealm_get_realmId(pointer));
- memcpy(&buff[5], ClientRealm_get_realmId(pointer), n);
- buff[3] = n >> 8; /* high bits of message length */
- buff[4] = n; /* low bits of message length */
- SslFd_send_message(ClientRealm_get_realmType(pointer),
- ClientRealm_get_masterSslFd(pointer), buff, n+5);
- aflog(LOG_T_CLIENT, LOG_I_INFO,
- "ID SENT: %s", ClientRealm_get_realmId(pointer));
- }
+
+ ClientRealm_send_realmId(pointer, buff);
+ ClientRealm_enable_multi(pointer);
for ( ; ; ) {
rset = allset;
@@ -860,14 +858,18 @@ main(int argc, char **argv)
usersTable = ClientRealm_get_usersTable(pointer);
for (i = 0; i < ClientRealm_get_usersLimit(pointer); ++i) {
if ((ConnectUser_get_state(usersTable[i]) == S_STATE_OPEN) ||
- (ConnectUser_get_state(usersTable[i]) == S_STATE_STOPPED)) {
+ (ConnectUser_get_state(usersTable[i]) == S_STATE_STOPPED) ||
+ (ConnectUser_get_state(usersTable[i]) == S_STATE_KICKING)) {
if (FD_ISSET(ConnectUser_get_connFd(usersTable[i]), &rset)) { /* FD_ISSET CONTABLE[i].CONNFD RSET */
aflog(LOG_T_USER, LOG_I_DDEBUG,
"user[%d]: FD_ISSET", i);
n = read(ConnectUser_get_connFd(usersTable[i]), &buff[5], 8091);
if (n == -1) {
+ if (errno == EAGAIN) {
+ continue;
+ }
aflog(LOG_T_USER, LOG_I_ERR,
- "error (%d): while reading from service", n);
+ "error (%d): while reading from service", errno);
n = 0;
}
#ifdef HAVE_LINUX_SOCKIOS_H
@@ -936,6 +938,8 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_NOTICE,
"user[%d] (by ser): DROPPED BY MODULE", i);
close(ConnectUser_get_connFd(usersTable[i]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", i, ConnectUser_get_connFd(usersTable[i]));
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &wset);
ConnectUser_set_state(usersTable[i], S_STATE_CLOSING);
@@ -989,9 +993,16 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_INFO,
"user[%d]: CLOSING", i);
close(ConnectUser_get_connFd(usersTable[i]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", i, ConnectUser_get_connFd(usersTable[i]));
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &wset);
- ConnectUser_set_state(usersTable[i], S_STATE_CLOSING);
+ if (ConnectUser_get_state(usersTable[i]) == S_STATE_KICKING) {
+ ConnectUser_set_state(usersTable[i], S_STATE_CLEAR);
+ }
+ else {
+ ConnectUser_set_state(usersTable[i], S_STATE_CLOSING);
+ }
BufList_clear(ConnectUser_get_bufList(usersTable[i]));
buff[0] = AF_S_CONCLOSED; /* closing connection */
buff[1] = i >> 8; /* high bits of user number */
@@ -1002,7 +1013,8 @@ main(int argc, char **argv)
}
}
for (i = 0; i < ClientRealm_get_usersLimit(pointer); ++i) {
- if (ConnectUser_get_state(usersTable[i]) == S_STATE_STOPPED) {
+ if ((ConnectUser_get_state(usersTable[i]) == S_STATE_STOPPED) ||
+ (ConnectUser_get_state(usersTable[i]) == S_STATE_KICKING)) {
if (FD_ISSET(ConnectUser_get_connFd(usersTable[i]), &tmpset)) { /* FD_ISSET CONTABLE[i].CONNFD TMPSET */
aflog(LOG_T_USER, LOG_I_DDEBUG,
"user[%d]: FD_ISSET - WRITE", i);
@@ -1019,25 +1031,49 @@ main(int argc, char **argv)
}
else if (temp2 == -1) {
close(ConnectUser_get_connFd(usersTable[i]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", i, ConnectUser_get_connFd(usersTable[i]));
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[i]), &wset);
- ConnectUser_set_state(usersTable[i], S_STATE_CLOSING);
+ if (ConnectUser_get_state(usersTable[i]) == S_STATE_KICKING) {
+ ConnectUser_set_state(usersTable[i], S_STATE_CLEAR);
+ }
+ else {
+ ConnectUser_set_state(usersTable[i], S_STATE_CLOSING);
+ }
buff[0] = AF_S_CONCLOSED; /* closing connection */
buff[1] = i >> 8; /* high bits of user number */
buff[2] = i; /* low bits of user number */
- SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, 5);
+ SslFd_send_message(ClientRealm_get_realmType(pointer),
+ ClientRealm_get_masterSslFd(pointer), buff, 5);
}
else {
BufList_delete_first(ConnectUser_get_bufList(usersTable[i]));
if (BufList_get_first(ConnectUser_get_bufList(usersTable[i])) == NULL) {
- ConnectUser_set_state(usersTable[i], S_STATE_OPEN);
- FD_CLR(ConnectUser_get_state(usersTable[i]), &wset);
+ FD_CLR(ConnectUser_get_connFd(usersTable[i]), &wset);
buff[0] = AF_S_CAN_SEND; /* stopping transfer */
buff[1] = i >> 8; /* high bits of user number */
buff[2] = i; /* low bits of user number */
aflog(LOG_T_USER, LOG_I_DDEBUG,
"FROM user[%d]: BUFFERING MESSAGE ENDED", i);
- SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, 5);
+ SslFd_send_message(ClientRealm_get_realmType(pointer),
+ ClientRealm_get_masterSslFd(pointer), buff, 5);
+ if (ConnectUser_get_state(usersTable[i]) == S_STATE_KICKING) {
+ close(ConnectUser_get_connFd(usersTable[i]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", i, ConnectUser_get_connFd(usersTable[i]));
+ FD_CLR(ConnectUser_get_connFd(usersTable[i]), &allset);
+ FD_CLR(ConnectUser_get_connFd(usersTable[i]), &wset);
+ ConnectUser_set_state(usersTable[i], S_STATE_CLEAR);
+ buff[0] = AF_S_CONCLOSED; /* closing connection */
+ buff[1] = i >> 8; /* high bits of user number */
+ buff[2] = i; /* low bits of user number */
+ SslFd_send_message(ClientRealm_get_realmType(pointer),
+ ClientRealm_get_masterSslFd(pointer), buff, 5);
+ }
+ else {
+ ConnectUser_set_state(usersTable[i], S_STATE_OPEN);
+ }
}
}
} /* - FD_ISSET CONTABLE[i].CONNFD TMPSET */
@@ -1099,17 +1135,10 @@ main(int argc, char **argv)
aflog(LOG_T_CLIENT, LOG_I_INFO,
"Reconnected successfully...");
usersTable = ClientRealm_get_usersTable(pointer);
- if (ClientRealm_get_realmId(pointer) != NULL) {
- buff[0] = AF_S_LOGIN;
- buff[1] = buff[2] = 0;
- n = strlen(ClientRealm_get_realmId(pointer));
- memcpy(&buff[5], ClientRealm_get_realmId(pointer), n);
- buff[3] = n >> 8; /* high bits of message length */
- buff[4] = n; /* low bits of message length */
- SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, n+5);
- aflog(LOG_T_CLIENT, LOG_I_INFO,
- "ID SENT: %s", ClientRealm_get_realmId(pointer));
- }
+
+ ClientRealm_send_realmId(pointer, buff);
+ ClientRealm_enable_multi(pointer);
+
break;
}
@@ -1135,17 +1164,17 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_DDEBUG,
"user[%d]: AF_S_CONCLOSED", numofcon);
if ((numofcon>=0) && (numofcon<=ClientRealm_get_usersLimit(pointer))) {
- usercon--;
if (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_CLOSING) {
ConnectUser_set_state(usersTable[numofcon], S_STATE_CLEAR);
aflog(LOG_T_USER, LOG_I_INFO,
- "user[%d]: CLOSED", numofcon);
+ "user[%d]: CLOSE CONFIRMED", numofcon);
}
- else if ((ConnectUser_get_state(usersTable[numofcon]) == S_STATE_OPEN) ||
- (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_STOPPED)) {
+ else if (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_OPEN) {
aflog(LOG_T_USER, LOG_I_INFO,
"user[%d]: CLOSED", numofcon);
close(ConnectUser_get_connFd(usersTable[numofcon]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", numofcon, ConnectUser_get_connFd(usersTable[numofcon]));
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &wset);
ConnectUser_set_state(usersTable[numofcon], S_STATE_CLEAR);
@@ -1155,6 +1184,11 @@ main(int argc, char **argv)
buff[2] = numofcon; /* low bits of user number */
SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, 5);
}
+ else if (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_STOPPED) {
+ ConnectUser_set_state(usersTable[numofcon], S_STATE_KICKING);
+ aflog(LOG_T_USER, LOG_I_INFO,
+ "user[%d]: CLOSING...", numofcon);
+ }
}
break;
}
@@ -1162,7 +1196,6 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_DDEBUG,
"user[%d]: AF_S_CONOPEN", numofcon);
if ((numofcon>=0) && (numofcon<=ClientRealm_get_usersLimit(pointer))) {
- usercon++;
if (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_CLEAR) {
n = SslFd_get_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, length);
ConnectUser_set_nameBuf(usersTable[numofcon], (char*) buff);
@@ -1183,7 +1216,6 @@ main(int argc, char **argv)
buff[1] = numofcon >> 8; /* high bits of user number */
buff[2] = numofcon; /* low bits of user number */
SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, 5);
- usercon--;
continue;
}
#endif
@@ -1201,21 +1233,31 @@ main(int argc, char **argv)
ipFamily |= 0x04;
}
#endif
+ temp2 = 0;
+ if (n == 136) {
+ if (PortList_get_size(ClientRealm_get_destinationPorts(pointer)) == 1) {
+ temp2 = 0;
+ }
+ else {
+ temp2 = buff[135] % PortList_get_size(ClientRealm_get_destinationPorts(pointer));
+ }
+ }
if (ip_connect(&temp, ClientRealm_get_hostName(pointer),
- ClientRealm_get_destinationPort(pointer), ipFamily,
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(pointer), temp2)), ipFamily,
ClientRealm_get_localDestinationName(pointer), NULL)) {
aflog(LOG_T_USER, LOG_I_WARNING,
"user[%d]: CAN'T CONNECT to %s:%s - DROPPING", numofcon,
ClientRealm_get_hostName(pointer),
- ClientRealm_get_destinationPort(pointer));
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(pointer), temp2)));
buff[0] = AF_S_CANT_OPEN; /* not opening connection */
buff[1] = numofcon >> 8; /* high bits of user number */
buff[2] = numofcon; /* low bits of user number */
SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, 5);
- usercon--;
continue;
}
ConnectUser_set_connFd(usersTable[numofcon], temp);
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Setting connFd: %d", numofcon, temp);
temp2 = fcntl(ConnectUser_get_connFd(usersTable[numofcon]), F_GETFL, 0);
fcntl(ConnectUser_get_connFd(usersTable[numofcon]), F_SETFL, temp2 | O_NONBLOCK);
FD_SET(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
@@ -1259,6 +1301,8 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_NOTICE,
"user[%d]: DROPPED BY MODULE", numofcon);
close(ConnectUser_get_connFd(usersTable[numofcon]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", numofcon, ConnectUser_get_connFd(usersTable[numofcon]));
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &wset);
ConnectUser_set_state(usersTable[numofcon], S_STATE_CLOSING);
@@ -1317,6 +1361,8 @@ main(int argc, char **argv)
}
else if (temp2 == -1) {
close(ConnectUser_get_connFd(usersTable[numofcon]));
+ aflog(LOG_T_USER, LOG_I_DDEBUG,
+ "user[%d]: Closing connFd: %d", numofcon, ConnectUser_get_connFd(usersTable[numofcon]));
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &wset);
ConnectUser_set_state(usersTable[numofcon], S_STATE_CLOSING);
@@ -1377,17 +1423,10 @@ main(int argc, char **argv)
aflog(LOG_T_CLIENT, LOG_I_INFO,
"Reconnected successfully...");
usersTable = ClientRealm_get_usersTable(pointer);
- if (ClientRealm_get_realmId(pointer) != NULL) {
- buff[0] = AF_S_LOGIN;
- buff[1] = buff[2] = 0;
- n = strlen(ClientRealm_get_realmId(pointer));
- memcpy(&buff[5], ClientRealm_get_realmId(pointer), n);
- buff[3] = n >> 8; /* high bits of message length */
- buff[4] = n; /* low bits of message length */
- SslFd_send_message(ClientRealm_get_realmType(pointer), ClientRealm_get_masterSslFd(pointer), buff, n+5);
- aflog(LOG_T_CLIENT, LOG_I_INFO,
- "ID SENT: %s", ClientRealm_get_realmId(pointer));
- }
+
+ ClientRealm_send_realmId(pointer, buff);
+ ClientRealm_enable_multi(pointer);
+
break;
}
@@ -1403,17 +1442,31 @@ main(int argc, char **argv)
break;
}
case AF_S_DONT_SEND: {
- aflog(LOG_T_USER, LOG_I_DEBUG,
- "user[%d]: AF_S_DONT_SEND", numofcon);
- FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
- break;
- }
+ if ((ConnectUser_get_state(usersTable[numofcon]) == S_STATE_OPEN) ||
+ (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_STOPPED)) {
+ aflog(LOG_T_USER, LOG_I_DEBUG,
+ "user[%d]: AF_S_DONT_SEND", numofcon);
+ FD_CLR(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
+ }
+ else {
+ aflog(LOG_T_USER, LOG_I_DEBUG,
+ "user[%d]: AF_S_DONT_SEND - ignored", numofcon);
+ }
+ break;
+ }
case AF_S_CAN_SEND: {
- aflog(LOG_T_USER, LOG_I_DEBUG,
- "user[%d]: AF_S_CAN_SEND", numofcon);
- FD_SET(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
- break;
- }
+ if ((ConnectUser_get_state(usersTable[numofcon]) == S_STATE_OPEN) ||
+ (ConnectUser_get_state(usersTable[numofcon]) == S_STATE_STOPPED)) {
+ aflog(LOG_T_USER, LOG_I_DEBUG,
+ "user[%d]: AF_S_CAN_SEND", numofcon);
+ FD_SET(ConnectUser_get_connFd(usersTable[numofcon]), &allset);
+ }
+ else {
+ aflog(LOG_T_USER, LOG_I_DEBUG,
+ "user[%d]: AF_S_CAN_SEND - ignored", numofcon);
+ }
+ break;
+ }
default : { /* unrecognized type of message -> exiting... */
aflog(LOG_T_CLIENT, LOG_I_ERR,
"SERVER: unrecognized message -> exiting... cg: %ld bytes", getcg());
diff --git a/src/afclient.h b/src/afclient.h
index 1cad80e..2bd1c02 100644
--- a/src/afclient.h
+++ b/src/afclient.h
@@ -40,6 +40,7 @@
#include "audit_list_struct.h"
#include "daemon.h"
#include "ar_options_struct.h"
+#include "port_list_struct.h"
#include <openssl/rsa.h>
#include <openssl/ssl.h>
diff --git a/src/afserver.c b/src/afserver.c
index e54234c..2ec71d1 100644
--- a/src/afserver.c
+++ b/src/afserver.c
@@ -125,6 +125,7 @@ main(int argc, char **argv)
TYPE_SET_SSL(mode);
TYPE_SET_ZLIB(mode);
+ TYPE_SET_SUPPORTED_MULTI(mode);
#ifdef HAVE_LIBPTHREAD
remember_mainthread();
@@ -753,61 +754,78 @@ main(int argc, char **argv)
for (j = 0; j < ServerRealm_get_userClientPairs(scRealmsTable[i]); ++j) {
switch (ServerRealm_get_tunnelType(scRealmsTable[i])) {
case 0: {
- if (ip_listen(&temp, UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
- UsrCli_get_manageHostName(srUsersClientsTable[j]) :
- ServerRealm_get_hostName(scRealmsTable[i]),
- UsrCli_get_managePortName(srUsersClientsTable[j]),
- (&len), ipfam)) {
- aflog(LOG_T_INIT, LOG_I_CRIT,
+ temp = find_previousFd(srUsersClientsTable, j,
+ UsrCli_get_manageHostName(srUsersClientsTable[j]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]));
+ if (temp == -1) {
+ if (ip_listen(&temp, UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) :
+ ServerRealm_get_hostName(scRealmsTable[i]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]),
+ (&len), ipfam)) {
+ aflog(LOG_T_INIT, LOG_I_CRIT,
#ifdef AF_INET6
- "tcp_listen_%s error for %s, %s",
- (ipfam & 0x02)?"ipv4":(ipfam & 0x04)?"ipv6":"unspec",
+ "tcp_listen_%s error for %s, %s",
+ (ipfam & 0x02)?"ipv4":(ipfam & 0x04)?"ipv6":"unspec",
#else
- "tcp_listen error for %s, %s",
+ "tcp_listen error for %s, %s",
#endif
- UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
- UsrCli_get_manageHostName(srUsersClientsTable[j]) :
- ServerRealm_get_hostName(scRealmsTable[i]),
- UsrCli_get_managePortName(srUsersClientsTable[j]));
- exit(1);
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) :
+ ServerRealm_get_hostName(scRealmsTable[i]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]));
+ exit(1);
+ }
}
ServerRealm_set_addressLength(scRealmsTable[i], len);
UsrCli_set_manageFd(srUsersClientsTable[j], temp);
flags = fcntl(UsrCli_get_manageFd(srUsersClientsTable[j]), F_GETFL, 0);
fcntl(UsrCli_get_manageFd(srUsersClientsTable[j]), F_SETFL, flags | O_NONBLOCK);
+ UsrCli_set_number(srUsersClientsTable[j], eval_UsrCliPair(srUsersClientsTable, j,
+ UsrCli_get_manageHostName(srUsersClientsTable[j]),
+ UsrCli_get_managePortName(srUsersClientsTable[j])));
break;
}
#ifdef HAVE_LIBPTHREAD
- case 1: case 2: {
- if (initialize_http_proxy_server(&temp,
- UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
- UsrCli_get_manageHostName(srUsersClientsTable[j]) :
- ServerRealm_get_hostName(scRealmsTable[i]),
- UsrCli_get_managePortName(srUsersClientsTable[j]),
- (&len), ipfam,
- ServerRealm_get_clientsLimit(scRealmsTable[i]) +
- ServerRealm_get_raClientsLimit(scRealmsTable[i]),
- (ServerRealm_get_tunnelType(scRealmsTable[i]) - 1),
- ctx)) {
- aflog(LOG_T_INIT, LOG_I_CRIT,
+ case 1:
+ case 2: {
+ temp = find_previousFd(srUsersClientsTable, j,
+ UsrCli_get_manageHostName(srUsersClientsTable[j]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]));
+ if (temp == -1) {
+ if (initialize_http_proxy_server(&temp,
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) :
+ ServerRealm_get_hostName(scRealmsTable[i]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]),
+ (&len), ipfam,
+ ServerRealm_get_clientsLimit(scRealmsTable[i]) +
+ ServerRealm_get_raClientsLimit(scRealmsTable[i]),
+ (ServerRealm_get_tunnelType(scRealmsTable[i]) - 1),
+ ctx)) {
+ aflog(LOG_T_INIT, LOG_I_CRIT,
#ifdef AF_INET6
- "http%s_proxy_listen_%s error for %s, %s",
- (ServerRealm_get_tunnelType(scRealmsTable[i]) == 2) ? "s" : "",
- (ipfam & 0x02)?"ipv4":(ipfam & 0x04)?"ipv6":"unspec",
+ "http%s_proxy_listen_%s error for %s, %s",
+ (ServerRealm_get_tunnelType(scRealmsTable[i]) == 2) ? "s" : "",
+ (ipfam & 0x02)?"ipv4":(ipfam & 0x04)?"ipv6":"unspec",
#else
- "http%s_proxy_listen error for %s, %s",
- (ServerRealm_get_tunnelType(scRealmsTable[i]) == 2) ? "s" : "",
+ "http%s_proxy_listen error for %s, %s",
+ (ServerRealm_get_tunnelType(scRealmsTable[i]) == 2) ? "s" : "",
#endif
- UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
- UsrCli_get_manageHostName(srUsersClientsTable[j]) :
- ServerRealm_get_hostName(scRealmsTable[i]),
- UsrCli_get_managePortName(srUsersClientsTable[j]));
- exit(1);
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) ?
+ UsrCli_get_manageHostName(srUsersClientsTable[j]) :
+ ServerRealm_get_hostName(scRealmsTable[i]),
+ UsrCli_get_managePortName(srUsersClientsTable[j]));
+ exit(1);
+ }
}
ServerRealm_set_addressLength(scRealmsTable[i], len);
UsrCli_set_manageFd(srUsersClientsTable[j], temp);
flags = fcntl(UsrCli_get_manageFd(srUsersClientsTable[j]), F_GETFL, 0);
fcntl(UsrCli_get_manageFd(srUsersClientsTable[j]), F_SETFL, flags | O_NONBLOCK);
+ UsrCli_set_number(srUsersClientsTable[j], eval_UsrCliPair(srUsersClientsTable, j,
+ UsrCli_get_manageHostName(srUsersClientsTable[j]),
+ UsrCli_get_managePortName(srUsersClientsTable[j])));
break;
}
#endif
@@ -955,7 +973,8 @@ main(int argc, char **argv)
srUsersClientsTable = ServerRealm_get_usersClientsTable(pointer);
for (i = 0; i < ServerRealm_get_usersLimit(pointer); ++i) {
if ((ConnectUser_get_state(srUsersTable[i]) == S_STATE_OPEN) ||
- (ConnectUser_get_state(srUsersTable[i]) == S_STATE_STOPPED))
+ (ConnectUser_get_state(srUsersTable[i]) == S_STATE_STOPPED) ||
+ (ConnectUser_get_state(srUsersTable[i]) == S_STATE_KICKING)) {
if (FD_ISSET(ConnectUser_get_connFd(srUsersTable[i]), &rset)) {
k = eval_usernum(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])], i);
aflog(LOG_T_USER, LOG_I_DDEBUG,
@@ -1023,7 +1042,15 @@ main(int argc, char **argv)
close(ConnectUser_get_connFd(srUsersTable[i]));
FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &allset);
FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &wset);
- ConnectUser_set_state(srUsersTable[i], S_STATE_CLOSING);
+ if (ConnectUser_get_state(srUsersTable[i]) == S_STATE_KICKING) {
+ ConnectUser_set_state(srUsersTable[i], S_STATE_CLEAR);
+ ServerRealm_decrease_connectedUsers(pointer);
+ ConnectClient_decrease_connected(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])]);
+ ConnectClient_get_users(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])])[k] = -1;
+ }
+ else {
+ ConnectUser_set_state(srUsersTable[i], S_STATE_CLOSING);
+ }
BufList_clear(ConnectUser_get_bufList(srUsersTable[i]));
buff[0] = AF_S_CONCLOSED; /* closing connection */
buff[1] = k >> 8; /* high bits of user number */
@@ -1093,10 +1120,12 @@ main(int argc, char **argv)
}
}
+ }
}
/* ------------------------------------ */
for (i = 0; i < ServerRealm_get_usersLimit(pointer); ++i) {
- if (ConnectUser_get_state(srUsersTable[i]) == S_STATE_STOPPED)
+ if ((ConnectUser_get_state(srUsersTable[i]) == S_STATE_STOPPED) ||
+ (ConnectUser_get_state(srUsersTable[i]) == S_STATE_KICKING))
if (FD_ISSET(ConnectUser_get_connFd(srUsersTable[i]), &tmpset)) {
k = eval_usernum(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])], i);
aflog(LOG_T_USER, LOG_I_DDEBUG,
@@ -1137,7 +1166,15 @@ main(int argc, char **argv)
close(ConnectUser_get_connFd(srUsersTable[i]));
FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &allset);
FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &wset);
- ConnectUser_set_state(srUsersTable[i], S_STATE_CLOSING);
+ if (ConnectUser_get_state(srUsersTable[i]) == S_STATE_KICKING) {
+ ConnectUser_set_state(srUsersTable[i], S_STATE_CLEAR);
+ ServerRealm_decrease_connectedUsers(pointer);
+ ConnectClient_decrease_connected(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])]);
+ ConnectClient_get_users(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])])[k] = -1;
+ }
+ else {
+ ConnectUser_set_state(srUsersTable[i], S_STATE_CLOSING);
+ }
BufList_clear(ConnectUser_get_bufList(srUsersTable[i]));
buff[0] = AF_S_CONCLOSED; /* closing connection */
buff[1] = k >> 8; /* high bits of user number */
@@ -1154,7 +1191,6 @@ main(int argc, char **argv)
get_username(pointer, i), sent, n);
BufList_delete_first(ConnectUser_get_bufList(srUsersTable[i]));
if (BufList_get_first(ConnectUser_get_bufList(srUsersTable[i])) == NULL) {
- ConnectUser_set_state(srUsersTable[i], S_STATE_OPEN);
FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &wset);
buff[0] = AF_S_CAN_SEND; /* stopping transfer */
buff[1] = k >> 8; /* high bits of user number */
@@ -1168,6 +1204,39 @@ main(int argc, char **argv)
ConnectClient_get_sslFd(
srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])]),
buff, 5);
+ if (ConnectUser_get_state(srUsersTable[i]) == S_STATE_KICKING) {
+ aflog(LOG_T_USER, LOG_I_INFO,
+ "realm[%s]: Client[%s]: user[%d]: delayed CLOSED", get_realmname(config, j),
+ get_clientname(pointer, ConnectUser_get_whatClient(srUsersTable[i])),
+ get_username(pointer, i));
+ time(&now);
+ aflog(LOG_T_USER, LOG_I_NOTICE,
+ "REALM: %s CLIENT: %s USER: %d IP: %s PORT: %s DURATION: %s",
+ get_realmname(config, j),
+ get_clientname(pointer, ConnectUser_get_whatClient(srUsersTable[i])),
+ get_username(pointer, i),
+ ConnectUser_get_nameBuf(srUsersTable[i]),
+ ConnectUser_get_portBuf(srUsersTable[i]),
+ timeperiod(now - ConnectUser_get_connectTime(srUsersTable[i])));
+ close(ConnectUser_get_connFd(srUsersTable[i]));
+ FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &allset);
+ FD_CLR(ConnectUser_get_connFd(srUsersTable[i]), &wset);
+ ConnectUser_set_state(srUsersTable[i], S_STATE_CLEAR);
+ ServerRealm_decrease_connectedUsers(pointer);
+ ConnectClient_decrease_connected(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])]);
+ ConnectClient_get_users(srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])])[k] = -1;
+ BufList_clear(ConnectUser_get_bufList(srUsersTable[i]));
+ buff[0] = AF_S_CONCLOSED; /* closing connection */
+ buff[1] = k >> 8; /* high bits of user number */
+ buff[2] = k; /* low bits of user number */
+ SslFd_send_message(ServerRealm_get_realmType(pointer),
+ ConnectClient_get_sslFd(
+ srClientsTable[ConnectUser_get_whatClient(srUsersTable[i])]),
+ buff, 5);
+ }
+ else {
+ ConnectUser_set_state(srUsersTable[i], S_STATE_OPEN);
+ }
}
}
}
@@ -1229,6 +1298,10 @@ main(int argc, char **argv)
memcpy(&buff[5], ConnectUser_get_nameBuf(srUsersTable[i]), 128);
memcpy(&buff[133], ConnectUser_get_portBuf(srUsersTable[i]), 7);
n = 135;
+ if (ConnectClient_get_multi(srClientsTable[k]) == CONNECTCLIENT_MULTI_ENABLED) {
+ n = 136;
+ buff[140] = UsrCli_get_number(srUsersClientsTable[l]);
+ }
i = find_usernum(srClientsTable[k], i);
buff[0] = AF_S_CONOPEN; /* opening connection */
buff[1] = i >> 8; /* high bits of user number */
@@ -1471,40 +1544,49 @@ main(int argc, char **argv)
if ((numofcon>=0) && (numofcon<(ServerRealm_get_usersLimit(pointer))) &&
(ConnectClient_get_state(srClientsTable[k]) ==
CONNECTCLIENT_STATE_ACCEPTED)) {
- ServerRealm_decrease_connectedUsers(pointer);
- ConnectClient_decrease_connected(srClientsTable[k]);
- ConnectClient_get_users(srClientsTable[k])[n] = -1;
- if (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_CLOSING) {
- ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLEAR);
- aflog(LOG_T_USER, LOG_I_DEBUG,
- "realm[%s]: user[%d]: CLOSE CONFIRMED",
- get_realmname(config, j), get_username(pointer, numofcon));
- }
- else if ((ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_OPEN) ||
- (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_STOPPED)) {
+ if (ConnectUser_get_state(srUsersTable[numofcon]) ==
+ S_STATE_STOPPED) {
+ ConnectUser_set_state(srUsersTable[numofcon], S_STATE_KICKING);
aflog(LOG_T_USER, LOG_I_INFO,
- "realm[%s]: user[%d]: KICKED",
+ "realm[%s]: user[%d]: KICKING...",
get_realmname(config, j), get_username(pointer, numofcon));
- time(&now);
- aflog(LOG_T_USER, LOG_I_NOTICE,
- "REALM: %s USER: %d IP: %s PORT: %s DURATION: %s",
- get_realmname(config, j),
- get_username(pointer, numofcon),
- ConnectUser_get_nameBuf(srUsersTable[numofcon]),
- ConnectUser_get_portBuf(srUsersTable[numofcon]),
- timeperiod(now - ConnectUser_get_connectTime(srUsersTable[numofcon])));
- close(ConnectUser_get_connFd(srUsersTable[numofcon]));
- FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
- FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &wset);
- ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLEAR);
- BufList_clear(ConnectUser_get_bufList(srUsersTable[numofcon]));
- buff[0] = AF_S_CONCLOSED; /* closing connection */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
- SslFd_send_message(ServerRealm_get_realmType(pointer),
- ConnectClient_get_sslFd(
- srClientsTable[k]),
- buff, 5);
+ }
+ else {
+ ServerRealm_decrease_connectedUsers(pointer);
+ ConnectClient_decrease_connected(srClientsTable[k]);
+ ConnectClient_get_users(srClientsTable[k])[n] = -1;
+ if (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_CLOSING) {
+ ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLEAR);
+ aflog(LOG_T_USER, LOG_I_DEBUG,
+ "realm[%s]: user[%d]: CLOSE CONFIRMED",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ }
+ else if (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_OPEN) {
+ aflog(LOG_T_USER, LOG_I_INFO,
+ "realm[%s]: user[%d]: KICKED",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ time(&now);
+ aflog(LOG_T_USER, LOG_I_NOTICE,
+ "REALM: %s USER: %d IP: %s PORT: %s DURATION: %s",
+ get_realmname(config, j),
+ get_username(pointer, numofcon),
+ ConnectUser_get_nameBuf(srUsersTable[numofcon]),
+ ConnectUser_get_portBuf(srUsersTable[numofcon]),
+ timeperiod(now -
+ ConnectUser_get_connectTime(srUsersTable[numofcon])));
+ close(ConnectUser_get_connFd(srUsersTable[numofcon]));
+ FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
+ FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &wset);
+ ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLEAR);
+ BufList_clear(ConnectUser_get_bufList(srUsersTable[numofcon]));
+ buff[0] = AF_S_CONCLOSED; /* closing connection */
+ buff[1] = n >> 8; /* high bits of user number */
+ buff[2] = n; /* low bits of user number */
+ SslFd_send_message(ServerRealm_get_realmType(pointer),
+ ConnectClient_get_sslFd(
+ srClientsTable[k]),
+ buff, 5);
+ }
}
}
else {
@@ -1513,6 +1595,7 @@ main(int argc, char **argv)
break;
}
case AF_S_CONOPEN : {
+ n = numofcon;
numofcon = eval_numofcon(pointer, k, numofcon);
if ((numofcon>=0) && (numofcon<(ServerRealm_get_usersLimit(pointer))) &&
(ConnectClient_get_state(srClientsTable[k]) ==
@@ -1534,8 +1617,8 @@ main(int argc, char **argv)
get_realmname(config, j), get_username(pointer, numofcon));
ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLOSING);
buff[0] = AF_S_CONCLOSED; /* closing connection */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
+ buff[1] = n >> 8; /* high bits of user number */
+ buff[2] = n; /* low bits of user number */
SslFd_send_message(ServerRealm_get_realmType(pointer),
ConnectClient_get_sslFd(
srClientsTable[k]),
@@ -1593,6 +1676,7 @@ main(int argc, char **argv)
srClientsTable[k]),
buff, length);
}
+ temp = numofcon;
numofcon = eval_numofcon(pointer, k, numofcon);
if ((numofcon>=0) && (numofcon<(ServerRealm_get_usersLimit(pointer)))) {
if (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_OPEN) {
@@ -1624,8 +1708,8 @@ main(int argc, char **argv)
ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLOSING);
BufList_clear(ConnectUser_get_bufList(srUsersTable[numofcon]));
buff[0] = AF_S_CONCLOSED; /* closing connection */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
+ buff[1] = temp >> 8; /* high bits of user number */
+ buff[2] = temp; /* low bits of user number */
SslFd_send_message(ServerRealm_get_realmType(pointer),
ConnectClient_get_sslFd(
srClientsTable[k]),
@@ -1640,8 +1724,8 @@ main(int argc, char **argv)
ConnectUser_set_state(srUsersTable[numofcon], S_STATE_STOPPED);
FD_SET(ConnectUser_get_connFd(srUsersTable[numofcon]), &wset);
buff[0] = AF_S_DONT_SEND; /* stopping transfer */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
+ buff[1] = temp >> 8; /* high bits of user number */
+ buff[2] = temp; /* low bits of user number */
aflog(LOG_T_USER, LOG_I_DDEBUG,
"realm[%s]: TO user[%d]: BUFFERING MESSAGE STARTED (%d/%d)",
get_realmname(config, j), get_username(pointer, numofcon), sent, n);
@@ -1656,8 +1740,8 @@ main(int argc, char **argv)
ConnectUser_set_state(srUsersTable[numofcon], S_STATE_STOPPED);
FD_SET(ConnectUser_get_connFd(srUsersTable[numofcon]), &wset);
buff[0] = AF_S_DONT_SEND; /* stopping transfer */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
+ buff[1] = temp >> 8; /* high bits of user number */
+ buff[2] = temp; /* low bits of user number */
aflog(LOG_T_USER, LOG_I_DDEBUG,
"realm[%s]: TO user[%d]: BUFFERING MESSAGE STARTED (%d/%d)",
get_realmname(config, j), get_username(pointer, numofcon), sent, n);
@@ -1684,8 +1768,8 @@ main(int argc, char **argv)
ConnectUser_set_state(srUsersTable[numofcon], S_STATE_CLOSING);
BufList_clear(ConnectUser_get_bufList(srUsersTable[numofcon]));
buff[0] = AF_S_CONCLOSED; /* closing connection */
- buff[1] = numofcon >> 8; /* high bits of user number */
- buff[2] = numofcon; /* low bits of user number */
+ buff[1] = temp >> 8; /* high bits of user number */
+ buff[2] = temp; /* low bits of user number */
SslFd_send_message(ServerRealm_get_realmType(pointer),
ConnectClient_get_sslFd(
srClientsTable[k]),
@@ -1733,6 +1817,7 @@ main(int argc, char **argv)
CONNECTCLIENT_STATE_AUTHORIZING) &&
(numofcon==(ServerRealm_get_password(pointer)[0]*256+ServerRealm_get_password(pointer)[1])) &&
(length==(ServerRealm_get_password(pointer)[2]*256+ServerRealm_get_password(pointer)[3]))) {
+ ConnectClient_set_multi(srClientsTable[k], CONNECTCLIENT_MULTI_DISABLED);
if (k != ServerRealm_get_clientsLimit(pointer)) {
ConnectClient_set_state(srClientsTable[k], CONNECTCLIENT_STATE_ACCEPTED);
aflog(LOG_T_CLIENT, LOG_I_INFO,
@@ -1832,17 +1917,33 @@ main(int argc, char **argv)
break;
}
case AF_S_DONT_SEND: {
- aflog(LOG_T_CLIENT, LOG_I_DEBUG,
- "realm[%s]: user[%d]: STOP READING",
- get_realmname(config, j), get_username(pointer, numofcon));
- FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
+ if ((ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_OPEN) ||
+ (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_STOPPED)) {
+ aflog(LOG_T_CLIENT, LOG_I_DEBUG,
+ "realm[%s]: user[%d]: STOP READING",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ FD_CLR(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
+ }
+ else {
+ aflog(LOG_T_CLIENT, LOG_I_DDEBUG,
+ "realm[%s]: user[%d]: STOP READING - ignored",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ }
break;
}
case AF_S_CAN_SEND: {
- aflog(LOG_T_CLIENT, LOG_I_DEBUG,
- "realm[%s]: user[%d]: START READING",
- get_realmname(config, j), get_username(pointer, numofcon));
- FD_SET(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
+ if ((ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_OPEN) ||
+ (ConnectUser_get_state(srUsersTable[numofcon]) == S_STATE_STOPPED)) {
+ aflog(LOG_T_CLIENT, LOG_I_DEBUG,
+ "realm[%s]: user[%d]: START READING",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ FD_SET(ConnectUser_get_connFd(srUsersTable[numofcon]), &allset);
+ }
+ else {
+ aflog(LOG_T_CLIENT, LOG_I_DDEBUG,
+ "realm[%s]: user[%d]: START READING - ignored",
+ get_realmname(config, j), get_username(pointer, numofcon));
+ }
break;
}
case AF_S_WRONG: {
@@ -1937,6 +2038,13 @@ main(int argc, char **argv)
get_realmname(config, j), get_clientname(pointer, k));
break;
}
+ case AF_S_ENABLE_MULTI: {
+ aflog(LOG_T_CLIENT, LOG_I_INFO,
+ "realm[%s]: Client[%s]: MULTI enabled: %d",
+ get_realmname(config, j), get_clientname(pointer, k), buff[1]);
+ ConnectClient_set_multi(srClientsTable[k], CONNECTCLIENT_MULTI_ENABLED);
+ break;
+ }
default : {
aflog(LOG_T_CLIENT, LOG_I_ERR,
"realm[%s]: Client[%s]: Unrecognized message - CLOSING",
@@ -2046,6 +2154,7 @@ main(int argc, char **argv)
CONNECTCLIENT_STATE_AUTHORIZING) &&
(numofcon==(ServerRealm_get_password(pointer)[0]*256+ServerRealm_get_password(pointer)[1])) &&
(length==(ServerRealm_get_password(pointer)[2]*256+ServerRealm_get_password(pointer)[3]))) {
+ ConnectClient_set_multi(srRaClientsTable[k], CONNECTCLIENT_MULTI_DISABLED);
for (l = 0; l < ServerRealm_get_clientsLimit(pointer); ++l) {
if (ConnectClient_get_state(srClientsTable[l]) ==
CONNECTCLIENT_STATE_FREE) {
@@ -2335,7 +2444,7 @@ main(int argc, char **argv)
aflog(LOG_T_USER, LOG_I_DDEBUG,
"realm[%s]: managefd: FD_ISSET --> errno=%d", get_realmname(config, j), errno);
}
- continue;
+ break;
}
flags = fcntl(sent, F_GETFL, 0);
fcntl(sent, F_SETFL, flags | O_NONBLOCK);
@@ -2386,8 +2495,10 @@ main(int argc, char **argv)
aflog(LOG_T_MANAGE, LOG_I_INFO,
"realm[%s]: new Client[%s] (ra) IP:%s",
get_realmname(config, j), get_raclientname(pointer, k),
- sock_ntop(ServerRealm_get_clientAddress(pointer), len, ConnectClient_get_nameBuf(srRaClientsTable[k]),
- ConnectClient_get_portBuf(srRaClientsTable[k]), ServerRealm_get_dnsLookupsOn(pointer)));
+ sock_ntop(ServerRealm_get_clientAddress(pointer), len,
+ ConnectClient_get_nameBuf(srRaClientsTable[k]),
+ ConnectClient_get_portBuf(srRaClientsTable[k]),
+ ServerRealm_get_dnsLookupsOn(pointer)));
FD_SET(SslFd_get_fd(ConnectClient_get_sslFd(srRaClientsTable[k])), &allset);
maxfdp1 = (maxfdp1 > (SslFd_get_fd(ConnectClient_get_sslFd(srRaClientsTable[k])) + 1)) ?
maxfdp1 : (SslFd_get_fd(ConnectClient_get_sslFd(srRaClientsTable[k])) + 1);
@@ -2405,6 +2516,7 @@ main(int argc, char **argv)
close(sent);
}
}
+ break;
}
}
} /* realms loop */
diff --git a/src/ar_options_struct.c b/src/ar_options_struct.c
index ae374ff..740f054 100644
--- a/src/ar_options_struct.c
+++ b/src/ar_options_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "ar_options_struct.h"
#include "string_functions.h"
@@ -37,6 +38,7 @@ ArOptions*
ArOptions_new()
{
ArOptions* tmp = calloc(1, sizeof(ArOptions));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -55,9 +57,11 @@ ArOptions_new()
void
ArOptions_free(ArOptions** ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
+ assert((*ao) != NULL);
if ((*ao) == NULL) {
return;
}
@@ -86,6 +90,7 @@ ArOptions_free(ArOptions** ao)
void
ArOptions_set_arTries(ArOptions* ao, int tries)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -103,6 +108,7 @@ ArOptions_set_arTries(ArOptions* ao, int tries)
void
ArOptions_set_s_arTries(ArOptions* ao, char* tries)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -119,6 +125,7 @@ ArOptions_set_s_arTries(ArOptions* ao, char* tries)
void
ArOptions_set_arDelay(ArOptions* ao, int delay)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -136,6 +143,7 @@ ArOptions_set_arDelay(ArOptions* ao, int delay)
void
ArOptions_set_s_arDelay(ArOptions* ao, char* delay)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -153,6 +161,7 @@ ArOptions_set_s_arDelay(ArOptions* ao, char* delay)
void
ArOptions_set_arStart(ArOptions* ao, char start)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -170,6 +179,7 @@ ArOptions_set_arStart(ArOptions* ao, char start)
void
ArOptions_set_arQuit(ArOptions* ao, char quit)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -187,6 +197,7 @@ ArOptions_set_arQuit(ArOptions* ao, char quit)
void
ArOptions_set_arPremature(ArOptions* ao, char premature)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
@@ -203,6 +214,7 @@ ArOptions_set_arPremature(ArOptions* ao, char premature)
int
ArOptions_get_arTries(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return 0;
}
@@ -219,6 +231,7 @@ ArOptions_get_arTries(ArOptions* ao)
int
ArOptions_get_arDelay(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return 0;
}
@@ -235,6 +248,7 @@ ArOptions_get_arDelay(ArOptions* ao)
char
ArOptions_get_arStart(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return AR_OPTION_DISABLED;
}
@@ -251,6 +265,7 @@ ArOptions_get_arStart(ArOptions* ao)
char
ArOptions_get_arQuit(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return AR_OPTION_DISABLED;
}
@@ -267,6 +282,7 @@ ArOptions_get_arQuit(ArOptions* ao)
char
ArOptions_get_arPremature(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return AR_OPTION_DISABLED;
}
@@ -284,6 +300,7 @@ ArOptions_get_arPremature(ArOptions* ao)
void
ArOptions_evaluate_values(ArOptions* ao)
{
+ assert(ao != NULL);
if (ao == NULL) {
return;
}
diff --git a/src/audit_list_node_struct.c b/src/audit_list_node_struct.c
index 20ebe29..2a7701b 100644
--- a/src/audit_list_node_struct.c
+++ b/src/audit_list_node_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "audit_list_node_struct.h"
@@ -35,6 +36,7 @@ AuditListNode*
AuditListNode_new()
{
AuditListNode* tmp = calloc(1, sizeof(AuditListNode));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -57,6 +59,7 @@ AuditListNode_new_entry(int userId, char* nameBuf, char* portBuf,
time_t connectTime, time_t duration)
{
AuditListNode* tmp = calloc(1, sizeof(AuditListNode));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -77,9 +80,11 @@ AuditListNode_new_entry(int userId, char* nameBuf, char* portBuf,
void
AuditListNode_free(AuditListNode** aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
+ assert((*aln) != NULL);
if ((*aln) == NULL) {
return;
}
@@ -97,6 +102,7 @@ AuditListNode_free(AuditListNode** aln)
void
AuditListNode_set_userId(AuditListNode* aln, int userId)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -113,6 +119,7 @@ AuditListNode_set_userId(AuditListNode* aln, int userId)
void
AuditListNode_set_nameBuf(AuditListNode* aln, char* nameBuf)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -130,6 +137,7 @@ AuditListNode_set_nameBuf(AuditListNode* aln, char* nameBuf)
void
AuditListNode_set_portBuf(AuditListNode* aln, char* portBuf)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -147,6 +155,7 @@ AuditListNode_set_portBuf(AuditListNode* aln, char* portBuf)
void
AuditListNode_set_connectTime(AuditListNode* aln, time_t connectTime)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -163,6 +172,7 @@ AuditListNode_set_connectTime(AuditListNode* aln, time_t connectTime)
void
AuditListNode_set_duration(AuditListNode* aln, time_t duration)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -179,6 +189,7 @@ AuditListNode_set_duration(AuditListNode* aln, time_t duration)
void
AuditListNode_set_nextNode(AuditListNode* aln, AuditListNode* nextNode)
{
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -195,6 +206,7 @@ AuditListNode_set_nextNode(AuditListNode* aln, AuditListNode* nextNode)
int
AuditListNode_get_userId(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return -1;
}
@@ -211,6 +223,7 @@ AuditListNode_get_userId(AuditListNode* aln)
char*
AuditListNode_get_nameBuf(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return NULL;
}
@@ -227,6 +240,7 @@ AuditListNode_get_nameBuf(AuditListNode* aln)
char*
AuditListNode_get_portBuf(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return NULL;
}
@@ -243,6 +257,7 @@ AuditListNode_get_portBuf(AuditListNode* aln)
time_t
AuditListNode_get_connectTime(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return 0;
}
@@ -259,6 +274,7 @@ AuditListNode_get_connectTime(AuditListNode* aln)
time_t
AuditListNode_get_duration(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return 0;
}
@@ -275,6 +291,7 @@ AuditListNode_get_duration(AuditListNode* aln)
AuditListNode*
AuditListNode_get_nextNode(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return NULL;
}
@@ -291,6 +308,7 @@ AuditListNode_get_nextNode(AuditListNode* aln)
time_t*
AuditListNode_get_connectTimep(AuditListNode* aln)
{
+ assert(aln != NULL);
if (aln == NULL) {
return 0;
}
diff --git a/src/audit_list_struct.c b/src/audit_list_struct.c
index 9eeeafe..3431dd2 100644
--- a/src/audit_list_struct.c
+++ b/src/audit_list_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "audit_list_struct.h"
@@ -35,6 +36,7 @@ AuditList*
AuditList_new()
{
AuditList* tmp = calloc(1, sizeof(AuditList));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -50,9 +52,11 @@ AuditList_new()
void
AuditList_free(AuditList** al)
{
+ assert(al != NULL);
if (al == NULL) {
return;
}
+ assert((*al) != NULL);
if ((*al) == NULL) {
return;
}
@@ -71,9 +75,11 @@ AuditList_free(AuditList** al)
void
AuditList_insert_back(AuditList* al, AuditListNode* aln)
{
+ assert(al != NULL);
if (al == NULL) {
return;
}
+ assert(aln != NULL);
if (aln == NULL) {
return;
}
@@ -97,6 +103,7 @@ AuditList_insert_back(AuditList* al, AuditListNode* aln)
AuditListNode*
AuditList_get_first(AuditList* al)
{
+ assert(al != NULL);
if (al == NULL) {
return NULL;
}
@@ -113,6 +120,7 @@ void
AuditList_delete_first(AuditList* al)
{
AuditListNode* tmp = AuditList_get_first(al);
+ assert(tmp != NULL);
if (tmp == NULL) {
return;
}
@@ -134,6 +142,10 @@ AuditList_delete_first(AuditList* al)
void
AuditList_clear(AuditList* al)
{
+ assert(al != NULL);
+ if (al == NULL) {
+ return;
+ }
while (AuditList_get_first(al)) {
AuditList_delete_first(al);
}
diff --git a/src/buf_list_node_struct.c b/src/buf_list_node_struct.c
index 6e265bd..2b69368 100644
--- a/src/buf_list_node_struct.c
+++ b/src/buf_list_node_struct.c
@@ -22,12 +22,13 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "buf_list_node_struct.h"
/*
* Function name: BufListNode_new
- * Description: Create and initialize new BufListNode structure.
+ * Description: Creates and initializes new BufListNode structure.
* Returns: Newly created BufListNode structure.
*/
@@ -35,6 +36,7 @@ BufListNode*
BufListNode_new()
{
BufListNode* tmp = calloc(1, sizeof(BufListNode));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -55,6 +57,7 @@ BufListNode*
BufListNode_new_message(int actPtr, int msgLen, unsigned char* message)
{
BufListNode* tmp = calloc(1, sizeof(BufListNode));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -65,16 +68,18 @@ BufListNode_new_message(int actPtr, int msgLen, unsigned char* message)
/*
* Function name: BufListNode_free
- * Description: Free the memory allocated for BufListNode structure.
+ * Description: Frees the memory allocated for BufListNode structure.
* Arguments: bln - pointer to pointer to BufListNode structure
*/
void
BufListNode_free(BufListNode** bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
+ assert((*bln) != NULL);
if ((*bln) == NULL) {
return;
}
@@ -88,7 +93,7 @@ BufListNode_free(BufListNode** bln)
/*
* Function name: BufListNode_set_actPtr
- * Description: Set actual buffer pointer.
+ * Description: Sets actual buffer pointer.
* Arguments: bln - pointer to BufListNode structure
* actPtr - actual buffer pointer
*/
@@ -96,6 +101,7 @@ BufListNode_free(BufListNode** bln)
void
BufListNode_set_actPtr(BufListNode* bln, int actPtr)
{
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
@@ -104,7 +110,7 @@ BufListNode_set_actPtr(BufListNode* bln, int actPtr)
/*
* Function name: BufListNode_set_msgLen
- * Description: Set length of the message.
+ * Description: Sets length of the message.
* Arguments: bln - pointer to BufListNode structure
* msgLen - length of the message
*/
@@ -112,6 +118,7 @@ BufListNode_set_actPtr(BufListNode* bln, int actPtr)
void
BufListNode_set_msgLen(BufListNode* bln, int msgLen)
{
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
@@ -120,7 +127,7 @@ BufListNode_set_msgLen(BufListNode* bln, int msgLen)
/*
* Function name: BufListNode_set_message
- * Description: Set message to be stored.
+ * Description: Sets message to be stored.
* Arguments: bln - pointer to BufListNode structure
* message - message to be stored
* msgLen - length of the message
@@ -129,6 +136,7 @@ BufListNode_set_msgLen(BufListNode* bln, int msgLen)
void
BufListNode_set_message(BufListNode* bln, unsigned char* message, int msgLen)
{
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
@@ -138,10 +146,12 @@ BufListNode_set_message(BufListNode* bln, unsigned char* message, int msgLen)
}
BufListNode_set_actPtr(bln, 0);
BufListNode_set_msgLen(bln, 0);
+ assert(message != NULL);
if (message == NULL) {
return;
}
bln->message = calloc(1, msgLen);
+ assert(bln->message != NULL);
if (bln->message == NULL) {
return;
}
@@ -151,7 +161,7 @@ BufListNode_set_message(BufListNode* bln, unsigned char* message, int msgLen)
/*
* Function name: BufListNode_set_nextNode
- * Description: Set next node pointer.
+ * Description: Sets next node pointer.
* Arguments: bln - pointer to BufListNode structure
* nextNode - next node pointer
*/
@@ -159,6 +169,7 @@ BufListNode_set_message(BufListNode* bln, unsigned char* message, int msgLen)
void
BufListNode_set_nextNode(BufListNode* bln, BufListNode* nextNode)
{
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
@@ -167,7 +178,7 @@ BufListNode_set_nextNode(BufListNode* bln, BufListNode* nextNode)
/*
* Function name: BufListNode_get_actPtr
- * Description: Get actual buffer pointer.
+ * Description: Gets actual buffer pointer.
* Aguments: bln - pointer to BufListNode structure
* Returns: Actual buffer pointer.
*/
@@ -175,6 +186,7 @@ BufListNode_set_nextNode(BufListNode* bln, BufListNode* nextNode)
int
BufListNode_get_actPtr(BufListNode* bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return -1;
}
@@ -183,7 +195,7 @@ BufListNode_get_actPtr(BufListNode* bln)
/*
* Function name: BufListNode_get_msgLen
- * Description: Get length of the message.
+ * Description: Gets length of the message.
* Arguments: bln - pointer to BufListNode structure
* Returns: Length of the message.
*/
@@ -191,6 +203,7 @@ BufListNode_get_actPtr(BufListNode* bln)
int
BufListNode_get_msgLen(BufListNode* bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return -1;
}
@@ -199,7 +212,7 @@ BufListNode_get_msgLen(BufListNode* bln)
/*
* Function name: BufListNode_get_message
- * Description: Get stored message.
+ * Description: Gets stored message.
* Arguments: bln - pointer to BufListNode structure
* Returns: Stored message.
*/
@@ -207,6 +220,7 @@ BufListNode_get_msgLen(BufListNode* bln)
unsigned char*
BufListNode_get_message(BufListNode* bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return NULL;
}
@@ -215,7 +229,7 @@ BufListNode_get_message(BufListNode* bln)
/*
* Function name: BufListNode_get_nextNode
- * Description: Get next node pointer.
+ * Description: Gets next node pointer.
* Arguments: bln - pointer to BufListNode structure
* Returns: Next BufListNode structure pointer or NULL, if there is no next one.
*/
@@ -223,6 +237,7 @@ BufListNode_get_message(BufListNode* bln)
BufListNode*
BufListNode_get_nextNode(BufListNode* bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return NULL;
}
@@ -239,6 +254,7 @@ BufListNode_get_nextNode(BufListNode* bln)
unsigned char*
BufListNode_readMessage(BufListNode* bln)
{
+ assert(bln != NULL);
if (bln == NULL) {
return NULL;
}
@@ -247,7 +263,7 @@ BufListNode_readMessage(BufListNode* bln)
/*
* Function name: BufListNode_readMessageLength
- * Description: Get the amount of unread bytes in the message.
+ * Description: Gets the amount of unread bytes in the message.
* Arguments: bln - pointer to BufListNode structure
* Returns: The amount of unread bytes in the message.
*/
@@ -256,13 +272,16 @@ int
BufListNode_readMessageLength(BufListNode* bln)
{
int tmp = 0;
+ assert(bln != NULL);
if (bln == NULL) {
return -1;
}
+ assert(BufListNode_get_message(bln) != NULL);
if (BufListNode_get_message(bln) == NULL) {
return -1;
}
tmp = BufListNode_get_msgLen(bln) - BufListNode_get_actPtr(bln);
+ assert(tmp >= 0);
if (tmp < 0) {
return 0;
}
diff --git a/src/buf_list_struct.c b/src/buf_list_struct.c
index 5df27fb..7de8acd 100644
--- a/src/buf_list_struct.c
+++ b/src/buf_list_struct.c
@@ -22,12 +22,13 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "buf_list_struct.h"
/*
* Function name: BufList_new
- * Description: Create and initialize new BufList structure.
+ * Description: Creates and initializes new BufList structure.
* Returns: Newly created BufList structure.
*/
@@ -35,6 +36,7 @@ BufList*
BufList_new()
{
BufList* tmp = calloc(1, sizeof(BufList));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -43,16 +45,18 @@ BufList_new()
/*
* Function name: BufList_free
- * Description: Free the memory allocated for BufList structure.
+ * Description: Frees the memory allocated for BufList structure.
* Arguments: bl - pointer to pointer to BufList structure.
*/
void
BufList_free(BufList** bl)
{
+ assert(bl != NULL);
if (bl == NULL) {
return;
}
+ assert((*bl) != NULL);
if ((*bl) == NULL) {
return;
}
@@ -63,7 +67,7 @@ BufList_free(BufList** bl)
/*
* Function name: BufList_insert_back
- * Description: Insert new node at the end of the list.
+ * Description: Inserts new node at the end of the list.
* Arguments: bl - pointer to BufList structure
* bln - pointer to BufListNode structure
*/
@@ -71,9 +75,11 @@ BufList_free(BufList** bl)
void
BufList_insert_back(BufList* bl, BufListNode* bln)
{
+ assert(bl != NULL);
if (bl == NULL) {
return;
}
+ assert(bln != NULL);
if (bln == NULL) {
return;
}
@@ -97,6 +103,7 @@ BufList_insert_back(BufList* bl, BufListNode* bln)
BufListNode*
BufList_get_first(BufList* bl)
{
+ assert(bl != NULL);
if (bl == NULL) {
return NULL;
}
@@ -113,6 +120,7 @@ void
BufList_delete_first(BufList* bl)
{
BufListNode* tmp = BufList_get_first(bl);
+ assert(tmp != NULL);
if (tmp == NULL) {
return;
}
@@ -134,6 +142,10 @@ BufList_delete_first(BufList* bl)
void
BufList_clear(BufList* bl)
{
+ assert(bl != NULL);
+ if (bl == NULL) {
+ return;
+ }
while (BufList_get_first(bl)) {
BufList_delete_first(bl);
}
diff --git a/src/client_configuration_struct.c b/src/client_configuration_struct.c
index c010cec..94c0419 100644
--- a/src/client_configuration_struct.c
+++ b/src/client_configuration_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "string_functions.h"
#include "client_configuration_struct.h"
@@ -36,6 +37,7 @@ ClientConfiguration*
ClientConfiguration_new()
{
ClientConfiguration* tmp = calloc(1, sizeof(ClientConfiguration));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -52,9 +54,11 @@ void
ClientConfiguration_free(ClientConfiguration** cc)
{
int i;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
+ assert((*cc) != NULL);
if ((*cc) == NULL) {
return;
}
@@ -89,6 +93,7 @@ ClientConfiguration_free(ClientConfiguration** cc)
void
ClientConfiguration_set_keysFile(ClientConfiguration* cc, char* keysFile)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -105,6 +110,7 @@ ClientConfiguration_set_keysFile(ClientConfiguration* cc, char* keysFile)
void
ClientConfiguration_set_storeFile(ClientConfiguration* cc, char* storeFile)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -121,6 +127,7 @@ ClientConfiguration_set_storeFile(ClientConfiguration* cc, char* storeFile)
void
ClientConfiguration_set_dateFormat(ClientConfiguration* cc, char* dateFormat)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -137,6 +144,7 @@ ClientConfiguration_set_dateFormat(ClientConfiguration* cc, char* dateFormat)
void
ClientConfiguration_set_realmsNumber(ClientConfiguration* cc, int realmsNumber)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -154,6 +162,7 @@ void
ClientConfiguration_set_realmsTable(ClientConfiguration* cc, ClientRealm** realmsTable)
{
int i;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -179,6 +188,7 @@ ClientConfiguration_set_realmsTable(ClientConfiguration* cc, ClientRealm** realm
void
ClientConfiguration_set_ignorePublicKeys(ClientConfiguration* cc, char ignorePublicKeys)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -195,6 +205,7 @@ ClientConfiguration_set_ignorePublicKeys(ClientConfiguration* cc, char ignorePub
char*
ClientConfiguration_get_keysFile(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -211,6 +222,7 @@ ClientConfiguration_get_keysFile(ClientConfiguration* cc)
char*
ClientConfiguration_get_storeFile(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -227,6 +239,7 @@ ClientConfiguration_get_storeFile(ClientConfiguration* cc)
char*
ClientConfiguration_get_dateFormat(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -243,6 +256,7 @@ ClientConfiguration_get_dateFormat(ClientConfiguration* cc)
int
ClientConfiguration_get_realmsNumber(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -259,6 +273,7 @@ ClientConfiguration_get_realmsNumber(ClientConfiguration* cc)
ClientRealm**
ClientConfiguration_get_realmsTable(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -275,6 +290,7 @@ ClientConfiguration_get_realmsTable(ClientConfiguration* cc)
char
ClientConfiguration_get_ignorePublicKeys(ClientConfiguration* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return 0;
}
diff --git a/src/client_initialization.c b/src/client_initialization.c
index 4361e1e..77c0e48 100644
--- a/src/client_initialization.c
+++ b/src/client_initialization.c
@@ -19,6 +19,7 @@
*/
#include <config.h>
+#include <assert.h>
#include "client_initialization.h"
#include "first_run.h"
@@ -40,6 +41,7 @@ initialize_client_stage1(ClientRealm* cr, SSL_CTX* ctx, unsigned char* buff, cha
unsigned char *encoded = NULL;
char b64_encoded[100];
unsigned char *key_buf = NULL;
+ assert((ClientRealm_get_tunnelType(cr) == 0) || (ClientRealm_get_tunnelType(cr) == 1));
switch (ClientRealm_get_tunnelType(cr)) {
case 0: {
if (ip_connect(&tmp, ClientRealm_get_serverName(cr),
diff --git a/src/client_realm_struct.c b/src/client_realm_struct.c
index 55f72e2..8edd91e 100644
--- a/src/client_realm_struct.c
+++ b/src/client_realm_struct.c
@@ -22,10 +22,12 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "string_functions.h"
#include "client_realm_struct.h"
#include "client_shutdown.h"
+#include "logging.h"
/*
* Function name: ClientRealm_new
@@ -37,6 +39,7 @@ ClientRealm*
ClientRealm_new()
{
ClientRealm* tmp = calloc(1, sizeof(ClientRealm));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -45,27 +48,32 @@ ClientRealm_new()
tmp->password[2] = 3;
tmp->password[3] = 4;
tmp->masterSslFd = SslFd_new();
+ assert(tmp->masterSslFd != NULL);
if (tmp->masterSslFd == NULL) {
ClientRealm_free(&tmp);
return NULL;
}
tmp->arOptions = ArOptions_new();
+ assert(tmp->arOptions != NULL);
if (tmp->arOptions == NULL) {
ClientRealm_free(&tmp);
return NULL;
}
tmp->httpProxyOptions = HttpProxyOptions_new();
+ assert(tmp->httpProxyOptions != NULL);
if (tmp->httpProxyOptions == NULL) {
ClientRealm_free(&tmp);
return NULL;
}
#ifdef HAVE_LIBDL
tmp->userModule = Module_new();
+ assert(tmp->userModule != NULL);
if (tmp->userModule == NULL) {
ClientRealm_free(&tmp);
return NULL;
}
tmp->serviceModule = Module_new();
+ assert(tmp->serviceModule != NULL);
if (tmp->serviceModule == NULL) {
ClientRealm_free(&tmp);
return NULL;
@@ -83,50 +91,33 @@ ClientRealm_new()
void
ClientRealm_free(ClientRealm** cr)
{
- int i;
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
+ assert((*cr) != NULL);
if ((*cr) == NULL) {
return;
}
- if ((*cr)->serverName) {
- free((*cr)->serverName);
- (*cr)->serverName = NULL;
- }
- if ((*cr)->managePort) {
- free((*cr)->managePort);
- (*cr)->managePort = NULL;
- }
- if ((*cr)->hostName) {
- free((*cr)->hostName);
- (*cr)->hostName = NULL;
- }
- if ((*cr)->destinationPort) {
- free((*cr)->destinationPort);
- (*cr)->destinationPort = NULL;
- }
- if ((*cr)->sKeepAliveTimeout) {
- free((*cr)->sKeepAliveTimeout);
- (*cr)->sKeepAliveTimeout = NULL;
- }
- if ((*cr)->realmName) {
- free((*cr)->realmName);
- (*cr)->realmName = NULL;
- }
- if ((*cr)->clientAddress) {
- free((*cr)->clientAddress);
- (*cr)->clientAddress = NULL;
- }
- if ((*cr)->usersTable) {
- for (i = 0; i < (*cr)->usersLimit; ++i) {
- if ((*cr)->usersTable[i]) {
- ConnectUser_free(&((*cr)->usersTable[i]));
- }
- }
- free((*cr)->usersTable);
- (*cr)->usersTable = NULL;
- }
+ ClientRealm_set_serverName((*cr), NULL);
+ ClientRealm_set_managePort((*cr), NULL);
+ ClientRealm_set_hostName((*cr), NULL);
+ ClientRealm_set_realmName((*cr), NULL);
+ ClientRealm_set_sKeepAliveTimeout((*cr), NULL);
+ ClientRealm_set_realmId((*cr), NULL);
+ ClientRealm_set_localName((*cr), NULL);
+ ClientRealm_set_localPort((*cr), NULL);
+ ClientRealm_set_localDestinationName((*cr), NULL);
+ ClientRealm_set_clientAddress((*cr), NULL);
+ ClientRealm_set_masterSslFd((*cr), NULL);
+ ClientRealm_set_httpProxyOptions((*cr), NULL);
+ ClientRealm_set_arOptions((*cr), NULL);
+ ClientRealm_set_destinationPorts((*cr), NULL);
+ ClientRealm_set_usersTable((*cr), NULL);
+#ifdef HAVE_LIBDL
+ ClientRealm_set_userModule((*cr), NULL);
+ ClientRealm_set_serviceModule((*cr), NULL);
+#endif
free((*cr));
(*cr) = NULL;
}
@@ -141,6 +132,7 @@ ClientRealm_free(ClientRealm** cr)
void
ClientRealm_set_serverName(ClientRealm* cr, char* serverName)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -157,6 +149,7 @@ ClientRealm_set_serverName(ClientRealm* cr, char* serverName)
void
ClientRealm_set_managePort(ClientRealm* cr, char* managePort)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -173,6 +166,7 @@ ClientRealm_set_managePort(ClientRealm* cr, char* managePort)
void
ClientRealm_set_hostName(ClientRealm* cr, char* hostName)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -180,19 +174,23 @@ ClientRealm_set_hostName(ClientRealm* cr, char* hostName)
}
/*
- * Function name: ClientRealm_set_destinationPort
- * Description: Set realm's destination port description.
+ * Function name: ClientRealm_set_destinationPorts
+ * Description: Set realm's destination ports list.
* Arguments: cr - pointer to ClientRealm structure
- * destinationPort - realm's destination port description
+ * destinationPorts - realm's destination ports list
*/
void
-ClientRealm_set_destinationPort(ClientRealm* cr, char* destinationPort)
+ClientRealm_set_destinationPorts(ClientRealm* cr, PortList* destinationPorts)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
- string_cp(&(cr->destinationPort), destinationPort);
+ if (cr->destinationPorts) {
+ PortList_free(&(cr->destinationPorts));
+ }
+ cr->destinationPorts = destinationPorts;
}
/*
@@ -205,6 +203,7 @@ ClientRealm_set_destinationPort(ClientRealm* cr, char* destinationPort)
void
ClientRealm_set_sKeepAliveTimeout(ClientRealm* cr, char* sKeepAliveTimeout)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -221,6 +220,7 @@ ClientRealm_set_sKeepAliveTimeout(ClientRealm* cr, char* sKeepAliveTimeout)
void
ClientRealm_set_realmName(ClientRealm* cr, char* realmName)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -237,6 +237,7 @@ ClientRealm_set_realmName(ClientRealm* cr, char* realmName)
void
ClientRealm_set_realmId(ClientRealm* cr, char* realmId)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -253,6 +254,7 @@ ClientRealm_set_realmId(ClientRealm* cr, char* realmId)
void
ClientRealm_set_localName(ClientRealm* cr, char* localName)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -269,6 +271,7 @@ ClientRealm_set_localName(ClientRealm* cr, char* localName)
void
ClientRealm_set_localPort(ClientRealm* cr, char* localPort)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -285,6 +288,7 @@ ClientRealm_set_localPort(ClientRealm* cr, char* localPort)
void
ClientRealm_set_localDestinationName(ClientRealm* cr, char* localDestinationName)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -301,6 +305,7 @@ ClientRealm_set_localDestinationName(ClientRealm* cr, char* localDestinationName
void
ClientRealm_set_password(ClientRealm* cr, unsigned char* password)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -317,6 +322,7 @@ ClientRealm_set_password(ClientRealm* cr, unsigned char* password)
void
ClientRealm_set_connectedUsers(ClientRealm* cr, int connectedUsers)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -333,6 +339,7 @@ ClientRealm_set_connectedUsers(ClientRealm* cr, int connectedUsers)
void
ClientRealm_set_usersLimit(ClientRealm* cr, int usersLimit)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -349,6 +356,7 @@ ClientRealm_set_usersLimit(ClientRealm* cr, int usersLimit)
void
ClientRealm_set_keepAliveTimeout(ClientRealm* cr, int keepAliveTimeout)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -365,6 +373,7 @@ ClientRealm_set_keepAliveTimeout(ClientRealm* cr, int keepAliveTimeout)
void
ClientRealm_set_clientMode(ClientRealm* cr, int clientMode)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -381,6 +390,7 @@ ClientRealm_set_clientMode(ClientRealm* cr, int clientMode)
void
ClientRealm_set_ipFamily(ClientRealm* cr, char ipFamily)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -397,6 +407,7 @@ ClientRealm_set_ipFamily(ClientRealm* cr, char ipFamily)
void
ClientRealm_set_realmType(ClientRealm* cr, char realmType)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -413,6 +424,7 @@ ClientRealm_set_realmType(ClientRealm* cr, char realmType)
void
ClientRealm_set_tunnelType(ClientRealm* cr, char tunnelType)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -429,6 +441,7 @@ ClientRealm_set_tunnelType(ClientRealm* cr, char tunnelType)
void
ClientRealm_set_keepAlive(ClientRealm* cr, struct timeval keepAlive)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -445,6 +458,7 @@ ClientRealm_set_keepAlive(ClientRealm* cr, struct timeval keepAlive)
void
ClientRealm_set_addressLength(ClientRealm* cr, socklen_t addressLength)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -461,6 +475,7 @@ ClientRealm_set_addressLength(ClientRealm* cr, socklen_t addressLength)
void
ClientRealm_set_clientAddress(ClientRealm* cr, struct sockaddr* clientAddress)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -481,6 +496,7 @@ ClientRealm_set_clientAddress(ClientRealm* cr, struct sockaddr* clientAddress)
void
ClientRealm_set_masterSslFd(ClientRealm* cr, SslFd* masterSslFd)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -500,6 +516,7 @@ ClientRealm_set_masterSslFd(ClientRealm* cr, SslFd* masterSslFd)
void
ClientRealm_set_httpProxyOptions(ClientRealm* cr, HttpProxyOptions* httpProxyOptions)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -519,6 +536,7 @@ ClientRealm_set_httpProxyOptions(ClientRealm* cr, HttpProxyOptions* httpProxyOpt
void
ClientRealm_set_arOptions(ClientRealm* cr, ArOptions* arOptions)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -539,6 +557,7 @@ void
ClientRealm_set_usersTable(ClientRealm* cr, ConnectUser** usersTable)
{
int i;
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -565,6 +584,7 @@ ClientRealm_set_usersTable(ClientRealm* cr, ConnectUser** usersTable)
void
ClientRealm_set_userModule(ClientRealm* cr, Module* userModule)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -584,6 +604,7 @@ ClientRealm_set_userModule(ClientRealm* cr, Module* userModule)
void
ClientRealm_set_serviceModule(ClientRealm* cr, Module* serviceModule)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -604,6 +625,7 @@ ClientRealm_set_serviceModule(ClientRealm* cr, Module* serviceModule)
char*
ClientRealm_get_serverName(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -620,6 +642,7 @@ ClientRealm_get_serverName(ClientRealm* cr)
char*
ClientRealm_get_managePort(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -636,6 +659,7 @@ ClientRealm_get_managePort(ClientRealm* cr)
char*
ClientRealm_get_hostName(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -643,19 +667,20 @@ ClientRealm_get_hostName(ClientRealm* cr)
}
/*
- * Function name: ClientRealm_get_destinationPort
- * Description: Get realm's destination port description.
+ * Function name: ClientRealm_get_destinationPorts
+ * Description: Get realm's destination ports list.
* Arguments: cr - pointer to ClientRealm structure
- * Returns: Realm's destination port description.
+ * Returns: Realm's destination ports list.
*/
-char*
-ClientRealm_get_destinationPort(ClientRealm* cr)
+PortList*
+ClientRealm_get_destinationPorts(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
- return cr->destinationPort;
+ return cr->destinationPorts;
}
/*
@@ -668,6 +693,7 @@ ClientRealm_get_destinationPort(ClientRealm* cr)
char*
ClientRealm_get_sKeepAliveTimeout(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -684,6 +710,7 @@ ClientRealm_get_sKeepAliveTimeout(ClientRealm* cr)
char*
ClientRealm_get_realmName(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -700,6 +727,7 @@ ClientRealm_get_realmName(ClientRealm* cr)
char*
ClientRealm_get_realmId(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -717,6 +745,7 @@ ClientRealm_get_realmId(ClientRealm* cr)
char*
ClientRealm_get_localName(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -734,6 +763,7 @@ ClientRealm_get_localName(ClientRealm* cr)
char*
ClientRealm_get_localPort(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -751,6 +781,7 @@ ClientRealm_get_localPort(ClientRealm* cr)
char*
ClientRealm_get_localDestinationName(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -767,6 +798,7 @@ ClientRealm_get_localDestinationName(ClientRealm* cr)
unsigned char*
ClientRealm_get_password(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -783,6 +815,7 @@ ClientRealm_get_password(ClientRealm* cr)
int
ClientRealm_get_connectedUsers(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return -1;
}
@@ -799,6 +832,7 @@ ClientRealm_get_connectedUsers(ClientRealm* cr)
int
ClientRealm_get_usersLimit(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return -1;
}
@@ -815,6 +849,7 @@ ClientRealm_get_usersLimit(ClientRealm* cr)
int
ClientRealm_get_keepAliveTimeout(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -831,6 +866,7 @@ ClientRealm_get_keepAliveTimeout(ClientRealm* cr)
int
ClientRealm_get_clientMode(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -847,6 +883,7 @@ ClientRealm_get_clientMode(ClientRealm* cr)
char
ClientRealm_get_ipFamily(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -863,6 +900,7 @@ ClientRealm_get_ipFamily(ClientRealm* cr)
char
ClientRealm_get_realmType(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -879,6 +917,7 @@ ClientRealm_get_realmType(ClientRealm* cr)
char
ClientRealm_get_tunnelType(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -896,6 +935,7 @@ struct timeval
ClientRealm_get_keepAlive(ClientRealm* cr)
{
struct timeval tmp = {0, 0};
+ assert(cr != NULL);
if (cr == NULL) {
return tmp;
}
@@ -912,6 +952,7 @@ ClientRealm_get_keepAlive(ClientRealm* cr)
socklen_t
ClientRealm_get_addressLength(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return 0;
}
@@ -928,6 +969,7 @@ ClientRealm_get_addressLength(ClientRealm* cr)
struct sockaddr*
ClientRealm_get_clientAddress(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -944,6 +986,7 @@ ClientRealm_get_clientAddress(ClientRealm* cr)
SslFd*
ClientRealm_get_masterSslFd(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -960,6 +1003,7 @@ ClientRealm_get_masterSslFd(ClientRealm* cr)
HttpProxyOptions*
ClientRealm_get_httpProxyOptions(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -976,6 +1020,7 @@ ClientRealm_get_httpProxyOptions(ClientRealm* cr)
ArOptions*
ClientRealm_get_arOptions(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -992,6 +1037,7 @@ ClientRealm_get_arOptions(ClientRealm* cr)
ConnectUser**
ClientRealm_get_usersTable(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -1009,6 +1055,7 @@ ClientRealm_get_usersTable(ClientRealm* cr)
Module*
ClientRealm_get_userModule(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -1025,6 +1072,7 @@ ClientRealm_get_userModule(ClientRealm* cr)
Module*
ClientRealm_get_serviceModule(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
@@ -1041,6 +1089,7 @@ ClientRealm_get_serviceModule(ClientRealm* cr)
void
ClientRealm_increase_connectedUsers(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -1056,6 +1105,7 @@ ClientRealm_increase_connectedUsers(ClientRealm* cr)
void
ClientRealm_decrease_connectedUsers(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -1064,13 +1114,14 @@ ClientRealm_decrease_connectedUsers(ClientRealm* cr)
/*
* Function name: ClientRealm_closeUsersConnections
- * Description: Close all users' connections and free usersTable
+ * Description: Close all users' connections and free usersTable.
* Arguments: cr - pointer to ClientRealm structure
*/
void
ClientRealm_closeUsersConnections(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return;
}
@@ -1079,16 +1130,76 @@ ClientRealm_closeUsersConnections(ClientRealm* cr)
/*
* Function name: ClientRealm_get_keepAlivePointer
- * Description: Get pointer to keep-alive structure
+ * Description: Get pointer to keep-alive structure.
* Arguments: cr - pointer to ClientRealm structure
- * Returns: Pointer to keep-alive structure
+ * Returns: Pointer to keep-alive structure.
*/
struct timeval*
ClientRealm_get_keepAlivePointer(ClientRealm* cr)
{
+ assert(cr != NULL);
if (cr == NULL) {
return NULL;
}
return (&(cr->keepAlive));
}
+
+/*
+ * Function name: ClientRealm_send_realmId
+ * Description: Sends the realm's id to the afserver.
+ * Arguments: cr - pointer to ClientRealm structure
+ * buff - buffer used for message creation
+ */
+
+void
+ClientRealm_send_realmId(ClientRealm* cr, unsigned char* buff)
+{
+ int n;
+ assert(cr != NULL);
+ if (cr == NULL) {
+ return;
+ }
+ assert(buff != NULL);
+ if (buff == NULL) {
+ return;
+ }
+ if (ClientRealm_get_realmId(cr) != NULL) {
+ buff[0] = AF_S_LOGIN;
+ buff[1] = buff[2] = 0;
+ n = strlen(ClientRealm_get_realmId(cr));
+ memcpy(&buff[5], ClientRealm_get_realmId(cr), n);
+ buff[3] = n >> 8; /* high bits of message length */
+ buff[4] = n; /* low bits of message length */
+ SslFd_send_message(ClientRealm_get_realmType(cr),
+ ClientRealm_get_masterSslFd(cr), buff, n+5);
+ aflog(LOG_T_CLIENT, LOG_I_INFO,
+ "ID SENT: %s", ClientRealm_get_realmId(cr));
+ }
+}
+
+/*
+ * Function name: ClientRealm_enable_multi
+ * Description: Enables the MULTI mode on the afserver, if supported.
+ * Arguments: cr - pointer to ClientRealm structure
+ */
+
+void
+ClientRealm_enable_multi(ClientRealm* cr)
+{
+ unsigned char buff[5];
+ assert(cr != NULL);
+ if (cr == NULL) {
+ return;
+ }
+ if ((TYPE_IS_SUPPORTED_MULTI(ClientRealm_get_realmType(cr))) &&
+ (PortList_get_size(ClientRealm_get_destinationPorts(cr)) > 1)) {
+ buff[0] = AF_S_ENABLE_MULTI;
+ buff[1] = PortList_get_size(ClientRealm_get_destinationPorts(cr));
+ buff[2] = buff[3] = buff[4] = 0;
+ SslFd_send_message(ClientRealm_get_realmType(cr),
+ ClientRealm_get_masterSslFd(cr), buff, 5);
+ aflog(LOG_T_CLIENT, LOG_I_INFO,
+ "ENABLED: MULTI (multiple tunnels managed by one afclient)");
+ }
+}
diff --git a/src/client_realm_struct.h b/src/client_realm_struct.h
index 69737db..d4d5c2b 100644
--- a/src/client_realm_struct.h
+++ b/src/client_realm_struct.h
@@ -23,6 +23,7 @@
#include "http_proxy_options_struct.h"
#include "ar_options_struct.h"
#include "module_struct.h"
+#include "port_list_struct.h"
#ifndef _JS_CLIENT_REALM_STRUCT_H
#define _JS_CLIENT_REALM_STRUCT_H
@@ -42,7 +43,6 @@ typedef struct {
char* serverName;
char* managePort;
char* hostName;
- char* destinationPort;
char* realmName;
char* sKeepAliveTimeout;
char* realmId;
@@ -63,6 +63,7 @@ typedef struct {
SslFd* masterSslFd;
HttpProxyOptions* httpProxyOptions;
ArOptions* arOptions;
+ PortList* destinationPorts;
ConnectUser** usersTable;
#ifdef HAVE_LIBDL
Module* userModule;
@@ -78,7 +79,6 @@ void ClientRealm_free(ClientRealm** cr);
void ClientRealm_set_serverName(ClientRealm* cr, char* serverName);
void ClientRealm_set_managePort(ClientRealm* cr, char* managePort);
void ClientRealm_set_hostName(ClientRealm* cr, char* hostName);
-void ClientRealm_set_destinationPort(ClientRealm* cr, char* destinationPort);
void ClientRealm_set_realmName(ClientRealm* cr, char* realmName);
void ClientRealm_set_sKeepAliveTimeout(ClientRealm* cr, char* sKeepAliveTimeout);
void ClientRealm_set_realmId(ClientRealm* cr, char* realmId);
@@ -99,6 +99,7 @@ void ClientRealm_set_clientAddress(ClientRealm* cr, struct sockaddr* clientAddre
void ClientRealm_set_masterSslFd(ClientRealm* cr, SslFd* masterSslFd);
void ClientRealm_set_httpProxyOptions(ClientRealm* cr, HttpProxyOptions* httpProxyOptions);
void ClientRealm_set_arOptions(ClientRealm* cr, ArOptions* arOptions);
+void ClientRealm_set_destinationPorts(ClientRealm* cr, PortList* destinationPorts);
void ClientRealm_set_usersTable(ClientRealm* cr, ConnectUser** usersTable);
#ifdef HAVE_LIBDL
void ClientRealm_set_userModule(ClientRealm* cr, Module* userModule);
@@ -108,7 +109,6 @@ void ClientRealm_set_serviceModule(ClientRealm* cr, Module* serviceModule);
char* ClientRealm_get_serverName(ClientRealm* cr);
char* ClientRealm_get_managePort(ClientRealm* cr);
char* ClientRealm_get_hostName(ClientRealm* cr);
-char* ClientRealm_get_destinationPort(ClientRealm* cr);
char* ClientRealm_get_realmName(ClientRealm* cr);
char* ClientRealm_get_sKeepAliveTimeout(ClientRealm* cr);
char* ClientRealm_get_realmId(ClientRealm* cr);
@@ -129,6 +129,7 @@ struct sockaddr* ClientRealm_get_clientAddress(ClientRealm* cr);
SslFd* ClientRealm_get_masterSslFd(ClientRealm* cr);
HttpProxyOptions* ClientRealm_get_httpProxyOptions(ClientRealm* cr);
ArOptions* ClientRealm_get_arOptions(ClientRealm* cr);
+PortList* ClientRealm_get_destinationPorts(ClientRealm* cr);
ConnectUser** ClientRealm_get_usersTable(ClientRealm* cr);
#ifdef HAVE_LIBDL
Module* ClientRealm_get_userModule(ClientRealm* cr);
@@ -139,5 +140,7 @@ void ClientRealm_increase_connectedUsers(ClientRealm* cr);
void ClientRealm_decrease_connectedUsers(ClientRealm* cr);
void ClientRealm_closeUsersConnections(ClientRealm* cr);
struct timeval* ClientRealm_get_keepAlivePointer(ClientRealm* cr);
+void ClientRealm_send_realmId(ClientRealm* cr, unsigned char* buff);
+void ClientRealm_enable_multi(ClientRealm* cr);
#endif
diff --git a/src/client_remoteadmin.c b/src/client_remoteadmin.c
index 298e983..c38ee0f 100644
--- a/src/client_remoteadmin.c
+++ b/src/client_remoteadmin.c
@@ -22,6 +22,18 @@
#include "client_remoteadmin.h"
+/*
+ * Function name: client_admin
+ * Description: This function is responsible for client part of the admin panel.
+ * Arguments: type - the type of the realm
+ * master - pointer to the SslFd structure representing the connection with afserver
+ * buff - buffer which will be used for communication
+ * connectfd - the optional descriptor which can be used instead of the stdin
+ * id - the realm's id
+ * Returns: 0 - connection was closed normally,
+ * 1 - something went bad.
+ */
+
int
client_admin(char type, SslFd* master, unsigned char* buff, int connectfd, char* id)
{
diff --git a/src/client_reverse_udp.c b/src/client_reverse_udp.c
index b1eb208..048ffda 100644
--- a/src/client_reverse_udp.c
+++ b/src/client_reverse_udp.c
@@ -24,6 +24,14 @@
#include <stdlib.h>
+/*
+ * Function name: initialize_client_reverse_udp
+ * Description: Initializes the realm for reverse udp connection.
+ * Arguments: cr - pointer to ClientRealm structure
+ * Returns: 0 - connection was initialized successfully,
+ * 1 - connection initialization failed.
+ */
+
int
initialize_client_reverse_udp(ClientRealm* cr)
{
@@ -56,26 +64,39 @@ initialize_client_reverse_udp(ClientRealm* cr)
return 0;
}
+/*
+ * Function name: client_reverse_udp
+ * Description: This function is responsible for the client part of the reverse udp tunnel.
+ * Arguments: cr - pointer to ClientRealm structure
+ * buff - buffer which will be used for communication
+ * buflength - socket send buffer size
+ */
+
void
client_reverse_udp(ClientRealm* cr, unsigned char* buff, int buflength)
{
socklen_t len, addrlen;
- int maxfdp1, temp, notsent, n, length;
+ int maxfdp1, temp, n, length;
+#ifdef HAVE_LINUX_SOCKIOS_H
+ int notsent;
+#endif
struct sockaddr* cliaddr;
fd_set rset, allset;
if (ip_listen(&temp, ClientRealm_get_hostName(cr),
- ClientRealm_get_destinationPort(cr), &addrlen,
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(cr), 0)), &addrlen,
ClientRealm_get_ipFamily(cr) & 0xfe)) {
#ifdef AF_INET6
aflog(LOG_T_INIT, LOG_I_DEBUG,
"udp_listen_%s error for %s, %s",
(ClientRealm_get_ipFamily(cr) & 0x02) ?
"ipv4":(ClientRealm_get_ipFamily(cr) & 0x04) ?
- "ipv6":"unspec", ClientRealm_get_hostName(cr), ClientRealm_get_destinationPort(cr));
+ "ipv6":"unspec", ClientRealm_get_hostName(cr),
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(cr), 0)));
#else
aflog(LOG_T_INIT, LOG_I_DEBUG,
- "udp_listen error for %s, %s", ClientRealm_get_hostName(cr), ClientRealm_get_destinationPort(cr));
+ "udp_listen error for %s, %s", ClientRealm_get_hostName(cr),
+ PortListNode_get_portName(PortList_get_nth(ClientRealm_get_destinationPorts(cr), 0)));
#endif
exit(1);
}
diff --git a/src/client_shutdown.c b/src/client_shutdown.c
index 8075632..bacb854 100644
--- a/src/client_shutdown.c
+++ b/src/client_shutdown.c
@@ -19,6 +19,7 @@
*/
#include <config.h>
+#include <assert.h>
#include "client_shutdown.h"
@@ -26,6 +27,12 @@ void
close_connections(int usernum, ConnectUser*** contable)
{
int i;
+
+ assert(contable != NULL);
+ if (contable == NULL) {
+ return;
+ }
+
if (*contable) {
for (i = 0; i < usernum; ++i) {
if ((ConnectUser_get_state((*contable)[i]) == S_STATE_OPEN) ||
diff --git a/src/clientnames.c b/src/clientnames.c
index c3f3fcf..8029abf 100644
--- a/src/clientnames.c
+++ b/src/clientnames.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "clientnames.h"
char*
@@ -29,6 +30,11 @@ get_clientname(ServerRealm* pointer, int client)
{
static char clientname[10];
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return NULL;
+ }
+
if (ConnectClient_get_sClientId(ServerRealm_get_clientsTable(pointer)[client]) == NULL) {
memset(clientname, 0, 10);
sprintf(clientname, "%d", ConnectClient_get_clientId(ServerRealm_get_clientsTable(pointer)[client]));
@@ -44,6 +50,16 @@ get_clientid(ServerRealm* pointer, char* clientname)
int i, n;
char guard;
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return -1;
+ }
+
+ assert(clientname != NULL);
+ if (clientname == NULL) {
+ return -1;
+ }
+
for (i = 0; i < ServerRealm_get_clientsLimit(pointer); ++i) {
if (ConnectClient_get_sClientId(ServerRealm_get_clientsTable(pointer)[i]) != NULL) {
if (strcmp(clientname, ConnectClient_get_sClientId(ServerRealm_get_clientsTable(pointer)[i])) == 0) {
@@ -67,6 +83,12 @@ int
get_clientnumber(ServerRealm* pointer, int clientid)
{
int i;
+
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return -1;
+ }
+
for (i = 0; i < ServerRealm_get_clientsLimit(pointer); ++i) {
if (ConnectClient_get_clientId(ServerRealm_get_clientsTable(pointer)[i]) == clientid) {
return i;
@@ -81,6 +103,11 @@ get_raclientname(ServerRealm* pointer, int client)
{
static char clientname[10];
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return NULL;
+ }
+
if (ConnectClient_get_sClientId(ServerRealm_get_raClientsTable(pointer)[client]) == NULL) {
memset(clientname, 0, 10);
sprintf(clientname, "%d", ConnectClient_get_clientId(ServerRealm_get_raClientsTable(pointer)[client]));
@@ -96,6 +123,16 @@ get_raclientid(ServerRealm* pointer, char* clientname)
int i, n;
char guard;
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return -1;
+ }
+
+ assert(clientname != NULL);
+ if (clientname == NULL) {
+ return -1;
+ }
+
for (i = 0; i < ServerRealm_get_raClientsLimit(pointer); ++i) {
if (ConnectClient_get_sClientId(ServerRealm_get_raClientsTable(pointer)[i]) != NULL) {
if (strcmp(clientname, ConnectClient_get_sClientId(ServerRealm_get_raClientsTable(pointer)[i])) == 0) {
@@ -120,6 +157,12 @@ int
get_raclientnumber(ServerRealm* pointer, int clientid)
{
int i;
+
+ assert(pointer != NULL);
+ if (pointer == NULL) {
+ return -1;
+ }
+
for (i = 0; i < ServerRealm_get_raClientsLimit(pointer); ++i) {
if (ConnectClient_get_clientId(ServerRealm_get_raClientsTable(pointer)[i]) == clientid) {
return i;
diff --git a/src/connect_client_struct.c b/src/connect_client_struct.c
index a07ed50..3481833 100644
--- a/src/connect_client_struct.c
+++ b/src/connect_client_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "string_functions.h"
#include "timeval_functions.h"
@@ -29,7 +30,7 @@
/*
* Function name: ConnectClient_new
- * Description: Create and initialize new ConnectClient structure.
+ * Description: Creates and initializes new ConnectClient structure.
* Returns: Pointer to newly created ConnectClient structure.
*/
@@ -37,20 +38,24 @@ ConnectClient*
ConnectClient_new()
{
ConnectClient* tmp = calloc(1, sizeof(ConnectClient));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
tmp->sslFd = SslFd_new();
+ assert(tmp->sslFd != NULL);
if (tmp->sslFd == NULL) {
ConnectClient_free(&tmp);
return NULL;
}
tmp->auditList = AuditList_new();
+ assert(tmp->auditList != NULL);
if (tmp->auditList == NULL) {
ConnectClient_free(&tmp);
return NULL;
}
tmp->header = HeaderBuffer_new();
+ assert(tmp->header != NULL);
if (tmp->header == NULL) {
ConnectClient_free(&tmp);
return NULL;
@@ -60,7 +65,7 @@ ConnectClient_new()
/*
* Function name: ConnectClient_free
- * Description: Free the memory allocated for ConnectClient structure.
+ * Description: Frees the memory allocated for ConnectClient structure.
* Arguments: cc - pointer to pointer to ConnectClient structure
*/
@@ -69,9 +74,11 @@ ConnectClient_free(ConnectClient** cc)
{
SslFd* sftmp;
AuditList* altmp;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
+ assert((*cc) != NULL);
if ((*cc) == NULL) {
return;
}
@@ -93,7 +100,7 @@ ConnectClient_free(ConnectClient** cc)
/*
* Function name: ConnectClient_set_state
- * Description: Set state of the connected client.
+ * Description: Sets state of the connected client.
* Arguments: cc - pointer to ConnectClient structure
* state - state of the connected client
*/
@@ -101,6 +108,7 @@ ConnectClient_free(ConnectClient** cc)
void
ConnectClient_set_state(ConnectClient* cc, char state)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -109,7 +117,7 @@ ConnectClient_set_state(ConnectClient* cc, char state)
/*
* Function name: ConnectClient_set_sslFd
- * Description: Set SslFd structure.
+ * Description: Sets SslFd structure.
* Arguments: cc - pointer to ConnectClient structure
* sf - SslFd structure
*/
@@ -118,6 +126,7 @@ void
ConnectClient_set_sslFd(ConnectClient* cc, SslFd* sf)
{
SslFd* sftmp;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -128,7 +137,7 @@ ConnectClient_set_sslFd(ConnectClient* cc, SslFd* sf)
/*
* Function name: ConnectClient_set_timer
- * Description: Set timer of the client used for internal time counting.
+ * Description: Sets timer of the client used for internal time counting.
* Arguments: cc - pointer to ConnectClient structure
* timer - timer of the client used for internal time counting
*/
@@ -136,6 +145,7 @@ ConnectClient_set_sslFd(ConnectClient* cc, SslFd* sf)
void
ConnectClient_set_timer(ConnectClient* cc, struct timeval timer)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -144,7 +154,7 @@ ConnectClient_set_timer(ConnectClient* cc, struct timeval timer)
/*
* Function name: ConnectClient_set_users
- * Description: Set users descriptor table.
+ * Description: Sets users descriptor table.
* Arguments: cc - pointer to ConnectClient structure
* users - users descriptor table
*/
@@ -152,6 +162,7 @@ ConnectClient_set_timer(ConnectClient* cc, struct timeval timer)
void
ConnectClient_set_users(ConnectClient* cc, int* users)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -163,7 +174,7 @@ ConnectClient_set_users(ConnectClient* cc, int* users)
/*
* Functions name: ConnectClient_set_connected
- * Description: Set number of connected users.
+ * Description: Sets number of connected users.
* Arguments: cc - pointer to ConnectClient structure
* connected - number of connected users
*/
@@ -171,6 +182,7 @@ ConnectClient_set_users(ConnectClient* cc, int* users)
void
ConnectClient_set_connected(ConnectClient* cc, int connected)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -179,7 +191,7 @@ ConnectClient_set_connected(ConnectClient* cc, int connected)
/*
* Function name: ConnectClient_set_limit
- * Description: Set limit of connected users.
+ * Description: Sets limit of connected users.
* Arguments: cc - pointer to ConnectClient structure
* limit - limit of connected users
*/
@@ -187,6 +199,7 @@ ConnectClient_set_connected(ConnectClient* cc, int connected)
void
ConnectClient_set_limit(ConnectClient* cc, int limit)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -195,7 +208,7 @@ ConnectClient_set_limit(ConnectClient* cc, int limit)
/*
* Function name: ConnectClient_set_listenFd
- * Description: Set listen socket descriptor.
+ * Description: Sets listen socket descriptor.
* Arguments: cc - pointer to ConnectClient structure
* listenFd - listen socket descriptor
*/
@@ -203,6 +216,7 @@ ConnectClient_set_limit(ConnectClient* cc, int limit)
void
ConnectClient_set_listenFd(ConnectClient* cc, int listenFd)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -211,7 +225,7 @@ ConnectClient_set_listenFd(ConnectClient* cc, int listenFd)
/*
* Function name: ConnectClient_set_usrCliPair
- * Description: Set user-client pair number.
+ * Description: Sets user-client pair number.
* Arguments: cc - pointer to ConnectClient structure
* usrCliPair - user-client pair number
*/
@@ -219,6 +233,7 @@ ConnectClient_set_listenFd(ConnectClient* cc, int listenFd)
void
ConnectClient_set_usrCliPair(ConnectClient* cc, int usrCliPair)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -227,7 +242,7 @@ ConnectClient_set_usrCliPair(ConnectClient* cc, int usrCliPair)
/*
* Function name: ConnectClient_set_clientId
- * Description: Set client identification number.
+ * Description: Sets client identification number.
* Arguments: cc - pointer to ConnectClient structure
* clientId - client identification number
*/
@@ -235,6 +250,7 @@ ConnectClient_set_usrCliPair(ConnectClient* cc, int usrCliPair)
void
ConnectClient_set_clientId(ConnectClient* cc, int clientId)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -243,7 +259,7 @@ ConnectClient_set_clientId(ConnectClient* cc, int clientId)
/*
* Function name: ConnectClient_set_connectTime
- * Description: Set start time of the connection.
+ * Description: Sets start time of the connection.
* Arguments: cc - pointer to ConnectClient structure
* connectTime - start time of the connection
*/
@@ -251,6 +267,7 @@ ConnectClient_set_clientId(ConnectClient* cc, int clientId)
void
ConnectClient_set_connectTime(ConnectClient* cc, time_t connectTime)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -259,7 +276,7 @@ ConnectClient_set_connectTime(ConnectClient* cc, time_t connectTime)
/*
* Function name: ConnectClient_set_sClientId
- * Description: Set client identification string.
+ * Description: Sets client identification string.
* Arguments: cc - pointer to ConnectClient structure
* sClientId - client identification string
*/
@@ -267,6 +284,7 @@ ConnectClient_set_connectTime(ConnectClient* cc, time_t connectTime)
void
ConnectClient_set_sClientId(ConnectClient* cc, char* sClientId)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -275,7 +293,7 @@ ConnectClient_set_sClientId(ConnectClient* cc, char* sClientId)
/*
* Function name: ConnectClient_set_nameBuf
- * Description: Set name of the client.
+ * Description: Sets name of the client.
* Arguments: cc - pointer to ConnectClient structure
* nameBuf - name of the client
*/
@@ -283,6 +301,7 @@ ConnectClient_set_sClientId(ConnectClient* cc, char* sClientId)
void
ConnectClient_set_nameBuf(ConnectClient* cc, char* nameBuf)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -292,7 +311,7 @@ ConnectClient_set_nameBuf(ConnectClient* cc, char* nameBuf)
/*
* Function name: ConnectClient_set_portBuf
- * Description: Set port from which client is connected.
+ * Description: Sets port from which client is connected.
* Arguments: cc - pointer to ConnectClient structure
* portBuf - port from which client is connected
*/
@@ -300,6 +319,7 @@ ConnectClient_set_nameBuf(ConnectClient* cc, char* nameBuf)
void
ConnectClient_set_portBuf(ConnectClient* cc, char* portBuf)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -309,7 +329,7 @@ ConnectClient_set_portBuf(ConnectClient* cc, char* portBuf)
/*
* Function name: ConnectClient_set_tunnelType
- * Description: Set tupe of the client tunnel.
+ * Description: Sets tupe of the client tunnel.
* Arguments: cc - pointer to ConnectClient structure
* tunnelType - tupe of the client tunnel
*/
@@ -317,6 +337,7 @@ ConnectClient_set_portBuf(ConnectClient* cc, char* portBuf)
void
ConnectClient_set_tunnelType(ConnectClient* cc, char tunnelType)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -324,8 +345,26 @@ ConnectClient_set_tunnelType(ConnectClient* cc, char tunnelType)
}
/*
+ * Function name: ConnectClient_set_multi
+ * Description: Sets the status of the multi option.
+ * Arguments: cc - pointer to ConnectClient structure
+ * multi - the status of the multi option
+ */
+
+void
+ConnectClient_set_multi(ConnectClient* cc, char multi)
+{
+ assert(cc != NULL);
+ if (cc == NULL) {
+ return;
+ }
+ assert((multi == CONNECTCLIENT_MULTI_ENABLED) || (multi == CONNECTCLIENT_MULTI_DISABLED));
+ cc->multi = multi;
+}
+
+/*
* Function name: ConnectClient_set_auditList
- * Description: Set audit list for the audit feature.
+ * Description: Sets audit list for the audit feature.
* Arguments: cc - pointer to ConnectClient structure
* al - audit list for the audit feature
*/
@@ -334,6 +373,7 @@ void
ConnectClient_set_auditList(ConnectClient* cc, AuditList* al)
{
AuditList* altmp;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -344,7 +384,7 @@ ConnectClient_set_auditList(ConnectClient* cc, AuditList* al)
/*
* Function name: ConnectClient_set_header
- * Description: Set header buffer for incomplete headers.
+ * Description: Sets header buffer for incomplete headers.
* Arguments: cc - pointer to ConnectClient structure
* hb - header buffer for incomplete headers
*/
@@ -353,6 +393,7 @@ void
ConnectClient_set_header(ConnectClient* cc, HeaderBuffer* hb)
{
HeaderBuffer* hbtmp;
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -363,7 +404,7 @@ ConnectClient_set_header(ConnectClient* cc, HeaderBuffer* hb)
/*
* Function name: ConnectClient_get_state
- * Description: Get state of the connected client.
+ * Description: Gets state of the connected client.
* Arguments: cc - pointer to ConnectClient structure
* Returns: State of the connected client.
*/
@@ -371,6 +412,7 @@ ConnectClient_set_header(ConnectClient* cc, HeaderBuffer* hb)
char
ConnectClient_get_state(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return CONNECTCLIENT_STATE_UNKNOWN;
}
@@ -379,7 +421,7 @@ ConnectClient_get_state(ConnectClient* cc)
/*
* Function name: ConnectClient_get_sslFd
- * Description: Get SslFd structure.
+ * Description: Gets SslFd structure.
* Arguments: cc - pointer to ConnectClient structure
* Returns: SslFd structure.
*/
@@ -387,6 +429,7 @@ ConnectClient_get_state(ConnectClient* cc)
SslFd*
ConnectClient_get_sslFd(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -395,7 +438,7 @@ ConnectClient_get_sslFd(ConnectClient* cc)
/*
* Function name: ConnectClient_get_timer
- * Description: Get timer of the client used for internal time counting.
+ * Description: Gets timer of the client used for internal time counting.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Timer of the client used for internal time counting.
*/
@@ -403,6 +446,7 @@ ConnectClient_get_sslFd(ConnectClient* cc)
struct timeval
ConnectClient_get_timer(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return timeval_create(0, 0);
}
@@ -411,7 +455,7 @@ ConnectClient_get_timer(ConnectClient* cc)
/*
* Function name: ConnectClient_get_users
- * Description: Get users descriptor table.
+ * Description: Gets users descriptor table.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Users descriptor table.
*/
@@ -419,6 +463,7 @@ ConnectClient_get_timer(ConnectClient* cc)
int*
ConnectClient_get_users(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -427,7 +472,7 @@ ConnectClient_get_users(ConnectClient* cc)
/*
* Function name: ConnectClient_get_connected
- * Description: Get number of connected users.
+ * Description: Gets number of connected users.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Number of connected users.
*/
@@ -435,6 +480,7 @@ ConnectClient_get_users(ConnectClient* cc)
int
ConnectClient_get_connected(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -443,7 +489,7 @@ ConnectClient_get_connected(ConnectClient* cc)
/*
* Function name: ConnectClient_get_limit
- * Description: Get limit of connected users.
+ * Description: Gets limit of connected users.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Limit of connected users.
*/
@@ -451,6 +497,7 @@ ConnectClient_get_connected(ConnectClient* cc)
int
ConnectClient_get_limit(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -459,7 +506,7 @@ ConnectClient_get_limit(ConnectClient* cc)
/*
* Function name: ConnectClient_get_listenFd
- * Description: Get listen socket descriptor.
+ * Description: Gets listen socket descriptor.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Listen socket descriptor.
*/
@@ -467,6 +514,7 @@ ConnectClient_get_limit(ConnectClient* cc)
int
ConnectClient_get_listenFd(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -475,7 +523,7 @@ ConnectClient_get_listenFd(ConnectClient* cc)
/*
* Function name: ConnectClient_get_usrCliPair
- * Description: Get user-client pair number.
+ * Description: Gets user-client pair number.
* Arguments: cc - pointer to ConnectClient structure
* Returns: User-client pair number.
*/
@@ -483,6 +531,7 @@ ConnectClient_get_listenFd(ConnectClient* cc)
int
ConnectClient_get_usrCliPair(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -491,7 +540,7 @@ ConnectClient_get_usrCliPair(ConnectClient* cc)
/*
* Function name: ConnectClient_get_clientId
- * Description: Get client identification number.
+ * Description: Gets client identification number.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Client identification number.
*/
@@ -499,6 +548,7 @@ ConnectClient_get_usrCliPair(ConnectClient* cc)
int
ConnectClient_get_clientId(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return -1;
}
@@ -507,7 +557,7 @@ ConnectClient_get_clientId(ConnectClient* cc)
/*
* Function name: ConnectClient_get_connectTime
- * Description: Get start time of the connection.
+ * Description: Gets start time of the connection.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Start time of the connection.
*/
@@ -515,6 +565,7 @@ ConnectClient_get_clientId(ConnectClient* cc)
time_t
ConnectClient_get_connectTime(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return 0;
}
@@ -523,7 +574,7 @@ ConnectClient_get_connectTime(ConnectClient* cc)
/*
* Function name: ConnectClient_get_sClientId
- * Description: Get client identification string.
+ * Description: Gets client identification string.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Client identification string.
*/
@@ -531,6 +582,7 @@ ConnectClient_get_connectTime(ConnectClient* cc)
char*
ConnectClient_get_sClientId(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -539,7 +591,7 @@ ConnectClient_get_sClientId(ConnectClient* cc)
/*
* Function name: ConnectClient_get_nameBuf
- * Description: Get name of the client.
+ * Description: Gets name of the client.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Name of the client.
*/
@@ -547,6 +599,7 @@ ConnectClient_get_sClientId(ConnectClient* cc)
char*
ConnectClient_get_nameBuf(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -555,7 +608,7 @@ ConnectClient_get_nameBuf(ConnectClient* cc)
/*
* Function name: ConnectClient_get_portBuf
- * Description: Get port from which client is connected.
+ * Description: Gets port from which client is connected.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Port from which client is connected.
*/
@@ -563,6 +616,7 @@ ConnectClient_get_nameBuf(ConnectClient* cc)
char*
ConnectClient_get_portBuf(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -571,7 +625,7 @@ ConnectClient_get_portBuf(ConnectClient* cc)
/*
* Function name: ConnectClient_get_tunnelType
- * Description: Get tupe of the client tunnel.
+ * Description: Gets tupe of the client tunnel.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Tupe of the client tunnel.
*/
@@ -579,6 +633,7 @@ ConnectClient_get_portBuf(ConnectClient* cc)
char
ConnectClient_get_tunnelType(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return CONNECTCLIENT_TUNNELTYPE_UNKNOWN;
}
@@ -586,8 +641,26 @@ ConnectClient_get_tunnelType(ConnectClient* cc)
}
/*
+ * Function name: ConnectClient_get_multi
+ * Description: Gets the status of the multi option.
+ * Arguments: cc - pointer to ConnectClient structure
+ * Returns: CONNECTCLIENT_MULTI_ENABLED - the option is enabled,
+ * CONNECTCLIENT_MULTI_DISABLED - the option is disabled.
+ */
+
+char
+ConnectClient_get_multi(ConnectClient* cc)
+{
+ assert(cc != NULL);
+ if (cc == NULL) {
+ return CONNECTCLIENT_MULTI_DISABLED;
+ }
+ return cc->multi;
+}
+
+/*
* Function name: ConnectClient_get_auditList
- * Description: Get audit list for the audit feature.
+ * Description: Gets audit list for the audit feature.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Audit list for the audit feature.
*/
@@ -595,6 +668,7 @@ ConnectClient_get_tunnelType(ConnectClient* cc)
AuditList*
ConnectClient_get_auditList(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -603,7 +677,7 @@ ConnectClient_get_auditList(ConnectClient* cc)
/*
* Function name: ConnectClient_get_header
- * Description: Get header buffer for incomplete headers.
+ * Description: Gets header buffer for incomplete headers.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Header buffer for incomplete headers.
*/
@@ -611,6 +685,7 @@ ConnectClient_get_auditList(ConnectClient* cc)
HeaderBuffer*
ConnectClient_get_header(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -619,7 +694,7 @@ ConnectClient_get_header(ConnectClient* cc)
/*
* Function name: ConnectClient_create_users
- * Description: Create user descriptor table. Memory for the table is allocated according
+ * Description: Creates user descriptor table. Memory for the table is allocated according
* to the previously set 'limit' value. All the descriptors are set to -1.
* Arguments: cc - pointer to ConnectClient structure
* Returns: >0 - there were some problems with memory allocation
@@ -630,14 +705,17 @@ int
ConnectClient_create_users(ConnectClient* cc)
{
int i, limit;
+ assert(cc != NULL);
if (cc == NULL) {
return 1;
}
limit = ConnectClient_get_limit(cc);
+ assert(limit != -1);
if (limit == -1) {
return 2;
}
cc->users = malloc(limit * sizeof(int));
+ assert(cc->users != NULL);
if (cc->users == NULL) {
return 3;
}
@@ -649,7 +727,7 @@ ConnectClient_create_users(ConnectClient* cc)
/*
* Function name: ConnectClient_get_timerp
- * Description: Get pointer to timer of the client used for internal time counting.
+ * Description: Gets pointer to timer of the client used for internal time counting.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Pointer to timer of the client used for internal time counting.
*/
@@ -657,6 +735,7 @@ ConnectClient_create_users(ConnectClient* cc)
struct timeval*
ConnectClient_get_timerp(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
@@ -665,13 +744,14 @@ ConnectClient_get_timerp(ConnectClient* cc)
/*
* Function name: ConnectClient_increase_connected
- * Description: Increase number of connected users.
+ * Description: Increases number of connected users.
* Arguments: cc - pointer to ConnectClient structure
*/
void
ConnectClient_increase_connected(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -680,13 +760,14 @@ ConnectClient_increase_connected(ConnectClient* cc)
/*
* Function name: ConnectClient_decrease_connected
- * Description: Decrease number of connected users.
+ * Description: Decreases number of connected users.
* Arguments: cc - pointer to ConnectClient structure
*/
void
ConnectClient_decrease_connected(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return;
}
@@ -695,7 +776,7 @@ ConnectClient_decrease_connected(ConnectClient* cc)
/*
* Function name: ConnectClient_get_listenFdp
- * Description: Get pointer to listen socket descriptor.
+ * Description: Gets pointer to listen socket descriptor.
* Arguments: cc - pointer to ConnectClient structure
* Returns: Pointer to listen socket descriptor.
*/
@@ -703,6 +784,7 @@ ConnectClient_decrease_connected(ConnectClient* cc)
int*
ConnectClient_get_listenFdp(ConnectClient* cc)
{
+ assert(cc != NULL);
if (cc == NULL) {
return NULL;
}
diff --git a/src/connect_client_struct.h b/src/connect_client_struct.h
index a0e9127..58ce276 100644
--- a/src/connect_client_struct.h
+++ b/src/connect_client_struct.h
@@ -39,6 +39,9 @@
#define CONNECTCLIENT_TUNNELTYPE_HTTPPROXY 1
#define CONNECTCLIENT_TUNNELTYPE_HTTPSPROXY 2
+#define CONNECTCLIENT_MULTI_ENABLED 1
+#define CONNECTCLIENT_MULTI_DISABLED 0
+
typedef struct {
char state;
SslFd* sslFd;
@@ -54,6 +57,7 @@ typedef struct {
char nameBuf[128];
char portBuf[7];
char tunnelType;
+ char multi;
AuditList* auditList;
HeaderBuffer* header;
} ConnectClient;
@@ -77,6 +81,7 @@ void ConnectClient_set_sClientId(ConnectClient* cc, char* sClientId);
void ConnectClient_set_nameBuf(ConnectClient* cc, char* nameBuf);
void ConnectClient_set_portBuf(ConnectClient* cc, char* portBuf);
void ConnectClient_set_tunnelType(ConnectClient* cc, char tunnelType);
+void ConnectClient_set_multi(ConnectClient* cc, char multi);
void ConnectClient_set_auditList(ConnectClient* cc, AuditList* al);
void ConnectClient_set_header(ConnectClient* cc, HeaderBuffer* hb);
/* getters */
@@ -94,6 +99,7 @@ char* ConnectClient_get_sClientId(ConnectClient* cc);
char* ConnectClient_get_nameBuf(ConnectClient* cc);
char* ConnectClient_get_portBuf(ConnectClient* cc);
char ConnectClient_get_tunnelType(ConnectClient* cc);
+char ConnectClient_get_multi(ConnectClient* cc);
AuditList* ConnectClient_get_auditList(ConnectClient* cc);
HeaderBuffer* ConnectClient_get_header(ConnectClient* cc);
/* other */
diff --git a/src/connect_user_struct.c b/src/connect_user_struct.c
index 7c46f68..d8cd5be 100644
--- a/src/connect_user_struct.c
+++ b/src/connect_user_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "activefor.h"
#include "connect_user_struct.h"
@@ -36,15 +37,18 @@ ConnectUser*
ConnectUser_new()
{
ConnectUser* tmp = calloc(1, sizeof(ConnectUser));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
tmp->bufList = BufList_new();
+ assert(tmp->bufList != NULL);
if (tmp->bufList == NULL) {
ConnectUser_free(&tmp);
return NULL;
}
tmp->stats = UserStats_new();
+ assert(tmp->stats != NULL);
if (tmp->stats == NULL) {
ConnectUser_free(&tmp);
return NULL;
@@ -63,9 +67,11 @@ ConnectUser_free(ConnectUser** cu)
{
BufList* bftmp;
UserStats* ustmp;
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
+ assert((*cu) != NULL);
if ((*cu) == NULL) {
return;
}
@@ -87,6 +93,7 @@ ConnectUser_free(ConnectUser** cu)
void
ConnectUser_set_state(ConnectUser* cu, char state)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -103,6 +110,7 @@ ConnectUser_set_state(ConnectUser* cu, char state)
void
ConnectUser_set_connFd(ConnectUser* cu, int connFd)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -119,6 +127,7 @@ ConnectUser_set_connFd(ConnectUser* cu, int connFd)
void
ConnectUser_set_whatClient(ConnectUser* cu, int whatClient)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -135,6 +144,7 @@ ConnectUser_set_whatClient(ConnectUser* cu, int whatClient)
void
ConnectUser_set_userId(ConnectUser* cu, int userId)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -151,6 +161,7 @@ ConnectUser_set_userId(ConnectUser* cu, int userId)
void
ConnectUser_set_connectTime(ConnectUser* cu, time_t connectTime)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -167,6 +178,7 @@ ConnectUser_set_connectTime(ConnectUser* cu, time_t connectTime)
void
ConnectUser_set_nameBuf(ConnectUser* cu, char* nameBuf)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -184,6 +196,7 @@ ConnectUser_set_nameBuf(ConnectUser* cu, char* nameBuf)
void
ConnectUser_set_portBuf(ConnectUser* cu, char* portBuf)
{
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -202,6 +215,7 @@ void
ConnectUser_set_bufList(ConnectUser* cu, BufList* bufList)
{
BufList* bftmp;
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -221,6 +235,7 @@ void
ConnectUser_set_stats(ConnectUser* cu, UserStats* stats)
{
UserStats* ustmp;
+ assert(cu != NULL);
if (cu == NULL) {
return;
}
@@ -239,6 +254,7 @@ ConnectUser_set_stats(ConnectUser* cu, UserStats* stats)
char
ConnectUser_get_state(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return S_STATE_CLEAR;
}
@@ -255,6 +271,7 @@ ConnectUser_get_state(ConnectUser* cu)
int
ConnectUser_get_connFd(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return -1;
}
@@ -271,6 +288,7 @@ ConnectUser_get_connFd(ConnectUser* cu)
int
ConnectUser_get_whatClient(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return -1;
}
@@ -287,6 +305,7 @@ ConnectUser_get_whatClient(ConnectUser* cu)
int
ConnectUser_get_userId(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return -1;
}
@@ -303,6 +322,7 @@ ConnectUser_get_userId(ConnectUser* cu)
time_t
ConnectUser_get_connectTime(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return 0;
}
@@ -319,6 +339,7 @@ ConnectUser_get_connectTime(ConnectUser* cu)
char*
ConnectUser_get_nameBuf(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return NULL;
}
@@ -335,6 +356,7 @@ ConnectUser_get_nameBuf(ConnectUser* cu)
char*
ConnectUser_get_portBuf(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return NULL;
}
@@ -351,6 +373,7 @@ ConnectUser_get_portBuf(ConnectUser* cu)
BufList*
ConnectUser_get_bufList(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return NULL;
}
@@ -367,6 +390,7 @@ ConnectUser_get_bufList(ConnectUser* cu)
UserStats*
ConnectUser_get_stats(ConnectUser* cu)
{
+ assert(cu != NULL);
if (cu == NULL) {
return NULL;
}
diff --git a/src/daemon.c b/src/daemon.c
index 7126981..0e2db7e 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -25,6 +25,18 @@
#ifndef HAVE_THIS_DAEMON
#define HAVE_THIS_DAEMON
+/*
+ * Function name: daemon
+ * Description: Enters into daemon mode. It's the emulation of the daemon
+ * function from the system.
+ * Arguments: nochdir - when 0, the directory will be changed to /, otherwise
+ * the directory will be unchanged
+ * noclose - when 0, the standard streams will be closed, otherwise
+ * the streams will be unchanged
+ * Returns: 0 - success,
+ * -1 - failure.
+ */
+
int
daemon(int nochdir, int noclose)
{
diff --git a/src/file.c b/src/file.c
index 5dca337..cdd2414 100644
--- a/src/file.c
+++ b/src/file.c
@@ -30,6 +30,17 @@
#include <limits.h>
#include <ctype.h>
+/*
+ * Function name: parse_line
+ * Description: Splits the buffer into two parts: option and value.
+ * Arguments: buff - the buffer to split
+ * tab1 - the place where option part will be stored
+ * tab2 - the place where value part will be stored
+ * Returns: 0 - the buffer was empty,
+ * 1 - the buffer contains only option name,
+ * 2 - the buffer contains only value of the option.
+ */
+
int
parse_line(char* buff, char* tab1, char* tab2)
{
diff --git a/src/file_client.c b/src/file_client.c
index fa5c0cd..c7784a6 100644
--- a/src/file_client.c
+++ b/src/file_client.c
@@ -20,15 +20,27 @@
#include <config.h>
-#include "file.h"
-#include "activefor.h"
-#include "logging.h"
-#include "network.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
+#include <assert.h>
+
+#include "file.h"
+#include "activefor.h"
+#include "logging.h"
+#include "network.h"
+
+/*
+ * Function name: cparsefile
+ * Description: Parses the client config file.
+ * Arguments: name - the name of the file with client's config
+ * status - the status returned from this function:
+ * 0 - file was parsed successfully
+ * n>0 - there was an error in the n-th line
+ * Returns: Pointer to ClientConfiguration structure.
+ */
ClientConfiguration*
cparsefile(char* name, int* status)
@@ -45,6 +57,9 @@ cparsefile(char* name, int* status)
char* tmpbuf;
unsigned char pass[4] = {1, 2, 3, 4};
+ assert(name != NULL);
+ assert(status != NULL);
+
*status = 1;
memset(buff, 0, 256);
@@ -78,10 +93,11 @@ cparsefile(char* name, int* status)
exit(1);
}
ClientRealm_set_password(ClientConfiguration_get_realmsTable(cfg)[i], pass);
+ ClientRealm_set_destinationPorts(ClientConfiguration_get_realmsTable(cfg)[i], PortList_new());
}
*status = 0;
- while (fgets(buff, 256, file) != NULL) { /* second loop - parsing file */
+ while (fgets(buff, 256, file) != NULL) { /* loop - parsing file */
(*status)++;
state = parse_line(buff, helpbuf1, helpbuf2);
if (helpbuf1[0] == '#') {
@@ -202,7 +218,8 @@ cparsefile(char* name, int* status)
ClientRealm_set_hostName(ClientConfiguration_get_realmsTable(cfg)[0], helpbuf2);
}
else if ((strcmp(helpbuf1, "p") == 0) || (strcmp(helpbuf1, "portnum") == 0)) {
- ClientRealm_set_destinationPort(ClientConfiguration_get_realmsTable(cfg)[0], helpbuf2);
+ PortList_insert_back(ClientRealm_get_destinationPorts(ClientConfiguration_get_realmsTable(cfg)[0]),
+ PortListNode_new(helpbuf2));
}
else if (strcmp(helpbuf1, "localname") == 0) {
ClientRealm_set_localName(ClientConfiguration_get_realmsTable(cfg)[0], helpbuf2);
diff --git a/src/file_server.c b/src/file_server.c
index 6f5f848..427fb1b 100644
--- a/src/file_server.c
+++ b/src/file_server.c
@@ -30,6 +30,16 @@
#include <limits.h>
#include <ctype.h>
+/*
+ * Function name: parsefile
+ * Description: Parses the server config file.
+ * Arguments: name - the name of the file with client's config
+ * status - the status returned from this function:
+ * 0 - file was parsed successfully
+ * n>0 - there was an error in the n-th line
+ * Returns: Pointer to ServerConfiguration structure.
+ */
+
ServerConfiguration*
parsefile(char* name, int* status)
{
diff --git a/src/first_run.c b/src/first_run.c
index a1ca4a0..594e869 100644
--- a/src/first_run.c
+++ b/src/first_run.c
@@ -30,6 +30,7 @@
#include <pwd.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
+#include <assert.h>
static char* home_dir = NULL;
static char* home_dir_store = NULL;
@@ -52,6 +53,12 @@ entryT entries[6] = {
{"commonName", (unsigned char*) "Jeremian <jeremian [at] poczta [dot] fm>"},
};
+/*
+ * Function name: callback
+ * Description: Prints the info about rsa key generation events.
+ * Arguments: i, j, k - described in the manual page about RSA_generate_key
+ */
+
static void
callback(int i, int j, void* k)
{
@@ -63,15 +70,15 @@ callback(int i, int j, void* k)
/*
* Function name: create_apf_dir
- * Description: creates .apf directory in ~/ or apf directory locally
+ * Description: Creates .apf directory in ~/ or apf directory locally.
* Arguments: type - type of the directory to create:
* 0 - .apf in ~/
* 1 - apf in current dir
- * Returns: 0 - success
- * 1 - problems with fetching user info
- * 2 - home directory is not set
- * 3 - calloc failure
- * 4 - directory creation failure
+ * Returns: 0 - success,
+ * 1 - problems with fetching user info,
+ * 2 - home directory is not set,
+ * 3 - calloc failure,
+ * 4 - directory creation failure.
*/
int
@@ -128,12 +135,22 @@ create_apf_dir(char type)
return 0;
}
+/*
+ * Function name: create_publickey_store
+ * Description: Creates the file to store information about public keys.
+ * Arguments: storefile - the pointer to filename
+ * Returns: 0 - success,
+ * >0 - failure.
+ */
+
int
create_publickey_store(char** storefile)
{
int store_length, home_length;
struct stat buf;
FILE* store_file;
+ assert(storefile != NULL);
+ assert((*storefile) != NULL);
/* check in local directory first */
if (stat(*storefile, &buf) == 0) {
return 0;
@@ -164,6 +181,14 @@ create_publickey_store(char** storefile)
return 2;
}
+/*
+ * Function name: generate_rsa_key
+ * Description: Generates the RSA key.
+ * Arguments: keyfile - the pointer to filename
+ * Returns: 0 - success,
+ * >0 - failure.
+ */
+
int
generate_rsa_key(char** keyfile)
{
@@ -171,6 +196,8 @@ generate_rsa_key(char** keyfile)
RSA* rsa_key;
FILE* rsa_file;
struct stat buf;
+ assert(keyfile != NULL);
+ assert((*keyfile) != NULL);
/* check in local directory first */
if (stat(*keyfile, &buf) == 0) {
return 0;
@@ -210,6 +237,15 @@ generate_rsa_key(char** keyfile)
return 0;
}
+/*
+ * Function name: generate_certificate
+ * Description: Generates X509 certificate.
+ * Arguments: cerfile - the pointer to filename
+ * keyfile - the name of the file with key
+ * Returns: 0 - success,
+ * >0 - failure.
+ */
+
int
generate_certificate(char** cerfile, char* keyfile)
{
@@ -222,6 +258,9 @@ generate_certificate(char** cerfile, char* keyfile)
EVP_PKEY* pkey;
const EVP_MD *digest;
FILE* fp;
+ assert(cerfile != NULL);
+ assert((*cerfile) != NULL);
+ assert(keyfile != NULL);
/* check in local directory first */
if (stat(*cerfile, &buf) == 0) {
return 0;
@@ -327,18 +366,36 @@ generate_certificate(char** cerfile, char* keyfile)
return 0;
}
+/*
+ * Function name: get_store_filename
+ * Description: Returns the name of the file for storing information about public keys.
+ * Returns: The name of the file for storing information about public keys.
+ */
+
char*
get_store_filename()
{
return home_dir_store;
}
+/*
+ * Function name: get_key_filename
+ * Description: Returns the name of the file with key.
+ * Returns: The name of the file with key.
+ */
+
char*
get_key_filename()
{
return home_dir_key;
}
+/*
+ * Function name: get_cer_filename
+ * Description: Returns the name of the file with certificate.
+ * Returns: The name of the file with certificate.
+ */
+
char*
get_cer_filename()
{
diff --git a/src/header_buffer_struct.c b/src/header_buffer_struct.c
index b670218..598ae20 100644
--- a/src/header_buffer_struct.c
+++ b/src/header_buffer_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "header_buffer_struct.h"
@@ -35,6 +36,7 @@ HeaderBuffer*
HeaderBuffer_new()
{
HeaderBuffer* tmp = calloc(1, sizeof(HeaderBuffer));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -50,9 +52,11 @@ HeaderBuffer_new()
void
HeaderBuffer_free(HeaderBuffer** hb)
{
+ assert(hb != NULL);
if (hb == NULL) {
return;
}
+ assert((*hb) != NULL);
if ((*hb) == NULL) {
return;
}
@@ -70,6 +74,7 @@ HeaderBuffer_free(HeaderBuffer** hb)
int
HeaderBuffer_to_read(HeaderBuffer* hb)
{
+ assert(hb != NULL);
if (hb == NULL) {
return -1;
}
@@ -87,12 +92,15 @@ HeaderBuffer_to_read(HeaderBuffer* hb)
void
HeaderBuffer_store(HeaderBuffer* hb, unsigned char* buff, int n)
{
+ assert(hb != NULL);
if (hb == NULL) {
return;
}
+ assert((hb->readed + n) <= 5);
if ((hb->readed + n) > 5) {
return;
}
+ assert(n > 0);
if (n <= 0) {
return;
}
@@ -110,6 +118,7 @@ HeaderBuffer_store(HeaderBuffer* hb, unsigned char* buff, int n)
void
HeaderBuffer_restore(HeaderBuffer* hb, unsigned char* buff)
{
+ assert(hb != NULL);
if (hb == NULL) {
return;
}
diff --git a/src/http_proxy_client.c b/src/http_proxy_client.c
index b06f523..e801a73 100644
--- a/src/http_proxy_client.c
+++ b/src/http_proxy_client.c
@@ -38,6 +38,12 @@ typedef struct {
SSL_CTX* ctx;
} proxy_argT;
+/*
+ * Function name: clean_return
+ * Description: Closes the connection and exits the thread.
+ * Arguments: sockfd - the descriptor of the connection
+ */
+
static void
clean_return(int sockfd)
{
@@ -47,6 +53,12 @@ clean_return(int sockfd)
pthread_exit(NULL);
}
+/*
+ * Function name: http_proxy_client
+ * Description: Function responsible for the client part of the http proxy connection.
+ * Arguments: vptr - the structure with all the information needed for http proxy tunnel
+ */
+
void*
http_proxy_client(void *vptr)
{
@@ -519,6 +531,16 @@ http_proxy_client(void *vptr)
clean_return(conn.sockfd);
}
+/*
+ * Function name: initialize_http_proxy_client
+ * Description: Initializes the thread responsible for http proxy connection.
+ * Arguments: sockfd - the new connection descriptor will be stored here
+ * cr - the pointer to ClientRealm structure
+ * ctx - the pointer to SSL_CTX structure
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
+
int
initialize_http_proxy_client(int* sockfd, ClientRealm* cr, SSL_CTX* ctx)
{
diff --git a/src/http_proxy_functions.c b/src/http_proxy_functions.c
index be8f402..495d7d8 100644
--- a/src/http_proxy_functions.c
+++ b/src/http_proxy_functions.c
@@ -27,6 +27,17 @@
static char isseed;
+/*
+ * Function name: myrand
+ * Description: Returns the pseudo-random number from the given range.
+ * If the lower and upper bounds are the same, the pseudo-random
+ * number is returned from the range (-RAND_MAX, -RAND_MAX+down)
+ * or (down, RAND_MAX).
+ * Arguments: down - the lower bound of the range
+ * up - the upper bound of the range
+ * Returns: The pseudo-random number from the given range.
+ */
+
int
myrand(int down, int up)
{
@@ -39,6 +50,12 @@ myrand(int down, int up)
return ( down + ( rand() % (up - down + 1) ) );
}
+/*
+ * Function name: mysleep
+ * Description: Sleeps for the given amount of milliseconds.
+ * Arguments: time - the amount of milliseconds to sleep for
+ */
+
void
mysleep(double time)
{
@@ -48,6 +65,14 @@ mysleep(double time)
select(0, NULL, NULL, NULL, &tv);
}
+/*
+ * Function name: delete_user
+ * Description: Deletes the user's connection from the http proxy connections.
+ * Arguments: cnts - the connection to remove
+ * i - the user's number
+ * allset - the set of file descriptors
+ */
+
void
delete_user(connection* cnts, int i, fd_set* allset)
{
@@ -65,6 +90,17 @@ delete_user(connection* cnts, int i, fd_set* allset)
cnts[i].type = 0;
}
+/*
+ * Function name: parse_header
+ * Description: Reads and parses the http header.
+ * Arguments: sf - the pointer to SslFd structure
+ * tab - the buffer used for reading the data
+ * hdr - the pointer to header structure
+ * https - the flag indicating if the connection is http/https
+ * Returns: 0 - success,
+ * 1 - failure.
+ */
+
int
parse_header(SslFd* sf, char* tab, header* hdr, char https)
{
@@ -187,6 +223,14 @@ parse_header(SslFd* sf, char* tab, header* hdr, char https)
return 1;
}
+/*
+ * Function name: set_fd
+ * Description: Starts watching the file descriptor.
+ * Arguments: fd - the file descriptor
+ * maxfdp1 - the upper limit of the file descriptor numbers
+ * allset - the set of file descriptors
+ */
+
void
set_fd(int fd, int* maxfdp1, fd_set* allset)
{
@@ -194,12 +238,25 @@ set_fd(int fd, int* maxfdp1, fd_set* allset)
(*maxfdp1) = ((*maxfdp1) > fd) ? (*maxfdp1) : (fd + 1);
}
+/*
+ * Function name: close_fd
+ * Description: Closes the file descriptor.
+ * Arguments: fd - the file descriptor to close
+ */
+
void
close_fd(int* fd)
{
close(*fd);
}
+/*
+ * Function name: clear_fd
+ * Description: Removes the file descriptor from the set and closes it.
+ * Arguments: fd - the file descriptor to remove and close
+ * set - the set of file descriptors
+ */
+
void
clear_fd(int* fd, fd_set* set)
{
@@ -207,6 +264,19 @@ clear_fd(int* fd, fd_set* set)
close_fd(fd);
}
+/*
+ * Function name: read_message
+ * Description: Reads the message from the http proxy connection and writes it
+ * to the file descriptor.
+ * Arguments: fd - the file descriptor
+ * length - the length of the buffer
+ * client - the http proxy connection
+ * tab - the buffer with the readed data
+ * ptr - the offset from which the data reading will start
+ * Returns: 0 - success,
+ * 1 - failure.
+ */
+
int
read_message(int fd, int length, connection* client, char* tab, int ptr)
{
diff --git a/src/http_proxy_options_struct.c b/src/http_proxy_options_struct.c
index 2d88574..96f84f8 100644
--- a/src/http_proxy_options_struct.c
+++ b/src/http_proxy_options_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "http_proxy_options_struct.h"
#include "string_functions.h"
@@ -36,6 +37,7 @@ HttpProxyOptions*
HttpProxyOptions_new()
{
HttpProxyOptions* tmp = calloc(1, sizeof(HttpProxyOptions));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -52,9 +54,11 @@ HttpProxyOptions_new()
void
HttpProxyOptions_free(HttpProxyOptions** hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
+ assert((*hpo) != NULL);
if ((*hpo) == NULL) {
return;
}
@@ -84,6 +88,7 @@ HttpProxyOptions_free(HttpProxyOptions** hpo)
void
HttpProxyOptions_set_proxyname(HttpProxyOptions* hpo, char* proxyname)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
@@ -100,6 +105,7 @@ HttpProxyOptions_set_proxyname(HttpProxyOptions* hpo, char* proxyname)
void
HttpProxyOptions_set_proxyport(HttpProxyOptions* hpo, char* proxyport)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
@@ -116,6 +122,7 @@ HttpProxyOptions_set_proxyport(HttpProxyOptions* hpo, char* proxyport)
void
HttpProxyOptions_set_proxyauth_cred(HttpProxyOptions* hpo, char* proxyauth_cred)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
@@ -132,9 +139,11 @@ HttpProxyOptions_set_proxyauth_cred(HttpProxyOptions* hpo, char* proxyauth_cred)
void
HttpProxyOptions_set_proxyauth_type(HttpProxyOptions* hpo, char proxyauth_type)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
+ assert(hpo->proxyauth_type == PROXYAUTH_TYPE_NOTSET);
if (hpo->proxyauth_type != PROXYAUTH_TYPE_NOTSET) {
hpo->proxyauth_type = PROXYAUTH_TYPE_WRONG;
return;
@@ -152,6 +161,7 @@ HttpProxyOptions_set_proxyauth_type(HttpProxyOptions* hpo, char proxyauth_type)
char*
HttpProxyOptions_get_proxyname(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return NULL;
}
@@ -168,6 +178,7 @@ HttpProxyOptions_get_proxyname(HttpProxyOptions* hpo)
char*
HttpProxyOptions_get_proxyport(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return NULL;
}
@@ -184,6 +195,7 @@ HttpProxyOptions_get_proxyport(HttpProxyOptions* hpo)
char*
HttpProxyOptions_get_proxyauth_cred(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return NULL;
}
@@ -200,6 +212,7 @@ HttpProxyOptions_get_proxyauth_cred(HttpProxyOptions* hpo)
char
HttpProxyOptions_get_proxyauth_type(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return PROXYAUTH_TYPE_WRONG;
}
@@ -215,6 +228,7 @@ HttpProxyOptions_get_proxyauth_type(HttpProxyOptions* hpo)
void
HttpProxyOptions_use_https(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return;
}
@@ -232,6 +246,7 @@ HttpProxyOptions_use_https(HttpProxyOptions* hpo)
char
HttpProxyOptions_is_https(HttpProxyOptions* hpo)
{
+ assert(hpo != NULL);
if (hpo == NULL) {
return USEHTTPS_OFF;
}
diff --git a/src/http_proxy_server.c b/src/http_proxy_server.c
index 6e41bb5..6da2c30 100644
--- a/src/http_proxy_server.c
+++ b/src/http_proxy_server.c
@@ -40,6 +40,16 @@ typedef struct {
SSL_CTX* ctx;
} sproxy_argT;
+/*
+ * Function name: afserver_connect
+ * Description: Connects new http proxy connection to the afserver.
+ * Arguments: sockfd - the file descriptor which will be used for communication with afserver
+ * afserverfd - the afserver's file descriptor
+ * cliaddr - pointer to sockaddr structure
+ * addrlenp - pointer to the length of the sockaddr structure
+ * type - the type of the connection
+ */
+
int
afserver_connect(int* sockfd, int afserverfd, struct sockaddr* cliaddr, socklen_t* addrlenp, char type)
{
@@ -54,7 +64,7 @@ afserver_connect(int* sockfd, int afserverfd, struct sockaddr* cliaddr, socklen_
return 3;
}
if (write(afserverfd, addrlenp, 4) != 4) {
- return 3;
+ return 4;
}
if (write(afserverfd, cliaddr, *addrlenp) != *addrlenp) {
return 5;
@@ -63,6 +73,12 @@ afserver_connect(int* sockfd, int afserverfd, struct sockaddr* cliaddr, socklen_
return 0;
}
+/*
+ * Function name: http_proxy_server
+ * Description: Function responsible for the server part of the http proxy connection.
+ * Arguments: vptr - the structure with all the information needed for http proxy tunnel.
+ */
+
void*
http_proxy_server(void *vptr)
{
@@ -486,6 +502,20 @@ http_proxy_server(void *vptr)
return 0;
}
+/*
+ * Function name: initialize_http_proxy_server
+ * Description: Initializes the thread responsible for http proxy connection.
+ * Arguments: sockfd - the new connection descriptor will be stored here
+ * host - the name of the host on which we will be listening on
+ * serv - the port on which we will be listening on
+ * addrlenp - pointer to the length of the sockaddr structure
+ * type - the type of the connection
+ * limit - the limit for user's connections
+ * https - if the connection should be https instead of http
+ * ctx - the pointer to SSL_CTX structure
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
int
initialize_http_proxy_server(int* sockfd, const char *host, const char *serv, socklen_t *addrlenp, const char type, int limit, char https, SSL_CTX* ctx)
diff --git a/src/logging.c b/src/logging.c
index cfe77e4..fd38431 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -31,6 +31,12 @@ static llnodeT* head = NULL;
static char verlev;
static char format[51] = "%Y-%m-%d %H:%M:%S";
+/*
+ * Function name: setdateformat
+ * Description: Sets the new date format based on the given string.
+ * Arguments: dateformat - the new date format
+ */
+
void
setdateformat(char* dateformat)
{
@@ -39,12 +45,25 @@ setdateformat(char* dateformat)
}
}
+/*
+ * Function name: getdateformat
+ * Description: Returns the date format.
+ * Returns: The date format.
+ */
+
char*
getdateformat()
{
return format;
}
+/*
+ * Function name: localdate
+ * Description: Returns the formatted date string.
+ * Arguments: sec - the date in seconds
+ * Returns: The formatted date.
+ */
+
char*
localdate(time_t* sec)
{
@@ -54,7 +73,13 @@ localdate(time_t* sec)
memset(localdat, 0, 31);
strftime(localdat, 30, format, tm);
return localdat;
-}
+}
+
+/*
+ * Function name: datum
+ * Description: Returns the formatted date string.
+ * Returns: The formatted date.
+ */
char*
datum(void)
@@ -69,12 +94,27 @@ datum(void)
return timedat;
}
+/*
+ * Function name: getloglisthead
+ * Description: Returns the head of the log targets list.
+ * Returns: The head of the log targets list.
+ */
+
llnodeT*
getloglisthead()
{
return head;
}
+/*
+ * Function name: checkmsgti
+ * Description: Adds the given msgtype/importance to the log target.
+ * Arguments: target - the log target
+ * tab - the name of the msttype/importance
+ * Returns: 0 - success,
+ * 1 - failure.
+ */
+
int
checkmsgti(llnodeT* target, char* tab)
{
@@ -123,6 +163,14 @@ checkmsgti(llnodeT* target, char* tab)
return 0;
}
+/*
+ * Function name: checklogtarget
+ * Description: Parses the command line and sets all the options.
+ * Arguments: target - the log target
+ * Returns 0 - success,
+ * !0 - failure.
+ */
+
int
checklogtarget(llnodeT* target)
{
@@ -258,6 +306,12 @@ checklogtarget(llnodeT* target)
return 0;
}
+/*
+ * Function name: addlogtarget
+ * Description: Adds the new non-initialized log target with the specified command line.
+ * Arguments: cmdline - the command line
+ */
+
void
addlogtarget(char* cmdline)
{
@@ -267,6 +321,15 @@ addlogtarget(char* cmdline)
head = newnode;
}
+/*
+ * Function name: loginit
+ * Description: Initializes the logging system.
+ * Arguments: verl - level of verbosity
+ * dateformat - date format
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
+
int
loginit(char verl, char* dateformat)
{
@@ -316,6 +379,14 @@ loginit(char verl, char* dateformat)
return 0;
}
+/*
+ * Function name: initializelogging
+ * Description: The opaque function for loginit. If the logging initialization
+ * failed, it prints the appropriate message and exits.
+ * Arguments: verl - level of verbosity
+ * dateformat - date format
+ */
+
void
initializelogging(char verl, char* dateformat)
{
@@ -357,6 +428,15 @@ initializelogging(char verl, char* dateformat)
}
}
+/*
+ * Function name: aflog
+ * Description: Logs the given message.
+ * Arguments: type - the type of the message
+ * importance - the importance of the message
+ * form - the format of the message
+ * ... - the additional arguments
+ */
+
void
aflog(char type, char importance, const char* form, ...)
{
diff --git a/src/make_ssl_handshake.c b/src/make_ssl_handshake.c
index 79e2fa5..21dbdb5 100644
--- a/src/make_ssl_handshake.c
+++ b/src/make_ssl_handshake.c
@@ -27,6 +27,12 @@
#include <errno.h>
#include <openssl/err.h>
+/*
+ * Function name: make_ssl_initialize
+ * Description: Initializes the file descriptor of the SSL connection.
+ * Arguments: sf - pointer to SslFd structure
+ */
+
void
make_ssl_initialize(SslFd* sf)
{
@@ -37,6 +43,14 @@ make_ssl_initialize(SslFd* sf)
}
}
+/*
+ * Function name: make_ssl_accept
+ * Description: Accepts new SSL connection.
+ * Arguments: sf - pointer to SslFd structure
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
+
int
make_ssl_accept(SslFd* sf)
{
@@ -47,6 +61,16 @@ make_ssl_accept(SslFd* sf)
return 0;
}
+/*
+ * Function name: get_ssl_error
+ * Description: Decodes and logs SSL errors.
+ * Arguments: sf - pointer to SslFd structure
+ * info - the header of the warning message
+ * result - the result from the SSL_accept function
+ * Returns: 1 - more i/o operations are needed to accomplish handshake,
+ * 2 - the error was fatal for the handshake.
+ */
+
int
get_ssl_error(SslFd* sf, char* info, int result)
{
diff --git a/src/module_struct.c b/src/module_struct.c
index aff8ed9..c7d8c0f 100644
--- a/src/module_struct.c
+++ b/src/module_struct.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <dlfcn.h>
+#include <assert.h>
/*
* Function name: Module_new
@@ -38,6 +39,7 @@ Module*
Module_new()
{
Module* tmp = calloc(1, sizeof(Module));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -53,9 +55,11 @@ Module_new()
void
Module_free(Module** m)
{
+ assert(m != NULL);
if (m == NULL) {
return;
}
+ assert((*m) != NULL);
if ((*m) == NULL) {
return;
}
@@ -78,6 +82,7 @@ Module_free(Module** m)
void
Module_set_fileName(Module* m, char* fileName)
{
+ assert(m != NULL);
if (m == NULL) {
return;
}
@@ -94,6 +99,7 @@ Module_set_fileName(Module* m, char* fileName)
char*
Module_get_fileName(Module* m)
{
+ assert(m != NULL);
if (m == NULL) {
return NULL;
}
@@ -160,6 +166,7 @@ Module_releaseModule(Module* m)
int
Module_isModuleLoaded(Module* m)
{
+ assert(m != NULL);
if (m == NULL) {
return 0;
}
diff --git a/src/network.c b/src/network.c
index 5a5885d..23b8ee5 100644
--- a/src/network.c
+++ b/src/network.c
@@ -28,6 +28,19 @@
#include <string.h>
#include <errno.h>
#include <zlib.h>
+#include <assert.h>
+
+/*
+ * Function name: ip_listen
+ * Description: Creates the listening socket.
+ * Arguments: sockfd - the created socket
+ * host - the name of the host
+ * serv - the name of the service (port)
+ * addrlenp - pointer to the length of the sockaddr structure
+ * type - the type of the socket
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
int
ip_listen(int* sockfd, const char *host, const char *serv, socklen_t *addrlenp, const char type)
@@ -37,6 +50,9 @@ ip_listen(int* sockfd, const char *host, const char *serv, socklen_t *addrlenp,
const int on = 1;
struct addrinfo hints, *res, *ressave;
+ aflog(LOG_T_INIT, LOG_I_DDEBUG,
+ "ip_listen: host=[%s] serv=[%s], type=[%d]", host, serv, type);
+
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
if (type & 0x02) {
@@ -92,9 +108,12 @@ ip_listen(int* sockfd, const char *host, const char *serv, socklen_t *addrlenp,
freeaddrinfo(ressave);
#else
struct sockaddr_in servaddr;
- struct hostent* hostaddr;
+ struct hostent* hostaddr = NULL;
int port;
+ aflog(LOG_T_INIT, LOG_I_DDEBUG,
+ "ip_listen: host=[%s] serv=[%s], type=[%d]", host, serv, type);
+
if (type & 0x01) {
(*sockfd) = socket(AF_INET, SOCK_STREAM, 0);
}
@@ -137,6 +156,19 @@ ip_listen(int* sockfd, const char *host, const char *serv, socklen_t *addrlenp,
return(0);
}
+/*
+ * Function name: ip_connect
+ * Description: Creates the connected socket.
+ * Arguments: sockfd - the connected socket
+ * host - the name of the host
+ * serv - the name of the service (port)
+ * type - the type of the socket
+ * lhost - the name of the local host (used for local bind of the socket)
+ * lserv - the name of the local service (port) (used for local bind of the socket)
+ * Returns: 0 - success,
+ * !0 - failure.
+ */
+
int
ip_connect(int* sockfd, const char *host, const char *serv, const char type,
const char *lhost, const char *lserv)
@@ -147,6 +179,9 @@ ip_connect(int* sockfd, const char *host, const char *serv, const char type,
struct addrinfo hints, *res, *ressave;
struct addrinfo lhints, *lres, *lressave = NULL;
+ aflog(LOG_T_INIT, LOG_I_DDEBUG,
+ "ip_connect: host=[%s] serv=[%s], type=[%d], lhost=[%s], lserv=[%s]", host, serv, type, lhost, lserv);
+
bzero(&hints, sizeof(struct addrinfo));
if (type & 0x02) {
hints.ai_family = AF_INET;
@@ -221,6 +256,9 @@ ip_connect(int* sockfd, const char *host, const char *serv, const char type,
struct hostent* hostaddr;
struct hostent* lhostaddr;
int port, lport;
+
+ aflog(LOG_T_INIT, LOG_I_DDEBUG,
+ "ip_connect: host=[%s] serv=[%s], type=[%d], lhost=[%s], lserv=[%s]", host, serv, type, lhost, lserv);
if (type & 0x01) {
(*sockfd) = socket(AF_INET, SOCK_STREAM, 0);
@@ -274,6 +312,18 @@ ip_connect(int* sockfd, const char *host, const char *serv, const char type,
return(0);
}
+/*
+ * Function name: sock_ntop
+ * Description: Returns the string representing given socket address.
+ * Arguments: sa - pointer to sockaddr structure
+ * salen - size of the sockaddr structure
+ * namebuf - buffer for string representation of the host name
+ * portbuf - buffer for string representation of the host port
+ * type - if the socket address should be resolved to the the DNS name
+ * Returns: The string representing given socket address or NULL, if the address
+ * can't be established.
+ */
+
char *
sock_ntop(const struct sockaddr *sa, socklen_t salen, char* namebuf, char* portbuf, char type)
{
@@ -291,12 +341,12 @@ sock_ntop(const struct sockaddr *sa, socklen_t salen, char* namebuf, char* portb
}
#else
struct hostent* hostname;
- if ((hostname = gethostbyaddr(&sin->sin_addr, sizeof(struct in_addr), AF_INET))) {
+ if ((hostname = gethostbyaddr((void*) &sin->sin_addr, sizeof(struct in_addr), AF_INET))) {
strncpy(str, hostname->h_name, 127);
str[127] = 0;
}
else {
- if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL) {
+ if (inet_ntop(AF_INET, (void*) &sin->sin_addr, str, sizeof(str)) == NULL) {
return NULL;
}
}
@@ -304,7 +354,7 @@ sock_ntop(const struct sockaddr *sa, socklen_t salen, char* namebuf, char* portb
}
else {
- if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) == NULL) {
+ if (inet_ntop(AF_INET, (void*) &sin->sin_addr, str, sizeof(str)) == NULL) {
return NULL;
}
}
@@ -369,13 +419,24 @@ sock_ntop(const struct sockaddr *sa, socklen_t salen, char* namebuf, char* portb
return NULL;
}
+/*
+ * Function name: SSL_writen
+ * Description: Writes the given amount of data to the SSL connection.
+ * Arguments: fd - the SSL connection
+ * buf - buffer with data to write
+ * amount - the size of the data
+ * Returns: The amount of bytes written to the SSL connection.
+ */
+
int
SSL_writen(SSL* fd, unsigned char* buf, int amount)
{
int sent, n;
sent = 0;
+ assert(amount > 0);
while (sent < amount) {
n = SSL_write(fd, buf+sent, amount - sent);
+ assert(n != 0);
if (n != -1) {
sent += n;
}
@@ -387,11 +448,21 @@ SSL_writen(SSL* fd, unsigned char* buf, int amount)
return amount;
}
+/*
+ * Function name: SSL_readn
+ * Description: Reads the given amount of data from the SSL connection.
+ * Arguments: fd - the SSL connection
+ * buf - buffer for data
+ * amount - the size of the data to read
+ * Returns: The amount of bytes read from the SSL connection.
+ */
+
int
SSL_readn(SSL* fd, unsigned char* buf, int amount)
{
int sent, n;
sent = 0;
+ assert(amount > 0);
while (sent < amount) {
n = SSL_read(fd, buf+sent, amount - sent);
if (n != -1) {
@@ -407,13 +478,24 @@ SSL_readn(SSL* fd, unsigned char* buf, int amount)
return amount;
}
+/*
+ * Function name: writen
+ * Description: Writes the given amount of data to the file descriptor.
+ * Arguments: fd - the file descriptor
+ * buf - buffer with data to write
+ * amount - the size of the data
+ * Returns: The amount of bytes written to the file descriptor
+ */
+
int
writen(int fd, unsigned char* buf, int amount)
{
int sent, n;
sent = 0;
+ assert(amount > 0);
while (sent < amount) {
n = write(fd, buf+sent, amount - sent);
+ assert(n != 0);
if (n != -1) {
sent += n;
}
@@ -425,11 +507,21 @@ writen(int fd, unsigned char* buf, int amount)
return amount;
}
+/*
+ * Function name: readn
+ * Description: Reads the given amount of data from the file descriptor.
+ * Arguments: fd - the file descriptor
+ * buf - buffer for data
+ * amount - the size of the data to read
+ * Returns: The amount of bytes read from the file descriptor.
+ */
+
int
readn(int fd, unsigned char* buf, int amount)
{
int sent, n;
sent = 0;
+ assert(amount > 0);
while (sent < amount) {
n = read(fd, buf+sent, amount - sent);
if (n != -1) {
diff --git a/src/port_list_node_struct.c b/src/port_list_node_struct.c
new file mode 100644
index 0000000..9d9f038
--- /dev/null
+++ b/src/port_list_node_struct.c
@@ -0,0 +1,140 @@
+/*
+ * active port forwarder - software for secure forwarding
+ * Copyright (C) 2003-2006 jeremian <jeremian [at] poczta.fm>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "port_list_node_struct.h"
+#include "string_functions.h"
+
+/*
+ * Function name: PortListNode_new
+ * Description: Creates and initializes new PortListNode structure from the
+ * given port name.
+ * Arguments: portName - the port name
+ * Returns: Newly created PortListNode structure.
+ */
+
+PortListNode*
+PortListNode_new(char* portName)
+{
+ PortListNode* tmp = calloc(1, sizeof(PortListNode));
+ assert(tmp != NULL);
+ if (tmp == NULL) {
+ return NULL;
+ }
+ PortListNode_set_portName(tmp, portName);
+ return tmp;
+}
+
+/*
+ * Function name: PortListNode_free
+ * Description: Frees the memory allocated for PortListNode structure.
+ * Arguments: pln - pointer to pointer to PortListNode structure
+ */
+
+void
+PortListNode_free(PortListNode** pln)
+{
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return;
+ }
+ assert((*pln) != NULL);
+ if ((*pln) == NULL) {
+ return;
+ }
+ if ((*pln)->portName) {
+ free((*pln)->portName);
+ (*pln)->portName = NULL;
+ }
+ free((*pln));
+ (*pln) = NULL;
+}
+
+/*
+ * Function name: PortListNode_set_portName
+ * Description: Sets the port name.
+ * Arguments: pln - pointer to PortListNode structure
+ * portName - the port name
+ */
+
+void
+PortListNode_set_portName(PortListNode* pln, char* portName)
+{
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return;
+ }
+ string_cp(&(pln->portName), portName);
+}
+
+/*
+ * Function name: PortListNode_set_nextNode
+ * Description: Sets next node pointer.
+ * Arguments: pln - pointer to PortListNode structure
+ * nextNode - next node pointer
+ */
+
+void
+PortListNode_set_nextNode(PortListNode* pln, PortListNode* nextNode)
+{
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return;
+ }
+ pln->nextNode = nextNode;
+}
+
+/*
+ * Function name: PortListNode_get_portName
+ * Description: Gets the port name.
+ * Arguments: pln - pointer to PortListNode structure
+ * Returns: The port name.
+ */
+
+char*
+PortListNode_get_portName(PortListNode* pln)
+{
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return NULL;
+ }
+ return pln->portName;
+}
+
+/*
+ * Function name: PortListNode_get_nextNode
+ * Description: Gets next node pointer.
+ * Arguments: pln - pointer to PortListNode structure
+ * Returns: Next PortListNode structure pointer or NULL, if there is no next one.
+ */
+
+PortListNode*
+PortListNode_get_nextNode(PortListNode* pln)
+{
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return NULL;
+ }
+ return pln->nextNode;
+}
diff --git a/src/port_list_node_struct.h b/src/port_list_node_struct.h
new file mode 100644
index 0000000..5099c84
--- /dev/null
+++ b/src/port_list_node_struct.h
@@ -0,0 +1,40 @@
+/*
+ * active port forwarder - software for secure forwarding
+ * Copyright (C) 2003-2006 jeremian <jeremian [at] poczta.fm>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _JS_PORT_LIST_NODE_STRUCT_H
+#define _JS_PORT_LIST_NODE_STRUCT_H
+
+typedef struct plnode {
+ char* portName;
+ struct plnode* nextNode;
+} PortListNode;
+
+/* 'constructor' */
+PortListNode* PortListNode_new(char* portName);
+/* 'destructor' */
+void PortListNode_free(PortListNode** pln);
+/* setters */
+void PortListNode_set_portName(PortListNode* pln, char* portName);
+void PortListNode_set_nextNode(PortListNode* pln, PortListNode* nextNode);
+/* getters */
+char* PortListNode_get_portName(PortListNode* pln);
+PortListNode* PortListNode_get_nextNode(PortListNode* pln);
+
+#endif
diff --git a/src/port_list_struct.c b/src/port_list_struct.c
new file mode 100644
index 0000000..4e10761
--- /dev/null
+++ b/src/port_list_struct.c
@@ -0,0 +1,167 @@
+/*
+ * active port forwarder - software for secure forwarding
+ * Copyright (C) 2003-2006 jeremian <jeremian [at] poczta.fm>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "port_list_struct.h"
+
+/*
+ * Function name: PortList_new
+ * Description: Creates and initialies new PortList structure.
+ * Returns: Newly created PortList structure.
+ */
+
+PortList*
+PortList_new()
+{
+ PortList* tmp = calloc(1, sizeof(PortList));
+ assert(tmp != NULL);
+ if (tmp == NULL) {
+ return NULL;
+ }
+ return tmp;
+}
+
+/*
+ * Function name: PortList_free
+ * Description: Frees the memory allocated for PortList structure.
+ * Arguments: pl - pointer to pointer to PortList structure
+ */
+
+void
+PortList_free(PortList** pl)
+{
+ assert(pl != NULL);
+ if (pl == NULL) {
+ return;
+ }
+ assert((*pl) != NULL);
+ if ((*pl) == NULL) {
+ return;
+ }
+ PortList_clear((*pl));
+ free((*pl));
+ (*pl) = NULL;
+}
+
+/*
+ * Function name: PortList_insert_back
+ * Description: Inserts new node at the end of the list.
+ * Arguments: pl - pointer to PortList structure
+ * pln - pointer to PortListNode structure
+ */
+
+void
+PortList_insert_back(PortList* pl, PortListNode* pln)
+{
+ assert(pl != NULL);
+ if (pl == NULL) {
+ return;
+ }
+ assert(pln != NULL);
+ if (pln == NULL) {
+ return;
+ }
+ if (pl->tail) {
+ pl->tail->nextNode = pln;
+ }
+ else {
+ pl->head = pln;
+ }
+ pl->tail = pln;
+ pln->nextNode = NULL;
+ pl->size += 1;
+}
+
+/*
+ * Function name: PortList_get_nth
+ * Description: Get the nth node from the beginning of the list.
+ * Arguments: pl - pointer to PortList structure
+ * n - the number of the node
+ * Returns: Nth node from the beginning of the list.
+ */
+
+PortListNode*
+PortList_get_nth(PortList* pl, int n)
+{
+ PortListNode* tmp;
+ assert(pl != NULL);
+ if (pl == NULL) {
+ return NULL;
+ }
+ assert(n >= 0);
+ assert(n < PortList_get_size(pl));
+ tmp = pl->head;
+ while (tmp) {
+ if (n <= 0) {
+ return tmp;
+ }
+ n -= 1;
+ tmp = PortListNode_get_nextNode(tmp);
+ }
+ return NULL;
+}
+
+/*
+ * Function name: PortList_get_size
+ * Description: Returns the size of the list.
+ * Arguments: pl - pointer to PortList structure
+ * Returns: The size of the list.
+ */
+
+int
+PortList_get_size(PortList* pl)
+{
+ assert(pl != NULL);
+ if (pl == NULL) {
+ return -1;
+ }
+ return pl->size;
+}
+
+/*
+ * Function name: PortList_clear
+ * Description: Deletes all nodes from the list.
+ * Arguments: pl - pointer to PortList structure
+ */
+
+void
+PortList_clear(PortList* pl)
+{
+ PortListNode* tmp;
+ assert(pl != NULL);
+ if (pl == NULL) {
+ return;
+ }
+ while (pl->head) {
+ tmp = pl->head;
+ if (tmp == pl->tail) {
+ pl->head = pl->tail = NULL;
+ }
+ else {
+ pl->head = PortListNode_get_nextNode(pl->head);
+ }
+ PortListNode_free(&tmp);
+ }
+ pl->size = 0;
+}
diff --git a/src/port_list_struct.h b/src/port_list_struct.h
new file mode 100644
index 0000000..4a46f10
--- /dev/null
+++ b/src/port_list_struct.h
@@ -0,0 +1,42 @@
+/*
+ * active port forwarder - software for secure forwarding
+ * Copyright (C) 2003-2006 jeremian <jeremian [at] poczta.fm>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _JS_PORT_LIST_STRUCT_H
+#define _JS_PORT_LIST_STRUCT_H
+
+#include "port_list_node_struct.h"
+
+typedef struct portlist {
+ int size;
+ PortListNode* head;
+ PortListNode* tail;
+} PortList;
+
+/* 'constructor' */
+PortList* PortList_new();
+/* 'destructor' */
+void PortList_free(PortList** pl);
+/* other */
+void PortList_insert_back(PortList* pl, PortListNode* pln);
+PortListNode* PortList_get_nth(PortList* pl, int n);
+int PortList_get_size(PortList* pl);
+void PortList_clear(PortList* pl);
+
+#endif
diff --git a/src/realmnames.c b/src/realmnames.c
index cbc38b2..0b920dd 100644
--- a/src/realmnames.c
+++ b/src/realmnames.c
@@ -22,12 +22,23 @@
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "realmnames.h"
+/*
+ * Function name: get_realmname
+ * Description: Returns the name of the realm.
+ * Arguments: config - the server configuration
+ * realm - the realm number
+ * Returns: The name of the realm.
+ */
+
char*
get_realmname(ServerConfiguration* config, int realm)
{
static char realmname[10];
+
+ assert(config != NULL);
if (ServerRealm_get_realmName(ServerConfiguration_get_realmsTable(config)[realm]) == NULL) {
memset(realmname, 0, 10);
@@ -38,12 +49,23 @@ get_realmname(ServerConfiguration* config, int realm)
return ServerRealm_get_realmName(ServerConfiguration_get_realmsTable(config)[realm]);
}
+/*
+ * Function name: get_realmnumber
+ * Description: Returns the realm number.
+ * Arguments: config - the server configuration
+ * realmname - the name of the realm
+ * Returns: The realm number or -1, if there is no realm with such name.
+ */
+
int
get_realmnumber(ServerConfiguration* config, char* realmname)
{
int i;
char guard;
+ assert(config != NULL);
+ assert(realmname != NULL);
+
for (i = 0; i < ServerConfiguration_get_realmsNumber(config); ++i) {
if (ServerRealm_get_realmName(ServerConfiguration_get_realmsTable(config)[i]) != NULL) {
if (strcmp(realmname, ServerRealm_get_realmName(ServerConfiguration_get_realmsTable(config)[i])) == 0) {
diff --git a/src/server_check.c b/src/server_check.c
index 7e2b015..9df5ac8 100644
--- a/src/server_check.c
+++ b/src/server_check.c
@@ -23,15 +23,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
+#include <assert.h>
#include "server_check.h"
#include "stats.h"
#include "logging.h"
+/*
+ * Function name: check_value
+ * Description: Checks if the string is a valid positive int number.
+ * Arguments: what - the string representing number
+ * info - the information string printed on failure
+ * Returns: The decoded int number.
+ */
+
int
check_value(char* what, char* info)
{
long tmp;
+
+ assert(what != NULL);
+ assert(info != NULL);
+
tmp = check_value_liberal(what, info);
if (tmp <= 0) {
@@ -42,11 +55,22 @@ check_value(char* what, char* info)
return tmp;
}
+/*
+ * Function name: check_value_liberal
+ * Description: Checks if the string is a valid int number.
+ * Arguments: what - the string representing number
+ * info - the information string printed on failure
+ * Returns: The decoded int number.
+ */
+
int
check_value_liberal(char* what, char* info)
{
char* znak;
long tmp;
+
+ assert(what != NULL);
+ assert(info != NULL);
if ((tmp = strtol(what, &znak, 10)) >= INT_MAX) {
aflog(LOG_T_INIT, LOG_I_CRIT,
@@ -61,6 +85,16 @@ check_value_liberal(char* what, char* info)
return tmp;
}
+/*
+ * Function name: check_long
+ * Description: Checks if the string is a valid long number.
+ * Arguments: text - the string representing number
+ * number - the pointer where decoded number will be stored
+ * Returns: 0 - success,
+ * 1 - value from outside the long number range,
+ * 2 - not the valid long number.
+ */
+
int
check_long(char* text, long* number)
{
diff --git a/src/server_configuration_struct.c b/src/server_configuration_struct.c
index d3f9eaf..e5bd9f3 100644
--- a/src/server_configuration_struct.c
+++ b/src/server_configuration_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "string_functions.h"
#include "server_configuration_struct.h"
@@ -36,6 +37,7 @@ ServerConfiguration*
ServerConfiguration_new()
{
ServerConfiguration* tmp = calloc(1, sizeof(ServerConfiguration));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -52,9 +54,11 @@ void
ServerConfiguration_free(ServerConfiguration** sc)
{
int i;
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
+ assert((*sc) != NULL);
if ((*sc) == NULL) {
return;
}
@@ -93,6 +97,7 @@ ServerConfiguration_free(ServerConfiguration** sc)
void
ServerConfiguration_set_certificateFile(ServerConfiguration* sc, char* certificateFile)
{
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -109,6 +114,7 @@ ServerConfiguration_set_certificateFile(ServerConfiguration* sc, char* certifica
void
ServerConfiguration_set_keysFile(ServerConfiguration* sc, char* keysFile)
{
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -125,6 +131,7 @@ ServerConfiguration_set_keysFile(ServerConfiguration* sc, char* keysFile)
void
ServerConfiguration_set_dateFormat(ServerConfiguration* sc, char* dateFormat)
{
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -141,6 +148,7 @@ ServerConfiguration_set_dateFormat(ServerConfiguration* sc, char* dateFormat)
void
ServerConfiguration_set_realmsNumber(ServerConfiguration* sc, int realmsNumber)
{
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -157,6 +165,7 @@ ServerConfiguration_set_realmsNumber(ServerConfiguration* sc, int realmsNumber)
void
ServerConfiguration_set_startTime(ServerConfiguration* sc, time_t startTime)
{
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -174,6 +183,7 @@ void
ServerConfiguration_set_realmsTable(ServerConfiguration* sc, ServerRealm** realmsTable)
{
int i;
+ assert(sc != NULL);
if (sc == NULL) {
return;
}
@@ -199,6 +209,7 @@ ServerConfiguration_set_realmsTable(ServerConfiguration* sc, ServerRealm** realm
char*
ServerConfiguration_get_certificateFile(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return NULL;
}
@@ -215,6 +226,7 @@ ServerConfiguration_get_certificateFile(ServerConfiguration* sc)
char*
ServerConfiguration_get_keysFile(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return NULL;
}
@@ -231,6 +243,7 @@ ServerConfiguration_get_keysFile(ServerConfiguration* sc)
char*
ServerConfiguration_get_dateFormat(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return NULL;
}
@@ -247,6 +260,7 @@ ServerConfiguration_get_dateFormat(ServerConfiguration* sc)
int
ServerConfiguration_get_realmsNumber(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return -1;
}
@@ -263,6 +277,7 @@ ServerConfiguration_get_realmsNumber(ServerConfiguration* sc)
time_t
ServerConfiguration_get_startTime(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return 0;
}
@@ -279,6 +294,7 @@ ServerConfiguration_get_startTime(ServerConfiguration* sc)
ServerRealm**
ServerConfiguration_get_realmsTable(ServerConfiguration* sc)
{
+ assert(sc != NULL);
if (sc == NULL) {
return NULL;
}
diff --git a/src/server_eval.c b/src/server_eval.c
index ef31c8d..a676d3d 100644
--- a/src/server_eval.c
+++ b/src/server_eval.c
@@ -19,12 +19,24 @@
*/
#include <config.h>
+#include <assert.h>
+#include <string.h>
#include "server_eval.h"
+/*
+ * Function name: eval_numofcon
+ * Description: Returns the real connection number on the afserver.
+ * Arguments: ptr - the server realm
+ * client - client number
+ * numofcon - the connection number on the afclient
+ * Returns: The real connection number on the afserver.
+ */
+
int
eval_numofcon(ServerRealm* ptr, int client, int numofcon)
{
+ assert(ptr != NULL);
if ((numofcon >= 0) && (numofcon < ConnectClient_get_limit(ServerRealm_get_clientsTable(ptr)[client]))) {
numofcon = ConnectClient_get_users(ServerRealm_get_clientsTable(ptr)[client])[numofcon];
}
@@ -34,13 +46,78 @@ eval_numofcon(ServerRealm* ptr, int client, int numofcon)
return numofcon;
}
+/*
+ * Function name: eval_usernum
+ * Description: Returns the user number in the connected client on the afserver side.
+ * Arguments: ptr - the connected client
+ * usernum - the connection number on the afserver
+ * Returns: The user number in the connected client on the afserver side.
+ */
+
int
eval_usernum(ConnectClient* ptr, int usernum)
{
int i;
+ assert(ptr != NULL);
for (i = 0; i < ConnectClient_get_limit(ptr); ++i) {
if (ConnectClient_get_users(ptr)[i] == usernum)
return i;
}
return -1;
}
+
+/*
+ * Function name: eval_UsrCliPair
+ * Description: Returns how many UsrCli structures are connected with the current manage port.
+ * Arguments: table - the table of UsrCli structures
+ * index - the current index of the evaluation
+ * host - the name of the host
+ * serv - the name of the service (port)
+ * Returns: How many UsrCli structures are connected with the current manage port.
+ */
+
+int
+eval_UsrCliPair(UsrCli** table, int index, char* host, char* serv)
+{
+ int i;
+ int result = 0;
+ assert(table != NULL);
+ assert(index >= 0);
+ for (i = 0; i < index; ++i) {
+
+ if (UsrCli_get_manageHostName(table[i])) {
+ if (host) {
+ if (strcmp(UsrCli_get_listenHostName(table[i]), host)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
+ }
+ else {
+ if (host) {
+ continue;
+ }
+ }
+
+ if (UsrCli_get_managePortName(table[i])) {
+ if (serv) {
+ if (strcmp(UsrCli_get_managePortName(table[i]), serv)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
+ }
+ else {
+ if (serv) {
+ continue;
+ }
+ }
+
+ result++;
+ }
+ return result;
+}
diff --git a/src/server_eval.h b/src/server_eval.h
index b372108..f144395 100644
--- a/src/server_eval.h
+++ b/src/server_eval.h
@@ -26,6 +26,7 @@
int eval_numofcon(ServerRealm*, int, int);
int eval_usernum(ConnectClient*, int);
+int eval_UsrCliPair(UsrCli**, int, char*, char*);
#endif
diff --git a/src/server_find.c b/src/server_find.c
index 50593a6..e0d86ac 100644
--- a/src/server_find.c
+++ b/src/server_find.c
@@ -19,13 +19,25 @@
*/
#include <config.h>
+#include <assert.h>
+#include <string.h>
#include "server_find.h"
+/*
+ * Function name: find_client
+ * Description: Returns the client number with free user slots.
+ * Arguments: ptr - the server realm
+ * mode - the strategy of client choosing
+ * usrclipair - the number of usrclipair
+ * Returns: The client number with free user slots.
+ */
+
int
find_client(ServerRealm* ptr, char mode, int usrclipair)
{
int i;
+ assert(ptr != NULL);
switch(mode) {
case 1: { /* fill first client before go to next */
for (i = 0; i < ServerRealm_get_clientsLimit(ptr); ++i) {
@@ -47,10 +59,19 @@ find_client(ServerRealm* ptr, char mode, int usrclipair)
return 0;
}
+/*
+ * Function name: find_usernum
+ * Description: Finds the free user slot, fill it and returns its number.
+ * Arguments: ptr - the connected client
+ * usernum - the connection number on the afserver
+ * Returns: The user number in the connected client on the afserver side.
+ */
+
int
find_usernum(ConnectClient* ptr, int usernum)
{
int i;
+ assert(ptr != NULL);
for (i = 0; i < ConnectClient_get_limit(ptr); ++i) {
if (ConnectClient_get_users(ptr)[i] == -1) {
ConnectClient_get_users(ptr)[i] = usernum;
@@ -59,3 +80,59 @@ find_usernum(ConnectClient* ptr, int usernum)
}
return -1;
}
+
+/*
+ * Function name: find_previousFd
+ * Description: Finds the file descriptor bound previously to the given
+ * host:serv.
+ * Arguments: table - the table of UsrCli structures
+ * index - the current index of the search
+ * host - the name of the host
+ * serv - the name of the service (port)
+ * Returns: The previously bound file descriptor.
+ */
+
+int
+find_previousFd(UsrCli** table, int index, char* host, char* serv)
+{
+ int i;
+ assert(table != NULL);
+ assert(index >= 0);
+ for (i = 0; i < index; ++i) {
+
+ if (UsrCli_get_manageHostName(table[i])) {
+ if (host) {
+ if (strcmp(UsrCli_get_listenHostName(table[i]), host)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
+ }
+ else {
+ if (host) {
+ continue;
+ }
+ }
+
+ if (UsrCli_get_managePortName(table[i])) {
+ if (serv) {
+ if (strcmp(UsrCli_get_managePortName(table[i]), serv)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
+ }
+ else {
+ if (serv) {
+ continue;
+ }
+ }
+
+ return UsrCli_get_manageFd(table[i]);
+ }
+ return -1;
+}
diff --git a/src/server_find.h b/src/server_find.h
index 4367119..406601a 100644
--- a/src/server_find.h
+++ b/src/server_find.h
@@ -26,6 +26,7 @@
int find_client(ServerRealm*, char, int);
int find_usernum(ConnectClient*, int);
+int find_previousFd(UsrCli**, int, char*, char*);
#endif
diff --git a/src/server_get.c b/src/server_get.c
index e8b052b..b09cab0 100644
--- a/src/server_get.c
+++ b/src/server_get.c
@@ -23,12 +23,29 @@
#include "server_get.h"
#include <stdlib.h>
#include <errno.h>
+#include <assert.h>
+
+/*
+ * Function name: get_new_socket
+ * Description: Returns new accepted socket.
+ * Arguments: sockfd - the file descriptor of the listening socket
+ * type - the type of the listening socket
+ * addr - pointer to sockaddr structure
+ * addrlen - pointer to the length of the sockaddr structure
+ * tunneltype - the type of the connection
+ * Returns: The new accepted socket.
+ */
int
get_new_socket(int sockfd, char type, struct sockaddr *addr, socklen_t *addrlen, char* tunneltype)
{
int tmp;
int n, i;
+
+ assert(addr != NULL);
+ assert(addrlen != NULL);
+ assert(tunneltype != NULL);
+
switch (type) {
case 0: {
return accept(sockfd, addr, addrlen);
diff --git a/src/server_realm_struct.c b/src/server_realm_struct.c
index ee3773d..f3f06c0 100644
--- a/src/server_realm_struct.c
+++ b/src/server_realm_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "string_functions.h"
#include "server_realm_struct.h"
@@ -36,6 +37,7 @@ ServerRealm*
ServerRealm_new()
{
ServerRealm* tmp = calloc(1, sizeof(ServerRealm));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -56,9 +58,11 @@ void
ServerRealm_free(ServerRealm** sr)
{
int i;
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
+ assert((*sr) != NULL);
if ((*sr) == NULL) {
return;
}
@@ -148,6 +152,7 @@ ServerRealm_free(ServerRealm** sr)
void
ServerRealm_set_hostName(ServerRealm* sr, char* hostName)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -164,6 +169,7 @@ ServerRealm_set_hostName(ServerRealm* sr, char* hostName)
void
ServerRealm_set_sUsersLimit(ServerRealm* sr, char* sUsersLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -180,6 +186,7 @@ ServerRealm_set_sUsersLimit(ServerRealm* sr, char* sUsersLimit)
void
ServerRealm_set_sClientsLimit(ServerRealm* sr, char* sClientsLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -196,6 +203,7 @@ ServerRealm_set_sClientsLimit(ServerRealm* sr, char* sClientsLimit)
void
ServerRealm_set_sRaClientsLimit(ServerRealm* sr, char* sRaClientsLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -212,6 +220,7 @@ ServerRealm_set_sRaClientsLimit(ServerRealm* sr, char* sRaClientsLimit)
void
ServerRealm_set_sUsersPerClient(ServerRealm* sr, char* sUsersPerClient)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -228,6 +237,7 @@ ServerRealm_set_sUsersPerClient(ServerRealm* sr, char* sUsersPerClient)
void
ServerRealm_set_sClientMode(ServerRealm* sr, char* sClientMode)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -244,6 +254,7 @@ ServerRealm_set_sClientMode(ServerRealm* sr, char* sClientMode)
void
ServerRealm_set_sTimeout(ServerRealm* sr, char* sTimeout)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -260,6 +271,7 @@ ServerRealm_set_sTimeout(ServerRealm* sr, char* sTimeout)
void
ServerRealm_set_realmName(ServerRealm* sr, char* realmName)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -276,6 +288,7 @@ ServerRealm_set_realmName(ServerRealm* sr, char* realmName)
void
ServerRealm_set_password(ServerRealm* sr, unsigned char* password)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -292,6 +305,7 @@ ServerRealm_set_password(ServerRealm* sr, unsigned char* password)
void
ServerRealm_set_connectedUsers(ServerRealm* sr, int connectedUsers)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -308,6 +322,7 @@ ServerRealm_set_connectedUsers(ServerRealm* sr, int connectedUsers)
void
ServerRealm_set_usersLimit(ServerRealm* sr, int usersLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -324,6 +339,7 @@ ServerRealm_set_usersLimit(ServerRealm* sr, int usersLimit)
void
ServerRealm_set_connectedClients(ServerRealm* sr, int connectedClients)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -340,6 +356,7 @@ ServerRealm_set_connectedClients(ServerRealm* sr, int connectedClients)
void
ServerRealm_set_clientsLimit(ServerRealm* sr, int clientsLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -356,6 +373,7 @@ ServerRealm_set_clientsLimit(ServerRealm* sr, int clientsLimit)
void
ServerRealm_set_connectedRaClients(ServerRealm* sr, int connectedRaClients)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -372,6 +390,7 @@ ServerRealm_set_connectedRaClients(ServerRealm* sr, int connectedRaClients)
void
ServerRealm_set_raClientsLimit(ServerRealm* sr, int raClientsLimit)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -388,6 +407,7 @@ ServerRealm_set_raClientsLimit(ServerRealm* sr, int raClientsLimit)
void
ServerRealm_set_usersPerClient(ServerRealm* sr, int usersPerClient)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -404,6 +424,7 @@ ServerRealm_set_usersPerClient(ServerRealm* sr, int usersPerClient)
void
ServerRealm_set_timeout(ServerRealm* sr, int timeout)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -420,6 +441,7 @@ ServerRealm_set_timeout(ServerRealm* sr, int timeout)
void
ServerRealm_set_clientMode(ServerRealm* sr, int clientMode)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -436,6 +458,7 @@ ServerRealm_set_clientMode(ServerRealm* sr, int clientMode)
void
ServerRealm_set_userClientPairs(ServerRealm* sr, int userClientPairs)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -452,6 +475,7 @@ ServerRealm_set_userClientPairs(ServerRealm* sr, int userClientPairs)
void
ServerRealm_set_clientsCounter(ServerRealm* sr, int clientsCounter)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -468,6 +492,7 @@ ServerRealm_set_clientsCounter(ServerRealm* sr, int clientsCounter)
void
ServerRealm_set_usersCounter(ServerRealm* sr, int usersCounter)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -484,6 +509,7 @@ ServerRealm_set_usersCounter(ServerRealm* sr, int usersCounter)
void
ServerRealm_set_realmType(ServerRealm* sr, char realmType)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -500,6 +526,7 @@ ServerRealm_set_realmType(ServerRealm* sr, char realmType)
void
ServerRealm_set_tunnelType(ServerRealm* sr, char tunnelType)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -516,6 +543,7 @@ ServerRealm_set_tunnelType(ServerRealm* sr, char tunnelType)
void
ServerRealm_set_dnsLookupsOn(ServerRealm* sr, char dnsLookupsOn)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -532,6 +560,7 @@ ServerRealm_set_dnsLookupsOn(ServerRealm* sr, char dnsLookupsOn)
void
ServerRealm_set_basePortOn(ServerRealm* sr, char basePortOn)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -548,6 +577,7 @@ ServerRealm_set_basePortOn(ServerRealm* sr, char basePortOn)
void
ServerRealm_set_auditOn(ServerRealm* sr, char auditOn)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -564,6 +594,7 @@ ServerRealm_set_auditOn(ServerRealm* sr, char auditOn)
void
ServerRealm_set_addressLength(ServerRealm* sr, socklen_t addressLength)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -580,6 +611,7 @@ ServerRealm_set_addressLength(ServerRealm* sr, socklen_t addressLength)
void
ServerRealm_set_clientAddress(ServerRealm* sr, struct sockaddr* clientAddress)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -601,6 +633,7 @@ void
ServerRealm_set_usersTable(ServerRealm* sr, ConnectUser** usersTable)
{
int i;
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -627,6 +660,7 @@ void
ServerRealm_set_clientsTable(ServerRealm* sr, ConnectClient** clientsTable)
{
int i;
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -653,6 +687,7 @@ void
ServerRealm_set_raClientsTable(ServerRealm* sr, ConnectClient** raClientsTable)
{
int i;
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -679,6 +714,7 @@ void
ServerRealm_set_usersClientsTable(ServerRealm* sr, UsrCli** usersClientsTable)
{
int i;
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -704,6 +740,7 @@ ServerRealm_set_usersClientsTable(ServerRealm* sr, UsrCli** usersClientsTable)
char*
ServerRealm_get_hostName(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -720,6 +757,7 @@ ServerRealm_get_hostName(ServerRealm* sr)
char*
ServerRealm_get_sUsersLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -736,6 +774,7 @@ ServerRealm_get_sUsersLimit(ServerRealm* sr)
char*
ServerRealm_get_sClientsLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -752,6 +791,7 @@ ServerRealm_get_sClientsLimit(ServerRealm* sr)
char*
ServerRealm_get_sRaClientsLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -768,6 +808,7 @@ ServerRealm_get_sRaClientsLimit(ServerRealm* sr)
char*
ServerRealm_get_sUsersPerClient(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -784,6 +825,7 @@ ServerRealm_get_sUsersPerClient(ServerRealm* sr)
char*
ServerRealm_get_sClientMode(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -800,6 +842,7 @@ ServerRealm_get_sClientMode(ServerRealm* sr)
char*
ServerRealm_get_sTimeout(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -816,6 +859,7 @@ ServerRealm_get_sTimeout(ServerRealm* sr)
char*
ServerRealm_get_realmName(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -832,6 +876,7 @@ ServerRealm_get_realmName(ServerRealm* sr)
unsigned char*
ServerRealm_get_password(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -848,6 +893,7 @@ ServerRealm_get_password(ServerRealm* sr)
int
ServerRealm_get_connectedUsers(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -864,6 +910,7 @@ ServerRealm_get_connectedUsers(ServerRealm* sr)
int
ServerRealm_get_usersLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -880,6 +927,7 @@ ServerRealm_get_usersLimit(ServerRealm* sr)
int
ServerRealm_get_connectedClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -896,6 +944,7 @@ ServerRealm_get_connectedClients(ServerRealm* sr)
int
ServerRealm_get_clientsLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -912,6 +961,7 @@ ServerRealm_get_clientsLimit(ServerRealm* sr)
int
ServerRealm_get_connectedRaClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -928,6 +978,7 @@ ServerRealm_get_connectedRaClients(ServerRealm* sr)
int
ServerRealm_get_raClientsLimit(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -944,6 +995,7 @@ ServerRealm_get_raClientsLimit(ServerRealm* sr)
int
ServerRealm_get_usersPerClient(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -960,6 +1012,7 @@ ServerRealm_get_usersPerClient(ServerRealm* sr)
int
ServerRealm_get_timeout(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -976,6 +1029,7 @@ ServerRealm_get_timeout(ServerRealm* sr)
int
ServerRealm_get_clientMode(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -992,6 +1046,7 @@ ServerRealm_get_clientMode(ServerRealm* sr)
int
ServerRealm_get_userClientPairs(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1008,6 +1063,7 @@ ServerRealm_get_userClientPairs(ServerRealm* sr)
int
ServerRealm_get_clientsCounter(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -1024,6 +1080,7 @@ ServerRealm_get_clientsCounter(ServerRealm* sr)
int
ServerRealm_get_usersCounter(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return -1;
}
@@ -1040,6 +1097,7 @@ ServerRealm_get_usersCounter(ServerRealm* sr)
char
ServerRealm_get_realmType(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1056,6 +1114,7 @@ ServerRealm_get_realmType(ServerRealm* sr)
char
ServerRealm_get_tunnelType(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1072,6 +1131,7 @@ ServerRealm_get_tunnelType(ServerRealm* sr)
char
ServerRealm_get_dnsLookupsOn(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1088,6 +1148,7 @@ ServerRealm_get_dnsLookupsOn(ServerRealm* sr)
char
ServerRealm_get_basePortOn(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1104,6 +1165,7 @@ ServerRealm_get_basePortOn(ServerRealm* sr)
char
ServerRealm_get_auditOn(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1120,6 +1182,7 @@ ServerRealm_get_auditOn(ServerRealm* sr)
socklen_t
ServerRealm_get_addressLength(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return 0;
}
@@ -1136,6 +1199,7 @@ ServerRealm_get_addressLength(ServerRealm* sr)
struct sockaddr*
ServerRealm_get_clientAddress(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -1152,6 +1216,7 @@ ServerRealm_get_clientAddress(ServerRealm* sr)
ConnectUser**
ServerRealm_get_usersTable(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -1168,6 +1233,7 @@ ServerRealm_get_usersTable(ServerRealm* sr)
ConnectClient**
ServerRealm_get_clientsTable(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -1184,6 +1250,7 @@ ServerRealm_get_clientsTable(ServerRealm* sr)
ConnectClient**
ServerRealm_get_raClientsTable(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -1200,6 +1267,7 @@ ServerRealm_get_raClientsTable(ServerRealm* sr)
UsrCli**
ServerRealm_get_usersClientsTable(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return NULL;
}
@@ -1215,6 +1283,7 @@ ServerRealm_get_usersClientsTable(ServerRealm* sr)
void
ServerRealm_increase_connectedUsers(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1230,6 +1299,7 @@ ServerRealm_increase_connectedUsers(ServerRealm* sr)
void
ServerRealm_decrease_connectedUsers(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1245,6 +1315,7 @@ ServerRealm_decrease_connectedUsers(ServerRealm* sr)
void
ServerRealm_increase_connectedClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1260,6 +1331,7 @@ ServerRealm_increase_connectedClients(ServerRealm* sr)
void
ServerRealm_decrease_connectedClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1275,6 +1347,7 @@ ServerRealm_decrease_connectedClients(ServerRealm* sr)
void
ServerRealm_increase_connectedRaClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1290,6 +1363,7 @@ ServerRealm_increase_connectedRaClients(ServerRealm* sr)
void
ServerRealm_decrease_connectedRaClients(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1305,6 +1379,7 @@ ServerRealm_decrease_connectedRaClients(ServerRealm* sr)
void
ServerRealm_increase_usersCounter(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
@@ -1320,6 +1395,7 @@ ServerRealm_increase_usersCounter(ServerRealm* sr)
void
ServerRealm_increase_clientsCounter(ServerRealm* sr)
{
+ assert(sr != NULL);
if (sr == NULL) {
return;
}
diff --git a/src/server_remoteadmin.c b/src/server_remoteadmin.c
index 2dabc2d..6c2a4a3 100644
--- a/src/server_remoteadmin.c
+++ b/src/server_remoteadmin.c
@@ -19,6 +19,7 @@
*/
#include <config.h>
+#include <assert.h>
#include "server_remoteadmin.h"
@@ -30,7 +31,7 @@ static char newmessage;
* parse pointer.
* Arguments: buff - string to parse
* ret - buffer's parse pointer
- * Returns: Parsed integer value or -1, if something goes wrong.
+ * Returns: Parsed integer value or -1, if something went wrong.
*/
static int
@@ -38,6 +39,10 @@ parse_int(unsigned char* buff, int* ret)
{
int intarg, i;
char guard;
+
+ assert(buff != NULL);
+ assert(ret != NULL);
+
if (((i = sscanf((char*) &buff[*ret], "%d%c", &intarg, &guard)) == 2) || (i == 1)) {
if (i == 1) {
guard = ' ';
@@ -71,11 +76,23 @@ parse_int(unsigned char* buff, int* ret)
}
}
+/*
+ * Function name: parse_cmd
+ * Description: This function parses the string as a command and updates the buffer's
+ * parse pointer.
+ * Arguments: buff - string to parse
+ * ret - buffer's parse pointer
+ * Returns: Parsed command number or 0, if something went wrong.
+ */
+
static int
parse_cmd(unsigned char* buff, int* ret)
{
int i, j, state;
char cmd[31];
+
+ assert(buff != NULL);
+ assert(ret != NULL);
i = j = state = 0;
newmessage = 1;
@@ -128,10 +145,23 @@ parse_cmd(unsigned char* buff, int* ret)
return 0;
}
+/*
+ * Function name: send_adm_message
+ * Description: Sends the message via the network.
+ * Arguments: type - the type of the connection
+ * master - pointer to SslFd structure
+ * buff - the message to send
+ * st - the result of the command
+ */
+
static void
send_adm_message(char type, SslFd* master, unsigned char* buff, unsigned char st)
{
int n;
+
+ assert(master != NULL);
+ assert(buff != NULL);
+
if (!newmessage) {
n = strlen((char*) &buff[5]);
}
@@ -146,11 +176,23 @@ send_adm_message(char type, SslFd* master, unsigned char* buff, unsigned char st
SslFd_send_message(type, master, buff, n+5);
}
+/*
+ * Function name: add_to_message
+ * Description: Adds text to the message.
+ * Arguments: buff - the message we are adding text to
+ * format - the format of the text
+ * ... - additional arguments
+ */
+
static void
add_to_message(unsigned char* buff, const char* format, ...)
{
va_list ap;
int n;
+
+ assert(buff != NULL);
+ assert(format != NULL);
+
if (!newmessage) {
n = strlen((char*) &buff[5]);
}
@@ -167,11 +209,22 @@ add_to_message(unsigned char* buff, const char* format, ...)
va_end(ap);
}
+/*
+ * Function name: add_uptime_to_message
+ * Description: Adds the formatted time period to the message.
+ * Arguments: buff - the message we are adding formatted time period to
+ * info - the info which will be added to the message just before the time
+ * period - the time period we are adding to the message
+ */
+
static void
add_uptime_to_message(unsigned char* buff, char* info, time_t period)
{
int hours, minutes, seconds;
+ assert(buff != NULL);
+ assert(info != NULL);
+
hours = period/3600;
minutes = (period/60)%60;
seconds = period%60;
@@ -184,6 +237,18 @@ add_uptime_to_message(unsigned char* buff, char* info, time_t period)
}
}
+/*
+ * Function name: serve_admin
+ * Description: Function responsible for the reaction for user's admin commands.
+ * Arguments: config - the server configuration
+ * realm - the realm number
+ * client - the client number
+ * buff - buffer containing the user's command
+ * Returns: 0 - do nothing,
+ * 1 - kick this client,
+ * >1 - kick the specified client.
+ */
+
int
serve_admin(ServerConfiguration* config, int realm, int client, unsigned char* buff)
{
@@ -197,6 +262,9 @@ serve_admin(ServerConfiguration* config, int realm, int client, unsigned char* b
ServerRealm* pointer = ServerConfiguration_get_realmsTable(config)[realm];
char type = ServerRealm_get_realmType(pointer) | TYPE_SSL | TYPE_ZLIB;
SslFd* master = ConnectClient_get_sslFd(ServerRealm_get_raClientsTable(pointer)[client]);
+
+ assert(config != NULL);
+ assert(buff != NULL);
olddf[50] = newdf[50] = 0;
length = buff[3];
diff --git a/src/server_remove.c b/src/server_remove.c
index 9a226bc..8a66813 100644
--- a/src/server_remove.c
+++ b/src/server_remove.c
@@ -18,12 +18,31 @@
*
*/
+#include <assert.h>
+
#include "server_remove.h"
+/*
+ * Function name: remove_client
+ * Description: Removes the client.
+ * Arguments: ptr - the server realm
+ * client - the client number
+ * set - the set of file descriptors for reading
+ * wset - the set of file descriptors for writing
+ * con - the connection counter
+ */
+
void
remove_client(ServerRealm* ptr, int client, fd_set* set, fd_set* wset, int* con)
{
int i;
+
+ assert(ptr != NULL);
+ assert(client >= 0);
+ assert(set != NULL);
+ assert(wset != NULL);
+ assert(con != NULL);
+
if (ConnectClient_get_state(ServerRealm_get_clientsTable(ptr)[client]) == CONNECTCLIENT_STATE_ACCEPTED) {
for (i = 0; i < ServerRealm_get_usersLimit(ptr); ++i) {
if (ConnectUser_get_whatClient(ServerRealm_get_usersTable(ptr)[i]) == client) {
@@ -56,10 +75,27 @@ remove_client(ServerRealm* ptr, int client, fd_set* set, fd_set* wset, int* con)
ServerRealm_decrease_connectedClients(ptr);
}
+/*
+ * Function name: remove_raclient
+ * Description: Removes the remote admin client.
+ * Arguments: ptr - the server realm
+ * client - the client number
+ * set - the set of file descriptors for reading
+ * wset - the set of file descriptors for writing
+ * con - the connection counter
+ */
+
void
remove_raclient(ServerRealm* ptr, int client, fd_set* set, fd_set* wset, int* con)
{
int i;
+
+ assert(ptr != NULL);
+ assert(client >= 0);
+ assert(set != NULL);
+ assert(wset != NULL);
+ assert(con != NULL);
+
for (i = 0; i < ConnectClient_get_limit(ServerRealm_get_raClientsTable(ptr)[client]); ++i) {
ConnectClient_get_users(ServerRealm_get_raClientsTable(ptr)[client])[i] = -1;
}
diff --git a/src/server_set.c b/src/server_set.c
index 9b04f33..0e9252e 100644
--- a/src/server_set.c
+++ b/src/server_set.c
@@ -19,12 +19,24 @@
*/
#include <stdlib.h>
+#include <assert.h>
#include "string_functions.h"
+/*
+ * Function name: set_value
+ * Description: If the variable has no value, set it from the given string.
+ * If the given string is NULL, use default value.
+ * Arguments: dest - the destination variable
+ * from - the given string
+ * def - the default value
+ */
+
void
set_value(char** dest, char* from, char* def)
{
+ assert(dest != NULL);
+
if ((*dest) == NULL) {
if (from != NULL) {
string_cp(dest, from);
diff --git a/src/server_signals.c b/src/server_signals.c
index 456bbe5..74ab3c4 100644
--- a/src/server_signals.c
+++ b/src/server_signals.c
@@ -30,7 +30,13 @@
extern ServerConfiguration* config;
- void
+/*
+ * Function name: server_sig_int
+ * Description: Function responsible for handling SIG_INT.
+ * Arguments: signo - the signal number
+ */
+
+void
server_sig_int(int signo)
{
int i, j;
diff --git a/src/ssl_fd_struct.c b/src/ssl_fd_struct.c
index 301602f..6522491 100644
--- a/src/ssl_fd_struct.c
+++ b/src/ssl_fd_struct.c
@@ -19,12 +19,13 @@
*/
#include <config.h>
+#include <zlib.h>
+#include <assert.h>
#include "activefor.h"
#include "stats.h"
#include "logging.h"
#include "ssl_fd_struct.h"
-#include <zlib.h>
/*
* Function name: SslFd_new
@@ -36,6 +37,7 @@ SslFd*
SslFd_new()
{
SslFd* tmp = calloc(1, sizeof(SslFd));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -51,9 +53,11 @@ SslFd_new()
void
SslFd_free(SslFd** sf)
{
+ assert(sf != NULL);
if (sf == NULL) {
return;
}
+ assert((*sf) != NULL);
if ((*sf) == NULL) {
return;
}
@@ -75,6 +79,7 @@ SslFd_free(SslFd** sf)
void
SslFd_set_fd(SslFd* sf, int fd)
{
+ assert(sf != NULL);
if (sf == NULL) {
return;
}
@@ -92,6 +97,7 @@ SslFd_set_fd(SslFd* sf, int fd)
void
SslFd_set_ssl_general(SslFd* sf, SSL* ssl, int free)
{
+ assert(sf != NULL);
if (sf == NULL) {
return;
}
@@ -138,6 +144,7 @@ SslFd_set_ssl_nf(SslFd* sf, SSL* ssl)
int
SslFd_get_fd(SslFd* sf)
{
+ assert(sf != NULL);
if (sf == NULL) {
return -1;
}
@@ -154,6 +161,7 @@ SslFd_get_fd(SslFd* sf)
SSL*
SslFd_get_ssl(SslFd* sf)
{
+ assert(sf != NULL);
if (sf == NULL) {
return NULL;
}
@@ -179,6 +187,9 @@ SslFd_send_message(char type, SslFd* sf, unsigned char* buf, int amount)
int length;
static unsigned char buffer[9000];
+ assert(sf != NULL);
+ assert(buf != NULL);
+
if ((sf == NULL) || (buf == NULL)) {
return -1;
}
@@ -246,6 +257,10 @@ SslFd_get_message(char type, SslFd* sf, unsigned char* buf, int amount)
int length;
unsigned long elen;
static unsigned char bufor[9000];
+
+ assert(sf != NULL);
+ assert(buf != NULL);
+
if ((sf == NULL) || (buf == NULL)) {
return -1;
}
@@ -301,6 +316,9 @@ SslFd_swap_content(SslFd* sf1, SslFd* sf2)
{
int tmpfd;
SSL* tmpssl;
+
+ assert(sf1 != NULL);
+ assert(sf2 != NULL);
tmpfd = SslFd_get_fd(sf1);
tmpssl = SslFd_get_ssl(sf2);
diff --git a/src/ssl_routines.c b/src/ssl_routines.c
index 30a0714..ae20fe2 100644
--- a/src/ssl_routines.c
+++ b/src/ssl_routines.c
@@ -19,11 +19,21 @@
*/
#include <config.h>
-
-#include "ssl_routines.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
+
+#include "ssl_routines.h"
+
+/*
+ * Function name: check_public_key
+ * Description: Checks if the public key is trusted.
+ * Arguments: filename - the name of the file with stored keys
+ * hostname - the name of the host
+ * keyhash - the hash of the key
+ * Returns: The result of the check.
+ */
int
check_public_key(char* filename, char* hostname, char* keyhash)
@@ -32,6 +42,10 @@ check_public_key(char* filename, char* hostname, char* keyhash)
char buff[256];
int lspaceind, i;
+ assert(filename != NULL);
+ assert(hostname != NULL);
+ assert(keyhash != NULL);
+
memset(buff, 0, 256);
storefile = fopen(filename, "r");
@@ -68,10 +82,23 @@ check_public_key(char* filename, char* hostname, char* keyhash)
return SSL_PUBLIC_KEY_NOT_KNOWN;
}
+/*
+ * Function name: add_public_key
+ * Description: Adds the key to the store file.
+ * Arguments: filename - the name of the file with stored keys
+ * hostname - the name of the host
+ * keyhash - the hash of the key
+ */
+
void
add_public_key(char* filename, char* hostname, char* keyhash)
{
FILE* storefile;
+
+ assert(filename != NULL);
+ assert(hostname != NULL);
+ assert(keyhash != NULL);
+
storefile = fopen(filename, "a");
if (storefile == NULL) {
return;
diff --git a/src/stats.c b/src/stats.c
index 67d369b..152eccd 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -24,6 +24,13 @@
static signed long compressgained;
+/*
+ * Function name: timeperiod
+ * Description: Returns the formatted time period string.
+ * Arguments: period - the time period
+ * Returns: The formatted time period string.
+ */
+
char*
timeperiod(time_t period)
{
@@ -44,18 +51,35 @@ timeperiod(time_t period)
return timeper;
}
+/*
+ * Function name: addtocg
+ * Description: Adds the given number to the bytes gained by the use of compression.
+ * Arguments: amount - the number to add
+ */
+
void
addtocg(int amount)
{
compressgained += amount;
}
+/*
+ * Function name: getcg
+ * Description: Returns the number of bytes gained by the use of compression.
+ * Returns: The number of bytes gained by the use of compression.
+ */
+
signed long
getcg(void)
{
return compressgained;
}
+/*
+ * Function name: resetcg
+ * Description: Resets the counter of bytes gained by the use of compression.
+ */
+
void
resetcg(void)
{
diff --git a/src/string_functions.c b/src/string_functions.c
index 705e1a9..17a58a2 100644
--- a/src/string_functions.c
+++ b/src/string_functions.c
@@ -19,7 +19,6 @@
*/
#include <config.h>
-
#include <stdlib.h>
#include <string.h>
@@ -30,10 +29,11 @@
* Description: Firstly, the memory allocated for *dest is released. After this, new memory is allocated
* and string from src is copied to newly created location. *dest is pointing to new string.
* Arguments: dest - pointer to pointer to string previously allocated by malloc family functions.
- * If dest is NULL, memory will be allocated and returned from the function. In latter
- * case dest will be unchanged
+ * If dest is NULL, memory will be allocated and returned from the function. In the
+ * latter case dest will be unchanged
* src - string containing data for copying. If src is NULL, new memory is not allocated, but
* the old one is still released.
+ * Returns: The newly allocated string.
*/
char*
@@ -41,7 +41,7 @@ string_cp(char** dest, char* src)
{
char* tmp;
int len = 0;
-
+
/* 1. releasing memory allocated by *dest */
if (dest != NULL) {
if ((*dest) != NULL) {
diff --git a/src/thread_management.c b/src/thread_management.c
index 12b406a..f3812e9 100644
--- a/src/thread_management.c
+++ b/src/thread_management.c
@@ -28,12 +28,24 @@ static pthread_t mainthread;
static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
+/*
+ * Function name: remember_mainthread
+ * Description: Remembers the current thread as a main thread.
+ */
+
void
remember_mainthread(void)
{
mainthread = pthread_self();
}
+/*
+ * Function name: is_this_a_mainthread
+ * Description: Checks, if the current thread is a main thread.
+ * Returns: 0 - this is not a main thread,
+ * 1 - this is a main thread.
+ */
+
int
is_this_a_mainthread(void)
{
@@ -43,24 +55,44 @@ is_this_a_mainthread(void)
return 0;
}
+/*
+ * Function name: start_critical_section
+ * Description: Starts the critical section of the code by locking the mutex.
+ */
+
void
start_critical_section(void)
{
pthread_mutex_lock( &mainmutex);
}
+/*
+ * Function name: end_critical_section
+ * Description: Ends the critical section of the code by unlocking the mutex.
+ */
+
void
end_critical_section(void)
{
pthread_mutex_unlock( &mainmutex);
}
+/*
+ * Function name: wait_for_condition
+ * Description: Starts waiting for the condition.
+ */
+
void
wait_for_condition(void)
{
pthread_cond_wait(&maincond, &mainmutex);
}
+/*
+ * Function name: broadcast_condition
+ * Description: Broadcast the met of the condition.
+ */
+
void
broadcast_condition(void)
{
diff --git a/src/usage.c b/src/usage.c
index 900495a..2241228 100644
--- a/src/usage.c
+++ b/src/usage.c
@@ -19,25 +19,39 @@
*/
#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
#include "usage.h"
#include "network.h"
-#include <stdio.h>
-#include <stdlib.h>
+/*
+ * Function name: server_short_usage
+ * Description: Prints the short usage of the afserver.
+ * Arguments: info - the text printed in the first line
+ */
- void
+void
server_short_usage(char* info)
{
+ assert(info != NULL);
printf("\n%s\n\n\n", info);
printf("Try `afserver --help' for more information.\n");
exit(1);
}
- void
+/*
+ * Function name: server_long_usage
+ * Description: Prints the long usage of the afserver.
+ * Arguments: info - the text printed in the first line
+ */
+
+void
server_long_usage(char* info)
{
+ assert(info != NULL);
printf("\n%s\n\n\n", info);
printf(" Basic options:\n\n");
printf(" -n, --hostname - it's used when creating listening sockets\n");
@@ -103,18 +117,32 @@ server_long_usage(char* info)
exit(0);
}
- void
+/*
+ * Function name: client_short_usage
+ * Description: Prints the short usage of the afclient.
+ * Arguments: info - the text printed in the first line
+ */
+
+void
client_short_usage(char* info)
{
+ assert(info != NULL);
printf("\n%s\n\n\n", info);
printf("Try `afclient --help' for more information.\n");
exit(1);
}
+/*
+ * Function name: client_long_usage
+ * Description: Prints the long usage of the afclient.
+ * Arguments: info - the text printed in the first line
+ */
+
void
client_long_usage(char* info)
{
+ assert(info != NULL);
printf("\n%s\n\n\n", info);
printf(" Basic options:\n\n");
printf(" -n, --servername - where the second part of the active\n");
diff --git a/src/user_stats_struct.c b/src/user_stats_struct.c
index 33cc8b3..df7ea9a 100644
--- a/src/user_stats_struct.c
+++ b/src/user_stats_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <time.h>
+#include <assert.h>
#include "user_stats_struct.h"
@@ -35,6 +36,7 @@ UserStats*
UserStats_new()
{
UserStats* tmp = calloc(1, sizeof(UserStats));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -50,9 +52,11 @@ UserStats_new()
void
UserStats_free(UserStats** us)
{
+ assert(us != NULL);
if (us == NULL) {
return;
}
+ assert((*us) != NULL);
if ((*us) == NULL) {
return;
}
@@ -70,6 +74,7 @@ UserStats_free(UserStats** us)
void
UserStats_set_lastActivity(UserStats* us, time_t lastActivity)
{
+ assert(us != NULL);
if (us == NULL) {
return;
}
@@ -86,6 +91,7 @@ UserStats_set_lastActivity(UserStats* us, time_t lastActivity)
void
UserStats_set_totalDownloadedBytes(UserStats* us, int totalDownloadedBytes)
{
+ assert(us != NULL);
if (us == NULL) {
return;
}
@@ -102,6 +108,7 @@ UserStats_set_totalDownloadedBytes(UserStats* us, int totalDownloadedBytes)
void
UserStats_set_totalUploadedBytes(UserStats* us, int totalUploadedBytes)
{
+ assert(us != NULL);
if (us == NULL) {
return;
}
@@ -118,6 +125,7 @@ UserStats_set_totalUploadedBytes(UserStats* us, int totalUploadedBytes)
time_t
UserStats_get_lastActivity(UserStats* us)
{
+ assert(us != NULL);
if (us == NULL) {
return 0;
}
@@ -134,6 +142,7 @@ UserStats_get_lastActivity(UserStats* us)
int
UserStats_get_totalDownloadedBytes(UserStats* us)
{
+ assert(us != NULL);
if (us == NULL) {
return 0;
}
@@ -150,6 +159,7 @@ UserStats_get_totalDownloadedBytes(UserStats* us)
int
UserStats_get_totalUploadedBytes(UserStats* us)
{
+ assert(us != NULL);
if (us == NULL) {
return 0;
}
@@ -168,6 +178,9 @@ void
UserStats_add_download(UserStats* us, int bytes)
{
time_t now;
+
+ assert(us != NULL);
+
if (us == NULL) {
return;
}
@@ -218,6 +231,9 @@ void
UserStats_add_upload(UserStats* us, int bytes)
{
time_t now;
+
+ assert(us != NULL);
+
if (us == NULL) {
return;
}
@@ -267,6 +283,9 @@ double
UserStats_get_downloadSpeed(UserStats* us)
{
time_t now;
+
+ assert(us != NULL);
+
if (us == NULL) {
return 0.0;
}
@@ -311,6 +330,9 @@ double
UserStats_get_uploadSpeed(UserStats* us)
{
time_t now;
+
+ assert(us != NULL);
+
if (us == NULL) {
return 0.0;
}
@@ -353,6 +375,7 @@ UserStats_get_uploadSpeed(UserStats* us)
void
UserStats_clear(UserStats* us)
{
+ assert(us != NULL);
if (us == NULL) {
return;
}
diff --git a/src/usernames.c b/src/usernames.c
index 792a1d1..656074a 100644
--- a/src/usernames.c
+++ b/src/usernames.c
@@ -19,20 +19,40 @@
*/
#include <config.h>
+#include <assert.h>
#include "usernames.h"
+/*
+ * Function name: get_username
+ * Description: Returns the id of the user.
+ * Arguments: pointer - the server realm
+ * user - the number of the user
+ * Returns: The id of the user.
+ */
+
int
get_username(ServerRealm* pointer, int user)
{
+ assert(pointer != NULL);
return ConnectUser_get_userId(ServerRealm_get_usersTable(pointer)[user]);
}
+/*
+ * Function name: get_usernumber
+ * Description: Returns the number of the user.
+ * Arguments: pointer - the server realm
+ * user - the id of the user
+ * Returns: The number of the user.
+ */
+
int
get_usernumber(ServerRealm* pointer, int userid)
{
int i;
+ assert(pointer != NULL);
+
for (i = 0; i < ServerRealm_get_usersLimit(pointer); ++i) {
if (userid == ConnectUser_get_userId(ServerRealm_get_usersTable(pointer)[i])) {
return i;
diff --git a/src/usr_cli_struct.c b/src/usr_cli_struct.c
index c4d351e..805fc27 100644
--- a/src/usr_cli_struct.c
+++ b/src/usr_cli_struct.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "usr_cli_struct.h"
#include "string_functions.h"
@@ -36,6 +37,7 @@ UsrCli*
UsrCli_new()
{
UsrCli* tmp = calloc(1, sizeof(UsrCli));
+ assert(tmp != NULL);
if (tmp == NULL) {
return NULL;
}
@@ -51,9 +53,11 @@ UsrCli_new()
void
UsrCli_free(UsrCli** uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return;
}
+ assert((*uc) != NULL);
if ((*uc) == NULL) {
return;
}
@@ -79,6 +83,9 @@ void
UsrCli_set_listenPortName(UsrCli* uc, char* listenPortName)
{
char* tmp;
+
+ assert(uc != NULL);
+
if (uc == NULL) {
return;
}
@@ -104,6 +111,9 @@ void
UsrCli_set_managePortName(UsrCli* uc, char* managePortName)
{
char* tmp;
+
+ assert(uc != NULL);
+
if (uc == NULL) {
return;
}
@@ -128,6 +138,7 @@ UsrCli_set_managePortName(UsrCli* uc, char* managePortName)
void
UsrCli_set_listenFd(UsrCli* uc, int listenFd)
{
+ assert(uc != NULL);
if (uc == NULL) {
return;
}
@@ -144,12 +155,31 @@ UsrCli_set_listenFd(UsrCli* uc, int listenFd)
void
UsrCli_set_manageFd(UsrCli* uc, int manageFd)
{
+ assert(uc != NULL);
if (uc == NULL) {
return;
}
uc->manageFd = manageFd;
}
+/*
+ * Function name: UsrCli_set_number
+ * Description: Sets the UsrCli number in the structures connected with manage port.
+ * Arguments: uc - pointer to UsrCli structure
+ * number - the number of the UsrCli structure
+ */
+
+void
+UsrCli_set_number(UsrCli* uc, int number)
+{
+ assert(uc != NULL);
+ assert(number >= 0);
+ if (uc == NULL) {
+ return;
+ }
+ uc->number = number;
+}
+
/* Function name: UsrCli_get_listenPortName
* Description: Get listen port name.
* Arguments: uc - pointer to UsrCli structure
@@ -159,6 +189,7 @@ UsrCli_set_manageFd(UsrCli* uc, int manageFd)
char*
UsrCli_get_listenPortName(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return NULL;
}
@@ -175,6 +206,7 @@ UsrCli_get_listenPortName(UsrCli* uc)
char*
UsrCli_get_managePortName(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return NULL;
}
@@ -191,6 +223,7 @@ UsrCli_get_managePortName(UsrCli* uc)
int
UsrCli_get_listenFd(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return -1;
}
@@ -207,6 +240,7 @@ UsrCli_get_listenFd(UsrCli* uc)
int
UsrCli_get_manageFd(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return -1;
}
@@ -223,6 +257,7 @@ UsrCli_get_manageFd(UsrCli* uc)
char*
UsrCli_get_listenHostName(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return NULL;
}
@@ -239,8 +274,26 @@ UsrCli_get_listenHostName(UsrCli* uc)
char*
UsrCli_get_manageHostName(UsrCli* uc)
{
+ assert(uc != NULL);
if (uc == NULL) {
return NULL;
}
return uc->manageHostName;
}
+
+/*
+ * Function name: UsrCli_get_number
+ * Description: Gets the number of the UsrCli structure.
+ * Arguments: uc - pointer to UsrCli structure
+ * Returns: The number of the UsrCli structure.
+ */
+
+int
+UsrCli_get_number(UsrCli* uc)
+{
+ assert(uc != NULL);
+ if (uc == NULL) {
+ return -1;
+ }
+ return uc->number;
+}
diff --git a/src/usr_cli_struct.h b/src/usr_cli_struct.h
index c406026..06bf55c 100644
--- a/src/usr_cli_struct.h
+++ b/src/usr_cli_struct.h
@@ -29,6 +29,7 @@ typedef struct {
char* managePortName;
int listenFd;
int manageFd;
+ int number;
} UsrCli;
/* 'constructor' */
@@ -40,6 +41,7 @@ void UsrCli_set_listenPortName(UsrCli* uc, char* listenPortName);
void UsrCli_set_managePortName(UsrCli* uc, char* managePortName);
void UsrCli_set_listenFd(UsrCli* uc, int listenFd);
void UsrCli_set_manageFd(UsrCli* uc, int manageFd);
+void UsrCli_set_number(UsrCli* uc, int number);
/* getters */
char* UsrCli_get_listenPortName(UsrCli* uc);
char* UsrCli_get_managePortName(UsrCli* uc);
@@ -47,5 +49,6 @@ int UsrCli_get_listenFd(UsrCli* uc);
int UsrCli_get_manageFd(UsrCli* uc);
char* UsrCli_get_listenHostName(UsrCli* uc);
char* UsrCli_get_manageHostName(UsrCli* uc);
+int UsrCli_get_number(UsrCli* uc);
#endif