LCOV - code coverage report
Current view: top level - nsswitch/libwbclient - wbc_guid.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 30 43 69.8 %
Date: 2024-02-28 12:06:22 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Winbind client API
       5             : 
       6             :    Copyright (C) Gerald (Jerry) Carter 2007
       7             : 
       8             : 
       9             :    This library is free software; you can redistribute it and/or
      10             :    modify it under the terms of the GNU Lesser General Public
      11             :    License as published by the Free Software Foundation; either
      12             :    version 3 of the License, or (at your option) any later version.
      13             : 
      14             :    This library is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :    Library General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : /* Required Headers */
      24             : 
      25             : #include "replace.h"
      26             : #include "libwbclient.h"
      27             : 
      28             : /* Convert a binary GUID to a character string */
      29             : _PUBLIC_
      30           4 : wbcErr wbcGuidToString(const struct wbcGuid *guid,
      31             :                        char **guid_string)
      32             : {
      33           0 :         char *result;
      34             : 
      35           4 :         result = (char *)wbcAllocateMemory(37, 1, NULL);
      36           4 :         if (result == NULL) {
      37           0 :                 return WBC_ERR_NO_MEMORY;
      38             :         }
      39           4 :         snprintf(result, 37,
      40             :                  "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
      41           4 :                  guid->time_low, guid->time_mid,
      42           4 :                  guid->time_hi_and_version,
      43           4 :                  guid->clock_seq[0],
      44           4 :                  guid->clock_seq[1],
      45           4 :                  guid->node[0], guid->node[1],
      46           4 :                  guid->node[2], guid->node[3],
      47           4 :                  guid->node[4], guid->node[5]);
      48           4 :         *guid_string = result;
      49             : 
      50           4 :         return WBC_ERR_SUCCESS;
      51             : }
      52             : 
      53             : /* @brief Convert a character string to a binary GUID */
      54             : _PUBLIC_
      55           8 : wbcErr wbcStringToGuid(const char *str,
      56             :                        struct wbcGuid *guid)
      57             : {
      58           0 :         unsigned int time_low;
      59           0 :         unsigned int time_mid, time_hi_and_version;
      60           0 :         unsigned int clock_seq[2];
      61           0 :         unsigned int node[6];
      62           0 :         int i;
      63           8 :         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
      64             : 
      65           8 :         if (!guid) {
      66           0 :                 wbc_status = WBC_ERR_INVALID_PARAM;
      67           0 :                 BAIL_ON_WBC_ERROR(wbc_status);
      68             :         }
      69             : 
      70           8 :         if (!str) {
      71           0 :                 wbc_status = WBC_ERR_INVALID_PARAM;
      72           0 :                 BAIL_ON_WBC_ERROR(wbc_status);
      73             :         }
      74             : 
      75           8 :         if (11 == sscanf(str, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
      76             :                          &time_low, &time_mid, &time_hi_and_version,
      77             :                          &clock_seq[0], &clock_seq[1],
      78             :                          &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
      79           8 :                 wbc_status = WBC_ERR_SUCCESS;
      80           0 :         } else if (11 == sscanf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
      81             :                                 &time_low, &time_mid, &time_hi_and_version,
      82             :                                 &clock_seq[0], &clock_seq[1],
      83             :                                 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
      84           0 :                 wbc_status = WBC_ERR_SUCCESS;
      85             :         }
      86             : 
      87           8 :         BAIL_ON_WBC_ERROR(wbc_status);
      88             : 
      89           8 :         guid->time_low = time_low;
      90           8 :         guid->time_mid = time_mid;
      91           8 :         guid->time_hi_and_version = time_hi_and_version;
      92           8 :         guid->clock_seq[0] = clock_seq[0];
      93           8 :         guid->clock_seq[1] = clock_seq[1];
      94             : 
      95          56 :         for (i=0;i<6;i++) {
      96          48 :                 guid->node[i] = node[i];
      97             :         }
      98             : 
      99           8 :         wbc_status = WBC_ERR_SUCCESS;
     100             : 
     101           8 : done:
     102           8 :         return wbc_status;
     103             : }

Generated by: LCOV version 1.14