VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/solaris/RTSystemQueryDmiString-solaris.cpp

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: RTSystemQueryDmiString-solaris.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryDmiString, solaris ring-3.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/system.h>
42#include "internal/iprt.h"
43
44#include <iprt/errcore.h>
45#include <iprt/assert.h>
46#include <iprt/string.h>
47
48#include <smbios.h>
49#include <errno.h>
50
51
52RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
53{
54 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
55 AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
56 *pszBuf = '\0';
57 AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
58
59 int rc = VERR_NOT_SUPPORTED;
60 int err = 0;
61 smbios_hdl_t *pSMB = smbios_open(NULL /* default fd */, SMB_VERSION, 0 /* flags */, &err);
62 if (pSMB)
63 {
64 smbios_system_t hSMBSys;
65 id_t hSMBId = smbios_info_system(pSMB, &hSMBSys);
66 if (hSMBId != SMB_ERR)
67 {
68 /* Don't need the common bits for the product UUID. */
69 if (enmString == RTSYSDMISTR_PRODUCT_UUID)
70 {
71 static char const s_szHex[17] = "0123456789ABCDEF";
72 char szData[64];
73 char *pszData = szData;
74 unsigned cchUuid = RT_MIN(hSMBSys.smbs_uuidlen, sizeof(szData) - 1);
75 for (unsigned i = 0; i < cchUuid; i++)
76 {
77 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] >> 4];
78 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] & 0xf];
79 if (i == 3 || i == 5 || i == 7 || i == 9)
80 *pszData++ = '-';
81 }
82 *pszData = '\0';
83 rc = RTStrCopy(pszBuf, cbBuf, szData);
84 smbios_close(pSMB);
85 return rc;
86 }
87
88 smbios_info_t hSMBInfo;
89 id_t hSMBInfoId = smbios_info_common(pSMB, hSMBId, &hSMBInfo);
90 if (hSMBInfoId != SMB_ERR)
91 {
92 switch (enmString)
93 {
94 case RTSYSDMISTR_PRODUCT_NAME: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_product); break;
95 case RTSYSDMISTR_PRODUCT_VERSION: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_version); break;
96 case RTSYSDMISTR_PRODUCT_SERIAL: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_serial); break;
97 case RTSYSDMISTR_MANUFACTURER: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_manufacturer); break;
98
99 default: /* make gcc happy */
100 rc = VERR_NOT_SUPPORTED;
101 }
102 smbios_close(pSMB);
103 return rc;
104 }
105 }
106
107 /* smbios_* error path. */
108 err = smbios_errno(pSMB);
109 smbios_close(pSMB);
110 }
111
112 /* Do some error conversion. */
113 if (err == EPERM || err == EACCES)
114 rc = VERR_ACCESS_DENIED;
115 return rc;
116}
117
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use