ReactOS  0.4.12-dev-51-ge94618b
propsheet_logon.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Services
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/applications/mscutils/servman/propsheet_logon.c
5  * PURPOSE: Logon property page
6  * COPYRIGHT: Eric Kohl
7  */
8 
9 #include "precomp.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 #define DEFAULT_PASSWORD L" "
15 
16 typedef struct _LOGONDATA
17 {
28 
29 
30 static
31 VOID
33  HWND hwndDlg,
34  PLOGONDATA pLogonData,
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 }
73 
74 
75 static
76 BOOL
78  LPWSTR lpServiceName,
79  DWORD dwServiceType,
80  LPWSTR lpStartName,
81  LPWSTR lpPassword)
82 {
83  SC_HANDLE hSCManager;
84  SC_HANDLE hSc;
85  SC_LOCK scLock;
86  BOOL bRet = FALSE;
87 
88  hSCManager = OpenSCManagerW(NULL,
89  NULL,
91  if (hSCManager)
92  {
93  scLock = LockServiceDatabase(hSCManager);
94  if (scLock)
95  {
96  hSc = OpenServiceW(hSCManager,
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 
122  CloseServiceHandle(hSCManager);
123  }
124 
125  if (!bRet)
126  GetError();
127 
128  return bRet;
129 }
130 
131 
132 static
133 BOOL
135  HWND hwndDlg,
136  PLOGONDATA pLogonData)
137 {
139 
140  SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LPARAM)hwnd);
141 
142  return TRUE;
143 }
144 
145 
146 static
147 BOOL
149  HWND hwndDlg,
150  PLOGONDATA pLogonData)
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 }
213 
214 
215 /*
216  * Logon Property dialog callback.
217  * Controls messages to the Logon dialog
218  */
219 INT_PTR
220 CALLBACK
222  HWND hwndDlg,
223  UINT uMsg,
224  WPARAM wParam,
225  LPARAM lParam)
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  {
260  if (pLogonData->pServiceConfig->dwServiceType & SERVICE_INTERACTIVE_PROCESS) {
261  pLogonData->nInteractive = BST_CHECKED;
262  SendDlgItemMessageW(hwndDlg, IDC_LOGON_INTERACTIVE, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
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]
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:965
#define IDC_LOGON_PW1TEXT
Definition: resource.h:149
#define IDC_LOGON_SYSTEMACCOUNT
Definition: resource.h:144
#define IDS_INVALID_PASSWORD
Definition: resource.h:226
#define CALLBACK
Definition: compat.h:27
LPQUERY_SERVICE_CONFIG pServiceConfig
WCHAR szPassword1[64]
BOOL WINAPI UnlockServiceDatabase(SC_LOCK ScLock)
Definition: scm.c:2960
#define PSN_APPLY
Definition: prsht.h:117
ENUM_SERVICE_STATUS_PROCESS * pService
int32_t INT_PTR
Definition: typedefs.h:62
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define DWLP_MSGRESULT
Definition: winuser.h:864
#define MB_ICONWARNING
Definition: winuser.h:780
UINT_PTR WPARAM
Definition: windef.h:207
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
VOID GetError(VOID)
Definition: misc.c:192
WCHAR szAccountName[64]
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_LOGON_THISACCOUNT
Definition: resource.h:145
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:479
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2102
#define GWLP_USERDATA
Definition: treelist.c:63
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
#define LPPROPSHEETPAGE
Definition: prsht.h:372
smooth NULL
Definition: ftsmooth.c:416
#define BM_GETCHECK
Definition: winuser.h:1879
#define WM_DESTROY
Definition: winuser.h:1591
static BOOL SetServiceAccount(LPWSTR lpServiceName, DWORD dwServiceType, LPWSTR lpStartName, LPWSTR lpPassword)
#define BM_SETCHECK
Definition: winuser.h:1882
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDC_LOGON_HWPROFILE
Definition: resource.h:153
#define GetDlgItemText
Definition: winuser.h:5651
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
VOID ResourceMessageBox(HINSTANCE hInstance, HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: misc.c:283
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
unsigned int UINT
Definition: ndis.h:50
#define BN_CLICKED
Definition: winuser.h:1886
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SC_MANAGER_LOCK
Definition: winsvc.h:17
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define SetDlgItemText
Definition: winuser.h:5715
_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:1087
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPWSTR lpServiceName)
Definition: query.c:29
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2010
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
SC_HANDLE hSCManager
Definition: sc.c:12
struct _LOGONDATA LOGONDATA
BOOL bAccountChanged
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define IDS_APPNAME
Definition: resource.h:49
static VOID SetControlStates(HWND hwndDlg, PLOGONDATA pLogonData, BOOL bLocalSystem)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HWND WINAPI GetParent(_In_ HWND)
#define GetModuleHandle
Definition: winbase.h:3641
#define IDC_LOGON_ACCOUNTNAME
Definition: resource.h:147
#define IDC_LOGON_PASSWORD1
Definition: resource.h:150
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
SC_LOCK WINAPI LockServiceDatabase(SC_HANDLE hSCManager)
Definition: scm.c:1900
#define MB_OK
Definition: winuser.h:784
#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
INT_PTR CALLBACK LogonPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _SERVICEPROPSHEET * PSERVICEPROPSHEET
#define IDC_LOGON_PW2TEXT
Definition: resource.h:151
#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 IDC_LOGON_SEARCH
Definition: resource.h:148
#define IDS_NOT_SAME_PASSWORD
Definition: resource.h:225
#define EN_CHANGE
Definition: winuser.h:1983