Mercurial > trustbridge
annotate cinst/nssstore_win.c @ 670:175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 27 Jun 2014 10:27:08 +0200 |
parents | ef6d3dc9e930 |
children | d4766b4922c9 |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 #ifdef WIN32 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 /* @file |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 @brief Windows implementation of nssstore process control. |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
12 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
13 The windows process will write an instructions file for |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
14 the mozilla process into the current users temp directory |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
15 (%APPDATA%/Local/Temp/) and start the NSS installation process to |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
16 exectute those instructions. If the current process is elevated |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
17 the NSS process is run with a restricted token. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
18 The execution of the mozilla process is not monitored. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
19 You have to refer to the system log to check which certificates were |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
20 installed / removed by it. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
21 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
22 If the installation process is running elevated it |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
23 will create the file in the ProgramData directory in |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
24 a subdirectory with the defined application name. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
25 %PROGRAMDATA%/$APPLICATION_NAME |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
26 with the file name: |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
27 current_selection.txt |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
28 The folder will have restricted permissions so |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
29 that only Administrators are allowed to access it. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
30 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
31 Additionally if this process is Elevated it also starts the |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
32 NSS installation process in default profile mode once to change |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
33 the default NSS certificate databases for new profiles. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
34 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
35 The process then adds a new RunOnce registry key |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
36 for each user on the system that executes the NSS installation |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
37 process on login to make sure it is launched once in the |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
38 security context of that user. |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 #include <windows.h> |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
42 #include <sddl.h> |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 #include <stdio.h> |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 #include <stdbool.h> |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 #include <userenv.h> |
329
b1059360a0c7
Debugprintf with output debug string on windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
324
diff
changeset
|
46 #include <io.h> |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
47 #include <accctrl.h> |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
48 #include <aclapi.h> |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
49 #include <shlobj.h> |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 #include "logging.h" |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 #include "util.h" |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
53 #include "strhelp.h" |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
55 #ifndef APPNAME |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
56 #define APPNAME L"cinst" |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
57 #endif |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
59 #ifndef SELECTION_FILE_NAME |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
60 #define SELECTION_FILE_NAME L"currently_selected.txt" |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
61 #endif |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
62 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
63 /**@def The maximum time to wait for the NSS Process */ |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
64 #define PROCESS_TIMEOUT 30000 |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
66 /**@def The registry key to look for user profile directories */ |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
67 #define PROFILE_LIST L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList" |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
68 |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 /**@brief Write strv of instructions to a handle |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 * |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 * Writes the null terminated list of instructions to |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 * the handle. |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 * |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
74 * @param [in] certificates base64 encoded der certificate to write |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
75 * @param [in] write_handle handle to write to |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
76 * @param [in] remove weather the certificate should be installed or removed |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 * |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 * @returns true on success, false on failure |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 static bool |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
81 write_instructions(char **certificates, HANDLE write_handle, |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
82 bool remove) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 { |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
84 bool retval = false; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 int i = 0; |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
86 const char *line_end = "\r\n"; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
87 char *line_start = NULL; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
89 if (!certificates) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 { |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
91 return true; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
94 line_start = remove ? "R:" : "I:"; |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
95 |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
96 for (i = 0; certificates[i]; i++) |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
97 { |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
98 DWORD written = 0; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
99 DWORD inst_len = strlen (certificates[i]); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
100 retval = WriteFile (write_handle, (LPCVOID) line_start, 2, &written, NULL); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
101 if (!retval) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 { |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
103 PRINTLASTERROR ("Failed to write line start\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
104 return false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
105 } |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
106 if (written != 2) |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
107 { |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
108 ERRORPRINTF ("Failed to write line start\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
109 retval = false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
110 return false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
111 } |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
112 written = 0; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
113 retval = WriteFile (write_handle, (LPCVOID) certificates[i], inst_len, &written, NULL); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
114 if (!retval) |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
115 { |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
116 PRINTLASTERROR ("Failed to write certificate\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
117 return false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
118 } |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
119 if (inst_len != written) |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
120 { |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
121 ERRORPRINTF ("Failed to write everything\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
122 retval = false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
123 return false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
124 } |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
125 written = 0; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
126 retval = WriteFile (write_handle, (LPCVOID) line_end, 2, &written, NULL); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
127 if (!retval) |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
128 { |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
129 PRINTLASTERROR ("Failed to write line end\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
130 return false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
131 } |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
132 if (written != 2) |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
133 { |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
134 ERRORPRINTF ("Failed to write full line end\n"); |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
135 retval = false; |
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
136 return false; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 return true; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
142 /**@brief Get the path to all users default registry hive |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
143 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
144 * Enumerates the keys in #PROFILE_LIST and retuns a |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
145 * strv array with the utf-8 encoded paths to their suggested |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
146 * registry hive location. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
147 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
148 * Users with an SID not starting with S-1-5-21- are ignored |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
149 * as is the current user. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
150 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
151 * Use strv_free to free that array. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
152 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
153 * @returns a newly allocated strv of the paths to the registry hives or NULL |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
154 */ |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
155 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
156 static char** |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
157 locate_other_hives() |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
158 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
159 HKEY profile_list = NULL; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
160 int ret = 0; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
161 DWORD index = 0, |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
162 key_len = 257; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
163 /* According to |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
164 http://msdn.microsoft.com/en-us/library/windows/desktop/ms724872%28v=vs.85%29.aspx |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
165 a registry key is limited to 255 characters. But according to |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
166 http://www.sepago.de/e/holger/2010/07/20/how-long-can-a-registry-key-name-really-be |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
167 the actual limit is 256 + \0 thus we create a buffer for 257 wchar_t's*/ |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
168 wchar_t key_name[257], |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
169 *current_user_sid = NULL; |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
170 char **retval = NULL; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
171 bool error = true; |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
172 PSID current_user = NULL; |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
173 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
174 ret = RegOpenKeyExW (HKEY_LOCAL_MACHINE, PROFILE_LIST, 0, |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
175 KEY_READ, &profile_list); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
176 if (ret != ERROR_SUCCESS) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
177 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
178 ERRORPRINTF ("Failed to open profile list. Error: %i", ret); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
179 return NULL; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
180 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
181 |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
182 |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
183 /* Obtain the current user sid to prevent it from being returned. */ |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
184 current_user = get_process_owner (GetCurrentProcess()); |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
185 |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
186 if (!current_user) |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
187 { |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
188 ERRORPRINTF ("Failed to get the current user."); |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
189 goto done; |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
190 } |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
191 |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
192 if (!ConvertSidToStringSidW (current_user, ¤t_user_sid)) |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
193 { |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
194 PRINTLASTERROR ("Failed to convert sid to string."); |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
195 goto done; |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
196 } |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
197 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
198 while ((ret = RegEnumKeyExW (profile_list, index++, |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
199 key_name, &key_len, |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
200 NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
201 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
202 if (key_len == 257) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
203 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
204 ERRORPRINTF ("Registry key too long."); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
205 goto done; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
206 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
207 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
208 /* Reset key_len to buffer size */ |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
209 key_len = 257; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
210 |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
211 if (wcsncmp (L"S-1-5-21-", key_name, 9) != 0 || |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
212 wcscmp (current_user_sid, key_name) == 0) |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
213 { |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
214 /* S-1-5-21 is the well known prefix for local users. Skip all |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
215 others and the current user*/ |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
216 continue; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
217 } |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
218 |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
219 DEBUGPRINTF ("Key : %S", key_name); |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
220 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
221 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
222 if (ret != ERROR_NO_MORE_ITEMS) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
223 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
224 ERRORPRINTF ("Failed to enumeratre profile list. Error: %i", ret); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
225 goto done; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
226 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
227 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
228 done: |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
229 xfree (current_user); |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
230 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
231 RegCloseKey (profile_list); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
232 |
670
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
233 if (current_user_sid) |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
234 { |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
235 LocalFree (current_user_sid); |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
236 } |
175370634226
Move getProcessOwner to util and use it to skip the current user in locate other hives
Andre Heinecke <andre.heinecke@intevation.de>
parents:
668
diff
changeset
|
237 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
238 if (error) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
239 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
240 strv_free (retval); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
241 retval = NULL; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
242 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
243 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
244 return retval; |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
245 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
246 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
247 /**@brief Register NSS process as runOnce for other users |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
248 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
249 * Loads the registry hives of other users on the system and |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
250 * adds a RunOnce registry key to start the NSS process to |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
251 * install the current selection on their next login. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
252 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
253 * This should avoid conflicts with their firefox / thunderbird |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
254 * while making the certificates available for their applications. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
255 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
256 * This function needs SE_BACKUP_NAME and SE_RESTORE_NAME |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
257 * privileges. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
258 * |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
259 * @param [in] selection_file filename of the file containing |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
260 * the users install / remove selection. |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
261 */ |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
262 void |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
263 register_proccesses_for_others (wchar_t *selection_file) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
264 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
265 char **hives = locate_other_hives(); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
266 |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
267 strv_free (hives); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
268 printf("Selection file %S", selection_file); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
269 } |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
270 |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
271 /**@brief Start the process to install / remove |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
272 * |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
273 * Starts the NSS installation process for the current user |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
274 * |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
275 * @param [in] selection_file filename of the file containing |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
276 * the users install / remove selection. |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
277 * |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
278 * @returns true on success, false on error. |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
279 */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
280 static bool |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
281 start_procces_for_user (wchar_t *selection_file) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
282 { |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
283 HANDLE hToken = NULL;/*, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
284 hChildToken = NULL;*/ |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
285 /* TODO get this as absolute path based on current module location */ |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
286 LPWSTR lpApplicationName = L"mozilla.exe", |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
287 lpCommandLine; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
288 PROCESS_INFORMATION piProcInfo = {0}; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
289 STARTUPINFOW siStartInfo = {0}; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
290 BOOL success = FALSE; |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
291 size_t cmd_line_len = 0; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
292 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
293 if (!selection_file) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
294 { |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
295 ERRORPRINTF ("Invalid call\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
296 return false; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
297 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
298 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
299 /* set up handles. stdin and stdout go to the same stdout*/ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
300 siStartInfo.cb = sizeof (STARTUPINFO); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
301 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
302 if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
303 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
304 PRINTLASTERROR("Failed to get current handle."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
305 return false; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
306 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
307 /* TODO! if (is_elevated()) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
308 restrict token -> hChildToken |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
309 */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
310 |
392
8090a1bc1b5b
Add a space in the command line
Andre Heinecke <andre.heinecke@intevation.de>
parents:
391
diff
changeset
|
311 cmd_line_len = wcslen (lpApplicationName) + wcslen(selection_file) + 2; |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
312 lpCommandLine = xmalloc (cmd_line_len * sizeof(wchar_t)); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
313 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
314 wcscpy_s (lpCommandLine, cmd_line_len, lpApplicationName); |
392
8090a1bc1b5b
Add a space in the command line
Andre Heinecke <andre.heinecke@intevation.de>
parents:
391
diff
changeset
|
315 wcscpy_s (lpCommandLine, cmd_line_len, L" "); |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
316 wcscat_s (lpCommandLine, cmd_line_len, selection_file); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
317 |
392
8090a1bc1b5b
Add a space in the command line
Andre Heinecke <andre.heinecke@intevation.de>
parents:
391
diff
changeset
|
318 DEBUGPRINTF ("Starting %S with command line %S\n", lpApplicationName, lpCommandLine); |
8090a1bc1b5b
Add a space in the command line
Andre Heinecke <andre.heinecke@intevation.de>
parents:
391
diff
changeset
|
319 |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
320 success = CreateProcessAsUserW (hToken, |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
321 lpApplicationName, |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
322 lpCommandLine, /* Commandline */ |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
323 NULL, /* Process attributes. Take hToken */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
324 NULL, /* Thread attribues. Take hToken */ |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
325 FALSE, /* Inherit Handles */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
326 0, /* Creation flags. */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
327 NULL, /* Inherit environment */ |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
328 NULL, /* Current working directory */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
329 &siStartInfo, |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
330 &piProcInfo); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
331 xfree (lpCommandLine); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
332 if (!success) |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
333 { |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
334 PRINTLASTERROR ("Failed to create process.\n"); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
335 return false; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
336 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
337 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
338 if (WaitForSingleObject (piProcInfo.hProcess, PROCESS_TIMEOUT) != WAIT_OBJECT_0) |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
339 { |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
340 /* Should not happen... */ |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
341 ERRORPRINTF ("Failed to wait for process.\n"); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
342 if (piProcInfo.hProcess) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
343 CloseHandle (piProcInfo.hProcess); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
344 if (piProcInfo.hThread) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
345 CloseHandle (piProcInfo.hThread); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
346 return false; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
347 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
348 if (piProcInfo.hProcess) |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
349 CloseHandle (piProcInfo.hProcess); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
350 if (piProcInfo.hThread) |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
329
diff
changeset
|
351 CloseHandle (piProcInfo.hThread); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
352 return true; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
353 } |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
354 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
355 /**@brief Create a directory with restricted access rights |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
356 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
357 * This creates a security attributes structure that restricts |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
358 * write access to the Administrators group but allows everyone to read files |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
359 * in that directory. |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
360 * Basically a very complicated version of mkdir path -m 644 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
361 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
362 * If the directory exists the permissions of that directory are checked if |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
363 * they are acceptable and true or false is returned accordingly. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
364 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
365 * Code based on msdn example: |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
366 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa446595%28v=vs.85%29.aspx |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
367 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
368 * @param[in] path Path of the directory to create |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
369 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
370 * @returns true on success of if the directory exists, false on error |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
371 */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
372 bool |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
373 create_restricted_directory (LPWSTR path) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
374 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
375 bool retval = false; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
376 PSID everyone_SID = NULL, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
377 admin_SID = NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
378 PACL access_control_list = NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
379 PSECURITY_DESCRIPTOR descriptor = NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
380 EXPLICIT_ACCESS explicit_access[2]; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
381 SID_IDENTIFIER_AUTHORITY world_identifier = {SECURITY_WORLD_SID_AUTHORITY}, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
382 admin_identifier = {SECURITY_NT_AUTHORITY}; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
383 SECURITY_ATTRIBUTES security_attributes; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
384 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
385 ZeroMemory(&security_attributes, sizeof(security_attributes)); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
386 ZeroMemory(&explicit_access, 2 * sizeof(EXPLICIT_ACCESS)); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
387 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
388 /* Create a well-known SID for the Everyone group. */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
389 if(!AllocateAndInitializeSid(&world_identifier, /* top-level identifier */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
390 1, /* subauthorties count */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
391 SECURITY_WORLD_RID, /* Only one authority */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
392 0, 0, 0, 0, 0, 0, 0, /* No other authorities*/ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
393 &everyone_SID)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
394 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
395 PRINTLASTERROR ("Failed to allocate world sid.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
396 return false; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
397 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
398 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
399 /* Initialize the first EXPLICIT_ACCESS structure for an ACE. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
400 to allow everyone read access */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
401 explicit_access[0].grfAccessPermissions = GENERIC_READ; /* Give read access */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
402 explicit_access[0].grfAccessMode = SET_ACCESS; /* Overwrite other access for all users */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
403 explicit_access[0].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; /* make it stick */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
404 explicit_access[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
405 explicit_access[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
406 explicit_access[0].Trustee.ptstrName = (LPTSTR) everyone_SID; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
407 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
408 /* Create the SID for the BUILTIN\Administrators group. */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
409 if(!AllocateAndInitializeSid(&admin_identifier, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
410 2, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
411 SECURITY_BUILTIN_DOMAIN_RID, /*BUILTIN\ */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
412 DOMAIN_ALIAS_RID_ADMINS, /*\Administrators */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
413 0, 0, 0, 0, 0, 0, /* No other */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
414 &admin_SID)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
415 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
416 PRINTLASTERROR ("Failed to allocate admin sid."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
417 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
418 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
419 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
420 /* explicit_access[1] grants admins full rights for this object and inherits |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
421 it to the children */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
422 explicit_access[1].grfAccessPermissions = GENERIC_ALL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
423 explicit_access[1].grfAccessMode = SET_ACCESS; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
424 explicit_access[1].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
425 explicit_access[1].Trustee.TrusteeForm = TRUSTEE_IS_SID; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
426 explicit_access[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
427 explicit_access[1].Trustee.ptstrName = (LPTSTR) admin_SID; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
428 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
429 /* Set up the ACL structure. */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
430 if (ERROR_SUCCESS != SetEntriesInAcl(2, explicit_access, NULL, &access_control_list)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
431 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
432 PRINTLASTERROR ("Failed to set up Acl."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
433 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
434 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
435 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
436 /* Initialize a security descriptor */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
437 descriptor = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
438 SECURITY_DESCRIPTOR_MIN_LENGTH); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
439 if (descriptor == NULL) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
440 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
441 PRINTLASTERROR("Failed to allocate descriptor."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
442 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
443 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
444 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
445 if (!InitializeSecurityDescriptor(descriptor, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
446 SECURITY_DESCRIPTOR_REVISION)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
447 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
448 PRINTLASTERROR("Failed to initialize descriptor."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
449 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
450 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
451 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
452 /* Now we add the ACL to the the descriptor */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
453 if (!SetSecurityDescriptorDacl(descriptor, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
454 TRUE, /* bDaclPresent flag */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
455 access_control_list, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
456 FALSE)) /* not a default DACL */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
457 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
458 PRINTLASTERROR("Failed to set security descriptor."); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
459 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
460 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
461 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
462 /* Finally set up the security attributes structure */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
463 security_attributes.nLength = sizeof (SECURITY_ATTRIBUTES); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
464 security_attributes.lpSecurityDescriptor = descriptor; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
465 security_attributes.bInheritHandle = FALSE; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
466 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
467 /* Use the security attributes to create the directory */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
468 if (!CreateDirectoryW(path, &security_attributes)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
469 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
470 DWORD err = GetLastError(); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
471 if (err == ERROR_ALREADY_EXISTS) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
472 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
473 /* Verify that the directory has the correct rights */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
474 // TODO |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
475 retval = true; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
476 goto done; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
477 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
478 ERRORPRINTF ("Failed to create directory. Err: %lu", err); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
479 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
480 retval = true; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
481 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
482 done: |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
483 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
484 if (everyone_SID) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
485 FreeSid(everyone_SID); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
486 if (admin_SID) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
487 FreeSid(admin_SID); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
488 if (access_control_list) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
489 LocalFree(access_control_list); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
490 if (descriptor) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
491 LocalFree(descriptor); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
492 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
493 return retval; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
494 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
495 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
496 /**@brief Writes the selection file containing the instructions |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
497 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
498 * If the process is running elevated the instructions are |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
499 * written to the global ProgramData directory otherwise |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
500 * they are written in the temporary directory of the current user. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
501 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
502 * If the return value is not NULL it needs to be freed by the caller. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
503 * The returned path will contain backslashes as directory seperators. |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
504 * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
505 * @param[in] to_install Certificates that should be installed |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
506 * @param[in] to_remove Certificates that should be removed |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
507 * @returns pointer to the absolute filename of the selection file or NULL |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
508 */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
509 wchar_t * |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
510 write_selection_file (char **to_install, char **to_remove) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
511 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
512 wchar_t *folder_name = NULL, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
513 *path = NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
514 bool elevated = is_elevated(); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
515 HRESULT result = E_FAIL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
516 HANDLE hFile = NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
517 size_t path_len; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
518 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
519 if (!elevated) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
520 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
521 /* TODO */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
522 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
523 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
524 result = SHGetKnownFolderPath (&FOLDERID_ProgramData, /* Get program data dir */ |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
525 KF_FLAG_CREATE | /* Create if it does not exist */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
526 KF_FLAG_INIT, /* Initialize it if created */ |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
527 INVALID_HANDLE_VALUE, /* Get it for the default user */ |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
528 &folder_name); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
529 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
530 if (result != S_OK) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
531 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
532 PRINTLASTERROR ("Failed to get folder path"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
533 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
534 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
535 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
536 path_len = wcslen (folder_name) + wcslen (APPNAME) + 2; /* path + dirsep + \0 */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
537 path_len += wcslen (SELECTION_FILE_NAME) + 1; /* filename + dirsep */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
538 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
539 if (path_len >= MAX_PATH) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
540 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
541 /* We could go and use the full 32,767 characters but this |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
542 should be a very weird setup if this is neccessary. */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
543 ERRORPRINTF ("Path too long.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
544 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
545 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
546 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
547 path = xmalloc (path_len * sizeof (wchar_t)); |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
548 if (wcscpy_s (path, path_len, folder_name) != 0) |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
549 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
550 ERRORPRINTF ("Failed to copy folder name.\n"); |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
551 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
552 CoTaskMemFree (folder_name); |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
553 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
554 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
555 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
556 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
557 CoTaskMemFree (folder_name); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
558 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
559 if (wcscat_s (path, path_len, L"\\") != 0) |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
560 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
561 ERRORPRINTF ("Failed to cat dirsep.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
562 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
563 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
564 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
565 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
566 if (wcscat_s (path, path_len, APPNAME) != 0) |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
567 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
568 ERRORPRINTF ("Failed to cat appname.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
569 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
570 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
571 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
572 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
573 /* Security: if someone has created this directory before |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
574 it might be a symlink to another place that a users |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
575 wants us to grant read access to or makes us overwrite |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
576 something */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
577 if(!create_restricted_directory (path)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
578 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
579 ERRORPRINTF ("Failed to create directory\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
580 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
581 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
582 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
583 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
584 if (wcscat_s (path, path_len, L"\\") != 0) |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
585 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
586 ERRORPRINTF ("Failed to cat dirsep.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
587 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
588 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
589 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
590 |
363
d10d9bc2e84f
Update Windows api usage. Warning: To build on windows you need
Andre Heinecke <aheinecke@intevation.de>
parents:
360
diff
changeset
|
591 if (wcscat_s (path, path_len, SELECTION_FILE_NAME) != 0) |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
592 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
593 ERRORPRINTF ("Failed to cat filename.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
594 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
595 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
596 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
597 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
598 hFile = CreateFileW(path, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
599 GENERIC_WRITE, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
600 0, /* don't share */ |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
601 NULL, /* use the security attributes from the folder */ |
489
a9da8e4eeff7
Fix instruction writing for Windows.
Andre Heinecke <aheinecke@intevation.de>
parents:
404
diff
changeset
|
602 OPEN_ALWAYS | TRUNCATE_EXISTING, |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
603 0, |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
604 NULL); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
605 |
502
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
606 if (hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND) |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
607 { |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
608 hFile = CreateFileW(path, |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
609 GENERIC_WRITE, |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
610 0, /* don't share */ |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
611 NULL, /* use the security attributes from the folder */ |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
612 CREATE_NEW, |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
613 0, |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
614 NULL); |
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
615 } |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
616 if (hFile == INVALID_HANDLE_VALUE) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
617 { |
502
e551de11d8b6
Properly handle the case that the file does not exist.
Andre Heinecke <aheinecke@intevation.de>
parents:
489
diff
changeset
|
618 PRINTLASTERROR ("Failed to create file\n"); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
619 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
620 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
621 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
622 if (!write_instructions (to_install, hFile, false)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
623 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
624 ERRORPRINTF ("Failed to write install instructions.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
625 CloseHandle(hFile); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
626 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
627 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
628 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
629 if (!write_instructions (to_remove, hFile, true)) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
630 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
631 ERRORPRINTF ("Failed to write remove instructions.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
632 CloseHandle(hFile); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
633 xfree(path); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
634 return NULL; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
635 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
636 CloseHandle(hFile); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
637 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
638 return path; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
639 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
640 |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
641 int |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
642 write_stores_nss (char **to_install, char **to_remove) |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
643 { |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
644 wchar_t *selection_file_name = NULL; |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
645 |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
646 selection_file_name = write_selection_file (to_install, to_remove); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
647 if (!selection_file_name) |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
648 { |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
649 ERRORPRINTF ("Failed to write instructions.\n"); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
650 return -1; |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
651 } |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
652 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
653 DEBUGPRINTF ("Wrote selection file. Loc: %S\n", selection_file_name); |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
654 |
668
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
655 if (is_elevated()) |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
656 { |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
657 register_proccesses_for_others (selection_file_name); |
ef6d3dc9e930
Framework for NSS multiuser installation on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents:
665
diff
changeset
|
658 } |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
659 |
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
660 if (!start_procces_for_user (selection_file_name)) |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
661 { |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
662 ERRORPRINTF ("Failed to run NSS installation process.\n"); |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
663 xfree(selection_file_name); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
664 return -1; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
665 } |
360
c0eac5c8c245
Keep working on nssstore_win and clarify its specification
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
666 xfree(selection_file_name); |
324
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
667 return 0; |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
668 } |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
669 |
eff8e7ce4dae
Add first compiling implementation of nssstore_win.c
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
670 #endif |