This file is indexed.

/usr/lib/oar/oarproperty is in oar-server 2.5.4-2+deb8u1.

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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/perl -w
# $Id$
#
# This script aims at managing the node properties (list, add, delete).
# To set the properties values, use oarnodesettings.
#
# To use the quiet mode, just do something like:
#   echo -e "mysqlroot\nmysqlpassword\n" | oar_property.pl -q -l

use strict;
use warnings;
use OAR::IO;
use OAR::Conf qw(init_conf get_conf is_conf);
use Getopt::Long;
use OAR::Version;
use OAR::Tools;

my $Old_umask = sprintf("%lo",umask());
umask(oct("022"));

# The functions are appended at the end of this file
sub print_usage();
sub check_property_name($);

Getopt::Long::Configure("gnu_getopt");

my ($Help,  $List_properties, $Quiet, $Varchar);
my @Add_property;
my @Delete_property;
my @Rename_property;
my $Version;
GetOptions( "help|h"   => \$Help,
            "add|a=s"    => \@Add_property,
            "delete|d=s" => \@Delete_property,
            "rename|r=s" => \@Rename_property,
            "list|l"   => \$List_properties,
            "quiet|q"  => \$Quiet,
            "varchar|c"  => \$Varchar,
            "version|V" => \$Version
          ) or exit(1);

if (defined($Version)){
    print("OAR version : ".OAR::Version::get_version()."\n");
    exit(0);
}

if ($Help || (($#Add_property < 0) and ($#Delete_property < 0)  and ($#Rename_property < 0)  and (! defined($List_properties)))) {
    print_usage();
    exit(1);
}

my $base = OAR::IO::connect();

my $query;

if (defined($List_properties)) {
    my %list = OAR::IO::list_resource_properties_fields($base);
    foreach my $l (keys(%list)){
        unless  (OAR::Tools::check_resource_property($l) == 1){
            print("$l\n");
        }
    }
}

foreach my $r (@Delete_property){
    check_property_name($r);

    $base->do("ALTER TABLE resources DROP COLUMN $r")
        or die("DB error: " . $base->errstr."\n");

    if (! $Quiet) {
        print("Removed property: $r\n");
    }
}

foreach my $a (@Add_property){
    check_property_name($a);

    my $req;
    if ($Varchar){
        $req = "ALTER TABLE resources ADD COLUMN $a VARCHAR(255)";
    }else{
        $req = "ALTER TABLE resources ADD COLUMN $a INT";
    }
    $base->do($req)
        or die("DB error: " . $base->errstr."\n");

    if (! $Quiet) {
        print("Added property: $a\n");
    }
}

foreach my $p (@Rename_property){
    my ($old_prop,$new_prop);
    if ($p !~ m/^\s*([a-z0-9_]+)\s*,\s*([a-z0-9_]+)\s*$/m){
        print_usage();
        exit(1);
    }
    $old_prop = $1;
    $new_prop = $2;
    
    check_property_name($old_prop);
    check_property_name($new_prop);
    if (OAR::IO::get_database_type() eq "Pg"){
        $base->do(" ALTER TABLE resources RENAME $old_prop TO $new_prop")
            or die("DB error: " . $base->errstr."\n");
    }else{
        my $sth = $base->prepare("  SHOW FIELDS
                                    FROM resources
                                 ");
        $sth->execute() or die("DB error : ".$base->errstr."\n");
        my $type;
        my $field = "";
        while (($field ne $old_prop) and (my @ref = $sth->fetchrow_array())){
            $field = $ref[0];
            $type = $ref[1];
        }
        $sth->finish();
        die("Unknown field $old_prop\n") if ($field ne $old_prop);
        $base->do(" ALTER TABLE resources CHANGE $old_prop $new_prop $type");
    }

    $base->do(" UPDATE resource_logs
                SET attribute = \'$new_prop\'
                WHERE
                    attribute = \'$old_prop\'")
        or die("DB error: " . $base->errstr."\n");

    $base->do(" UPDATE job_resource_descriptions
                SET res_job_resource_type = \'$new_prop\'
                WHERE
                    res_job_resource_type = \'$old_prop\'")
        or die("DB error: " . $base->errstr."\n");

    if (! $Quiet) {
        print("Rename property $old_prop into $new_prop\n");
    }
}

OAR::IO::disconnect($base);
	
exit(0);


#############################################################################
# FUNCTIONS
#
#Display usage
sub print_usage() {
    print <<EOS;
Usage: $0 [ -l | [ -a [ -V ] | -d ] ] [ -q ] [ -h ]
Manage OAR resource properties
Options:
 -l, --list                             list properties
 -a NAME, --add NAME                    add property
    -c, --varchar                       sql new field of type VARCHAR(255)
                                        (default is integer)
 -d NAME, --delete NAME                 delete property
 -r "OLD_NAME,NEW_NAME", --rename ...   rename property OLD_NAME into NEW_NAME
 -q, --quiet                            quiet mode (no extra output)
 -h, --help                             show this help screen
 -V, --version                          show OAR version
EOS
}

# Check that the given parameter is a valid column name to avoid issues within
# MySQL
sub check_property_name($) {
    my $propertyname = shift;
    if (not $propertyname =~ /^[a-z0-9_]+$/) {
        die("Error: '$propertyname' is not a valid property name");
    }
    if (OAR::Tools::check_resource_property($propertyname) == 1){
        warn("Error: '$propertyname' is a OAR system property and may not be altered\n");
        exit(1);
    }
}
#############################################################################