-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqubes-core-agent-windows-mingw-fragments.patch
1853 lines (1640 loc) · 64.9 KB
/
qubes-core-agent-windows-mingw-fragments.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -pruN a/include/customddkinc.h b/include/customddkinc.h
--- a/include/customddkinc.h 1970-01-01 03:00:00.000000000 +0300
+++ b/include/customddkinc.h 2020-01-17 13:31:52.958729291 +0300
@@ -0,0 +1,72 @@
+#include <devpropdef.h>
+#include <strsafe.h>
+#include <sal.h>
+
+#define __field_bcount_part(size,init) SAL__notnull SAL__byte_writableTo(size) SAL__byte_readableTo(init)
+
+DEFINE_DEVPROPKEY(DEVPKEY_Device_HardwareIds, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 3); // DEVPROP_TYPE_STRING_LIST
+DEFINE_DEVPROPKEY(DEVPKEY_Device_Class, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 9); // DEVPROP_TYPE_STRING
+DEFINE_DEVPROPKEY(DEVPKEY_Device_LocationInfo, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 15); // DEVPROP_TYPE_STRING
+#define IOCTL_DISK_SET_DISK_ATTRIBUTES CTL_CODE(IOCTL_DISK_BASE, 0x003d, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+
+#define DISK_ATTRIBUTE_OFFLINE 0x0000000000000001
+#define DISK_ATTRIBUTE_READ_ONLY 0x0000000000000002
+
+//
+// IOCTL_DISK_SET_DISK_ATTRIBUTES
+//
+// Input Buffer:
+// Structure of type SET_DISK_ATTRIBUTES
+//
+// Output Buffer:
+// None
+//
+
+typedef struct _SET_DISK_ATTRIBUTES {
+
+ //
+ // Specifies the size of the
+ // structure for versioning.
+ //
+ ULONG Version;
+
+ //
+ // Indicates whether to remember
+ // these settings across reboots
+ // or not.
+ //
+ BOOLEAN Persist;
+
+ //
+ // Indicates whether the ownership
+ // taken earlier is being released.
+ //
+ BOOLEAN RelinquishOwnership;
+
+ //
+ // For alignment purposes.
+ //
+ BOOLEAN Reserved1[2];
+
+ //
+ // Specifies the new attributes.
+ //
+ ULONGLONG Attributes;
+
+ //
+ // Specifies the attributes
+ // that are being modified.
+ //
+ ULONGLONG AttributesMask;
+
+ //
+ // Specifies an identifier to be
+ // associated with the caller.
+ // This setting is not persisted
+ // across reboots.
+ //
+ GUID Owner;
+
+} SET_DISK_ATTRIBUTES, *PSET_DISK_ATTRIBUTES;
+
+
diff -pruN a/include/setupapifn.h b/include/setupapifn.h
--- a/include/setupapifn.h 1970-01-01 03:00:00.000000000 +0300
+++ b/include/setupapifn.h 2020-01-17 13:31:52.958729291 +0300
@@ -0,0 +1,4 @@
+#define SetupDiGetDeviceProperty __MINGW_NAME_AW(SetupDiGetDeviceProperty)
+
+WINSETUPAPI WINBOOL WINAPI SetupDiGetDevicePropertyW(HDEVINFO DeviceInfoSet,PSP_DEVINFO_DATA DeviceInfoData,const DEVPROPKEY *PropertyKey,DEVPROPTYPE *PropertyType,PBYTE PropertyBuffer,DWORD PropertyBufferSize,PDWORD RequiredSize,DWORD Flags);
+
diff -pruN a/Makefile b/Makefile
--- a/Makefile 1970-01-01 03:00:00.000000000 +0300
+++ b/Makefile 2020-01-17 13:31:52.895729144 +0300
@@ -0,0 +1,57 @@
+OUTDIR = bin/$(ARCH)
+OUTDIR_ANY = bin/AnyCPU
+CFLAGS += -Iinclude -DUNICODE -D_UNICODE -mwindows -D_WIN32_WINNT=0x0600 -std=c11 -fgnu89-inline
+LDFLAGS += -Wl,--as-needed -lqubesdb-client -lwindows-utils -lshlwapi -lwtsapi32 -lwsock32 -liphlpapi -lsetupapi -lole32 -lcomctl32 -lrpcrt4 -luuid -lntdll -Wl,--no-insert-timestamp
+
+#TODO: drop ask-vm-and-run.exe
+TOOLS = $(addprefix $(OUTDIR)/, advertise-tools.exe ask-vm-and-run.exe network-setup.exe prepare-volume.exe qrexec-agent.exe qrexec-client-vm.exe qrexec-wrapper.exe)
+QREXEC_SERVICES = $(addprefix $(OUTDIR)/, clipboard-copy.exe clipboard-paste.exe file-receiver.exe file-sender.exe get-image-rgba.exe open-in-vm.exe open-url.exe set-gui-mode.exe vm-file-editor.exe wait-for-logon.exe window-icon-updater.exe)
+RPC_FILES = $(addprefix $(OUTDIR_ANY)/qubes-rpc/,qubes.ClipboardCopy qubes.ClipboardPaste qubes.Filecopy qubes.GetAppMenus qubes.GetImageRGBA qubes.OpenInVM qubes.OpenURL qubes.SetDateTime qubes.SetGuiMode qubes.StartApp qubes.VMShell qubes.WaitForSession)
+RPC_SCRIPTS = $(addprefix $(OUTDIR_ANY)/, get-appmenus.ps1 set-time.ps1 start-app.ps1)
+
+
+all: $(OUTDIR) $(OUTDIR_ANY) $(OUTDIR_ANY)/qubes-rpc $(TOOLS) $(QREXEC_SERVICES) $(RPC_FILES) $(RPC_SCRIPTS) $(OUTDIR_ANY)/service-policy.exe $(OUTDIR_ANY)/service-policy.cfg $(OUTDIR)/relocate-dir.exe
+
+$(OUTDIR) $(OUTDIR_ANY) $(OUTDIR_ANY)/qubes-rpc:
+ mkdir -p $@
+
+$(addprefix $(OUTDIR)/,qrexec-agent.exe qrexec-client-vm.exe qrexec-wrapper.exe): LDFLAGS+=-lvchan
+$(OUTDIR)/advertise-tools.exe: LDFLAGS+=-lqubesdb-client
+
+$(QREXEC_SERVICES): CFLAGS += -Isrc/qrexec-services/common
+
+
+$(OUTDIR)/file-receiver.exe: src/qrexec-services/common/filecopy.c src/qrexec-services/common/filecopy-error.c
+#$(OUTDIR)/file-receiver.exe: CFLAGS += -DNO_SHLWAPI_STRFCNS
+
+$(OUTDIR)/file-sender.exe: src/qrexec-services/common/filecopy.c src/qrexec-services/common/filecopy-error.c $(OUTDIR)/file-sender.res
+$(OUTDIR)/open-in-vm.exe: src/qrexec-services/common/filecopy.c src/qrexec-services/common/filecopy-error.c
+
+# specific rules
+
+$(OUTDIR)/file-sender.res: src/qrexec-services/file-sender/file-sender.rc
+ $(WINDRES) -i $< -o $@ -O coff
+
+$(OUTDIR_ANY)/service-policy.exe: $(wildcard src/service-policy/*.cs)
+ mcs $^ -r:System.ServiceProcess.dll -out:$@
+
+$(OUTDIR_ANY)/service-policy.cfg: src/service-policy/service-policy.cfg
+ cp $^ $@
+
+$(OUTDIR)/relocate-dir.exe: $(wildcard src/relocate-dir/*.c)
+ $(CC) $^ $(CFLAGS) -I$(DDK_PATH) -e NtProcessStartup -Wl,--subsystem,native -L $(OUTDIR) -lntdll -nostdlib -D__INTRINSIC_DEFINED__InterlockedAdd64 -fstack-check -Wl,--stack,16777216 -mno-stack-arg-probe -municode -Wl,--no-insert-timestamp -o $@
+
+$(RPC_FILES): $(OUTDIR_ANY)/qubes-rpc/%: src/qrexec-services/%
+ cp $^ $@
+
+$(RPC_SCRIPTS): $(OUTDIR_ANY)/%: src/qrexec-services/%
+ cp $^ $@
+
+# generic rules
+
+.SECONDEXPANSION:
+$(TOOLS): $(OUTDIR)/%.exe: $$(wildcard src/%/*.c)
+ $(CC) $^ $(CFLAGS) $(LDFLAGS) -municode -o $@
+
+$(QREXEC_SERVICES): $(OUTDIR)/%.exe: $$(wildcard src/qrexec-services/%/*.c)
+ $(CC) $^ $(CFLAGS) $(LDFLAGS) -municode -o $@
diff -pruN a/src/advertise-tools/advertise-tools.c b/src/advertise-tools/advertise-tools.c
--- a/src/advertise-tools/advertise-tools.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/advertise-tools/advertise-tools.c 2020-01-17 13:31:52.959729293 +0300
@@ -21,7 +21,7 @@
#include <windows.h>
#include <shlwapi.h>
-#include <Wtsapi32.h>
+#include <wtsapi32.h>
#include <qubesdb-client.h>
#include <log.h>
@@ -42,7 +42,7 @@ BOOL GetCurrentUser(OUT char **userName)
if (!WTSEnumerateSessionsA(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessionInfo, &sessionCount))
{
- perror("WTSEnumerateSessionsA");
+ win_perror("WTSEnumerateSessionsA");
return FALSE;
}
@@ -58,7 +58,7 @@ BOOL GetCurrentUser(OUT char **userName)
userName,
&cbUserName))
{
- perror("WTSQuerySessionInformationA");
+ win_perror("WTSQuerySessionInformationA");
goto cleanup;
}
LogDebug("Found session: %S\n", *userName);
@@ -79,7 +79,7 @@ BOOL PrepareExePath(OUT WCHAR *fullPath,
{
if (ERROR_SUCCESS != CfgReadString(NULL, L"InstallDir", fullPath, MAX_PATH, NULL))
{
- perror("CfgReadString(InstallDir)");
+ win_perror("CfgReadString(InstallDir)");
return FALSE;
}
@@ -87,12 +87,12 @@ BOOL PrepareExePath(OUT WCHAR *fullPath,
if (!PathAppend(fullPath, L"bin"))
{
- perror("PathAppend(bin)");
+ win_perror("PathAppend(bin)");
return FALSE;
}
if (!PathAppend(fullPath, exeName))
{
- perror("PathAppend(exe)");
+ win_perror("PathAppend(exe)");
return FALSE;
}
@@ -141,7 +141,7 @@ BOOL NotifyDom0(void)
&si,
&pi))
{
- perror("CreateProcess(qrexec-client-vm.exe)");
+ win_perror("CreateProcess(qrexec-client-vm.exe)");
return FALSE;
}
@@ -178,7 +178,7 @@ int wmain(int argc, WCHAR *argv[])
qdb = qdb_open(NULL);
if (!qdb)
{
- perror("qdb_open");
+ win_perror("qdb_open");
goto cleanup;
}
@@ -204,37 +204,37 @@ int wmain(int argc, WCHAR *argv[])
/* for now mostly hardcoded values, but this can change in the future */
if (!QdbWrite(qdb, QDB_PATH_PREFIX "version", "1"))
{
- perror("write 'version' entry");
+ win_perror("write 'version' entry");
goto cleanup;
}
if (!QdbWrite(qdb, QDB_PATH_PREFIX "os", "Windows"))
{
- perror("write 'os' entry");
+ win_perror("write 'os' entry");
goto cleanup;
}
if (!QdbWrite(qdb, QDB_PATH_PREFIX "qrexec", qrexecAgentPresent ? "1" : "0"))
{
- perror("write 'qrexec' entry");
+ win_perror("write 'qrexec' entry");
goto cleanup;
}
if (!QdbWrite(qdb, QDB_PATH_PREFIX "gui", guiAgentPresent ? "1" : "0"))
{
- perror("write 'gui' entry");
+ win_perror("write 'gui' entry");
goto cleanup;
}
if (!QdbWrite(qdb, QDB_PATH_PREFIX "gui-emulated", guiAgentPresent ? "0" : "1"))
{
- perror("write 'gui-emulated' entry");
+ win_perror("write 'gui-emulated' entry");
goto cleanup;
}
if (!QdbWrite(qdb, QDB_PATH_PREFIX "default-user", userName))
{
- perror("write 'default-user' entry");
+ win_perror("write 'default-user' entry");
goto cleanup;
}
diff -pruN a/src/ask-vm-and-run/ask-vm-and-run.c b/src/ask-vm-and-run/ask-vm-and-run.c
--- a/src/ask-vm-and-run/ask-vm-and-run.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/ask-vm-and-run/ask-vm-and-run.c 2020-01-17 13:31:52.959729293 +0300
@@ -20,7 +20,7 @@
*/
#include <windows.h>
-#include <Shlwapi.h>
+#include <shlwapi.h>
#include <strsafe.h>
#include <stdlib.h>
#include "resource.h"
@@ -87,7 +87,7 @@ int APIENTRY wWinMain(HINSTANCE instance
// build qrexec-client-vm path, first get our own
if (!GetModuleFileName(NULL, qrexecClientPath, RTL_NUMBER_OF(qrexecClientPath)))
{
- status = perror("GetModuleFileName");
+ status = win_perror("GetModuleFileName");
ReportError(L"Failed to get " QREXEC_CLIENT_VM L" path");
return status;
}
@@ -130,7 +130,7 @@ int APIENTRY wWinMain(HINSTANCE instance
if (!CreateProcess(qrexecClientPath, qrexecClientCmdLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
{
- status = perror("CreateProcess");
+ status = win_perror("CreateProcess");
ReportError(L"Failed to execute qrexec-client-vm.exe");
return status;
}
diff -pruN a/src/network-setup/qubes-network-setup.c b/src/network-setup/qubes-network-setup.c
--- a/src/network-setup/qubes-network-setup.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/network-setup/qubes-network-setup.c 2020-01-17 13:31:52.959729293 +0300
@@ -72,14 +72,14 @@ DWORD SetNetworkParameters(IN DWORD ip,
if (status != ERROR_BUFFER_OVERFLOW)
{
- perror2(status, "GetAdaptersInfo");
+ win_perror2(status, "GetAdaptersInfo");
goto cleanup;
}
adapterInfo = (IP_ADAPTER_INFO *) malloc(cbAdaptersInfo);
if ((status = GetAdaptersInfo(adapterInfo, &cbAdaptersInfo)) != ERROR_SUCCESS)
{
- perror2(status, "GetAdaptersInfo 2");
+ win_perror2(status, "GetAdaptersInfo 2");
goto cleanup;
}
@@ -107,7 +107,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
status = DeleteIPAddress(addrCurrent->Context);
if (status != ERROR_SUCCESS)
{
- perror2(status, "DeleteIPAddress");
+ win_perror2(status, "DeleteIPAddress");
goto cleanup;
}
addrCurrent = addrCurrent->Next;
@@ -117,7 +117,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
status = AddIPAddress(ip, netmask, adapterInfoCurrent->Index, &nteContext, &nteInstance);
if (status != ERROR_SUCCESS)
{
- perror2(status, "AddIPAddress");
+ win_perror2(status, "AddIPAddress");
goto cleanup;
}
@@ -147,7 +147,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
if (status != ERROR_SUCCESS)
{
- perror2(status, "GetIpForwardTable");
+ win_perror2(status, "GetIpForwardTable");
goto cleanup;
}
@@ -164,7 +164,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
if (status != ERROR_SUCCESS)
{
- perror2(status, "DeleteIpForwardEntry");
+ win_perror2(status, "DeleteIpForwardEntry");
goto cleanup;
}
}
@@ -176,7 +176,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
status = GetIpInterfaceEntry(&ipInterfaceRow);
if (status != NO_ERROR)
{
- perror2(status, "GetIpInterfaceEntry");
+ win_perror2(status, "GetIpInterfaceEntry");
goto cleanup;
}
@@ -190,7 +190,7 @@ DWORD SetNetworkParameters(IN DWORD ip,
status = CreateIpForwardEntry(&ipForwardRow);
if (status != NO_ERROR)
- perror2(status, "CreateIpForwardEntry");
+ win_perror2(status, "CreateIpForwardEntry");
status = ERROR_SUCCESS;
@@ -248,7 +248,7 @@ DWORD WINAPI SetupNetwork(PVOID param)
qdb = qdb_open(NULL);
if (!qdb)
{
- perror("qdb_open");
+ win_perror("qdb_open");
goto cleanup;
}
diff -pruN a/src/prepare-volume/device.c b/src/prepare-volume/device.c
--- a/src/prepare-volume/device.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/device.c 2020-01-17 13:31:52.959729293 +0300
@@ -22,11 +22,18 @@
#include "device.h"
#include "disk.h"
-#include <SetupAPI.h>
+#include <setupapi.h>
#include <cfgmgr32.h>
#include <rpc.h>
#include <devpkey.h>
+#ifdef __MINGW32__
+#include "customddkinc.h"
+#include "setupapifn.h"
+#endif
+
+#include <strsafe.h>
+
// Convert backend device ID to Windows' disk target id.
// See __ParseVbd() in xenvbd/fdo.c in the new pvdrivers.
static ULONG BackendIdToTargetId(ULONG backendId)
@@ -115,7 +122,7 @@ BOOL GetPrivateImgDriveNumber(IN ULONG x
if (deviceInfoSet == INVALID_HANDLE_VALUE)
{
- perror("SetupDiGetClassDevs");
+ win_perror("SetupDiGetClassDevs");
return FALSE;
}
@@ -126,7 +133,7 @@ BOOL GetPrivateImgDriveNumber(IN ULONG x
{
if (!SetupDiGetDeviceInstanceId(deviceInfoSet, &deviceInfoData, deviceId, RTL_NUMBER_OF(deviceId), &returnedSize))
{
- perror("SetupDiGetDeviceInstanceId");
+ win_perror("SetupDiGetDeviceInstanceId");
continue;
}
@@ -137,7 +144,7 @@ BOOL GetPrivateImgDriveNumber(IN ULONG x
if (!SetupDiGetDeviceProperty(deviceInfoSet, &deviceInfoData, &DEVPKEY_Device_LocationInfo, &devPropType,
(BYTE *)locationString, sizeof(locationString), &returnedSize, 0))
{
- perror("SetupDiGetDeviceProperty(location)");
+ win_perror("SetupDiGetDeviceProperty(location)");
continue;
}
diff -pruN a/src/prepare-volume/disk.c b/src/prepare-volume/disk.c
--- a/src/prepare-volume/disk.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/disk.c 2020-01-17 13:31:52.960729296 +0300
@@ -22,8 +22,12 @@
#include "disk.h"
#include "format.h"
#include "wait-for-volume.h"
+#ifdef __MINGW32__
+#include "customddkinc.h"
+#endif
#include <stdlib.h>
+#include <strsafe.h>
// without braces
PWCHAR DISK_CLASS_GUID = L"4d36e967-e325-11ce-bfc1-08002be10318";
@@ -38,14 +42,14 @@ BOOL GetPhysicalDriveNumber(IN WCHAR *de
if (device == INVALID_HANDLE_VALUE)
{
- perror("CreateFile");
+ win_perror("CreateFile");
goto cleanup;
}
// Get device number.
if (!DeviceIoControl(device, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &deviceNumber, sizeof(deviceNumber), &returnedSize, NULL))
{
- perror("IOCTL_STORAGE_GET_DEVICE_NUMBER");
+ win_perror("IOCTL_STORAGE_GET_DEVICE_NUMBER");
goto cleanup;
}
@@ -87,7 +91,7 @@ static BOOL VolumeNameToDiskLetter(IN WC
ZeroMemory(mountPoints, returned*sizeof(WCHAR));
if (!GetVolumePathNamesForVolumeName(volumeName, mountPoints, returned, &returned))
{
- perror("GetVolumePathNamesForVolumeName");
+ win_perror("GetVolumePathNamesForVolumeName");
free(mountPoints);
return FALSE;
}
@@ -121,7 +125,7 @@ BOOL DriveNumberToVolumeName(IN DWORD dr
findHandle = FindFirstVolume(volumeName, volumeNameLength);
if (findHandle == INVALID_HANDLE_VALUE)
{
- perror("FindFirstVolume");
+ win_perror("FindFirstVolume");
return FALSE;
}
@@ -134,14 +138,14 @@ BOOL DriveNumberToVolumeName(IN DWORD dr
volume = CreateFile(volumeName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (volume == INVALID_HANDLE_VALUE)
{
- perror("open volume");
+ win_perror("open volume");
goto skip;
}
// Get volume disk extents.
if (!DeviceIoControl(volume, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, &extents, sizeof(extents), &returnedSize, NULL))
{
- perror("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS");
+ win_perror("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS");
goto skip;
}
@@ -205,14 +209,14 @@ static BOOL InitializeDisk(IN HANDLE dev
if (!DeviceIoControl(device, IOCTL_DISK_SET_DISK_ATTRIBUTES, &diskAttrs, sizeof(diskAttrs), NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_SET_DISK_ATTRIBUTES");
+ win_perror("IOCTL_DISK_SET_DISK_ATTRIBUTES");
return FALSE;
}
// Tell the system that the disk was changed.
if (!DeviceIoControl(device, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_UPDATE_PROPERTIES");
+ win_perror("IOCTL_DISK_UPDATE_PROPERTIES");
return FALSE;
}
@@ -226,7 +230,7 @@ static BOOL InitializeDisk(IN HANDLE dev
if (!DeviceIoControl(device, IOCTL_DISK_CREATE_DISK, &createDisk, sizeof(createDisk), NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_CREATE_DISK");
+ win_perror("IOCTL_DISK_CREATE_DISK");
return FALSE;
}
@@ -234,7 +238,7 @@ static BOOL InitializeDisk(IN HANDLE dev
if (!DeviceIoControl(device, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_UPDATE_PROPERTIES");
+ win_perror("IOCTL_DISK_UPDATE_PROPERTIES");
return FALSE;
}
@@ -270,13 +274,13 @@ static BOOL InitializeDisk(IN HANDLE dev
if (!DeviceIoControl(device, IOCTL_DISK_SET_DRIVE_LAYOUT_EX, partitionBuffer, sizeof(partitionBuffer), NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_SET_DRIVE_LAYOUT_EX");
+ win_perror("IOCTL_DISK_SET_DRIVE_LAYOUT_EX");
return FALSE;
}
if (!DeviceIoControl(device, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &requiredSize, NULL))
{
- perror("IOCTL_DISK_UPDATE_PROPERTIES");
+ win_perror("IOCTL_DISK_UPDATE_PROPERTIES");
return FALSE;
}
@@ -315,14 +319,14 @@ BOOL PreparePrivateVolume(IN ULONG drive
device = CreateFile(driveName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (device == INVALID_HANDLE_VALUE)
{
- perror("CreateFile");
+ win_perror("CreateFile");
return FALSE;
}
// Get partition information.
if (!DeviceIoControl(device, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, buf, sizeof(buf), &returnedSize, NULL))
{
- perror("IOCTL_DISK_GET_DRIVE_LAYOUT_EX");
+ win_perror("IOCTL_DISK_GET_DRIVE_LAYOUT_EX");
goto cleanup;
}
@@ -355,7 +359,7 @@ BOOL PreparePrivateVolume(IN ULONG drive
// Check the filesystem.
if (!GetVolumeInformation(volumeName, NULL, 0, NULL, NULL, NULL, filesystemName, RTL_NUMBER_OF(filesystemName)))
{
- perror("GetVolumeInformation");
+ win_perror("GetVolumeInformation");
reinitialize = TRUE;
}
else
@@ -394,7 +398,7 @@ BOOL PreparePrivateVolume(IN ULONG drive
// Get disk size.
if (!DeviceIoControl(device, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &lengthInfo, sizeof(lengthInfo), &returnedSize, NULL))
{
- perror("IOCTL_DISK_GET_LENGTH_INFO");
+ win_perror("IOCTL_DISK_GET_LENGTH_INFO");
goto cleanup;
}
diff -pruN a/src/prepare-volume/format.c b/src/prepare-volume/format.c
--- a/src/prepare-volume/format.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/format.c 2020-01-17 13:31:52.960729296 +0300
@@ -120,7 +120,7 @@ BOOL FormatVolume(IN DWORD diskNumber)
g_fmifsDll = LoadLibrary(L"fmifs");
if (!g_fmifsDll)
{
- perror("LoadLibrary(fmifs)");
+ win_perror("LoadLibrary(fmifs)");
return FALSE;
}
}
@@ -130,7 +130,7 @@ BOOL FormatVolume(IN DWORD diskNumber)
g_FormatEx = (FormatEx_t) GetProcAddress(g_fmifsDll, "FormatEx");
if (!g_FormatEx)
{
- perror("GetProcAddress(fmifs, FormatEx)");
+ win_perror("GetProcAddress(fmifs, FormatEx)");
return FALSE;
}
}
diff -pruN a/src/prepare-volume/prepare-volume.c b/src/prepare-volume/prepare-volume.c
--- a/src/prepare-volume/prepare-volume.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/prepare-volume.c 2020-01-17 13:31:52.960729296 +0300
@@ -23,11 +23,12 @@
#include "prepare-volume.h"
#include <shellapi.h>
-#include <Shlwapi.h>
-#include <ShlObj.h>
-#include <Knownfolders.h>
+#include <shlobj.h>
+#include <shlwapi.h>
+#include <knownfolders.h>
#include <aclapi.h>
#include <stdlib.h>
+#include <strsafe.h>
#include "device.h"
#include "disk.h"
@@ -44,7 +45,7 @@ DWORD EnablePrivilege(HANDLE token, cons
LUID luid;
if (!LookupPrivilegeValue(NULL, privilegeName, &luid))
- return perror("LookupPrivilegeValue");
+ return win_perror("LookupPrivilegeValue");
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
@@ -57,7 +58,7 @@ DWORD EnablePrivilege(HANDLE token, cons
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL))
- return perror("AdjustTokenPrivileges");
+ return win_perror("AdjustTokenPrivileges");
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
@@ -132,7 +133,7 @@ int wmain(int argc, WCHAR *argv[])
// Check if profiles directory is already a junction point to the private volume.
if (S_OK != SHGetKnownFolderPath(&FOLDERID_UserProfiles, 0, NULL, &usersPath))
{
- perror("SHGetKnownFolderPath(FOLDERID_UserProfiles)");
+ win_perror("SHGetKnownFolderPath(FOLDERID_UserProfiles)");
return 1;
}
@@ -153,7 +154,7 @@ int wmain(int argc, WCHAR *argv[])
status = CfgReadString(NULL, LOG_CONFIG_PATH_VALUE, logPath, MAX_PATH_LONG, NULL);
if (ERROR_SUCCESS != status)
{
- perror2(status, "Reading log path from registry");
+ win_perror2(status, "Reading log path from registry");
return 1;
}
@@ -164,7 +165,7 @@ int wmain(int argc, WCHAR *argv[])
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", 0, KEY_READ | KEY_WRITE, &key);
if (ERROR_SUCCESS != status)
{
- perror2(status, "Opening Session Manager registry key");
+ win_perror2(status, "Opening Session Manager registry key");
return 1;
}
@@ -172,7 +173,7 @@ int wmain(int argc, WCHAR *argv[])
status = RegQueryValueEx(key, L"BootExecute", NULL, &valueType, (PBYTE)valueData, &size);
if (ERROR_SUCCESS != status)
{
- perror2(status, "Reading BootExecute entry");
+ win_perror2(status, "Reading BootExecute entry");
return 1;
}
@@ -217,7 +218,7 @@ int wmain(int argc, WCHAR *argv[])
status = RegSetValueEx(key, L"BootExecute", 0, REG_MULTI_SZ, (PBYTE)valueData, MultiWStrSize(valueData, NULL));
if (ERROR_SUCCESS != status)
{
- perror2(status, "RegSetValueEx");
+ win_perror2(status, "RegSetValueEx");
return 1;
}
diff -pruN a/src/prepare-volume/prepare-volume.h b/src/prepare-volume/prepare-volume.h
--- a/src/prepare-volume/prepare-volume.h 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/prepare-volume.h 2020-01-17 13:31:52.960729296 +0300
@@ -22,8 +22,7 @@
#pragma once
#define INITGUID
-#include <Windows.h>
+#include <windows.h>
#include <stdlib.h>
-#include <strsafe.h>
#include "log.h"
diff -pruN a/src/prepare-volume/wait-for-volume.c b/src/prepare-volume/wait-for-volume.c
--- a/src/prepare-volume/wait-for-volume.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/prepare-volume/wait-for-volume.c 2020-01-17 13:31:52.961729298 +0300
@@ -38,7 +38,7 @@ static void MessagePump(void)
{
if (retval == -1)
{
- perror("GetMessage");
+ win_perror("GetMessage");
break;
}
else
@@ -70,7 +70,7 @@ static BOOL DoRegisterDeviceInterface(
if (NULL == *deviceNotify)
{
- perror("RegisterDeviceNotification");
+ win_perror("RegisterDeviceNotification");
return FALSE;
}
@@ -97,7 +97,7 @@ static INT_PTR WINAPI DevNotifyWndProc(
hWnd,
&hDeviceNotify))
{
- perror("DoRegisterDeviceInterfaceToHwnd");
+ win_perror("DoRegisterDeviceInterfaceToHwnd");
ExitThread(1);
}
@@ -139,7 +139,7 @@ static INT_PTR WINAPI DevNotifyWndProc(
case WM_CLOSE:
if (!UnregisterDeviceNotification(hDeviceNotify))
{
- perror("UnregisterDeviceNotification");
+ win_perror("UnregisterDeviceNotification");
}
DestroyWindow(hWnd);
break;
@@ -173,7 +173,7 @@ static BOOL InitWindowClass(void)
if (!RegisterClassEx(&wndClass))
{
- perror("RegisterClassEx");
+ win_perror("RegisterClassEx");
return FALSE;
}
@@ -204,7 +204,7 @@ static DWORD WINAPI DevNotifyThread(void
if (hWnd == NULL)
{
- perror("CreateWindowEx: main appwindow hWnd");
+ win_perror("CreateWindowEx: main appwindow hWnd");
return 2;
}
@@ -234,7 +234,7 @@ WCHAR WaitForVolumeArrival(void)
notifyThread = CreateThread(NULL, 0, DevNotifyThread, &diskLetter, 0, NULL);
if (!notifyThread)
{
- perror("CreateThread");
+ win_perror("CreateThread");
return 0;
}
@@ -250,7 +250,7 @@ WCHAR WaitForVolumeArrival(void)
// Check thread's exit code.
if (!GetExitCodeThread(notifyThread, &exitCode))
{
- perror("GetExitCodeThread");
+ win_perror("GetExitCodeThread");
return 0;
}
diff -pruN a/src/qrexec-agent/qrexec-agent.c b/src/qrexec-agent/qrexec-agent.c
--- a/src/qrexec-agent/qrexec-agent.c 2019-06-20 03:55:59.000000000 +0300
+++ b/src/qrexec-agent/qrexec-agent.c 2020-01-17 13:31:52.961729298 +0300
@@ -22,10 +22,10 @@
#include <windows.h>
#include <stdlib.h>
#include <lmcons.h>
-#include <strsafe.h>
-#include <Shlwapi.h>
+#include <shlwapi.h>
#include <assert.h>
#include <crtdbg.h>
+#include <strsafe.h>
#include "qrexec-agent.h"
@@ -191,7 +191,7 @@ static DWORD Utf8WithBomToUtf16(IN const
hresult = StringCbCopyW(bufferUtf16, cbStringUtf8 - cbSkipChars + sizeof(WCHAR), (STRSAFE_LPCWSTR)(stringUtf8 + cbSkipChars));
if (FAILED(hresult))
{
- perror2(hresult, "StringCbCopyW");
+ win_perror2(hresult, "StringCbCopyW");
free(bufferUtf16);
return hresult;
}
@@ -215,7 +215,7 @@ static DWORD Utf8WithBomToUtf16(IN const
status = ConvertUTF8ToUTF16(stringUtf8 + cbSkipChars, stringUtf16, NULL);
if (ERROR_SUCCESS != status)
{
- return perror2(status, "ConvertUTF8ToUTF16");
+ return win_perror2(status, "ConvertUTF8ToUTF16");
}
LogVerbose("success");
@@ -309,7 +309,7 @@ static DWORD ParseUtf8Command(IN const c
status = ConvertUTF8ToUTF16(commandUtf8, commandUtf16, NULL);
if (ERROR_SUCCESS != status)
{
- return perror2(status, "ConvertUTF8ToUTF16");
+ return win_perror2(status, "ConvertUTF8ToUTF16");
}
LogInfo("Command: %s", *commandUtf16);
@@ -396,7 +396,7 @@ static DWORD InterceptRPCRequest(IN OUT
*sourceDomainName = _wcsdup(separator);
if (*sourceDomainName == NULL)
{
- return perror2(ERROR_NOT_ENOUGH_MEMORY, "_wcsdup");
+ return win_perror2(ERROR_NOT_ENOUGH_MEMORY, "_wcsdup");
}
LogDebug("source domain: '%s'", *sourceDomainName);
}
@@ -415,7 +415,7 @@ static DWORD InterceptRPCRequest(IN OUT
{
status = GetLastError();
free(*sourceDomainName);
- return perror2(status, "GetModuleFileName");
+ return win_perror2(status, "GetModuleFileName");
}
// cut off file name (qrexec_agent.exe)
separator = wcsrchr(serviceFilePath, L'\\');
@@ -490,7 +490,7 @@ static DWORD InterceptRPCRequest(IN OUT
if (serviceConfigFile == INVALID_HANDLE_VALUE)
{
- status = perror("CreateFile");
+ status = win_perror("CreateFile");
free(*sourceDomainName);
LogError("Failed to open service '%s' configuration file (%s)", serviceName, serviceFilePath);
return status;
@@ -501,7 +501,7 @@ static DWORD InterceptRPCRequest(IN OUT
if (!ReadFile(serviceConfigFile, serviceConfigContents, sizeof(WCHAR) * MAX_PATH, &cbRead, NULL))
{
- status = perror("ReadFile");
+ status = win_perror("ReadFile");
free(*sourceDomainName);
LogError("Failed to read RPC %s configuration file (%s)", serviceName, serviceFilePath);
CloseHandle(serviceConfigFile);
@@ -512,7 +512,7 @@ static DWORD InterceptRPCRequest(IN OUT
status = Utf8WithBomToUtf16(serviceConfigContents, cbRead, &rawServiceFilePath);
if (status != ERROR_SUCCESS)
{
- perror2(status, "TextBOMToUTF16");
+ win_perror2(status, "TextBOMToUTF16");
free(*sourceDomainName);
LogError("Failed to parse the encoding in RPC '%s' configuration file (%s)", serviceName, serviceFilePath);
return status;
@@ -559,7 +559,7 @@ static DWORD InterceptRPCRequest(IN OUT
if (*serviceCommandLine == NULL)
{
free(*sourceDomainName);
- return perror2(ERROR_NOT_ENOUGH_MEMORY, "malloc");
+ return win_perror2(ERROR_NOT_ENOUGH_MEMORY, "malloc");
}
LogDebug("RPC %s: %s\n", serviceName, *serviceCommandLine);
}
@@ -738,7 +738,7 @@ DWORD HandleServiceConnect(IN const stru
// TODO: should all service handlers run as current user (SYSTEM)?
status = StartChild(params->connect_domain, params->connect_port, NULL, context->CommandLine, TRUE, TRUE, TRUE);
if (ERROR_SUCCESS != status)
- perror("StartChild");
+ win_perror("StartChild");
EnterCriticalSection(&g_RequestCriticalSection);
RemoveEntryList(&context->ListEntry);
@@ -947,7 +947,7 @@ static DWORD HandleDaemonMessage(void)
LogVerbose("start");
if (!VchanReceiveBuffer(g_DaemonVchan, &header, sizeof header, L"daemon header"))
- return perror2(ERROR_INVALID_FUNCTION, "VchanReceiveBuffer");
+ return win_perror2(ERROR_INVALID_FUNCTION, "VchanReceiveBuffer");
switch (header.type)
{
@@ -991,14 +991,14 @@ static DWORD WatchForEvents(HANDLE stopE
// Don't do anything before qdb is available, otherwise advertise-tools may fail.
if (!WaitForQdb())
- return perror2(ERROR_INVALID_FUNCTION, "WaitForQdb");
+ return win_perror2(ERROR_INVALID_FUNCTION, "WaitForQdb");
// We give a 5 minute timeout here because xeniface can take some time
// to load the first time after reboot after pvdrivers installation.
g_DaemonVchan = VchanInitServer(0, VCHAN_BASE_PORT, VCHAN_BUFFER_SIZE, 5 * 60 * 1000);
if (!g_DaemonVchan)
- return perror2(ERROR_INVALID_FUNCTION, "VchanInitServer");
+ return win_perror2(ERROR_INVALID_FUNCTION, "VchanInitServer");
LogDebug("port %d: daemon vchan = %p", VCHAN_BASE_PORT, g_DaemonVchan);
LogInfo("Waiting for qrexec daemon connection, write buffer size: %d", VchanGetWriteBufferSize(g_DaemonVchan));
@@ -1027,7 +1027,7 @@ static DWORD WatchForEvents(HANDLE stopE
if (signaledEvent != 1)
{
- status = perror("WaitForMultipleObjects");
+ status = win_perror("WaitForMultipleObjects");
break;
}
@@ -1055,7 +1055,7 @@ static DWORD WatchForEvents(HANDLE stopE
}
else
{
- perror("Failed to create advertise-tools process");
+ win_perror("Failed to create advertise-tools process");
// this is non-fatal?
}
continue;
@@ -1075,7 +1075,7 @@ static DWORD WatchForEvents(HANDLE stopE
if (ERROR_SUCCESS != status)
{
run = FALSE;
- perror2(status, "HandleDaemonMessage");
+ win_perror2(status, "HandleDaemonMessage");
goto out;
}
}
@@ -1134,7 +1134,7 @@ DWORD WINAPI PipeClientThread(PVOID para
status = QpsRead(g_PipeServer, clientId, &context->ServiceParams, sizeof(context->ServiceParams));
if (ERROR_SUCCESS != status)
{
- perror2(status, "QpsRead(params)");
+ win_perror2(status, "QpsRead(params)");
goto cleanup;
}
@@ -1142,7 +1142,7 @@ DWORD WINAPI PipeClientThread(PVOID para
status = QpsRead(g_PipeServer, clientId, &commandSize, sizeof(commandSize));
if (ERROR_SUCCESS != status)
{
- perror2(status, "QpsRead(cmd size)");
+ win_perror2(status, "QpsRead(cmd size)");
goto cleanup;
}
@@ -1156,7 +1156,7 @@ DWORD WINAPI PipeClientThread(PVOID para
status = QpsRead(g_PipeServer, clientId, context->CommandLine, (DWORD)commandSize);
if (ERROR_SUCCESS != status)
{
- return perror2(status, "QpsRead(cmd)");
+ return win_perror2(status, "QpsRead(cmd)");
goto cleanup;
}
@@ -1204,7 +1204,7 @@ void ClientConnectedCallback(PIPE_SERVER
clientThread = CreateThread(NULL, 0, PipeClientThread, (PVOID)id, 0, NULL);
if (!clientThread)
{
- perror("create client thread");
+ win_perror("create client thread");
return;
}
CloseHandle(clientThread);
@@ -1242,7 +1242,7 @@ DWORD WINAPI ServiceExecutionThread(void
status = CreatePublicPipeSecurityDescriptor(&sd, &acl);
if (status != ERROR_SUCCESS)
- return perror("create pipe security descriptor");
+ return win_perror("create pipe security descriptor");
sa.nLength = sizeof(sa);
sa.bInheritHandle = FALSE;
@@ -1260,7 +1260,7 @@ DWORD WINAPI ServiceExecutionThread(void
&g_PipeServer);
if (ERROR_SUCCESS != status)
- perror2(status, "create pipe server");
+ win_perror2(status, "create pipe server");
LogVerbose("pipe server: %p", g_PipeServer);
@@ -1268,14 +1268,14 @@ DWORD WINAPI ServiceExecutionThread(void
if (!pipeServerThread)
{
status = GetLastError();
- return perror2(status, "create pipe server thread");
+ return win_perror2(status, "create pipe server thread");
}
LogVerbose("pipe thread: %p, entering loop", pipeServerThread);
status = WatchForEvents(ctx->StopEvent);
if (ERROR_SUCCESS != status)
- perror2(status, "WatchForEvents");
+ win_perror2(status, "WatchForEvents");
// FIXME: pipe server doesn't have the ability for graceful stop
diff -pruN a/src/qrexec-client-vm/qrexec-client-vm.c b/src/qrexec-client-vm/qrexec-client-vm.c