git ssb

0+

cel / sslh



Tree: ae008179f033c8409c69b13787a539351bace626

Files: ae008179f033c8409c69b13787a539351bace626 / common.h

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

Built with git-ssb-web