17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*d1419d5aSNobutomo Nakano * Common Development and Distribution License (the "License"). 6*d1419d5aSNobutomo Nakano * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 227c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate /* 25*d1419d5aSNobutomo Nakano * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 26*d1419d5aSNobutomo Nakano * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/stat.h> 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <ctype.h> 347c478bd9Sstevel@tonic-gate #include <pwd.h> 35*d1419d5aSNobutomo Nakano #include <auth_attr.h> 36*d1419d5aSNobutomo Nakano #include <auth_list.h> 37*d1419d5aSNobutomo Nakano 387c478bd9Sstevel@tonic-gate #include "cron.h" 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate struct stat globstat; 417c478bd9Sstevel@tonic-gate #define exists(file) (stat(file, &globstat) == 0) 427c478bd9Sstevel@tonic-gate #define ROOT "root" 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate int per_errno; /* status info from getuser */ 457c478bd9Sstevel@tonic-gate static int within(char *, char *); 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate char * 497c478bd9Sstevel@tonic-gate getuser(uid) 507c478bd9Sstevel@tonic-gate uid_t uid; 517c478bd9Sstevel@tonic-gate { 527c478bd9Sstevel@tonic-gate struct passwd *nptr; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate if ((nptr = getpwuid(uid)) == NULL) { 557c478bd9Sstevel@tonic-gate per_errno = 1; 567c478bd9Sstevel@tonic-gate return (NULL); 577c478bd9Sstevel@tonic-gate } 587c478bd9Sstevel@tonic-gate if ((strcmp(nptr->pw_shell, SHELL) != 0) && 597c478bd9Sstevel@tonic-gate (strcmp(nptr->pw_shell, "") != 0)) { 607c478bd9Sstevel@tonic-gate per_errno = 2; 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * return NULL if you want crontab and at to abort 637c478bd9Sstevel@tonic-gate * when the users login shell is not /usr/bin/sh otherwise 647c478bd9Sstevel@tonic-gate * return pw_name 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate return (nptr->pw_name); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate return (nptr->pw_name); 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate int 727c478bd9Sstevel@tonic-gate allowed(user, allow, deny) 737c478bd9Sstevel@tonic-gate char *user, *allow, *deny; 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate if (exists(allow)) { 767c478bd9Sstevel@tonic-gate if (within(user, allow)) { 777c478bd9Sstevel@tonic-gate return (1); 787c478bd9Sstevel@tonic-gate } else { 797c478bd9Sstevel@tonic-gate return (0); 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate } else if (exists(deny)) { 827c478bd9Sstevel@tonic-gate if (within(user, deny)) { 837c478bd9Sstevel@tonic-gate return (0); 847c478bd9Sstevel@tonic-gate } else { 857c478bd9Sstevel@tonic-gate return (1); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate } else if (chkauthattr(CRONUSER_AUTH, user)) { 887c478bd9Sstevel@tonic-gate return (1); 897c478bd9Sstevel@tonic-gate } else { 907c478bd9Sstevel@tonic-gate return (0); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate } 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate static int 957c478bd9Sstevel@tonic-gate within(username, filename) 967c478bd9Sstevel@tonic-gate char *username, *filename; 977c478bd9Sstevel@tonic-gate { 987c478bd9Sstevel@tonic-gate char line[UNAMESIZE]; 997c478bd9Sstevel@tonic-gate FILE *cap; 1007c478bd9Sstevel@tonic-gate int i; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate if ((cap = fopen(filename, "r")) == NULL) 1037c478bd9Sstevel@tonic-gate return (0); 1047c478bd9Sstevel@tonic-gate while (fgets(line, UNAMESIZE, cap) != NULL) { 1057c478bd9Sstevel@tonic-gate for (i = 0; line[i] != '\0'; i++) { 1067c478bd9Sstevel@tonic-gate if (isspace(line[i])) { 1077c478bd9Sstevel@tonic-gate line[i] = '\0'; 1087c478bd9Sstevel@tonic-gate break; } 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate if (strcmp(line, username) == 0) { 1117c478bd9Sstevel@tonic-gate fclose(cap); 1127c478bd9Sstevel@tonic-gate return (1); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate fclose(cap); 1167c478bd9Sstevel@tonic-gate return (0); 1177c478bd9Sstevel@tonic-gate } 118*d1419d5aSNobutomo Nakano 119*d1419d5aSNobutomo Nakano int 120*d1419d5aSNobutomo Nakano cron_admin(const char *name) 121*d1419d5aSNobutomo Nakano { 122*d1419d5aSNobutomo Nakano return (chkauthattr(CRONADMIN_AUTH, name)); 123*d1419d5aSNobutomo Nakano } 124