VirtualBox

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

Last change on this file since 76452 was 76452, checked in by vboxsync, 6 years ago

IPRT: Ran scm --fix-err-h. bugref:9344

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette