This file is indexed.

/usr/bin/onedb is in opennebula 4.12.3+dfsg-3.1build1.

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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/usr/bin/env ruby

# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

nk_encoding = nil

if RUBY_VERSION =~ /^1.9/
    Encoding.default_external = Encoding::UTF_8
    Encoding.default_internal = Encoding::UTF_8
    nk_encoding = "UTF-8"
end

NOKOGIRI_ENCODING = nk_encoding

ONE_LOCATION = ENV["ONE_LOCATION"]

if !ONE_LOCATION
    LIB_LOCATION      = "/usr/lib/one"
    RUBY_LIB_LOCATION = LIB_LOCATION + "/ruby"
    VAR_LOCATION      = "/var/lib/one"
    ETC_LOCATION      = "/etc/one"
    LOCK_FILE         = "/var/lock/one/one"
else
    LIB_LOCATION      = ONE_LOCATION + "/lib"
    RUBY_LIB_LOCATION = LIB_LOCATION + "/ruby"
    VAR_LOCATION      = ONE_LOCATION + "/var"
    ETC_LOCATION      = ONE_LOCATION + "/etc"
    LOCK_FILE         = VAR_LOCATION + "/.lock"
end

$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+'/onedb'

require 'cli/command_parser'
require 'onedb'
require 'opennebula'

FORCE={
    :name => "force",
    :short => "-f",
    :large => "--force",
    :description => "Forces the backup even if the DB exists"
}

BACKUP={
    :name => "backup",
    :short => "-b file",
    :large => "--backup file",
    :description => "Use this file to store SQL dump",
    :format => String
}

###############################################################################
# SQLite options
###############################################################################
SQLITE={
    :name => "sqlite",
    :short => "-s file",
    :large => "--sqlite file",
    :format => String,
    :description => "SQLite DB file",
    :proc => lambda { |o, options|
        options[:backend] = :sqlite
        options[:sqlite]  = o
    }
}

###############################################################################
# MySQL options
###############################################################################
SERVER={
    :name => "server",
    :short => "-S host",
    :large => "--server host",
    :format => String,
    :description => "MySQL server hostname or IP. Defaults to localhost",
    :proc => lambda { |o, options|
        options[:backend] = :mysql
        options[:server]  = o
    }
}

PORT={
    :name => "port",
    :short => "-P port",
    :large => "--port port",
    :format => String,
    :description => "MySQL server port. Defaults to 3306",
    :proc => lambda { |o, options|
        options[:backend] = :mysql
        options[:port]  = o
    }
}

USERNAME={
    :name => "username",
    :short => "-u user",
    :large => "--username user",
    :format => String,
    :description => "MySQL username",
    :proc => lambda { |o, options|
        options[:backend] = :mysql
        options[:user]    = o
    }
}

PASSWORD={
    :name => "password",
    :short => "-p pass",
    :large => "--password pass",
    :format => String,
    :description => "MySQL password. Leave unset to be prompted for it",
    :proc => lambda { |o, options|
        options[:backend] = :mysql
        options[:passwd]  = o
    }
}

DBNAME={
    :name => "dbname",
    :short => "-d dbname",
    :large => "--dbname dbname",
    :format => String,
    :description => "MySQL DB name for OpenNebula",
    :proc => lambda { |o, options|
        options[:backend] = :mysql
        options[:db_name] = o
    }
}

###############################################################################
# Slave MySQL options
###############################################################################
SLAVE_SERVER={
    :name => "slave-server",
    :large => "--slave-server host",
    :format => String,
    :description => "Slave MySQL server hostname or IP. Defaults to localhost",
    :proc => lambda { |o, options|
        options[:slave_backend] = :mysql
        options[:slave_server]  = o
    }
}

SLAVE_PORT={
    :name => "slave-port",
    :large => "--slave-port port",
    :format => String,
    :description => "Slave MySQL server port. Defaults to 3306",
    :proc => lambda { |o, options|
        options[:slave_backend] = :mysql
        options[:slave_port]  = o
    }
}

SLAVE_USERNAME={
    :name => "slave-username",
    :large => "--slave-username user",
    :format => String,
    :description => "Slave MySQL username",
    :proc => lambda { |o, options|
        options[:slave_backend] = :mysql
        options[:slave_user]    = o
    }
}

