ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

environment.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Winlogon
00004  * FILE:            base/system/winlogon/environment.c
00005  * PURPOSE:         User environment routines
00006  * PROGRAMMERS:     Thomas Weidenmueller (w3seek@users.sourceforge.net)
00007  *                  Hervé Poussineau (hpoussin@reactos.org)
00008  *                  Eric Kohl
00009  */
00010 
00011 /* INCLUDES *****************************************************************/
00012 
00013 #include "winlogon.h"
00014 #include <shlobj.h>
00015 
00016 #include <wine/debug.h>
00017 
00018 WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
00019 
00020 /* GLOBALS ******************************************************************/
00021 
00022 
00023 /* FUNCTIONS ****************************************************************/
00024 
00025 static VOID
00026 BuildVolatileEnvironment(IN PWLSESSION Session,
00027                          IN HKEY hKeyCurrentUser)
00028 {
00029     WCHAR szPath[MAX_PATH + 1];
00030     LPCWSTR wstr;
00031     SIZE_T size;
00032     WCHAR szEnvKey[MAX_PATH];
00033     WCHAR szEnvValue[1024];
00034     SIZE_T length;
00035     LPWSTR eqptr, endptr;
00036     DWORD dwDisp;
00037     LONG lError;
00038     HKEY hKeyVolatileEnv;
00039     HKEY hKeyShellFolders;
00040     DWORD dwType;
00041     DWORD dwSize;
00042 
00043     /* Create the 'Volatile Environment' key */
00044     lError = RegCreateKeyExW(hKeyCurrentUser,
00045                              L"Volatile Environment",
00046                              0,
00047                              NULL,
00048                              REG_OPTION_VOLATILE,
00049                              KEY_WRITE,
00050                              NULL,
00051                              &hKeyVolatileEnv,
00052                              &dwDisp);
00053     if (lError != ERROR_SUCCESS)
00054     {
00055         WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError);
00056         return;
00057     }
00058 
00059     /* Parse the environment variables and add them to the volatile environment key */
00060     if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
00061         Session->Profile->pszEnvironment != NULL)
00062     {
00063         wstr = Session->Profile->pszEnvironment;
00064         while (*wstr != UNICODE_NULL)
00065         {
00066             size = wcslen(wstr) + 1;
00067 
00068             eqptr = wcschr(wstr, L'=');
00069 
00070             if (eqptr != NULL)
00071             {
00072                 endptr = eqptr;
00073 
00074                 endptr--;
00075                 while (iswspace(*endptr))
00076                     endptr--;
00077 
00078                 length = (SIZE_T)(endptr - wstr + 1);
00079 
00080                 wcsncpy(szEnvKey, wstr, length);
00081                 szEnvKey[length] = 0;
00082 
00083                 eqptr++;
00084                 while (iswspace(*eqptr))
00085                     eqptr++;
00086                 wcscpy(szEnvValue, eqptr);
00087 
00088                 RegSetValueExW(hKeyVolatileEnv,
00089                                szEnvKey,
00090                                0,
00091                                REG_SZ,
00092                                (LPBYTE)szEnvValue,
00093                                (wcslen(szEnvValue) + 1) * sizeof(WCHAR));
00094             }
00095 
00096             wstr += size;
00097         }
00098     }
00099 
00100     /* Set the 'APPDATA' environment variable */
00101     lError = RegOpenKeyExW(hKeyCurrentUser,
00102                            L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
00103                            0,
00104                            KEY_READ,
00105                            &hKeyShellFolders);
00106     if (lError == ERROR_SUCCESS)
00107     {
00108         dwSize = (MAX_PATH + 1) * sizeof(WCHAR);
00109         lError = RegQueryValueExW(hKeyShellFolders,
00110                                   L"AppData",
00111                                   NULL,
00112                                   &dwType,
00113                                   (LPBYTE)szPath,
00114                                   &dwSize);
00115         if (lError == ERROR_SUCCESS)
00116         {
00117             TRACE("APPDATA path: %S\n", szPath);
00118             RegSetValueExW(hKeyVolatileEnv,
00119                            L"APPDATA",
00120                            0,
00121                            REG_SZ,
00122                            (LPBYTE)szPath,
00123                            (wcslen(szPath) + 1) * sizeof(WCHAR));
00124         }
00125 
00126         RegCloseKey(hKeyShellFolders);
00127     }
00128 
00129     RegCloseKey(hKeyVolatileEnv);
00130 }
00131 
00132 
00133 BOOL
00134 CreateUserEnvironment(IN PWLSESSION Session)
00135 {
00136     HKEY hKeyCurrentUser;
00137     LONG lError;
00138 
00139     TRACE("WL: CreateUserEnvironment called\n");
00140 
00141     /* Impersonate the new user */
00142     ImpersonateLoggedOnUser(Session->UserToken);
00143 
00144     /* Open the new users HKCU key */
00145     lError = RegOpenCurrentUser(KEY_CREATE_SUB_KEY,
00146                                 &hKeyCurrentUser);
00147     if (lError == ERROR_SUCCESS)
00148     {
00149         BuildVolatileEnvironment(Session,
00150                                  hKeyCurrentUser);
00151         RegCloseKey(hKeyCurrentUser);
00152     }
00153 
00154     /* Revert the impersonation */
00155     RevertToSelf();
00156 
00157     TRACE("WL: CreateUserEnvironment done\n");
00158 
00159     return TRUE;
00160 }

Generated on Sun May 27 2012 04:18:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.