diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/astmanproxy.h | 149 | ||||
-rw-r--r-- | src/include/dlfcn-compat.h | 83 | ||||
-rw-r--r-- | src/include/endian.h | 60 | ||||
-rw-r--r-- | src/include/md5.h | 18 | ||||
-rw-r--r-- | src/include/poll-compat.h | 101 | ||||
-rw-r--r-- | src/include/ssl.h | 89 |
6 files changed, 500 insertions, 0 deletions
diff --git a/src/include/astmanproxy.h b/src/include/astmanproxy.h new file mode 100644 index 0000000..dc7ac87 --- /dev/null +++ b/src/include/astmanproxy.h @@ -0,0 +1,149 @@ +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <sys/time.h> +#include <sys/types.h> +#include <netdb.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <arpa/inet.h> +#include <signal.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdarg.h> +#include <dirent.h> +#include <errno.h> +#ifdef __APPLE__ + #include "dlfcn-compat.h" + #include "poll-compat.h" +#else + #include <dlfcn.h> + #include <sys/poll.h> +#endif + +#define BUFSIZE 1024 +#define MAX_HEADERS 256 +#define MAX_LEN 1024 + +#define PROXY_BANNER "Asterisk Call Manager Proxy" +#define PROXY_SHUTDOWN "ProxyMessage: Proxy Shutting Down" +#define ACTION_ID "ActionID" + +struct ast_server { + char nickname[80]; + char ast_host[40]; + char ast_port[10]; + char ast_user[80]; + char ast_pass[80]; + char ast_events[10]; + int use_ssl; /* Use SSL when Connecting to Server? */ + int status; /* TODO: have this mean something */ + struct ast_server *next; +}; + +struct proxy_user { + char username[80]; + char secret[80]; + char channel[80]; + char icontext[80]; + char ocontext[80]; + struct proxy_user *next; +}; + +struct proxyconfig { + struct ast_server *serverlist; + struct proxy_user *userlist; + char listen_addr[INET_ADDRSTRLEN]; + int listen_port; + char inputformat[80]; + char outputformat[80]; + int autofilter; /* enable autofiltering? */ + int authrequired; /* is authentication required? */ + char key[80]; + char proc_user[40]; + char proc_group[40]; + char logfile[256]; + int retryinterval; + int maxretries; + int asteriskwritetimeout; /* ms to wait when writing to asteriskfor ast_carefulwrite */ + int clientwritetimeout; /* ms to wait when writing to client ast_carefulwrite */ + int sslclhellotimeout; /* ssl client hello timeout -- how long to wait before assuming not ssl */ + int acceptencryptedconnection; /* accept encrypted connections? */ + int acceptunencryptedconnection; /* accept unencrypted connections? */ + char certfile[256]; /* our SERVER-side SSL certificate file */ +}; + +struct iohandler { + int (*read) (); + int (*write) (); + int (*onconnect) (); + char formatname[80]; + void *dlhandle; + struct iohandler *next; +}; + +struct mansession { + pthread_t t; + pthread_mutex_t lock; + struct sockaddr_in sin; + int fd; + char inbuf[MAX_LEN]; + int inlen; + struct iohandler *input; + struct iohandler *output; + int autofilter; + int authenticated; + int connected; + int dead; /* Whether we are dead */ + int busy; /* Whether we are busy */ + int inputcomplete; /* Whether we want any more input from this session (http) */ + int outputcomplete; /* Whether output to this session is done (http) */ + struct ast_server *server; + struct proxy_user user; + char actionid[MAX_LEN]; + char challenge[10]; /*! Authentication challenge */ + int writetimeout; /* Timeout for ast_carefulwrite() */ + struct mansession *next; +}; + +struct message { + int hdrcount; + char headers[MAX_HEADERS][MAX_LEN]; + int in_command; + struct mansession *session; +}; + +struct proxyconfig pc; +extern int debug; + +/* Common Function Prototypes */ +void debugmsg (const char *, ...); +const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia); +int AddHeader(struct message *m, const char *fmt, ...); +void debugmsg (const char *fmt, ...); +void logmsg (const char *fmt, ...); + +int StartServer(struct ast_server *srv); +int WriteAsterisk(struct message *m); +char *astman_get_header(struct message *m, char *var); +int proxyerror_do(struct mansession *s, char *err); +int get_input(struct mansession *s, char *output); +int SetIOHandlers(struct mansession *s, char *ifmt, char *ofmt); +void destroy_session(struct mansession *s); +int ast_carefulwrite(int fd, char *s, int len, int timeoutms); +extern void *SendError(struct mansession *s, char *errmsg); + +int close_sock(int socket); +int ProxyChallenge(struct mansession *s, struct message *m); +int ast_connect(struct mansession *a); +int is_encrypt_request(int sslclhellotimeout, int fd); +int saccept(int s); +int get_real_fd(int fd); +int client_init_secure(void); +int init_secure(char *certfile); +int m_send(int fd, const void *data, size_t len); +int m_recv(int s, void *buf, size_t len, int flags); diff --git a/src/include/dlfcn-compat.h b/src/include/dlfcn-compat.h new file mode 100644 index 0000000..7c5e87f --- /dev/null +++ b/src/include/dlfcn-compat.h @@ -0,0 +1,83 @@ +/* +Copyright (c) 2002 Jorge Acereda <jacereda@users.sourceforge.net> & + Peter O'Gorman <ogorman@users.sourceforge.net> + +Portions may be copyright others, see the AUTHORS file included with this +distribution. + +Maintained by Peter O'Gorman <ogorman@users.sourceforge.net> + +Bug Reports and other queries should go to <ogorman@users.sourceforge.net> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#ifndef _DLFCN_H_ +#define _DLFCN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined (__GNUC__) && __GNUC__ > 3 +#define dl_restrict __restrict +#else +#define dl_restrict +#endif + +#ifndef _POSIX_SOURCE +/* + * Structure filled in by dladdr(). + */ +typedef struct dl_info { + const char *dli_fname; /* Pathname of shared object */ + void *dli_fbase; /* Base address of shared object */ + const char *dli_sname; /* Name of nearest symbol */ + void *dli_saddr; /* Address of nearest symbol */ +} Dl_info; + +extern int dladdr(const void * dl_restrict, Dl_info * dl_restrict); +#endif /* ! _POSIX_SOURCE */ + +extern int dlclose(void * handle); +extern char * dlerror(void); +extern void * dlopen(const char *path, int mode); +extern void * dlsym(void * dl_restrict handle, const char * dl_restrict symbol); + +#define RTLD_LAZY 0x1 +#define RTLD_NOW 0x2 +#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 0x8 + +#ifndef _POSIX_SOURCE +#define RTLD_NOLOAD 0x10 +#define RTLD_NODELETE 0x80 + +/* + * Special handle arguments for dlsym(). + */ +#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ +#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ +#endif /* ! _POSIX_SOURCE */ + +#ifdef __cplusplus +} +#endif + +#endif /* _DLFCN_H_ */ diff --git a/src/include/endian.h b/src/include/endian.h new file mode 100644 index 0000000..f5e20fb --- /dev/null +++ b/src/include/endian.h @@ -0,0 +1,60 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Asterisk architecture endianess compatibility definitions + * + * Copyright (C) 1999 - 2005, Digium, Inc. + * + * Mark Spencer <markster@digium.com> + * + * This program is free software, distributed under the terms of + * the GNU Lesser General Public License. Other components of + * Asterisk are distributed under The GNU General Public License + * only. + */ + +#ifndef _ASTERISK_ENDIAN_H +#define _ASTERISK_ENDIAN_H + +/* + * Autodetect system endianess + */ + +#ifdef SOLARIS +#include "solaris-compat/compat.h" +#endif + +#ifndef __BYTE_ORDER +#ifdef __linux__ +#include <endian.h> +#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#if defined(__OpenBSD__) +#include <machine/types.h> +#endif /* __OpenBSD__ */ +#include <machine/endian.h> +#define __BYTE_ORDER BYTE_ORDER +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#else +#ifdef __LITTLE_ENDIAN__ +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif /* __LITTLE_ENDIAN */ + +#if defined(i386) || defined(__i386__) +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif /* defined i386 */ + +#if defined(sun) && defined(unix) && defined(sparc) +#define __BYTE_ORDER __BIG_ENDIAN +#endif /* sun unix sparc */ + +#endif /* linux */ + +#endif /* __BYTE_ORDER */ + +#ifndef __BYTE_ORDER +#error Need to know endianess +#endif /* __BYTE_ORDER */ + +#endif /* _ASTERISK_ENDIAN_H */ + diff --git a/src/include/md5.h b/src/include/md5.h new file mode 100644 index 0000000..30ac30c --- /dev/null +++ b/src/include/md5.h @@ -0,0 +1,18 @@ +#ifndef MD5_H +#define MD5_H + +#include <inttypes.h> + +struct MD5Context { + uint32_t buf[4]; + uint32_t bits[2]; + unsigned char in[64]; +}; + +void MD5Init(struct MD5Context *context); +void MD5Update(struct MD5Context *context, unsigned char const *buf, + unsigned len); +void MD5Final(unsigned char digest[16], struct MD5Context *context); +void MD5Transform(uint32_t buf[4], uint32_t const in[16]); + +#endif /* !MD5_H */ diff --git a/src/include/poll-compat.h b/src/include/poll-compat.h new file mode 100644 index 0000000..79eab15 --- /dev/null +++ b/src/include/poll-compat.h @@ -0,0 +1,101 @@ +/*---------------------------------------------------------------------------*\ + $Id: poll-compat.h,v 1.1 2003/10/26 18:50:49 markster Exp $ + + NAME + + poll - select(2)-based poll() emulation function for BSD systems. + + SYNOPSIS + #include "poll.h" + + struct pollfd + { + int fd; + short events; + short revents; + } + + int poll (struct pollfd *pArray, unsigned long n_fds, int timeout) + + DESCRIPTION + + This file, and the accompanying "poll.c", implement the System V + poll(2) system call for BSD systems (which typically do not provide + poll()). Poll() provides a method for multiplexing input and output + on multiple open file descriptors; in traditional BSD systems, that + capability is provided by select(). While the semantics of select() + differ from those of poll(), poll() can be readily emulated in terms + of select() -- which is how this function is implemented. + + REFERENCES + Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990. + + NOTES + 1. This software requires an ANSI C compiler. + + LICENSE + + This software is released under the following license: + + Copyright (c) 1995-2002 Brian M. Clapper + All rights reserved. + + Redistribution and use in source and binary forms are + permitted provided that: (1) source distributions retain + this entire copyright notice and comment; (2) modifications + made to the software are prominently mentioned, and a copy + of the original software (or a pointer to its location) are + included; and (3) distributions including binaries display + the following acknowledgement: "This product includes + software developed by Brian M. Clapper <bmc@clapper.org>" + in the documentation or other materials provided with the + distribution. The name of the author may not be used to + endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE. + + Effectively, this means you can do what you want with the software + except remove this notice or take advantage of the author's name. + If you modify the software and redistribute your modified version, + you must indicate that your version is a modification of the + original, and you must provide either a pointer to or a copy of the + original. +\*---------------------------------------------------------------------------*/ + +#ifndef _POLL_EMUL_H_ +#define _POLL_EMUL_H_ + +#define POLLIN 0x01 +#define POLLPRI 0x02 +#define POLLOUT 0x04 +#define POLLERR 0x08 +#define POLLHUP 0x10 +#define POLLNVAL 0x20 + +struct pollfd +{ + int fd; + short events; + short revents; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if (__STDC__ > 0) || defined(__cplusplus) +extern int poll (struct pollfd *pArray, unsigned long n_fds, int timeout); +#else +extern int poll(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _POLL_EMUL_H_ */ diff --git a/src/include/ssl.h b/src/include/ssl.h new file mode 100644 index 0000000..123bd43 --- /dev/null +++ b/src/include/ssl.h @@ -0,0 +1,89 @@ +/* + * ssl_addon: Encrypts the asterisk management interface + * + * Copyrights: + * Copyright (C) 2005-2006, Tello Corporation, Inc. + * + * Contributors: + * Remco Treffkorn(Architect) and Mahesh Karoshi + * + * This program is free software, distributed under the terms of + * the GNU Lesser (Library) General Public License + * + * Copyright on this file is disclaimed to Digium for inclusion in Asterisk + */ + +#ifndef _SSL_ADDON_H_ +#define _SSL_ADDON_H_ + +#include <openssl/ssl.h> +#include "astmanproxy.h" + +int connect_nonb(struct mansession *a); + +/*! \brief + This data structure holds the additional SSL data needed to use the ssl functions. + The negative fd is used as an index into this data structure (after processing). + Choose SEC_MAX to be impossibly large for the application. +*/ +#define SEC_MAX 16 +struct { + int fd; + SSL* ssl; +} sec_channel[SEC_MAX]; + +/*! \brief + this has to be called before any other function dealing with ssl. +*/ +int init_secure(char* certfile); + +/*! \brief + Returns the real fd, that is received from os, when we accept the connection. +*/ +int get_real_fd(int fd); + +/*! \brief + Returns the ssl structure from the fd. +*/ +SSL *get_ssl(int fd); + +/*! \brief + Returns the availabe security slot. This restricts the maximun number of security connection, + the asterisk server can have for AMI. +*/ +int sec_getslot(void); + +/*! \brief + Accepts the connection, if the security is enabled it returns the negative fd. -1 is flase, -2, -3 + etc are ssl connections. +*/ +int saccept(int s); + +/*! \brief + Sends the data over secured or unsecured connections. +*/ +int m_send(int fd, const void *data, size_t len); + + +/*! \brief + Receives the connection from either ssl or fd. +*/ +int m_recv(int s, void *buf, size_t len, int flags); + + +/*! \brief + Needs to be called instead of close() to close a socket. + It also closes the ssl meta connection. +*/ + +int close_sock(int socket); + +int errexit(char s[]); + +int is_encrypt_request(int sslclhellotimeout, int fd); +#ifdef __cplusplus +} +#endif + + +#endif |