Esempio n. 1
0
        private void ExtractRbacDataFromRunspace(object sender, EventArgs e)
        {
            ADObjectId     adobjectId     = null;
            OrganizationId organizationId = null;

            ExchangePropertyContainer.InitializeExchangePropertyContainerIfNeeded(this.context.SessionState, out adobjectId, out organizationId);
            ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = null;

            if (this.context.SessionState != null)
            {
                exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(this.context.SessionState);
            }
            OrganizationId organizationId2;
            string         executingUserIdentityName;
            SmtpAddress    executingWindowsLiveId;

            if (exchangeRunspaceConfiguration == null)
            {
                if (this.context.SessionState != null)
                {
                    organizationId = (organizationId ?? ExchangePropertyContainer.GetExecutingUserOrganizationId(this.context.SessionState));
                    adobjectId     = (adobjectId ?? ExchangePropertyContainer.GetExecutingUserId(this.context.SessionState));
                }
                organizationId2           = organizationId;
                executingUserIdentityName = ((adobjectId == null) ? string.Empty : adobjectId.Name);
            }
            else
            {
                exchangeRunspaceConfiguration.TryGetExecutingUserId(out adobjectId);
                executingUserIdentityName = exchangeRunspaceConfiguration.IdentityName;
                exchangeRunspaceConfiguration.TryGetExecutingWindowsLiveId(out executingWindowsLiveId);
                organizationId  = (exchangeRunspaceConfiguration.PartnerMode ? OrganizationId.ForestWideOrgId : exchangeRunspaceConfiguration.OrganizationId);
                organizationId2 = exchangeRunspaceConfiguration.OrganizationId;
                SecurityIdentifier value;
                exchangeRunspaceConfiguration.TryGetExecutingUserSid(out value);
                CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.ExecutingUserSid, value);
            }
            if (this.context.InvocationInfo != null && this.context.InvocationInfo.IsVerboseOn && !TaskLogger.IsSetupLogging)
            {
                string executingUserId             = (adobjectId != null) ? adobjectId.ToCanonicalName() : string.Empty;
                string executingUserOrganizationId = (organizationId != null) ? organizationId.ToString() : string.Empty;
                string currentOrganizationId       = (organizationId2 != null) ? organizationId2.ToString() : string.Empty;
                if (this.context.CommandShell != null)
                {
                    this.context.CommandShell.WriteVerbose(Strings.VerboseExecutingUserContext(executingUserId, executingUserOrganizationId, currentOrganizationId, (exchangeRunspaceConfiguration == null) ? Strings.DisabledString : Strings.EnabledString));
                }
            }
            this.context.ExchangeRunspaceConfig = exchangeRunspaceConfiguration;
            this.context.UserInfo = new TaskUserInfo(organizationId, organizationId2, adobjectId, executingUserIdentityName, executingWindowsLiveId);
        }
Esempio n. 2
0
        private static IPowerShellBudget AcquirePowerShellBudget(ExchangeRunspaceConfiguration configuration)
        {
            IPowerShellBudget  powerShellBudget;
            SecurityIdentifier callerSid;

            if (configuration.DelegatedPrincipal != null)
            {
                powerShellBudget = PowerShellBudget.Acquire(new DelegatedPrincipalBudgetKey(configuration.DelegatedPrincipal, BudgetType.PowerShell));
            }
            else if (!configuration.TryGetExecutingUserSid(out callerSid))
            {
                ADObjectId adobjectId;
                if (!configuration.TryGetExecutingUserId(out adobjectId))
                {
                    throw new ExecutingUserPropertyNotFoundException("ExecutingUserSid");
                }
                powerShellBudget = PowerShellBudget.AcquireFallback(adobjectId.ObjectGuid.ToString(), BudgetType.PowerShell);
            }
            else
            {
                ADObjectId rootOrgId;
                if (configuration.ExecutingUserOrganizationId == null || configuration.ExecutingUserOrganizationId.Equals(OrganizationId.ForestWideOrgId))
                {
                    rootOrgId = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest();
                }
                else
                {
                    rootOrgId = ADSystemConfigurationSession.GetRootOrgContainerId(configuration.ExecutingUserOrganizationId.PartitionId.ForestFQDN, null, null);
                }
                powerShellBudget = PowerShellBudget.Acquire(callerSid, BudgetType.PowerShell, ADSessionSettings.FromOrganizationIdWithoutRbacScopes(rootOrgId, configuration.ExecutingUserOrganizationId, configuration.ExecutingUserOrganizationId, true));
            }
            PowerShellThrottlingPolicyUpdater.RevertExpiredThrottlingPolicyIfNeeded(powerShellBudget);
            if (configuration.IsPowerShellWebService)
            {
                IPowerShellBudget result = new PswsBudgetWrapper(((BudgetWrapper <PowerShellBudget>)powerShellBudget).GetInnerBudget());
                if (powerShellBudget != null)
                {
                    powerShellBudget.Dispose();
                }
                return(result);
            }
            return(powerShellBudget);
        }
Esempio n. 3
0
        internal static GenericIdentity GetExecutingIdentityFromRunspace(ExchangeRunspaceConfiguration runspaceConfig)
        {
            if (runspaceConfig == null)
            {
                using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                {
                    return(new GenericSidIdentity(string.Empty, string.Empty, current.User));
                }
            }
            SecurityIdentifier sid;

            if (runspaceConfig.TryGetExecutingUserSid(out sid))
            {
                return(new GenericSidIdentity(string.Empty, string.Empty, sid));
            }
            if (!string.IsNullOrEmpty(runspaceConfig.ExecutingUserDisplayName))
            {
                return(new GenericIdentity(runspaceConfig.ExecutingUserDisplayName));
            }
            return(new GenericIdentity(runspaceConfig.IdentityName));
        }