ReactOS  0.4.15-dev-1619-g69dffed
security.c File Reference
#include "precomp.h"
#include <ntlsa.h>
#include <ntsecapi.h>
#include <ntsam.h>
#include <sddl.h>
#include <debug.h>
Include dependency graph for security.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS WINAPI SetAccountsDomainSid (PSID DomainSid, LPCWSTR DomainName)
 
static NTSTATUS SetPrimaryDomain (LPCWSTR DomainName, PSID DomainSid)
 
static VOID InstallBuiltinAccounts (VOID)
 
static VOID InstallPrivileges (HINF hSecurityInf)
 
static VOID ApplyRegistryValues (HINF hSecurityInf)
 
static VOID ApplyEventlogSettings (_In_ HINF hSecurityInf, _In_ PWSTR pszSectionName, _In_ PWSTR pszLogName)
 
VOID InstallSecurity (VOID)
 
NTSTATUS SetAdministratorPassword (LPCWSTR Password)
 
VOID SetAutoAdminLogon (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 18 of file security.c.

Function Documentation

◆ ApplyEventlogSettings()

static VOID ApplyEventlogSettings ( _In_ HINF  hSecurityInf,
_In_ PWSTR  pszSectionName,
_In_ PWSTR  pszLogName 
)
static

Definition at line 591 of file security.c.

595 {
596  INFCONTEXT InfContext;
597  HKEY hServiceKey = NULL, hLogKey = NULL;
598  DWORD dwValue, dwError;
599  BOOL bValueSet;
600 
601  DPRINT("ApplyEventlogSettings(%p %S %S)\n",
602  hSecurityInf, pszSectionName, pszLogName);
603 
605  L"System\\CurrentControlSet\\Services\\Eventlog",
606  0,
607  NULL,
609  KEY_WRITE,
610  NULL,
611  &hServiceKey,
612  NULL);
613  if (dwError != ERROR_SUCCESS)
614  {
615  DPRINT1("Failed to create the Eventlog Service key (Error %lu)\n", dwError);
616  return;
617  }
618 
619  dwError = RegCreateKeyExW(hServiceKey,
620  pszLogName,
621  0,
622  NULL,
624  KEY_WRITE,
625  NULL,
626  &hLogKey,
627  NULL);
628  if (dwError != ERROR_SUCCESS)
629  {
630  DPRINT1("Failed to create the key %S (Error %lu)\n", pszLogName, dwError);
631  RegCloseKey(hServiceKey);
632  return;
633  }
634 
635  if (SetupFindFirstLineW(hSecurityInf,
636  pszSectionName,
637  L"MaximumLogSize",
638  &InfContext))
639  {
640  DPRINT("MaximumLogSize\n");
641  dwValue = 0;
642  SetupGetIntField(&InfContext,
643  1,
644  (PINT)&dwValue);
645 
646  DPRINT("MaximumLogSize: %lu (kByte)\n", dwValue);
647  if (dwValue >= 64 && dwValue <= 4194240)
648  {
649  dwValue *= 1024;
650 
651  DPRINT("MaxSize: %lu\n", dwValue);
652  RegSetValueEx(hLogKey,
653  L"MaxSize",
654  0,
655  REG_DWORD,
656  (LPBYTE)&dwValue,
657  sizeof(dwValue));
658  }
659  }
660 
661  if (SetupFindFirstLineW(hSecurityInf,
662  pszSectionName,
663  L"AuditLogRetentionPeriod",
664  &InfContext))
665  {
666  bValueSet = FALSE;
667  dwValue = 0;
668  SetupGetIntField(&InfContext,
669  1,
670  (PINT)&dwValue);
671  if (dwValue == 0)
672  {
673  bValueSet = TRUE;
674  }
675  else if (dwValue == 1)
676  {
677  if (SetupFindFirstLineW(hSecurityInf,
678  pszSectionName,
679  L"RetentionDays",
680  &InfContext))
681  {
682  SetupGetIntField(&InfContext,
683  1,
684  (PINT)&dwValue);
685  dwValue *= 86400;
686  bValueSet = TRUE;
687  }
688  }
689  else if (dwValue == 2)
690  {
691  dwValue = (DWORD)-1;
692  bValueSet = TRUE;
693  }
694 
695  if (bValueSet)
696  {
697  DPRINT("Retention: %lu\n", dwValue);
698  RegSetValueEx(hLogKey,
699  L"Retention",
700  0,
701  REG_DWORD,
702  (LPBYTE)&dwValue,
703  sizeof(dwValue));
704  }
705  }
706 
707  if (SetupFindFirstLineW(hSecurityInf,
708  pszSectionName,
709  L"RestrictGuestAccess",
710  &InfContext))
711  {
712  dwValue = 0;
713  SetupGetIntField(&InfContext,
714  1,
715  (PINT)&dwValue);
716  if (dwValue == 0 || dwValue == 1)
717  {
718  DPRINT("RestrictGuestAccess: %lu\n", dwValue);
719  RegSetValueEx(hLogKey,
720  L"RestrictGuestAccess",
721  0,
722  REG_DWORD,
723  (LPBYTE)&dwValue,
724  sizeof(dwValue));
725  }
726  }
727 
728  RegCloseKey(hLogKey);
729  RegCloseKey(hServiceKey);
730 }
static DWORD
Definition: security.c:70
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
int * PINT
Definition: windef.h:177
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
BOOL WINAPI SetupGetIntField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.c:146
#define REG_DWORD
Definition: sdbapi.c:596
#define RegSetValueEx
Definition: winreg.h:533
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by InstallSecurity().

