* Fixed all tests, now can be run with -DWITH_ADDRESS_SANITIZER=ON compiled.
* Enabled address sanitizer for nightly builds.
message("PRELOADING android cache")
set(CMAKE_TOOLCHAIN_FILE "cmake/AndroidToolchain.cmake" CACHE PATH "ToolChain file")
+set(WITH_SANITIZE_ADDRESS ON)
set(FREERDP_EXTERNAL_SSL_PATH $ENV{ANDROID_SSL_PATH} CACHE PATH "android ssl")
# ANDROID_NDK and ANDROID_SDK must be set as environment variable
#set(ANDROID_NDK $ENV{ANDROID_SDK} CACHE PATH "Android NDK")
set (WITH_XV OFF CACHE BOOL "xvideo support")
set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
+set (WITH_SANITIZE_ADDRESS ON)
message("PRELOADING android cache")
-set(CMAKE_TOOLCHAIN_FILE "cmake/iOSToolchain.cmake" CACHE PATH "ToolChain file")
-set(FREERDP_IOS_EXTERNAL_SSL_PATH $ENV{FREERDP_IOS_EXTERNAL_SSL_PATH} CACHE PATH "android ssl")
+set (CMAKE_TOOLCHAIN_FILE "cmake/iOSToolchain.cmake" CACHE PATH "ToolChain file")
+set (FREERDP_IOS_EXTERNAL_SSL_PATH $ENV{FREERDP_IOS_EXTERNAL_SSL_PATH} CACHE PATH "android ssl")
set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
-set(IOS_PLATFORM "SIMULATOR" CACHE STRING "iso platfrorm to build")
+set (IOS_PLATFORM "SIMULATOR" CACHE STRING "iso platfrorm to build")
+set (WITH_SANITIZE_ADDRESS ON)
set (WITH_DEBUG_XV OFF CACHE BOOL "enable debug")
set (WITH_SAMPLE ON CACHE BOOL "samples")
set (WITH_NO_UNDEFINED ON CACHE BOOL "don't link with undefined symbols")
+set (WITH_SANITIZE_ADDRESS ON)
set (WITH_CUPS ON CACHE BOOL "CUPS printing")
set (WITH_X11 ON CACHE BOOL "Enable X11")
set (BUILD_TESTING ON CACHE BOOL "build testing")
+set (WITH_SANITIZE_ADDRESS ON)
set (WITH_XV OFF CACHE BOOL "xvideo support")
set (BUILD_TESTING ON CACHE BOOL "build testing")
set (WITH_XSHM OFF CACHE BOOL "build with xshm support")
+set (WITH_SANITIZE_ADDRESS ON)
message("PRELOADING windows cache")
set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type")
-set(WITH_SERVER "ON" CACHE BOOL "Build server binaries")
+set (WITH_SERVER "ON" CACHE BOOL "Build server binaries")
set (BUILD_TESTING ON CACHE BOOL "build testing")
+set (WITH_SANITIZE_ADDRESS ON)
int rc = -1;
int status;
UINT32 Flags;
- BYTE* pSrcData;
+ BYTE* pSrcData = NULL;
UINT32 SrcSize;
UINT32 DstSize;
- BYTE* pDstData;
+ BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx;
UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE);
rc = 0;
fail:
+ free(pDstData);
zgfx_context_free(zgfx);
return rc;
}
BYTE* pSrcData;
UINT32 SrcSize;
UINT32 DstSize;
- BYTE* pDstData;
+ BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx;
UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE);
rc = 0;
fail:
+ free(pDstData);
zgfx_context_free(zgfx);
return rc;
}
BYTE* pSrcData;
UINT32 SrcSize;
UINT32 DstSize;
- BYTE* pDstData;
+ BYTE* pDstData = NULL;
ZGFX_CONTEXT* zgfx;
UINT32 expectedSize;
zgfx = zgfx_context_new(TRUE);
rc = 0;
fail:
+ free(pDstData);
zgfx_context_free(zgfx);
return rc;
}
BYTE* pSrcData;
UINT32 SrcSize;
UINT32 DstSize;
- BYTE* pDstData;
+ BYTE* pDstData = NULL;
UINT32 DstSize2;
- BYTE* pDstData2;
+ BYTE* pDstData2 = NULL;
ZGFX_CONTEXT* zgfx;
UINT32 expectedSize;
BYTE BigBuffer[65536];
rc = 0;
fail:
+ free(pDstData);
+ free(pDstData2);
zgfx_context_free(zgfx);
return rc;
}
retCode = 0;
out:
region16_uninit(®ion);
+ region16_uninit(&intersection);
return retCode;
}
EventArgsInit(&e, "freerdp");
e.result = status ? 0 : -1;
PubSub_OnConnectionResult(instance->context->pubSub, instance->context, &e);
+
+ if (!status)
+ freerdp_disconnect(instance);
+
return status;
}
struct sockaddr* addr,
socklen_t addrlen, int timeout)
{
+ BOOL rc = FALSE;
HANDLE handles[2];
int status = 0;
int count = 0;
if (status < 0)
{
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
- return FALSE;
+ goto fail;
}
handles[count++] = context->abortEvent;
break;
default:
- return FALSE;
+ goto fail;
}
}
if (status == WAIT_OBJECT_0 + 1)
freerdp_set_last_error(context, FREERDP_ERROR_CONNECT_CANCELLED);
- return FALSE;
+ goto fail;
}
status = recv(sockfd, NULL, 0, 0);
if (status == SOCKET_ERROR)
{
if (WSAGetLastError() == WSAECONNRESET)
- return FALSE;
+ goto fail;
}
status = WSAEventSelect(sockfd, handles[0], 0);
- CloseHandle(handles[0]);
if (status < 0)
{
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
- return FALSE;
+ goto fail;
}
if (_ioctlsocket(sockfd, FIONBIO, &arg) != 0)
- return FALSE;
+ goto fail;
- return TRUE;
+ rc = TRUE;
+fail:
+ CloseHandle(handles[0]);
+ return rc;
}
static int freerdp_tcp_connect_multi(rdpContext* context, char** hostnames,
static int prepare(const char* currentFileV2, const char* legacyFileV2, const char* legacyFile)
{
char* legacy[] = {
- "someurl ff:11:22:dd\r\n",
- "otherurl aa:bb:cc:dd\r",
- "legacyurl aa:bb:cc:dd\n"
+ "someurl ff:11:22:dd\r\n",
+ "otherurl aa:bb:cc:dd\r",
+ "legacyurl aa:bb:cc:dd\n"
};
char* hosts[] = {
- "someurl 3389 ff:11:22:dd subject issuer\r\n",
- "otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r",
+ "someurl 3389 ff:11:22:dd subject issuer\r\n",
+ "otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r",
};
FILE* fl = NULL;
FILE* fc = NULL;
for (i=0; i<sizeof(hosts)/sizeof(hosts[0]); i++)
{
if (fwrite(hosts[i], strlen(hosts[i]), 1, fl) != 1 ||
- fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
+ fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
goto finish;
}
goto finish;
}
- store = certificate_store_new(¤t);
+ store = certificate_store_new(¤t);
if (!store)
{
fprintf(stderr, "Could not create certificate store!\n");
rc = 0;
finish:
+ free(current.ConfigPath);
+ free(legacy.ConfigPath);
if (store)
certificate_store_free(store);
if (data)
goto fail;
hBmpDstOriginal = test_convert_to_bitmap(bmp_DST, RawFormat, 0, 0, 0,
- DstFormat, 0, 0, 0, 16, 16, hPalette);
+ SrcFormat, 0, 0, 0, 16, 16, hPalette);
if (!hBmpDstOriginal)
goto fail;
static int test_gdi_ClipCoords(void)
{
+ int rc = -1;
BOOL draw;
HGDI_DC hdc;
- HGDI_RGN rgn1;
- HGDI_RGN rgn2;
- HGDI_BITMAP bmp;
+ HGDI_RGN rgn1 = NULL;
+ HGDI_RGN rgn2 = NULL;
+ HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_ARGB32;
if (!(hdc = gdi_GetDC()))
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* region all inside clipping region */
gdi_SetClipRgn(hdc, 0, 0, 1024, 768);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* region all outside clipping region, on the left */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
NULL);
if (draw)
- return -1;
+ goto fail;
/* region all outside clipping region, on the right */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
NULL);
if (draw)
- return -1;
+ goto fail;
/* region all outside clipping region, on top */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
NULL);
if (draw)
- return -1;
+ goto fail;
/* region all outside clipping region, at the bottom */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
NULL);
if (draw)
- return -1;
+ goto fail;
/* left outside, right = clip, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* left outside, right inside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* left = clip, right outside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* left inside, right outside, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* top outside, bottom = clip, left = clip, right = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* top = clip, bottom outside, left = clip, right = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
/* top = clip, bottom = clip, top = clip, bottom = clip */
gdi_SetClipRgn(hdc, 300, 300, 100, 100);
gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL);
if (!gdi_EqualRgn(rgn1, rgn2))
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+
+ if (rgn1)
+ gdi_DeleteObject((HGDIOBJECT)rgn1);
+
+ if (rgn2)
+ gdi_DeleteObject((HGDIOBJECT)rgn2);
+
+ if (bmp)
+ gdi_DeleteObject((HGDIOBJECT)bmp);
+
+ gdi_DeleteDC(hdc);
+ return rc;
}
static int test_gdi_InvalidateRegion(void)
{
+ int rc = -1;
HGDI_DC hdc;
- HGDI_RGN rgn1;
- HGDI_RGN rgn2;
- HGDI_RGN invalid;
- HGDI_BITMAP bmp;
+ HGDI_RGN rgn1 = NULL;
+ HGDI_RGN rgn2 = NULL;
+ HGDI_RGN invalid = NULL;
+ HGDI_BITMAP bmp = NULL;
const UINT32 format = PIXEL_FORMAT_XRGB32;
if (!(hdc = gdi_GetDC()))
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* region same as invalid region */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* left outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* top outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* left outside, right outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* top outside, bottom outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* all outside, left */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* all outside, right */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* all outside, top */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* all outside, bottom */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* all outside */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
/* everything */
gdi_SetRgn(invalid, 300, 300, 100, 100);
gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h);
if (!gdi_EqualRgn(invalid, rgn2))
- return -1;
+ goto fail;
+
+ rc = 0;
+fail:
+
+ if (rgn1)
+ gdi_DeleteObject((HGDIOBJECT)rgn1);
+
+ if (rgn2)
+ gdi_DeleteObject((HGDIOBJECT)rgn2);
+
+ if (bmp)
+ gdi_DeleteObject((HGDIOBJECT)bmp);
+ gdi_DeleteDC(hdc);
return 0;
}
static int test_gdi_GetDC(void)
{
+ int rc = -1;
HGDI_DC hdc;
if (!(hdc = gdi_GetDC()))
}
if (hdc->format != PIXEL_FORMAT_XRGB32)
- return -1;
+ goto fail;
if (hdc->drawMode != GDI_R2_BLACK)
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+ gdi_DeleteDC(hdc);
+ return rc;
}
static int test_gdi_CreateCompatibleDC(void)
{
- HGDI_DC hdc;
- HGDI_DC chdc;
+ int rc = -1;
+ HGDI_DC hdc = NULL;
+ HGDI_DC chdc = NULL;
if (!(hdc = gdi_GetDC()))
{
if (!(chdc = gdi_CreateCompatibleDC(hdc)))
{
printf("gdi_CreateCompatibleDC failed\n");
- return -1;
+ goto fail;
}
if (chdc->format != hdc->format)
- return -1;
+ goto fail;
if (chdc->drawMode != hdc->drawMode)
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+
+ if (chdc)
+ gdi_DeleteDC(chdc);
+
+ gdi_DeleteDC(hdc);
+ return rc;
}
static int test_gdi_CreateBitmap(void)
{
+ int rc = -1;
UINT32 format = PIXEL_FORMAT_ARGB32;
UINT32 width;
UINT32 height;
BYTE* data;
- HGDI_BITMAP hBitmap;
+ HGDI_BITMAP hBitmap = NULL;
width = 32;
height = 16;
if (!(hBitmap = gdi_CreateBitmap(width, height, format, data)))
{
printf("gdi_CreateBitmap failed\n");
- return -1;
+ goto fail;
}
if (hBitmap->objectType != GDIOBJECT_BITMAP)
- return -1;
+ goto fail;
if (hBitmap->format != format)
- return -1;
+ goto fail;
if (hBitmap->width != width)
- return -1;
+ goto fail;
if (hBitmap->height != height)
- return -1;
+ goto fail;
if (hBitmap->data != data)
- return -1;
+ goto fail;
- gdi_DeleteObject((HGDIOBJECT) hBitmap);
- return 0;
+ rc = 0;
+fail:
+
+ if (hBitmap)
+ gdi_DeleteObject((HGDIOBJECT) hBitmap);
+ else
+ free(data);
+
+ return rc;
}
static int test_gdi_CreateCompatibleBitmap(void)
{
+ int rc = -1;
HGDI_DC hdc;
UINT32 width;
UINT32 height;
- HGDI_BITMAP hBitmap;
+ HGDI_BITMAP hBitmap = NULL;
if (!(hdc = gdi_GetDC()))
{
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
if (hBitmap->objectType != GDIOBJECT_BITMAP)
- return -1;
+ goto fail;
if (hBitmap->format != hdc->format)
- return -1;
+ goto fail;
if (hBitmap->width != width)
- return -1;
+ goto fail;
if (hBitmap->height != height)
- return -1;
+ goto fail;
if (!hBitmap->data)
- return -1;
+ goto fail;
- gdi_DeleteObject((HGDIOBJECT) hBitmap);
- return 0;
+ rc = 0;
+fail:
+
+ if (hBitmap)
+ gdi_DeleteObject((HGDIOBJECT) hBitmap);
+
+ gdi_DeleteDC(hdc);
+ return rc;
}
static int test_gdi_CreatePen(void)
{
+ int rc = -1;
const UINT32 format = PIXEL_FORMAT_RGBA32;
HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD,
format, NULL);
}
if (hPen->style != GDI_PS_SOLID)
- return -1;
+ goto fail;
if (hPen->width != 8)
- return -1;
+ goto fail;
if (hPen->color != 0xAABBCCDD)
- return -1;
+ goto fail;
+ rc = 0;
+fail:
gdi_DeleteObject((HGDIOBJECT) hPen);
- return 0;
+ return rc;
}
static int test_gdi_CreateSolidBrush(void)
{
+ int rc = -1;
HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);
if (hBrush->objectType != GDIOBJECT_BRUSH)
- return -1;
+ goto fail;
if (hBrush->style != GDI_BS_SOLID)
- return -1;
+ goto fail;
if (hBrush->color != 0xAABBCCDD)
- return -1;
+ goto fail;
+ rc = 0;
+fail:
gdi_DeleteObject((HGDIOBJECT) hBrush);
- return 0;
+ return rc;
}
static int test_gdi_CreatePatternBrush(void)
{
+ int rc = -1;
HGDI_BRUSH hBrush;
HGDI_BITMAP hBitmap;
hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
hBrush = gdi_CreatePatternBrush(hBitmap);
+ if (!hBitmap || !hBrush)
+ goto fail;
+
if (hBrush->objectType != GDIOBJECT_BRUSH)
- return -1;
+ goto fail;
if (hBrush->style != GDI_BS_PATTERN)
- return -1;
+ goto fail;
if (hBrush->pattern != hBitmap)
- return -1;
+ goto fail;
- gdi_DeleteObject((HGDIOBJECT) hBitmap);
- return 0;
+ rc = 0;
+fail:
+
+ if (hBitmap)
+ gdi_DeleteObject((HGDIOBJECT) hBitmap);
+
+ if (hBrush)
+ gdi_DeleteObject((HGDIOBJECT) hBrush);
+
+ return rc;
}
static int test_gdi_CreateRectRgn(void)
{
- int x1 = 32;
- int y1 = 64;
- int x2 = 128;
- int y2 = 256;
+ int rc = -1;
+ UINT32 x1 = 32;
+ UINT32 y1 = 64;
+ UINT32 x2 = 128;
+ UINT32 y2 = 256;
HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
+ if (!hRegion)
+ return rc;
+
if (hRegion->objectType != GDIOBJECT_REGION)
- return -1;
+ goto fail;
if (hRegion->x != x1)
- return -1;
+ goto fail;
if (hRegion->y != y1)
- return -1;
+ goto fail;
if (hRegion->w != x2 - x1 + 1)
- return -1;
+ goto fail;
if (hRegion->h != y2 - y1 + 1)
- return -1;
+ goto fail;
if (hRegion->null)
- return -1;
+ goto fail;
+ rc = 0;
+fail:
gdi_DeleteObject((HGDIOBJECT) hRegion);
- return 0;
+ return rc;
}
static int test_gdi_CreateRect(void)
{
+ int rc = -1;
HGDI_RECT hRect;
- int x1 = 32;
- int y1 = 64;
- int x2 = 128;
- int y2 = 256;
+ UINT32 x1 = 32;
+ UINT32 y1 = 64;
+ UINT32 x2 = 128;
+ UINT32 y2 = 256;
if (!(hRect = gdi_CreateRect(x1, y1, x2, y2)))
{
}
if (hRect->objectType != GDIOBJECT_RECT)
- return -1;
+ goto fail;
if (hRect->left != x1)
- return -1;
+ goto fail;
if (hRect->top != y1)
- return -1;
+ goto fail;
if (hRect->right != x2)
- return -1;
+ goto fail;
if (hRect->bottom != y2)
- return -1;
+ goto fail;
+ rc = 0;
+fail:
gdi_DeleteObject((HGDIOBJECT) hRect);
- return 0;
+ return rc;
}
static BOOL test_gdi_GetPixel(void)
hdc->format = colorFormatList[x];
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
+
+ if (!hBitmap)
+ {
+ gdi_DeleteDC(hdc);
+ return -1;
+ }
+
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
bpp = GetBytesPerPixel(hBitmap->format);
static int test_gdi_SetROP2(void)
{
+ int rc = -1;
HGDI_DC hdc;
if (!(hdc = gdi_GetDC()))
gdi_SetROP2(hdc, GDI_R2_BLACK);
if (hdc->drawMode != GDI_R2_BLACK)
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+ gdi_DeleteDC(hdc);
+ return rc;
}
static int test_gdi_MoveToEx(void)
{
+ int rc = -1;
HGDI_DC hdc;
- HGDI_PEN hPen;
- HGDI_POINT prevPoint;
+ HGDI_PEN hPen = NULL;
+ HGDI_POINT prevPoint = NULL;
const UINT32 format = PIXEL_FORMAT_RGBA32;
gdiPalette* palette = NULL;
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette)))
{
printf("gdi_CreatePen failed\n");
- return -1;
+ goto fail;
}
gdi_SelectObject(hdc, (HGDIOBJECT) hPen);
gdi_MoveToEx(hdc, 128, 256, NULL);
if (hdc->pen->posX != 128)
- return -1;
+ goto fail;
if (hdc->pen->posY != 256)
- return -1;
+ goto fail;
prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT));
ZeroMemory(prevPoint, sizeof(GDI_POINT));
gdi_MoveToEx(hdc, 64, 128, prevPoint);
if (prevPoint->x != 128)
- return -1;
+ goto fail;
if (prevPoint->y != 256)
- return -1;
+ goto fail;
if (hdc->pen->posX != 64)
- return -1;
+ goto fail;
if (hdc->pen->posY != 128)
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+
+ if (hPen)
+ gdi_DeleteObject((HGDIOBJECT)hPen);
+
+ free(prevPoint);
+ gdi_DeleteDC(hdc);
+ return rc;
}
int TestGdiCreate(int argc, char* argv[])
for (x = 0; x < map_size; x++)
gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp);
+ gdi_DeleteObject((HGDIOBJECT)hBmp);
gdi_DeleteObject((HGDIOBJECT) pen);
gdi_DeleteDC(hdc);
static int test_gdi_PtInRect(void)
{
+ int rc = -1;
HGDI_RECT hRect;
- int left = 20;
- int top = 40;
- int right = 60;
- int bottom = 80;
+ UINT32 left = 20;
+ UINT32 top = 40;
+ UINT32 right = 60;
+ UINT32 bottom = 80;
if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
{
printf("gdi_CreateRect failed\n");
- return -1;
+ return rc;
}
if (gdi_PtInRect(hRect, 0, 0))
- return -1;
+ goto fail;
if (gdi_PtInRect(hRect, 500, 500))
- return -1;
+ goto fail;
if (gdi_PtInRect(hRect, 40, 100))
- return -1;
+ goto fail;
if (gdi_PtInRect(hRect, 10, 40))
- return -1;
+ goto fail;
if (!gdi_PtInRect(hRect, 30, 50))
- return -1;
+ goto fail;
if (!gdi_PtInRect(hRect, left, top))
- return -1;
+ goto fail;
if (!gdi_PtInRect(hRect, right, bottom))
- return -1;
+ goto fail;
if (!gdi_PtInRect(hRect, right, 60))
- return -1;
+ goto fail;
if (!gdi_PtInRect(hRect, 40, bottom))
- return -1;
+ goto fail;
- return 0;
+ rc = 0;
+fail:
+ gdi_DeleteObject((HGDIOBJECT)hRect);
+ return rc;
}
int test_gdi_FillRect(void)
{
int rc = -1;
- HGDI_DC hdc;
- HGDI_RECT hRect;
+ HGDI_DC hdc = NULL;
+ HGDI_RECT hRect = NULL;
HGDI_BRUSH hBrush = NULL;
HGDI_BITMAP hBitmap = NULL;
UINT32 color;
UINT32 pixel;
UINT32 rawPixel;
- int x, y;
- int badPixels;
- int goodPixels;
- int width = 200;
- int height = 300;
- int left = 20;
- int top = 40;
- int right = 60;
- int bottom = 80;
+ UINT32 x, y;
+ UINT32 badPixels;
+ UINT32 goodPixels;
+ UINT32 width = 200;
+ UINT32 height = 300;
+ UINT32 left = 20;
+ UINT32 top = 40;
+ UINT32 right = 60;
+ UINT32 bottom = 80;
if (!(hdc = gdi_GetDC()))
{
fail:
gdi_DeleteObject((HGDIOBJECT) hBrush);
gdi_DeleteObject((HGDIOBJECT) hBitmap);
+ gdi_DeleteObject((HGDIOBJECT)hRect);
+ gdi_DeleteDC(hdc);
return rc;
}
if (!bitmapsEqual)
{
- printf("\n%s\n", name);
+ printf("Testing ROP %s [%s|%s]\n", name,
+ GetColorFormatName(hBmpActual->format),
+ GetColorFormatName(hBmpExpected->format));
test_dump_bitmap(hBmpActual, "Actual");
test_dump_bitmap(hBmpExpected, "Expected");
fflush(stdout);
}
/* Open the server socket and start listening. */
- sprintf_s(name, sizeof(name), "tfreerdp-server.%d", port);
+ sprintf_s(name, sizeof(name), "tfreerdp-server.%ld", port);
file = GetKnownSubPath(KNOWN_PATH_TEMP, name);
if (!file)
DWORD Flags;
struct
{
- DWORD LongFunction:1;
- DWORD Persistent:1;
- DWORD Private:30;
+ DWORD LongFunction: 1;
+ DWORD Persistent: 1;
+ DWORD Private: 30;
} s;
} u;
} TP_CALLBACK_ENVIRON_V1;
typedef VOID (*PTP_WORK_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work);
typedef VOID (*PTP_TIMER_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_TIMER Timer);
-typedef VOID (*PTP_WAIT_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WAIT Wait, TP_WAIT_RESULT WaitResult);
+typedef VOID (*PTP_WAIT_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WAIT Wait,
+ TP_WAIT_RESULT WaitResult);
#endif
-/*
-There is a bug in the Win8 header that defines the IO
+/*
+There is a bug in the Win8 header that defines the IO
callback unconditionally. Versions of Windows greater
-than XP will conditionally define it. The following
+than XP will conditionally define it. The following
logic tries to fix that.
*/
#ifdef _THREADPOOLAPISET_H_
#ifndef PTP_WIN32_IO_CALLBACK_DEFINED
-typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PVOID Overlapped,
- ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io);
+typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context,
+ PVOID Overlapped,
+ ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io);
#endif
#ifdef WINPR_THREAD_POOL
-WINPR_API PTP_WAIT winpr_CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+WINPR_API PTP_WAIT winpr_CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolWait(PTP_WAIT pwa);
WINPR_API VOID winpr_SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout);
WINPR_API VOID winpr_WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPendingCallbacks);
/* Work */
-WINPR_API PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+WINPR_API PTP_WORK winpr_CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolWork(PTP_WORK pwk);
WINPR_API VOID winpr_SubmitThreadpoolWork(PTP_WORK pwk);
-WINPR_API BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+WINPR_API BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallbacks);
#define CreateThreadpoolWork winpr_CreateThreadpoolWork
/* Timer */
-WINPR_API PTP_TIMER winpr_CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+WINPR_API PTP_TIMER winpr_CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolTimer(PTP_TIMER pti);
WINPR_API BOOL winpr_IsThreadpoolTimerSet(PTP_TIMER pti);
-WINPR_API VOID winpr_SetThreadpoolTimer(PTP_TIMER pti, PFILETIME pftDueTime, DWORD msPeriod, DWORD msWindowLength);
+WINPR_API VOID winpr_SetThreadpoolTimer(PTP_TIMER pti, PFILETIME pftDueTime, DWORD msPeriod,
+ DWORD msWindowLength);
WINPR_API VOID winpr_WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancelPendingCallbacks);
#define CreateThreadpoolTimer winpr_CreateThreadpoolTimer
/* I/O */
-WINPR_API PTP_IO winpr_CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+WINPR_API PTP_IO winpr_CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID winpr_CloseThreadpoolIo(PTP_IO pio);
WINPR_API VOID winpr_StartThreadpoolIo(PTP_IO pio);
WINPR_API VOID winpr_CancelThreadpoolIo(PTP_IO pio);
/* Clean-up Group */
+WINPR_API VOID winpr_SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg,
+ PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng);
WINPR_API PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void);
-WINPR_API VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
+WINPR_API VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg,
+ BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
WINPR_API VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg);
+#define SetThreadpoolCallbackCleanupGroup winpr_SetThreadpoolCallbackCleanupGroup
#define CreateThreadpoolCleanupGroup winpr_CreateThreadpoolCleanupGroup
#define CloseThreadpoolCleanupGroupMembers winpr_CloseThreadpoolCleanupGroupMembers
#define CloseThreadpoolCleanupGroup winpr_CloseThreadpoolCleanupGroup
pcbe->Pool = ptpp;
}
-static INLINE VOID SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg, PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng)
-{
- pcbe->CleanupGroup = ptpcg;
- pcbe->CleanupGroupCancelCallback = pfng;
-}
-
static INLINE VOID SetThreadpoolCallbackRunsLong(PTP_CALLBACK_ENVIRON pcbe)
{
pcbe->u.s.LongFunction = 1;
/* Callback Clean-up */
WINPR_API VOID winpr_SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt);
-WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem, DWORD crel);
+WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem,
+ DWORD crel);
WINPR_API VOID winpr_ReleaseMutexWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE mut);
-WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, PCRITICAL_SECTION pcs);
+WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci,
+ PCRITICAL_SECTION pcs);
WINPR_API VOID winpr_FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod);
WINPR_API VOID winpr_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci);
#include <winpr/tchar.h>
#include <winpr/dsparse.h>
-LPCTSTR testServiceClass = _T("HTTP");
-LPCTSTR testServiceName = _T("LAB1-W2K8R2-GW.lab1.awake.local");
-LPCTSTR testSpn = _T("HTTP/LAB1-W2K8R2-GW.lab1.awake.local");
+static LPCTSTR testServiceClass = _T("HTTP");
+static LPCTSTR testServiceName = _T("LAB1-W2K8R2-GW.lab1.awake.local");
+static LPCTSTR testSpn = _T("HTTP/LAB1-W2K8R2-GW.lab1.awake.local");
int TestDsMakeSpn(int argc, char* argv[])
{
- LPTSTR Spn;
+ int rc = -1;
+ LPTSTR Spn = NULL;
DWORD status;
DWORD SpnLength;
-
SpnLength = -1;
status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, NULL);
if (status != ERROR_INVALID_PARAMETER)
{
_tprintf(_T("DsMakeSpn: expected ERROR_INVALID_PARAMETER\n"));
- return -1;
+ goto fail;
}
SpnLength = 0;
if (status != ERROR_BUFFER_OVERFLOW)
{
_tprintf(_T("DsMakeSpn: expected ERROR_BUFFER_OVERFLOW\n"));
- return -1;
+ goto fail;
}
if (SpnLength != 37)
{
_tprintf(_T("DsMakeSpn: SpnLength mismatch: Actual: %")_T(PRIu32)_T(", Expected: 37\n"), SpnLength);
- return -1;
+ goto fail;
}
/* SpnLength includes null terminator */
Spn = (LPTSTR) calloc(SpnLength, sizeof(TCHAR));
+
if (!Spn)
{
_tprintf(_T("DsMakeSpn: Unable to allocate memroy\n"));
- return -1;
+ goto fail;
}
-
status = DsMakeSpn(testServiceClass, testServiceName, NULL, 0, NULL, &SpnLength, Spn);
if (status != ERROR_SUCCESS)
{
_tprintf(_T("DsMakeSpn: expected ERROR_SUCCESS\n"));
- return -1;
+ goto fail;
}
if (_tcscmp(Spn, testSpn) != 0)
{
_tprintf(_T("DsMakeSpn: SPN mismatch: Actual: %s, Expected: %s\n"), Spn, testSpn);
- return -1;
+ goto fail;
}
_tprintf(_T("DsMakeSpn: %s\n"), Spn);
-
- return 0;
+ rc = 0;
+fail:
+ free(Spn);
+ return rc;
}
LPTCH lpszEnvironmentBlock;
LPTCH lpsz2Merge = "SHELL=123\0test=1\0test1=2\0DISPLAY=:77\0\0";
LPTCH lpszMergedEnvironmentBlock;
-
lpszEnvironmentBlock = GetEnvironmentStrings();
- lpszMergedEnvironmentBlock = MergeEnvironmentStrings(lpszEnvironmentBlock,lpsz2Merge);
-
+ lpszMergedEnvironmentBlock = MergeEnvironmentStrings(lpszEnvironmentBlock, lpsz2Merge);
p = (TCHAR*) lpszMergedEnvironmentBlock;
while (p[0] && p[1])
p += (length + 1);
}
+ FreeEnvironmentStrings(lpszMergedEnvironmentBlock);
FreeEnvironmentStrings(lpszEnvironmentBlock);
#endif
-
return 0;
}
LPTSTR BasePath;
WIN32_FIND_DATA FindData;
TCHAR FilePath[PATHCCH_MAX_CCH];
-
str = argv[1];
-
#ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
+
if (!BasePath)
{
_tprintf(_T("Unable to allocate memory\n"));
return -1;
}
+
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+
if (!BasePath)
{
printf("Unable to allocate memory\n");
return -1;
}
+
length = strlen(BasePath);
#endif
-
CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
FilePath[length] = 0;
-
PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestFile1"));
-
+ free(BasePath);
_tprintf(_T("Finding file: %s\n"), FilePath);
-
hFind = FindFirstFile(FilePath, &FindData);
if (hFind == INVALID_HANDLE_VALUE)
if (_tcscmp(FindData.cFileName, testFile1) != 0)
{
_tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"),
- testFile1, FindData.cFileName);
+ testFile1, FindData.cFileName);
return -1;
}
FindClose(hFind);
-
return 0;
}
LPTSTR BasePath;
WIN32_FIND_DATA FindData;
TCHAR FilePath[PATHCCH_MAX_CCH];
-
str = argv[1];
-
#ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) calloc((length + 1), sizeof(WCHAR));
+
if (!BasePath)
{
_tprintf(_T("Unable to allocate memory"));
return -1;
}
+
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0;
#else
BasePath = _strdup(str);
+
if (!BasePath)
{
printf("Unable to allocate memory");
return -1;
}
+
length = strlen(BasePath);
#endif
-
/* Simple filter matching all files inside current directory */
-
CopyMemory(FilePath, BasePath, length * sizeof(TCHAR));
FilePath[length] = 0;
-
PathCchConvertStyle(BasePath, length, PATH_STYLE_WINDOWS);
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2"));
NativePathCchAppend(FilePath, PATHCCH_MAX_CCH, _T("TestDirectory2File*"));
-
+ free(BasePath);
_tprintf(_T("Finding file: %s\n"), FilePath);
-
hFind = FindFirstFile(FilePath, &FindData);
if (hFind == INVALID_HANDLE_VALUE)
* The current implementation does not enforce a particular order
*/
- if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) && (_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
+ if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) &&
+ (_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
{
_tprintf(_T("FindFirstFile failure: Expected: %s, Actual: %s\n"),
- testDirectory2File1, FindData.cFileName);
+ testDirectory2File1, FindData.cFileName);
return -1;
}
return -1;
}
- if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) && (_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
+ if ((_tcscmp(FindData.cFileName, testDirectory2File1) != 0) &&
+ (_tcscmp(FindData.cFileName, testDirectory2File2) != 0))
{
_tprintf(_T("FindNextFile failure: Expected: %s, Actual: %s\n"),
- testDirectory2File2, FindData.cFileName);
+ testDirectory2File2, FindData.cFileName);
return -1;
}
}
FindClose(hFind);
-
return 0;
}
OBJECT_ATTRIBUTES attributes;
IO_STATUS_BLOCK ioStatusBlock;
int result = -1;
-
_RtlInitAnsiString(&aString, TESTFILE);
-
ntstatus = _RtlAnsiStringToUnicodeString(&uString, &aString, TRUE);
+
if (ntstatus != STATUS_SUCCESS)
{
printf("_RtlAnsiStringToUnicodeString failure: 0x%08"PRIX32"\n", ntstatus);
handle = NULL;
ZeroMemory(&ioStatusBlock, sizeof(IO_STATUS_BLOCK));
-
_InitializeObjectAttributes(&attributes, &uString, 0, NULL, NULL);
-
DesiredAccess = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
CreateOptions = FILE_DIRECTORY_FILE | FILE_WRITE_THROUGH;
CreateDisposition = FILE_OVERWRITE_IF;
-
ntstatus = _NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock,
- 0, 0, CreateDisposition, CreateOptions, 0, 0, 0);
+ 0, 0, CreateDisposition, CreateOptions, 0, 0, 0);
if (ntstatus != STATUS_SUCCESS)
{
goto out;
}
- _RtlFreeUnicodeString(&uString);
-
ntstatus = _NtClose(handle);
if (ntstatus != STATUS_SUCCESS)
}
result = 0;
-
out:
-
+ _RtlFreeUnicodeString(&uString);
#ifndef _WIN32
+
if (result == 0)
{
printf("%s: Error, this test is currently expected not to succeed on this platform.\n",
- __FUNCTION__);
+ __FUNCTION__);
result = -1;
}
else
{
printf("%s: This test is currently expected to fail on this platform.\n",
- __FUNCTION__);
+ __FUNCTION__);
result = 0;
}
-#endif
+#endif
return result;
}
int TestPathShell(int argc, char* argv[])
{
- char* path;
-
- path = GetKnownPath(KNOWN_PATH_HOME);
- if (!path)
- return -1;
- printf("KNOWN_PATH_HOME: %s\n", path);
-
- path = GetKnownPath(KNOWN_PATH_TEMP);
- if (!path)
- return -1;
- printf("KNOWN_PATH_TEMP: %s\n", path);
-
- path = GetKnownPath(KNOWN_PATH_XDG_DATA_HOME);
- if (!path)
- return -1;
- printf("KNOWN_PATH_DATA: %s\n", path);
-
- path = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME);
- if (!path)
- return -1;
- printf("KNOWN_PATH_CONFIG: %s\n", path);
-
- path = GetKnownPath(KNOWN_PATH_XDG_CACHE_HOME);
- if (!path)
- return -1;
- printf("KNOWN_PATH_CACHE: %s\n", path);
-
- path = GetKnownPath(KNOWN_PATH_XDG_RUNTIME_DIR);
- if (!path)
- return -1;
- printf("KNOWN_PATH_RUNTIME: %s\n", path);
-
- path = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
- if (!path)
- return -1;
- printf("KNOWN_PATH_CONFIG SubPath: %s\n", path);
-
- return 0;
+ const int paths[] =
+ {
+ KNOWN_PATH_HOME,
+ KNOWN_PATH_TEMP,
+ KNOWN_PATH_XDG_DATA_HOME,
+ KNOWN_PATH_XDG_CONFIG_HOME,
+ KNOWN_PATH_XDG_CACHE_HOME,
+ KNOWN_PATH_XDG_RUNTIME_DIR,
+ KNOWN_PATH_XDG_CONFIG_HOME
+ };
+ const char* names[] =
+ {
+ "KNOWN_PATH_HOME",
+ "KNOWN_PATH_TEMP",
+ "KNOWN_PATH_XDG_DATA_HOME",
+ "KNOWN_PATH_XDG_CONFIG_HOME",
+ "KNOWN_PATH_XDG_CACHE_HOME",
+ "KNOWN_PATH_XDG_RUNTIME_DIR",
+ "KNOWN_PATH_XDG_CONFIG_HOME"
+ };
+ int rc = 0;
+ size_t x;
+
+ for (x = 0; x < sizeof(paths) / sizeof(paths[0]); x++)
+ {
+ const int id = paths[x];
+ const char* name = names[x];
+ {
+ char* path = GetKnownPath(id);
+
+ if (!path)
+ rc = -1;
+
+ printf("%s Path: %s\n", name, path);
+ free(path);
+ }
+ {
+ char* path = GetKnownSubPath(id, "freerdp");
+
+ if (!path)
+ rc = -1;
+
+ printf("%s SubPath: %s\n", name, path);
+ free(path);
+ }
+ }
+
+ return rc;
}
#ifdef _WIN32
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
-static PTP_CLEANUP_GROUP (WINAPI * pCreateThreadpoolCleanupGroup)();
-static VOID (WINAPI * pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
-static VOID (WINAPI * pCloseThreadpoolCleanupGroup)(PTP_CLEANUP_GROUP ptpcg);
+static PTP_CLEANUP_GROUP(WINAPI* pCreateThreadpoolCleanupGroup)();
+static VOID (WINAPI* pCloseThreadpoolCleanupGroupMembers)(PTP_CLEANUP_GROUP ptpcg,
+ BOOL fCancelPendingCallbacks, PVOID pvCleanupContext);
+static VOID (WINAPI* pCloseThreadpoolCleanupGroup)(PTP_CLEANUP_GROUP ptpcg);
-static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID *context)
+static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
+
if (kernel32)
{
pCreateThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup");
- pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroupMembers");
+ pCloseThreadpoolCleanupGroupMembers = (void*)GetProcAddress(kernel32,
+ "CloseThreadpoolCleanupGroupMembers");
pCloseThreadpoolCleanupGroup = (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup");
}
+
return TRUE;
}
#endif
-PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup()
+PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void)
{
PTP_CLEANUP_GROUP cleanupGroup = NULL;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pCreateThreadpoolCleanupGroup)
return pCreateThreadpoolCleanupGroup();
-#endif
- cleanupGroup = (PTP_CLEANUP_GROUP) malloc(sizeof(TP_CLEANUP_GROUP));
+
+#else
+ cleanupGroup = (PTP_CLEANUP_GROUP) calloc(1, sizeof(TP_CLEANUP_GROUP));
+
+ if (!cleanupGroup)
+ return NULL;
+
+ cleanupGroup->groups = ArrayList_New(FALSE);
+
+ if (!cleanupGroup->groups)
+ {
+ free(cleanupGroup);
+ return NULL;
+ }
+
return cleanupGroup;
+#endif
+}
+
+VOID winpr_SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg,
+ PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng)
+{
+ pcbe->CleanupGroup = ptpcg;
+ pcbe->CleanupGroupCancelCallback = pfng;
+#ifndef _WIN32
+ pcbe->CleanupGroup->env = pcbe;
+#endif
}
-VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks, PVOID pvCleanupContext)
+VOID winpr_CloseThreadpoolCleanupGroupMembers(PTP_CLEANUP_GROUP ptpcg, BOOL fCancelPendingCallbacks,
+ PVOID pvCleanupContext)
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pCloseThreadpoolCleanupGroupMembers)
{
pCloseThreadpoolCleanupGroupMembers(ptpcg, fCancelPendingCallbacks, pvCleanupContext);
return;
}
+
+#else
+
+ while (ArrayList_Count(ptpcg->groups) > 0)
+ {
+ PTP_WORK work = ArrayList_GetItem(ptpcg->groups, 0);
+ winpr_CloseThreadpoolWork(work);
+ }
+
#endif
- /* No default implementation */
}
VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg)
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pCloseThreadpoolCleanupGroup)
{
pCloseThreadpoolCleanupGroup(ptpcg);
return;
}
-#endif
+
+#else
+
+ if (ptpcg && ptpcg->groups)
+ ArrayList_Free(ptpcg->groups);
+
+ ptpcg->env->CleanupGroup = NULL;
free(ptpcg);
+#endif
}
#endif /* WINPR_THREAD_POOL defined */
struct _TP_CLEANUP_GROUP
{
+#ifndef _WIN32
+ wArrayList* groups;
+ PTP_CALLBACK_ENVIRON env;
+#else
void* dummy;
+#endif
};
-PTP_POOL GetDefaultThreadpool();
+PTP_POOL GetDefaultThreadpool(void);
#endif /* WINPR_POOL_PRIVATE_H */
static LONG count = 0;
-void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
+static void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
{
int index;
BYTE a[1024];
BYTE b[1024];
BYTE c[1024];
-
printf("Hello %s: %03"PRId32" (thread: 0x%08"PRIX32")\n", (char*) context,
- InterlockedIncrement(&count), GetCurrentThreadId());
+ InterlockedIncrement(&count), GetCurrentThreadId());
for (index = 0; index < 100; index++)
{
}
}
-int TestPoolWork(int argc, char* argv[])
+static BOOL test1(void)
{
int index;
- PTP_POOL pool;
PTP_WORK work;
- PTP_CLEANUP_GROUP cleanupGroup;
- TP_CALLBACK_ENVIRON environment;
-
printf("Global Thread Pool\n");
-
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", NULL);
if (!work)
{
printf("CreateThreadpoolWork failure\n");
- return -1;
+ return FALSE;
}
/**
WaitForThreadpoolWorkCallbacks(work, FALSE);
CloseThreadpoolWork(work);
+ return TRUE;
+}
+static BOOL test2(void)
+{
+ BOOL rc = FALSE;
+ int index;
+ PTP_POOL pool;
+ PTP_WORK work;
+ PTP_CLEANUP_GROUP cleanupGroup;
+ TP_CALLBACK_ENVIRON environment;
printf("Private Thread Pool\n");
if (!(pool = CreateThreadpool(NULL)))
{
printf("CreateThreadpool failure\n");
- return -1;
+ return FALSE;
}
if (!SetThreadpoolThreadMinimum(pool, 4))
{
printf("SetThreadpoolThreadMinimum failure\n");
- return -1;
+ goto fail;
}
SetThreadpoolThreadMaximum(pool, 8);
-
InitializeThreadpoolEnvironment(&environment);
SetThreadpoolCallbackPool(&environment, pool);
-
cleanupGroup = CreateThreadpoolCleanupGroup();
if (!cleanupGroup)
{
printf("CreateThreadpoolCleanupGroup failure\n");
- return -1;
+ goto fail;
}
SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);
-
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", &environment);
if (!work)
{
printf("CreateThreadpoolWork failure\n");
- return -1;
+ goto fail;
}
for (index = 0; index < 10; index++)
SubmitThreadpoolWork(work);
WaitForThreadpoolWorkCallbacks(work, FALSE);
+ rc = TRUE;
+fail:
- CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
-
- CloseThreadpoolCleanupGroup(cleanupGroup);
-
- DestroyThreadpoolEnvironment(&environment);
+ if (cleanupGroup)
+ {
+ CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
+ CloseThreadpoolCleanupGroup(cleanupGroup);
+ DestroyThreadpoolEnvironment(&environment);
+ /**
+ * See Remarks at https://msdn.microsoft.com/en-us/library/windows/desktop/ms682043(v=vs.85).aspx
+ * If there is a cleanup group associated with the work object,
+ * it is not necessary to call CloseThreadpoolWork !
+ * calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait,
+ * and timer objects associated with the cleanup group.
+ */
+#if 0
+ CloseThreadpoolWork(work); // this would segfault, see comment above. */
+#endif
+ }
- /**
- * See Remarks at https://msdn.microsoft.com/en-us/library/windows/desktop/ms682043(v=vs.85).aspx
- * If there is a cleanup group associated with the work object,
- * it is not necessary to call CloseThreadpoolWork !
- * calling the CloseThreadpoolCleanupGroupMembers function releases the work, wait,
- * and timer objects associated with the cleanup group.
- */
+ CloseThreadpool(pool);
+ return rc;
+}
- /* CloseThreadpoolWork(work); // this would segfault, see comment above. */
+int TestPoolWork(int argc, char* argv[])
+{
+ if (!test1())
+ return -1;
- CloseThreadpool(pool);
+ if (!test2())
+ return -1;
return 0;
}
#ifdef _WIN32
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
-static PTP_WORK(WINAPI* pCreateThreadpoolWork)(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+static PTP_WORK(WINAPI* pCreateThreadpoolWork)(PTP_WORK_CALLBACK pfnwk, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
static VOID (WINAPI* pCloseThreadpoolWork)(PTP_WORK pwk);
static VOID (WINAPI* pSubmitThreadpoolWork)(PTP_WORK pwk);
-static BOOL (WINAPI* pTrySubmitThreadpoolCallback)(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
+static BOOL (WINAPI* pTrySubmitThreadpoolCallback)(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe);
static VOID (WINAPI* pWaitForThreadpoolWorkCallbacks)(PTP_WORK pwk, BOOL fCancelPendingCallbacks);
-static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID *context)
+static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
+
if (kernel32)
{
pCreateThreadpoolWork = (void*)GetProcAddress(kernel32, "CreateThreadpoolWork");
pTrySubmitThreadpoolCallback = (void*)GetProcAddress(kernel32, "TrySubmitThreadpoolCallback");
pWaitForThreadpoolWorkCallbacks = (void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks");
}
+
return TRUE;
}
#endif
PTP_WORK work = NULL;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pCreateThreadpoolWork)
return pCreateThreadpoolWork(pfnwk, pv, pcbe);
+
#endif
- work = (PTP_WORK) malloc(sizeof(TP_WORK));
+ work = (PTP_WORK) calloc(1, sizeof(TP_WORK));
if (work)
{
pcbe = &DEFAULT_CALLBACK_ENVIRONMENT;
pcbe->Pool = GetDefaultThreadpool();
}
+
work->CallbackEnvironment = pcbe;
work->WorkCallback = pfnwk;
work->CallbackParameter = pv;
+#ifndef _WIN32
+
+ if (pcbe->CleanupGroup)
+ ArrayList_Add(pcbe->CleanupGroup->groups, work);
+
+#endif
}
return work;
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pCloseThreadpoolWork)
{
pCloseThreadpoolWork(pwk);
return;
}
+
+#else
+
+ if (pwk->CallbackEnvironment->CleanupGroup)
+ ArrayList_Remove(pwk->CallbackEnvironment->CleanupGroup->groups, pwk);
+
#endif
free(pwk);
}
PTP_CALLBACK_INSTANCE callbackInstance;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pSubmitThreadpoolWork)
{
pSubmitThreadpoolWork(pwk);
return;
}
+
#endif
pool = pwk->CallbackEnvironment->Pool;
- callbackInstance = (PTP_CALLBACK_INSTANCE) malloc(sizeof(TP_CALLBACK_INSTANCE));
+ callbackInstance = (PTP_CALLBACK_INSTANCE) calloc(1, sizeof(TP_CALLBACK_INSTANCE));
if (callbackInstance)
{
}
}
-BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv, PTP_CALLBACK_ENVIRON pcbe)
+BOOL winpr_TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK pfns, PVOID pv,
+ PTP_CALLBACK_ENVIRON pcbe)
{
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pTrySubmitThreadpoolCallback)
return pTrySubmitThreadpoolCallback(pfns, pv, pcbe);
+
#endif
WLog_ERR(TAG, "TrySubmitThreadpoolCallback is not implemented");
return FALSE;
PTP_POOL pool;
#ifdef _WIN32
InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL);
+
if (pWaitForThreadpoolWorkCallbacks)
{
pWaitForThreadpoolWorkCallbacks(pwk, fCancelPendingCallbacks);
return;
}
+
#endif
pool = pwk->CallbackEnvironment->Pool;
event = CountdownEvent_WaitHandle(pool->WorkComplete);
extern const SecurityFunctionTableA SCHANNEL_SecurityFunctionTableA;
extern const SecurityFunctionTableW SCHANNEL_SecurityFunctionTableW;
-const SecPkgInfoA* SecPkgInfoA_LIST[] =
+static const SecPkgInfoA* SecPkgInfoA_LIST[] =
{
- &NTLM_SecPkgInfoA,
- &KERBEROS_SecPkgInfoA,
- &NEGOTIATE_SecPkgInfoA,
- &CREDSSP_SecPkgInfoA,
- &SCHANNEL_SecPkgInfoA
+ &NTLM_SecPkgInfoA,
+ &KERBEROS_SecPkgInfoA,
+ &NEGOTIATE_SecPkgInfoA,
+ &CREDSSP_SecPkgInfoA,
+ &SCHANNEL_SecPkgInfoA
};
-const SecPkgInfoW* SecPkgInfoW_LIST[] =
+static const SecPkgInfoW* SecPkgInfoW_LIST[] =
{
- &NTLM_SecPkgInfoW,
- &KERBEROS_SecPkgInfoW,
- &NEGOTIATE_SecPkgInfoW,
- &CREDSSP_SecPkgInfoW,
- &SCHANNEL_SecPkgInfoW
+ &NTLM_SecPkgInfoW,
+ &KERBEROS_SecPkgInfoW,
+ &NEGOTIATE_SecPkgInfoW,
+ &CREDSSP_SecPkgInfoW,
+ &SCHANNEL_SecPkgInfoW
};
-SecurityFunctionTableA winpr_SecurityFunctionTableA;
-SecurityFunctionTableW winpr_SecurityFunctionTableW;
+static SecurityFunctionTableA winpr_SecurityFunctionTableA;
+static SecurityFunctionTableW winpr_SecurityFunctionTableW;
struct _SecurityFunctionTableA_NAME
{
- SEC_CHAR* Name;
+ const SEC_CHAR* Name;
const SecurityFunctionTableA* SecurityFunctionTable;
};
typedef struct _SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME;
struct _SecurityFunctionTableW_NAME
{
- SEC_WCHAR* Name;
+ const SEC_WCHAR* Name;
const SecurityFunctionTableW* SecurityFunctionTable;
};
typedef struct _SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME;
-const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] =
+static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] =
{
- { "NTLM", &NTLM_SecurityFunctionTableA },
- { "Kerberos", &KERBEROS_SecurityFunctionTableA },
- { "Negotiate", &NEGOTIATE_SecurityFunctionTableA },
- { "CREDSSP", &CREDSSP_SecurityFunctionTableA },
- { "Schannel", &SCHANNEL_SecurityFunctionTableA }
+ { "NTLM", &NTLM_SecurityFunctionTableA },
+ { "Kerberos", &KERBEROS_SecurityFunctionTableA },
+ { "Negotiate", &NEGOTIATE_SecurityFunctionTableA },
+ { "CREDSSP", &CREDSSP_SecurityFunctionTableA },
+ { "Schannel", &SCHANNEL_SecurityFunctionTableA }
};
-WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' };
-WCHAR KERBEROS_NAME_W[] = { 'K', 'e', 'r', 'b', 'e', 'r', 'o', 's', '\0' };
-WCHAR NEGOTIATE_NAME_W[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' };
-WCHAR CREDSSP_NAME_W[] = { 'C', 'r', 'e', 'd', 'S', 'S', 'P', '\0' };
-WCHAR SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' };
+static const WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' };
+static const WCHAR KERBEROS_NAME_W[] = { 'K', 'e', 'r', 'b', 'e', 'r', 'o', 's', '\0' };
+static const WCHAR NEGOTIATE_NAME_W[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' };
+static const WCHAR CREDSSP_NAME_W[] = { 'C', 'r', 'e', 'd', 'S', 'S', 'P', '\0' };
+static const WCHAR SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' };
-const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] =
+static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] =
{
- { NTLM_NAME_W, &NTLM_SecurityFunctionTableW },
- { KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW },
- { NEGOTIATE_NAME_W, &NEGOTIATE_SecurityFunctionTableW },
- { CREDSSP_NAME_W, &CREDSSP_SecurityFunctionTableW },
- { SCHANNEL_NAME_W, &SCHANNEL_SecurityFunctionTableW }
+ { NTLM_NAME_W, &NTLM_SecurityFunctionTableW },
+ { KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW },
+ { NEGOTIATE_NAME_W, &NEGOTIATE_SecurityFunctionTableW },
+ { CREDSSP_NAME_W, &CREDSSP_SecurityFunctionTableW },
+ { SCHANNEL_NAME_W, &SCHANNEL_SecurityFunctionTableW }
};
#define SecHandle_LOWER_MAX 0xFFFFFFFF
};
typedef struct _CONTEXT_BUFFER_ALLOC_TABLE CONTEXT_BUFFER_ALLOC_TABLE;
-CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable;
+static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
-int sspi_ContextBufferAllocTableNew()
+static int sspi_ContextBufferAllocTableNew(void)
{
size_t size;
ContextBufferAllocTable.entries = NULL;
return 1;
}
-int sspi_ContextBufferAllocTableGrow()
+static int sspi_ContextBufferAllocTableGrow(void)
{
size_t size;
CONTEXT_BUFFER_ALLOC_ENTRY* entries;
return 1;
}
-void sspi_ContextBufferAllocTableFree()
+static void sspi_ContextBufferAllocTableFree(void)
{
- ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
- free(ContextBufferAllocTable.entries);
+ if (ContextBufferAllocTable.cEntries == 0)
+ {
+ ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
+ free(ContextBufferAllocTable.entries);
+ ContextBufferAllocTable.entries = NULL;
+ }
}
-void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size)
+static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size)
{
- int index;
+ UINT32 index;
void* contextBuffer;
- for (index = 0; index < (int) ContextBufferAllocTable.cMaxEntries; index++)
+ for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
{
if (!ContextBufferAllocTable.entries[index].contextBuffer)
{
return sspi_ContextBufferAlloc(allocatorIndex, size);
}
-SSPI_CREDENTIALS* sspi_CredentialsNew()
+SSPI_CREDENTIALS* sspi_CredentialsNew(void)
{
SSPI_CREDENTIALS* credentials;
credentials = (SSPI_CREDENTIALS*) calloc(1, sizeof(SSPI_CREDENTIALS));
SecBuffer->cbBuffer = 0;
}
-SecHandle* sspi_SecureHandleAlloc()
+SecHandle* sspi_SecureHandleAlloc(void)
{
SecHandle* handle = (SecHandle*) calloc(1, sizeof(SecHandle));
return pSecBuffer;
}
-static BOOL sspi_initialized = FALSE;
-
-void sspi_GlobalInit()
+static BOOL CALLBACK sspi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context)
{
- if (!sspi_initialized)
- {
- winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
- sspi_ContextBufferAllocTableNew();
- sspi_initialized = TRUE;
- }
+ winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
+ sspi_ContextBufferAllocTableNew();
+ return TRUE;
}
-void sspi_GlobalFinish()
+void sspi_GlobalInit(void)
{
- if (sspi_initialized)
- {
- sspi_ContextBufferAllocTableFree();
- }
+ static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
+ DWORD flags = 0;
- sspi_initialized = FALSE;
+ InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
}
-SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
+void sspi_GlobalFinish(void)
+{
+ sspi_ContextBufferAllocTableFree();
+}
+
+static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
{
int index;
UINT32 cPackages;
return NULL;
}
-SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name)
+static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name)
{
return NULL;
}
-SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
+static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
{
int index;
UINT32 cPackages;
return NULL;
}
-SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
+static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
{
int status;
SEC_WCHAR* NameW = NULL;
return table;
}
-void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer);
-void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer);
+static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer);
+static void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer);
-void sspi_ContextBufferFree(void* contextBuffer)
+static void sspi_ContextBufferFree(void* contextBuffer)
{
- int index;
+ UINT32 index;
UINT32 allocatorIndex;
- for (index = 0; index < (int) ContextBufferAllocTable.cMaxEntries; index++)
+ for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
{
if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
{
switch (allocatorIndex)
{
- case EnumerateSecurityPackagesIndex:
- FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
- break;
+ case EnumerateSecurityPackagesIndex:
+ FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
+ break;
- case QuerySecurityPackageInfoIndex:
- FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
- break;
+ case QuerySecurityPackageInfoIndex:
+ FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
+ break;
}
}
}
/* Package Management */
-SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
+static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
PSecPkgInfoW* ppPackageInfo)
{
int index;
return SEC_E_OK;
}
-SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
+static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
PSecPkgInfoA* ppPackageInfo)
{
int index;
return SEC_E_OK;
}
-void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
+static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
{
int index;
UINT32 cPackages;
return &winpr_SecurityFunctionTableA;
}
-SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
+static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
PSecPkgInfoW* ppPackageInfo)
{
int index;
return SEC_E_SECPKG_NOT_FOUND;
}
-SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
+static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
PSecPkgInfoA* ppPackageInfo)
{
int index;
/* Credential Management */
-SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal,
+static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal,
SEC_WCHAR* pszPackage,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal,
+static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal,
SEC_CHAR* pszPackage,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags,
+static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags,
PSecBuffer pPackedContext, HANDLE* pToken)
{
SEC_CHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential)
+static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential)
{
char* Name;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
+static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext)
{
SEC_CHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
+static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
PSecBuffer pPackedContext, HANDLE pToken, PCtxtHandle phContext)
{
char* Name = NULL;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCredential,
+static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer)
{
SEC_WCHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCredential,
+static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer)
{
char* Name;
/* Context Management */
-SECURITY_STATUS SEC_ENTRY winpr_AcceptSecurityContext(PCredHandle phCredential,
+static SECURITY_STATUS SEC_ENTRY winpr_AcceptSecurityContext(PCredHandle phCredential,
PCtxtHandle phContext,
PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp)
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext, PSecBufferDesc pInput)
+static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext,
+ PSecBufferDesc pInput)
{
char* Name = NULL;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext, PSecBufferDesc pToken)
+static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext,
+ PSecBufferDesc pToken)
{
char* Name = NULL;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext)
+static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext)
{
char* Name = NULL;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer)
+static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer)
{
if (!pvContextBuffer)
return SEC_E_INVALID_HANDLE;
return SEC_E_OK;
}
-SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext)
+static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext)
{
SEC_CHAR* Name;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(PCredHandle phCredential,
+static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(PCredHandle phCredential,
PCtxtHandle phContext,
SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(PCredHandle phCredential,
+static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(PCredHandle phCredential,
PCtxtHandle phContext,
SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute,
+static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext,
+ ULONG ulAttribute,
void* pBuffer)
{
SEC_CHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute,
+static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext,
+ ULONG ulAttribute,
void* pBuffer)
{
SEC_CHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext, HANDLE* phToken)
+static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext,
+ HANDLE* phToken)
{
SEC_CHAR* Name;
SECURITY_STATUS status;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute,
+static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext,
+ ULONG ulAttribute,
void* pBuffer, ULONG cbBuffer)
{
SEC_CHAR* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute,
+static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext,
+ ULONG ulAttribute,
void* pBuffer, ULONG cbBuffer)
{
char* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext)
+static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext)
{
SEC_CHAR* Name;
SECURITY_STATUS status;
/* Message Support */
-SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage,
+static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext,
+ PSecBufferDesc pMessage,
ULONG MessageSeqNo, PULONG pfQOP)
{
char* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
+static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo)
{
char* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
+static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo)
{
char* Name;
return status;
}
-SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext, PSecBufferDesc pMessage,
+static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext,
+ PSecBufferDesc pMessage,
ULONG MessageSeqNo, PULONG pfQOP)
{
char* Name;
return status;
}
-SecurityFunctionTableA winpr_SecurityFunctionTableA =
-{
- 1, /* dwVersion */
- winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */
- winpr_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */
- winpr_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */
- winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
- NULL, /* Reserved2 */
- winpr_InitializeSecurityContextA, /* InitializeSecurityContext */
- winpr_AcceptSecurityContext, /* AcceptSecurityContext */
- winpr_CompleteAuthToken, /* CompleteAuthToken */
- winpr_DeleteSecurityContext, /* DeleteSecurityContext */
- winpr_ApplyControlToken, /* ApplyControlToken */
- winpr_QueryContextAttributesA, /* QueryContextAttributes */
- winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
- winpr_RevertSecurityContext, /* RevertSecurityContext */
- winpr_MakeSignature, /* MakeSignature */
- winpr_VerifySignature, /* VerifySignature */
- winpr_FreeContextBuffer, /* FreeContextBuffer */
- winpr_QuerySecurityPackageInfoA, /* QuerySecurityPackageInfo */
- NULL, /* Reserved3 */
- NULL, /* Reserved4 */
- winpr_ExportSecurityContext, /* ExportSecurityContext */
- winpr_ImportSecurityContextA, /* ImportSecurityContext */
- NULL, /* AddCredentials */
- NULL, /* Reserved8 */
- winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
- winpr_EncryptMessage, /* EncryptMessage */
- winpr_DecryptMessage, /* DecryptMessage */
- winpr_SetContextAttributesA, /* SetContextAttributes */
+static SecurityFunctionTableA winpr_SecurityFunctionTableA =
+{
+ 1, /* dwVersion */
+ winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */
+ winpr_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */
+ winpr_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */
+ winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
+ NULL, /* Reserved2 */
+ winpr_InitializeSecurityContextA, /* InitializeSecurityContext */
+ winpr_AcceptSecurityContext, /* AcceptSecurityContext */
+ winpr_CompleteAuthToken, /* CompleteAuthToken */
+ winpr_DeleteSecurityContext, /* DeleteSecurityContext */
+ winpr_ApplyControlToken, /* ApplyControlToken */
+ winpr_QueryContextAttributesA, /* QueryContextAttributes */
+ winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
+ winpr_RevertSecurityContext, /* RevertSecurityContext */
+ winpr_MakeSignature, /* MakeSignature */
+ winpr_VerifySignature, /* VerifySignature */
+ winpr_FreeContextBuffer, /* FreeContextBuffer */
+ winpr_QuerySecurityPackageInfoA, /* QuerySecurityPackageInfo */
+ NULL, /* Reserved3 */
+ NULL, /* Reserved4 */
+ winpr_ExportSecurityContext, /* ExportSecurityContext */
+ winpr_ImportSecurityContextA, /* ImportSecurityContext */
+ NULL, /* AddCredentials */
+ NULL, /* Reserved8 */
+ winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
+ winpr_EncryptMessage, /* EncryptMessage */
+ winpr_DecryptMessage, /* DecryptMessage */
+ winpr_SetContextAttributesA, /* SetContextAttributes */
};
-SecurityFunctionTableW winpr_SecurityFunctionTableW =
-{
- 1, /* dwVersion */
- winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */
- winpr_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */
- winpr_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */
- winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
- NULL, /* Reserved2 */
- winpr_InitializeSecurityContextW, /* InitializeSecurityContext */
- winpr_AcceptSecurityContext, /* AcceptSecurityContext */
- winpr_CompleteAuthToken, /* CompleteAuthToken */
- winpr_DeleteSecurityContext, /* DeleteSecurityContext */
- winpr_ApplyControlToken, /* ApplyControlToken */
- winpr_QueryContextAttributesW, /* QueryContextAttributes */
- winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
- winpr_RevertSecurityContext, /* RevertSecurityContext */
- winpr_MakeSignature, /* MakeSignature */
- winpr_VerifySignature, /* VerifySignature */
- winpr_FreeContextBuffer, /* FreeContextBuffer */
- winpr_QuerySecurityPackageInfoW, /* QuerySecurityPackageInfo */
- NULL, /* Reserved3 */
- NULL, /* Reserved4 */
- winpr_ExportSecurityContext, /* ExportSecurityContext */
- winpr_ImportSecurityContextW, /* ImportSecurityContext */
- NULL, /* AddCredentials */
- NULL, /* Reserved8 */
- winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
- winpr_EncryptMessage, /* EncryptMessage */
- winpr_DecryptMessage, /* DecryptMessage */
- winpr_SetContextAttributesW, /* SetContextAttributes */
+static SecurityFunctionTableW winpr_SecurityFunctionTableW =
+{
+ 1, /* dwVersion */
+ winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */
+ winpr_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */
+ winpr_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */
+ winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
+ NULL, /* Reserved2 */
+ winpr_InitializeSecurityContextW, /* InitializeSecurityContext */
+ winpr_AcceptSecurityContext, /* AcceptSecurityContext */
+ winpr_CompleteAuthToken, /* CompleteAuthToken */
+ winpr_DeleteSecurityContext, /* DeleteSecurityContext */
+ winpr_ApplyControlToken, /* ApplyControlToken */
+ winpr_QueryContextAttributesW, /* QueryContextAttributes */
+ winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
+ winpr_RevertSecurityContext, /* RevertSecurityContext */
+ winpr_MakeSignature, /* MakeSignature */
+ winpr_VerifySignature, /* VerifySignature */
+ winpr_FreeContextBuffer, /* FreeContextBuffer */
+ winpr_QuerySecurityPackageInfoW, /* QuerySecurityPackageInfo */
+ NULL, /* Reserved3 */
+ NULL, /* Reserved4 */
+ winpr_ExportSecurityContext, /* ExportSecurityContext */
+ winpr_ImportSecurityContextW, /* ImportSecurityContext */
+ NULL, /* AddCredentials */
+ NULL, /* Reserved8 */
+ winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
+ winpr_EncryptMessage, /* EncryptMessage */
+ winpr_DecryptMessage, /* DecryptMessage */
+ winpr_SetContextAttributesW, /* SetContextAttributes */
};
int TestAcquireCredentialsHandle(int argc, char* argv[])
{
+ int rc = -1;
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
identity.Password = (UINT16*) _strdup(test_Password);
if (!identity.User || !identity.Domain || !identity.Password)
- {
- free(identity.User);
- free(identity.Domain);
- free(identity.Password);
- fprintf(stderr, "Memory allocation failed\n");
- return -1;
- }
+ goto fail;
identity.UserLength = strlen(test_User);
identity.DomainLength = strlen(test_Domain);
SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, &credentials, &expiration);
if (status != SEC_E_OK)
- {
- sspi_GlobalFinish();
- return -1;
- }
+ goto fail;
status = table->QueryCredentialsAttributes(&credentials, SECPKG_CRED_ATTR_NAMES, &credential_names);
if (status != SEC_E_OK)
- {
- sspi_GlobalFinish();
- return -1;
- }
+ goto fail;
+ rc = 0;
+fail:
+
+ if (SecIsValidHandle(&credentials))
+ table->FreeCredentialsHandle(&credentials);
+
+ free(identity.User);
+ free(identity.Domain);
+ free(identity.Password);
sspi_GlobalFinish();
- return 0;
+ return rc;
}
int TestInitializeSecurityContext(int argc, char* argv[])
{
+ int rc = -1;
UINT32 cbMaxLen;
UINT32 fContextReq;
- void* output_buffer;
+ void* output_buffer = NULL;
CtxtHandle context;
ULONG pfContextAttr;
SECURITY_STATUS status;
CredHandle credentials;
TimeStamp expiration;
PSecPkgInfo pPackageInfo;
- SEC_WINNT_AUTH_IDENTITY identity;
+ SEC_WINNT_AUTH_IDENTITY identity = { 0 };
SecurityFunctionTable* table;
PSecBuffer p_SecBuffer;
SecBuffer output_SecBuffer;
if (status != SEC_E_OK)
{
printf("QuerySecurityPackageInfo status: 0x%08"PRIX32"\n", status);
- return -1;
+ goto fail;
}
cbMaxLen = pPackageInfo->cbMaxToken;
identity.Password = (UINT16*) _strdup(test_Password);
if (!identity.User || !identity.Domain || !identity.Password)
- {
- free(identity.User);
- free(identity.Domain);
- free(identity.Password);
- fprintf(stderr, "Memory allocation failed\n");
- return -1;
- }
+ goto fail;
identity.UserLength = strlen(test_User);
identity.DomainLength = strlen(test_Domain);
if (status != SEC_E_OK)
{
printf("AcquireCredentialsHandle status: 0x%08"PRIX32"\n", status);
- sspi_GlobalFinish();
- return -1;
+ goto fail;
}
fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_CONFIDENTIALITY |
if (!output_buffer)
{
printf("Memory allocation failed\n");
- sspi_GlobalFinish();
- return -1;
+ goto fail;
}
output_SecBuffer_desc.ulVersion = 0;
if (status != SEC_I_CONTINUE_NEEDED)
{
printf("InitializeSecurityContext status: 0x%08"PRIX32"\n", status);
- sspi_GlobalFinish();
- return -1;
+ goto fail;
}
printf("cBuffers: %"PRIu32" ulVersion: %"PRIu32"\n", output_SecBuffer_desc.cBuffers,
p_SecBuffer = &output_SecBuffer_desc.pBuffers[0];
printf("BufferType: 0x%08"PRIX32" cbBuffer: %"PRIu32"\n", p_SecBuffer->BufferType,
p_SecBuffer->cbBuffer);
- table->FreeCredentialsHandle(&credentials);
+ status = table->DeleteSecurityContext(&context);
+
+ if (status != SEC_E_OK)
+ {
+ printf("DeleteSecurityContext status: 0x%08"PRIX32"\n", status);
+ goto fail;
+ }
+
+ rc = 0;
+fail:
+ free(identity.User);
+ free(identity.Domain);
+ free(identity.Password);
+ free(output_buffer);
+
+ if (SecIsValidHandle(&credentials))
+ table->FreeCredentialsHandle(&credentials);
+
FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
- return 0;
+ return rc;
}
int TestQuerySecurityPackageInfo(int argc, char* argv[])
{
+ int rc;
SECURITY_STATUS status;
SecPkgInfo* pPackageInfo;
sspi_GlobalInit();
status = QuerySecurityPackageInfo(NTLM_SSP_NAME, &pPackageInfo);
if (status != SEC_E_OK)
+ rc = -1;
+ else
{
- sspi_GlobalFinish();
- return -1;
+ _tprintf(_T("\nQuerySecurityPackageInfo:\n"));
+ _tprintf(_T("\"%s\", \"%s\"\n"), pPackageInfo->Name, pPackageInfo->Comment);
+ rc = 0;
}
- _tprintf(_T("\nQuerySecurityPackageInfo:\n"));
- _tprintf(_T("\"%s\", \"%s\"\n"), pPackageInfo->Name, pPackageInfo->Comment);
+ FreeContextBuffer(pPackageInfo);
sspi_GlobalFinish();
- return 0;
+ return rc;
}
if (!TimerIsHandled(handle))
return FALSE;
-#ifdef __linux__
+ if (!timer->lpArgToCompletionRoutine)
+ {
+#ifdef HAVE_TIMERFD_H
- if (timer->fd != -1)
- close(timer->fd);
+ if (timer->fd != -1)
+ close(timer->fd);
#endif
+ }
+ else
+ {
+#ifdef WITH_POSIX_TIMER
+ timer_delete(timer->tid);
+#endif
+ }
+
free(timer);
return TRUE;
}
UINT32 HashTable_PointerHash(void* pointer)
{
- return ((UINT32) (UINT_PTR) pointer) >> 4;
+ return ((UINT32)(UINT_PTR) pointer) >> 4;
}
BOOL HashTable_StringCompare(void* string1, void* string2)
}
void HashTable_SetIdealRatio(wHashTable* table, float idealRatio,
- float lowerRehashThreshold, float upperRehashThreshold)
+ float lowerRehashThreshold, float upperRehashThreshold)
{
table->idealRatio = idealRatio;
table->lowerRehashThreshold = lowerRehashThreshold;
{
UINT32 hashValue;
wKeyValuePair* pair;
-
hashValue = table->hash(key) % table->numOfBuckets;
-
pair = table->bucketArray[hashValue];
while (pair && !table->keyCompare(key, pair->key))
{
if (table->keyFree)
table->keyFree(pair->key);
+
pair->key = key;
}
{
if (table->valueFree)
table->valueFree(pair->value);
+
pair->value = value;
}
}
EnterCriticalSection(&table->lock);
hashValue = table->hash(key) % table->numOfBuckets;
-
pair = table->bucketArray[hashValue];
while (pair && !table->keyCompare(key, pair->key))
table->bucketArray[hashValue] = pair->next;
free(pair);
-
table->numOfElements--;
if (table->lowerRehashThreshold > 0.0)
if (!pair)
status = FALSE;
else
+ {
+ if (table->valueClone && table->valueFree)
+ table->valueFree(pair->value);
+
pair->value = value;
+ }
if (table->synchronized)
LeaveCriticalSection(&table->lock);
table->valueFree(pair->value);
free(pair);
-
pair = nextPair;
}
while (pair)
{
nextPair = pair->next;
-
pKeys[iKey++] = (ULONG_PTR) pair->key;
-
pair = nextPair;
}
}
LeaveCriticalSection(&table->lock);
*ppKeys = pKeys;
-
return count;
}
wHashTable* HashTable_New(BOOL synchronized)
{
wHashTable* table;
-
table = (wHashTable*) calloc(1, sizeof(wHashTable));
if (table)
{
table->synchronized = synchronized;
-
InitializeCriticalSectionAndSpinCount(&(table->lock), 4000);
-
table->numOfBuckets = 64;
table->numOfElements = 0;
-
table->bucketArray = (wKeyValuePair**) calloc(table->numOfBuckets, sizeof(wKeyValuePair*));
if (!table->bucketArray)
table->idealRatio = 3.0;
table->lowerRehashThreshold = 0.0;
table->upperRehashThreshold = 15.0;
-
table->hash = HashTable_PointerHash;
table->keyCompare = HashTable_PointerCompare;
table->valueCompare = HashTable_PointerCompare;
table->valueFree(pair->value);
free(pair);
-
pair = nextPair;
}
}
DeleteCriticalSection(&(table->lock));
-
free(table->bucketArray);
free(table);
}
{
int rc = -1;
size_t used, x;
- char **msg;
- void *stack = winpr_backtrace(20);
+ char** msg;
+ void* stack = winpr_backtrace(20);
+
if (!stack)
{
fprintf(stderr, "winpr_backtrace failed!\n");
}
msg = winpr_backtrace_symbols(stack, &used);
+
if (msg)
{
- for (x=0; x<used; x++)
+ for (x = 0; x < used; x++)
printf("%"PRIuz": %s\n", x, msg[x]);
+
rc = 0;
}
+
winpr_backtrace_symbols_fd(stack, fileno(stdout));
-
winpr_backtrace_free(stack);
-
+ free(msg);
return rc;
}
static char* val2 = "val2";
static char* val3 = "val3";
-int test_hash_table_pointer()
+static int test_hash_table_pointer(void)
{
+ int rc = -1;
int count;
char* value;
wHashTable* table;
-
table = HashTable_New(TRUE);
+
if (!table)
return -1;
HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3);
-
count = HashTable_Count(table);
if (count != 3)
{
printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key2);
-
count = HashTable_Count(table);
if (count != 2)
{
printf("HashTable_Count: Expected : 2, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key3);
-
count = HashTable_Count(table);
if (count != 1)
{
printf("HashTable_Count: Expected : 1, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key1);
-
count = HashTable_Count(table);
if (count != 0)
{
printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3);
-
count = HashTable_Count(table);
if (count != 3)
{
printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key1);
if (strcmp(value, val1) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, val2) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key3);
if (strcmp(value, val3) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value);
- return -1;
+ goto fail;
}
HashTable_SetItemValue(table, key2, "apple");
-
value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, "apple") != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
- return -1;
+ goto fail;
}
if (!HashTable_Contains(table, key2))
{
printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n");
- return -1;
+ goto fail;
}
if (!HashTable_Remove(table, key2))
{
printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n");
- return -1;
+ goto fail;
}
if (HashTable_Remove(table, key2))
{
printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n");
- return -1;
+ goto fail;
}
HashTable_Clear(table);
-
count = HashTable_Count(table);
if (count != 0)
{
printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
- return -1;
+ goto fail;
}
+ rc = 1;
+fail:
HashTable_Free(table);
-
- return 1;
+ return rc;
}
-int test_hash_table_string()
+static int test_hash_table_string(void)
{
+ int rc = -1;
int count;
char* value;
wHashTable* table;
-
table = HashTable_New(TRUE);
+
if (!table)
return -1;
table->valueClone = HashTable_StringClone;
table->keyFree = HashTable_StringFree;
table->valueFree = HashTable_StringFree;
-
HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3);
-
count = HashTable_Count(table);
if (count != 3)
{
printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key2);
-
count = HashTable_Count(table);
if (count != 2)
{
printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key3);
-
count = HashTable_Count(table);
if (count != 1)
{
printf("HashTable_Count: Expected : 1, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Remove(table, key1);
-
count = HashTable_Count(table);
if (count != 0)
{
printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
- return -1;
+ goto fail;
}
HashTable_Add(table, key1, val1);
HashTable_Add(table, key2, val2);
HashTable_Add(table, key3, val3);
-
count = HashTable_Count(table);
if (count != 3)
{
printf("HashTable_Count: Expected : 3, Actual: %d\n", count);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key1);
if (strcmp(value, val1) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val1, value);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, val2) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val2, value);
- return -1;
+ goto fail;
}
value = (char*) HashTable_GetItemValue(table, key3);
if (strcmp(value, val3) != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", val3, value);
- return -1;
+ goto fail;
}
HashTable_SetItemValue(table, key2, "apple");
-
value = (char*) HashTable_GetItemValue(table, key2);
if (strcmp(value, "apple") != 0)
{
printf("HashTable_GetItemValue: Expected : %s, Actual: %s\n", "apple", value);
- return -1;
+ goto fail;
}
if (!HashTable_Contains(table, key2))
{
printf("HashTable_Contains: Expected : TRUE, Actual: FALSE\n");
- return -1;
+ goto fail;
}
if (!HashTable_Remove(table, key2))
{
printf("HashTable_Remove: Expected : TRUE, Actual: FALSE\n");
- return -1;
+ goto fail;
}
if (HashTable_Remove(table, key2))
{
printf("HashTable_Remove: Expected : FALSE, Actual: TRUE\n");
- return -1;
+ goto fail;
}
HashTable_Clear(table);
-
count = HashTable_Count(table);
if (count != 0)
{
printf("HashTable_Count: Expected : 0, Actual: %d\n", count);
- return -1;
+ goto fail;
}
+ rc = 1;
+fail:
HashTable_Free(table);
-
- return 1;
+ return rc;
}
int TestHashTable(int argc, char* argv[])
#define PATH_MAX 4096
#endif
-static void *read_image(const char *src, size_t *size)
+static void* read_image(const char* src, size_t* size)
{
int success = 0;
- void *a = NULL;
+ void* a = NULL;
INT64 src_size;
- FILE *fsrc = fopen(src, "rb");
+ FILE* fsrc = fopen(src, "rb");
if (!fsrc)
{
success = 1;
*size = src_size;
-
cleanup:
+
if (a && !success)
{
free(a);
a = NULL;
}
+
if (fsrc)
fclose(fsrc);
return a;
}
-static int img_compare(wImage *image, wImage *image2, BOOL ignoreType)
+static int img_compare(wImage* image, wImage* image2, BOOL ignoreType)
{
int rc = -1;
+
if ((image->type != image2->type) && !ignoreType)
{
fprintf(stderr, "Image type mismatch %d:%d\n", image->type, image2->type);
if (image->bytesPerPixel != image2->bytesPerPixel)
{
- fprintf(stderr, "Image bytesPerPixel mismatch %d:%d\n", image->bytesPerPixel, image2->bytesPerPixel);
+ fprintf(stderr, "Image bytesPerPixel mismatch %d:%d\n", image->bytesPerPixel,
+ image2->bytesPerPixel);
goto cleanup;
}
return rc;
}
-static wImage *get_image(const char *src)
+static wImage* get_image(const char* src)
{
int status;
wImage* image = NULL;
-
image = winpr_image_new();
if (!image)
}
cleanup:
-
return image;
}
-static int create_test(const char *src, const char *dst_png, const char *dst_bmp)
+static int create_test(const char* src, const char* dst_png, const char* dst_bmp)
{
int rc = -1;
int ret = -1;
int status;
size_t bsize;
- void *buffer = NULL;
+ void* buffer = NULL;
wImage* image = NULL, *image2 = NULL, *image3 = NULL, *image4 = NULL;
if (!PathFileExistsA(src))
/* Read image from buffer, compare. */
buffer = read_image(src, &bsize);
+
if (!buffer)
{
fprintf(stderr, "Failed to read image %s!\n", src);
}
rc = img_compare(image, image2, TRUE);
+
if (rc)
goto cleanup;
image3 = get_image(dst_png);
+
if (!image3)
goto cleanup;
rc = img_compare(image, image3, TRUE);
+
if (rc)
goto cleanup;
image4 = get_image(dst_bmp);
+
if (!image4)
goto cleanup;
rc = img_compare(image, image4, TRUE);
+
if (rc)
goto cleanup;
ret = 0;
cleanup:
+
if (image)
winpr_image_free(image, TRUE);
+
if (image2)
winpr_image_free(image2, TRUE);
+
if (image3)
winpr_image_free(image3, TRUE);
+
if (image4)
winpr_image_free(image4, TRUE);
free(buffer);
-
return ret;
}
-int test_image_png_to_bmp()
+static int test_image_png_to_bmp(void)
{
- char *buffer = TEST_SOURCE_PATH;
+ char* buffer = TEST_SOURCE_PATH;
char src_png[PATH_MAX];
char src_bmp[PATH_MAX];
char dst_png[PATH_MAX];
char dst_bmp[PATH_MAX];
char dst_png2[PATH_MAX];
char dst_bmp2[PATH_MAX];
- char *tmp = GetKnownPath(KNOWN_PATH_TEMP);
+ char* tmp = GetKnownPath(KNOWN_PATH_TEMP);
if (!tmp)
return -1;
if (!buffer)
+ {
+ free(tmp);
return -1;
+ }
sprintf_s(src_png, sizeof(src_png), "%s/lodepng_32bit.png", buffer);
sprintf_s(src_bmp, sizeof(src_bmp), "%s/lodepng_32bit.bmp", buffer);
sprintf_s(dst_bmp, sizeof(dst_bmp), "%s/lodepng_32bit.bmp", tmp);
sprintf_s(dst_png2, sizeof(dst_png2), "%s/lodepng_32bit-2.png", tmp);
sprintf_s(dst_bmp2, sizeof(dst_bmp2), "%s/lodepng_32bit-2.bmp", tmp);
+ free(tmp);
if (create_test(src_png, dst_png, dst_bmp))
return -1;
int TestImage(int argc, char* argv[])
{
int rc = test_image_png_to_bmp();
-
return rc;
}