advpack: Add a stub for SetPerUserSecValues.
[wine.git] / dlls / advpack / advpack.c
blob1214901cd49e1e1271a18a5d717d50ef07b55fab
1 /*
2 * Advpack main
4 * Copyright 2004 Huw D M Davies
5 * Copyright 2005 Sami Aario
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "winver.h"
29 #include "winnls.h"
30 #include "setupapi.h"
31 #include "advpub.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
37 typedef HRESULT (WINAPI *DLLREGISTER) (void);
39 /***********************************************************************
40 * CloseINFEngine (ADVPACK.@)
43 * PARAMS
44 * hInf [I]
46 * RETURNS
47 * Success: S_OK.
48 * Failure: E_FAIL.
50 * BUGS
51 * Unimplemented.
53 HRESULT WINAPI CloseINFEngine(HINF hInf)
55 FIXME("(%p) stub\n", hInf);
57 return E_FAIL;
60 /***********************************************************************
61 * DllMain (ADVPACK.@)
63 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
65 TRACE("(%p, %ld, %p)\n",hinstDLL, fdwReason, lpvReserved);
67 if (fdwReason == DLL_PROCESS_ATTACH)
68 DisableThreadLibraryCalls(hinstDLL);
70 return TRUE;
73 /***********************************************************************
74 * RunSetupCommand (ADVPACK.@)
76 * Executes an install section in an INF file or a program.
78 * PARAMS
79 * hWnd [I] Handle to parent window, NULL for quiet mode
80 * szCmdName [I] Inf or EXE filename to execute
81 * szInfSection [I] Inf section to install, NULL for DefaultInstall
82 * szDir [I] Path to extracted files
83 * szTitle [I] Title of all dialogs
84 * phEXE [O] Handle of EXE to wait for
85 * dwFlags [I] Flags; see include/advpub.h
86 * pvReserved [I] Reserved
88 * RETURNS
89 * S_OK Everything OK
90 * S_ASYNCHRONOUS OK, required to wait on phEXE
91 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
92 * E_INVALIDARG Invalid argument given
93 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
94 * Not supported on this Windows version
95 * E_UNEXPECTED Unexpected error
96 * HRESULT_FROM_WIN32(GetLastError()) Some other error
98 * BUGS
99 * Unimplemented
101 HRESULT WINAPI RunSetupCommand( HWND hWnd, LPCSTR szCmdName,
102 LPCSTR szInfSection, LPCSTR szDir,
103 LPCSTR lpszTitle, HANDLE *phEXE,
104 DWORD dwFlags, LPVOID pvReserved )
106 FIXME("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p): stub\n",
107 hWnd, debugstr_a(szCmdName), debugstr_a(szInfSection),
108 debugstr_a(szDir), debugstr_a(lpszTitle),
109 phEXE, dwFlags, pvReserved);
110 return E_UNEXPECTED;
113 /***********************************************************************
114 * LaunchINFSection (ADVPACK.@)
116 * Installs an INF section without BACKUP/ROLLBACK capabilities.
118 * PARAMS
119 * hWnd [I] Handle to parent window, NULL for desktop.
120 * hInst [I] Instance of the process.
121 * cmdline [I] Contains parameters in the order INF,section,flags.
122 * show [I] Reboot behaviour:
123 * 'A' reboot always
124 * 'I' default, reboot if needed
125 * 'N' no reboot
127 * RETURNS
128 * Success: S_OK.
129 * Failure: S_FALSE
131 * BUGS
132 * Unimplemented.
134 INT WINAPI LaunchINFSection( HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show )
136 FIXME("(%p %p %s %d): stub\n", hWnd, hInst, debugstr_a(cmdline), show );
137 return 0;
140 /***********************************************************************
141 * LaunchINFSectionEx (ADVPACK.@)
143 * Installs an INF section with BACKUP/ROLLBACK capabilities.
145 * PARAMS
146 * hWnd [I] Handle to parent window, NULL for desktop.
147 * hInst [I] Instance of the process.
148 * cmdline [I] Contains parameters in the order INF,section,CAB,flags.
149 * show [I] Reboot behaviour:
150 * 'A' reboot always
151 * 'I' default, reboot if needed
152 * 'N' no reboot
154 * RETURNS
155 * Success: S_OK.
156 * Failure: E_FAIL.
158 * BUGS
159 * Unimplemented.
161 HRESULT WINAPI LaunchINFSectionEx( HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show )
163 FIXME("(%p %p %s %d): stub\n", hWnd, hInst, debugstr_a(cmdline), show );
164 return E_FAIL;
167 /* this structure very closely resembles parameters of RunSetupCommand() */
168 typedef struct
170 HWND hwnd;
171 LPCSTR title;
172 LPCSTR inf_name;
173 LPCSTR dir;
174 LPCSTR section_name;
175 } SETUPCOMMAND_PARAMS;
177 /***********************************************************************
178 * DoInfInstall (ADVPACK.@)
180 * Install an INF section.
182 * PARAMS
183 * setup [I] Structure containing install information.
185 * RETURNS
186 * S_OK Everything OK
187 * HRESULT_FROM_WIN32(GetLastError()) Some other error
189 HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
191 BOOL ret;
192 HINF hinf;
193 void *callback_context;
195 TRACE("%p %s %s %s %s\n", setup->hwnd, debugstr_a(setup->title),
196 debugstr_a(setup->inf_name), debugstr_a(setup->dir),
197 debugstr_a(setup->section_name));
199 hinf = SetupOpenInfFileA(setup->inf_name, NULL, INF_STYLE_WIN4, NULL);
200 if (hinf == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
202 callback_context = SetupInitDefaultQueueCallback(setup->hwnd);
204 ret = SetupInstallFromInfSectionA(NULL, hinf, setup->section_name, SPINST_ALL,
205 NULL, NULL, 0, SetupDefaultQueueCallbackA,
206 callback_context, NULL, NULL);
207 SetupTermDefaultQueueCallback(callback_context);
208 SetupCloseInfFile(hinf);
210 return ret ? S_OK : HRESULT_FROM_WIN32(GetLastError());
213 /***********************************************************************
214 * IsNTAdmin (ADVPACK.@)
216 * Checks if the user has admin privileges.
218 * PARAMS
219 * reserved [I] Reserved. Must be 0.
220 * pReserved [I] Reserved. Must be NULL.
222 * RETURNS
223 * TRUE if user has admin rights, FALSE otherwise.
225 BOOL WINAPI IsNTAdmin( DWORD reserved, LPDWORD pReserved )
227 SID_IDENTIFIER_AUTHORITY SidAuthority = {SECURITY_NT_AUTHORITY};
228 PTOKEN_GROUPS pTokenGroups;
229 BOOL bSidFound = FALSE;
230 DWORD dwSize, i;
231 HANDLE hToken;
232 PSID pSid;
234 TRACE("(0x%08lx, %p)\n", reserved, pReserved);
236 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
237 return FALSE;
239 if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
241 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
243 CloseHandle(hToken);
244 return FALSE;
248 pTokenGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
249 if (!pTokenGroups)
251 CloseHandle(hToken);
252 return FALSE;
255 if (!GetTokenInformation(hToken, TokenGroups, pTokenGroups, dwSize, &dwSize))
257 HeapFree(GetProcessHeap(), 0, pTokenGroups);
258 CloseHandle(hToken);
259 return FALSE;
262 CloseHandle(hToken);
264 if (!AllocateAndInitializeSid(&SidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
265 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSid))
267 HeapFree(GetProcessHeap(), 0, pTokenGroups);
268 return FALSE;
271 for (i = 0; i < pTokenGroups->GroupCount; i++)
273 if (EqualSid(pSid, pTokenGroups->Groups[i].Sid))
275 bSidFound = TRUE;
276 break;
280 HeapFree(GetProcessHeap(), 0, pTokenGroups);
281 FreeSid(pSid);
283 return bSidFound;
286 /***********************************************************************
287 * NeedRebootInit (ADVPACK.@)
289 * Sets up conditions for reboot checking.
291 * RETURNS
292 * Value required by NeedReboot.
294 DWORD WINAPI NeedRebootInit(VOID)
296 FIXME("(): stub\n");
297 return 0;
300 /***********************************************************************
301 * NeedReboot (ADVPACK.@)
303 * Determines whether a reboot is required.
305 * PARAMS
306 * dwRebootCheck [I] Value from NeedRebootInit.
308 * RETURNS
309 * TRUE if a reboot is needed, FALSE otherwise.
311 * BUGS
312 * Unimplemented.
314 BOOL WINAPI NeedReboot(DWORD dwRebootCheck)
316 FIXME("(0x%08lx): stub\n", dwRebootCheck);
317 return FALSE;
320 /***********************************************************************
321 * OpenINFEngine (ADVPACK.@)
323 * Opens and returns a handle to an INF file to be used by
324 * TranslateInfStringEx to continuously translate the INF file.
326 * PARAMS
327 * pszInfFilename [I] Filename of the INF to open.
328 * pszInstallSection [I] Name of the Install section in the INF.
329 * dwFlags [I] See advpub.h.
330 * phInf [O] Handle to the loaded INF file.
331 * pvReserved [I] Reserved. Must be NULL.
333 * RETURNS
334 * Success: S_OK.
335 * Failure: E_FAIL.
337 * BUGS
338 * Unimplemented.
340 HRESULT WINAPI OpenINFEngine(PCSTR pszInfFilename, PCSTR pszInstallSection,
341 DWORD dwFlags, HINF *phInf, PVOID pvReserved)
343 FIXME("(%p, %p, %ld, %p, %p) stub\n", pszInfFilename, pszInstallSection,
344 dwFlags, phInf, pvReserved);
346 return E_FAIL;
349 /***********************************************************************
350 * RegisterOCX (ADVPACK.@)
352 void WINAPI RegisterOCX( HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show )
354 WCHAR wszBuff[MAX_PATH];
355 WCHAR* pwcComma;
356 HMODULE hm;
357 DLLREGISTER pfnRegister;
358 HRESULT hr;
360 TRACE("(%s)\n", cmdline);
362 MultiByteToWideChar(CP_ACP, 0, cmdline, strlen(cmdline), wszBuff, MAX_PATH);
363 if ((pwcComma = strchrW( wszBuff, ',' ))) *pwcComma = 0;
365 TRACE("Parsed DLL name (%s)\n", debugstr_w(wszBuff));
367 hm = LoadLibraryExW(wszBuff, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
368 if (!hm)
370 ERR("Couldn't load DLL: %s\n", debugstr_w(wszBuff));
371 return;
374 pfnRegister = (DLLREGISTER)GetProcAddress(hm, "DllRegisterServer");
375 if (pfnRegister == NULL)
377 ERR("DllRegisterServer entry point not found\n");
379 else
381 hr = pfnRegister();
382 if (hr != S_OK)
384 ERR("DllRegisterServer entry point returned %08lx\n", hr);
388 TRACE("Successfully registered OCX\n");
390 FreeLibrary(hm);
393 /***********************************************************************
394 * ExecuteCab (ADVPACK.@)
396 * Installs the INF file extracted from a specified cabinet file.
398 * PARAMS
399 * hwnd [I] Handle to the window used for the display.
400 * pCab [I] Information about the cabinet file.
401 * pReserved [I] Reserved. Must be NULL.
403 * RETURNS
404 * Success: S_OK.
405 * Failure: E_FAIL.
407 * BUGS
408 * Unimplemented
410 HRESULT WINAPI ExecuteCab( HWND hwnd, PCABINFO pCab, LPVOID pReserved )
412 FIXME("(%p %p %p): stub\n", hwnd, pCab, pReserved);
413 return E_FAIL;
416 /***********************************************************************
417 * SetPerUserSecValues (ADVPACK.@)
419 * Prepares the per-user stub values under IsInstalled\{GUID} that
420 * control the per-user installation.
422 * PARAMS
423 * pPerUser [I] Per-user stub values.
425 * RETURNS
426 * Success: S_OK.
427 * Failure: E_FAIL.
429 * BUGS
430 * Unimplemented.
432 HRESULT WINAPI SetPerUserSecValues(PPERUSERSECTION pPerUser)
434 FIXME("(%p) stub\n", pPerUser);
436 return E_FAIL;
439 /***********************************************************************
440 * TranslateInfString (ADVPACK.@)
442 * Translates the value of a specified key in an inf file into the
443 * current locale by expanding string macros.
445 * PARAMS
446 * pszInfFilename [I] Filename of the inf file.
447 * pszInstallSection [I]
448 * pszTranslateSection [I] Inf section where the key exists.
449 * pszTranslateKey [I] Key to translate.
450 * pszBuffer [O] Contains the translated string on exit.
451 * dwBufferSize [I] Size on input of pszBuffer.
452 * pdwRequiredSize [O] Length of the translated key.
453 * pvReserved [I] Reserved, must be NULL.
455 * RETURNS
456 * Success: S_OK.
457 * Failure: An hresult error code.
459 HRESULT WINAPI TranslateInfString(PCSTR pszInfFilename, PCSTR pszInstallSection,
460 PCSTR pszTranslateSection, PCSTR pszTranslateKey, PSTR pszBuffer,
461 DWORD dwBufferSize, PDWORD pdwRequiredSize, PVOID pvReserved)
463 HINF hInf;
465 TRACE("(%s %s %s %s %p %ld %p %p)\n",
466 debugstr_a(pszInfFilename), debugstr_a(pszInstallSection),
467 debugstr_a(pszTranslateSection), debugstr_a(pszTranslateKey),
468 pszBuffer, dwBufferSize,pdwRequiredSize, pvReserved);
470 if (!pszInfFilename || !pszTranslateSection ||
471 !pszTranslateKey || !pdwRequiredSize)
472 return E_INVALIDARG;
474 hInf = SetupOpenInfFileA(pszInfFilename, NULL, INF_STYLE_WIN4, NULL);
475 if (hInf == INVALID_HANDLE_VALUE)
476 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
478 if (!SetupGetLineTextA(NULL, hInf, pszTranslateSection, pszTranslateKey,
479 pszBuffer, dwBufferSize, pdwRequiredSize))
481 if (dwBufferSize < *pdwRequiredSize)
482 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
484 return SPAPI_E_LINE_NOT_FOUND;
487 return S_OK;
490 /***********************************************************************
491 * TranslateInfStringEx (ADVPACK.@)
493 * Using a handle to an INF file opened with OpenINFEngine, translates
494 * the value of a specified key in an inf file into the current locale
495 * by expanding string macros.
497 * PARAMS
498 * hInf [I] Handle to the INF file.
499 * pszInfFilename [I] Filename of the INF file.
500 * pszTranslateSection [I] Inf section where the key exists.
501 * pszTranslateKey [I] Key to translate.
502 * pszBuffer [O] Contains the translated string on exit.
503 * dwBufferSize [I] Size on input of pszBuffer.
504 * pdwRequiredSize [O] Length of the translated key.
505 * pvReserved [I] Reserved. Must be NULL.
507 * RETURNS
508 * Success: S_OK.
509 * Failure: E_FAIL.
511 * NOTES
512 * To use TranslateInfStringEx to translate an INF file continuously,
513 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
514 * many times as needed, then release the handle with CloseINFEngine.
515 * When translating more than one keys, this method is more efficient
516 * than calling TranslateInfString, because the INF file is only
517 * opened once.
519 * BUGS
520 * Unimplemented.
522 HRESULT WINAPI TranslateInfStringEx(HINF hInf, PCSTR pszInfFilename,
523 PCSTR pszTranslateSection, PCSTR pszTranslateKey,
524 PSTR pszBuffer, DWORD dwBufferSize,
525 PDWORD pdwRequiredSize, PVOID pvReserved)
527 FIXME("(%p, %p, %p, %p, %p, %ld, %p, %p) stub\n", hInf, pszInfFilename,
528 pszTranslateSection, pszTranslateKey, pszBuffer, dwBufferSize,
529 pdwRequiredSize, pvReserved);
531 return E_FAIL;
534 /***********************************************************************
535 * UserInstStubWrapper (ADVPACK.@)
537 HRESULT WINAPI UserInstStubWrapper(HWND hWnd, HINSTANCE hInstance,
538 PSTR pszParms, INT nShow)
540 FIXME("(%p, %p, %p, %i) stub\n", hWnd, hInstance, pszParms, nShow);
542 return E_FAIL;
545 /***********************************************************************
546 * UserUnInstStubWrapper (ADVPACK.@)
548 HRESULT WINAPI UserUnInstStubWrapper(HWND hWnd, HINSTANCE hInstance,
549 PSTR pszParms, INT nShow)
551 FIXME("(%p, %p, %p, %i) stub\n", hWnd, hInstance, pszParms, nShow);
553 return E_FAIL;