KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > AclCrawler


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 import jcifs.smb.*;
6
7 public class AclCrawler {
8
9     int maxDepth;
10
11     AclCrawler( int maxDepth ) {
12         this.maxDepth = maxDepth;
13     }
14
15     void traverse( SmbFile f, int depth ) throws MalformedURLException JavaDoc, IOException JavaDoc {
16
17         if( depth == 0 ) {
18             return;
19         }
20
21         SmbFile[] l = f.listFiles();
22
23         for(int i = 0; l != null && i < l.length; i++ ) {
24             try {
25                 System.out.println( l[i] );
26                 ACE[] acl = l[i].getSecurity();
27                 for (int j = 0; j < acl.length; j++) {
28                     System.out.print( acl[j] );
29                     int a = acl[j].getAccessMask();
30                     if ((a & 0xFF000000) != 0) {
31                         if ((a & ACE.GENERIC_ALL) != 0) {
32                             System.out.print( " GENERIC_ALL" );
33                         }
34                         if ((a & ACE.GENERIC_WRITE) != 0) {
35                             System.out.print( " GENERIC_WRITE" );
36                         }
37                         if ((a & ACE.GENERIC_READ) != 0) {
38                             System.out.print( " GENERIC_READ" );
39                         }
40                     }
41                     System.out.println();
42                 }
43                 if( l[i].isDirectory() ) {
44                     traverse( l[i], depth - 1 );
45                 }
46             } catch( IOException JavaDoc ioe ) {
47                 ioe.printStackTrace();
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: AclCrawler <url> <depth>" );
55             System.exit(1);
56         }
57         int depth = Integer.parseInt( argv[1] );
58         AclCrawler sc = new AclCrawler( depth );
59         sc.traverse( new SmbFile( argv[0] ), depth );
60     }
61 }
62
Popular Tags