C # file creation - how to provide IUSR DELETE?

I have a console program written in C # that runs under the user foo. The program creates a file. In some situations, a web application running under IUSR may be able to delete files created by the console application.

I want to provide a DELETE (or something similar) IUSR when creating a file. How can I do this in C #?

I found FileIOPermission , and I'm not sure what it is, but since you cannot specify a specific user I am "I am sure now what I need."

Has anyone got a good pointer on how to do this?

[By the way, I understand that in some circles, granting IUSR DELETE rights to any files would be quite a tricky thing, but in this case the nature of the files used means that I am glad to grant these rights to IUSR]

0
source share
3 answers

Use Windows Explorer → select the directory where the file is located → right-click → Properties → Security tab → specify the “Change” right to the IUSR_xxx user account.

I assume that you have physical access to the computer running the console application and the web application.

: ntfs System.Security.AccessControl.FileSecurity File.SetAccessControl.

, .

+1

@Sabau: - , , . , , . IUSR, , , / , .

    using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Permissions;
using System.Security.Principal;
using System.Security.AccessControl;

namespace GrantingFilePermsTests
{
    class Program
    {
    static void Main(string[] args)
    {
        string strFilePath1 = "E:/1.txt";
        string strFilePath2 = "E:/2.txt";

        if (File.Exists(strFilePath1))
        {
        File.Delete(strFilePath1);
        }
        if (File.Exists(strFilePath2))
        {
        File.Delete(strFilePath2);
        }

        File.Create(strFilePath1);
        File.Create(strFilePath2);
        // Get a FileSecurity object that represents the
        // current security settings.
        FileSecurity fSecurity = File.GetAccessControl(strFilePath1);

        // Add the FileSystemAccessRule to the security settings.
        fSecurity.AddAccessRule(new FileSystemAccessRule("IUSR_SOMESERVER",FileSystemRights.FullControl,AccessControlType.Allow));

        // Set the new access settings.
        File.SetAccessControl(strFilePath1, fSecurity);



        }
    }
}

.

+2

google NTFS #

+1

Source: https://habr.com/ru/post/1733376/


All Articles