s3: torture: Add SMB1-TRUNCATED-SESSSETUP test.
[Samba.git] / nsswitch / libwbclient / wbc_guid.c
blob72701c8c574d10df5c9ae9c2bd6cf43d38b7aa4b
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind client API
6 Copyright (C) Gerald (Jerry) Carter 2007
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.
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.
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/>.
23 /* Required Headers */
25 #include "replace.h"
26 #include "libwbclient.h"
28 /* Convert a binary GUID to a character string */
29 _PUBLIC_
30 wbcErr wbcGuidToString(const struct wbcGuid *guid,
31 char **guid_string)
33 char *result;
35 result = (char *)wbcAllocateMemory(37, 1, NULL);
36 if (result == NULL) {
37 return WBC_ERR_NO_MEMORY;
39 snprintf(result, 37,
40 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
41 guid->time_low, guid->time_mid,
42 guid->time_hi_and_version,
43 guid->clock_seq[0],
44 guid->clock_seq[1],
45 guid->node[0], guid->node[1],
46 guid->node[2], guid->node[3],
47 guid->node[4], guid->node[5]);
48 *guid_string = result;
50 return WBC_ERR_SUCCESS;
53 /* @brief Convert a character string to a binary GUID */
54 _PUBLIC_
55 wbcErr wbcStringToGuid(const char *str,
56 struct wbcGuid *guid)
58 unsigned int time_low;
59 unsigned int time_mid, time_hi_and_version;
60 unsigned int clock_seq[2];
61 unsigned int node[6];
62 int i;
63 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
65 if (!guid) {
66 wbc_status = WBC_ERR_INVALID_PARAM;
67 BAIL_ON_WBC_ERROR(wbc_status);
70 if (!str) {
71 wbc_status = WBC_ERR_INVALID_PARAM;
72 BAIL_ON_WBC_ERROR(wbc_status);
75 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 wbc_status = WBC_ERR_SUCCESS;
80 } 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 wbc_status = WBC_ERR_SUCCESS;
87 BAIL_ON_WBC_ERROR(wbc_status);
89 guid->time_low = time_low;
90 guid->time_mid = time_mid;
91 guid->time_hi_and_version = time_hi_and_version;
92 guid->clock_seq[0] = clock_seq[0];
93 guid->clock_seq[1] = clock_seq[1];
95 for (i=0;i<6;i++) {
96 guid->node[i] = node[i];
99 wbc_status = WBC_ERR_SUCCESS;
101 done:
102 return wbc_status;