1 import jcifs.smb.SmbFile; 2 import java.util.LinkedList ; 3 import java.util.ListIterator ; 4 import java.net.MalformedURLException ; 5 import java.io.IOException ; 6 import jcifs.util.Hexdump; 7 8 public class CountPerms { 9 10 int maxDepth; 11 int numFiles; 12 int numDirectories; 13 int numMeta; 14 int numMetaWithArch; 15 16 int[] permissionCounts = new int[16]; 17 18 String [] permissionNames = { 19 "Read Only", 20 "Hidden", 21 "System", 22 "Volume ID", 23 "Directory", 24 "Archive", 25 "Device", 26 "Normal", 27 "Temporary", 28 "Sparse", 29 "Reparse Point", 30 "Compressed", 31 "Offline", 32 "Content Indexed", 33 "Encrypted", 34 "Unknown" 35 }; 36 37 CountPerms( int maxDepth ) { 38 this.maxDepth = maxDepth; 39 } 40 41 void traverse( SmbFile f, int depth ) throws MalformedURLException , IOException { 42 43 if( depth == 0 ) { 44 return; 45 } 46 47 SmbFile[] l = f.listFiles(); 48 49 for(int i = 0; l != null && i < l.length; i++ ) { 50 try { 51 int attrs = l[i].getAttributes(); 52 53 if(( attrs & 0x7FEE ) != 0) { 54 if(( attrs & 0x7FCE ) != 0) { 55 numMeta++; 56 } 57 numMetaWithArch++; 58 } 59 for (int b = 0; b < 16; b++) { 60 if(( attrs & (1 << b)) != 0 ) { 61 permissionCounts[b]++; 62 } 63 } 64 65 System.out.print( Hexdump.toHexString( l[i].getAttributes(), 4 ) + ": " ); 66 for( int j = maxDepth - depth; j > 0; j-- ) { 67 System.out.print( " " ); 68 } 69 System.out.println( l[i].getName() ); 70 if( l[i].isDirectory() ) { 71 traverse( l[i], depth - 1 ); 72 } 73 74 if(( attrs & SmbFile.ATTR_DIRECTORY ) != 0 ) { 75 numDirectories++; 76 } else { 77 numFiles++; 78 } 79 } catch( IOException ioe ) { 80 System.out.println( l[i] + ": " + ioe.getMessage() ); 81 } 82 } 83 } 84 85 void run( String url ) throws Exception { 86 traverse( new SmbFile( url ), maxDepth ); 87 88 for (int p = 0; p < 16; p++) { 89 int len = 15 - permissionNames[p].length(); 90 while( len > 0 ) { 91 System.out.print( " " ); 92 len--; 93 } 94 System.out.println( permissionNames[p] + ": " + permissionCounts[p] ); 95 } 96 System.out.println( " num files: " + numFiles ); 97 System.out.println( " num directories: " + numDirectories ); 98 System.out.println( " num both: " + (numFiles + numDirectories) ); 99 System.out.println( " meta req: " + numMeta ); 100 System.out.println( "meta (incl. arch) req: " + numMetaWithArch ); 101 } 102 103 public static void main(String [] argv) throws Exception { 104 105 if( argv.length < 2 ) { 106 System.err.println( "usage: CountPerms <dir> <maxdepth>" ); 107 System.exit(1); 108 } 109 110 int depth = Integer.parseInt( argv[1] ); 111 CountPerms cp = new CountPerms( depth ); 112 cp.run( argv[0] ); 113 } 114 } 115 | Popular Tags |