2005-06-05 Peter Bartok <pbartok@novell.com>
[mono.git] / mcs / class / corlib / System.Security.Permissions / FileIOPermissionAttribute.cs
1 //
2 // System.Security.Permissions.FileIOPermissionAttribute.cs
3 //
4 // Authors
5 //      Duncan Mak <duncan@ximian.com>
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
9 // Portions Copyright (C) 2003 Motus Technologies (http://www.motus.com)
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 namespace System.Security.Permissions {
33
34         [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class |
35                          AttributeTargets.Struct | AttributeTargets.Constructor |
36                          AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
37         [Serializable]
38         public sealed class FileIOPermissionAttribute : CodeAccessSecurityAttribute {
39
40                 // Fields
41                 private string append;
42                 private string path;
43                 private string read;
44                 private string write;
45 #if NET_2_0
46                 private FileIOPermissionAccess allFiles;
47                 private FileIOPermissionAccess allLocalFiles;
48                 private string changeAccessControl;
49                 private string viewAccessControl;
50                 private string viewAndModify;
51 #endif
52
53                 // Constructor
54                 public FileIOPermissionAttribute (SecurityAction action) : base (action)
55                 {
56                 }
57                 
58                 // Properties
59 #if NET_2_0
60                 [Obsolete ("use newer properties")]
61 #endif
62                 public string All {
63 #if NET_1_1
64                         get { throw new NotSupportedException ("All"); }
65 #endif
66                         set {
67                                 append = value; 
68                                 path = value;
69                                 read = value;
70                                 write = value;
71                         }
72                 }
73
74                 public string Append {
75                         get { return append; }
76                         set { append = value; }
77                 }
78
79                 public string PathDiscovery {
80                         get { return path; }
81                         set { path = value; }
82                 }
83
84                 public string Read {
85                         get { return read; }
86                         set { read = value; }
87                 }                                   
88                 
89                 public string Write {
90                         get { return write; }
91                         set { write = value; }
92                 }
93
94 #if NET_2_0
95                 public FileIOPermissionAccess AllFiles {
96                         get { return allFiles; }
97                         set { allFiles = value; }
98                 }
99
100                 public FileIOPermissionAccess AllLocalFiles {
101                         get { return allLocalFiles; }
102                         set { allLocalFiles = value; }
103                 }
104
105                 public string ChangeAccessControl {
106                         get { return changeAccessControl; }
107                         set { changeAccessControl = value; }
108                 }
109
110                 public string ViewAccessControl {
111                         get { return viewAccessControl; }
112                         set { viewAccessControl = value; }
113                 }
114
115                 public string ViewAndModify {
116                         get { throw new NotSupportedException (); }     // as documented
117                         set {
118                                 append = value;
119                                 path = value;
120                                 read = value;
121                                 write = value;
122                         }
123                 }
124 #endif
125                          
126                 // Methods
127                 public override IPermission CreatePermission ()
128                 {
129                         FileIOPermission perm = null;
130                         if (this.Unrestricted)
131                                 perm = new FileIOPermission (PermissionState.Unrestricted);
132                         else {
133                                 perm = new FileIOPermission (PermissionState.None);
134                                 if (append != null)
135                                         perm.AddPathList (FileIOPermissionAccess.Append, append);
136                                 if (path != null)
137                                         perm.AddPathList (FileIOPermissionAccess.PathDiscovery, path);
138                                 if (read != null)
139                                         perm.AddPathList (FileIOPermissionAccess.Read, read);
140                                 if (write != null)
141                                         perm.AddPathList (FileIOPermissionAccess.Write, write);
142                         }
143                         return perm;
144                 }
145         }
146 }