libstand: gzipfs unused variable
[unleashed.git] / usr / src / cmd / cron / permit.c
bloba5a951200bc89cfb34699659169ba951c172f8f7
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <pwd.h>
35 #include <auth_attr.h>
36 #include <auth_list.h>
38 #include "cron.h"
40 struct stat globstat;
41 #define exists(file) (stat(file, &globstat) == 0)
42 #define ROOT "root"
44 int per_errno; /* status info from getuser */
45 static int within(char *, char *);
48 char *
49 getuser(uid)
50 uid_t uid;
52 struct passwd *nptr;
54 if ((nptr = getpwuid(uid)) == NULL) {
55 per_errno = 1;
56 return (NULL);
58 if ((strcmp(nptr->pw_shell, SHELL) != 0) &&
59 (strcmp(nptr->pw_shell, "") != 0)) {
60 per_errno = 2;
62 * return NULL if you want crontab and at to abort
63 * when the users login shell is not /usr/bin/sh otherwise
64 * return pw_name
66 return (nptr->pw_name);
68 return (nptr->pw_name);
71 int
72 allowed(user, allow, deny)
73 char *user, *allow, *deny;
75 if (exists(allow)) {
76 if (within(user, allow)) {
77 return (1);
78 } else {
79 return (0);
81 } else if (exists(deny)) {
82 if (within(user, deny)) {
83 return (0);
84 } else {
85 return (1);
87 } else if (chkauthattr(CRONUSER_AUTH, user)) {
88 return (1);
89 } else {
90 return (0);
94 static int
95 within(username, filename)
96 char *username, *filename;
98 char line[UNAMESIZE];
99 FILE *cap;
100 int i;
102 if ((cap = fopen(filename, "r")) == NULL)
103 return (0);
104 while (fgets(line, UNAMESIZE, cap) != NULL) {
105 for (i = 0; line[i] != '\0'; i++) {
106 if (isspace(line[i])) {
107 line[i] = '\0';
108 break; }
110 if (strcmp(line, username) == 0) {
111 fclose(cap);
112 return (1);
115 fclose(cap);
116 return (0);
120 cron_admin(const char *name)
122 return (chkauthattr(CRONADMIN_AUTH, name));