Ejemplo n.º 1
0
        internal override Command.ExecutionState ExecuteCommand()
        {
            base.XmlResponse = base.GetCommandXmlStub();
            XmlNode provisionResponseNode = base.XmlResponse[this.RootNodeName];

            switch (ProvisionCommandPhaseBase.DetermineCallPhase(base.XmlRequest))
            {
            case ProvisionCommandPhaseBase.ProvisionPhase.PhaseOne:
            {
                ProvisionCommandPhaseOne provisionCommandPhaseOne = new ProvisionCommandPhaseOne(this);
                provisionCommandPhaseOne.Process(provisionResponseNode);
                break;
            }

            case ProvisionCommandPhaseBase.ProvisionPhase.PhaseTwo:
            {
                ProvisionCommandPhaseTwo provisionCommandPhaseTwo = new ProvisionCommandPhaseTwo(this);
                provisionCommandPhaseTwo.Process(provisionResponseNode);
                break;
            }

            default:
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolVersionMismatch, false)
                      {
                          ErrorStringForProtocolLogger = "Provision_InvalidCallType"
                      };
            }
            return(Command.ExecutionState.Complete);
        }
Ejemplo n.º 2
0
        private void ProcessPolicy(XmlNode response)
        {
            uint?headerPolicyKey = this.owningCommand.HeaderPolicyKey;

            this.owningCommand.GlobalInfo.ProvisionSupported = true;
            bool flag;

            Command.DetectPolicyChange(this.owningCommand.PolicyData, this.owningCommand.GlobalInfo, this.owningCommand.ProtocolVersion, out flag);
            if (!flag)
            {
                this.owningCommand.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DeviceNotFullyProvisionable");
                this.owningCommand.SetErrorResponse(HttpStatusCode.Forbidden, StatusCode.DeviceNotFullyProvisionable);
                this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                return;
            }
            if (!string.IsNullOrEmpty(this.requestPolicyType) && this.requestPolicyStatus != ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.NotPresent && this.requestPolicyKey != null)
            {
                if (!ProvisionCommandPhaseBase.IsValidPolicyType(this.requestPolicyType))
                {
                    this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                    this.responsePolicyType   = this.requestPolicyType;
                    this.responsePolicyStatus = ProvisionCommand.PolicyStatusCode.UnknownPolicyType;
                }
                else
                {
                    if (this.requestPolicyStatus < ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.MinValue || this.requestPolicyStatus > ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.AllowExternalDeviceManagement)
                    {
                        this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                        this.responseProvisionStatus = ProvisionCommand.ProvisionStatusCode.ProtocolError;
                        this.BuildPolicyResponse(response);
                        return;
                    }
                    if (this.requestPolicyStatus >= ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.AllowExternalDeviceManagement && this.owningCommand.ProtocolVersion < 121)
                    {
                        this.responseProvisionStatus = ProvisionCommand.ProvisionStatusCode.ProtocolError;
                        this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                        this.BuildPolicyResponse(response);
                        return;
                    }
                    if (this.requestPolicyKey == null)
                    {
                        this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                        this.responseProvisionStatus = ProvisionCommand.ProvisionStatusCode.ProtocolError;
                        this.BuildPolicyResponse(response);
                        return;
                    }
                    if (this.requestPolicyKey == this.owningCommand.GlobalInfo.PolicyKeyWaitingAck)
                    {
                        this.responsePolicyType   = this.requestPolicyType;
                        this.responsePolicyStatus = ProvisionCommand.PolicyStatusCode.Success;
                        this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = ProvisionCommandPhaseTwo.MapPolicyStatusCodeFromClientToDevicePolicyApplicationStatus(this.requestPolicyStatus);
                        IPolicyData policyData = this.owningCommand.PolicyData;
                        if (policyData != null)
                        {
                            if (this.requestPolicyStatus == ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.AllowExternalDeviceManagement && !policyData.AllowExternalDeviceManagement)
                            {
                                this.owningCommand.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternallyManagedDevicesNotAllowed");
                                this.owningCommand.SetErrorResponse(HttpStatusCode.Forbidden, StatusCode.ExternallyManagedDevicesNotAllowed);
                                return;
                            }
                            if (this.requestPolicyStatus == ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.MinValue || this.requestPolicyStatus == ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.AllowExternalDeviceManagement || (this.requestPolicyStatus == ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.PartialError && policyData.AllowNonProvisionableDevices))
                            {
                                this.responsePolicyKey = new uint?(this.owningCommand.GlobalInfo.PolicyKeyNeeded);
                                this.owningCommand.GlobalInfo.LastPolicyTime    = new ExDateTime?(ExDateTime.UtcNow);
                                this.owningCommand.GlobalInfo.PolicyKeyOnDevice = this.owningCommand.GlobalInfo.PolicyKeyNeeded;
                            }
                            else if (this.requestPolicyStatus == ProvisionCommandPhaseTwo.PolicyStatusCodeFromClient.PartialError && !policyData.AllowNonProvisionableDevices)
                            {
                                this.owningCommand.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DevicePartiallyProvisionableStrictPolicy");
                                this.owningCommand.SetErrorResponse(HttpStatusCode.Forbidden, StatusCode.DeviceNotFullyProvisionable);
                                this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
                                return;
                            }
                        }
                        else
                        {
                            this.responsePolicyKey = new uint?(0U);
                            this.owningCommand.GlobalInfo.PolicyKeyOnDevice = 0U;
                            this.owningCommand.GlobalInfo.LastPolicyTime    = new ExDateTime?(ExDateTime.UtcNow);
                        }
                    }
                    else
                    {
                        this.responsePolicyStatus = ProvisionCommand.PolicyStatusCode.PolicyKeyMismatch;
                        this.responsePolicyType   = this.requestPolicyType;
                    }
                }
                this.responseProvisionStatus = ProvisionCommand.ProvisionStatusCode.Success;
                this.BuildPolicyResponse(response);
                return;
            }
            this.owningCommand.GlobalInfo.DevicePolicyApplicationStatus = DevicePolicyApplicationStatus.NotApplied;
            this.responseProvisionStatus = ProvisionCommand.ProvisionStatusCode.ProtocolError;
            this.BuildPolicyResponse(response);
        }