◆ ApplyRegistryValues()

static VOID ApplyRegistryValues ( HINF  hSecurityInf)
static

Definition at line 392 of file security.c.

394 {
395  WCHAR szRegistryPath[MAX_PATH];
396  WCHAR szRootName[MAX_PATH];
397  WCHAR szKeyName[MAX_PATH];
398  WCHAR szValueName[MAX_PATH];
399  INFCONTEXT InfContext;
400  DWORD dwLength, dwType;
401  HKEY hRootKey, hKey;
402  PWSTR Ptr1, Ptr2;
403  DWORD dwError;
404  PVOID pBuffer;
405 
406  DPRINT("ApplyRegistryValues()\n");
407 
408  if (!SetupFindFirstLineW(hSecurityInf,
409  L"Registry Values",
410  NULL,
411  &InfContext))
412  {
413  DPRINT1("SetupFindFirstLineW failed\n");
414  return;
415  }
416 
417  do
418  {
419  /* Retrieve the privilege name */
420  if (!SetupGetStringFieldW(&InfContext,
421  0,
422  szRegistryPath,
423  ARRAYSIZE(szRegistryPath),
424  NULL))
425  {
426  DPRINT1("SetupGetStringFieldW() failed\n");
427  return;
428  }
429 
430  DPRINT("RegistryPath: %S\n", szRegistryPath);
431 
432  Ptr1 = wcschr(szRegistryPath, L'\\');
433  Ptr2 = wcsrchr(szRegistryPath, L'\\');
434  if (Ptr1 != NULL && Ptr2 != NULL && Ptr1 != Ptr2)
435  {
436  dwLength = (DWORD)(((ULONG_PTR)Ptr1 - (ULONG_PTR)szRegistryPath) / sizeof(WCHAR));
437  wcsncpy(szRootName, szRegistryPath, dwLength);
438  szRootName[dwLength] = UNICODE_NULL;
439 
440  Ptr1++;
441  dwLength = (DWORD)(((ULONG_PTR)Ptr2 - (ULONG_PTR)Ptr1) / sizeof(WCHAR));
442  wcsncpy(szKeyName, Ptr1, dwLength);
443  szKeyName[dwLength] = UNICODE_NULL;
444 
445  Ptr2++;
446  wcscpy(szValueName, Ptr2);
447 
448  DPRINT("RootName: %S\n", szRootName);
449  DPRINT("KeyName: %S\n", szKeyName);
450  DPRINT("ValueName: %S\n", szValueName);
451 
452  if (_wcsicmp(szRootName, L"Machine") == 0)
453  {
454  hRootKey = HKEY_LOCAL_MACHINE;
455  }
456  else
457  {
458  DPRINT1("Unsupported root key %S\n", szRootName);
459  break;
460  }
461 
462  if (!SetupGetIntField(&InfContext,
463  1,
464  (PINT)&dwType))
465  {
466  DPRINT1("Failed to get key type (Error %lu)\n", GetLastError());
467  break;
468  }
469 
470  if (dwType != REG_SZ && dwType != REG_EXPAND_SZ && dwType != REG_BINARY &&
471  dwType != REG_DWORD && dwType != REG_MULTI_SZ)
472  {
473  DPRINT1("Invalid value type %lu\n", dwType);
474  break;
475  }
476 
477  dwLength = 0;
478  switch (dwType)
479  {
480  case REG_SZ:
481  case REG_EXPAND_SZ:
482  SetupGetStringField(&InfContext,
483  2,
484  NULL,
485  0,
486  &dwLength);
487  dwLength *= sizeof(WCHAR);
488  break;
489 
490  case REG_BINARY:
491  SetupGetBinaryField(&InfContext,
492  2,
493  NULL,
494  0,
495  &dwLength);
496  break;
497 
498  case REG_DWORD:
499  dwLength = sizeof(INT);
500  break;
501 
502  case REG_MULTI_SZ:
503  SetupGetMultiSzField(&InfContext,
504  2,
505  NULL,
506  0,
507  &dwLength);
508  dwLength *= sizeof(WCHAR);
509  break;
510  }
511 
512  if (dwLength == 0)
513  {
514  DPRINT1("Failed to determine the required buffer size!\n");
515  break;
516  }
517 
518  dwError = RegCreateKeyExW(hRootKey,
519  szKeyName,
520  0,
521  NULL,
523  KEY_WRITE,
524  NULL,
525  &hKey,
526  NULL);
527  if (dwError != ERROR_SUCCESS)
528  {
529  DPRINT1("Failed to create the key %S (Error %lu)\n", szKeyName, dwError);
530  break;
531  }
532 
534  if (pBuffer)
535  {
536  switch (dwType)
537  {
538  case REG_SZ:
539  case REG_EXPAND_SZ:
540  SetupGetStringField(&InfContext,
541  2,
542  pBuffer,
543  dwLength / sizeof(WCHAR),
544  &dwLength);
545  dwLength *= sizeof(WCHAR);
546  break;
547 
548  case REG_BINARY:
549  SetupGetBinaryField(&InfContext,
550  2,
551  pBuffer,
552  dwLength,
553  &dwLength);
554  break;
555 
556  case REG_DWORD:
557  SetupGetIntField(&InfContext,
558  2,
559  pBuffer);
560  break;
561 
562  case REG_MULTI_SZ:
563  SetupGetMultiSzField(&InfContext,
564  2,
565  pBuffer,
566  dwLength / sizeof(WCHAR),
567  &dwLength);
568  dwLength *= sizeof(WCHAR);
569  break;
570  }
571 
573  szValueName,
574  0,
575  dwType,
576  pBuffer,
577  dwLength);
578 
580  }
581 
582  RegCloseKey(hKey);
583  }
584  }
585  while (SetupFindNextLine(&InfContext, &InfContext));
586 }
static DWORD
Definition: security.c:70
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
uint16_t * PWSTR
Definition: typedefs.h:56
#define SetupGetMultiSzField
Definition: setupapi.h:2630
#define INT
Definition: polytest.cpp:20
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
uint32_t ULONG_PTR
Definition: typedefs.h:65
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define UNICODE_NULL
BOOL WINAPI SetupGetBinaryField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:126
#define REG_MULTI_SZ
Definition: nt_native.h:1501
PVOID pBuffer
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
int * PINT
Definition: windef.h:177
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD DWORD * dwLength
Definition: fusion.c:85
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetupGetStringField
Definition: setupapi.h:2634
_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
#define wcsrchr
Definition: compat.h:16
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
FxAutoRegKey hKey
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define NULL
Definition: types.h:112
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:80
#define DPRINT1
Definition: precomp.h:8
BOOL WINAPI SetupGetIntField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.c:146
#define REG_DWORD
Definition: sdbapi.c:596
#define HeapFree(x, y, z)
Definition: compat.h:594
#define RegSetValueEx
Definition: winreg.h:533
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184

