11590Srgrimes/* 21590Srgrimes * Copyright (c) 1980, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 301590Srgrimes#ifndef lint 3141568Sarchiestatic const char copyright[] = 321590Srgrimes"@(#) Copyright (c) 1980, 1993\n\ 331590Srgrimes The Regents of the University of California. All rights reserved.\n"; 3487258Smarkm#endif 351590Srgrimes 3687628Sdwmalone#if 0 371590Srgrimes#ifndef lint 3887628Sdwmalonestatic char sccsid[] = "@(#)biff.c 8.1 (Berkeley) 6/6/93"; 3987258Smarkm#endif 4087628Sdwmalone#endif 411590Srgrimes 4287628Sdwmalone#include <sys/cdefs.h> 4387628Sdwmalone__FBSDID("$FreeBSD: releng/10.2/usr.bin/biff/biff.c 216370 2010-12-11 08:32:16Z joel $"); 4487628Sdwmalone 451590Srgrimes#include <sys/stat.h> 4690722Smike 4787749Scharnier#include <err.h> 4887749Scharnier#include <stdio.h> 4990722Smike#include <stdlib.h> 501590Srgrimes#include <unistd.h> 511590Srgrimes 5292920Simpstatic void usage(void); 531590Srgrimes 5432069Salexint 55100626Srobertmain(int argc, char *argv[]) 561590Srgrimes{ 571590Srgrimes struct stat sb; 581590Srgrimes int ch; 591590Srgrimes char *name; 601590Srgrimes 611590Srgrimes 6224360Simp while ((ch = getopt(argc, argv, "")) != -1) 631590Srgrimes switch(ch) { 641590Srgrimes case '?': 651590Srgrimes default: 661590Srgrimes usage(); 671590Srgrimes } 681590Srgrimes argc -= optind; 691590Srgrimes argv += optind; 701590Srgrimes 71100614Srobert if ((name = ttyname(STDIN_FILENO)) == NULL && 72100614Srobert (name = ttyname(STDOUT_FILENO)) == NULL && 73100614Srobert (name = ttyname(STDERR_FILENO)) == NULL) 7426836Scharnier err(2, "unknown tty"); 751590Srgrimes 761590Srgrimes if (stat(name, &sb)) 7726836Scharnier err(2, "stat"); 781590Srgrimes 791590Srgrimes if (*argv == NULL) { 80100443Sjohan (void)printf("is %s\n", 8199632Sjohan sb.st_mode & S_IXUSR ? "y" : 8299632Sjohan sb.st_mode & S_IXGRP ? "b" : "n"); 83100627Srobert return (sb.st_mode & (S_IXUSR | S_IXGRP) ? 0 : 1); 8499632Sjohan 851590Srgrimes } 861590Srgrimes 87100627Srobert switch (argv[0][0]) { 881590Srgrimes case 'n': 8999632Sjohan if (chmod(name, sb.st_mode & ~(S_IXUSR | S_IXGRP)) < 0) 9062889Skris err(2, "%s", name); 911590Srgrimes break; 921590Srgrimes case 'y': 93100627Srobert if (chmod(name, (sb.st_mode & ~(S_IXUSR | S_IXGRP)) | S_IXUSR) 94100627Srobert < 0) 9562889Skris err(2, "%s", name); 961590Srgrimes break; 9799632Sjohan case 'b': 98100627Srobert if (chmod(name, (sb.st_mode & ~(S_IXUSR | S_IXGRP)) | S_IXGRP) 99100627Srobert < 0) 10099632Sjohan err(2, "%s", name); 10199632Sjohan break; 1021590Srgrimes default: 1031590Srgrimes usage(); 1041590Srgrimes } 105100627Srobert return (sb.st_mode & (S_IXUSR | S_IXGRP) ? 0 : 1); 1061590Srgrimes} 1071590Srgrimes 1081590Srgrimesstatic void 109201382Sedusage(void) 1101590Srgrimes{ 11199632Sjohan (void)fprintf(stderr, "usage: biff [n | y | b]\n"); 1121590Srgrimes exit(2); 1131590Srgrimes} 114