File: WindowsPrincipal.xml

package info (click to toggle)
monodoc 1.1.18-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 58,432 kB
  • ctags: 4,991
  • sloc: xml: 718,392; cs: 38,337; sh: 3,172; perl: 554; makefile: 303
file content (216 lines) | stat: -rwxr-xr-x 9,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<Type Name="WindowsPrincipal" FullName="System.Security.Principal.WindowsPrincipal">
  <TypeSignature Maintainer="auto" Language="C#" Value="public class WindowsPrincipal : System.Security.Principal.IPrincipal" />
  <AssemblyInfo>
    <AssemblyName>mscorlib</AssemblyName>
    <AssemblyPublicKey>[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00]</AssemblyPublicKey>
    <AssemblyVersion>1.0.5000.0</AssemblyVersion>
  </AssemblyInfo>
  <ThreadSafetyStatement>Gtk# is thread aware, but not thread safe; See the &lt;link location="node:gtk-sharp/programming/threads"&gt;Gtk# Thread Programming&lt;/link&gt; for details.</ThreadSafetyStatement>
  <Docs>
    <summary>This class represents the group membership of an operating system user.</summary>
    <remarks>
      <para>The WindowsPrincipal class can also be used on POSIX compliant operating system.</para>
      <example>
        <code lang="C#">
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;

class WinPrincipal {

     [DllImport ("advapi32.dll", CallingConvention=CallingConvention.StdCall)]
     public static extern bool LogonUser (string lpszUsername, 
          string lpszDomain, string lpszPassword, int dwLogonType,
          int dwLogonProvider, ref IntPtr phToken);

     static void Principal (WindowsIdentity user) 
     {
          WindowsPrincipal wp = new WindowsPrincipal (user);
          while (true) {
               Console.Write ("Enter group name: ");
               string group = Console.ReadLine ();
               if (group == String.Empty)
                    break;

               Console.WriteLine ("\t{0} is {1}a member of {2}{3}", 
                    user.Name,
                    (wp.IsInRole (group) ? String.Empty : "NOT "),
                    group,
                    Environment.NewLine);
          }
     }

     [STAThread]
     static void Main (string[] args)
     {
          bool posix = ((int) Environment.OSVersion.Platform == 128);
          while (true) {
               Console.Write ("Enter username:\t");
               string username = Console.ReadLine ();
               if (username == String.Empty)
                    break;

               WindowsIdentity user = null;
               // check for Posix versus Windows
               if (posix) {
                    user = new WindowsIdentity (username);
               }
               else {
                    Console.Write ("Enter domain:\t");
                    string domain = Console.ReadLine ();
                    Console.Write ("Enter password:\t");
                    string password = Console.ReadLine ();

                    IntPtr token = IntPtr.Zero;
                    // note: we should close that handle
                    LogonUser (username, domain, password, 2, 0, ref token);
                    if (token == IntPtr.Zero) {
                         Console.WriteLine ("Invalid username/domain/password");
                         continue;
                    }

                    user = new WindowsIdentity (token);
               }

               Principal (user);
          }
     }
}  </code>
      </example>
    </remarks>
  </Docs>
  <Base>
    <BaseTypeName>System.Object</BaseTypeName>
  </Base>
  <Interfaces>
    <Interface>
      <InterfaceName>System.Security.Principal.IPrincipal</InterfaceName>
    </Interface>
  </Interfaces>
  <Members>
    <Member MemberName="IsInRole">
      <MemberSignature Language="C#" Value="public virtual bool IsInRole (string role);" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Boolean</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="role" Type="System.String" />
      </Parameters>
      <Docs>
        <summary>Return the membership of the current principal in the specified role.</summary>
        <param name="role">The group name.</param>
        <returns>True if the current identity is a member of the specified role, false otherwise.</returns>
        <remarks>On Unix systems, the role is mapped to Unix groups.   For users to be considered to have a certain role, the role must be listed in the Unix groups (the /etc/group file) and it must contain a list of users that belong to that group.

