20#include <winpr/config.h>
33#ifdef WINPR_HAVE_UNISTD_H
41#include <winpr/path.h>
42#include <winpr/file.h>
63#define DEVICE_FILE_PREFIX_PATH "\\Device\\"
65static char* GetDeviceFileNameWithoutPrefixA(LPCSTR lpName)
67 char* lpFileName = NULL;
72 if (strncmp(lpName, DEVICE_FILE_PREFIX_PATH,
sizeof(DEVICE_FILE_PREFIX_PATH) - 1) != 0)
76 _strdup(&lpName[strnlen(DEVICE_FILE_PREFIX_PATH,
sizeof(DEVICE_FILE_PREFIX_PATH))]);
80static char* GetDeviceFileUnixDomainSocketBaseFilePathA(
void)
82 char* lpTempPath = NULL;
83 char* lpPipePath = NULL;
84 lpTempPath = GetKnownPath(KNOWN_PATH_TEMP);
89 lpPipePath = GetCombinedPath(lpTempPath,
".device");
94static char* GetDeviceFileUnixDomainSocketFilePathA(LPCSTR lpName)
96 char* lpPipePath = NULL;
97 char* lpFileName = NULL;
98 char* lpFilePath = NULL;
99 lpPipePath = GetDeviceFileUnixDomainSocketBaseFilePathA();
104 lpFileName = GetDeviceFileNameWithoutPrefixA(lpName);
112 lpFilePath = GetCombinedPath(lpPipePath, lpFileName);
123NTSTATUS _IoCreateDeviceEx(WINPR_ATTR_UNUSED PDRIVER_OBJECT_EX DriverObject,
124 WINPR_ATTR_UNUSED ULONG DeviceExtensionSize,
PUNICODE_STRING DeviceName,
125 WINPR_ATTR_UNUSED DEVICE_TYPE DeviceType,
126 WINPR_ATTR_UNUSED ULONG DeviceCharacteristics,
127 WINPR_ATTR_UNUSED BOOLEAN Exclusive, PDEVICE_OBJECT_EX* DeviceObject)
130 char* DeviceBasePath = NULL;
132 DeviceBasePath = GetDeviceFileUnixDomainSocketBaseFilePathA();
135 return STATUS_NO_MEMORY;
137 if (!winpr_PathFileExists(DeviceBasePath))
139 if (mkdir(DeviceBasePath, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
141 free(DeviceBasePath);
142 return STATUS_ACCESS_DENIED;
146 free(DeviceBasePath);
149 if (!pDeviceObjectEx)
150 return STATUS_NO_MEMORY;
152 pDeviceObjectEx->DeviceName =
153 ConvertWCharNToUtf8Alloc(DeviceName->Buffer, DeviceName->Length /
sizeof(WCHAR), NULL);
154 if (!pDeviceObjectEx->DeviceName)
156 free(pDeviceObjectEx);
157 return STATUS_NO_MEMORY;
160 pDeviceObjectEx->DeviceFileName =
161 GetDeviceFileUnixDomainSocketFilePathA(pDeviceObjectEx->DeviceName);
163 if (!pDeviceObjectEx->DeviceFileName)
165 free(pDeviceObjectEx->DeviceName);
166 free(pDeviceObjectEx);
167 return STATUS_NO_MEMORY;
170 if (winpr_PathFileExists(pDeviceObjectEx->DeviceFileName))
172 if (unlink(pDeviceObjectEx->DeviceFileName) == -1)
174 free(pDeviceObjectEx->DeviceName);
175 free(pDeviceObjectEx->DeviceFileName);
176 free(pDeviceObjectEx);
177 return STATUS_ACCESS_DENIED;
181 status = mkfifo(pDeviceObjectEx->DeviceFileName, 0666);
185 free(pDeviceObjectEx->DeviceName);
186 free(pDeviceObjectEx->DeviceFileName);
187 free(pDeviceObjectEx);
192 return STATUS_ACCESS_DENIED;
195 return STATUS_OBJECT_NAME_EXISTS;
198 return STATUS_NAME_TOO_LONG;
202 return STATUS_NOT_A_DIRECTORY;
205 return STATUS_DISK_FULL;
208 return STATUS_INTERNAL_ERROR;
212 *((ULONG_PTR*)(DeviceObject)) = (ULONG_PTR)pDeviceObjectEx;
213 return STATUS_SUCCESS;
221VOID _IoDeleteDeviceEx(PDEVICE_OBJECT_EX DeviceObject)
226 if (!pDeviceObjectEx)
229 unlink(pDeviceObjectEx->DeviceFileName);
230 free(pDeviceObjectEx->DeviceName);
231 free(pDeviceObjectEx->DeviceFileName);
232 free(pDeviceObjectEx);