-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactive_sync_uuid.php
More file actions
executable file
·74 lines (62 loc) · 2.1 KB
/
active_sync_uuid.php
File metadata and controls
executable file
·74 lines (62 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?
function active_sync_create_guid($version = 4, $name = "localhost", $namespace = "{00000000-0000-0000-0000-000000000000}")
{
# be careful on non 64 bit machines
# $namespace could be /etc/machine-id
# $name could be /etc/hostname
$time_low = 0;
$time_mid = 0;
$time_hi = 0;
$clock_seq_high = 0;
$clock_seq_low = 0;
$node = 0;
# time-based version
if($version == 1)
{
$time = gettimeofday();
$time = ($time["sec"] * 10 * 1000 * 1000) + ($time["usec"] * 10) + 0x01B21DD213814000;
$time_low = ((intval($time / 0x00000001) >> 0) & 0xffffffff);
$time_mid = ((intval($time / 0xffffffff) >> 0) & 0x0000ffff);
$time_hi = ((intval($time / 0xffffffff) >> 16) & 0x0000ffff);
}
# DCE Security version, with embedded POSIX UIDs
if($version == 2)
{
}
# name-based version that uses MD5 hashing
if($version == 3)
{
$namespace = hex2bin(str_replace(["-", "{", "}"], "", $namespace));
$hash = md5($namespace . $name);
$time_low = hexdec(substr($hash, 0, 8));
$time_mid = hexdec(substr($hash, 8, 4));
$time_hi = hexdec(substr($hash, 12, 4));
$clock_seq_high = hexdec(substr($hash, 16, 2));
$clock_seq_low = hexdec(substr($hash, 18, 2));
$node = hexdec(substr($hash, 20, 12));
}
# randomly or pseudo-randomly generated version
if($version == 4)
{
$time_low = mt_rand(0, 0xffffffff);
$time_mid = mt_rand(0, 0xffff);
$time_hi = mt_rand(0, 0xffff);
$clock_seq_high = mt_rand(0, 0xff);
$clock_seq_low = mt_rand(0, 0xff);
$node = mt_rand(0, 0xffffffffffff);
}
# name-based version that uses SHA-1 hashing
if($version == 5)
{
$namespace = hex2bin(str_replace(["-", "{", "}"], "", $namespace));
$hash = sha1($namespace . $name);
$time_low = hexdec(substr($hash, 0, 8));
$time_mid = hexdec(substr($hash, 8, 4));
$time_hi = hexdec(substr($hash, 12, 4));
$clock_seq_high = hexdec(substr($hash, 16, 2));
$clock_seq_low = hexdec(substr($hash, 18, 2));
$node = hexdec(substr($hash, 20, 12));
}
return(sprintf("%08x-%04x-%04x-%02x%02x-%012x", $time_low, $time_mid, ($version << 12) | ($time_hi & 0x0FFF), 0x80 | ($clock_seq_high & 0x3F), $clock_seq_low, $node));
}
?>