ReactOS  0.4.13-dev-235-g7373cb3
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,
231  GWLP_USERDATA);
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 
326  case IDC_LOGON_PASSWORD1:
327  case IDC_LOGON_PASSWORD2:
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 }
WCHAR szPassword2[64]
#define IDC_LOGON_PASSWORD2
Definition: resource.h:152
static BOOL OnQueryInitialFocus(HWND hwndDlg, PLOGONDATA pLogonData)
static BOOL OnApply(HWND hwndDlg, PLOGONDATA pLogonData)
#define DEFAULT_PASSWORD
#define TRUE
Definition: types.h:120
LPSTR lpServiceStartName
Definition: winsvc.h:152
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:965
#define IDC_LOGON_SYSTEMACCOUNT
Definition: resource.h:144
LPQUERY_SERVICE_CONFIG pServiceConfig
WCHAR szPassword1[64]
UINT_PTR WPARAM
Definition: windef.h:207
#define PSN_APPLY
Definition: prsht.h:117
ENUM_SERVICE_STATUS_PROCESS * pService
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
WCHAR szAccountName[64]
#define IDC_LOGON_THISACCOUNT
Definition: resource.h:145
#define GWLP_USERDATA
Definition: treelist.c:63
#define LPPROPSHEETPAGE
Definition: prsht.h:372
smooth NULL
Definition: ftsmooth.c:416
#define WM_DESTROY
Definition: winuser.h:1591
#define BM_SETCHECK
Definition: winuser.h:1882
#define IDC_LOGON_HWPROFILE
Definition: resource.h:153
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define BN_CLICKED
Definition: winuser.h:1886
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPWSTR lpServiceName)
Definition: query.c:29
#define WM_COMMAND
Definition: winuser.h:1716
BOOL bAccountChanged
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
static VOID SetControlStates(HWND hwndDlg, PLOGONDATA pLogonData, BOOL bLocalSystem)
HWND WINAPI GetParent(_In_ HWND)
#define IDC_LOGON_ACCOUNTNAME
Definition: resource.h:147
#define IDC_LOGON_PASSWORD1
Definition: resource.h:150
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define BST_CHECKED
Definition: winuser.h:197
#define HIWORD(l)
Definition: typedefs.h:246
#define IDC_LOGON_INTERACTIVE
Definition: resource.h:146
#define GetWindowLongPtr
Definition: treelist.c:73
struct _SERVICEPROPSHEET * PSERVICEPROPSHEET
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define PSN_QUERYINITIALFOCUS
Definition: settings.cpp:98
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define WM_NOTIFY
Definition: richedit.h:61
struct _LOGONDATA * PLOGONDATA
#define EN_CHANGE
Definition: winuser.h:1983

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 IDC_LOGON_PASSWORD2
Definition: resource.h:152
#define DEFAULT_PASSWORD
#define TRUE
Definition: types.h:120
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:965
#define IDC_LOGON_SYSTEMACCOUNT
Definition: resource.h:144
#define IDS_INVALID_PASSWORD
Definition: resource.h:226
LPQUERY_SERVICE_CONFIG pServiceConfig
ENUM_SERVICE_STATUS_PROCESS * pService
#define MB_ICONWARNING
Definition: winuser.h:780
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define BM_GETCHECK
Definition: winuser.h:1879
static BOOL SetServiceAccount(LPWSTR lpServiceName, DWORD dwServiceType, LPWSTR lpStartName, LPWSTR lpPassword)
#define GetDlgItemText
Definition: winuser.h:5651
VOID ResourceMessageBox(HINSTANCE hInstance, HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: misc.c:283
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
BOOL bAccountChanged
#define IDS_APPNAME
Definition: resource.h:49
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define GetModuleHandle
Definition: winbase.h:3641
#define IDC_LOGON_ACCOUNTNAME
Definition: resource.h:147
#define IDC_LOGON_PASSWORD1
Definition: resource.h:150
#define MB_OK
Definition: winuser.h:784
#define BST_CHECKED
Definition: winuser.h:197
#define IDC_LOGON_INTERACTIVE
Definition: resource.h:146
#define IDS_NOT_SAME_PASSWORD
Definition: resource.h:225

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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
#define IDC_LOGON_SYSTEMACCOUNT
Definition: resource.h:144
#define SetWindowLongPtr
Definition: treelist.c:70
#define DWLP_MSGRESULT
Definition: winuser.h:864
#define IDC_LOGON_THISACCOUNT
Definition: resource.h:145
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)

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 
66  SetDlgItemText(hwndDlg, IDC_LOGON_ACCOUNTNAME, pLogonData->szAccountName);
67  SetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD1, pLogonData->szPassword1);
68  SetDlgItemText(hwndDlg, IDC_LOGON_PASSWORD2, pLogonData->szPassword2);
69  }
70 
71  pLogonData->bLocalSystem = bLocalSystem;
72 }
WCHAR szPassword2[64]
#define IDC_LOGON_PASSWORD2
Definition: resource.h:152
#define TRUE
Definition: types.h:120
#define IDC_LOGON_PW1TEXT
Definition: resource.h:149
WCHAR szPassword1[64]
UINT_PTR WPARAM
Definition: windef.h:207
WCHAR szAccountName[64]
#define BM_GETCHECK
Definition: winuser.h:1879
#define BM_SETCHECK
Definition: winuser.h:1882
#define GetDlgItemText
Definition: winuser.h:5651
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define SetDlgItemText
Definition: winuser.h:5715
static const WCHAR L[]
Definition: oid.c:1250
#define BST_UNCHECKED
Definition: winuser.h:199
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define IDC_LOGON_ACCOUNTNAME
Definition: resource.h:147
#define IDC_LOGON_PASSWORD1
Definition: resource.h:150
#define IDC_LOGON_INTERACTIVE
Definition: resource.h:146
#define IDC_LOGON_PW2TEXT
Definition: resource.h:151
#define IDC_LOGON_SEARCH
Definition: resource.h:148

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 
116  CloseServiceHandle(hSc);
117  }
118 
119  UnlockServiceDatabase(scLock);
120  }
121 
123  }
124 
125  if (!bRet)
126  GetError();
127 
128  return bRet;
129 }
#define TRUE
Definition: types.h:120
BOOL WINAPI UnlockServiceDatabase(SC_LOCK ScLock)
Definition: scm.c:2961
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
VOID GetError(VOID)
Definition: misc.c:192
unsigned int BOOL
Definition: ntddk_ex.h:94
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:480
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
#define SC_MANAGER_LOCK
Definition: winsvc.h:17
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
SC_HANDLE hSCManager
Definition: sc.c:12
SC_LOCK WINAPI LockServiceDatabase(SC_HANDLE hSCManager)
Definition: scm.c:1901

Referenced by OnApply().