ReactOS 0.4.15-dev-7942-gd23573b
propsheet_logon.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for propsheet_logon.c:

Go to the source code of this file.

Classes

struct  _LOGONDATA
 

Macros

#define NDEBUG
 
#define DEFAULT_PASSWORD   L" "
 

Typedefs

typedef struct _LOGONDATA LOGONDATA
 
typedef struct _LOGONDATAPLOGONDATA
 

Functions

static VOID SetControlStates (HWND hwndDlg, PLOGONDATA pLogonData, BOOL bLocalSystem)
 
static BOOL SetServiceAccount (LPWSTR lpServiceName, DWORD dwServiceType, LPWSTR lpStartName, LPWSTR lpPassword)
 
static BOOL OnQueryInitialFocus (HWND hwndDlg, PLOGONDATA pLogonData)
 
static BOOL OnApply (HWND hwndDlg, PLOGONDATA pLogonData)
 
INT_PTR CALLBACK LogonPageProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Macro Definition Documentation

◆ DEFAULT_PASSWORD

#define DEFAULT_PASSWORD   L" "

Definition at line 14 of file propsheet_logon.c.

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file propsheet_logon.c.

Typedef Documentation

◆ LOGONDATA

◆ PLOGONDATA

Function Documentation

◆ LogonPageProc()

INT_PTR CALLBACK LogonPageProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 221 of file propsheet_logon.c.

226{
227 PLOGONDATA pLogonData;
228
229 /* Get the window context */
230 pLogonData = (PLOGONDATA)GetWindowLongPtr(hwndDlg,
232 if (pLogonData == NULL && uMsg != WM_INITDIALOG)
233 {
234 return FALSE;
235 }
236
237 switch (uMsg)
238 {
239 case WM_INITDIALOG:
240 pLogonData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGONDATA));
241 if (pLogonData != NULL)
242 {
243 SetWindowLongPtr(hwndDlg,
245 (LONG_PTR)pLogonData);
246
247 pLogonData->bInitialized = FALSE;
248 pLogonData->pService = ((PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam))->pService;
249
250 pLogonData->pServiceConfig = GetServiceConfig(pLogonData->pService->lpServiceName);
251 if (pLogonData->pServiceConfig != NULL)
252 {
253 wcscpy(pLogonData->szPassword1, DEFAULT_PASSWORD);
254 wcscpy(pLogonData->szPassword2, DEFAULT_PASSWORD);
255
256 if (pLogonData->pServiceConfig->lpServiceStartName == NULL ||
257 _wcsicmp(pLogonData->pServiceConfig->lpServiceStartName, L"LocalSystem") == 0)
258 {
261 pLogonData->nInteractive = BST_CHECKED;
263 }
264 SetControlStates(hwndDlg, pLogonData, TRUE);
265 }
266 else
267 {
268 wcscpy(pLogonData->szAccountName, pLogonData->pServiceConfig->lpServiceStartName);
270 SetControlStates(hwndDlg, pLogonData, FALSE);
271 }
272 }
273
274 pLogonData->bInitialized = TRUE;
275 }
276
278 break;
279
280 case WM_DESTROY:
281 if (pLogonData->pServiceConfig)
282 HeapFree(GetProcessHeap(), 0, pLogonData->pServiceConfig);
283
284 HeapFree(GetProcessHeap(), 0, pLogonData);
285 break;
286
287 case WM_COMMAND:
288 switch(LOWORD(wParam))
289 {
291 if (HIWORD(wParam) == BN_CLICKED)
292 {
293 if (pLogonData->bInitialized)
294 {
295 pLogonData->bAccountChanged = TRUE;
296 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
297 }
298 SetControlStates(hwndDlg, pLogonData, TRUE);
299 }
300 break;
301
303 if (HIWORD(wParam) == BN_CLICKED)
304 {
305 if (pLogonData->bInitialized)
306 {
307 pLogonData->bAccountChanged = TRUE;
308 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
309 }
310 SetControlStates(hwndDlg, pLogonData, FALSE);
311 }
312 break;
313
315 if (HIWORD(wParam) == BN_CLICKED)
316 {
317 if (pLogonData->bInitialized)
318 {
319 pLogonData->bAccountChanged = TRUE;
320 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
321 }
322 }
323 break;
324
328 if (HIWORD(wParam) == EN_CHANGE && pLogonData->bInitialized)
329 {
330 pLogonData->bAccountChanged = TRUE;
331 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
332 }
333 break;
334 }
335 break;
336
337 case WM_NOTIFY:
338 switch (((LPNMHDR)lParam)->code)
339 {
341 return OnQueryInitialFocus(hwndDlg, pLogonData);
342
343 case PSN_APPLY:
344 return OnApply(hwndDlg, pLogonData);
345 }
346 break;
347 }
348
349 return FALSE;
350}
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPWSTR lpServiceName)
Definition: query.c:29
struct _SERVICEPROPSHEET * PSERVICEPROPSHEET
#define IDC_LOGON_ACCOUNTNAME
Definition: resource.h:145
#define IDC_LOGON_PASSWORD1
Definition: resource.h:148
#define IDC_LOGON_PASSWORD2
Definition: resource.h:150
#define IDC_LOGON_HWPROFILE
Definition: resource.h:151
#define IDC_LOGON_THISACCOUNT
Definition: resource.h:143
#define IDC_LOGON_SYSTEMACCOUNT
Definition: resource.h:142
#define IDC_LOGON_INTERACTIVE
Definition: resource.h:144
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define PSN_QUERYINITIALFOCUS
Definition: settings.cpp:98
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
static BOOL OnQueryInitialFocus(HWND hwndDlg, PLOGONDATA pLogonData)
struct _LOGONDATA * PLOGONDATA
static BOOL OnApply(HWND hwndDlg, PLOGONDATA pLogonData)
static VOID SetControlStates(HWND hwndDlg, PLOGONDATA pLogonData, BOOL bLocalSystem)
#define DEFAULT_PASSWORD
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define LPPROPSHEETPAGE
Definition: prsht.h:390
#define WM_NOTIFY
Definition: richedit.h:61
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
LPQUERY_SERVICE_CONFIG pServiceConfig
BOOL bAccountChanged
WCHAR szAccountName[64]
WCHAR szPassword1[64]
ENUM_SERVICE_STATUS_PROCESS * pService
WCHAR szPassword2[64]
LPSTR lpServiceStartName
Definition: winsvc.h:152
Definition: inflate.c:139
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
#define HIWORD(l)
Definition: typedefs.h:247
UINT_PTR WPARAM
Definition: windef.h:207
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BM_SETCHECK
Definition: winuser.h:1921
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
#define BN_CLICKED
Definition: winuser.h:1925
#define WM_DESTROY
Definition: winuser.h:1609
#define BST_CHECKED
Definition: winuser.h:197
#define EN_CHANGE
Definition: winuser.h:2022
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:967

