Author: rharabien
Date: Fri Apr 15 20:42:07 2011
New Revision: 51358

URL: http://svn.reactos.org/svn/reactos?rev=51358&view=rev
Log:
[SYSSETUP]
* Generate random computer name (REACTOS-xxxxxxx) in Setup. Patch by David 
Quintana <gigaherz at gmail dot com> modified by me
See issue #6099 for more details.

Modified:
    trunk/reactos/dll/win32/syssetup/wizard.c

Modified: trunk/reactos/dll/win32/syssetup/wizard.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/syssetup/wizard.c?rev=51358&r1=51357&r2=51358&view=diff
==============================================================================
--- trunk/reactos/dll/win32/syssetup/wizard.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/syssetup/wizard.c [iso-8859-1] Fri Apr 15 20:42:07 
2011
@@ -564,6 +564,25 @@
   return TRUE;
 }
 
+/* lpBuffer will be filled with a 15-char string (plus the null terminator) */
+static void
+GenerateComputerName(LPWSTR lpBuffer)
+{
+    static const WCHAR Chars[] = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    static const unsigned cChars = sizeof(Chars) / sizeof(WCHAR) - 1;
+    unsigned i;
+
+    wcscpy(lpBuffer, L"REACTOS-");
+
+    srand(GetTickCount());
+
+    /* fill in 7 characters */
+    for (i = 8; i < 15; i++)
+        lpBuffer[i] = Chars[rand() % cChars];
+
+    lpBuffer[15] = UNICODE_NULL; /* NULL-terminate */
+}
+
 static INT_PTR CALLBACK
 ComputerPageDlgProc(HWND hwndDlg,
                     UINT uMsg,
@@ -576,7 +595,6 @@
   PWCHAR Password;
   WCHAR Title[64];
   WCHAR EmptyComputerName[256], NotMatchPassword[256], WrongPassword[256];
-  DWORD Length;
   LPNMHDR lpnm;
 
   if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / 
sizeof(Title[0])))
@@ -588,9 +606,8 @@
     {
       case WM_INITDIALOG:
         {
-          /* Retrieve current computer name */
-          Length = MAX_COMPUTERNAME_LENGTH + 1;
-          GetComputerNameW(ComputerName, &Length);
+          /* Generate a new pseudo-random computer name */
+          GenerateComputerName(ComputerName);
 
           /* Display current computer name */
           SetDlgItemTextW(hwndDlg, IDC_COMPUTERNAME, ComputerName);


Reply via email to