Unleashed v1.4
[unleashed.git] / bin / uadmin / uadmin.c
blob26206e578fbfb580f7e7abddedf95d9ac72ffb37
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <strings.h>
36 #include <signal.h>
37 #include <unistd.h>
38 #include <libscf_priv.h>
40 #include <sys/types.h>
41 #include <sys/uadmin.h>
42 #include <sys/wait.h>
44 #define SMF_RST "/etc/svc/volatile/resetting"
45 #define RETRY_COUNT 15 /* number of 1 sec retries for audit(8) to complete */
47 static const char *Usage = "Usage: %s cmd fcn [mdep]\n";
49 int
50 main(int argc, char *argv[])
52 int cmd, fcn;
53 uintptr_t mdep = (uintptr_t)NULL;
54 sigset_t set;
56 if (argc < 3 || argc > 4) {
57 (void) fprintf(stderr, Usage, argv[0]);
58 return (1);
61 (void) sigfillset(&set);
62 (void) sigprocmask(SIG_BLOCK, &set, NULL);
64 cmd = atoi(argv[1]);
65 fcn = atoi(argv[2]);
66 if (argc == 4) { /* mdep argument given */
67 if (cmd != A_REBOOT && cmd != A_SHUTDOWN && cmd != A_DUMP &&
68 cmd != A_FREEZE) {
69 (void) fprintf(stderr, "%s: mdep argument not "
70 "allowed for this cmd value\n", argv[0]);
71 (void) fprintf(stderr, Usage, argv[0]);
72 return (1);
73 } else {
74 mdep = (uintptr_t)argv[3];
78 switch (fcn) {
79 case AD_HALT:
80 case AD_POWEROFF:
81 case AD_BOOT:
82 case AD_IBOOT:
83 case AD_SBOOT:
84 case AD_SIBOOT:
85 case AD_NOSYNC:
86 break;
87 case AD_FASTREBOOT:
88 case AD_FASTREBOOT_DRYRUN:
89 mdep = (uintptr_t)NULL; /* Ignore all arguments */
90 break;
91 default:
92 break;
95 if (cmd == A_CONFIG) {
96 uint8_t boot_config = 0;
97 uint8_t boot_config_ovr = 0;
99 switch (fcn) {
100 case AD_UPDATE_BOOT_CONFIG:
101 scf_get_boot_config(&boot_config);
102 boot_config_ovr = boot_config;
103 scf_get_boot_config_ovr(&boot_config_ovr);
104 boot_config &= boot_config_ovr;
105 mdep = (uintptr_t)(&boot_config);
106 break;
110 if (geteuid() == 0) {
111 if (cmd == A_SHUTDOWN || cmd == A_REBOOT)
112 (void) creat(SMF_RST, 0777);
115 if (uadmin(cmd, fcn, mdep) < 0) {
116 perror("uadmin");
118 (void) unlink(SMF_RST);
120 return (1);
123 return (0);