2 # Functions for listing and creating at jobs
4 BEGIN { push(@INC, ".."); };
7 %access = &get_module_acl();
9 do "$config{'at_style'}-lib.pl";
11 # wrap_lines(text, width)
12 # Given a multi-line string, return an array of lines wrapped to
18 foreach $rest (split(/\n/, $_[0])) {
20 while(length($rest) > $w) {
21 push(@rv, substr($rest, 0, $w));
22 $rest = substr($rest, $w);
27 # Empty line .. keep as it is
34 # can_edit_user(&access, user)
38 map { $umap{$_}++; } split(/\s+/, $_[0]->{'users'});
39 if ($_[0]->{'mode'} == 1 && !$umap{$_[1]} ||
40 $_[0]->{'mode'} == 2 && $umap{$_[1]}) { return 0; }
41 elsif ($_[0]->{'mode'} == 3) {
42 return $remote_user eq $_[1];
50 # Returns a list of all users in the cron allow file
54 &open_readfile(ALLOW, $config{allow_file});
57 chop; push(@rv, $_) if (/\S/);
65 # Return a list of users from the cron deny file
69 &open_readfile(DENY, $config{deny_file});
72 chop; push(@rv, $_) if (/\S/);
79 # save_allowed(user, user, ...)
80 # Save the list of allowed users
83 &lock_file($config{allow_file});
86 &open_tempfile(ALLOW, ">$config{allow_file}");
88 &print_tempfile(ALLOW, $u,"\n");
90 &close_tempfile(ALLOW);
91 chmod(0444, $config{allow_file});
94 &unlink_file($config{allow_file});
96 &unlock_file($config{allow_file});
100 # save_denied(user, user, ...)
101 # Save the list of denied users
104 &lock_file($config{deny_file});
105 if (@_ || !-r $config{'allow_file'}) {
106 &open_tempfile(DENY, ">$config{deny_file}");
108 &print_tempfile(DENY, $u,"\n");
110 &close_tempfile(DENY);
111 chmod(0444, $config{deny_file});
114 &unlink_file($config{deny_file});
116 &unlock_file($config{deny_file});
120 # Returns 1 if some user is allowed to use At jobs, based on the allow
125 if (!$config{'allow_file'}) {
126 return 1; # not supported by OS
128 elsif (@allow = &list_allowed()) {
129 return &indexof($user, @allow) >= 0; # check allowed list
131 elsif (@deny = &list_denied()) {
132 return &indexof($user, @denied) < 0; # check denied list
135 return 1; # if neither exists, fall back to allowing all