10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*11115SNobutomo.Nakano@Sun.COM * Common Development and Distribution License (the "License").
6*11115SNobutomo.Nakano@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
220Sstevel@tonic-gate /* All Rights Reserved */
230Sstevel@tonic-gate
240Sstevel@tonic-gate /*
25*11115SNobutomo.Nakano@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26*11115SNobutomo.Nakano@Sun.COM * Use is subject to license terms.
270Sstevel@tonic-gate */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/stat.h>
310Sstevel@tonic-gate #include <stdio.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <ctype.h>
340Sstevel@tonic-gate #include <pwd.h>
35*11115SNobutomo.Nakano@Sun.COM #include <auth_attr.h>
36*11115SNobutomo.Nakano@Sun.COM #include <auth_list.h>
37*11115SNobutomo.Nakano@Sun.COM
380Sstevel@tonic-gate #include "cron.h"
390Sstevel@tonic-gate
400Sstevel@tonic-gate struct stat globstat;
410Sstevel@tonic-gate #define exists(file) (stat(file, &globstat) == 0)
420Sstevel@tonic-gate #define ROOT "root"
430Sstevel@tonic-gate
440Sstevel@tonic-gate int per_errno; /* status info from getuser */
450Sstevel@tonic-gate static int within(char *, char *);
460Sstevel@tonic-gate
470Sstevel@tonic-gate
480Sstevel@tonic-gate char *
getuser(uid)490Sstevel@tonic-gate getuser(uid)
500Sstevel@tonic-gate uid_t uid;
510Sstevel@tonic-gate {
520Sstevel@tonic-gate struct passwd *nptr;
530Sstevel@tonic-gate
540Sstevel@tonic-gate if ((nptr = getpwuid(uid)) == NULL) {
550Sstevel@tonic-gate per_errno = 1;
560Sstevel@tonic-gate return (NULL);
570Sstevel@tonic-gate }
580Sstevel@tonic-gate if ((strcmp(nptr->pw_shell, SHELL) != 0) &&
590Sstevel@tonic-gate (strcmp(nptr->pw_shell, "") != 0)) {
600Sstevel@tonic-gate per_errno = 2;
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate * return NULL if you want crontab and at to abort
630Sstevel@tonic-gate * when the users login shell is not /usr/bin/sh otherwise
640Sstevel@tonic-gate * return pw_name
650Sstevel@tonic-gate */
660Sstevel@tonic-gate return (nptr->pw_name);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate return (nptr->pw_name);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate
710Sstevel@tonic-gate int
allowed(user,allow,deny)720Sstevel@tonic-gate allowed(user, allow, deny)
730Sstevel@tonic-gate char *user, *allow, *deny;
740Sstevel@tonic-gate {
750Sstevel@tonic-gate if (exists(allow)) {
760Sstevel@tonic-gate if (within(user, allow)) {
770Sstevel@tonic-gate return (1);
780Sstevel@tonic-gate } else {
790Sstevel@tonic-gate return (0);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate } else if (exists(deny)) {
820Sstevel@tonic-gate if (within(user, deny)) {
830Sstevel@tonic-gate return (0);
840Sstevel@tonic-gate } else {
850Sstevel@tonic-gate return (1);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate } else if (chkauthattr(CRONUSER_AUTH, user)) {
880Sstevel@tonic-gate return (1);
890Sstevel@tonic-gate } else {
900Sstevel@tonic-gate return (0);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate }
930Sstevel@tonic-gate
940Sstevel@tonic-gate static int
within(username,filename)950Sstevel@tonic-gate within(username, filename)
960Sstevel@tonic-gate char *username, *filename;
970Sstevel@tonic-gate {
980Sstevel@tonic-gate char line[UNAMESIZE];
990Sstevel@tonic-gate FILE *cap;
1000Sstevel@tonic-gate int i;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate if ((cap = fopen(filename, "r")) == NULL)
1030Sstevel@tonic-gate return (0);
1040Sstevel@tonic-gate while (fgets(line, UNAMESIZE, cap) != NULL) {
1050Sstevel@tonic-gate for (i = 0; line[i] != '\0'; i++) {
1060Sstevel@tonic-gate if (isspace(line[i])) {
1070Sstevel@tonic-gate line[i] = '\0';
1080Sstevel@tonic-gate break; }
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate if (strcmp(line, username) == 0) {
1110Sstevel@tonic-gate fclose(cap);
1120Sstevel@tonic-gate return (1);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate fclose(cap);
1160Sstevel@tonic-gate return (0);
1170Sstevel@tonic-gate }
118*11115SNobutomo.Nakano@Sun.COM
119*11115SNobutomo.Nakano@Sun.COM int
cron_admin(const char * name)120*11115SNobutomo.Nakano@Sun.COM cron_admin(const char *name)
121*11115SNobutomo.Nakano@Sun.COM {
122*11115SNobutomo.Nakano@Sun.COM return (chkauthattr(CRONADMIN_AUTH, name));
123*11115SNobutomo.Nakano@Sun.COM }
124