3 * FCRON - periodic command scheduler
5 * Copyright 2000-2016 Thibault Godouet <fcron@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * The GNU General Public License can also be found in the file
22 * `LICENSE' that comes with the fcron source distribution.
31 in_file(char *str, char *file)
32 /* return -1 if file doesn't exist
33 * 0 if string is not in file,
35 * and 2 if file contains "all" string */
41 if ((f = fopen(file, "r")) == NULL) {
43 /* file does not exist */
46 die_e("could not open %s", file);
49 while (fgets(buf, sizeof(buf), f) != NULL) {
51 /* skip leading and trailing blanks, comments */
54 if (*start == '#' || *start == '\0')
58 if (strcmp(str, start) == 0) {
59 xfclose_check(&f, file);
62 if (strcmp(start, "all") == 0) {
63 xfclose_check(&f, file);
68 xfclose_check(&f, file);
69 /* if execution gets here, string is not in file */
76 is_allowed(char *user)
77 /* return 1 if user is allowed to use this software
78 * otherwise return 0 */
83 /* check if user is in passwd file */
84 if (getpwnam(user) != NULL) {
86 /* check if user is in fcron.allow and/or in fcron.deny files */
87 allow = in_file(user, fcronallow);
88 deny = in_file(user, fcrondeny);
91 * -1 if file doesn't exist
92 * 0 if string is not in file,
94 * and 2 if file contains "all" string */
96 if (allow == -1 && deny == -1)
97 /* neither fcron.allow nor fcron.deny exist :
98 * we consider that user is allowed */
101 if (allow == -1 && deny == 0)
104 if (deny == -1 && allow == 1)
107 if (allow == 1 && deny != 1)
109 if (allow == 2 && deny <= 0)
114 /* if we gets here, user is not allowed */
118 int audit_fd = audit_open();
119 audit_log_user_message(audit_fd, AUDIT_USER_START, "fcron deny",
120 NULL, NULL, NULL, 0);
121 xclose_check(&audit_fd, "audit");