2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Theodore Ts'o 1996, 1997,
5 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Offset between 15-Oct-1582 and 1-Jan-70
27 #define TIME_OFFSET_HIGH 0x01B21DD2
28 #define TIME_OFFSET_LOW 0x13814000
33 uint16 time_hi_and_version
;
39 static void uuid_pack(const struct uuid
*uu
, GUID
*ptr
)
41 uint8
*out
= ptr
->info
;
43 SIVAL(out
, 0, uu
->time_low
);
44 SSVAL(out
, 4, uu
->time_mid
);
45 SSVAL(out
, 6, uu
->time_hi_and_version
);
46 memcpy(out
+8, uu
->clock_seq
, 2);
47 memcpy(out
+10, uu
->node
, 6);
50 static void uuid_unpack(const GUID in
, struct uuid
*uu
)
52 const uint8
*ptr
= in
.info
;
54 uu
->time_low
= IVAL(ptr
, 0);
55 uu
->time_mid
= SVAL(ptr
, 4);
56 uu
->time_hi_and_version
= SVAL(ptr
, 6);
57 memcpy(uu
->clock_seq
, ptr
+8, 2);
58 memcpy(uu
->node
, ptr
+10, 6);
61 void smb_uuid_generate_random(GUID
*out
)
66 generate_random_buffer(tmp
.info
, sizeof(tmp
.info
), True
);
67 uuid_unpack(tmp
, &uu
);
69 uu
.clock_seq
[0] = (uu
.clock_seq
[0] & 0x3F) | 0x80;
70 uu
.time_hi_and_version
= (uu
.time_hi_and_version
& 0x0FFF) | 0x4000;
74 char *smb_uuid_to_string(const GUID in
)
81 asprintf(&out
, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
82 uu
.time_low
, uu
.time_mid
, uu
.time_hi_and_version
,
83 uu
.clock_seq
[0], uu
.clock_seq
[1],
84 uu
.node
[0], uu
.node
[1], uu
.node
[2],
85 uu
.node
[3], uu
.node
[4], uu
.node
[5]);
90 const char *smb_uuid_string_static(const GUID in
)
96 slprintf(out
, sizeof(out
) -1,
97 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
98 uu
.time_low
, uu
.time_mid
, uu
.time_hi_and_version
,
99 uu
.clock_seq
[0], uu
.clock_seq
[1],
100 uu
.node
[0], uu
.node
[1], uu
.node
[2],
101 uu
.node
[3], uu
.node
[4], uu
.node
[5]);