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 | wbcErr wbcGuidToString(const struct wbcGuid *guid,
|
---|
30 | char **guid_string)
|
---|
31 | {
|
---|
32 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
---|
33 |
|
---|
34 | if (!guid) {
|
---|
35 | wbc_status = WBC_ERR_INVALID_PARAM;
|
---|
36 | BAIL_ON_WBC_ERROR(wbc_status);
|
---|
37 | }
|
---|
38 |
|
---|
39 | *guid_string = talloc_asprintf(NULL,
|
---|
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 | BAIL_ON_PTR_ERROR((*guid_string), wbc_status);
|
---|
49 |
|
---|
50 | wbc_status = WBC_ERR_SUCCESS;
|
---|
51 |
|
---|
52 | done:
|
---|
53 | return wbc_status;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /* @brief Convert a character string to a binary GUID */
|
---|
57 | wbcErr wbcStringToGuid(const char *str,
|
---|
58 | struct wbcGuid *guid)
|
---|
59 | {
|
---|
60 | uint32_t time_low;
|
---|
61 | uint32_t time_mid, time_hi_and_version;
|
---|
62 | uint32_t clock_seq[2];
|
---|
63 | uint32_t node[6];
|
---|
64 | int i;
|
---|
65 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
---|
66 |
|
---|
67 | if (!guid) {
|
---|
68 | wbc_status = WBC_ERR_INVALID_PARAM;
|
---|
69 | BAIL_ON_WBC_ERROR(wbc_status);
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (!str) {
|
---|
73 | wbc_status = WBC_ERR_INVALID_PARAM;
|
---|
74 | BAIL_ON_WBC_ERROR(wbc_status);
|
---|
75 | }
|
---|
76 |
|
---|
77 | if (11 == sscanf(str, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
---|
78 | &time_low, &time_mid, &time_hi_and_version,
|
---|
79 | &clock_seq[0], &clock_seq[1],
|
---|
80 | &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
|
---|
81 | wbc_status = WBC_ERR_SUCCESS;
|
---|
82 | } else if (11 == sscanf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
---|
83 | &time_low, &time_mid, &time_hi_and_version,
|
---|
84 | &clock_seq[0], &clock_seq[1],
|
---|
85 | &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
|
---|
86 | wbc_status = WBC_ERR_SUCCESS;
|
---|
87 | }
|
---|
88 |
|
---|
89 | BAIL_ON_WBC_ERROR(wbc_status);
|
---|
90 |
|
---|
91 | guid->time_low = time_low;
|
---|
92 | guid->time_mid = time_mid;
|
---|
93 | guid->time_hi_and_version = time_hi_and_version;
|
---|
94 | guid->clock_seq[0] = clock_seq[0];
|
---|
95 | guid->clock_seq[1] = clock_seq[1];
|
---|
96 |
|
---|
97 | for (i=0;i<6;i++) {
|
---|
98 | guid->node[i] = node[i];
|
---|
99 | }
|
---|
100 |
|
---|
101 | wbc_status = WBC_ERR_SUCCESS;
|
---|
102 |
|
---|
103 | done:
|
---|
104 | return wbc_status;
|
---|
105 | }
|
---|