/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* The copyright in this file is taken from the original Leach & Salz
* UUID specification, from which this implementation is derived.
*/
/*
* Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
* Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
* Digital Equipment Corporation, Maynard, Mass. Copyright (c) 1998
* Microsoft. To anyone who acknowledges that this file is provided
* "AS IS" without any express or implied warranty: permission to use,
* copy, modify, and distribute this file for any purpose is hereby
* granted without fee, provided that the above copyright notices and
* this notice appears in all source code copies, and that none of the
* names of Open Software Foundation, Inc., Hewlett-Packard Company,
* or Digital Equipment Corporation be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Neither Open Software
* Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital
* Equipment Corporation makes any representations about the
* suitability of this software for any purpose.
*/
/*
* This module is the workhorse for generating abstract
* UUIDs. It delegates system-specific tasks (such
* as obtaining the node identifier or system time)
* to the sysdep module.
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <fcntl.h>
#include <unistd.h>
#include <synch.h>
#include "uuid_misc.h"
static int node_init;
static int buffer_init;
static int file_type;
static int fd;
/*
* misc routines
*/
uint16_t get_random(void);
void get_current_time(uuid_time_t *);
int get_ethernet_address(uuid_node_t *);
/*
* local functions
*/
static int map_state();
static void fill_random_bytes(uchar_t *, int);
static int uuid_create(struct uuid *);
static void gen_ethernet_address(uuid_node_t *);
static void revalidate_data(uuid_node_t *);
/*
* Generates a uuid based on version 1 format.
* Returns 0 on success and -1 on failure.
*/
static int
{
/*
*/
if (node_init) {
} else {
node_init = 1;
}
/*
* Access the state file, mmap it and initialize the shared lock.
* file_type tells us whether we had access to the state file or
* created a temporary one.
*/
buffer_init = map_state();
if (buffer_init == -1) {
return (buffer_init);
}
/*
* Acquire the lock
*/
for (;;) {
break;
else
switch (ret) {
case EOWNERDEAD:
break;
case ENOTRECOVERABLE:
return (ret);
/* NOTREACHED */
break;
}
}
/* State file is either new or is temporary, get a random clock seq */
non_unique++;
}
/*
* If timestamp is not set or is not in the past, bump
* data->state.clock
*/
}
if (non_unique)
/* Stuff fields into the UUID struct */
return (0);
}
/*
* Fills system_node with Ethernet address if available,
* else fills random numbers
*/
static void
{
if (get_ethernet_address(system_node) != 0) {
/*
* use 8:0:20 with the multicast bit set
* to avoid namespace collisions.
*/
}
}
/*
* Formats a UUID, given the clock_seq timestamp, and node address.
* Fills in passed-in pointer with the resulting uuid.
*/
static void
{
/*
* First set up the first 60 bits from the timestamp
*/
/*
* This is version 1, so say so in the UUID version field (4 bits)
*/
/*
* Now do the clock sequence
*/
/*
* We must save the most-significant 2 bits for the reserved field
*/
/*
* The variant for this format is the 2 high bits set to 10,
* so here it is
*/
/*
* write result to passed-in pointer
*/
}
/*
*/
static int
{
char *tmpname;
return (-1);
/* If file's mapped, return */
if (file_type != 0) {
return (1);
}
return (-1);
} else {
}
} else {
}
if (data == MAP_FAILED)
return (-1);
return (1);
}
static void
{
int i;
node_init = 1;
}
/*
* Prints a nicely-formatted uuid to stdout.
*/
void
{
int i;
u.clock_seq_low);
for (i = 0; i < 6; i++)
(void) printf("\n");
}
/*
* Fills buf with random numbers - nbytes is the number of bytes
* if that fails for some reason, it retries MAX_RETRY times. If
* it still fails then it uses srand48(3C)
*/
static void
{
if (fd >= 0) {
while (nbytes > 0) {
continue;
}
if (i <= 0) {
break;
continue;
}
nbytes -= i;
buf += i;
retries = 0;
}
if (nbytes == 0) {
return;
}
}
for (i = 0; i < nbytes; i++) {
}
if (fd >= 0) {
}
}
/*
* Unpacks the structure members in "struct uuid" to a char string "uuid_t".
*/
void
{
tmp >>= 8;
tmp >>= 8;
tmp >>= 8;
tmp >>= 8;
tmp >>= 8;
}
/*
* Packs the values in the "uuid_t" string into "struct uuid".
*/
void
{
}
/*
* Generates UUID based on DCE Version 4
*/
void
{
return;
/*
* This is version 4, so say so in the UUID version field (4 bits)
*/
/*
* we don't want the bit 1 to be set also which is for version 1
*/
/*
* The variant for this format is the 2 high bits set to 10,
* so here it is
*/
/*
* Set MSB of Ethernet address to 1 to indicate that it was generated
* randomly
*/
}
/*
* Generates UUID based on DCE Version 1.
*/
void
{
return;
if (uuid_create(&uuid) < 0) {
return;
}
}
/*
* Creates a new UUID. The uuid will be generated based on high-quality
* If it failed to generate UUID then uuid_generate will call
* uuid_generate_time.
*/
void
{
int fd;
return;
}
if (fd >= 0) {
} else {
(void) uuid_generate_time(uu);
}
}
/*
* Copies the UUID variable src to dst.
*/
void
{
}
/*
* Sets the value of the supplied uuid variable uu, to the NULL value.
*/
void
{
}
/*
* This function converts the supplied UUID uu from the internal
* binary format into a 36-byte string (plus trailing null char)
* and stores this value in the character string pointed to by out.
*/
void
{
int index = 0, i;
/* basic sanity checking */
return;
}
/* XXX user should have allocated enough memory */
/*
* if (strlen(out) < UUID_PRINTABLE_STRING_LENGTH) {
* return;
* }
*/
for (i = 0; i < 6; i++) {
index++;
}
}
/*
* The uuid_is_null function compares the value of the supplied
* UUID variable uu to the NULL value. If the value is equal
* to the NULL UUID, 1 is returned, otherwise 0 is returned.
*/
int
{
int i;
if (i == 0) {
/* uu is NULL uuid */
return (1);
} else {
return (0);
}
}
/*
* uuid_parse converts the UUID string given by 'in' into the
* internal uuid_t format. The input UUID is a string of the form
* cefa7a9c-1dd2-11b2-8350-880020adbeef in printf(3C) format.
* Upon successfully parsing the input string, UUID is stored
* in the location pointed to by uu
*/
int
{
int i;
/* do some sanity checking */
return (-1);
}
for (i = 0; i < 36; i++, ptr++) {
if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
if (*ptr != '-') {
return (-1);
}
} else {
return (-1);
}
}
}
for (i = 0; i < 6; i++) {
}
return (0);
}
/*
* uuid_time extracts the time at which the supplied UUID uu
* was created. This function can only extract the creation
* time for UUIDs created with the uuid_generate_time function.
* The time at which the UUID was created, in seconds and
* microseconds since the epoch is stored in the location
* pointed to by ret_tv.
*/
{
/* check if uu is NULL, Version = 1 of DCE and Variant = 0b10x */
return (-1);
}
if (ret_tv) {
}
}