Skip to content

Need one step API for creating files on Windows with security #27021

@JeremyKuhne

Description

@JeremyKuhne

The Framework (NetFX) APIs for applying security to created files are as follows:

namespace System.IO
{
    public static class File
    {
        public static FileStream Create(string path, int bufferSize, FileOptions options, FileSecurity fileSecurity);
    }

    public static class Directory
    {
        public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity);
    }

    public class FileStream : Stream
    {
        public FileStream(string path, FileMode mode, FileSystemRights rights, FileShare share, int bufferSize, FileOptions options, FileSecurity fileSecurity);
    }
}

The Windows specific security in .NET Core is in System.IO.FileSystem.AccessControl. We currently have no way to set security before creating an object. To facilitate porting from .NET Framework we should add some static helpers to FileSecurity and DirectorySecurity that allow doing this in one step. Not only is this easier, it is safer than trying to add to an existing object.

namespace System.Security.AccessControl
{
    public sealed partial class FileSecurity : System.Security.AccessControl.FileSystemSecurity
    {
        public static FileStream CreateFileStream(string path, int bufferSize, FileOptions options, FileSecurity fileSecurity);
        public static FileStream CreateFileStream(string path, FileMode mode, FileSystemRights rights, FileShare share, int bufferSize, FileOptions options, FileSecurity fileSecurity);
    }

    public sealed partial class DirectorySecurity : System.Security.AccessControl.FileSystemSecurity
    {
        public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity);
    }
}

These APIs are showing up in customer projects that they're attempting to move to Core.

cc: @pjanotti, @danmosemsft

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions