/// <summary> /// Creates a file from a list of strings; each string is placed on a line in the file. /// </summary> /// <param name="TempFileName">Name of response file</param> /// <param name="Lines">List of lines to write to the response file</param> public static FileReference Create(FileReference TempFileName, List<string> Lines, CreateOptions Options = CreateOptions.None) { FileInfo TempFileInfo = new FileInfo(TempFileName.FullName); if (TempFileInfo.Exists) { if ((Options & CreateOptions.WriteEvenIfUnchanged) != CreateOptions.WriteEvenIfUnchanged) { string Body = string.Join(Environment.NewLine, Lines); // Reuse the existing response file if it remains unchanged string OriginalBody = File.ReadAllText(TempFileName.FullName); if (string.Equals(OriginalBody, Body, StringComparison.Ordinal)) { return TempFileName; } } // Delete the existing file if it exists and requires modification TempFileInfo.IsReadOnly = false; TempFileInfo.Delete(); TempFileInfo.Refresh(); } FileItem.CreateIntermediateTextFile(TempFileName, string.Join(Environment.NewLine, Lines)); return TempFileName; }
public void Trigger(ExactTargetTriggeredEmail exactTargetTriggeredEmail, RequestQueueing requestQueueing = RequestQueueing.No, Priority priority = Priority.Normal) { var clientId = _config.ClientId; var client = SoapClientFactory.Manufacture(_config); var subscriber = new Subscriber { EmailAddress = exactTargetTriggeredEmail.EmailAddress, SubscriberKey = exactTargetTriggeredEmail.SubscriberKey ?? exactTargetTriggeredEmail.EmailAddress, Attributes = exactTargetTriggeredEmail.ReplacementValues.Select(value => new Attribute { Name = value.Key, Value = value.Value }).ToArray() }; // Add sender information if specified. This will send the email with FromAddress in the sender field. // Official doco here under the section "Determining the From Information at Send Time": // https://help.exacttarget.com/en/technical_library/web_service_guide/triggered_email_scenario_guide_for_developers/#Determining_the_From_Information_at_Send_Time if (!string.IsNullOrEmpty(exactTargetTriggeredEmail.FromAddress) && !string.IsNullOrEmpty(exactTargetTriggeredEmail.FromName)) { subscriber.Owner = new Owner() { FromAddress = exactTargetTriggeredEmail.FromAddress, FromName = exactTargetTriggeredEmail.FromName }; } var subscribers = new List<Subscriber> { subscriber }; var tsd = new TriggeredSendDefinition { Client = clientId.HasValue ? new ClientID { ID = clientId.Value, IDSpecified = true } : null, CustomerKey = exactTargetTriggeredEmail.ExternalKey }; var ts = new TriggeredSend { Client = clientId.HasValue ? new ClientID { ID = clientId.Value, IDSpecified = true } : null, TriggeredSendDefinition = tsd, Subscribers = subscribers.ToArray() }; var co = new CreateOptions { RequestType = requestQueueing == RequestQueueing.No ? RequestType.Synchronous : RequestType.Asynchronous, RequestTypeSpecified = true, QueuePriority = priority == Priority.High ? ExactTargetApi.Priority.High : ExactTargetApi.Priority.Medium, QueuePrioritySpecified = true }; string requestId, status; var result = client.Create( co, new APIObject[] { ts }, out requestId, out status); ExactTargetResultChecker.CheckResult(result.FirstOrDefault()); //we expect only one result because we've sent only one APIObject }
/// <summary> /// Creates a new item for the given item type. /// </summary> /// <param name="context"> /// The designer's editing context. /// </param> /// <param name="itemType"> /// The type of item to create. /// </param> /// <param name="options"> /// A set of create options to use when creating the item. The default value is CreateOptions.None. /// </param> /// <param name="arguments"> /// An optional array of arguments that should be passed to the constructor of the item. /// </param> /// <returns> /// The newly created item type. /// </returns> /// <exception cref="ArgumentNullException">if itemType or context is null.</exception> /// <exception cref="InvalidOperationException">if there is no editing model in the context that can create new items.</exception> public static ModelItem CreateItem(EditingContext context, Type itemType, CreateOptions options, params object[] arguments) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemType == null) throw FxTrace.Exception.ArgumentNull("itemType"); if (!EnumValidator.IsValid(options)) throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException("options")); ModelService ms = context.Services.GetRequiredService<ModelService>(); return ms.InvokeCreateItem(itemType, options, arguments); }
public List<SendResult> Send(List<DataForAPI> entities) { List<SendResult> list = new List<SendResult>(); _service = new ExactTargetServiceProxy(); _options = InitCreateOptions(); foreach (var entity in entities) { var subscriber = CreateSubscriber(entity); TriggeredSend ts = CreateTriggeredSendDefinitions(subscriber, entity.TriggeredSendDefinition); string errorMessage = ProcessTriggeredSend(ts, _options); var result = base.FillSendResult(errorMessage, entity.SourceEntity); list.Add(result); } return list; }
internal static MessageStatus WorkaroundCreateFile(FileNameStatus fileNameStatus, CreateOptions createOption, FileAccess desiredAccess, FileType openFileType, FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site) { if (openFileType == FileType.DirectoryFile && desiredFileAttribute == FileAttribute.TEMPORARY) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(507, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.DELETE_ON_CLOSE && (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(507, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING && (desiredAccess == FileAccess.FILE_APPEND_DATA || desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } return returnedStatus; }
protected override ModelItem CreateItem(Type itemType, CreateOptions options, params object[] arguments) { Object instance = Activator.CreateInstance(itemType, arguments); return modelTreeManager.CreateModelItem(null, instance); }
/// <summary> /// Creates a ModelItem for a given type. This method is called by /// ModelFactory when the user wishes to create a new item. /// </summary> internal ModelItem InvokeCreateItem(Type itemType, CreateOptions options, params object[] arguments) { return CreateItem(itemType, options, arguments); }
// // ctor // /// <summary> /// </summary> protected DBCreateIndexQuery() { this.ColumnOrders = new DBOrderList(); Options = CreateOptions.None; }
public static MessageStatus CheckExistingFileAccess( FileType openFileType, FileAttribute fileAttribute, FileAccess desiredAccess, CreateOptions createOption, CreateOptions existingOpenModeCreateOption, StreamTypeNameToOPen streamTypeNameToOPen, ShareAccess shareAccess, ShareAccess existOpenShareModeShareAccess) { //If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && //(DesiredAccess.FILE_WRITE_DATA)) if (openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && (fileAttribute == FileAttribute.READONLY && desiredAccess == FileAccess.FILE_WRITE_DATA)) { Helper.CaptureRequirement(2422, @"[In Algorithm to Check Access to an Existing File]Pseudocode for these checks is as follows: If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && (DesiredAccess.FILE_APPEND_DATA)), then return STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && //(DesiredAccess.FILE_APPEND_DATA)) if (openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && (fileAttribute == FileAttribute.READONLY && desiredAccess == FileAccess.FILE_APPEND_DATA)) { Helper.CaptureRequirement(53, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:] If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && (DesiredAccess.FILE_WRITE_DATA )), then return STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If ((File.FileAttributes.FILE_ATTRIBUTE_READONLY ) && //CreateOptions.FILE_DELETE_ON_CLOSE) if (fileAttribute == FileAttribute.READONLY && (createOption == CreateOptions.DELETE_ON_CLOSE)) { Helper.CaptureRequirement(54, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:] If ((File.FileAttributes.FILE_ATTRIBUTE_READONLY) && CreateOptions.FILE_DELETE_ON_CLOSE), then return STATUS_CANNOT_DELETE."); return MessageStatus.CANNOT_DELETE; } //If ((File.Volume.IsReadOnly) && //CreateOptions.FILE_DELETE_ON_CLOSE) if (isFileVolumeReadOnly && (createOption == CreateOptions.DELETE_ON_CLOSE)) { Helper.CaptureRequirement(2423, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:] If (( File.Volume.IsReadOnly) && CreateOptions.FILE_DELETE_ON_CLOSE), then return STATUS_CANNOT_DELETE."); return MessageStatus.CANNOT_DELETE; } //If Open.RemainingDesiredAccess is nonzero if (gOpenRemainingDesiredAccess != FileAccess.None) { //If Open.RemainingDesiredAccess.MAXIMUM_ALLOWED if ((gOpenRemainingDesiredAccess & FileAccess.MAXIMUM_ALLOWED) != 0) { //For each Access Flag in FILE_ALL_ACCESS, the object store MUST set Open.GrantedAccess. //Access if SecurityContext has Access based on File.SecurityDescriptor //gOpenGrantedAccess = FileAccess.FILE_ALL_ACCESS; //If File.FileAttributes.FILE_ATTRIBUTE_READONLY or File.Volume.IsReadOnly if ((fileAttribute == FileAttribute.READONLY) || isFileVolumeReadOnly) { //then the object store MUST clear (FILE_WRITE_DATA | FILE_APPEND_DATA | //FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD) from Open.GrantedAccess. gOpenGrantedAccess = gOpenGrantedAccess & (~(FileAccess.FILE_WRITE_DATA | FileAccess.FILE_APPEND_DATA | FileAccess.FILE_ADD_SUBDIRECTORY | FileAccess.FILE_DELETE_CHILD)); } } else { //For each Access Flag in Open.RemainingDesired.Access, the object store MUST set //Open.GrantedAccess.Access if SecurityContext has Access based on File.SecurityDescriptor gOpenGrantedAccess = gOpenRemainingDesiredAccess; } //If (Open.RemainingDesiredAccess.MAXIMUM_ALLOWED || Open.RemainingDesiredAccess.DELETE), //the object store MUST set Open.GrantedAccess.DELETE if AccessCheck( SecurityContext, //Open.Link.ParentFile.SecurityDescriptor, FILE_DELETE_CHILD ) returns true if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED || gOpenRemainingDesiredAccess == FileAccess.DELETE) { //the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES gOpenGrantedAccess = FileAccess.DELETE; } //If (Open.RemainingDesiredAccess.MAXIMUM_ALLOWED || Open.RemainingDesiredAccess. //FILE_READ_ATTRIBUTES), the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES //if AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_LIST_DIRECTORY ) //returns true if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED || gOpenRemainingDesiredAccess == FileAccess.FILE_READ_ATTRIBUTES) { //the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES gOpenGrantedAccess = FileAccess.FILE_READ_ATTRIBUTES; } //Open.RemainingDesiredAccess &= ~(Open.GrantedAccess | MAXIMUM_ALLOWED) gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~(gOpenGrantedAccess | FileAccess.MAXIMUM_ALLOWED)); //If Open.RemainingDesiredAccess is nonzero, then return STATUS_ACCESS_DENIED. if (gOpenRemainingDesiredAccess != FileAccess.None) { Helper.CaptureRequirement(61, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:, If Open.RemainingDesiredAccess is nonzero:]If Open.RemainingDesiredAccess is nonzero, then return STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } } //If Open.SharingMode.FILE_SHARE_DELETE is FALSE and Open.GrantedAccess contains any //one or more of (FILE_EXECUTE | FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA): if ((gOpenSharingMode & ShareAccess.FILE_SHARE_DELETE) != 0 && (gOpenGrantedAccess & (FileAccess.FILE_EXECUTE | FileAccess.FILE_READ_DATA | FileAccess.FILE_WRITE_DATA | FileAccess.FILE_APPEND_DATA)) != 0) { //For each ExistingOpen is Open.File.OpenList: //If ExistingOpen.Mode.FILE_DELETE_ON_CLOSE is true and ExistingOpen.Stream.StreamType is //DirectoryStream if ((existingOpenModeCreateOption & CreateOptions.DELETE_ON_CLOSE) != 0 && openFileType == FileType.DirectoryFile) { Helper.CaptureRequirement(68, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:] Pseudocode for these checks is as follows:If Open.SharingMode.FILE_SHARE_DELETE is FALSE and Open. GrantedAccess contains any one or more of (FILE_EXECUTE | FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA): For each ExistingOpen is Open.File.OpenList: If ExistingOpen.Mode.FILE_DELETE_ON_CLOSE is TRUE and ExistingOpen.Stream.StreamType is DirectoryStream, then return STATUS_SHARING_VIOLATION."); return MessageStatus.SHARING_VIOLATION; } } //If Open.GrantedAccess.DELETE is true and Open.Stream.StreamType is DirectoryStream if ((gOpenGrantedAccess & FileAccess.DELETE) != 0 && (streamTypeNameToOPen == StreamTypeNameToOPen.INDEX_ALLOCATION)) { //For each ExistingOpen in Open.File.OpenList: //If ExistingOpen.SharingMode.FILE_SHARE_DELETE is FALSE if (existOpenShareModeShareAccess != ShareAccess.FILE_SHARE_DELETE) { Helper.CaptureRequirement(66, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:] If Open.GrantedAccess.DELETE is TRUE and Open.Stream.StreamType is DirectoryStream:For each ExistingOpen in Open.File.OpenList: If ExistingOpen.SharingMode.FILE_SHARE_DELETE is FALSE, then return STATUS_SHARING_VIOLATION."); return MessageStatus.SHARING_VIOLATION; } } Helper.CaptureRequirement(65, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:, if the sharing conflicts check has no violation]Return STATUS_SUCCESS."); return MessageStatus.SUCCESS; }
public void CreateTable(Table table, CreateOptions options = null) { var commandText = _commandFormatter.CreateTable(table, options); Execute(cmd => { cmd.ExecuteNonQuery(); }, commandText); }
/// <summary> /// Creates a ModelItem for a given type. This method is called by /// ModelFactory when the user wishes to create a new item. /// </summary> /// <param name="itemType"> /// The type of item to create. /// </param> /// <param name="options"> /// Creation options. You can specify if you would like to initialize /// default values for an item. /// </param> /// <param name="arguments"> /// An array of arguments to the constructor of the item. /// </param> /// <returns>The newly created model item.</returns> /// <exception cref="ArgumentNullException">if itemType is null</exception> protected abstract ModelItem CreateItem(Type itemType, CreateOptions options, params object[] arguments);
public async Task <IFileSystemInfo> CreateAsync(SqlItem parentItem, string name, CreateOptions options = null) { var item = await CreateSqlItemAsync(parentItem, name, options).ConfigureAwait(false); return(item); }
internal static long WorkaroundReadFileForByteRead(CreateOptions gOpenMode, long byteCount, long readCount, ITestSite site) { if ((gOpenMode & CreateOptions.NO_INTERMEDIATE_BUFFERING) != 0) { readCount = FsaUtility.TransferExpectedResult<long>(692, byteCount, readCount, site); } return readCount; }
internal static MessageStatus WorkaroundReadFile(CreateOptions gOpenMode, long byteCount, MessageStatus returnedStatus, ITestSite site) { long gOpenFileVolumeSize = long.Parse(site.Properties["FSA.OpenFileVolumeSize"]); if ((byteCount % gOpenFileVolumeSize) != 0) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(669, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if ((gOpenMode & CreateOptions.NO_INTERMEDIATE_BUFFERING) != 0) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(693, MessageStatus.SUCCESS, returnedStatus, site); } return returnedStatus; }
internal static MessageStatus WorkaroundOpenExistingFile(ShareAccess shareAccess, FileAccess desiredAccess, bool streamFound, bool isSymbolicLink, FileType openFileType, FileNameStatus fileNameStatus, CreateOptions existingOpenModeCreateOption, ShareAccess existOpenShareModeShareAccess, FileAccess existOpenDesiredAccess, CreateOptions createOption, CreateDisposition createDisposition, StreamTypeNameToOPen streamTypeNameToOPen, FileAttribute fileAttribute, FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site) { if (shareAccess == ShareAccess.FILE_SHARE_READ && desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY && !streamFound && !isSymbolicLink && openFileType == FileType.DataFile && fileNameStatus == FileNameStatus.Normal && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenShareModeShareAccess == ShareAccess.FILE_SHARE_READ && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING && createDisposition == CreateDisposition.OPEN_IF && streamTypeNameToOPen == StreamTypeNameToOPen.NULL && fileAttribute == FileAttribute.NORMAL && desiredFileAttribute == FileAttribute.NORMAL) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.DELETE_ON_CLOSE && (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (streamFound && !isSymbolicLink && openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.DIRECTORY_FILE && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.DIRECTORY_FILE) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.ACCESS_VIOLATION, returnedStatus, site); } else if (!streamFound && !isSymbolicLink && openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NON_DIRECTORY_FILE && fileAttribute == FileAttribute.READONLY) { returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.ACCESS_DENIED, returnedStatus, site); } return returnedStatus; }
/// <summary> /// Create one alternate data stream on the newly created file /// </summary> /// <param name="fileType">The newly created file type: DataFile, DirectoryFile</param> private void AlternateDataStream_CreateStream(FileType fileType) { dataStreamList = new Dictionary<string, long>(); long bytesToWrite = 0; long bytesWritten = 0; //Step 1: Create a new File, it could be a DataFile or a DirectoryFile fileName = this.fsaAdapter.ComposeRandomFileName(8); createFileType = (fileType == FileType.DataFile ? CreateOptions.NON_DIRECTORY_FILE : CreateOptions.DIRECTORY_FILE); BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Create a file with type: " + fileType.ToString() + " and name: " + fileName, ++testStep); status = this.fsaAdapter.CreateFile( fileName, FileAttribute.NORMAL, createFileType, FileAccess.GENERIC_ALL, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE | ShareAccess.FILE_SHARE_DELETE, CreateDisposition.OPEN_IF); this.fsaAdapter.AssertIfNotSuccess(status, "Create file operation failed"); //Step 2: Write some bytes into the Unnamed Data Stream in the newly created file if (fileType == FileType.DataFile) { //Write some bytes into the DataFile. bytesToWrite = 1024; bytesWritten = 0; dataStreamList.Add("::$DATA", bytesToWrite); BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Write the file with " + bytesToWrite + " bytes data.", ++testStep); status = this.fsaAdapter.WriteFile(0, bytesToWrite, out bytesWritten); this.fsaAdapter.AssertIfNotSuccess(status, "Write data to file operation failed."); } else { //Do not write data into DirectoryFile. bytesToWrite = 0; BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Do not write data into DirectoryFile.", ++testStep); } //Step 3: Create an Alternate Data Stream <Stream1> in the newly created file dataStreamName1 = this.fsaAdapter.ComposeRandomFileName(8); BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Create an Alternate Data Stream with name: " + dataStreamName1 + " on this file.", ++testStep); status = this.fsaAdapter.CreateFile( fileName + ":" + dataStreamName1 + ":$DATA", FileAttribute.NORMAL | FileAttribute.INTEGRITY_STREAM, // Set Integrity field CreateOptions.NON_DIRECTORY_FILE, FileAccess.GENERIC_ALL, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE | ShareAccess.FILE_SHARE_DELETE, CreateDisposition.OPEN_IF); this.fsaAdapter.AssertIfNotSuccess(status, "Create Alternate Data Stream operation failed"); //Step 4: Write some bytes into the Alternate Data Stream <Stream1> in the file bytesToWrite = 2048; bytesWritten = 0; dataStreamList.Add(":" + dataStreamName1 + ":$DATA", bytesToWrite); BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Write the stream with " + bytesToWrite + " bytes data.", ++testStep); status = this.fsaAdapter.WriteFile(0, bytesToWrite, out bytesWritten); this.fsaAdapter.AssertIfNotSuccess(status, "Write data to stream operation failed."); }
private void AlternateDataStream_DeleteStream(FileType fileType) { //Prerequisites: Create streams on a newly created file // Step 1: Delete the Alternate Data Stream <Stream2> BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Delete the Alternate Data Stream with name: " + dataStreamName2, ++testStep); dataStreamList.Remove(":" + dataStreamName2 + ":$DATA"); BaseTestSite.Log.Add(LogEntryKind.Debug, "Set FileDispositionInformation.DeletePending to 1."); FileDispositionInformation fileDispositionInfo = new FileDispositionInformation(); fileDispositionInfo.DeletePending = 1; List<byte> byteList = new List<byte>(); byteList.AddRange(BitConverter.GetBytes(fileDispositionInfo.DeletePending)); status = this.fsaAdapter.SetFileInformation( FileInfoClass.FILE_DISPOSITION_INFORMATION, byteList.ToArray()); this.fsaAdapter.AssertIfNotSuccess(status, "Set FileDispositionInformation.DeletePending operation failed"); BaseTestSite.Log.Add(LogEntryKind.Debug, "Close the open to delete the stream."); status = this.fsaAdapter.CloseOpen(); this.fsaAdapter.AssertIfNotSuccess(status, "Close open operation failed"); this.fsaAdapter.AssertIfNotSuccess(status, "Delete the Alternate Data Stream operation failed"); //Step 2: Create a new open for the File, it could be a DataFile or a DirectoryFile BaseTestSite.Log.Add(LogEntryKind.TestStep, "{0}. Create a new open for the file with type: " + fileType.ToString() + " and name: " + fileName, ++testStep); createFileType = (fileType == FileType.DataFile ? CreateOptions.NON_DIRECTORY_FILE : CreateOptions.DIRECTORY_FILE); status = this.fsaAdapter.CreateFile( fileName, FileAttribute.NORMAL, createFileType, FileAccess.GENERIC_ALL, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE | ShareAccess.FILE_SHARE_DELETE, CreateDisposition.OPEN_IF); this.fsaAdapter.AssertIfNotSuccess(status, "Create file operation failed"); }
public static MessageStatus OpenFileinitial( FileAccess desiredAccess, ShareAccess shareAccess, CreateOptions createOption, CreateDisposition createDisposition, FileAttribute fileAttribute, StreamFoundType streamFoundType, SymbolicLinkType symbolicLinkType, StreamTypeNameToOPen streamTypeNameToOPen, FileType openFileType, FileNameStatus fileNameStatus) { #region phase 1 Parameter Validation //If DesiredAccess is not a valid value as specified in MS-SMB2 section 2.2.13.1 if (desiredAccess == FileAccess.None) { Helper.CaptureRequirement(366, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]If any of the bits in the mask 0x0CE0FE00 are set, the operation MUST be failed with STATUS_ACCESS_DENIED."); //If DesiredAccess is zero Helper.CaptureRequirement(377, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]If DesiredAccess is zero, the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If ShareAccess is not valid values for a file object as specified in MS-SMB2 section 2.2.13 if (shareAccess == ShareAccess.NOT_VALID_VALUE) { Helper.CaptureRequirement(2370, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If ShareAccess are not valid values for a file object as specified in [MS-SMB2] section 2.2.13."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions is not valid values for a file object as specified in MS-SMB2 section 2.2.13 if (createOption == CreateOptions.NOT_VALID_VALUE) { Helper.CaptureRequirement(2371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions are not valid values for a file object as specified in [MS-SMB2] section 2.2.13."); return MessageStatus.INVALID_PARAMETER; } //If CreateDisposition is not valid values for a file object as specified in MS-SMB2 section 2.2.13 if (createDisposition == CreateDisposition.NOT_VALID_VALUE) { Helper.CaptureRequirement(2372, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateDisposition are not valid values for a file object as specified in [MS-SMB2] section 2.2.13."); return MessageStatus.INVALID_PARAMETER; } //If FileAttributes is not valid values for a file object as specified in MS-SMB2 section 2.2.13 if (fileAttribute == FileAttribute.NOT_VALID_VALUE) { Helper.CaptureRequirement(404, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If FileAttributes are not valid values for a file object as specified in [MS-SMB2] section 2.2.13."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE. //65 indicates CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE if (createOption == (CreateOptions.DIRECTORY_FILE | CreateOptions.NON_DIRECTORY_FILE)) { Helper.CaptureRequirement(368, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE. //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT && desiredAccess == FileAccess.FILE_READ_DATA) { Helper.CaptureRequirement(369, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE."); return MessageStatus.INVALID_PARAMETER; } //If Create.FILE_SYNCHRONOUS_IO_NONALERT && !DesiredAccess.SYNCHRONIZE. //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT && desiredAccess == FileAccess.FILE_READ_DATA) { Helper.CaptureRequirement(2373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If Create.FILE_SYNCHRONOUS_IO_NONALERT&& !DesiredAccess.SYNCHRONIZE."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE. if (createOption == CreateOptions.DELETE_ON_CLOSE && (desiredAccess == FileAccess.FILE_READ_DATA)) { Helper.CaptureRequirement(371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE."); return MessageStatus.INVALID_PARAMETER; } //CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT //48 indicates CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT)) { Helper.CaptureRequirement(373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE. if (createOption == CreateOptions.DIRECTORY_FILE && createDisposition == CreateDisposition.OVERWRITE) { Helper.CaptureRequirement(2375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == NONE . if (createOption == CreateOptions.DIRECTORY_FILE && createDisposition == CreateDisposition.SUPERSEDE) { Helper.CaptureRequirement(2374, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == SUPERSEDE ."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF. if (createOption == CreateOptions.DIRECTORY_FILE && createDisposition == CreateDisposition.OVERWRITE_IF) { Helper.CaptureRequirement(2376, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF)."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER //if ((createOption & (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) != 0) //1048832 indicates CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) { Helper.CaptureRequirement(375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER."); return MessageStatus.INVALID_PARAMETER; } //If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA. if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING && desiredAccess == FileAccess.FILE_APPEND_DATA) { Helper.CaptureRequirement(376, @"[In Application Requests an Open of a File ,Phase 1 - Parameter Validation:] The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions: If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA."); return MessageStatus.INVALID_PARAMETER; } //If PathName is not valid as specified in [MS-FSCC] section 2.1.5. if (fileNameStatus == FileNameStatus.NotPathNameValid) { Helper.CaptureRequirement(379, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions: If PathName is not valid as specified in [MS-FSCC] section 2.1.5."); return MessageStatus.OBJECT_NAME_INVALID; } //If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is true if (fileNameStatus == FileNameStatus.BlacklashName && createOption == CreateOptions.NON_DIRECTORY_FILE && desiredAccess == FileAccess.FILE_READ_DATA) { Helper.CaptureRequirement(380, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows: Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions: If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE."); return MessageStatus.OBJECT_NAME_INVALID; } #endregion #region phase 2 Volume State //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_CREATE) //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.CREATE)) { Helper.CaptureRequirement(2377, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ] If RootOpen.Volume.IsReadOnly && CreateDisposition == FILE_CREATE,then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_SUPERSEDE) //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.SUPERSEDE)) { Helper.CaptureRequirement(2378, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ] If RootOpen.Volume.IsReadOnly &&CreateDisposition == FILE_SUPERSEDE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE) //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE)) { Helper.CaptureRequirement(2379, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ] If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE_IF) //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE_IF)) { Helper.CaptureRequirement(2380, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ] If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE_IF, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } #endregion #region Phase 3 Initialization of Open Object gOpenRemainingDesiredAccess = desiredAccess; gOpenSharingMode = shareAccess; //4158 indicates (createOption & (CreateOptions.WRITE_THROUGH | //CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING | //CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT | //CreateOptions.DELETE_ON_CLOSE)); gOpenMode = (CreateOptions.WRITE_THROUGH | CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING | CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.DELETE_ON_CLOSE); if (gSecurityContext.privilegeSet == PrivilegeSet.SeBackupPrivilege) { isOpenHasBackupAccess = true; } if (gSecurityContext.privilegeSet == PrivilegeSet.SeRestorePrivilege) { isOpenHasRestoreAccess = true; } if (gSecurityContext.privilegeSet == PrivilegeSet.SeCreateSymbolicLinkPrivilege) { isOpenHasCreateSymbolicLinkAccess = true; } if (gSecurityContext.privilegeSet == PrivilegeSet.SeManageVolumePrivilege) { isOpenHasManageVolumeAccess = true; } if (gSecurityContext.isSecurityContextSIDsContainWellKnown) { isOpenIsAdministrator = true; } #endregion #region phase 4 Check for backup/restore intent //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and (CreateDisposition == //FILE_OPEN || CreateDisposition == FILE_OPEN_IF || CreateDisposition == //FILE_OVERWRITE_IF) and Open.HasBackupAccess is true, then the object store //SHOULD grant backup access as shown in the following pseudocode: if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT && (createDisposition == CreateDisposition.OPEN || createDisposition == CreateDisposition.OPEN_IF || createDisposition == CreateDisposition.OVERWRITE_IF) && isOpenHasBackupAccess) { //2164391968 indicates FileAccess.READ_CONTROL | //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ | //FileAccess.FILE_TRAVERSE; FileAccess BackupAccess = FileAccess.READ_CONTROL | FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ | FileAccess.FILE_TRAVERSE; if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED) { gOpenGrantedAccess = gOpenGrantedAccess | BackupAccess; } else { gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & BackupAccess); } gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess); } //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and Open.HasRestoreAccess is true, //then the object store SHOULD grant restore access as shown in the following pseudocode: if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT && isHasRestoreAccess) { //1091309574 indicates FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER | //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE | //FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY | //FileAccess.DELETE FileAccess RestoreAccess = FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER | FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE | FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY | FileAccess.DELETE; if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED) { gOpenGrantedAccess = gOpenGrantedAccess | RestoreAccess; } else { gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & RestoreAccess); } gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess); } #endregion #region phase 5 Parse path name //If any StreamTypeNamei is "$INDEX_ALLOCATION" and the corresponding //StreamNamei has a value other than an empty string or "$I30" if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION) { if (sutPlatForm != PlatformType.NoneWindows) { Helper.CaptureRequirement(507, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:] If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string or \""$I30"", the operation is failed with STATUS_INVALID_PARAMETER in Windows."); return MessageStatus.INVALID_PARAMETER; } else if (isR507Implemented) { Helper.CaptureRequirement(392, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:] If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string or \""$I30\"", the operation SHOULD be failed with STATUS_INVALID_PARAMETER."); return MessageStatus.INVALID_PARAMETER; } } #endregion #region phase 6 Location of file if (streamFoundType == StreamFoundType.StreamIsNotFound) { //If (CreateDisposition == FILE_OPEN ) if (createDisposition == CreateDisposition.OPEN) { Helper.CaptureRequirement(513, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 6 -- Location of file:] Else:[If such a link is not found:] If CreateDisposition == FILE_OPEN, the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND."); return MessageStatus.OBJECT_NAME_NOT_FOUND; } //If (CreateDisposition == FILE_OVERWRITE) if (createDisposition == CreateDisposition.OVERWRITE) { Helper.CaptureRequirement(2395, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 6 -- Location of file:] Else:[If such a link is not found:]If CreateDisposition == FILE_OVERWRITE), the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND."); return MessageStatus.OBJECT_NAME_NOT_FOUND; } //If RootOpen.Volume.IsReadOnly if (isFileVolumeReadOnly) { Helper.CaptureRequirement(514, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 6 -- Location of file:] Else:[If such a link is not found:]If RootOpen.Volume.IsReadOnly then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //Helper.CaptureRequirement(547, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:Phase 6 -- Location of file:] for this search is as follows:For i = 1 to n-1:Search ParentFile.DirectoryList for a Link where Link.Name or Link.ShortName matches FileNamei,If no such link is found, the operation MUST be failed with STATUS_OBJECT_PATH_NOT_FOUND."); //return MessageStatus.OBJECT_PATH_NOT_FOUND; } //If Open.GrantedAccess.FILE_TRAVERSE is not set and //AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) //returns FALSE, if ((gOpenGrantedAccess & FileAccess.FILE_TRAVERSE) == 0) { if (sutPlatForm != PlatformType.NoneWindows) { Helper.CaptureRequirement(405, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 6 -- Location of file:] Pseudocode for this search:For i = 1 to n-1: If Open.GrantedAccess.FILE_TRAVERSE is not set and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) returns FALSE, the operation is not failed with STATUS_ACCESS_DENIED in Windows."); } if (isR405Implemented) { Helper.CaptureRequirement(397, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:Phase 6 -- Location of file:] Pseudocode for this search:For i = 1 to n-1:If Open.GrantedAccess.FILE_TRAVERSE is not set and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) returns FALSE, the operation MAY be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } } //If Link.File.IsSymbolicLink is true if (symbolicLinkType == SymbolicLinkType.IsSymbolicLink) { Helper.CaptureRequirement(399, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:Phase 6 - Location of file:] Pseudocode for this search:For i = 1 to n-1:If Link.File.IsSymbolicLink is TRUE, the operation MUST be failed with Status set to STATUS_STOPPED_ON_SYMLINK ."); return MessageStatus.STOPPED_ON_SYMLINK; } #endregion #region phase 7 Type of file to open //If CreateOptions.FILE_DIRECTORY_FILE is true if (createOption == CreateOptions.DIRECTORY_FILE) { gfileTypeToOpen = FileType.DirectoryFile; } //Else if CreateOptions.FILE_NON_DIRECTORY_FILE is true else if (createOption == CreateOptions.NON_DIRECTORY_FILE) { gfileTypeToOpen = FileType.DataFile; } //Else if StreamTypeNameToOpen is "$INDEX_ALLOCATION" else if (streamTypeNameToOPen == StreamTypeNameToOPen.INDEX_ALLOCATION) { gfileTypeToOpen = FileType.DirectoryFile; } //Else if StreamTypeNameToOpen is "$DATA" else if (streamTypeNameToOPen == StreamTypeNameToOPen.DATA) { gfileTypeToOpen = FileType.DataFile; } //Else if Open.File is not NULL and Open.File.FileType is DirectoryFile else if (fileNameStatus == FileNameStatus.OpenFileNotNull && openFileType == FileType.DirectoryFile) { gfileTypeToOpen = FileType.DirectoryFile; } //Else if PathName contains a trailing backslash else if (fileNameStatus == FileNameStatus.PathNameTraiblack) { gfileTypeToOpen = FileType.DirectoryFile; } //else else { gfileTypeToOpen = FileType.DataFile; } //If FileTypeToOpen is DirectoryFile and Open.File is not NULL and //Open.File.FileType is not DirectoryFile: if (gfileTypeToOpen == FileType.DirectoryFile && fileNameStatus == FileNameStatus.OpenFileNotNull && openFileType == FileType.DataFile) { //If CreateDisposition == FILE_CREATE if (createDisposition == CreateDisposition.CREATE) { Helper.CaptureRequirement(414, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 7 -- Type of file to open:]If FileTypeToOpen is DirectoryFile and Open.File is not NULL and Open.File.FileType is not DirectoryFile:If CreateDisposition == FILE_CREATE then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION."); return MessageStatus.OBJECT_NAME_COLLISION; } //else else { Helper.CaptureRequirement(2396, @"[In Application Requests an Open of a File , Phase 7 -- Type of file to open:] If FileTypeToOpen is DirectoryFile and Open.File is not NULL and Open.File.FileType is not DirectoryFile: else[If CreateDisposition != FILE_CREATE] the operation MUST be failed with STATUS_NOT_A_DIRECTORY."); return MessageStatus.NOT_A_DIRECTORY; } } //If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File //is not NULL and Open.File.FileType is DirectoryFile if (gfileTypeToOpen == FileType.DataFile && streamTypeNameToOPen == StreamTypeNameToOPen.NULL && fileNameStatus == FileNameStatus.OpenFileNotNull && openFileType == FileType.DirectoryFile) { Helper.CaptureRequirement(415, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows: Phase 7 -- Type of file to open:]If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File is not NULL and Open.File.FileType is DirectoryFile, the operation MUST be failed with STATUS_FILE_IS_A_DIRECTORY."); return MessageStatus.FILE_IS_A_DIRECTORY; } #endregion return MessageStatus.SUCCESS; }
public T CreateItem <T>(CreateOptions options) where T : class { return(_requestContext.SitecoreService.CreateItem <T>(options)); }
private string ProcessTriggeredSend(TriggeredSend ts, CreateOptions createOptions) { string status; string sendResult; CreateResult[] results = _service.Client.Create(createOptions, new APIObject[] { ts }, out _requestID, out status); TriggeredSendCreateResult createResults = results[0] as TriggeredSendCreateResult; if (createResults != null) { if (status != "OK") { UnityResolver.UnityContainer.Resolve<ILogger>().LogEvent(() => Config.AppEvents.GainWinServicesExactTarget.ExactTargetWarning, string.Format("Error during sending data to ExactTarget. ExactTarget.API.ProcessTriggeredSend. Error {0}", createResults.ErrorCode)); sendResult = createResults.ErrorCode.ToString(); } else { UnityResolver.UnityContainer.Resolve<ILogger>().LogEvent(() => Config.AppEvents.GainWinServicesExactTarget.ExactTargetWarning, "Successful sending. ExactTarget.API.ProcessTriggeredSend"); sendResult = string.Empty; } } else { sendResult = "Unexpected error"; } return sendResult; }
public async Task <(NTStatus status, object handle, FileStatus fileStatus)> CreateFile(string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext, CancellationToken cancellationToken) { CreateRequest request = new CreateRequest(); request.Name = path; request.DesiredAccess = desiredAccess; request.FileAttributes = fileAttributes; request.ShareAccess = shareAccess; request.CreateDisposition = createDisposition; request.CreateOptions = createOptions; request.ImpersonationLevel = ImpersonationLevel.Impersonation; await TrySendCommandAsync(request, cancellationToken); SMB2Command response = m_client.WaitForCommand(SMB2CommandName.Create); var fileStatus = FileStatus.FILE_DOES_NOT_EXIST; if (response != null) { object handle = null; if (response.Header.Status == NTStatus.STATUS_SUCCESS && response is CreateResponse) { CreateResponse createResponse = ((CreateResponse)response); handle = createResponse.FileId; fileStatus = ToFileStatus(createResponse.CreateAction); } return(response.Header.Status, handle, fileStatus); } return(NTStatus.STATUS_INVALID_SMB, null, fileStatus); }
public static MessageStatus CreateFile( FileAttribute desiredFileAttribute, CreateOptions createOption, StreamTypeNameToOPen streamTypeNameToOPen, FileAccess desiredAccess, ShareAccess shareAccess, CreateDisposition createDisposition, StreamFoundType streamFoundType, SymbolicLinkType symbolicLinkType, FileType openFileType, FileNameStatus fileNameStatus ) { MessageStatus status = OpenFileinitial( desiredAccess, shareAccess, createOption, createDisposition, desiredFileAttribute, streamFoundType, symbolicLinkType, streamTypeNameToOPen, openFileType, fileNameStatus); if (status != MessageStatus.SUCCESS) { return status; } #region Pseudocode for the operation //If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set if (gfileTypeToOpen == FileType.DirectoryFile && desiredFileAttribute == FileAttribute.TEMPORARY) { Helper.CaptureRequirement(418, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set, the operation MUST be failed with STATUS_INVALID_PARAMETER."); return MessageStatus.INVALID_PARAMETER; } //If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE //are both set if (desiredFileAttribute == FileAttribute.READONLY && createOption == CreateOptions.DELETE_ON_CLOSE) { Helper.CaptureRequirement(419, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE are both set, the operation MUST be failed with STATUS_CANNOT_DELETE."); return MessageStatus.CANNOT_DELETE; } //If StreamTypeNameToOpen is non-empty and has a value other than "$DATA" or //"$INDEX_ALLOCATION", the operation MUST be failed with STATUS_ACCESS_DENIED. if (streamTypeNameToOPen == StreamTypeNameToOPen.Other) { Helper.CaptureRequirement(420, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If StreamTypeNameToOpen is non-empty and has a value other than \""$DATA"",the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.OBJECT_NAME_INVALID; } //If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and //Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and //SecurityContext.PrivilegeSet does not contain "SeSecurityPrivilege" //3 indicate SeBackupPrivilege and SeRestorePrivilege if (gOpenRemainingDesiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY && gOpenGrantedAccess == FileAccess.FILE_APPEND_DATA && gSecurityContext.privilegeSet == (PrivilegeSet.SeBackupPrivilege | PrivilegeSet.SeRestorePrivilege)) { Helper.CaptureRequirement(422, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and SecurityContext.PrivilegeSet does not contain \""SeSecurityPrivilege"", the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set //and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, //FILE_ADD_FILE ) returns FALSE and Open.HasRestoreAccess is FALSE if (gfileTypeToOpen == FileType.DataFile && gOpenGrantedAccess == FileAccess.FILE_ADD_SUBDIRECTORY && !isOpenHasRestoreAccess) { Helper.CaptureRequirement(423, @"[In Creation of a New File,Pseudocode for the operation is as follows:] If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_FILE ) returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY //is not set and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, //FILE_ADD_SUBDIRECTORY ) returns FALSE and Open.HasRestoreAccess is FALSE if (gfileTypeToOpen == FileType.DirectoryFile && gOpenGrantedAccess == FileAccess.FILE_ADD_FILE && !isOpenHasRestoreAccess) { Helper.CaptureRequirement(424, @"[In Creation of a New File,Pseudocode for the operation is as follows:] If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY is not set and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_SUBDIRECTORY ) returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } if (streamTypeNameToOPen == StreamTypeNameToOPen.DATA || streamTypeNameToOPen == StreamTypeNameToOPen.NULL) { gStreamType = StreamType.DataStream; } else { gStreamType = StreamType.DirectoryStream; } gFileAttribute = desiredFileAttribute; Helper.CaptureRequirement(475, @"[In Creation of a New File,Pseudocode for the operation is as follows:] The object store MUST return:CreateAction set to FILE_CREATED."); gCreateAction = CreateAction.CREATED; #endregion Helper.CaptureRequirement(474, @"[In Creation of a New File,Pseudocode for the operation is as follows:] The object store MUST return :Status set to STATUS_SUCCESS."); return MessageStatus.SUCCESS; }
internal static MessageStatus WorkaroundOpenExistingFile(ShareAccess shareAccess, FileAccess desiredAccess, bool streamFound, bool isSymbolicLink, FileType openFileType, FileNameStatus fileNameStatus, CreateOptions existingOpenModeCreateOption, ShareAccess existOpenShareModeShareAccess, FileAccess existOpenDesiredAccess, CreateOptions createOption, CreateDisposition createDisposition, StreamTypeNameToOpen streamTypeNameToOPen, FileAttribute fileAttribute, FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site) { if (shareAccess == ShareAccess.FILE_SHARE_READ && desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY && !streamFound && !isSymbolicLink && openFileType == FileType.DataFile && fileNameStatus == FileNameStatus.Normal && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenShareModeShareAccess == ShareAccess.FILE_SHARE_READ && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING && createDisposition == CreateDisposition.OPEN_IF && streamTypeNameToOPen == StreamTypeNameToOpen.NULL && fileAttribute == FileAttribute.NORMAL && desiredFileAttribute == FileAttribute.NORMAL) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.DELETE_ON_CLOSE && (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (streamFound && !isSymbolicLink && openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.DIRECTORY_FILE && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.DIRECTORY_FILE) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.ACCESS_VIOLATION, returnedStatus, site); } else if (!streamFound && !isSymbolicLink && openFileType == FileType.DataFile && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NON_DIRECTORY_FILE && fileAttribute == FileAttribute.READONLY) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.ACCESS_DENIED, returnedStatus, site); } return(returnedStatus); }
public static unsafe extern bool vlImageCreateSingle(uint uiWidth, uint uiHeight, byte* lpImageDataRGBA8888, ref CreateOptions createOptions);
public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext) { IntPtr fileHandle; string nativePath = ToNativePath(path); // NtQueryDirectoryFile will return STATUS_PENDING if the directory handle was not opened with SYNCHRONIZE and FILE_SYNCHRONOUS_IO_ALERT or FILE_SYNCHRONOUS_IO_NONALERT. // Our usage of NtNotifyChangeDirectoryFile assumes the directory handle is opened with SYNCHRONIZE and FILE_SYNCHRONOUS_IO_ALERT (or FILE_SYNCHRONOUS_IO_NONALERT starting from Windows Vista). // Note: Sometimes a directory will be opened without specifying FILE_DIRECTORY_FILE. desiredAccess |= AccessMask.SYNCHRONIZE; createOptions &= ~CreateOptions.FILE_SYNCHRONOUS_IO_NONALERT; createOptions |= CreateOptions.FILE_SYNCHRONOUS_IO_ALERT; if ((createOptions & CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING) > 0 && ((FileAccessMask)desiredAccess & FileAccessMask.FILE_APPEND_DATA) > 0) { // FILE_NO_INTERMEDIATE_BUFFERING is incompatible with FILE_APPEND_DATA // [MS-SMB2] 3.3.5.9 suggests setting FILE_APPEND_DATA to zero in this case. desiredAccess = (AccessMask)((uint)desiredAccess & (uint)~FileAccessMask.FILE_APPEND_DATA); } NTStatus status = CreateFile(out fileHandle, out fileStatus, nativePath, desiredAccess, 0, fileAttributes, shareAccess, createDisposition, createOptions); handle = fileHandle; return(status); }
private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions) { stream = null; FileShare fileShare = NTFileStoreHelper.ToFileShare(shareAccess); FileOptions fileOptions = ToFileOptions(openOptions); string fileShareString = fileShare.ToString().Replace(", ", "|"); string fileOptionsString = ToFileOptionsString(fileOptions); try { stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare, fileOptions); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status); return(status); } else { throw; } } Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString); return(NTStatus.STATUS_SUCCESS); }
public async Task CreateTable(Table table, CreateOptions options = null) { var commandText = _commandFormatter.CreateTable(_clickHouseConnection.Database, table, options); await ExecuteNonQueryAsync(commandText); }
public static MessageStatus OpenExistingFile( ShareAccess shareAccess, FileAccess desiredAccess, StreamFoundType streamFoundType, SymbolicLinkType symbolicLinkType, FileType openFileType, FileNameStatus fileNameStatus, CreateOptions existingOpenModeCreateOption, ShareAccess existOpenShareModeShareAccess, FileAccess existOpenDesiredAccess, CreateOptions createOption, CreateDisposition createDisposition, StreamTypeNameToOPen streamTypeNameToOPen, FileAttribute fileAttribute, FileAttribute desiredFileAttribute ) { MessageStatus statusShareAccess = MessageStatus.SUCCESS; MessageStatus statusExistAccess = MessageStatus.SUCCESS; //call 3.1.5.1 openInitial MessageStatus statusInitial = OpenFileinitial( desiredAccess, shareAccess, createOption, createDisposition, desiredFileAttribute, streamFoundType, symbolicLinkType, streamTypeNameToOPen, openFileType, fileNameStatus); if (statusInitial != MessageStatus.SUCCESS) { return statusInitial; } #region FileTypeToOpen //If FileTypeToOpen is DirectoryFile if (gfileTypeToOpen == FileType.DirectoryFile) { //If CreateDisposition is FILE_OPEN if (createDisposition == CreateDisposition.OPEN) { //call 3.1.5.1.2.1 statusExistAccess = CheckExistingFileAccess( openFileType, fileAttribute, desiredAccess, createOption, existingOpenModeCreateOption, streamTypeNameToOPen, shareAccess, existOpenShareModeShareAccess); if (statusExistAccess != MessageStatus.SUCCESS) { Helper.CaptureRequirement(635, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN then:] If this[Perform access checks as described in section 3.1.5.1.2.1.] fails, the request MUST be failed with the same status."); return statusExistAccess; } //call 3.1.5.1.2.2 statusShareAccess = CheckShareAccess( streamFoundType, existOpenShareModeShareAccess, desiredAccess, existOpenDesiredAccess, shareAccess); if (statusShareAccess != MessageStatus.SUCCESS) { Helper.CaptureRequirement(636, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If OpenFileType is DirectoryFile:If CreateDisposition is FILE_OPEN_IF then:] If this[Perform access checks as described in section 3.1.5.1.2.1.] fails, the request MUST be failed with the same status."); return statusShareAccess; } gCreateAction = CreateAction.OPENED; } //If CreateDisposition is FILE_OPEN_IF then else if (createDisposition == CreateDisposition.OPEN_IF) { //call 3.1.5.1.2.1 statusExistAccess = CheckExistingFileAccess( openFileType, fileAttribute, desiredAccess, createOption, existingOpenModeCreateOption, streamTypeNameToOPen, shareAccess, existOpenShareModeShareAccess); if (statusExistAccess != MessageStatus.SUCCESS) { Helper.CaptureRequirement(640, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN_IF then:] If this[Perform sharing access checks as described in section 3.1.5.1.2.2.] fails, the request MUST be failed with the same status."); return statusExistAccess; } //call 3.1.5.1.2.2 statusShareAccess = CheckShareAccess( streamFoundType, existOpenShareModeShareAccess, desiredAccess, existOpenDesiredAccess, shareAccess); if (statusShareAccess != MessageStatus.SUCCESS) { Helper.CaptureRequirement(639, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN then:] If this [Perform sharing access checks as described in section 3.1.5.1.2.2.]fails, the request MUST be failed with the same status."); return statusShareAccess; } gCreateAction = CreateAction.OPENED; } else { //Existing directories cannot be overwritten/superseded //If File == File.Volume.RootDirectory if (isFileEqualRootDirectory) { Helper.CaptureRequirement(578, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If FileTypeToOpen is DirectoryFile:] Else If File == File.Volume.RootDirectory then the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } else { Helper.CaptureRequirement(579, @"[In Open of an Existing File,Pseudocode for the operation is as follows: If FileTypeToOpen is DirectoryFile:] else[If File != File.Volume.RootDirectory ] the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION."); return MessageStatus.OBJECT_NAME_COLLISION; } } } //Else if FileTypeToOpen is DataFile else if (gfileTypeToOpen == FileType.DataFile) { #region If Stream was found if (streamFoundType == StreamFoundType.StreamIsFound) { //If CreateDisposition is FILE_CREATE if (createDisposition == CreateDisposition.CREATE) { Helper.CaptureRequirement(584, @"[In Open of an Existing File,Pseudocode for the operation is as follows: Else if FileTypeToOpen is DataFile,If Stream was found,]If CreateDisposition is FILE_CREATE, then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION."); return MessageStatus.OBJECT_NAME_COLLISION; } //If CreateDisposition is FILE_OPEN_IF if (createDisposition == CreateDisposition.OPEN_IF) { //call 3.1.5.1.2.1 statusExistAccess = CheckExistingFileAccess( openFileType, fileAttribute, desiredAccess, createOption, existingOpenModeCreateOption, streamTypeNameToOPen, shareAccess, existOpenShareModeShareAccess); if (statusExistAccess != MessageStatus.SUCCESS) { return statusExistAccess; } //call 3.1.5.1.2.2 statusShareAccess = CheckShareAccess( streamFoundType, existOpenShareModeShareAccess, desiredAccess, existOpenDesiredAccess, shareAccess); if (statusShareAccess != MessageStatus.SUCCESS) { return statusShareAccess; } gCreateAction = CreateAction.OPENED; } //If CreateDisposition is FILE_OPEN else if (createDisposition == CreateDisposition.OPEN) { //call 3.1.5.1.2.1 statusExistAccess = CheckExistingFileAccess( openFileType, fileAttribute, desiredAccess, createOption, existingOpenModeCreateOption, streamTypeNameToOPen, shareAccess, existOpenShareModeShareAccess); if (statusExistAccess != MessageStatus.SUCCESS) { return statusExistAccess; } //call 3.1.5.1.2.2 statusShareAccess = CheckShareAccess( streamFoundType, existOpenShareModeShareAccess, desiredAccess, existOpenDesiredAccess, shareAccess); if (statusShareAccess != MessageStatus.SUCCESS) { return statusShareAccess; } gCreateAction = CreateAction.OPENED; } else { //If File.Volume.IsReadOnly is true if (isFileVolumeReadOnly) { Helper.CaptureRequirement(596, @"[In Open of an Existing File,Pseudocode for the operation is as follows: Else if FileTypeToOpen is DataFile:If Stream was found]Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF) If File.Volume.IsReadOnly is true, the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //If Stream.Name is empty if (fileNameStatus == FileNameStatus.StreamNameNull) { //If File.FileAttributes.FILE_ATTRIBUTE_HIDDEN is true and //DesiredFileAttributes.FILE_ATTRIBUTE_HIDDEN is FALSE if (fileAttribute == FileAttribute.HIDDEN && desiredFileAttribute != FileAttribute.HIDDEN) { Helper.CaptureRequirement(487, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,If Stream was found,Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF), If Stream.Name is empty:]If File.FileAttributes.FILE_ATTRIBUTE_HIDDEN is TRUE and DesiredFileAttributes.FILE_ATTRIBUTE_HIDDEN is FALSE, then the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //If File.FileAttributes.FILE_ATTRIBUTE_SYSTEM is true and //DesiredFileAttributes.FILE_ATTRIBUTE_SYSTEM is FALSE if (fileAttribute == FileAttribute.SYSTEM && desiredFileAttribute != FileAttribute.SYSTEM) { Helper.CaptureRequirement(488, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,If Stream was found,Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF), If Stream.Name is empty:]If File.FileAttributes.FILE_ATTRIBUTE_SYSTEM is TRUE and DesiredFileAttributes.FILE_ATTRIBUTE_SYSTEM is FALSE, then the operation MUST be failed with STATUS_ACCESS_DENIED."); return MessageStatus.ACCESS_DENIED; } //Set DesiredFileAttributes.FILE_ATTRIBUTE_ARCHIVE to true. desiredFileAttribute = desiredFileAttribute | FileAttribute.ARCHIVE; //Set DesiredFileAttributes.FILE_ATTRIBUTE_NORMAL to FALSE. desiredFileAttribute = desiredFileAttribute & (~FileAttribute.NORMAL); //Set DesiredFileAttributes.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED to FALSE desiredFileAttribute = desiredFileAttribute & (~FileAttribute.NOT_CONTENT_INDEXED); //If File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is true, then //set DesiredFileAttributes.FILE_ATTRIBUTE_ENCRYPTED to true. if ((fileAttribute & FileAttribute.ENCRYPTED) != 0) { desiredFileAttribute = desiredFileAttribute | FileAttribute.ENCRYPTED; } //If Open.HasRestoreAccess is true if (isOpenHasRestoreAccess) { //set Open.GrantedAccess.FILE_WRITE_EA to true gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_EA; //set Open.GrantedAccess.FILE_WRITE_ATTRIBUTES to true gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_ATTRIBUTES; } else { //set Open.RemainingDesiredAccess gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.FILE_WRITE_EA; //store must set Open.RemainingDesiredAccess.FILE_WRITE_ATTRIBUTES to //true gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.FILE_WRITE_ATTRIBUTES; } } //If CreateDisposition is FILE_SUPERSEDE if (createDisposition == CreateDisposition.SUPERSEDE) { //If Open.HasRestoreAccess is true if (isOpenHasRestoreAccess) { //set Open.GrantedAccess.DELETE to true gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.DELETE; } else { //Otherwise, the object store must set Open.RemainingDesiredAccess. //FILE_WRITE_DATA to true gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.DELETE; } } else { //If Open.HasRestoreAccess is true if (isOpenHasRestoreAccess) { //set Open.GrantedAccess.DELETE to true gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_DATA; } else { //Otherwise, the object store must set Open.RemainingDesiredAccess. //FILE_WRITE_DATA to true gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.FILE_WRITE_DATA; } } gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess); if (createDisposition == CreateDisposition.SUPERSEDE) { gCreateAction = CreateAction.SUPERSEDED; } else { gCreateAction = CreateAction.OVERWRITTEN; } } } #endregion #region Stream not found else { //If CreateDisposition is FILE_OPEN or FILE_OVERWRITE if (createDisposition == CreateDisposition.OPEN) { Helper.CaptureRequirement(610, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,Else (Steam not found)]If CreateDisposition is FILE_OPEN , the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND."); return MessageStatus.OBJECT_NAME_NOT_FOUND; } //If CreateDisposition is FILE_OPEN or FILE_OVERWRITE if (createDisposition == CreateDisposition.OVERWRITE) { Helper.CaptureRequirement(2416, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,Else (Steam not found)]If CreateDisposition is FILE_OVERWRITE, the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND."); return MessageStatus.OBJECT_NAME_NOT_FOUND; } //If Open.GrantedAccess.FILE_WRITE_DATA is not set and Open.RemainingDesiredAccess. //FILE_WRITE_DATA is not set: if ((gOpenGrantedAccess & FileAccess.FILE_WRITE_DATA) == 0 && (gOpenRemainingDesiredAccess & FileAccess.FILE_WRITE_DATA) == 0) { //If Open.HasRestoreAccess is true if (isOpenHasRestoreAccess) { //then the object store MUST set Open.GrantedAccess.FILE_WRITE_DATA to true. gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_DATA; } else { //Otherwise, the object store MUST set Open.RemainingDesiredAccess. //FILE_WRITE_DATA to true. gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.FILE_WRITE_DATA; } } //call 3.1.5.1.2.1 statusExistAccess = CheckExistingFileAccess( openFileType, fileAttribute, desiredAccess, createOption, existingOpenModeCreateOption, streamTypeNameToOPen, shareAccess, existOpenShareModeShareAccess); if (statusExistAccess != MessageStatus.SUCCESS) { Helper.CaptureRequirement(9840, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,Else (Steam not found)] If this[Perform access checks as described in section 3.1.5.1.2.1] fails, the request MUST be failed with the same status."); return statusExistAccess; } //If File.Volume.IsReadOnly is true if (isFileVolumeReadOnly) { Helper.CaptureRequirement(614, @"[In Open of an Existing File,Pseudocode for these checks is as follows: Else if FileTypeToOpen is DataFile,Else (Steam not found)]If File.Volume.IsReadOnly is TRUE, the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED."); return MessageStatus.MEDIA_WRITE_PROTECTED; } //Set CreateAction to FILE_CREATED. gCreateAction = CreateAction.CREATED; } #endregion } #endregion // If the object store implements encryption: if (gSecurityContext.isImplementsEncryption) { //If (CreateAction is FILE_OVERWRITTEN) and //(Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is true) //and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE) then: if ((gCreateAction == CreateAction.OVERWRITTEN) && (fileNameStatus == FileNameStatus.StreamNameNull) && ((desiredFileAttribute & FileAttribute.ENCRYPTED) != 0) && ((fileAttribute & FileAttribute.ENCRYPTED) == 0)) { //If File.OpenList is non-empty //the openList must not empty Helper.CaptureRequirement(623, @"[In Open of an Existing File,Pseudocode for these checks is as follows:] If the object store implements encryption:If (CreateAction is FILE_OVERWRITTEN) and (Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is TRUE) and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE), then:If File.OpenList is non-empty, then the operation MUST be failed with STATUS_SHARING_VIOLATION."); return MessageStatus.SHARING_VIOLATION; } //If (CreateAction is FILE_SUPERSEDED) and //(Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is true) //and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE) then: if ((gCreateAction == CreateAction.SUPERSEDED) && (fileNameStatus == FileNameStatus.FileNameNull) && ((desiredFileAttribute & FileAttribute.ENCRYPTED) != 0) && ((fileAttribute & FileAttribute.ENCRYPTED) == 0)) { //If File.OpenList is non-empty //the openList must not empty Helper.CaptureRequirement(2417, @"[In Open of an Existing File,Pseudocode for these checks is as follows:] If the object store implements encryption:If (CreateAction is FILE_SUPERSEDED) and (Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is TRUE) and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE), then:If File.OpenList is non-empty, then the operation MUST be failed with STATUS_SHARING_VIOLATION."); return MessageStatus.SHARING_VIOLATION; } } // If CreateAction is FILE_OVERWRITTEN if (gCreateAction == CreateAction.OVERWRITTEN) { if (fileNameStatus == FileNameStatus.FileNameNull) { //Set File.FileAttributes to DesiredFileAttributes fileAttribute = desiredFileAttribute; } } // If CreateAction is FILE_SUPERSEDED if (gCreateAction == CreateAction.SUPERSEDED) { if (fileNameStatus == FileNameStatus.FileNameNull) { //Set File.FileAttributes to DesiredFileAttributes fileAttribute = desiredFileAttribute; } } Helper.CaptureRequirement(631, @"[In Open of an Existing File,Pseudocode for these checks is as follows:] The object store MUST return :CreateAction set to FILE_OPENED."); gCreateAction = CreateAction.OPENED; Helper.CaptureRequirement(630, @"[In Open of an Existing File,Pseudocode for these checks is as follows:] The object store MUST return:Status set to STATUS_SUCCESS."); return MessageStatus.SUCCESS; }
private CreateOptions InitCreateOptions() { CreateOptions options = new CreateOptions(); options.RequestType = RequestType.Asynchronous; options.RequestTypeSpecified = true; options.QueuePriority = GetQueuePriority(); options.QueuePrioritySpecified = true; return options; }
public static bool IsValid(CreateOptions value) { return value == CreateOptions.None || value == CreateOptions.InitializeDefaults; }
public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext) { handle = null; fileStatus = FileStatus.FILE_DOES_NOT_EXIST; FileAccess createAccess = NTFileStoreHelper.ToCreateFileAccess(desiredAccess, createDisposition); bool requestedWriteAccess = (createAccess & FileAccess.Write) > 0; bool forceDirectory = (createOptions & CreateOptions.FILE_DIRECTORY_FILE) > 0; bool forceFile = (createOptions & CreateOptions.FILE_NON_DIRECTORY_FILE) > 0; if (forceDirectory & (createDisposition != CreateDisposition.FILE_CREATE && createDisposition != CreateDisposition.FILE_OPEN && createDisposition != CreateDisposition.FILE_OPEN_IF && createDisposition != CreateDisposition.FILE_SUPERSEDE)) { return(NTStatus.STATUS_INVALID_PARAMETER); } // Windows will try to access named streams (alternate data streams) regardless of the FILE_NAMED_STREAMS flag, we need to prevent this behaviour. if (!m_fileSystem.SupportsNamedStreams && path.Contains(":")) { // Windows Server 2003 will return STATUS_OBJECT_NAME_NOT_FOUND return(NTStatus.STATUS_NO_SUCH_FILE); } FileSystemEntry entry = null; try { entry = m_fileSystem.GetEntry(path); } catch (FileNotFoundException) { } catch (DirectoryNotFoundException) { } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status); return(status); } else { throw; } } if (createDisposition == CreateDisposition.FILE_OPEN) { if (entry == null) { return(NTStatus.STATUS_NO_SUCH_FILE); } fileStatus = FileStatus.FILE_EXISTS; if (entry.IsDirectory && forceFile) { return(NTStatus.STATUS_FILE_IS_A_DIRECTORY); } if (!entry.IsDirectory && forceDirectory) { return(NTStatus.STATUS_OBJECT_PATH_INVALID); } } else if (createDisposition == CreateDisposition.FILE_CREATE) { if (entry != null) { // File already exists, fail the request Log(Severity.Verbose, "CreateFile: File '{0}' already exists.", path); fileStatus = FileStatus.FILE_EXISTS; return(NTStatus.STATUS_OBJECT_NAME_COLLISION); } if (!requestedWriteAccess) { return(NTStatus.STATUS_ACCESS_DENIED); } try { if (forceDirectory) { Log(Severity.Information, "CreateFile: Creating directory '{0}'", path); entry = m_fileSystem.CreateDirectory(path); } else { Log(Severity.Information, "CreateFile: Creating file '{0}'", path); entry = m_fileSystem.CreateFile(path); } } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status); return(status); } else { throw; } } fileStatus = FileStatus.FILE_CREATED; } else if (createDisposition == CreateDisposition.FILE_OPEN_IF || createDisposition == CreateDisposition.FILE_OVERWRITE || createDisposition == CreateDisposition.FILE_OVERWRITE_IF || createDisposition == CreateDisposition.FILE_SUPERSEDE) { if (entry == null) { if (createDisposition == CreateDisposition.FILE_OVERWRITE) { return(NTStatus.STATUS_OBJECT_PATH_NOT_FOUND); } if (!requestedWriteAccess) { return(NTStatus.STATUS_ACCESS_DENIED); } try { if (forceDirectory) { Log(Severity.Information, "CreateFile: Creating directory '{0}'", path); entry = m_fileSystem.CreateDirectory(path); } else { Log(Severity.Information, "CreateFile: Creating file '{0}'", path); entry = m_fileSystem.CreateFile(path); } } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status); return(status); } else { throw; } } fileStatus = FileStatus.FILE_CREATED; } else { fileStatus = FileStatus.FILE_EXISTS; if (createDisposition == CreateDisposition.FILE_OPEN_IF) { if (entry.IsDirectory && forceFile) { return(NTStatus.STATUS_FILE_IS_A_DIRECTORY); } if (!entry.IsDirectory && forceDirectory) { return(NTStatus.STATUS_OBJECT_PATH_INVALID); } } else { if (!requestedWriteAccess) { return(NTStatus.STATUS_ACCESS_DENIED); } if (createDisposition == CreateDisposition.FILE_OVERWRITE || createDisposition == CreateDisposition.FILE_OVERWRITE_IF) { // Truncate the file try { Stream temp = m_fileSystem.OpenFile(path, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None); temp.Close(); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status); return(status); } else { throw; } } fileStatus = FileStatus.FILE_OVERWRITTEN; } else if (createDisposition == CreateDisposition.FILE_SUPERSEDE) { // Delete the old file try { m_fileSystem.Delete(path); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status); return(status); } else { throw; } } try { if (forceDirectory) { Log(Severity.Information, "CreateFile: Creating directory '{0}'", path); entry = m_fileSystem.CreateDirectory(path); } else { Log(Severity.Information, "CreateFile: Creating file '{0}'", path); entry = m_fileSystem.CreateFile(path); } } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status); return(status); } else { throw; } } fileStatus = FileStatus.FILE_SUPERSEDED; } } } } else { return(NTStatus.STATUS_INVALID_PARAMETER); } FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess); Stream stream; if (fileAccess == (FileAccess)0 || entry.IsDirectory) { stream = null; } else { // Note that SetFileInformationByHandle/FILE_DISPOSITION_INFO has no effect if the handle was opened with FILE_DELETE_ON_CLOSE. NTStatus openStatus = OpenFileStream(out stream, path, fileAccess, shareAccess, createOptions); if (openStatus != NTStatus.STATUS_SUCCESS) { return(openStatus); } } bool deleteOnClose = (createOptions & CreateOptions.FILE_DELETE_ON_CLOSE) > 0; handle = new FileHandle(path, entry.IsDirectory, stream, deleteOnClose); if (fileStatus != FileStatus.FILE_CREATED && fileStatus != FileStatus.FILE_OVERWRITTEN && fileStatus != FileStatus.FILE_SUPERSEDED) { fileStatus = FileStatus.FILE_OPENED; } return(NTStatus.STATUS_SUCCESS); }
public T CreateItem <T>(CreateOptions options) where T : class { throw new System.NotImplementedException(); }
public DBCreateIndexQuery NonClustered() { this.Options |= CreateOptions.NonClustered; return(this); }
// // Library routines. (Basically class wrappers.) // public unsafe static void vlImageCreateDefaultCreateStructure(out CreateOptions CreateOptions) { if (IsWow64()) x64.vlImageCreateDefaultCreateStructure(out CreateOptions); else x86.vlImageCreateDefaultCreateStructure(out CreateOptions); }
// // instance methods // /// <summary> /// Adds the unique constraint to this index /// </summary> /// <returns></returns> public DBCreateIndexQuery Unique() { this.Options |= CreateOptions.Unique; return(this); }
public unsafe static bool vlImageCreateSingle(uint uiWidth, uint uiHeight, byte* lpImageDataRGBA8888, ref CreateOptions CreateOptions) { return IsWow64() ? x64.vlImageCreateSingle(uiWidth, uiHeight, lpImageDataRGBA8888, ref CreateOptions) : x86.vlImageCreateSingle(uiWidth, uiHeight, lpImageDataRGBA8888, ref CreateOptions); }
public unsafe static bool vlImageCreateMultiple(uint uiWidth, uint uiHeight, uint uiFrames, uint uiFaces, uint uiSlices, byte** lpImageDataRGBA8888, ref CreateOptions CreateOptions) { return IsWow64() ? x64.vlImageCreateMultiple(uiWidth, uiHeight, uiFrames, uiFaces, uiSlices, lpImageDataRGBA8888, ref CreateOptions) : x86.vlImageCreateMultiple(uiWidth, uiHeight, uiFrames, uiFaces, uiSlices, lpImageDataRGBA8888, ref CreateOptions); }
public GraphicsDeviceCreationParameters(GraphicsAdapter graphicsAdapter, DeviceType deviceType, IntPtr windowHandle, CreateOptions createOptions) { throw new NotImplementedException(); }
static int RunCreate(ILogger logger, DatabaseConnectionSettings settings, CreateOptions options) => Create.Run(logger, settings);
public object CreateItem(CreateOptions options) { return(_requestContext.SitecoreService.CreateItem(options)); }
public int Compare(GraphicsDeviceInformation d1, GraphicsDeviceInformation d2) { float num5; if (d1.DeviceType != d2.DeviceType) { if (d1.DeviceType >= d2.DeviceType) { return(1); } return(-1); } CreateOptions options = CreateOptions.MixedVertexProcessing | CreateOptions.HardwareVertexProcessing | CreateOptions.SoftwareVertexProcessing; CreateOptions options2 = d1.CreationOptions & options; CreateOptions options3 = d2.CreationOptions & options; if (options2 != options3) { if (options2 == CreateOptions.HardwareVertexProcessing) { return(-1); } if (options3 != CreateOptions.HardwareVertexProcessing) { if (options2 == CreateOptions.MixedVertexProcessing) { return(-1); } if (options3 == CreateOptions.MixedVertexProcessing) { return(1); } if (options2 != CreateOptions.None) { return(-1); } } return(1); } PresentationParameters presentationParameters = d1.PresentationParameters; PresentationParameters parameters2 = d2.PresentationParameters; if (presentationParameters.IsFullScreen != parameters2.IsFullScreen) { if (this.graphics.IsFullScreen != presentationParameters.IsFullScreen) { return(1); } return(-1); } int num = this.RankFormat(presentationParameters.BackBufferFormat); int num2 = this.RankFormat(parameters2.BackBufferFormat); if (num != num2) { if (num >= num2) { return(1); } return(-1); } if (presentationParameters.MultiSampleType != parameters2.MultiSampleType) { int num3 = (presentationParameters.MultiSampleType == MultiSampleType.NonMaskable) ? ((int)(MultiSampleType.SixteenSamples | MultiSampleType.NonMaskable)) : ((int)presentationParameters.MultiSampleType); int num4 = (parameters2.MultiSampleType == MultiSampleType.NonMaskable) ? ((int)(MultiSampleType.SixteenSamples | MultiSampleType.NonMaskable)) : ((int)parameters2.MultiSampleType); if (num3 <= num4) { return(1); } return(-1); } if (presentationParameters.MultiSampleQuality != parameters2.MultiSampleQuality) { if (presentationParameters.MultiSampleQuality <= parameters2.MultiSampleQuality) { return(1); } return(-1); } if ((this.graphics.PreferredBackBufferWidth == 0) || (this.graphics.PreferredBackBufferHeight == 0)) { num5 = ((float)GraphicsDeviceManager.DefaultBackBufferWidth) / ((float)GraphicsDeviceManager.DefaultBackBufferHeight); } else { num5 = ((float)this.graphics.PreferredBackBufferWidth) / ((float)this.graphics.PreferredBackBufferHeight); } float num6 = ((float)presentationParameters.BackBufferWidth) / ((float)presentationParameters.BackBufferHeight); float num7 = ((float)parameters2.BackBufferWidth) / ((float)parameters2.BackBufferHeight); float num8 = Math.Abs((float)(num6 - num5)); float num9 = Math.Abs((float)(num7 - num5)); if (Math.Abs((float)(num8 - num9)) > 0.2f) { if (num8 >= num9) { return(1); } return(-1); } int num10 = 0; int num11 = 0; if (this.graphics.IsFullScreen) { if ((this.graphics.PreferredBackBufferWidth == 0) || (this.graphics.PreferredBackBufferHeight == 0)) { GraphicsAdapter adapter = d1.Adapter; num10 = adapter.CurrentDisplayMode.Width * adapter.CurrentDisplayMode.Height; GraphicsAdapter adapter2 = d2.Adapter; num11 = adapter2.CurrentDisplayMode.Width * adapter2.CurrentDisplayMode.Height; } else { num10 = num11 = this.graphics.PreferredBackBufferWidth * this.graphics.PreferredBackBufferHeight; } } else if ((this.graphics.PreferredBackBufferWidth == 0) || (this.graphics.PreferredBackBufferHeight == 0)) { num10 = num11 = GraphicsDeviceManager.DefaultBackBufferWidth * GraphicsDeviceManager.DefaultBackBufferHeight; } else { num10 = num11 = this.graphics.PreferredBackBufferWidth * this.graphics.PreferredBackBufferHeight; } int num12 = Math.Abs((int)((presentationParameters.BackBufferWidth * presentationParameters.BackBufferHeight) - num10)); int num13 = Math.Abs((int)((parameters2.BackBufferWidth * parameters2.BackBufferHeight) - num11)); if (num12 != num13) { if (num12 >= num13) { return(1); } return(-1); } if (this.graphics.IsFullScreen && (presentationParameters.FullScreenRefreshRateInHz != parameters2.FullScreenRefreshRateInHz)) { int num14 = Math.Abs((int)(d1.Adapter.CurrentDisplayMode.RefreshRate - presentationParameters.FullScreenRefreshRateInHz)); int num15 = Math.Abs((int)(d2.Adapter.CurrentDisplayMode.RefreshRate - parameters2.FullScreenRefreshRateInHz)); if (num14 > num15) { return(1); } return(-1); } if (d1.Adapter != d2.Adapter) { if (d1.Adapter.IsDefaultAdapter) { return(-1); } if (d2.Adapter.IsDefaultAdapter) { return(1); } } return(0); }
private async Task <SqlItem> CreateSqlItemAsync(SqlItem parentItem, string name, CreateOptions options = null) { if (parentItem == null) { throw new ArgumentNullException(nameof(parentItem)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Log("Parent: " + parentItem.Id + " '" + parentItem.Name + "' name: '" + name + "'"); options ??= new CreateOptions(); // if a race condition occurred, it may already exists var item = await GetSqlItemAsync(parentItem.Id, name).ConfigureAwait(false); if (item == null) { var id = Guid.NewGuid(); var parameters = new { id, parentId = parentItem.Id, name, attributes = options.Attributes, now = DateTime.UtcNow.RemoveMilliseconds() }; await SqlExtensions.ExecuteNonQueryAsync(ConnectionString, "INSERT INTO Item (Id, ParentId, Name, LastAccessTimeUtc, CreationTimeUtc, LastWriteTimeUtc, Attributes) VALUES (@id, @parentId, @name, @now, @now, @now, @attributes)", parameters, Logger).ConfigureAwait(false); item = await GetSqlItemAsync(id).ConfigureAwait(false); } if (!item.IsFolder && options.InputStream != null) { await WriteAsync(item, options.InputStream).ConfigureAwait(false); // refresh item = await GetSqlItemAsync(item.Id).ConfigureAwait(false); } AddEvent(item.Id, item.ParentId, WatcherChangeTypes.Created); AddEvent(item.ParentId, (item.Parent?.ParentId).GetValueOrDefault(), WatcherChangeTypes.Changed); return(item); }
public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext) { handle = null; fileStatus = FileStatus.FILE_DOES_NOT_EXIST; CreateRequest request = new CreateRequest(); request.Name = path; request.DesiredAccess = desiredAccess; request.FileAttributes = fileAttributes; request.ShareAccess = shareAccess; request.CreateDisposition = createDisposition; request.CreateOptions = createOptions; request.ImpersonationLevel = ImpersonationLevel.Impersonation; TrySendCommand(request); SMB2Command response = m_client.WaitForCommand(SMB2CommandName.Create); if (response != null) { if (response.Header.Status == NTStatus.STATUS_SUCCESS && response is CreateResponse) { CreateResponse createResponse = ((CreateResponse)response); handle = createResponse.FileId; fileStatus = ToFileStatus(createResponse.CreateAction); } return(response.Header.Status); } return(NTStatus.STATUS_INVALID_SMB); }
internal static MessageStatus WorkaroundCreateFile(FileNameStatus fileNameStatus, CreateOptions createOption, FileAccess desiredAccess, FileType openFileType, FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site) { if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT && desiredAccess == FileAccess.FILE_READ_DATA) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.DELETE_ON_CLOSE && (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(507, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } else if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING && (desiredAccess == FileAccess.FILE_APPEND_DATA || desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY)) { returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site); } return(returnedStatus); }
[DisableRequestSizeLimit] // note we added this to disable the 30M request limit https://github.com/aspnet/Announcements/issues/267 public async Task <IActionResult> Upload() { try { Log(string.Empty); if (!IsMultipartContentType(Request.ContentType)) { LogWarning("Content is not multipart."); return(BadRequest()); } var boundary = GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType)); if (boundary == null) { LogWarning("Boundary was not found."); return(BadRequest()); } // note we expect the json document to arrive before the file document UpdateRequest updateRequest = null; MultipartSection dataSection = null; var reader = new MultipartReader(boundary, HttpContext.Request.Body); do { var section = await reader.ReadNextSectionAsync().ConfigureAwait(false); if (section == null) { break; } if (string.IsNullOrWhiteSpace(section.ContentType)) { continue; } if (updateRequest == null) { if (!MediaTypeHeaderValue.TryParse(new StringSegment(section.ContentType), out var mediaType) || string.IsNullOrWhiteSpace(mediaType.MediaType.Value)) { continue; } if (mediaType.MediaType.Value.Contains("/json")) { try { updateRequest = await JsonSerializer.DeserializeAsync <UpdateRequest>(section.Body).ConfigureAwait(false); Log("Request id : " + updateRequest.Id + " name: " + updateRequest.Name + " parentId: " + updateRequest.ParentId + " attributes: " + updateRequest.Attributes); } catch (Exception e) { LogWarning("Invalid json document: " + e.Message); return(BadRequest()); } } continue; } else if (dataSection == null) { if (!section.ContentType.Equals("application/octet-stream")) { continue; } dataSection = section; break; // don't continue, we don't want to read the rest of stream } }while (true); if (updateRequest == null) { LogWarning("Request was not found."); return(BadRequest()); } var updateOptions = UpdateOptions.FromUpdateRequest(updateRequest); if (updateRequest.Id == Guid.Empty) { // creation var parent = await FileSystem.GetItemAsync(updateRequest.ParentId).ConfigureAwait(false); if (parent == null) { LogWarning("Parent " + updateRequest.ParentId + " was not found."); return(BadRequest()); } if (!parent.IsFolder()) { LogWarning("Parent " + parent.Id + " is not a folder."); return(BadRequest()); } var createOptions = new CreateOptions(); if (dataSection != null) { createOptions.InputStream = dataSection.Body; } createOptions.Attributes = updateRequest.Attributes ?? FileAttributes.Normal; var created = await((IFolderInfo)parent).CreateAsync(updateRequest.Name, createOptions).ConfigureAwait(false); if (updateOptions != null) { await created.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(created)); } var item = await FileSystem.GetItemAsync(updateRequest.Id).ConfigureAwait(false); if (item == null) { LogWarning("Item " + updateRequest.Id + " was not found."); return(BadRequest()); } if (item.IsFolder()) { if (dataSection != null) { LogWarning("Item " + updateRequest.Id + " is a folder so it's content cannot be set."); return(BadRequest()); } if (updateOptions != null) { await item.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(item)); } var file = (IFileInfo)item; if (dataSection != null) { await file.WriteAsync(dataSection.Body).ConfigureAwait(false); } if (updateOptions != null) { await item.UpdateAsync(updateOptions).ConfigureAwait(false); } return(Ok(item)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } }
/// <summary> /// Creates a ModelItem for a given type. This method is called by /// ModelFactory when the user wishes to create a new item. /// </summary> internal ModelItem InvokeCreateItem(Type itemType, CreateOptions options, params object[] arguments) { return(CreateItem(itemType, options, arguments)); }
static int RunCreate(ILogger logger, CreateOptions options) => Create.Run(logger);
private NTStatus CreateFile(out IntPtr handle, out FileStatus fileStatus, string nativePath, AccessMask desiredAccess, long allocationSize, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions) { UNICODE_STRING objectName = new UNICODE_STRING(nativePath); OBJECT_ATTRIBUTES objectAttributes = InitializeObjectAttributes(objectName); IO_STATUS_BLOCK ioStatusBlock; NTStatus status = NtCreateFile(out handle, (uint)desiredAccess, ref objectAttributes, out ioStatusBlock, ref allocationSize, fileAttributes, shareAccess, createDisposition, createOptions, IntPtr.Zero, 0); fileStatus = (FileStatus)ioStatusBlock.Information; return(status); }
public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext) { handle = null; fileStatus = FileStatus.FILE_DOES_NOT_EXIST; NTCreateAndXRequest request = new NTCreateAndXRequest(); request.FileName = path; request.DesiredAccess = desiredAccess; request.ExtFileAttributes = ToExtendedFileAttributes(fileAttributes); request.ShareAccess = shareAccess; request.CreateDisposition = createDisposition; request.CreateOptions = createOptions; request.ImpersonationLevel = ImpersonationLevel.Impersonation; TrySendMessage(request); SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_NT_CREATE_ANDX); if (reply != null) { if (reply.Commands[0] is NTCreateAndXResponse) { NTCreateAndXResponse response = reply.Commands[0] as NTCreateAndXResponse; handle = response.FID; fileStatus = ToFileStatus(response.CreateDisposition); return(reply.Header.Status); } else if (reply.Commands[0] is ErrorResponse) { return(reply.Header.Status); } } return(NTStatus.STATUS_INVALID_SMB); }
private static extern NTStatus NtCreateFile(out IntPtr handle, uint desiredAccess, ref OBJECT_ATTRIBUTES objectAttributes, out IO_STATUS_BLOCK ioStatusBlock, ref long allocationSize, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, IntPtr eaBuffer, uint eaLength);
public object OpenFile( string filename, bool isDirectory, FileMode fileMode = FileMode.Open, FileAccess fileAccess = FileAccess.Read, FileShare fileShare = FileShare.None, bool forDeletion = false) { AccessMask accessMask = 0; if (fileAccess == FileAccess.Read) { accessMask |= AccessMask.GENERIC_READ; } if (fileAccess == FileAccess.Write) { accessMask |= AccessMask.GENERIC_WRITE; } if (fileAccess == FileAccess.ReadWrite) { accessMask |= AccessMask.GENERIC_WRITE | AccessMask.GENERIC_READ; } if (forDeletion) { accessMask |= AccessMask.DELETE; } ShareAccess shareAccess = ShareAccess.None; if (fileShare == FileShare.Read) { shareAccess |= ShareAccess.Read; } if (fileShare == FileShare.Delete) { shareAccess |= ShareAccess.Delete; } if (fileShare == FileShare.Write) { shareAccess |= ShareAccess.Write; } if (fileShare == FileShare.ReadWrite) { shareAccess |= ShareAccess.Write | ShareAccess.Read; } CreateDisposition createDisposition = CreateDisposition.FILE_SUPERSEDE; if (fileMode == FileMode.CreateNew) { createDisposition = CreateDisposition.FILE_CREATE; } if (fileMode == FileMode.Create) { createDisposition = CreateDisposition.FILE_SUPERSEDE; } if (fileMode == FileMode.Open) { createDisposition = CreateDisposition.FILE_OPEN; } if (fileMode == FileMode.OpenOrCreate) { createDisposition = CreateDisposition.FILE_OPEN_IF; } if (fileMode == FileMode.Truncate) { createDisposition = CreateDisposition.FILE_OVERWRITE_IF; } if (fileMode == FileMode.Append) { createDisposition = CreateDisposition.FILE_OPEN; } CreateOptions createOptions = 0; if (isDirectory) { createOptions |= CreateOptions.FILE_DIRECTORY_FILE; } else { createOptions |= CreateOptions.FILE_NON_DIRECTORY_FILE; } object fileHandle; FileStatus fileStatus; ThrowOnError(FileStore.CreateFile( out fileHandle, out fileStatus, filename, accessMask, SMBLibrary.FileAttributes.Normal, shareAccess, createDisposition, createOptions, null)); return(fileHandle); }
public void CreateDatabase(string databaseName, CreateOptions options = null) { var commandText = _commandFormatter.CreateDatabase(databaseName, options); Execute(cmd => { cmd.ExecuteNonQuery(); }, commandText); }
public static unsafe extern void vlImageCreateDefaultCreateStructure(out CreateOptions createOptions);
public async Task CreateDatabase(string databaseName, CreateOptions options = null) { var commandText = _commandFormatter.CreateDatabase(databaseName, options); await ExecuteNonQueryAsync(commandText); }
public static unsafe extern bool vlImageCreateMultiple(uint uiWidth, uint uiHeight, uint uiFrames, uint uiFaces, uint uiSlices, byte** lpImageDataRGBA8888, ref CreateOptions createOptions);
protected void Button1_Click(object sender, EventArgs e) { try { //Create a GUID to ensure a unique subscriber key string strGUID = System.Guid.NewGuid().ToString(); //Create Subscriber object [Subscribers > My Subscribers > All Subscribers] ExactTarget. Subscriber sub = new Subscriber(); sub.SubscriberKey = strGUID;//required //may not be active in all accounts //some choose to set this to email address sub.EmailAddress = "*****@*****.**";//required sub.EmailTypePreference = EmailType.Text;//EmailType.HTML is the default this only needs to be set to override to Text sub.EmailTypePreferenceSpecified = true; //Create an Array of Lists sub.Lists = new SubscriberList[1];//If a list is not specified the Subscriber will be added to the "All Subscribers" List sub.Lists[0] = new SubscriberList(); sub.Lists[0].ID = 182857;//Available in the UI via List Properties sub.Lists[0].IDSpecified = true; //Subscriber Attributes differ per account. Some may be required to create a Subscriber sub.Attributes = new etAPI.Attribute[2]; sub.Attributes[0] = new etAPI.Attribute(); sub.Attributes[0].Name = "First Name"; sub.Attributes[0].Value = "John"; sub.Attributes[1] = new etAPI.Attribute(); sub.Attributes[1].Name = "Last Name"; sub.Attributes[1].Value = "Smith"; //Create the CreateOptions object for the Create method CreateOptions co = new CreateOptions(); co.SaveOptions = new SaveOption[1]; co.SaveOptions[0] = new SaveOption(); co.SaveOptions[0].SaveAction = SaveAction.UpdateAdd;//This set this call to act as an UpSert, meaning if the Subscriber doesn't exist it will Create if it does it will Update co.SaveOptions[0].PropertyName = "*"; try { string cRequestID = String.Empty; string cStatus = String.Empty; //Call the Create method on the Subscriber object CreateResult[] cResults = client.Create(co, new APIObject[] { sub }, out cRequestID, out cStatus); //Display Results lblMessage.Text += "Overall Status: " + cStatus; lblMessage.Text += "<br/>"; lblMessage.Text += "Number of Results: " + cResults.Length; lblMessage.Text += "<br/>"; //Loop through each object returned and display the StatusMessage foreach (CreateResult cr in cResults) { lblMessage.Text += "Status Message: " + cr.StatusMessage; lblMessage.Text += "<br/>"; } } catch (Exception exCreate) { //Set Message lblMessage.Text += "<br/><br/>CREATE ERROR:<br/>" + exCreate.Message; } } catch (Exception exc) { //Set Message lblMessage.Text += "<br/><br/><h3>ERROR</h3><br/>" + exc.Message; } }