Prechádzať zdrojové kódy

- merged from stable (rel0_8_11):
- kill_all_children (fixes 'we kill our launching script bug ')
- debian updates
- tm & sl destroy when not init fixes
- ver no. updated

Andrei Pelinescu-Onciul 22 rokov pred
rodič
commit
b484b77497

+ 1 - 2
Makefile.defs

@@ -26,7 +26,6 @@
 #  2003-06-06  moved compiler detection before DEFS (andrei)
 #  2003-06-06  moved compiler detection before DEFS (andrei)
 #  2003-06-10  removed -m32 for gcc 3.x/sparc64  -- it will use 
 #  2003-06-10  removed -m32 for gcc 3.x/sparc64  -- it will use 
 #              arch. default: -m32 on solaris, -m64 on *bsd (andrei)
 #              arch. default: -m32 on solaris, -m64 on *bsd (andrei)
-#  2003-06-29  added TLS support: TLS=1 (andrei)
 
 
 
 
 # check if already included/exported
 # check if already included/exported
@@ -41,7 +40,7 @@ export makefile_defs
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   12
 SUBLEVEL =   12
-EXTRAVERSION = dev-tls01
+EXTRAVERSION = dev-t02
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 0 - 6
debian/README.Debian

@@ -1,6 +0,0 @@
-ser for Debian
---------------------
-
- - experimental version (under construction)
-
- -- Andrei Pelinescu-Onciul <[email protected]>, Tue, 16 Jul 2002 15:41:31 +0200

+ 9 - 0
debian/changelog

@@ -1,3 +1,12 @@
+ser (0.8.11-pre34) unstable; urgency=low
+
+  * minor bugfixes
+
+  * debian packaging changes (debhelper 4.0, init & postinst cleanups, added
+    examples, a.s.o)
+
+ -- Andrei Pelinescu-Onciul <[email protected]>  Fri, 27 Jun 2003 15:14:52 +0200
+
 ser (0.8.11-pre30) unstable; urgency=low
 ser (0.8.11-pre30) unstable; urgency=low
 
 
   * minor bugfixes
   * minor bugfixes

+ 1 - 0
debian/compat

@@ -0,0 +1 @@
+4

+ 0 - 2
debian/conffiles

@@ -1,2 +0,0 @@
-/etc/ser/ser.cfg
-/etc/init.d/ser

+ 3 - 3
debian/control

@@ -2,14 +2,14 @@ Source: ser
 Section: net
 Section: net
 Priority: optional
 Priority: optional
 Maintainer: Andrei Pelinescu-Onciul <[email protected]>
 Maintainer: Andrei Pelinescu-Onciul <[email protected]>
-Build-Depends: debhelper (>> 3.0.0), libmysqlclient-dev, libexpat1-dev, zlib1g-dev, libradius1-dev
+Build-Depends: debhelper (>= 4), libmysqlclient-dev, libexpat1-dev, zlib1g-dev, libradius1-dev
 Standards-Version: 3.5.2
 Standards-Version: 3.5.2
 
 
 Package: ser
 Package: ser
 Architecture: any
 Architecture: any
