diff --git a/.gitignore b/.gitignore index 7abf740..300f72e 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ lib/libsntl.pc examples/sntlc examples/sntld examples/gentest +debian/tmp diff --git a/configure.ac b/configure.ac index 2502d82..627a506 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(libsntl, 0.1) +AC_INIT(libsntl, 0.1.0) #LDFLAGS="$LDFLAGS -L/mingw/lib -L/local/lib" diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..caa65f6 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +libsntl for Debian +------------------- + + + + -- Alexander Vdolainen Mon, 24 Nov 2014 11:52:48 +0200 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..45e0597 --- /dev/null +++ b/debian/README.source @@ -0,0 +1,9 @@ +libsntl for Debian +------------------- + + + + + + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..2233f2d --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +libsntl (0.1.0) stable; urgency=low + + * Initial release (Closes: #nnnn) + + -- Alexander Vdolainen Mon, 24 Nov 2014 11:52:48 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +8 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..8bd8eb5 --- /dev/null +++ b/debian/control @@ -0,0 +1,23 @@ +Source: libsntl +Priority: extra +Maintainer: Alexander Vdolainen +Build-Depends: debhelper (>= 8.0.0), autotools-dev, libssl-dev, libsexpr-dev, libtdata-dev, uuid-dev +Standards-Version: 3.9.3 +Section: libs +Homepage: http://askele.com/software +#Vcs-Git: git://git.debian.org/collab-maint/libsntl.git +#Vcs-Browser: http://git.debian.org/?p=collab-maint/libsntl.git;a=summary + +Package: libsntl-dev +Section: libdevel +Architecture: any +Depends: libsntl (= ${binary:Version}), libsexpr-dev, libssl1.0.0-dev, libtdata-dev, uuid-dev +Description: Development files for libsntl + Development files for sntl library + +Package: libsntl +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libsexpr, libssl1.0.0, libtdata, libuuid1 +Description: Secure Networking Transport Layer implementation library + Library used to develop secure services diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..9fcefe8 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,38 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: libsntl +Source: + +Files: * +Copyright: + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2014 Alexander Vdolainen +License: GPL-2+ + This package 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 package 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, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid to pick license terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..50bd824 --- /dev/null +++ b/debian/docs @@ -0,0 +1,2 @@ +NEWS +README diff --git a/debian/emacsen-install.ex b/debian/emacsen-install.ex new file mode 100644 index 0000000..d849956 --- /dev/null +++ b/debian/emacsen-install.ex @@ -0,0 +1,47 @@ +#! /bin/sh -e +# /usr/lib/emacsen-common/packages/install/libsntl + +# Written by Jim Van Zandt , borrowing heavily +# from the install scripts for gettext by Santiago Vila +# and octave by Dirk Eddelbuettel . + +FLAVOR=$1 +PACKAGE=libsntl + +if [ ${FLAVOR} = emacs ]; then exit 0; fi + +echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR} + +#FLAVORTEST=`echo $FLAVOR | cut -c-6` +#if [ ${FLAVORTEST} = xemacs ] ; then +# SITEFLAG="-no-site-file" +#else +# SITEFLAG="--no-site-file" +#fi +FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile" + +ELDIR=/usr/share/emacs/site-lisp/${PACKAGE} +ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE} +ELRELDIR=../../../emacs/site-lisp/${PACKAGE} + +# Install-info-altdir does not actually exist. +# Maybe somebody will write it. +if test -x /usr/sbin/install-info-altdir; then + echo install/${PACKAGE}: install Info links for ${FLAVOR} + install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/share/info/${PACKAGE}.info.gz +fi + +install -m 755 -d ${ELCDIR} +cd ${ELDIR} +FILES=`echo *.el` +cd ${ELCDIR} +ln -sf ${ELRELDIR}/*.el . + +cat << EOF > path.el +(debian-pkg-add-load-path-item ".") +(setq byte-compile-warnings nil) +EOF +${FLAVOR} ${FLAGS} ${FILES} +rm -f path.el + +exit 0 diff --git a/debian/emacsen-remove.ex b/debian/emacsen-remove.ex new file mode 100644 index 0000000..114d368 --- /dev/null +++ b/debian/emacsen-remove.ex @@ -0,0 +1,15 @@ +#!/bin/sh -e +# /usr/lib/emacsen-common/packages/remove/libsntl + +FLAVOR=$1 +PACKAGE=libsntl + +if [ ${FLAVOR} != emacs ]; then + if test -x /usr/sbin/install-info-altdir; then + echo remove/${PACKAGE}: removing Info links for ${FLAVOR} + install-info-altdir --quiet --remove --dirname=${FLAVOR} /usr/share/info/libsntl.info.gz + fi + + echo remove/${PACKAGE}: purging byte-compiled files for ${FLAVOR} + rm -rf /usr/share/${FLAVOR}/site-lisp/${PACKAGE} +fi diff --git a/debian/emacsen-startup.ex b/debian/emacsen-startup.ex new file mode 100644 index 0000000..2cb1f63 --- /dev/null +++ b/debian/emacsen-startup.ex @@ -0,0 +1,27 @@ +;; -*-emacs-lisp-*- +;; +;; Emacs startup file, e.g. /etc/emacs/site-start.d/50libsntl.el +;; for the Debian libsntl package +;; +;; Originally contributed by Nils Naumann +;; Modified by Dirk Eddelbuettel +;; Adapted for dh-make by Jim Van Zandt + +;; The libsntl package follows the Debian/GNU Linux 'emacsen' policy and +;; byte-compiles its elisp files for each 'emacs flavor' (emacs19, +;; xemacs19, emacs20, xemacs20...). The compiled code is then +;; installed in a subdirectory of the respective site-lisp directory. +;; We have to add this to the load-path: +(let ((package-dir (concat "/usr/share/" + (symbol-name debian-emacs-flavor) + "/site-lisp/libsntl"))) +;; If package-dir does not exist, the libsntl package must have +;; removed but not purged, and we should skip the setup. + (when (file-directory-p package-dir) + (if (fboundp 'debian-pkg-add-load-path-item) + (debian-pkg-add-load-path-item package-dir) + (setq load-path (cons package-dir load-path))) + (autoload 'libsntl-mode "libsntl-mode" + "Major mode for editing libsntl files." t) + (add-to-list 'auto-mode-alist '("\\.libsntl$" . libsntl-mode)))) + diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..8a5d5a8 --- /dev/null +++ b/debian/files @@ -0,0 +1,2 @@ +libsntl-dev_0.1.0_amd64.deb libdevel extra +libsntl_0.1.0_amd64.deb libs extra diff --git a/debian/init.d.ex b/debian/init.d.ex new file mode 100644 index 0000000..c138d9d --- /dev/null +++ b/debian/init.d.ex @@ -0,0 +1,154 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: libsntl +# Required-Start: $network $local_fs +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: +# Description: +# <...> +# <...> +### END INIT INFO + +# Author: Alexander Vdolainen + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC=libsntl # Introduce a short description here +NAME=libsntl # Introduce the short server's name here +DAEMON=/usr/sbin/libsntl # Introduce the server's location here +DAEMON_ARGS="" # Arguments to run the daemon with +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x $DAEMON ] || exit 0 + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + $DAEMON_ARGS \ + || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/debian/libsntl-dev.debhelper.log b/debian/libsntl-dev.debhelper.log new file mode 100644 index 0000000..f283180 --- /dev/null +++ b/debian/libsntl-dev.debhelper.log @@ -0,0 +1,50 @@ +dh_autotools-dev_updateconfig +dh_auto_configure +dh_auto_build +dh_auto_test +dh_prep +dh_installdirs +dh_auto_install +dh_install +dh_installdocs +dh_installchangelogs +dh_installexamples +dh_installman +dh_installcatalogs +dh_installcron +dh_installdebconf +dh_installemacsen +dh_installifupdown +dh_installinfo +dh_pysupport +dh_installinit +dh_installmenu +dh_installmime +dh_installmodules +dh_installlogcheck +dh_installlogrotate +dh_installpam +dh_installppp +dh_installudev +dh_installwm +dh_installxfonts +dh_installgsettings +dh_bugfiles +dh_ucf +dh_lintian +dh_gconf +dh_icons +dh_perl +dh_usrlocal +dh_link +dh_compress +dh_fixperms +dh_strip +dh_makeshlibs +dh_shlibdeps +dh_installdeb +dh_gencontrol +dh_md5sums +dh_builddeb +dh_builddeb +dh_builddeb diff --git a/debian/libsntl-dev.dirs b/debian/libsntl-dev.dirs new file mode 100644 index 0000000..4418816 --- /dev/null +++ b/debian/libsntl-dev.dirs @@ -0,0 +1,2 @@ +usr/lib +usr/include diff --git a/debian/libsntl-dev.install b/debian/libsntl-dev.install new file mode 100644 index 0000000..6cd8ddd --- /dev/null +++ b/debian/libsntl-dev.install @@ -0,0 +1,4 @@ +usr/include/* +usr/lib/lib*.a +usr/lib/lib*.so +usr/lib/pkgconfig/* diff --git a/debian/libsntl-dev.substvars b/debian/libsntl-dev.substvars new file mode 100644 index 0000000..abd3ebe --- /dev/null +++ b/debian/libsntl-dev.substvars @@ -0,0 +1 @@ +misc:Depends= diff --git a/debian/libsntl-dev/DEBIAN/control b/debian/libsntl-dev/DEBIAN/control new file mode 100644 index 0000000..b508816 --- /dev/null +++ b/debian/libsntl-dev/DEBIAN/control @@ -0,0 +1,12 @@ +Package: libsntl-dev +Source: libsntl +Version: 0.1.0 +Architecture: amd64 +Maintainer: Alexander Vdolainen +Installed-Size: 94 +Depends: libsntl (= 0.1.0), libsexpr-dev, libssl1.0.0-dev, libtdata-dev, uuid-dev +Section: libdevel +Priority: extra +Homepage: http://askele.com/software +Description: Development files for libsntl + Development files for sntl library diff --git a/debian/libsntl-dev/DEBIAN/md5sums b/debian/libsntl-dev/DEBIAN/md5sums new file mode 100644 index 0000000..a2348cf --- /dev/null +++ b/debian/libsntl-dev/DEBIAN/md5sums @@ -0,0 +1,9 @@ +a308bdc1ae862fbc6d6a17ed75e33bfa usr/include/sntl/connection.h +57ab61abf79d35bcc7cf5f186b55cf76 usr/include/sntl/pth_queue.h +29d522606ca36fcb6113762477f32ea5 usr/lib/libsntl.a +e6cfd12c5a6771aac0251ba14bdc5a6c usr/lib/pkgconfig/libsntl.pc +71871531899aaf89ff3e0c7d659ff820 usr/share/doc/libsntl-dev/NEWS.gz +f93d2d6c0d313ad0266f6f88cf4d3d2a usr/share/doc/libsntl-dev/README +c3f0efcfa0458a2eaab242c388b28bda usr/share/doc/libsntl-dev/README.Debian +87736146030b265e3f3c8b577726c44b usr/share/doc/libsntl-dev/changelog.gz +7f3520d22e4f7e2bbbb8bf0b1b104a9e usr/share/doc/libsntl-dev/copyright diff --git a/debian/libsntl-dev/usr/include/sntl/connection.h b/debian/libsntl-dev/usr/include/sntl/connection.h new file mode 100644 index 0000000..c203dda --- /dev/null +++ b/debian/libsntl-dev/usr/include/sntl/connection.h @@ -0,0 +1,320 @@ +/* + * File: connection.h + * Author: vdo + * + * Created on September 24, 2014, 2:36 AM + */ + +#ifndef __ESXC_CONNECTION_H_ +#define __ESXC_CONNECTION_H_ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +/* error codes */ +#define ESXOREPLYREQ 44 /* protocol require reply with expression, + * or expression return for the request */ +#define ESXOTIMEDOUT 45 /* timedout */ +#define ESXRCBADPROT 46 /* invalid protocol */ +#define ESXNOCONNECT 47 /* connection is lost */ +#define ESXNOCHANSUP 48 +#define ESXRAPIDREPLY 49 + +/* sexp helpers */ +#define SEXP_IS_LIST(sx) \ + ((sx)->ty == SEXP_LIST) ? 1 : 0 + +#define SEXP_IS_TYPE(sx,type) \ + ((sx)->ty == SEXP_VALUE && (sx)->aty == (type)) ? 1 : 0 + +#define SEXP_ITERATE_LIST(lst, iter, ind) \ + for((ind) = 0, (iter) = (lst)->list; (ind) < sexp_list_length(lst); \ + (ind)++, (iter) = (iter)->next) +#ifdef __cplusplus +extern "C" { +#endif +int sexp_list_cdr(sexp_t *expr, sexp_t **sx); +int sexp_list_car(sexp_t *expr, sexp_t **sx); +#ifdef __cplusplus +} +#endif + +#define VERIFY_DEPTH 1 /* FIXME: */ + +#define MAX_CONNECTIONS 32768 +#define MAX_CHANNELS 4096 +#define MAX_RPC_LIST 2048 +#define MAX_MULTI 12 +#define MAX_PENDINGMSG 16384 +#define MAX_MSGINDEX ((MAX_PENDINGMSG) * (MAX_MULTI)) + +typedef struct __perm_context_type { + char *login; + char *passwd; + ulong_t certid; + ulong_t uid; + ulong_t gid; + ulong_t *gids; + int n_gids; + int p_attr; + struct in_addr *addr; + void *priv; +} perm_ctx_t; + +#define CXCONN_MASTER (1 << 1) +#define CXCONN_SLAVE (1 << 2) +#define CXCONN_ESTABL (1 << 3) +#define CXCONN_BROKEN (1 << 4) + +/* + * älä jätä kommentteja omalla kielellä! yksinkertaisia englanti sijaan! + * i found somebody who write comments and messages in non-english, + * itäs a fucking practice - forget it. + */ +typedef struct __connection_t { + char *uuid; /** < uuid of the connection */ + idx_allocator_t *idx_ch; /** < index allocation for channels */ + usrtc_t *chnl_tree; /** < search tree of all channels */ + usrtc_t *rpc_list; /** < search tree of possible RPC typed lists */ + SSL_CTX *ctx; /** < SSL context */ + SSL *ssl; /** < SSL connection */ + int ssl_data_index; /** < SSL index for the custom data */ + perm_ctx_t *pctx; /** < higher layer authentification context */ + pthread_t cthread; /** < thread for listening the connection socket */ + pthread_t rmsgthread; /** < thread for message queue (1) */ + pthread_t msgthread; /** < thread for message queue (2) */ + pth_queue_t *mqueue; /** < message queue (2) */ + pth_queue_t *rqueue; /** < message queue (1) */ + pth_dqtpoll_t *tpoll; /** < thread poll for rpc requests */ + pthread_mutex_t oplock; /** < mutex used to sync operations on connection */ + pthread_rwlock_t chnl_lock; /** < rwlock used to sync ops with channels */ + int flags; /** < flags of the connection */ + usrtc_node_t csnode; /** < node to store the connection within list */ +} conn_t; + +struct __connection_rpc_list_type; +struct __message_t; + +#define ESXCHAN_PENDING (1 << 1) +#define ESXCHAN_CLOSURE (1 << 2) + +typedef struct __channel_t { + ulong_t cid; /** < ID of the channel */ + char *uuid; /** < UUID of the channel, used in advanced implementation + * of the complex distributed systems */ + conn_t *connection; /** < pointer to the parent connection */ + idx_allocator_t *idx_msg; /** < index allocation for messages */ + usrtc_t *msgs_tree; /** < search tree of the existing messages */ + struct __message_t *sysmsg; /** < system message used to operate with channel */ + struct __connection_rpc_list_type *rpc_list; /** < rpc functions list */ + pthread_mutex_t oplock; /** < operation ops lock */ + pthread_rwlock_t msglock; /** < rwlock used to operate with messages */ + usrtc_node_t node; /** < node for connection search tree */ + int use_count; /** < use count */ + int flags; /** < flags of the channel */ +} chnl_t; + +typedef struct __sexp_payload_t { + char *cstr; + sexp_t *sx; +} sxpayload_t; + +#define ESX_SYSMSG_SIZE 512 + +#define ESXMSG_SYS (1 << 1) +#define ESXMSG_USR (1 << 2) +#define ESXMSG_PENDING (1 << 3) +#define ESXMSG_NOWAY (1 << 4) +#define ESXMSG_TIMEDOUT (1 << 5) +#define ESXMSG_PULSE (1 << 6) +#define ESXMSG_NOWAIT (1 << 7) +#define ESXMSG_ISREPLY (1 << 8) +#define ESXMSG_CLOSURE (1 << 9) +#define ESXMSG_RMONRETR (1 << 10) +#define ESXMSG_KILLTHRD (1 << 11) +#define ESXMSG_ISRAPID (1 << 12) + +/** + * \brief Message used in sntl message passing + * + * This structure used to manage a message within a channel + * of the sntl structure stack. + */ +typedef struct __message_t { + chnl_t *pch; /** < channel of the message(if applicable) */ + ulong_t mid; /** < unique ID within connection context */ + char *uuid; /** < UUID of the message, used for special messages */ + usrtc_node_t pendingq_node; /** < node for the pending queue */ + pthread_mutex_t wait; /** < special wait mutex, used for sync */ + void *payload; /** < payload */ + sexp_t *initial_sx; + int opcode; /** < opcode for system and pulse messages */ + int flags; /** < flags of the message (type, state etc ...)*/ + int use_count; /** < use count */ +} sxmsg_t; + +typedef struct __connection_rpc_entry_type { + char *name; + int (*rpcf)(void *, sexp_t *); + usrtc_node_t node; +} cx_rpc_t; + +typedef struct __connection_rpc_list_type { + usrtc_t *rpc_tree; /** < search tree for the rpc lookup */ + char *opt_version; /** < reserved for future implementations */ +} cx_rpc_list_t; + +/** + * \brief Connection subsystem structure. + * + * This structure used for management and control a set of a + * determined connections with the same RPC lists and the same + * mode (server, client). + * + */ +typedef struct __connections_subsys_type { + int ex_ssldata_index; /** < index used to work with additional data + * provided to the special call during SSL handshake */ + usrtc_t *connections; + pth_queue_t *ioq; /** < general messages queue */ + pth_queue_t *ioqueue; /** < system messages queue */ + /* system threads */ + pthread_t iog_thread; /** < general io queue */ + pthread_t ios_thread; /** < system io queue */ + pthread_rwlock_t rwlock; + char *rootca, *certpem, *certkey; /* path name to the certificates */ + cx_rpc_list_t *system_rpc; + /* special functions pointers */ + int (*validate_sslpem)(conn_t *); /** < this function used to validate SSL certificate while SSL handshake */ + int (*secure_check)(conn_t *); /** < this function authorize user to login, + * and also should check SSL cert and user, and already made sessions */ + usrtc_t* (*get_rpc_typed_list_tree)(conn_t *); /** < this function is used to set RPC list of the functions */ + int (*set_typed_list_callback)(conn_t *, int, char *); /** < this function is a callback + * during setting up a typed channel */ + void (*on_destroy)(conn_t *); /** < callback on connection destroy */ + void *priv; +} conn_sys_t; + +typedef struct __rpc_typed_list_type { + int type_id; + char *description; + cx_rpc_list_t *rpc_list; + usrtc_node_t lnode; +} rpc_typed_list_t; + +extern conn_sys_t *conn_sys; + +/* General API */ +/* subsystem */ + +extern conn_sys_t *conn_sys; +#ifdef __cplusplus +extern "C" { +#endif + +int connections_subsystem_init(void); + +int connections_subsystem_setsslserts(const char *rootca, const char *certpem, + const char *certkey); + +int connections_subsystem_setrpclist_function(usrtc_t* (*get_rpc_typed_list_tree)(conn_t *)); + +#ifdef __cplusplus +} +#endif + +#define connections_subsystem_set_securecheck(c, fuu) (c)->secure_check = fuu +#define connections_subsystem_set_sslvalidator(c, fuu) (c)->validate_sslpem = fuu +#define connections_subsystem_set_rpctlist_call(c, fuu) (c)->set_typed_list_callback = fuu +#define connections_subsystem_set_on_destroy(c, fuu) (c)->on_destroy = fuu + +/* connection */ +#define connection_create(c, s) connection_create_fapi((c), (s), NULL) +#ifdef __cplusplus +extern "C" { +#endif + +int connection_initiate (conn_t *co, const char *host, int port, + const char *SSL_cert, perm_ctx_t *pctx); + +int connection_create_fapi(conn_t *co, int sck, struct in_addr *addr); + +int connection_close(conn_t *co); + +/* FIXME: for the next versions */ +int connection_reinit(conn_t *co); + +/* channels */ +int channel_open(conn_t *co, chnl_t **ch, int type); + +int channel_close(chnl_t *chnl); + +/* message passing */ +int msg_send(chnl_t *ch, sexp_t *sx, sxmsg_t **msg); + +int msg_send_timed(chnl_t *ch, sexp_t *sx, sxmsg_t **msg, struct timespec *tio); + +int msg_return(sxmsg_t *msg, int opcode); + +int msg_reply(sxmsg_t *msg, sexp_t *sx); + +int msg_reply_timed(sxmsg_t *msg, sexp_t *sx, struct timespec *tio); + +/* reply with S expression without confirmation of delivery and applying */ +int msg_reply_rapid(sxmsg_t *msg, sexp_t *sx); + +/* this is required to clean the message in case if it's a rapid message */ +int msg_rapid_clean(sxmsg_t *msg); + +int msg_send_pulse(chnl_t *ch, sexp_t *sx); + +int msg_send_pulse_timed(chnl_t *ch, sexp_t *sx, struct timespec *tio); + +int msg_send_pulse_nowait(chnl_t *ch, sexp_t *sx); + +#ifdef __cplusplus +} +#endif + +/* additional functions */ +#define sntl_msg_get_secctx(m) (m)->pch->connection->pctx + +/* RPC List API */ +#define SNTL_FILTER_INC 0xa +#define SNTL_FILTER_EXC 0xb +#define SNTL_FILTER_END -1 + +#ifdef __cplusplus +extern "C" { +#endif + +int sntl_rpclist_init(usrtc_t *tree); + +int sntl_rpclist_add(usrtc_t *tree, int type, const char *description, + const char *version); + +int sntl_rpclist_add_function(usrtc_t *tree, int type, const char *fu_name, + int (*rpcf)(void *, sexp_t *)); + +int sntl_rpclist_filter(usrtc_t *source, usrtc_t **dest, int flag, int *filter); + +#ifdef __cplusplus +} +#endif + +/* for DEBUG purposes */ +#define __DBGLINE fprintf(stderr, "%s:%d at %s\n", __FILE__, __LINE__, __FUNCTION__) + +#endif /* __ESXC_CONNECTION_H_ */ + diff --git a/debian/libsntl-dev/usr/include/sntl/pth_queue.h b/debian/libsntl-dev/usr/include/sntl/pth_queue.h new file mode 100644 index 0000000..521e849 --- /dev/null +++ b/debian/libsntl-dev/usr/include/sntl/pth_queue.h @@ -0,0 +1,117 @@ +/* + * This is a proprietary software. See COPYING for further details. + * + * (c) 2013 Copyright Askele, inc. + * (c) 2013 Copyright Askele Ingria, inc. + * (c) 2014 Copyright Confident, inc. (granted permission to use in commercial software) + */ + +/** + * @file pth_queue.h + * @author Alexander Vdolainen + * @date 4 Nov 2013, 20 Dec 2014 (dynamic polls) + * @brief queue implementation for threads intercommunication + * + */ + +#ifndef __PTH_QUEUE_H__ +#define __PTH_QUEUE_H__ + +#include +#include + +/* possible message types, ones with POLL_ prefix valid on for pth_dqtpoll_* */ +#define SYS_MSG 0x0f0affee +#define USR_MSG 0x0afeeffe +#define POLL_DECREASE 0x0afafafe +#define POLL_INCREASE 0x0afaffff +#define NIL_MSG 0x0 +#define END_MSG 0xdead0000 + +/* max amount of threads within the poll */ +#define MAX_POLL_VALUE 32 + +typedef struct pth_msg_s { + void *data; /** < message payload */ + unsigned int msgtype; /** < message type ID */ + unsigned int qlength; /** < current queue length (actual on add moment), + * it makes no sense with few readers */ + usrtc_node_t node; +} pth_msg_t; + +typedef struct pth_queue_s { + unsigned int length; + /* sync */ + pthread_mutex_t mutex; + pthread_cond_t cond; + /* queue data */ + usrtc_t qtree; + /* cache */ + usrtc_t msgcache; +} pth_queue_t; + +int pth_queue_init(pth_queue_t *queue); + +int pth_queue_add(pth_queue_t *queue, void *data, unsigned int msgtype); + +int pth_queue_get(pth_queue_t *queue, const struct timespec *timeout, + pth_msg_t *msg); + +unsigned int pth_queue_length(pth_queue_t *queue); + +int pth_queue_destroy(pth_queue_t *queue, int freedata, + void (*free_msg)(void *)); + +/* dynamic queue thread poll ... bbrrr .... ok, ok with beer + * Dynamic queue thread poll is a queue like pth_queue, + * but also it has itäs own mamagement for threads - that's + * why dynamic. + * Ideally, the model is trying to achieve the following: + * 1. one thread in queue while no or very small amount of jobs in the queue + * 2. grow until max threads is reached while too many requests + * 3. gently slide down volume of threads after job heat + * 4. minimal additional drawbacks (i hate something periodically running, + * it's bad practice) + * The model is quite simple, we should make spurious wakeups equal to zero, + * if no - decrease poll value, and, if we don't have thread available - + * create it. + */ +typedef struct pth_dqtpoll_s { + pth_queue_t *queue; /** < Job queue */ + pthread_t *poll; /** < Thread descriptors */ + int (*jobdata_callback)(void *); /** < Callback to have a deal with data */ + int flags; /** < Flags */ + idx_allocator_t *idx; /** < index allocator for the poll threads */ + pthread_rwlock_t stats_lock; /** < rwlock for stats data */ + unsigned long spurious_wakeups; /** < amount of spurios wakeups */ + int poll_value; /** < value of the poll (totally) */ + struct timeval sched_time; + int msgop; +} pth_dqtpoll_t; + +/* flags for poll */ +#define DQTPOLL_RUNNING (1 << 1) /* poll is running */ +#define DQTPOLL_DEADSTAGE (1 << 2) /* poll in the stage of destroy */ + +/* keep it stupid */ +#define DQTPOLL_DELTAMS 500000 +#define DQTPOLL_DELTASE 0 + +/* init poll, structure must be allocated */ +int pth_dqtpoll_init(pth_dqtpoll_t*, int (*jobdata_callback)(void *)); + +/* run poll: poll */ +int pth_dqtpoll_run(pth_dqtpoll_t*); + +/* add the job to the queue: poll, job data, message type */ +int pth_dqtpoll_add(pth_dqtpoll_t*, void*, unsigned int); + +/* destroy the poll: poll, force flag + * if force flag is set (!= 0), give up + * about jobs, if no, do the job, but don't + * accept the new ones, and destroy all poll + * with last thread. + */ +int pth_dqtpoll_destroy(pth_dqtpoll_t*, int); + +#endif /* __PTH_QUEUE_H__ */ diff --git a/debian/libsntl-dev/usr/lib/libsntl.so b/debian/libsntl-dev/usr/lib/libsntl.so new file mode 120000 index 0000000..e3471f4 --- /dev/null +++ b/debian/libsntl-dev/usr/lib/libsntl.so @@ -0,0 +1 @@ +libsntl.so.0.0.0 \ No newline at end of file diff --git a/debian/libsntl-dev/usr/lib/pkgconfig/libsntl.pc b/debian/libsntl-dev/usr/lib/pkgconfig/libsntl.pc new file mode 100644 index 0000000..d53dc14 --- /dev/null +++ b/debian/libsntl-dev/usr/lib/pkgconfig/libsntl.pc @@ -0,0 +1,13 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +datarootdir=${prefix}/share +datadir=${datarootdir} +includedir=${prefix}/include + +Name: libsntl +Description: Secure Network Transport Layer library implementation +Version: 0.1.0 +Requires: +Libs: -L${libdir} -lsntl +Cflags: -I${includedir} diff --git a/debian/libsntl-dev/usr/share/doc/libsntl-dev/NEWS.gz b/debian/libsntl-dev/usr/share/doc/libsntl-dev/NEWS.gz new file mode 100644 index 0000000..095d3f3 Binary files /dev/null and b/debian/libsntl-dev/usr/share/doc/libsntl-dev/NEWS.gz differ diff --git a/debian/libsntl-dev/usr/share/doc/libsntl-dev/README b/debian/libsntl-dev/usr/share/doc/libsntl-dev/README new file mode 100644 index 0000000..e69e2f7 --- /dev/null +++ b/debian/libsntl-dev/usr/share/doc/libsntl-dev/README @@ -0,0 +1 @@ +1. Build the Debian package: debuild -i -us -uc -b diff --git a/debian/libsntl-dev/usr/share/doc/libsntl-dev/README.Debian b/debian/libsntl-dev/usr/share/doc/libsntl-dev/README.Debian new file mode 100644 index 0000000..caa65f6 --- /dev/null +++ b/debian/libsntl-dev/usr/share/doc/libsntl-dev/README.Debian @@ -0,0 +1,6 @@ +libsntl for Debian +------------------- + + + + -- Alexander Vdolainen Mon, 24 Nov 2014 11:52:48 +0200 diff --git a/debian/libsntl-dev/usr/share/doc/libsntl-dev/changelog.gz b/debian/libsntl-dev/usr/share/doc/libsntl-dev/changelog.gz new file mode 100644 index 0000000..c50b8d2 Binary files /dev/null and b/debian/libsntl-dev/usr/share/doc/libsntl-dev/changelog.gz differ diff --git a/debian/libsntl-dev/usr/share/doc/libsntl-dev/copyright b/debian/libsntl-dev/usr/share/doc/libsntl-dev/copyright new file mode 100644 index 0000000..9fcefe8 --- /dev/null +++ b/debian/libsntl-dev/usr/share/doc/libsntl-dev/copyright @@ -0,0 +1,38 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: libsntl +Source: + +Files: * +Copyright: + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2014 Alexander Vdolainen +License: GPL-2+ + This package 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 package 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, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid to pick license terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. diff --git a/debian/libsntl.cron.d.ex b/debian/libsntl.cron.d.ex new file mode 100644 index 0000000..8227383 --- /dev/null +++ b/debian/libsntl.cron.d.ex @@ -0,0 +1,4 @@ +# +# Regular cron jobs for the libsntl package +# +0 4 * * * root [ -x /usr/bin/libsntl_maintenance ] && /usr/bin/libsntl_maintenance diff --git a/debian/libsntl.debhelper.log b/debian/libsntl.debhelper.log new file mode 100644 index 0000000..f283180 --- /dev/null +++ b/debian/libsntl.debhelper.log @@ -0,0 +1,50 @@ +dh_autotools-dev_updateconfig +dh_auto_configure +dh_auto_build +dh_auto_test +dh_prep +dh_installdirs +dh_auto_install +dh_install +dh_installdocs +dh_installchangelogs +dh_installexamples +dh_installman +dh_installcatalogs +dh_installcron +dh_installdebconf +dh_installemacsen +dh_installifupdown +dh_installinfo +dh_pysupport +dh_installinit +dh_installmenu +dh_installmime +dh_installmodules +dh_installlogcheck +dh_installlogrotate +dh_installpam +dh_installppp +dh_installudev +dh_installwm +dh_installxfonts +dh_installgsettings +dh_bugfiles +dh_ucf +dh_lintian +dh_gconf +dh_icons +dh_perl +dh_usrlocal +dh_link +dh_compress +dh_fixperms +dh_strip +dh_makeshlibs +dh_shlibdeps +dh_installdeb +dh_gencontrol +dh_md5sums +dh_builddeb +dh_builddeb +dh_builddeb diff --git a/debian/libsntl.default.ex b/debian/libsntl.default.ex new file mode 100644 index 0000000..3a568d4 --- /dev/null +++ b/debian/libsntl.default.ex @@ -0,0 +1,10 @@ +# Defaults for libsntl initscript +# sourced by /etc/init.d/libsntl +# installed at /etc/default/libsntl by the maintainer scripts + +# +# This is a POSIX shell fragment +# + +# Additional options that are passed to the Daemon. +DAEMON_OPTS="" diff --git a/debian/libsntl.dirs b/debian/libsntl.dirs new file mode 100644 index 0000000..6845771 --- /dev/null +++ b/debian/libsntl.dirs @@ -0,0 +1 @@ +usr/lib diff --git a/debian/libsntl.doc-base.EX b/debian/libsntl.doc-base.EX new file mode 100644 index 0000000..666e215 --- /dev/null +++ b/debian/libsntl.doc-base.EX @@ -0,0 +1,20 @@ +Document: libsntl +Title: Debian libsntl Manual +Author: +Abstract: This manual describes what libsntl is + and how it can be used to + manage online manuals on Debian systems. +Section: unknown + +Format: debiandoc-sgml +Files: /usr/share/doc/libsntl/libsntl.sgml.gz + +Format: postscript +Files: /usr/share/doc/libsntl/libsntl.ps.gz + +Format: text +Files: /usr/share/doc/libsntl/libsntl.text.gz + +Format: HTML +Index: /usr/share/doc/libsntl/html/index.html +Files: /usr/share/doc/libsntl/html/*.html diff --git a/debian/libsntl.install b/debian/libsntl.install new file mode 100644 index 0000000..d0dbfd1 --- /dev/null +++ b/debian/libsntl.install @@ -0,0 +1 @@ +usr/lib/lib*.so.* diff --git a/debian/libsntl.postinst.debhelper b/debian/libsntl.postinst.debhelper new file mode 100644 index 0000000..3d89d3e --- /dev/null +++ b/debian/libsntl.postinst.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "configure" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libsntl.postrm.debhelper b/debian/libsntl.postrm.debhelper new file mode 100644 index 0000000..7f44047 --- /dev/null +++ b/debian/libsntl.postrm.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "remove" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libsntl.substvars b/debian/libsntl.substvars new file mode 100644 index 0000000..2f9fbbd --- /dev/null +++ b/debian/libsntl.substvars @@ -0,0 +1,2 @@ +shlibs:Depends=libc6 (>= 2.3.2), libsexpr, libssl1.0.0 (>= 1.0.1), libtdata, libuuid1 (>= 2.20.1) +misc:Depends= diff --git a/debian/libsntl/DEBIAN/control b/debian/libsntl/DEBIAN/control new file mode 100644 index 0000000..925d839 --- /dev/null +++ b/debian/libsntl/DEBIAN/control @@ -0,0 +1,11 @@ +Package: libsntl +Version: 0.1.0 +Architecture: amd64 +Maintainer: Alexander Vdolainen +Installed-Size: 52 +Depends: libc6 (>= 2.3.2), libsexpr, libssl1.0.0 (>= 1.0.1), libtdata, libuuid1 (>= 2.20.1) +Section: libs +Priority: extra +Homepage: http://askele.com/software +Description: Secure Networking Transport Layer implementation library + Library used to develop secure services diff --git a/debian/libsntl/DEBIAN/md5sums b/debian/libsntl/DEBIAN/md5sums new file mode 100644 index 0000000..c746adc --- /dev/null +++ b/debian/libsntl/DEBIAN/md5sums @@ -0,0 +1,3 @@ +4e0af3e3160f08d6f72f48d619dbbc6e usr/lib/libsntl.so.0.0.0 +87736146030b265e3f3c8b577726c44b usr/share/doc/libsntl/changelog.gz +7f3520d22e4f7e2bbbb8bf0b1b104a9e usr/share/doc/libsntl/copyright diff --git a/debian/libsntl/DEBIAN/postinst b/debian/libsntl/DEBIAN/postinst new file mode 100755 index 0000000..379f1fa --- /dev/null +++ b/debian/libsntl/DEBIAN/postinst @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_makeshlibs +if [ "$1" = "configure" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libsntl/DEBIAN/postrm b/debian/libsntl/DEBIAN/postrm new file mode 100755 index 0000000..3e73d38 --- /dev/null +++ b/debian/libsntl/DEBIAN/postrm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_makeshlibs +if [ "$1" = "remove" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libsntl/DEBIAN/shlibs b/debian/libsntl/DEBIAN/shlibs new file mode 100644 index 0000000..f6714f5 --- /dev/null +++ b/debian/libsntl/DEBIAN/shlibs @@ -0,0 +1 @@ +libsntl 0 libsntl diff --git a/debian/libsntl/usr/lib/libsntl.so.0 b/debian/libsntl/usr/lib/libsntl.so.0 new file mode 120000 index 0000000..e3471f4 --- /dev/null +++ b/debian/libsntl/usr/lib/libsntl.so.0 @@ -0,0 +1 @@ +libsntl.so.0.0.0 \ No newline at end of file diff --git a/debian/libsntl/usr/lib/libsntl.so.0.0.0 b/debian/libsntl/usr/lib/libsntl.so.0.0.0 new file mode 100644 index 0000000..dcd76f0 Binary files /dev/null and b/debian/libsntl/usr/lib/libsntl.so.0.0.0 differ diff --git a/debian/libsntl/usr/share/doc/libsntl/changelog.gz b/debian/libsntl/usr/share/doc/libsntl/changelog.gz new file mode 100644 index 0000000..c50b8d2 Binary files /dev/null and b/debian/libsntl/usr/share/doc/libsntl/changelog.gz differ diff --git a/debian/libsntl/usr/share/doc/libsntl/copyright b/debian/libsntl/usr/share/doc/libsntl/copyright new file mode 100644 index 0000000..9fcefe8 --- /dev/null +++ b/debian/libsntl/usr/share/doc/libsntl/copyright @@ -0,0 +1,38 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: libsntl +Source: + +Files: * +Copyright: + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2014 Alexander Vdolainen +License: GPL-2+ + This package 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 package 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, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid to pick license terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. diff --git a/debian/manpage.1.ex b/debian/manpage.1.ex new file mode 100644 index 0000000..f41a5f5 --- /dev/null +++ b/debian/manpage.1.ex @@ -0,0 +1,56 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" (C) Copyright 2014 Alexander Vdolainen , +.\" +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH LIBSNTL SECTION "November 24, 2014" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +libsntl \- program to do something +.SH SYNOPSIS +.B libsntl +.RI [ options ] " files" ... +.br +.B bar +.RI [ options ] " files" ... +.SH DESCRIPTION +This manual page documents briefly the +.B libsntl +and +.B bar +commands. +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +\fBlibsntl\fP is a program that... +.SH OPTIONS +These programs follow the usual GNU command line syntax, with long +options starting with two dashes (`-'). +A summary of options is included below. +For a complete description, see the Info files. +.TP +.B \-h, \-\-help +Show summary of options. +.TP +.B \-v, \-\-version +Show version of program. +.SH SEE ALSO +.BR bar (1), +.BR baz (1). +.br +The programs are documented fully by +.IR "The Rise and Fall of a Fooish Bar" , +available via the Info system. diff --git a/debian/manpage.sgml.ex b/debian/manpage.sgml.ex new file mode 100644 index 0000000..fa85375 --- /dev/null +++ b/debian/manpage.sgml.ex @@ -0,0 +1,154 @@ + manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + + FIRSTNAME"> + SURNAME"> + + November 24, 2014"> + + SECTION"> + vdo@daze"> + + LIBSEXPR"> + + + Debian"> + GNU"> + GPL"> +]> + + + +
+ &dhemail; +
+ + &dhfirstname; + &dhsurname; + + + 2003 + &dhusername; + + &dhdate; +
+ + &dhucpackage; + + &dhsection; + + + &dhpackage; + + program to do something + + + + &dhpackage; + + + + + + + + DESCRIPTION + + This manual page documents briefly the + &dhpackage; and bar + commands. + + This manual page was written for the &debian; distribution + because the original program does not have a manual page. + Instead, it has documentation in the &gnu; + Info format; see below. + + &dhpackage; is a program that... + + + + OPTIONS + + These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. For a complete description, see the + Info files. + + + + + + + + Show summary of options. + + + + + + + + Show version of program. + + + + + + SEE ALSO + + bar (1), baz (1). + + The programs are documented fully by The Rise and + Fall of a Fooish Bar available via the + Info system. + + + AUTHOR + + This manual page was written by &dhusername; &dhemail; for + the &debian; system (and may be used by others). Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; General Public License, Version 2 any + later version published by the Free Software Foundation. + + + On Debian systems, the complete text of the GNU General Public + License can be found in /usr/share/common-licenses/GPL. + + + +
+ + diff --git a/debian/manpage.xml.ex b/debian/manpage.xml.ex new file mode 100644 index 0000000..73a275f --- /dev/null +++ b/debian/manpage.xml.ex @@ -0,0 +1,291 @@ + +.
will be generated. You may view the +manual page with: nroff -man .
| less'. A typical entry +in a Makefile or Makefile.am is: + +DB2MAN = /usr/share/sgml/docbook/stylesheet/xsl/docbook-xsl/manpages/docbook.xsl +XP = xsltproc -''-nonet -''-param man.charmap.use.subset "0" + +manpage.1: manpage.xml + $(XP) $(DB2MAN) $< + +The xsltproc binary is found in the xsltproc package. The XSL files are in +docbook-xsl. A description of the parameters you can use can be found in the +docbook-xsl-doc-* packages. Please remember that if you create the nroff +version in one of the debian/rules file targets (such as build), you will need +to include xsltproc and docbook-xsl in your Build-Depends control field. +Alternatively use the xmlto command/package. That will also automatically +pull in xsltproc and docbook-xsl. + +Notes for using docbook2x: docbook2x-man does not automatically create the +AUTHOR(S) and COPYRIGHT sections. In this case, please add them manually as + ... . + +To disable the automatic creation of the AUTHOR(S) and COPYRIGHT sections +read /usr/share/doc/docbook-xsl/doc/manpages/authors.html. This file can be +found in the docbook-xsl-doc-html package. + +Validation can be done using: `xmllint -''-noout -''-valid manpage.xml` + +General documentation about man-pages and man-page-formatting: +man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + +--> + + + + + + + + + + + + + +]> + + + + &dhtitle; + &dhpackage; + + + &dhfirstname; + &dhsurname; + Wrote this manpage for the Debian system. +
+ &dhemail; +
+
+
+ + 2007 + &dhusername; + + + This manual page was written for the Debian system + (and may be used by others). + Permission is granted to copy, distribute and/or modify this + document under the terms of the GNU General Public License, + Version 2 or (at your option) any later version published by + the Free Software Foundation. + On Debian systems, the complete text of the GNU General Public + License can be found in + /usr/share/common-licenses/GPL. + +
+ + &dhucpackage; + &dhsection; + + + &dhpackage; + program to do something + + + + &dhpackage; + + + + + + + + + this + + + + + + + + this + that + + + + + &dhpackage; + + + + + + + + + + + + + + + + + + + DESCRIPTION + This manual page documents briefly the + &dhpackage; and bar + commands. + This manual page was written for the Debian distribution + because the original program does not have a manual page. + Instead, it has documentation in the GNU + info + 1 + format; see below. + &dhpackage; is a program that... + + + OPTIONS + The program follows the usual GNU command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. For a complete description, see the + + info + 1 + files. + + + + + + + Does this and that. + + + + + + + Show summary of options. + + + + + + + Show version of program. + + + + + + FILES + + + /etc/foo.conf + + The system-wide configuration file to control the + behaviour of &dhpackage;. See + + foo.conf + 5 + for further details. + + + + ${HOME}/.foo.conf + + The per-user configuration file to control the + behaviour of &dhpackage;. See + + foo.conf + 5 + for further details. + + + + + + ENVIRONMENT + + + FOO_CONF + + If used, the defined file is used as configuration + file (see also ). + + + + + + DIAGNOSTICS + The following diagnostics may be issued + on stderr: + + + Bad configuration file. Exiting. + + The configuration file seems to contain a broken configuration + line. Use the option, to get more info. + + + + + &dhpackage; provides some return codes, that can + be used in scripts: + + Code + Diagnostic + + 0 + Program exited successfully. + + + 1 + The configuration file seems to be broken. + + + + + + BUGS + The program is currently limited to only work + with the foobar library. + The upstreams BTS can be found + at . + + + SEE ALSO + + + bar + 1 + , + baz + 1 + , + foo.conf + 5 + + The programs are documented fully by The Rise and + Fall of a Fooish Bar available via the + info + 1 + system. + +
+ diff --git a/debian/menu.ex b/debian/menu.ex new file mode 100644 index 0000000..d14a962 --- /dev/null +++ b/debian/menu.ex @@ -0,0 +1,2 @@ +?package(libsntl):needs="X11|text|vc|wm" section="Applications/see-menu-manual"\ + title="libsntl" command="/usr/bin/libsntl" diff --git a/debian/postinst.ex b/debian/postinst.ex new file mode 100644 index 0000000..46cd8a7 --- /dev/null +++ b/debian/postinst.ex @@ -0,0 +1,39 @@ +#!/bin/sh +# postinst script for libsntl +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/postrm.ex b/debian/postrm.ex new file mode 100644 index 0000000..40d2e01 --- /dev/null +++ b/debian/postrm.ex @@ -0,0 +1,37 @@ +#!/bin/sh +# postrm script for libsntl +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/preinst.ex b/debian/preinst.ex new file mode 100644 index 0000000..050f69e --- /dev/null +++ b/debian/preinst.ex @@ -0,0 +1,35 @@ +#!/bin/sh +# preinst script for libsntl +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/prerm.ex b/debian/prerm.ex new file mode 100644 index 0000000..4bba561 --- /dev/null +++ b/debian/prerm.ex @@ -0,0 +1,38 @@ +#!/bin/sh +# prerm script for libsntl +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `upgrade' +# * `failed-upgrade' +# * `remove' `in-favour' +# * `deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove|upgrade|deconfigure) + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..312e24d --- /dev/null +++ b/debian/rules @@ -0,0 +1,13 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ --with autotools-dev diff --git a/debian/shlibs.local.ex b/debian/shlibs.local.ex new file mode 100644 index 0000000..180b0d6 --- /dev/null +++ b/debian/shlibs.local.ex @@ -0,0 +1 @@ +libsntl 0.1.0 libsntl (>> 0.1.0), libsntl (<< 0.1.99) diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/watch.ex b/debian/watch.ex new file mode 100644 index 0000000..bc7e56c --- /dev/null +++ b/debian/watch.ex @@ -0,0 +1,23 @@ +# Example watch control file for uscan +# Rename this file to "watch" and then you can run the "uscan" command +# to check for upstream updates and more. +# See uscan(1) for format + +# Compulsory line, this is a version 3 file +version=3 + +# Uncomment to examine a Webpage +# +#http://www.example.com/downloads.php libsntl-(.*)\.tar\.gz + +# Uncomment to examine a Webserver directory +#http://www.example.com/pub/libsntl-(.*)\.tar\.gz + +# Uncommment to examine a FTP server +#ftp://ftp.example.com/pub/libsntl-(.*)\.tar\.gz debian uupdate + +# Uncomment to find new files on sourceforge, for devscripts >= 2.9 +# http://sf.net/libsntl/libsntl-(.*)\.tar\.gz + +# Uncomment to find new files on GooglePages +# http://example.googlepages.com/foo.html libsntl-(.*)\.tar\.gz diff --git a/include/Makefile.am b/include/Makefile.am index 3216740..7af89e1 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = sntl/pth_queue.h sntl/mcache.h sntl/connection.h +nobase_include_HEADERS = sntl/pth_queue.h sntl/connection.h diff --git a/lib/Makefile.am b/lib/Makefile.am index ebcc096..eaa6fbb 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -14,7 +14,7 @@ lib_LTLIBRARIES = libsntl.la libsntl_la_SOURCES = \ - support.c queue.c mcache.c rpclist.c message.c channel.c connection.c + support.c queue.c rpclist.c message.c channel.c connection.c libsntl_la_LDFLAGS = -Wl,--export-dynamic diff --git a/lib/channel.c b/lib/channel.c index 59ed32d..d79fb00 100644 --- a/lib/channel.c +++ b/lib/channel.c @@ -2,8 +2,8 @@ * Secure Network Transport Layer Library implementation. * This is a proprietary software. See COPYING for further details. * - * (c) 2013-2014 Copyright Askele, inc. - * (c) 2013-2014 Copyright Askele Ingria, inc. + * (c) Askele Group 2013-2015 + * */ #include @@ -223,30 +223,31 @@ int channel_close(chnl_t *chnl) return ESXNOCONNECT; } - uuid_ = __generate_uuid(); - pthread_rwlock_rdlock(&(co->chnl_lock)); node = usrtc_lookup(co->chnl_tree, &chnl->cid); pthread_rwlock_unlock(&(co->chnl_lock)); if(!node) { - fprintf(stderr, "No such channel\n"); return ENOENT; } pthread_rwlock_wrlock(&(chnl->msglock)); /* check unprocessed messages */ - if(!usrtc_isempty(chnl->msgs_tree)) { + if(!usrtc_isempty(chnl->msgs_tree)) { /* messages on the queue */ pthread_rwlock_unlock(&(chnl->msglock)); - fprintf(stderr, "Unable to close channel\n"); return EBUSY; } + uuid_ = __generate_uuid(); pl = malloc(sizeof(sxpayload_t)); - if(!pl) return ENOMEM; + if(!pl) { + pthread_rwlock_unlock(&(chnl->msglock)); + free(uuid_); + return ENOMEM; + } if(__create_sys_msg(&sms, uuid_, chnl, pl)) { - if(chnl->idx_msg) free(chnl->idx_msg); - if(chnl->msgs_tree) free(chnl->msgs_tree); - free(chnl); + pthread_rwlock_unlock(&(chnl->msglock)); + free(pl); + free(uuid_); return ENOMEM; } @@ -254,6 +255,7 @@ int channel_close(chnl_t *chnl) if(!(pl->cstr = malloc(sizeof(char) * ESX_SYSMSG_SIZE))) { pthread_rwlock_unlock(&(chnl->msglock)); free(pl); + free(uuid_); return ENOMEM; } memset(pl->cstr, 0, sizeof(char) * ESX_SYSMSG_SIZE); @@ -273,8 +275,9 @@ int channel_close(chnl_t *chnl) goto __process_smsg; } else pthread_mutex_lock(&(sms->wait)); /* will sleep until got a reply */ -__process_smsg: + __process_smsg: if(sms->opcode) { + pthread_rwlock_unlock(&(chnl->msglock)); r = sms->opcode; return r; } else r = 0; diff --git a/lib/connection.c b/lib/connection.c index 819b345..437ebf2 100644 --- a/lib/connection.c +++ b/lib/connection.c @@ -2,8 +2,8 @@ * Secure Network Transport Layer Library implementation. * This is a proprietary software. See COPYING for further details. * - * (c) 2013-2014 Copyright Askele, inc. - * (c) 2013-2014 Copyright Askele Ingria, inc. + * (c) Askele Group 2013-2015 + * */ #include @@ -103,6 +103,7 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len) __retry: do { + __try_again: r = SSL_read(co->ssl, buf, (int)buf_len); switch(SSL_get_error (co->ssl, r)) { case SSL_ERROR_NONE: @@ -115,19 +116,41 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len) case SSL_ERROR_WANT_WRITE: /* here we blocked on write */ read_blocked_on_write = 1; break; + case SSL_ERROR_SYSCALL: + if(errno == EAGAIN || errno == EINTR) goto __try_again; + else { + fprintf(stderr, "SSL syscall error.\n"); + goto __close_conn; + } + break; + case SSL_ERROR_WANT_CONNECT: + case SSL_ERROR_WANT_ACCEPT: + fprintf(stderr, "SSL negotiation required. Trying again.\n"); + goto __try_again; + break; + case SSL_ERROR_SSL: + fprintf(stderr, "SSL error occured. Connection will be closed.\n"); + goto __close_conn; + break; + case SSL_ERROR_ZERO_RETURN: + fprintf(stderr, "SSL connection is cleary closed.\n"); default: - fprintf(stderr, "(RD)Unknown error on %s\n", co->uuid); + __close_conn: + fprintf(stderr, "(RD)Unknown error on %s (errno = %d)\n", co->uuid, errno); return -1; } } while(SSL_pending(co->ssl) && !read_blocked); + __select_retry: + if(read_blocked) { FD_ZERO(&readset); FD_SET(rfd, &readset); /* waits until something will be ready to read */ r = select(rfd + 1, &readset, NULL, NULL, NULL); if(r < 0) { - printf("select (%d)\n", errno); + if(errno == EINTR || errno == EAGAIN) goto __select_retry; + printf("(RD) select (%d) on %s\n", errno, co->uuid); return -1; } if(!r) { @@ -156,7 +179,7 @@ static int __conn_write(conn_t *co, void *buf, size_t buf_len) int r, rfd = SSL_get_fd(co->ssl); fd_set writeset; - //pthread_mutex_lock(&(co->oplock)); + pthread_mutex_lock(&(co->oplock)); __retry: r = SSL_write(co->ssl, buf, (int)buf_len); switch(SSL_get_error(co->ssl, r)) { @@ -168,14 +191,19 @@ static int __conn_write(conn_t *co, void *buf, size_t buf_len) r = select(rfd + 1, NULL, &writeset, NULL, NULL); if(r && FD_ISSET(rfd, &writeset)) goto __retry; break; + case SSL_ERROR_SYSCALL: + if(errno == EAGAIN || errno == EINTR) goto __retry; + else goto __close_conn; + break; default: - //pthread_mutex_unlock(&(co->oplock)); + pthread_mutex_unlock(&(co->oplock)); + __close_conn: if(r < 0) { fprintf(stderr, "(WR)Unknown error on %s (%d)\n", co->uuid, r); return -1; } else return 0; } - //pthread_mutex_unlock(&(co->oplock)); + pthread_mutex_unlock(&(co->oplock)); return 0; } @@ -242,6 +270,7 @@ static void __wake_up_waiters(conn_t *co, int opcode) pthread_rwlock_wrlock(&(co->chnl_lock)); + if(!co->chnl_tree) goto __skip; node = usrtc_first(co->chnl_tree); last_node = usrtc_last(co->chnl_tree); @@ -270,6 +299,7 @@ static void __wake_up_waiters(conn_t *co, int opcode) node = usrtc_next(co->chnl_tree, node); } + __skip: pthread_rwlock_unlock(&(co->chnl_lock)); return; @@ -815,32 +845,25 @@ static int __default_ch_close(void *cctx, sexp_t *sx) } } - //printf("%s(%ld)\n", __FUNCTION__, cid); - /* additional check for type of the channel */ pthread_rwlock_rdlock(&(co->chnl_lock)); node = usrtc_lookup(co->chnl_tree, &cid); pthread_rwlock_unlock(&(co->chnl_lock)); if(!node) { r = ENOENT; - printf("there is no channel with id=%ld\n", cid); + /* there are no such channel exist */ + destroy_sexp(sx); goto __send_repl; } channel = (chnl_t *)usrtc_node_getdata(node); -__send_repl: - buf = malloc(2048); - snprintf(buf, 2048, "(ch-close-ret ((:id %ld) (:error %d)))", - channel->cid, r); - /* check up the message queue */ pthread_rwlock_rdlock(&(channel->msglock)); if(usrtc_count(channel->msgs_tree)) { - fprintf(stderr, "Operation is not permitted. There are some " - "undelivered messages in the message tree"); - free(buf); + /* we have some undelivered messages in the queue */ destroy_sexp(sx); - return EPERM; + r = EBUSY; + goto __send_repl; } pthread_rwlock_unlock(&(channel->msglock)); @@ -859,6 +882,11 @@ __send_repl: free(channel); destroy_sexp(sx); + + __send_repl: + buf = malloc(2048); + snprintf(buf, 2048, "(ch-close-ret ((:id %ld) (:error %d)))", cid, r); + if(__conn_write(co, buf, strlen(buf)) < 0) { co->flags &= ~CXCONN_ESTABL; co->flags |= CXCONN_BROKEN; @@ -871,7 +899,6 @@ __send_repl: static int __default_ch_close_ret(void *cctx, sexp_t *sx) { - ; conn_t *co = (conn_t *)cctx; chnl_t *chan; usrtc_node_t *node; @@ -885,7 +912,6 @@ static int __default_ch_close_ret(void *cctx, sexp_t *sx) lsx = sx->list->next; /* now we expect a list of lists */ if(lsx->ty != SEXP_LIST) { - //printf("%s:%d\n", __FUNCTION__, __LINE__); r = ESXRCBADPROT; goto __mark_msg; } @@ -927,8 +953,8 @@ static int __default_ch_close_ret(void *cctx, sexp_t *sx) /* try to find desired channel to intercept message */ pthread_rwlock_rdlock(&(co->chnl_lock)); node = usrtc_lookup(co->chnl_tree, (void *)&id); - //printf("channels (%d)\n", usrtc_count(co->chnl_tree)); pthread_rwlock_unlock(&(co->chnl_lock)); + if(node) { chan = (chnl_t *)usrtc_node_getdata(node); sms = chan->sysmsg; @@ -1535,16 +1561,22 @@ static int __eval_cstr(char *cstr, cx_rpc_list_t *rpc_list, void *ctx) if(sx->ty == SEXP_LIST) rpcf = sx->list->val; - else rpcf = sx->val; + else goto __enoent; /* find an appropriate function */ node = usrtc_lookup(rpc_list->rpc_tree, rpcf); - if(!node) return ENOENT; + if(!node) { + __enoent: + fprintf(stderr, "Invalid S-expression catched.\n"); + destroy_sexp(sx); + return ENOENT; + } else rentry = (cx_rpc_t *)usrtc_node_getdata(node); - + /* call it */ r = rentry->rpcf(ctx, sx); + //if(r) destroy_sexp(sx); return r; } @@ -1635,8 +1667,14 @@ static void *__rmsg_queue_thread(void *ctx) /* now we're need to have a deal with the rpc calling, other - we don't care */ ch = msg->pch; sx = (sexp_t *)msg->payload; + + if(!sx) { + r = ESXRCBADPROT; + goto __err_ret; + } /* get the function name */ - if(sx->ty == SEXP_LIST) rpcf = sx->list->val; + if((sx->ty == SEXP_LIST) && (sx->list != NULL)) + rpcf = sx->list->val; else { r = ESXRCBADPROT; goto __err_ret; @@ -1719,6 +1757,7 @@ static void *__msg_queue_thread(void *ctx) } else { if(msg->flags & ESXMSG_ISRAPID) { msg->flags |= ESXMSG_CLOSURE; + pthread_mutex_unlock(&(msg->wait)); /* wake it up */ snprintf(buf, 4096, "(ch-msg-rapid (:chid %lu (:msgid %lu ", ch->cid, msg->mid); } else @@ -1844,7 +1883,7 @@ static int __verify_certcall(int preverify_ok, X509_STORE_CTX *ctx) /* ok, now we're on top of SSL (depth == 0) certs chain, * and we can validate client certificate */ if(!depth) { - co->pctx = malloc(sizeof(perm_ctx_t)); + //co->pctx = malloc(sizeof(perm_ctx_t)); co->pctx->certid = ASN1_INTEGER_get((const ASN1_INTEGER *)X509_get_serialNumber(ctx->current_cert)); //printf("Certificate ID: %lu\n", co->pctx->certid); @@ -2202,20 +2241,34 @@ int connection_initiate(conn_t *co, const char *host, int port, /* now we will create an SSL connection */ co->ssl = SSL_new(co->ctx); SSL_set_fd(co->ssl, sd); /* attach connected socket */ - BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + // BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + SSL_set_connect_state(co->ssl); if(SSL_connect(co->ssl) == -1) { r = EBADE; free(buf); /* shutdown connection */ goto __fail_3; } /* if success we're ready to use established SSL channel */ - BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + // BIO_set_nbio(SSL_get_rbio(co->ssl), 1); /* auth and RPC contexts sync */ co->pctx = pctx; snprintf(buf, __TMPBUFLEN, "(auth-set-context ((:user \"%s\")(:passwd \"%s\")))", pctx->login, pctx->passwd); /* send an auth request */ - SSL_write(co->ssl, buf, strlen(buf) + sizeof(char)); + if(__conn_write(co, buf, strlen(buf) + sizeof(char))) { + __finalize: + co->flags &= ~CXCONN_ESTABL; + co->flags |= CXCONN_BROKEN; + r = ESXNOCONNECT; + free(buf); + __retry_shut: + if(!SSL_shutdown(co->ssl)) { + usleep(100); + goto __retry_shut; + } + /* shutdown connection */ + goto __fail_3; + } /* read the message reply */ bytes = __conn_read(co, buf, __TMPBUFLEN); @@ -2236,17 +2289,14 @@ int connection_initiate(conn_t *co, const char *host, int port, if(!r) { /* all is fine security context is good */ snprintf(buf, __TMPBUFLEN, "(ch-get-types)"); /* now we should receive possible channel types */ - SSL_write(co->ssl, buf, strlen(buf) + sizeof(char)); + if(__conn_write(co, buf, strlen(buf) + sizeof(char))) { + goto __finalize; + } + /* read the message reply */ bytes = __conn_read(co, buf, __TMPBUFLEN); if(bytes == -1) { - /* we've lost the connection */ - co->flags &= ~CXCONN_ESTABL; - co->flags |= CXCONN_BROKEN; - r = ESXNOCONNECT; - free(buf); - /* shutdown connection */ - goto __fail_3; + goto __finalize; } buf[bytes] = 0; @@ -2267,9 +2317,9 @@ int connection_initiate(conn_t *co, const char *host, int port, pthread_rwlock_unlock(&conn_sys->rwlock); } r = pthread_create(&co->msgthread, NULL, __msg_queue_thread, (void *)co); - if(r) goto __fail_3; + if(r) goto __finalize; r = pthread_create(&co->rmsgthread, NULL, __rmsg_queue_thread, (void *)co); - if(r) goto __fail_3; + if(r) goto __finalize; pth_dqtpoll_run(tpoll); co->tpoll = tpoll; @@ -2381,10 +2431,19 @@ int connection_create_fapi(conn_t *co, int sck, struct in_addr *addr) /* now we will create an SSL connection */ co->ssl = SSL_new(co->ctx); + co->pctx = malloc(sizeof(perm_ctx_t)); SSL_set_fd(co->ssl, sck); /* attach connected socket */ + /* ok now we need to initialize address */ + if(addr) { + co->pctx->addr = malloc(sizeof(struct in_addr)); + memcpy(co->pctx->addr, addr, sizeof(struct in_addr)); + } else co->pctx->addr = NULL; + + SSL_set_accept_state(co->ssl); /* set the context to verify ssl connection */ SSL_set_ex_data(co->ssl, conn_sys->ex_ssldata_index, (void *)co); - BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + //BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + SSL_set_accept_state(co->ssl); if(SSL_accept(co->ssl) == -1) { r = EBADE; free(buf); @@ -2392,13 +2451,8 @@ int connection_create_fapi(conn_t *co, int sck, struct in_addr *addr) goto __fail_3; } /* if success we're ready to use established SSL channel */ - BIO_set_nbio(SSL_get_rbio(co->ssl), 1); + //BIO_set_nbio(SSL_get_rbio(co->ssl), 1); - /* ok now we need to initialize address */ - if(addr) { - co->pctx->addr = malloc(sizeof(struct in_addr)); - memcpy(co->pctx->addr, addr, sizeof(struct in_addr)); - } else co->pctx->addr = NULL; /*******************************************/ /*-=Protocol part of connection establish=-*/ /*******************************************/ @@ -2407,13 +2461,20 @@ int connection_create_fapi(conn_t *co, int sck, struct in_addr *addr) if(bytes > 0) { buf[bytes] = 0; r = __eval_cstr(buf, conn_sys->system_rpc, (void *)co); - if(r) goto __fail_3; + if(r) { + fprintf(stderr, "Initiation func return %d\n", r); + free(buf); + SSL_shutdown(co->ssl); + goto __fail_3; + } } else { if(bytes < 0) { printf("Terminate SSL connection, the other end is lost.\n"); co->flags &= ~CXCONN_ESTABL; co->flags |= CXCONN_BROKEN; - + free(buf); + if(conn_sys->on_destroy) conn_sys->on_destroy(co); + SSL_shutdown(co->ssl); r = ESXNOCONNECT; goto __fail_3; } @@ -2513,6 +2574,7 @@ static void __connection_free(conn_t *co) free(co->idx_ch); free(co->chnl_tree); /* kill SSL context */ + SSL_shutdown(co->ssl); close(SSL_get_fd(co->ssl)); SSL_free(co->ssl); SSL_CTX_free(co->ctx); diff --git a/lib/libsntl.pc.in b/lib/libsntl.pc.in index 8d00a4f..622a506 100644 --- a/lib/libsntl.pc.in +++ b/lib/libsntl.pc.in @@ -5,7 +5,7 @@ datarootdir=@datarootdir@ datadir=@datadir@ includedir=@includedir@ -Name: liblibsntl +Name: libsntl Description: Secure Network Transport Layer library implementation Version: @VERSION@ Requires: diff --git a/lib/message.c b/lib/message.c index 636a6ed..a8a46bd 100644 --- a/lib/message.c +++ b/lib/message.c @@ -2,8 +2,8 @@ * Secure Network Transport Layer Library implementation. * This is a proprietary software. See COPYING for further details. * - * (c) 2013-2014 Copyright Askele, inc. - * (c) 2013-2014 Copyright Askele Ingria, inc. + * (c) Askele Group 2013-2015 + * */ #include @@ -233,7 +233,7 @@ static int __msg_reply(sxmsg_t *msg, sexp_t *sx, struct timespec *tio, int opcod if(r) return r; /* FIXME: better give up */ if(!sx || israpid) { /* wait for write */ - pthread_mutex_lock(&(msg->wait)); + //pthread_mutex_lock(&(msg->wait)); return 0; } @@ -250,8 +250,6 @@ static int __msg_reply(sxmsg_t *msg, sexp_t *sx, struct timespec *tio, int opcod r = msg->opcode; if(msg->flags & ESXMSG_CLOSURE) { - /* destroy */ - destroy_sexp(msg->initial_sx); __destroy_msg(msg); } diff --git a/lib/queue.c b/lib/queue.c index 8ab08f9..2dce4e1 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -1,9 +1,9 @@ /* * This is a proprietary software. See COPYING for further details. * - * (c) 2013 Copyright Askele, inc. - * (c) 2013 Copyright Askele Ingria, inc. - * (c) 2014 Copyright Confident, inc. (granted permission to use in commercial software) + * + * + * (c) Askele Group 2013-2015 */ #include diff --git a/lib/rpclist.c b/lib/rpclist.c index 7baabd6..444b3ad 100644 --- a/lib/rpclist.c +++ b/lib/rpclist.c @@ -2,8 +2,7 @@ * Secure Network Transport Layer Library implementation. * This is a proprietary software. See COPYING for further details. * - * (c) 2013-2014 Copyright Askele, inc. - * (c) 2013-2014 Copyright Askele Ingria, inc. + * (c) Askele Group 2013-2015 */ #include diff --git a/lib/support.c b/lib/support.c index 6a8081d..12efbff 100644 --- a/lib/support.c +++ b/lib/support.c @@ -2,8 +2,7 @@ * Secure Network Transport Layer Library implementation. * This is a proprietary software. See COPYING for further details. * - * (c) 2013-2014 Copyright Askele, inc. - * (c) 2013-2014 Copyright Askele Ingria, inc. + * (c) Askele Group 2013-2015 */ #include @@ -42,16 +41,14 @@ #ifdef WIN32 #define UUID_T_LENGTH 16 -#endif -#ifdef uuid_t +#ifdef uuid_t #undef uuid_t -#endif +#endif -#ifdef WIN32 - typedef unsigned char uuid_t[16]; +typedef unsigned char uuid_t[16]; - void uuid_generate_random(uuid_t out){ +void uuid_generate_random(uuid_t out){ int i,a=0; LARGE_INTEGER frequency,t1; long int d; @@ -63,7 +60,7 @@ QueryPerformanceFrequency(&frequency); - QueryPerformanceCounter(&t1); + QueryPerformanceCounter(&t1); d=(long int)t1.QuadPart*1000/frequency.QuadPart; memcpy(out,&d,sizeof(d)); } @@ -73,7 +70,6 @@ char *__generate_uuid(void) { #ifdef WIN32 - char *uuidc = NULL; uuid_t uuid_t_m; int len, i = 0,r=0; @@ -89,7 +85,6 @@ char *__generate_uuid(void) return uuidc; #else - char *uuidc = NULL; uuid_t uuid; int len, i = 0; @@ -102,8 +97,8 @@ char *__generate_uuid(void) for(i = 0; i < sizeof(uuid_t); i++) snprintf(uuidc+(2*i*sizeof(char)), len, "%02x", uuid[i]); - return uuidc; -#endif + return uuidc; +#endif } /* networking helpers */