comparison cinst/windowsstore.c @ 247:4de97f74d038

Check for process elevation and write into system store accordingly
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 31 Mar 2014 08:02:46 +0000
parents 53ea9b975d1c
children 3595ea4fd3fb
comparison
equal deleted inserted replaced
246:1efe494c3d2b 247:4de97f74d038
183 } 183 }
184 } 184 }
185 return; 185 return;
186 } 186 }
187 187
188 static bool is_elevated() {
189 HANDLE hToken = NULL;
190 bool ret = false;
191 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
192 {
193 TOKEN_ELEVATION elevation;
194 DWORD cbSize = sizeof (TOKEN_ELEVATION);
195 if (GetTokenInformation (hToken, TokenElevation, &elevation,
196 sizeof (TokenElevation), &cbSize))
197 {
198 ret = elevation.TokenIsElevated;
199 }
200 }
201 if (hToken)
202 CloseHandle (hToken);
203
204 return ret;
205 }
206
188 int 207 int
189 write_stores_win (char **to_install, char **to_remove, bool user_store) 208 write_stores_win (char **to_install, char **to_remove)
190 { 209 {
191 HCERTSTORE hStore = NULL; 210 HCERTSTORE hStore = NULL;
192 211
193 if (!to_install && !to_remove) 212 if (!to_install && !to_remove)
194 { 213 {
195 /* Nothing to do */ 214 /* Nothing to do */
196 return 0; 215 return 0;
197 } 216 }
198 217
199 if (user_store) 218 if (!is_elevated())
200 { 219 {
201 hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0, 220 hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0,
202 0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root"); 221 0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
203 } 222 }
204 else 223 else

http://wald.intevation.org/projects/trustbridge/