SLAVE_PASSWORD={
    :name => "slave-password",
    :large => "--slave-password pass",
    :format => String,
    :description => "Slave MySQL password. Leave unset to be prompted for it",
    :proc => lambda { |o, options|
        options[:slave_backend] = :mysql
        options[:slave_passwd]  = o
    }
}

SLAVE_DBNAME={
    :name => "slave-dbname",
    :large => "--slave-dbname dbname",
    :format => String,
    :description => "Slave MySQL DB name for OpenNebula",
    :proc => lambda { |o, options|
        options[:slave_backend] = :mysql
        options[:slave_db_name] = o
    }
}

SLAVE_BACKUP={
    :name => "slave-backup",
    :large => "--slave-backup file",
    :description => "Use this file to store SQL dump",
    :format => String
}

cmd=CommandParser::CmdParser.new(ARGV) do
    description <<-EOT.unindent
        This command enables the user to manage the OpenNebula database. It
        provides information about the DB version, means to upgrade it to the
        latest version, and backup tools.
    EOT

    ###########################################################################
    # Global options
    ###########################################################################
    set :option, CommandParser::OPTIONS
    set :option, [SQLITE, SERVER, PORT, USERNAME, PASSWORD, DBNAME]

    ###########################################################################
    # Backup
    ###########################################################################
    backup_desc = <<-EOT.unindent
        Dumps the DB to a file specified in the argument
    EOT

    command :backup, backup_desc, [:output_file, nil], :options=>FORCE do
        begin
            helper = OneDB.new(options)
            helper.backup(args[0], options)
        rescue Exception => e
            [-1, e.message]
        end
    end

    ###########################################################################
    # Version
    ###########################################################################
    version_desc = <<-EOT.unindent
        Prints the current DB version.
        Use -v flag to see also OpenNebula version
    EOT

    command :version , version_desc do
        begin
            helper = OneDB.new(options)
            helper.version(options)
        rescue Exception => e
            [-1, e.message]
        end
    end

    ###########################################################################
    # History
    ###########################################################################
    history_desc = <<-EOT.unindent
        Prints the upgrades history
    EOT

    command :history , history_desc do
        begin
            helper = OneDB.new(options)
            helper.history
        rescue Exception => e
            [-1, e.message]
        end
    end

    ###########################################################################
    # Restore
    ###########################################################################
    restore_desc = <<-EOT.unindent
        Restores the DB from a backup file. Only restores backups generated
        from the same backend (SQLite or MySQL)
    EOT

    command :restore , restore_desc, [:backup_file, nil], :options=>FORCE do
        begin
            helper = OneDB.new(options)
            helper.restore(args[0], options)
        rescue Exception => e
            [-1, e.message]
        end
    end

    ###########################################################################
    # Upgrade
    ###########################################################################
    upgrade_desc = <<-EOT.unindent
        Upgrades the DB to the latest version
        where <version> : DB version (e.g. 1, 3) to upgrade.
                          By default the DB is upgraded to the latest version
    EOT

    command :upgrade , upgrade_desc, [:version, nil], :options=>[FORCE,BACKUP] do
        begin
            helper = OneDB.new(options)
            helper.upgrade(args[0], options)
        rescue Exception => e
            [-1, e.message]
        end
    end

    ###########################################################################
    # fsck
    ###########################################################################
    fsck_desc = <<-EOT.unindent
        Checks the consistency of the DB, and fixes the problems found
    EOT

    command :fsck, fsck_desc, :options=>[FORCE,BACKUP] do
        begin
            helper = OneDB.new(options)
            helper.fsck(options)
        rescue Exception => e
            [-1, e.message]
        end
    end


    ###########################################################################
    # Import slave
    ###########################################################################
    import_slave_desc = <<-EOT.unindent
        Imports an existing federation slave into the federation master database
    EOT

    command :"import-slave", import_slave_desc, :options=>[FORCE,BACKUP,
        SLAVE_SERVER,SLAVE_PORT,SLAVE_USERNAME,SLAVE_PASSWORD,
        SLAVE_DBNAME,SLAVE_BACKUP] do

        begin
            helper = OneDB.new(options)
            helper.import_slave(options)
        rescue Exception => e
            [-1, e.message]
        end
    end
end