proxy.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. 3APA3A simpliest proxy server
  3. (c) 2002-2009 by ZARAZA <3APA3A@security.nnov.ru>
  4. please read License Agreement
  5. $Id: proxy.h,v 1.92 2012-04-11 23:01:20 vlad Exp $
  6. */
  7. #define COPYRIGHT "(c)2000-2009 3APA3A, Vladimir Dubrovin & 3proxy.ru\n"\
  8. "Documentation and sources: http://3proxy.ru/\n"\
  9. "Please read license agreement in \'copying\' file.\n"\
  10. "You may not use this program without accepting license agreement"
  11. #ifndef _3PROXY_H_
  12. #define _3PROXY_H_
  13. #include "version.h"
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include <sys/timeb.h>
  21. #include <fcntl.h>
  22. #include <time.h>
  23. #define MAXUSERNAME 128
  24. #define _PASSWORD_LEN 256
  25. #define MAXNSERVERS 5
  26. #define ALLOW 0
  27. #define DENY 1
  28. #define REDIRECT 2
  29. #define BANDLIM 3
  30. #define NOBANDLIM 4
  31. #define COUNTIN 5
  32. #define NOCOUNTIN 6
  33. #define COUNTOUT 7
  34. #define NOCOUNTOUT 8
  35. #define UDPBUFSIZE 16384
  36. #define TCPBUFSIZE 4096
  37. #ifdef _WIN32
  38. #include <winsock2.h>
  39. #ifndef _WINCE
  40. #include <io.h>
  41. #else
  42. #include <sys/unistd.h>
  43. #endif
  44. #include <process.h>
  45. #define SASIZETYPE int
  46. #define SHUT_RDWR SD_BOTH
  47. #else
  48. #ifndef FD_SETSIZE
  49. #define FD_SETSIZE 4096
  50. #endif
  51. #include <errno.h>
  52. #include <signal.h>
  53. #include <sys/uio.h>
  54. #include <sys/time.h>
  55. #include <unistd.h>
  56. #include <pthread.h>
  57. #include <syslog.h>
  58. #endif
  59. #ifdef __CYGWIN__
  60. #include <windows.h>
  61. #define daemonize() FreeConsole()
  62. #define SLEEPTIME 1000
  63. #undef _WIN32
  64. #elif _WIN32
  65. #ifdef errno
  66. #undef errno
  67. #endif
  68. #define errno WSAGetLastError()
  69. #define EAGAIN WSAEWOULDBLOCK
  70. #define EINTR WSAEWOULDBLOCK
  71. #define SLEEPTIME 1
  72. #define usleep Sleep
  73. #define pthread_self GetCurrentThreadId
  74. #define getpid GetCurrentProcessId
  75. #define pthread_t unsigned
  76. #ifndef _WINCE
  77. #define daemonize() FreeConsole()
  78. #else
  79. #define daemonize()
  80. #endif
  81. #define socket(x, y, z) WSASocket(x, y, z, NULL, 0, 0)
  82. #define accept(x, y, z) WSAAccept(x, y, z, NULL, 0)
  83. #define ftruncate chsize
  84. #else
  85. #include <pthread.h>
  86. #ifndef PTHREAD_STACK_MIN
  87. #define PTHREAD_STACK_MIN 32768
  88. #define sockerror strerror
  89. #endif
  90. #define daemonize() daemon(1,1)
  91. #define SLEEPTIME 1000
  92. #ifndef O_BINARY
  93. #define O_BINARY 0
  94. #endif
  95. #endif
  96. #ifndef NOODBC
  97. #ifndef _WIN32
  98. #include <sqltypes.h>
  99. #endif
  100. #include <sql.h>
  101. #include <sqlext.h>
  102. #endif
  103. #ifdef _WIN32
  104. #define strcasecmp stricmp
  105. #define strncasecmp strnicmp
  106. #else
  107. extern pthread_attr_t pa;
  108. #endif
  109. #ifndef SOCKET_ERROR
  110. #define SOCKET_ERROR -1
  111. #endif
  112. #ifndef isnumber
  113. #define isnumber(n) (n >= '0' && n <= '9')
  114. #endif
  115. #ifndef ishex
  116. #define ishex(n) ((n >= '0' && n <= '9') || (n >= 'a' && n<='f') || (n >= 'A' && n <= 'F'))
  117. #endif
  118. #define isallowed(n) ((n >= '0' && n <= '9') || (n >= 'a' && n <= 'z') || (n >= 'A' && n <= 'Z') || (n >= '*' && n <= '/') || n == '_')
  119. #include "structures.h"
  120. extern RESOLVFUNC resolvfunc;
  121. extern int wday;
  122. extern time_t basetime;
  123. extern int timetoexit;
  124. extern struct extparam conf;
  125. int sockmap(struct clientparam * param, int timeo);
  126. int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to);
  127. int socksendto(SOCKET sock, struct sockaddr_in * sin, unsigned char * buf, int bufsize, int to);
  128. int sockrecvfrom(SOCKET sock, struct sockaddr_in * sin, unsigned char * buf, int bufsize, int to);
  129. int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec);
  130. int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec);
  131. int sockfillbuffcli(struct clientparam * param, unsigned long size, int timeosec);
  132. int sockfillbuffsrv(struct clientparam * param, unsigned long size, int timeosec);
  133. int sockgetlinebuf(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to);
  134. int dobuf(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec);
  135. int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, struct tm* tm, char * format);
  136. extern FILE * stdlog;
  137. void logstdout(struct clientparam * param, const unsigned char *s);
  138. void logsyslog(struct clientparam * param, const unsigned char *s);
  139. void lognone(struct clientparam * param, const unsigned char *s);
  140. #ifndef NOSQL
  141. void logsql(struct clientparam * param, const unsigned char *s);
  142. int init_sql(char * s);
  143. void close_sql();
  144. #endif
  145. int doconnect(struct clientparam * param);
  146. int nbnameauth(struct clientparam * param);
  147. int alwaysauth(struct clientparam * param);
  148. int ipauth(struct clientparam * param);
  149. int doauth(struct clientparam * param);
  150. int strongauth(struct clientparam * param);
  151. void trafcountfunc(struct clientparam *param);
  152. unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nbytesout);
  153. int scanaddr(const unsigned char *s, unsigned long * ip, unsigned long * mask);
  154. int myinet_ntoa(struct in_addr in, char * buf);
  155. extern unsigned long nservers[MAXNSERVERS];
  156. extern unsigned long authnserver;
  157. unsigned long getip(unsigned char *name);
  158. unsigned long getip46(int family, unsigned char *name, struct sockaddr *sa);
  159. unsigned long myresolver(unsigned char *);
  160. unsigned long fakeresolver (unsigned char *name);
  161. int initdnshashtable(unsigned nhashsize);
  162. void freeparam(struct clientparam * param);
  163. void clearstat(struct clientparam * param);
  164. void dumpcounters(struct trafcount *tl, int counterd);
  165. extern struct auth authfuncs[];
  166. int reload (void);
  167. extern int paused;
  168. extern int demon;
  169. unsigned char * mycrypt(const unsigned char *key, const unsigned char *salt, unsigned char *buf);
  170. unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int tohex);
  171. int de64 (const unsigned char *in, unsigned char *out, int maxlen);
  172. unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen);
  173. void tohex(unsigned char *in, unsigned char *out, int len);
  174. void fromhex(unsigned char *in, unsigned char *out, int len);
  175. int ftplogin(struct clientparam *param, char *buf, int *inbuf);
  176. int ftpcd(struct clientparam *param, unsigned char* path, char *buf, int *inbuf);
  177. int ftpsyst(struct clientparam *param, unsigned char *buf, unsigned len);
  178. int ftppwd(struct clientparam *param, unsigned char *buf, unsigned len);
  179. int ftptype(struct clientparam *param, unsigned char* f_type);
  180. int ftpres(struct clientparam *param, unsigned char * buf, int len);
  181. SOCKET ftpcommand(struct clientparam *param, unsigned char * command, unsigned char *arg);
  182. int text2unicode(const char * text, char * buf, int buflen);
  183. void unicode2text(const char *unicode, char * buf, int len);
  184. void genchallenge(struct clientparam *param, char * challenge, char *buf);
  185. void mschap(const unsigned char *win_password,
  186. const unsigned char *challenge, unsigned char *response);
  187. struct hashtable;
  188. void hashadd(struct hashtable *ht, const unsigned char* name, unsigned long value, time_t expires);
  189. int parsehostname(char *hostname, struct clientparam *param, unsigned short port);
  190. int parseusername(char *username, struct clientparam *param, int extpasswd);
  191. int parseconnusername(char *username, struct clientparam *param, int extpasswd, unsigned short port);
  192. int ACLmatches(struct ace* acentry, struct clientparam * param);
  193. unsigned long udpresolve(unsigned char * name, unsigned *retttl, struct clientparam* param, int makeauth);
  194. struct ace * copyacl (struct ace *ac);
  195. struct auth * copyauth (struct auth *);
  196. void freeacl(struct ace *ac);
  197. void freeauth(struct auth *);
  198. void freefilter(struct filter *filter);
  199. void freeconf(struct extparam *confp);
  200. struct passwords * copypwl (struct passwords *pwl);
  201. void freepwl(struct passwords *pw);
  202. void copyfilter(struct filter *, struct srvparam *srv);
  203. FILTER_ACTION makefilters (struct srvparam *srv, struct clientparam *param);
  204. FILTER_ACTION handlereqfilters(struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
  205. FILTER_ACTION handlehdrfilterscli(struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
  206. FILTER_ACTION handlehdrfilterssrv(struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
  207. FILTER_ACTION handlepredatflt(struct clientparam *param);
  208. FILTER_ACTION handledatfltcli(struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
  209. FILTER_ACTION handledatfltsrv(struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p);
  210. void srvinit(struct srvparam * srv, struct clientparam *param);
  211. void srvinit2(struct srvparam * srv, struct clientparam *param);
  212. void srvfree(struct srvparam * srv);
  213. unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
  214. int myrand(void * entropy, int len);
  215. #ifdef WITH_STD_MALLOC
  216. #define myalloc malloc
  217. #define myfree free
  218. #define myrealloc realloc
  219. #define mystrdup strdup
  220. #else
  221. void *myalloc(size_t size);
  222. void myfree(void *ptr);
  223. void *myrealloc(void *ptr, size_t size);
  224. char * mystrdup(const char *str);
  225. #endif
  226. extern char *copyright;
  227. #define SERVICES 5
  228. void * dnsprchild(struct clientparam * param);
  229. void * pop3pchild(struct clientparam * param);
  230. void * smtppchild(struct clientparam * param);
  231. void * proxychild(struct clientparam * param);
  232. void * sockschild(struct clientparam * param);
  233. void * tcppmchild(struct clientparam * param);
  234. void * icqprchild(struct clientparam * param);
  235. void * msnprchild(struct clientparam * param);
  236. void * udppmchild(struct clientparam * param);
  237. void * adminchild(struct clientparam * param);
  238. void * ftpprchild(struct clientparam * param);
  239. struct datatype;
  240. struct dictionary;
  241. struct node;
  242. struct property;
  243. extern pthread_mutex_t bandlim_mutex;
  244. extern pthread_mutex_t hash_mutex;
  245. extern pthread_mutex_t tc_mutex;
  246. extern pthread_mutex_t pwl_mutex;
  247. #ifndef NOODBC
  248. extern pthread_mutex_t odbc_mutex;
  249. #endif
  250. extern struct hashtable dns_table;
  251. extern struct datatype datatypes[64];
  252. extern struct commands commandhandlers[];
  253. #ifdef _WINCE
  254. char * CEToUnicode (const char *str);
  255. int cesystem(const char *str);
  256. int ceparseargs(const char *str);
  257. extern char * ceargv[32];
  258. #define system(S) cesystem(S)
  259. #endif
  260. #define WEBBANNERS 35
  261. #endif