Referenced by InstallSecurity().

◆ InstallBuiltinAccounts()

static VOID InstallBuiltinAccounts ( VOID  )
static

Definition at line 214 of file security.c.

215 {
216  LPWSTR BuiltinAccounts[] = {
217  L"S-1-1-0", /* Everyone */
218  L"S-1-5-4", /* Interactive */
219  L"S-1-5-6", /* Service */
220  L"S-1-5-19", /* Local Service */
221  L"S-1-5-20", /* Network Service */
222  L"S-1-5-32-544", /* Administrators */
223  L"S-1-5-32-545", /* Users */
224  L"S-1-5-32-547", /* Power Users */
225  L"S-1-5-32-551", /* Backup Operators */
226  L"S-1-5-32-555"}; /* Remote Desktop Users */
229  LSA_HANDLE PolicyHandle = NULL;
230  LSA_HANDLE AccountHandle = NULL;
231  PSID AccountSid;
232  ULONG i;
233 
234  DPRINT("InstallBuiltinAccounts()\n");
235 
237 
241  &PolicyHandle);
242  if (!NT_SUCCESS(Status))
243  {
244  DPRINT1("LsaOpenPolicy failed (Status %08lx)\n", Status);
245  return;
246  }
247 
248  for (i = 0; i < ARRAYSIZE(BuiltinAccounts); i++)
249  {
250  if (!ConvertStringSidToSid(BuiltinAccounts[i], &AccountSid))
251  {
252  DPRINT1("ConvertStringSidToSid(%S) failed: %lu\n", BuiltinAccounts[i], GetLastError());
253  continue;
254  }
255 
256  Status = LsaCreateAccount(PolicyHandle,
257  AccountSid,
258  0,
259  &AccountHandle);
260  if (NT_SUCCESS(Status))
261  {
262  LsaClose(AccountHandle);
263  }
264 
265  LocalFree(AccountSid);
266  }
267 
268  LsaClose(PolicyHandle);
269 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ConvertStringSidToSid
Definition: sddl.h:161
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS WINAPI LsaCreateAccount(IN LSA_HANDLE PolicyHandle, IN PSID AccountSid, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE AccountHandle)
Definition: lsa.c:217
static const WCHAR L[]
Definition: oid.c:1250
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define POLICY_CREATE_ACCOUNT
Definition: ntsecapi.h:65
#define memset(x, y, z)
Definition: compat.h:39

