2013-04-08 20 views
9

.NETのサービス/クライアント通信用の名前付きパイプを実装していて、this codeを見つけました。パイプのサーバー側を初期化するときに、パイプのセキュリティ記述子を設定する必要がありました。彼らはそれをこのようでした:.NETでのセキュリティIDのローカライゼーション

PipeSecurity pipeSecurity = new PipeSecurity(); 

// Allow Everyone read and write access to the pipe. 
pipeSecurity.SetAccessRule(new PipeAccessRule("Authenticated Users", 
    PipeAccessRights.ReadWrite, AccessControlType.Allow)); 

// Allow the Administrators group full access to the pipe. 
pipeSecurity.SetAccessRule(new PipeAccessRule("Administrators", 
    PipeAccessRights.FullControl, AccessControlType.Allow)); 

をしかし、私はそれを見ている、と私は、文字列、またはAuthenticated UsersAdministrators部品としてSIDを指定心配です。中国語などの言葉で保証される保証は何ですか? (OPの元の質問から抽出された)

+0

OKを。私はそれを自分で確認した。それは動作するようです。 – ahmd0

+5

これを適切な質問/回答のペアに分割することを検討する必要があります。 – slugster

+0

はい、あなた自身の質問に答えることができます。 – DWright

答えて

0

私はこの代替を思い付いた:

PipeSecurity pipeSecurity = new PipeSecurity(); 

// Allow Everyone read and write access to the pipe. 
pipeSecurity.SetAccessRule(new PipeAccessRule(
    "Authenticated Users", 
    new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), 
    PipeAccessRights.ReadWrite, AccessControlType.Allow)); 

// Allow the Administrators group full access to the pipe. 
pipeSecurity.SetAccessRule(new PipeAccessRule(
    "Administrators", 
    new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), 
    PipeAccessRights.FullControl, AccessControlType.Allow)); 
+0

それは私のためには動作しません、文字列と 'SecurityIdentifier'を取るオーバーロードはありません[こちらを参照](https://msdn.microsoft.com/en-us/library/system.io.pipesを参照)。 pipeaccessrule.pipeaccessrule(v = vs.110).aspx)。文字列リテラル ''認証されたユーザ ''と' '管理者''を削除してください。 – doug65536

2

あなたはSIDを取得したIdentityReferenceに変換するWellKnownSidType列挙型を使用することができます。

 var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); 
     var everyone = sid.Translate(typeof(NTAccount)); 
     security.AddAccessRule(new PipeAccessRule(everyone, PipeAccessRights.ReadWrite, AccessControlType.Allow)); 
+1

「Everyone」は素晴らしいアイデアではありません。おそらく少なくともWellKnownSidType.AuthenticatedUserSidが必要です。パラノイア以外の 'WorldSid'(Everyone)を使用する特別な理由はありますか? – doug65536

+0

まさに!かわった。 –

+1

未知のセキュリティ問題に遭遇したときには誰もが良いアイデアです。これを使用すると、コードが正常に動作していることを確認し、実際に必要なセキュリティレベルを絞り込むことができます。 – TheLegendaryCopyCoder

関連する問題