Add files using upload-large-folder tool
Browse files- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/brush.c +322 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/palette.c +142 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/palette.h +65 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/CMakeLists.txt +27 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/addin.c +398 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/settings_str.c +485 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/README.txt +101 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/prim_YCoCg.h +31 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/prim_andor.c +63 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/CMakeLists.txt +59 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/cliprdr_utils.c +258 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/http.c +402 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/profiler.c +98 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/rdpdr_utils.c +597 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/ringbuffer.c +308 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/signal.c +269 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_call.c +2042 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_operations.c +1048 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_pack.c +0 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/string.c +128 -0
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/brush.c
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stdio.h>
|
| 23 |
+
#include <winpr/crt.h>
|
| 24 |
+
#include <winpr/assert.h>
|
| 25 |
+
|
| 26 |
+
#include <freerdp/log.h>
|
| 27 |
+
#include <freerdp/update.h>
|
| 28 |
+
#include <freerdp/freerdp.h>
|
| 29 |
+
#include <winpr/stream.h>
|
| 30 |
+
|
| 31 |
+
#include "brush.h"
|
| 32 |
+
#include "cache.h"
|
| 33 |
+
|
| 34 |
+
#define TAG FREERDP_TAG("cache.brush")
|
| 35 |
+
|
| 36 |
+
typedef struct
|
| 37 |
+
{
|
| 38 |
+
UINT32 bpp;
|
| 39 |
+
void* entry;
|
| 40 |
+
} BRUSH_ENTRY;
|
| 41 |
+
|
| 42 |
+
struct rdp_brush_cache
|
| 43 |
+
{
|
| 44 |
+
pPatBlt PatBlt; /* 0 */
|
| 45 |
+
pCacheBrush CacheBrush; /* 1 */
|
| 46 |
+
pPolygonSC PolygonSC; /* 2 */
|
| 47 |
+
pPolygonCB PolygonCB; /* 3 */
|
| 48 |
+
UINT32 paddingA[16 - 4]; /* 4 */
|
| 49 |
+
|
| 50 |
+
UINT32 maxEntries; /* 16 */
|
| 51 |
+
UINT32 maxMonoEntries; /* 17 */
|
| 52 |
+
BRUSH_ENTRY* entries; /* 18 */
|
| 53 |
+
BRUSH_ENTRY* monoEntries; /* 19 */
|
| 54 |
+
UINT32 paddingB[32 - 20]; /* 20 */
|
| 55 |
+
|
| 56 |
+
rdpContext* context;
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
static BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
|
| 60 |
+
{
|
| 61 |
+
BOOL ret = TRUE;
|
| 62 |
+
|
| 63 |
+
WINPR_ASSERT(context);
|
| 64 |
+
WINPR_ASSERT(patblt);
|
| 65 |
+
|
| 66 |
+
const rdpCache* cache = context->cache;
|
| 67 |
+
WINPR_ASSERT(cache);
|
| 68 |
+
|
| 69 |
+
rdpBrush* brush = &patblt->brush;
|
| 70 |
+
WINPR_ASSERT(brush->style <= UINT8_MAX);
|
| 71 |
+
const BYTE style = (BYTE)brush->style;
|
| 72 |
+
|
| 73 |
+
if (brush->style & CACHED_BRUSH)
|
| 74 |
+
{
|
| 75 |
+
brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
|
| 76 |
+
brush->style = 0x03;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
WINPR_ASSERT(cache->brush);
|
| 80 |
+
IFCALLRET(cache->brush->PatBlt, ret, context, patblt);
|
| 81 |
+
brush->style = style;
|
| 82 |
+
return ret;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
static BOOL update_gdi_polygon_sc(rdpContext* context, const POLYGON_SC_ORDER* polygon_sc)
|
| 86 |
+
{
|
| 87 |
+
rdpCache* cache = NULL;
|
| 88 |
+
WINPR_ASSERT(context);
|
| 89 |
+
cache = context->cache;
|
| 90 |
+
WINPR_ASSERT(cache);
|
| 91 |
+
WINPR_ASSERT(cache->brush);
|
| 92 |
+
return IFCALLRESULT(TRUE, cache->brush->PolygonSC, context, polygon_sc);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
static BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
|
| 96 |
+
{
|
| 97 |
+
BOOL ret = TRUE;
|
| 98 |
+
|
| 99 |
+
WINPR_ASSERT(context);
|
| 100 |
+
WINPR_ASSERT(polygon_cb);
|
| 101 |
+
|
| 102 |
+
rdpCache* cache = context->cache;
|
| 103 |
+
WINPR_ASSERT(cache);
|
| 104 |
+
|
| 105 |
+
rdpBrush* brush = &polygon_cb->brush;
|
| 106 |
+
WINPR_ASSERT(brush->style <= UINT8_MAX);
|
| 107 |
+
const BYTE style = (UINT8)brush->style;
|
| 108 |
+
|
| 109 |
+
if (brush->style & CACHED_BRUSH)
|
| 110 |
+
{
|
| 111 |
+
brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
|
| 112 |
+
brush->style = 0x03;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
WINPR_ASSERT(cache->brush);
|
| 116 |
+
IFCALLRET(cache->brush->PolygonCB, ret, context, polygon_cb);
|
| 117 |
+
brush->style = style;
|
| 118 |
+
return ret;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
static BOOL update_gdi_cache_brush(rdpContext* context, const CACHE_BRUSH_ORDER* cacheBrush)
|
| 122 |
+
{
|
| 123 |
+
UINT32 length = 0;
|
| 124 |
+
void* data = NULL;
|
| 125 |
+
rdpCache* cache = NULL;
|
| 126 |
+
|
| 127 |
+
WINPR_ASSERT(context);
|
| 128 |
+
WINPR_ASSERT(cacheBrush);
|
| 129 |
+
|
| 130 |
+
cache = context->cache;
|
| 131 |
+
WINPR_ASSERT(cache);
|
| 132 |
+
|
| 133 |
+
length = cacheBrush->bpp * 64 / 8;
|
| 134 |
+
data = malloc(length);
|
| 135 |
+
|
| 136 |
+
if (!data)
|
| 137 |
+
return FALSE;
|
| 138 |
+
|
| 139 |
+
CopyMemory(data, cacheBrush->data, length);
|
| 140 |
+
brush_cache_put(cache->brush, cacheBrush->index, data, cacheBrush->bpp);
|
| 141 |
+
return TRUE;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void* brush_cache_get(rdpBrushCache* brushCache, UINT32 index, UINT32* bpp)
|
| 145 |
+
{
|
| 146 |
+
void* entry = NULL;
|
| 147 |
+
|
| 148 |
+
if (!brushCache)
|
| 149 |
+
return NULL;
|
| 150 |
+
|
| 151 |
+
if (!bpp)
|
| 152 |
+
return NULL;
|
| 153 |
+
|
| 154 |
+
if (*bpp == 1)
|
| 155 |
+
{
|
| 156 |
+
if (index >= brushCache->maxMonoEntries)
|
| 157 |
+
{
|
| 158 |
+
WLog_ERR(TAG, "invalid brush (%" PRIu32 " bpp) index: 0x%08" PRIX32 "", *bpp, index);
|
| 159 |
+
return NULL;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
*bpp = brushCache->monoEntries[index].bpp;
|
| 163 |
+
entry = brushCache->monoEntries[index].entry;
|
| 164 |
+
}
|
| 165 |
+
else
|
| 166 |
+
{
|
| 167 |
+
if (index >= brushCache->maxEntries)
|
| 168 |
+
{
|
| 169 |
+
WLog_ERR(TAG, "invalid brush (%" PRIu32 " bpp) index: 0x%08" PRIX32 "", *bpp, index);
|
| 170 |
+
return NULL;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
*bpp = brushCache->entries[index].bpp;
|
| 174 |
+
entry = brushCache->entries[index].entry;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
if (entry == NULL)
|
| 178 |
+
{
|
| 179 |
+
WLog_ERR(TAG, "invalid brush (%" PRIu32 " bpp) at index: 0x%08" PRIX32 "", *bpp, index);
|
| 180 |
+
return NULL;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return entry;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
void brush_cache_put(rdpBrushCache* brushCache, UINT32 index, void* entry, UINT32 bpp)
|
| 187 |
+
{
|
| 188 |
+
WINPR_ASSERT(brushCache);
|
| 189 |
+
|
| 190 |
+
if (bpp == 1)
|
| 191 |
+
{
|
| 192 |
+
if (index >= brushCache->maxMonoEntries)
|
| 193 |
+
{
|
| 194 |
+
WLog_ERR(TAG, "invalid brush (%" PRIu32 " bpp) index: 0x%08" PRIX32 "", bpp, index);
|
| 195 |
+
free(entry);
|
| 196 |
+
return;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
WINPR_ASSERT(brushCache->monoEntries);
|
| 200 |
+
free(brushCache->monoEntries[index].entry);
|
| 201 |
+
brushCache->monoEntries[index].bpp = bpp;
|
| 202 |
+
brushCache->monoEntries[index].entry = entry;
|
| 203 |
+
}
|
| 204 |
+
else
|
| 205 |
+
{
|
| 206 |
+
if (index >= brushCache->maxEntries)
|
| 207 |
+
{
|
| 208 |
+
WLog_ERR(TAG, "invalid brush (%" PRIu32 " bpp) index: 0x%08" PRIX32 "", bpp, index);
|
| 209 |
+
free(entry);
|
| 210 |
+
return;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
WINPR_ASSERT(brushCache->entries);
|
| 214 |
+
free(brushCache->entries[index].entry);
|
| 215 |
+
brushCache->entries[index].bpp = bpp;
|
| 216 |
+
brushCache->entries[index].entry = entry;
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
void brush_cache_register_callbacks(rdpUpdate* update)
|
| 221 |
+
{
|
| 222 |
+
WINPR_ASSERT(update);
|
| 223 |
+
WINPR_ASSERT(update->context);
|
| 224 |
+
WINPR_ASSERT(update->primary);
|
| 225 |
+
WINPR_ASSERT(update->secondary);
|
| 226 |
+
|
| 227 |
+
if (!freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding))
|
| 228 |
+
{
|
| 229 |
+
rdpCache* cache = update->context->cache;
|
| 230 |
+
WINPR_ASSERT(cache);
|
| 231 |
+
WINPR_ASSERT(cache->brush);
|
| 232 |
+
|
| 233 |
+
cache->brush->PatBlt = update->primary->PatBlt;
|
| 234 |
+
cache->brush->PolygonSC = update->primary->PolygonSC;
|
| 235 |
+
cache->brush->PolygonCB = update->primary->PolygonCB;
|
| 236 |
+
update->primary->PatBlt = update_gdi_patblt;
|
| 237 |
+
update->primary->PolygonSC = update_gdi_polygon_sc;
|
| 238 |
+
update->primary->PolygonCB = update_gdi_polygon_cb;
|
| 239 |
+
update->secondary->CacheBrush = update_gdi_cache_brush;
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
rdpBrushCache* brush_cache_new(rdpContext* context)
|
| 244 |
+
{
|
| 245 |
+
rdpBrushCache* brushCache = NULL;
|
| 246 |
+
|
| 247 |
+
WINPR_ASSERT(context);
|
| 248 |
+
|
| 249 |
+
brushCache = (rdpBrushCache*)calloc(1, sizeof(rdpBrushCache));
|
| 250 |
+
|
| 251 |
+
if (!brushCache)
|
| 252 |
+
return NULL;
|
| 253 |
+
|
| 254 |
+
brushCache->context = context;
|
| 255 |
+
brushCache->maxEntries = 64;
|
| 256 |
+
brushCache->maxMonoEntries = 64;
|
| 257 |
+
brushCache->entries = (BRUSH_ENTRY*)calloc(brushCache->maxEntries, sizeof(BRUSH_ENTRY));
|
| 258 |
+
|
| 259 |
+
if (!brushCache->entries)
|
| 260 |
+
goto fail;
|
| 261 |
+
|
| 262 |
+
brushCache->monoEntries = (BRUSH_ENTRY*)calloc(brushCache->maxMonoEntries, sizeof(BRUSH_ENTRY));
|
| 263 |
+
|
| 264 |
+
if (!brushCache->monoEntries)
|
| 265 |
+
goto fail;
|
| 266 |
+
|
| 267 |
+
return brushCache;
|
| 268 |
+
fail:
|
| 269 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 270 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 271 |
+
brush_cache_free(brushCache);
|
| 272 |
+
WINPR_PRAGMA_DIAG_POP
|
| 273 |
+
return NULL;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
void brush_cache_free(rdpBrushCache* brushCache)
|
| 277 |
+
{
|
| 278 |
+
if (brushCache)
|
| 279 |
+
{
|
| 280 |
+
if (brushCache->entries)
|
| 281 |
+
{
|
| 282 |
+
for (size_t i = 0; i < brushCache->maxEntries; i++)
|
| 283 |
+
free(brushCache->entries[i].entry);
|
| 284 |
+
|
| 285 |
+
free(brushCache->entries);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
if (brushCache->monoEntries)
|
| 289 |
+
{
|
| 290 |
+
for (size_t i = 0; i < brushCache->maxMonoEntries; i++)
|
| 291 |
+
free(brushCache->monoEntries[i].entry);
|
| 292 |
+
|
| 293 |
+
free(brushCache->monoEntries);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
free(brushCache);
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
void free_cache_brush_order(rdpContext* context, CACHE_BRUSH_ORDER* order)
|
| 301 |
+
{
|
| 302 |
+
WINPR_UNUSED(context);
|
| 303 |
+
free(order);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
CACHE_BRUSH_ORDER* copy_cache_brush_order(rdpContext* context, const CACHE_BRUSH_ORDER* order)
|
| 307 |
+
{
|
| 308 |
+
CACHE_BRUSH_ORDER* dst = NULL;
|
| 309 |
+
|
| 310 |
+
WINPR_ASSERT(context);
|
| 311 |
+
|
| 312 |
+
dst = calloc(1, sizeof(CACHE_BRUSH_ORDER));
|
| 313 |
+
|
| 314 |
+
if (!dst || !order)
|
| 315 |
+
goto fail;
|
| 316 |
+
|
| 317 |
+
*dst = *order;
|
| 318 |
+
return dst;
|
| 319 |
+
fail:
|
| 320 |
+
free_cache_brush_order(context, dst);
|
| 321 |
+
return NULL;
|
| 322 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/palette.c
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Palette (Color Table) Cache
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stdio.h>
|
| 23 |
+
|
| 24 |
+
#include <winpr/crt.h>
|
| 25 |
+
|
| 26 |
+
#include <freerdp/log.h>
|
| 27 |
+
|
| 28 |
+
#include "palette.h"
|
| 29 |
+
#include "cache.h"
|
| 30 |
+
|
| 31 |
+
#define TAG FREERDP_TAG("cache.palette")
|
| 32 |
+
|
| 33 |
+
static void* palette_cache_get(rdpPaletteCache* palette, UINT32 index);
|
| 34 |
+
|
| 35 |
+
static void palette_cache_put(rdpPaletteCache* palette, UINT32 index, void* entry);
|
| 36 |
+
|
| 37 |
+
static BOOL update_gdi_cache_color_table(rdpContext* context,
|
| 38 |
+
const CACHE_COLOR_TABLE_ORDER* cacheColorTable)
|
| 39 |
+
{
|
| 40 |
+
UINT32* colorTable = NULL;
|
| 41 |
+
rdpCache* cache = context->cache;
|
| 42 |
+
colorTable = (UINT32*)malloc(sizeof(UINT32) * 256);
|
| 43 |
+
|
| 44 |
+
if (!colorTable)
|
| 45 |
+
return FALSE;
|
| 46 |
+
|
| 47 |
+
CopyMemory(colorTable, cacheColorTable->colorTable, sizeof(UINT32) * 256);
|
| 48 |
+
palette_cache_put(cache->palette, cacheColorTable->cacheIndex, (void*)colorTable);
|
| 49 |
+
return TRUE;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void* palette_cache_get(rdpPaletteCache* paletteCache, UINT32 index)
|
| 53 |
+
{
|
| 54 |
+
void* entry = NULL;
|
| 55 |
+
|
| 56 |
+
if (index >= paletteCache->maxEntries)
|
| 57 |
+
{
|
| 58 |
+
WLog_ERR(TAG, "invalid color table index: 0x%08" PRIX32 "", index);
|
| 59 |
+
return NULL;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
entry = paletteCache->entries[index].entry;
|
| 63 |
+
|
| 64 |
+
if (!entry)
|
| 65 |
+
{
|
| 66 |
+
WLog_ERR(TAG, "invalid color table at index: 0x%08" PRIX32 "", index);
|
| 67 |
+
return NULL;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
return entry;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void palette_cache_put(rdpPaletteCache* paletteCache, UINT32 index, void* entry)
|
| 74 |
+
{
|
| 75 |
+
if (index >= paletteCache->maxEntries)
|
| 76 |
+
{
|
| 77 |
+
WLog_ERR(TAG, "invalid color table index: 0x%08" PRIX32 "", index);
|
| 78 |
+
free(entry);
|
| 79 |
+
return;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
free(paletteCache->entries[index].entry);
|
| 83 |
+
paletteCache->entries[index].entry = entry;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void palette_cache_register_callbacks(rdpUpdate* update)
|
| 87 |
+
{
|
| 88 |
+
update->secondary->CacheColorTable = update_gdi_cache_color_table;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
rdpPaletteCache* palette_cache_new(rdpContext* context)
|
| 92 |
+
{
|
| 93 |
+
rdpPaletteCache* paletteCache = NULL;
|
| 94 |
+
|
| 95 |
+
WINPR_ASSERT(context);
|
| 96 |
+
|
| 97 |
+
paletteCache = (rdpPaletteCache*)calloc(1, sizeof(rdpPaletteCache));
|
| 98 |
+
|
| 99 |
+
if (paletteCache)
|
| 100 |
+
{
|
| 101 |
+
paletteCache->context = context;
|
| 102 |
+
paletteCache->maxEntries = 6;
|
| 103 |
+
paletteCache->entries =
|
| 104 |
+
(PALETTE_TABLE_ENTRY*)calloc(paletteCache->maxEntries, sizeof(PALETTE_TABLE_ENTRY));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
return paletteCache;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
void palette_cache_free(rdpPaletteCache* paletteCache)
|
| 111 |
+
{
|
| 112 |
+
if (paletteCache)
|
| 113 |
+
{
|
| 114 |
+
for (UINT32 i = 0; i < paletteCache->maxEntries; i++)
|
| 115 |
+
free(paletteCache->entries[i].entry);
|
| 116 |
+
|
| 117 |
+
free(paletteCache->entries);
|
| 118 |
+
free(paletteCache);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void free_palette_update(rdpContext* context, PALETTE_UPDATE* pointer)
|
| 123 |
+
{
|
| 124 |
+
free(pointer);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
PALETTE_UPDATE* copy_palette_update(rdpContext* context, const PALETTE_UPDATE* pointer)
|
| 128 |
+
{
|
| 129 |
+
PALETTE_UPDATE* dst = calloc(1, sizeof(PALETTE_UPDATE));
|
| 130 |
+
|
| 131 |
+
if (!dst || !pointer)
|
| 132 |
+
goto fail;
|
| 133 |
+
|
| 134 |
+
*dst = *pointer;
|
| 135 |
+
return dst;
|
| 136 |
+
fail:
|
| 137 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 138 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 139 |
+
free_palette_update(context, dst);
|
| 140 |
+
WINPR_PRAGMA_DIAG_POP
|
| 141 |
+
return NULL;
|
| 142 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/cache/palette.h
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
*
|
| 4 |
+
* Copyright 2018 Armin Novak <[email protected]>
|
| 5 |
+
* Copyright 2018 Thincast Technologies GmbH
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CACHE_PALETTE_H
|
| 21 |
+
#define FREERDP_LIB_CACHE_PALETTE_H
|
| 22 |
+
|
| 23 |
+
#include <freerdp/api.h>
|
| 24 |
+
#include <freerdp/update.h>
|
| 25 |
+
|
| 26 |
+
typedef struct rdp_palette_cache rdpPaletteCache;
|
| 27 |
+
|
| 28 |
+
typedef struct
|
| 29 |
+
{
|
| 30 |
+
void* entry;
|
| 31 |
+
} PALETTE_TABLE_ENTRY;
|
| 32 |
+
|
| 33 |
+
struct rdp_palette_cache
|
| 34 |
+
{
|
| 35 |
+
UINT32 maxEntries; /* 0 */
|
| 36 |
+
PALETTE_TABLE_ENTRY* entries; /* 1 */
|
| 37 |
+
|
| 38 |
+
/* internal */
|
| 39 |
+
|
| 40 |
+
rdpContext* context;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
#ifdef __cplusplus
|
| 44 |
+
extern "C"
|
| 45 |
+
{
|
| 46 |
+
#endif
|
| 47 |
+
|
| 48 |
+
FREERDP_LOCAL void palette_cache_register_callbacks(rdpUpdate* update);
|
| 49 |
+
|
| 50 |
+
FREERDP_LOCAL void palette_cache_free(rdpPaletteCache* palette_cache);
|
| 51 |
+
|
| 52 |
+
WINPR_ATTR_MALLOC(palette_cache_free, 1)
|
| 53 |
+
FREERDP_LOCAL rdpPaletteCache* palette_cache_new(rdpContext* context);
|
| 54 |
+
|
| 55 |
+
FREERDP_LOCAL void free_palette_update(rdpContext* context, PALETTE_UPDATE* pointer);
|
| 56 |
+
|
| 57 |
+
WINPR_ATTR_MALLOC(free_palette_update, 2)
|
| 58 |
+
FREERDP_LOCAL PALETTE_UPDATE* copy_palette_update(rdpContext* context,
|
| 59 |
+
const PALETTE_UPDATE* pointer);
|
| 60 |
+
|
| 61 |
+
#ifdef __cplusplus
|
| 62 |
+
}
|
| 63 |
+
#endif
|
| 64 |
+
|
| 65 |
+
#endif /* FREERDP_LIB_CACHE_PALETTE_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/CMakeLists.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# libfreerdp-common cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <[email protected]>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
set(MODULE_NAME "freerdp-common")
|
| 19 |
+
set(MODULE_PREFIX "FREERDP_COMMON")
|
| 20 |
+
|
| 21 |
+
set(${MODULE_PREFIX}_SRCS addin.c settings.c settings_getters.c settings_str.c settings_str.h assistance.c)
|
| 22 |
+
|
| 23 |
+
freerdp_module_add(${${MODULE_PREFIX}_SRCS})
|
| 24 |
+
|
| 25 |
+
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
|
| 26 |
+
add_subdirectory(test)
|
| 27 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/addin.c
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Addin Loader
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stdio.h>
|
| 23 |
+
#include <stdlib.h>
|
| 24 |
+
#include <string.h>
|
| 25 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
#include <winpr/path.h>
|
| 28 |
+
#include <winpr/string.h>
|
| 29 |
+
#include <winpr/library.h>
|
| 30 |
+
|
| 31 |
+
#include <freerdp/addin.h>
|
| 32 |
+
#include <freerdp/build-config.h>
|
| 33 |
+
|
| 34 |
+
#include <freerdp/log.h>
|
| 35 |
+
#define TAG FREERDP_TAG("addin")
|
| 36 |
+
|
| 37 |
+
static INLINE BOOL is_path_required(LPCSTR path, size_t len)
|
| 38 |
+
{
|
| 39 |
+
if (!path || (len <= 1))
|
| 40 |
+
return FALSE;
|
| 41 |
+
|
| 42 |
+
if (strcmp(path, ".") == 0)
|
| 43 |
+
return FALSE;
|
| 44 |
+
|
| 45 |
+
return TRUE;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
LPSTR freerdp_get_library_install_path(void)
|
| 49 |
+
{
|
| 50 |
+
LPSTR pszPath = NULL;
|
| 51 |
+
size_t cchPath = 0;
|
| 52 |
+
size_t cchLibraryPath = 0;
|
| 53 |
+
size_t cchInstallPrefix = 0;
|
| 54 |
+
BOOL needLibPath = 0;
|
| 55 |
+
BOOL needInstallPath = 0;
|
| 56 |
+
LPCSTR pszLibraryPath = FREERDP_LIBRARY_PATH;
|
| 57 |
+
LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX;
|
| 58 |
+
cchLibraryPath = strlen(pszLibraryPath) + 1;
|
| 59 |
+
cchInstallPrefix = strlen(pszInstallPrefix) + 1;
|
| 60 |
+
cchPath = cchInstallPrefix + cchLibraryPath;
|
| 61 |
+
needInstallPath = is_path_required(pszInstallPrefix, cchInstallPrefix);
|
| 62 |
+
needLibPath = is_path_required(pszLibraryPath, cchLibraryPath);
|
| 63 |
+
|
| 64 |
+
if (!needInstallPath && !needLibPath)
|
| 65 |
+
return NULL;
|
| 66 |
+
|
| 67 |
+
pszPath = (LPSTR)malloc(cchPath + 1);
|
| 68 |
+
|
| 69 |
+
if (!pszPath)
|
| 70 |
+
return NULL;
|
| 71 |
+
|
| 72 |
+
if (needInstallPath)
|
| 73 |
+
{
|
| 74 |
+
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
|
| 75 |
+
pszPath[cchInstallPrefix] = '\0';
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (needLibPath)
|
| 79 |
+
{
|
| 80 |
+
if (FAILED(NativePathCchAppendA(pszPath, cchPath + 1, pszLibraryPath)))
|
| 81 |
+
{
|
| 82 |
+
free(pszPath);
|
| 83 |
+
return NULL;
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
return pszPath;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
LPSTR freerdp_get_dynamic_addin_install_path(void)
|
| 91 |
+
{
|
| 92 |
+
#if defined(WITH_ADD_PLUGIN_TO_RPATH)
|
| 93 |
+
return NULL;
|
| 94 |
+
#else
|
| 95 |
+
LPSTR pszPath = NULL;
|
| 96 |
+
size_t cchPath = 0;
|
| 97 |
+
size_t cchAddinPath = 0;
|
| 98 |
+
size_t cchInstallPrefix = 0;
|
| 99 |
+
BOOL needLibPath = 0;
|
| 100 |
+
BOOL needInstallPath = 0;
|
| 101 |
+
LPCSTR pszAddinPath = FREERDP_ADDIN_PATH;
|
| 102 |
+
LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX;
|
| 103 |
+
cchAddinPath = strlen(pszAddinPath) + 1;
|
| 104 |
+
cchInstallPrefix = strlen(pszInstallPrefix) + 1;
|
| 105 |
+
cchPath = cchInstallPrefix + cchAddinPath;
|
| 106 |
+
needInstallPath = is_path_required(pszInstallPrefix, cchInstallPrefix);
|
| 107 |
+
needLibPath = is_path_required(pszAddinPath, cchAddinPath);
|
| 108 |
+
|
| 109 |
+
WLog_DBG(TAG,
|
| 110 |
+
"freerdp_get_dynamic_addin_install_path <- pszInstallPrefix: %s, pszAddinPath: %s",
|
| 111 |
+
pszInstallPrefix, pszAddinPath);
|
| 112 |
+
|
| 113 |
+
if (!needInstallPath && !needLibPath)
|
| 114 |
+
return NULL;
|
| 115 |
+
|
| 116 |
+
pszPath = (LPSTR)calloc(cchPath + 1, sizeof(CHAR));
|
| 117 |
+
|
| 118 |
+
if (!pszPath)
|
| 119 |
+
return NULL;
|
| 120 |
+
|
| 121 |
+
if (needInstallPath)
|
| 122 |
+
{
|
| 123 |
+
CopyMemory(pszPath, pszInstallPrefix, cchInstallPrefix);
|
| 124 |
+
pszPath[cchInstallPrefix] = '\0';
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
if (needLibPath)
|
| 128 |
+
{
|
| 129 |
+
if (FAILED(NativePathCchAppendA(pszPath, cchPath + 1, pszAddinPath)))
|
| 130 |
+
{
|
| 131 |
+
free(pszPath);
|
| 132 |
+
return NULL;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
WLog_DBG(TAG, "freerdp_get_dynamic_addin_install_path -> pszPath: %s", pszPath);
|
| 137 |
+
|
| 138 |
+
return pszPath;
|
| 139 |
+
#endif
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath,
|
| 143 |
+
LPCSTR pszEntryName)
|
| 144 |
+
{
|
| 145 |
+
LPSTR pszAddinInstallPath = freerdp_get_dynamic_addin_install_path();
|
| 146 |
+
PVIRTUALCHANNELENTRY entry = NULL;
|
| 147 |
+
BOOL bHasExt = TRUE;
|
| 148 |
+
PCSTR pszExt = NULL;
|
| 149 |
+
size_t cchExt = 0;
|
| 150 |
+
HINSTANCE library = NULL;
|
| 151 |
+
size_t cchFileName = 0;
|
| 152 |
+
size_t cchFilePath = 0;
|
| 153 |
+
LPSTR pszAddinFile = NULL;
|
| 154 |
+
LPSTR pszFilePath = NULL;
|
| 155 |
+
LPSTR pszRelativeFilePath = NULL;
|
| 156 |
+
size_t cchAddinFile = 0;
|
| 157 |
+
size_t cchAddinInstallPath = 0;
|
| 158 |
+
|
| 159 |
+
if (!pszFileName || !pszEntryName)
|
| 160 |
+
goto fail;
|
| 161 |
+
|
| 162 |
+
WLog_DBG(TAG, "freerdp_load_dynamic_addin <- pszFileName: %s, pszPath: %s, pszEntryName: %s",
|
| 163 |
+
pszFileName, pszPath, pszEntryName);
|
| 164 |
+
|
| 165 |
+
cchFileName = strlen(pszFileName);
|
| 166 |
+
|
| 167 |
+
/* Get file name with prefix and extension */
|
| 168 |
+
if (FAILED(PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt)))
|
| 169 |
+
{
|
| 170 |
+
pszExt = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
|
| 171 |
+
cchExt = strlen(pszExt);
|
| 172 |
+
bHasExt = FALSE;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
if (bHasExt)
|
| 176 |
+
{
|
| 177 |
+
pszAddinFile = _strdup(pszFileName);
|
| 178 |
+
|
| 179 |
+
if (!pszAddinFile)
|
| 180 |
+
goto fail;
|
| 181 |
+
}
|
| 182 |
+
else
|
| 183 |
+
{
|
| 184 |
+
cchAddinFile = cchFileName + cchExt + 2 + sizeof(FREERDP_SHARED_LIBRARY_PREFIX);
|
| 185 |
+
pszAddinFile = (LPSTR)malloc(cchAddinFile + 1);
|
| 186 |
+
|
| 187 |
+
if (!pszAddinFile)
|
| 188 |
+
goto fail;
|
| 189 |
+
|
| 190 |
+
(void)sprintf_s(pszAddinFile, cchAddinFile, FREERDP_SHARED_LIBRARY_PREFIX "%s%s",
|
| 191 |
+
pszFileName, pszExt);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
cchAddinFile = strlen(pszAddinFile);
|
| 195 |
+
|
| 196 |
+
/* If a path is provided prefix the library name with it. */
|
| 197 |
+
if (pszPath)
|
| 198 |
+
{
|
| 199 |
+
size_t relPathLen = strlen(pszPath) + cchAddinFile + 1;
|
| 200 |
+
pszRelativeFilePath = calloc(relPathLen, sizeof(CHAR));
|
| 201 |
+
|
| 202 |
+
if (!pszRelativeFilePath)
|
| 203 |
+
goto fail;
|
| 204 |
+
|
| 205 |
+
(void)sprintf_s(pszRelativeFilePath, relPathLen, "%s", pszPath);
|
| 206 |
+
const HRESULT hr = NativePathCchAppendA(pszRelativeFilePath, relPathLen, pszAddinFile);
|
| 207 |
+
if (FAILED(hr))
|
| 208 |
+
goto fail;
|
| 209 |
+
}
|
| 210 |
+
else
|
| 211 |
+
pszRelativeFilePath = _strdup(pszAddinFile);
|
| 212 |
+
|
| 213 |
+
if (!pszRelativeFilePath)
|
| 214 |
+
goto fail;
|
| 215 |
+
|
| 216 |
+
/* If a system prefix path is provided try these locations too. */
|
| 217 |
+
if (pszAddinInstallPath)
|
| 218 |
+
{
|
| 219 |
+
cchAddinInstallPath = strlen(pszAddinInstallPath);
|
| 220 |
+
cchFilePath = cchAddinInstallPath + cchFileName + 32;
|
| 221 |
+
pszFilePath = (LPSTR)malloc(cchFilePath + 1);
|
| 222 |
+
|
| 223 |
+
if (!pszFilePath)
|
| 224 |
+
goto fail;
|
| 225 |
+
|
| 226 |
+
CopyMemory(pszFilePath, pszAddinInstallPath, cchAddinInstallPath);
|
| 227 |
+
pszFilePath[cchAddinInstallPath] = '\0';
|
| 228 |
+
const HRESULT hr = NativePathCchAppendA(pszFilePath, cchFilePath + 1, pszRelativeFilePath);
|
| 229 |
+
if (FAILED(hr))
|
| 230 |
+
goto fail;
|
| 231 |
+
}
|
| 232 |
+
else
|
| 233 |
+
pszFilePath = _strdup(pszRelativeFilePath);
|
| 234 |
+
|
| 235 |
+
library = LoadLibraryX(pszFilePath);
|
| 236 |
+
|
| 237 |
+
if (!library)
|
| 238 |
+
goto fail;
|
| 239 |
+
|
| 240 |
+
entry = GetProcAddressAs(library, pszEntryName, PVIRTUALCHANNELENTRY);
|
| 241 |
+
fail:
|
| 242 |
+
free(pszRelativeFilePath);
|
| 243 |
+
free(pszAddinFile);
|
| 244 |
+
free(pszFilePath);
|
| 245 |
+
free(pszAddinInstallPath);
|
| 246 |
+
|
| 247 |
+
if (!entry && library)
|
| 248 |
+
FreeLibrary(library);
|
| 249 |
+
|
| 250 |
+
return entry;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
PVIRTUALCHANNELENTRY freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPCSTR pszSubsystem,
|
| 254 |
+
LPCSTR pszType, DWORD dwFlags)
|
| 255 |
+
{
|
| 256 |
+
PVIRTUALCHANNELENTRY entry = NULL;
|
| 257 |
+
LPSTR pszFileName = NULL;
|
| 258 |
+
const size_t cchBaseFileName = sizeof(FREERDP_SHARED_LIBRARY_PREFIX) + 32;
|
| 259 |
+
size_t nameLen = 0;
|
| 260 |
+
size_t subsystemLen = 0;
|
| 261 |
+
size_t typeLen = 0;
|
| 262 |
+
size_t cchFileName = 0;
|
| 263 |
+
|
| 264 |
+
if (pszName)
|
| 265 |
+
nameLen = strnlen(pszName, MAX_PATH);
|
| 266 |
+
if (pszSubsystem)
|
| 267 |
+
subsystemLen = strnlen(pszSubsystem, MAX_PATH);
|
| 268 |
+
if (pszType)
|
| 269 |
+
typeLen = strnlen(pszType, MAX_PATH);
|
| 270 |
+
|
| 271 |
+
if (pszName && pszSubsystem && pszType)
|
| 272 |
+
{
|
| 273 |
+
cchFileName = cchBaseFileName + nameLen + subsystemLen + typeLen;
|
| 274 |
+
pszFileName = (LPSTR)malloc(cchFileName);
|
| 275 |
+
|
| 276 |
+
if (!pszFileName)
|
| 277 |
+
return NULL;
|
| 278 |
+
|
| 279 |
+
(void)sprintf_s(pszFileName, cchFileName, "%s-client-%s-%s", pszName, pszSubsystem,
|
| 280 |
+
pszType);
|
| 281 |
+
}
|
| 282 |
+
else if (pszName && pszSubsystem)
|
| 283 |
+
{
|
| 284 |
+
cchFileName = cchBaseFileName + nameLen + subsystemLen;
|
| 285 |
+
pszFileName = (LPSTR)malloc(cchFileName);
|
| 286 |
+
|
| 287 |
+
if (!pszFileName)
|
| 288 |
+
return NULL;
|
| 289 |
+
|
| 290 |
+
(void)sprintf_s(pszFileName, cchFileName, "%s-client-%s", pszName, pszSubsystem);
|
| 291 |
+
}
|
| 292 |
+
else if (pszName)
|
| 293 |
+
{
|
| 294 |
+
cchFileName = cchBaseFileName + nameLen;
|
| 295 |
+
pszFileName = (LPSTR)malloc(cchFileName);
|
| 296 |
+
|
| 297 |
+
if (!pszFileName)
|
| 298 |
+
return NULL;
|
| 299 |
+
|
| 300 |
+
(void)sprintf_s(pszFileName, cchFileName, "%s-client", pszName);
|
| 301 |
+
}
|
| 302 |
+
else
|
| 303 |
+
{
|
| 304 |
+
return NULL;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
{
|
| 308 |
+
LPCSTR pszExtension = PathGetSharedLibraryExtensionA(0);
|
| 309 |
+
const char pszPrefix[] = FREERDP_SHARED_LIBRARY_PREFIX;
|
| 310 |
+
int rc = 0;
|
| 311 |
+
|
| 312 |
+
cchFileName += strnlen(pszPrefix, ARRAYSIZE(pszPrefix));
|
| 313 |
+
if (pszExtension)
|
| 314 |
+
cchFileName += strnlen(pszExtension, MAX_PATH) + 1;
|
| 315 |
+
LPSTR tmp = calloc(cchFileName, sizeof(CHAR));
|
| 316 |
+
if (tmp)
|
| 317 |
+
rc = sprintf_s(tmp, cchFileName, "%s%s.%s", pszPrefix, pszFileName, pszExtension);
|
| 318 |
+
|
| 319 |
+
free(pszFileName);
|
| 320 |
+
pszFileName = tmp;
|
| 321 |
+
if (!pszFileName || (rc < 0))
|
| 322 |
+
{
|
| 323 |
+
free(pszFileName);
|
| 324 |
+
return NULL;
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
if (pszSubsystem)
|
| 329 |
+
{
|
| 330 |
+
LPSTR pszEntryName = NULL;
|
| 331 |
+
size_t cchEntryName = 0;
|
| 332 |
+
/* subsystem add-in */
|
| 333 |
+
cchEntryName = 64 + nameLen;
|
| 334 |
+
pszEntryName = (LPSTR)malloc(cchEntryName + 1);
|
| 335 |
+
|
| 336 |
+
if (!pszEntryName)
|
| 337 |
+
{
|
| 338 |
+
free(pszFileName);
|
| 339 |
+
return NULL;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
(void)sprintf_s(pszEntryName, cchEntryName + 1, "freerdp_%s_client_subsystem_entry",
|
| 343 |
+
pszName);
|
| 344 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszEntryName);
|
| 345 |
+
free(pszEntryName);
|
| 346 |
+
free(pszFileName);
|
| 347 |
+
return entry;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
/* channel add-in */
|
| 351 |
+
|
| 352 |
+
if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC)
|
| 353 |
+
{
|
| 354 |
+
if (dwFlags & FREERDP_ADDIN_CHANNEL_ENTRYEX)
|
| 355 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "VirtualChannelEntryEx");
|
| 356 |
+
else
|
| 357 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "VirtualChannelEntry");
|
| 358 |
+
}
|
| 359 |
+
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC)
|
| 360 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DVCPluginEntry");
|
| 361 |
+
else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE)
|
| 362 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, "DeviceServiceEntry");
|
| 363 |
+
else
|
| 364 |
+
entry = freerdp_load_dynamic_addin(pszFileName, NULL, pszType);
|
| 365 |
+
|
| 366 |
+
free(pszFileName);
|
| 367 |
+
return entry;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
static FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN freerdp_load_static_channel_addin_entry = NULL;
|
| 371 |
+
|
| 372 |
+
int freerdp_register_addin_provider(FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN provider, DWORD dwFlags)
|
| 373 |
+
{
|
| 374 |
+
freerdp_load_static_channel_addin_entry = provider;
|
| 375 |
+
return 0;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN freerdp_get_current_addin_provider(void)
|
| 379 |
+
{
|
| 380 |
+
return freerdp_load_static_channel_addin_entry;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
PVIRTUALCHANNELENTRY freerdp_load_channel_addin_entry(LPCSTR pszName, LPCSTR pszSubsystem,
|
| 384 |
+
LPCSTR pszType, DWORD dwFlags)
|
| 385 |
+
{
|
| 386 |
+
PVIRTUALCHANNELENTRY entry = NULL;
|
| 387 |
+
|
| 388 |
+
if (freerdp_load_static_channel_addin_entry)
|
| 389 |
+
entry = freerdp_load_static_channel_addin_entry(pszName, pszSubsystem, pszType, dwFlags);
|
| 390 |
+
|
| 391 |
+
if (!entry)
|
| 392 |
+
entry = freerdp_load_dynamic_channel_addin_entry(pszName, pszSubsystem, pszType, dwFlags);
|
| 393 |
+
|
| 394 |
+
if (!entry)
|
| 395 |
+
WLog_WARN(TAG, "Failed to load channel %s [%s]", pszName, pszSubsystem);
|
| 396 |
+
|
| 397 |
+
return entry;
|
| 398 |
+
}
|
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freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)
|
| 7 |
+
{
|
| 8 |
+
WINPR_ASSERT(dst);
|
| 9 |
+
WINPR_ASSERT(src);
|
| 10 |
+
|
| 11 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 12 |
+
{
|
| 13 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 14 |
+
switch (cur->type)
|
| 15 |
+
{
|
| 16 |
+
case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
|
| 17 |
+
{
|
| 18 |
+
BOOL sval = freerdp_settings_get_bool(src, (FreeRDP_Settings_Keys_Bool)cur->id);
|
| 19 |
+
if (!freerdp_settings_set_bool(dst, (FreeRDP_Settings_Keys_Bool)cur->id, sval))
|
| 20 |
+
return FALSE;
|
| 21 |
+
}
|
| 22 |
+
break;
|
| 23 |
+
case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
|
| 24 |
+
{
|
| 25 |
+
UINT16 sval =
|
| 26 |
+
freerdp_settings_get_uint16(src, (FreeRDP_Settings_Keys_UInt16)cur->id);
|
| 27 |
+
if (!freerdp_settings_set_uint16(dst, (FreeRDP_Settings_Keys_UInt16)cur->id, sval))
|
| 28 |
+
return FALSE;
|
| 29 |
+
}
|
| 30 |
+
break;
|
| 31 |
+
case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
|
| 32 |
+
{
|
| 33 |
+
INT16 sval = freerdp_settings_get_int16(src, (FreeRDP_Settings_Keys_Int16)cur->id);
|
| 34 |
+
if (!freerdp_settings_set_int16(dst, (FreeRDP_Settings_Keys_Int16)cur->id, sval))
|
| 35 |
+
return FALSE;
|
| 36 |
+
}
|
| 37 |
+
break;
|
| 38 |
+
case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
|
| 39 |
+
{
|
| 40 |
+
UINT32 sval =
|
| 41 |
+
freerdp_settings_get_uint32(src, (FreeRDP_Settings_Keys_UInt32)cur->id);
|
| 42 |
+
if (!freerdp_settings_set_uint32(dst, (FreeRDP_Settings_Keys_UInt32)cur->id, sval))
|
| 43 |
+
return FALSE;
|
| 44 |
+
}
|
| 45 |
+
break;
|
| 46 |
+
case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
|
| 47 |
+
{
|
| 48 |
+
INT32 sval = freerdp_settings_get_int32(src, (FreeRDP_Settings_Keys_Int32)cur->id);
|
| 49 |
+
if (!freerdp_settings_set_int32(dst, (FreeRDP_Settings_Keys_Int32)cur->id, sval))
|
| 50 |
+
return FALSE;
|
| 51 |
+
}
|
| 52 |
+
break;
|
| 53 |
+
case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
|
| 54 |
+
{
|
| 55 |
+
UINT64 sval =
|
| 56 |
+
freerdp_settings_get_uint64(src, (FreeRDP_Settings_Keys_UInt64)cur->id);
|
| 57 |
+
if (!freerdp_settings_set_uint64(dst, (FreeRDP_Settings_Keys_UInt64)cur->id, sval))
|
| 58 |
+
return FALSE;
|
| 59 |
+
}
|
| 60 |
+
break;
|
| 61 |
+
case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
|
| 62 |
+
{
|
| 63 |
+
INT64 sval = freerdp_settings_get_int64(src, (FreeRDP_Settings_Keys_Int64)cur->id);
|
| 64 |
+
if (!freerdp_settings_set_int64(dst, (FreeRDP_Settings_Keys_Int64)cur->id, sval))
|
| 65 |
+
return FALSE;
|
| 66 |
+
}
|
| 67 |
+
break;
|
| 68 |
+
case FREERDP_SETTINGS_TYPE_STRING: /* strings */
|
| 69 |
+
{
|
| 70 |
+
const char* sval =
|
| 71 |
+
freerdp_settings_get_string(src, (FreeRDP_Settings_Keys_String)cur->id);
|
| 72 |
+
size_t len = 0;
|
| 73 |
+
if (sval)
|
| 74 |
+
len = strlen(sval);
|
| 75 |
+
if (!freerdp_settings_set_string_copy_(dst, (FreeRDP_Settings_Keys_String)cur->id,
|
| 76 |
+
sval, len, FALSE))
|
| 77 |
+
return FALSE;
|
| 78 |
+
}
|
| 79 |
+
break;
|
| 80 |
+
case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
|
| 81 |
+
{
|
| 82 |
+
const void* sval =
|
| 83 |
+
freerdp_settings_get_pointer(src, (FreeRDP_Settings_Keys_Pointer)cur->id);
|
| 84 |
+
if (!freerdp_settings_set_pointer(dst, (FreeRDP_Settings_Keys_Pointer)cur->id,
|
| 85 |
+
sval))
|
| 86 |
+
return FALSE;
|
| 87 |
+
}
|
| 88 |
+
break;
|
| 89 |
+
default:
|
| 90 |
+
return FALSE;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
return TRUE;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* settings,
|
| 97 |
+
const rdpSettings* other)
|
| 98 |
+
{
|
| 99 |
+
BOOL rc = FALSE;
|
| 100 |
+
|
| 101 |
+
WINPR_ASSERT(log);
|
| 102 |
+
WINPR_ASSERT(settings);
|
| 103 |
+
WINPR_ASSERT(other);
|
| 104 |
+
|
| 105 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 106 |
+
{
|
| 107 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 108 |
+
switch (cur->type)
|
| 109 |
+
{
|
| 110 |
+
case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
|
| 111 |
+
{
|
| 112 |
+
BOOL sval =
|
| 113 |
+
freerdp_settings_get_bool(settings, (FreeRDP_Settings_Keys_Bool)cur->id);
|
| 114 |
+
BOOL cval = freerdp_settings_get_bool(other, (FreeRDP_Settings_Keys_Bool)cur->id);
|
| 115 |
+
if (sval != cval)
|
| 116 |
+
{
|
| 117 |
+
rc = TRUE;
|
| 118 |
+
WLog_Print(log, level, "%s [BOOL]: %s -> %s", cur->str, sval ? "TRUE" : "FALSE",
|
| 119 |
+
cval ? "TRUE" : "FALSE");
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
break;
|
| 123 |
+
case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
|
| 124 |
+
{
|
| 125 |
+
UINT16 sval =
|
| 126 |
+
freerdp_settings_get_uint16(settings, (FreeRDP_Settings_Keys_UInt16)cur->id);
|
| 127 |
+
UINT16 cval =
|
| 128 |
+
freerdp_settings_get_uint16(other, (FreeRDP_Settings_Keys_UInt16)cur->id);
|
| 129 |
+
if (sval != cval)
|
| 130 |
+
{
|
| 131 |
+
rc = TRUE;
|
| 132 |
+
WLog_Print(log, level, "%s [UINT16]: %" PRIu16 " -> %" PRIu16, cur->str, sval,
|
| 133 |
+
cval);
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
break;
|
| 137 |
+
case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
|
| 138 |
+
{
|
| 139 |
+
INT16 sval =
|
| 140 |
+
freerdp_settings_get_int16(settings, (FreeRDP_Settings_Keys_Int16)cur->id);
|
| 141 |
+
INT16 cval =
|
| 142 |
+
freerdp_settings_get_int16(other, (FreeRDP_Settings_Keys_Int16)cur->id);
|
| 143 |
+
if (sval != cval)
|
| 144 |
+
{
|
| 145 |
+
rc = TRUE;
|
| 146 |
+
WLog_Print(log, level, "%s [INT16]: %" PRId16 " -> %" PRId16, cur->str, sval,
|
| 147 |
+
cval);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
break;
|
| 151 |
+
case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
|
| 152 |
+
{
|
| 153 |
+
UINT32 sval =
|
| 154 |
+
freerdp_settings_get_uint32(settings, (FreeRDP_Settings_Keys_UInt32)cur->id);
|
| 155 |
+
UINT32 cval =
|
| 156 |
+
freerdp_settings_get_uint32(other, (FreeRDP_Settings_Keys_UInt32)cur->id);
|
| 157 |
+
if (sval != cval)
|
| 158 |
+
{
|
| 159 |
+
rc = TRUE;
|
| 160 |
+
WLog_Print(log, level, "%s [UINT32]: %" PRIu32 " -> %" PRIu32, cur->str, sval,
|
| 161 |
+
cval);
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
break;
|
| 165 |
+
case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
|
| 166 |
+
{
|
| 167 |
+
INT32 sval =
|
| 168 |
+
freerdp_settings_get_int32(settings, (FreeRDP_Settings_Keys_Int32)cur->id);
|
| 169 |
+
INT32 cval =
|
| 170 |
+
freerdp_settings_get_int32(other, (FreeRDP_Settings_Keys_Int32)cur->id);
|
| 171 |
+
if (sval != cval)
|
| 172 |
+
{
|
| 173 |
+
rc = TRUE;
|
| 174 |
+
WLog_Print(log, level, "%s [INT32]: %" PRId32 " -> %" PRId32, cur->str, sval,
|
| 175 |
+
cval);
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
break;
|
| 179 |
+
case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
|
| 180 |
+
{
|
| 181 |
+
UINT64 sval =
|
| 182 |
+
freerdp_settings_get_uint64(settings, (FreeRDP_Settings_Keys_UInt64)cur->id);
|
| 183 |
+
UINT64 cval =
|
| 184 |
+
freerdp_settings_get_uint64(other, (FreeRDP_Settings_Keys_UInt64)cur->id);
|
| 185 |
+
if (sval != cval)
|
| 186 |
+
{
|
| 187 |
+
rc = TRUE;
|
| 188 |
+
WLog_Print(log, level, "%s [UINT64]: %" PRIu64 " -> %" PRIu64, cur->str, sval,
|
| 189 |
+
cval);
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
break;
|
| 193 |
+
case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
|
| 194 |
+
{
|
| 195 |
+
INT64 sval =
|
| 196 |
+
freerdp_settings_get_int64(settings, (FreeRDP_Settings_Keys_Int64)cur->id);
|
| 197 |
+
INT64 cval =
|
| 198 |
+
freerdp_settings_get_int64(other, (FreeRDP_Settings_Keys_Int64)cur->id);
|
| 199 |
+
if (sval != cval)
|
| 200 |
+
{
|
| 201 |
+
rc = TRUE;
|
| 202 |
+
WLog_Print(log, level, "%s [INT64]: %" PRId64 " -> %" PRId64, cur->str, sval,
|
| 203 |
+
cval);
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
break;
|
| 207 |
+
case FREERDP_SETTINGS_TYPE_STRING: /* strings */
|
| 208 |
+
{
|
| 209 |
+
const char* sval =
|
| 210 |
+
freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)cur->id);
|
| 211 |
+
const char* cval =
|
| 212 |
+
freerdp_settings_get_string(other, (FreeRDP_Settings_Keys_String)cur->id);
|
| 213 |
+
if (sval != cval)
|
| 214 |
+
{
|
| 215 |
+
if (!sval || !cval || (strcmp(sval, cval) != 0))
|
| 216 |
+
{
|
| 217 |
+
rc = TRUE;
|
| 218 |
+
WLog_Print(log, level, "%s [STRING]: '%s' -> '%s'", cur->str, sval, cval);
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
break;
|
| 223 |
+
case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
|
| 224 |
+
{
|
| 225 |
+
const void* sval =
|
| 226 |
+
freerdp_settings_get_pointer(settings, (FreeRDP_Settings_Keys_Pointer)cur->id);
|
| 227 |
+
const void* cval =
|
| 228 |
+
freerdp_settings_get_pointer(other, (FreeRDP_Settings_Keys_Pointer)cur->id);
|
| 229 |
+
if (sval != cval)
|
| 230 |
+
{
|
| 231 |
+
if ((sval && !cval) || (!sval && cval))
|
| 232 |
+
{
|
| 233 |
+
rc = TRUE;
|
| 234 |
+
WLog_Print(log, level, "%s [POINTER]: '%p' -> '%p'", cur->str, sval, cval);
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
break;
|
| 239 |
+
default:
|
| 240 |
+
break;
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
return rc;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings)
|
| 247 |
+
{
|
| 248 |
+
WINPR_ASSERT(log);
|
| 249 |
+
WINPR_ASSERT(settings);
|
| 250 |
+
|
| 251 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 252 |
+
{
|
| 253 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 254 |
+
switch (cur->type)
|
| 255 |
+
{
|
| 256 |
+
case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
|
| 257 |
+
{
|
| 258 |
+
BOOL sval =
|
| 259 |
+
freerdp_settings_get_bool(settings, (FreeRDP_Settings_Keys_Bool)cur->id);
|
| 260 |
+
WLog_Print(log, level, "%s [BOOL]: %s", cur->str, sval ? "TRUE" : "FALSE");
|
| 261 |
+
}
|
| 262 |
+
break;
|
| 263 |
+
case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
|
| 264 |
+
{
|
| 265 |
+
UINT16 sval =
|
| 266 |
+
freerdp_settings_get_uint16(settings, (FreeRDP_Settings_Keys_UInt16)cur->id);
|
| 267 |
+
WLog_Print(log, level, "%s [UINT16]: %" PRIu16, cur->str, sval);
|
| 268 |
+
}
|
| 269 |
+
break;
|
| 270 |
+
case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
|
| 271 |
+
{
|
| 272 |
+
INT16 sval =
|
| 273 |
+
freerdp_settings_get_int16(settings, (FreeRDP_Settings_Keys_Int16)cur->id);
|
| 274 |
+
WLog_Print(log, level, "%s [INT16]: %" PRId16, cur->str, sval);
|
| 275 |
+
}
|
| 276 |
+
break;
|
| 277 |
+
case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
|
| 278 |
+
{
|
| 279 |
+
UINT32 sval =
|
| 280 |
+
freerdp_settings_get_uint32(settings, (FreeRDP_Settings_Keys_UInt32)cur->id);
|
| 281 |
+
WLog_Print(log, level, "%s [UINT32]: %" PRIu32, cur->str, sval);
|
| 282 |
+
}
|
| 283 |
+
break;
|
| 284 |
+
case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
|
| 285 |
+
{
|
| 286 |
+
INT32 sval =
|
| 287 |
+
freerdp_settings_get_int32(settings, (FreeRDP_Settings_Keys_Int32)cur->id);
|
| 288 |
+
WLog_Print(log, level, "%s [INT32]: %" PRId32, cur->str, sval);
|
| 289 |
+
}
|
| 290 |
+
break;
|
| 291 |
+
case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
|
| 292 |
+
{
|
| 293 |
+
UINT64 sval =
|
| 294 |
+
freerdp_settings_get_uint64(settings, (FreeRDP_Settings_Keys_UInt64)cur->id);
|
| 295 |
+
WLog_Print(log, level, "%s [UINT64]: %" PRIu64, cur->str, sval);
|
| 296 |
+
}
|
| 297 |
+
break;
|
| 298 |
+
case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
|
| 299 |
+
{
|
| 300 |
+
INT64 sval =
|
| 301 |
+
freerdp_settings_get_int64(settings, (FreeRDP_Settings_Keys_Int64)cur->id);
|
| 302 |
+
WLog_Print(log, level, "%s [INT64]: %" PRId64, cur->str, sval);
|
| 303 |
+
}
|
| 304 |
+
break;
|
| 305 |
+
case FREERDP_SETTINGS_TYPE_STRING: /* strings */
|
| 306 |
+
{
|
| 307 |
+
const char* sval =
|
| 308 |
+
freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)cur->id);
|
| 309 |
+
WLog_Print(log, level, "%s [STRING]: '%s'", cur->str, sval);
|
| 310 |
+
}
|
| 311 |
+
break;
|
| 312 |
+
case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
|
| 313 |
+
{
|
| 314 |
+
const void* sval =
|
| 315 |
+
freerdp_settings_get_pointer(settings, (FreeRDP_Settings_Keys_Pointer)cur->id);
|
| 316 |
+
WLog_Print(log, level, "%s [POINTER]: '%p'", cur->str, sval);
|
| 317 |
+
}
|
| 318 |
+
break;
|
| 319 |
+
default:
|
| 320 |
+
break;
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)
|
| 326 |
+
{
|
| 327 |
+
WINPR_ASSERT(dst);
|
| 328 |
+
|
| 329 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 330 |
+
{
|
| 331 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 332 |
+
switch (cur->type)
|
| 333 |
+
{
|
| 334 |
+
case FREERDP_SETTINGS_TYPE_STRING: /* strings */
|
| 335 |
+
(void)freerdp_settings_set_string_copy_(dst, (FreeRDP_Settings_Keys_String)cur->id,
|
| 336 |
+
NULL, 0, cleanup);
|
| 337 |
+
break;
|
| 338 |
+
case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
|
| 339 |
+
(void)freerdp_settings_set_pointer_len(dst, (FreeRDP_Settings_Keys_Pointer)cur->id,
|
| 340 |
+
NULL, 0);
|
| 341 |
+
break;
|
| 342 |
+
default:
|
| 343 |
+
break;
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
SSIZE_T freerdp_settings_get_key_for_name(const char* value)
|
| 349 |
+
{
|
| 350 |
+
WINPR_ASSERT(value);
|
| 351 |
+
|
| 352 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 353 |
+
{
|
| 354 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 355 |
+
if (strcmp(value, cur->str) == 0)
|
| 356 |
+
return cur->id;
|
| 357 |
+
}
|
| 358 |
+
return -1;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
SSIZE_T freerdp_settings_get_type_for_name(const char* value)
|
| 362 |
+
{
|
| 363 |
+
WINPR_ASSERT(value);
|
| 364 |
+
|
| 365 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 366 |
+
{
|
| 367 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 368 |
+
if (strcmp(value, cur->str) == 0)
|
| 369 |
+
return cur->type;
|
| 370 |
+
}
|
| 371 |
+
return -1;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
const char* freerdp_settings_get_type_name_for_key(SSIZE_T key)
|
| 375 |
+
{
|
| 376 |
+
const SSIZE_T type = freerdp_settings_get_type_for_key(key);
|
| 377 |
+
return freerdp_settings_get_type_name_for_type(type);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
const char* freerdp_settings_get_type_name_for_type(SSIZE_T type)
|
| 381 |
+
{
|
| 382 |
+
switch (type)
|
| 383 |
+
{
|
| 384 |
+
case FREERDP_SETTINGS_TYPE_BOOL:
|
| 385 |
+
return "FREERDP_SETTINGS_TYPE_BOOL";
|
| 386 |
+
case FREERDP_SETTINGS_TYPE_UINT16:
|
| 387 |
+
return "FREERDP_SETTINGS_TYPE_UINT16";
|
| 388 |
+
case FREERDP_SETTINGS_TYPE_INT16:
|
| 389 |
+
return "FREERDP_SETTINGS_TYPE_INT16";
|
| 390 |
+
case FREERDP_SETTINGS_TYPE_UINT32:
|
| 391 |
+
return "FREERDP_SETTINGS_TYPE_UINT32";
|
| 392 |
+
case FREERDP_SETTINGS_TYPE_INT32:
|
| 393 |
+
return "FREERDP_SETTINGS_TYPE_INT32";
|
| 394 |
+
case FREERDP_SETTINGS_TYPE_UINT64:
|
| 395 |
+
return "FREERDP_SETTINGS_TYPE_UINT64";
|
| 396 |
+
case FREERDP_SETTINGS_TYPE_INT64:
|
| 397 |
+
return "FREERDP_SETTINGS_TYPE_INT64";
|
| 398 |
+
case FREERDP_SETTINGS_TYPE_STRING:
|
| 399 |
+
return "FREERDP_SETTINGS_TYPE_STRING";
|
| 400 |
+
case FREERDP_SETTINGS_TYPE_POINTER:
|
| 401 |
+
return "FREERDP_SETTINGS_TYPE_POINTER";
|
| 402 |
+
default:
|
| 403 |
+
return "FREERDP_SETTINGS_TYPE_UNKNOWN";
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
SSIZE_T freerdp_settings_get_type_for_key(SSIZE_T key)
|
| 408 |
+
{
|
| 409 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 410 |
+
{
|
| 411 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 412 |
+
if (cur->id == key)
|
| 413 |
+
return cur->type;
|
| 414 |
+
}
|
| 415 |
+
return -1;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
const char* freerdp_settings_get_name_for_key(SSIZE_T key)
|
| 419 |
+
{
|
| 420 |
+
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
|
| 421 |
+
{
|
| 422 |
+
const struct settings_str_entry* cur = &settings_map[x];
|
| 423 |
+
if (cur->id == key)
|
| 424 |
+
return cur->str;
|
| 425 |
+
}
|
| 426 |
+
return NULL;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src, SSIZE_T id)
|
| 430 |
+
{
|
| 431 |
+
WINPR_ASSERT(dst);
|
| 432 |
+
WINPR_ASSERT(src);
|
| 433 |
+
|
| 434 |
+
const SSIZE_T key = freerdp_settings_get_type_for_key(id);
|
| 435 |
+
switch (key)
|
| 436 |
+
{
|
| 437 |
+
case FREERDP_SETTINGS_TYPE_BOOL:
|
| 438 |
+
{
|
| 439 |
+
const BOOL val = freerdp_settings_get_bool(src, (FreeRDP_Settings_Keys_Bool)id);
|
| 440 |
+
return freerdp_settings_set_bool(dst, (FreeRDP_Settings_Keys_Bool)id, val);
|
| 441 |
+
}
|
| 442 |
+
case FREERDP_SETTINGS_TYPE_INT16:
|
| 443 |
+
{
|
| 444 |
+
const INT16 val = freerdp_settings_get_int16(src, (FreeRDP_Settings_Keys_Int16)id);
|
| 445 |
+
return freerdp_settings_set_int16(dst, (FreeRDP_Settings_Keys_Int16)id, val);
|
| 446 |
+
}
|
| 447 |
+
case FREERDP_SETTINGS_TYPE_INT32:
|
| 448 |
+
{
|
| 449 |
+
const INT32 val = freerdp_settings_get_int32(src, (FreeRDP_Settings_Keys_Int32)id);
|
| 450 |
+
return freerdp_settings_set_int32(dst, (FreeRDP_Settings_Keys_Int32)id, val);
|
| 451 |
+
}
|
| 452 |
+
case FREERDP_SETTINGS_TYPE_INT64:
|
| 453 |
+
{
|
| 454 |
+
const INT64 val = freerdp_settings_get_int64(src, (FreeRDP_Settings_Keys_Int64)id);
|
| 455 |
+
return freerdp_settings_set_int64(dst, (FreeRDP_Settings_Keys_Int64)id, val);
|
| 456 |
+
}
|
| 457 |
+
case FREERDP_SETTINGS_TYPE_UINT16:
|
| 458 |
+
{
|
| 459 |
+
const UINT16 val = freerdp_settings_get_uint16(src, (FreeRDP_Settings_Keys_UInt16)id);
|
| 460 |
+
return freerdp_settings_set_uint16(dst, (FreeRDP_Settings_Keys_UInt16)id, val);
|
| 461 |
+
}
|
| 462 |
+
case FREERDP_SETTINGS_TYPE_UINT32:
|
| 463 |
+
{
|
| 464 |
+
const UINT32 val = freerdp_settings_get_uint32(src, (FreeRDP_Settings_Keys_UInt32)id);
|
| 465 |
+
return freerdp_settings_set_uint32(dst, (FreeRDP_Settings_Keys_UInt32)id, val);
|
| 466 |
+
}
|
| 467 |
+
case FREERDP_SETTINGS_TYPE_UINT64:
|
| 468 |
+
{
|
| 469 |
+
const UINT64 val = freerdp_settings_get_uint64(src, (FreeRDP_Settings_Keys_UInt64)id);
|
| 470 |
+
return freerdp_settings_set_uint64(dst, (FreeRDP_Settings_Keys_UInt64)id, val);
|
| 471 |
+
}
|
| 472 |
+
case FREERDP_SETTINGS_TYPE_STRING:
|
| 473 |
+
{
|
| 474 |
+
const char* val = freerdp_settings_get_string(src, (FreeRDP_Settings_Keys_String)id);
|
| 475 |
+
return freerdp_settings_set_string(dst, (FreeRDP_Settings_Keys_String)id, val);
|
| 476 |
+
}
|
| 477 |
+
case FREERDP_SETTINGS_TYPE_POINTER:
|
| 478 |
+
{
|
| 479 |
+
const void* val = freerdp_settings_get_pointer(src, (FreeRDP_Settings_Keys_Pointer)id);
|
| 480 |
+
return freerdp_settings_set_pointer(dst, (FreeRDP_Settings_Keys_Pointer)id, val);
|
| 481 |
+
}
|
| 482 |
+
default:
|
| 483 |
+
return FALSE;
|
| 484 |
+
}
|
| 485 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/README.txt
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The Primitives Library
|
| 2 |
+
|
| 3 |
+
Introduction
|
| 4 |
+
------------
|
| 5 |
+
The purpose of the primitives library is to give the freerdp code easy
|
| 6 |
+
access to *run-time* optimization via SIMD operations. When the library
|
| 7 |
+
is initialized, dynamic checks of processor features are run (such as
|
| 8 |
+
the support of SSE3 or Neon), and entrypoints are linked to through
|
| 9 |
+
function pointers to provide the fastest possible operations. All
|
| 10 |
+
routines offer generic C alternatives as fallbacks.
|
| 11 |
+
|
| 12 |
+
Run-time optimization has the advantage of allowing a single executable
|
| 13 |
+
to run fast on multiple platforms with different SIMD capabilities.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Use In Code
|
| 17 |
+
-----------
|
| 18 |
+
A singleton pointing to a structure containing the function pointers
|
| 19 |
+
is accessed through primitives_get(). The function pointers can then
|
| 20 |
+
be used from that structure, e.g.
|
| 21 |
+
|
| 22 |
+
primitives_t *prims = primitives_get();
|
| 23 |
+
prims->shiftC_16s(buffer, shifts, buffer, 256);
|
| 24 |
+
|
| 25 |
+
Of course, there is some overhead in calling through the function pointer
|
| 26 |
+
and setting up the SIMD operations, so it would be counterproductive to
|
| 27 |
+
call the primitives library for very small operation, e.g. initializing an
|
| 28 |
+
array of eight values to a constant. The primitives library is intended
|
| 29 |
+
for larger-scale operations, e.g. arrays of size 64 and larger.
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Initialization and Cleanup
|
| 33 |
+
--------------------------
|
| 34 |
+
Library initialization is done the first time primitives_init() is called
|
| 35 |
+
or the first time primitives_get() is used. Cleanup (if any) is done by
|
| 36 |
+
primitives_deinit().
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Intel Integrated Performance Primitives (IPP)
|
| 40 |
+
---------------------------------------------
|
| 41 |
+
If freerdp is compiled with IPP support (-DWITH_IPP=ON), the IPP function
|
| 42 |
+
calls will be used (where available) to fill the function pointers.
|
| 43 |
+
Where possible, function names and parameter lists match IPP format so
|
| 44 |
+
that the IPP functions can be plugged into the function pointers without
|
| 45 |
+
a wrapper layer. Use of IPP is completely optional, and in many cases
|
| 46 |
+
the SSE operations in the primitives library itself are faster or similar
|
| 47 |
+
in performance.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Coverage
|
| 51 |
+
--------
|
| 52 |
+
The primitives library is not meant to be comprehensive, offering
|
| 53 |
+
entrypoints for every operation and operand type. Instead, the coverage
|
| 54 |
+
is focused on operations known to be performance bottlenecks in the code.
|
| 55 |
+
For instance, 16-bit signed operations are used widely in the RemoteFX
|
| 56 |
+
software, so you'll find 16s versions of several operations, but there
|
| 57 |
+
is no attempt to provide (unused) copies of the same code for 8u, 16u,
|
| 58 |
+
32s, etc.
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
New Optimizations
|
| 62 |
+
-----------------
|
| 63 |
+
As the need arises, new optimizations can be added to the library,
|
| 64 |
+
including NEON, AVX, and perhaps OpenCL or other SIMD implementations.
|
| 65 |
+
The CPU feature detection is done in winpr/sysinfo.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Adding Entrypoints
|
| 69 |
+
------------------
|
| 70 |
+
As the need for new operations or operands arises, new entrypoints can
|
| 71 |
+
be added.
|
| 72 |
+
1) Function prototypes and pointers are added to
|
| 73 |
+
include/freerdp/primitives.h
|
| 74 |
+
2) New module initialization and cleanup function prototypes are added
|
| 75 |
+
to prim_internal.h and called in primitives.c (primitives_init()
|
| 76 |
+
and primitives_deinit()).
|
| 77 |
+
3) Operation names and parameter lists should be compatible with the IPP.
|
| 78 |
+
IPP manuals are available online at software.intel.com.
|
| 79 |
+
4) A generic C entrypoint must be available as a fallback.
|
| 80 |
+
5) prim_templates.h contains macro-based templates for simple operations,
|
| 81 |
+
such as applying a single SSE operation to arrays of data.
|
| 82 |
+
The template functions can frequently be used to extend the
|
| 83 |
+
operations without writing a lot of new code.
|
| 84 |
+
|
| 85 |
+
Cache Management
|
| 86 |
+
----------------
|
| 87 |
+
I haven't found a lot of speed improvement by attempting prefetch, and
|
| 88 |
+
in fact it seems to have a negative impact in some cases. Done correctly
|
| 89 |
+
perhaps the routines could be further accelerated by proper use of prefetch,
|
| 90 |
+
fences, etc.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
Testing
|
| 94 |
+
-------
|
| 95 |
+
In the test subdirectory is an executable (prim_test) that tests both
|
| 96 |
+
functionality and speed of primitives library operations. Any new
|
| 97 |
+
modules should be added to that test, following the conventions already
|
| 98 |
+
established in that directory. The program can be executed on various
|
| 99 |
+
target hardware to compare generic C, optimized, and IPP performance
|
| 100 |
+
with various array sizes.
|
| 101 |
+
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/prim_YCoCg.h
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Primitives copy
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2024 Armin Novak <[email protected]>
|
| 6 |
+
* Copyright 2024 Thincast Technologies GmbH
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#ifndef FREERDP_LIB_PRIM_YCoCg_H
|
| 22 |
+
#define FREERDP_LIB_PRIM_YCoCg_H
|
| 23 |
+
|
| 24 |
+
#include <winpr/wtypes.h>
|
| 25 |
+
#include <freerdp/config.h>
|
| 26 |
+
#include <freerdp/primitives.h>
|
| 27 |
+
|
| 28 |
+
void primitives_init_YCoCg_ssse3(primitives_t* WINPR_RESTRICT prims);
|
| 29 |
+
void primitives_init_YCoCg_neon(primitives_t* WINPR_RESTRICT prims);
|
| 30 |
+
|
| 31 |
+
#endif
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/prim_andor.c
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* FreeRDP: A Remote Desktop Protocol Client
|
| 2 |
+
* Logical operations.
|
| 3 |
+
* vi:ts=4 sw=4:
|
| 4 |
+
*
|
| 5 |
+
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
| 6 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
| 7 |
+
* not use this file except in compliance with the License. You may obtain
|
| 8 |
+
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
| 9 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
| 12 |
+
* or implied. See the License for the specific language governing
|
| 13 |
+
* permissions and limitations under the License.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <freerdp/config.h>
|
| 17 |
+
|
| 18 |
+
#include <freerdp/types.h>
|
| 19 |
+
#include <freerdp/primitives.h>
|
| 20 |
+
|
| 21 |
+
#include "prim_internal.h"
|
| 22 |
+
#include "prim_andor.h"
|
| 23 |
+
|
| 24 |
+
/* ----------------------------------------------------------------------------
|
| 25 |
+
* 32-bit AND with a constant.
|
| 26 |
+
*/
|
| 27 |
+
static pstatus_t general_andC_32u(const UINT32* pSrc, UINT32 val, UINT32* pDst, INT32 len)
|
| 28 |
+
{
|
| 29 |
+
if (val == 0)
|
| 30 |
+
return PRIMITIVES_SUCCESS;
|
| 31 |
+
|
| 32 |
+
while (len--)
|
| 33 |
+
*pDst++ = *pSrc++ & val;
|
| 34 |
+
|
| 35 |
+
return PRIMITIVES_SUCCESS;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* ----------------------------------------------------------------------------
|
| 39 |
+
* 32-bit OR with a constant.
|
| 40 |
+
*/
|
| 41 |
+
static pstatus_t general_orC_32u(const UINT32* pSrc, UINT32 val, UINT32* pDst, INT32 len)
|
| 42 |
+
{
|
| 43 |
+
if (val == 0)
|
| 44 |
+
return PRIMITIVES_SUCCESS;
|
| 45 |
+
|
| 46 |
+
while (len--)
|
| 47 |
+
*pDst++ = *pSrc++ | val;
|
| 48 |
+
|
| 49 |
+
return PRIMITIVES_SUCCESS;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* ------------------------------------------------------------------------- */
|
| 53 |
+
void primitives_init_andor(primitives_t* WINPR_RESTRICT prims)
|
| 54 |
+
{
|
| 55 |
+
/* Start with the default. */
|
| 56 |
+
prims->andC_32u = general_andC_32u;
|
| 57 |
+
prims->orC_32u = general_orC_32u;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void primitives_init_andor_opt(primitives_t* WINPR_RESTRICT prims)
|
| 61 |
+
{
|
| 62 |
+
primitives_init_andor_sse3(prims);
|
| 63 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/CMakeLists.txt
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FreeRDP: A Remote Desktop Protocol Implementation
|
| 2 |
+
# libfreerdp-utils cmake build script
|
| 3 |
+
#
|
| 4 |
+
# Copyright 2012 Marc-Andre Moreau <[email protected]>
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
set(MODULE_NAME "freerdp-utils")
|
| 19 |
+
set(MODULE_PREFIX "FREERDP_UTILS")
|
| 20 |
+
|
| 21 |
+
set(${MODULE_PREFIX}_SRCS
|
| 22 |
+
encoded_types.c
|
| 23 |
+
helpers.c
|
| 24 |
+
passphrase.c
|
| 25 |
+
cliprdr_utils.c
|
| 26 |
+
rdpdr_utils.c
|
| 27 |
+
pcap.c
|
| 28 |
+
profiler.c
|
| 29 |
+
ringbuffer.c
|
| 30 |
+
signal.c
|
| 31 |
+
string.c
|
| 32 |
+
gfx.c
|
| 33 |
+
drdynvc.c
|
| 34 |
+
smartcard_operations.c
|
| 35 |
+
smartcard_pack.c
|
| 36 |
+
smartcard_call.c
|
| 37 |
+
stopwatch.c
|
| 38 |
+
http.c
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
freerdp_module_add(${${MODULE_PREFIX}_SRCS})
|
| 42 |
+
|
| 43 |
+
freerdp_library_add(${CMAKE_THREAD_LIBS_INIT})
|
| 44 |
+
|
| 45 |
+
if(WIN32)
|
| 46 |
+
freerdp_library_add(ws2_32)
|
| 47 |
+
freerdp_library_add(credui)
|
| 48 |
+
freerdp_library_add(cfgmgr32)
|
| 49 |
+
endif()
|
| 50 |
+
|
| 51 |
+
check_library_exists(m pow "" HAVE_LIB_M)
|
| 52 |
+
|
| 53 |
+
if(HAVE_LIB_M)
|
| 54 |
+
freerdp_library_add(m)
|
| 55 |
+
endif()
|
| 56 |
+
|
| 57 |
+
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
|
| 58 |
+
add_subdirectory(test)
|
| 59 |
+
endif()
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/cliprdr_utils.c
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Clipboard Virtual Channel Extension
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2022 Armin Novak <[email protected]
|
| 7 |
+
* Copyright 2022 Thincast Technologies GmbH
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <winpr/stream.h>
|
| 23 |
+
#include <freerdp/utils/cliprdr_utils.h>
|
| 24 |
+
#include <freerdp/channels/cliprdr.h>
|
| 25 |
+
|
| 26 |
+
#include <freerdp/log.h>
|
| 27 |
+
#define TAG FREERDP_TAG("utils." CLIPRDR_SVC_CHANNEL_NAME)
|
| 28 |
+
|
| 29 |
+
#define CLIPRDR_FILEDESCRIPTOR_SIZE (4 + 32 + 4 + 16 + 8 + 8 + 520)
|
| 30 |
+
#define CLIPRDR_MAX_FILE_SIZE (2U * 1024 * 1024 * 1024)
|
| 31 |
+
|
| 32 |
+
static UINT64 filetime_to_uint64(FILETIME value)
|
| 33 |
+
{
|
| 34 |
+
UINT64 converted = 0;
|
| 35 |
+
converted |= (UINT32)value.dwHighDateTime;
|
| 36 |
+
converted <<= 32;
|
| 37 |
+
converted |= (UINT32)value.dwLowDateTime;
|
| 38 |
+
return converted;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
static FILETIME uint64_to_filetime(UINT64 value)
|
| 42 |
+
{
|
| 43 |
+
FILETIME converted;
|
| 44 |
+
converted.dwLowDateTime = (UINT32)(value >> 0);
|
| 45 |
+
converted.dwHighDateTime = (UINT32)(value >> 32);
|
| 46 |
+
return converted;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Parse a packed file list.
|
| 51 |
+
*
|
| 52 |
+
* The resulting array must be freed with the `free()` function.
|
| 53 |
+
*
|
| 54 |
+
* @param [in] format_data packed `CLIPRDR_FILELIST` to parse.
|
| 55 |
+
* @param [in] format_data_length length of `format_data` in bytes.
|
| 56 |
+
* @param [out] file_descriptor_array parsed array of `FILEDESCRIPTOR` structs.
|
| 57 |
+
* @param [out] file_descriptor_count number of elements in `file_descriptor_array`.
|
| 58 |
+
*
|
| 59 |
+
* @returns 0 on success, otherwise a Win32 error code.
|
| 60 |
+
*/
|
| 61 |
+
UINT cliprdr_parse_file_list(const BYTE* format_data, UINT32 format_data_length,
|
| 62 |
+
FILEDESCRIPTORW** file_descriptor_array, UINT32* file_descriptor_count)
|
| 63 |
+
{
|
| 64 |
+
UINT result = NO_ERROR;
|
| 65 |
+
UINT32 count = 0;
|
| 66 |
+
wStream sbuffer;
|
| 67 |
+
wStream* s = NULL;
|
| 68 |
+
|
| 69 |
+
if (!format_data || !file_descriptor_array || !file_descriptor_count)
|
| 70 |
+
return ERROR_BAD_ARGUMENTS;
|
| 71 |
+
|
| 72 |
+
s = Stream_StaticConstInit(&sbuffer, format_data, format_data_length);
|
| 73 |
+
if (!s)
|
| 74 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 75 |
+
|
| 76 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 77 |
+
{
|
| 78 |
+
result = ERROR_INCORRECT_SIZE;
|
| 79 |
+
goto out;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
Stream_Read_UINT32(s, count); /* cItems (4 bytes) */
|
| 83 |
+
|
| 84 |
+
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, count, CLIPRDR_FILEDESCRIPTOR_SIZE))
|
| 85 |
+
{
|
| 86 |
+
result = ERROR_INCORRECT_SIZE;
|
| 87 |
+
goto out;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
*file_descriptor_count = count;
|
| 91 |
+
*file_descriptor_array = calloc(count, sizeof(FILEDESCRIPTORW));
|
| 92 |
+
if (!*file_descriptor_array)
|
| 93 |
+
{
|
| 94 |
+
result = ERROR_NOT_ENOUGH_MEMORY;
|
| 95 |
+
goto out;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
for (UINT32 i = 0; i < count; i++)
|
| 99 |
+
{
|
| 100 |
+
FILEDESCRIPTORW* file = &((*file_descriptor_array)[i]);
|
| 101 |
+
|
| 102 |
+
if (!cliprdr_read_filedescriptor(s, file))
|
| 103 |
+
goto out;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
if (Stream_GetRemainingLength(s) > 0)
|
| 107 |
+
WLog_WARN(TAG, "packed file list has %" PRIuz " excess bytes",
|
| 108 |
+
Stream_GetRemainingLength(s));
|
| 109 |
+
out:
|
| 110 |
+
|
| 111 |
+
return result;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
BOOL cliprdr_read_filedescriptor(wStream* s, FILEDESCRIPTORW* file)
|
| 115 |
+
{
|
| 116 |
+
UINT64 tmp = 0;
|
| 117 |
+
WINPR_ASSERT(file);
|
| 118 |
+
|
| 119 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, sizeof(FILEDESCRIPTORW)))
|
| 120 |
+
return FALSE;
|
| 121 |
+
|
| 122 |
+
Stream_Read_UINT32(s, file->dwFlags); /* flags (4 bytes) */
|
| 123 |
+
Stream_Read_UINT32(s, file->clsid.Data1);
|
| 124 |
+
Stream_Read_UINT16(s, file->clsid.Data2);
|
| 125 |
+
Stream_Read_UINT16(s, file->clsid.Data3);
|
| 126 |
+
Stream_Read(s, &file->clsid.Data4, sizeof(file->clsid.Data4));
|
| 127 |
+
Stream_Read_INT32(s, file->sizel.cx);
|
| 128 |
+
Stream_Read_INT32(s, file->sizel.cy);
|
| 129 |
+
Stream_Read_INT32(s, file->pointl.x);
|
| 130 |
+
Stream_Read_INT32(s, file->pointl.y);
|
| 131 |
+
Stream_Read_UINT32(s, file->dwFileAttributes); /* fileAttributes (4 bytes) */
|
| 132 |
+
Stream_Read_UINT64(s, tmp); /* ftCreationTime (8 bytes) */
|
| 133 |
+
file->ftCreationTime = uint64_to_filetime(tmp);
|
| 134 |
+
Stream_Read_UINT64(s, tmp); /* ftLastAccessTime (8 bytes) */
|
| 135 |
+
file->ftLastAccessTime = uint64_to_filetime(tmp);
|
| 136 |
+
Stream_Read_UINT64(s, tmp); /* lastWriteTime (8 bytes) */
|
| 137 |
+
file->ftLastWriteTime = uint64_to_filetime(tmp);
|
| 138 |
+
Stream_Read_UINT32(s, file->nFileSizeHigh); /* fileSizeHigh (4 bytes) */
|
| 139 |
+
Stream_Read_UINT32(s, file->nFileSizeLow); /* fileSizeLow (4 bytes) */
|
| 140 |
+
Stream_Read_UTF16_String(s, file->cFileName,
|
| 141 |
+
ARRAYSIZE(file->cFileName)); /* cFileName (520 bytes) */
|
| 142 |
+
return TRUE;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
BOOL cliprdr_write_filedescriptor(wStream* s, const FILEDESCRIPTORW* file)
|
| 146 |
+
{
|
| 147 |
+
WINPR_ASSERT(file);
|
| 148 |
+
|
| 149 |
+
if (!Stream_EnsureRemainingCapacity(s, sizeof(FILEDESCRIPTORW)))
|
| 150 |
+
return FALSE;
|
| 151 |
+
|
| 152 |
+
Stream_Write_UINT32(s, file->dwFlags); /* flags (4 bytes) */
|
| 153 |
+
|
| 154 |
+
Stream_Write_UINT32(s, file->clsid.Data1);
|
| 155 |
+
Stream_Write_UINT16(s, file->clsid.Data2);
|
| 156 |
+
Stream_Write_UINT16(s, file->clsid.Data3);
|
| 157 |
+
Stream_Write(s, &file->clsid.Data4, sizeof(file->clsid.Data4));
|
| 158 |
+
Stream_Write_INT32(s, file->sizel.cx);
|
| 159 |
+
Stream_Write_INT32(s, file->sizel.cy);
|
| 160 |
+
Stream_Write_INT32(s, file->pointl.x);
|
| 161 |
+
Stream_Write_INT32(s, file->pointl.y);
|
| 162 |
+
Stream_Write_UINT32(s, file->dwFileAttributes); /* fileAttributes (4 bytes) */
|
| 163 |
+
Stream_Write_UINT64(s, filetime_to_uint64(file->ftCreationTime));
|
| 164 |
+
Stream_Write_UINT64(s, filetime_to_uint64(file->ftLastAccessTime));
|
| 165 |
+
Stream_Write_UINT64(s, filetime_to_uint64(file->ftLastWriteTime)); /* lastWriteTime (8 bytes) */
|
| 166 |
+
Stream_Write_UINT32(s, file->nFileSizeHigh); /* fileSizeHigh (4 bytes) */
|
| 167 |
+
Stream_Write_UINT32(s, file->nFileSizeLow); /* fileSizeLow (4 bytes) */
|
| 168 |
+
Stream_Write_UTF16_String(s, file->cFileName,
|
| 169 |
+
ARRAYSIZE(file->cFileName)); /* cFileName (520 bytes) */
|
| 170 |
+
return TRUE;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Serialize a packed file list.
|
| 175 |
+
*
|
| 176 |
+
* The resulting format data must be freed with the `free()` function.
|
| 177 |
+
*
|
| 178 |
+
* @param [in] file_descriptor_array array of `FILEDESCRIPTOR` structs to serialize.
|
| 179 |
+
* @param [in] file_descriptor_count number of elements in `file_descriptor_array`.
|
| 180 |
+
* @param [out] format_data serialized CLIPRDR_FILELIST.
|
| 181 |
+
* @param [out] format_data_length length of `format_data` in bytes.
|
| 182 |
+
*
|
| 183 |
+
* @returns 0 on success, otherwise a Win32 error code.
|
| 184 |
+
*/
|
| 185 |
+
UINT cliprdr_serialize_file_list(const FILEDESCRIPTORW* file_descriptor_array,
|
| 186 |
+
UINT32 file_descriptor_count, BYTE** format_data,
|
| 187 |
+
UINT32* format_data_length)
|
| 188 |
+
{
|
| 189 |
+
return cliprdr_serialize_file_list_ex(CB_STREAM_FILECLIP_ENABLED, file_descriptor_array,
|
| 190 |
+
file_descriptor_count, format_data, format_data_length);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
UINT cliprdr_serialize_file_list_ex(UINT32 flags, const FILEDESCRIPTORW* file_descriptor_array,
|
| 194 |
+
UINT32 file_descriptor_count, BYTE** format_data,
|
| 195 |
+
UINT32* format_data_length)
|
| 196 |
+
{
|
| 197 |
+
UINT result = NO_ERROR;
|
| 198 |
+
size_t len = 0;
|
| 199 |
+
wStream* s = NULL;
|
| 200 |
+
|
| 201 |
+
if (!file_descriptor_array || !format_data || !format_data_length)
|
| 202 |
+
return ERROR_BAD_ARGUMENTS;
|
| 203 |
+
|
| 204 |
+
if ((flags & CB_STREAM_FILECLIP_ENABLED) == 0)
|
| 205 |
+
{
|
| 206 |
+
WLog_WARN(TAG, "No file clipboard support annouonced!");
|
| 207 |
+
return ERROR_BAD_ARGUMENTS;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
s = Stream_New(NULL, 4 + file_descriptor_count * CLIPRDR_FILEDESCRIPTOR_SIZE);
|
| 211 |
+
if (!s)
|
| 212 |
+
return ERROR_NOT_ENOUGH_MEMORY;
|
| 213 |
+
|
| 214 |
+
Stream_Write_UINT32(s, file_descriptor_count); /* cItems (4 bytes) */
|
| 215 |
+
|
| 216 |
+
for (UINT32 i = 0; i < file_descriptor_count; i++)
|
| 217 |
+
{
|
| 218 |
+
const FILEDESCRIPTORW* file = &file_descriptor_array[i];
|
| 219 |
+
|
| 220 |
+
/*
|
| 221 |
+
* There is a known issue with Windows server getting stuck in
|
| 222 |
+
* an infinite loop when downloading files that are larger than
|
| 223 |
+
* 2 gigabytes. Do not allow clients to send such file lists.
|
| 224 |
+
*
|
| 225 |
+
* https://support.microsoft.com/en-us/help/2258090
|
| 226 |
+
*/
|
| 227 |
+
if ((flags & CB_HUGE_FILE_SUPPORT_ENABLED) == 0)
|
| 228 |
+
{
|
| 229 |
+
if ((file->nFileSizeHigh > 0) || (file->nFileSizeLow >= CLIPRDR_MAX_FILE_SIZE))
|
| 230 |
+
{
|
| 231 |
+
WLog_ERR(TAG, "cliprdr does not support files over 2 GB");
|
| 232 |
+
result = ERROR_FILE_TOO_LARGE;
|
| 233 |
+
goto error;
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
if (!cliprdr_write_filedescriptor(s, file))
|
| 238 |
+
goto error;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
Stream_SealLength(s);
|
| 242 |
+
|
| 243 |
+
Stream_GetBuffer(s, *format_data);
|
| 244 |
+
Stream_GetLength(s, len);
|
| 245 |
+
if (len > UINT32_MAX)
|
| 246 |
+
goto error;
|
| 247 |
+
|
| 248 |
+
*format_data_length = (UINT32)len;
|
| 249 |
+
|
| 250 |
+
Stream_Free(s, FALSE);
|
| 251 |
+
|
| 252 |
+
return result;
|
| 253 |
+
|
| 254 |
+
error:
|
| 255 |
+
Stream_Free(s, TRUE);
|
| 256 |
+
|
| 257 |
+
return result;
|
| 258 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/http.c
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Simple HTTP client request utility
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2023 Isaac Klein <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
#include <freerdp/utils/http.h>
|
| 22 |
+
|
| 23 |
+
#include <winpr/assert.h>
|
| 24 |
+
#include <winpr/string.h>
|
| 25 |
+
|
| 26 |
+
#include <openssl/bio.h>
|
| 27 |
+
#include <openssl/ssl.h>
|
| 28 |
+
#include <openssl/err.h>
|
| 29 |
+
|
| 30 |
+
#include <freerdp/log.h>
|
| 31 |
+
#define TAG FREERDP_TAG("utils.http")
|
| 32 |
+
|
| 33 |
+
static const char get_header_fmt[] = "GET %s HTTP/1.1\r\n"
|
| 34 |
+
"Host: %s\r\n"
|
| 35 |
+
"\r\n";
|
| 36 |
+
|
| 37 |
+
static const char post_header_fmt[] = "POST %s HTTP/1.1\r\n"
|
| 38 |
+
"Host: %s\r\n"
|
| 39 |
+
"Content-Type: application/x-www-form-urlencoded\r\n"
|
| 40 |
+
"Content-Length: %lu\r\n"
|
| 41 |
+
"\r\n";
|
| 42 |
+
|
| 43 |
+
#define log_errors(log, msg) log_errors_(log, msg, __FILE__, __func__, __LINE__)
|
| 44 |
+
static void log_errors_(wLog* log, const char* msg, const char* file, const char* fkt, size_t line)
|
| 45 |
+
{
|
| 46 |
+
const DWORD level = WLOG_ERROR;
|
| 47 |
+
unsigned long ec = 0;
|
| 48 |
+
|
| 49 |
+
if (!WLog_IsLevelActive(log, level))
|
| 50 |
+
return;
|
| 51 |
+
|
| 52 |
+
BOOL error_logged = FALSE;
|
| 53 |
+
while ((ec = ERR_get_error()))
|
| 54 |
+
{
|
| 55 |
+
error_logged = TRUE;
|
| 56 |
+
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, "%s: %s", msg,
|
| 57 |
+
ERR_error_string(ec, NULL));
|
| 58 |
+
}
|
| 59 |
+
if (!error_logged)
|
| 60 |
+
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt,
|
| 61 |
+
"%s (no details available)", msg);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
static int get_line(BIO* bio, char* buffer, size_t size)
|
| 65 |
+
{
|
| 66 |
+
#if !defined(OPENSSL_VERSION_MAJOR) || (OPENSSL_VERSION_MAJOR < 3)
|
| 67 |
+
if (size <= 1)
|
| 68 |
+
return -1;
|
| 69 |
+
|
| 70 |
+
size_t pos = 0;
|
| 71 |
+
do
|
| 72 |
+
{
|
| 73 |
+
int rc = BIO_read(bio, &buffer[pos], 1);
|
| 74 |
+
if (rc <= 0)
|
| 75 |
+
return rc;
|
| 76 |
+
char cur = buffer[pos];
|
| 77 |
+
pos += rc;
|
| 78 |
+
if ((cur == '\n') || (pos >= size - 1))
|
| 79 |
+
{
|
| 80 |
+
buffer[pos] = '\0';
|
| 81 |
+
return (int)pos;
|
| 82 |
+
}
|
| 83 |
+
} while (1);
|
| 84 |
+
#else
|
| 85 |
+
if (size > INT32_MAX)
|
| 86 |
+
return -1;
|
| 87 |
+
return BIO_get_line(bio, buffer, (int)size);
|
| 88 |
+
#endif
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
BOOL freerdp_http_request(const char* url, const char* body, long* status_code, BYTE** response,
|
| 92 |
+
size_t* response_length)
|
| 93 |
+
{
|
| 94 |
+
BOOL ret = FALSE;
|
| 95 |
+
char* hostname = NULL;
|
| 96 |
+
const char* path = NULL;
|
| 97 |
+
char* headers = NULL;
|
| 98 |
+
size_t size = 0;
|
| 99 |
+
int status = 0;
|
| 100 |
+
char buffer[1024] = { 0 };
|
| 101 |
+
BIO* bio = NULL;
|
| 102 |
+
SSL_CTX* ssl_ctx = NULL;
|
| 103 |
+
SSL* ssl = NULL;
|
| 104 |
+
|
| 105 |
+
WINPR_ASSERT(status_code);
|
| 106 |
+
WINPR_ASSERT(response);
|
| 107 |
+
WINPR_ASSERT(response_length);
|
| 108 |
+
|
| 109 |
+
wLog* log = WLog_Get(TAG);
|
| 110 |
+
WINPR_ASSERT(log);
|
| 111 |
+
|
| 112 |
+
*response = NULL;
|
| 113 |
+
|
| 114 |
+
if (!url || strnlen(url, 8) < 8 || strncmp(url, "https://", 8) != 0 ||
|
| 115 |
+
!(path = strchr(url + 8, '/')))
|
| 116 |
+
{
|
| 117 |
+
WLog_Print(log, WLOG_ERROR, "invalid url provided");
|
| 118 |
+
goto out;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
const size_t len = WINPR_ASSERTING_INT_CAST(size_t, path - (url + 8));
|
| 122 |
+
hostname = strndup(&url[8], len);
|
| 123 |
+
if (!hostname)
|
| 124 |
+
return FALSE;
|
| 125 |
+
|
| 126 |
+
size_t blen = 0;
|
| 127 |
+
if (body)
|
| 128 |
+
{
|
| 129 |
+
blen = strlen(body);
|
| 130 |
+
if (winpr_asprintf(&headers, &size, post_header_fmt, path, hostname, blen) < 0)
|
| 131 |
+
{
|
| 132 |
+
free(hostname);
|
| 133 |
+
return FALSE;
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
else
|
| 137 |
+
{
|
| 138 |
+
if (winpr_asprintf(&headers, &size, get_header_fmt, path, hostname) < 0)
|
| 139 |
+
{
|
| 140 |
+
free(hostname);
|
| 141 |
+
return FALSE;
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
ssl_ctx = SSL_CTX_new(TLS_client_method());
|
| 146 |
+
|
| 147 |
+
if (!ssl_ctx)
|
| 148 |
+
{
|
| 149 |
+
log_errors(log, "could not set up ssl context");
|
| 150 |
+
goto out;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (!SSL_CTX_set_default_verify_paths(ssl_ctx))
|
| 154 |
+
{
|
| 155 |
+
log_errors(log, "could not set ssl context verify paths");
|
| 156 |
+
goto out;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
|
| 160 |
+
|
| 161 |
+
bio = BIO_new_ssl_connect(ssl_ctx);
|
| 162 |
+
if (!bio)
|
| 163 |
+
{
|
| 164 |
+
log_errors(log, "could not set up connection");
|
| 165 |
+
goto out;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
if (BIO_set_conn_port(bio, "https") <= 0)
|
| 169 |
+
{
|
| 170 |
+
log_errors(log, "could not set port");
|
| 171 |
+
goto out;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (!BIO_set_conn_hostname(bio, hostname))
|
| 175 |
+
{
|
| 176 |
+
log_errors(log, "could not set hostname");
|
| 177 |
+
goto out;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
BIO_get_ssl(bio, &ssl);
|
| 181 |
+
if (!ssl)
|
| 182 |
+
{
|
| 183 |
+
log_errors(log, "could not get ssl");
|
| 184 |
+
goto out;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if (!SSL_set_tlsext_host_name(ssl, hostname))
|
| 188 |
+
{
|
| 189 |
+
log_errors(log, "could not set sni hostname");
|
| 190 |
+
goto out;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
WLog_Print(log, WLOG_DEBUG, "headers:\n%s", headers);
|
| 194 |
+
ERR_clear_error();
|
| 195 |
+
const size_t hlen = strnlen(headers, size);
|
| 196 |
+
if (hlen > INT32_MAX)
|
| 197 |
+
goto out;
|
| 198 |
+
|
| 199 |
+
if (BIO_write(bio, headers, (int)hlen) < 0)
|
| 200 |
+
{
|
| 201 |
+
log_errors(log, "could not write headers");
|
| 202 |
+
goto out;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
if (body)
|
| 206 |
+
{
|
| 207 |
+
WLog_Print(log, WLOG_DEBUG, "body:\n%s", body);
|
| 208 |
+
|
| 209 |
+
if (blen > INT_MAX)
|
| 210 |
+
{
|
| 211 |
+
WLog_Print(log, WLOG_ERROR, "body too long!");
|
| 212 |
+
goto out;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
ERR_clear_error();
|
| 216 |
+
if (BIO_write(bio, body, (int)blen) < 0)
|
| 217 |
+
{
|
| 218 |
+
log_errors(log, "could not write body");
|
| 219 |
+
goto out;
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
status = get_line(bio, buffer, sizeof(buffer));
|
| 224 |
+
if (status <= 0)
|
| 225 |
+
{
|
| 226 |
+
log_errors(log, "could not read response");
|
| 227 |
+
goto out;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// NOLINTNEXTLINE(cert-err34-c)
|
| 231 |
+
if (sscanf(buffer, "HTTP/1.1 %li %*[^\r\n]\r\n", status_code) < 1)
|
| 232 |
+
{
|
| 233 |
+
WLog_Print(log, WLOG_ERROR, "invalid HTTP status line");
|
| 234 |
+
goto out;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
do
|
| 238 |
+
{
|
| 239 |
+
status = get_line(bio, buffer, sizeof(buffer));
|
| 240 |
+
if (status <= 0)
|
| 241 |
+
{
|
| 242 |
+
log_errors(log, "could not read response");
|
| 243 |
+
goto out;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
char* val = NULL;
|
| 247 |
+
char* name = strtok_s(buffer, ":", &val);
|
| 248 |
+
if (name && (_stricmp(name, "content-length") == 0))
|
| 249 |
+
{
|
| 250 |
+
errno = 0;
|
| 251 |
+
*response_length = strtoul(val, NULL, 10);
|
| 252 |
+
if (errno)
|
| 253 |
+
{
|
| 254 |
+
char ebuffer[256] = { 0 };
|
| 255 |
+
WLog_Print(log, WLOG_ERROR, "could not parse content length (%s): %s [%d]", val,
|
| 256 |
+
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
| 257 |
+
goto out;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
} while (strcmp(buffer, "\r\n") != 0);
|
| 261 |
+
|
| 262 |
+
if (*response_length > 0)
|
| 263 |
+
{
|
| 264 |
+
if (*response_length > INT_MAX)
|
| 265 |
+
{
|
| 266 |
+
WLog_Print(log, WLOG_ERROR, "response too long!");
|
| 267 |
+
goto out;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
*response = calloc(1, *response_length + 1);
|
| 271 |
+
if (!*response)
|
| 272 |
+
goto out;
|
| 273 |
+
|
| 274 |
+
BYTE* p = *response;
|
| 275 |
+
size_t left = *response_length;
|
| 276 |
+
while (left > 0)
|
| 277 |
+
{
|
| 278 |
+
const int rd = (left < INT32_MAX) ? (int)left : INT32_MAX;
|
| 279 |
+
status = BIO_read(bio, p, rd);
|
| 280 |
+
if (status <= 0)
|
| 281 |
+
{
|
| 282 |
+
log_errors(log, "could not read response");
|
| 283 |
+
goto out;
|
| 284 |
+
}
|
| 285 |
+
p += status;
|
| 286 |
+
if ((size_t)status > left)
|
| 287 |
+
break;
|
| 288 |
+
left -= (size_t)status;
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
ret = TRUE;
|
| 293 |
+
|
| 294 |
+
out:
|
| 295 |
+
if (!ret)
|
| 296 |
+
{
|
| 297 |
+
free(*response);
|
| 298 |
+
*response = NULL;
|
| 299 |
+
*response_length = 0;
|
| 300 |
+
}
|
| 301 |
+
free(hostname);
|
| 302 |
+
free(headers);
|
| 303 |
+
BIO_free_all(bio);
|
| 304 |
+
SSL_CTX_free(ssl_ctx);
|
| 305 |
+
return ret;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
const char* freerdp_http_status_string(long status)
|
| 309 |
+
{
|
| 310 |
+
switch (status)
|
| 311 |
+
{
|
| 312 |
+
case HTTP_STATUS_CONTINUE:
|
| 313 |
+
return "HTTP_STATUS_CONTINUE";
|
| 314 |
+
case HTTP_STATUS_SWITCH_PROTOCOLS:
|
| 315 |
+
return "HTTP_STATUS_SWITCH_PROTOCOLS";
|
| 316 |
+
case HTTP_STATUS_OK:
|
| 317 |
+
return "HTTP_STATUS_OK";
|
| 318 |
+
case HTTP_STATUS_CREATED:
|
| 319 |
+
return "HTTP_STATUS_CREATED";
|
| 320 |
+
case HTTP_STATUS_ACCEPTED:
|
| 321 |
+
return "HTTP_STATUS_ACCEPTED";
|
| 322 |
+
case HTTP_STATUS_PARTIAL:
|
| 323 |
+
return "HTTP_STATUS_PARTIAL";
|
| 324 |
+
case HTTP_STATUS_NO_CONTENT:
|
| 325 |
+
return "HTTP_STATUS_NO_CONTENT";
|
| 326 |
+
case HTTP_STATUS_RESET_CONTENT:
|
| 327 |
+
return "HTTP_STATUS_RESET_CONTENT";
|
| 328 |
+
case HTTP_STATUS_PARTIAL_CONTENT:
|
| 329 |
+
return "HTTP_STATUS_PARTIAL_CONTENT";
|
| 330 |
+
case HTTP_STATUS_WEBDAV_MULTI_STATUS:
|
| 331 |
+
return "HTTP_STATUS_WEBDAV_MULTI_STATUS";
|
| 332 |
+
case HTTP_STATUS_AMBIGUOUS:
|
| 333 |
+
return "HTTP_STATUS_AMBIGUOUS";
|
| 334 |
+
case HTTP_STATUS_MOVED:
|
| 335 |
+
return "HTTP_STATUS_MOVED";
|
| 336 |
+
case HTTP_STATUS_REDIRECT:
|
| 337 |
+
return "HTTP_STATUS_REDIRECT";
|
| 338 |
+
case HTTP_STATUS_REDIRECT_METHOD:
|
| 339 |
+
return "HTTP_STATUS_REDIRECT_METHOD";
|
| 340 |
+
case HTTP_STATUS_NOT_MODIFIED:
|
| 341 |
+
return "HTTP_STATUS_NOT_MODIFIED";
|
| 342 |
+
case HTTP_STATUS_USE_PROXY:
|
| 343 |
+
return "HTTP_STATUS_USE_PROXY";
|
| 344 |
+
case HTTP_STATUS_REDIRECT_KEEP_VERB:
|
| 345 |
+
return "HTTP_STATUS_REDIRECT_KEEP_VERB";
|
| 346 |
+
case HTTP_STATUS_BAD_REQUEST:
|
| 347 |
+
return "HTTP_STATUS_BAD_REQUEST";
|
| 348 |
+
case HTTP_STATUS_DENIED:
|
| 349 |
+
return "HTTP_STATUS_DENIED";
|
| 350 |
+
case HTTP_STATUS_PAYMENT_REQ:
|
| 351 |
+
return "HTTP_STATUS_PAYMENT_REQ";
|
| 352 |
+
case HTTP_STATUS_FORBIDDEN:
|
| 353 |
+
return "HTTP_STATUS_FORBIDDEN";
|
| 354 |
+
case HTTP_STATUS_NOT_FOUND:
|
| 355 |
+
return "HTTP_STATUS_NOT_FOUND";
|
| 356 |
+
case HTTP_STATUS_BAD_METHOD:
|
| 357 |
+
return "HTTP_STATUS_BAD_METHOD";
|
| 358 |
+
case HTTP_STATUS_NONE_ACCEPTABLE:
|
| 359 |
+
return "HTTP_STATUS_NONE_ACCEPTABLE";
|
| 360 |
+
case HTTP_STATUS_PROXY_AUTH_REQ:
|
| 361 |
+
return "HTTP_STATUS_PROXY_AUTH_REQ";
|
| 362 |
+
case HTTP_STATUS_REQUEST_TIMEOUT:
|
| 363 |
+
return "HTTP_STATUS_REQUEST_TIMEOUT";
|
| 364 |
+
case HTTP_STATUS_CONFLICT:
|
| 365 |
+
return "HTTP_STATUS_CONFLICT";
|
| 366 |
+
case HTTP_STATUS_GONE:
|
| 367 |
+
return "HTTP_STATUS_GONE";
|
| 368 |
+
case HTTP_STATUS_LENGTH_REQUIRED:
|
| 369 |
+
return "HTTP_STATUS_LENGTH_REQUIRED";
|
| 370 |
+
case HTTP_STATUS_PRECOND_FAILED:
|
| 371 |
+
return "HTTP_STATUS_PRECOND_FAILED";
|
| 372 |
+
case HTTP_STATUS_REQUEST_TOO_LARGE:
|
| 373 |
+
return "HTTP_STATUS_REQUEST_TOO_LARGE";
|
| 374 |
+
case HTTP_STATUS_URI_TOO_LONG:
|
| 375 |
+
return "HTTP_STATUS_URI_TOO_LONG";
|
| 376 |
+
case HTTP_STATUS_UNSUPPORTED_MEDIA:
|
| 377 |
+
return "HTTP_STATUS_UNSUPPORTED_MEDIA";
|
| 378 |
+
case HTTP_STATUS_RETRY_WITH:
|
| 379 |
+
return "HTTP_STATUS_RETRY_WITH";
|
| 380 |
+
case HTTP_STATUS_SERVER_ERROR:
|
| 381 |
+
return "HTTP_STATUS_SERVER_ERROR";
|
| 382 |
+
case HTTP_STATUS_NOT_SUPPORTED:
|
| 383 |
+
return "HTTP_STATUS_NOT_SUPPORTED";
|
| 384 |
+
case HTTP_STATUS_BAD_GATEWAY:
|
| 385 |
+
return "HTTP_STATUS_BAD_GATEWAY";
|
| 386 |
+
case HTTP_STATUS_SERVICE_UNAVAIL:
|
| 387 |
+
return "HTTP_STATUS_SERVICE_UNAVAIL";
|
| 388 |
+
case HTTP_STATUS_GATEWAY_TIMEOUT:
|
| 389 |
+
return "HTTP_STATUS_GATEWAY_TIMEOUT";
|
| 390 |
+
case HTTP_STATUS_VERSION_NOT_SUP:
|
| 391 |
+
return "HTTP_STATUS_VERSION_NOT_SUP";
|
| 392 |
+
default:
|
| 393 |
+
return "HTTP_STATUS_UNKNOWN";
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
const char* freerdp_http_status_string_format(long status, char* buffer, size_t size)
|
| 398 |
+
{
|
| 399 |
+
const char* code = freerdp_http_status_string(status);
|
| 400 |
+
(void)_snprintf(buffer, size, "%s [%ld]", code, status);
|
| 401 |
+
return buffer;
|
| 402 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/profiler.c
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Profiler Utils
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Stephen Erisman
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stdio.h>
|
| 23 |
+
#include <stdlib.h>
|
| 24 |
+
|
| 25 |
+
#include <freerdp/utils/profiler.h>
|
| 26 |
+
#include <freerdp/log.h>
|
| 27 |
+
|
| 28 |
+
#define TAG FREERDP_TAG("utils")
|
| 29 |
+
|
| 30 |
+
struct S_PROFILER
|
| 31 |
+
{
|
| 32 |
+
char* name;
|
| 33 |
+
STOPWATCH* stopwatch;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
PROFILER* profiler_create(const char* name)
|
| 37 |
+
{
|
| 38 |
+
PROFILER* profiler = (PROFILER*)calloc(1, sizeof(PROFILER));
|
| 39 |
+
|
| 40 |
+
if (!profiler)
|
| 41 |
+
return NULL;
|
| 42 |
+
|
| 43 |
+
profiler->name = _strdup(name);
|
| 44 |
+
profiler->stopwatch = stopwatch_create();
|
| 45 |
+
|
| 46 |
+
if (!profiler->name || !profiler->stopwatch)
|
| 47 |
+
goto fail;
|
| 48 |
+
|
| 49 |
+
return profiler;
|
| 50 |
+
fail:
|
| 51 |
+
profiler_free(profiler);
|
| 52 |
+
return NULL;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void profiler_free(PROFILER* profiler)
|
| 56 |
+
{
|
| 57 |
+
if (profiler)
|
| 58 |
+
{
|
| 59 |
+
free(profiler->name);
|
| 60 |
+
stopwatch_free(profiler->stopwatch);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
free(profiler);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void profiler_enter(PROFILER* profiler)
|
| 67 |
+
{
|
| 68 |
+
stopwatch_start(profiler->stopwatch);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void profiler_exit(PROFILER* profiler)
|
| 72 |
+
{
|
| 73 |
+
stopwatch_stop(profiler->stopwatch);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void profiler_print_header(void)
|
| 77 |
+
{
|
| 78 |
+
WLog_INFO(TAG,
|
| 79 |
+
"-------------------------------+------------+-------------+-----------+-------");
|
| 80 |
+
WLog_INFO(TAG,
|
| 81 |
+
"PROFILER NAME | COUNT | TOTAL | AVG | IPS");
|
| 82 |
+
WLog_INFO(TAG,
|
| 83 |
+
"-------------------------------+------------+-------------+-----------+-------");
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void profiler_print(PROFILER* profiler)
|
| 87 |
+
{
|
| 88 |
+
double s = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
|
| 89 |
+
double avg = profiler->stopwatch->count == 0 ? 0 : s / profiler->stopwatch->count;
|
| 90 |
+
WLog_INFO(TAG, "%-30s | %10u | %10.4fs | %8.6fs | %6.0f", profiler->name,
|
| 91 |
+
profiler->stopwatch->count, s, avg, profiler->stopwatch->count / s);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
void profiler_print_footer(void)
|
| 95 |
+
{
|
| 96 |
+
WLog_INFO(TAG,
|
| 97 |
+
"-------------------------------+------------+-------------+-----------+-------");
|
| 98 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/rdpdr_utils.c
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* SCard utility functions
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2021 Armin Novak <[email protected]>
|
| 6 |
+
* Copyright 2021 Thincast Technologies GmbH
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <winpr/wlog.h>
|
| 22 |
+
#include <winpr/print.h>
|
| 23 |
+
#include <winpr/smartcard.h>
|
| 24 |
+
|
| 25 |
+
#include <freerdp/utils/rdpdr_utils.h>
|
| 26 |
+
#include <freerdp/channels/scard.h>
|
| 27 |
+
#include <freerdp/channels/rdpdr.h>
|
| 28 |
+
|
| 29 |
+
#include <freerdp/log.h>
|
| 30 |
+
|
| 31 |
+
LONG scard_log_status_error(const char* tag, const char* what, LONG status)
|
| 32 |
+
{
|
| 33 |
+
if (status != SCARD_S_SUCCESS)
|
| 34 |
+
{
|
| 35 |
+
DWORD level = WLOG_ERROR;
|
| 36 |
+
switch (status)
|
| 37 |
+
{
|
| 38 |
+
case SCARD_E_TIMEOUT:
|
| 39 |
+
level = WLOG_DEBUG;
|
| 40 |
+
break;
|
| 41 |
+
case SCARD_E_NO_READERS_AVAILABLE:
|
| 42 |
+
level = WLOG_INFO;
|
| 43 |
+
break;
|
| 44 |
+
default:
|
| 45 |
+
break;
|
| 46 |
+
}
|
| 47 |
+
WLog_Print(WLog_Get(tag), level, "%s failed with error %s [%" PRId32 "]", what,
|
| 48 |
+
SCardGetErrorString(status), status);
|
| 49 |
+
}
|
| 50 |
+
return status;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
const char* scard_get_ioctl_string(UINT32 ioControlCode, BOOL funcName)
|
| 54 |
+
{
|
| 55 |
+
switch (ioControlCode)
|
| 56 |
+
{
|
| 57 |
+
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
| 58 |
+
return funcName ? "SCardEstablishContext" : "SCARD_IOCTL_ESTABLISHCONTEXT";
|
| 59 |
+
|
| 60 |
+
case SCARD_IOCTL_RELEASECONTEXT:
|
| 61 |
+
return funcName ? "SCardReleaseContext" : "SCARD_IOCTL_RELEASECONTEXT";
|
| 62 |
+
|
| 63 |
+
case SCARD_IOCTL_ISVALIDCONTEXT:
|
| 64 |
+
return funcName ? "SCardIsValidContext" : "SCARD_IOCTL_ISVALIDCONTEXT";
|
| 65 |
+
|
| 66 |
+
case SCARD_IOCTL_LISTREADERGROUPSA:
|
| 67 |
+
return funcName ? "SCardListReaderGroupsA" : "SCARD_IOCTL_LISTREADERGROUPSA";
|
| 68 |
+
|
| 69 |
+
case SCARD_IOCTL_LISTREADERGROUPSW:
|
| 70 |
+
return funcName ? "SCardListReaderGroupsW" : "SCARD_IOCTL_LISTREADERGROUPSW";
|
| 71 |
+
|
| 72 |
+
case SCARD_IOCTL_LISTREADERSA:
|
| 73 |
+
return funcName ? "SCardListReadersA" : "SCARD_IOCTL_LISTREADERSA";
|
| 74 |
+
|
| 75 |
+
case SCARD_IOCTL_LISTREADERSW:
|
| 76 |
+
return funcName ? "SCardListReadersW" : "SCARD_IOCTL_LISTREADERSW";
|
| 77 |
+
|
| 78 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
| 79 |
+
return funcName ? "SCardIntroduceReaderGroupA" : "SCARD_IOCTL_INTRODUCEREADERGROUPA";
|
| 80 |
+
|
| 81 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
| 82 |
+
return funcName ? "SCardIntroduceReaderGroupW" : "SCARD_IOCTL_INTRODUCEREADERGROUPW";
|
| 83 |
+
|
| 84 |
+
case SCARD_IOCTL_FORGETREADERGROUPA:
|
| 85 |
+
return funcName ? "SCardForgetReaderGroupA" : "SCARD_IOCTL_FORGETREADERGROUPA";
|
| 86 |
+
|
| 87 |
+
case SCARD_IOCTL_FORGETREADERGROUPW:
|
| 88 |
+
return funcName ? "SCardForgetReaderGroupW" : "SCARD_IOCTL_FORGETREADERGROUPW";
|
| 89 |
+
|
| 90 |
+
case SCARD_IOCTL_INTRODUCEREADERA:
|
| 91 |
+
return funcName ? "SCardIntroduceReaderA" : "SCARD_IOCTL_INTRODUCEREADERA";
|
| 92 |
+
|
| 93 |
+
case SCARD_IOCTL_INTRODUCEREADERW:
|
| 94 |
+
return funcName ? "SCardIntroduceReaderW" : "SCARD_IOCTL_INTRODUCEREADERW";
|
| 95 |
+
|
| 96 |
+
case SCARD_IOCTL_FORGETREADERA:
|
| 97 |
+
return funcName ? "SCardForgetReaderA" : "SCARD_IOCTL_FORGETREADERA";
|
| 98 |
+
|
| 99 |
+
case SCARD_IOCTL_FORGETREADERW:
|
| 100 |
+
return funcName ? "SCardForgetReaderW" : "SCARD_IOCTL_FORGETREADERW";
|
| 101 |
+
|
| 102 |
+
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
| 103 |
+
return funcName ? "SCardAddReaderToGroupA" : "SCARD_IOCTL_ADDREADERTOGROUPA";
|
| 104 |
+
|
| 105 |
+
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
| 106 |
+
return funcName ? "SCardAddReaderToGroupW" : "SCARD_IOCTL_ADDREADERTOGROUPW";
|
| 107 |
+
|
| 108 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
| 109 |
+
return funcName ? "SCardRemoveReaderFromGroupA" : "SCARD_IOCTL_REMOVEREADERFROMGROUPA";
|
| 110 |
+
|
| 111 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
| 112 |
+
return funcName ? "SCardRemoveReaderFromGroupW" : "SCARD_IOCTL_REMOVEREADERFROMGROUPW";
|
| 113 |
+
|
| 114 |
+
case SCARD_IOCTL_LOCATECARDSA:
|
| 115 |
+
return funcName ? "SCardLocateCardsA" : "SCARD_IOCTL_LOCATECARDSA";
|
| 116 |
+
|
| 117 |
+
case SCARD_IOCTL_LOCATECARDSW:
|
| 118 |
+
return funcName ? "SCardLocateCardsW" : "SCARD_IOCTL_LOCATECARDSW";
|
| 119 |
+
|
| 120 |
+
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
| 121 |
+
return funcName ? "SCardGetStatusChangeA" : "SCARD_IOCTL_GETSTATUSCHANGEA";
|
| 122 |
+
|
| 123 |
+
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
| 124 |
+
return funcName ? "SCardGetStatusChangeW" : "SCARD_IOCTL_GETSTATUSCHANGEW";
|
| 125 |
+
|
| 126 |
+
case SCARD_IOCTL_CANCEL:
|
| 127 |
+
return funcName ? "SCardCancel" : "SCARD_IOCTL_CANCEL";
|
| 128 |
+
|
| 129 |
+
case SCARD_IOCTL_CONNECTA:
|
| 130 |
+
return funcName ? "SCardConnectA" : "SCARD_IOCTL_CONNECTA";
|
| 131 |
+
|
| 132 |
+
case SCARD_IOCTL_CONNECTW:
|
| 133 |
+
return funcName ? "SCardConnectW" : "SCARD_IOCTL_CONNECTW";
|
| 134 |
+
|
| 135 |
+
case SCARD_IOCTL_RECONNECT:
|
| 136 |
+
return funcName ? "SCardReconnect" : "SCARD_IOCTL_RECONNECT";
|
| 137 |
+
|
| 138 |
+
case SCARD_IOCTL_DISCONNECT:
|
| 139 |
+
return funcName ? "SCardDisconnect" : "SCARD_IOCTL_DISCONNECT";
|
| 140 |
+
|
| 141 |
+
case SCARD_IOCTL_BEGINTRANSACTION:
|
| 142 |
+
return funcName ? "SCardBeginTransaction" : "SCARD_IOCTL_BEGINTRANSACTION";
|
| 143 |
+
|
| 144 |
+
case SCARD_IOCTL_ENDTRANSACTION:
|
| 145 |
+
return funcName ? "SCardEndTransaction" : "SCARD_IOCTL_ENDTRANSACTION";
|
| 146 |
+
|
| 147 |
+
case SCARD_IOCTL_STATE:
|
| 148 |
+
return funcName ? "SCardState" : "SCARD_IOCTL_STATE";
|
| 149 |
+
|
| 150 |
+
case SCARD_IOCTL_STATUSA:
|
| 151 |
+
return funcName ? "SCardStatusA" : "SCARD_IOCTL_STATUSA";
|
| 152 |
+
|
| 153 |
+
case SCARD_IOCTL_STATUSW:
|
| 154 |
+
return funcName ? "SCardStatusW" : "SCARD_IOCTL_STATUSW";
|
| 155 |
+
|
| 156 |
+
case SCARD_IOCTL_TRANSMIT:
|
| 157 |
+
return funcName ? "SCardTransmit" : "SCARD_IOCTL_TRANSMIT";
|
| 158 |
+
|
| 159 |
+
case SCARD_IOCTL_CONTROL:
|
| 160 |
+
return funcName ? "SCardControl" : "SCARD_IOCTL_CONTROL";
|
| 161 |
+
|
| 162 |
+
case SCARD_IOCTL_GETATTRIB:
|
| 163 |
+
return funcName ? "SCardGetAttrib" : "SCARD_IOCTL_GETATTRIB";
|
| 164 |
+
|
| 165 |
+
case SCARD_IOCTL_SETATTRIB:
|
| 166 |
+
return funcName ? "SCardSetAttrib" : "SCARD_IOCTL_SETATTRIB";
|
| 167 |
+
|
| 168 |
+
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
| 169 |
+
return funcName ? "SCardAccessStartedEvent" : "SCARD_IOCTL_ACCESSSTARTEDEVENT";
|
| 170 |
+
|
| 171 |
+
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
| 172 |
+
return funcName ? "SCardLocateCardsByATRA" : "SCARD_IOCTL_LOCATECARDSBYATRA";
|
| 173 |
+
|
| 174 |
+
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
| 175 |
+
return funcName ? "SCardLocateCardsByATRB" : "SCARD_IOCTL_LOCATECARDSBYATRW";
|
| 176 |
+
|
| 177 |
+
case SCARD_IOCTL_READCACHEA:
|
| 178 |
+
return funcName ? "SCardReadCacheA" : "SCARD_IOCTL_READCACHEA";
|
| 179 |
+
|
| 180 |
+
case SCARD_IOCTL_READCACHEW:
|
| 181 |
+
return funcName ? "SCardReadCacheW" : "SCARD_IOCTL_READCACHEW";
|
| 182 |
+
|
| 183 |
+
case SCARD_IOCTL_WRITECACHEA:
|
| 184 |
+
return funcName ? "SCardWriteCacheA" : "SCARD_IOCTL_WRITECACHEA";
|
| 185 |
+
|
| 186 |
+
case SCARD_IOCTL_WRITECACHEW:
|
| 187 |
+
return funcName ? "SCardWriteCacheW" : "SCARD_IOCTL_WRITECACHEW";
|
| 188 |
+
|
| 189 |
+
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
| 190 |
+
return funcName ? "SCardGetTransmitCount" : "SCARD_IOCTL_GETTRANSMITCOUNT";
|
| 191 |
+
|
| 192 |
+
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
| 193 |
+
return funcName ? "SCardReleaseStartedEvent" : "SCARD_IOCTL_RELEASETARTEDEVENT";
|
| 194 |
+
|
| 195 |
+
case SCARD_IOCTL_GETREADERICON:
|
| 196 |
+
return funcName ? "SCardGetReaderIcon" : "SCARD_IOCTL_GETREADERICON";
|
| 197 |
+
|
| 198 |
+
case SCARD_IOCTL_GETDEVICETYPEID:
|
| 199 |
+
return funcName ? "SCardGetDeviceTypeId" : "SCARD_IOCTL_GETDEVICETYPEID";
|
| 200 |
+
|
| 201 |
+
default:
|
| 202 |
+
return funcName ? "SCardUnknown" : "SCARD_IOCTL_UNKNOWN";
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
const char* rdpdr_component_string(UINT16 component)
|
| 207 |
+
{
|
| 208 |
+
switch (component)
|
| 209 |
+
{
|
| 210 |
+
case RDPDR_CTYP_PRN:
|
| 211 |
+
return "RDPDR_CTYP_PRN";
|
| 212 |
+
case RDPDR_CTYP_CORE:
|
| 213 |
+
return "RDPDR_CTYP_CORE";
|
| 214 |
+
default:
|
| 215 |
+
return "UNKNOWN";
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
const char* rdpdr_packetid_string(UINT16 packetid)
|
| 220 |
+
{
|
| 221 |
+
switch (packetid)
|
| 222 |
+
{
|
| 223 |
+
case PAKID_CORE_SERVER_ANNOUNCE:
|
| 224 |
+
return "PAKID_CORE_SERVER_ANNOUNCE";
|
| 225 |
+
case PAKID_CORE_CLIENTID_CONFIRM:
|
| 226 |
+
return "PAKID_CORE_CLIENTID_CONFIRM";
|
| 227 |
+
case PAKID_CORE_CLIENT_NAME:
|
| 228 |
+
return "PAKID_CORE_CLIENT_NAME";
|
| 229 |
+
case PAKID_CORE_DEVICELIST_ANNOUNCE:
|
| 230 |
+
return "PAKID_CORE_DEVICELIST_ANNOUNCE";
|
| 231 |
+
case PAKID_CORE_DEVICE_REPLY:
|
| 232 |
+
return "PAKID_CORE_DEVICE_REPLY";
|
| 233 |
+
case PAKID_CORE_DEVICE_IOREQUEST:
|
| 234 |
+
return "PAKID_CORE_DEVICE_IOREQUEST";
|
| 235 |
+
case PAKID_CORE_DEVICE_IOCOMPLETION:
|
| 236 |
+
return "PAKID_CORE_DEVICE_IOCOMPLETION";
|
| 237 |
+
case PAKID_CORE_SERVER_CAPABILITY:
|
| 238 |
+
return "PAKID_CORE_SERVER_CAPABILITY";
|
| 239 |
+
case PAKID_CORE_CLIENT_CAPABILITY:
|
| 240 |
+
return "PAKID_CORE_CLIENT_CAPABILITY";
|
| 241 |
+
case PAKID_CORE_DEVICELIST_REMOVE:
|
| 242 |
+
return "PAKID_CORE_DEVICELIST_REMOVE";
|
| 243 |
+
case PAKID_CORE_USER_LOGGEDON:
|
| 244 |
+
return "PAKID_CORE_USER_LOGGEDON";
|
| 245 |
+
case PAKID_PRN_CACHE_DATA:
|
| 246 |
+
return "PAKID_PRN_CACHE_DATA";
|
| 247 |
+
case PAKID_PRN_USING_XPS:
|
| 248 |
+
return "PAKID_PRN_USING_XPS";
|
| 249 |
+
default:
|
| 250 |
+
return "UNKNOWN";
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
BOOL rdpdr_write_iocompletion_header(wStream* out, UINT32 DeviceId, UINT32 CompletionId,
|
| 255 |
+
NTSTATUS ioStatus)
|
| 256 |
+
{
|
| 257 |
+
WINPR_ASSERT(out);
|
| 258 |
+
Stream_SetPosition(out, 0);
|
| 259 |
+
if (!Stream_EnsureRemainingCapacity(out, 16))
|
| 260 |
+
return FALSE;
|
| 261 |
+
Stream_Write_UINT16(out, RDPDR_CTYP_CORE); /* Component (2 bytes) */
|
| 262 |
+
Stream_Write_UINT16(out, PAKID_CORE_DEVICE_IOCOMPLETION); /* PacketId (2 bytes) */
|
| 263 |
+
Stream_Write_UINT32(out, DeviceId); /* DeviceId (4 bytes) */
|
| 264 |
+
Stream_Write_UINT32(out, CompletionId); /* CompletionId (4 bytes) */
|
| 265 |
+
Stream_Write_INT32(out, ioStatus); /* IoStatus (4 bytes) */
|
| 266 |
+
|
| 267 |
+
return TRUE;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
static void rdpdr_dump_packet(wLog* log, DWORD lvl, wStream* s, const char* custom, BOOL send)
|
| 271 |
+
{
|
| 272 |
+
if (!WLog_IsLevelActive(log, lvl))
|
| 273 |
+
return;
|
| 274 |
+
|
| 275 |
+
const size_t gpos = Stream_GetPosition(s);
|
| 276 |
+
const size_t pos = send ? Stream_GetPosition(s) : Stream_Length(s);
|
| 277 |
+
|
| 278 |
+
UINT16 component = 0;
|
| 279 |
+
UINT16 packetid = 0;
|
| 280 |
+
|
| 281 |
+
Stream_SetPosition(s, 0);
|
| 282 |
+
|
| 283 |
+
if (pos >= 2)
|
| 284 |
+
Stream_Read_UINT16(s, component);
|
| 285 |
+
if (pos >= 4)
|
| 286 |
+
Stream_Read_UINT16(s, packetid);
|
| 287 |
+
|
| 288 |
+
switch (packetid)
|
| 289 |
+
{
|
| 290 |
+
case PAKID_CORE_SERVER_ANNOUNCE:
|
| 291 |
+
case PAKID_CORE_CLIENTID_CONFIRM:
|
| 292 |
+
{
|
| 293 |
+
UINT16 versionMajor = 0;
|
| 294 |
+
UINT16 versionMinor = 0;
|
| 295 |
+
UINT32 clientID = 0;
|
| 296 |
+
|
| 297 |
+
if (pos >= 6)
|
| 298 |
+
Stream_Read_UINT16(s, versionMajor);
|
| 299 |
+
if (pos >= 8)
|
| 300 |
+
Stream_Read_UINT16(s, versionMinor);
|
| 301 |
+
if (pos >= 12)
|
| 302 |
+
Stream_Read_UINT32(s, clientID);
|
| 303 |
+
WLog_Print(log, lvl,
|
| 304 |
+
"%s [%s | %s] [version:%" PRIu16 ".%" PRIu16 "][id:0x%08" PRIx32
|
| 305 |
+
"] -> %" PRIuz,
|
| 306 |
+
custom, rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 307 |
+
versionMajor, versionMinor, clientID, pos);
|
| 308 |
+
}
|
| 309 |
+
break;
|
| 310 |
+
case PAKID_CORE_CLIENT_NAME:
|
| 311 |
+
{
|
| 312 |
+
char name[256] = { 0 };
|
| 313 |
+
UINT32 unicodeFlag = 0;
|
| 314 |
+
UINT32 codePage = 0;
|
| 315 |
+
UINT32 computerNameLen = 0;
|
| 316 |
+
if (pos >= 8)
|
| 317 |
+
Stream_Read_UINT32(s, unicodeFlag);
|
| 318 |
+
if (pos >= 12)
|
| 319 |
+
Stream_Read_UINT32(s, codePage);
|
| 320 |
+
if (pos >= 16)
|
| 321 |
+
Stream_Read_UINT32(s, computerNameLen);
|
| 322 |
+
if (pos >= 16 + computerNameLen)
|
| 323 |
+
{
|
| 324 |
+
if (unicodeFlag == 0)
|
| 325 |
+
Stream_Read(s, name, MIN(sizeof(name), computerNameLen));
|
| 326 |
+
else
|
| 327 |
+
(void)ConvertWCharNToUtf8(Stream_ConstPointer(s),
|
| 328 |
+
computerNameLen / sizeof(WCHAR), name, sizeof(name));
|
| 329 |
+
}
|
| 330 |
+
WLog_Print(log, lvl,
|
| 331 |
+
"%s [%s | %s] [ucs:%" PRIu32 "|cp:%" PRIu32 "][len:0x%08" PRIx32
|
| 332 |
+
"] '%s' -> %" PRIuz,
|
| 333 |
+
custom, rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 334 |
+
unicodeFlag, codePage, computerNameLen, name, pos);
|
| 335 |
+
}
|
| 336 |
+
break;
|
| 337 |
+
|
| 338 |
+
case PAKID_CORE_DEVICE_IOREQUEST:
|
| 339 |
+
{
|
| 340 |
+
UINT32 CompletionId = 0;
|
| 341 |
+
UINT32 deviceID = 0;
|
| 342 |
+
UINT32 FileId = 0;
|
| 343 |
+
UINT32 MajorFunction = 0;
|
| 344 |
+
UINT32 MinorFunction = 0;
|
| 345 |
+
|
| 346 |
+
if (pos >= 8)
|
| 347 |
+
Stream_Read_UINT32(s, deviceID);
|
| 348 |
+
if (pos >= 12)
|
| 349 |
+
Stream_Read_UINT32(s, FileId);
|
| 350 |
+
if (pos >= 16)
|
| 351 |
+
Stream_Read_UINT32(s, CompletionId);
|
| 352 |
+
if (pos >= 20)
|
| 353 |
+
Stream_Read_UINT32(s, MajorFunction);
|
| 354 |
+
if (pos >= 24)
|
| 355 |
+
Stream_Read_UINT32(s, MinorFunction);
|
| 356 |
+
WLog_Print(log, lvl,
|
| 357 |
+
"%s [%s | %s] [0x%08" PRIx32 "] FileId=0x%08" PRIx32
|
| 358 |
+
", CompletionId=0x%08" PRIx32 ", MajorFunction=0x%08" PRIx32
|
| 359 |
+
", MinorFunction=0x%08" PRIx32 " -> %" PRIuz,
|
| 360 |
+
custom, rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 361 |
+
deviceID, FileId, CompletionId, MajorFunction, MinorFunction, pos);
|
| 362 |
+
}
|
| 363 |
+
break;
|
| 364 |
+
case PAKID_CORE_DEVICE_IOCOMPLETION:
|
| 365 |
+
{
|
| 366 |
+
UINT32 completionID = 0;
|
| 367 |
+
UINT32 ioStatus = 0;
|
| 368 |
+
UINT32 deviceID = 0;
|
| 369 |
+
if (pos >= 8)
|
| 370 |
+
Stream_Read_UINT32(s, deviceID);
|
| 371 |
+
if (pos >= 12)
|
| 372 |
+
Stream_Read_UINT32(s, completionID);
|
| 373 |
+
if (pos >= 16)
|
| 374 |
+
Stream_Read_UINT32(s, ioStatus);
|
| 375 |
+
|
| 376 |
+
WLog_Print(log, lvl,
|
| 377 |
+
"%s [%s | %s] [0x%08" PRIx32 "] completionID=0x%08" PRIx32
|
| 378 |
+
", ioStatus=0x%08" PRIx32 " -> %" PRIuz,
|
| 379 |
+
custom, rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 380 |
+
deviceID, completionID, ioStatus, pos);
|
| 381 |
+
}
|
| 382 |
+
break;
|
| 383 |
+
case PAKID_CORE_DEVICE_REPLY:
|
| 384 |
+
{
|
| 385 |
+
UINT32 deviceID = 0;
|
| 386 |
+
UINT32 status = 0;
|
| 387 |
+
|
| 388 |
+
if (pos >= 8)
|
| 389 |
+
Stream_Read_UINT32(s, deviceID);
|
| 390 |
+
if (pos >= 12)
|
| 391 |
+
Stream_Read_UINT32(s, status);
|
| 392 |
+
WLog_Print(log, lvl,
|
| 393 |
+
"%s [%s | %s] [id:0x%08" PRIx32 ",status=0x%08" PRIx32 "] -> %" PRIuz,
|
| 394 |
+
custom, rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 395 |
+
deviceID, status, pos);
|
| 396 |
+
}
|
| 397 |
+
break;
|
| 398 |
+
case PAKID_CORE_CLIENT_CAPABILITY:
|
| 399 |
+
case PAKID_CORE_SERVER_CAPABILITY:
|
| 400 |
+
{
|
| 401 |
+
UINT16 numCapabilities = 0;
|
| 402 |
+
if (pos >= 6)
|
| 403 |
+
Stream_Read_UINT16(s, numCapabilities);
|
| 404 |
+
if (pos >= 8)
|
| 405 |
+
Stream_Seek_UINT16(s); /* padding */
|
| 406 |
+
WLog_Print(log, lvl, "%s [%s | %s] [caps:%" PRIu16 "] -> %" PRIuz, custom,
|
| 407 |
+
rdpdr_component_string(component), rdpdr_packetid_string(packetid),
|
| 408 |
+
numCapabilities, pos);
|
| 409 |
+
for (UINT16 x = 0; x < numCapabilities; x++)
|
| 410 |
+
{
|
| 411 |
+
RDPDR_CAPABILITY_HEADER header = { 0 };
|
| 412 |
+
const UINT error = rdpdr_read_capset_header(log, s, &header);
|
| 413 |
+
if (error == CHANNEL_RC_OK)
|
| 414 |
+
Stream_Seek(s, header.CapabilityLength);
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
break;
|
| 418 |
+
case PAKID_CORE_DEVICELIST_ANNOUNCE:
|
| 419 |
+
{
|
| 420 |
+
size_t offset = 8;
|
| 421 |
+
UINT32 count = 0;
|
| 422 |
+
|
| 423 |
+
if (pos >= offset)
|
| 424 |
+
Stream_Read_UINT32(s, count);
|
| 425 |
+
|
| 426 |
+
WLog_Print(log, lvl, "%s [%s | %s] [%" PRIu32 "] -> %" PRIuz, custom,
|
| 427 |
+
rdpdr_component_string(component), rdpdr_packetid_string(packetid), count,
|
| 428 |
+
pos);
|
| 429 |
+
|
| 430 |
+
for (UINT32 x = 0; x < count; x++)
|
| 431 |
+
{
|
| 432 |
+
RdpdrDevice device = { 0 };
|
| 433 |
+
|
| 434 |
+
offset += 20;
|
| 435 |
+
if (pos >= offset)
|
| 436 |
+
{
|
| 437 |
+
Stream_Read_UINT32(s, device.DeviceType); /* DeviceType (4 bytes) */
|
| 438 |
+
Stream_Read_UINT32(s, device.DeviceId); /* DeviceId (4 bytes) */
|
| 439 |
+
Stream_Read(s, device.PreferredDosName, 8); /* PreferredDosName (8 bytes) */
|
| 440 |
+
Stream_Read_UINT32(s, device.DeviceDataLength); /* DeviceDataLength (4 bytes) */
|
| 441 |
+
device.DeviceData = Stream_Pointer(s);
|
| 442 |
+
}
|
| 443 |
+
offset += device.DeviceDataLength;
|
| 444 |
+
|
| 445 |
+
WLog_Print(log, lvl,
|
| 446 |
+
"%s [announce][%" PRIu32 "] %s [0x%08" PRIx32
|
| 447 |
+
"] '%s' [DeviceDataLength=%" PRIu32 "]",
|
| 448 |
+
custom, x, freerdp_rdpdr_dtyp_string(device.DeviceType), device.DeviceId,
|
| 449 |
+
device.PreferredDosName, device.DeviceDataLength);
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
break;
|
| 453 |
+
case PAKID_CORE_DEVICELIST_REMOVE:
|
| 454 |
+
{
|
| 455 |
+
size_t offset = 8;
|
| 456 |
+
UINT32 count = 0;
|
| 457 |
+
|
| 458 |
+
if (pos >= offset)
|
| 459 |
+
Stream_Read_UINT32(s, count);
|
| 460 |
+
|
| 461 |
+
WLog_Print(log, lvl, "%s [%s | %s] [%" PRIu32 "] -> %" PRIuz, custom,
|
| 462 |
+
rdpdr_component_string(component), rdpdr_packetid_string(packetid), count,
|
| 463 |
+
pos);
|
| 464 |
+
|
| 465 |
+
for (UINT32 x = 0; x < count; x++)
|
| 466 |
+
{
|
| 467 |
+
UINT32 id = 0;
|
| 468 |
+
|
| 469 |
+
offset += 4;
|
| 470 |
+
if (pos >= offset)
|
| 471 |
+
Stream_Read_UINT32(s, id);
|
| 472 |
+
|
| 473 |
+
WLog_Print(log, lvl, "%s [remove][%" PRIu32 "] id=%" PRIu32, custom, x, id);
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
break;
|
| 477 |
+
case PAKID_CORE_USER_LOGGEDON:
|
| 478 |
+
WLog_Print(log, lvl, "%s [%s | %s] -> %" PRIuz, custom,
|
| 479 |
+
rdpdr_component_string(component), rdpdr_packetid_string(packetid), pos);
|
| 480 |
+
break;
|
| 481 |
+
default:
|
| 482 |
+
{
|
| 483 |
+
WLog_Print(log, lvl, "%s [%s | %s] -> %" PRIuz, custom,
|
| 484 |
+
rdpdr_component_string(component), rdpdr_packetid_string(packetid), pos);
|
| 485 |
+
}
|
| 486 |
+
break;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
// winpr_HexLogDump(log, lvl, Stream_Buffer(s), pos);
|
| 490 |
+
Stream_SetPosition(s, gpos);
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
void rdpdr_dump_received_packet(wLog* log, DWORD lvl, wStream* s, const char* custom)
|
| 494 |
+
{
|
| 495 |
+
rdpdr_dump_packet(log, lvl, s, custom, FALSE);
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
void rdpdr_dump_send_packet(wLog* log, DWORD lvl, wStream* s, const char* custom)
|
| 499 |
+
{
|
| 500 |
+
rdpdr_dump_packet(log, lvl, s, custom, TRUE);
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
const char* rdpdr_irp_string(UINT32 major)
|
| 504 |
+
{
|
| 505 |
+
switch (major)
|
| 506 |
+
{
|
| 507 |
+
case IRP_MJ_CREATE:
|
| 508 |
+
return "IRP_MJ_CREATE";
|
| 509 |
+
case IRP_MJ_CLOSE:
|
| 510 |
+
return "IRP_MJ_CLOSE";
|
| 511 |
+
case IRP_MJ_READ:
|
| 512 |
+
return "IRP_MJ_READ";
|
| 513 |
+
case IRP_MJ_WRITE:
|
| 514 |
+
return "IRP_MJ_WRITE";
|
| 515 |
+
case IRP_MJ_DEVICE_CONTROL:
|
| 516 |
+
return "IRP_MJ_DEVICE_CONTROL";
|
| 517 |
+
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
| 518 |
+
return "IRP_MJ_QUERY_VOLUME_INFORMATION";
|
| 519 |
+
case IRP_MJ_SET_VOLUME_INFORMATION:
|
| 520 |
+
return "IRP_MJ_SET_VOLUME_INFORMATION";
|
| 521 |
+
case IRP_MJ_QUERY_INFORMATION:
|
| 522 |
+
return "IRP_MJ_QUERY_INFORMATION";
|
| 523 |
+
case IRP_MJ_SET_INFORMATION:
|
| 524 |
+
return "IRP_MJ_SET_INFORMATION";
|
| 525 |
+
case IRP_MJ_DIRECTORY_CONTROL:
|
| 526 |
+
return "IRP_MJ_DIRECTORY_CONTROL";
|
| 527 |
+
case IRP_MJ_LOCK_CONTROL:
|
| 528 |
+
return "IRP_MJ_LOCK_CONTROL";
|
| 529 |
+
default:
|
| 530 |
+
return "IRP_UNKNOWN";
|
| 531 |
+
}
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
const char* rdpdr_cap_type_string(UINT16 capability)
|
| 535 |
+
{
|
| 536 |
+
switch (capability)
|
| 537 |
+
{
|
| 538 |
+
case CAP_GENERAL_TYPE:
|
| 539 |
+
return "CAP_GENERAL_TYPE";
|
| 540 |
+
case CAP_PRINTER_TYPE:
|
| 541 |
+
return "CAP_PRINTER_TYPE";
|
| 542 |
+
case CAP_PORT_TYPE:
|
| 543 |
+
return "CAP_PORT_TYPE";
|
| 544 |
+
case CAP_DRIVE_TYPE:
|
| 545 |
+
return "CAP_DRIVE_TYPE";
|
| 546 |
+
case CAP_SMARTCARD_TYPE:
|
| 547 |
+
return "CAP_SMARTCARD_TYPE";
|
| 548 |
+
default:
|
| 549 |
+
return "CAP_UNKNOWN";
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
UINT rdpdr_read_capset_header(wLog* log, wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
| 554 |
+
{
|
| 555 |
+
WINPR_ASSERT(header);
|
| 556 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
|
| 557 |
+
return ERROR_INVALID_DATA;
|
| 558 |
+
|
| 559 |
+
Stream_Read_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
|
| 560 |
+
Stream_Read_UINT16(s, header->CapabilityLength); /* CapabilityLength (2 bytes) */
|
| 561 |
+
Stream_Read_UINT32(s, header->Version); /* Version (4 bytes) */
|
| 562 |
+
|
| 563 |
+
WLog_Print(log, WLOG_TRACE,
|
| 564 |
+
"capability %s [0x%04" PRIx16 "] got version %" PRIu32 ", length %" PRIu16,
|
| 565 |
+
rdpdr_cap_type_string(header->CapabilityType), header->CapabilityType,
|
| 566 |
+
header->Version, header->CapabilityLength);
|
| 567 |
+
if (header->CapabilityLength < 8)
|
| 568 |
+
{
|
| 569 |
+
WLog_Print(log, WLOG_ERROR, "capability %s got short length %" PRIu32,
|
| 570 |
+
rdpdr_cap_type_string(header->CapabilityType), header->CapabilityLength);
|
| 571 |
+
return ERROR_INVALID_DATA;
|
| 572 |
+
}
|
| 573 |
+
header->CapabilityLength -= 8;
|
| 574 |
+
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, header->CapabilityLength))
|
| 575 |
+
return ERROR_INVALID_DATA;
|
| 576 |
+
return CHANNEL_RC_OK;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
UINT rdpdr_write_capset_header(wLog* log, wStream* s, const RDPDR_CAPABILITY_HEADER* header)
|
| 580 |
+
{
|
| 581 |
+
WINPR_ASSERT(header);
|
| 582 |
+
WINPR_ASSERT(header->CapabilityLength >= 8);
|
| 583 |
+
|
| 584 |
+
if (!Stream_EnsureRemainingCapacity(s, header->CapabilityLength))
|
| 585 |
+
{
|
| 586 |
+
WLog_Print(log, WLOG_ERROR, "not enough data in stream!");
|
| 587 |
+
return ERROR_INVALID_DATA;
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
WLog_Print(log, WLOG_TRACE, "writing capability %s version %" PRIu32 ", length %" PRIu16,
|
| 591 |
+
rdpdr_cap_type_string(header->CapabilityType), header->Version,
|
| 592 |
+
header->CapabilityLength);
|
| 593 |
+
Stream_Write_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
|
| 594 |
+
Stream_Write_UINT16(s, header->CapabilityLength); /* CapabilityLength (2 bytes) */
|
| 595 |
+
Stream_Write_UINT32(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Copyright 2014 Thincast Technologies GmbH
|
| 5 |
+
* Copyright 2014 Hardening <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <freerdp/utils/ringbuffer.h>
|
| 23 |
+
|
| 24 |
+
#include <stdlib.h>
|
| 25 |
+
#include <string.h>
|
| 26 |
+
#include <winpr/assert.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/crt.h>
|
| 29 |
+
#include <freerdp/log.h>
|
| 30 |
+
|
| 31 |
+
#ifdef WITH_DEBUG_RINGBUFFER
|
| 32 |
+
#define TAG FREERDP_TAG("utils.ringbuffer")
|
| 33 |
+
|
| 34 |
+
#define DEBUG_RINGBUFFER(...) WLog_DBG(TAG, __VA_ARGS__)
|
| 35 |
+
#else
|
| 36 |
+
#define DEBUG_RINGBUFFER(...) \
|
| 37 |
+
do \
|
| 38 |
+
{ \
|
| 39 |
+
} while (0)
|
| 40 |
+
#endif
|
| 41 |
+
|
| 42 |
+
BOOL ringbuffer_init(RingBuffer* rb, size_t initialSize)
|
| 43 |
+
{
|
| 44 |
+
WINPR_ASSERT(rb);
|
| 45 |
+
rb->buffer = malloc(initialSize);
|
| 46 |
+
|
| 47 |
+
if (!rb->buffer)
|
| 48 |
+
return FALSE;
|
| 49 |
+
|
| 50 |
+
rb->readPtr = rb->writePtr = 0;
|
| 51 |
+
rb->initialSize = rb->size = rb->freeSize = initialSize;
|
| 52 |
+
DEBUG_RINGBUFFER("ringbuffer_init(%p)", (void*)rb);
|
| 53 |
+
return TRUE;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
size_t ringbuffer_used(const RingBuffer* rb)
|
| 57 |
+
{
|
| 58 |
+
WINPR_ASSERT(rb);
|
| 59 |
+
return rb->size - rb->freeSize;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
size_t ringbuffer_capacity(const RingBuffer* rb)
|
| 63 |
+
{
|
| 64 |
+
WINPR_ASSERT(rb);
|
| 65 |
+
return rb->size;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void ringbuffer_destroy(RingBuffer* rb)
|
| 69 |
+
{
|
| 70 |
+
DEBUG_RINGBUFFER("ringbuffer_destroy(%p)", (void*)rb);
|
| 71 |
+
if (!rb)
|
| 72 |
+
return;
|
| 73 |
+
|
| 74 |
+
free(rb->buffer);
|
| 75 |
+
rb->buffer = NULL;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
| 79 |
+
{
|
| 80 |
+
WINPR_ASSERT(rb);
|
| 81 |
+
BYTE* newData = NULL;
|
| 82 |
+
DEBUG_RINGBUFFER("ringbuffer_realloc(%p): targetSize: %" PRIdz "", (void*)rb, targetSize);
|
| 83 |
+
|
| 84 |
+
if (rb->writePtr == rb->readPtr)
|
| 85 |
+
{
|
| 86 |
+
/* when no size is used we can realloc() and set the heads at the
|
| 87 |
+
* beginning of the buffer
|
| 88 |
+
*/
|
| 89 |
+
newData = (BYTE*)realloc(rb->buffer, targetSize);
|
| 90 |
+
|
| 91 |
+
if (!newData)
|
| 92 |
+
return FALSE;
|
| 93 |
+
|
| 94 |
+
rb->readPtr = rb->writePtr = 0;
|
| 95 |
+
rb->buffer = newData;
|
| 96 |
+
}
|
| 97 |
+
else if ((rb->writePtr >= rb->readPtr) && (rb->writePtr < targetSize))
|
| 98 |
+
{
|
| 99 |
+
/* we reallocate only if we're in that case, realloc don't touch read
|
| 100 |
+
* and write heads
|
| 101 |
+
*
|
| 102 |
+
* readPtr writePtr
|
| 103 |
+
* | |
|
| 104 |
+
* v v
|
| 105 |
+
* [............|XXXXXXXXXXXXXX|..........]
|
| 106 |
+
*/
|
| 107 |
+
newData = (BYTE*)realloc(rb->buffer, targetSize);
|
| 108 |
+
|
| 109 |
+
if (!newData)
|
| 110 |
+
return FALSE;
|
| 111 |
+
|
| 112 |
+
rb->buffer = newData;
|
| 113 |
+
}
|
| 114 |
+
else
|
| 115 |
+
{
|
| 116 |
+
/* in case of malloc the read head is moved at the beginning of the new buffer
|
| 117 |
+
* and the write head is set accordingly
|
| 118 |
+
*/
|
| 119 |
+
newData = (BYTE*)malloc(targetSize);
|
| 120 |
+
|
| 121 |
+
if (!newData)
|
| 122 |
+
return FALSE;
|
| 123 |
+
|
| 124 |
+
if (rb->readPtr < rb->writePtr)
|
| 125 |
+
{
|
| 126 |
+
/* readPtr writePtr
|
| 127 |
+
* | |
|
| 128 |
+
* v v
|
| 129 |
+
* [............|XXXXXXXXXXXXXX|..........]
|
| 130 |
+
*/
|
| 131 |
+
memcpy(newData, rb->buffer + rb->readPtr, ringbuffer_used(rb));
|
| 132 |
+
}
|
| 133 |
+
else
|
| 134 |
+
{
|
| 135 |
+
/* writePtr readPtr
|
| 136 |
+
* | |
|
| 137 |
+
* v v
|
| 138 |
+
* [XXXXXXXXXXXX|..............|XXXXXXXXXX]
|
| 139 |
+
*/
|
| 140 |
+
BYTE* dst = newData;
|
| 141 |
+
memcpy(dst, rb->buffer + rb->readPtr, rb->size - rb->readPtr);
|
| 142 |
+
dst += (rb->size - rb->readPtr);
|
| 143 |
+
|
| 144 |
+
if (rb->writePtr)
|
| 145 |
+
memcpy(dst, rb->buffer, rb->writePtr);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
rb->writePtr = rb->size - rb->freeSize;
|
| 149 |
+
rb->readPtr = 0;
|
| 150 |
+
free(rb->buffer);
|
| 151 |
+
rb->buffer = newData;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
rb->freeSize += (targetSize - rb->size);
|
| 155 |
+
rb->size = targetSize;
|
| 156 |
+
return TRUE;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Write to a ringbuffer
|
| 161 |
+
*
|
| 162 |
+
* @param rb A pointer to the ringbuffer
|
| 163 |
+
* @param ptr A pointer to the data to write
|
| 164 |
+
* @param sz The number of bytes to write
|
| 165 |
+
*
|
| 166 |
+
* @return \b TRUE for success, \b FALSE for failure
|
| 167 |
+
*/
|
| 168 |
+
BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
|
| 169 |
+
{
|
| 170 |
+
size_t toWrite = 0;
|
| 171 |
+
size_t remaining = 0;
|
| 172 |
+
|
| 173 |
+
WINPR_ASSERT(rb);
|
| 174 |
+
DEBUG_RINGBUFFER("ringbuffer_write(%p): sz: %" PRIdz "", (void*)rb, sz);
|
| 175 |
+
|
| 176 |
+
if ((rb->freeSize <= sz) && !ringbuffer_realloc(rb, rb->size + sz))
|
| 177 |
+
return FALSE;
|
| 178 |
+
|
| 179 |
+
/* the write could be split in two
|
| 180 |
+
* readHead writeHead
|
| 181 |
+
* | |
|
| 182 |
+
* v v
|
| 183 |
+
* [ ################ ]
|
| 184 |
+
*/
|
| 185 |
+
toWrite = sz;
|
| 186 |
+
remaining = sz;
|
| 187 |
+
|
| 188 |
+
if (rb->size - rb->writePtr < sz)
|
| 189 |
+
toWrite = rb->size - rb->writePtr;
|
| 190 |
+
|
| 191 |
+
if (toWrite)
|
| 192 |
+
{
|
| 193 |
+
memcpy(rb->buffer + rb->writePtr, ptr, toWrite);
|
| 194 |
+
remaining -= toWrite;
|
| 195 |
+
ptr += toWrite;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
if (remaining)
|
| 199 |
+
memcpy(rb->buffer, ptr, remaining);
|
| 200 |
+
|
| 201 |
+
rb->writePtr = (rb->writePtr + sz) % rb->size;
|
| 202 |
+
rb->freeSize -= sz;
|
| 203 |
+
return TRUE;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
BYTE* ringbuffer_ensure_linear_write(RingBuffer* rb, size_t sz)
|
| 207 |
+
{
|
| 208 |
+
DEBUG_RINGBUFFER("ringbuffer_ensure_linear_write(%p): sz: %" PRIdz "", (void*)rb, sz);
|
| 209 |
+
|
| 210 |
+
WINPR_ASSERT(rb);
|
| 211 |
+
if (rb->freeSize < sz)
|
| 212 |
+
{
|
| 213 |
+
if (!ringbuffer_realloc(rb, rb->size + sz - rb->freeSize + 32))
|
| 214 |
+
return NULL;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
if (rb->writePtr == rb->readPtr)
|
| 218 |
+
{
|
| 219 |
+
rb->writePtr = rb->readPtr = 0;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
if (rb->writePtr + sz < rb->size)
|
| 223 |
+
return rb->buffer + rb->writePtr;
|
| 224 |
+
|
| 225 |
+
/*
|
| 226 |
+
* to add: .......
|
| 227 |
+
* [ XXXXXXXXX ]
|
| 228 |
+
*
|
| 229 |
+
* result:
|
| 230 |
+
* [XXXXXXXXX....... ]
|
| 231 |
+
*/
|
| 232 |
+
memmove(rb->buffer, rb->buffer + rb->readPtr, rb->writePtr - rb->readPtr);
|
| 233 |
+
rb->readPtr = 0;
|
| 234 |
+
rb->writePtr = rb->size - rb->freeSize;
|
| 235 |
+
return rb->buffer + rb->writePtr;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
BOOL ringbuffer_commit_written_bytes(RingBuffer* rb, size_t sz)
|
| 239 |
+
{
|
| 240 |
+
DEBUG_RINGBUFFER("ringbuffer_commit_written_bytes(%p): sz: %" PRIdz "", (void*)rb, sz);
|
| 241 |
+
|
| 242 |
+
WINPR_ASSERT(rb);
|
| 243 |
+
if (sz < 1)
|
| 244 |
+
return TRUE;
|
| 245 |
+
|
| 246 |
+
if (rb->writePtr + sz > rb->size)
|
| 247 |
+
return FALSE;
|
| 248 |
+
|
| 249 |
+
rb->writePtr = (rb->writePtr + sz) % rb->size;
|
| 250 |
+
rb->freeSize -= sz;
|
| 251 |
+
return TRUE;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
|
| 255 |
+
{
|
| 256 |
+
size_t remaining = sz;
|
| 257 |
+
size_t toRead = 0;
|
| 258 |
+
int chunkIndex = 0;
|
| 259 |
+
int status = 0;
|
| 260 |
+
DEBUG_RINGBUFFER("ringbuffer_peek(%p): sz: %" PRIdz "", (const void*)rb, sz);
|
| 261 |
+
|
| 262 |
+
WINPR_ASSERT(rb);
|
| 263 |
+
if (sz < 1)
|
| 264 |
+
return 0;
|
| 265 |
+
|
| 266 |
+
if ((rb->size - rb->freeSize) < sz)
|
| 267 |
+
remaining = rb->size - rb->freeSize;
|
| 268 |
+
|
| 269 |
+
toRead = remaining;
|
| 270 |
+
|
| 271 |
+
if ((rb->readPtr + remaining) > rb->size)
|
| 272 |
+
toRead = rb->size - rb->readPtr;
|
| 273 |
+
|
| 274 |
+
if (toRead)
|
| 275 |
+
{
|
| 276 |
+
chunks[0].data = rb->buffer + rb->readPtr;
|
| 277 |
+
chunks[0].size = toRead;
|
| 278 |
+
remaining -= toRead;
|
| 279 |
+
chunkIndex++;
|
| 280 |
+
status++;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
if (remaining)
|
| 284 |
+
{
|
| 285 |
+
chunks[chunkIndex].data = rb->buffer;
|
| 286 |
+
chunks[chunkIndex].size = remaining;
|
| 287 |
+
status++;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
return status;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
void ringbuffer_commit_read_bytes(RingBuffer* rb, size_t sz)
|
| 294 |
+
{
|
| 295 |
+
DEBUG_RINGBUFFER("ringbuffer_commit_read_bytes(%p): sz: %" PRIdz "", (void*)rb, sz);
|
| 296 |
+
|
| 297 |
+
WINPR_ASSERT(rb);
|
| 298 |
+
if (sz < 1)
|
| 299 |
+
return;
|
| 300 |
+
|
| 301 |
+
WINPR_ASSERT(rb->size - rb->freeSize >= sz);
|
| 302 |
+
rb->readPtr = (rb->readPtr + sz) % rb->size;
|
| 303 |
+
rb->freeSize += sz;
|
| 304 |
+
|
| 305 |
+
/* when we reach a reasonable free size, we can go back to the original size */
|
| 306 |
+
if ((rb->size != rb->initialSize) && (ringbuffer_used(rb) < rb->initialSize / 2))
|
| 307 |
+
ringbuffer_realloc(rb, rb->initialSize);
|
| 308 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/signal.c
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Signal handling
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Shea Levy <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stddef.h>
|
| 23 |
+
#include <errno.h>
|
| 24 |
+
#include <string.h>
|
| 25 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
|
| 28 |
+
#include <freerdp/utils/signal.h>
|
| 29 |
+
#include <freerdp/log.h>
|
| 30 |
+
|
| 31 |
+
#ifndef _WIN32
|
| 32 |
+
#include <signal.h>
|
| 33 |
+
#include <termios.h>
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
#define TAG FREERDP_TAG("utils.signal")
|
| 37 |
+
|
| 38 |
+
#ifdef _WIN32
|
| 39 |
+
|
| 40 |
+
int freerdp_handle_signals(void)
|
| 41 |
+
{
|
| 42 |
+
errno = ENOSYS;
|
| 43 |
+
return -1;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
BOOL freerdp_add_signal_cleanup_handler(void* context, freerdp_signal_handler_t fkt)
|
| 47 |
+
{
|
| 48 |
+
return FALSE;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
BOOL freerdp_del_signal_cleanup_handler(void* context, freerdp_signal_handler_t fkt)
|
| 52 |
+
{
|
| 53 |
+
return FALSE;
|
| 54 |
+
}
|
| 55 |
+
#else
|
| 56 |
+
|
| 57 |
+
#include <pthread.h>
|
| 58 |
+
#include <winpr/debug.h>
|
| 59 |
+
|
| 60 |
+
static BOOL handlers_registered = FALSE;
|
| 61 |
+
static pthread_mutex_t signal_handler_lock = PTHREAD_MUTEX_INITIALIZER;
|
| 62 |
+
|
| 63 |
+
typedef struct
|
| 64 |
+
{
|
| 65 |
+
void* context;
|
| 66 |
+
freerdp_signal_handler_t handler;
|
| 67 |
+
} cleanup_handler_t;
|
| 68 |
+
|
| 69 |
+
static size_t cleanup_handler_count = 0;
|
| 70 |
+
static cleanup_handler_t cleanup_handlers[20] = { 0 };
|
| 71 |
+
|
| 72 |
+
static void lock(void)
|
| 73 |
+
{
|
| 74 |
+
const int rc = pthread_mutex_lock(&signal_handler_lock);
|
| 75 |
+
if (rc != 0)
|
| 76 |
+
{
|
| 77 |
+
char ebuffer[256] = { 0 };
|
| 78 |
+
WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]",
|
| 79 |
+
winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc);
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
static void unlock(void)
|
| 84 |
+
{
|
| 85 |
+
const int rc = pthread_mutex_unlock(&signal_handler_lock);
|
| 86 |
+
if (rc != 0)
|
| 87 |
+
{
|
| 88 |
+
char ebuffer[256] = { 0 };
|
| 89 |
+
WLog_ERR(TAG, "[pthread_mutex_lock] failed with %s [%d]",
|
| 90 |
+
winpr_strerror(rc, ebuffer, sizeof(ebuffer)), rc);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
static void term_handler(int signum)
|
| 95 |
+
{
|
| 96 |
+
static BOOL recursive = FALSE;
|
| 97 |
+
|
| 98 |
+
if (!recursive)
|
| 99 |
+
{
|
| 100 |
+
recursive = TRUE;
|
| 101 |
+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
| 102 |
+
WLog_ERR(TAG, "Caught signal '%s' [%d]", strsignal(signum), signum);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
lock();
|
| 106 |
+
for (size_t x = 0; x < cleanup_handler_count; x++)
|
| 107 |
+
{
|
| 108 |
+
const cleanup_handler_t empty = { 0 };
|
| 109 |
+
cleanup_handler_t* cur = &cleanup_handlers[x];
|
| 110 |
+
if (cur->handler)
|
| 111 |
+
{
|
| 112 |
+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
| 113 |
+
cur->handler(signum, strsignal(signum), cur->context);
|
| 114 |
+
}
|
| 115 |
+
*cur = empty;
|
| 116 |
+
}
|
| 117 |
+
cleanup_handler_count = 0;
|
| 118 |
+
unlock();
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
static void fatal_handler(int signum)
|
| 122 |
+
{
|
| 123 |
+
struct sigaction default_sigaction;
|
| 124 |
+
sigset_t this_mask;
|
| 125 |
+
static BOOL recursive = FALSE;
|
| 126 |
+
|
| 127 |
+
if (!recursive)
|
| 128 |
+
{
|
| 129 |
+
recursive = TRUE;
|
| 130 |
+
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
| 131 |
+
WLog_ERR(TAG, "Caught signal '%s' [%d]", strsignal(signum), signum);
|
| 132 |
+
|
| 133 |
+
winpr_log_backtrace(TAG, WLOG_ERROR, 20);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
default_sigaction.sa_handler = SIG_DFL;
|
| 137 |
+
sigfillset(&(default_sigaction.sa_mask));
|
| 138 |
+
default_sigaction.sa_flags = 0;
|
| 139 |
+
sigaction(signum, &default_sigaction, NULL);
|
| 140 |
+
sigemptyset(&this_mask);
|
| 141 |
+
sigaddset(&this_mask, signum);
|
| 142 |
+
pthread_sigmask(SIG_UNBLOCK, &this_mask, NULL);
|
| 143 |
+
(void)raise(signum);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
static const int term_signals[] = { SIGINT, SIGKILL, SIGQUIT, SIGSTOP, SIGTERM };
|
| 147 |
+
|
| 148 |
+
static const int fatal_signals[] = { SIGABRT, SIGALRM, SIGBUS, SIGFPE, SIGHUP, SIGILL,
|
| 149 |
+
SIGSEGV, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2,
|
| 150 |
+
#ifdef SIGPOLL
|
| 151 |
+
SIGPOLL,
|
| 152 |
+
#endif
|
| 153 |
+
#ifdef SIGPROF
|
| 154 |
+
SIGPROF,
|
| 155 |
+
#endif
|
| 156 |
+
#ifdef SIGSYS
|
| 157 |
+
SIGSYS,
|
| 158 |
+
#endif
|
| 159 |
+
SIGTRAP,
|
| 160 |
+
#ifdef SIGVTALRM
|
| 161 |
+
SIGVTALRM,
|
| 162 |
+
#endif
|
| 163 |
+
SIGXCPU, SIGXFSZ };
|
| 164 |
+
|
| 165 |
+
static BOOL register_handlers(const int* signals, size_t count, void (*handler)(int))
|
| 166 |
+
{
|
| 167 |
+
WINPR_ASSERT(signals || (count == 0));
|
| 168 |
+
WINPR_ASSERT(handler);
|
| 169 |
+
|
| 170 |
+
sigset_t orig_set = { 0 };
|
| 171 |
+
struct sigaction saction = { 0 };
|
| 172 |
+
|
| 173 |
+
pthread_sigmask(SIG_BLOCK, &(saction.sa_mask), &orig_set);
|
| 174 |
+
|
| 175 |
+
sigfillset(&(saction.sa_mask));
|
| 176 |
+
sigdelset(&(saction.sa_mask), SIGCONT);
|
| 177 |
+
|
| 178 |
+
saction.sa_handler = handler;
|
| 179 |
+
saction.sa_flags = 0;
|
| 180 |
+
|
| 181 |
+
for (size_t x = 0; x < count; x++)
|
| 182 |
+
{
|
| 183 |
+
struct sigaction orig_sigaction = { 0 };
|
| 184 |
+
if (sigaction(signals[x], NULL, &orig_sigaction) == 0)
|
| 185 |
+
{
|
| 186 |
+
if (orig_sigaction.sa_handler != SIG_IGN)
|
| 187 |
+
{
|
| 188 |
+
sigaction(signals[x], &saction, NULL);
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);
|
| 194 |
+
|
| 195 |
+
return TRUE;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
int freerdp_handle_signals(void)
|
| 199 |
+
{
|
| 200 |
+
int rc = -1;
|
| 201 |
+
|
| 202 |
+
lock();
|
| 203 |
+
|
| 204 |
+
WLog_DBG(TAG, "Registering signal hook...");
|
| 205 |
+
|
| 206 |
+
if (!register_handlers(fatal_signals, ARRAYSIZE(fatal_signals), fatal_handler))
|
| 207 |
+
goto fail;
|
| 208 |
+
if (!register_handlers(term_signals, ARRAYSIZE(term_signals), term_handler))
|
| 209 |
+
goto fail;
|
| 210 |
+
|
| 211 |
+
/* Ignore SIGPIPE signal. */
|
| 212 |
+
(void)signal(SIGPIPE, SIG_IGN);
|
| 213 |
+
handlers_registered = TRUE;
|
| 214 |
+
rc = 0;
|
| 215 |
+
fail:
|
| 216 |
+
unlock();
|
| 217 |
+
return rc;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
BOOL freerdp_add_signal_cleanup_handler(void* context, freerdp_signal_handler_t handler)
|
| 221 |
+
{
|
| 222 |
+
BOOL rc = FALSE;
|
| 223 |
+
lock();
|
| 224 |
+
if (handlers_registered)
|
| 225 |
+
{
|
| 226 |
+
if (cleanup_handler_count < ARRAYSIZE(cleanup_handlers))
|
| 227 |
+
{
|
| 228 |
+
cleanup_handler_t* cur = &cleanup_handlers[cleanup_handler_count++];
|
| 229 |
+
cur->context = context;
|
| 230 |
+
cur->handler = handler;
|
| 231 |
+
}
|
| 232 |
+
else
|
| 233 |
+
WLog_WARN(TAG, "Failed to register cleanup handler, only %" PRIuz " handlers supported",
|
| 234 |
+
ARRAYSIZE(cleanup_handlers));
|
| 235 |
+
}
|
| 236 |
+
rc = TRUE;
|
| 237 |
+
unlock();
|
| 238 |
+
return rc;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
BOOL freerdp_del_signal_cleanup_handler(void* context, freerdp_signal_handler_t handler)
|
| 242 |
+
{
|
| 243 |
+
BOOL rc = FALSE;
|
| 244 |
+
lock();
|
| 245 |
+
if (handlers_registered)
|
| 246 |
+
{
|
| 247 |
+
for (size_t x = 0; x < cleanup_handler_count; x++)
|
| 248 |
+
{
|
| 249 |
+
cleanup_handler_t* cur = &cleanup_handlers[x];
|
| 250 |
+
if ((cur->context == context) && (cur->handler == handler))
|
| 251 |
+
{
|
| 252 |
+
const cleanup_handler_t empty = { 0 };
|
| 253 |
+
for (size_t y = x + 1; y < cleanup_handler_count - 1; y++)
|
| 254 |
+
{
|
| 255 |
+
*cur++ = cleanup_handlers[y];
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
*cur = empty;
|
| 259 |
+
cleanup_handler_count--;
|
| 260 |
+
break;
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
rc = TRUE;
|
| 265 |
+
unlock();
|
| 266 |
+
return rc;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
#endif
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_call.c
ADDED
|
@@ -0,0 +1,2042 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Smartcard Device Service Virtual Channel
|
| 4 |
+
*
|
| 5 |
+
* Copyright (C) Alexi Volkov <[email protected]> 2006
|
| 6 |
+
* Copyright 2011 O.S. Systems Software Ltda.
|
| 7 |
+
* Copyright 2011 Anthony Tong <[email protected]>
|
| 8 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 9 |
+
* Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
|
| 10 |
+
* Copyright 2017 Armin Novak <[email protected]>
|
| 11 |
+
* Copyright 2017 Thincast Technologies GmbH
|
| 12 |
+
*
|
| 13 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 14 |
+
* you may not use this file except in compliance with the License.
|
| 15 |
+
* You may obtain a copy of the License at
|
| 16 |
+
*
|
| 17 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 18 |
+
*
|
| 19 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 20 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 21 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 22 |
+
* See the License for the specific language governing permissions and
|
| 23 |
+
* limitations under the License.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include <freerdp/config.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/assert.h>
|
| 29 |
+
|
| 30 |
+
#include <winpr/crt.h>
|
| 31 |
+
#include <winpr/print.h>
|
| 32 |
+
#include <winpr/stream.h>
|
| 33 |
+
#include <winpr/library.h>
|
| 34 |
+
#include <winpr/smartcard.h>
|
| 35 |
+
|
| 36 |
+
#include <freerdp/freerdp.h>
|
| 37 |
+
#include <freerdp/channels/rdpdr.h>
|
| 38 |
+
#include <freerdp/channels/scard.h>
|
| 39 |
+
|
| 40 |
+
#include <freerdp/utils/rdpdr_utils.h>
|
| 41 |
+
#include <freerdp/utils/smartcard_pack.h>
|
| 42 |
+
#include <freerdp/utils/smartcard_call.h>
|
| 43 |
+
|
| 44 |
+
#include <freerdp/log.h>
|
| 45 |
+
#define TAG FREERDP_TAG("utils.smartcard.call")
|
| 46 |
+
|
| 47 |
+
#if defined(WITH_SMARTCARD_EMULATE)
|
| 48 |
+
#include <freerdp/emulate/scard/smartcard_emulate.h>
|
| 49 |
+
|
| 50 |
+
#define wrap(ctx, fkt, ...) \
|
| 51 |
+
ctx->useEmulatedCard ? Emulate_##fkt(ctx->emulation, ##__VA_ARGS__) \
|
| 52 |
+
: ctx->pWinSCardApi->pfn##fkt(__VA_ARGS__)
|
| 53 |
+
#define wrap_ptr(ctx, fkt, ...) wrap(ctx, fkt, ##__VA_ARGS__)
|
| 54 |
+
#else
|
| 55 |
+
#define wrap(ctx, fkt, ...) \
|
| 56 |
+
ctx->useEmulatedCard ? SCARD_F_INTERNAL_ERROR : ctx->pWinSCardApi->pfn##fkt(__VA_ARGS__)
|
| 57 |
+
#define wrap_ptr(ctx, fkt, ...) \
|
| 58 |
+
ctx->useEmulatedCard ? NULL : ctx->pWinSCardApi->pfn##fkt(__VA_ARGS__)
|
| 59 |
+
#endif
|
| 60 |
+
|
| 61 |
+
struct s_scard_call_context
|
| 62 |
+
{
|
| 63 |
+
BOOL useEmulatedCard;
|
| 64 |
+
HANDLE StartedEvent;
|
| 65 |
+
wLinkedList* names;
|
| 66 |
+
wHashTable* rgSCardContextList;
|
| 67 |
+
#if defined(WITH_SMARTCARD_EMULATE)
|
| 68 |
+
SmartcardEmulationContext* emulation;
|
| 69 |
+
#endif
|
| 70 |
+
HANDLE hWinSCardLibrary;
|
| 71 |
+
SCardApiFunctionTable WinSCardApi;
|
| 72 |
+
const SCardApiFunctionTable* pWinSCardApi;
|
| 73 |
+
HANDLE stopEvent;
|
| 74 |
+
void* userdata;
|
| 75 |
+
|
| 76 |
+
void* (*fn_new)(void*, SCARDCONTEXT);
|
| 77 |
+
void (*fn_free)(void*);
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
struct s_scard_context_element
|
| 81 |
+
{
|
| 82 |
+
void* context;
|
| 83 |
+
void (*fn_free)(void*);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
static void context_free(void* arg);
|
| 87 |
+
|
| 88 |
+
static LONG smartcard_EstablishContext_Call(scard_call_context* smartcard, wStream* out,
|
| 89 |
+
SMARTCARD_OPERATION* operation)
|
| 90 |
+
{
|
| 91 |
+
LONG status = 0;
|
| 92 |
+
SCARDCONTEXT hContext = { 0 };
|
| 93 |
+
EstablishContext_Return ret = { 0 };
|
| 94 |
+
EstablishContext_Call* call = &operation->call.establishContext;
|
| 95 |
+
status = ret.ReturnCode =
|
| 96 |
+
wrap(smartcard, SCardEstablishContext, call->dwScope, NULL, NULL, &hContext);
|
| 97 |
+
|
| 98 |
+
if (ret.ReturnCode == SCARD_S_SUCCESS)
|
| 99 |
+
{
|
| 100 |
+
const void* key = (void*)(size_t)hContext;
|
| 101 |
+
struct s_scard_context_element* pContext =
|
| 102 |
+
calloc(1, sizeof(struct s_scard_context_element));
|
| 103 |
+
if (!pContext)
|
| 104 |
+
return STATUS_NO_MEMORY;
|
| 105 |
+
|
| 106 |
+
pContext->fn_free = smartcard->fn_free;
|
| 107 |
+
|
| 108 |
+
if (smartcard->fn_new)
|
| 109 |
+
{
|
| 110 |
+
pContext->context = smartcard->fn_new(smartcard->userdata, hContext);
|
| 111 |
+
if (!pContext->context)
|
| 112 |
+
{
|
| 113 |
+
free(pContext);
|
| 114 |
+
return STATUS_NO_MEMORY;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
if (!HashTable_Insert(smartcard->rgSCardContextList, key, (void*)pContext))
|
| 119 |
+
{
|
| 120 |
+
WLog_ERR(TAG, "ListDictionary_Add failed!");
|
| 121 |
+
context_free(pContext);
|
| 122 |
+
return STATUS_INTERNAL_ERROR;
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
else
|
| 126 |
+
{
|
| 127 |
+
return scard_log_status_error(TAG, "SCardEstablishContext", status);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert takes ownership of pContext
|
| 131 |
+
smartcard_scard_context_native_to_redir(&(ret.hContext), hContext);
|
| 132 |
+
|
| 133 |
+
status = smartcard_pack_establish_context_return(out, &ret);
|
| 134 |
+
if (status != SCARD_S_SUCCESS)
|
| 135 |
+
{
|
| 136 |
+
return scard_log_status_error(TAG, "smartcard_pack_establish_context_return", status);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return ret.ReturnCode;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
static LONG smartcard_ReleaseContext_Call(scard_call_context* smartcard, wStream* out,
|
| 143 |
+
SMARTCARD_OPERATION* operation)
|
| 144 |
+
{
|
| 145 |
+
Long_Return ret = { 0 };
|
| 146 |
+
|
| 147 |
+
WINPR_ASSERT(smartcard);
|
| 148 |
+
WINPR_ASSERT(out);
|
| 149 |
+
WINPR_ASSERT(operation);
|
| 150 |
+
|
| 151 |
+
ret.ReturnCode = wrap(smartcard, SCardReleaseContext, operation->hContext);
|
| 152 |
+
|
| 153 |
+
if (ret.ReturnCode == SCARD_S_SUCCESS)
|
| 154 |
+
HashTable_Remove(smartcard->rgSCardContextList, (void*)operation->hContext);
|
| 155 |
+
else
|
| 156 |
+
{
|
| 157 |
+
return scard_log_status_error(TAG, "SCardReleaseContext", ret.ReturnCode);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
smartcard_trace_long_return(&ret, "ReleaseContext");
|
| 161 |
+
return ret.ReturnCode;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
static LONG smartcard_IsValidContext_Call(scard_call_context* smartcard, wStream* out,
|
| 165 |
+
SMARTCARD_OPERATION* operation)
|
| 166 |
+
{
|
| 167 |
+
Long_Return ret = { 0 };
|
| 168 |
+
|
| 169 |
+
WINPR_ASSERT(smartcard);
|
| 170 |
+
WINPR_ASSERT(out);
|
| 171 |
+
WINPR_ASSERT(operation);
|
| 172 |
+
|
| 173 |
+
ret.ReturnCode = wrap(smartcard, SCardIsValidContext, operation->hContext);
|
| 174 |
+
smartcard_trace_long_return(&ret, "IsValidContext");
|
| 175 |
+
return ret.ReturnCode;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
static LONG smartcard_ListReaderGroupsA_Call(scard_call_context* smartcard, wStream* out,
|
| 179 |
+
SMARTCARD_OPERATION* operation)
|
| 180 |
+
{
|
| 181 |
+
LONG status = 0;
|
| 182 |
+
ListReaderGroups_Return ret = { 0 };
|
| 183 |
+
LPSTR mszGroups = NULL;
|
| 184 |
+
DWORD cchGroups = 0;
|
| 185 |
+
|
| 186 |
+
WINPR_ASSERT(smartcard);
|
| 187 |
+
WINPR_ASSERT(out);
|
| 188 |
+
WINPR_ASSERT(operation);
|
| 189 |
+
|
| 190 |
+
cchGroups = SCARD_AUTOALLOCATE;
|
| 191 |
+
ret.ReturnCode =
|
| 192 |
+
wrap(smartcard, SCardListReaderGroupsA, operation->hContext, (LPSTR)&mszGroups, &cchGroups);
|
| 193 |
+
if (cchGroups == SCARD_AUTOALLOCATE)
|
| 194 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 195 |
+
|
| 196 |
+
ret.msz = (BYTE*)mszGroups;
|
| 197 |
+
ret.cBytes = cchGroups;
|
| 198 |
+
|
| 199 |
+
status = smartcard_pack_list_reader_groups_return(out, &ret, FALSE);
|
| 200 |
+
|
| 201 |
+
if (status != SCARD_S_SUCCESS)
|
| 202 |
+
return status;
|
| 203 |
+
|
| 204 |
+
if (mszGroups)
|
| 205 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszGroups);
|
| 206 |
+
|
| 207 |
+
return ret.ReturnCode;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
static LONG smartcard_ListReaderGroupsW_Call(scard_call_context* smartcard, wStream* out,
|
| 211 |
+
SMARTCARD_OPERATION* operation)
|
| 212 |
+
{
|
| 213 |
+
LONG status = 0;
|
| 214 |
+
ListReaderGroups_Return ret = { 0 };
|
| 215 |
+
LPWSTR mszGroups = NULL;
|
| 216 |
+
DWORD cchGroups = 0;
|
| 217 |
+
|
| 218 |
+
WINPR_ASSERT(smartcard);
|
| 219 |
+
WINPR_ASSERT(out);
|
| 220 |
+
WINPR_ASSERT(operation);
|
| 221 |
+
|
| 222 |
+
cchGroups = SCARD_AUTOALLOCATE;
|
| 223 |
+
status = ret.ReturnCode = wrap(smartcard, SCardListReaderGroupsW, operation->hContext,
|
| 224 |
+
(LPWSTR)&mszGroups, &cchGroups);
|
| 225 |
+
if (cchGroups == SCARD_AUTOALLOCATE)
|
| 226 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 227 |
+
|
| 228 |
+
ret.msz = (BYTE*)mszGroups;
|
| 229 |
+
|
| 230 |
+
WINPR_ASSERT(cchGroups < SCARD_AUTOALLOCATE / sizeof(WCHAR));
|
| 231 |
+
const size_t blen = sizeof(WCHAR) * cchGroups;
|
| 232 |
+
WINPR_ASSERT(blen <= UINT32_MAX);
|
| 233 |
+
ret.cBytes = (UINT32)blen;
|
| 234 |
+
|
| 235 |
+
if (status != SCARD_S_SUCCESS)
|
| 236 |
+
return status;
|
| 237 |
+
|
| 238 |
+
status = smartcard_pack_list_reader_groups_return(out, &ret, TRUE);
|
| 239 |
+
|
| 240 |
+
if (status != SCARD_S_SUCCESS)
|
| 241 |
+
return status;
|
| 242 |
+
|
| 243 |
+
if (mszGroups)
|
| 244 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszGroups);
|
| 245 |
+
|
| 246 |
+
return ret.ReturnCode;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
static BOOL filter_match(wLinkedList* list, LPCSTR reader, size_t readerLen)
|
| 250 |
+
{
|
| 251 |
+
if (readerLen < 1)
|
| 252 |
+
return FALSE;
|
| 253 |
+
|
| 254 |
+
LinkedList_Enumerator_Reset(list);
|
| 255 |
+
|
| 256 |
+
while (LinkedList_Enumerator_MoveNext(list))
|
| 257 |
+
{
|
| 258 |
+
const char* filter = LinkedList_Enumerator_Current(list);
|
| 259 |
+
|
| 260 |
+
if (filter)
|
| 261 |
+
{
|
| 262 |
+
if (strstr(reader, filter) != NULL)
|
| 263 |
+
return TRUE;
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
return FALSE;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
static DWORD filter_device_by_name_a(wLinkedList* list, LPSTR* mszReaders, DWORD cchReaders)
|
| 271 |
+
{
|
| 272 |
+
size_t rpos = 0;
|
| 273 |
+
size_t wpos = 0;
|
| 274 |
+
|
| 275 |
+
if (*mszReaders == NULL || LinkedList_Count(list) < 1)
|
| 276 |
+
return cchReaders;
|
| 277 |
+
|
| 278 |
+
do
|
| 279 |
+
{
|
| 280 |
+
LPCSTR rreader = &(*mszReaders)[rpos];
|
| 281 |
+
LPSTR wreader = &(*mszReaders)[wpos];
|
| 282 |
+
size_t readerLen = strnlen(rreader, cchReaders - rpos);
|
| 283 |
+
|
| 284 |
+
rpos += readerLen + 1;
|
| 285 |
+
|
| 286 |
+
if (filter_match(list, rreader, readerLen))
|
| 287 |
+
{
|
| 288 |
+
if (rreader != wreader)
|
| 289 |
+
memmove(wreader, rreader, readerLen + 1);
|
| 290 |
+
|
| 291 |
+
wpos += readerLen + 1;
|
| 292 |
+
}
|
| 293 |
+
} while (rpos < cchReaders);
|
| 294 |
+
|
| 295 |
+
/* this string must be double 0 terminated */
|
| 296 |
+
if (rpos != wpos)
|
| 297 |
+
{
|
| 298 |
+
if (wpos >= cchReaders)
|
| 299 |
+
return 0;
|
| 300 |
+
|
| 301 |
+
(*mszReaders)[wpos++] = '\0';
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
return (DWORD)wpos;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
static DWORD filter_device_by_name_w(wLinkedList* list, LPWSTR* mszReaders, DWORD cchReaders)
|
| 308 |
+
{
|
| 309 |
+
DWORD rc = 0;
|
| 310 |
+
LPSTR readers = NULL;
|
| 311 |
+
|
| 312 |
+
if (LinkedList_Count(list) < 1)
|
| 313 |
+
return cchReaders;
|
| 314 |
+
|
| 315 |
+
readers = ConvertMszWCharNToUtf8Alloc(*mszReaders, cchReaders, NULL);
|
| 316 |
+
|
| 317 |
+
if (!readers)
|
| 318 |
+
{
|
| 319 |
+
free(readers);
|
| 320 |
+
return 0;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
free(*mszReaders);
|
| 324 |
+
*mszReaders = NULL;
|
| 325 |
+
rc = filter_device_by_name_a(list, &readers, cchReaders);
|
| 326 |
+
|
| 327 |
+
*mszReaders = ConvertMszUtf8NToWCharAlloc(readers, rc, NULL);
|
| 328 |
+
if (!*mszReaders)
|
| 329 |
+
rc = 0;
|
| 330 |
+
|
| 331 |
+
free(readers);
|
| 332 |
+
return rc;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
static LONG smartcard_ListReadersA_Call(scard_call_context* smartcard, wStream* out,
|
| 336 |
+
SMARTCARD_OPERATION* operation)
|
| 337 |
+
{
|
| 338 |
+
ListReaders_Return ret = { 0 };
|
| 339 |
+
LPSTR mszReaders = NULL;
|
| 340 |
+
|
| 341 |
+
WINPR_ASSERT(smartcard);
|
| 342 |
+
WINPR_ASSERT(out);
|
| 343 |
+
WINPR_ASSERT(operation);
|
| 344 |
+
|
| 345 |
+
ListReaders_Call* call = &operation->call.listReaders;
|
| 346 |
+
DWORD cchReaders = SCARD_AUTOALLOCATE;
|
| 347 |
+
LONG status = ret.ReturnCode = wrap(smartcard, SCardListReadersA, operation->hContext,
|
| 348 |
+
(LPCSTR)call->mszGroups, (LPSTR)&mszReaders, &cchReaders);
|
| 349 |
+
if (cchReaders == SCARD_AUTOALLOCATE)
|
| 350 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 351 |
+
|
| 352 |
+
if (status != SCARD_S_SUCCESS)
|
| 353 |
+
{
|
| 354 |
+
(void)scard_log_status_error(TAG, "SCardListReadersA", status);
|
| 355 |
+
return smartcard_pack_list_readers_return(out, &ret, FALSE);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
cchReaders = filter_device_by_name_a(smartcard->names, &mszReaders, cchReaders);
|
| 359 |
+
ret.msz = (BYTE*)mszReaders;
|
| 360 |
+
ret.cBytes = cchReaders;
|
| 361 |
+
|
| 362 |
+
status = smartcard_pack_list_readers_return(out, &ret, FALSE);
|
| 363 |
+
if (mszReaders)
|
| 364 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszReaders);
|
| 365 |
+
|
| 366 |
+
if (status != SCARD_S_SUCCESS)
|
| 367 |
+
return scard_log_status_error(TAG, "smartcard_pack_list_readers_return", status);
|
| 368 |
+
|
| 369 |
+
return ret.ReturnCode;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
static LONG smartcard_ListReadersW_Call(scard_call_context* smartcard, wStream* out,
|
| 373 |
+
SMARTCARD_OPERATION* operation)
|
| 374 |
+
{
|
| 375 |
+
LONG status = 0;
|
| 376 |
+
ListReaders_Return ret = { 0 };
|
| 377 |
+
DWORD cchReaders = 0;
|
| 378 |
+
ListReaders_Call* call = NULL;
|
| 379 |
+
union
|
| 380 |
+
{
|
| 381 |
+
const BYTE* bp;
|
| 382 |
+
const char* sz;
|
| 383 |
+
const WCHAR* wz;
|
| 384 |
+
} string;
|
| 385 |
+
union
|
| 386 |
+
{
|
| 387 |
+
WCHAR** ppw;
|
| 388 |
+
WCHAR* pw;
|
| 389 |
+
CHAR* pc;
|
| 390 |
+
BYTE* pb;
|
| 391 |
+
} mszReaders;
|
| 392 |
+
|
| 393 |
+
WINPR_ASSERT(smartcard);
|
| 394 |
+
WINPR_ASSERT(operation);
|
| 395 |
+
|
| 396 |
+
call = &operation->call.listReaders;
|
| 397 |
+
|
| 398 |
+
string.bp = call->mszGroups;
|
| 399 |
+
cchReaders = SCARD_AUTOALLOCATE;
|
| 400 |
+
status = ret.ReturnCode = wrap(smartcard, SCardListReadersW, operation->hContext, string.wz,
|
| 401 |
+
(LPWSTR)&mszReaders.pw, &cchReaders);
|
| 402 |
+
if (cchReaders == SCARD_AUTOALLOCATE)
|
| 403 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 404 |
+
|
| 405 |
+
if (status != SCARD_S_SUCCESS)
|
| 406 |
+
{
|
| 407 |
+
(void)scard_log_status_error(TAG, "SCardListReadersW", status);
|
| 408 |
+
return smartcard_pack_list_readers_return(out, &ret, TRUE);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
cchReaders = filter_device_by_name_w(smartcard->names, &mszReaders.pw, cchReaders);
|
| 412 |
+
ret.msz = mszReaders.pb;
|
| 413 |
+
ret.cBytes = cchReaders * sizeof(WCHAR);
|
| 414 |
+
status = smartcard_pack_list_readers_return(out, &ret, TRUE);
|
| 415 |
+
|
| 416 |
+
if (mszReaders.pb)
|
| 417 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszReaders.pb);
|
| 418 |
+
|
| 419 |
+
if (status != SCARD_S_SUCCESS)
|
| 420 |
+
return status;
|
| 421 |
+
|
| 422 |
+
return ret.ReturnCode;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
static LONG smartcard_IntroduceReaderGroupA_Call(scard_call_context* smartcard, wStream* out,
|
| 426 |
+
SMARTCARD_OPERATION* operation)
|
| 427 |
+
{
|
| 428 |
+
Long_Return ret = { 0 };
|
| 429 |
+
ContextAndStringA_Call* call = NULL;
|
| 430 |
+
|
| 431 |
+
WINPR_ASSERT(smartcard);
|
| 432 |
+
WINPR_ASSERT(out);
|
| 433 |
+
WINPR_ASSERT(operation);
|
| 434 |
+
|
| 435 |
+
call = &operation->call.contextAndStringA;
|
| 436 |
+
ret.ReturnCode = wrap(smartcard, SCardIntroduceReaderGroupA, operation->hContext, call->sz);
|
| 437 |
+
scard_log_status_error(TAG, "SCardIntroduceReaderGroupA", ret.ReturnCode);
|
| 438 |
+
smartcard_trace_long_return(&ret, "IntroduceReaderGroupA");
|
| 439 |
+
return ret.ReturnCode;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
static LONG smartcard_IntroduceReaderGroupW_Call(scard_call_context* smartcard, wStream* out,
|
| 443 |
+
SMARTCARD_OPERATION* operation)
|
| 444 |
+
{
|
| 445 |
+
Long_Return ret = { 0 };
|
| 446 |
+
ContextAndStringW_Call* call = NULL;
|
| 447 |
+
|
| 448 |
+
WINPR_ASSERT(smartcard);
|
| 449 |
+
WINPR_ASSERT(out);
|
| 450 |
+
WINPR_ASSERT(operation);
|
| 451 |
+
|
| 452 |
+
call = &operation->call.contextAndStringW;
|
| 453 |
+
ret.ReturnCode = wrap(smartcard, SCardIntroduceReaderGroupW, operation->hContext, call->sz);
|
| 454 |
+
scard_log_status_error(TAG, "SCardIntroduceReaderGroupW", ret.ReturnCode);
|
| 455 |
+
smartcard_trace_long_return(&ret, "IntroduceReaderGroupW");
|
| 456 |
+
return ret.ReturnCode;
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
static LONG smartcard_IntroduceReaderA_Call(scard_call_context* smartcard, wStream* out,
|
| 460 |
+
SMARTCARD_OPERATION* operation)
|
| 461 |
+
{
|
| 462 |
+
Long_Return ret = { 0 };
|
| 463 |
+
ContextAndTwoStringA_Call* call = NULL;
|
| 464 |
+
|
| 465 |
+
WINPR_ASSERT(smartcard);
|
| 466 |
+
WINPR_ASSERT(out);
|
| 467 |
+
WINPR_ASSERT(operation);
|
| 468 |
+
|
| 469 |
+
call = &operation->call.contextAndTwoStringA;
|
| 470 |
+
ret.ReturnCode =
|
| 471 |
+
wrap(smartcard, SCardIntroduceReaderA, operation->hContext, call->sz1, call->sz2);
|
| 472 |
+
scard_log_status_error(TAG, "SCardIntroduceReaderA", ret.ReturnCode);
|
| 473 |
+
smartcard_trace_long_return(&ret, "IntroduceReaderA");
|
| 474 |
+
return ret.ReturnCode;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
static LONG smartcard_IntroduceReaderW_Call(scard_call_context* smartcard, wStream* out,
|
| 478 |
+
SMARTCARD_OPERATION* operation)
|
| 479 |
+
{
|
| 480 |
+
Long_Return ret = { 0 };
|
| 481 |
+
ContextAndTwoStringW_Call* call = NULL;
|
| 482 |
+
|
| 483 |
+
WINPR_ASSERT(smartcard);
|
| 484 |
+
WINPR_ASSERT(out);
|
| 485 |
+
WINPR_ASSERT(operation);
|
| 486 |
+
|
| 487 |
+
call = &operation->call.contextAndTwoStringW;
|
| 488 |
+
ret.ReturnCode =
|
| 489 |
+
wrap(smartcard, SCardIntroduceReaderW, operation->hContext, call->sz1, call->sz2);
|
| 490 |
+
scard_log_status_error(TAG, "SCardIntroduceReaderW", ret.ReturnCode);
|
| 491 |
+
smartcard_trace_long_return(&ret, "IntroduceReaderW");
|
| 492 |
+
return ret.ReturnCode;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
static LONG smartcard_ForgetReaderA_Call(scard_call_context* smartcard, wStream* out,
|
| 496 |
+
SMARTCARD_OPERATION* operation)
|
| 497 |
+
{
|
| 498 |
+
Long_Return ret = { 0 };
|
| 499 |
+
ContextAndStringA_Call* call = NULL;
|
| 500 |
+
|
| 501 |
+
WINPR_ASSERT(smartcard);
|
| 502 |
+
WINPR_ASSERT(out);
|
| 503 |
+
WINPR_ASSERT(operation);
|
| 504 |
+
|
| 505 |
+
call = &operation->call.contextAndStringA;
|
| 506 |
+
ret.ReturnCode = wrap(smartcard, SCardForgetReaderA, operation->hContext, call->sz);
|
| 507 |
+
scard_log_status_error(TAG, "SCardForgetReaderA", ret.ReturnCode);
|
| 508 |
+
smartcard_trace_long_return(&ret, "SCardForgetReaderA");
|
| 509 |
+
return ret.ReturnCode;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
static LONG smartcard_ForgetReaderW_Call(scard_call_context* smartcard, wStream* out,
|
| 513 |
+
SMARTCARD_OPERATION* operation)
|
| 514 |
+
{
|
| 515 |
+
Long_Return ret = { 0 };
|
| 516 |
+
ContextAndStringW_Call* call = NULL;
|
| 517 |
+
|
| 518 |
+
WINPR_ASSERT(smartcard);
|
| 519 |
+
WINPR_ASSERT(out);
|
| 520 |
+
WINPR_ASSERT(operation);
|
| 521 |
+
|
| 522 |
+
call = &operation->call.contextAndStringW;
|
| 523 |
+
ret.ReturnCode = wrap(smartcard, SCardForgetReaderW, operation->hContext, call->sz);
|
| 524 |
+
scard_log_status_error(TAG, "SCardForgetReaderW", ret.ReturnCode);
|
| 525 |
+
smartcard_trace_long_return(&ret, "SCardForgetReaderW");
|
| 526 |
+
return ret.ReturnCode;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
static LONG smartcard_AddReaderToGroupA_Call(scard_call_context* smartcard, wStream* out,
|
| 530 |
+
SMARTCARD_OPERATION* operation)
|
| 531 |
+
{
|
| 532 |
+
Long_Return ret = { 0 };
|
| 533 |
+
ContextAndTwoStringA_Call* call = NULL;
|
| 534 |
+
|
| 535 |
+
WINPR_ASSERT(smartcard);
|
| 536 |
+
WINPR_ASSERT(out);
|
| 537 |
+
WINPR_ASSERT(operation);
|
| 538 |
+
|
| 539 |
+
call = &operation->call.contextAndTwoStringA;
|
| 540 |
+
ret.ReturnCode =
|
| 541 |
+
wrap(smartcard, SCardAddReaderToGroupA, operation->hContext, call->sz1, call->sz2);
|
| 542 |
+
scard_log_status_error(TAG, "SCardAddReaderToGroupA", ret.ReturnCode);
|
| 543 |
+
smartcard_trace_long_return(&ret, "SCardAddReaderToGroupA");
|
| 544 |
+
return ret.ReturnCode;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
static LONG smartcard_AddReaderToGroupW_Call(scard_call_context* smartcard, wStream* out,
|
| 548 |
+
SMARTCARD_OPERATION* operation)
|
| 549 |
+
{
|
| 550 |
+
Long_Return ret = { 0 };
|
| 551 |
+
ContextAndTwoStringW_Call* call = NULL;
|
| 552 |
+
|
| 553 |
+
WINPR_ASSERT(smartcard);
|
| 554 |
+
WINPR_ASSERT(out);
|
| 555 |
+
WINPR_ASSERT(operation);
|
| 556 |
+
|
| 557 |
+
call = &operation->call.contextAndTwoStringW;
|
| 558 |
+
ret.ReturnCode =
|
| 559 |
+
wrap(smartcard, SCardAddReaderToGroupW, operation->hContext, call->sz1, call->sz2);
|
| 560 |
+
scard_log_status_error(TAG, "SCardAddReaderToGroupW", ret.ReturnCode);
|
| 561 |
+
smartcard_trace_long_return(&ret, "SCardAddReaderToGroupA");
|
| 562 |
+
return ret.ReturnCode;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
static LONG smartcard_RemoveReaderFromGroupA_Call(scard_call_context* smartcard, wStream* out,
|
| 566 |
+
SMARTCARD_OPERATION* operation)
|
| 567 |
+
{
|
| 568 |
+
Long_Return ret = { 0 };
|
| 569 |
+
ContextAndTwoStringA_Call* call = NULL;
|
| 570 |
+
|
| 571 |
+
WINPR_ASSERT(smartcard);
|
| 572 |
+
WINPR_ASSERT(out);
|
| 573 |
+
WINPR_ASSERT(operation);
|
| 574 |
+
|
| 575 |
+
call = &operation->call.contextAndTwoStringA;
|
| 576 |
+
ret.ReturnCode =
|
| 577 |
+
wrap(smartcard, SCardRemoveReaderFromGroupA, operation->hContext, call->sz1, call->sz2);
|
| 578 |
+
scard_log_status_error(TAG, "SCardRemoveReaderFromGroupA", ret.ReturnCode);
|
| 579 |
+
smartcard_trace_long_return(&ret, "SCardRemoveReaderFromGroupA");
|
| 580 |
+
return ret.ReturnCode;
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
static LONG smartcard_RemoveReaderFromGroupW_Call(scard_call_context* smartcard, wStream* out,
|
| 584 |
+
SMARTCARD_OPERATION* operation)
|
| 585 |
+
{
|
| 586 |
+
Long_Return ret = { 0 };
|
| 587 |
+
ContextAndTwoStringW_Call* call = NULL;
|
| 588 |
+
|
| 589 |
+
WINPR_ASSERT(smartcard);
|
| 590 |
+
WINPR_ASSERT(out);
|
| 591 |
+
WINPR_ASSERT(operation);
|
| 592 |
+
|
| 593 |
+
call = &operation->call.contextAndTwoStringW;
|
| 594 |
+
ret.ReturnCode =
|
| 595 |
+
wrap(smartcard, SCardRemoveReaderFromGroupW, operation->hContext, call->sz1, call->sz2);
|
| 596 |
+
scard_log_status_error(TAG, "SCardRemoveReaderFromGroupW", ret.ReturnCode);
|
| 597 |
+
smartcard_trace_long_return(&ret, "SCardRemoveReaderFromGroupW");
|
| 598 |
+
return ret.ReturnCode;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
static LONG smartcard_LocateCardsA_Call(scard_call_context* smartcard, wStream* out,
|
| 602 |
+
SMARTCARD_OPERATION* operation)
|
| 603 |
+
{
|
| 604 |
+
LONG status = 0;
|
| 605 |
+
LocateCards_Return ret = { 0 };
|
| 606 |
+
LocateCardsA_Call* call = NULL;
|
| 607 |
+
|
| 608 |
+
WINPR_ASSERT(smartcard);
|
| 609 |
+
WINPR_ASSERT(operation);
|
| 610 |
+
|
| 611 |
+
call = &operation->call.locateCardsA;
|
| 612 |
+
|
| 613 |
+
ret.ReturnCode = wrap(smartcard, SCardLocateCardsA, operation->hContext, call->mszCards,
|
| 614 |
+
call->rgReaderStates, call->cReaders);
|
| 615 |
+
scard_log_status_error(TAG, "SCardLocateCardsA", ret.ReturnCode);
|
| 616 |
+
ret.cReaders = call->cReaders;
|
| 617 |
+
ret.rgReaderStates = NULL;
|
| 618 |
+
|
| 619 |
+
if (ret.cReaders > 0)
|
| 620 |
+
{
|
| 621 |
+
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
| 622 |
+
|
| 623 |
+
if (!ret.rgReaderStates)
|
| 624 |
+
return STATUS_NO_MEMORY;
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
for (UINT32 x = 0; x < ret.cReaders; x++)
|
| 628 |
+
{
|
| 629 |
+
ret.rgReaderStates[x].dwCurrentState = call->rgReaderStates[x].dwCurrentState;
|
| 630 |
+
ret.rgReaderStates[x].dwEventState = call->rgReaderStates[x].dwEventState;
|
| 631 |
+
ret.rgReaderStates[x].cbAtr = call->rgReaderStates[x].cbAtr;
|
| 632 |
+
CopyMemory(&(ret.rgReaderStates[x].rgbAtr), &(call->rgReaderStates[x].rgbAtr),
|
| 633 |
+
sizeof(ret.rgReaderStates[x].rgbAtr));
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
status = smartcard_pack_locate_cards_return(out, &ret);
|
| 637 |
+
|
| 638 |
+
if (status != SCARD_S_SUCCESS)
|
| 639 |
+
return status;
|
| 640 |
+
|
| 641 |
+
return ret.ReturnCode;
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
static LONG smartcard_LocateCardsW_Call(scard_call_context* smartcard, wStream* out,
|
| 645 |
+
SMARTCARD_OPERATION* operation)
|
| 646 |
+
{
|
| 647 |
+
LONG status = 0;
|
| 648 |
+
LocateCards_Return ret = { 0 };
|
| 649 |
+
LocateCardsW_Call* call = NULL;
|
| 650 |
+
|
| 651 |
+
WINPR_ASSERT(smartcard);
|
| 652 |
+
WINPR_ASSERT(operation);
|
| 653 |
+
|
| 654 |
+
call = &operation->call.locateCardsW;
|
| 655 |
+
|
| 656 |
+
ret.ReturnCode = wrap(smartcard, SCardLocateCardsW, operation->hContext, call->mszCards,
|
| 657 |
+
call->rgReaderStates, call->cReaders);
|
| 658 |
+
scard_log_status_error(TAG, "SCardLocateCardsW", ret.ReturnCode);
|
| 659 |
+
ret.cReaders = call->cReaders;
|
| 660 |
+
ret.rgReaderStates = NULL;
|
| 661 |
+
|
| 662 |
+
if (ret.cReaders > 0)
|
| 663 |
+
{
|
| 664 |
+
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
| 665 |
+
|
| 666 |
+
if (!ret.rgReaderStates)
|
| 667 |
+
return STATUS_NO_MEMORY;
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
for (UINT32 x = 0; x < ret.cReaders; x++)
|
| 671 |
+
{
|
| 672 |
+
ret.rgReaderStates[x].dwCurrentState = call->rgReaderStates[x].dwCurrentState;
|
| 673 |
+
ret.rgReaderStates[x].dwEventState = call->rgReaderStates[x].dwEventState;
|
| 674 |
+
ret.rgReaderStates[x].cbAtr = call->rgReaderStates[x].cbAtr;
|
| 675 |
+
CopyMemory(&(ret.rgReaderStates[x].rgbAtr), &(call->rgReaderStates[x].rgbAtr),
|
| 676 |
+
sizeof(ret.rgReaderStates[x].rgbAtr));
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
status = smartcard_pack_locate_cards_return(out, &ret);
|
| 680 |
+
|
| 681 |
+
if (status != SCARD_S_SUCCESS)
|
| 682 |
+
return status;
|
| 683 |
+
|
| 684 |
+
return ret.ReturnCode;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
static LONG smartcard_ReadCacheA_Call(scard_call_context* smartcard, wStream* out,
|
| 688 |
+
SMARTCARD_OPERATION* operation)
|
| 689 |
+
{
|
| 690 |
+
LONG status = 0;
|
| 691 |
+
BOOL autoalloc = 0;
|
| 692 |
+
ReadCache_Return ret = { 0 };
|
| 693 |
+
ReadCacheA_Call* call = NULL;
|
| 694 |
+
|
| 695 |
+
WINPR_ASSERT(smartcard);
|
| 696 |
+
WINPR_ASSERT(out);
|
| 697 |
+
WINPR_ASSERT(operation);
|
| 698 |
+
|
| 699 |
+
call = &operation->call.readCacheA;
|
| 700 |
+
autoalloc = (call->Common.cbDataLen == SCARD_AUTOALLOCATE);
|
| 701 |
+
|
| 702 |
+
if (!call->Common.fPbDataIsNULL)
|
| 703 |
+
{
|
| 704 |
+
ret.cbDataLen = call->Common.cbDataLen;
|
| 705 |
+
if (!autoalloc)
|
| 706 |
+
{
|
| 707 |
+
ret.pbData = malloc(ret.cbDataLen);
|
| 708 |
+
if (!ret.pbData)
|
| 709 |
+
return SCARD_F_INTERNAL_ERROR;
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
if (autoalloc)
|
| 714 |
+
ret.ReturnCode = wrap(smartcard, SCardReadCacheA, operation->hContext,
|
| 715 |
+
call->Common.CardIdentifier, call->Common.FreshnessCounter,
|
| 716 |
+
call->szLookupName, (BYTE*)&ret.pbData, &ret.cbDataLen);
|
| 717 |
+
else
|
| 718 |
+
ret.ReturnCode =
|
| 719 |
+
wrap(smartcard, SCardReadCacheA, operation->hContext, call->Common.CardIdentifier,
|
| 720 |
+
call->Common.FreshnessCounter, call->szLookupName, ret.pbData, &ret.cbDataLen);
|
| 721 |
+
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
| 722 |
+
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
| 723 |
+
{
|
| 724 |
+
scard_log_status_error(TAG, "SCardReadCacheA", ret.ReturnCode);
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
status = smartcard_pack_read_cache_return(out, &ret);
|
| 728 |
+
if (autoalloc)
|
| 729 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, ret.pbData);
|
| 730 |
+
else
|
| 731 |
+
free(ret.pbData);
|
| 732 |
+
if (status != SCARD_S_SUCCESS)
|
| 733 |
+
return status;
|
| 734 |
+
|
| 735 |
+
return ret.ReturnCode;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
static LONG smartcard_ReadCacheW_Call(scard_call_context* smartcard, wStream* out,
|
| 739 |
+
SMARTCARD_OPERATION* operation)
|
| 740 |
+
{
|
| 741 |
+
LONG status = 0;
|
| 742 |
+
ReadCache_Return ret = { 0 };
|
| 743 |
+
ReadCacheW_Call* call = NULL;
|
| 744 |
+
|
| 745 |
+
WINPR_ASSERT(smartcard);
|
| 746 |
+
WINPR_ASSERT(out);
|
| 747 |
+
WINPR_ASSERT(operation);
|
| 748 |
+
|
| 749 |
+
call = &operation->call.readCacheW;
|
| 750 |
+
|
| 751 |
+
if (!call->Common.fPbDataIsNULL)
|
| 752 |
+
ret.cbDataLen = SCARD_AUTOALLOCATE;
|
| 753 |
+
|
| 754 |
+
ret.ReturnCode =
|
| 755 |
+
wrap(smartcard, SCardReadCacheW, operation->hContext, call->Common.CardIdentifier,
|
| 756 |
+
call->Common.FreshnessCounter, call->szLookupName, (BYTE*)&ret.pbData, &ret.cbDataLen);
|
| 757 |
+
|
| 758 |
+
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
| 759 |
+
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
| 760 |
+
{
|
| 761 |
+
scard_log_status_error(TAG, "SCardReadCacheW", ret.ReturnCode);
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
status = smartcard_pack_read_cache_return(out, &ret);
|
| 765 |
+
|
| 766 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, ret.pbData);
|
| 767 |
+
|
| 768 |
+
if (status != SCARD_S_SUCCESS)
|
| 769 |
+
return status;
|
| 770 |
+
|
| 771 |
+
return ret.ReturnCode;
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
static LONG smartcard_WriteCacheA_Call(scard_call_context* smartcard, wStream* out,
|
| 775 |
+
SMARTCARD_OPERATION* operation)
|
| 776 |
+
{
|
| 777 |
+
Long_Return ret = { 0 };
|
| 778 |
+
WriteCacheA_Call* call = NULL;
|
| 779 |
+
|
| 780 |
+
WINPR_ASSERT(smartcard);
|
| 781 |
+
WINPR_ASSERT(out);
|
| 782 |
+
WINPR_ASSERT(operation);
|
| 783 |
+
|
| 784 |
+
call = &operation->call.writeCacheA;
|
| 785 |
+
|
| 786 |
+
ret.ReturnCode = wrap(smartcard, SCardWriteCacheA, operation->hContext,
|
| 787 |
+
call->Common.CardIdentifier, call->Common.FreshnessCounter,
|
| 788 |
+
call->szLookupName, call->Common.pbData, call->Common.cbDataLen);
|
| 789 |
+
scard_log_status_error(TAG, "SCardWriteCacheA", ret.ReturnCode);
|
| 790 |
+
smartcard_trace_long_return(&ret, "SCardWriteCacheA");
|
| 791 |
+
return ret.ReturnCode;
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
static LONG smartcard_WriteCacheW_Call(scard_call_context* smartcard, wStream* out,
|
| 795 |
+
SMARTCARD_OPERATION* operation)
|
| 796 |
+
{
|
| 797 |
+
Long_Return ret = { 0 };
|
| 798 |
+
WriteCacheW_Call* call = NULL;
|
| 799 |
+
|
| 800 |
+
WINPR_ASSERT(smartcard);
|
| 801 |
+
WINPR_ASSERT(out);
|
| 802 |
+
WINPR_ASSERT(operation);
|
| 803 |
+
|
| 804 |
+
call = &operation->call.writeCacheW;
|
| 805 |
+
|
| 806 |
+
ret.ReturnCode = wrap(smartcard, SCardWriteCacheW, operation->hContext,
|
| 807 |
+
call->Common.CardIdentifier, call->Common.FreshnessCounter,
|
| 808 |
+
call->szLookupName, call->Common.pbData, call->Common.cbDataLen);
|
| 809 |
+
scard_log_status_error(TAG, "SCardWriteCacheW", ret.ReturnCode);
|
| 810 |
+
smartcard_trace_long_return(&ret, "SCardWriteCacheW");
|
| 811 |
+
return ret.ReturnCode;
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
static LONG smartcard_GetTransmitCount_Call(scard_call_context* smartcard, wStream* out,
|
| 815 |
+
SMARTCARD_OPERATION* operation)
|
| 816 |
+
{
|
| 817 |
+
LONG status = 0;
|
| 818 |
+
GetTransmitCount_Return ret = { 0 };
|
| 819 |
+
|
| 820 |
+
WINPR_ASSERT(smartcard);
|
| 821 |
+
WINPR_ASSERT(out);
|
| 822 |
+
WINPR_ASSERT(operation);
|
| 823 |
+
|
| 824 |
+
ret.ReturnCode = wrap(smartcard, SCardGetTransmitCount, operation->hCard, &ret.cTransmitCount);
|
| 825 |
+
scard_log_status_error(TAG, "SCardGetTransmitCount", ret.ReturnCode);
|
| 826 |
+
status = smartcard_pack_get_transmit_count_return(out, &ret);
|
| 827 |
+
if (status != SCARD_S_SUCCESS)
|
| 828 |
+
return status;
|
| 829 |
+
|
| 830 |
+
return ret.ReturnCode;
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
static LONG smartcard_ReleaseStartedEvent_Call(scard_call_context* smartcard, wStream* out,
|
| 834 |
+
SMARTCARD_OPERATION* operation)
|
| 835 |
+
{
|
| 836 |
+
WINPR_UNUSED(smartcard);
|
| 837 |
+
WINPR_UNUSED(out);
|
| 838 |
+
WINPR_UNUSED(operation);
|
| 839 |
+
|
| 840 |
+
WLog_WARN(TAG, "According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
| 841 |
+
"this is not supported?!?");
|
| 842 |
+
return SCARD_E_UNSUPPORTED_FEATURE;
|
| 843 |
+
}
|
| 844 |
+
|
| 845 |
+
static LONG smartcard_GetReaderIcon_Call(scard_call_context* smartcard, wStream* out,
|
| 846 |
+
SMARTCARD_OPERATION* operation)
|
| 847 |
+
{
|
| 848 |
+
LONG status = 0;
|
| 849 |
+
GetReaderIcon_Return ret = { 0 };
|
| 850 |
+
GetReaderIcon_Call* call = NULL;
|
| 851 |
+
|
| 852 |
+
WINPR_ASSERT(smartcard);
|
| 853 |
+
WINPR_ASSERT(out);
|
| 854 |
+
WINPR_ASSERT(operation);
|
| 855 |
+
|
| 856 |
+
call = &operation->call.getReaderIcon;
|
| 857 |
+
|
| 858 |
+
ret.cbDataLen = SCARD_AUTOALLOCATE;
|
| 859 |
+
ret.ReturnCode = wrap(smartcard, SCardGetReaderIconW, operation->hContext, call->szReaderName,
|
| 860 |
+
(LPBYTE)&ret.pbData, &ret.cbDataLen);
|
| 861 |
+
scard_log_status_error(TAG, "SCardGetReaderIconW", ret.ReturnCode);
|
| 862 |
+
if (ret.cbDataLen == SCARD_AUTOALLOCATE)
|
| 863 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 864 |
+
|
| 865 |
+
status = smartcard_pack_get_reader_icon_return(out, &ret);
|
| 866 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, ret.pbData);
|
| 867 |
+
if (status != SCARD_S_SUCCESS)
|
| 868 |
+
return status;
|
| 869 |
+
|
| 870 |
+
return ret.ReturnCode;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
static LONG smartcard_GetDeviceTypeId_Call(scard_call_context* smartcard, wStream* out,
|
| 874 |
+
SMARTCARD_OPERATION* operation)
|
| 875 |
+
{
|
| 876 |
+
LONG status = 0;
|
| 877 |
+
GetDeviceTypeId_Return ret = { 0 };
|
| 878 |
+
GetDeviceTypeId_Call* call = NULL;
|
| 879 |
+
|
| 880 |
+
WINPR_ASSERT(smartcard);
|
| 881 |
+
WINPR_ASSERT(out);
|
| 882 |
+
WINPR_ASSERT(operation);
|
| 883 |
+
|
| 884 |
+
call = &operation->call.getDeviceTypeId;
|
| 885 |
+
|
| 886 |
+
ret.ReturnCode = wrap(smartcard, SCardGetDeviceTypeIdW, operation->hContext, call->szReaderName,
|
| 887 |
+
&ret.dwDeviceId);
|
| 888 |
+
scard_log_status_error(TAG, "SCardGetDeviceTypeIdW", ret.ReturnCode);
|
| 889 |
+
|
| 890 |
+
status = smartcard_pack_device_type_id_return(out, &ret);
|
| 891 |
+
if (status != SCARD_S_SUCCESS)
|
| 892 |
+
return status;
|
| 893 |
+
|
| 894 |
+
return ret.ReturnCode;
|
| 895 |
+
}
|
| 896 |
+
|
| 897 |
+
static LONG smartcard_GetStatusChangeA_Call(scard_call_context* smartcard, wStream* out,
|
| 898 |
+
SMARTCARD_OPERATION* operation)
|
| 899 |
+
{
|
| 900 |
+
LONG status = STATUS_NO_MEMORY;
|
| 901 |
+
DWORD dwTimeOut = 0;
|
| 902 |
+
const DWORD dwTimeStep = 100;
|
| 903 |
+
GetStatusChange_Return ret = { 0 };
|
| 904 |
+
GetStatusChangeA_Call* call = NULL;
|
| 905 |
+
LPSCARD_READERSTATEA rgReaderStates = NULL;
|
| 906 |
+
|
| 907 |
+
WINPR_ASSERT(smartcard);
|
| 908 |
+
WINPR_ASSERT(out);
|
| 909 |
+
WINPR_ASSERT(operation);
|
| 910 |
+
|
| 911 |
+
call = &operation->call.getStatusChangeA;
|
| 912 |
+
dwTimeOut = call->dwTimeOut;
|
| 913 |
+
|
| 914 |
+
if (call->cReaders > 0)
|
| 915 |
+
{
|
| 916 |
+
ret.cReaders = call->cReaders;
|
| 917 |
+
rgReaderStates = calloc(ret.cReaders, sizeof(SCARD_READERSTATEA));
|
| 918 |
+
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
| 919 |
+
if (!rgReaderStates || !ret.rgReaderStates)
|
| 920 |
+
goto fail;
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
for (UINT32 x = 0; x < MAX(1, dwTimeOut);)
|
| 924 |
+
{
|
| 925 |
+
if (call->cReaders > 0)
|
| 926 |
+
memcpy(rgReaderStates, call->rgReaderStates,
|
| 927 |
+
call->cReaders * sizeof(SCARD_READERSTATEA));
|
| 928 |
+
ret.ReturnCode = wrap(smartcard, SCardGetStatusChangeA, operation->hContext,
|
| 929 |
+
MIN(dwTimeOut, dwTimeStep), rgReaderStates, call->cReaders);
|
| 930 |
+
if (ret.ReturnCode != SCARD_E_TIMEOUT)
|
| 931 |
+
break;
|
| 932 |
+
if (WaitForSingleObject(smartcard->stopEvent, 0) == WAIT_OBJECT_0)
|
| 933 |
+
break;
|
| 934 |
+
if (dwTimeOut != INFINITE)
|
| 935 |
+
x += dwTimeStep;
|
| 936 |
+
}
|
| 937 |
+
scard_log_status_error(TAG, "SCardGetStatusChangeA", ret.ReturnCode);
|
| 938 |
+
|
| 939 |
+
for (UINT32 index = 0; index < ret.cReaders; index++)
|
| 940 |
+
{
|
| 941 |
+
const SCARD_READERSTATEA* cur = &rgReaderStates[index];
|
| 942 |
+
ReaderState_Return* rout = &ret.rgReaderStates[index];
|
| 943 |
+
|
| 944 |
+
rout->dwCurrentState = cur->dwCurrentState;
|
| 945 |
+
rout->dwEventState = cur->dwEventState;
|
| 946 |
+
rout->cbAtr = cur->cbAtr;
|
| 947 |
+
CopyMemory(&(rout->rgbAtr), cur->rgbAtr, sizeof(rout->rgbAtr));
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
status = smartcard_pack_get_status_change_return(out, &ret, TRUE);
|
| 951 |
+
fail:
|
| 952 |
+
free(ret.rgReaderStates);
|
| 953 |
+
free(rgReaderStates);
|
| 954 |
+
if (status != SCARD_S_SUCCESS)
|
| 955 |
+
return status;
|
| 956 |
+
return ret.ReturnCode;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
static LONG smartcard_GetStatusChangeW_Call(scard_call_context* smartcard, wStream* out,
|
| 960 |
+
SMARTCARD_OPERATION* operation)
|
| 961 |
+
{
|
| 962 |
+
LONG status = STATUS_NO_MEMORY;
|
| 963 |
+
DWORD dwTimeOut = 0;
|
| 964 |
+
const DWORD dwTimeStep = 100;
|
| 965 |
+
GetStatusChange_Return ret = { 0 };
|
| 966 |
+
GetStatusChangeW_Call* call = NULL;
|
| 967 |
+
LPSCARD_READERSTATEW rgReaderStates = NULL;
|
| 968 |
+
|
| 969 |
+
WINPR_ASSERT(smartcard);
|
| 970 |
+
WINPR_ASSERT(out);
|
| 971 |
+
WINPR_ASSERT(operation);
|
| 972 |
+
|
| 973 |
+
call = &operation->call.getStatusChangeW;
|
| 974 |
+
dwTimeOut = call->dwTimeOut;
|
| 975 |
+
|
| 976 |
+
if (call->cReaders > 0)
|
| 977 |
+
{
|
| 978 |
+
ret.cReaders = call->cReaders;
|
| 979 |
+
rgReaderStates = calloc(ret.cReaders, sizeof(SCARD_READERSTATEW));
|
| 980 |
+
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
| 981 |
+
if (!rgReaderStates || !ret.rgReaderStates)
|
| 982 |
+
goto fail;
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
for (UINT32 x = 0; x < MAX(1, dwTimeOut);)
|
| 986 |
+
{
|
| 987 |
+
if (call->cReaders > 0)
|
| 988 |
+
memcpy(rgReaderStates, call->rgReaderStates,
|
| 989 |
+
call->cReaders * sizeof(SCARD_READERSTATEW));
|
| 990 |
+
{
|
| 991 |
+
ret.ReturnCode = wrap(smartcard, SCardGetStatusChangeW, operation->hContext,
|
| 992 |
+
MIN(dwTimeOut, dwTimeStep), rgReaderStates, call->cReaders);
|
| 993 |
+
}
|
| 994 |
+
if (ret.ReturnCode != SCARD_E_TIMEOUT)
|
| 995 |
+
break;
|
| 996 |
+
if (WaitForSingleObject(smartcard->stopEvent, 0) == WAIT_OBJECT_0)
|
| 997 |
+
break;
|
| 998 |
+
if (dwTimeOut != INFINITE)
|
| 999 |
+
x += dwTimeStep;
|
| 1000 |
+
}
|
| 1001 |
+
scard_log_status_error(TAG, "SCardGetStatusChangeW", ret.ReturnCode);
|
| 1002 |
+
|
| 1003 |
+
for (UINT32 index = 0; index < ret.cReaders; index++)
|
| 1004 |
+
{
|
| 1005 |
+
const SCARD_READERSTATEW* cur = &rgReaderStates[index];
|
| 1006 |
+
ReaderState_Return* rout = &ret.rgReaderStates[index];
|
| 1007 |
+
|
| 1008 |
+
rout->dwCurrentState = cur->dwCurrentState;
|
| 1009 |
+
rout->dwEventState = cur->dwEventState;
|
| 1010 |
+
rout->cbAtr = cur->cbAtr;
|
| 1011 |
+
CopyMemory(&(rout->rgbAtr), cur->rgbAtr, sizeof(rout->rgbAtr));
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
status = smartcard_pack_get_status_change_return(out, &ret, TRUE);
|
| 1015 |
+
fail:
|
| 1016 |
+
free(ret.rgReaderStates);
|
| 1017 |
+
free(rgReaderStates);
|
| 1018 |
+
if (status != SCARD_S_SUCCESS)
|
| 1019 |
+
return status;
|
| 1020 |
+
return ret.ReturnCode;
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
static LONG smartcard_Cancel_Call(scard_call_context* smartcard, wStream* out,
|
| 1024 |
+
SMARTCARD_OPERATION* operation)
|
| 1025 |
+
{
|
| 1026 |
+
Long_Return ret = { 0 };
|
| 1027 |
+
|
| 1028 |
+
WINPR_ASSERT(smartcard);
|
| 1029 |
+
WINPR_ASSERT(out);
|
| 1030 |
+
WINPR_ASSERT(operation);
|
| 1031 |
+
|
| 1032 |
+
ret.ReturnCode = wrap(smartcard, SCardCancel, operation->hContext);
|
| 1033 |
+
scard_log_status_error(TAG, "SCardCancel", ret.ReturnCode);
|
| 1034 |
+
smartcard_trace_long_return(&ret, "Cancel");
|
| 1035 |
+
return ret.ReturnCode;
|
| 1036 |
+
}
|
| 1037 |
+
|
| 1038 |
+
static LONG smartcard_ConnectA_Call(scard_call_context* smartcard, wStream* out,
|
| 1039 |
+
SMARTCARD_OPERATION* operation)
|
| 1040 |
+
{
|
| 1041 |
+
LONG status = 0;
|
| 1042 |
+
SCARDHANDLE hCard = 0;
|
| 1043 |
+
Connect_Return ret = { 0 };
|
| 1044 |
+
ConnectA_Call* call = NULL;
|
| 1045 |
+
|
| 1046 |
+
WINPR_ASSERT(smartcard);
|
| 1047 |
+
WINPR_ASSERT(out);
|
| 1048 |
+
WINPR_ASSERT(operation);
|
| 1049 |
+
|
| 1050 |
+
call = &operation->call.connectA;
|
| 1051 |
+
|
| 1052 |
+
if ((call->Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
|
| 1053 |
+
(call->Common.dwShareMode != SCARD_SHARE_DIRECT))
|
| 1054 |
+
{
|
| 1055 |
+
call->Common.dwPreferredProtocols = SCARD_PROTOCOL_Tx;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
ret.ReturnCode = wrap(smartcard, SCardConnectA, operation->hContext, (char*)call->szReader,
|
| 1059 |
+
call->Common.dwShareMode, call->Common.dwPreferredProtocols, &hCard,
|
| 1060 |
+
&ret.dwActiveProtocol);
|
| 1061 |
+
smartcard_scard_context_native_to_redir(&(ret.hContext), operation->hContext);
|
| 1062 |
+
smartcard_scard_handle_native_to_redir(&(ret.hCard), hCard);
|
| 1063 |
+
|
| 1064 |
+
status = smartcard_pack_connect_return(out, &ret);
|
| 1065 |
+
if (status != SCARD_S_SUCCESS)
|
| 1066 |
+
goto out_fail;
|
| 1067 |
+
|
| 1068 |
+
status = ret.ReturnCode;
|
| 1069 |
+
out_fail:
|
| 1070 |
+
|
| 1071 |
+
return status;
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
static LONG smartcard_ConnectW_Call(scard_call_context* smartcard, wStream* out,
|
| 1075 |
+
SMARTCARD_OPERATION* operation)
|
| 1076 |
+
{
|
| 1077 |
+
LONG status = 0;
|
| 1078 |
+
SCARDHANDLE hCard = 0;
|
| 1079 |
+
Connect_Return ret = { 0 };
|
| 1080 |
+
ConnectW_Call* call = NULL;
|
| 1081 |
+
|
| 1082 |
+
WINPR_ASSERT(smartcard);
|
| 1083 |
+
WINPR_ASSERT(out);
|
| 1084 |
+
WINPR_ASSERT(operation);
|
| 1085 |
+
|
| 1086 |
+
call = &operation->call.connectW;
|
| 1087 |
+
|
| 1088 |
+
if ((call->Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
|
| 1089 |
+
(call->Common.dwShareMode != SCARD_SHARE_DIRECT))
|
| 1090 |
+
{
|
| 1091 |
+
call->Common.dwPreferredProtocols = SCARD_PROTOCOL_Tx;
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
ret.ReturnCode = wrap(smartcard, SCardConnectW, operation->hContext, (WCHAR*)call->szReader,
|
| 1095 |
+
call->Common.dwShareMode, call->Common.dwPreferredProtocols, &hCard,
|
| 1096 |
+
&ret.dwActiveProtocol);
|
| 1097 |
+
smartcard_scard_context_native_to_redir(&(ret.hContext), operation->hContext);
|
| 1098 |
+
smartcard_scard_handle_native_to_redir(&(ret.hCard), hCard);
|
| 1099 |
+
|
| 1100 |
+
status = smartcard_pack_connect_return(out, &ret);
|
| 1101 |
+
if (status != SCARD_S_SUCCESS)
|
| 1102 |
+
goto out_fail;
|
| 1103 |
+
|
| 1104 |
+
status = ret.ReturnCode;
|
| 1105 |
+
out_fail:
|
| 1106 |
+
|
| 1107 |
+
return status;
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
static LONG smartcard_Reconnect_Call(scard_call_context* smartcard, wStream* out,
|
| 1111 |
+
SMARTCARD_OPERATION* operation)
|
| 1112 |
+
{
|
| 1113 |
+
LONG status = 0;
|
| 1114 |
+
Reconnect_Return ret = { 0 };
|
| 1115 |
+
Reconnect_Call* call = NULL;
|
| 1116 |
+
|
| 1117 |
+
WINPR_ASSERT(smartcard);
|
| 1118 |
+
WINPR_ASSERT(out);
|
| 1119 |
+
WINPR_ASSERT(operation);
|
| 1120 |
+
|
| 1121 |
+
call = &operation->call.reconnect;
|
| 1122 |
+
ret.ReturnCode =
|
| 1123 |
+
wrap(smartcard, SCardReconnect, operation->hCard, call->dwShareMode,
|
| 1124 |
+
call->dwPreferredProtocols, call->dwInitialization, &ret.dwActiveProtocol);
|
| 1125 |
+
scard_log_status_error(TAG, "SCardReconnect", ret.ReturnCode);
|
| 1126 |
+
status = smartcard_pack_reconnect_return(out, &ret);
|
| 1127 |
+
if (status != SCARD_S_SUCCESS)
|
| 1128 |
+
return status;
|
| 1129 |
+
|
| 1130 |
+
return ret.ReturnCode;
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
static LONG smartcard_Disconnect_Call(scard_call_context* smartcard, wStream* out,
|
| 1134 |
+
SMARTCARD_OPERATION* operation)
|
| 1135 |
+
{
|
| 1136 |
+
Long_Return ret = { 0 };
|
| 1137 |
+
HCardAndDisposition_Call* call = NULL;
|
| 1138 |
+
|
| 1139 |
+
WINPR_ASSERT(smartcard);
|
| 1140 |
+
WINPR_ASSERT(out);
|
| 1141 |
+
WINPR_ASSERT(operation);
|
| 1142 |
+
|
| 1143 |
+
call = &operation->call.hCardAndDisposition;
|
| 1144 |
+
|
| 1145 |
+
ret.ReturnCode = wrap(smartcard, SCardDisconnect, operation->hCard, call->dwDisposition);
|
| 1146 |
+
scard_log_status_error(TAG, "SCardDisconnect", ret.ReturnCode);
|
| 1147 |
+
smartcard_trace_long_return(&ret, "Disconnect");
|
| 1148 |
+
|
| 1149 |
+
return ret.ReturnCode;
|
| 1150 |
+
}
|
| 1151 |
+
|
| 1152 |
+
static LONG smartcard_BeginTransaction_Call(scard_call_context* smartcard, wStream* out,
|
| 1153 |
+
SMARTCARD_OPERATION* operation)
|
| 1154 |
+
{
|
| 1155 |
+
Long_Return ret = { 0 };
|
| 1156 |
+
|
| 1157 |
+
WINPR_ASSERT(smartcard);
|
| 1158 |
+
WINPR_ASSERT(out);
|
| 1159 |
+
WINPR_ASSERT(operation);
|
| 1160 |
+
|
| 1161 |
+
ret.ReturnCode = wrap(smartcard, SCardBeginTransaction, operation->hCard);
|
| 1162 |
+
scard_log_status_error(TAG, "SCardBeginTransaction", ret.ReturnCode);
|
| 1163 |
+
smartcard_trace_long_return(&ret, "BeginTransaction");
|
| 1164 |
+
return ret.ReturnCode;
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
static LONG smartcard_EndTransaction_Call(scard_call_context* smartcard, wStream* out,
|
| 1168 |
+
SMARTCARD_OPERATION* operation)
|
| 1169 |
+
{
|
| 1170 |
+
Long_Return ret = { 0 };
|
| 1171 |
+
HCardAndDisposition_Call* call = NULL;
|
| 1172 |
+
|
| 1173 |
+
WINPR_ASSERT(smartcard);
|
| 1174 |
+
WINPR_ASSERT(out);
|
| 1175 |
+
WINPR_ASSERT(operation);
|
| 1176 |
+
|
| 1177 |
+
call = &operation->call.hCardAndDisposition;
|
| 1178 |
+
|
| 1179 |
+
ret.ReturnCode = wrap(smartcard, SCardEndTransaction, operation->hCard, call->dwDisposition);
|
| 1180 |
+
scard_log_status_error(TAG, "SCardEndTransaction", ret.ReturnCode);
|
| 1181 |
+
smartcard_trace_long_return(&ret, "EndTransaction");
|
| 1182 |
+
return ret.ReturnCode;
|
| 1183 |
+
}
|
| 1184 |
+
|
| 1185 |
+
static LONG smartcard_State_Call(scard_call_context* smartcard, wStream* out,
|
| 1186 |
+
SMARTCARD_OPERATION* operation)
|
| 1187 |
+
{
|
| 1188 |
+
LONG status = 0;
|
| 1189 |
+
State_Return ret = { 0 };
|
| 1190 |
+
|
| 1191 |
+
WINPR_ASSERT(smartcard);
|
| 1192 |
+
WINPR_ASSERT(out);
|
| 1193 |
+
WINPR_ASSERT(operation);
|
| 1194 |
+
|
| 1195 |
+
ret.cbAtrLen = SCARD_ATR_LENGTH;
|
| 1196 |
+
ret.ReturnCode = wrap(smartcard, SCardState, operation->hCard, &ret.dwState, &ret.dwProtocol,
|
| 1197 |
+
(BYTE*)&ret.rgAtr, &ret.cbAtrLen);
|
| 1198 |
+
|
| 1199 |
+
scard_log_status_error(TAG, "SCardState", ret.ReturnCode);
|
| 1200 |
+
status = smartcard_pack_state_return(out, &ret);
|
| 1201 |
+
if (status != SCARD_S_SUCCESS)
|
| 1202 |
+
return status;
|
| 1203 |
+
|
| 1204 |
+
return ret.ReturnCode;
|
| 1205 |
+
}
|
| 1206 |
+
|
| 1207 |
+
static LONG smartcard_StatusA_Call(scard_call_context* smartcard, wStream* out,
|
| 1208 |
+
SMARTCARD_OPERATION* operation)
|
| 1209 |
+
{
|
| 1210 |
+
LONG status = 0;
|
| 1211 |
+
Status_Return ret = { 0 };
|
| 1212 |
+
DWORD cchReaderLen = 0;
|
| 1213 |
+
DWORD cbAtrLen = 0;
|
| 1214 |
+
LPSTR mszReaderNames = NULL;
|
| 1215 |
+
Status_Call* call = NULL;
|
| 1216 |
+
|
| 1217 |
+
WINPR_ASSERT(smartcard);
|
| 1218 |
+
WINPR_ASSERT(out);
|
| 1219 |
+
WINPR_ASSERT(operation);
|
| 1220 |
+
|
| 1221 |
+
call = &operation->call.status;
|
| 1222 |
+
|
| 1223 |
+
call->cbAtrLen = 32;
|
| 1224 |
+
cbAtrLen = call->cbAtrLen;
|
| 1225 |
+
|
| 1226 |
+
if (call->fmszReaderNamesIsNULL)
|
| 1227 |
+
cchReaderLen = 0;
|
| 1228 |
+
else
|
| 1229 |
+
cchReaderLen = SCARD_AUTOALLOCATE;
|
| 1230 |
+
|
| 1231 |
+
status = ret.ReturnCode =
|
| 1232 |
+
wrap(smartcard, SCardStatusA, operation->hCard,
|
| 1233 |
+
call->fmszReaderNamesIsNULL ? NULL : (LPSTR)&mszReaderNames, &cchReaderLen,
|
| 1234 |
+
&ret.dwState, &ret.dwProtocol, cbAtrLen ? (BYTE*)&ret.pbAtr : NULL, &cbAtrLen);
|
| 1235 |
+
|
| 1236 |
+
scard_log_status_error(TAG, "SCardStatusA", status);
|
| 1237 |
+
if (cchReaderLen == SCARD_AUTOALLOCATE)
|
| 1238 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 1239 |
+
|
| 1240 |
+
if (status == SCARD_S_SUCCESS)
|
| 1241 |
+
{
|
| 1242 |
+
if (!call->fmszReaderNamesIsNULL)
|
| 1243 |
+
ret.mszReaderNames = (BYTE*)mszReaderNames;
|
| 1244 |
+
|
| 1245 |
+
ret.cBytes = cchReaderLen;
|
| 1246 |
+
|
| 1247 |
+
if (call->cbAtrLen)
|
| 1248 |
+
ret.cbAtrLen = cbAtrLen;
|
| 1249 |
+
}
|
| 1250 |
+
|
| 1251 |
+
status = smartcard_pack_status_return(out, &ret, FALSE);
|
| 1252 |
+
|
| 1253 |
+
if (mszReaderNames)
|
| 1254 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszReaderNames);
|
| 1255 |
+
|
| 1256 |
+
if (status != SCARD_S_SUCCESS)
|
| 1257 |
+
return status;
|
| 1258 |
+
return ret.ReturnCode;
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
static LONG smartcard_StatusW_Call(scard_call_context* smartcard, wStream* out,
|
| 1262 |
+
SMARTCARD_OPERATION* operation)
|
| 1263 |
+
{
|
| 1264 |
+
LONG status = 0;
|
| 1265 |
+
Status_Return ret = { 0 };
|
| 1266 |
+
LPWSTR mszReaderNames = NULL;
|
| 1267 |
+
Status_Call* call = NULL;
|
| 1268 |
+
DWORD cbAtrLen = 0;
|
| 1269 |
+
|
| 1270 |
+
WINPR_ASSERT(smartcard);
|
| 1271 |
+
WINPR_ASSERT(out);
|
| 1272 |
+
WINPR_ASSERT(operation);
|
| 1273 |
+
|
| 1274 |
+
call = &operation->call.status;
|
| 1275 |
+
|
| 1276 |
+
/**
|
| 1277 |
+
* [MS-RDPESC]
|
| 1278 |
+
* According to 2.2.2.18 Status_Call cbAtrLen is unused an must be ignored upon receipt.
|
| 1279 |
+
*/
|
| 1280 |
+
cbAtrLen = call->cbAtrLen = 32;
|
| 1281 |
+
|
| 1282 |
+
if (call->fmszReaderNamesIsNULL)
|
| 1283 |
+
ret.cBytes = 0;
|
| 1284 |
+
else
|
| 1285 |
+
ret.cBytes = SCARD_AUTOALLOCATE;
|
| 1286 |
+
|
| 1287 |
+
status = ret.ReturnCode =
|
| 1288 |
+
wrap(smartcard, SCardStatusW, operation->hCard,
|
| 1289 |
+
call->fmszReaderNamesIsNULL ? NULL : (LPWSTR)&mszReaderNames, &ret.cBytes,
|
| 1290 |
+
&ret.dwState, &ret.dwProtocol, (BYTE*)&ret.pbAtr, &cbAtrLen);
|
| 1291 |
+
scard_log_status_error(TAG, "SCardStatusW", status);
|
| 1292 |
+
if (ret.cBytes == SCARD_AUTOALLOCATE)
|
| 1293 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 1294 |
+
|
| 1295 |
+
if (status == SCARD_S_SUCCESS)
|
| 1296 |
+
{
|
| 1297 |
+
if (!call->fmszReaderNamesIsNULL)
|
| 1298 |
+
ret.mszReaderNames = (BYTE*)mszReaderNames;
|
| 1299 |
+
|
| 1300 |
+
ret.cbAtrLen = cbAtrLen;
|
| 1301 |
+
}
|
| 1302 |
+
|
| 1303 |
+
/* SCardStatusW returns number of characters, we need number of bytes */
|
| 1304 |
+
WINPR_ASSERT(ret.cBytes < SCARD_AUTOALLOCATE / sizeof(WCHAR));
|
| 1305 |
+
const size_t blen = sizeof(WCHAR) * ret.cBytes;
|
| 1306 |
+
WINPR_ASSERT(blen <= UINT32_MAX);
|
| 1307 |
+
ret.cBytes = (UINT32)blen;
|
| 1308 |
+
|
| 1309 |
+
status = smartcard_pack_status_return(out, &ret, TRUE);
|
| 1310 |
+
if (status != SCARD_S_SUCCESS)
|
| 1311 |
+
return status;
|
| 1312 |
+
|
| 1313 |
+
if (mszReaderNames)
|
| 1314 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, mszReaderNames);
|
| 1315 |
+
|
| 1316 |
+
return ret.ReturnCode;
|
| 1317 |
+
}
|
| 1318 |
+
|
| 1319 |
+
static LONG smartcard_Transmit_Call(scard_call_context* smartcard, wStream* out,
|
| 1320 |
+
SMARTCARD_OPERATION* operation)
|
| 1321 |
+
{
|
| 1322 |
+
LONG status = 0;
|
| 1323 |
+
Transmit_Return ret = { 0 };
|
| 1324 |
+
Transmit_Call* call = NULL;
|
| 1325 |
+
|
| 1326 |
+
WINPR_ASSERT(smartcard);
|
| 1327 |
+
WINPR_ASSERT(out);
|
| 1328 |
+
WINPR_ASSERT(operation);
|
| 1329 |
+
|
| 1330 |
+
call = &operation->call.transmit;
|
| 1331 |
+
ret.cbRecvLength = 0;
|
| 1332 |
+
ret.pbRecvBuffer = NULL;
|
| 1333 |
+
|
| 1334 |
+
if (call->cbRecvLength && !call->fpbRecvBufferIsNULL)
|
| 1335 |
+
{
|
| 1336 |
+
if (call->cbRecvLength >= 66560)
|
| 1337 |
+
call->cbRecvLength = 66560;
|
| 1338 |
+
|
| 1339 |
+
ret.cbRecvLength = call->cbRecvLength;
|
| 1340 |
+
ret.pbRecvBuffer = (BYTE*)malloc(ret.cbRecvLength);
|
| 1341 |
+
|
| 1342 |
+
if (!ret.pbRecvBuffer)
|
| 1343 |
+
return STATUS_NO_MEMORY;
|
| 1344 |
+
}
|
| 1345 |
+
|
| 1346 |
+
ret.pioRecvPci = call->pioRecvPci;
|
| 1347 |
+
ret.ReturnCode =
|
| 1348 |
+
wrap(smartcard, SCardTransmit, operation->hCard, call->pioSendPci, call->pbSendBuffer,
|
| 1349 |
+
call->cbSendLength, ret.pioRecvPci, ret.pbRecvBuffer, &(ret.cbRecvLength));
|
| 1350 |
+
|
| 1351 |
+
scard_log_status_error(TAG, "SCardTransmit", ret.ReturnCode);
|
| 1352 |
+
|
| 1353 |
+
status = smartcard_pack_transmit_return(out, &ret);
|
| 1354 |
+
free(ret.pbRecvBuffer);
|
| 1355 |
+
|
| 1356 |
+
if (status != SCARD_S_SUCCESS)
|
| 1357 |
+
return status;
|
| 1358 |
+
return ret.ReturnCode;
|
| 1359 |
+
}
|
| 1360 |
+
|
| 1361 |
+
static LONG smartcard_Control_Call(scard_call_context* smartcard, wStream* out,
|
| 1362 |
+
SMARTCARD_OPERATION* operation)
|
| 1363 |
+
{
|
| 1364 |
+
LONG status = 0;
|
| 1365 |
+
Control_Return ret = { 0 };
|
| 1366 |
+
Control_Call* call = NULL;
|
| 1367 |
+
|
| 1368 |
+
WINPR_ASSERT(smartcard);
|
| 1369 |
+
WINPR_ASSERT(out);
|
| 1370 |
+
WINPR_ASSERT(operation);
|
| 1371 |
+
|
| 1372 |
+
call = &operation->call.control;
|
| 1373 |
+
ret.cbOutBufferSize = call->cbOutBufferSize;
|
| 1374 |
+
ret.pvOutBuffer = (BYTE*)malloc(call->cbOutBufferSize);
|
| 1375 |
+
|
| 1376 |
+
if (!ret.pvOutBuffer)
|
| 1377 |
+
return SCARD_E_NO_MEMORY;
|
| 1378 |
+
|
| 1379 |
+
ret.ReturnCode =
|
| 1380 |
+
wrap(smartcard, SCardControl, operation->hCard, call->dwControlCode, call->pvInBuffer,
|
| 1381 |
+
call->cbInBufferSize, ret.pvOutBuffer, call->cbOutBufferSize, &ret.cbOutBufferSize);
|
| 1382 |
+
scard_log_status_error(TAG, "SCardControl", ret.ReturnCode);
|
| 1383 |
+
status = smartcard_pack_control_return(out, &ret);
|
| 1384 |
+
|
| 1385 |
+
free(ret.pvOutBuffer);
|
| 1386 |
+
if (status != SCARD_S_SUCCESS)
|
| 1387 |
+
return status;
|
| 1388 |
+
return ret.ReturnCode;
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
static LONG smartcard_GetAttrib_Call(scard_call_context* smartcard, wStream* out,
|
| 1392 |
+
SMARTCARD_OPERATION* operation)
|
| 1393 |
+
{
|
| 1394 |
+
BOOL autoAllocate = FALSE;
|
| 1395 |
+
LONG status = 0;
|
| 1396 |
+
DWORD cbAttrLen = 0;
|
| 1397 |
+
LPBYTE pbAttr = NULL;
|
| 1398 |
+
GetAttrib_Return ret = { 0 };
|
| 1399 |
+
const GetAttrib_Call* call = NULL;
|
| 1400 |
+
|
| 1401 |
+
WINPR_ASSERT(smartcard);
|
| 1402 |
+
WINPR_ASSERT(operation);
|
| 1403 |
+
|
| 1404 |
+
call = &operation->call.getAttrib;
|
| 1405 |
+
|
| 1406 |
+
if (!call->fpbAttrIsNULL)
|
| 1407 |
+
{
|
| 1408 |
+
autoAllocate = (call->cbAttrLen == SCARD_AUTOALLOCATE) ? TRUE : FALSE;
|
| 1409 |
+
cbAttrLen = call->cbAttrLen;
|
| 1410 |
+
if (cbAttrLen && !autoAllocate)
|
| 1411 |
+
{
|
| 1412 |
+
ret.pbAttr = (BYTE*)malloc(cbAttrLen);
|
| 1413 |
+
|
| 1414 |
+
if (!ret.pbAttr)
|
| 1415 |
+
return SCARD_E_NO_MEMORY;
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
pbAttr = autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr;
|
| 1419 |
+
}
|
| 1420 |
+
|
| 1421 |
+
ret.ReturnCode =
|
| 1422 |
+
wrap(smartcard, SCardGetAttrib, operation->hCard, call->dwAttrId, pbAttr, &cbAttrLen);
|
| 1423 |
+
scard_log_status_error(TAG, "SCardGetAttrib", ret.ReturnCode);
|
| 1424 |
+
if (cbAttrLen == SCARD_AUTOALLOCATE)
|
| 1425 |
+
return SCARD_F_UNKNOWN_ERROR;
|
| 1426 |
+
|
| 1427 |
+
ret.cbAttrLen = cbAttrLen;
|
| 1428 |
+
|
| 1429 |
+
status = smartcard_pack_get_attrib_return(out, &ret, call->dwAttrId, call->cbAttrLen);
|
| 1430 |
+
|
| 1431 |
+
if (autoAllocate)
|
| 1432 |
+
wrap(smartcard, SCardFreeMemory, operation->hContext, ret.pbAttr);
|
| 1433 |
+
else
|
| 1434 |
+
free(ret.pbAttr);
|
| 1435 |
+
return status;
|
| 1436 |
+
}
|
| 1437 |
+
|
| 1438 |
+
static LONG smartcard_SetAttrib_Call(scard_call_context* smartcard, wStream* out,
|
| 1439 |
+
SMARTCARD_OPERATION* operation)
|
| 1440 |
+
{
|
| 1441 |
+
Long_Return ret = { 0 };
|
| 1442 |
+
SetAttrib_Call* call = NULL;
|
| 1443 |
+
|
| 1444 |
+
WINPR_ASSERT(smartcard);
|
| 1445 |
+
WINPR_ASSERT(out);
|
| 1446 |
+
WINPR_ASSERT(operation);
|
| 1447 |
+
|
| 1448 |
+
call = &operation->call.setAttrib;
|
| 1449 |
+
|
| 1450 |
+
ret.ReturnCode = wrap(smartcard, SCardSetAttrib, operation->hCard, call->dwAttrId, call->pbAttr,
|
| 1451 |
+
call->cbAttrLen);
|
| 1452 |
+
scard_log_status_error(TAG, "SCardSetAttrib", ret.ReturnCode);
|
| 1453 |
+
smartcard_trace_long_return(&ret, "SetAttrib");
|
| 1454 |
+
|
| 1455 |
+
return ret.ReturnCode;
|
| 1456 |
+
}
|
| 1457 |
+
|
| 1458 |
+
static LONG smartcard_AccessStartedEvent_Call(scard_call_context* smartcard, wStream* out,
|
| 1459 |
+
SMARTCARD_OPERATION* operation)
|
| 1460 |
+
{
|
| 1461 |
+
LONG status = SCARD_S_SUCCESS;
|
| 1462 |
+
|
| 1463 |
+
WINPR_ASSERT(smartcard);
|
| 1464 |
+
WINPR_ASSERT(out);
|
| 1465 |
+
WINPR_UNUSED(operation);
|
| 1466 |
+
|
| 1467 |
+
if (!smartcard->StartedEvent)
|
| 1468 |
+
smartcard->StartedEvent = wrap_ptr(smartcard, SCardAccessStartedEvent);
|
| 1469 |
+
|
| 1470 |
+
if (!smartcard->StartedEvent)
|
| 1471 |
+
status = SCARD_E_NO_SERVICE;
|
| 1472 |
+
|
| 1473 |
+
return status;
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
static LONG smartcard_LocateCardsByATRA_Call(scard_call_context* smartcard, wStream* out,
|
| 1477 |
+
SMARTCARD_OPERATION* operation)
|
| 1478 |
+
{
|
| 1479 |
+
LONG status = 0;
|
| 1480 |
+
GetStatusChange_Return ret = { 0 };
|
| 1481 |
+
LPSCARD_READERSTATEA state = NULL;
|
| 1482 |
+
LPSCARD_READERSTATEA states = NULL;
|
| 1483 |
+
LocateCardsByATRA_Call* call = NULL;
|
| 1484 |
+
|
| 1485 |
+
WINPR_ASSERT(smartcard);
|
| 1486 |
+
WINPR_ASSERT(operation);
|
| 1487 |
+
|
| 1488 |
+
call = &operation->call.locateCardsByATRA;
|
| 1489 |
+
states = (LPSCARD_READERSTATEA)calloc(call->cReaders, sizeof(SCARD_READERSTATEA));
|
| 1490 |
+
|
| 1491 |
+
if (!states)
|
| 1492 |
+
return STATUS_NO_MEMORY;
|
| 1493 |
+
|
| 1494 |
+
for (UINT32 i = 0; i < call->cReaders; i++)
|
| 1495 |
+
{
|
| 1496 |
+
states[i].szReader = call->rgReaderStates[i].szReader;
|
| 1497 |
+
states[i].dwCurrentState = call->rgReaderStates[i].dwCurrentState;
|
| 1498 |
+
states[i].dwEventState = call->rgReaderStates[i].dwEventState;
|
| 1499 |
+
states[i].cbAtr = call->rgReaderStates[i].cbAtr;
|
| 1500 |
+
CopyMemory(&(states[i].rgbAtr), &(call->rgReaderStates[i].rgbAtr), 36);
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
status = ret.ReturnCode = wrap(smartcard, SCardGetStatusChangeA, operation->hContext,
|
| 1504 |
+
0x000001F4, states, call->cReaders);
|
| 1505 |
+
|
| 1506 |
+
scard_log_status_error(TAG, "SCardGetStatusChangeA", status);
|
| 1507 |
+
for (UINT32 i = 0; i < call->cAtrs; i++)
|
| 1508 |
+
{
|
| 1509 |
+
for (UINT32 j = 0; j < call->cReaders; j++)
|
| 1510 |
+
{
|
| 1511 |
+
for (UINT32 k = 0; k < call->rgAtrMasks[i].cbAtr; k++)
|
| 1512 |
+
{
|
| 1513 |
+
if ((call->rgAtrMasks[i].rgbAtr[k] & call->rgAtrMasks[i].rgbMask[k]) !=
|
| 1514 |
+
(states[j].rgbAtr[k] & call->rgAtrMasks[i].rgbMask[k]))
|
| 1515 |
+
{
|
| 1516 |
+
break;
|
| 1517 |
+
}
|
| 1518 |
+
|
| 1519 |
+
states[j].dwEventState |= SCARD_STATE_ATRMATCH;
|
| 1520 |
+
}
|
| 1521 |
+
}
|
| 1522 |
+
}
|
| 1523 |
+
|
| 1524 |
+
ret.cReaders = call->cReaders;
|
| 1525 |
+
ret.rgReaderStates = NULL;
|
| 1526 |
+
|
| 1527 |
+
if (ret.cReaders > 0)
|
| 1528 |
+
ret.rgReaderStates = (ReaderState_Return*)calloc(ret.cReaders, sizeof(ReaderState_Return));
|
| 1529 |
+
|
| 1530 |
+
if (!ret.rgReaderStates)
|
| 1531 |
+
{
|
| 1532 |
+
free(states);
|
| 1533 |
+
return STATUS_NO_MEMORY;
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
for (UINT32 i = 0; i < ret.cReaders; i++)
|
| 1537 |
+
{
|
| 1538 |
+
state = &states[i];
|
| 1539 |
+
ret.rgReaderStates[i].dwCurrentState = state->dwCurrentState;
|
| 1540 |
+
ret.rgReaderStates[i].dwEventState = state->dwEventState;
|
| 1541 |
+
ret.rgReaderStates[i].cbAtr = state->cbAtr;
|
| 1542 |
+
CopyMemory(&(ret.rgReaderStates[i].rgbAtr), &(state->rgbAtr),
|
| 1543 |
+
sizeof(ret.rgReaderStates[i].rgbAtr));
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
free(states);
|
| 1547 |
+
|
| 1548 |
+
status = smartcard_pack_get_status_change_return(out, &ret, FALSE);
|
| 1549 |
+
|
| 1550 |
+
free(ret.rgReaderStates);
|
| 1551 |
+
if (status != SCARD_S_SUCCESS)
|
| 1552 |
+
return status;
|
| 1553 |
+
return ret.ReturnCode;
|
| 1554 |
+
}
|
| 1555 |
+
|
| 1556 |
+
LONG smartcard_irp_device_control_call(scard_call_context* smartcard, wStream* out,
|
| 1557 |
+
NTSTATUS* pIoStatus, SMARTCARD_OPERATION* operation)
|
| 1558 |
+
{
|
| 1559 |
+
LONG result = 0;
|
| 1560 |
+
UINT32 offset = 0;
|
| 1561 |
+
UINT32 ioControlCode = 0;
|
| 1562 |
+
size_t outputBufferLength = 0;
|
| 1563 |
+
size_t objectBufferLength = 0;
|
| 1564 |
+
|
| 1565 |
+
WINPR_ASSERT(smartcard);
|
| 1566 |
+
WINPR_ASSERT(out);
|
| 1567 |
+
WINPR_ASSERT(pIoStatus);
|
| 1568 |
+
WINPR_ASSERT(operation);
|
| 1569 |
+
|
| 1570 |
+
ioControlCode = operation->ioControlCode;
|
| 1571 |
+
/**
|
| 1572 |
+
* [MS-RDPESC] 3.2.5.1: Sending Outgoing Messages:
|
| 1573 |
+
* the output buffer length SHOULD be set to 2048
|
| 1574 |
+
*
|
| 1575 |
+
* Since it's a SHOULD and not a MUST, we don't care
|
| 1576 |
+
* about it, but we still reserve at least 2048 bytes.
|
| 1577 |
+
*/
|
| 1578 |
+
if (!Stream_EnsureRemainingCapacity(out, 2048))
|
| 1579 |
+
return SCARD_E_NO_MEMORY;
|
| 1580 |
+
|
| 1581 |
+
/* Device Control Response */
|
| 1582 |
+
Stream_Write_UINT32(out, 0); /* OutputBufferLength (4 bytes) */
|
| 1583 |
+
Stream_Zero(out, SMARTCARD_COMMON_TYPE_HEADER_LENGTH); /* CommonTypeHeader (8 bytes) */
|
| 1584 |
+
Stream_Zero(out, SMARTCARD_PRIVATE_TYPE_HEADER_LENGTH); /* PrivateTypeHeader (8 bytes) */
|
| 1585 |
+
Stream_Write_UINT32(out, 0); /* Result (4 bytes) */
|
| 1586 |
+
|
| 1587 |
+
/* Call */
|
| 1588 |
+
switch (ioControlCode)
|
| 1589 |
+
{
|
| 1590 |
+
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
| 1591 |
+
result = smartcard_EstablishContext_Call(smartcard, out, operation);
|
| 1592 |
+
break;
|
| 1593 |
+
|
| 1594 |
+
case SCARD_IOCTL_RELEASECONTEXT:
|
| 1595 |
+
result = smartcard_ReleaseContext_Call(smartcard, out, operation);
|
| 1596 |
+
break;
|
| 1597 |
+
|
| 1598 |
+
case SCARD_IOCTL_ISVALIDCONTEXT:
|
| 1599 |
+
result = smartcard_IsValidContext_Call(smartcard, out, operation);
|
| 1600 |
+
break;
|
| 1601 |
+
|
| 1602 |
+
case SCARD_IOCTL_LISTREADERGROUPSA:
|
| 1603 |
+
result = smartcard_ListReaderGroupsA_Call(smartcard, out, operation);
|
| 1604 |
+
break;
|
| 1605 |
+
|
| 1606 |
+
case SCARD_IOCTL_LISTREADERGROUPSW:
|
| 1607 |
+
result = smartcard_ListReaderGroupsW_Call(smartcard, out, operation);
|
| 1608 |
+
break;
|
| 1609 |
+
|
| 1610 |
+
case SCARD_IOCTL_LISTREADERSA:
|
| 1611 |
+
result = smartcard_ListReadersA_Call(smartcard, out, operation);
|
| 1612 |
+
break;
|
| 1613 |
+
|
| 1614 |
+
case SCARD_IOCTL_LISTREADERSW:
|
| 1615 |
+
result = smartcard_ListReadersW_Call(smartcard, out, operation);
|
| 1616 |
+
break;
|
| 1617 |
+
|
| 1618 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
| 1619 |
+
result = smartcard_IntroduceReaderGroupA_Call(smartcard, out, operation);
|
| 1620 |
+
break;
|
| 1621 |
+
|
| 1622 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
| 1623 |
+
result = smartcard_IntroduceReaderGroupW_Call(smartcard, out, operation);
|
| 1624 |
+
break;
|
| 1625 |
+
|
| 1626 |
+
case SCARD_IOCTL_FORGETREADERGROUPA:
|
| 1627 |
+
result = smartcard_ForgetReaderA_Call(smartcard, out, operation);
|
| 1628 |
+
break;
|
| 1629 |
+
|
| 1630 |
+
case SCARD_IOCTL_FORGETREADERGROUPW:
|
| 1631 |
+
result = smartcard_ForgetReaderW_Call(smartcard, out, operation);
|
| 1632 |
+
break;
|
| 1633 |
+
|
| 1634 |
+
case SCARD_IOCTL_INTRODUCEREADERA:
|
| 1635 |
+
result = smartcard_IntroduceReaderA_Call(smartcard, out, operation);
|
| 1636 |
+
break;
|
| 1637 |
+
|
| 1638 |
+
case SCARD_IOCTL_INTRODUCEREADERW:
|
| 1639 |
+
result = smartcard_IntroduceReaderW_Call(smartcard, out, operation);
|
| 1640 |
+
break;
|
| 1641 |
+
|
| 1642 |
+
case SCARD_IOCTL_FORGETREADERA:
|
| 1643 |
+
result = smartcard_ForgetReaderA_Call(smartcard, out, operation);
|
| 1644 |
+
break;
|
| 1645 |
+
|
| 1646 |
+
case SCARD_IOCTL_FORGETREADERW:
|
| 1647 |
+
result = smartcard_ForgetReaderW_Call(smartcard, out, operation);
|
| 1648 |
+
break;
|
| 1649 |
+
|
| 1650 |
+
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
| 1651 |
+
result = smartcard_AddReaderToGroupA_Call(smartcard, out, operation);
|
| 1652 |
+
break;
|
| 1653 |
+
|
| 1654 |
+
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
| 1655 |
+
result = smartcard_AddReaderToGroupW_Call(smartcard, out, operation);
|
| 1656 |
+
break;
|
| 1657 |
+
|
| 1658 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
| 1659 |
+
result = smartcard_RemoveReaderFromGroupA_Call(smartcard, out, operation);
|
| 1660 |
+
break;
|
| 1661 |
+
|
| 1662 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
| 1663 |
+
result = smartcard_RemoveReaderFromGroupW_Call(smartcard, out, operation);
|
| 1664 |
+
break;
|
| 1665 |
+
|
| 1666 |
+
case SCARD_IOCTL_LOCATECARDSA:
|
| 1667 |
+
result = smartcard_LocateCardsA_Call(smartcard, out, operation);
|
| 1668 |
+
break;
|
| 1669 |
+
|
| 1670 |
+
case SCARD_IOCTL_LOCATECARDSW:
|
| 1671 |
+
result = smartcard_LocateCardsW_Call(smartcard, out, operation);
|
| 1672 |
+
break;
|
| 1673 |
+
|
| 1674 |
+
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
| 1675 |
+
result = smartcard_GetStatusChangeA_Call(smartcard, out, operation);
|
| 1676 |
+
break;
|
| 1677 |
+
|
| 1678 |
+
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
| 1679 |
+
result = smartcard_GetStatusChangeW_Call(smartcard, out, operation);
|
| 1680 |
+
break;
|
| 1681 |
+
|
| 1682 |
+
case SCARD_IOCTL_CANCEL:
|
| 1683 |
+
result = smartcard_Cancel_Call(smartcard, out, operation);
|
| 1684 |
+
break;
|
| 1685 |
+
|
| 1686 |
+
case SCARD_IOCTL_CONNECTA:
|
| 1687 |
+
result = smartcard_ConnectA_Call(smartcard, out, operation);
|
| 1688 |
+
break;
|
| 1689 |
+
|
| 1690 |
+
case SCARD_IOCTL_CONNECTW:
|
| 1691 |
+
result = smartcard_ConnectW_Call(smartcard, out, operation);
|
| 1692 |
+
break;
|
| 1693 |
+
|
| 1694 |
+
case SCARD_IOCTL_RECONNECT:
|
| 1695 |
+
result = smartcard_Reconnect_Call(smartcard, out, operation);
|
| 1696 |
+
break;
|
| 1697 |
+
|
| 1698 |
+
case SCARD_IOCTL_DISCONNECT:
|
| 1699 |
+
result = smartcard_Disconnect_Call(smartcard, out, operation);
|
| 1700 |
+
break;
|
| 1701 |
+
|
| 1702 |
+
case SCARD_IOCTL_BEGINTRANSACTION:
|
| 1703 |
+
result = smartcard_BeginTransaction_Call(smartcard, out, operation);
|
| 1704 |
+
break;
|
| 1705 |
+
|
| 1706 |
+
case SCARD_IOCTL_ENDTRANSACTION:
|
| 1707 |
+
result = smartcard_EndTransaction_Call(smartcard, out, operation);
|
| 1708 |
+
break;
|
| 1709 |
+
|
| 1710 |
+
case SCARD_IOCTL_STATE:
|
| 1711 |
+
result = smartcard_State_Call(smartcard, out, operation);
|
| 1712 |
+
break;
|
| 1713 |
+
|
| 1714 |
+
case SCARD_IOCTL_STATUSA:
|
| 1715 |
+
result = smartcard_StatusA_Call(smartcard, out, operation);
|
| 1716 |
+
break;
|
| 1717 |
+
|
| 1718 |
+
case SCARD_IOCTL_STATUSW:
|
| 1719 |
+
result = smartcard_StatusW_Call(smartcard, out, operation);
|
| 1720 |
+
break;
|
| 1721 |
+
|
| 1722 |
+
case SCARD_IOCTL_TRANSMIT:
|
| 1723 |
+
result = smartcard_Transmit_Call(smartcard, out, operation);
|
| 1724 |
+
break;
|
| 1725 |
+
|
| 1726 |
+
case SCARD_IOCTL_CONTROL:
|
| 1727 |
+
result = smartcard_Control_Call(smartcard, out, operation);
|
| 1728 |
+
break;
|
| 1729 |
+
|
| 1730 |
+
case SCARD_IOCTL_GETATTRIB:
|
| 1731 |
+
result = smartcard_GetAttrib_Call(smartcard, out, operation);
|
| 1732 |
+
break;
|
| 1733 |
+
|
| 1734 |
+
case SCARD_IOCTL_SETATTRIB:
|
| 1735 |
+
result = smartcard_SetAttrib_Call(smartcard, out, operation);
|
| 1736 |
+
break;
|
| 1737 |
+
|
| 1738 |
+
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
| 1739 |
+
result = smartcard_AccessStartedEvent_Call(smartcard, out, operation);
|
| 1740 |
+
break;
|
| 1741 |
+
|
| 1742 |
+
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
| 1743 |
+
result = smartcard_LocateCardsByATRA_Call(smartcard, out, operation);
|
| 1744 |
+
break;
|
| 1745 |
+
|
| 1746 |
+
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
| 1747 |
+
result = smartcard_LocateCardsW_Call(smartcard, out, operation);
|
| 1748 |
+
break;
|
| 1749 |
+
|
| 1750 |
+
case SCARD_IOCTL_READCACHEA:
|
| 1751 |
+
result = smartcard_ReadCacheA_Call(smartcard, out, operation);
|
| 1752 |
+
break;
|
| 1753 |
+
|
| 1754 |
+
case SCARD_IOCTL_READCACHEW:
|
| 1755 |
+
result = smartcard_ReadCacheW_Call(smartcard, out, operation);
|
| 1756 |
+
break;
|
| 1757 |
+
|
| 1758 |
+
case SCARD_IOCTL_WRITECACHEA:
|
| 1759 |
+
result = smartcard_WriteCacheA_Call(smartcard, out, operation);
|
| 1760 |
+
break;
|
| 1761 |
+
|
| 1762 |
+
case SCARD_IOCTL_WRITECACHEW:
|
| 1763 |
+
result = smartcard_WriteCacheW_Call(smartcard, out, operation);
|
| 1764 |
+
break;
|
| 1765 |
+
|
| 1766 |
+
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
| 1767 |
+
result = smartcard_GetTransmitCount_Call(smartcard, out, operation);
|
| 1768 |
+
break;
|
| 1769 |
+
|
| 1770 |
+
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
| 1771 |
+
result = smartcard_ReleaseStartedEvent_Call(smartcard, out, operation);
|
| 1772 |
+
break;
|
| 1773 |
+
|
| 1774 |
+
case SCARD_IOCTL_GETREADERICON:
|
| 1775 |
+
result = smartcard_GetReaderIcon_Call(smartcard, out, operation);
|
| 1776 |
+
break;
|
| 1777 |
+
|
| 1778 |
+
case SCARD_IOCTL_GETDEVICETYPEID:
|
| 1779 |
+
result = smartcard_GetDeviceTypeId_Call(smartcard, out, operation);
|
| 1780 |
+
break;
|
| 1781 |
+
|
| 1782 |
+
default:
|
| 1783 |
+
result = STATUS_UNSUCCESSFUL;
|
| 1784 |
+
break;
|
| 1785 |
+
}
|
| 1786 |
+
|
| 1787 |
+
/**
|
| 1788 |
+
* [MS-RPCE] 2.2.6.3 Primitive Type Serialization
|
| 1789 |
+
* The type MUST be aligned on an 8-byte boundary. If the size of the
|
| 1790 |
+
* primitive type is not a multiple of 8 bytes, the data MUST be padded.
|
| 1791 |
+
*/
|
| 1792 |
+
|
| 1793 |
+
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
| 1794 |
+
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
| 1795 |
+
{
|
| 1796 |
+
offset = (RDPDR_DEVICE_IO_RESPONSE_LENGTH + RDPDR_DEVICE_IO_CONTROL_RSP_HDR_LENGTH);
|
| 1797 |
+
smartcard_pack_write_size_align(out, Stream_GetPosition(out) - offset, 8);
|
| 1798 |
+
}
|
| 1799 |
+
|
| 1800 |
+
if ((result != SCARD_S_SUCCESS) && (result != SCARD_E_TIMEOUT) &&
|
| 1801 |
+
(result != SCARD_E_NO_READERS_AVAILABLE) && (result != SCARD_E_NO_SERVICE) &&
|
| 1802 |
+
(result != SCARD_W_CACHE_ITEM_NOT_FOUND) && (result != SCARD_W_CACHE_ITEM_STALE))
|
| 1803 |
+
{
|
| 1804 |
+
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), status: %s (0x%08" PRIX32 ")",
|
| 1805 |
+
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode,
|
| 1806 |
+
SCardGetErrorString(result), result);
|
| 1807 |
+
}
|
| 1808 |
+
|
| 1809 |
+
*pIoStatus = STATUS_SUCCESS;
|
| 1810 |
+
|
| 1811 |
+
if ((result & 0xC0000000L) == 0xC0000000L)
|
| 1812 |
+
{
|
| 1813 |
+
/* NTSTATUS error */
|
| 1814 |
+
*pIoStatus = result;
|
| 1815 |
+
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), ntstatus: 0x%08" PRIX32 "",
|
| 1816 |
+
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, result);
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
Stream_SealLength(out);
|
| 1820 |
+
outputBufferLength = Stream_Length(out);
|
| 1821 |
+
WINPR_ASSERT(outputBufferLength >= RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4U);
|
| 1822 |
+
outputBufferLength -= (RDPDR_DEVICE_IO_RESPONSE_LENGTH + 4U);
|
| 1823 |
+
WINPR_ASSERT(outputBufferLength >= RDPDR_DEVICE_IO_RESPONSE_LENGTH);
|
| 1824 |
+
objectBufferLength = outputBufferLength - RDPDR_DEVICE_IO_RESPONSE_LENGTH;
|
| 1825 |
+
WINPR_ASSERT(outputBufferLength <= UINT32_MAX);
|
| 1826 |
+
WINPR_ASSERT(objectBufferLength <= UINT32_MAX);
|
| 1827 |
+
Stream_SetPosition(out, RDPDR_DEVICE_IO_RESPONSE_LENGTH);
|
| 1828 |
+
/* Device Control Response */
|
| 1829 |
+
Stream_Write_UINT32(out, (UINT32)outputBufferLength); /* OutputBufferLength (4 bytes) */
|
| 1830 |
+
smartcard_pack_common_type_header(out); /* CommonTypeHeader (8 bytes) */
|
| 1831 |
+
smartcard_pack_private_type_header(
|
| 1832 |
+
out, (UINT32)objectBufferLength); /* PrivateTypeHeader (8 bytes) */
|
| 1833 |
+
Stream_Write_INT32(out, result); /* Result (4 bytes) */
|
| 1834 |
+
Stream_SetPosition(out, Stream_Length(out));
|
| 1835 |
+
return SCARD_S_SUCCESS;
|
| 1836 |
+
}
|
| 1837 |
+
|
| 1838 |
+
void context_free(void* arg)
|
| 1839 |
+
{
|
| 1840 |
+
struct s_scard_context_element* element = arg;
|
| 1841 |
+
if (!arg)
|
| 1842 |
+
return;
|
| 1843 |
+
|
| 1844 |
+
if (element->fn_free)
|
| 1845 |
+
element->fn_free(element->context);
|
| 1846 |
+
free(element);
|
| 1847 |
+
}
|
| 1848 |
+
|
| 1849 |
+
scard_call_context* smartcard_call_context_new(const rdpSettings* settings)
|
| 1850 |
+
{
|
| 1851 |
+
wObject* obj = NULL;
|
| 1852 |
+
scard_call_context* ctx = NULL;
|
| 1853 |
+
|
| 1854 |
+
WINPR_ASSERT(settings);
|
| 1855 |
+
ctx = calloc(1, sizeof(scard_call_context));
|
| 1856 |
+
if (!ctx)
|
| 1857 |
+
goto fail;
|
| 1858 |
+
|
| 1859 |
+
ctx->stopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
|
| 1860 |
+
if (!ctx->stopEvent)
|
| 1861 |
+
goto fail;
|
| 1862 |
+
|
| 1863 |
+
ctx->names = LinkedList_New();
|
| 1864 |
+
if (!ctx->names)
|
| 1865 |
+
goto fail;
|
| 1866 |
+
|
| 1867 |
+
#if defined(WITH_SMARTCARD_EMULATE)
|
| 1868 |
+
ctx->useEmulatedCard = freerdp_settings_get_bool(settings, FreeRDP_SmartcardEmulation);
|
| 1869 |
+
#endif
|
| 1870 |
+
|
| 1871 |
+
if (ctx->useEmulatedCard)
|
| 1872 |
+
{
|
| 1873 |
+
#if defined(WITH_SMARTCARD_EMULATE)
|
| 1874 |
+
ctx->emulation = Emulate_New(settings);
|
| 1875 |
+
if (!ctx->emulation)
|
| 1876 |
+
goto fail;
|
| 1877 |
+
#else
|
| 1878 |
+
WLog_ERR(TAG, "Smartcard emulation requested, but not supported!");
|
| 1879 |
+
goto fail;
|
| 1880 |
+
#endif
|
| 1881 |
+
}
|
| 1882 |
+
else
|
| 1883 |
+
{
|
| 1884 |
+
const char* WinSCardModule = freerdp_settings_get_string(settings, FreeRDP_WinSCardModule);
|
| 1885 |
+
if (WinSCardModule)
|
| 1886 |
+
{
|
| 1887 |
+
ctx->hWinSCardLibrary = LoadLibraryX(WinSCardModule);
|
| 1888 |
+
|
| 1889 |
+
if (!ctx->hWinSCardLibrary)
|
| 1890 |
+
{
|
| 1891 |
+
WLog_ERR(TAG, "Failed to load WinSCard library: '%s'", WinSCardModule);
|
| 1892 |
+
goto fail;
|
| 1893 |
+
}
|
| 1894 |
+
|
| 1895 |
+
if (!WinSCard_LoadApiTableFunctions(&ctx->WinSCardApi, ctx->hWinSCardLibrary))
|
| 1896 |
+
goto fail;
|
| 1897 |
+
ctx->pWinSCardApi = &ctx->WinSCardApi;
|
| 1898 |
+
}
|
| 1899 |
+
else
|
| 1900 |
+
{
|
| 1901 |
+
ctx->pWinSCardApi = WinPR_GetSCardApiFunctionTable();
|
| 1902 |
+
}
|
| 1903 |
+
|
| 1904 |
+
if (!ctx->pWinSCardApi)
|
| 1905 |
+
{
|
| 1906 |
+
WLog_ERR(TAG, "Failed to load WinSCard API!");
|
| 1907 |
+
goto fail;
|
| 1908 |
+
}
|
| 1909 |
+
}
|
| 1910 |
+
|
| 1911 |
+
ctx->rgSCardContextList = HashTable_New(FALSE);
|
| 1912 |
+
if (!ctx->rgSCardContextList)
|
| 1913 |
+
goto fail;
|
| 1914 |
+
|
| 1915 |
+
obj = HashTable_ValueObject(ctx->rgSCardContextList);
|
| 1916 |
+
WINPR_ASSERT(obj);
|
| 1917 |
+
obj->fnObjectFree = context_free;
|
| 1918 |
+
|
| 1919 |
+
return ctx;
|
| 1920 |
+
fail:
|
| 1921 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 1922 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 1923 |
+
smartcard_call_context_free(ctx);
|
| 1924 |
+
WINPR_PRAGMA_DIAG_POP
|
| 1925 |
+
return NULL;
|
| 1926 |
+
}
|
| 1927 |
+
|
| 1928 |
+
void smartcard_call_context_free(scard_call_context* ctx)
|
| 1929 |
+
{
|
| 1930 |
+
if (!ctx)
|
| 1931 |
+
return;
|
| 1932 |
+
|
| 1933 |
+
smartcard_call_context_signal_stop(ctx, FALSE);
|
| 1934 |
+
|
| 1935 |
+
LinkedList_Free(ctx->names);
|
| 1936 |
+
if (ctx->StartedEvent)
|
| 1937 |
+
{
|
| 1938 |
+
WINPR_ASSERT(ctx->useEmulatedCard || ctx->pWinSCardApi);
|
| 1939 |
+
wrap(ctx, SCardReleaseStartedEvent);
|
| 1940 |
+
}
|
| 1941 |
+
|
| 1942 |
+
if (ctx->useEmulatedCard)
|
| 1943 |
+
{
|
| 1944 |
+
#ifdef WITH_SMARTCARD_EMULATE
|
| 1945 |
+
if (ctx->emulation)
|
| 1946 |
+
{
|
| 1947 |
+
Emulate_Free(ctx->emulation);
|
| 1948 |
+
ctx->emulation = NULL;
|
| 1949 |
+
}
|
| 1950 |
+
#endif
|
| 1951 |
+
}
|
| 1952 |
+
|
| 1953 |
+
if (ctx->hWinSCardLibrary)
|
| 1954 |
+
{
|
| 1955 |
+
ZeroMemory(&ctx->WinSCardApi, sizeof(SCardApiFunctionTable));
|
| 1956 |
+
FreeLibrary(ctx->hWinSCardLibrary);
|
| 1957 |
+
ctx->hWinSCardLibrary = NULL;
|
| 1958 |
+
}
|
| 1959 |
+
|
| 1960 |
+
ctx->pWinSCardApi = NULL;
|
| 1961 |
+
|
| 1962 |
+
HashTable_Free(ctx->rgSCardContextList);
|
| 1963 |
+
(void)CloseHandle(ctx->stopEvent);
|
| 1964 |
+
free(ctx);
|
| 1965 |
+
}
|
| 1966 |
+
|
| 1967 |
+
BOOL smartcard_call_context_add(scard_call_context* ctx, const char* name)
|
| 1968 |
+
{
|
| 1969 |
+
WINPR_ASSERT(ctx);
|
| 1970 |
+
WINPR_ASSERT(name);
|
| 1971 |
+
return LinkedList_AddLast(ctx->names, name);
|
| 1972 |
+
}
|
| 1973 |
+
|
| 1974 |
+
BOOL smartcard_call_cancel_context(scard_call_context* ctx, SCARDCONTEXT hContext)
|
| 1975 |
+
{
|
| 1976 |
+
WINPR_ASSERT(ctx);
|
| 1977 |
+
if (wrap(ctx, SCardIsValidContext, hContext) == SCARD_S_SUCCESS)
|
| 1978 |
+
{
|
| 1979 |
+
wrap(ctx, SCardCancel, hContext);
|
| 1980 |
+
}
|
| 1981 |
+
return TRUE;
|
| 1982 |
+
}
|
| 1983 |
+
|
| 1984 |
+
BOOL smartcard_call_release_context(scard_call_context* ctx, SCARDCONTEXT hContext)
|
| 1985 |
+
{
|
| 1986 |
+
WINPR_ASSERT(ctx);
|
| 1987 |
+
wrap(ctx, SCardReleaseContext, hContext);
|
| 1988 |
+
return TRUE;
|
| 1989 |
+
}
|
| 1990 |
+
|
| 1991 |
+
BOOL smartcard_call_cancel_all_context(scard_call_context* ctx)
|
| 1992 |
+
{
|
| 1993 |
+
WINPR_ASSERT(ctx);
|
| 1994 |
+
|
| 1995 |
+
HashTable_Clear(ctx->rgSCardContextList);
|
| 1996 |
+
return TRUE;
|
| 1997 |
+
}
|
| 1998 |
+
|
| 1999 |
+
BOOL smarcard_call_set_callbacks(scard_call_context* ctx, void* userdata,
|
| 2000 |
+
void* (*fn_new)(void*, SCARDCONTEXT), void (*fn_free)(void*))
|
| 2001 |
+
{
|
| 2002 |
+
WINPR_ASSERT(ctx);
|
| 2003 |
+
ctx->userdata = userdata;
|
| 2004 |
+
ctx->fn_new = fn_new;
|
| 2005 |
+
ctx->fn_free = fn_free;
|
| 2006 |
+
return TRUE;
|
| 2007 |
+
}
|
| 2008 |
+
|
| 2009 |
+
void* smartcard_call_get_context(scard_call_context* ctx, SCARDCONTEXT hContext)
|
| 2010 |
+
{
|
| 2011 |
+
struct s_scard_context_element* element = NULL;
|
| 2012 |
+
|
| 2013 |
+
WINPR_ASSERT(ctx);
|
| 2014 |
+
element = HashTable_GetItemValue(ctx->rgSCardContextList, (void*)hContext);
|
| 2015 |
+
if (!element)
|
| 2016 |
+
return NULL;
|
| 2017 |
+
return element->context;
|
| 2018 |
+
}
|
| 2019 |
+
|
| 2020 |
+
BOOL smartcard_call_is_configured(scard_call_context* ctx)
|
| 2021 |
+
{
|
| 2022 |
+
WINPR_ASSERT(ctx);
|
| 2023 |
+
|
| 2024 |
+
#if defined(WITH_SMARTCARD_EMULATE)
|
| 2025 |
+
if (ctx->useEmulatedCard)
|
| 2026 |
+
return Emulate_IsConfigured(ctx->emulation);
|
| 2027 |
+
#endif
|
| 2028 |
+
|
| 2029 |
+
return FALSE;
|
| 2030 |
+
}
|
| 2031 |
+
|
| 2032 |
+
BOOL smartcard_call_context_signal_stop(scard_call_context* ctx, BOOL reset)
|
| 2033 |
+
{
|
| 2034 |
+
WINPR_ASSERT(ctx);
|
| 2035 |
+
if (!ctx->stopEvent)
|
| 2036 |
+
return TRUE;
|
| 2037 |
+
|
| 2038 |
+
if (reset)
|
| 2039 |
+
return ResetEvent(ctx->stopEvent);
|
| 2040 |
+
else
|
| 2041 |
+
return SetEvent(ctx->stopEvent);
|
| 2042 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_operations.c
ADDED
|
@@ -0,0 +1,1048 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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alexi Volkov <[email protected]> 2006
|
| 6 |
+
* Copyright 2011 O.S. Systems Software Ltda.
|
| 7 |
+
* Copyright 2011 Anthony Tong <[email protected]>
|
| 8 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 9 |
+
* Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
|
| 10 |
+
* Copyright 2017 Armin Novak <[email protected]>
|
| 11 |
+
* Copyright 2017 Thincast Technologies GmbH
|
| 12 |
+
*
|
| 13 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 14 |
+
* you may not use this file except in compliance with the License.
|
| 15 |
+
* You may obtain a copy of the License at
|
| 16 |
+
*
|
| 17 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 18 |
+
*
|
| 19 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 20 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 21 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 22 |
+
* See the License for the specific language governing permissions and
|
| 23 |
+
* limitations under the License.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include <freerdp/config.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/assert.h>
|
| 29 |
+
|
| 30 |
+
#include <winpr/crt.h>
|
| 31 |
+
#include <winpr/print.h>
|
| 32 |
+
#include <winpr/stream.h>
|
| 33 |
+
#include <winpr/smartcard.h>
|
| 34 |
+
|
| 35 |
+
#include <freerdp/freerdp.h>
|
| 36 |
+
#include <freerdp/channels/rdpdr.h>
|
| 37 |
+
#include <freerdp/channels/scard.h>
|
| 38 |
+
|
| 39 |
+
#include <freerdp/utils/rdpdr_utils.h>
|
| 40 |
+
|
| 41 |
+
#include <freerdp/utils/smartcard_operations.h>
|
| 42 |
+
#include <freerdp/utils/smartcard_pack.h>
|
| 43 |
+
|
| 44 |
+
#include <freerdp/log.h>
|
| 45 |
+
#define TAG FREERDP_TAG("utils.smartcard.ops")
|
| 46 |
+
|
| 47 |
+
static LONG smartcard_call_to_operation_handle(SMARTCARD_OPERATION* operation)
|
| 48 |
+
{
|
| 49 |
+
WINPR_ASSERT(operation);
|
| 50 |
+
|
| 51 |
+
operation->hContext =
|
| 52 |
+
smartcard_scard_context_native_from_redir(&(operation->call.handles.hContext));
|
| 53 |
+
operation->hCard = smartcard_scard_handle_native_from_redir(&(operation->call.handles.hCard));
|
| 54 |
+
|
| 55 |
+
return SCARD_S_SUCCESS;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
static LONG smartcard_EstablishContext_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 59 |
+
{
|
| 60 |
+
LONG status = 0;
|
| 61 |
+
|
| 62 |
+
WINPR_ASSERT(s);
|
| 63 |
+
WINPR_ASSERT(operation);
|
| 64 |
+
|
| 65 |
+
status = smartcard_unpack_establish_context_call(s, &operation->call.establishContext);
|
| 66 |
+
if (status != SCARD_S_SUCCESS)
|
| 67 |
+
{
|
| 68 |
+
return scard_log_status_error(TAG, "smartcard_unpack_establish_context_call", status);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return SCARD_S_SUCCESS;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
static LONG smartcard_ReleaseContext_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 75 |
+
{
|
| 76 |
+
LONG status = 0;
|
| 77 |
+
|
| 78 |
+
WINPR_ASSERT(s);
|
| 79 |
+
WINPR_ASSERT(operation);
|
| 80 |
+
|
| 81 |
+
status = smartcard_unpack_context_call(s, &operation->call.context, "ReleaseContext");
|
| 82 |
+
if (status != SCARD_S_SUCCESS)
|
| 83 |
+
scard_log_status_error(TAG, "smartcard_unpack_context_call", status);
|
| 84 |
+
|
| 85 |
+
return status;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
static LONG smartcard_IsValidContext_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 89 |
+
{
|
| 90 |
+
LONG status = 0;
|
| 91 |
+
|
| 92 |
+
WINPR_ASSERT(s);
|
| 93 |
+
WINPR_ASSERT(operation);
|
| 94 |
+
|
| 95 |
+
status = smartcard_unpack_context_call(s, &operation->call.context, "IsValidContext");
|
| 96 |
+
|
| 97 |
+
return status;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
static LONG smartcard_ListReaderGroupsA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 101 |
+
{
|
| 102 |
+
LONG status = 0;
|
| 103 |
+
|
| 104 |
+
WINPR_ASSERT(s);
|
| 105 |
+
WINPR_ASSERT(operation);
|
| 106 |
+
|
| 107 |
+
status = smartcard_unpack_list_reader_groups_call(s, &operation->call.listReaderGroups, FALSE);
|
| 108 |
+
|
| 109 |
+
return status;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
static LONG smartcard_ListReaderGroupsW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 113 |
+
{
|
| 114 |
+
LONG status = 0;
|
| 115 |
+
|
| 116 |
+
WINPR_ASSERT(s);
|
| 117 |
+
WINPR_ASSERT(operation);
|
| 118 |
+
|
| 119 |
+
status = smartcard_unpack_list_reader_groups_call(s, &operation->call.listReaderGroups, TRUE);
|
| 120 |
+
|
| 121 |
+
return status;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
static LONG smartcard_ListReadersA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 125 |
+
{
|
| 126 |
+
LONG status = 0;
|
| 127 |
+
|
| 128 |
+
WINPR_ASSERT(s);
|
| 129 |
+
WINPR_ASSERT(operation);
|
| 130 |
+
|
| 131 |
+
status = smartcard_unpack_list_readers_call(s, &operation->call.listReaders, FALSE);
|
| 132 |
+
|
| 133 |
+
return status;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
static LONG smartcard_ListReadersW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 137 |
+
{
|
| 138 |
+
LONG status = 0;
|
| 139 |
+
|
| 140 |
+
WINPR_ASSERT(s);
|
| 141 |
+
WINPR_ASSERT(operation);
|
| 142 |
+
|
| 143 |
+
status = smartcard_unpack_list_readers_call(s, &operation->call.listReaders, TRUE);
|
| 144 |
+
|
| 145 |
+
return status;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
static LONG smartcard_context_and_two_strings_a_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 149 |
+
{
|
| 150 |
+
LONG status = 0;
|
| 151 |
+
|
| 152 |
+
WINPR_ASSERT(s);
|
| 153 |
+
WINPR_ASSERT(operation);
|
| 154 |
+
|
| 155 |
+
status =
|
| 156 |
+
smartcard_unpack_context_and_two_strings_a_call(s, &operation->call.contextAndTwoStringA);
|
| 157 |
+
|
| 158 |
+
return status;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
static LONG smartcard_context_and_two_strings_w_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 162 |
+
{
|
| 163 |
+
LONG status = 0;
|
| 164 |
+
|
| 165 |
+
WINPR_ASSERT(s);
|
| 166 |
+
WINPR_ASSERT(operation);
|
| 167 |
+
|
| 168 |
+
status =
|
| 169 |
+
smartcard_unpack_context_and_two_strings_w_call(s, &operation->call.contextAndTwoStringW);
|
| 170 |
+
|
| 171 |
+
return status;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
static LONG smartcard_context_and_string_a_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 175 |
+
{
|
| 176 |
+
LONG status = 0;
|
| 177 |
+
|
| 178 |
+
WINPR_ASSERT(s);
|
| 179 |
+
WINPR_ASSERT(operation);
|
| 180 |
+
|
| 181 |
+
status = smartcard_unpack_context_and_string_a_call(s, &operation->call.contextAndStringA);
|
| 182 |
+
|
| 183 |
+
return status;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
static LONG smartcard_context_and_string_w_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 187 |
+
{
|
| 188 |
+
LONG status = 0;
|
| 189 |
+
|
| 190 |
+
WINPR_ASSERT(s);
|
| 191 |
+
WINPR_ASSERT(operation);
|
| 192 |
+
|
| 193 |
+
status = smartcard_unpack_context_and_string_w_call(s, &operation->call.contextAndStringW);
|
| 194 |
+
|
| 195 |
+
return status;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
static LONG smartcard_LocateCardsA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 199 |
+
{
|
| 200 |
+
LONG status = 0;
|
| 201 |
+
|
| 202 |
+
WINPR_ASSERT(s);
|
| 203 |
+
WINPR_ASSERT(operation);
|
| 204 |
+
|
| 205 |
+
status = smartcard_unpack_locate_cards_a_call(s, &operation->call.locateCardsA);
|
| 206 |
+
|
| 207 |
+
return status;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
static LONG smartcard_LocateCardsW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 211 |
+
{
|
| 212 |
+
LONG status = 0;
|
| 213 |
+
|
| 214 |
+
WINPR_ASSERT(s);
|
| 215 |
+
WINPR_ASSERT(operation);
|
| 216 |
+
|
| 217 |
+
status = smartcard_unpack_locate_cards_w_call(s, &operation->call.locateCardsW);
|
| 218 |
+
|
| 219 |
+
return status;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
static LONG smartcard_GetStatusChangeA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 223 |
+
{
|
| 224 |
+
LONG status = 0;
|
| 225 |
+
|
| 226 |
+
WINPR_ASSERT(s);
|
| 227 |
+
WINPR_ASSERT(operation);
|
| 228 |
+
|
| 229 |
+
status = smartcard_unpack_get_status_change_a_call(s, &operation->call.getStatusChangeA);
|
| 230 |
+
|
| 231 |
+
return status;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
static LONG smartcard_GetStatusChangeW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 235 |
+
{
|
| 236 |
+
LONG status = 0;
|
| 237 |
+
|
| 238 |
+
WINPR_ASSERT(s);
|
| 239 |
+
WINPR_ASSERT(operation);
|
| 240 |
+
|
| 241 |
+
status = smartcard_unpack_get_status_change_w_call(s, &operation->call.getStatusChangeW);
|
| 242 |
+
|
| 243 |
+
return status;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
static LONG smartcard_Cancel_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 247 |
+
{
|
| 248 |
+
LONG status = 0;
|
| 249 |
+
|
| 250 |
+
WINPR_ASSERT(s);
|
| 251 |
+
WINPR_ASSERT(operation);
|
| 252 |
+
|
| 253 |
+
status = smartcard_unpack_context_call(s, &operation->call.context, "Cancel");
|
| 254 |
+
|
| 255 |
+
return status;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
static LONG smartcard_ConnectA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 259 |
+
{
|
| 260 |
+
LONG status = 0;
|
| 261 |
+
|
| 262 |
+
WINPR_ASSERT(s);
|
| 263 |
+
WINPR_ASSERT(operation);
|
| 264 |
+
|
| 265 |
+
status = smartcard_unpack_connect_a_call(s, &operation->call.connectA);
|
| 266 |
+
|
| 267 |
+
return status;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
static LONG smartcard_ConnectW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 271 |
+
{
|
| 272 |
+
LONG status = 0;
|
| 273 |
+
|
| 274 |
+
WINPR_ASSERT(s);
|
| 275 |
+
WINPR_ASSERT(operation);
|
| 276 |
+
|
| 277 |
+
status = smartcard_unpack_connect_w_call(s, &operation->call.connectW);
|
| 278 |
+
|
| 279 |
+
return status;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
static LONG smartcard_Reconnect_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 283 |
+
{
|
| 284 |
+
LONG status = 0;
|
| 285 |
+
|
| 286 |
+
WINPR_ASSERT(s);
|
| 287 |
+
WINPR_ASSERT(operation);
|
| 288 |
+
|
| 289 |
+
status = smartcard_unpack_reconnect_call(s, &operation->call.reconnect);
|
| 290 |
+
|
| 291 |
+
return status;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
static LONG smartcard_Disconnect_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 295 |
+
{
|
| 296 |
+
LONG status = 0;
|
| 297 |
+
|
| 298 |
+
WINPR_ASSERT(s);
|
| 299 |
+
WINPR_ASSERT(operation);
|
| 300 |
+
|
| 301 |
+
status = smartcard_unpack_hcard_and_disposition_call(s, &operation->call.hCardAndDisposition,
|
| 302 |
+
"Disconnect");
|
| 303 |
+
|
| 304 |
+
return status;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
static LONG smartcard_BeginTransaction_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 308 |
+
{
|
| 309 |
+
LONG status = 0;
|
| 310 |
+
|
| 311 |
+
WINPR_ASSERT(s);
|
| 312 |
+
WINPR_ASSERT(operation);
|
| 313 |
+
|
| 314 |
+
status = smartcard_unpack_hcard_and_disposition_call(s, &operation->call.hCardAndDisposition,
|
| 315 |
+
"BeginTransaction");
|
| 316 |
+
|
| 317 |
+
return status;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
static LONG smartcard_EndTransaction_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 321 |
+
{
|
| 322 |
+
LONG status = 0;
|
| 323 |
+
|
| 324 |
+
WINPR_ASSERT(s);
|
| 325 |
+
WINPR_ASSERT(operation);
|
| 326 |
+
|
| 327 |
+
status = smartcard_unpack_hcard_and_disposition_call(s, &operation->call.hCardAndDisposition,
|
| 328 |
+
"EndTransaction");
|
| 329 |
+
|
| 330 |
+
return status;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
static LONG smartcard_State_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 334 |
+
{
|
| 335 |
+
LONG status = 0;
|
| 336 |
+
|
| 337 |
+
WINPR_ASSERT(s);
|
| 338 |
+
WINPR_ASSERT(operation);
|
| 339 |
+
|
| 340 |
+
status = smartcard_unpack_state_call(s, &operation->call.state);
|
| 341 |
+
|
| 342 |
+
return status;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
static LONG smartcard_StatusA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 346 |
+
{
|
| 347 |
+
LONG status = 0;
|
| 348 |
+
|
| 349 |
+
WINPR_ASSERT(s);
|
| 350 |
+
WINPR_ASSERT(operation);
|
| 351 |
+
|
| 352 |
+
status = smartcard_unpack_status_call(s, &operation->call.status, FALSE);
|
| 353 |
+
|
| 354 |
+
return status;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
static LONG smartcard_StatusW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 358 |
+
{
|
| 359 |
+
LONG status = 0;
|
| 360 |
+
|
| 361 |
+
WINPR_ASSERT(s);
|
| 362 |
+
WINPR_ASSERT(operation);
|
| 363 |
+
|
| 364 |
+
status = smartcard_unpack_status_call(s, &operation->call.status, TRUE);
|
| 365 |
+
|
| 366 |
+
return status;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
static LONG smartcard_Transmit_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 370 |
+
{
|
| 371 |
+
LONG status = 0;
|
| 372 |
+
|
| 373 |
+
WINPR_ASSERT(s);
|
| 374 |
+
WINPR_ASSERT(operation);
|
| 375 |
+
|
| 376 |
+
status = smartcard_unpack_transmit_call(s, &operation->call.transmit);
|
| 377 |
+
|
| 378 |
+
return status;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
static LONG smartcard_Control_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 382 |
+
{
|
| 383 |
+
LONG status = 0;
|
| 384 |
+
|
| 385 |
+
WINPR_ASSERT(s);
|
| 386 |
+
WINPR_ASSERT(operation);
|
| 387 |
+
|
| 388 |
+
status = smartcard_unpack_control_call(s, &operation->call.control);
|
| 389 |
+
|
| 390 |
+
return status;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
static LONG smartcard_GetAttrib_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 394 |
+
{
|
| 395 |
+
LONG status = 0;
|
| 396 |
+
|
| 397 |
+
WINPR_ASSERT(s);
|
| 398 |
+
WINPR_ASSERT(operation);
|
| 399 |
+
|
| 400 |
+
status = smartcard_unpack_get_attrib_call(s, &operation->call.getAttrib);
|
| 401 |
+
|
| 402 |
+
return status;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
static LONG smartcard_SetAttrib_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 406 |
+
{
|
| 407 |
+
LONG status = 0;
|
| 408 |
+
|
| 409 |
+
WINPR_ASSERT(s);
|
| 410 |
+
WINPR_ASSERT(operation);
|
| 411 |
+
|
| 412 |
+
status = smartcard_unpack_set_attrib_call(s, &operation->call.setAttrib);
|
| 413 |
+
|
| 414 |
+
return status;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
static LONG smartcard_AccessStartedEvent_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 418 |
+
{
|
| 419 |
+
WINPR_ASSERT(s);
|
| 420 |
+
WINPR_ASSERT(operation);
|
| 421 |
+
|
| 422 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 423 |
+
return SCARD_F_INTERNAL_ERROR;
|
| 424 |
+
|
| 425 |
+
Stream_Read_INT32(s, operation->call.lng.LongValue); /* Unused (4 bytes) */
|
| 426 |
+
|
| 427 |
+
return SCARD_S_SUCCESS;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
static LONG smartcard_LocateCardsByATRA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 431 |
+
{
|
| 432 |
+
LONG status = 0;
|
| 433 |
+
|
| 434 |
+
WINPR_ASSERT(s);
|
| 435 |
+
WINPR_ASSERT(operation);
|
| 436 |
+
|
| 437 |
+
status = smartcard_unpack_locate_cards_by_atr_a_call(s, &operation->call.locateCardsByATRA);
|
| 438 |
+
|
| 439 |
+
return status;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
static LONG smartcard_LocateCardsByATRW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 443 |
+
{
|
| 444 |
+
LONG status = 0;
|
| 445 |
+
|
| 446 |
+
WINPR_ASSERT(s);
|
| 447 |
+
WINPR_ASSERT(operation);
|
| 448 |
+
|
| 449 |
+
status = smartcard_unpack_locate_cards_by_atr_w_call(s, &operation->call.locateCardsByATRW);
|
| 450 |
+
|
| 451 |
+
return status;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
static LONG smartcard_ReadCacheA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 455 |
+
{
|
| 456 |
+
LONG status = 0;
|
| 457 |
+
|
| 458 |
+
WINPR_ASSERT(s);
|
| 459 |
+
WINPR_ASSERT(operation);
|
| 460 |
+
|
| 461 |
+
status = smartcard_unpack_read_cache_a_call(s, &operation->call.readCacheA);
|
| 462 |
+
|
| 463 |
+
return status;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
static LONG smartcard_ReadCacheW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 467 |
+
{
|
| 468 |
+
LONG status = 0;
|
| 469 |
+
|
| 470 |
+
WINPR_ASSERT(s);
|
| 471 |
+
WINPR_ASSERT(operation);
|
| 472 |
+
|
| 473 |
+
status = smartcard_unpack_read_cache_w_call(s, &operation->call.readCacheW);
|
| 474 |
+
|
| 475 |
+
return status;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
static LONG smartcard_WriteCacheA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 479 |
+
{
|
| 480 |
+
LONG status = 0;
|
| 481 |
+
|
| 482 |
+
WINPR_ASSERT(s);
|
| 483 |
+
WINPR_ASSERT(operation);
|
| 484 |
+
|
| 485 |
+
status = smartcard_unpack_write_cache_a_call(s, &operation->call.writeCacheA);
|
| 486 |
+
|
| 487 |
+
return status;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
static LONG smartcard_WriteCacheW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 491 |
+
{
|
| 492 |
+
LONG status = 0;
|
| 493 |
+
|
| 494 |
+
WINPR_ASSERT(s);
|
| 495 |
+
WINPR_ASSERT(operation);
|
| 496 |
+
|
| 497 |
+
status = smartcard_unpack_write_cache_w_call(s, &operation->call.writeCacheW);
|
| 498 |
+
|
| 499 |
+
return status;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
static LONG smartcard_GetTransmitCount_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 503 |
+
{
|
| 504 |
+
LONG status = 0;
|
| 505 |
+
|
| 506 |
+
WINPR_ASSERT(s);
|
| 507 |
+
WINPR_ASSERT(operation);
|
| 508 |
+
|
| 509 |
+
status = smartcard_unpack_get_transmit_count_call(s, &operation->call.getTransmitCount);
|
| 510 |
+
|
| 511 |
+
return status;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
static LONG smartcard_ReleaseStartedEvent_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 515 |
+
{
|
| 516 |
+
WINPR_UNUSED(s);
|
| 517 |
+
WINPR_UNUSED(operation);
|
| 518 |
+
WLog_WARN(TAG, "According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
| 519 |
+
"SCARD_IOCTL_RELEASETARTEDEVENT is not supported");
|
| 520 |
+
return SCARD_E_UNSUPPORTED_FEATURE;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
static LONG smartcard_GetReaderIcon_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 524 |
+
{
|
| 525 |
+
LONG status = 0;
|
| 526 |
+
|
| 527 |
+
WINPR_ASSERT(s);
|
| 528 |
+
WINPR_ASSERT(operation);
|
| 529 |
+
|
| 530 |
+
status = smartcard_unpack_get_reader_icon_call(s, &operation->call.getReaderIcon);
|
| 531 |
+
|
| 532 |
+
return status;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
static LONG smartcard_GetDeviceTypeId_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
| 536 |
+
{
|
| 537 |
+
LONG status = 0;
|
| 538 |
+
|
| 539 |
+
WINPR_ASSERT(s);
|
| 540 |
+
WINPR_ASSERT(operation);
|
| 541 |
+
|
| 542 |
+
status = smartcard_unpack_get_device_type_id_call(s, &operation->call.getDeviceTypeId);
|
| 543 |
+
|
| 544 |
+
return status;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
LONG smartcard_irp_device_control_decode(wStream* s, UINT32 CompletionId, UINT32 FileId,
|
| 548 |
+
SMARTCARD_OPERATION* operation)
|
| 549 |
+
{
|
| 550 |
+
LONG status = 0;
|
| 551 |
+
UINT32 offset = 0;
|
| 552 |
+
UINT32 ioControlCode = 0;
|
| 553 |
+
UINT32 outputBufferLength = 0;
|
| 554 |
+
UINT32 inputBufferLength = 0;
|
| 555 |
+
|
| 556 |
+
WINPR_ASSERT(s);
|
| 557 |
+
WINPR_ASSERT(operation);
|
| 558 |
+
|
| 559 |
+
/* Device Control Request */
|
| 560 |
+
|
| 561 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 32))
|
| 562 |
+
return SCARD_F_INTERNAL_ERROR;
|
| 563 |
+
|
| 564 |
+
Stream_Read_UINT32(s, outputBufferLength); /* OutputBufferLength (4 bytes) */
|
| 565 |
+
Stream_Read_UINT32(s, inputBufferLength); /* InputBufferLength (4 bytes) */
|
| 566 |
+
Stream_Read_UINT32(s, ioControlCode); /* IoControlCode (4 bytes) */
|
| 567 |
+
Stream_Seek(s, 20); /* Padding (20 bytes) */
|
| 568 |
+
operation->ioControlCode = ioControlCode;
|
| 569 |
+
operation->ioControlCodeName = scard_get_ioctl_string(ioControlCode, FALSE);
|
| 570 |
+
|
| 571 |
+
if (Stream_Length(s) != (Stream_GetPosition(s) + inputBufferLength))
|
| 572 |
+
{
|
| 573 |
+
WLog_WARN(TAG, "InputBufferLength mismatch: Actual: %" PRIuz " Expected: %" PRIuz "",
|
| 574 |
+
Stream_Length(s), Stream_GetPosition(s) + inputBufferLength);
|
| 575 |
+
return SCARD_F_INTERNAL_ERROR;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
WLog_DBG(TAG, "%s (0x%08" PRIX32 ") FileId: %" PRIu32 " CompletionId: %" PRIu32 "",
|
| 579 |
+
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, FileId, CompletionId);
|
| 580 |
+
|
| 581 |
+
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
| 582 |
+
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
| 583 |
+
{
|
| 584 |
+
status = smartcard_unpack_common_type_header(s);
|
| 585 |
+
if (status != SCARD_S_SUCCESS)
|
| 586 |
+
return status;
|
| 587 |
+
|
| 588 |
+
status = smartcard_unpack_private_type_header(s);
|
| 589 |
+
if (status != SCARD_S_SUCCESS)
|
| 590 |
+
return status;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
/* Decode */
|
| 594 |
+
switch (ioControlCode)
|
| 595 |
+
{
|
| 596 |
+
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
| 597 |
+
status = smartcard_EstablishContext_Decode(s, operation);
|
| 598 |
+
break;
|
| 599 |
+
|
| 600 |
+
case SCARD_IOCTL_RELEASECONTEXT:
|
| 601 |
+
status = smartcard_ReleaseContext_Decode(s, operation);
|
| 602 |
+
break;
|
| 603 |
+
|
| 604 |
+
case SCARD_IOCTL_ISVALIDCONTEXT:
|
| 605 |
+
status = smartcard_IsValidContext_Decode(s, operation);
|
| 606 |
+
break;
|
| 607 |
+
|
| 608 |
+
case SCARD_IOCTL_LISTREADERGROUPSA:
|
| 609 |
+
status = smartcard_ListReaderGroupsA_Decode(s, operation);
|
| 610 |
+
break;
|
| 611 |
+
|
| 612 |
+
case SCARD_IOCTL_LISTREADERGROUPSW:
|
| 613 |
+
status = smartcard_ListReaderGroupsW_Decode(s, operation);
|
| 614 |
+
break;
|
| 615 |
+
|
| 616 |
+
case SCARD_IOCTL_LISTREADERSA:
|
| 617 |
+
status = smartcard_ListReadersA_Decode(s, operation);
|
| 618 |
+
break;
|
| 619 |
+
|
| 620 |
+
case SCARD_IOCTL_LISTREADERSW:
|
| 621 |
+
status = smartcard_ListReadersW_Decode(s, operation);
|
| 622 |
+
break;
|
| 623 |
+
|
| 624 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
| 625 |
+
status = smartcard_context_and_string_a_Decode(s, operation);
|
| 626 |
+
break;
|
| 627 |
+
|
| 628 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
| 629 |
+
status = smartcard_context_and_string_w_Decode(s, operation);
|
| 630 |
+
break;
|
| 631 |
+
|
| 632 |
+
case SCARD_IOCTL_FORGETREADERGROUPA:
|
| 633 |
+
status = smartcard_context_and_string_a_Decode(s, operation);
|
| 634 |
+
break;
|
| 635 |
+
|
| 636 |
+
case SCARD_IOCTL_FORGETREADERGROUPW:
|
| 637 |
+
status = smartcard_context_and_string_w_Decode(s, operation);
|
| 638 |
+
break;
|
| 639 |
+
|
| 640 |
+
case SCARD_IOCTL_INTRODUCEREADERA:
|
| 641 |
+
status = smartcard_context_and_two_strings_a_Decode(s, operation);
|
| 642 |
+
break;
|
| 643 |
+
|
| 644 |
+
case SCARD_IOCTL_INTRODUCEREADERW:
|
| 645 |
+
status = smartcard_context_and_two_strings_w_Decode(s, operation);
|
| 646 |
+
break;
|
| 647 |
+
|
| 648 |
+
case SCARD_IOCTL_FORGETREADERA:
|
| 649 |
+
status = smartcard_context_and_string_a_Decode(s, operation);
|
| 650 |
+
break;
|
| 651 |
+
|
| 652 |
+
case SCARD_IOCTL_FORGETREADERW:
|
| 653 |
+
status = smartcard_context_and_string_w_Decode(s, operation);
|
| 654 |
+
break;
|
| 655 |
+
|
| 656 |
+
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
| 657 |
+
status = smartcard_context_and_two_strings_a_Decode(s, operation);
|
| 658 |
+
break;
|
| 659 |
+
|
| 660 |
+
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
| 661 |
+
status = smartcard_context_and_two_strings_w_Decode(s, operation);
|
| 662 |
+
break;
|
| 663 |
+
|
| 664 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
| 665 |
+
status = smartcard_context_and_two_strings_a_Decode(s, operation);
|
| 666 |
+
break;
|
| 667 |
+
|
| 668 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
| 669 |
+
status = smartcard_context_and_two_strings_w_Decode(s, operation);
|
| 670 |
+
break;
|
| 671 |
+
|
| 672 |
+
case SCARD_IOCTL_LOCATECARDSA:
|
| 673 |
+
status = smartcard_LocateCardsA_Decode(s, operation);
|
| 674 |
+
break;
|
| 675 |
+
|
| 676 |
+
case SCARD_IOCTL_LOCATECARDSW:
|
| 677 |
+
status = smartcard_LocateCardsW_Decode(s, operation);
|
| 678 |
+
break;
|
| 679 |
+
|
| 680 |
+
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
| 681 |
+
status = smartcard_GetStatusChangeA_Decode(s, operation);
|
| 682 |
+
break;
|
| 683 |
+
|
| 684 |
+
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
| 685 |
+
status = smartcard_GetStatusChangeW_Decode(s, operation);
|
| 686 |
+
break;
|
| 687 |
+
|
| 688 |
+
case SCARD_IOCTL_CANCEL:
|
| 689 |
+
status = smartcard_Cancel_Decode(s, operation);
|
| 690 |
+
break;
|
| 691 |
+
|
| 692 |
+
case SCARD_IOCTL_CONNECTA:
|
| 693 |
+
status = smartcard_ConnectA_Decode(s, operation);
|
| 694 |
+
break;
|
| 695 |
+
|
| 696 |
+
case SCARD_IOCTL_CONNECTW:
|
| 697 |
+
status = smartcard_ConnectW_Decode(s, operation);
|
| 698 |
+
break;
|
| 699 |
+
|
| 700 |
+
case SCARD_IOCTL_RECONNECT:
|
| 701 |
+
status = smartcard_Reconnect_Decode(s, operation);
|
| 702 |
+
break;
|
| 703 |
+
|
| 704 |
+
case SCARD_IOCTL_DISCONNECT:
|
| 705 |
+
status = smartcard_Disconnect_Decode(s, operation);
|
| 706 |
+
break;
|
| 707 |
+
|
| 708 |
+
case SCARD_IOCTL_BEGINTRANSACTION:
|
| 709 |
+
status = smartcard_BeginTransaction_Decode(s, operation);
|
| 710 |
+
break;
|
| 711 |
+
|
| 712 |
+
case SCARD_IOCTL_ENDTRANSACTION:
|
| 713 |
+
status = smartcard_EndTransaction_Decode(s, operation);
|
| 714 |
+
break;
|
| 715 |
+
|
| 716 |
+
case SCARD_IOCTL_STATE:
|
| 717 |
+
status = smartcard_State_Decode(s, operation);
|
| 718 |
+
break;
|
| 719 |
+
|
| 720 |
+
case SCARD_IOCTL_STATUSA:
|
| 721 |
+
status = smartcard_StatusA_Decode(s, operation);
|
| 722 |
+
break;
|
| 723 |
+
|
| 724 |
+
case SCARD_IOCTL_STATUSW:
|
| 725 |
+
status = smartcard_StatusW_Decode(s, operation);
|
| 726 |
+
break;
|
| 727 |
+
|
| 728 |
+
case SCARD_IOCTL_TRANSMIT:
|
| 729 |
+
status = smartcard_Transmit_Decode(s, operation);
|
| 730 |
+
break;
|
| 731 |
+
|
| 732 |
+
case SCARD_IOCTL_CONTROL:
|
| 733 |
+
status = smartcard_Control_Decode(s, operation);
|
| 734 |
+
break;
|
| 735 |
+
|
| 736 |
+
case SCARD_IOCTL_GETATTRIB:
|
| 737 |
+
status = smartcard_GetAttrib_Decode(s, operation);
|
| 738 |
+
break;
|
| 739 |
+
|
| 740 |
+
case SCARD_IOCTL_SETATTRIB:
|
| 741 |
+
status = smartcard_SetAttrib_Decode(s, operation);
|
| 742 |
+
break;
|
| 743 |
+
|
| 744 |
+
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
| 745 |
+
status = smartcard_AccessStartedEvent_Decode(s, operation);
|
| 746 |
+
break;
|
| 747 |
+
|
| 748 |
+
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
| 749 |
+
status = smartcard_LocateCardsByATRA_Decode(s, operation);
|
| 750 |
+
break;
|
| 751 |
+
|
| 752 |
+
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
| 753 |
+
status = smartcard_LocateCardsByATRW_Decode(s, operation);
|
| 754 |
+
break;
|
| 755 |
+
|
| 756 |
+
case SCARD_IOCTL_READCACHEA:
|
| 757 |
+
status = smartcard_ReadCacheA_Decode(s, operation);
|
| 758 |
+
break;
|
| 759 |
+
|
| 760 |
+
case SCARD_IOCTL_READCACHEW:
|
| 761 |
+
status = smartcard_ReadCacheW_Decode(s, operation);
|
| 762 |
+
break;
|
| 763 |
+
|
| 764 |
+
case SCARD_IOCTL_WRITECACHEA:
|
| 765 |
+
status = smartcard_WriteCacheA_Decode(s, operation);
|
| 766 |
+
break;
|
| 767 |
+
|
| 768 |
+
case SCARD_IOCTL_WRITECACHEW:
|
| 769 |
+
status = smartcard_WriteCacheW_Decode(s, operation);
|
| 770 |
+
break;
|
| 771 |
+
|
| 772 |
+
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
| 773 |
+
status = smartcard_GetTransmitCount_Decode(s, operation);
|
| 774 |
+
break;
|
| 775 |
+
|
| 776 |
+
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
| 777 |
+
status = smartcard_ReleaseStartedEvent_Decode(s, operation);
|
| 778 |
+
break;
|
| 779 |
+
|
| 780 |
+
case SCARD_IOCTL_GETREADERICON:
|
| 781 |
+
status = smartcard_GetReaderIcon_Decode(s, operation);
|
| 782 |
+
break;
|
| 783 |
+
|
| 784 |
+
case SCARD_IOCTL_GETDEVICETYPEID:
|
| 785 |
+
status = smartcard_GetDeviceTypeId_Decode(s, operation);
|
| 786 |
+
break;
|
| 787 |
+
|
| 788 |
+
default:
|
| 789 |
+
status = SCARD_F_INTERNAL_ERROR;
|
| 790 |
+
break;
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
smartcard_call_to_operation_handle(operation);
|
| 794 |
+
|
| 795 |
+
if ((ioControlCode != SCARD_IOCTL_ACCESSSTARTEDEVENT) &&
|
| 796 |
+
(ioControlCode != SCARD_IOCTL_RELEASETARTEDEVENT))
|
| 797 |
+
{
|
| 798 |
+
offset = (RDPDR_DEVICE_IO_REQUEST_LENGTH + RDPDR_DEVICE_IO_CONTROL_REQ_HDR_LENGTH);
|
| 799 |
+
smartcard_unpack_read_size_align(s, Stream_GetPosition(s) - offset, 8);
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
if (Stream_GetPosition(s) < Stream_Length(s))
|
| 803 |
+
{
|
| 804 |
+
size_t difference = 0;
|
| 805 |
+
difference = Stream_Length(s) - Stream_GetPosition(s);
|
| 806 |
+
WLog_WARN(TAG,
|
| 807 |
+
"IRP was not fully parsed %s (%s [0x%08" PRIX32 "]): Actual: %" PRIuz
|
| 808 |
+
", Expected: %" PRIuz ", Difference: %" PRIuz "",
|
| 809 |
+
scard_get_ioctl_string(ioControlCode, TRUE),
|
| 810 |
+
scard_get_ioctl_string(ioControlCode, FALSE), ioControlCode,
|
| 811 |
+
Stream_GetPosition(s), Stream_Length(s), difference);
|
| 812 |
+
winpr_HexDump(TAG, WLOG_WARN, Stream_ConstPointer(s), difference);
|
| 813 |
+
}
|
| 814 |
+
|
| 815 |
+
if (Stream_GetPosition(s) > Stream_Length(s))
|
| 816 |
+
{
|
| 817 |
+
size_t difference = 0;
|
| 818 |
+
difference = Stream_GetPosition(s) - Stream_Length(s);
|
| 819 |
+
WLog_WARN(TAG,
|
| 820 |
+
"IRP was parsed beyond its end %s (0x%08" PRIX32 "): Actual: %" PRIuz
|
| 821 |
+
", Expected: %" PRIuz ", Difference: %" PRIuz "",
|
| 822 |
+
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, Stream_GetPosition(s),
|
| 823 |
+
Stream_Length(s), difference);
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
return status;
|
| 827 |
+
}
|
| 828 |
+
|
| 829 |
+
static void free_reader_states_a(LPSCARD_READERSTATEA rgReaderStates, UINT32 cReaders)
|
| 830 |
+
{
|
| 831 |
+
for (UINT32 x = 0; x < cReaders; x++)
|
| 832 |
+
{
|
| 833 |
+
SCARD_READERSTATEA* state = &rgReaderStates[x];
|
| 834 |
+
free(state->szReader);
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
free(rgReaderStates);
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
static void free_reader_states_w(LPSCARD_READERSTATEW rgReaderStates, UINT32 cReaders)
|
| 841 |
+
{
|
| 842 |
+
for (UINT32 x = 0; x < cReaders; x++)
|
| 843 |
+
{
|
| 844 |
+
SCARD_READERSTATEW* state = &rgReaderStates[x];
|
| 845 |
+
free(state->szReader);
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
free(rgReaderStates);
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
void smartcard_operation_free(SMARTCARD_OPERATION* op, BOOL allocated)
|
| 852 |
+
{
|
| 853 |
+
if (!op)
|
| 854 |
+
return;
|
| 855 |
+
switch (op->ioControlCode)
|
| 856 |
+
{
|
| 857 |
+
case SCARD_IOCTL_CANCEL:
|
| 858 |
+
case SCARD_IOCTL_ACCESSSTARTEDEVENT:
|
| 859 |
+
case SCARD_IOCTL_RELEASETARTEDEVENT:
|
| 860 |
+
case SCARD_IOCTL_LISTREADERGROUPSA:
|
| 861 |
+
case SCARD_IOCTL_LISTREADERGROUPSW:
|
| 862 |
+
case SCARD_IOCTL_RECONNECT:
|
| 863 |
+
case SCARD_IOCTL_DISCONNECT:
|
| 864 |
+
case SCARD_IOCTL_BEGINTRANSACTION:
|
| 865 |
+
case SCARD_IOCTL_ENDTRANSACTION:
|
| 866 |
+
case SCARD_IOCTL_STATE:
|
| 867 |
+
case SCARD_IOCTL_STATUSA:
|
| 868 |
+
case SCARD_IOCTL_STATUSW:
|
| 869 |
+
case SCARD_IOCTL_ESTABLISHCONTEXT:
|
| 870 |
+
case SCARD_IOCTL_RELEASECONTEXT:
|
| 871 |
+
case SCARD_IOCTL_ISVALIDCONTEXT:
|
| 872 |
+
case SCARD_IOCTL_GETATTRIB:
|
| 873 |
+
case SCARD_IOCTL_GETTRANSMITCOUNT:
|
| 874 |
+
break;
|
| 875 |
+
|
| 876 |
+
case SCARD_IOCTL_LOCATECARDSA:
|
| 877 |
+
{
|
| 878 |
+
LocateCardsA_Call* call = &op->call.locateCardsA;
|
| 879 |
+
free(call->mszCards);
|
| 880 |
+
|
| 881 |
+
free_reader_states_a(call->rgReaderStates, call->cReaders);
|
| 882 |
+
}
|
| 883 |
+
break;
|
| 884 |
+
case SCARD_IOCTL_LOCATECARDSW:
|
| 885 |
+
{
|
| 886 |
+
LocateCardsW_Call* call = &op->call.locateCardsW;
|
| 887 |
+
free(call->mszCards);
|
| 888 |
+
|
| 889 |
+
free_reader_states_w(call->rgReaderStates, call->cReaders);
|
| 890 |
+
}
|
| 891 |
+
break;
|
| 892 |
+
|
| 893 |
+
case SCARD_IOCTL_LOCATECARDSBYATRA:
|
| 894 |
+
{
|
| 895 |
+
LocateCardsByATRA_Call* call = &op->call.locateCardsByATRA;
|
| 896 |
+
|
| 897 |
+
free_reader_states_a(call->rgReaderStates, call->cReaders);
|
| 898 |
+
}
|
| 899 |
+
break;
|
| 900 |
+
case SCARD_IOCTL_LOCATECARDSBYATRW:
|
| 901 |
+
{
|
| 902 |
+
LocateCardsByATRW_Call* call = &op->call.locateCardsByATRW;
|
| 903 |
+
free_reader_states_w(call->rgReaderStates, call->cReaders);
|
| 904 |
+
}
|
| 905 |
+
break;
|
| 906 |
+
case SCARD_IOCTL_FORGETREADERA:
|
| 907 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPA:
|
| 908 |
+
case SCARD_IOCTL_FORGETREADERGROUPA:
|
| 909 |
+
{
|
| 910 |
+
ContextAndStringA_Call* call = &op->call.contextAndStringA;
|
| 911 |
+
free(call->sz);
|
| 912 |
+
}
|
| 913 |
+
break;
|
| 914 |
+
|
| 915 |
+
case SCARD_IOCTL_FORGETREADERW:
|
| 916 |
+
case SCARD_IOCTL_INTRODUCEREADERGROUPW:
|
| 917 |
+
case SCARD_IOCTL_FORGETREADERGROUPW:
|
| 918 |
+
{
|
| 919 |
+
ContextAndStringW_Call* call = &op->call.contextAndStringW;
|
| 920 |
+
free(call->sz);
|
| 921 |
+
}
|
| 922 |
+
break;
|
| 923 |
+
|
| 924 |
+
case SCARD_IOCTL_INTRODUCEREADERA:
|
| 925 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPA:
|
| 926 |
+
case SCARD_IOCTL_ADDREADERTOGROUPA:
|
| 927 |
+
|
| 928 |
+
{
|
| 929 |
+
ContextAndTwoStringA_Call* call = &op->call.contextAndTwoStringA;
|
| 930 |
+
free(call->sz1);
|
| 931 |
+
free(call->sz2);
|
| 932 |
+
}
|
| 933 |
+
break;
|
| 934 |
+
|
| 935 |
+
case SCARD_IOCTL_INTRODUCEREADERW:
|
| 936 |
+
case SCARD_IOCTL_REMOVEREADERFROMGROUPW:
|
| 937 |
+
case SCARD_IOCTL_ADDREADERTOGROUPW:
|
| 938 |
+
|
| 939 |
+
{
|
| 940 |
+
ContextAndTwoStringW_Call* call = &op->call.contextAndTwoStringW;
|
| 941 |
+
free(call->sz1);
|
| 942 |
+
free(call->sz2);
|
| 943 |
+
}
|
| 944 |
+
break;
|
| 945 |
+
|
| 946 |
+
case SCARD_IOCTL_LISTREADERSA:
|
| 947 |
+
case SCARD_IOCTL_LISTREADERSW:
|
| 948 |
+
{
|
| 949 |
+
ListReaders_Call* call = &op->call.listReaders;
|
| 950 |
+
free(call->mszGroups);
|
| 951 |
+
}
|
| 952 |
+
break;
|
| 953 |
+
case SCARD_IOCTL_GETSTATUSCHANGEA:
|
| 954 |
+
{
|
| 955 |
+
GetStatusChangeA_Call* call = &op->call.getStatusChangeA;
|
| 956 |
+
free_reader_states_a(call->rgReaderStates, call->cReaders);
|
| 957 |
+
}
|
| 958 |
+
break;
|
| 959 |
+
|
| 960 |
+
case SCARD_IOCTL_GETSTATUSCHANGEW:
|
| 961 |
+
{
|
| 962 |
+
GetStatusChangeW_Call* call = &op->call.getStatusChangeW;
|
| 963 |
+
free_reader_states_w(call->rgReaderStates, call->cReaders);
|
| 964 |
+
}
|
| 965 |
+
break;
|
| 966 |
+
case SCARD_IOCTL_GETREADERICON:
|
| 967 |
+
{
|
| 968 |
+
GetReaderIcon_Call* call = &op->call.getReaderIcon;
|
| 969 |
+
free(call->szReaderName);
|
| 970 |
+
}
|
| 971 |
+
break;
|
| 972 |
+
case SCARD_IOCTL_GETDEVICETYPEID:
|
| 973 |
+
{
|
| 974 |
+
GetDeviceTypeId_Call* call = &op->call.getDeviceTypeId;
|
| 975 |
+
free(call->szReaderName);
|
| 976 |
+
}
|
| 977 |
+
break;
|
| 978 |
+
case SCARD_IOCTL_CONNECTA:
|
| 979 |
+
{
|
| 980 |
+
ConnectA_Call* call = &op->call.connectA;
|
| 981 |
+
free(call->szReader);
|
| 982 |
+
}
|
| 983 |
+
break;
|
| 984 |
+
case SCARD_IOCTL_CONNECTW:
|
| 985 |
+
{
|
| 986 |
+
ConnectW_Call* call = &op->call.connectW;
|
| 987 |
+
free(call->szReader);
|
| 988 |
+
}
|
| 989 |
+
break;
|
| 990 |
+
case SCARD_IOCTL_SETATTRIB:
|
| 991 |
+
free(op->call.setAttrib.pbAttr);
|
| 992 |
+
break;
|
| 993 |
+
case SCARD_IOCTL_TRANSMIT:
|
| 994 |
+
{
|
| 995 |
+
Transmit_Call* call = &op->call.transmit;
|
| 996 |
+
free(call->pbSendBuffer);
|
| 997 |
+
free(call->pioSendPci);
|
| 998 |
+
free(call->pioRecvPci);
|
| 999 |
+
}
|
| 1000 |
+
break;
|
| 1001 |
+
case SCARD_IOCTL_CONTROL:
|
| 1002 |
+
{
|
| 1003 |
+
Control_Call* call = &op->call.control;
|
| 1004 |
+
free(call->pvInBuffer);
|
| 1005 |
+
}
|
| 1006 |
+
break;
|
| 1007 |
+
case SCARD_IOCTL_READCACHEA:
|
| 1008 |
+
{
|
| 1009 |
+
ReadCacheA_Call* call = &op->call.readCacheA;
|
| 1010 |
+
free(call->szLookupName);
|
| 1011 |
+
free(call->Common.CardIdentifier);
|
| 1012 |
+
}
|
| 1013 |
+
break;
|
| 1014 |
+
case SCARD_IOCTL_READCACHEW:
|
| 1015 |
+
{
|
| 1016 |
+
ReadCacheW_Call* call = &op->call.readCacheW;
|
| 1017 |
+
free(call->szLookupName);
|
| 1018 |
+
free(call->Common.CardIdentifier);
|
| 1019 |
+
}
|
| 1020 |
+
break;
|
| 1021 |
+
case SCARD_IOCTL_WRITECACHEA:
|
| 1022 |
+
{
|
| 1023 |
+
WriteCacheA_Call* call = &op->call.writeCacheA;
|
| 1024 |
+
free(call->szLookupName);
|
| 1025 |
+
free(call->Common.CardIdentifier);
|
| 1026 |
+
free(call->Common.pbData);
|
| 1027 |
+
}
|
| 1028 |
+
break;
|
| 1029 |
+
case SCARD_IOCTL_WRITECACHEW:
|
| 1030 |
+
{
|
| 1031 |
+
WriteCacheW_Call* call = &op->call.writeCacheW;
|
| 1032 |
+
free(call->szLookupName);
|
| 1033 |
+
free(call->Common.CardIdentifier);
|
| 1034 |
+
free(call->Common.pbData);
|
| 1035 |
+
}
|
| 1036 |
+
break;
|
| 1037 |
+
default:
|
| 1038 |
+
break;
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
{
|
| 1042 |
+
SMARTCARD_OPERATION empty = { 0 };
|
| 1043 |
+
*op = empty;
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
if (allocated)
|
| 1047 |
+
free(op);
|
| 1048 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/smartcard_pack.c
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/string.c
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
*
|
| 4 |
+
* String Utils - Helper functions converting something to string
|
| 5 |
+
*
|
| 6 |
+
* Copyright 2022 Armin Novak <[email protected]>
|
| 7 |
+
* Copyright 2022 Thincast Technologies GmbH
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <errno.h>
|
| 23 |
+
|
| 24 |
+
#include <freerdp/utils/string.h>
|
| 25 |
+
#include <freerdp/settings.h>
|
| 26 |
+
|
| 27 |
+
const char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size)
|
| 28 |
+
{
|
| 29 |
+
struct map_t
|
| 30 |
+
{
|
| 31 |
+
UINT32 flag;
|
| 32 |
+
const char* name;
|
| 33 |
+
};
|
| 34 |
+
const struct map_t map[] = {
|
| 35 |
+
{ LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" },
|
| 36 |
+
{ LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" },
|
| 37 |
+
{ LB_USERNAME, "LB_USERNAME" },
|
| 38 |
+
{ LB_DOMAIN, "LB_DOMAIN" },
|
| 39 |
+
{ LB_PASSWORD, "LB_PASSWORD" },
|
| 40 |
+
{ LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" },
|
| 41 |
+
{ LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" },
|
| 42 |
+
{ LB_NOREDIRECT, "LB_NOREDIRECT" },
|
| 43 |
+
{ LB_TARGET_FQDN, "LB_TARGET_FQDN" },
|
| 44 |
+
{ LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" },
|
| 45 |
+
{ LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" },
|
| 46 |
+
{ LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" },
|
| 47 |
+
{ LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" },
|
| 48 |
+
{ LB_PASSWORD_IS_PK_ENCRYPTED, "LB_PASSWORD_IS_PK_ENCRYPTED" },
|
| 49 |
+
{ LB_REDIRECTION_GUID, "LB_REDIRECTION_GUID" },
|
| 50 |
+
{ LB_TARGET_CERTIFICATE, "LB_TARGET_CERTIFICATE" },
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
for (size_t x = 0; x < ARRAYSIZE(map); x++)
|
| 54 |
+
{
|
| 55 |
+
const struct map_t* cur = &map[x];
|
| 56 |
+
if (flags & cur->flag)
|
| 57 |
+
{
|
| 58 |
+
if (!winpr_str_append(cur->name, buffer, size, "|"))
|
| 59 |
+
return NULL;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
return buffer;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size)
|
| 66 |
+
{
|
| 67 |
+
const UINT32 version = (flags & ServerSessionRedirectionVersionMask) >> 2;
|
| 68 |
+
if (flags & REDIRECTION_SUPPORTED)
|
| 69 |
+
winpr_str_append("REDIRECTION_SUPPORTED", buffer, size, "|");
|
| 70 |
+
if (flags & REDIRECTED_SESSIONID_FIELD_VALID)
|
| 71 |
+
winpr_str_append("REDIRECTED_SESSIONID_FIELD_VALID", buffer, size, "|");
|
| 72 |
+
if (flags & REDIRECTED_SMARTCARD)
|
| 73 |
+
winpr_str_append("REDIRECTED_SMARTCARD", buffer, size, "|");
|
| 74 |
+
|
| 75 |
+
const char* str = NULL;
|
| 76 |
+
switch (version)
|
| 77 |
+
{
|
| 78 |
+
case REDIRECTION_VERSION1:
|
| 79 |
+
str = "REDIRECTION_VERSION1";
|
| 80 |
+
break;
|
| 81 |
+
case REDIRECTION_VERSION2:
|
| 82 |
+
str = "REDIRECTION_VERSION2";
|
| 83 |
+
break;
|
| 84 |
+
case REDIRECTION_VERSION3:
|
| 85 |
+
str = "REDIRECTION_VERSION3";
|
| 86 |
+
break;
|
| 87 |
+
case REDIRECTION_VERSION4:
|
| 88 |
+
str = "REDIRECTION_VERSION4";
|
| 89 |
+
break;
|
| 90 |
+
case REDIRECTION_VERSION5:
|
| 91 |
+
str = "REDIRECTION_VERSION5";
|
| 92 |
+
break;
|
| 93 |
+
case REDIRECTION_VERSION6:
|
| 94 |
+
str = "REDIRECTION_VERSION6";
|
| 95 |
+
break;
|
| 96 |
+
default:
|
| 97 |
+
str = "REDIRECTION_VERSION_UNKNOWN";
|
| 98 |
+
break;
|
| 99 |
+
}
|
| 100 |
+
winpr_str_append(str, buffer, size, "|");
|
| 101 |
+
{
|
| 102 |
+
char msg[32] = { 0 };
|
| 103 |
+
(void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
|
| 104 |
+
winpr_str_append(msg, buffer, size, "");
|
| 105 |
+
}
|
| 106 |
+
return buffer;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
BOOL freerdp_extract_key_value(const char* str, UINT32* pkey, UINT32* pvalue)
|
| 110 |
+
{
|
| 111 |
+
if (!str || !pkey || !pvalue)
|
| 112 |
+
return FALSE;
|
| 113 |
+
|
| 114 |
+
char* end1 = NULL;
|
| 115 |
+
errno = 0;
|
| 116 |
+
unsigned long key = strtoul(str, &end1, 0);
|
| 117 |
+
if ((errno != 0) || !end1 || (*end1 != '=') || (key > UINT32_MAX))
|
| 118 |
+
return FALSE;
|
| 119 |
+
|
| 120 |
+
errno = 0;
|
| 121 |
+
unsigned long val = strtoul(&end1[1], NULL, 0);
|
| 122 |
+
if ((errno != 0) || (val > UINT32_MAX))
|
| 123 |
+
return FALSE;
|
| 124 |
+
|
| 125 |
+
*pkey = (UINT32)key;
|
| 126 |
+
*pvalue = (UINT32)val;
|
| 127 |
+
return TRUE;
|
| 128 |
+
}
|