git ssb

0+

cel / sslh



Tree: 9bcb2cdd7a920ebc78b59d0b5797d678424aa93a

Files: 9bcb2cdd7a920ebc78b59d0b5797d678424aa93a / common.h

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

Built with git-ssb-web