xref: /titanic_50/usr/src/cmd/uadmin/uadmin.c (revision 58091fd8689db902780a10667e0e8118a9454b8f)
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*58091fd8Ssetje  * Common Development and Distribution License (the "License").
6*58091fd8Ssetje  * 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 /*
22*58091fd8Ssetje  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <fcntl.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <signal.h>
377c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
387c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
397c478bd9Sstevel@tonic-gate 
40*58091fd8Ssetje #define	SMF_RST "/etc/svc/volatile/resetting"
41*58091fd8Ssetje 
427c478bd9Sstevel@tonic-gate static const char *Usage = "Usage: %s cmd fcn [mdep]\n";
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate extern int audit_uadmin_setup(int, char **);
457c478bd9Sstevel@tonic-gate extern int audit_uadmin_success();
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate int
487c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate 	int cmd, fcn;
517c478bd9Sstevel@tonic-gate 	uintptr_t mdep = NULL;
527c478bd9Sstevel@tonic-gate 	sigset_t set;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	if (argc < 3 || argc > 4) {
557c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, Usage, argv[0]);
567c478bd9Sstevel@tonic-gate 		return (1);
577c478bd9Sstevel@tonic-gate 	}
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	(void) audit_uadmin_setup(argc, argv);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	(void) sigfillset(&set);
627c478bd9Sstevel@tonic-gate 	(void) sigprocmask(SIG_BLOCK, &set, NULL);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	cmd = atoi(argv[1]);
657c478bd9Sstevel@tonic-gate 	fcn = atoi(argv[2]);
667c478bd9Sstevel@tonic-gate 	if (argc == 4) {	/* mdep argument given */
677c478bd9Sstevel@tonic-gate 		if (cmd != A_REBOOT && cmd != A_SHUTDOWN && cmd != A_DUMP) {
687c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: mdep argument not "
697c478bd9Sstevel@tonic-gate 			    "allowed for this cmd value\n", argv[0]);
707c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, Usage, argv[0]);
717c478bd9Sstevel@tonic-gate 			return (1);
727c478bd9Sstevel@tonic-gate 		} else {
737c478bd9Sstevel@tonic-gate 			mdep = (uintptr_t)argv[3];
747c478bd9Sstevel@tonic-gate 		}
757c478bd9Sstevel@tonic-gate 	}
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	if (geteuid() == 0) {
787c478bd9Sstevel@tonic-gate 		if (audit_uadmin_success() == -1)
797c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: can't turn off auditd\n",
807c478bd9Sstevel@tonic-gate 			    argv[0]);
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 		if (cmd == A_SHUTDOWN || cmd == A_REBOOT)
83*58091fd8Ssetje 			(void) creat(SMF_RST, 0777);
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	if (uadmin(cmd, fcn, mdep) < 0) {
877c478bd9Sstevel@tonic-gate 		perror("uadmin");
887c478bd9Sstevel@tonic-gate 
89*58091fd8Ssetje 		(void) unlink(SMF_RST);
90*58091fd8Ssetje 
917c478bd9Sstevel@tonic-gate 		return (1);
927c478bd9Sstevel@tonic-gate 	}
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	return (0);
957c478bd9Sstevel@tonic-gate }
96