//TODO: Expand this function to allow for artificially elevated limited users.
        //      For example, a limited user given the permission to write to HKLM
        //      (something that is normally forbidden).
        bool OnlyUpdatingLocalUser()
        {
            // if installing
            //         - system folders
            //         - non-user registry
            //         - Windows Services
            //         - COM files
            // then return false
            // Also note how we're excluding the "BaseDir".
            // This is because the base directory may or may not be in the userprofile
            // directory (or otherwise writable by the user), thus it needs a separate check.
            // Ditto for the "client.wyc" file.
            if (((updateFrom.InstallingTo | InstallingTo.BaseDir) ^ InstallingTo.BaseDir) != 0)
            {
                return(false);
            }

            string userProfileFolder = SystemFolders.GetUserProfile();

            // if the basedir isn't in the userprofile folder (C:\Users\UserName)
            // OR
            // if the folder isn't in the full control of the current user
            // THEN
            // we're not "only updating the local user
            if ((updateFrom.InstallingTo & InstallingTo.BaseDir) != 0 && !(SystemFolders.IsDirInDir(userProfileFolder, baseDirectory) || HaveFolderPermissions(baseDirectory)))
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        //TODO: Expand this function to allow for artificially elevated limited users.
        //      For example, a limited user given the permission to write to HKLM
        //      (something that is normally forbidden).
        bool OnlyUpdatingLocalUser()
        {
            // if installing
            //         - system folders
            //         - non-user registry
            //         - Windows Services
            //         - COM files
            // then return false
            // Also note how we're excluding the "BaseDir".
            // This is because the base directory may or may not be in the userprofile
            // directory (or otherwise writable by the user), thus it needs a separate check.
            // Ditto for the "client.wyc" file.
            if (((updateFrom.InstallingTo | InstallingTo.BaseDir) ^ InstallingTo.BaseDir) != 0)
            {
                return(false);
            }

            string userProfileFolder = SystemFolders.GetUserProfile();

            // if the basedir isn't in the userprofile folder (C:\Users\UserName)
            // OR
            // if the folder isn't in the full control of the current user
            // THEN
            // we're not "only updating the local user
            if ((updateFrom.InstallingTo & InstallingTo.BaseDir) != 0 && !(SystemFolders.IsDirInDir(userProfileFolder, baseDirectory) || HaveFolderPermissions(baseDirectory)))
            {
                return(false);
            }

            // if the client data file isn't in the userprofile folder (or otherwise writable)
            // then bail out.
            if (!(SystemFolders.IsFileInDirectory(userProfileFolder, clientFileLoc) || HaveFolderPermissions(Path.GetDirectoryName(clientFileLoc))))
            {
                return(false);
            }

            // when self-updating, if this client isn't in the userprofile folder
            if ((SelfUpdateState == SelfUpdateState.WillUpdate ||
                 SelfUpdateState == SelfUpdateState.FullUpdate ||
                 SelfUpdateState == SelfUpdateState.Extracted) &&
                !(SystemFolders.IsFileInDirectory(userProfileFolder, VersionTools.SelfLocation) ||
                  HaveFolderPermissions(Path.GetDirectoryName(VersionTools.SelfLocation))))
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        public AutoUpdaterInfo(string auID, string oldAUTempFolder)
        {
            autoUpdateID = auID;

            // get the admin filename
            filenames[0] = GetFilename();

#if CLIENT
            // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user
            if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder))
            {
                // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\
                // The tempFolder is:             %appdata%\wyUpdate AU\cache\AppGUID\

                // get the limited user's AutoUpdate file
                filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate");

                // check if LimitedUser AutoUpdateFile exists
                if (!File.Exists(filenames[1]))
                {
                    filenames[1] = null;
                }
            }
#endif

            bool failedToLoad;

            bool firstFailed  = false;
            int  retriedTimes = 0;

            while (true)
            {
                try
                {
                    // try to load the AutoUpdatefile for limited user
                    if (filenames[1] != null && !firstFailed)
                    {
                        Load(filenames[1]);
                    }
                    else // load the admin user
                    {
                        Load(filenames[0]);
                    }

                    failedToLoad = false;
                }
                catch (IOException IOEx)
                {
                    int HResult = Marshal.GetHRForException(IOEx);

                    // if sharing violation
                    if ((HResult & 0xFFFF) == 32)
                    {
                        // sleep for 1/2 second
                        Thread.Sleep(500);

                        // if we're skipping UI and we've already waited 20 seconds for a file to be released
                        // then throw the exception, rollback updates, etc
                        if (retriedTimes != 20)
                        {
                            // otherwise, retry file copy
                            ++retriedTimes;
                            continue;
                        }
                    }

                    failedToLoad = true;

                    // the first has already failed (the second just failed)
                    if (firstFailed)
                    {
                        break;
                    }

                    firstFailed = true;
                    continue;
                }
                catch
                {
                    failedToLoad = true;

                    // the first has already failed (the second just failed)
                    if (firstFailed)
                    {
                        break;
                    }

                    firstFailed = true;
                    continue;
                }

                break;
            }

            if (failedToLoad)
            {
                LastCheckedForUpdate = DateTime.MinValue;
                UpdateStepOn         = UpdateStepOn.Nothing;
            }
        }
