Handle hostnames with upper-case letters
[webmin.git] / samba / acl_security.pl
1
2 require 'samba-lib.pl';
3
4 # acl_security_form(&options)
5 # Output HTML for editing security options for the samba module
6 sub acl_security_form
7 {
8 print "<tr>\n<td><b>$text{'acl_apply'}</b></td> <td>\n";
9 printf "<input type=radio name=apply value=1 %s> $text{'yes'}\n",
10                 $_[0]->{'apply'} ? "checked" : "";
11 printf "<input type=radio name=apply value=0 %s> $text{'no'}</td>\n",
12                 $_[0]->{'apply'} ? "" : "checked";
13 print "</tr>\n";
14
15 print "<tr>\n<td><b>$text{'acl_view_all_con'}</b></td> <td>\n";
16 printf "<input type=radio name=view_all_con value=1 %s> $text{'yes'}\n",
17                 $_[0]->{'view_all_con'} ? "checked" : "";
18 printf "<input type=radio name=view_all_con value=0 %s> $text{'no'}</td>\n",
19                 $_[0]->{'view_all_con'} ? "" : "checked";
20 print "</tr>\n";
21
22 print "<tr>\n<td><b>$text{'acl_kill_con'}</b></td> <td>\n";
23 printf "<input type=radio name=kill_con value=1 %s> $text{'yes'}\n",
24                 $_[0]->{'kill_con'} ? "checked" : "";
25 printf "<input type=radio name=kill_con value=0 %s> $text{'no'}</td>\n",
26                 $_[0]->{'kill_con'} ? "" : "checked";
27 print "</tr>\n";
28
29 print "<tr> <td colspan=4><hr></td> </tr>\n";
30
31 print "<tr>\n<td><b>$text{'acl_conf_net'}</b></td> <td>\n";
32 printf "<input type=radio name=conf_net value=1 %s> $text{'yes'}\n",
33                 $_[0]->{'conf_net'} ? "checked" : "";
34 printf "<input type=radio name=conf_net value=0 %s> $text{'no'}</td>\n",
35                 $_[0]->{'conf_net'} ? "" : "checked";
36 print "</tr>\n";
37
38 print "<tr>\n<td><b>$text{'acl_conf_smb'}</b></td> <td>\n";
39 printf "<input type=radio name=conf_smb value=1 %s> $text{'yes'}\n",
40                 $_[0]->{'conf_smb'} ? "checked" : "";
41 printf "<input type=radio name=conf_smb value=0 %s> $text{'no'}</td>\n",
42                 $_[0]->{'conf_smb'} ? "" : "checked";
43 print "</tr>\n";
44
45 print "<tr>\n<td><b>$text{'acl_conf_pass'}</b></td> <td>\n";
46 printf "<input type=radio name=conf_pass value=1 %s> $text{'yes'}\n",
47                 $_[0]->{'conf_pass'} ? "checked" : "";
48 printf "<input type=radio name=conf_pass value=0 %s> $text{'no'}</td>\n",
49                 $_[0]->{'conf_pass'} ? "" : "checked";
50 print "</tr>\n";
51
52 print "<tr>\n<td><b>$text{'acl_conf_print'}</b></td> <td>\n";
53 printf "<input type=radio name=conf_print value=1 %s> $text{'yes'}\n",
54                 $_[0]->{'conf_print'} ? "checked" : "";
55 printf "<input type=radio name=conf_print value=0 %s> $text{'no'}</td>\n",
56                 $_[0]->{'conf_print'} ? "" : "checked";
57 print "</tr>\n";
58
59 print "<tr>\n<td><b>$text{'acl_conf_misc'}</b></td> <td>\n";
60 printf "<input type=radio name=conf_misc value=1 %s> $text{'yes'}\n",
61                 $_[0]->{'conf_misc'} ? "checked" : "";
62 printf "<input type=radio name=conf_misc value=0 %s> $text{'no'}</td>\n",
63                 $_[0]->{'conf_misc'} ? "" : "checked";
64 print "</tr>\n";
65
66 print "<tr>\n<td><b>$text{'acl_swat'}</b></td> <td>\n";
67 printf "<input type=radio name=swat value=1 %s> $text{'yes'}\n",
68                 $_[0]->{'swat'} ? "checked" : "";
69 printf "<input type=radio name=swat value=0 %s> $text{'no'}</td>\n",
70                 $_[0]->{'swat'} ? "" : "checked";
71 print "</tr>\n";
72
73 print "<tr>\n<td><b>$text{'acl_manual'}</b></td> <td>\n";
74 printf "<input type=radio name=manual value=1 %s> $text{'yes'}\n",
75                 $_[0]->{'manual'} ? "checked" : "";
76 printf "<input type=radio name=manual value=0 %s> $text{'no'}</td>\n",
77                 $_[0]->{'manual'} ? "" : "checked";
78 print "</tr>\n";
79
80 print "<tr>\n<td><b>$text{'acl_winbind'}</b></td> <td>\n";
81 printf "<input type=radio name=winbind value=1 %s> $text{'yes'}\n",
82                 $_[0]->{'winbind'} ? "checked" : "";
83 printf "<input type=radio name=winbind value=0 %s> $text{'no'}</td>\n",
84                 $_[0]->{'winbind'} ? "" : "checked";
85 print "</tr>\n";
86
87 print "<tr> <td colspan=4><hr></td> </tr>\n";
88
89 # encripted passwords
90 print "<tr>\n<td $tb><b>$text{'acl_enc_passwd_opts'}</b></td></tr> \n";
91
92 print "<tr>\n<td><b>$text{'acl_view_users'}</b></td> <td>\n";
93 printf "<input type=radio name=view_users value=1 %s> $text{'yes'}\n",
94                 $_[0]->{'view_users'} ? "checked" : "";
95 printf "<input type=radio name=view_users value=0 %s> $text{'no'}</td>\n",
96                 $_[0]->{'view_users'} ? "" : "checked";
97 print "</tr>\n";
98
99 print "<tr>\n<td><b>$text{'acl_maint_users'}</b></td> <td>\n";
100 printf "<input type=radio name=maint_users value=1 %s> $text{'yes'}\n",
101                 $_[0]->{'maint_users'} ? "checked" : "";
102 printf "<input type=radio name=maint_users value=0 %s> $text{'no'}</td>\n",
103                 $_[0]->{'maint_users'} ? "" : "checked";
104 print "</tr>\n";
105
106 print "<tr>\n<td><b>$text{'acl_maint_makepass'}</b></td> <td>\n";
107 printf "<input type=radio name=maint_makepass value=1 %s> $text{'yes'}\n",
108                 $_[0]->{'maint_makepass'} ? "checked" : "";
109 printf "<input type=radio name=maint_makepass value=0 %s> $text{'no'}</td>\n",
110                 $_[0]->{'maint_makepass'} ? "" : "checked";
111 print "</tr>\n";
112
113 print "<tr>\n<td><b>$text{'acl_maint_sync'}</b></td> <td>\n";
114 printf "<input type=radio name=maint_sync value=1 %s> $text{'yes'}\n",
115                 $_[0]->{'maint_sync'} ? "checked" : "";
116 printf "<input type=radio name=maint_sync value=0 %s> $text{'no'}</td>\n",
117                 $_[0]->{'maint_sync'} ? "" : "checked";
118 print "</tr>\n";
119
120 print "<tr> <td colspan=4><hr></td> </tr>\n";
121
122 # encripted passwords
123 print "<tr>\n<td $tb><b>$text{'acl_group_opts'}</b></td></tr> \n";
124
125 print "<tr>\n<td><b>$text{'acl_maint_groups'}</b></td> <td>\n";
126 printf "<input type=radio name=maint_groups value=1 %s> $text{'yes'}\n",
127                 $_[0]->{'maint_groups'} ? "checked" : "";
128 printf "<input type=radio name=maint_groups value=0 %s> $text{'no'}</td>\n",
129                 $_[0]->{'maint_groups'} ? "" : "checked";
130 print "</tr>\n";
131
132 print "<tr>\n<td><b>$text{'acl_maint_gsync'}</b></td> <td>\n";
133 printf "<input type=radio name=maint_gsync value=1 %s> $text{'yes'}\n",
134                 $_[0]->{'maint_gsync'} ? "checked" : "";
135 printf "<input type=radio name=maint_gsync value=0 %s> $text{'no'}</td>\n",
136                 $_[0]->{'maint_gsync'} ? "" : "checked";
137 print "</tr>\n";
138
139 print "<tr> <td colspan=4><hr></td> </tr>\n";
140
141 # hide
142 print "<tr>\n<td><b>$text{'acl_hide'}</b></td> <td>\n";
143 printf "<input type=radio name=hide value=1 %s> $text{'yes'}\n",
144                 $_[0]->{'hide'} == 1 ? "checked" : "";
145 printf "<input type=radio name=hide value=0 %s> $text{'no'}</td>\n",
146                 $_[0]->{'hide'} == 0 ? "checked" : "";
147 print "</tr>\n";
148
149 print "<tr> <td colspan=4><hr></td> </tr>\n";
150
151 # global acls
152 print "<tr>\n<td><b>$text{'acl_afs'}</b></td>\n";
153 print "<td colspan=3>\n";
154 printf "<input type=checkbox name=c_fs value=1 %s> %s\n",
155                 $_[0]->{'c_fs'} ? "checked" : "", $text{"acl_c"};
156 printf "<input type=checkbox name=r_fs value=1 %s> %s\n",
157                 $_[0]->{'r_fs'} ? "checked" : "", $text{"acl_r"};
158 printf "<input type=checkbox name=w_fs value=1 %s> %s\n",
159                 $_[0]->{'w_fs'} ? "checked" : "", $text{"acl_w"};
160 print "</td> </tr>\n";
161
162 print "<tr>\n<td><b>$text{'acl_aps'}</b></td>\n";
163 print "<td colspan=3>\n";
164 printf "<input type=checkbox name=c_ps value=1 %s> %s\n",
165                 $_[0]->{'c_ps'} ? "checked" : "", $text{"acl_c"};
166 printf "<input type=checkbox name=r_ps value=1 %s> %s\n",
167                 $_[0]->{'r_ps'} ? "checked" : "", $text{"acl_r"};
168 printf "<input type=checkbox name=w_ps value=1 %s> %s\n",
169                 $_[0]->{'w_ps'} ? "checked" : "", $text{"acl_w"};
170 print "</td> </tr>\n";
171
172 print "<tr>\n<td><b>$text{'acl_copy'}</b></td> <td>\n";
173 printf "<input type=radio name=copy value=1 %s> $text{'yes'}\n",
174                 $_[0]->{'copy'} ? "checked" : "";
175 printf "<input type=radio name=copy value=0 %s> $text{'no'}</td>\n",
176                 $_[0]->{'copy'} ? "" : "checked";
177 print "</tr>\n";
178
179 print "<tr> <td colspan=4><hr></td> </tr>\n";
180
181 # per-share acls
182 print "<tr><td><b>$text{'acl_per_fs_acls'}</b></td> <td>\n";
183 printf "<input type=radio name=per_fs_acls value=1 %s> $text{'yes'}\n",
184                 $_[0]->{'per_fs_acls'} ? "checked" : "";
185 printf "<input type=radio name=per_fs_acls value=0 %s> $text{'no'}\n",
186                 $_[0]->{'per_fs_acls'} ? "" : "checked";
187 print "</td></tr>\n";
188
189 print "<tr><td><b>$text{'acl_per_ps_acls'}</b></td> <td>\n";
190 printf "<input type=radio name=per_ps_acls value=1 %s> $text{'yes'}\n",
191                 $_[0]->{'per_ps_acls'} ? "checked" : "";
192 printf "<input type=radio name=per_ps_acls value=0 %s> $text{'no'}\n",
193                 $_[0]->{'per_ps_acls'} ? "" : "checked";
194 print "</td></tr>\n";
195
196 print "<tr> <td colspan=4><hr></td> </tr>\n";
197
198 # table
199 print "<tr> <td colspan=4>\n<table border width=100%>\n";
200 printf "<th $tb colspan=7><b>%s</b></th>\n", $text{'acl_per_share_acls'};
201 print "<tr $tb>\n";
202 printf "<td rowspan=2><b>%s</b></td>\n", $text{'acl_sname'};
203 printf "<td rowspan=2><b>%s</b></td>\n", $text{'acl_saccess'};
204 printf "<td rowspan=2><b>%s</b></td>\n", $text{'acl_sconn'};
205 printf "<th colspan=4><b>%s</b></th>\n", $text{'acl_sopthdr'};
206 print "</tr>\n<tr $tb>\n";
207 printf "<td><b>%s</b></td>\n", $text{'acl_ssec'};
208 printf "<td><b>%s</b></td>\n", $text{'acl_sperm'};
209 printf "<td><b>%s</b></td>\n", $text{'acl_snaming'};
210 printf "<td><b>%s<br>%s</b></td>\n", $text{'acl_smisc'}, $text{'acl_sprn'};
211 print "</tr>\n";
212
213 foreach (&list_shares()) {
214         &display_acl_row($_[0], $_);
215         }
216 print "</table> </td> </tr>\n";
217 }
218
219 # acl_security_save(&options)
220 # Parse the form for security options for the samba module
221 sub acl_security_save
222 {
223 if ($in{'r_fs'} < $in{'w_fs'} || $in{'r_ps'} < $in{'w_ps'}) {
224         &error($text{'acl_ernow'});
225         }
226 $_[0]->{'apply'}=$in{'apply'};
227 $_[0]->{'view_all_con'}=$in{'view_all_con'};
228 $_[0]->{'kill_con'}=$in{'kill_con'};
229 $_[0]->{'conf_net'}=$in{'conf_net'};
230 $_[0]->{'conf_smb'}=$in{'conf_smb'};
231 $_[0]->{'conf_pass'}=$in{'conf_pass'};
232 $_[0]->{'conf_print'}=$in{'conf_print'};
233 $_[0]->{'conf_misc'}=$in{'conf_misc'};
234 $_[0]->{'swat'}=$in{'swat'};
235 $_[0]->{'manual'}=$in{'manual'};
236 $_[0]->{'hide'}=$in{'hide'};
237 $_[0]->{'per_fs_acls'}=$in{'per_fs_acls'};
238 $_[0]->{'per_ps_acls'}=$in{'per_ps_acls'};
239 $_[0]->{'c_fs'}=$in{'c_fs'};
240 $_[0]->{'r_fs'}=$in{'r_fs'};
241 $_[0]->{'w_fs'}=$in{'w_fs'};
242 $_[0]->{'c_ps'}=$in{'c_ps'};
243 $_[0]->{'r_ps'}=$in{'r_ps'};
244 $_[0]->{'w_ps'}=$in{'w_ps'};
245 $_[0]->{'copy'}=$in{'copy'};
246 $_[0]->{'view_users'}=$in{'view_users'};
247 $_[0]->{'maint_users'}=$in{'maint_users'};
248 $_[0]->{'maint_makepass'}=$in{'maint_makepass'};
249 $_[0]->{'maint_sync'}=$in{'maint_sync'};
250 $_[0]->{'maint_groups'}=$in{'maint_groups'};
251 $_[0]->{'maint_gsync'}=$in{'maint_gsync'};
252 $_[0]->{'winbind'}=$in{'winbind'};
253
254 foreach (keys %in) {
255           $_[0]->{$1} .= $in{$_} if /^\w\w_(ACL\w\w_\w+)$/;
256           }
257 }
258
259 # display_acl_row(\%access, $share_name)                                                                        
260 sub display_acl_row
261 {
262 local($acc,$name)=@_;
263 local %share;
264 &get_share($name);
265 local $stype=&istrue('printable') ? 'ps' : 'fs';
266 local $aclname='ACL' . $stype . '_' . $name;
267
268 #display row
269 print "<tr>\n";
270 printf $stype eq 'fs' ? "<td><b>%s</b></td>\n" : 
271                                                 "<td><b><i>%s</i></td>\n", $name;
272 &display_acl_cell($acc, $name, 'r', 'w', $aclname, 
273                                   $text{'acl_na'}, $text{'acl_r1'}, $text{'acl_rw'});
274 &display_acl_cell($acc, $name, 'v', 'V', $aclname, 
275                                   $text{'acl_na'}, $text{'acl_view'}, $text{'acl_kill'});
276 &display_acl_cell($acc, $name, 's', 'S', $aclname, 
277                                   $text{'acl_na'}, $text{'acl_view'}, $text{'acl_edit'});
278 $stype eq 'fs' ? &display_acl_cell($acc, $name, 'p', 'P', $aclname, 
279                                   $text{'acl_na'}, $text{'acl_view'}, $text{'acl_edit'}) : 
280                                   print "<td> </td>\n";
281 $stype eq 'fs' ? &display_acl_cell($acc, $name, 'n', 'N', $aclname, 
282                                 $text{'acl_na'}, $text{'acl_view'}, $text{'acl_edit'}) :
283                                 print "<td> </td>\n";
284 &display_acl_cell($acc, $name, 'o', 'O', $aclname, 
285                                   $text{'acl_na'}, $text{'acl_view'}, $text{'acl_edit'});
286 print "</tr>\n";                
287 }
288
289 #display_acl_cell(\%access, $name, 
290 #                                 $rperm, $wperm, $aclname, 
291 #                                 $text1, $text2, $text3)
292 sub display_acl_cell
293 {
294 local ($acc, $name, $rp, $wp, $aclname, $text1, $text2, $text3) = @_;
295 local $rn = $rp . $wp . '_' . $aclname;
296
297 print "<td>\n";
298 if($acc->{$aclname}) { 
299         printf "<input type=radio name=$rn value='' %s> %s<br>\n",
300                         !&perm_to($rp, $acc, $aclname) ? 
301                                 "checked" : "", $text1;
302         printf "<input type=radio name=$rn value='$rp' %s> %s<br>\n",
303                         &perm_to($rp, $acc, $aclname) && 
304                         !&perm_to($rp.$wp, $acc, $aclname) ? 
305                                 "checked" : "",$text2;
306         printf "<input type=radio name=$rn value='$rp$wp' %s> %s\n",
307                         &perm_to($rp.$wp, $acc, $aclname) ? 
308                                 "checked" : "", $text3;
309         }
310 else {
311         printf "<input type=radio name=$rn value='' checked> %s<br>\n",
312                         $text1;
313         printf "<input type=radio name=$rn value='$rp'> %s<br>\n", 
314                         $text2;
315         printf "<input type=radio name=$rn value='$rp$wp'> %s\n",
316                         $text3;
317         }
318 print "</td>\n";
319 }
320
321 # perm_to($permissions_string,\%access,$ACLname)
322 # check only per-share permissions
323 sub perm_to
324 {
325 local $acl=$_[1]->{$_[2]};
326 foreach (split //,$_[0]) {
327         return 0 if index($acl,$_) == -1;
328         }
329 return 1;
330 }
331                 
332 1;