Ejemplo n.º 1
0
        public void Destroy()
        {
            this.TerminateProcesses();

            if (this.createInfo.NetworkOutboundRateLimitBitsPerSecond > 0)
            {
                NetworkQos.RemoveOutboundThrottlePolicy(this.WindowsUsername);

                if (this.createInfo.UrlPortAccess > 0)
                {
                    NetworkQos.RemoveOutboundThrottlePolicy(this.createInfo.UrlPortAccess.ToString());
                }
            }

            if (this.createInfo.UrlPortAccess > 0)
            {
                UrlsAcl.RemovePortAccess(this.createInfo.UrlPortAccess);
            }

            UserImpersonator.DeleteUserProfile(this.WindowsUsername, "");
            WindowsUsersAndGroups.DeleteUser(this.WindowsUsername);

            if (this.jobObject != null)
            {
                jobObject.Dispose();
                jobObject = null;
            }

            this.Created = false;
        }
Ejemplo n.º 2
0
        public void Create(ProcessPrisonCreateInfo createInfo)
        {
            if (createInfo.Id == null)
            {
                this.Id = GenerateSecureGuid().ToString();
            }
            else
            {
                this.Id = createInfo.Id;
            }

            string[] keys = new string[] { "ALLUSERSPROFILE", "APPDATA", "CommonProgramFiles", "CommonProgramFiles(x86)", "CommonProgramW6432", "COMPUTERNAME",
                                           "HOMEDRIVE", "LOCALAPPDATA", "NUMBER_OF_PROCESSORS", "OS", "Path", "PROCESSOR_ARCHITECTURE", "PROCESSOR_IDENTIFIER", "PROCESSOR_LEVEL",
                                           "PROCESSOR_REVISION", "ProgramData", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432", "PROMPT", "PSModulePath",
                                           "SystemDrive", "SystemRoot", "windir" };

            this.myenvvars["HOMEPATH"] = createInfo.DiskQuotaPath;
            this.myenvvars["TEMP"]     = Path.Combine(createInfo.DiskQuotaPath, "tmp");
            this.myenvvars["TMP"]      = Path.Combine(createInfo.DiskQuotaPath, "tmp");

            foreach (string key in keys)
            {
                this.myenvvars[key] = Environment.GetEnvironmentVariable(key);
            }

            this.createInfo = createInfo;
            this.jobObject  = new JobObject(JobObjectNamespace() + this.Id);

            this.jobObject.ActiveProcessesLimit = this.createInfo.RunningProcessesLimit;
            this.jobObject.JobMemoryLimitBytes  = this.createInfo.TotalPrivateMemoryLimitBytes;

            this.jobObject.KillProcessesOnJobClose = this.createInfo.KillProcessesrOnPrisonClose;


            if (this.createInfo.WindowsPassword == null)
            {
                this.WindowsPassword = GenerateSecurePassword(40);
            }
            else
            {
                this.WindowsPassword = this.createInfo.WindowsPassword;
            }


            this.WindowsUsername = CreateDecoratedUser(this.Id, this.WindowsPassword);


            if (this.createInfo.DiskQuotaBytes > -1)
            {
                if (string.IsNullOrEmpty(this.createInfo.DiskQuotaPath))
                {
                    // set this.createInfo.DiskQuotaPath to the output of GetUserProfileDirectory
                    throw new NotImplementedException();
                }

                // Set the disk quota to 0 for all disks, exept disk quota path
                var volumesQuotas = DiskQuotaManager.GetDisksQuotaUser(this.WindowsUsername);
                foreach (var volumeQuota in volumesQuotas)
                {
                    volumeQuota.QuotaLimit = 0;
                }

                userQuota            = DiskQuotaManager.GetDiskQuotaUser(DiskQuotaManager.GetVolumeRootFromPath(this.createInfo.DiskQuotaPath), this.WindowsUsername);
                userQuota.QuotaLimit = this.createInfo.DiskQuotaBytes;
            }

            if (this.createInfo.UrlPortAccess > 0)
            {
                UrlsAcl.AddPortAccess(this.createInfo.UrlPortAccess, this.WindowsUsername);
            }

            if (this.createInfo.NetworkOutboundRateLimitBitsPerSecond > 0)
            {
                NetworkQos.CreateOutboundThrottlePolicy(this.WindowsUsername, this.WindowsUsername, this.createInfo.NetworkOutboundRateLimitBitsPerSecond);

                if (this.createInfo.UrlPortAccess > 0)
                {
                    NetworkQos.CreateOutboundThrottlePolicy(this.createInfo.UrlPortAccess.ToString(), this.createInfo.UrlPortAccess, this.createInfo.NetworkOutboundRateLimitBitsPerSecond);
                }
            }

            this.Created = true;
        }