Referenced by InstallSecurity().

◆ InstallPrivileges()

static VOID InstallPrivileges ( HINF  hSecurityInf)
static

Definition at line 274 of file security.c.

276 {
278  WCHAR szPrivilegeString[256];
279  WCHAR szSidString[256];
280  INFCONTEXT InfContext;
281  DWORD i;
282  PSID AccountSid = NULL;
284  LSA_HANDLE PolicyHandle = NULL;
285  LSA_UNICODE_STRING RightString;
286  PLSA_TRANSLATED_SID2 Sids = NULL;
287 
288  DPRINT("InstallPrivileges()\n");
289 
291 
295  &PolicyHandle);
296  if (!NT_SUCCESS(Status))
297  {
298  DPRINT1("LsaOpenPolicy failed (Status %08lx)\n", Status);
299  goto done;
300  }
301 
302  if (!SetupFindFirstLineW(hSecurityInf,
303  L"Privilege Rights",
304  NULL,
305  &InfContext))
306  {
307  DPRINT1("SetupFindFirstLineW failed\n");
308  goto done;
309  }
310 
311  do
312  {
313  /* Retrieve the privilege name */
314  if (!SetupGetStringFieldW(&InfContext,
315  0,
316  szPrivilegeString,
317  ARRAYSIZE(szPrivilegeString),
318  NULL))
319  {
320  DPRINT1("SetupGetStringFieldW() failed\n");
321  goto done;
322  }
323  DPRINT("Privilege: %S\n", szPrivilegeString);
324 
325  for (i = 0; i < SetupGetFieldCount(&InfContext); i++)
326  {
327  if (!SetupGetStringFieldW(&InfContext,
328  i + 1,
329  szSidString,
330  ARRAYSIZE(szSidString),
331  NULL))
332  {
333  DPRINT1("SetupGetStringFieldW() failed\n");
334  goto done;
335  }
336  DPRINT("SID: %S\n", szSidString);
337 
338  if (szSidString[0] == UNICODE_NULL)
339  continue;
340 
341  if (szSidString[0] == L'*')
342  {
343  DPRINT("Account Sid: %S\n", &szSidString[1]);
344 
345  if (!ConvertStringSidToSid(&szSidString[1], &AccountSid))
346  {
347  DPRINT1("ConvertStringSidToSid(%S) failed: %lu\n", szSidString, GetLastError());
348  continue;
349  }
350  }
351  else
352  {
353  DPRINT("Account name: %S\n", szSidString);
354  continue;
355 
356  }
357 
358  RtlInitUnicodeString(&RightString, szPrivilegeString);
359  Status = LsaAddAccountRights(PolicyHandle,
360  (AccountSid != NULL) ? AccountSid : Sids[0].Sid,
361  &RightString,
362  1);
363  if (!NT_SUCCESS(Status))
364  {
365  DPRINT1("LsaAddAccountRights() failed (Status %08lx)\n", Status);
366  }
367 
368  if (Sids != NULL)
369  {
370  LsaFreeMemory(Sids);
371  Sids = NULL;
372  }
373 
374  if (AccountSid != NULL)
375  {
376  LocalFree(AccountSid);
377  AccountSid = NULL;
378  }
379  }
380 
381  }
382  while (SetupFindNextLine(&InfContext, &InfContext));
383 
384 done:
385  if (PolicyHandle != NULL)
386  LsaClose(PolicyHandle);
387 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
#define ConvertStringSidToSid
Definition: sddl.h:161
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
#define UNICODE_NULL
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1103
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:699
#define POLICY_LOOKUP_NAMES
Definition: ntsecapi.h:72
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:91
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS WINAPI LsaAddAccountRights(IN LSA_HANDLE PolicyHandle, IN PSID AccountSid, IN PLSA_UNICODE_STRING UserRights, IN ULONG CountOfRights)
Definition: lsa.c:103
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define NULL
Definition: types.h:112
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:80
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define POLICY_CREATE_ACCOUNT
Definition: ntsecapi.h:65
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184