-Depends: ${shlibs:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
 Suggests: ser-mysql-module, ser-jabber-module
 Suggests: ser-mysql-module, ser-jabber-module
-Conflicts: ser-mysql-module (< ${Source-Version}), ser-jabber-module (< ${Source-Version}), ser-radius-modules (< ${Source-Version})
+Conflicts: ser-mysql-module (<< ${Source-Version}), ser-jabber-module (<< ${Source-Version}), ser-radius-modules (<< ${Source-Version})
 Description: Sip Express Router, very fast and configurable SIP proxy
 Description: Sip Express Router, very fast and configurable SIP proxy
  ser or SIP Express Router is a very fast and flexible SIP (RFC3621)
  ser or SIP Express Router is a very fast and flexible SIP (RFC3621)
  proxy server. Written entirely in C, ser can handle thousands calls
  proxy server. Written entirely in C, ser can handle thousands calls

+ 9 - 4
debian/copyright

@@ -1,13 +1,18 @@
-This package was debianized by Andrei Pelinescu-Onciul <[email protected]> on
-Tue, 16 Jul 2002 15:41:31 +0200.
+This package was debianized by Andrei Pelinescu-Onciul
+<[email protected]> on Tue, 16 Jul 2002 15:41:31 +0200.
 
 
 It was downloaded from http://iptel.org/ser.
 It was downloaded from http://iptel.org/ser.
 
 
-Upstream Authors: Andrei Pelinescu - Onciul <[email protected]>, Bogdan Iancu <[email protected]>, Daniel-Constantin Mierla, Jan Janak <[email protected]>, Jiri Kuthan <[email protected]>, Nils Ohlmeier, Ricardo Baratto, Stelios Sidiroglou-Douskos 
+Upstream Authors: Andrei Pelinescu-Onciul
+<[email protected]>, Bogdan Iancu
+<[email protected]>, Daniel-Constantin Mierla, Jan Janak
+<[email protected]>, Jiri Kuthan <[email protected]>, Nils Ohlmeier, Ricardo
+Baratto, Stelios Sidiroglou-Douskos  (see AUTHORS file for details)
 
 
 This software is copyright (c) 2002-2003 by Fhg Fokus
 This software is copyright (c) 2002-2003 by Fhg Fokus
 
 
 You are free to distribute this software under the terms of
 You are free to distribute this software under the terms of
 the GNU General Public License.
 the GNU General Public License.
+
 On Debian systems, the complete text of the GNU General Public
 On Debian systems, the complete text of the GNU General Public
-License can be found in the file `/usr/share/common-licenses/GPL´.
+License can be found in the file `/usr/share/common-licenses/GPL.

+ 0 - 2
debian/dirs

@@ -1,2 +0,0 @@
-usr/bin
-usr/sbin

+ 0 - 2
debian/docs

@@ -1,2 +0,0 @@
-README
-TODO

+ 0 - 2
debian/files

@@ -1,2 +0,0 @@
-ser_0.8.7.16_i386.deb net optional
-ser-mysql-module_0.8.7.16_i386.deb net optional

+ 29 - 6
debian/postinst

@@ -26,7 +26,9 @@ set -e
 
 
 case "$1" in
 case "$1" in
     configure)
     configure)
-        adduser --system --group --home /var/run/ser ser
+        adduser --quiet --system --group --disabled-password \
+                --shell /bin/false --gecos "SIP Express Router" \
+                --home /var/run/ser ser || true
 
 
     ;;
     ;;
 
 
@@ -42,12 +44,33 @@ esac
 
 
 # # dh_installdeb will replace this with shell code automatically
 # # dh_installdeb will replace this with shell code automatically
 # # generated by other debhelper scripts.
 # # generated by other debhelper scripts.
+# deb_helper is not used here to avoid automatically starting ser after
+# the installation (dh_installinit 4.0 , from woody does not support
+# --nostart, if you're using a newer version is safe to comment out the 
+# rest of the code and add again deb_helper)
 
 
-# #DEBHELPER#
-echo ""
-echo "Next install any additional ser modules and then (re)start ser"
-echo "by executing command '/etc/init.d/ser start|restart'."
-
+# this will be added automatically by dh_installdocs if deb_helper is 
+# "enabled"
+if [ "$1" = "configure" ]; then
+	if [ -d /usr/doc -a ! -e /usr/doc/ser -a -d /usr/share/doc/ser ]; then
+		ln -sf ../share/doc/ser /usr/doc/ser
+	fi
+fi
+# end dh_installdocs section
+# this will be automativally added by dh_installinit if deb_helper is
+# "enabled
+if [ -x "/etc/init.d/ser" ]; then
+	 update-rc.d ser defaults 23 >/dev/null
+	 if ! invoke-rc.d ser restart ; then
+		echo ""
+		echo "ser failed to (re)start. Perhaps your configuration requires "
+		echo "additional modules (e.g. ser-mysql-module, ser-jabber-module "
+		echo "or ser-radius-modules). Next try to install any additional ser"
+		echo "modules you might need and then (re)start ser by executing "
+		echo "the command '/etc/init.d/ser start|restart'."
+	fi
+fi
+# end dh_installinit section
 
 
 exit 0
 exit 0
 
 

+ 8 - 0
debian/postrm

@@ -29,9 +29,17 @@ case "$1" in
 
 
 esac
 esac
 
 
+
 # dh_installdeb will replace this with shell code automatically
 # dh_installdeb will replace this with shell code automatically
 # generated by other debhelper scripts.
 # generated by other debhelper scripts.
 
 
 #DEBHELPER#
 #DEBHELPER#
 
 
