diff --git a/configure.ac b/configure.ac index 6d3a563985..5639da83ec 100644 --- a/configure.ac +++ b/configure.ac @@ -94,49 +94,52 @@ AC_CHECK_LIB([dl], [dlopen], AC_MSG_ERROR("libdl is required on systems which do not otherwise provide dlopen()"), [#include ])]) -# -# libuuid -# - -have_libuuid=disabled -AC_ARG_WITH([libuuid], - [AS_HELP_STRING([--with-libuuid], - [use libuuid to generate unique identifiers @<:@default=check@:>@])], - [], - [with_libuuid=check]) - -if test "x$with_libuuid" != "xno" +if test "x$with_cygwin" = "xno" then - have_libuuid=yes - AC_CHECK_LIB([uuid], [uuid_generate], - [UUID_LIBS=-luuid] - [AC_DEFINE([HAVE_LIBUUID],, [Whether libuuid is available])], - [have_libuuid=no]) -fi + # + # libuuid + # + + have_libuuid=disabled + AC_ARG_WITH([libuuid], + [AS_HELP_STRING([--with-libuuid], + [use libuuid to generate unique identifiers @<:@default=check@:>@])], + [], + [with_libuuid=check]) -# OSSP UUID (if libuuid is unavilable) -if test "x${have_libuuid}" != "xyes" -then + if test "x$with_libuuid" != "xno" + then + have_libuuid=yes + AC_CHECK_LIB([uuid], [uuid_generate], + [UUID_LIBS=-luuid] + [AC_DEFINE([HAVE_LIBUUID],, [Whether libuuid is available])], + [have_libuuid=no]) + fi - AC_CHECK_LIB([ossp-uuid], [uuid_make], [UUID_LIBS=-lossp-uuid], - AC_CHECK_LIB([uuid], [uuid_make], [UUID_LIBS=-luuid], - AC_MSG_ERROR([ - -------------------------------------------- - Unable to find libuuid or the OSSP UUID library. - Either libuuid (from util-linux) or the OSSP UUID library is required for - guacamole-server to be built. - --------------------------------------------]))) - - # Check for and validate OSSP uuid.h header - AC_CHECK_HEADERS([ossp/uuid.h]) - AC_CHECK_DECL([uuid_make],, - AC_MSG_ERROR("No OSSP uuid.h found in include path"), - [#ifdef HAVE_OSSP_UUID_H - #include - #else - #include - #endif - ]) + # OSSP UUID (if libuuid is unavilable) + if test "x${have_libuuid}" != "xyes" + then + + AC_CHECK_LIB([ossp-uuid], [uuid_make], [UUID_LIBS=-lossp-uuid], + AC_CHECK_LIB([uuid], [uuid_make], [UUID_LIBS=-luuid], + AC_MSG_ERROR([ + -------------------------------------------- + Unable to find libuuid or the OSSP UUID library. + Either libuuid (from util-linux) or the OSSP UUID library is required for + guacamole-server to be built. + --------------------------------------------]))) + + # Check for and validate OSSP uuid.h header + AC_CHECK_HEADERS([ossp/uuid.h]) + AC_CHECK_DECL([uuid_make],, + AC_MSG_ERROR("No OSSP uuid.h found in include path"), + [#ifdef HAVE_OSSP_UUID_H + #include + #else + #include + #endif + ]) + fi fi # cunit diff --git a/src/libguac/id.c b/src/libguac/id.c index 610f836d55..c42bdff81e 100644 --- a/src/libguac/id.c +++ b/src/libguac/id.c @@ -22,7 +22,10 @@ #include "guacamole/error.h" #include -#if defined(HAVE_LIBUUID) + +#ifdef CYGWIN_BUILD +#include +#elif defined(HAVE_LIBUUID) #include #elif defined(HAVE_OSSP_UUID_H) #include @@ -37,6 +40,38 @@ char* guac_generate_id(char prefix) { char* buffer; char* identifier; + /* Allocate buffer for future formatted ID */ + buffer = malloc(GUAC_UUID_LEN + 1); + if (buffer == NULL) { + guac_error = GUAC_STATUS_NO_MEMORY; + guac_error_message = "Could not allocate memory for unique ID"; + return NULL; + } + + identifier = &(buffer[1]); + +#ifdef CYGWIN_BUILD + + /* Generate a UUID using a built in windows function */ + UUID uuid; + UuidCreate(&uuid); + + /* Convert the UUID to an all-caps, null-terminated tring */ + RPC_CSTR uuid_string; + if (UuidToString(uuid, &uuid_string) == RPC_S_OUT_OF_MEMORY) { + guac_error = GUAC_STATUS_NO_MEMORY; + guac_error_message = "Could not allocate memory for unique ID"; + return NULL; + } + + /* Copy over lowercase letters to the final target string */ + for (int i = 0; i < GUAC_UUID_LEN; i++) + identifier[i] = tolower(uuid_string[i]); + + RpcStringFree(uuid_string); + +#else + /* Prepare object to receive generated UUID */ #ifdef HAVE_LIBUUID uuid_t uuid; @@ -61,19 +96,6 @@ char* guac_generate_id(char prefix) { } #endif - /* Allocate buffer for future formatted ID */ - buffer = malloc(GUAC_UUID_LEN + 1); - if (buffer == NULL) { -#ifndef HAVE_LIBUUID - uuid_destroy(uuid); -#endif - guac_error = GUAC_STATUS_NO_MEMORY; - guac_error_message = "Could not allocate memory for unique ID"; - return NULL; - } - - identifier = &(buffer[1]); - /* Convert UUID to string to produce unique identifier */ #ifdef HAVE_LIBUUID uuid_unparse_lower(uuid, identifier); @@ -89,6 +111,7 @@ char* guac_generate_id(char prefix) { /* Clean up generated UUID */ uuid_destroy(uuid); +#endif #endif buffer[0] = prefix;