This file is indexed.

/usr/share/lemonldap-ng/bin/purgeCentralCache is in liblemonldap-ng-portal-perl 1.1.2-1.

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

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
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/perl
#=============================================================================
# Cleaner for LemonLDAP::NG: removes old sessions from Apache::Session
#
# This module is written to be used by cron to clean old sessions from
# Apache::Session. It does not works with Apache::Session::Memcached
#
# This is part of LemonLDAP::NG product, released under GPL
#=============================================================================

use Lemonldap::NG::Common::Conf;
use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Common::Apache::Session;
use strict;

my $debug     = 0;
my $nb_purged = 0;

#=============================================================================
# Load configuration
#=============================================================================
my $lmconf = Lemonldap::NG::Common::Conf->new()
  or die $Lemonldap::NG::Common::Conf::msg;
my $conf = $lmconf->getConf or die "Unable to get configuration ($!)";
my $localconf = $lmconf->getLocalConf(PORTALSECTION)
  or die "Unable to get local configuration ($!)";

if ($localconf) {
    $conf->{$_} = $localconf->{$_} foreach ( keys %$localconf );
}

print "Configuration loaded\n" if $debug;

#=============================================================================
# Timeout
#=============================================================================
$conf->{timeout}         ||= 7200;
$conf->{timeoutActivity} ||= 0;

print "Timeout value: " . $conf->{timeout} . "\n" if $debug;

#=============================================================================
# Apache::Session backends
#=============================================================================
my @backends;
my $module;

# Sessions
if ( defined $conf->{globalStorage}
    and $conf->{globalStorage} ne "Apache::Session::Memcached" )
{

    # Load module
    $module = $conf->{globalStorage};
    eval "use $module";
    die $@ if ($@);
    $conf->{globalStorageOptions}->{backend} = $module;
    $module = 'Lemonldap::NG::Common::Apache::Session';

    # Add module in managed backends
    push @backends, [ $module, $conf->{globalStorageOptions} ];

    print "Session backend $module will be used\n" if $debug;
}

# SAML
if (    defined $conf->{samlStorage}
    and $conf->{samlStorage} ne $conf->{globalStorage}
    and $conf->{samlStorage} ne "Apache::Session::Memcached" )
{

    # Load module
    $module = $conf->{samlStorage};
    eval "use $module";
    die $@ if ($@);
    $conf->{samlStorageOptions}->{backend} = $module;
    $module = 'Lemonldap::NG::Common::Apache::Session';

    # Add module in managed backends
    push @backends, [ $module, $conf->{samlStorageOptions} ];

    print "SAML backend $module will be used\n" if $debug;
}

#=============================================================================
# Load and purge sessions
#=============================================================================
for my $backend (@backends) {

    my ( $storage, $options ) = splice @$backend;
    my @t;

    # Get all expired sessions
    $storage->get_key_from_all_sessions(
        $options,
        sub {
            my $entry = shift;
            my $id    = shift;
            my $time  = time;

            # Do net check sessions without _utime
            return undef unless $entry->{_utime};

            # Session expired
            if ( $time - $entry->{_utime} > $conf->{timeout} ) {
                push @t, $id;
                print "Session $id expired\n" if $debug;
            }

            # User has no activity, so considere the session has expired
            elsif ( $conf->{timeoutActivity}
                and $entry->{_lastSeen}
                and $time - $entry->{_lastSeen} > $conf->{timeoutActivity} )
            {
                push @t, $id;
                print "Session $id inactive\n" if $debug;
            }
            undef;
        }
    );

    # Delete sessions
    for my $id (@t) {
        my %h;
        eval { tie %h, $storage, $id, $options };
        if ($@) {
            print "Error while opening session $id: $@\n" if $debug;
            next;
        }
        eval { tied(%h)->delete; };
        if ($@) {
            print "Error while deleting session $id: $@\n" if $debug;
            next;
        }
        print "Session $id has been purged\n" if $debug;
        $nb_purged++;
    }

    # Remove lock files for File backend
    if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i ) {
        require Apache::Session::Lock::File;
        my $l = new Apache::Session::Lock::File;
        my $lock_directory = $options->{LockDirectory} || $options->{Directory};
        $l->clean( $lock_directory, $conf->{timeout} );
    }
}

#=============================================================================
# Exit with success
#=============================================================================
print "$nb_purged sessions have been purged\n" if $debug;
exit 0;