I am running a .net Core 3.1 application on a Debian 10 Server. The application has to copy a given Windows source Directory to a Windows network drive. When copying the files and Directories, it has to set the Destination Files and Directories acl to the Source acl.
I tried doing this using Mono.Unix. To access the Windows Network drive on Linux, I mounted to a Diretory in /media.
// get Source Directories Info
var unixSrcDirInfo = new Mono.Unix.UnixDirectoryInfo(dir.FullName);
//get Destination Directory info
var unixDestDirInfo = new Mono.Unix.UnixDirectoryInfo(destinationDir);
//set Destination Directory File Permissions to Source Directory File Permission
unixDestDirInfo.FileAccessPermissions = unixSrcDirInfo.FileAccessPermissions;
unixDestDirInfo.Refresh();
Does somebody have an Idea how to copy the ACL of a file on a Linux Machine?
I tried using System.IO.FileSystem.AccessControl, but that's not allowed on Linux. I tried using Mono.Unix, but it doesn't copy the permissions.
I just want to set the Destination Directorys ACL to the Source Directorys ACL.
Related
I am saving log files on a Raspberry Pi using this method to get the save path:
private static string GetFullFilePath(ISettingsReader settingsReader)
{
StorageFolder appLocalFolder = ApplicationData.Current.LocalFolder;
var logFilPath = appLocalFolder.Path + settingsReader.LogFileName;
return logFilPath;
}
The files are saved at this location on the RPi:
c$\Data\Users\DefaultAccount\AppData\Local\Packages\MyApp_ktn1kqb2ndh66\LocalState\Logs
If I open Device Portal - File Explorer I see a slightly different name for my app: User Folders\LocalAppData\MyApp_1.0.0.0_arm_ktn1kqb2ndh66
There are no files under that link.
If I search for the folder name on the RPi I can find it under c$\Data\ProgramData\Microsoft\Windows\AppRepository\Packages
Where do I have to save the files so that they are available on the Device Portal?
From C# VS2013, I would like to get the whole path of an application that has been indtalled on win 7.
The post with 7 methods at:
http://stackoverflow.com/questions/6041332/best-way-to-get-application-folder-path
cannot help me because I do Not need the path of the current running application.
I need the path of an application that has been installed (but currently not running).
I have tried
string [] allfiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories)
at
http://stackoverflow.com/questions/23736343/recursive-search-for-files-in-root-directory-and-subfolders
But got:
Additional information: Access to the path 'C:\Program Files\MSSomeApp\DATA' is denied.
My C# code:
FileInfo executableFileInfo = new FileInfo("MyApplication.exe"); // It has been installed on win 7.
string executableDirectoryName = executableFileInfo.DirectoryName;
This just returned my current VS2013 working directory. But, actually, "MyApplication.exe" was installed at C:\MyPath.
I need to get the full file path C:\MyPath\, where all libs and exe files (of MyApplication) are there.
Any suggestions ? thanks
Well You can use something like:
string[] paths =
System.IO.Directory.GetFiles(System.Environment.SpecialFolder.ProgramFiles,
"MyApplication.exe", System.IO.SearchOption.AllDirectories);
This will look the Program Files Folder and all its Sub Folders for the file named MyApplication.exe and will return the full path of all of matches
I am a new C# programmer. I made a setup file of an application in Inno setup, but when I use this application after installation, the application crashes when it tries to access (read) an existing folder in the computer (which the user has permission to access otherwise). This folder does not contain any program file, or logs. It just contains some media files which are already in the computer.
I saw the Inno script format, but it shows only how to give permission to access program files/folders only, what about the files which are already there in the computer? Shouldn't the application should have access to files which the user (who installed it)has access to ?
To set permissions on existing files or folders, you can use the Windows cacls command in the [Run] section.
Filename: "{sys}\cacls.exe"; Parameters: """C:\My Folder\My File.ext"" /t /e /g ""Everyone"":f ""Power Users"":f ""Users"":f ""Authenticated Users"":f "; StatusMsg: "Configuring Windows settings..."; Flags: runhidden
Type cacls /? at a command prompt for all available switches and syntax.
It worked when I used
"Permissions: users-modify" in [Dirs] section.
i am trying to create a folder and copy some images into it using c# wpf application.
curName = txt_PoemName.Text;
// Specify a "currently active folder"
string activeDir = #"C:\Program Files\Default Company Name\Setup2\Poems";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, curName);
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
foreach(DictionaryEntry entry in curPoem){
string newFilePath = System.IO.Path.Combine(newPath, entry.Key.ToString() + Path.GetExtension(entry.Value.ToString()));
System.IO.File.Copy(entry.Value.ToString(), newFilePath, true);
}
i have successfully created the folder and images. and also i can access them via application. but i cant see them in the location on my local disk. when i restart the machine , then application also cant see them.how can i solve this?
Sounds like you have encountered UAC Data Redirection
http://blogs.windows.com/windows/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
You need to either force the application to run as an administrator.
How do I force my .NET application to run as administrator?
Or not save your data in a sensitive area. I would recommend saving in a subfolder of
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
It seems I have a strange issue with security:
I have a website with the following folders:
inetpub\wwwroot
inetpub\wwwroot\readyfordownload
The IIS APPPOOL\Classic user has full access to this 'readyfordownload' folder.
Now I have a console APP that creates a zipfile in the readyfordownload folder. This is done from a c# classlib. Strangely enough, the IIS APPOOL cannot access this file, even though it has full control over the folder. Also, the classlib first creates an xlsx file that is later added to the zip. The APPPOOL user does have access to the xlsx file.
If I run the same function in the C# classlib from a code behind in the website, the same zipfile is created and the IIS APPPOOL user CAN access the file....
Any ideas?
zip is created like this (not the actual code, but it is the same)
http://dotnetzip.codeplex.com/
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("test.xlsx");
zip.Save("MyZipFile.zip");
}
OS is windows 2008 R2 web server
ZIP library is Dotnetzip (Ionic)
Update: I am most interested in why the ZIPfile does not get the rights and the xlsx file does....
Have you tried setting the FileAccessSecurity explicitly? Maybe the files are not inheriting the ACL from the directory.
the apppool user can access the xlsx file because your console creates it directly under readyfordownload folder.
the zip file on the other hand is first created in a temp folder and then copied to your folder. This means that the file permissions are wrongly set on the file.
Make sure IIS_IUSR and DefaultAppPool users have access on your wwwroot.
As scottm suggested change your console code to give permissions to the IUSR and DefaultAppPool users on the zip file. Your code should read like:
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("test.xlsx");
zip.Save("MyZipFile.zip");
var accessControl = File.GetAccessControl("MyZipFile.zip");
var fileSystemAccessRule = new FileSystemAccessRule(
#"BUILTIN\IIS_IUSRS",
FileSystemRights.Read | FileSystemRights.ReadAndExecute,
AccessControlType.Allow);
var fileSystemAccessRule2 = new FileSystemAccessRule(
#"IIS AppPool\DefaultAppPool",
FileSystemRights.Read | FileSystemRights.ReadAndExecute,
AccessControlType.Allow);
accessControl.AddAccessRule(fileSystemAccessRule);
accessControl.AddAccessRule(fileSystemAccessRule2);
File.SetAccessControl(path, accessControl);
}
Check Windows EventLog for related errors. For detailed info use ProcessMonitor, so you can see if there is a problem with permissions.
Configure the security of the folder using “advanced securty setting property page”. (Select properties--> security). Also note that the application pool can impersonate the user so that the application may not be serving the request with the identity of the app pool. By default impersonation may not work. You have to set it explicitly in the web config. E.g. <identity impersonate="true" /> or <identity impersonate="true" userName="domain\user" password="password" />
Sriwantha Sri Aravinda