Пример #1
0
        internal static SecurityIdentifier GetCurrentAppContainerSid()
        {
            Fx.Assert(AppContainerInfo.IsAppContainerSupported, "AppContainers are not supported.");
            if (currentAppContainerSid == null)
            {
                lock (thisLock)
                {
                    if (currentAppContainerSid == null)
                    {
                        SafeCloseHandle tokenHandle = null;
                        try
                        {
                            tokenHandle            = AppContainerInfo.GetCurrentProcessToken();
                            currentAppContainerSid = UnsafeNativeMethods.GetAppContainerSid(tokenHandle);
                        }
                        finally
                        {
                            if (tokenHandle != null)
                            {
                                tokenHandle.Dispose();
                            }
                        }
                    }
                }
            }

            return(currentAppContainerSid);
        }
Пример #2
0
        static int GetCurrentSessionId()
        {
            Fx.Assert(AppContainerInfo.IsAppContainerSupported, "AppContainers are not supported.");
            SafeCloseHandle tokenHandle = null;

            try
            {
                tokenHandle = AppContainerInfo.GetCurrentProcessToken();
                return(UnsafeNativeMethods.GetSessionId(tokenHandle));
            }
            finally
            {
                if (tokenHandle != null)
                {
                    tokenHandle.Dispose();
                }
            }
        }
Пример #3
0
        internal static AppContainerInfo CreateAppContainerInfo(string fullName, int sessionId)
        {
            Fx.Assert(IsAppContainerSupported, "AppContainers are not supported.");
            Fx.Assert(!string.IsNullOrEmpty(fullName), "fullName should be provided to initialize an AppContainerInfo.");

            int appSession = sessionId;

            if (appSession == ApplicationContainerSettings.CurrentSession)
            {
                lock (thisLock)
                {
                    if (currentSessionId == null)
                    {
                        currentSessionId = AppContainerInfo.GetCurrentSessionId();
                    }
                }

                appSession = currentSessionId.Value;
            }

            string namedObjectPath = AppContainerInfo.GetAppContainerNamedObjectPath(fullName);

            return(new AppContainerInfo(appSession, namedObjectPath));
        }
Пример #4
0
        internal static string BuildSharedMemoryName(string hostName, string path, bool global, AppContainerInfo appContainerInfo)
        {
            if (appContainerInfo == null)
            {
                return BuildSharedMemoryName(hostName, path, global);
            }
            else
            {
                Fx.Assert(appContainerInfo.SessionId != ApplicationContainerSettingsDefaults.CurrentSession, "Session has not yet been initialized.");
                Fx.Assert(!String.IsNullOrEmpty(appContainerInfo.NamedObjectPath),
                    "NamedObjectPath cannot be empty when creating the SharedMemoryName when running in an AppContainer.");

                //We need to use a session symlink for the lowbox appcontainer.
                // Session\{0}\{1}\{2}\<SharedMemoryName>                
                return string.Format(
                            CultureInfo.InvariantCulture,
                            @"Session\{0}\{1}\{2}",
                            appContainerInfo.SessionId,
                            appContainerInfo.NamedObjectPath,
                            BuildSharedMemoryName(hostName, path, global));
            }
        }
Пример #5
0
        internal string GetPipeName(AppContainerInfo appInfo)
        {
            if (appInfo == null)
            {
                return this.PipeName;
            }
            else if (this.PipeName != null)
            {
                // Build the PipeName for a pipe inside an AppContainer as follows
                // \\.\pipe\Sessions\<SessionId>\<NamedObjectPath>\<PipeGuid>
                return string.Format(
                            CultureInfo.InvariantCulture,
                            @"\\.\pipe\Sessions\{0}\{1}\{2}",
                            appInfo.SessionId,
                            appInfo.NamedObjectPath,
                            this.pipeNameGuidPart);
            }

            return null;
        }