+if [ "$1" = "purge" ] ; then
+# remove user/group on purge
+	deluser --quiet --remove-home ser &>/dev/null || true
+# remove /etc/ser if empty
+	rmdir /etc/ser || true
+fi
+
 exit 0
 exit 0

+ 8 - 3
debian/rules

@@ -8,13 +8,18 @@
 # --------
 # --------
 #  2003-05-30  updated for the 0.8.11 release, changed modules list and
 #  2003-05-30  updated for the 0.8.11 release, changed modules list and
 #              some ser make options (andrei)
 #              some ser make options (andrei)
+#  2003-06-27  changed to DH_COMPAT 4 (debian/compat) + other filenames
+#              & small fixes (andrei)
 
 
 
 
 # Uncomment this to turn on verbose mode.
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 #export DH_VERBOSE=1
 
 
 # This is the debhelper compatibility version to use.
 # This is the debhelper compatibility version to use.
-export DH_COMPAT=3
+# export DH_COMPAT=4
+#  -- already set in compat
+#  force no striping (always include debug symbols for now)
+export DEB_BUILD_OPTIONS:="$(DEB_BUILD_OPTIONS) nostrip"
 
 
 # modules not in the "main" package or unstable 
 # modules not in the "main" package or unstable 
 EXCLUDED_MODULES=	mysql jabber auth_radius group_radius uri_radius \
 EXCLUDED_MODULES=	mysql jabber auth_radius group_radius uri_radius \
@@ -126,7 +131,7 @@ binary-common:
 #	dh_installemacsen
 #	dh_installemacsen
 #	dh_installpam
 #	dh_installpam
 #	dh_installmime
 #	dh_installmime
-	dh_installinit --init-script=ser -- defaults 23
+	dh_installinit  -- defaults 23
 	dh_installcron
 	dh_installcron
 	dh_installman
 	dh_installman
 	dh_installinfo
 	dh_installinfo
@@ -134,7 +139,7 @@ binary-common:
 	dh_installchangelogs 
 	dh_installchangelogs 
 	dh_link
 	dh_link
 	dh_strip
 	dh_strip
-	dh_compress
+	dh_compress 
 	dh_fixperms
 	dh_fixperms
 #	dh_makeshlibs
 #	dh_makeshlibs
 	dh_installdeb
 	dh_installdeb

+ 0 - 1
debian/ser-mysql-module.dirs

@@ -1 +0,0 @@
-usr/lib/ser/modules

+ 0 - 1
debian/ser-mysql-module.files

@@ -1 +0,0 @@
-usr/lib/ser/modules/mysql.so

+ 13 - 0
debian/ser.examples

@@ -0,0 +1,13 @@
+examples/acc.cfg
+examples/ccdiversion.cfg
+examples/ctd.sh
+examples/exec.cfg
+examples/logging.cfg
+examples/msilo.cfg
+examples/onr.cfg
+examples/pstn.cfg
+examples/redirect.cfg
+examples/replicate.cfg
+examples/serial_183.cfg
+examples/uas.cfg
+examples/welcome.cfg

+ 1 - 1
debian/init.d → debian/ser.init

@@ -56,7 +56,7 @@ case "$1" in
 	#	just the same as "restart".
 	#	just the same as "restart".
 	#
 	#
 	echo -n "Restarting $DESC: $NAME"
 	echo -n "Restarting $DESC: $NAME"
-	start-stop-daemon --stop --quiet --pidfile \
+	start-stop-daemon --oknodo --stop --quiet --pidfile \
 		$PIDFILE --exec $DAEMON
 		$PIDFILE --exec $DAEMON
 	sleep 1
 	sleep 1
 	start-stop-daemon --start --quiet --pidfile \
 	start-stop-daemon --start --quiet --pidfile \

+ 0 - 7
debian/ser.postinst.debhelper

@@ -1,7 +0,0 @@
-# Automatically added by dh_installdocs
-if [ "$1" = "configure" ]; then
-	if [ -d /usr/doc -a ! -e /usr/doc/ser -a -d /usr/share/doc/ser ]; then
-		ln -sf ../share/doc/ser /usr/doc/ser
-	fi
-fi
-# End automatically added section

+ 0 - 5
debian/ser.prerm.debhelper

@@ -1,5 +0,0 @@
-# Automatically added by dh_installdocs
-if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/ser ]; then
-	rm -f /usr/doc/ser
-fi
-# End automatically added section

