-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsem_parse_posix.sh
115 lines (98 loc) · 1.69 KB
/
sem_parse_posix.sh
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
#!/bin/bash
cat $FWCONF/conf/sem_objects.C | sed -e 's/\s\s*/ /g' | awk '
# Remove the round brackets
function unwrap(word) {
return gensub(/.*\((.*)\).*/,"\\1","g",word)
}
# Remove the left bracket
function unwrapsvc(line) {
return gensub(/.*\((.*)$/,"\\1","g",line)
}
BEGIN {
servobj=0
bracket=0
svc=0
type=""
port=""
group=0
members=""
proto_type=0
expr=""
}
# :servobj (servobj
/:servobj[ ]+\(servobj/ {
# Beginning of the servobj block
servobj=1
bracket=1
}
# : (FW1_mgmt
/^[ ]*:[ ]+\([^ ]+$/ {
# Beginning of the object definition
if (!servobj) next
svc=1
bracket++
svcname=unwrapsvc($0)
}
# )
/^[ ]*\)[ ]*$/ {
# End of the object definition
if (!servobj) next
bracket--
if (bracket <= 0) {
servobj=0
next
}
if (proto_type) {
proto_type=0
next
}
# End of the servobj section?
if (group) {
print svcname " " members
}
else if (type != "ignore") {
print svcname " " type ":" port " " expr
}
expr=""
svc=0
type=""
port=""
group=0
members=""
}
/^[ ]*:type[ ]/ {
if (!svc || proto_type) next
type=tolower(unwrap($0))
if (type == "group") group=1
else if (type == "other") type ="ip"
else if (type == "icmp" || type == "tcp" || type == "udp") next
else type="ignore"
}
/^[ ]*:proto_type[ ]\([ ]*$/ {
if (svc) {
proto_type=1
bracket++
}
}
/^[ ]*:port[ ][^ ]/ {
if (svc) port=unwrap($0)
}
/^[ ]*:protocol[ ]/ {
if (svc) port=unwrap($0)
}
# :icmp_type (3)
/^[ ]*:icmp_type[ ]/ {
if (svc) port=unwrap($0)
}
# :exp ("dport=520,rip_cmd=RIPCMD_RESPONSE")
/^[ ]*:exp[ ]\([^ ]+.*\)/ {
if (svc) expr=unwrap($0)
}
# Group members
# : sqlnet2-1521
/^[ ]*:[ ][^(][^ ]+$/ {
if (!group) next
if (members) members=members "," $NF
else members=$NF
}
'