3  *
   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #include <sys/smbios_impl.h>
  28 
  29 static const uint_t _smb_hashlen = 64;          /* hash length (must be Pof2) */
  30 static const char _smb_emptystr[] = "";         /* empty string to return */
  31 int _smb_debug = 0;                             /* default debug mode */
  32 
  33 /*
  34  * Strip out identification information for you privacy weenies.  This is quite
  35  * simple using our smbios_info_common() abstraction: we just locate any serial
  36  * numbers and asset tags for each record, and then zero out those strings.
  37  * Then we must handle two special cases: SMB_TYPE_SYSTEM holds a 16-byte UUID
  38  * and SMB_TYPE_BATTERY stores a Smart Battery Data Spec 16-bit serial number.
  39  * We use a literal '0' rather than '\0' for zeroing strings because \0\0 in
  40  * the SMBIOS string table has a special meaning (denotes end-of-record).
  41  */
  42 static void
 
 
  65                         for (p = (char *)info.smbi_serial; *p != '\0'; p++)
  66                                 *p = '0';
  67                         for (p = (char *)info.smbi_asset; *p != '\0'; p++)
  68                                 *p = '0';
  69                 }
  70         }
  71 }
  72 
  73 smbios_hdl_t *
  74 smbios_bufopen(const smbios_entry_t *ep, const void *buf, size_t len,
  75     int version, int flags, int *errp)
  76 {
  77         smbios_hdl_t *shp = smb_zalloc(sizeof (smbios_hdl_t));
  78         const smb_header_t *hp, *nhp;
  79         const uchar_t *p, *q, *s;
  80         uint_t i, h;
  81 
  82         switch (version) {
  83         case SMB_VERSION_23:
  84         case SMB_VERSION_24:
  85                 break;
  86         default:
  87                 return (smb_open_error(shp, errp, ESMB_VERSION));
  88         }
  89 
  90         if (ep == NULL || buf == NULL || len == 0 || (flags & ~SMB_O_MASK))
  91                 return (smb_open_error(shp, errp, ESMB_INVAL));
  92 
  93         if (shp == NULL)
  94                 return (smb_open_error(shp, errp, ESMB_NOMEM));
  95 
  96         if (_smb_debug)
  97                 shp->sh_flags |= SMB_FL_DEBUG;
  98 
  99         if (strncmp(ep->smbe_eanchor, SMB_ENTRY_EANCHOR, SMB_ENTRY_EANCHORLEN))
 100                 return (smb_open_error(shp, errp, ESMB_HEADER));
 101 
 102         if (strncmp(ep->smbe_ianchor, SMB_ENTRY_IANCHOR, SMB_ENTRY_IANCHORLEN))
 103                 return (smb_open_error(shp, errp, ESMB_HEADER));
 104 
 
 | 
 
 
   3  *
   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
  24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 #include <sys/smbios_impl.h>
  29 
  30 static const uint_t _smb_hashlen = 64;          /* hash length (must be Pof2) */
  31 static const char _smb_emptystr[] = "";         /* empty string to return */
  32 int _smb_debug = 0;                             /* default debug mode */
  33 
  34 /*
  35  * Strip out identification information for you privacy weenies.  This is quite
  36  * simple using our smbios_info_common() abstraction: we just locate any serial
  37  * numbers and asset tags for each record, and then zero out those strings.
  38  * Then we must handle two special cases: SMB_TYPE_SYSTEM holds a 16-byte UUID
  39  * and SMB_TYPE_BATTERY stores a Smart Battery Data Spec 16-bit serial number.
  40  * We use a literal '0' rather than '\0' for zeroing strings because \0\0 in
  41  * the SMBIOS string table has a special meaning (denotes end-of-record).
  42  */
  43 static void
 
 
  66                         for (p = (char *)info.smbi_serial; *p != '\0'; p++)
  67                                 *p = '0';
  68                         for (p = (char *)info.smbi_asset; *p != '\0'; p++)
  69                                 *p = '0';
  70                 }
  71         }
  72 }
  73 
  74 smbios_hdl_t *
  75 smbios_bufopen(const smbios_entry_t *ep, const void *buf, size_t len,
  76     int version, int flags, int *errp)
  77 {
  78         smbios_hdl_t *shp = smb_zalloc(sizeof (smbios_hdl_t));
  79         const smb_header_t *hp, *nhp;
  80         const uchar_t *p, *q, *s;
  81         uint_t i, h;
  82 
  83         switch (version) {
  84         case SMB_VERSION_23:
  85         case SMB_VERSION_24:
  86         case SMB_VERSION_25:
  87         case SMB_VERSION_26:
  88         case SMB_VERSION_27:
  89         case SMB_VERSION_28:
  90                 break;
  91         default:
  92                 return (smb_open_error(shp, errp, ESMB_VERSION));
  93         }
  94 
  95         if (ep == NULL || buf == NULL || len == 0 || (flags & ~SMB_O_MASK))
  96                 return (smb_open_error(shp, errp, ESMB_INVAL));
  97 
  98         if (shp == NULL)
  99                 return (smb_open_error(shp, errp, ESMB_NOMEM));
 100 
 101         if (_smb_debug)
 102                 shp->sh_flags |= SMB_FL_DEBUG;
 103 
 104         if (strncmp(ep->smbe_eanchor, SMB_ENTRY_EANCHOR, SMB_ENTRY_EANCHORLEN))
 105                 return (smb_open_error(shp, errp, ESMB_HEADER));
 106 
 107         if (strncmp(ep->smbe_ianchor, SMB_ENTRY_IANCHOR, SMB_ENTRY_IANCHORLEN))
 108                 return (smb_open_error(shp, errp, ESMB_HEADER));
 109 
 
 |