git ssb

0+

cel / sslh



Tree: 74de4f4fd22375fae4d21eeb920326fc6a905586

Files: 74de4f4fd22375fae4d21eeb920326fc6a905586 / common.h

3470 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#ifdef LIBCAP
32#include <sys/prctl.h>
33#include <sys/capability.h>
34#endif
35
36#include "version.h"
37
38#define CHECK_RES_DIE(res, str) \
39 if (res == -1) { \
40 perror(str); \
41 exit(1); \
42 }
43
44#define CHECK_RES_RETURN(res, str) \
45 if (res == -1) { \
46 log_message(LOG_CRIT, "%s:%d:%s\n", str, errno, strerror(errno)); \
47 return res; \
48 }
49
50#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
51
52#if 1
53#define TRACE fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
54#else
55#define TRACE
56#endif
57
58#ifndef IP_FREEBIND
59#define IP_FREEBIND 0
60#endif
61
62enum connection_state {
63 ST_PROBING=1, /* Waiting for timeout to find where to forward */
64 ST_SHOVELING /* Connexion is established */
65};
66
67/* this is used to pass protocols through the command-line parameter parsing */
68#define PROT_SHIFT 1000 /* protocol options will be 1000, 1001, etc */
69
70/* A 'queue' is composed of a file descriptor (which can be read from or
71 * written to), and a queue for deferred write data */
72struct queue {
73 int fd;
74 void *begin_deferred_data;
75 void *deferred_data;
76 int deferred_data_size;
77};
78
79struct connection {
80 enum connection_state state;
81 time_t probe_timeout;
82 struct proto *proto;
83
84 /* q[0]: queue for external connection (client);
85 * q[1]: queue for internal connection (httpd or sshd);
86 * */
87 struct queue q[2];
88};
89
90#define FD_CNXCLOSED 0
91#define FD_NODATA -1
92#define FD_STALLED -2
93
94
95/* common.c */
96void init_cnx(struct connection *cnx);
97int connect_addr(struct connection *cnx, int fd_from);
98int fd2fd(struct queue *target, struct queue *from);
99char* sprintaddr(char* buf, size_t size, struct addrinfo *a);
100void resolve_name(struct addrinfo **out, char* fullname);
101void log_connection(struct connection *cnx);
102int check_access_rights(int in_socket, const char* service);
103void setup_signals(void);
104void setup_syslog(const char* bin_name);
105void drop_privileges(const char* user_name);
106void write_pid_file(const char* pidfile);
107void log_message(int type, char* msg, ...);
108void dump_connection(struct connection *cnx);
109int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port);
110
111int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
112
113int defer_write(struct queue *q, void* data, int data_size);
114int flush_deferred(struct queue *q);
115
116extern int probing_timeout, verbose, inetd, foreground,
117 background, transparent, numeric;
118extern struct sockaddr_storage addr_ssl, addr_ssh, addr_openvpn;
119extern struct addrinfo *addr_listen;
120extern const char* USAGE_STRING;
121extern const char* user_name, *pid_file;
122extern const char* server_type;
123
124/* sslh-fork.c */
125void start_shoveler(int);
126
127void main_loop(int *listen_sockets, int num_addr_listen);
128
129#endif
130

Built with git-ssb-web