예제 #4
0
        public AutoUpdaterInfo(string auID, string oldAUTempFolder)
        {
            autoUpdateID = auID;
            filenames[0] = GetFilename();
            if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder))
            {
                filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate");
                if (!File.Exists(filenames[1]))
                {
                    filenames[1] = null;
                }
            }
            bool flag = false;
            int  num  = 0;
            bool flag2;

            while (true)
            {
                try
                {
                    if (filenames[1] != null && !flag)
                    {
                        Load(filenames[1]);
                    }
                    else
                    {
                        Load(filenames[0]);
                    }
                    flag2 = false;
                }
                catch (IOException e)
                {
                    int hRForException = Marshal.GetHRForException(e);
                    if ((hRForException & 0xFFFF) == 32)
                    {
                        Thread.Sleep(500);
                        if (num != 20)
                        {
                            num++;
                            continue;
                        }
                    }
                    flag2 = true;
                    if (!flag)
                    {
                        flag = true;
                        continue;
                    }
                }
                catch
                {
                    flag2 = true;
                    if (!flag)
                    {
                        flag = true;
                        continue;
                    }
                }
                break;
            }
            if (flag2)
            {
                LastCheckedForUpdate = DateTime.MinValue;
                UpdateStepOn         = UpdateStepOn.Nothing;
            }
        }
예제 #5
0
        public AutoUpdaterInfo(string auID, string oldAUTempFolder)
        {
            autoUpdateID = auID;

            // get the admin filename
            filenames[0] = GetFilename();

#if CLIENT
            // if tempFolder is not in ApplicationData, then we're updating on behalf of a limited user
            if (oldAUTempFolder != null && !SystemFolders.IsDirInDir(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), oldAUTempFolder))
            {
                // AutoUpdateFiles are stored in: %appdata%\wyUpdate AU\
                // The tempFolder is:             %appdata%\wyUpdate AU\cache\AppGUID\

                // get the limited user's AutoUpdate file
                filenames[1] = Path.Combine(oldAUTempFolder, "..\\..\\" + AutoUpdateID + ".autoupdate");

                // check if LimitedUser AutoUpdateFile exists
                if (!File.Exists(filenames[1]))
                {
                    filenames[1] = null;
                }
            }
#endif

            bool failedToLoad = false;

            try
            {
                // try to load the AutoUpdatefile for limited user
                if (filenames[1] != null)
                {
                    Load(filenames[1]);
                }
                else // load the admin user
                {
                    Load(filenames[0]);
                }
            }
            catch
            {
                if (filenames[1] != null)
                {
                    try
                    {
                        // try to load the AutoUpdateFile for the admin user
                        Load(filenames[0]);
                    }
                    catch
                    {
                        failedToLoad = true;
                    }
                }
                else
                {
                    failedToLoad = true;
                }
            }

            if (failedToLoad)
            {
                LastCheckedForUpdate = DateTime.MinValue;
                UpdateStepOn         = UpdateStepOn.Nothing;
            }
        }