+ 0 - 1
debian/ser.substvars

@@ -1 +0,0 @@
-shlibs:Depends=libc6 (>= 2.2.5-13)

+ 34 - 6
main.c

@@ -40,8 +40,9 @@
  *               after daemonize (so that we won't catch anymore our own
  *               after daemonize (so that we won't catch anymore our own
  *               SIGCHLD generated when becoming session leader) (andrei)
  *               SIGCHLD generated when becoming session leader) (andrei)
  *              changed is_main default value to 1 (andrei)
  *              changed is_main default value to 1 (andrei)
- *  2003-06-29  preliminary tls support (andrei)
- *              replaced port_no_str snprintf w/ int2str (andrei)
+ *  2003-06-28  kill_all_children is now used instead of kill(0, sig)
+ *                see comment above it for explanations. (andrei)
+ *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
  *
  *
  */
  */
 
 
@@ -267,6 +268,8 @@ void receive_stdin_loop()
 
 
 /* global vars */
 /* global vars */
 
 
+int own_pgid = 0; /* whether or not we have our own pgid (and it's ok
+					 to use kill(0, sig) */
 char* cfg_file = 0;
 char* cfg_file = 0;
 unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do
 unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do
 												  not want to exceed durig the
 												  not want to exceed durig the
@@ -460,6 +463,8 @@ int daemonize(char*  name)
 	/* become session leader to drop the ctrl. terminal */
 	/* become session leader to drop the ctrl. terminal */
 	if (setsid()<0){
 	if (setsid()<0){
 		LOG(L_WARN, "setsid failed: %s\n",strerror(errno));
 		LOG(L_WARN, "setsid failed: %s\n",strerror(errno));
+	}else{
+		own_pgid=1; /* we have our own process group */
 	}
 	}
 	/* fork again to drop group  leadership */
 	/* fork again to drop group  leadership */
 	if ((pid=fork())<0){
 	if ((pid=fork())<0){
@@ -535,6 +540,29 @@ error:
 
 
 
 
 
 
+/* tries to send a signal to all our processes
+ * if daemonized  is ok to send the signal to all the process group,
+ * however if not daemonized we might end up sending the signal also
+ * to the shell which launched us => most signals will kill it if 
+ * it's not in interactive mode and we don't want this. The non-daemonized 
+ * case can occur when an error is encountered before daemonize is called 
+ * (e.g. when parsing the config file) or when ser is started in "dont-fork"
+ *  mode. Sending the signal to all the processes in pt[] will not work
+ *  for processes forked from modules (which have no correspondent entry in 
+ *  pt), but this can happen only in dont_fork mode (which is only for
+ *  debugging). So in the worst case + "dont-fork" we might leave some
+ *  zombies. -- andrei */
+static void kill_all_children(int signum)
+{
+	int r;
+	if (own_pgid) kill(0, signum);
+	else if (pt)
+		for (r=1; r<process_count(); r++)
+			if (pt[r].pid) kill(pt[r].pid, signum);
+}
+
+
+
 void handle_sigs()
 void handle_sigs()
 {
 {
 	pid_t	chld;
 	pid_t	chld;
@@ -557,7 +585,7 @@ void handle_sigs()
 				DBG("SIGTERM received, program terminates\n");
 				DBG("SIGTERM received, program terminates\n");
 				
 				
 			/* first of all, kill the children also */
 			/* first of all, kill the children also */
-			kill(0, SIGTERM);
+			kill_all_children(SIGTERM);
 
 
 			     /* Wait for all the children to die */
 			     /* Wait for all the children to die */
 			while(wait(0) > 0);
 			while(wait(0) > 0);
@@ -607,7 +635,7 @@ void handle_sigs()
 			LOG(L_INFO, "INFO: terminating due to SIGCHLD\n");
 			LOG(L_INFO, "INFO: terminating due to SIGCHLD\n");
 #endif
 #endif
 			/* exit */
 			/* exit */
-			kill(0, SIGTERM);
+			kill_all_children(SIGTERM);
 			while(wait(0) > 0); /* wait for all the children to terminate*/
 			while(wait(0) > 0); /* wait for all the children to terminate*/
 			cleanup(1); /* cleanup & show status*/
 			cleanup(1); /* cleanup & show status*/
 			DBG("terminating due to SIGCHLD\n");
 			DBG("terminating due to SIGCHLD\n");
@@ -1739,14 +1767,14 @@ try_again:
 	
 	
 	ret=main_loop();
 	ret=main_loop();
 	/*kill everything*/
 	/*kill everything*/
-	kill(0, SIGTERM);
+	kill_all_children(SIGTERM);
 	/*clean-up*/
 	/*clean-up*/
 	cleanup(0);
 	cleanup(0);
 	return ret;
 	return ret;
 
 
 error:
 error:
 	/*kill everything*/
 	/*kill everything*/
-	kill(0, SIGTERM);
+	kill_all_children(SIGTERM);
 	/*clean-up*/
 	/*clean-up*/
 	cleanup(0);
 	cleanup(0);
 	return -1;
 	return -1;

+ 18 - 5
modules/tm/t_stats.c

@@ -26,6 +26,11 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+/*
+ * History:
+ * --------
+ *  2003-06-27  tm_stats & friends freed on exit only if non-null (andrei)
+ */
 
 
 
 
 #include "defs.h"
 #include "defs.h"
@@ -39,7 +44,7 @@
 #include "../../fifo_server.h"
 #include "../../fifo_server.h"
 #include "../../pt.h"
 #include "../../pt.h"
 
 
-struct t_stats *tm_stats;
+struct t_stats *tm_stats=0;
 
 
 
 
 /* we don't worry about locking data during reads (unlike
 /* we don't worry about locking data during reads (unlike
@@ -147,10 +152,13 @@ int init_tm_stats(void)
 
 
 error4:
 error4:
 	shm_free(tm_stats->s_client_transactions);
 	shm_free(tm_stats->s_client_transactions);
+	tm_stats->s_client_transactions=0;
 error3:
 error3:
 	shm_free(tm_stats->s_transactions);
 	shm_free(tm_stats->s_transactions);
+	tm_stats->s_transactions=0;
 error2:
 error2:
 	shm_free(tm_stats->s_waiting);
 	shm_free(tm_stats->s_waiting);
+	tm_stats->s_waiting=0;
 error1:
 error1:
 	shm_free(tm_stats);
 	shm_free(tm_stats);
 error0:
 error0:
@@ -159,8 +167,13 @@ error0:
 
 
 void free_tm_stats()
 void free_tm_stats()
 {
 {
-	shm_free(tm_stats->s_client_transactions);
-	shm_free(tm_stats->s_transactions);
-	shm_free(tm_stats->s_waiting);
-	shm_free(tm_stats);
+	if (tm_stats!=0){
+		if (tm_stats->s_client_transactions) 
+			shm_free(tm_stats->s_client_transactions);
+		if (tm_stats->s_transactions)
+			shm_free(tm_stats->s_transactions);
+		if (tm_stats->s_waiting)
+			shm_free(tm_stats->s_waiting);
+		shm_free(tm_stats);
+	}
 }
 }

+ 7 - 1
modules/tm/timer.c

@@ -92,6 +92,11 @@
 	a REPLY_LOCK.
 	a REPLY_LOCK.
 
 
 */
 */
+/*
+ * History:
+ * --------
+ *  2003-06-27  timers are not unlinked if timerlist is 0 (andrei)
+ */
 
 
 #include "defs.h"
 #include "defs.h"
 
 
@@ -114,7 +119,7 @@
 #include "t_cancel.h"
 #include "t_cancel.h"
 
 
 
 
-static struct timer_table *timertable;
+static struct timer_table *timertable=0;
 
 
 int noisy_ctimer=0;
 int noisy_ctimer=0;
 
 
@@ -463,6 +468,7 @@ void unlink_timer_lists()
 	struct timer_link  *tl, *end, *tmp;
 	struct timer_link  *tl, *end, *tmp;
 	enum lists i;
 	enum lists i;
 
 
+	if (timertable==0) return; /* nothing to do */
 	/* remember the DELETE LIST */
 	/* remember the DELETE LIST */
 	tl = timertable->timers[DELETE_LIST].first_tl.next_tl;
 	tl = timertable->timers[DELETE_LIST].first_tl.next_tl;
 	end = & timertable->timers[DELETE_LIST].last_tl;
 	end = & timertable->timers[DELETE_LIST].last_tl;

+ 0 - 244
tls_init.c

@@ -1,244 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2001-2003 Fhg Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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
- */
-/*
- * tls initialization & cleanup functions
- * 
- * History:
- * --------
- *  2003-06-29  created by andrei
- */
-#ifdef USE_TLS
-
-
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-
-#include "mem/mem.h"
-#include "mem/shm_mem.h"
-#include "tcp_init.h"
-#include "dprint.h"
-
-
-
-#if OPENSSL_VERSION_NUMBER < 0x00906000L  /* 0.9.6*/
-#error "OpenSSL 0.9.6 or greater required"
-/* it might work ok with older versions (I think
- *  >= 0.9.4 should be ok), but I didn't test them
- *  so try them at your own risk :-) -- andrei
- */
-#endif
-
-
-/* global tls related data */
-SSL_CTX* default_ctx=0 ; /* global ssl context */
-
-int tls_log=L_INFO; /* tls log level */
-int tls_require_cert=0; /* require client certificate */
-char* tls_pkey_file=0; /* private key file name */
-char* tls_cert_file=0; /* certificate file name */
-char* tls_ca_file=0;   /* CA list file name */
-
-
-/* inits a sock_info structure with tls data
- * (calls tcp_init for the tcp part)
- * returns 0 on success, -1 on error */
-int tls_init(struct socket_info* sock_info)
-{
-	int ret;
-	if ((ret=tcp_init(sock_info))!=0){
-		LOG(L_ERR, "ERROR: tls_init: tcp_init failed on"
-			"%.*s:%d\n", sock_info->address_str.len,
-			sock_info->address_str.s, sock_info->port_no);
-		return ret;
-	}
-	sock_info->proto=PROTO_TLS;
-	/* tls specific stuff */
-	return 0;
-}
-
-
-/* malloc & friends functions that will be used
- * by libssl (we need most ssl info in shared mem.)*/
-
-void* tls_malloc(size_t size)
-{
-	return shm_malloc(size);
-}
-
-
-void tls_free(void* ptr)
-{
-	shm_free(ptr);
-}
-
-
-void* tls_realloc(void* ptr, size_t size)
-{
-	return shm_realloc(ptr, size);
-}
-
-
-/* print the ssl error stack */
-void tls_dump_errors(char* s)
-{
-	long err;
-	if ( 1 /*default_ctx */) /* only if ssl was initialized */
-		while((err=ERR_get_error()))
-			LOG(L_ERR, "%s%s\n", (s)?s:"", ERR_error_string(err,0));
-}
-
-
-
-/* inits ser tls support
- * returns 0 on success, <0 on error */
-int init_tls()
-{
-
-	
-	if (tls_pkey_file==0)
-		tls_pkey_file=TLS_PKEY_FILE;
-	if (tls_cert_file==0)
-		tls_cert_file=TLS_CERT_FILE;
-	if (tls_ca_file==0)
-		tls_ca_file=TLS_CA_FILE;
-	
-	DBG("initializing openssl...\n");
-	SSL_library_init();  /* don't use shm_ for SSL_library_init() */
-	/* init mem. alloc. for libcrypt & openssl */
-	CRYPTO_set_mem_functions(tls_malloc, tls_realloc,
-								tls_free);
-	
-	/* init the openssl library */
-	SSL_load_error_strings(); /* readable error messages*/
-	/* seed the PRNG, nothing on linux because openssl should automatically
-	   use /dev/urandom, see RAND_seed, RAND_add */
-	
-	/* create the ssl context */
-	DBG("creating the ssl context...\n");
-	default_ctx=SSL_CTX_new(TLSv1_method());
-	if (default_ctx==0){
-		LOG(L_ERR, "init_tls: failed to create ssl context\n");
-		goto error;
-	}
-	/* no passwd: */
-	 /* SSL_CTX_set_default_passwd_cb(ctx, callback); */
-	
-	/* set options, e.g SSL_OP_NO_SSLv2, 
-	 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
-	 */
-	/* SSL_CTX_set_options(ctx, options); */
-	
-	/* mode, e.g. SSL_MODE_ENABLE_PARTIAL_WRITE,
-	 * SSL_MODE_AUTO_RETRY */
-	/* SSL_CTX_set_mode(ctx, mode); */
-	
-	/* using certificates (we don't allow anonymous ciphers => at least
-	 * the server must have a cert)*/
-	/* private key */
-	if (SSL_CTX_use_PrivateKey_file(default_ctx, tls_pkey_file,
-				SSL_FILETYPE_PEM)!=1){
-		LOG(L_ERR, "init_tls: failed to load private key from \"%s\"\n",
-				tls_pkey_file);
-		goto error_certs;
-	}
-	if (SSL_CTX_use_certificate_chain_file(default_ctx, tls_cert_file)!=1){
-		/* better than *_use_certificate_file 
-		 * see SSL_CTX_use_certificate(3)/Notes */
-		LOG(L_ERR, "init_tls: failed to load certificate from \"%s\"\n",
-					tls_cert_file);
-		goto error_certs;
-	}
-	/* check if private key corresponds to the loaded ceritficate */
-	if (SSL_CTX_check_private_key(default_ctx)!=1){
-		LOG(L_CRIT, "init_tls: private key \"%s\" does not match the"
-				" certificate file \"%s\"\n", tls_pkey_file, tls_cert_file);
-		goto error_certs;
-	}
-	
-	/* set session id context, usefull for reusing stored sessions */
-	/*
-	if (SSL_CTX_set_session_id_context(ctx, version, version_len)!=1){
-		LOG(L_CRIT, "init_tls: failed to set session id\n");
-		goto error;
-	}
-	*/
-	
-	/* set cert. verifications options */
-	/* verify peer if it has a cert (to fail for no cert. add 
-	 *  | SSL_VERIFY_FAIL_IF_NO_PEER_CERT ); forces the server to send
-	 *  a client certificate request */
-	SSL_CTX_set_verify(default_ctx, SSL_VERIFY_PEER | ( (tls_require_cert)?
-			SSL_VERIFY_FAIL_IF_NO_PEER_CERT:0 ), 0);
-	/* SSL_CTX_set_verify_depth(ctx, 2);  -- default 9 */
-	/* CA locations, list */
-	if (tls_ca_file){
-		if (SSL_CTX_load_verify_locations(default_ctx, tls_ca_file, 0 )!=1){
-			/* we don't support ca path, we load them only from files */
-			LOG(L_CRIT, "init_tls: error while processing CA locations\n");
-			goto error_certs;
-		}
-		SSL_CTX_set_client_CA_list(default_ctx, 
-									SSL_load_client_CA_file(tls_ca_file));
-		if (SSL_CTX_get_client_CA_list(default_ctx)==0){
-			LOG(L_CRIT, "init_tls: error setting client CA list from <%s>\n",
-						tls_ca_file);
-			goto error_certs;
-		}
-	}
-	
-	/* DH tmp key generation -- see DSA_generate_parameters,
-	 * SSL_CTX_set_tmp_dh, SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE */
-	
-	/* RSA tmp key generation => we don't care, we won't accept 
-	 * connection to export restricted applications and tls does not
-	 * allow a tmp key in another sitaution */
-	
-	return 0;
-error_certs:
-	/*
-	SSL_CTX_free(ctx);
-	ctx=0;
-	*/
-error:
-	tls_dump_errors("tls_init:");
-	return -1;
-}
-
-
-
-void destroy_tls()
-{
-	if(default_ctx){
-		DBG("destroy_tls...\n");
-		SSL_CTX_free(default_ctx);
-		ERR_free_strings();
-		default_ctx=0; 
-	}
-}
-
-#endif

+ 0 - 67
tls_init.h

@@ -1,67 +0,0 @@
-
-/*
- * $Id$
- *
- * Copyright (C) 2001-2003 Fhg Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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
- */
-/*
- * tls initialization & cleanup functions
- * 
- * History:
- * --------
- *  2003-06-29  created by andrei
- */
-#ifdef USE_TLS
-
-#ifndef tls_init_h
-#define tls_init_h
-
-#ifndef USE_TCP
-#error "TLS requires TCP support compiled-in, please" \
-        " add -DUSE_TCP to the Makefile.defs"
-#endif
-
-#ifndef SHM_MEM
-#error "shared memory support needed (add -DSHM_MEM to Makefile.defs)"
-#endif
-
-
-/* inits ser tls support
- * returns 0 on success, <0 on error */
-int init_tls();
-
-/* cleans up */
-void destroy_tls();
-
-/* inits a sock_info structure with tls data
- * (calls tcp_init for the tcp part)
- * returns 0 on success, -1 on error */
-int tls_init(struct socket_info* sock_info);
-
-/* print the ssl error stack */
-void tls_dump_errors(char* s);
-
-
-#endif /* tls_init_h*/
-#endif /* USE_TLS*/