Referenced by InstallSecurity().

◆ InstallSecurity()

VOID InstallSecurity ( VOID  )

Definition at line 734 of file security.c.

735 {
736  HINF hSecurityInf;
737  PWSTR pszSecurityInf;
738 
739 // if (IsServer())
740 // pszSecurityInf = L"defltsv.inf";
741 // else
742  pszSecurityInf = L"defltwk.inf";
743 
745 
746  hSecurityInf = SetupOpenInfFileW(pszSecurityInf,
747  NULL,
749  NULL);
750  if (hSecurityInf != INVALID_HANDLE_VALUE)
751  {
752  InstallPrivileges(hSecurityInf);
753  ApplyRegistryValues(hSecurityInf);
754 
755  ApplyEventlogSettings(hSecurityInf, L"Application Log", L"Application");
756  ApplyEventlogSettings(hSecurityInf, L"Security Log", L"Security");
757  ApplyEventlogSettings(hSecurityInf, L"System Log", L"System");
758 
759  SetupCloseInfFile(hSecurityInf);
760  }
761 
762  /* Hack */
763  SetPrimaryDomain(L"WORKGROUP", NULL);
764 }
static VOID InstallPrivileges(HINF hSecurityInf)
Definition: security.c:274
#define INF_STYLE_WIN4
Definition: infsupp.h:41
uint16_t * PWSTR
Definition: typedefs.h:56
static VOID InstallBuiltinAccounts(VOID)
Definition: security.c:214
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
static const WCHAR L[]
Definition: oid.c:1250
static VOID ApplyRegistryValues(HINF hSecurityInf)
Definition: security.c:392
#define NULL
Definition: types.h:112
static NTSTATUS SetPrimaryDomain(LPCWSTR DomainName, PSID DomainSid)
Definition: security.c:140
static VOID ApplyEventlogSettings(_In_ HINF hSecurityInf, _In_ PWSTR pszSectionName, _In_ PWSTR pszLogName)
Definition: security.c:591

Referenced by InstallReactOS().

◆ SetAccountsDomainSid()

NTSTATUS WINAPI SetAccountsDomainSid ( PSID  DomainSid,
LPCWSTR  DomainName 
)

Definition at line 25 of file security.c.

