r3462: separate out the crypto includes
[ira/wip.git] / source / lib / util_uuid.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  UUID server routines
4  *  Copyright (C) Theodore Ts'o               1996, 1997,
5  *  Copyright (C) Jim McDonough                     2002.
6  *  Copyright (C) Andrew Tridgell                   2003.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *  
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *  
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include "includes.h"
24
25 void uuid_generate_random(struct GUID *out)
26 {
27         generate_random_buffer((unsigned char *)out, sizeof(struct GUID));
28         out->clock_seq[0] = (out->clock_seq[0] & 0x3F) | 0x80;
29         out->time_hi_and_version = (out->time_hi_and_version & 0x0FFF) | 0x4000;
30 }
31
32 BOOL uuid_all_zero(const struct GUID *u)
33 {
34         if (u->time_low != 0 ||
35             u->time_mid != 0 ||
36             u->time_hi_and_version != 0 ||
37             u->clock_seq[0] != 0 ||
38             u->clock_seq[1] != 0 ||
39             !all_zero(u->node, 6)) {
40                 return False;
41         }
42         return True;
43 }
44
45 BOOL uuid_equal(const struct GUID *u1, const struct GUID *u2)
46 {
47         if (u1->time_low != u2->time_low ||
48             u1->time_mid != u2->time_mid ||
49             u1->time_hi_and_version != u2->time_hi_and_version ||
50             u1->clock_seq[0] != u2->clock_seq[0] ||
51             u1->clock_seq[1] != u2->clock_seq[1] ||
52             memcmp(u1->node, u2->node, 6) != 0) {
53                 return False;
54         }
55         return True;
56 }
57
58 BOOL policy_handle_empty(struct policy_handle *h) 
59 {
60         return (h->handle_type == 0 && uuid_all_zero(&h->uuid));
61 }
62