Use SID S-1-1-0 instead of EVERYONE for non-english systems

This commit is contained in:
Mark McDowall 2013-08-12 17:22:35 -07:00
parent d8da292516
commit 4d65f05000
3 changed files with 9 additions and 9 deletions

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.EnvironmentInfo;
@ -38,7 +39,7 @@ namespace NzbDrone.Common
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
bool IsFileLocked(FileInfo file);
string GetPathRoot(string path);
void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType);
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
bool IsParent(string parentPath, string childPath);
FileAttributes GetFileAttributes(string path);
}
@ -243,7 +244,6 @@ namespace NzbDrone.Common
break;
}
}
}
}
@ -403,17 +403,16 @@ namespace NzbDrone.Common
return Path.GetPathRoot(path);
}
public void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType)
public void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType)
{
try
{
var sid = new SecurityIdentifier(accountSid, null);
var directoryInfo = new DirectoryInfo(filename);
var directorySecurity = directoryInfo.GetAccessControl();
var accessRule = new FileSystemAccessRule(account, rights,
var accessRule = new FileSystemAccessRule(sid, rights,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, controlType);
@ -423,7 +422,7 @@ namespace NzbDrone.Common
}
catch (Exception e)
{
Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, account, rights, controlType), e);
Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType), e);
throw;
}

View File

@ -2,6 +2,7 @@
using System.IO;
using System.Reflection;
using System.Security.AccessControl;
using System.Security.Principal;
using NLog;
namespace NzbDrone.Common.EnvironmentInfo
@ -47,7 +48,7 @@ namespace NzbDrone.Common.EnvironmentInfo
{
try
{
_diskProvider.SetPermissions(AppDataFolder, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
_diskProvider.SetPermissions(AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.FullControl, AccessControlType.Allow);
}
catch (Exception ex)
{

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Host.AccessControl
private void RegisterUrl(int portNumber)
{
var arguments = String.Format("http add urlacl http://*:{0}/ user=EVERYONE", portNumber);
var arguments = String.Format("http add urlacl http://*:{0}/ sddl=D:(A;;GX;;;S-1-1-0)", portNumber);
RunNetsh(arguments);
}