1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 /* All Rights Reserved */ 24 25 26 /* 27 * Copyright (c) 2000 by Sun Microsystems, Inc. 28 * All rights reserved. 29 */ 30 31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ 32 33 #include <sys/types.h> 34 #include <sys/stat.h> 35 #include <stdio.h> 36 #include <string.h> 37 #include <ctype.h> 38 #include <pwd.h> 39 #include "cron.h" 40 41 struct stat globstat; 42 #define exists(file) (stat(file, &globstat) == 0) 43 #define ROOT "root" 44 45 int per_errno; /* status info from getuser */ 46 static int within(char *, char *); 47 48 49 char * 50 getuser(uid) 51 uid_t uid; 52 { 53 struct passwd *nptr; 54 55 if ((nptr = getpwuid(uid)) == NULL) { 56 per_errno = 1; 57 return (NULL); 58 } 59 if ((strcmp(nptr->pw_shell, SHELL) != 0) && 60 (strcmp(nptr->pw_shell, "") != 0)) { 61 per_errno = 2; 62 /* 63 * return NULL if you want crontab and at to abort 64 * when the users login shell is not /usr/bin/sh otherwise 65 * return pw_name 66 */ 67 return (nptr->pw_name); 68 } 69 return (nptr->pw_name); 70 } 71 72 int 73 allowed(user, allow, deny) 74 char *user, *allow, *deny; 75 { 76 if (exists(allow)) { 77 if (within(user, allow)) { 78 return (1); 79 } else { 80 return (0); 81 } 82 } else if (exists(deny)) { 83 if (within(user, deny)) { 84 return (0); 85 } else { 86 return (1); 87 } 88 } else if (chkauthattr(CRONUSER_AUTH, user)) { 89 return (1); 90 } else { 91 return (0); 92 } 93 } 94 95 static int 96 within(username, filename) 97 char *username, *filename; 98 { 99 char line[UNAMESIZE]; 100 FILE *cap; 101 int i; 102 103 if ((cap = fopen(filename, "r")) == NULL) 104 return (0); 105 while (fgets(line, UNAMESIZE, cap) != NULL) { 106 for (i = 0; line[i] != '\0'; i++) { 107 if (isspace(line[i])) { 108 line[i] = '\0'; 109 break; } 110 } 111 if (strcmp(line, username) == 0) { 112 fclose(cap); 113 return (1); 114 } 115 } 116 fclose(cap); 117 return (0); 118 } 119