]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/uuid.c
Added lutil_passwd_init, _destroy, _add for dynamically adding passwd
[openldap] / libraries / liblutil / uuid.c
index 0bb664a0dc01815032551defd2955ee137e402a4..a9640c13603197e4ef7dbf3b87a665a88b9ab97a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* Portions
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <sys/types.h>
 
+#include <ac/stdlib.h>
+#include <ac/string.h> /* get memcmp() */
 
-#ifdef HAVE_SYS_UUID_H
+#ifdef HAVE_UUID_TO_STR
 #  include <sys/uuid.h>
 #elif defined( _WIN32 )
 #  include <rpc.h>
@@ -42,7 +43,8 @@
 
 #include <lutil.h>
 
-#ifndef HAVE_SYS_UUID_H
+/* not needed for Windows */
+#if !defined(HAVE_UUID_TO_STR) && !defined(_WIN32)
 static unsigned char *
 lutil_eaddr( void )
 {
@@ -96,7 +98,7 @@ lutil_eaddr( void )
        free(buf);
        return NULL;
 
-#elif defined (SIOCGIFADDR)
+#elif defined( SIOCGIFADDR ) && defined( AFLINK )
        char buf[sizeof(struct ifreq) * 32];
        struct ifconf ifc;
        struct ifreq *ifr;
@@ -155,7 +157,7 @@ lutil_eaddr( void )
        if (memcmp(eaddr, zero, sizeof(eaddr)) == 0) {
                /* XXX - who knows? */
                lutil_entropy( eaddr, sizeof(eaddr) );
-               eaddr[0] |= 0x80; /* turn it into a mutlicast address */
+               eaddr[0] |= 0x80; /* turn it into a multicast address */
        }
 
        return eaddr;
@@ -181,7 +183,7 @@ lutil_eaddr( void )
 size_t
 lutil_uuidstr( char *buf, size_t len )
 {
-#ifdef HAVE_SYS_UUID_H
+#ifdef HAVE_UUID_TO_STR
        uuid_t uu = {0};
        unsigned rc;
        char *s;
@@ -227,7 +229,7 @@ lutil_uuidstr( char *buf, size_t len )
        }
 
        strncpy( buf, uuidstr, len );
-       free( uuidstr );
+       RpcStringFree( &uuidstr );
 
        return uuidlen;
  
@@ -235,7 +237,7 @@ lutil_uuidstr( char *buf, size_t len )
        struct timeval tv;
        unsigned long long tl;
        unsigned char *nl;
-       unsigned short t2, t3, s1, n1, n2, n3;
+       unsigned short t2, t3, s1;
        unsigned int t1;
 
        /*
@@ -272,7 +274,7 @@ lutil_uuidstr( char *buf, size_t len )
                (unsigned) nl[2], (unsigned) nl[3],
                (unsigned) nl[4], (unsigned) nl[5] );
 
-       return (t1 < len) ? t1 : 0;
+       return (0 < t1 && t1 < len) ? t1 : 0;
 #endif
 }
 
@@ -282,7 +284,7 @@ main(int argc, char **argv)
 {
        char buf1[8], buf2[64];
 
-#ifndef HAVE_SYS_UUID_H
+#ifndef HAVE_UUID_TO_STR
        unsigned char *p = lutil_eaddr();
 
        if( p ) {