This file is indexed.

/usr/share/doc/libjcifs-java/examples/T2Crawler.java is in libjcifs-java-doc 1.3.19-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* examples for the jcifs smb client library in Java
 * Copyright (C) 2000  "Michael B. Allen" <jcifs at samba dot org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

import jcifs.smb.SmbFile;
import jcifs.util.*;
import java.util.LinkedList;
import java.util.ListIterator;
import java.net.MalformedURLException;
import java.io.IOException;

public class T2Crawler {

    class Semaphore {
        private int value = 0;

        Semaphore() {value = 0;}
        Semaphore(int initial) {value = initial;}

        public synchronized void P() {
            value--;
            if (value < 0) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public synchronized void V() {
            value++;
            notify();
        }
    }

    class CrawlerThread extends Thread {
        LinkedList list;
        Semaphore sem;
        SmbFile dir;
        int depth;


        CrawlerThread( SmbFile dir, Semaphore sem, int depth ) {
            this.dir = dir;
            list = new LinkedList();
            list.add( dir );
            this.sem = sem;
            this.depth = depth;
        }

        public void run() {
            SmbFile d;
            SmbFile l[];

            while( list.isEmpty() == false ) {
                int i;
                d = (SmbFile)list.remove( 0 );
                try {
                    l = d.listFiles();

/* This is flawed. It decrements depth too agressively and causes the
 * thread to finish prematurely. I do not know of a way to fix this
 * because there is no concept of a stack here.
 */
                    depth--;
                    for( i = 0; i < l.length; i++ ) {
                        System.out.println( l[i] );
                    //  if( depth++ > 0 && l[i].isDirectory() && !l[i].isHidden() ) {
                        if( depth > 0 && l[i].isDirectory() ) {
                            list.add( l[i] );
                        }
                    }
                } catch( Exception e ) {
                    System.out.println( d );
                    e.printStackTrace();
                }
            }
            sem.V();
        }
    }

    T2Crawler( String dir, int numThreads, int depth ) throws Exception {
        SmbFile top = new SmbFile( dir );
        Semaphore sem = new Semaphore( numThreads );
        SmbFile[] l = null;
        int i = 0;

        try {
            l = top.listFiles();
            depth--;
            for( i = 0; i < l.length; i++ ) {
                try {
                    System.out.println( l[i] );
                    if( !l[i].isDirectory() || l[i].isHidden() ) {
                        continue;
                    }
                    if( depth > 0 ) {
                        sem.P();
                        (new CrawlerThread( l[i], sem, depth )).start();
                    }
                } catch( Exception e ) {
                    e.printStackTrace();
                }
            }
            for( i = 0; i < l.length; i++ ) {
                try {
                    l[i].canRead();
                } catch(Exception ex) {
                    System.err.println( l[i] );
                    ex.printStackTrace();
                }
            }
        } catch( Exception ex ) {
            System.err.println( l[i] );
            ex.printStackTrace();
        }
    }
    public static void main(String[] argv) throws Exception {
        if( argv.length < 3) {
            System.out.println( "$ java -Djcifs.properties=miallen.prp T2Crawler <dir> <num threads> <depth>");
            System.exit(1);
        }
        new T2Crawler( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
    }
}