Skip to content

Commit

Permalink
Change the way agent deviceid is computed
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bougard committed Jan 11, 2019
1 parent 46dd198 commit f544344
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
52 changes: 39 additions & 13 deletions src/agent.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GLPI Windows CE Agent
*
* Copyright (C) 2016 - Teclib SAS
* Copyright (C) 2019 - Teclib SAS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -357,31 +357,57 @@ void Quit(void)
bInitialized = FALSE;
}

#define MAX_DEVICEID_LENGTH 32
static LPSTR computeDeviceID(void)
{
int buflen = 21 ;
LPSTR hostname = NULL;
LPSYSTEMTIME lpSystemTime = NULL;

hostname = getHostname();
buflen += strlen(hostname);

DeviceID = allocate( buflen, "DeviceID");
DeviceID = allocate( MAX_DEVICEID_LENGTH, "DeviceID");

lpSystemTime = getLocalTime();

if (sprintf( DeviceID, "%s-%02d-%02d-%02d-%02d-%02d-%02d", hostname,
// Use date base DeviceID only if date time has been updated as older
// devices often starts with a default date time
if ( lpSystemTime->wYear >= 2019 )
{
_snprintf(DeviceID, MAX_DEVICEID_LENGTH-1,
"WindowsCE-%02d-%02d-%02d-%02d-%02d-%02d",
lpSystemTime->wYear,
lpSystemTime->wMonth,
lpSystemTime->wDay,
lpSystemTime->wHour,
lpSystemTime->wMinute,
lpSystemTime->wSecond) > buflen)
lpSystemTime->wSecond);
}
else
{
Error("Bad computed DeviceID");
#ifndef GWA
Abort();
ULONG tag = 0;
#ifdef GWA
LPSTR uuid = NULL;
// As hostname on WinCE devices are not nice enough and localtime is
// often also not the real current localtime, we prefer to compute a
// simpler deviceid including a tag based on UUID XOR result as UUID
// checksum or even a random value.
uuid = getUUID(TRUE);
if (uuid != NULL)
{
ULONG l1 = 0, l2 = 0, l3 = 0, l4 = 0;
if (sscanf(uuid, "%08lx%08lx%08lx%08lx%08lx", &tag, &l1, &l2, &l3, &l4)>0)
{
tag ^= l1 ; tag ^= l2 ; tag ^= l3 ; tag ^= l4 ;
Debug2("MachineID ? UUID XOR checksum: %08x", tag);
}
}
else
#endif
{
Debug2("No uuid to checksum on");
srand( GetTickCount() );
if (sscanf(vsPrintf("%04x%04x", rand(), rand()), "%08lx", &tag))
{
Debug2("MachineID ? Random tag: %08x", tag);
}
}
_snprintf(DeviceID, MAX_DEVICEID_LENGTH-1, "WindowsCE-%08x", tag);
}

Debug2("Computed DeviceID=%s", DeviceID);
Expand Down
1 change: 1 addition & 0 deletions src/glpi-wince-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ typedef struct _MANUFACTURER {
LPCSTR name;
} MANUFACTURER, *LPMANUFACTURER;

LPSTR getUUID(BOOL tryDeprecated);
void getBios(void);
void getHardware(void);
void CheckDeviceId(LPMANUFACTURER manufacturer, LIST *list);
Expand Down
12 changes: 6 additions & 6 deletions src/inventory/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ LPSTR getUUID(BOOL tryDeprecated)

if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
{
Error("getUUID: Can't get Platform UUID via SystemParametersInfo");
DebugError("getUUID: Can't get Platform UUID via SystemParametersInfo (err=%d)", GetLastError());
}
else
{
Error("getUUID: Insufficient buffer size for SystemParametersInfo");
DebugError("getUUID: Insufficient buffer size for SystemParametersInfo");
}

hCoreDll = LoadLibrary(L"coredll.dll");
Expand Down Expand Up @@ -350,15 +350,15 @@ LPSTR getUUID(BOOL tryDeprecated)
}

// Eventually try deprecated method
if (tryDeprecated && !uuidlen)
if (!uuidlen)
{
if (KernelIoControl(IOCTL_HAL_GET_UUID, NULL, 0, &uuid, 0, NULL))
if (KernelIoControl(IOCTL_HAL_GET_UUID, NULL, 0, &uuid, sizeof(UUID), NULL))
{
uuidlen = 16;
uuidlen = sizeof(UUID);
}
else
{
DebugError("Deprecated UUID IOCL call failed");
DebugError("Deprecated UUID IOCL call failed (%d)", GetLastError());
}
}
}
Expand Down

0 comments on commit f544344

Please sign in to comment.