28 {
32  LSA_HANDLE PolicyHandle;
33 
34  SAM_HANDLE ServerHandle = NULL;
35  SAM_HANDLE DomainHandle = NULL;
36  DOMAIN_NAME_INFORMATION DomainNameInfo;
37 
39 
40  DPRINT("SYSSETUP: SetAccountsDomainSid\n");
41 
44 
48  &PolicyHandle);
49  if (Status != STATUS_SUCCESS)
50  {
51  DPRINT("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
52  return Status;
53  }
54 
55  Status = LsaQueryInformationPolicy(PolicyHandle,
57  (PVOID *)&OrigInfo);
58  if (Status == STATUS_SUCCESS && OrigInfo != NULL)
59  {
60  if (DomainName == NULL)
61  {
62  Info.DomainName.Buffer = OrigInfo->DomainName.Buffer;
63  Info.DomainName.Length = OrigInfo->DomainName.Length;
64  Info.DomainName.MaximumLength = OrigInfo->DomainName.MaximumLength;
65  }
66  else
67  {
68  Info.DomainName.Buffer = (LPWSTR)DomainName;
69  Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
70  Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
71  }
72 
73  if (DomainSid == NULL)
74  Info.DomainSid = OrigInfo->DomainSid;
75  else
76  Info.DomainSid = DomainSid;
77  }
78  else
79  {
80  Info.DomainName.Buffer = (LPWSTR)DomainName;
81  Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
82  Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
83  Info.DomainSid = DomainSid;
84  }
85 
86  Status = LsaSetInformationPolicy(PolicyHandle,
88  (PVOID)&Info);
89  if (Status != STATUS_SUCCESS)
90  {
91  DPRINT("LsaSetInformationPolicy failed (Status: 0x%08lx)\n", Status);
92  }
93 
94  if (OrigInfo != NULL)
95  LsaFreeMemory(OrigInfo);
96 
97  LsaClose(PolicyHandle);
98 
99  DomainNameInfo.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
100  DomainNameInfo.DomainName.MaximumLength = (wcslen(DomainName) + 1) * sizeof(WCHAR);
101  DomainNameInfo.DomainName.Buffer = (LPWSTR)DomainName;
102 
104  &ServerHandle,
106  NULL);
107  if (NT_SUCCESS(Status))
108  {
109  Status = SamOpenDomain(ServerHandle,
111  Info.DomainSid,
112  &DomainHandle);
113  if (NT_SUCCESS(Status))
114  {
115  Status = SamSetInformationDomain(DomainHandle,
117  (PVOID)&DomainNameInfo);
118  if (!NT_SUCCESS(Status))
119  {
120  DPRINT1("SamSetInformationDomain failed (Status: 0x%08lx)\n", Status);
121  }
122 
123  SamCloseHandle(DomainHandle);
124  }
125  else
126  {
127  DPRINT1("SamOpenDomain failed (Status: 0x%08lx)\n", Status);
128  }
129 
130  SamCloseHandle(ServerHandle);
131  }
132 
133  return Status;
134 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1471
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
NTSTATUS WINAPI LsaSetInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, IN PVOID Buffer)
Definition: lsa.c:1946
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:699
UNICODE_STRING DomainName
Definition: ntsam.h:381
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI SamSetInformationDomain(IN SAM_HANDLE DomainHandle, IN DOMAIN_INFORMATION_CLASS DomainInformationClass, IN PVOID Buffer)
Definition: samlib.c:1910
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define POLICY_TRUST_ADMIN
Definition: ntsecapi.h:64
#define DOMAIN_WRITE_OTHER_PARAMETERS
Definition: ntsam.h:36
struct _LSA_OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES
USHORT MaximumLength
Definition: ntsecapi.h:164
#define NULL
Definition: types.h:112
LSA_UNICODE_STRING DomainName
Definition: ntsecapi.h:566
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by WriteComputerSettings().

◆ SetAdministratorPassword()

NTSTATUS SetAdministratorPassword ( LPCWSTR  Password)

Definition at line 768 of file security.c.

