KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > SecurityDescriptor


1 /* jcifs smb client library in Java
2  * Copyright (C) 2005 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package jcifs.smb;
20
21 public class SecurityDescriptor {
22
23     public int type;
24     public ACE[] aces;
25
26     public SecurityDescriptor() {
27     }
28     public SecurityDescriptor(byte[] buffer, int bufferIndex, int len) {
29         this.decode(buffer, bufferIndex, len);
30     }
31     public int decode(byte[] buffer, int bufferIndex, int len) {
32         int start = bufferIndex;
33
34         bufferIndex++; // revision
35
bufferIndex++;
36         type = ServerMessageBlock.readInt2(buffer, bufferIndex);
37         bufferIndex += 2;
38         ServerMessageBlock.readInt4(buffer, bufferIndex); // offset to owner sid
39
bufferIndex += 4;
40         ServerMessageBlock.readInt4(buffer, bufferIndex); // offset to group sid
41
bufferIndex += 4;
42         ServerMessageBlock.readInt4(buffer, bufferIndex); // offset to sacl
43
bufferIndex += 4;
44         int daclOffset = ServerMessageBlock.readInt4(buffer, bufferIndex);
45
46         bufferIndex = start + daclOffset;
47
48         bufferIndex++; // revision
49
bufferIndex++;
50         int size = ServerMessageBlock.readInt2(buffer, bufferIndex);
51         bufferIndex += 2;
52         int numAces = ServerMessageBlock.readInt4(buffer, bufferIndex);
53         bufferIndex += 4;
54
55         if (numAces > 4096)
56             throw new RuntimeException JavaDoc( "Invalid SecurityDescriptor" );
57
58         aces = new ACE[numAces];
59         for (int i = 0; i < numAces; i++) {
60             aces[i] = new ACE();
61             bufferIndex += aces[i].decode(buffer, bufferIndex);
62         }
63
64         return bufferIndex - start;
65     }
66     public String JavaDoc toString() {
67         String JavaDoc ret = "SecurityDescriptor:\n";
68         for (int ai = 0; ai < aces.length; ai++) {
69             ret += aces[ai].toString() + "\n";
70         }
71         return ret;
72     }
73 }
74
Popular Tags