【发布时间】:2010-09-23 01:59:54
【问题描述】:
我在 Windows Server 2003 上使用 ActiveState Perl。
我想在 Windows NTFS 分区上创建一个目录,然后授予 Windows NT 安全组对该文件夹的读取权限。这在 Perl 中可能吗?我是否必须使用 Windows NT 命令或是否有 Perl 模块来执行此操作?
一个小例子将不胜感激!
【问题讨论】:
标签: perl winapi permissions
我在 Windows Server 2003 上使用 ActiveState Perl。
我想在 Windows NTFS 分区上创建一个目录,然后授予 Windows NT 安全组对该文件夹的读取权限。这在 Perl 中可能吗?我是否必须使用 Windows NT 命令或是否有 Perl 模块来执行此操作?
一个小例子将不胜感激!
【问题讨论】:
标签: perl winapi permissions
标准方式是使用Win32::FileSecurity模块:
use Win32::FileSecurity qw(Set MakeMask);
my $dir = 'c:/newdir';
mkdir $dir or die $!;
Set($dir, { 'Power Users'
=> MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) });
请注意,Set 将覆盖该目录的权限。如果你想编辑现有的权限,你需要先Get他们:
my %permissions;
Win32::FileSecurity::Get($dir, \%permissions);
$permissions{'Power Users'}
= MakeMask( qw( READ GENERIC_READ GENERIC_EXECUTE ) ) });
Win32::FileSecurity::Set($dir, \%permissions);
【讨论】:
Here 是 ActivePerl 的通用权限包。
use Win32::Perms;
# Create a new Security Descriptor and auto import permissions
# from the directory
$Dir = new Win32::Perms( 'c:/temp' ) || die;
# One of three ways to remove an ACE
$Dir->Remove('guest');
# Deny access for all attributes (deny read, deny write, etc)
$Dir->Deny( 'joel', FULL );
# Set the directory permissions (no need to specify the
# path since the object was created with it)
$Dir->Set();
# If you are curious about the contents of the SD
# dump the contents to STDOUT $Dir->Dump;
【讨论】: