-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinifile.h
136 lines (117 loc) · 7.59 KB
/
inifile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* ------------------------------------------------------------------------------------------------------------------ */
/* TS-Warp - Transparent proxy server and traffic wrapper */
/* ------------------------------------------------------------------------------------------------------------------ */
/*
* Copyright (c) 2021-2024, Mikhail Zakharov <zmey20000@yahoo.com>
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* -- INI-file processing ------------------------------------------------------------------------------------------- */
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
/* ------------------------------------------------------------------------------------------------------------------ */
typedef struct ini_section {
char *section_name; /* Section name */
uint8_t section_balance; /* Balance proxy server on accessibility */
struct sockaddr_storage proxy_server; /* Proxy server IP-address and Port */
uint8_t proxy_type; /* Proxy type Socks: '4', '5' or HTTP: 'H' */
char *proxy_user; /* Proxy server username */
char *proxy_password; /* Proxy server user password */
char *proxy_key; /* User's private key filename */
char *proxy_key_passphrase; /* SSH2 private key passphrase */
uint8_t proxy_ssh_force_auth; /* Force SSH2 auth: 'Y' or 'N' */
struct proxy_chain *p_chain; /* Proxy chain */
struct ini_target *target_entry; /* List of target definitions */
/*NIT Pool specification */
char *nit_domain; /* NIT Domain name */
struct sockaddr_storage nit_ipaddr; /* NIT IP/address */
struct sockaddr_storage nit_ipmask; /* NIT address mask */
struct ini_section *next; /* The next INI-section */
} ini_section;
typedef struct ini_entry { /* Parsed INI-entry: var=val1[[:mod1[-mod2]]/val2] */
char *var;
char *val; /* Raw value: whatever right from the '=' char */
char *val1;
char *mod1;
char *mod2;
char *val2;
} ini_entry;
typedef struct ini_target {
int target_type; /* Hostname, Host IP, Domain, Network, Range */
char *name; /* Hostname / Domain or null */
struct sockaddr_storage ip1; /* Host IP, Net IP, First IP in Range or null and optional port number 0 65535 */
struct sockaddr_storage ip2; /* Netmask, Last IP in Range or null + port */
struct ini_target *next; /* The next range entry */
} ini_target;
typedef struct proxy_chain { /* Proxy server chains */
struct ini_section *chain_member;
struct proxy_chain *next;
} proxy_chain;
typedef struct chain_list { /* Chains as they defind in the INI */
char *txt_section; /* section name */
char *txt_chain; /* String representing sections to chain */
struct chain_list *next;
} chain_list;
/* -- INI-file entries --------------------------------------------------------------------------------------------- */
/* Section balancing modes in memory */
#define SECTION_BALANCE_NONE 0
#define SECTION_BALANCE_FAILOVER 1 /* Default */
#define SECTION_BALANCE_ROUNDROBIN 2
/* Section balancing modes in the INI-file */
#define INI_ENTRY_SECTION_BALANCE "section_balance" /* Socks section balance policy */
#define INI_ENTRY_SECTION_BALANCE_NONE "none" /* 0 */
#define INI_ENTRY_SECTION_BALANCE_FAILOVER "failover" /* 1 - Default */
#define INI_ENTRY_SECTION_BALANCE_ROUNDROBIN "roundrobin" /* 2 */
#define INI_ENTRY_PROXY_SERVER "proxy_server"
#define INI_ENTRY_PROXY_CHAIN "proxy_chain"
#define INI_ENTRY_PROXY_TYPE "proxy_type" /* H: HTTP, 4: Socks4, 5: Socks5 (default), S: SSH2 */
#define INI_ENTRY_PROXY_USER "proxy_user"
#define INI_ENTRY_PROXY_PASSWORD "proxy_password"
#define INI_ENTRY_PROXY_KEY "proxy_key" /* Currently SSH2 private key filename */
#define INI_ENTRY_PROXY_KEY_PASSPHRASE "proxy_key_passphrase" /* SSH2 private key passphrase */
#define INI_ENTRY_PROXY_SSH_FORCE_AUTH "proxy_ssh_force_auth" /* Force authmethods: 'Y' or 'N' */
/* TODO: Deprecated INI_ENTRY_SOCKS_* variables to be removed */
#define INI_ENTRY_SOCKS_SERVER "socks_server"
#define INI_ENTRY_SOCKS_CHAIN "socks_chain"
#define INI_ENTRY_SOCKS_VERSION "socks_version"
#define INI_ENTRY_SOCKS_USER "socks_user"
#define INI_ENTRY_SOCKS_PASSWORD "socks_password"
/* Target type IDs in memory */
#define INI_TARGET_NOTSET 0
#define INI_TARGET_HOST 1
#define INI_TARGET_DOMAIN 2
#define INI_TARGET_NETWORK 3
#define INI_TARGET_RANGE 4
/* Target type IDs in the INI-file */
#define INI_ENTRY_TARGET_NOTSET ""
#define INI_ENTRY_TARGET_HOST "target_host"
#define INI_ENTRY_TARGET_DOMAIN "target_domain"
#define INI_ENTRY_TARGET_NETWORK "target_network"
#define INI_ENTRY_TARGET_RANGE "target_range"
#define NS_INI_ENTRY_NIT_POOL "nit_pool" /* nit_pool = domain.net:192.168.168.0/255.255.255.0 */
/* -- Function prototypes ------------------------------------------------------------------------------------------- */
ini_section *read_ini(char *ifile_name);
void show_ini(struct ini_section *ini, int loglvl);
struct ini_section *delete_ini(struct ini_section *ini);
int pushback_ini(struct ini_section **ini, struct ini_section *target);
struct ini_section *ini_look_server(struct ini_section *ini, struct uvaddr addr_u);
int create_chains(struct ini_section *ini, struct chain_list *chain);
struct ini_section *getsection(struct ini_section *ini, char *name);
int chk_inivar(void *v, char *vi, int d);