KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SidCrawler


1 import java.util.LinkedList JavaDoc;
2 import java.util.ListIterator JavaDoc;
3 import java.net.MalformedURLException JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 import jcifs.smb.*;
7
8 public class SidCrawler {
9
10     static final byte[] SP = " ".getBytes();
11
12     static void printSpace(int count) {
13         if (count > SP.length)
14             count = SP.length;
15         System.out.write(SP, 0, count);
16     }
17
18     int maxDepth;
19
20     SidCrawler( int maxDepth ) {
21         this.maxDepth = maxDepth;
22     }
23
24     void traverse( SmbFile f, int depth ) throws MalformedURLException JavaDoc, IOException JavaDoc {
25         int indent = maxDepth - depth;
26
27         if( depth == 0 ) {
28             return;
29         }
30
31         SmbFile[] l = f.listFiles();
32
33         for(int i = 0; l != null && i < l.length; i++ ) {
34             try {
35                 printSpace(indent * 4);
36                 ACE[] acl = l[i].getSecurity(true);
37                 System.out.println( l[i] );
38                 for (int ai = 0; ai < acl.length; ai++) {
39                     printSpace((indent + 1) * 4);
40                     System.out.println("+ " + acl[ai].toString());
41                 }
42                 if( l[i].isDirectory() ) {
43                     traverse( l[i], depth - 1 );
44                 }
45             } catch( IOException JavaDoc ioe ) {
46                 System.out.println( l[i] + ":" );
47                 ioe.printStackTrace( System.out );
48             }
49         }
50     }
51
52     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
53         if (argv.length < 2) {
54             System.err.println("usage: SidCrawler <smburl> <depth>");
55             return;
56         }
57         int depth = Integer.parseInt( argv[1] );
58         SidCrawler sc = new SidCrawler( depth );
59         sc.traverse( new SmbFile( argv[0] ), depth );
60     }
61 }
62
Popular Tags