Update of /cvsroot/xplc/xplc/uuid
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4380/uuid
Added Files:
.cvsignore COPYING ChangeLog clear.c compare.c copy.c
gen_uuid.c gen_uuid_nt.c isnull.c pack.c parse.c rules.mk
unpack.c unparse.c uuid.h uuidP.h uuid_time.c uuid_types.h.in
vars.mk
Log Message:
Add a UUID generation program that also spits out XPLC C definitions.
This is supposed to be quite portable, so I've only used what POSIX gives us.
http://bugs.debian.org/310755
--- NEW FILE: compare.c ---
/*
* compare.c --- compare whether or not two UUID's are the same
*
* Returns 0 if the two UUID's are different, and 1 if they are the same.
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include "uuidP.h"
#include <string.h>
#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
int uuid_compare(const uuid_t uu1, const uuid_t uu2)
{
struct uuid uuid1, uuid2;
uuid_unpack(uu1, &uuid1);
uuid_unpack(uu2, &uuid2);
UUCMP(uuid1.time_low, uuid2.time_low);
UUCMP(uuid1.time_mid, uuid2.time_mid);
UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
UUCMP(uuid1.clock_seq, uuid2.clock_seq);
return memcmp(uuid1.node, uuid2.node, 6);
}
--- NEW FILE: rules.mk ---
# XPLC - Cross-Platform Lightweight Components
# Copyright (C) 2005, Net Integration Technologies, Inc.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# $Id: rules.mk,v 1.1 2005/10/21 13:18:22 sfllaw Exp $
default: $(UUID_OBJS) $(UUID_BINS) uuid/bin/uuidcdef
uuid/libuuid.a: $(patsubst %.c,%.o,$(wildcard uuid/*.c))
uuid/bin/uuidcdef: uuid/bin/uuidgen
$(LN_S) $(notdir $<) $@
uuid/bin/%: uuid/bin/%.o $(with_uuid_static)
$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
uuid/bin/%: LDLIBS+=$(with_uuid)
--- NEW FILE: unpack.c ---
/*
* Internal routine for unpacking UUID
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include <string.h>
#include "uuidP.h"
void uuid_unpack(const uuid_t in, struct uuid *uu)
{
const uint8_t *ptr = in;
uint32_t tmp;
tmp = *ptr++;
tmp = (tmp << 8) | *ptr++;
tmp = (tmp << 8) | *ptr++;
tmp = (tmp << 8) | *ptr++;
uu->time_low = tmp;
tmp = *ptr++;
tmp = (tmp << 8) | *ptr++;
uu->time_mid = tmp;
tmp = *ptr++;
tmp = (tmp << 8) | *ptr++;
uu->time_hi_and_version = tmp;
tmp = *ptr++;
tmp = (tmp << 8) | *ptr++;
uu->clock_seq = tmp;
memcpy(uu->node, ptr, 6);
}
--- NEW FILE: .cvsignore ---
.*.d
*.o
libuuid.a
uuid_types.h
--- NEW FILE: ChangeLog ---
2005-10-18 Simon Law <sf...@ni...>
* Imported libuuid into XPLC.
* rules.mk vars.mk: Build system changes.
* gen_uuid_nt.c: Better Win32 support.
2005-06-30 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.38
2005-03-21 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.37
2006-02-05 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.36
2005-02-05 Theodore Ts'o <ty...@mi...>
* Makefile.in: Remove uuid.pc on a "make distclean"
2005-01-26 Theodore Ts'o <ty...@mi...>
* uuid.pc.in: Add pkg-config files.
2005-01-18 Theodore Ts'o <ty...@mi...>
* Makefile.in: Fix the kernel compile-time echo commands to be
consistent and portable
2005-01-17 Theodore Ts'o <ty...@mi...>
* uuidP.h: Use inttypes.h in preference to stdint.h for
compatibility with older FreeBSD and Solaris systems.
2004-12-14 Theodore Ts'o <ty...@mi...>
* Makefile.in: Use Linux-kernel-style makefile output for "make
install"
* Makefile.in (installdirs): Use $(MKINSTALLDIRS) macro.
Update dependencies.
2004-11-30 Theodore Ts'o <ty...@mi...>
* Makefile.in: Use Linux-kernel-style makefile output to make it
easier to see errors/warnings.
2004-09-17 Theodore Ts'o <ty...@mi...>
* gen_uuid.c (get_node_id): glibc always defines AF_LINK, so only
try to use struct sockaddr_dl if HAVE_NET_IF_DL_H is
defined. (Addresses Debian Bug #256669)
2004-05-27 Theodore Ts'o <ty...@mi...>
* uuid.h (UUID_DEFINE): Make the UUID defined as a static
variable, with __attribute__ ((unused)) if we are using GCC.
2004-05-04 Theodore Ts'o <ty...@mi...>
* Update and clean up uuid man pages
* gen_uuid.c (uuid_generate_time): Mask off the timestamp to avoid
a Y8.8888K problem.
2004-04-03 Theodore Ts'o <ty...@mi...>
* Makefile.in: Update the modtime even if subst doesn't need to
update the libuuid man pages, to avoid always re-running
subst, especially since there are no dependencies on the
man page.
2004-04-03 Theodore Ts'o <ty...@mi...>
* libuuid.3.in, uuid_clear.3.in, uuid_compare.3.in, uuid_copy.3.in,
uuid_generate.3.in, uuid_is_null.3.in, uuid_parse.3.in,
uuid_time.3.in, uuid_unparse.3.in: Change licensing of man
pages from GPL to 3-clause BSD-style.
* uuid_parse.3.in, uuid_unparse.3.in: Change the use of the term
"internal format" to "binary representation".
* gen_uuid.c, pack.c, unpack.c, uuid_time.c, uuidP.h,
uuid_types.h.in: Use ANSI C99 types if stdint.h exists.
2004-03-30 Theodore Ts'o <ty...@mi...>
* gen_uuid.c (get_node_id): Clean up AF_LINK #ifdef's for Darwin.
2004-03-22 Theodore Ts'o <ty...@mi...>
* unparse.c (uuid_unparse_lower, uuid_unparse_upper),
uuid_unparse.3.in, uuid.h: Add new functions.
2004-03-19 Theodore Ts'o <ty...@mi...>
* Change the license to be the 3-clause BSD-style license
* uuid.h (UUID_DEFINE): Add UUID type #define's, and add an CPP
macro to define UUID constants.
* gen_uuid.c (get_clock): Use 14 bits for the clock sequence,
instead of just 13 bits.
* gen_uuid.c (get_node_id): Fix so that Darwin will actually get
the ethernet address correctly.
2004-02-29 Brian Bergstrand <br...@be...>
* Makefile.in: Use $(BSDLIB_PIC_FLAG) to determine whether to use
-fpic or -fPIC
2004-02-28 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.35
2004-01-30 Theodore Ts'o <ty...@mi...>
* gen_uuid.c (uuid_generate_time): Fix bug pointed out by Ralf
S. Engelshall; when generating a random ethernet address
because one is not available, set the least significant
bit of the first byte of the MAC address, since it is the
first bit to be transmitted, and is therefore the
multicast bit.
2003-07-25 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.34
2003-04-21 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.33
2003-04-21 Theodore Ts'o <ty...@mi...>
* Makefile.in: Use DYLD_LIBRAY_PATH so that "make check" works on
Darwin systems when building with shared libraries.
2003-04-12 Theodore Ts'o <ty...@mi...>
* gen_uuid.c: Add #ifdef checks around #include <sys/ioctl.h> and
<sys/socket.h>.
2003-04-03 Theodore Ts'o <ty...@mi...>
* gen_uuid.c (get_random_bytes): Always xor in a stream of bytes
from the system PRNG (i.e., random/srandom, seeded from
the time, pid, and uid) in case /dev/random isn't doing
the right thing on a particular system. It doesn't hurt,
and it can help, in the case of a buggy /dev/random.
2003-03-14 Theodore Ts'o <ty...@mi...>
* Makefile.in: Add support for Apple Darwin
2003-03-06 Theodore Tso <ty...@mi...>
* uuid_types.h.in: Don't redefine types if other e2fsprogs
*_types.h files have been included already.
* Makefile.in (tst_uuid): Link against the static library instead
of all of the object files, so that we automatically pick
up -lsocket under Solaris.
2003-03-02 Theodore Ts'o <ty...@mi...>
* Makefile.in, uuidP.h, uuid_types.h.in: Use uuid_types.h instead
of ext2_types.h
2002-11-09 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.32
2002-11-08 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.31
2002-10-31 Theodore Ts'o <ty...@mi...>
* Release of E2fsprogs 1.30
2002-10-31 Theodore Ts'o <ty...@mi...>
* gen_uuid.c (get_random_bytes): Don't spin forever if read()
returns EINTR or EAGAIN, so that when /dev/random is
opened O_NONBLOCK, we don't end up spinning forever.
2001-09-24 Theodore Tso <ty...@mi...>
* Release of E2fsprogs 1.29
2001-08-31 Theodore Tso <ty...@th...>
* Release of E2fsprogs 1.28
2002-07-15 Theodore Ts'o <ty...@mi...>
* parse.c (uuid_parse): Fix uuid parsing bug which didn't complain
for certain types of invalid input text. (Addresses
Debian bug #152891).
* tst_uuid.c: Add test cases for invalid text strings passed to
uuid_parse.
2002-03-08 Theodore Tso <ty...@mi...>
* Release of E2fsprogs 1.27
2002-02-24 Theodore Tso <ty...@mi...>
* Makefile.in (install): Install hard links to man pages for
uuid_generate_random and uuid_generate_time. Remove
any compressed man pages before installing the man pages.
2002-02-03 Theodore Tso <ty...@th...>
* Release of E2fsprogs 1.26
2001-09-20 Theodore Tso <ty...@th...>
* Release of E2fsprogs 1.25
2001-09-10 Theodore Tso <ty...@mi...>
* compare.c (uuid_compare), copy.c (uuid_copy),
isnull.c (uuid_is_null), pack.c (uuid_pack),
parse.c (uuid_parse), unpack.c (uuid_unpack),
unparse.c (uuid_unparse), uuid.h, uuidP.h,
uuid_time.c (uuid_time, uuid_type, uuid_variant):
Use const for pointer variables that we don't modify. Add
the appropriate ifdef's in uuid.h to make it be C++ friendly.
2001-09-02 Theodore Tso <ty...@th...>
* Release of E2fsprogs 1.24a
2001-08-30 Theodore Tso <ty...@th...>
* Release of E2fsprogs 1.24
2001-08-15 Theodore Tso <ty...@va...>
* Release of E2fsprogs 1.23
2001-06-23 Theodore Tso <ty...@va...>
* Release of E2fsprogs 1.22
2001-06-21 Theodore Tso <ty...@va...>
* uuid.h: Add protection against multiple inclusion
2001-06-15 Theodore Tso <ty...@va...>
* Release of E2fsprogs 1.21
2001-06-01 Theodore Tso <ty...@va...>
* Makefile.in, uuidP.h: Move include/asm/types.h.in to
lib/ext2fs/ext2_types.h.in.
2001-06-01 Theodore Tso <ty...@va...>
* unpack.c, unparse.c, uuid_time.c: Update files to be under the
LGPL (that somehow were missed when libuuid was converted
to use the LGPL). Whoops.
2001-05-25 Theodore Tso <ty...@va...>
* Release of E2fsprogs 1.20
2001-05-14 Theodore Tso <ty...@va...>
* tst_uuid.c, uuid_time.c: Remove unneeded #include of ext2_fs.h
2001-05-12 Theodore Tso <ty...@va...>
* libuuid.3.in, uuid_clear.3.in, uuid_compare.3.in, uuid_copy.3.in,
uuid_generate.3.in, uuid_is_null.3.in, uuid_parse.3.in,
uuid_time.3.in, uuid_unparse.3.in: Update URL location of
e2fsprogs package.
2001-05-01 Theodore Tso <ty...@va...>
* parse.c, compare.c: Include string.h to fix gcc -Wall
complaints.
* gen_uuid.c: Define _SVID_SOURCE to avoid gcc -Wall errors
because some required structures wouldn't be otherwise
defined. Fix a minor gcc -Wall nit in the declaration of
get_random_fd().
2001-01-12 Theodore Ts'o <ty...@va...>
* uuid_time.c (main), tst_uuid.c (main): Fix gcc -Wall complaints.
* uuid.h, copy.c (uuid_copy): Change arguments to make it
clear which argument is the source and which is the
destination.
* gen_uuid.c (get_random_fd): Use gettimeofday to seed the PRNG,
so we can take advantage of tv_usec to do (slightly)
better at seeding it.
2000-07-13 <ty...@va...>
* Release of E2fsprogs 1.19
2000-07-07 Theodore Ts'o <ty...@va...>
* Makefile.in (uuid_time): Fix compilation rule so that
uuid_time.o doesn't get bashed in order to build the
command-line version of uuid_time.
2000-07-04 Theodore Ts'o <ty...@va...>
* Makefile.in: Remove explicit link of -lc in the shared library.
(It shouldn't be necessary, and is harmful in some cases).
2000-06-12 Theodore Ts'o <ty...@va...>
* gen_uuid.c (get_random_bytes): Use O_NONBLOCK when trying to
open /dev/random. Break out the /dev/random
initialization code into a get_random_fd() function, and
use that function in uuid_generate() to determine whether
to use uuid_generate_random() or uuid_generate_time().
2000-05-25 <ty...@sn...>
* Makefile: Add hack dependency rule so that parallel makes work
correctly.
2000-04-07 Theodore Ts'o <ty...@va...>
* clear.c, compare.c, copy.c, gen_uuid.c, isnull.c, pack.c,
parse.c, uuid.h, uuidP.h: Changed copyright to be the
LGPL.
Thu Apr 6 17:38:58 2000 Theodore Y. Ts'o <ty...@si...>
* Makefile.in (uuid_time): Compile uuid_time in two steps (first
create .o, then link it against the libraries) to work
around bug in a.out linker.
* dll/jump.funcs, dll/jump.import, dll/jump.params: Update a.out
shared library control files to reflect new added files.
2000-04-03 Theodore Ts'o <ty...@va...>
* gen_uuid.c (get_clock): Fix bug where the last timeval wasn't
getting set, causing potentially duplicate UUID's to be
generated.
2000-03-12 Theodore Ts'o <ty...@va...>
* gen_uuid.c (get_random_bytes): Make more paranoid about
misbehaving /dev/urandom. If we get a return of zero
without an error more than 8 times in a row, we break out
and return an error. Also, if /dev/urandom doesn't exist,
try /dev/random.
2000-01-18 Theodore Ts'o <ty...@va...>
* Makefile.in: Since LIBUUID can sometimes include
"-lsocket" we need a separate DEPLIBUUID that can be used
in Makefile's dependency rules.
1999-11-19 <ty...@va...>
* Makefile.in (distclean): Remove TAGS and Makefile.in.old from
the source directory.
1999-11-10 <ty...@va...>
* Release of E2fsprogs 1.18
1999-10-26 <ty...@va...>
* Release of E2fsprogs 1.17
1999-10-26 <ty...@va...>
* uuid_time.c (variant_string): Declare to be static to avoid gcc
warnings.
* uuid.h: Add function prototypes for uuid_generate_random() and
uuid_generate_time().
1999-10-25 <ty...@va...>
* gen_uuid_nt.c (uuid_generate): W2K strikes again! An
incompatible interface change means we need to detect
whether the code is running on an NT4 or NT5 system.
1999-10-22 <ty...@va...>
* Release of E2fsprogs 1.16
1999-10-21 <ty...@va...>
* uuid_generate.8.in: Update man page to use a more standard
format (bold option flags and italicized variables), as
suggested by Andreas Dilger (ad...@en...)
1999-09-24 <ty...@va...>
* gen_uuid_nt.c: New file which creates a UUID under Windows NT.
1999-07-18 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs 1.15
1999-05-17 <ty...@rs...>
* gen_uuid.c (get_random_bytes): Use a while loop when reading
from /dev/urandom so that if we get interrupted while
reading the right thing happens.
(uuid_generate_random): Add new function which uses the
new UUID format which uses 122 random bits to form the
128-bit UUID.
(uuid_generate): Rename the old uuid_generate to be
uuid_generate_time, and create a new uuid_generate
function which calls either uuid_generate_random or
uuid_genereate_time depending on whether /dev/urandom is
present.
* uuid_generate.3.in: Update to reflect changesin uuid_generate
and its two new variants.
* tst_uuid.c: Updated to test new uuid_generate functions, and to
reflect new semantics of uuid_compare. Added tests to
make sure the UUID type and variant created by UUID
generate is correct.
* uuid_time.c (uuid_variant, uuid_type): Added new functions to
return the UUID variant and type information. The
debugging program now prints the UUID variant and type,
and warns if the unparsed time information is likely to be
incorrect.
* uuid_parse.3.in, libuuid.3.in: Miscellaneous text cleanups.
1999-05-03 <ty...@rs...>
* compare.c (uuid_compare): Change sense of uuid_compare so that
its return values match that of memcpy and the
uuid_compare() found in Paul Leach's internet-draft.
1999-03-11 Andreas Dilger <ad...@en...>
* Created man pages for libuuid functions.
1999-01-09 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs 1.14
1998-12-15 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs 1.13
1998-12-04 Theodore Ts'o <ty...@rs...>
* Makefile.in: Update version numbers of the UUID shared library,
since we've added a new function (uuid_time()).
* uuid_time.c: New file which returns the time field of a UUID.
(Good for debugging purposes)
1998-07-09 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs 1.12
1998-06-25 Theodore Ts'o <ty...@rs...>
* tst_uuid.c (main): Fixed bogus declaration of the main's argv
parameter.
1998-04-26 Theodore Ts'o <ty...@rs...>
* uuidP.h: Use asm/types.h instead of linux/types.h to avoid a
problem caused by glibc hack to prevent linux/types.h from
being included.
1998-03-30 Theodore Ts'o <ty...@rs...>
* Makefile.in: Change to use new installation directory variables
convention. Fix uninstall rules to take $(DESTDIR) into
account.
Sun Mar 8 22:17:59 1998 Theodore Ts'o <ty...@rs...>
* gen_uuid.c (get_node_id): Use char * instead of caddr_t, which
doesn't always exist for glibc.
Tue Oct 14 21:48:16 1997 Theodore Ts'o <ty...@rs...>
* gen_uuid.c: Use clock_reg instead of clock, since clock
conflicts with a header file declaration.
Tue Jun 17 01:33:20 1997 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs 1.11
Thu Apr 24 12:16:42 1997 Theodre Ts'o <ty...@lo...>
* Release of E2fsprogs version 1.10
Thu Apr 17 12:23:38 1997 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs version 1.09
Fri Apr 11 18:56:26 1997 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs version 1.08
Wed Mar 12 13:32:05 1997 Theodore Y. Ts'o <ty...@mi...>
* Release of E2fsprogs version 1.07
Sun Mar 2 16:45:36 1997 Theodore Ts'o <ty...@rs...>
* Makefile.in (ELF_VERSION): Change version to be 1.1
Thu Feb 6 23:08:07 1997 Theodore Ts'o <ty...@rs...>
* gen_uuid.c (uuid_generate): Set Multicast bit when picking a
random node_id, to prevent conflicts with IEEE 802
addresses obtained from network cards.
Wed Jan 1 23:51:09 1997 Theodore Ts'o <ty...@rs...>
* unpack.c, pack.c: Include string.h, since we use memcpy().
Tue Dec 3 13:05:11 1996 Theodore Ts'o <ty...@rs...>
* parse.c: Add #include of ctype.h and stdlib.h, to pull in the
required prototypes.
Fri Oct 11 17:15:10 1996 Theodore Ts'o <ty...@rs...>
* Makefile.in (DLL_ADDRESS): Updated DLL address for libuuid.
Tue Oct 8 02:02:03 1996 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs version 1.06
Thu Sep 12 15:23:07 1996 Theodore Ts'o <ty...@rs...>
* Release of E2fsprogs version 1.05
Tue Aug 27 16:50:43 1996 Miles Bader <mi...@gn...>
* uuid/gen_uuid.c [HAVE_NET_IF_H] <net/if.h>: Include guarded.
[HAVE_NETINET_IN_H] <netinet/in.h>: Include guarded.
(get_node_id): Surround bulk of function with #ifdef HAVE_NET_IF_H.
Tue Aug 27 16:50:16 1996 Theodore Ts'o <ty...@rs...>
* gen_uuid.c (get_node_id): Add a specific ifdef for the HURD,
since it is broken w.r.t getting hardware addresses.
--- NEW FILE: gen_uuid.c ---
/*
* gen_uuid.c --- generate a DCE-compatible uuid
*
* Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
* Copyright (C) 2005, Net Integration Technologies, Inc.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#ifndef WIN32
/*
* Force inclusion of SVID stuff since we need it if we're compiling in
* gcc-wall wall mode
*/
#define _SVID_SOURCE
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/file.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif
#include "uuidP.h"
#ifdef HAVE_SRANDOM
#define srand(x) srandom(x)
#define rand() random()
#endif
static int get_random_fd(void)
{
struct timeval tv;
static int fd = -2;
int i;
if (fd == -2) {
gettimeofday(&tv, 0);
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
}
/* Crank the random number generator a few times */
gettimeofday(&tv, 0);
for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
rand();
return fd;
}
/*
* Generate a series of random bytes. Use /dev/urandom if possible,
* and if not, use srandom/random.
*/
static void get_random_bytes(void *buf, int nbytes)
{
int i, n = nbytes, fd = get_random_fd();
int lose_counter = 0;
unsigned char *cp = (unsigned char *) buf;
if (fd >= 0) {
while (n > 0) {
i = read(fd, cp, n);
if (i <= 0) {
if (lose_counter++ > 16)
break;
continue;
}
n -= i;
cp += i;
lose_counter = 0;
}
}
/*
* We do this all the time, but this is the only source of
* randomness if /dev/random/urandom is out to lunch.
*/
for (cp = buf, i = 0; i < nbytes; i++)
*cp++ ^= (rand() >> 7) & 0xFF;
return;
}
/*
* Get the ethernet hardware address, if we can find it...
*/
static int get_node_id(unsigned char *node_id)
{
#ifdef HAVE_NET_IF_H
int sd;
struct ifreq ifr, *ifrp;
struct ifconf ifc;
char buf[1024];
int n, i;
unsigned char *a;
#ifdef HAVE_NET_IF_DL_H
struct sockaddr_dl *sdlp;
#endif
/*
* BSD 4.4 defines the size of an ifreq to be
* max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
* However, under earlier systems, sa_len isn't present, so the size is
* just sizeof(struct ifreq)
*/
#ifdef HAVE_SA_LEN
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#define ifreq_size(i) max(sizeof(struct ifreq),\
sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
#else
#define ifreq_size(i) sizeof(struct ifreq)
#endif /* HAVE_SA_LEN*/
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sd < 0) {
return -1;
}
memset(buf, 0, sizeof(buf));
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
close(sd);
return -1;
}
n = ifc.ifc_len;
for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
#ifdef SIOCGIFHWADDR
if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
continue;
a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
#else
#ifdef SIOCGENADDR
if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
continue;
a = (unsigned char *) ifr.ifr_enaddr;
#else
#ifdef HAVE_NET_IF_DL_H
sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
continue;
a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
#else
/*
* XXX we don't have a way of getting the hardware
* address
*/
close(sd);
return 0;
#endif /* HAVE_NET_IF_DL_H */
#endif /* SIOCGENADDR */
#endif /* SIOCGIFHWADDR */
if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
continue;
if (node_id) {
memcpy(node_id, a, 6);
close(sd);
return 1;
}
}
close(sd);
#endif
return 0;
}
/* Assume that the gettimeofday() has microsecond granularity */
#define MAX_ADJUSTMENT 10
static int get_clock(uint32_t *clock_high, uint32_t *clock_low, uint16_t *ret_clock_seq)
{
static int adjustment = 0;
static struct timeval last = {0, 0};
static uint16_t clock_seq;
struct timeval tv;
unsigned long long clock_reg;
try_again:
gettimeofday(&tv, 0);
if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
get_random_bytes(&clock_seq, sizeof(clock_seq));
clock_seq &= 0x3FFF;
last = tv;
last.tv_sec--;
}
if ((tv.tv_sec < last.tv_sec) ||
((tv.tv_sec == last.tv_sec) &&
(tv.tv_usec < last.tv_usec))) {
clock_seq = (clock_seq+1) & 0x3FFF;
adjustment = 0;
last = tv;
} else if ((tv.tv_sec == last.tv_sec) &&
(tv.tv_usec == last.tv_usec)) {
if (adjustment >= MAX_ADJUSTMENT)
goto try_again;
adjustment++;
} else {
adjustment = 0;
last = tv;
}
clock_reg = tv.tv_usec*10 + adjustment;
clock_reg += ((unsigned long long) tv.tv_sec)*10000000;
clock_reg += (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
*clock_high = clock_reg >> 32;
*clock_low = clock_reg;
*ret_clock_seq = clock_seq;
return 0;
}
void uuid_generate_time(uuid_t out)
{
static unsigned char node_id[6];
static int has_init = 0;
struct uuid uu;
uint32_t clock_mid;
if (!has_init) {
if (get_node_id(node_id) <= 0) {
get_random_bytes(node_id, 6);
/*
* Set multicast bit, to prevent conflicts
* with IEEE 802 addresses obtained from
* network cards
*/
node_id[0] |= 0x01;
}
has_init = 1;
}
get_clock(&clock_mid, &uu.time_low, &uu.clock_seq);
uu.clock_seq |= 0x8000;
uu.time_mid = (uint16_t) clock_mid;
uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
memcpy(uu.node, node_id, 6);
uuid_pack(&uu, out);
}
void uuid_generate_random(uuid_t out)
{
uuid_t buf;
struct uuid uu;
get_random_bytes(buf, sizeof(buf));
uuid_unpack(buf, &uu);
uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000;
uuid_pack(&uu, out);
}
/*
* This is the generic front-end to uuid_generate_random and
* uuid_generate_time. It uses uuid_generate_random only if
* /dev/urandom is available, since otherwise we won't have
* high-quality randomness.
*/
void uuid_generate(uuid_t out)
{
if (get_random_fd() >= 0)
uuid_generate_random(out);
else
uuid_generate_time(out);
}
#endif /* WIN32 */
--- NEW FILE: uuid.h ---
/*
* Public include file for the UUID library
*
* Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#ifndef _UUID_UUID_H
#define _UUID_UUID_H
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
typedef unsigned char uuid_t[16];
/* UUID Variant definitions */
#define UUID_VARIANT_NCS 0
#define UUID_VARIANT_DCE 1
#define UUID_VARIANT_MICROSOFT 2
#define UUID_VARIANT_OTHER 3
/* UUID Type definitions */
#define UUID_TYPE_DCE_TIME 1
#define UUID_TYPE_DCE_RANDOM 4
/* Allow UUID constants to be defined */
#ifdef __GNUC__
#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
#else
#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* clear.c */
void uuid_clear(uuid_t uu);
/* compare.c */
int uuid_compare(const uuid_t uu1, const uuid_t uu2);
/* copy.c */
void uuid_copy(uuid_t dst, const uuid_t src);
/* gen_uuid.c */
void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
void uuid_generate_time(uuid_t out);
/* isnull.c */
int uuid_is_null(const uuid_t uu);
/* parse.c */
int uuid_parse(const char *in, uuid_t uu);
/* unparse.c */
void uuid_unparse(const uuid_t uu, char *out);
void uuid_unparse_lower(const uuid_t uu, char *out);
void uuid_unparse_upper(const uuid_t uu, char *out);
/* uuid_time.c */
time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
int uuid_type(const uuid_t uu);
int uuid_variant(const uuid_t uu);
#ifdef __cplusplus
}
#endif
#endif /* _UUID_UUID_H */
--- NEW FILE: uuidP.h ---
/*
* uuid.h -- private header file for uuids
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#include <uuid/uuid_types.h>
#endif
#include <sys/types.h>
#include "uuid.h"
/*
* Offset between 15-Oct-1582 and 1-Jan-70
*/
#define TIME_OFFSET_HIGH 0x01B21DD2
#define TIME_OFFSET_LOW 0x13814000
struct uuid {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_version;
uint16_t clock_seq;
uint8_t node[6];
};
/*
* prototypes
*/
void uuid_pack(const struct uuid *uu, uuid_t ptr);
void uuid_unpack(const uuid_t in, struct uuid *uu);
--- NEW FILE: uuid_types.h.in ---
/*
* If linux/types.h is already been included, assume it has defined
* everything we need. (cross fingers) Other header files may have
* also defined the types that we need.
*/
#if (!defined(_STDINT_H) && !defined(_UUID_STDINT_H))
#define _UUID_STDINT_H
typedef unsigned char uint8_t;
typedef signed char int8_t;
#if (@SIZEOF_INT@ == 8)
typedef int int64_t;
typedef unsigned int uint64_t;
#elif (@SIZEOF_LONG@ == 8)
typedef long int64_t;
typedef unsigned long uint64_t;
#elif (@SIZEOF_LONG_LONG@ == 8)
#if defined(__GNUC__)
typedef __signed__ long long int64_t;
#else
typedef signed long long int64_t;
#endif
typedef unsigned long long uint64_t;
#endif
#if (@SIZEOF_INT@ == 2)
typedef int int16_t;
typedef unsigned int uint16_t;
#elif (@SIZEOF_SHORT@ == 2)
typedef short int16_t;
typedef unsigned short uint16_t;
#else
?==error: undefined 16 bit type
#endif
#if (@SIZEOF_INT@ == 4)
typedef int int32_t;
typedef unsigned int uint32_t;
#elif (@SIZEOF_LONG@ == 4)
typedef long int32_t;
typedef unsigned long uint32_t;
#elif (@SIZEOF_SHORT@ == 4)
typedef short int32_t;
typedef unsigned short uint32_t;
#else
?== error: undefined 32 bit type
#endif
#endif
--- NEW FILE: clear.c ---
/*
* clear.c -- Clear a UUID
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include "string.h"
#include "uuidP.h"
void uuid_clear(uuid_t uu)
{
memset(uu, 0, 16);
}
--- NEW FILE: gen_uuid_nt.c ---
/*
* gen_uuid_nt.c -- Use NT api to generate uuid
*
* Written by Andrey Shedel (an...@ns...)
* Copyright (C) 2005, Net Integration Technologies, Inc.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#ifdef WIN32
#include "uuidP.h"
#pragma warning(push,4)
#pragma comment(lib, "ntdll.lib")
//
// Here is a nice example why it's not a good idea
// to use native API in ordinary applications.
// Number of parameters in function below was changed from 3 to 4
// for NT5.
//
//
// NTSYSAPI
// NTSTATUS
// NTAPI
// NtAllocateUuids(
// OUT PULONG p1,
// OUT PULONG p2,
// OUT PULONG p3,
// OUT PUCHAR Seed // 6 bytes
// );
//
//
unsigned long
__stdcall
NtAllocateUuids(
void* p1, // 8 bytes
void* p2, // 4 bytes
void* p3 // 4 bytes
);
typedef
unsigned long
(__stdcall*
NtAllocateUuids_2000)(
void* p1, // 8 bytes
void* p2, // 4 bytes
void* p3, // 4 bytes
void* seed // 6 bytes
);
//
// Nice, but instead of including ntddk.h ot winnt.h
// I should define it here because they MISSED __stdcall in those headers.
//
__declspec(dllimport)
struct _TEB*
__stdcall
NtCurrentTeb(void);
//
// The only way to get version information from the system is to examine
// one stored in PEB. But it's pretty dangerouse because this value could
// be altered in image header.
//
static
int
Nt5(void)
{
//return NtCuttentTeb()->Peb->OSMajorVersion >= 5;
return (int)*(int*)((char*)(int)(*(int*)((char*)NtCurrentTeb() + 0x30)) + 0xA4) >= 5;
}
/* Use the native Windows UUID generation facilities. */
void uuid_generate(uuid_t out)
{
if(Nt5())
{
unsigned char seed[6];
((NtAllocateUuids_2000)NtAllocateUuids)(out, ((char*)out)+8, ((char*)out)+12, &seed[0] );
}
else
{
NtAllocateUuids(out, ((char*)out)+8, ((char*)out)+12);
}
}
/* The following two functions exist to provide compatibility. */
void uuid_generate_random(uuid_t out)
{
uuid_generate(out);
}
void uuid_generate_time(uuid_t out)
{
uuid_generate(out);
}
#endif /* WIN32 */
--- NEW FILE: unparse.c ---
/*
* unparse.c -- convert a UUID to string
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include <stdio.h>
#include "uuidP.h"
static const char *fmt_lower =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
static const char *fmt_upper =
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
#ifdef UUID_UNPARSE_DEFAULT_UPPER
#define FMT_DEFAULT fmt_upper
#else
#define FMT_DEFAULT fmt_lower
#endif
static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
{
struct uuid uuid;
uuid_unpack(uu, &uuid);
sprintf(out, fmt,
uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
uuid.node[0], uuid.node[1], uuid.node[2],
uuid.node[3], uuid.node[4], uuid.node[5]);
}
void uuid_unparse_lower(const uuid_t uu, char *out)
{
uuid_unparse_x(uu, out, fmt_lower);
}
void uuid_unparse_upper(const uuid_t uu, char *out)
{
uuid_unparse_x(uu, out, fmt_upper);
}
void uuid_unparse(const uuid_t uu, char *out)
{
uuid_unparse_x(uu, out, FMT_DEFAULT);
}
--- NEW FILE: vars.mk ---
# XPLC - Cross-Platform Lightweight Components
# Copyright (C) 2005, Net Integration Technologies, Inc.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# $Id: vars.mk,v 1.1 2005/10/21 13:18:22 sfllaw Exp $
UUID_BINS=uuid/bin/uuidgen uuid/bin/tst_uuid
UUID_OBJS=$(addsuffix .o,$(UUID_BINS))
CLEAN+=$(UUID_BINS) $(UUID_OBJS) uuid/bin/uuidcdef uuid/libuuid.a
DISTCLEAN+=uuid/uuid_types.h
uuid/%.o: CFLAGS+=-I. -include include/autoconf.h
--- NEW FILE: COPYING ---
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, and the entire permission notice in its entirety,
including the disclaimer of warranties.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
--- NEW FILE: parse.c ---
/*
* parse.c --- UUID parsing
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "uuidP.h"
int uuid_parse(const char *in, uuid_t uu)
{
struct uuid uuid;
int i;
const char *cp;
char buf[3];
if (strlen(in) != 36)
return -1;
for (i=0, cp = in; i <= 36; i++,cp++) {
if ((i == 8) || (i == 13) || (i == 18) ||
(i == 23)) {
if (*cp == '-')
continue;
else
return -1;
}
if (i== 36)
if (*cp == 0)
continue;
if (!isxdigit(*cp))
return -1;
}
uuid.time_low = strtoul(in, NULL, 16);
uuid.time_mid = strtoul(in+9, NULL, 16);
uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
uuid.clock_seq = strtoul(in+19, NULL, 16);
cp = in+24;
buf[2] = 0;
for (i=0; i < 6; i++) {
buf[0] = *cp++;
buf[1] = *cp++;
uuid.node[i] = strtoul(buf, NULL, 16);
}
uuid_pack(&uuid, uu);
return 0;
}
--- NEW FILE: pack.c ---
/*
* Internal routine for packing UUID's
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include <string.h>
#include "uuidP.h"
void uuid_pack(const struct uuid *uu, uuid_t ptr)
{
uint32_t tmp;
unsigned char *out = ptr;
tmp = uu->time_low;
out[3] = (unsigned char) tmp;
tmp >>= 8;
out[2] = (unsigned char) tmp;
tmp >>= 8;
out[1] = (unsigned char) tmp;
tmp >>= 8;
out[0] = (unsigned char) tmp;
tmp = uu->time_mid;
out[5] = (unsigned char) tmp;
tmp >>= 8;
out[4] = (unsigned char) tmp;
tmp = uu->time_hi_and_version;
out[7] = (unsigned char) tmp;
tmp >>= 8;
out[6] = (unsigned char) tmp;
tmp = uu->clock_seq;
out[9] = (unsigned char) tmp;
tmp >>= 8;
out[8] = (unsigned char) tmp;
memcpy(out+10, uu->node, 6);
}
--- NEW FILE: uuid_time.c ---
/*
* uuid_time.c --- Interpret the time field from a uuid. This program
* violates the UUID abstraction barrier by reaching into the guts
* of a UUID and interpreting it.
*
* Copyright (C) 1998, 1999 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include "uuidP.h"
time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
{
struct uuid uuid;
uint32_t high;
struct timeval tv;
unsigned long long clock_reg;
uuid_unpack(uu, &uuid);
high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
clock_reg = uuid.time_low | ((unsigned long long) high << 32);
clock_reg -= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
tv.tv_sec = clock_reg / 10000000;
tv.tv_usec = (clock_reg % 10000000) / 10;
if (ret_tv)
*ret_tv = tv;
return tv.tv_sec;
}
int uuid_type(const uuid_t uu)
{
struct uuid uuid;
uuid_unpack(uu, &uuid);
return ((uuid.time_hi_and_version >> 12) & 0xF);
}
int uuid_variant(const uuid_t uu)
{
struct uuid uuid;
int var;
uuid_unpack(uu, &uuid);
var = uuid.clock_seq;
if ((var & 0x8000) == 0)
return UUID_VARIANT_NCS;
if ((var & 0x4000) == 0)
return UUID_VARIANT_DCE;
if ((var & 0x2000) == 0)
return UUID_VARIANT_MICROSOFT;
return UUID_VARIANT_OTHER;
}
#ifdef DEBUG
static const char *variant_string(int variant)
{
switch (variant) {
case UUID_VARIANT_NCS:
return "NCS";
case UUID_VARIANT_DCE:
return "DCE";
case UUID_VARIANT_MICROSOFT:
return "Microsoft";
default:
return "Other";
}
}
int
main(int argc, char **argv)
{
uuid_t buf;
time_t time_reg;
struct timeval tv;
int type, variant;
if (argc != 2) {
fprintf(stderr, "Usage: %s uuid\n", argv[0]);
exit(1);
}
if (uuid_parse(argv[1], buf)) {
fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
exit(1);
}
variant = uuid_variant(buf);
type = uuid_type(buf);
time_reg = uuid_time(buf, &tv);
printf("UUID variant is %d (%s)\n", variant, variant_string(variant));
if (variant != UUID_VARIANT_DCE) {
printf("Warning: This program only knows how to interpret "
"DCE UUIDs.\n\tThe rest of the output is likely "
"to be incorrect!!\n");
}
printf("UUID type is %d", type);
switch (type) {
case 1:
printf(" (time based)\n");
break;
case 2:
printf(" (DCE)\n");
break;
case 3:
printf(" (name-based)\n");
break;
case 4:
printf(" (random)\n");
break;
default:
printf("\n");
}
if (type != 1) {
printf("Warning: not a time-based UUID, so UUID time "
"decoding will likely not work!\n");
}
printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
ctime(&time_reg));
return 0;
}
#endif
--- NEW FILE: copy.c ---
/*
* copy.c --- copy UUIDs
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include "uuidP.h"
void uuid_copy(uuid_t dst, const uuid_t src)
{
unsigned char *cp1;
const unsigned char *cp2;
int i;
for (i=0, cp1 = dst, cp2 = src; i < 16; i++)
*cp1++ = *cp2++;
}
--- NEW FILE: isnull.c ---
/*
* isnull.c --- Check whether or not the UUID is null
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, and the entire permission notice in its entirety,
* including the disclaimer of warranties.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
* %End-Header%
*/
#include "uuidP.h"
/* Returns 1 if the uuid is the NULL uuid */
int uuid_is_null(const uuid_t uu)
{
const unsigned char *cp;
int i;
for (i=0, cp = uu; i < 16; i++)
if (*cp++)
return 0;
return 1;
}
|