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 52334Ssetje * Common Development and Distribution License (the "License"). 62334Ssetje * 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 /* 22*5295Srandyf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <fcntl.h> 330Sstevel@tonic-gate #include <stdio.h> 340Sstevel@tonic-gate #include <stdlib.h> 350Sstevel@tonic-gate #include <unistd.h> 360Sstevel@tonic-gate #include <signal.h> 370Sstevel@tonic-gate #include <sys/uadmin.h> 380Sstevel@tonic-gate #include <bsm/libbsm.h> 390Sstevel@tonic-gate 402334Ssetje #define SMF_RST "/etc/svc/volatile/resetting" 412334Ssetje 420Sstevel@tonic-gate static const char *Usage = "Usage: %s cmd fcn [mdep]\n"; 430Sstevel@tonic-gate 440Sstevel@tonic-gate extern int audit_uadmin_setup(int, char **); 450Sstevel@tonic-gate extern int audit_uadmin_success(); 460Sstevel@tonic-gate 470Sstevel@tonic-gate int 480Sstevel@tonic-gate main(int argc, char *argv[]) 490Sstevel@tonic-gate { 500Sstevel@tonic-gate int cmd, fcn; 510Sstevel@tonic-gate uintptr_t mdep = NULL; 520Sstevel@tonic-gate sigset_t set; 530Sstevel@tonic-gate 540Sstevel@tonic-gate if (argc < 3 || argc > 4) { 550Sstevel@tonic-gate (void) fprintf(stderr, Usage, argv[0]); 560Sstevel@tonic-gate return (1); 570Sstevel@tonic-gate } 580Sstevel@tonic-gate 590Sstevel@tonic-gate (void) audit_uadmin_setup(argc, argv); 600Sstevel@tonic-gate 610Sstevel@tonic-gate (void) sigfillset(&set); 620Sstevel@tonic-gate (void) sigprocmask(SIG_BLOCK, &set, NULL); 630Sstevel@tonic-gate 640Sstevel@tonic-gate cmd = atoi(argv[1]); 650Sstevel@tonic-gate fcn = atoi(argv[2]); 660Sstevel@tonic-gate if (argc == 4) { /* mdep argument given */ 67*5295Srandyf if (cmd != A_REBOOT && cmd != A_SHUTDOWN && cmd != A_DUMP && 68*5295Srandyf cmd != A_FREEZE) { 690Sstevel@tonic-gate (void) fprintf(stderr, "%s: mdep argument not " 700Sstevel@tonic-gate "allowed for this cmd value\n", argv[0]); 710Sstevel@tonic-gate (void) fprintf(stderr, Usage, argv[0]); 720Sstevel@tonic-gate return (1); 730Sstevel@tonic-gate } else { 740Sstevel@tonic-gate mdep = (uintptr_t)argv[3]; 750Sstevel@tonic-gate } 760Sstevel@tonic-gate } 770Sstevel@tonic-gate 780Sstevel@tonic-gate if (geteuid() == 0) { 790Sstevel@tonic-gate if (audit_uadmin_success() == -1) 800Sstevel@tonic-gate (void) fprintf(stderr, "%s: can't turn off auditd\n", 810Sstevel@tonic-gate argv[0]); 820Sstevel@tonic-gate 830Sstevel@tonic-gate if (cmd == A_SHUTDOWN || cmd == A_REBOOT) 842334Ssetje (void) creat(SMF_RST, 0777); 850Sstevel@tonic-gate } 860Sstevel@tonic-gate 870Sstevel@tonic-gate if (uadmin(cmd, fcn, mdep) < 0) { 880Sstevel@tonic-gate perror("uadmin"); 890Sstevel@tonic-gate 902334Ssetje (void) unlink(SMF_RST); 912334Ssetje 920Sstevel@tonic-gate return (1); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate return (0); 960Sstevel@tonic-gate } 97