769 {
771  PUSER_ACCOUNT_NAME_INFORMATION AccountNameInfo = NULL;
772  USER_SET_PASSWORD_INFORMATION PasswordInfo;
774  LSA_HANDLE PolicyHandle = NULL;
775  SAM_HANDLE ServerHandle = NULL;
776  SAM_HANDLE DomainHandle = NULL;
777  SAM_HANDLE UserHandle = NULL;
779 
780  DPRINT("SYSSETUP: SetAdministratorPassword(%p)\n", Password);
781 
784 
788  &PolicyHandle);
789  if (Status != STATUS_SUCCESS)
790  {
791  DPRINT1("LsaOpenPolicy() failed (Status: 0x%08lx)\n", Status);
792  return Status;
793  }
794 
795  Status = LsaQueryInformationPolicy(PolicyHandle,
797  (PVOID *)&OrigInfo);
798  if (!NT_SUCCESS(Status))
799  {
800  DPRINT1("LsaQueryInformationPolicy() failed (Status: 0x%08lx)\n", Status);
801  goto done;
802  }
803 
805  &ServerHandle,
807  NULL);
808  if (!NT_SUCCESS(Status))
809  {
810  DPRINT1("SamConnect() failed (Status: 0x%08lx)\n", Status);
811  goto done;
812  }
813 
814  Status = SamOpenDomain(ServerHandle,
816  OrigInfo->DomainSid,
817  &DomainHandle);
818  if (!NT_SUCCESS(Status))
819  {
820  DPRINT1("SamOpenDomain() failed (Status: 0x%08lx)\n", Status);
821  goto done;
822  }
823 
824  Status = SamOpenUser(DomainHandle,
827  &UserHandle);
828  if (!NT_SUCCESS(Status))
829  {
830  DPRINT1("SamOpenUser() failed (Status %08lx)\n", Status);
831  goto done;
832  }
833 
834  RtlInitUnicodeString(&PasswordInfo.Password, Password);
835  PasswordInfo.PasswordExpired = FALSE;
836 
837  Status = SamSetInformationUser(UserHandle,
839  (PVOID)&PasswordInfo);
840  if (!NT_SUCCESS(Status))
841  {
842  DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
843  goto done;
844  }
845 
846  Status = SamQueryInformationUser(UserHandle,
848  (PVOID*)&AccountNameInfo);
849  if (!NT_SUCCESS(Status))
850  {
851  DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
852  goto done;
853  }
854 
855  AdminInfo.Name = RtlAllocateHeap(RtlGetProcessHeap(),
857  AccountNameInfo->UserName.Length + sizeof(WCHAR));
858  if (AdminInfo.Name != NULL)
860  AccountNameInfo->UserName.Buffer,
861  AccountNameInfo->UserName.Length);
862 
863  AdminInfo.Domain = RtlAllocateHeap(RtlGetProcessHeap(),
865  OrigInfo->DomainName.Length + sizeof(WCHAR));
866  if (AdminInfo.Domain != NULL)
868  OrigInfo->DomainName.Buffer,
869  OrigInfo->DomainName.Length);
870 
871  AdminInfo.Password = RtlAllocateHeap(RtlGetProcessHeap(),
872  0,
873  (wcslen(Password) + 1) * sizeof(WCHAR));
874  if (AdminInfo.Password != NULL)
876 
877  DPRINT("Administrator Name: %S\n", AdminInfo.Name);
878  DPRINT("Administrator Domain: %S\n", AdminInfo.Domain);
879  DPRINT("Administrator Password: %S\n", AdminInfo.Password);
880 
881 done:
882  if (AccountNameInfo != NULL)
883  SamFreeMemory(AccountNameInfo);
884 
885  if (OrigInfo != NULL)
886  LsaFreeMemory(OrigInfo);
887 
888  if (PolicyHandle != NULL)
889  LsaClose(PolicyHandle);
890 
891  if (UserHandle != NULL)
892  SamCloseHandle(UserHandle);
893 
894  if (DomainHandle != NULL)
895  SamCloseHandle(DomainHandle);
896 
897  if (ServerHandle != NULL)
898  SamCloseHandle(ServerHandle);
899 
900  DPRINT1("SYSSETUP: SetAdministratorPassword() done (Status %08lx)\n", Status);
901 
902  return Status;
903 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1471
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
ADMIN_INFO AdminInfo
Definition: install.c:38
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
LPWSTR Name
Definition: globals.h:23
UNICODE_STRING UserName
Definition: ntsam.h:595
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
#define USER_READ_GENERAL
Definition: ntsam.h:126
#define FALSE
Definition: types.h:117
#define DOMAIN_USER_RID_ADMIN
Definition: setypes.h:603
#define USER_FORCE_PASSWORD_CHANGE
Definition: ntsam.h:133
UNICODE_STRING Password
Definition: ntsam.h:636
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:699
NTSTATUS NTAPI SamSetInformationUser(IN SAM_HANDLE UserHandle, IN USER_INFORMATION_CLASS UserInformationClass, IN PVOID Buffer)
Definition: samlib.c:1964
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define POLICY_TRUST_ADMIN
Definition: ntsecapi.h:64
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
LPWSTR Password
Definition: globals.h:25
struct _LSA_OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
LSA_UNICODE_STRING DomainName
Definition: ntsecapi.h:566
#define DPRINT1
Definition: precomp.h:8
LPWSTR Domain
Definition: globals.h:24
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI SamQueryInformationUser(IN SAM_HANDLE UserHandle, IN USER_INFORMATION_CLASS UserInformationClass, OUT PVOID *Buffer)
Definition: samlib.c:1695
#define memset(x, y, z)
Definition: compat.h:39
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSTATUS NTAPI SamOpenUser(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG UserId, OUT PSAM_HANDLE UserHandle)
Definition: samlib.c:1499

