Whamcloud - gitweb
lib/uuid: remove conflicting Windows implementation of gettimeofday()
[tools/e2fsprogs.git] / lib / uuid / gen_uuid.c
1 /*
2  * gen_uuid.c --- generate a DCE-compatible uuid
3  *
4  * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
5  *
6  * %Begin-Header%
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, and the entire permission notice in its entirety,
12  *    including the disclaimer of warranties.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote
17  *    products derived from this software without specific prior
18  *    written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23  * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30  * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  * %End-Header%
33  */
34
35 /*
36  * Force inclusion of SVID stuff since we need it if we're compiling in
37  * gcc-wall wall mode
38  */
39 #define _SVID_SOURCE
40 #define _DEFAULT_SOURCE   /* since glibc 2.20 _SVID_SOURCE is deprecated */
41
42 #include "config.h"
43
44 #ifdef _WIN32
45 #define _WIN32_WINNT 0x0500
46 #include <windows.h>
47 #define UUID MYUUID
48 #endif
49 #include <stdio.h>
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
53 #ifdef HAVE_STDLIB_H
54 #include <stdlib.h>
55 #endif
56 #include <string.h>
57 #include <fcntl.h>
58 #include <errno.h>
59 #include <sys/types.h>
60 #ifdef HAVE_SYS_TIME_H
61 #include <sys/time.h>
62 #endif
63 #ifdef HAVE_SYS_WAIT_H
64 #include <sys/wait.h>
65 #endif
66 #include <sys/stat.h>
67 #ifdef HAVE_SYS_FILE_H
68 #include <sys/file.h>
69 #endif
70 #ifdef HAVE_SYS_IOCTL_H
71 #include <sys/ioctl.h>
72 #endif
73 #ifdef HAVE_SYS_RANDOM_H
74 #include <sys/random.h>
75 #endif
76 #ifdef HAVE_SYS_SOCKET_H
77 #include <sys/socket.h>
78 #endif
79 #ifdef HAVE_SYS_UN_H
80 #include <sys/un.h>
81 #endif
82 #ifdef HAVE_SYS_SOCKIO_H
83 #include <sys/sockio.h>
84 #endif
85 #ifdef HAVE_NET_IF_H
86 #include <net/if.h>
87 #endif
88 #ifdef HAVE_NETINET_IN_H
89 #include <netinet/in.h>
90 #endif
91 #ifdef HAVE_NET_IF_DL_H
92 #include <net/if_dl.h>
93 #endif
94 #if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
95 #include <sys/syscall.h>
96 #endif
97 #ifdef HAVE_SYS_RESOURCE_H
98 #include <sys/resource.h>
99 #endif
100
101 #include "uuidP.h"
102 #include "uuidd.h"
103
104 #ifdef HAVE_SRANDOM
105 #define srand(x)        srandom(x)
106 #define rand()          random()
107 #endif
108
109 #ifdef TLS
110 #define THREAD_LOCAL static TLS
111 #else
112 #define THREAD_LOCAL static
113 #endif
114
115 #if defined(__linux__) && defined(__NR_gettid) && defined(HAVE_JRAND48)
116 #define DO_JRAND_MIX
117 THREAD_LOCAL unsigned short jrand_seed[3];
118 #endif
119
120 static int get_random_fd(void)
121 {
122         struct timeval  tv;
123         static int      fd = -2;
124         int             i;
125
126         if (fd == -2) {
127                 gettimeofday(&tv, 0);
128 #ifndef _WIN32
129                 fd = open("/dev/urandom", O_RDONLY);
130                 if (fd == -1)
131                         fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
132                 if (fd >= 0) {
133                         i = fcntl(fd, F_GETFD);
134                         if (i >= 0)
135                                 fcntl(fd, F_SETFD, i | FD_CLOEXEC);
136                 }
137 #endif
138                 srand(((unsigned)getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
139 #ifdef DO_JRAND_MIX
140                 jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);
141                 jrand_seed[1] = getppid() ^ (tv.tv_usec & 0xFFFF);
142                 jrand_seed[2] = (tv.tv_sec ^ tv.tv_usec) >> 16;
143 #endif
144         }
145         /* Crank the random number generator a few times */
146         gettimeofday(&tv, 0);
147         for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
148                 rand();
149         return fd;
150 }
151
152
153 /*
154  * Generate a series of random bytes.  Use /dev/urandom if possible,
155  * and if not, use srandom/random.
156  */
157 static void get_random_bytes(void *buf, int nbytes)
158 {
159         int i, n = nbytes, fd;
160         int lose_counter = 0;
161         unsigned char *cp = buf;
162
163 #ifdef HAVE_GETRANDOM
164         i = getrandom(buf, nbytes, 0);
165         if (i == nbytes)
166                 return;
167 #endif
168 #ifdef HAVE_GETENTROPY
169         if (getentropy(buf, nbytes) == 0)
170                 return;
171 #endif
172
173         fd = get_random_fd();
174         if (fd >= 0) {
175                 while (n > 0) {
176                         i = read(fd, cp, n);
177                         if (i <= 0) {
178                                 if (lose_counter++ > 16)
179                                         break;
180                                 continue;
181                         }
182                         n -= i;
183                         cp += i;
184                         lose_counter = 0;
185                 }
186         }
187
188         /*
189          * We do this all the time, but this is the only source of
190          * randomness if /dev/random/urandom is out to lunch.
191          */
192         for (cp = buf, i = 0; i < nbytes; i++)
193                 *cp++ ^= (rand() >> 7) & 0xFF;
194 #ifdef DO_JRAND_MIX
195         {
196                 unsigned short tmp_seed[3];
197
198                 memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed));
199                 jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid);
200                 for (cp = buf, i = 0; i < nbytes; i++)
201                         *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
202                 memcpy(jrand_seed, tmp_seed,
203                        sizeof(jrand_seed) - sizeof(unsigned short));
204         }
205 #endif
206
207         return;
208 }
209
210 /*
211  * Get the ethernet hardware address, if we can find it...
212  *
213  * XXX for a windows version, probably should use GetAdaptersInfo:
214  * http://www.codeguru.com/cpp/i-n/network/networkinformation/article.php/c5451
215  * commenting out get_node_id just to get gen_uuid to compile under windows
216  * is not the right way to go!
217  */
218 static int get_node_id(unsigned char *node_id)
219 {
220 #ifdef HAVE_NET_IF_H
221         int             sd;
222         struct ifreq    ifr, *ifrp;
223         struct ifconf   ifc;
224         char buf[1024];
225         int             n, i;
226         unsigned char   *a;
227 #ifdef HAVE_NET_IF_DL_H
228         struct sockaddr_dl *sdlp;
229 #endif
230
231 /*
232  * BSD 4.4 defines the size of an ifreq to be
233  * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
234  * However, under earlier systems, sa_len isn't present, so the size is
235  * just sizeof(struct ifreq)
236  */
237 #ifdef HAVE_SA_LEN
238 #ifndef max
239 #define max(a,b) ((a) > (b) ? (a) : (b))
240 #endif
241 #define ifreq_size(i) max(sizeof(struct ifreq),\
242      sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
243 #else
244 #define ifreq_size(i) sizeof(struct ifreq)
245 #endif /* HAVE_SA_LEN*/
246
247         sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
248         if (sd < 0) {
249                 return -1;
250         }
251         memset(buf, 0, sizeof(buf));
252         ifc.ifc_len = sizeof(buf);
253         ifc.ifc_buf = buf;
254         if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
255                 close(sd);
256                 return -1;
257         }
258         n = ifc.ifc_len;
259         for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
260                 ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
261                 strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
262 #ifdef SIOCGIFHWADDR
263                 if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
264                         continue;
265                 a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
266 #else
267 #ifdef SIOCGENADDR
268                 if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
269                         continue;
270                 a = (unsigned char *) ifr.ifr_enaddr;
271 #else
272 #ifdef HAVE_NET_IF_DL_H
273                 sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
274                 if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
275                         continue;
276                 a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
277 #else
278                 /*
279                  * XXX we don't have a way of getting the hardware
280                  * address
281                  */
282                 close(sd);
283                 return 0;
284 #endif /* HAVE_NET_IF_DL_H */
285 #endif /* SIOCGENADDR */
286 #endif /* SIOCGIFHWADDR */
287                 if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
288                         continue;
289                 if (node_id) {
290                         memcpy(node_id, a, 6);
291                         close(sd);
292                         return 1;
293                 }
294         }
295         close(sd);
296 #endif
297         return 0;
298 }
299
300 /* Assume that the gettimeofday() has microsecond granularity */
301 #define MAX_ADJUSTMENT 10
302
303 static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
304                      uint16_t *ret_clock_seq, int *num)
305 {
306         THREAD_LOCAL int                adjustment = 0;
307         THREAD_LOCAL struct timeval     last = {0, 0};
308         THREAD_LOCAL int                state_fd = -2;
309         THREAD_LOCAL FILE               *state_f;
310         THREAD_LOCAL uint16_t           clock_seq;
311         struct timeval                  tv;
312 #ifndef _WIN32
313         struct flock                    fl;
314 #endif
315         uint64_t                        clock_reg;
316         mode_t                          save_umask;
317         int                             len;
318
319         if (state_fd == -2) {
320                 save_umask = umask(0);
321                 state_fd = open("/var/lib/libuuid/clock.txt",
322                                 O_RDWR|O_CREAT, 0660);
323                 (void) umask(save_umask);
324                 if (state_fd >= 0) {
325                         state_f = fdopen(state_fd, "r+");
326                         if (!state_f) {
327                                 close(state_fd);
328                                 state_fd = -1;
329                         }
330                 }
331         }
332 #ifndef _WIN32
333         fl.l_type = F_WRLCK;
334         fl.l_whence = SEEK_SET;
335         fl.l_start = 0;
336         fl.l_len = 0;
337         fl.l_pid = 0;
338         if (state_fd >= 0) {
339                 rewind(state_f);
340                 while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
341                         if ((errno == EAGAIN) || (errno == EINTR))
342                                 continue;
343                         fclose(state_f);
344                         state_fd = -1;
345                         break;
346                 }
347         }
348 #endif
349         if (state_fd >= 0) {
350                 unsigned int cl;
351                 unsigned long tv1, tv2;
352                 int a;
353
354                 if (fscanf(state_f, "clock: %04x tv: %lu %lu adj: %d\n",
355                            &cl, &tv1, &tv2, &a) == 4) {
356                         clock_seq = cl & 0x3FFF;
357                         last.tv_sec = tv1;
358                         last.tv_usec = tv2;
359                         adjustment = a;
360                 }
361         }
362
363         if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
364                 get_random_bytes(&clock_seq, sizeof(clock_seq));
365                 clock_seq &= 0x3FFF;
366                 gettimeofday(&last, 0);
367                 last.tv_sec--;
368         }
369
370 try_again:
371         gettimeofday(&tv, 0);
372         if ((tv.tv_sec < last.tv_sec) ||
373             ((tv.tv_sec == last.tv_sec) &&
374              (tv.tv_usec < last.tv_usec))) {
375                 clock_seq = (clock_seq+1) & 0x3FFF;
376                 adjustment = 0;
377                 last = tv;
378         } else if ((tv.tv_sec == last.tv_sec) &&
379             (tv.tv_usec == last.tv_usec)) {
380                 if (adjustment >= MAX_ADJUSTMENT)
381                         goto try_again;
382                 adjustment++;
383         } else {
384                 adjustment = 0;
385                 last = tv;
386         }
387
388         clock_reg = tv.tv_usec*10 + adjustment;
389         clock_reg += ((uint64_t) tv.tv_sec)*10000000;
390         clock_reg += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
391
392         if (num && (*num > 1)) {
393                 adjustment += *num - 1;
394                 last.tv_usec += adjustment / 10;
395                 adjustment = adjustment % 10;
396                 last.tv_sec += last.tv_usec / 1000000;
397                 last.tv_usec = last.tv_usec % 1000000;
398         }
399
400         if (state_fd > 0) {
401                 rewind(state_f);
402                 len = fprintf(state_f,
403                               "clock: %04x tv: %016lu %08lu adj: %08d\n",
404                               clock_seq, (unsigned long)last.tv_sec,
405                               (unsigned long)last.tv_usec, adjustment);
406                 fflush(state_f);
407                 if (ftruncate(state_fd, len) < 0) {
408                         fprintf(state_f, "                   \n");
409                         fflush(state_f);
410                 }
411                 rewind(state_f);
412 #ifndef _WIN32
413                 fl.l_type = F_UNLCK;
414                 if (fcntl(state_fd, F_SETLK, &fl) < 0) {
415                         fclose(state_f);
416                         state_fd = -1;
417                 }
418 #endif
419         }
420
421         *clock_high = clock_reg >> 32;
422         *clock_low = clock_reg;
423         *ret_clock_seq = clock_seq;
424         return 0;
425 }
426
427 #if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
428 static ssize_t read_all(int fd, char *buf, size_t count)
429 {
430         ssize_t ret;
431         ssize_t c = 0;
432         int tries = 0;
433
434         memset(buf, 0, count);
435         while (count > 0) {
436                 ret = read(fd, buf, count);
437                 if (ret <= 0) {
438                         if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
439                             (tries++ < 5))
440                                 continue;
441                         return c ? c : -1;
442                 }
443                 if (ret > 0)
444                         tries = 0;
445                 count -= ret;
446                 buf += ret;
447                 c += ret;
448         }
449         return c;
450 }
451
452 /*
453  * Close all file descriptors
454  */
455 static void close_all_fds(void)
456 {
457         int i, max;
458
459 #if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
460         max = sysconf(_SC_OPEN_MAX);
461 #elif defined(HAVE_GETDTABLESIZE)
462         max = getdtablesize();
463 #elif defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
464         struct rlimit rl;
465
466         getrlimit(RLIMIT_NOFILE, &rl);
467         max = rl.rlim_cur;
468 #else
469         max = OPEN_MAX;
470 #endif
471
472         for (i=0; i < max; i++) {
473                 close(i);
474                 if (i <= 2)
475                         open("/dev/null", O_RDWR);
476         }
477 }
478 #endif /* defined(USE_UUIDD) && defined(HAVE_SYS_UN_H) */
479
480 #if __GNUC_PREREQ (4, 6)
481 #pragma GCC diagnostic push
482 #if !defined(USE_UUIDD) || !defined(HAVE_SYS_UN_H)
483 #pragma GCC diagnostic ignored "-Wunused-parameter"
484 #endif
485 #endif
486 /*
487  * Try using the uuidd daemon to generate the UUID
488  *
489  * Returns 0 on success, non-zero on failure.
490  */
491 static int get_uuid_via_daemon(int op, uuid_t out, int *num)
492 {
493 #if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
494         char op_buf[64];
495         int op_len;
496         int s;
497         ssize_t ret;
498         int32_t reply_len = 0, expected = 16;
499         struct sockaddr_un srv_addr;
500         struct stat st;
501         pid_t pid;
502         static const char *uuidd_path = UUIDD_PATH;
503         static int access_ret = -2;
504         static int start_attempts = 0;
505
506         if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
507                 return -1;
508
509         srv_addr.sun_family = AF_UNIX;
510         strcpy(srv_addr.sun_path, UUIDD_SOCKET_PATH);
511
512         if (connect(s, (const struct sockaddr *) &srv_addr,
513                     sizeof(struct sockaddr_un)) < 0) {
514                 if (access_ret == -2)
515                         access_ret = access(uuidd_path, X_OK);
516                 if (access_ret == 0)
517                         access_ret = stat(uuidd_path, &st);
518                 if (access_ret == 0 && (st.st_mode & (S_ISUID | S_ISGID)) == 0)
519                         access_ret = access(UUIDD_DIR, W_OK);
520                 if (access_ret == 0 && start_attempts++ < 5) {
521                         if ((pid = fork()) == 0) {
522                                 close_all_fds();
523                                 execl(uuidd_path, "uuidd", "-qT", "300",
524                                       (char *) NULL);
525                                 exit(1);
526                         }
527                         (void) waitpid(pid, 0, 0);
528                         if (connect(s, (const struct sockaddr *) &srv_addr,
529                                     sizeof(struct sockaddr_un)) < 0)
530                                 goto fail;
531                 } else
532                         goto fail;
533         }
534         op_buf[0] = op;
535         op_len = 1;
536         if (op == UUIDD_OP_BULK_TIME_UUID) {
537                 memcpy(op_buf+1, num, sizeof(*num));
538                 op_len += sizeof(*num);
539                 expected += sizeof(*num);
540         }
541
542         ret = write(s, op_buf, op_len);
543         if (ret < 1)
544                 goto fail;
545
546         ret = read_all(s, (char *) &reply_len, sizeof(reply_len));
547         if (ret < 0)
548                 goto fail;
549
550         if (reply_len != expected)
551                 goto fail;
552
553         ret = read_all(s, op_buf, reply_len);
554
555         if (op == UUIDD_OP_BULK_TIME_UUID)
556                 memcpy(op_buf+16, num, sizeof(int));
557
558         memcpy(out, op_buf, 16);
559
560         close(s);
561         return ((ret == expected) ? 0 : -1);
562
563 fail:
564         close(s);
565 #endif
566         return -1;
567 }
568 #if __GNUC_PREREQ (4, 6)
569 #pragma GCC diagnostic pop
570 #endif
571
572 void uuid__generate_time(uuid_t out, int *num)
573 {
574         static unsigned char node_id[6];
575         static int has_init = 0;
576         struct uuid uu;
577         uint32_t        clock_mid;
578
579         if (!has_init) {
580                 if (get_node_id(node_id) <= 0) {
581                         get_random_bytes(node_id, 6);
582                         /*
583                          * Set multicast bit, to prevent conflicts
584                          * with IEEE 802 addresses obtained from
585                          * network cards
586                          */
587                         node_id[0] |= 0x01;
588                 }
589                 has_init = 1;
590         }
591         get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num);
592         uu.clock_seq |= 0x8000;
593         uu.time_mid = (uint16_t) clock_mid;
594         uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
595         memcpy(uu.node, node_id, 6);
596         uuid_pack(&uu, out);
597 }
598
599 void uuid_generate_time(uuid_t out)
600 {
601 #ifdef TLS
602         THREAD_LOCAL int                num = 0;
603         THREAD_LOCAL struct uuid        uu;
604         THREAD_LOCAL time_t             last_time = 0;
605         time_t                          now;
606
607         if (num > 0) {
608                 now = time(0);
609                 if (now > last_time+1)
610                         num = 0;
611         }
612         if (num <= 0) {
613                 num = 1000;
614                 if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
615                                         out, &num) == 0) {
616                         last_time = time(0);
617                         uuid_unpack(out, &uu);
618                         num--;
619                         return;
620                 }
621                 num = 0;
622         }
623         if (num > 0) {
624                 uu.time_low++;
625                 if (uu.time_low == 0) {
626                         uu.time_mid++;
627                         if (uu.time_mid == 0)
628                                 uu.time_hi_and_version++;
629                 }
630                 num--;
631                 uuid_pack(&uu, out);
632                 return;
633         }
634 #else
635         if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, 0) == 0)
636                 return;
637 #endif
638
639         uuid__generate_time(out, 0);
640 }
641
642
643 void uuid__generate_random(uuid_t out, int *num)
644 {
645         uuid_t  buf;
646         struct uuid uu;
647         int i, n;
648
649         if (!num || !*num)
650                 n = 1;
651         else
652                 n = *num;
653
654         for (i = 0; i < n; i++) {
655                 get_random_bytes(buf, sizeof(buf));
656                 uuid_unpack(buf, &uu);
657
658                 uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
659                 uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF)
660                         | 0x4000;
661                 uuid_pack(&uu, out);
662                 out += sizeof(uuid_t);
663         }
664 }
665
666 void uuid_generate_random(uuid_t out)
667 {
668         int     num = 1;
669         /* No real reason to use the daemon for random uuid's -- yet */
670
671         uuid__generate_random(out, &num);
672 }
673
674
675 /*
676  * This is the generic front-end to uuid_generate_random and
677  * uuid_generate_time.  It uses uuid_generate_random only if
678  * /dev/urandom is available, since otherwise we won't have
679  * high-quality randomness.
680  */
681 void uuid_generate(uuid_t out)
682 {
683         if (get_random_fd() >= 0)
684                 uuid_generate_random(out);
685         else
686                 uuid_generate_time(out);
687 }