Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / tests / test_hosts_access.aug
1 module Test_Hosts_Access =
2
3 let multi_daemon = "sshd, sendmail : 10.234.\n"
4
5 test Hosts_Access.lns get multi_daemon =
6   { "1"
7     { "process" = "sshd" }
8     { "process" = "sendmail" }
9     { "client" = "10.234." }
10   }
11
12 let multi_daemon_spc = "sshd sendmail : 10.234.\n"
13
14 test Hosts_Access.lns get multi_daemon_spc =
15   { "1"
16     { "process" = "sshd" }
17     { "process" = "sendmail" }
18     { "client" = "10.234." }
19   }
20
21 let multi_client = "sshd: 10.234. , 192.168.\n"
22
23 test Hosts_Access.lns get multi_client =
24   { "1"
25     { "process" = "sshd" }
26     { "client" = "10.234." }
27     { "client" = "192.168." }
28   }
29
30 let multi_client_spc = "sshd: 10.234. 192.168.\n"
31
32 test Hosts_Access.lns get multi_client_spc =
33   { "1"
34     { "process" = "sshd" }
35     { "client" = "10.234." }
36     { "client" = "192.168." }
37   }
38
39 let daemon_except = "ALL Except sshd : 10.234.\n"
40
41 test Hosts_Access.lns get daemon_except =
42   { "1"
43     { "process" = "ALL" }
44     { "except"
45       { "process" = "sshd" }
46     }
47     { "client" = "10.234." }
48   }
49
50 let client_except = "sshd : ALL EXCEPT 192.168\n"
51
52 test Hosts_Access.lns get client_except =
53   { "1"
54     { "process" = "sshd" }
55     { "client" = "ALL" }
56     { "except"
57       { "client" = "192.168" }
58     }
59   }
60
61 let daemon_host = "sshd@192.168.0.1: 10.234.\n"
62
63 test Hosts_Access.lns get daemon_host =
64   { "1"
65     { "process" = "sshd"
66       { "host" = "192.168.0.1" }
67     }
68     { "client" = "10.234." }
69   }
70
71 let user_client = "sshd: root@.example.tld\n"
72
73 test Hosts_Access.lns get user_client =
74   { "1"
75     { "process" = "sshd" }
76     { "client" = ".example.tld"
77       { "user" = "root" }
78     }
79   }
80
81 let shell_command = "sshd: 192.168. : /usr/bin/my_cmd -t -f some_arg\n"
82
83 test Hosts_Access.lns get shell_command =
84   { "1"
85     { "process" = "sshd" }
86     { "client" = "192.168." }
87     { "shell_command" = "/usr/bin/my_cmd -t -f some_arg" }
88   }
89
90 let client_netgroup = "sshd: @hostgroup\n"
91 test Hosts_Access.lns get client_netgroup =
92   { "1"
93     { "process" = "sshd" }
94     { "client" = "@hostgroup" }
95   }
96
97 let client_netmask = "sshd: 192.168.0.0/255.255.0.0\n"
98 test Hosts_Access.lns get client_netmask =
99   { "1"
100     { "process" = "sshd" }
101     { "client" = "192.168.0.0"
102       { "netmask" = "255.255.0.0" } }
103   }
104
105 let client_cidr_v4 = "sshd: 192.168.0.0/24\n"
106 test Hosts_Access.lns get client_cidr_v4 =
107   { "1"
108     { "process" = "sshd" }
109     { "client" = "192.168.0.0"
110       { "netmask" = "24" } }
111   }
112
113 let client_cidr_v6 = "sshd: [fe80::%fxp0]/64\n"
114 test Hosts_Access.lns get client_cidr_v6 =
115   { "1"
116     { "process" = "sshd" }
117     { "client" = "[fe80::%fxp0]"
118       { "netmask" = "64" } }
119   }
120
121 let client_file = "sshd: /etc/external_file\n"
122 test Hosts_Access.lns get client_file =
123   { "1"
124     { "process" = "sshd" }
125     { "file" = "/etc/external_file" }
126   }
127
128 let client_wildcard = "sshd: 192.168.?.*\n"
129 test Hosts_Access.lns get client_wildcard =
130   { "1"
131     { "process" = "sshd" }
132     { "client" = "192.168.?.*" }
133   }
134
135 let sample_hosts_allow = "# hosts.allow This file describes the names of the hosts which are
136 #               allowed to use the local INET services, as decided
137 #               by the '/usr/sbin/tcpd' server.
138 in.telnetd:     192.168.1.
139 sshd:           70.16., 207.228.
140 ipop3d:         ALL
141 sendmail:       ALL
142 "
143
144 test Hosts_Access.lns get sample_hosts_allow =
145   { "#comment" = "hosts.allow   This file describes the names of the hosts which are" }
146   { "#comment" = "allowed to use the local INET services, as decided" }
147   { "#comment" = "by the '/usr/sbin/tcpd' server." }
148   { "1"
149     { "process" = "in.telnetd" }
150     { "client" = "192.168.1." }
151   }
152   { "2"
153     { "process" = "sshd" }
154     { "client" = "70.16." }
155     { "client" = "207.228." }
156   }
157   { "3"
158     { "process" = "ipop3d" }
159     { "client" = "ALL" }
160   }
161   { "4"
162     { "process" = "sendmail" }
163     { "client" = "ALL" }
164   }
165
166
167 let sample_hosts_deny = "#
168 # hosts.deny    This file describes the names of the hosts which are
169 #               *not* allowed to use the local INET services, as decided
170 #               by the '/usr/sbin/tcpd' server.
171 in.telnetd: all
172
173 sshd: 61., 62., \
174  64.179., 65.
175 "
176
177 test Hosts_Access.lns get sample_hosts_deny =
178   {  }
179   { "#comment" = "hosts.deny    This file describes the names of the hosts which are" }
180   { "#comment" = "*not* allowed to use the local INET services, as decided" }
181   { "#comment" = "by the '/usr/sbin/tcpd' server." }
182   { "1"
183     { "process" = "in.telnetd" }
184     { "client" = "all" }
185   }
186   {  }
187   { "2"
188     { "process" = "sshd" }
189     { "client" = "61." }
190     { "client" = "62." }
191     { "client" = "64.179." }
192     { "client" = "65." }
193   }
194
195
196 let ip_mask = "sshd: 61./255.255.255.255\n"
197
198 test Hosts_Access.lns get ip_mask =
199   { "1"
200     { "process" = "sshd" }
201     { "client" = "61." { "netmask" = "255.255.255.255" } } }
202
203 (* Support options from hosts_options(5) *)
204 test Hosts_Access.lns get "sshd: all: keepalive\n" =
205   { "1"
206     { "process" = "sshd" }
207     { "client" = "all" }
208     { "keepalive" } }
209
210 test Hosts_Access.lns get "sshd: all: severity mail.info\n" =
211   { "1"
212     { "process" = "sshd" }
213     { "client" = "all" }
214     { "severity" = "mail.info" } }
215
216 test Hosts_Access.lns get "sshd: all: severity mail.info : rfc931 5 : DENY\n" =
217   { "1"
218     { "process" = "sshd" }
219     { "client" = "all" }
220     { "severity" = "mail.info" }
221     { "rfc931" = "5" }
222     { "DENY" } }
223
224 (* Ticket #255, from FreeBSD *)
225 let host_options_cmds = "# You need to be clever with finger; do _not_ backfinger!! You can easily
226 # start a \"finger war\".
227 fingerd : ALL \
228         : spawn (echo Finger. | \
229          /usr/bin/mail -s \"tcpd\: %u@%h[%a] fingered me!\" root) & \
230         : deny
231
232 # The rest of the daemons are protected.
233 ALL : ALL : \
234           severity auth.info \
235         : twist /bin/echo \"You are not welcome to use %d from %h.\"
236 "
237
238 test Hosts_Access.lns get host_options_cmds = 
239   { "#comment" = "You need to be clever with finger; do _not_ backfinger!! You can easily" }
240   { "#comment" = "start a \"finger war\"." }
241   { "1"
242     { "process" = "fingerd" }
243     { "client" = "ALL" }
244     { "spawn" = "(echo Finger. | \
245          /usr/bin/mail -s \"tcpd\\: %u@%h[%a] fingered me!\" root) &" }
246     { "deny" } }
247   {  }
248   { "#comment" = "The rest of the daemons are protected." }
249   { "2"
250     { "process" = "ALL" }
251     { "client" = "ALL" }
252     { "severity" = "auth.info" }
253     { "twist" = "/bin/echo \"You are not welcome to use %d from %h.\"" } }