ネットワーク上の特定のフォルダへの書き込みアクセスを取得できることを確認する必要がある状況があります。したがって、最初に、ユーザーまたはそれが属するグループの 1 つ (ドメイン グループ) が、アクセス ルールの ID の 1 つであることを確認します。そうでない場合は、リモート マシン上のすべてのローカル グループを確認して、自分のユーザーまたはユーザーのグループの 1 つがマシン上のローカル グループのメンバーであるかどうかを確認する必要があります。たとえば、この特定のマシンでは、私は BUILTIN\Administrators のメンバーです。つまり、特定のフォルダーへの書き込みアクセス権があります。ただし、リモート マシンからそのローカル グループを取得して、書き込みアクセス権があるかどうかを確認する方法が明確ではありません。
以下のコードで、GroupPrincipal.FindByIdentity を使用しようとすると、「バインディング ハンドルが無効です」という例外が発生します。何が無効なのかわかりません。ctx.ValidateCredentials(UserName, Password) を使用して、自分のユーザー名とパスワード (ドメイン ユーザー名) を確認しようとすると、まったく同じエラーが発生します。
マシン名を「pvr-pc」とだけ指定すると、ネットワーク上で名前が見つからないと表示されますが、「\\pvr-pc」はその問題をうまく解決します。
同じコードは、私が所属しているグループの 1 つが、ローカル マシンの BUILTIN\Administrators にあるグループであることを正しく検出するため、問題はネットワーク アクセスに関するものです。
私が間違ったことを誰かが考えていますか?
コードは次のようになります。
using (WindowsIdentity identity = GetUserIdentity())
{
if (identity != null)
{
try
{
FileInfo fi = new FileInfo(@"\\pvr-pc\c\installers\");
AuthorizationRuleCollection acl = fi.GetAccessControl().GetAccessRules
(true, true, typeof (SecurityIdentifier));
var rules = acl.Cast<FileSystemAccessRule>();
List<string> sids = new List<string>();
sids.Add(identity.User.Value);
sids.AddRange(identity.Groups.Select(identityReference => identityReference.Value));
// check for a direct user match
var matches = from r in rules where sids.Contains(r.IdentityReference.Value) select r;
foreach (FileSystemAccessRule accessRule in matches)
{
// apply rules
}
foreach (FileSystemAccessRule rule in rules)
{
// if it is built in, try and get the group
var groupDetail = rule.IdentityReference.Translate(typeof (NTAccount));
if (!groupDetail.Value.StartsWith("BUILTIN\\")) continue;
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, @"\\pvr-pc", null,
ContextOptions.Negotiate, UserName, Password);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Sid,
rule.IdentityReference.Value);
if (grp != null)
{
//// find out if we are a member of the group
var isInGroup = (from g in grp.GetMembers(true)
where sids.Contains(g.Sid.ToString())
select g).Any();
if (isInGroup)
{
// apply rules
}
}
}
}
catch (Exception ex)
{
}
ありがとう、ステファン