public Task Install(string identity, CancellationToken cancellationToken = default)
        {
            if (!enabled)
            {
                return(Task.FromResult(0));
            }

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var platform = RuntimeInformation.OSDescription;

                logger.InfoFormat("Installer does not support platform {0}. Ensure that the process has required permissions to listen to configured urls.", platform);
                return(Task.FromResult(0));
            }

            if (Environment.OSVersion.Version.Major <= 5)
            {
                logger.InfoFormat(
                    @"Did not attempt to grant user '{0}' HttpListener permissions since you are running an old OS. Processing will continue.
To manually perform this action run the following command for each url from an admin console:
httpcfg set urlacl /u {{http://URL:PORT/[PATH/] | https://URL:PORT/[PATH/]}} /a D:(A;;GX;;;""{0}"")", identity);
                return(Task.FromResult(0));
            }
            if (!ElevateChecker.IsCurrentUserElevated())
            {
                logger.InfoFormat(
                    @"Did not attempt to grant user '{0}' HttpListener permissions since process is not running with elevate privileges. Processing will continue.
To manually perform this action run the following command for each url from an admin console:
netsh http add urlacl url={{http://URL:PORT/[PATH/] | https://URL:PORT/[PATH/]}} user=""{0}""", identity);
                return(Task.FromResult(0));
            }

            foreach (var receiveChannel in channelManager.GetReceiveChannels())
            {
                if (receiveChannel.Type.ToLower() != "http")
                {
                    continue;
                }

                var uri = receiveChannel.Address;
                if (!uri.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                try
                {
                    StartNetshProcess(identity, uri);
                }
                catch (Exception exception)
                {
                    var message = string.Format(
                        @"Failed to grant user '{0}' HttpListener permissions due to an Exception. Processing will continue.
To help diagnose the problem try running the following command from an admin console:
netsh http add urlacl url={1} user=""{0}""", uri, identity);
                    logger.Warn(message, exception);
                }
            }

            return(Task.CompletedTask);
        }
示例#2
0
        public void Install(string identity)
        {
            if (!Feature.IsEnabled <Gateway>())
            {
                return;
            }

            if (Environment.OSVersion.Version.Major <= 5)
            {
                logger.InfoFormat(
                    @"Did not attempt to grant user '{0}' HttpListener permissions since you are running an old OS. Processing will continue. 
To manually perform this action run the following command for each url from an admin console:
httpcfg set urlacl /u {{http://URL:PORT/[PATH/] | https://URL:PORT/[PATH/]}} /a D:(A;;GX;;;""{0}"")", identity);
                return;
            }
            if (!ElevateChecker.IsCurrentUserElevated())
            {
                logger.InfoFormat(
                    @"Did not attempt to grant user '{0}' HttpListener permissions since process is not running with elevate privileges. Processing will continue. 
To manually perform this action run the following command for each url from an admin console:
netsh http add urlacl url={{http://URL:PORT/[PATH/] | https://URL:PORT/[PATH/]}} user=""{0}""", identity);
                return;
            }

            foreach (var receiveChannel in ChannelManager.GetReceiveChannels())
            {
                if (receiveChannel.Type.ToLower() != "http")
                {
                    continue;
                }

                var uri = new Uri(receiveChannel.Address);
                if (!uri.Scheme.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                try
                {
                    StartNetshProcess(identity, uri);
                }
                catch (Exception exception)
                {
                    var message = string.Format(
                        @"Failed to grant to grant user '{0}' HttpListener permissions due to an Exception. Processing will continue.  
To help diagnose the problem try running the following command from an admin console:
netsh http add urlacl url={1} user=""{0}""", uri, identity);
                    logger.Warn(message, exception);
                }
            }
        }
        public void Install(string identity)
        {
            //did not use DirectoryEntry to avoid a ref to the DirectoryServices.dll
            try
            {
                if (!ElevateChecker.IsCurrentUserElevated())
                {
                    logger.InfoFormat(@"Did not attempt to add user '{0}' to group 'Performance Monitor Users' since process is not running with elevate privileges. Processing will continue. To manually perform this action run the following command from an admin console:
net localgroup ""Performance Monitor Users"" ""{0}"" /add", identity);
                    return;
                }
                StartProcess(identity);
            }
            catch (Exception win32Exception)
            {
                var message = string.Format(
                    @"Failed adding user '{0}' to group 'Performance Monitor Users' due to an Exception. 
To help diagnose the problem try running the following command from an admin console:
net localgroup ""Performance Monitor Users"" ""{0}"" /add", identity);
                logger.Warn(message, win32Exception);
            }
        }