Referenced by PropSheetThread().

◆ OnApply()

static BOOL OnApply ( HWND  hwndDlg,
PLOGONDATA  pLogonData 
)
static

Definition at line 148 of file propsheet_logon.c.

151{
152 WCHAR szAccountName[64];
153 WCHAR szPassword1[64];
154 WCHAR szPassword2[64];
155 DWORD dwServiceType = SERVICE_NO_CHANGE;
156 BOOL bRet = TRUE;
157
158 if (!pLogonData->bAccountChanged)
159 return TRUE;
160
162 {
163 /* System account selected */
164 wcscpy(szAccountName, L"LocalSystem");
165 wcscpy(szPassword1, L"");
166 wcscpy(szPassword2, L"");
167
168 /* Handle the interactive flag */
169 dwServiceType = pLogonData->pServiceConfig->dwServiceType;
171 dwServiceType |= SERVICE_INTERACTIVE_PROCESS;
172 else
173 dwServiceType &= ~SERVICE_INTERACTIVE_PROCESS;
174 }
175 else
176 {
177 /* Other account selected */
178 GetDlgItemText(hwndDlg, IDC_LOGON_ACCOUNTNAME, szAccountName, 64);
179 GetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD1, szPassword1, 64);
180 GetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD2, szPassword2, 64);
181
182 if (wcscmp(szPassword1, szPassword2))
183 {
185 return FALSE;
186 }
187
188 if (!wcscmp(szPassword1, DEFAULT_PASSWORD))
189 {
191 return FALSE;
192 }
193 }
194
195
196 bRet = SetServiceAccount(pLogonData->pService->lpServiceName,
197 dwServiceType,
198 szAccountName,
199 szPassword1);
200 if (bRet == FALSE)
201 {
202
203 }
204
205 if (bRet == TRUE)
206 {
207 pLogonData->bAccountChanged = FALSE;
208
209 }
210
211 return bRet;
212}
#define IDS_APPNAME
Definition: resource.h:49
VOID ResourceMessageBox(HINSTANCE hInstance, HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: misc.c:282
#define IDS_NOT_SAME_PASSWORD
Definition: resource.h:223
#define IDS_INVALID_PASSWORD
Definition: resource.h:224
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL SetServiceAccount(LPWSTR lpServiceName, DWORD dwServiceType, LPWSTR lpStartName, LPWSTR lpPassword)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define GetModuleHandle
Definition: winbase.h:3827
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
#define GetDlgItemText
Definition: winuser.h:5785
#define MB_OK
Definition: winuser.h:790
#define MB_ICONWARNING
Definition: winuser.h:786
#define BM_GETCHECK
Definition: winuser.h:1918
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LogonPageProc().

◆ OnQueryInitialFocus()

static BOOL OnQueryInitialFocus ( HWND  hwndDlg,
PLOGONDATA  pLogonData 
)
static

Definition at line 134 of file propsheet_logon.c.

137{
139
141
142 return TRUE;
143}
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define DWLP_MSGRESULT
Definition: winuser.h:870

Referenced by LogonPageProc().

◆ SetControlStates()

static VOID SetControlStates ( HWND  hwndDlg,
PLOGONDATA  pLogonData,
BOOL  bLocalSystem 
)
static

bLocalSystem

Definition at line 32 of file propsheet_logon.c.

36{
37 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_INTERACTIVE), bLocalSystem);
38 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_ACCOUNTNAME), !bLocalSystem);
40 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_PW1TEXT), !bLocalSystem);
41 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_PASSWORD1), !bLocalSystem);
42 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_PW2TEXT), !bLocalSystem);
43 EnableWindow(GetDlgItem(hwndDlg, IDC_LOGON_PASSWORD2), !bLocalSystem);
44
45 if (bLocalSystem)
46 {
48
49 if (pLogonData->bInitialized == TRUE)
50 {
51 GetDlgItemText(hwndDlg, IDC_LOGON_ACCOUNTNAME, pLogonData->szAccountName, 64);
52 GetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD1, pLogonData->szPassword1, 64);
53 GetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD2, pLogonData->szPassword2, 64);
54 }
55
59 }
60 else
61 {
62 if (pLogonData->bInitialized == TRUE)
65
67 SetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD1, pLogonData->szPassword1);
68 SetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD2, pLogonData->szPassword2);
69 }
70
71 pLogonData->bLocalSystem = bLocalSystem;
72}
#define IDC_LOGON_PW1TEXT
Definition: resource.h:147
#define IDC_LOGON_SEARCH
Definition: resource.h:146
#define IDC_LOGON_PW2TEXT
Definition: resource.h:149
#define BST_UNCHECKED
Definition: winuser.h:199
#define SetDlgItemText
Definition: winuser.h:5849

