xref: /titanic_41/usr/src/cmd/uadmin/uadmin.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <fcntl.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <signal.h>
38 #include <sys/uadmin.h>
39 #include <bsm/libbsm.h>
40 
41 static const char *Usage = "Usage: %s cmd fcn [mdep]\n";
42 
43 extern int audit_uadmin_setup(int, char **);
44 extern int audit_uadmin_success();
45 
46 int
47 main(int argc, char *argv[])
48 {
49 	int cmd, fcn;
50 	uintptr_t mdep = NULL;
51 	sigset_t set;
52 
53 	if (argc < 3 || argc > 4) {
54 		(void) fprintf(stderr, Usage, argv[0]);
55 		return (1);
56 	}
57 
58 	(void) audit_uadmin_setup(argc, argv);
59 
60 	(void) sigfillset(&set);
61 	(void) sigprocmask(SIG_BLOCK, &set, NULL);
62 
63 	cmd = atoi(argv[1]);
64 	fcn = atoi(argv[2]);
65 	if (argc == 4) {	/* mdep argument given */
66 		if (cmd != A_REBOOT && cmd != A_SHUTDOWN && cmd != A_DUMP) {
67 			(void) fprintf(stderr, "%s: mdep argument not "
68 			    "allowed for this cmd value\n", argv[0]);
69 			(void) fprintf(stderr, Usage, argv[0]);
70 			return (1);
71 		} else {
72 			mdep = (uintptr_t)argv[3];
73 		}
74 	}
75 
76 	if (geteuid() == 0) {
77 		if (audit_uadmin_success() == -1)
78 			(void) fprintf(stderr, "%s: can't turn off auditd\n",
79 			    argv[0]);
80 
81 		if (cmd == A_SHUTDOWN || cmd == A_REBOOT)
82 			(void) creat("/etc/svc/volatile/resetting", 0777);
83 	}
84 
85 	if (uadmin(cmd, fcn, mdep) < 0) {
86 		perror("uadmin");
87 
88 		/* GLXXX unlink resetting file? */
89 		return (1);
90 	}
91 
92 	return (0);
93 }
94