git ssb

0+

cel / sslh



Tree: 59c9be54ad6423c26ae1fb8012f0ecf219e26ceb

Files: 59c9be54ad6423c26ae1fb8012f0ecf219e26ceb / common.h

3422 bytesRaw
1#ifndef __COMMON_H_
2#define __COMMON_H_
3
4/* FD_SETSIZE is 64 on Cygwin, which is really low. Just redefining it is
5 * enough for the macros to adapt (http://support.microsoft.com/kb/111855)
6 */
7#ifdef __CYGWIN__
8#define FD_SETSIZE 4096
9#endif
10
11#define _GNU_SOURCE
12#include <sys/types.h>
13#include <fcntl.h>
14#include <errno.h>
15#include <string.h>
16#include <unistd.h>
17#include <stdlib.h>
18#include <stdio.h>
19#include <signal.h>
20#include <sys/socket.h>
21#include <sys/wait.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
24#include <netdb.h>
25#include <pwd.h>
26#include <syslog.h>
27#include <libgen.h>
28#include <time.h>
29#include <getopt.h>
30
31#ifndef VERSION
32#define VERSION "v?"
33#endif
34
35#define CHECK_RES_DIE(res, str) \
36 if (res == -1) { \
37 perror(str); \
38 exit(1); \
39 }
40
41#define CHECK_RES_RETURN(res, str) \
42 if (res == -1) { \
43 log_message(LOG_CRIT, "%s:%d:%s\n", str, errno, strerror(errno)); \
44 return res; \
45 }
46
47#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
48
49#if 1
50#define TRACE fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
51#else
52#define TRACE
53#endif
54
55enum connection_state {
56 ST_PROBING=1, /* Waiting for timeout to find where to forward */
57 ST_SHOVELING /* Connexion is established */
58};
59
60/* this is used to pass protocols through the command-line parameter parsing */
61#define PROT_SHIFT 1000 /* protocol options will be 1000, 1001, etc */
62
63/* A 'queue' is composed of a file descriptor (which can be read from or
64 * written to), and a queue for defered write data */
65struct queue {
66 int fd;
67 void *begin_defered_data;
68 void *defered_data;
69 int defered_data_size;
70};
71
72struct connection {
73 enum connection_state state;
74 time_t probe_timeout;
75
76 /* q[0]: queue for external connection (client);
77 * q[1]: queue for internal connection (httpd or sshd);
78 * */
79 struct queue q[2];
80};
81
82#define FD_CNXCLOSED 0
83#define FD_NODATA -1
84#define FD_STALLED -2
85
86
87/* common.c */
88void init_cnx(struct connection *cnx);
89int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name);
90int fd2fd(struct queue *target, struct queue *from);
91char* sprintaddr(char* buf, size_t size, struct addrinfo *a);
92void resolve_name(struct addrinfo **out, char* fullname);
93struct proto* probe_client_protocol(struct connection *cnx);
94void log_connection(struct connection *cnx);
95int check_access_rights(int in_socket, const char* service);
96void setup_signals(void);
97void setup_syslog(const char* bin_name);
98void drop_privileges(const char* user_name);
99void write_pid_file(const char* pidfile);
100void log_message(int type, char* msg, ...);
101void dump_connection(struct connection *cnx);
102int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port);
103
104int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
105
106int defer_write(struct queue *q, void* data, int data_size);
107int flush_defered(struct queue *q);
108
109extern int probing_timeout, verbose, inetd, foreground,
110 background, transparent, numeric;
111extern struct sockaddr_storage addr_ssl, addr_ssh, addr_openvpn;
112extern struct addrinfo *addr_listen;
113extern const char* USAGE_STRING;
114extern const char* user_name, *pid_file;
115extern const char* server_type;
116
117/* sslh-fork.c */
118void start_shoveler(int);
119
120void main_loop(int *listen_sockets, int num_addr_listen);
121
122#endif
123

Built with git-ssb-web