1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <fm/fmd_fmri.h> 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate /* 32*0Sstevel@tonic-gate * buf_append -- Append str to buf (if it's non-NULL). Place prepend 33*0Sstevel@tonic-gate * in buf in front of str and append behind it (if they're non-NULL). 34*0Sstevel@tonic-gate * Continue to update size even if we run out of space to actually 35*0Sstevel@tonic-gate * stuff characters in the buffer. 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate static void 38*0Sstevel@tonic-gate buf_append(ssize_t *sz, char *buf, size_t buflen, char *str, 39*0Sstevel@tonic-gate char *prepend, char *append) 40*0Sstevel@tonic-gate { 41*0Sstevel@tonic-gate ssize_t left; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if (str == NULL) 44*0Sstevel@tonic-gate return; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate if (buflen == 0 || (left = buflen - *sz) < 0) 47*0Sstevel@tonic-gate left = 0; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate if (buf != NULL && left != 0) 50*0Sstevel@tonic-gate buf += *sz; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate if (prepend == NULL && append == NULL) 53*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s", str); 54*0Sstevel@tonic-gate else if (append == NULL) 55*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s", prepend, str); 56*0Sstevel@tonic-gate else if (prepend == NULL) 57*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s", str, append); 58*0Sstevel@tonic-gate else 59*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s%s", prepend, str, append); 60*0Sstevel@tonic-gate } 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate ssize_t 63*0Sstevel@tonic-gate fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) 64*0Sstevel@tonic-gate { 65*0Sstevel@tonic-gate nvlist_t *anvl = NULL; 66*0Sstevel@tonic-gate uint8_t version; 67*0Sstevel@tonic-gate ssize_t size = 0; 68*0Sstevel@tonic-gate char *pkgname = NULL; 69*0Sstevel@tonic-gate char *achas = NULL; 70*0Sstevel@tonic-gate char *adom = NULL; 71*0Sstevel@tonic-gate char *aprod = NULL; 72*0Sstevel@tonic-gate char *asrvr = NULL; 73*0Sstevel@tonic-gate char *ahost = NULL; 74*0Sstevel@tonic-gate int more_auth = 0; 75*0Sstevel@tonic-gate int err; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || 78*0Sstevel@tonic-gate version > FM_PKG_SCHEME_VERSION) 79*0Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* Get authority, if present */ 82*0Sstevel@tonic-gate err = nvlist_lookup_nvlist(nvl, FM_FMRI_AUTHORITY, &anvl); 83*0Sstevel@tonic-gate if (err != 0 && err != ENOENT) 84*0Sstevel@tonic-gate return (fmd_fmri_set_errno(err)); 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* 87*0Sstevel@tonic-gate * For brevity, we only include the pkgname and any authority 88*0Sstevel@tonic-gate * info present in the FMRI in our output string. The FMRI 89*0Sstevel@tonic-gate * also has data on the package directory and version. 90*0Sstevel@tonic-gate */ 91*0Sstevel@tonic-gate err = nvlist_lookup_string(nvl, FM_FMRI_PKG_INST, &pkgname); 92*0Sstevel@tonic-gate if (err != 0 || pkgname == NULL) 93*0Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate if (anvl != NULL) { 96*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 97*0Sstevel@tonic-gate FM_FMRI_AUTH_PRODUCT, &aprod); 98*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 99*0Sstevel@tonic-gate FM_FMRI_AUTH_CHASSIS, &achas); 100*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 101*0Sstevel@tonic-gate FM_FMRI_AUTH_DOMAIN, &adom); 102*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 103*0Sstevel@tonic-gate FM_FMRI_AUTH_SERVER, &asrvr); 104*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 105*0Sstevel@tonic-gate FM_FMRI_AUTH_HOST, &ahost); 106*0Sstevel@tonic-gate if (aprod != NULL) 107*0Sstevel@tonic-gate more_auth++; 108*0Sstevel@tonic-gate if (achas != NULL) 109*0Sstevel@tonic-gate more_auth++; 110*0Sstevel@tonic-gate if (adom != NULL) 111*0Sstevel@tonic-gate more_auth++; 112*0Sstevel@tonic-gate if (asrvr != NULL) 113*0Sstevel@tonic-gate more_auth++; 114*0Sstevel@tonic-gate if (ahost != NULL) 115*0Sstevel@tonic-gate more_auth++; 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* pkg:// */ 119*0Sstevel@tonic-gate buf_append(&size, buf, buflen, FM_FMRI_SCHEME_PKG, NULL, "://"); 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate /* authority, if any */ 122*0Sstevel@tonic-gate if (aprod != NULL) 123*0Sstevel@tonic-gate buf_append(&size, buf, buflen, aprod, FM_FMRI_AUTH_PRODUCT "=", 124*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 125*0Sstevel@tonic-gate if (achas != NULL) 126*0Sstevel@tonic-gate buf_append(&size, buf, buflen, achas, FM_FMRI_AUTH_CHASSIS "=", 127*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 128*0Sstevel@tonic-gate if (adom != NULL) 129*0Sstevel@tonic-gate buf_append(&size, buf, buflen, adom, FM_FMRI_AUTH_DOMAIN "=", 130*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 131*0Sstevel@tonic-gate if (asrvr != NULL) 132*0Sstevel@tonic-gate buf_append(&size, buf, buflen, asrvr, FM_FMRI_AUTH_SERVER "=", 133*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 134*0Sstevel@tonic-gate if (ahost != NULL) 135*0Sstevel@tonic-gate buf_append(&size, buf, buflen, ahost, FM_FMRI_AUTH_HOST "=", 136*0Sstevel@tonic-gate NULL); 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* pkg-name part */ 139*0Sstevel@tonic-gate buf_append(&size, buf, buflen, pkgname, "/", NULL); 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate return (size); 142*0Sstevel@tonic-gate } 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate /* 145*0Sstevel@tonic-gate * fmd_fmri_present() is called by fmadm to determine if a faulty ASRU 146*0Sstevel@tonic-gate * is still present in the system. In general we don't expect to get 147*0Sstevel@tonic-gate * ASRUs in this scheme, so it's unlikely this routine will get called. 148*0Sstevel@tonic-gate * In case it does, though, we just return true by default, as we have no 149*0Sstevel@tonic-gate * real way to look up the component in the system configuration. 150*0Sstevel@tonic-gate */ 151*0Sstevel@tonic-gate /*ARGSUSED*/ 152*0Sstevel@tonic-gate int 153*0Sstevel@tonic-gate fmd_fmri_present(nvlist_t *nvl) 154*0Sstevel@tonic-gate { 155*0Sstevel@tonic-gate return (1); 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate /* 159*0Sstevel@tonic-gate * fmd_fmri_unusable() is called by fmadm to determine if a faulty ASRU 160*0Sstevel@tonic-gate * is usable. In general we don't expect to get ASRUs in this scheme, 161*0Sstevel@tonic-gate * so it's unlikely this routine will get called. In case it does, 162*0Sstevel@tonic-gate * though, we just return false by default, as we have no real way to 163*0Sstevel@tonic-gate * find the component or determine the component's usability. 164*0Sstevel@tonic-gate */ 165*0Sstevel@tonic-gate /*ARGSUSED*/ 166*0Sstevel@tonic-gate int 167*0Sstevel@tonic-gate fmd_fmri_unusable(nvlist_t *nvl) 168*0Sstevel@tonic-gate { 169*0Sstevel@tonic-gate return (0); 170*0Sstevel@tonic-gate } 171