int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int i, length, ck; RDPDR_SMARTCARD* device; SMARTCARD_DEVICE* smartcard; device = (RDPDR_SMARTCARD*) pEntryPoints->device; name = device->Name; path = device->Path; /* TODO: check if server supports sc redirect (version 5.1) */ smartcard = (SMARTCARD_DEVICE*) malloc(sizeof(SMARTCARD_DEVICE)); ZeroMemory(smartcard, sizeof(SMARTCARD_DEVICE)); smartcard->device.type = RDPDR_DTYP_SMARTCARD; smartcard->device.name = "SCARD"; smartcard->device.IRPRequest = smartcard_irp_request; smartcard->device.Free = smartcard_free; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->name = NULL; smartcard->path = NULL; if (path) { smartcard->path = path; smartcard->name = name; } else if (name) { if (1 == sscanf(name, "%d", &ck)) smartcard->path = name; else smartcard->name = name; } smartcard->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); InitializeSListHead(smartcard->pIrpList); smartcard->irpEvent = CreateEvent(NULL, TRUE, FALSE, NULL); smartcard->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); smartcard->CompletionIds = list_new(); smartcard->CompletionIdsMutex = CreateMutex(NULL, FALSE, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard); ResumeThread(smartcard->thread); return 0; }
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path) { int i, length; DRIVE_DEVICE* disk; #ifdef WIN32 /* * We cannot enter paths like c:\ because : is an arg separator * thus, paths are entered as c+\ and the + is substituted here */ if ( path[1] == '+' ) { if ( (path[0]>='a' && path[0]<='z') || (path[0]>='A' && path[0]<='Z') ) { path[1] = ':'; } } #endif if (name[0] && path[0]) { disk = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE)); ZeroMemory(disk, sizeof(DRIVE_DEVICE)); disk->device.type = RDPDR_DTYP_FILESYSTEM; disk->device.name = name; disk->device.IRPRequest = drive_irp_request; disk->device.Free = drive_free; length = strlen(name); disk->device.data = stream_new(length + 1); for (i = 0; i <= length; i++) stream_write_BYTE(disk->device.data, name[i] < 0 ? '_' : name[i]); disk->path = path; disk->files = list_new(); disk->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); InitializeSListHead(disk->pIrpList); disk->irpEvent = CreateEvent(NULL, TRUE, FALSE, NULL); disk->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); disk->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, disk, CREATE_SUSPENDED, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) disk); ResumeThread(disk->thread); } }
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path) { int i, length; DRIVE_DEVICE* drive; #ifdef WIN32 /* * We cannot enter paths like c:\ because : is an arg separator * thus, paths are entered as c+\ and the + is substituted here */ if (path[1] == '+') { if ((path[0]>='a' && path[0]<='z') || (path[0]>='A' && path[0]<='Z')) { path[1] = ':'; } } #endif if (name[0] && path[0]) { drive = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE)); ZeroMemory(drive, sizeof(DRIVE_DEVICE)); drive->device.type = RDPDR_DTYP_FILESYSTEM; drive->device.name = name; drive->device.IRPRequest = drive_irp_request; drive->device.Free = drive_free; length = (int) strlen(name); drive->device.data = Stream_New(NULL, length + 1); for (i = 0; i <= length; i++) Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]); drive->path = path; drive->files = ListDictionary_New(TRUE); ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free; drive->IrpQueue = MessageQueue_New(NULL); drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive); ResumeThread(drive->thread); } }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int i, length; RDPDR_PARALLEL* device; PARALLEL_DEVICE* parallel; device = (RDPDR_PARALLEL*) pEntryPoints->device; name = device->Name; path = device->Path; if (!name || (name[0] == '*')) { /* TODO: implement auto detection of parallel ports */ return 0; } if (name[0] && path[0]) { parallel = (PARALLEL_DEVICE*) calloc(1, sizeof(PARALLEL_DEVICE)); if (!parallel) return -1; parallel->device.type = RDPDR_DTYP_PARALLEL; parallel->device.name = name; parallel->device.IRPRequest = parallel_irp_request; parallel->device.Free = parallel_free; length = strlen(name); parallel->device.data = Stream_New(NULL, length + 1); for (i = 0; i <= length; i++) Stream_Write_UINT8(parallel->device.data, name[i] < 0 ? '_' : name[i]); parallel->path = path; parallel->queue = MessageQueue_New(NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel); parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL); } return 0; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { int i, len; char* name; char* path; RDPDR_SERIAL* device; SERIAL_DEVICE* serial; device = (RDPDR_SERIAL*) pEntryPoints->device; name = device->Name; path = device->Path; if ((name && name[0]) && (path && path[0])) { serial = (SERIAL_DEVICE*) malloc(sizeof(SERIAL_DEVICE)); ZeroMemory(serial, sizeof(SERIAL_DEVICE)); serial->device.type = RDPDR_DTYP_SERIAL; serial->device.name = name; serial->device.IRPRequest = serial_irp_request; serial->device.Free = serial_free; len = strlen(name); serial->device.data = Stream_New(NULL, len + 1); for (i = 0; i <= len; i++) Stream_Write_UINT8(serial->device.data, name[i] < 0 ? '_' : name[i]); serial->path = path; serial->queue = Queue_New(TRUE, -1, -1); serial->pending_irps = list_new(); serial->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); serial->newEvent = CreateEvent(NULL, TRUE, FALSE, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial); serial->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL); serial->mthread = NULL; } return 0; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { SCARD_DEVICE* scard; char* name; char* path; int i, length; name = (char *)pEntryPoints->plugin_data->data[1]; path = (char *)pEntryPoints->plugin_data->data[2]; if (name) { /* TODO: check if server supports sc redirect (version 5.1) */ scard = xnew(SCARD_DEVICE); scard->device.type = RDPDR_DTYP_SMARTCARD; scard->device.name = "SCARD"; scard->device.IRPRequest = scard_irp_request; scard->device.Free = scard_free; length = strlen(scard->device.name); scard->device.data = stream_new(length + 1); for (i = 0; i <= length; i++) stream_write_uint8(scard->device.data, name[i] < 0 ? '_' : name[i]); scard->path = path; scard->irp_list = list_new(); scard->thread = freerdp_thread_new(); scard->CompletionIds = list_new(); scard->CompletionIdsMutex = freerdp_mutex_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE *)scard); freerdp_thread_start(scard->thread, scard_thread_func, scard); } return 0; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int i, length; RDPDR_PARALLEL* device; PARALLEL_DEVICE* parallel; device = (RDPDR_PARALLEL*) pEntryPoints->device; name = device->Name; path = device->Path; if (name[0] && path[0]) { parallel = (PARALLEL_DEVICE*) malloc(sizeof(PARALLEL_DEVICE)); ZeroMemory(parallel, sizeof(PARALLEL_DEVICE)); parallel->device.type = RDPDR_DTYP_PARALLEL; parallel->device.name = name; parallel->device.IRPRequest = parallel_irp_request; parallel->device.Free = parallel_free; length = strlen(name); parallel->device.data = stream_new(length + 1); for (i = 0; i <= length; i++) stream_write_BYTE(parallel->device.data, name[i] < 0 ? '_' : name[i]); parallel->path = path; parallel->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); InitializeSListHead(parallel->pIrpList); parallel->thread = freerdp_thread_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel); freerdp_thread_start(parallel->thread, parallel_thread_func, parallel); } return 0; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { SERIAL_DEVICE* serial; char* name; char* path; int i, len; name = (char*)pEntryPoints->plugin_data->data[1]; path = (char*)pEntryPoints->plugin_data->data[2]; if (name[0] && path[0]) { serial = xnew(SERIAL_DEVICE); serial->device.type = RDPDR_DTYP_SERIAL; serial->device.name = name; serial->device.IRPRequest = serial_irp_request; serial->device.Free = serial_free; len = strlen(name); serial->device.data = stream_new(len + 1); for (i = 0; i <= len; i++) stream_write_uint8(serial->device.data, name[i] < 0 ? '_' : name[i]); serial->path = path; serial->irp_list = list_new(); serial->pending_irps = list_new(); serial->thread = freerdp_thread_new(); serial->in_event = wait_obj_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*)serial); freerdp_thread_start(serial->thread, serial_thread_func, serial); } return 0; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int i, length; PARALLEL_DEVICE* parallel; name = (char*) pEntryPoints->plugin_data->data[1]; path = (char*) pEntryPoints->plugin_data->data[2]; if (name[0] && path[0]) { parallel = xnew(PARALLEL_DEVICE); parallel->device.type = RDPDR_DTYP_PARALLEL; parallel->device.name = name; parallel->device.IRPRequest = parallel_irp_request; parallel->device.Free = parallel_free; length = strlen(name); parallel->device.data = stream_new(length + 1); for (i = 0; i <= length; i++) stream_write_uint8(parallel->device.data, name[i] < 0 ? '_' : name[i]); parallel->path = path; parallel->irp_list = list_new(); parallel->thread = freerdp_thread_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel); freerdp_thread_start(parallel->thread, parallel_thread_func, parallel); } return 0; }
void printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer) { char* port; UINT32 Flags; int DriverNameLen; WCHAR* DriverName = NULL; int PrintNameLen; WCHAR* PrintName = NULL; UINT32 CachedFieldsLen; BYTE* CachedPrinterConfigData; PRINTER_DEVICE* printer_dev; port = malloc(10); snprintf(port, 10, "PRN%d", printer->id); printer_dev = (PRINTER_DEVICE*) malloc(sizeof(PRINTER_DEVICE)); ZeroMemory(printer_dev, sizeof(PRINTER_DEVICE)); printer_dev->device.type = RDPDR_DTYP_PRINT; printer_dev->device.name = port; printer_dev->device.IRPRequest = printer_irp_request; printer_dev->device.Free = printer_free; printer_dev->printer = printer; CachedFieldsLen = 0; CachedPrinterConfigData = NULL; DEBUG_SVC("Printer %s registered", printer->name); Flags = 0; if (printer->is_default) Flags |= RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER; DriverNameLen = ConvertToUnicode(CP_UTF8, 0, printer->driver, -1, &DriverName, 0) * 2; PrintNameLen = ConvertToUnicode(CP_UTF8, 0, printer->name, -1, &PrintName, 0) * 2; printer_dev->device.data = stream_new(28 + DriverNameLen + PrintNameLen + CachedFieldsLen); stream_write_UINT32(printer_dev->device.data, Flags); stream_write_UINT32(printer_dev->device.data, 0); /* CodePage, reserved */ stream_write_UINT32(printer_dev->device.data, 0); /* PnPNameLen */ stream_write_UINT32(printer_dev->device.data, DriverNameLen + 2); stream_write_UINT32(printer_dev->device.data, PrintNameLen + 2); stream_write_UINT32(printer_dev->device.data, CachedFieldsLen); stream_write(printer_dev->device.data, DriverName, DriverNameLen); stream_write_UINT16(printer_dev->device.data, 0); stream_write(printer_dev->device.data, PrintName, PrintNameLen); stream_write_UINT16(printer_dev->device.data, 0); if (CachedFieldsLen > 0) { stream_write(printer_dev->device.data, CachedPrinterConfigData, CachedFieldsLen); } free(DriverName); free(PrintName); printer_dev->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); InitializeSListHead(printer_dev->pIrpList); printer_dev->thread = freerdp_thread_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) printer_dev); freerdp_thread_start(printer_dev->thread, printer_thread_func, printer_dev); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; char* driver; RDPDR_SERIAL* device; #if defined __linux__ && !defined ANDROID int i, len; SERIAL_DEVICE* serial; #endif /* __linux__ */ UINT error = CHANNEL_RC_OK; device = (RDPDR_SERIAL*) pEntryPoints->device; name = device->Name; path = device->Path; driver = device->Driver; if (!name || (name[0] == '*')) { /* TODO: implement auto detection of serial ports */ return CHANNEL_RC_OK; } if ((name && name[0]) && (path && path[0])) { wLog* log; WLog_Init(); log = WLog_Get("com.freerdp.channel.serial.client"); WLog_Print(log, WLOG_DEBUG, "initializing"); #ifndef __linux__ /* to be removed */ WLog_Print(log, WLOG_WARN, "Serial ports redirection not supported on this platform."); return CHANNEL_RC_INITIALIZATION_ERROR; #else /* __linux __ */ WLog_Print(log, WLOG_DEBUG, "Defining %s as %s", name, path); if (!DefineCommDevice(name /* eg: COM1 */, path /* eg: /dev/ttyS0 */)) { WLog_ERR(TAG, "DefineCommDevice failed!"); return ERROR_INTERNAL_ERROR; } serial = (SERIAL_DEVICE*) calloc(1, sizeof(SERIAL_DEVICE)); if (!serial) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } serial->log = log; serial->device.type = RDPDR_DTYP_SERIAL; serial->device.name = name; serial->device.IRPRequest = serial_irp_request; serial->device.Free = serial_free; serial->rdpcontext = pEntryPoints->rdpcontext; len = strlen(name); serial->device.data = Stream_New(NULL, len + 1); if (!serial->device.data) { WLog_ERR(TAG, "calloc failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } for (i = 0; i <= len; i++) Stream_Write_UINT8(serial->device.data, name[i] < 0 ? '_' : name[i]); if (driver != NULL) { if (_stricmp(driver, "Serial") == 0) serial->ServerSerialDriverId = SerialDriverSerialSys; else if (_stricmp(driver, "SerCx") == 0) serial->ServerSerialDriverId = SerialDriverSerCxSys; else if (_stricmp(driver, "SerCx2") == 0) serial->ServerSerialDriverId = SerialDriverSerCx2Sys; else { assert(FALSE); WLog_Print(serial->log, WLOG_DEBUG, "Unknown server's serial driver: %s. SerCx2 will be used", driver); serial->ServerSerialDriverId = SerialDriverSerialSys; } } else { /* default driver */ serial->ServerSerialDriverId = SerialDriverSerialSys; } if (device->Permissive != NULL) { if (_stricmp(device->Permissive, "permissive") == 0) { serial->permissive = TRUE; } else { WLog_Print(serial->log, WLOG_DEBUG, "Unknown flag: %s", device->Permissive); assert(FALSE); } } WLog_Print(serial->log, WLOG_DEBUG, "Server's serial driver: %s (id: %d)", driver, serial->ServerSerialDriverId); /* TODO: implement auto detection of the server's serial driver */ serial->MainIrpQueue = MessageQueue_New(NULL); if (!serial->MainIrpQueue) { WLog_ERR(TAG, "MessageQueue_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } /* IrpThreads content only modified by create_irp_thread() */ serial->IrpThreads = ListDictionary_New(FALSE); if (!serial->IrpThreads) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } serial->IrpThreadToBeTerminatedCount = 0; InitializeCriticalSection(&serial->TerminatingIrpThreadsLock); if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial))) { WLog_ERR(TAG, "EntryPoints->RegisterDevice failed with error %"PRIu32"!", error); goto error_out; } if (!(serial->MainThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); error = ERROR_INTERNAL_ERROR; goto error_out; } #endif /* __linux __ */ } return error; error_out: #ifdef __linux__ /* to be removed */ ListDictionary_Free(serial->IrpThreads); MessageQueue_Free(serial->MainIrpQueue); Stream_Free(serial->device.data, TRUE); free(serial); #endif /* __linux __ */ return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { SMARTCARD_DEVICE* smartcard = NULL; size_t length; UINT error = CHANNEL_RC_NO_MEMORY; if (!sSmartcard) { wObject* obj; smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE)); if (!smartcard) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } smartcard->device.type = RDPDR_DTYP_SMARTCARD; smartcard->device.name = "SCARD"; smartcard->device.IRPRequest = smartcard_irp_request; smartcard->device.Init = smartcard_init; smartcard->device.Free = smartcard_free; smartcard->names = LinkedList_New(); smartcard->rdpcontext = pEntryPoints->rdpcontext; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); if (!smartcard->device.data || !smartcard->names) { WLog_ERR(TAG, "Stream_New failed!"); goto fail; } Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->IrpQueue = MessageQueue_New(NULL); if (!smartcard->IrpQueue) { WLog_ERR(TAG, "MessageQueue_New failed!"); goto fail; } smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1); if (!smartcard->CompletedIrpQueue) { WLog_ERR(TAG, "Queue_New failed!"); goto fail; } smartcard->rgSCardContextList = ListDictionary_New(TRUE); if (!smartcard->rgSCardContextList) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto fail; } obj = ListDictionary_ValueObject(smartcard->rgSCardContextList); obj->fnObjectFree = smartcard_context_free; smartcard->rgOutstandingMessages = ListDictionary_New(TRUE); if (!smartcard->rgOutstandingMessages) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto fail; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &smartcard->device))) { WLog_ERR(TAG, "RegisterDevice failed!"); goto fail; } smartcard->thread = CreateThread(NULL, 0, smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); if (!smartcard->thread) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = ERROR_INTERNAL_ERROR; goto fail; } ResumeThread(smartcard->thread); } else smartcard = sSmartcard; if (pEntryPoints->device->Name) LinkedList_AddLast(smartcard->names, pEntryPoints->device->Name); sSmartcard = smartcard; return CHANNEL_RC_OK; fail: smartcard_free_(smartcard); return error; }
void printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer) { PRINTER_DEVICE* printer_dev; char* port; UNICONV* uniconv; uint32 Flags; size_t DriverNameLen; char* DriverName; size_t PrintNameLen; char* PrintName; uint32 CachedFieldsLen; uint8* CachedPrinterConfigData; port = xmalloc(10); snprintf(port, 10, "PRN%d", printer->id); printer_dev = xnew(PRINTER_DEVICE); printer_dev->device.type = RDPDR_DTYP_PRINT; printer_dev->device.name = port; printer_dev->device.IRPRequest = printer_irp_request; printer_dev->device.Free = printer_free; printer_dev->printer = printer; CachedFieldsLen = 0; CachedPrinterConfigData = NULL; log_debug("Printer '%s' registered", printer->name); Flags = 0; if (printer->is_default) Flags |= RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER; uniconv = freerdp_uniconv_new(); DriverName = freerdp_uniconv_out(uniconv, printer->driver, &DriverNameLen); PrintName = freerdp_uniconv_out(uniconv, printer->name, &PrintNameLen); freerdp_uniconv_free(uniconv); printer_dev->device.data = stream_new(28 + DriverNameLen + PrintNameLen + CachedFieldsLen); stream_write_uint32(printer_dev->device.data, Flags); stream_write_uint32(printer_dev->device.data, 0); /* CodePage, reserved */ stream_write_uint32(printer_dev->device.data, 0); /* PnPNameLen */ stream_write_uint32(printer_dev->device.data, DriverNameLen + 2); stream_write_uint32(printer_dev->device.data, PrintNameLen + 2); stream_write_uint32(printer_dev->device.data, CachedFieldsLen); stream_write(printer_dev->device.data, DriverName, DriverNameLen); stream_write_uint16(printer_dev->device.data, 0); stream_write(printer_dev->device.data, PrintName, PrintNameLen); stream_write_uint16(printer_dev->device.data, 0); if (CachedFieldsLen > 0) { stream_write(printer_dev->device.data, CachedPrinterConfigData, CachedFieldsLen); } xfree(DriverName); xfree(PrintName); printer_dev->irp_list = list_new(); printer_dev->thread = freerdp_thread_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) printer_dev); freerdp_thread_start(printer_dev->thread, printer_thread_func, printer_dev); }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int length, ck; RDPDR_SMARTCARD* device; SMARTCARD_DEVICE* smartcard; device = (RDPDR_SMARTCARD*) pEntryPoints->device; name = device->Name; path = device->Path; smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE)); if (!smartcard) return -1; smartcard->device.type = RDPDR_DTYP_SMARTCARD; smartcard->device.name = "SCARD"; smartcard->device.IRPRequest = smartcard_irp_request; smartcard->device.Init = smartcard_init; smartcard->device.Free = smartcard_free; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); if (!smartcard->device.data) goto error_device_data; Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->name = NULL; smartcard->path = NULL; if (path) { smartcard->path = path; smartcard->name = name; } else if (name) { if (1 == sscanf(name, "%d", &ck)) smartcard->path = name; else smartcard->name = name; } smartcard->IrpQueue = MessageQueue_New(NULL); if (!smartcard->IrpQueue) goto error_irp_queue; smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1); if (!smartcard->CompletedIrpQueue) goto error_completed_irp_queue; smartcard->rgSCardContextList = ListDictionary_New(TRUE); if (!smartcard->rgSCardContextList) goto error_context_list; ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree = (OBJECT_FREE_FN) smartcard_context_free; smartcard->rgOutstandingMessages = ListDictionary_New(TRUE); if (!smartcard->rgOutstandingMessages) goto error_outstanding_messages; smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); if (!smartcard->thread) goto error_thread; pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard); ResumeThread(smartcard->thread); return 0; error_thread: ListDictionary_Free(smartcard->rgOutstandingMessages); error_outstanding_messages: ListDictionary_Free(smartcard->rgSCardContextList); error_context_list: Queue_Free(smartcard->CompletedIrpQueue); error_completed_irp_queue: MessageQueue_Free(smartcard->IrpQueue); error_irp_queue: Stream_Free(smartcard->device.data, TRUE); error_device_data: free(smartcard); return -1; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path) { int i, length; DRIVE_DEVICE* drive; UINT error; #ifdef WIN32 /* * We cannot enter paths like c:\ because : is an arg separator * thus, paths are entered as c+\ and the + is substituted here */ if (path[1] == '+') { if ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z')) { path[1] = ':'; } } #endif if (name[0] && path[0]) { drive = (DRIVE_DEVICE*) calloc(1, sizeof(DRIVE_DEVICE)); if (!drive) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } drive->device.type = RDPDR_DTYP_FILESYSTEM; drive->device.name = name; drive->device.IRPRequest = drive_irp_request; drive->device.Free = drive_free; drive->rdpcontext = pEntryPoints->rdpcontext; length = (int) strlen(name); drive->device.data = Stream_New(NULL, length + 1); if (!drive->device.data) { WLog_ERR(TAG, "Stream_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto out_error; } for (i = 0; i <= length; i++) Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]); drive->path = path; drive->files = ListDictionary_New(TRUE); if (!drive->files) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto out_error; } ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free; drive->IrpQueue = MessageQueue_New(NULL); if (!drive->IrpQueue) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto out_error; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive))) { WLog_ERR(TAG, "RegisterDevice failed with error %u!", error); goto out_error; } if (!(drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); goto out_error; } ResumeThread(drive->thread); } return CHANNEL_RC_OK; out_error: MessageQueue_Free(drive->IrpQueue); ListDictionary_Free(drive->files); free(drive); return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer) { char* port; UINT32 Flags; int DriverNameLen; WCHAR* DriverName = NULL; int PrintNameLen; WCHAR* PrintName = NULL; UINT32 CachedFieldsLen; BYTE* CachedPrinterConfigData; PRINTER_DEVICE* printer_dev; UINT error; port = malloc(10); if (!port) { WLog_ERR(TAG, "malloc failed!"); return CHANNEL_RC_NO_MEMORY; } sprintf_s(port, 10, "PRN%d", printer->id); printer_dev = (PRINTER_DEVICE*) calloc(1, sizeof(PRINTER_DEVICE)); if (!printer_dev) { WLog_ERR(TAG, "calloc failed!"); free(port); return CHANNEL_RC_NO_MEMORY; } printer_dev->device.type = RDPDR_DTYP_PRINT; printer_dev->device.name = port; printer_dev->device.IRPRequest = printer_irp_request; printer_dev->device.Free = printer_free; printer_dev->rdpcontext = pEntryPoints->rdpcontext; printer_dev->printer = printer; CachedFieldsLen = 0; CachedPrinterConfigData = NULL; Flags = 0; if (printer->is_default) Flags |= RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER; DriverNameLen = ConvertToUnicode(CP_UTF8, 0, printer->driver, -1, &DriverName, 0) * 2; PrintNameLen = ConvertToUnicode(CP_UTF8, 0, printer->name, -1, &PrintName, 0) * 2; printer_dev->device.data = Stream_New(NULL, 28 + DriverNameLen + PrintNameLen + CachedFieldsLen); if (!printer_dev->device.data) { WLog_ERR(TAG, "calloc failed!"); error = CHANNEL_RC_NO_MEMORY; free(DriverName); free(PrintName); goto error_out; } Stream_Write_UINT32(printer_dev->device.data, Flags); Stream_Write_UINT32(printer_dev->device.data, 0); /* CodePage, reserved */ Stream_Write_UINT32(printer_dev->device.data, 0); /* PnPNameLen */ Stream_Write_UINT32(printer_dev->device.data, DriverNameLen + 2); Stream_Write_UINT32(printer_dev->device.data, PrintNameLen + 2); Stream_Write_UINT32(printer_dev->device.data, CachedFieldsLen); Stream_Write(printer_dev->device.data, DriverName, DriverNameLen); Stream_Write_UINT16(printer_dev->device.data, 0); Stream_Write(printer_dev->device.data, PrintName, PrintNameLen); Stream_Write_UINT16(printer_dev->device.data, 0); if (CachedFieldsLen > 0) { Stream_Write(printer_dev->device.data, CachedPrinterConfigData, CachedFieldsLen); } free(DriverName); free(PrintName); printer_dev->pIrpList = (WINPR_PSLIST_HEADER) _aligned_malloc(sizeof( WINPR_SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); if (!printer_dev->pIrpList) { WLog_ERR(TAG, "_aligned_malloc failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } InitializeSListHead(printer_dev->pIrpList); if (!(printer_dev->event = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "CreateEvent failed!"); error = ERROR_INTERNAL_ERROR; goto error_out; } if (!(printer_dev->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "CreateEvent failed!"); error = ERROR_INTERNAL_ERROR; goto error_out; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) printer_dev))) { WLog_ERR(TAG, "RegisterDevice failed with error %d!", error); goto error_out; } if (!(printer_dev->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) printer_thread_func, (void*) printer_dev, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); error = ERROR_INTERNAL_ERROR; goto error_out; } return CHANNEL_RC_OK; error_out: CloseHandle(printer_dev->stopEvent); CloseHandle(printer_dev->event); _aligned_free(printer_dev->pIrpList); Stream_Free(printer_dev->device.data, TRUE); free(printer_dev); free(port); return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; size_t length; int ck; RDPDR_SMARTCARD* device; SMARTCARD_DEVICE* smartcard; UINT error = CHANNEL_RC_NO_MEMORY; device = (RDPDR_SMARTCARD*) pEntryPoints->device; name = device->Name; path = device->Path; smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE)); if (!smartcard) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } smartcard->device.type = RDPDR_DTYP_SMARTCARD; smartcard->device.name = "SCARD"; smartcard->device.IRPRequest = smartcard_irp_request; smartcard->device.Init = smartcard_init; smartcard->device.Free = smartcard_free; smartcard->rdpcontext = pEntryPoints->rdpcontext; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); if (!smartcard->device.data) { WLog_ERR(TAG, "Stream_New failed!"); goto error_device_data; } Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->name = NULL; smartcard->path = NULL; if (path) { smartcard->path = path; smartcard->name = name; } else if (name) { if (1 == sscanf(name, "%d", &ck)) smartcard->path = name; else smartcard->name = name; } smartcard->IrpQueue = MessageQueue_New(NULL); if (!smartcard->IrpQueue) { WLog_ERR(TAG, "MessageQueue_New failed!"); goto error_irp_queue; } smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1); if (!smartcard->CompletedIrpQueue) { WLog_ERR(TAG, "Queue_New failed!"); goto error_completed_irp_queue; } smartcard->rgSCardContextList = ListDictionary_New(TRUE); if (!smartcard->rgSCardContextList) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto error_context_list; } ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree = (OBJECT_FREE_FN) smartcard_context_free; smartcard->rgOutstandingMessages = ListDictionary_New(TRUE); if (!smartcard->rgOutstandingMessages) { WLog_ERR(TAG, "ListDictionary_New failed!"); goto error_outstanding_messages; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard))) { WLog_ERR(TAG, "RegisterDevice failed!"); goto error_outstanding_messages; } smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); if (!smartcard->thread) { WLog_ERR(TAG, "ListDictionary_New failed!"); error = ERROR_INTERNAL_ERROR; goto error_thread; } ResumeThread(smartcard->thread); return CHANNEL_RC_OK; error_thread: ListDictionary_Free(smartcard->rgOutstandingMessages); error_outstanding_messages: ListDictionary_Free(smartcard->rgSCardContextList); error_context_list: Queue_Free(smartcard->CompletedIrpQueue); error_completed_irp_queue: MessageQueue_Free(smartcard->IrpQueue); error_irp_queue: Stream_Free(smartcard->device.data, TRUE); error_device_data: free(smartcard); return error; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int i; size_t length; RDPDR_PARALLEL* device; PARALLEL_DEVICE* parallel; UINT error; device = (RDPDR_PARALLEL*) pEntryPoints->device; name = device->Name; path = device->Path; if (!name || (name[0] == '*')) { /* TODO: implement auto detection of parallel ports */ return CHANNEL_RC_OK; } if (name[0] && path[0]) { parallel = (PARALLEL_DEVICE*) calloc(1, sizeof(PARALLEL_DEVICE)); if (!parallel) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } parallel->device.type = RDPDR_DTYP_PARALLEL; parallel->device.name = name; parallel->device.IRPRequest = parallel_irp_request; parallel->device.Free = parallel_free; parallel->rdpcontext = pEntryPoints->rdpcontext; length = strlen(name); parallel->device.data = Stream_New(NULL, length + 1); if (!parallel->device.data) { WLog_ERR(TAG, "Stream_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } for (i = 0; i <= length; i++) Stream_Write_UINT8(parallel->device.data, name[i] < 0 ? '_' : name[i]); parallel->path = path; parallel->queue = MessageQueue_New(NULL); if (!parallel->queue) { WLog_ERR(TAG, "MessageQueue_New failed!"); error = CHANNEL_RC_NO_MEMORY; goto error_out; } if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel))) { WLog_ERR(TAG, "RegisterDevice failed with error %lu!", error); goto error_out; } if (!(parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); error = ERROR_INTERNAL_ERROR; goto error_out; } } return CHANNEL_RC_OK; error_out: MessageQueue_Free(parallel->queue); Stream_Free(parallel->device.data, TRUE); free(parallel); return error; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { char* name; char* path; int length, ck; RDPDR_SMARTCARD* device; SMARTCARD_DEVICE* smartcard; device = (RDPDR_SMARTCARD*) pEntryPoints->device; name = device->Name; path = device->Path; smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE)); if (!smartcard) return -1; smartcard->device.type = RDPDR_DTYP_SMARTCARD; smartcard->device.name = "SCARD"; smartcard->device.IRPRequest = smartcard_irp_request; smartcard->device.Init = smartcard_init; smartcard->device.Free = smartcard_free; length = strlen(smartcard->device.name); smartcard->device.data = Stream_New(NULL, length + 1); Stream_Write(smartcard->device.data, "SCARD", 6); smartcard->name = NULL; smartcard->path = NULL; if (path) { smartcard->path = path; smartcard->name = name; } else if (name) { if (1 == sscanf(name, "%d", &ck)) smartcard->path = name; else smartcard->name = name; } smartcard->log = WLog_Get("com.freerdp.channel.smartcard.client"); //WLog_SetLogLevel(smartcard->log, WLOG_DEBUG); smartcard->IrpQueue = MessageQueue_New(NULL); smartcard->rgSCardContextList = ListDictionary_New(TRUE); smartcard->rgOutstandingMessages = ListDictionary_New(TRUE); smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1); smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func, smartcard, CREATE_SUSPENDED, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard); ResumeThread(smartcard->thread); return 0; }