Referenced by LogonPageProc().

◆ SetServiceAccount()

static BOOL SetServiceAccount ( LPWSTR  lpServiceName,
DWORD  dwServiceType,
LPWSTR  lpStartName,
LPWSTR  lpPassword 
)
static

Definition at line 77 of file propsheet_logon.c.

82{
83 SC_HANDLE hSCManager;
84 SC_HANDLE hSc;
85 SC_LOCK scLock;
86 BOOL bRet = FALSE;
87
89 NULL,
91 if (hSCManager)
92 {
94 if (scLock)
95 {
97 lpServiceName,
99 if (hSc)
100 {
101 if (ChangeServiceConfigW(hSc,
102 dwServiceType,
105 NULL,
106 NULL,
107 NULL,
108 NULL,
109 lpStartName,
110 lpPassword,
111 NULL))
112 {
113 bRet = TRUE;
114 }
115
117 }
118
119 UnlockServiceDatabase(scLock);
120 }
121
123 }
124
125 if (!bRet)
126 GetError();
127
128 return bRet;
129}
VOID GetError(VOID)
Definition: misc.c:192
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
BOOL WINAPI UnlockServiceDatabase(SC_LOCK ScLock)
Definition: scm.c:3018
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI ChangeServiceConfigW(SC_HANDLE hService, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword, LPCWSTR lpDisplayName)
Definition: scm.c:482
SC_LOCK WINAPI LockServiceDatabase(SC_HANDLE hSCManager)
Definition: scm.c:1958
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define SC_MANAGER_LOCK
Definition: winsvc.h:17
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54

Referenced by OnApply().