Referenced by ComputerPageDlgProc().

◆ SetAutoAdminLogon()

VOID SetAutoAdminLogon ( VOID  )

Definition at line 907 of file security.c.

908 {
909  WCHAR szAutoAdminLogon[2];
910  HKEY hKey = NULL;
911  DWORD dwType;
912  DWORD dwSize;
913  LONG lError;
914 
916  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
917  0,
919  &hKey);
920  if (lError != ERROR_SUCCESS)
921  return;
922 
923  dwSize = 2 * sizeof(WCHAR);
924  lError = RegQueryValueExW(hKey,
925  L"AutoAdminLogon",
926  NULL,
927  &dwType,
928  (LPBYTE)szAutoAdminLogon,
929  &dwSize);
930  if (lError != ERROR_SUCCESS)
931  goto done;
932 
933  if (wcscmp(szAutoAdminLogon, L"1") == 0)
934  {
936  L"DefaultDomainName",
937  0,
938  REG_SZ,
940  (wcslen(AdminInfo.Domain) + 1) * sizeof(WCHAR));
941 
943  L"DefaultUserName",
944  0,
945  REG_SZ,
947  (wcslen(AdminInfo.Name) + 1) * sizeof(WCHAR));
948 
950  L"DefaultPassword",
951  0,
952  REG_SZ,
954  (wcslen(AdminInfo.Password) + 1) * sizeof(WCHAR));
955  }
956 
957 done:
958  if (hKey != NULL)
959  RegCloseKey(hKey);
960 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
ADMIN_INFO AdminInfo
Definition: install.c:38
LPWSTR Name
Definition: globals.h:23
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
long LONG
Definition: pedump.c:60
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR Password
Definition: globals.h:25
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
LPWSTR Domain
Definition: globals.h:24
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by InstallReactOS().

◆ SetPrimaryDomain()

static NTSTATUS SetPrimaryDomain ( LPCWSTR  DomainName,
PSID  DomainSid 
)
static

Definition at line 140 of file security.c.

142 {
146  LSA_HANDLE PolicyHandle;
148 
149  DPRINT1("SYSSETUP: SetPrimaryDomain()\n");
150 
153 
157  &PolicyHandle);
158  if (Status != STATUS_SUCCESS)
159  {
160  DPRINT("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
161  return Status;
162  }
163 
164  Status = LsaQueryInformationPolicy(PolicyHandle,
166  (PVOID *)&OrigInfo);
167  if (Status == STATUS_SUCCESS && OrigInfo != NULL)
168  {
169  if (DomainName == NULL)
170  {
171  Info.Name.Buffer = OrigInfo->Name.Buffer;
172  Info.Name.Length = OrigInfo->Name.Length;
173  Info.Name.MaximumLength = OrigInfo->Name.MaximumLength;
174  }
175  else
176  {
177  Info.Name.Buffer = (LPWSTR)DomainName;
178  Info.Name.Length = wcslen(DomainName) * sizeof(WCHAR);
179  Info.Name.MaximumLength = Info.Name.Length + sizeof(WCHAR);
180  }
181 
182  if (DomainSid == NULL)
183  Info.Sid = OrigInfo->Sid;
184  else
185  Info.Sid = DomainSid;
186  }
187  else
188  {
189  Info.Name.Buffer = (LPWSTR)DomainName;
190  Info.Name.Length = wcslen(DomainName) * sizeof(WCHAR);
191  Info.Name.MaximumLength = Info.Name.Length + sizeof(WCHAR);
192  Info.Sid = DomainSid;
193  }
194 
195  Status = LsaSetInformationPolicy(PolicyHandle,
197  (PVOID)&Info);
198  if (Status != STATUS_SUCCESS)
199  {
200  DPRINT("LsaSetInformationPolicy failed (Status: 0x%08lx)\n", Status);
201  }
202 
203  if (OrigInfo != NULL)
204  LsaFreeMemory(OrigInfo);
205 
206  LsaClose(PolicyHandle);
207 
208  return Status;
209 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1471
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
NTSTATUS WINAPI LsaSetInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, IN PVOID Buffer)
Definition: lsa.c:1946
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
LSA_UNICODE_STRING Name
Definition: ntsecapi.h:570
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:699
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define POLICY_TRUST_ADMIN
Definition: ntsecapi.h:64
struct _LSA_OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES
USHORT MaximumLength
Definition: ntsecapi.h:164
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by InstallSecurity().