protected IEnumerator <IAsyncResult> GetTableAclImpl(IAccountIdentifier identifier, string account, string tableName, TimeSpan timeout, RequestContext requestContext, AsyncIteratorContext <ContainerAclSettings> context) { Duration startingNow = Duration.StartingNow; if (identifier == null) { throw new ArgumentNullException("identifier"); } if (string.IsNullOrEmpty(account)) { throw new ArgumentException("account", "Cannot be null or empty"); } if (string.IsNullOrEmpty(tableName)) { throw new ArgumentException("tableName", "Cannot be null or empty"); } if (timeout <= TimeSpan.Zero) { throw new TimeoutException("Timed out in GetTableAcl"); } if (identifier is TableSignedAccessAccountIdentifier || identifier is AccountSasAccessIdentifier) { throw new NephosUnauthorizedAccessException("Signed access not supported for this request", AuthorizationFailureReason.InvalidOperationSAS); } IAsyncResult asyncResult = this.authorizationManager.BeginCheckAccess(identifier, account, tableName, null, PermissionLevel.ReadAcl, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("TableManager.GetTableAclImpl")); yield return(asyncResult); this.authorizationManager.EndCheckAccess(asyncResult); string str = account; string str1 = tableName; using (IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(str)) { using (ITableContainer tableContainer = storageAccount.CreateTableContainerInstance(str1)) { ContainerPropertyNames containerPropertyName = ContainerPropertyNames.LastModificationTime | ContainerPropertyNames.ServiceMetadata; tableContainer.Timeout = startingNow.Remaining(timeout); asyncResult = tableContainer.BeginGetProperties(containerPropertyName, null, CacheRefreshOptions.SkipAllCache, context.GetResumeCallback(), context.GetResumeState("TableManager.GetTableAclImpl")); yield return(asyncResult); tableContainer.EndGetProperties(asyncResult); try { context.ResultData = new ContainerAclSettings(tableContainer.ServiceMetadata); } catch (MetadataFormatException metadataFormatException1) { MetadataFormatException metadataFormatException = metadataFormatException1; throw new NephosStorageDataCorruptionException(string.Format("Error decoding Acl setting for {0}", RealServiceManager.GetResourceString(account, tableName)), metadataFormatException); } } } }
public ListContainersResultContainerProperties(IBaseBlobContainer container) { long num; if (container == null) { throw new ArgumentNullException("container"); } this.containerName = container.ContainerName; NephosAssertionException.Assert(container.LastModificationTime.HasValue); this.lastModifiedTime = container.LastModificationTime; if (container.ApplicationMetadata != null) { this.applicationMetadata = new NameValueCollection(); try { MetadataEncoding.Decode(container.ApplicationMetadata, this.applicationMetadata); } catch (MetadataFormatException metadataFormatException1) { MetadataFormatException metadataFormatException = metadataFormatException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { this.containerName }; throw new NephosStorageDataCorruptionException(string.Format(invariantCulture, "Error decoding application metadata for container {0}", objArray), metadataFormatException); } } if (container.LeaseInfo != null) { if (container.LeaseInfo.Type == LeaseType.ReadWrite && container.LeaseInfo.Duration.HasValue) { TimeSpan?duration = container.LeaseInfo.Duration; TimeSpan zero = TimeSpan.Zero; if ((duration.HasValue ? duration.GetValueOrDefault() <= zero : true)) { goto Label1; } this.leaseStatus = "locked"; goto Label0; } Label1: this.leaseStatus = "unlocked"; Label0: if (container.LeaseInfo.State.HasValue) { this.leaseState = LeaseStateStrings.LeaseStates[(int)container.LeaseInfo.State.Value]; if (container.LeaseInfo.State.Equals(Microsoft.Cis.Services.Nephos.Common.Storage.LeaseState.Leased)) { TimeSpan?nullable = container.LeaseInfo.Duration; TimeSpan timeSpan = TimeSpan.FromSeconds(4294967295); if ((!nullable.HasValue ? true : nullable.GetValueOrDefault() != timeSpan)) { this.leaseDuration = "fixed"; } else { this.leaseDuration = "infinite"; } } } } if (container.ServiceMetadata != null) { NameValueCollection nameValueCollection = new NameValueCollection(); try { MetadataEncoding.Decode(container.ServiceMetadata, nameValueCollection); } catch (MetadataFormatException metadataFormatException3) { MetadataFormatException metadataFormatException2 = metadataFormatException3; CultureInfo cultureInfo = CultureInfo.InvariantCulture; object[] objArray1 = new object[] { this.containerName }; throw new NephosStorageDataCorruptionException(string.Format(cultureInfo, "Error decoding service metadata for container {0}", objArray1), metadataFormatException2); } this.containerQuotaInGB = (long)RealServiceManager.MaxShareQuotaInGBPriorToLargeFileShareFeature; string str = nameValueCollection.Get(RealServiceManager.XSmbContainerQuotaMetadataName); if (str != null) { if (!long.TryParse(str, out num) || num < (long)RealServiceManager.MinShareQuotaInGB || num > this.containerQuotaInGB) { TimeSpan?nullable1 = null; AlertsManager.AlertOrLogException(string.Format("Invalid XsmbContainerQuota retrieved from servicemetadata for account {0}: {1}", this.accountNameForLogging, str), "InvalidXSMBContainerQuota", nullable1); } else { this.containerQuotaInGB = num; } } string str1 = nameValueCollection.Get("PublicAccess"); string str2 = nameValueCollection.Get("PublicAccess1"); if (str1 != null) { this.publicAccessLevel = str1; return; } if (str2 != null) { this.publicAccessLevel = str2; } } }
public ListBlobResultsBlobProperties(IBlobObject blobObject, string separator) { if (blobObject == null) { throw new ArgumentNullException("blobObject"); } this.blobName = blobObject.Name; this.containerName = blobObject.ContainerName; if (separator == null || blobObject.Type != Microsoft.Cis.Services.Nephos.Common.Storage.BlobType.None) { this.isActualBlob = true; this.contentType = blobObject.ContentType; NephosAssertionException.Assert(blobObject.LastModificationTime.HasValue); NephosAssertionException.Assert(blobObject.ContentLength.HasValue); this.lastModifiedTime = blobObject.LastModificationTime; this.size = blobObject.ContentLength; NameValueCollection nameValueCollection = null; if (blobObject.ServiceMetadata != null) { nameValueCollection = new NameValueCollection(); try { MetadataEncoding.Decode(blobObject.ServiceMetadata, nameValueCollection); } catch (MetadataFormatException metadataFormatException1) { MetadataFormatException metadataFormatException = metadataFormatException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { this.blobName }; throw new NephosStorageDataCorruptionException(string.Format(invariantCulture, "Error decoding service metadata for blob {0}", objArray), metadataFormatException); } this.contentEncoding = nameValueCollection[RealServiceManager.ContentEncodingTag]; this.contentLanguage = nameValueCollection[RealServiceManager.ContentLanguageTag]; this.cacheControl = nameValueCollection[RealServiceManager.CacheControlTag]; this.contentCrc64 = nameValueCollection[RealServiceManager.ContentCrc64Tag]; this.contentMD5 = nameValueCollection[RealServiceManager.ContentMD5Tag]; this.contentDisposition = nameValueCollection[RealServiceManager.ContentDispositionTag]; if (this.contentMD5 != null && this.contentMD5.Equals(RealServiceManager.EmptyContentMD5Value, StringComparison.OrdinalIgnoreCase)) { this.contentMD5 = null; } this.copyId = nameValueCollection[RealServiceManager.CopyIdTag]; this.copySource = nameValueCollection[RealServiceManager.CopySourceTag]; this.copyStatus = nameValueCollection[RealServiceManager.CopyStatusTag]; this.copyStatusDescription = nameValueCollection[RealServiceManager.CopyStatusDescriptionTag]; if (!string.IsNullOrEmpty(nameValueCollection[RealServiceManager.CopyProgressOffsetTag]) && !string.IsNullOrEmpty(nameValueCollection[RealServiceManager.CopyProgressTotalTag])) { this.copyProgress = string.Format("{0}/{1}", nameValueCollection[RealServiceManager.CopyProgressOffsetTag], nameValueCollection[RealServiceManager.CopyProgressTotalTag]); } this.copyCompletionTime = RealServiceManager.ParseDateTimeFromString(nameValueCollection[RealServiceManager.CopyCompletionTimeTag]); } if (blobObject.ApplicationMetadata != null) { this.metadata = new NameValueCollection(); try { MetadataEncoding.Decode(blobObject.ApplicationMetadata, this.metadata); } catch (MetadataFormatException metadataFormatException3) { MetadataFormatException metadataFormatException2 = metadataFormatException3; CultureInfo cultureInfo = CultureInfo.InvariantCulture; object[] objArray1 = new object[] { this.blobName }; throw new NephosStorageDataCorruptionException(string.Format(cultureInfo, "Error decoding application metadata for blob {0}", objArray1), metadataFormatException2); } } this.blobType = BlobTypeStrings.GetString(blobObject.Type); if (blobObject.LeaseInfo != null) { if (blobObject.LeaseInfo.Type == LeaseType.ReadWrite && blobObject.LeaseInfo.Duration.HasValue) { TimeSpan?duration = blobObject.LeaseInfo.Duration; TimeSpan zero = TimeSpan.Zero; if ((duration.HasValue ? duration.GetValueOrDefault() <= zero : true)) { goto Label1; } this.leaseStatus = "locked"; goto Label0; } Label1: this.leaseStatus = "unlocked"; Label0: if (blobObject.LeaseInfo.State.HasValue) { this.leaseState = LeaseStateStrings.LeaseStates[(int)blobObject.LeaseInfo.State.Value]; if (blobObject.LeaseInfo.State.Equals(Microsoft.Cis.Services.Nephos.Common.Storage.LeaseState.Leased)) { TimeSpan?nullable = blobObject.LeaseInfo.Duration; TimeSpan timeSpan = TimeSpan.FromSeconds(4294967295); if ((!nullable.HasValue ? true : nullable.GetValueOrDefault() != timeSpan)) { this.leaseDuration = "fixed"; } else { this.leaseDuration = "infinite"; } } } } this.snapshot = blobObject.Snapshot; if (blobObject.Type != Microsoft.Cis.Services.Nephos.Common.Storage.BlobType.IndexBlob) { this.sequenceNumber = null; } else { NephosAssertionException.Assert(blobObject.SequenceNumber.HasValue, "SequenceNumber must be present for PageBlob's."); this.sequenceNumber = blobObject.SequenceNumber; } this.isBlobEncrypted = blobObject.IsBlobEncrypted; this.isIncrementalCopy = blobObject.IsIncrementalCopy; if (this.isIncrementalCopy && nameValueCollection != null) { this.lastCopySnapshot = RealServiceManager.ParseDateTimeFromString(nameValueCollection[RealServiceManager.LastCopySnapshotTag]); } } }
private IEnumerator <IAsyncResult> AuthenticateImpl(IStorageAccount storageAccount, RequestContext requestContext, NephosUriComponents uriComponents, AuthenticationManager.GetStringToSignCallback getStringToSignCallback, TimeSpan timeout, AsyncIteratorContext <IAuthenticationResult> context) { bool flag; bool flag1; SignedAccessHelper queueSignedAccessHelper; IStorageAccount operationStatus; ContainerAclSettings containerAclSetting; string signedVersion = null; Duration startingNow = Duration.StartingNow; NameValueCollection queryParameters = requestContext.QueryParameters; if (AuthenticationManager.IsInvalidAccess(requestContext)) { throw new InvalidAuthenticationInfoException("Ambiguous authentication scheme credentials providedRequest contains authentication credentials for signed access and authenticated access"); } bool flag2 = AuthenticationManager.IsAuthenticatedAccess(requestContext); bool flag3 = AuthenticationManager.IsSignatureAccess(requestContext); flag = (!flag2 ? false : AuthenticationManager.IsAuthenticatedAccess(requestContext, "SignedKey")); bool flag4 = flag; flag1 = (flag2 ? false : !flag3); if ((!flag2 || flag4) && !flag1) { NephosAssertionException.Assert((flag3 ? true : flag4)); bool flag5 = (flag3 ? false : flag4); if (!AuthenticationManager.IsAccountSasAccess(requestContext.QueryParameters)) { queueSignedAccessHelper = new QueueSignedAccessHelper(requestContext, uriComponents, flag5); } else { if (flag5) { throw new AuthenticationFailureException("SignedKey is not supported with account-level SAS."); } queueSignedAccessHelper = new AccountSasHelper(requestContext, uriComponents); } queueSignedAccessHelper.ParseAccessPolicyFields(flag5); queueSignedAccessHelper.PerformSignedAccessAuthenticationFirstPhaseValidations(); AccountIdentifier signedAccessAccountIdentifier = null; if (!flag5) { byte[] sign = queueSignedAccessHelper.ComputeUrlDecodedUtf8EncodedStringToSign(); if (storageAccount == null || !string.Equals(storageAccount.Name, uriComponents.AccountName)) { try { operationStatus = this.storageManager.CreateAccountInstance(uriComponents.AccountName); if (requestContext != null) { operationStatus.OperationStatus = requestContext.OperationStatus; } } catch (ArgumentOutOfRangeException argumentOutOfRangeException) { throw new AuthenticationFailureException(string.Format(CultureInfo.InvariantCulture, "The account name is invalid.", new object[0])); } operationStatus.Timeout = startingNow.Remaining(timeout); IAsyncResult asyncResult = operationStatus.BeginGetProperties(AccountPropertyNames.All, null, context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl")); yield return(asyncResult); try { operationStatus.EndGetProperties(asyncResult); } catch (AccountNotFoundException accountNotFoundException1) { AccountNotFoundException accountNotFoundException = accountNotFoundException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] name = new object[] { operationStatus.Name }; throw new AuthenticationFailureException(string.Format(invariantCulture, "Cannot find the claimed account when trying to GetProperties for the account {0}.", name), accountNotFoundException); } catch (Exception exception1) { Exception exception = exception1; IStringDataEventStream warning = Logger <IRestProtocolHeadLogger> .Instance.Warning; object[] objArray = new object[] { operationStatus.Name, exception }; warning.Log("Rethrow exception when trying to GetProperties for the account {0}: {1}", objArray); throw; } } else { operationStatus = storageAccount; } if (!queueSignedAccessHelper.ComputeSignatureAndCompare(sign, operationStatus.SecretKeysV3)) { throw new AuthenticationFailureException(string.Concat("Signature did not match. String to sign used was ", (new UTF8Encoding()).GetString(sign))); } NephosAssertionException.Assert(queueSignedAccessHelper.KeyUsedForSigning != null, "Key used for signing cannot be null"); signedAccessAccountIdentifier = queueSignedAccessHelper.CreateAccountIdentifier(operationStatus); if (storageAccount != operationStatus) { operationStatus.Dispose(); } } else { IAsyncResult asyncResult1 = this.nephosAuthenticationManager.BeginAuthenticate(storageAccount, requestContext, uriComponents, getStringToSignCallback, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl")); yield return(asyncResult1); IAuthenticationResult authenticationResult = this.nephosAuthenticationManager.EndAuthenticate(asyncResult1); signedAccessAccountIdentifier = new SignedAccessAccountIdentifier(authenticationResult.AccountIdentifier); } signedVersion = queueSignedAccessHelper.SignedVersion; if (queueSignedAccessHelper.IsRevocableAccess) { using (IQueueContainer queueContainer = this.storageManager.CreateQueueContainerInstance(uriComponents.AccountName, uriComponents.ContainerName)) { if (requestContext != null) { queueContainer.OperationStatus = requestContext.OperationStatus; } ContainerPropertyNames containerPropertyName = ContainerPropertyNames.ServiceMetadata; queueContainer.Timeout = startingNow.Remaining(timeout); IAsyncResult asyncResult2 = queueContainer.BeginGetProperties(containerPropertyName, null, context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl")); yield return(asyncResult2); try { queueContainer.EndGetProperties(asyncResult2); } catch (Exception exception3) { Exception exception2 = exception3; if (exception2 is ContainerNotFoundException) { throw new AuthenticationFailureException("Error locating SAS identifier", exception2); } IStringDataEventStream stringDataEventStream = Logger <IRestProtocolHeadLogger> .Instance.Warning; object[] accountName = new object[] { uriComponents.AccountName, uriComponents.ContainerName, exception2 }; stringDataEventStream.Log("Rethrow exception when trying to fetch SAS identifier account {0} container {1} : {2}", accountName); throw; } try { containerAclSetting = new ContainerAclSettings(queueContainer.ServiceMetadata); } catch (MetadataFormatException metadataFormatException1) { MetadataFormatException metadataFormatException = metadataFormatException1; throw new NephosStorageDataCorruptionException(string.Format("Error decoding Acl setting for container {0}", uriComponents.ContainerName), metadataFormatException); } } try { queueSignedAccessHelper.ValidateAndDeriveEffectiveAccessPolicy(queueSignedAccessHelper.LocateSasIdentifier(containerAclSetting.SASIdentifiers)); queueSignedAccessHelper.PerformSignedAccessAuthenticationSecondPhaseValidations(); signedAccessAccountIdentifier.Initialize(queueSignedAccessHelper); context.ResultData = new AuthenticationResult(signedAccessAccountIdentifier, signedVersion, true); } catch (FormatException formatException) { throw new AuthenticationFailureException("Signature fields not well formed.", formatException); } } else { signedAccessAccountIdentifier.Initialize(queueSignedAccessHelper); context.ResultData = new AuthenticationResult(signedAccessAccountIdentifier, signedVersion, true); } } else { IAsyncResult asyncResult3 = this.nephosAuthenticationManager.BeginAuthenticate(storageAccount, requestContext, uriComponents, getStringToSignCallback, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("XFEQueueAuthenticationManager.AuthenticateImpl")); yield return(asyncResult3); context.ResultData = this.nephosAuthenticationManager.EndAuthenticate(asyncResult3); } }