<para>
For example, if you want to check that the user is in role "USAGNT\\UGR_RBP" the file /etc/group should contain a line like this:
</para><example>
            <code lang="/etc/group">
USAGNT\UGR_RBP:x:300:miguel,don,jon,julia
  </code></example><para>
In this particular example, the users miguel, don, jon and julia belong to the "USAGNT\UGR_RBP" role.
</para></remarks>
      </Docs>
    </Member>
    <Member MemberName="IsInRole">
      <MemberSignature Language="C#" Value="public virtual bool IsInRole (System.Security.Principal.WindowsBuiltInRole role);" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Boolean</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="role" Type="System.Security.Principal.WindowsBuiltInRole" />
      </Parameters>
      <Docs>
        <summary>Return the membership of the current principal in the specified role.</summary>
        <param name="role">A member of the <see cref="T:System.Security.Principal.WindowsBuiltInRole" /> enumeration.</param>
        <returns>True if the current identity is a member of the specified role, false otherwise.</returns>
        <remarks>On POSIX compliant systems the <see cref="M:System.Security.Principal.WindowsBuiltInRole.Administrators" /> group is mapped to the "root" group. All other groups will return false.</remarks>
      </Docs>
    </Member>
    <Member MemberName="IsInRole">
      <MemberSignature Language="C#" Value="public virtual bool IsInRole (int rid);" />
      <MemberType>Method</MemberType>
      <ReturnValue>
        <ReturnType>System.Boolean</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="rid" Type="System.Int32" />
      </Parameters>
      <Docs>
        <summary>Return the membership of the current principal in the specified role.</summary>
        <param name="rid">An integer representing the group.</param>
        <returns>True if the current identity is a member of the specified role, false otherwise.</returns>
        <remarks>The role id, is mapped like this:

<list type="table">
            <listheader>
              <term>Role ID</term>
              <description>Description</description>
            </listheader>
            <item>
              <term>544</term>
              <description>BUILTIN\\Administrators</description>
            </item>
            <item>
              <term>545</term>
              <description>BUILTIN\\Users</description>
            </item>
            <item>
              <term>546</term>
              <description>BUILTIN\\Guests</description>
            </item>
            <item>
              <term>547</term>
              <description>BUILTIN\\Power Users</description>
            </item>
            <item>
              <term>548</term>
              <description>BUILTIN\\Account Operators</description>
            </item>
            <item>
              <term>549</term>
              <description>BUILTIN\\System Operators</description>
            </item>
            <item>
              <term>550</term>
              <description>BUILTIN\\Print Operators</description>
            </item>
            <item>
              <term>551</term>
              <description>BUILTIN\\Backup Operators</description>
            </item>
            <item>
              <term>552</term>
              <description>BUILTIN\\Replicator</description>
            </item></list></remarks>
      </Docs>
    </Member>
    <Member MemberName=".ctor">
      <MemberSignature Language="C#" Value="public WindowsPrincipal (System.Security.Principal.WindowsIdentity ntIdentity);" />
      <MemberType>Constructor</MemberType>
      <ReturnValue />
      <Parameters>
        <Parameter Name="ntIdentity" Type="System.Security.Principal.WindowsIdentity" />
      </Parameters>
      <Docs>
        <summary>Creates the corresponding principal of a WindowsIdentity instance.</summary>
        <param name="ntIdentity">The identity for which the principal will be created.</param>
        <remarks>To be added</remarks>
      </Docs>
    </Member>
    <Member MemberName="Identity">
      <MemberSignature Language="C#" Value="public virtual System.Security.Principal.IIdentity Identity { get; };" />
      <MemberType>Property</MemberType>
      <ReturnValue>
        <ReturnType>System.Security.Principal.IIdentity</ReturnType>
      </ReturnValue>
      <Docs>
        <summary>The operating system identity associated with the current principal.</summary>
        <value>The current identity of the principal. </value>
        <remarks>The returned identity will always be a <see cref="T:System.Security.Principal.WindowsIdentity" /> instance.</remarks>
      </Docs>
    </Member>
  </Members>
</Type>