5

我在 Windows Server 2003 上使用 ActiveState Perl。

我想在 Windows NTFS 分区上创建一个目录,然后授予 Windows NT 安全组对该文件夹的读取权限。这在 Perl 中可能吗?我是否必须使用 Windows NT 命令或是否有 Perl 模块来执行此操作?

一个小例子将不胜感激!

4

2 回答 2

10

标准方法是使用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);
于 2008-11-19T17:24:28.310 回答
7

是 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;
于 2008-11-19T16:50:06.817 回答