Merge pull request #2097 from steffen-kiess/posix-sockets-3
[mono.git] / mcs / class / corlib / System.Security.AccessControl / QualifiedAce.cs
1 //
2 // System.Security.AccessControl.QualifiedAce implementation
3 //
4 // Authors:
5 //      Dick Porter  <dick@ximian.com>
6 //      Atsushi Enomoto  <atsushi@ximian.com>
7 //      Kenneth Bell
8 //
9 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 namespace System.Security.AccessControl {
32         public abstract class QualifiedAce : KnownAce
33         {
34                 private byte [] opaque;
35                 
36                 internal QualifiedAce (AceType type, AceFlags flags,
37                                        byte[] opaque)
38                         : base (type, flags)
39                 {
40                         SetOpaque (opaque);
41                 }
42                 
43                 internal QualifiedAce (byte[] binaryForm, int offset)
44                         : base(binaryForm, offset)
45                 {
46                 }
47
48                 public AceQualifier AceQualifier {
49                         get {
50                                 switch(AceType)
51                                 {
52                                 case AceType.AccessAllowed:
53                                 case AceType.AccessAllowedCallback:
54                                 case AceType.AccessAllowedCallbackObject:
55                                 case AceType.AccessAllowedCompound:
56                                 case AceType.AccessAllowedObject:
57                                         return AceQualifier.AccessAllowed;
58                                 
59                                 case AceType.AccessDenied:
60                                 case AceType.AccessDeniedCallback:
61                                 case AceType.AccessDeniedCallbackObject:
62                                 case AceType.AccessDeniedObject:
63                                         return AceQualifier.AccessDenied;
64                                         
65                                 case AceType.SystemAlarm:
66                                 case AceType.SystemAlarmCallback:
67                                 case AceType.SystemAlarmCallbackObject:
68                                 case AceType.SystemAlarmObject:
69                                         return AceQualifier.SystemAlarm;
70                                         
71                                 case AceType.SystemAudit:
72                                 case AceType.SystemAuditCallback:
73                                 case AceType.SystemAuditCallbackObject:
74                                 case AceType.SystemAuditObject:
75                                         return AceQualifier.SystemAudit;
76                                         
77                                 default:
78                                         throw new ArgumentException("Unrecognised ACE type: " + AceType);
79                                 }
80                         }
81                 }
82                 
83                 public bool IsCallback {
84                         get {
85                                 return AceType == AceType.AccessAllowedCallback
86                                         || AceType == AceType.AccessAllowedCallbackObject
87                                         || AceType == AceType.AccessDeniedCallback
88                                         || AceType == AceType.AccessDeniedCallbackObject
89                                         || AceType == AceType.SystemAlarmCallback
90                                         || AceType == AceType.SystemAlarmCallbackObject
91                                         || AceType == AceType.SystemAuditCallback
92                                         || AceType == AceType.SystemAuditCallbackObject;
93                         }
94                 }
95                 
96                 public int OpaqueLength {
97                         get {
98                                 if (opaque == null)
99                                         return  0;
100                                 return opaque.Length;
101                         }
102                 }
103                 
104                 public byte[] GetOpaque ()
105                 {
106                         if (opaque == null)
107                                 return null;
108                         return (byte []) opaque.Clone();
109                 }
110                 
111                 public void SetOpaque (byte[] opaque)
112                 {
113                         if (opaque == null)
114                                 this.opaque = null;
115                         else
116                                 this.opaque = (byte []) opaque.Clone();
117                 }
118         }
119 }
120