753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER START
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * The contents of this file are subject to the terms of the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Common Development and Distribution License (the "License").
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You may not use this file except in compliance with the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or http://www.opensolaris.org/os/licensing.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * See the License for the specific language governing permissions
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * and limitations under the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If applicable, add the following below this CDDL HEADER, with the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER END
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
e557d412e15c7f384b2ea3bf316a739a0f81cd55Christopher Kiick * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use is subject to license terms.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This file contains high level functions used by multiple utilities.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include "libscf_impl.h"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <assert.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <libuutil.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <string.h>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe#include <strings.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <stdlib.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/systeminfo.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/uadmin.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/utsname.h>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe#include <sys/secflags.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#ifdef __x86
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <smbios.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Check whether the platform is on the fastreboot_blacklist.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 1 if the platform has been blacklisted, 0 otherwise.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic int
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorescf_is_fb_blacklisted(void)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore smbios_hdl_t *shp;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore smbios_system_t sys;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore smbios_info_t info;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore id_t id;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int err;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int i;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore scf_simple_prop_t *prop = NULL;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore ssize_t numvals;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char *platform_name;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int blacklisted = 0;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If there's no SMBIOS, assume it's blacklisted.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((shp = smbios_open(NULL, SMB_VERSION, 0, &err)) == NULL)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (1);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If we can't read system info, assume it's blacklisted.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((id = smbios_info_system(shp, &sys)) == SMB_ERR ||
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore smbios_info_common(shp, id, &info) == SMB_ERR) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore blacklisted = 1;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore goto fb_out;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If we can't read the "platforms" property from property group
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * BOOT_CONFIG_PG_FBBLACKLIST, assume no platforms have
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * been blacklisted.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((prop = scf_simple_prop_get(NULL, FMRI_BOOT_CONFIG,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore BOOT_CONFIG_PG_FBBLACKLIST, "platforms")) == NULL)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore goto fb_out;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore numvals = scf_simple_prop_numvalues(prop);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < numvals; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore platform_name = scf_simple_prop_next_astring(prop);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (platform_name == NULL)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore break;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (strcmp(platform_name, info.smbi_product) == 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore blacklisted = 1;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore break;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefb_out:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore smbios_close(shp);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore scf_simple_prop_free(prop);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (blacklisted);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore/*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Add or get a property group given an FMRI.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Return SCF_SUCCESS on success, SCF_FAILED on failure.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorestatic int
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorescf_fmri_pg_get_or_add(const char *fmri, const char *pgname,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore const char *pgtype, uint32_t pgflags, int add)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore{
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_handle_t *handle = NULL;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_instance_t *inst = NULL;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore int rc = SCF_FAILED;
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore int error;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if ((handle = scf_handle_create(SCF_VERSION)) == NULL ||
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_handle_bind(handle) != 0 ||
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (inst = scf_instance_create(handle)) == NULL ||
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_handle_decode_fmri(handle, fmri, NULL, NULL,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore inst, NULL, NULL, SCF_DECODE_FMRI_EXACT) != SCF_SUCCESS)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore goto scferror;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (add) {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = scf_instance_add_pg(inst, pgname, pgtype, pgflags, NULL);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore /*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * If the property group already exists, return SCF_SUCCESS.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore if (rc != SCF_SUCCESS && scf_error() == SCF_ERROR_EXISTS)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = SCF_SUCCESS;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore } else {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = scf_instance_get_pg(inst, pgname, NULL);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorescferror:
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore if (rc != SCF_SUCCESS)
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore error = scf_error();
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_instance_destroy(inst);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (handle)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) scf_handle_unbind(handle);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_handle_destroy(handle);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore if (rc != SCF_SUCCESS)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) scf_set_error(error);
57b30532f440463cfdc0decec0c4b07e9c0991f6Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (rc);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif /* __x86 */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Get config properties from svc:/system/boot-config:default.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * It prints errors with uu_warn().
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorevoid
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorescf_get_boot_config(uint8_t *boot_config)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
d0b2dca528da7be0d70565a5655d328da4e28ec2Richard Lowe uint64_t ret = 0;
d0b2dca528da7be0d70565a5655d328da4e28ec2Richard Lowe
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore assert(boot_config);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *boot_config = 0;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Property vector for BOOT_CONFIG_PG_PARAMS property group.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore scf_propvec_t ua_boot_config[] = {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore { FASTREBOOT_DEFAULT, NULL, SCF_TYPE_BOOLEAN, NULL,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore UA_FASTREBOOT_DEFAULT },
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore { FASTREBOOT_ONPANIC, NULL, SCF_TYPE_BOOLEAN, NULL,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore UA_FASTREBOOT_ONPANIC },
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore { NULL }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore };
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore scf_propvec_t *prop;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (prop = ua_boot_config; prop->pv_prop != NULL; prop++)
d0b2dca528da7be0d70565a5655d328da4e28ec2Richard Lowe prop->pv_ptr = &ret;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore prop = NULL;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (scf_read_propvec(FMRI_BOOT_CONFIG, BOOT_CONFIG_PG_PARAMS,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore B_TRUE, ua_boot_config, &prop) != SCF_FAILED) {
e557d412e15c7f384b2ea3bf316a739a0f81cd55Christopher Kiick
e557d412e15c7f384b2ea3bf316a739a0f81cd55Christopher Kiick#ifdef __x86
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Unset both flags if the platform has been
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * blacklisted.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (scf_is_fb_blacklisted())
d0b2dca528da7be0d70565a5655d328da4e28ec2Richard Lowe return;
e557d412e15c7f384b2ea3bf316a739a0f81cd55Christopher Kiick#endif /* __x86 */
d0b2dca528da7be0d70565a5655d328da4e28ec2Richard Lowe *boot_config = (uint8_t)ret;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#if defined(FASTREBOOT_DEBUG)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (prop != NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) uu_warn("Service %s property '%s/%s' "
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore "not found.\n", FMRI_BOOT_CONFIG,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore BOOT_CONFIG_PG_PARAMS, prop->pv_prop);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore } else {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (void) uu_warn("Unable to read service %s "
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore "property '%s': %s\n", FMRI_BOOT_CONFIG,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore BOOT_CONFIG_PG_PARAMS, scf_strerror(scf_error()));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif /* FASTREBOOT_DEBUG */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore }
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore/*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Get or set properties in non-persistent "config_ovr" property group
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * in svc:/system/boot-config:default.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * It prints errors with uu_warn().
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore/*ARGSUSED*/
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorestatic int
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorescf_getset_boot_config_ovr(int set, uint8_t *boot_config_ovr)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore{
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore int rc = SCF_SUCCESS;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore assert(boot_config_ovr);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#ifndef __x86
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (rc);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#else
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore /*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Property vector for BOOT_CONFIG_PG_OVR property group.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_propvec_t ua_boot_config_ovr[] = {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore { FASTREBOOT_DEFAULT, NULL, SCF_TYPE_BOOLEAN, NULL,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore UA_FASTREBOOT_DEFAULT },
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore { FASTREBOOT_ONPANIC, NULL, SCF_TYPE_BOOLEAN, NULL,
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore UA_FASTREBOOT_ONPANIC },
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore { NULL }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore };
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_propvec_t *prop;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = scf_fmri_pg_get_or_add(FMRI_BOOT_CONFIG,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore BOOT_CONFIG_PG_OVR, SCF_GROUP_APPLICATION,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore SCF_PG_FLAG_NONPERSISTENT, set);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (rc != SCF_SUCCESS) {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#if defined(FASTREBOOT_DEBUG)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (set)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) uu_warn("Unable to add service %s "
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore "property group '%s'\n",
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore FMRI_BOOT_CONFIG, BOOT_CONFIG_PG_OVR);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#endif /* FASTREBOOT_DEBUG */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (rc);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore for (prop = ua_boot_config_ovr; prop->pv_prop != NULL; prop++)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore prop->pv_ptr = boot_config_ovr;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore prop = NULL;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (set)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = scf_write_propvec(FMRI_BOOT_CONFIG,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore BOOT_CONFIG_PG_OVR, ua_boot_config_ovr, &prop);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore else
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore rc = scf_read_propvec(FMRI_BOOT_CONFIG,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore BOOT_CONFIG_PG_OVR, B_FALSE, ua_boot_config_ovr,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore &prop);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#if defined(FASTREBOOT_DEBUG)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (rc != SCF_SUCCESS) {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore if (prop != NULL) {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) uu_warn("Service %s property '%s/%s' "
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore "not found.\n", FMRI_BOOT_CONFIG,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore BOOT_CONFIG_PG_OVR, prop->pv_prop);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore } else {
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) uu_warn("Unable to %s service %s "
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore "property '%s': %s\n", set ? "set" : "get",
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore FMRI_BOOT_CONFIG, BOOT_CONFIG_PG_OVR,
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_strerror(scf_error()));
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#endif /* FASTREBOOT_DEBUG */
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore if (set)
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore (void) smf_refresh_instance(FMRI_BOOT_CONFIG);
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (rc);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore }
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore#endif /* __x86 */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore}
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore/*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Get values of properties in non-persistent "config_ovr" property group.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moorevoid
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorescf_get_boot_config_ovr(uint8_t *boot_config_ovr)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore{
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore (void) scf_getset_boot_config_ovr(B_FALSE, boot_config_ovr);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore}
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore/*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Set value of "config_ovr/fastreboot_default".
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
4196e26398ab7019943a8f276006fa66937b4425Sherry Mooreint
4196e26398ab7019943a8f276006fa66937b4425Sherry Moorescf_fastreboot_default_set_transient(boolean_t value)
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore{
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore uint8_t boot_config_ovr = 0;
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore if (value == B_TRUE)
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore boot_config_ovr = UA_FASTREBOOT_DEFAULT | UA_FASTREBOOT_ONPANIC;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (scf_getset_boot_config_ovr(B_TRUE, &boot_config_ovr));
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore}
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Check whether Fast Reboot is the default operating mode.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 0 if
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 1. the platform is xVM
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 2. svc:/system/boot-config:default service doesn't exist,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * 3. property "config/fastreboot_default" doesn't exist,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * 4. value of property "config/fastreboot_default" is set to "false"
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * and "config_ovr/fastreboot_default" is not set to "true",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 5. the platform has been blacklisted.
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * or
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * 6. value of property "config_ovr/fastreboot_default" is set to "false".
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return non-zero otherwise.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreint
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorescf_is_fastboot_default(void)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore uint8_t boot_config = 0, boot_config_ovr;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char procbuf[SYS_NMLN];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If we are on xVM, do not fast reboot by default.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1 ||
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore strcmp(procbuf, "i86xpv") == 0)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (0);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore /*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Get property values from "config" property group
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore scf_get_boot_config(&boot_config);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore /*
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore * Get property values from non-persistent "config_ovr" property group
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore */
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore boot_config_ovr = boot_config;
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore scf_get_boot_config_ovr(&boot_config_ovr);
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore
4196e26398ab7019943a8f276006fa66937b4425Sherry Moore return (boot_config & boot_config_ovr & UA_FASTREBOOT_DEFAULT);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe/*
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe * Read the default security-flags from system/process-security and return a
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe * secflagset_t suitable for psecflags(2)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe *
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe * Unfortunately, this symbol must _exist_ in the native build, for the sake
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe * of the mapfile, even though we don't ever use it, and it will never work.
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe */
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowestruct group_desc {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe secflagdelta_t *delta;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe char *fmri;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe};
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Loweint
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowescf_default_secflags(scf_handle_t *hndl, scf_secflags_t *flags)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe{
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe#if !defined(NATIVE_BUILD)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe scf_property_t *prop;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe scf_value_t *val;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe const char *flagname;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe int flag;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe struct group_desc *g;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe struct group_desc groups[] = {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe {NULL, "svc:/system/process-security/"
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe ":properties/default"},
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe {NULL, "svc:/system/process-security/"
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe ":properties/lower"},
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe {NULL, "svc:/system/process-security/"
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe ":properties/upper"},
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe {NULL, NULL}
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe };
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe bzero(flags, sizeof (*flags));
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe groups[0].delta = &flags->ss_default;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe groups[1].delta = &flags->ss_lower;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe groups[2].delta = &flags->ss_upper;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe for (g = groups; g->delta != NULL; g++) {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe for (flag = 0; (flagname = secflag_to_str(flag)) != NULL;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe flag++) {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe char *pfmri;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe uint8_t flagval = 0;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if ((val = scf_value_create(hndl)) == NULL)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe return (-1);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if ((prop = scf_property_create(hndl)) == NULL) {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe scf_value_destroy(val);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe return (-1);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe }
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if ((pfmri = uu_msprintf("%s/%s", g->fmri,
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe flagname)) == NULL)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe uu_die("Allocation failure\n");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if (scf_handle_decode_fmri(hndl, pfmri,
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe NULL, NULL, NULL, NULL, prop, NULL) != 0)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe goto next;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if (scf_property_get_value(prop, val) != 0)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe goto next;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe (void) scf_value_get_boolean(val, &flagval);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe if (flagval != 0)
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe secflag_set(&g->delta->psd_add, flag);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe else
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe secflag_set(&g->delta->psd_rem, flag);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowenext:
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe uu_free(pfmri);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe scf_value_destroy(val);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe scf_property_destroy(prop);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe }
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe }
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe return (0);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe#else
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe assert(0);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe abort();
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe#endif /* !NATIVE_BUILD */
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe}