source: branches/samba-3.3.x/source/nsswitch/libwbclient/wbc_guid.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 16 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 3.1 KB
Line 
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 "libwbclient.h"
26
27/** @brief Convert a binary GUID to a character string
28 *
29 * @param guid Binary Guid
30 * @param **guid_string Resulting character string
31 *
32 * @return #wbcErr
33 **/
34
35wbcErr wbcGuidToString(const struct wbcGuid *guid,
36 char **guid_string)
37{
38 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
39
40 if (!guid) {
41 wbc_status = WBC_ERR_INVALID_PARAM;
42 BAIL_ON_WBC_ERROR(wbc_status);
43 }
44
45 *guid_string = talloc_asprintf(NULL,
46 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
47 guid->time_low, guid->time_mid,
48 guid->time_hi_and_version,
49 guid->clock_seq[0],
50 guid->clock_seq[1],
51 guid->node[0], guid->node[1],
52 guid->node[2], guid->node[3],
53 guid->node[4], guid->node[5]);
54 BAIL_ON_PTR_ERROR((*guid_string), wbc_status);
55
56 wbc_status = WBC_ERR_SUCCESS;
57
58done:
59 return wbc_status;
60}
61
62/** @brief Convert a character string to a binary GUID
63 *
64 * @param *str Character string
65 * @param guid Resulting binary GUID
66 *
67 * @return #wbcErr
68 **/
69
70wbcErr wbcStringToGuid(const char *str,
71 struct wbcGuid *guid)
72{
73 uint32_t time_low;
74 uint32_t time_mid, time_hi_and_version;
75 uint32_t clock_seq[2];
76 uint32_t node[6];
77 int i;
78 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
79
80 if (!guid) {
81 wbc_status = WBC_ERR_INVALID_PARAM;
82 BAIL_ON_WBC_ERROR(wbc_status);
83 }
84
85 if (!str) {
86 wbc_status = WBC_ERR_INVALID_PARAM;
87 BAIL_ON_WBC_ERROR(wbc_status);
88 }
89
90 if (11 == sscanf(str, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
91 &time_low, &time_mid, &time_hi_and_version,
92 &clock_seq[0], &clock_seq[1],
93 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
94 wbc_status = WBC_ERR_SUCCESS;
95 } else if (11 == sscanf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
96 &time_low, &time_mid, &time_hi_and_version,
97 &clock_seq[0], &clock_seq[1],
98 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
99 wbc_status = WBC_ERR_SUCCESS;
100 }
101
102 BAIL_ON_WBC_ERROR(wbc_status);
103
104 guid->time_low = time_low;
105 guid->time_mid = time_mid;
106 guid->time_hi_and_version = time_hi_and_version;
107 guid->clock_seq[0] = clock_seq[0];
108 guid->clock_seq[1] = clock_seq[1];
109
110 for (i=0;i<6;i++) {
111 guid->node[i] = node[i];
112 }
113
114 wbc_status = WBC_ERR_SUCCESS;
115
116done:
117 return wbc_status;
118}
Note: See TracBrowser for help on using the repository browser.