1 /*
2    (c) 2002-2016 by Vladimir Dubrovin <3proxy@3proxy.ru>
3 
4    please read License Agreement
5 
6 */
7 
8 #include "proxy.h"
9 
pr_unsigned64(struct node * node,CBFUNC cbf,void * cb)10 static void pr_unsigned64(struct node *node, CBFUNC cbf, void*cb){
11 	char buf[32];
12 	if(node->value)(*cbf)(cb, buf, sprintf(buf, "%"PRINTF_INT64_MODIFIER"u", *(uint64_t *)node->value));
13 }
14 
pr_integer(struct node * node,CBFUNC cbf,void * cb)15 static void pr_integer(struct node *node, CBFUNC cbf, void*cb){
16 	char buf[16];
17 	if(node->value)(*cbf)(cb, buf, sprintf(buf, "%d", *(int *)node->value));
18 }
19 
pr_short(struct node * node,CBFUNC cbf,void * cb)20 static void pr_short(struct node *node, CBFUNC cbf, void*cb){
21 	char buf[8];
22 	if(node->value)(*cbf)(cb, buf, sprintf(buf, "%hu", *(unsigned short*)node->value));
23 }
24 
pr_char(struct node * node,CBFUNC cbf,void * cb)25 static void pr_char(struct node *node, CBFUNC cbf, void*cb){
26 	if(node->value)(*cbf)(cb, (char *)node->value, 1);
27 }
28 
29 
pr_unsigned(struct node * node,CBFUNC cbf,void * cb)30 static void pr_unsigned(struct node *node, CBFUNC cbf, void*cb){
31 	char buf[16];
32 	if(node->value)(*cbf)(cb, buf, sprintf(buf, "%u", *(unsigned *)node->value));
33 }
34 
pr_traffic(struct node * node,CBFUNC cbf,void * cb)35 static void pr_traffic(struct node *node, CBFUNC cbf, void*cb){
36 	char buf[16];
37 	unsigned long u1, u2;
38 	if(node->value){
39 		u1 = ((unsigned long *)node->value)[0];
40 		u2 = ((unsigned long *)node->value)[0];
41 		(*cbf)(cb, buf, sprintf(buf, "%lu", (u1>>20) + (u2<<10)));
42 	}
43 }
44 
pr_port(struct node * node,CBFUNC cbf,void * cb)45 static void pr_port(struct node *node, CBFUNC cbf, void*cb){
46 	char buf[8];
47 	if(node->value)(*cbf)(cb, buf, sprintf(buf, "%hu", ntohs(*(unsigned short*)node->value)));
48 }
49 
pr_datetime(struct node * node,CBFUNC cbf,void * cb)50 static void pr_datetime(struct node *node, CBFUNC cbf, void*cb){
51 	char *s;
52 	if(node->value){
53 		s = ctime((time_t *)node->value);
54 
55 		(*cbf)(cb, s, (int)strlen(s)-1);
56 	}
57 }
58 
pr_ip(struct node * node,CBFUNC cbf,void * cb)59 static void pr_ip(struct node *node, CBFUNC cbf, void*cb){
60 	char buf[16];
61 	if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET, node -> value, buf, 4));
62 }
63 
64 #ifndef NOIPV6
pr_ip6(struct node * node,CBFUNC cbf,void * cb)65 static void pr_ip6(struct node *node, CBFUNC cbf, void*cb){
66 	char buf[64];
67 	if(node->value)(*cbf)(cb, buf, myinet_ntop(AF_INET6, node -> value, buf, 16));
68 }
69 #endif
70 
pr_sa(struct node * node,CBFUNC cbf,void * cb)71 static void pr_sa(struct node *node, CBFUNC cbf, void*cb){
72 #ifdef NOIPV6
73 	if(node->value)pr_ip(node, cbf, cb);
74 #else
75 	char buf[64];
76 	buf[0] = '[';
77 	buf[1] = 0;
78 	inet_ntop(*SAFAMILY(node->value), SAADDR(node->value), buf+1, sizeof(buf)-10);
79 	sprintf(buf + strlen(buf), "]:%hu", (unsigned short)*SAPORT(node->value));
80 	if(node->value)(*cbf)(cb, buf, strlen(buf));
81 #endif
82 }
83 
pr_wdays(struct node * node,CBFUNC cbf,void * cb)84 static void pr_wdays(struct node *node, CBFUNC cbf, void*cb){
85 	char buf[16];
86 	int i, found = 0;
87 	if(node -> value)for(i = 0; i<8; i++){
88 		if( (1<<i) & *(int *)node -> value ) {
89 			sprintf(buf, "%s%d", found?",":"", i);
90 			(*cbf)(cb, buf, found? 2:1);
91 			found = 1;
92 		}
93 	}
94 }
95 
pr_time(struct node * node,CBFUNC cbf,void * cb)96 static void pr_time(struct node *node, CBFUNC cbf, void*cb){
97 	char buf[16];
98 	int t = *(int *)node;
99 
100 	(*cbf)(cb, buf, sprintf(buf, "%02d:%02d:%02d", (t/3600)%24, (t/60)%60, t%60));
101 }
102 
cidrprint(char * buf,unsigned long u)103 int cidrprint(char *buf, unsigned long u){
104 	unsigned long u1 = 0xffffffff;
105 	int i;
106 
107 	u = ntohl(u);
108 	for(i = 32; i && (u1!=u); i--){
109 		u1 = (u1 << 1);
110 	}
111 	if (i == 32) {
112 		return 0;
113 	}
114 	return sprintf(buf, "/%d", i);
115 }
116 
pr_cidr(struct node * node,CBFUNC cbf,void * cb)117 static void pr_cidr(struct node *node, CBFUNC cbf, void*cb){
118 	char buf[4];
119 	int i;
120 
121 	if(node->value){
122 		if ((i = cidrprint(buf, *(unsigned *)node -> value)))
123 		 (*cbf)(cb, buf, i);
124 		else (*cbf)(cb, "/32", 3);
125 	}
126 }
127 
pr_string(struct node * node,CBFUNC cbf,void * cb)128 static void pr_string(struct node *node, CBFUNC cbf, void*cb){
129 	if(node->value){
130 		(*cbf)(cb, (char*)node->value, (int)strlen((char*)node->value));
131 	}
132 	else (*cbf)(cb, "(NULL)", 6);
133 }
134 
pr_rotation(struct node * node,CBFUNC cbf,void * cb)135 static void pr_rotation(struct node *node, CBFUNC cbf, void*cb){
136 	char * lstrings[] = {
137 		"N", "C", "H", "D", "W", "M", "Y", "N"
138 	};
139 	int i;
140 
141 	if(node->value && (i = *(int*)node->value) > 1 && i < 6){
142 	 (*cbf)(cb, lstrings[i], 1);
143 	}
144 }
145 
pr_operations(struct node * node,CBFUNC cbf,void * cb)146 static void pr_operations(struct node *node, CBFUNC cbf, void*cb){
147 	char buf[64];
148 	int operation;
149 	int delim = 0;
150 
151 	*buf = 0;
152 	if(!node->value || !(operation = *(int*)node->value)){
153 		(*cbf)(cb, "*", 1);
154 		return;
155 	}
156 	if(operation & HTTP){
157 		if((operation & HTTP) == HTTP)
158 		 (*cbf)(cb, buf, sprintf(buf, "HTTP"));
159 		else
160 		 (*cbf)(cb, buf, sprintf(buf, "%s%s%s%s%s%s%s%s%s",
161 			(operation & HTTP_GET)? "HTTP_GET" : "",
162 			((operation & HTTP_GET) && (operation & (HTTP_PUT|HTTP_POST|HTTP_HEAD|HTTP_OTHER)))? "," : "",
163 			(operation & HTTP_PUT)? "HTTP_PUT" : "",
164 			((operation & HTTP_PUT) && (operation & (HTTP_POST|HTTP_HEAD|HTTP_OTHER)))? "," : "",
165 			(operation & HTTP_POST)? "HTTP_POST" : "",
166 			((operation & HTTP_POST) && (operation & (HTTP_HEAD|HTTP_OTHER)))? "," : "",
167 			(operation & HTTP_HEAD)? "HTTP_HEAD" : "",
168 			((operation & HTTP_HEAD) && (operation & HTTP_OTHER))? "," : "",
169 			(operation & HTTP_OTHER)? "HTTP_OTHER" : ""));
170 		delim = 1;
171 	}
172 	if(operation & HTTP_CONNECT){
173 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "HTTP_CONNECT"));
174 		delim = 1;
175 	}
176 	if(operation & FTP) {
177 		if((operation & FTP) == FTP)
178 		 (*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "FTP"));
179 		else
180 		 (*cbf)(cb, buf, sprintf(buf, "%s%s%s%s%s%s",
181 			delim? ",":"",
182 			(operation & FTP_GET)? "FTP_GET" : "",
183 			((operation & FTP_GET) && (operation & (FTP_PUT|FTP_LIST)))? ",":"",
184 			(operation & FTP_PUT)? "FTP_PUT" : "",
185 			((operation & FTP_PUT) && (operation & FTP_LIST))? ",":"",
186 			(operation & FTP_LIST)? "FTP_LIST" : ""));
187 		delim = 1;
188 	}
189 	if(operation & CONNECT){
190 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "CONNECT"));
191 		delim = 1;
192 	}
193 	if(operation & BIND){
194 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "BIND"));
195 		delim = 1;
196 	}
197 	if(operation & UDPASSOC){
198 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "UDPASSOC"));
199 		delim = 1;
200 	}
201 	if(operation & ICMPASSOC){
202 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "ICMPASSOC"));
203 		delim = 1;
204 	}
205 	if(operation & DNSRESOLVE){
206 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "DNSRESOLVE"));
207 		delim = 1;
208 	}
209 	if(operation & ADMIN){
210 		(*cbf)(cb, buf, sprintf(buf, "%s%s", delim?",":"", "ADMIN"));
211 	}
212 }
213 
pr_portlist(struct node * node,CBFUNC cbf,void * cb)214 static void pr_portlist(struct node *node, CBFUNC cbf, void*cb){
215 	struct portlist *pl= (struct portlist *)node->value;
216 	char buf[16];
217 	if(!pl) {
218 		(*cbf)(cb, "*", 1);
219 		return;
220 	}
221 	for(; pl; pl = pl->next) {
222 		if(pl->startport == pl->endport)
223 		 (*cbf)(cb, buf, sprintf(buf, "%hu", pl->startport));
224 		else
225 		 (*cbf)(cb, buf, sprintf(buf, "%hu-%hu", pl->startport, pl->endport));
226 		if(pl->next)(*cbf)(cb, ",", 1);
227 	}
228 }
229 
pr_userlist(struct node * node,CBFUNC cbf,void * cb)230 static void pr_userlist(struct node *node, CBFUNC cbf, void*cb){
231 	struct userlist *ul= (struct userlist *)node->value;
232 	if(!ul) {
233 		(*cbf)(cb, "*", 1);
234 		return;
235 	}
236 	for(; ul; ul = ul->next){
237 	 (*cbf)(cb, (char *)ul->user, (int)strlen((char *)ul->user));
238 	 if(ul->next)(*cbf)(cb, ",", 1);
239 	}
240 }
241 
printiple(char * buf,struct iplist * ipl)242 int printiple(char *buf, struct iplist* ipl){
243 	 int addrlen = (ipl->family == AF_INET6)?16:4, i;
244 	 i = myinet_ntop(ipl->family, &ipl->ip_from, buf, addrlen);
245 	 if(memcmp(&ipl->ip_from, &ipl->ip_to, addrlen)){
246 		buf[i++] = '-';
247 		i += myinet_ntop(ipl->family, &ipl->ip_from, buf+i, addrlen);
248 	 }
249 	 if(ipl->next){
250 		buf[i++] = ',';
251 		buf[i++] = ' ';
252 	}
253 	return i;
254 }
255 
pr_iplist(struct node * node,CBFUNC cbf,void * cb)256 static void pr_iplist(struct node *node, CBFUNC cbf, void*cb){
257 	char buf[128];
258 	struct iplist *il = (struct iplist *)node->value;
259 
260 	if(!il) {
261 		(*cbf)(cb, "*", 1);
262 		return;
263 	}
264 	for(; il; il = il->next){
265 	 (*cbf)(cb, buf, printiple(buf, il));
266 	}
267 }
268 
ef_portlist_next(struct node * node)269 static void * ef_portlist_next(struct node *node){
270 	return (((struct portlist *)node->value) -> next);
271 }
272 
273 
ef_portlist_start(struct node * node)274 static void * ef_portlist_start(struct node *node){
275 	return &(((struct portlist *)node->value) -> startport);
276 }
277 
ef_portlist_end(struct node * node)278 static void * ef_portlist_end(struct node *node){
279 	return &(((struct portlist *)node->value) -> endport);
280 }
281 
ef_iplist_next(struct node * node)282 static void * ef_iplist_next(struct node *node){
283 	return (((struct iplist *)node->value) -> next);
284 }
285 
ef_userlist_next(struct node * node)286 static void * ef_userlist_next(struct node * node){
287 	return (((struct userlist *)node->value) -> next);
288 }
289 
ef_userlist_user(struct node * node)290 static void * ef_userlist_user(struct node * node){
291 	return (((struct userlist *)node->value) -> user);
292 }
293 
ef_pwlist_next(struct node * node)294 static void * ef_pwlist_next(struct node * node){
295 	return (((struct passwords *)node->value) -> next);
296 }
297 
ef_pwlist_user(struct node * node)298 static void * ef_pwlist_user(struct node * node){
299 	return (((struct passwords *)node->value) -> user);
300 }
301 
ef_pwlist_password(struct node * node)302 static void * ef_pwlist_password(struct node * node){
303 	return (((struct passwords *)node->value) -> password);
304 }
305 
ef_pwlist_type(struct node * node)306 static void * ef_pwlist_type(struct node * node){
307 	switch (((struct passwords *)node->value) -> pwtype) {
308 		case SYS:
309 			return "SYS";
310 		case CL:
311 			return "CL";
312 		case CR:
313 			return "CR";
314 		case NT:
315 			return "NT";
316 		case LM:
317 			return "LM";
318 		default:
319 			return "UNKNOWN";
320 	}
321 }
322 
ef_chain_next(struct node * node)323 static void * ef_chain_next(struct node * node){
324 	return ((struct chain *)node->value) -> next;
325 }
326 
ef_chain_type(struct node * node)327 static void * ef_chain_type(struct node * node){
328 	switch (((struct chain *)node->value) -> type) {
329 		case R_TCP:
330 			return "tcp";
331 		case R_CONNECT:
332 			return "connect";
333 		case R_SOCKS4:
334 			return "socks4";
335 		case R_SOCKS5:
336 			return "socks5";
337 		case R_HTTP:
338 			return "http";
339 		case R_FTP:
340 			return "ftp";
341 		case R_POP3:
342 			return "pop3";
343 		default:
344 			return "";
345 	}
346 }
347 
ef_chain_addr(struct node * node)348 static void * ef_chain_addr(struct node * node){
349 	return &((struct chain *)node->value) -> addr;
350 }
351 
ef_chain_weight(struct node * node)352 static void * ef_chain_weight(struct node * node){
353 	return &((struct chain *)node->value) -> weight;
354 }
355 
ef_chain_user(struct node * node)356 static void * ef_chain_user(struct node * node){
357 	return ((struct chain *)node->value) -> extuser;
358 }
359 
ef_chain_password(struct node * node)360 static void * ef_chain_password(struct node * node){
361 	return ((struct chain *)node->value) -> extpass;
362 }
363 
ef_ace_next(struct node * node)364 static void * ef_ace_next(struct node * node){
365 	return ((struct ace *)node->value) -> next;
366 }
367 
368 
369 char * aceaction (int action);
370 
ef_ace_type(struct node * node)371 static void * ef_ace_type(struct node * node){
372 	return aceaction(((struct ace *)node->value) -> action);
373 }
374 
375 
ef_ace_operations(struct node * node)376 static void * ef_ace_operations(struct node * node){
377 	if(!((struct ace *)node->value) -> operation) return NULL;
378 	return &((struct ace *)node->value) -> operation;
379 }
380 
ef_ace_users(struct node * node)381 static void * ef_ace_users(struct node * node){
382 	return ((struct ace *)node->value) -> users;
383 }
384 
ef_ace_src(struct node * node)385 static void * ef_ace_src(struct node * node){
386 	return ((struct ace *)node->value) -> src;
387 }
388 
389 
ef_ace_dst(struct node * node)390 static void * ef_ace_dst(struct node * node){
391 	return ((struct ace *)node->value) -> dst;
392 }
393 
394 
ef_ace_ports(struct node * node)395 static void * ef_ace_ports(struct node * node){
396 	return ((struct ace *)node->value) -> ports;
397 }
398 
ef_ace_chain(struct node * node)399 static void * ef_ace_chain(struct node * node){
400 	return ((struct ace *)node->value) -> chains;
401 }
402 
ef_ace_weekdays(struct node * node)403 static void * ef_ace_weekdays(struct node * node){
404 	return (((struct ace *)node->value) -> wdays) ? &((struct ace *)node->value) -> wdays : NULL;
405 }
406 
ef_ace_period(struct node * node)407 static void * ef_ace_period(struct node * node){
408 	return ((struct ace *)node->value) -> periods;
409 }
410 
411 
ef_bandlimit_next(struct node * node)412 static void * ef_bandlimit_next(struct node * node){
413 	return ((struct bandlim *)node->value) -> next;
414 }
415 
ef_bandlimit_ace(struct node * node)416 static void * ef_bandlimit_ace(struct node * node){
417 	return ((struct bandlim *)node->value) -> ace;
418 }
419 
ef_bandlimit_rate(struct node * node)420 static void * ef_bandlimit_rate(struct node * node){
421 	return &((struct bandlim *)node->value) -> rate;
422 }
423 
ef_trafcounter_next(struct node * node)424 static void * ef_trafcounter_next(struct node * node){
425 	return ((struct trafcount *)node->value) -> next;
426 }
427 
ef_trafcounter_ace(struct node * node)428 static void * ef_trafcounter_ace(struct node * node){
429 	return ((struct trafcount *)node->value) -> ace;
430 }
431 
ef_trafcounter_number(struct node * node)432 static void * ef_trafcounter_number(struct node * node){
433 	return &((struct trafcount *)node->value) -> number;
434 }
435 
ef_trafcounter_type(struct node * node)436 static void * ef_trafcounter_type(struct node * node){
437 	return &((struct trafcount *)node->value) -> type;
438 }
439 
ef_trafcounter_traffic64(struct node * node)440 static void * ef_trafcounter_traffic64(struct node * node){
441 	return &((struct trafcount *)node->value) -> traf64;
442 }
ef_trafcounter_limit64(struct node * node)443 static void * ef_trafcounter_limit64(struct node * node){
444 	return &((struct trafcount *)node->value) -> traflim64;
445 }
ef_client_maxtrafin64(struct node * node)446 static void * ef_client_maxtrafin64(struct node * node){
447 	return &((struct clientparam *)node->value) -> maxtrafin64;
448 }
449 
ef_client_maxtrafout64(struct node * node)450 static void * ef_client_maxtrafout64(struct node * node){
451 	return &((struct clientparam *)node->value) -> maxtrafout64;
452 }
453 
ef_client_bytesin64(struct node * node)454 static void * ef_client_bytesin64(struct node * node){
455 	return &((struct clientparam *)node->value) -> statssrv64;
456 }
457 
ef_client_bytesout64(struct node * node)458 static void * ef_client_bytesout64(struct node * node){
459 	return &((struct clientparam *)node->value) -> statscli64;
460 }
461 
ef_trafcounter_cleared(struct node * node)462 static void * ef_trafcounter_cleared(struct node * node){
463 	return &((struct trafcount *)node->value) -> cleared;
464 }
465 
ef_trafcounter_updated(struct node * node)466 static void * ef_trafcounter_updated(struct node * node){
467 	return &((struct trafcount *)node->value) -> updated;
468 }
469 
ef_trafcounter_comment(struct node * node)470 static void * ef_trafcounter_comment(struct node * node){
471 	return ((struct trafcount *)node->value) -> comment;
472 }
473 
ef_trafcounter_disabled(struct node * node)474 static void * ef_trafcounter_disabled(struct node * node){
475 	return &((struct trafcount *)node->value) -> disabled;
476 }
477 
ef_server_next(struct node * node)478 static void * ef_server_next(struct node * node){
479 	return ((struct srvparam *)node->value) -> next;
480 }
481 
ef_server_type(struct node * node)482 static void * ef_server_type(struct node * node){
483 	int service = ((struct srvparam *)node->value) -> service;
484 	return (service>=0 && service < 15)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
485 }
486 
ef_server_child(struct node * node)487 static void * ef_server_child(struct node * node){
488 	return ((struct srvparam *)node->value) -> child;
489 }
490 
ef_server_auth(struct node * node)491 static void * ef_server_auth(struct node * node){
492 	AUTHFUNC af = ((struct srvparam *)node->value) -> authfunc;
493 
494 	if(af == alwaysauth) return "none";
495 	if(af == ipauth) return "iponly";
496 	if(af == strongauth) return "strong";
497 	return "uknown";
498 }
499 
ef_server_childcount(struct node * node)500 static void * ef_server_childcount(struct node * node){
501 	return &((struct srvparam *)node->value) -> childcount;
502 }
503 
ef_server_log(struct node * node)504 static void * ef_server_log(struct node * node){
505 	if(((struct srvparam *)node->value) -> logfunc == lognone)	return "none";
506 #ifndef NORADIUS
507 	else if(((struct srvparam *)node->value) -> logfunc == logradius)	return "radius";
508 #endif
509 	else if(((struct srvparam *)node->value) -> logfunc == logstdout)
510 		return (((struct srvparam *)node->value) -> logtarget)?"file":"stdout";
511 #ifndef _WIN32
512 	else if(((struct srvparam *)node->value) -> logfunc == logsyslog)	return "syslog";
513 #endif
514 #ifndef NOODBC
515 	else if(((struct srvparam *)node->value) -> logfunc == logsql)	return "odbc";
516 #endif
517 	return NULL;
518 }
519 
ef_server_logformat(struct node * node)520 static void * ef_server_logformat(struct node * node){
521 	return ((struct srvparam *)node->value) -> logformat;
522 }
523 
ef_server_nonprintable(struct node * node)524 static void * ef_server_nonprintable(struct node * node){
525 	return ((struct srvparam *)node->value) -> nonprintable;
526 }
527 
ef_server_replacement(struct node * node)528 static void * ef_server_replacement(struct node * node){
529 	if(((struct srvparam *)node->value) -> nonprintable)return &((struct srvparam *)node->value) -> replace;
530 	return NULL;
531 }
532 
ef_server_logtarget(struct node * node)533 static void * ef_server_logtarget(struct node * node){
534 	return ((struct srvparam *)node->value) -> logtarget;
535 }
536 
537 
ef_server_target(struct node * node)538 static void * ef_server_target(struct node * node){
539 	return ((struct srvparam *)node->value) -> target;
540 }
541 
ef_server_targetport(struct node * node)542 static void * ef_server_targetport(struct node * node){
543 	return &((struct srvparam *)node->value) -> targetport;
544 }
545 
ef_server_intsa(struct node * node)546 static void * ef_server_intsa(struct node * node){
547 	return &((struct srvparam *)node->value) -> intsa;
548 }
549 
ef_server_extsa(struct node * node)550 static void * ef_server_extsa(struct node * node){
551 	return &((struct srvparam *)node->value) -> extsa;
552 }
553 
554 #ifndef NOIPV6
ef_server_extsa6(struct node * node)555 static void * ef_server_extsa6(struct node * node){
556 	return &((struct srvparam *)node->value) -> extsa6;
557 }
558 #endif
559 
ef_server_acl(struct node * node)560 static void * ef_server_acl(struct node * node){
561 	return ((struct srvparam *)node->value) -> acl;
562 }
563 
ef_server_singlepacket(struct node * node)564 static void * ef_server_singlepacket(struct node * node){
565 	return &((struct srvparam *)node->value) -> singlepacket;
566 }
567 
ef_server_usentlm(struct node * node)568 static void * ef_server_usentlm(struct node * node){
569 	return &((struct srvparam *)node->value) -> usentlm;
570 }
571 
ef_server_starttime(struct node * node)572 static void * ef_server_starttime(struct node * node){
573 	return &((struct srvparam *)node->value) -> time_start;
574 }
575 
576 
ef_client_next(struct node * node)577 static void * ef_client_next(struct node * node){
578 	return ((struct clientparam *)node->value) -> next;
579 }
580 
ef_client_type(struct node * node)581 static void * ef_client_type(struct node * node){
582 	int service = ((struct clientparam *)node->value) -> service;
583 	return (service>=0 && service < 15)? (void *)conf.stringtable[SERVICES + service] : (void *)"unknown";
584 }
585 
ef_client_operation(struct node * node)586 static void * ef_client_operation(struct node * node){
587 	if(!((struct clientparam *)node->value) -> operation) return NULL;
588 	return &((struct clientparam *)node->value) -> operation;
589 
590 }
591 
ef_client_redirected(struct node * node)592 static void * ef_client_redirected(struct node * node){
593 	return &((struct clientparam *)node->value) -> redirected;
594 
595 }
596 
ef_client_hostname(struct node * node)597 static void * ef_client_hostname(struct node * node){
598 	return ((struct clientparam *)node->value) -> hostname;
599 }
600 
ef_client_username(struct node * node)601 static void * ef_client_username(struct node * node){
602 	return ((struct clientparam *)node->value) -> username;
603 }
604 
ef_client_password(struct node * node)605 static void * ef_client_password(struct node * node){
606 	return ((struct clientparam *)node->value) -> password;
607 }
608 
ef_client_extusername(struct node * node)609 static void * ef_client_extusername(struct node * node){
610 	return ((struct clientparam *)node->value) -> extusername;
611 }
612 
ef_client_extpassword(struct node * node)613 static void * ef_client_extpassword(struct node * node){
614 	return ((struct clientparam *)node->value) -> extpassword;
615 }
616 
ef_client_clisa(struct node * node)617 static void * ef_client_clisa(struct node * node){
618 	return &((struct clientparam *)node->value) -> sincr;
619 }
620 
ef_client_srvsa(struct node * node)621 static void * ef_client_srvsa(struct node * node){
622 	return &((struct clientparam *)node->value) -> sinsr;
623 }
624 
ef_client_reqsa(struct node * node)625 static void * ef_client_reqsa(struct node * node){
626 	return &((struct clientparam *)node->value) -> req;
627 }
628 
ef_client_pwtype(struct node * node)629 static void * ef_client_pwtype(struct node * node){
630 	return &((struct clientparam *)node->value) -> pwtype;
631 }
632 
ef_client_threadid(struct node * node)633 static void * ef_client_threadid(struct node * node){
634 	return &((struct clientparam *)node->value) -> threadid;
635 }
636 
ef_client_clisock(struct node * node)637 static void * ef_client_clisock(struct node * node){
638 	return &((struct clientparam *)node->value) -> clisock;
639 }
640 
ef_client_remsock(struct node * node)641 static void * ef_client_remsock(struct node * node){
642 	return &((struct clientparam *)node->value) -> remsock;
643 }
644 
ef_client_starttime(struct node * node)645 static void * ef_client_starttime(struct node * node){
646 	return &((struct clientparam *)node->value) -> time_start;
647 }
648 
ef_client_starttime_msec(struct node * node)649 static void * ef_client_starttime_msec(struct node * node){
650 	return &((struct clientparam *)node->value) -> msec_start;
651 }
652 
ef_period_fromtime(struct node * node)653 static void * ef_period_fromtime(struct node * node){
654 	return &((struct period *)node->value) -> fromtime;
655 }
656 
ef_period_totime(struct node * node)657 static void * ef_period_totime(struct node * node){
658 	return &((struct period *)node->value) -> totime;
659 }
660 
ef_period_next(struct node * node)661 static void * ef_period_next(struct node * node){
662 	return ((struct period *)node->value) -> next;
663 }
664 
665 static struct property prop_portlist[] = {
666 	{prop_portlist + 1, "start", ef_portlist_start, TYPE_PORT, "port range start"},
667 	{prop_portlist + 2, "end", ef_portlist_end, TYPE_PORT, "port range end"},
668 	{NULL, "next", ef_portlist_next, TYPE_PORTLIST, "next"}
669 };
670 
671 static struct property prop_userlist[] = {
672 	{prop_userlist+1, "user", ef_userlist_user, TYPE_STRING, "user name"},
673 	{NULL, "next", ef_userlist_next, TYPE_USERLIST, "next"}
674 };
675 
676 static struct property prop_pwlist[] = {
677 	{prop_pwlist + 1, "user", ef_pwlist_user, TYPE_STRING, "user name"},
678 	{prop_pwlist + 2, "password", ef_pwlist_password, TYPE_STRING, "password string"},
679 	{prop_pwlist + 3, "type", ef_pwlist_type, TYPE_STRING, "password type"},
680 	{NULL, "next", ef_pwlist_next, TYPE_PWLIST, "next"}
681 };
682 
683 static struct property prop_chain[] = {
684 	{prop_chain + 1, "addr", ef_chain_addr, TYPE_SA, "parent address"},
685 	{prop_chain + 2, "type", ef_chain_type, TYPE_STRING, "parent type"},
686 	{prop_chain + 3, "weight", ef_chain_weight, TYPE_SHORT, "parent weight 0-1000"},
687 	{prop_chain + 4, "user", ef_chain_user, TYPE_STRING, "parent login"},
688 	{prop_chain + 5, "password", ef_chain_password, TYPE_STRING, "parent password"},
689 	{NULL, "next", ef_chain_next, TYPE_CHAIN, "next"}
690 };
691 
692 static struct property prop_period[] = {
693 	{prop_period + 1, "fromtime", ef_period_fromtime, TYPE_TIME, "from time" },
694 	{prop_period + 2, "totime", ef_period_totime, TYPE_TIME, "to time" },
695 	{NULL, "next", ef_period_next, TYPE_PERIOD, "next"}
696 };
697 
698 static struct property prop_ace[] = {
699 	{prop_ace + 1, "type", ef_ace_type, TYPE_STRING, "ace action"},
700 	{prop_ace + 2, "operations", ef_ace_operations, TYPE_OPERATIONS, "request type"},
701 	{prop_ace + 3, "users", ef_ace_users, TYPE_USERLIST, "list of users"},
702 	{prop_ace + 4, "src", ef_ace_src, TYPE_IPLIST, "list of source ips"},
703 	{prop_ace + 5, "dst", ef_ace_dst, TYPE_IPLIST, "list of destination ips"},
704 	{prop_ace + 6, "ports", ef_ace_ports, TYPE_PORTLIST, "list of destination ports"},
705 	{prop_ace + 7, "chain", ef_ace_chain, TYPE_CHAIN, "redirect to parent(s)"},
706 	{prop_ace + 8, "wdays", ef_ace_weekdays, TYPE_WEEKDAYS, "days of week"},
707 	{prop_ace + 9, "periods", ef_ace_period, TYPE_PERIOD, "time of the day"},
708 	{NULL, "next", ef_ace_next, TYPE_ACE, "next"}
709 };
710 
711 static struct property prop_bandlimit[] = {
712 	{prop_bandlimit + 1, "ace", ef_bandlimit_ace, TYPE_ACE, "acl to apply"},
713 	{prop_bandlimit + 2, "rate", ef_bandlimit_rate, TYPE_UNSIGNED, "max allowed bandwidth"},
714 	{NULL, "next", ef_bandlimit_next, TYPE_BANDLIMIT, "next"}
715 };
716 
717 static struct property prop_trafcounter[] = {
718 	{prop_trafcounter + 1, "disabled", ef_trafcounter_disabled, TYPE_INTEGER, "counter status"},
719 	{prop_trafcounter + 2, "ace", ef_trafcounter_ace, TYPE_ACE, "traffic to count"},
720 	{prop_trafcounter + 3, "number", ef_trafcounter_number, TYPE_UNSIGNED, "counter number"},
721 	{prop_trafcounter + 4, "type", ef_trafcounter_type, TYPE_ROTATION, "rotation type"},
722 
723 
724 	{prop_trafcounter + 5, "traffic", ef_trafcounter_traffic64, TYPE_UNSIGNED64, "counter value"},
725 	{prop_trafcounter + 6, "limit", ef_trafcounter_limit64, TYPE_UNSIGNED64, "counter limit"},
726 	{prop_trafcounter + 7, "cleared", ef_trafcounter_cleared, TYPE_DATETIME, "last rotated"},
727 	{prop_trafcounter + 8, "updated", ef_trafcounter_updated, TYPE_DATETIME, "last updated"},
728 	{prop_trafcounter + 9, "comment", ef_trafcounter_comment, TYPE_STRING, "counter comment"},
729 	{NULL, "next", ef_trafcounter_next, TYPE_TRAFCOUNTER}
730 };
731 
732 /*
733 */
734 
735 static struct property prop_server[] = {
736 	{prop_server + 1, "servicetype", ef_server_type, TYPE_STRING, "type of the service/client"},
737 	{prop_server + 2, "target", ef_server_target, TYPE_STRING, "portmapper target ip"},
738 	{prop_server + 3, "targetport", ef_server_targetport, TYPE_PORT, "portmapper target port"},
739 	{prop_server + 4, "starttime", ef_server_starttime, TYPE_DATETIME, "service started seconds"},
740 	{prop_server + 5, "auth", ef_server_auth, TYPE_STRING, "service authentication type"},
741 	{prop_server + 6, "acl", ef_server_acl, TYPE_ACE, "access control list"},
742 	{prop_server + 7, "singlepacket", ef_server_singlepacket, TYPE_INTEGER, "is single packet redirection"},
743 	{prop_server + 8, "usentlm", ef_server_usentlm, TYPE_INTEGER, "allow NTLM authentication"},
744 	{prop_server + 9, "log", ef_server_log, TYPE_STRING, "type of logging"},
745 	{prop_server + 10, "logtarget", ef_server_logtarget, TYPE_STRING, "log target options"},
746 	{prop_server + 11, "logformat", ef_server_logformat, TYPE_STRING, "logging format string"},
747 	{prop_server + 12, "nonprintable", ef_server_nonprintable, TYPE_STRING, "non printable characters"},
748 	{prop_server + 13, "replacement", ef_server_replacement, TYPE_CHAR, "replacement character"},
749 	{prop_server + 14, "childcount", ef_server_childcount, TYPE_INTEGER, "number of servers connected"},
750 	{prop_server + 15, "intsa", ef_server_intsa, TYPE_SA, "ip address of internal interface"},
751 	{prop_server + 16, "extsa", ef_server_extsa, TYPE_SA, "ip address of external interface"},
752 #ifndef NOIPV6
753 	{prop_server + 17, "extsa6", ef_server_extsa6, TYPE_SA, "ipv6 address of external interface"},
754 	{prop_server + 18, "child", ef_server_child, TYPE_CLIENT, "connected clients"},
755 #else
756 	{prop_server + 17, "child", ef_server_child, TYPE_CLIENT, "connected clients"},
757 #endif
758 	{NULL, "next", ef_server_next, TYPE_SERVER, "next"}
759 };
760 
761 
762 static struct property prop_client[] = {
763 	{prop_client + 1, "servicetype", ef_client_type, TYPE_STRING, "type of the client"},
764 	{prop_client + 2, "threadid", ef_client_threadid, TYPE_INTEGER, "process thread id"},
765 	{prop_client + 3, "starttime", ef_client_starttime, TYPE_DATETIME, "client started seconds"},
766 	{prop_client + 4, "starttime_msec", ef_client_starttime_msec, TYPE_UNSIGNED, "client started milliseconds"},
767 	{prop_client + 5, "redirected", ef_client_redirected, TYPE_INTEGER, "number of redirections"},
768 	{prop_client + 6, "operation", ef_client_operation, TYPE_OPERATIONS, "action requested by client"},
769 	{prop_client + 7, "hostname", ef_client_hostname, TYPE_STRING, "name of the requested host"},
770 	{prop_client + 8, "extusername", ef_client_extusername, TYPE_STRING, "username for requested host"},
771 	{prop_client + 9, "extpassword", ef_client_extpassword, TYPE_STRING, "password for requested host"},
772 	{prop_client + 10, "username", ef_client_username, TYPE_STRING, "client username"},
773 	{prop_client + 11, "password", ef_client_password, TYPE_STRING, "client password"},
774 	{prop_client + 12, "clisa", ef_client_clisa, TYPE_SA, "client sa"},
775 	{prop_client + 13, "srvsa", ef_client_srvsa, TYPE_SA, "target server sa"},
776 	{prop_client + 14, "reqsa", ef_client_reqsa, TYPE_SA, "requested server sa"},
777 	{prop_client + 15, "bytesin", ef_client_bytesin64, TYPE_UNSIGNED64, "bytes from server to client"},
778 	{prop_client + 16, "bytesout", ef_client_bytesout64, TYPE_UNSIGNED64, "bytes from client to server"},
779 	{prop_client + 17, "maxtrafin", ef_client_maxtrafin64, TYPE_UNSIGNED64, "maximum traffic allowed for download"},
780 	{prop_client + 18, "maxtrafout", ef_client_maxtrafout64, TYPE_UNSIGNED64, "maximum traffic allowed for upload"},
781 	{prop_client + 19, "pwtype", ef_client_pwtype, TYPE_INTEGER, "type of client password"},
782 	{prop_client + 20, "clisock", ef_client_clisock, TYPE_INTEGER, "client socket"},
783 	{prop_client + 21, "remsock", ef_client_remsock, TYPE_INTEGER, "remote socket"},
784 	{NULL, "next", ef_client_next, TYPE_CLIENT, "next"}
785 
786 
787 };
788 
789 struct datatype datatypes[64] = {
790 	{"integer", NULL, pr_integer, NULL},
791 	{"short", NULL, pr_short, NULL},
792 	{"char", NULL, pr_char, NULL},
793 	{"unsigned", NULL, pr_unsigned, NULL},
794 	{"unsigned64", NULL, pr_unsigned64, NULL},
795 	{"traffic", NULL, pr_traffic, NULL},
796 	{"port", NULL, pr_port, NULL},
797 	{"ip", NULL, pr_ip, NULL},
798 	{"sa", NULL, pr_sa, NULL},
799 	{"cidr", NULL, pr_cidr, NULL},
800 	{"string", NULL, pr_string, NULL},
801 	{"datetime", NULL, pr_datetime, NULL},
802 	{"operations", NULL, pr_operations, NULL},
803 	{"rotation", NULL, pr_rotation, NULL},
804 	{"portlist", ef_portlist_next, pr_portlist, prop_portlist},
805 	{"iplist", ef_iplist_next, pr_iplist, NULL},
806 	{"userlist", ef_userlist_next, pr_userlist, prop_userlist},
807 	{"pwlist", ef_pwlist_next, NULL, prop_pwlist},
808 	{"chain", ef_chain_next, NULL, prop_chain},
809 	{"ace", ef_ace_next, NULL, prop_ace},
810 	{"bandlimit", ef_bandlimit_next, NULL, prop_bandlimit},
811 	{"trafcounter", ef_trafcounter_next, NULL, prop_trafcounter},
812 	{"client", ef_client_next, NULL, prop_client},
813 	{"weekdays", NULL, pr_wdays, NULL},
814 	{"time", NULL, pr_time, NULL},
815 	{"period", ef_period_next, NULL, prop_period},
816 	{"server", ef_server_next, NULL, prop_server}
817 };
818