File: socks_dumpcf.c

package info (click to toggle)
socks4-server 4.3.beta2-20
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,512 kB
  • ctags: 1,778
  • sloc: ansic: 19,305; makefile: 399; sh: 52
file content (97 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (9)
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
/* socks_dumpcf */

#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "socks.h"


void socks_dumpcf(cfAddr, Ncf, useSyslog)
struct config *cfAddr;
int Ncf;
int useSyslog;
{
	char buf[1024], *bp;
	struct config *cp;
	char buf2[1024];
	int i, t;
	struct in_addr addr;
	
	if (useSyslog)
		syslog(LOG_HIGH,"Effective configuration entries: %d\n",Ncf);
	else
		printf("Effective configuration entries: %d\n",Ncf);

	for (i = 0, cp = cfAddr; i++ < Ncf; cp++) {
		switch (cp->action) {
		case SOCKS_DIRECT:
			strcpy(buf, "direct ");
			break;
		case SOCKS_SOCKD:
			strcpy(buf, "sockd ");
			break;
		case SOCKS_DENY:
			strcpy(buf, "deny ");
			break;
		default:
			strcpy(buf, "*badaction* ");
			continue;
		}

		if (cp->serverlist != NULL) {
			strcat(buf, "@=");
			strcat(buf, cp->serverlist);
			strcat(buf, " ");
		}
		if (cp->userlist != NULL) {
			strcat(buf, "*=");
			strcat(buf, cp->userlist);
			strcat(buf, " ");
		}
		if (cp->ddomain != NULL)
			strcat(buf, cp->ddomain);
		else
			strcat(buf, inet_ntoa(cp->daddr));
		strcat(buf, " ");
		strcat(buf, inet_ntoa(cp->dmask));
	
		switch (cp->tst) {
		case e_lt:
			sprintf(buf2,"lt %d ", cp->dport);
			break;
		case e_gt:
			sprintf(buf2,"gt %d ", cp->dport);
			break;
		case e_eq:
			sprintf(buf2,"eq %d ", cp->dport);
			break;
		case e_neq:
			sprintf(buf2,"neq %d ", cp->dport);
			break;
		case e_le:
			sprintf(buf2,"le %d ", cp->dport);
			break;
		case e_ge:
			sprintf(buf2,"ge %d ", cp->dport);
			break;
		case e_nil:
			buf2[0] = '\0';
			break;
		default:
			sprintf(buf2, "*badcmp* %d ", cp->dport);
		}
	
		if (cp->cmdp) {
			strcat(buf2, ": ");
			strcat(buf2, cp->cmdp);
		}
dump_it:
		if (useSyslog)
			syslog(LOG_HIGH, "CF%3d>>%s %s<<\n",i,buf, buf2);
		else
			printf("CF%3d>>%s %s<<\n",i,buf, buf2);
	}
}