2013-08-15 12:04:40 -04:00
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
2023-01-09 12:23:19 +01:00
# Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
2013-08-15 12:04:40 -04:00
# #
# 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. #
#--------------------------------------------------------------------------- #
2019-09-30 15:15:42 +02:00
ONE_LOCATION = ENV [ 'ONE_LOCATION' ]
2018-12-11 12:21:43 +01:00
if ! ONE_LOCATION
2019-09-30 15:15:42 +02:00
LIB_LOCATION = '/usr/lib/one'
2018-12-11 12:21:43 +01:00
else
2019-09-30 15:15:42 +02:00
LIB_LOCATION = ONE_LOCATION + '/lib'
2018-12-11 12:21:43 +01:00
end
2013-08-15 12:04:40 -04:00
2019-09-30 15:15:42 +02:00
require 'erb'
require_relative 'sudoers'
2013-08-15 13:58:43 -04:00
2019-09-30 15:15:42 +02:00
sudoers = Sudoers . new LIB_LOCATION
aliases = sudoers . aliases
aliases . reject! { | _k , v | v . empty? }
2013-08-15 12:04:40 -04:00
2019-09-30 15:15:42 +02:00
puts ERB . new ( DATA . read , nil , '<>' ) . result ( binding )
2013-08-15 12:04:40 -04:00
__END__
2019-09-30 15:15:42 +02:00
Defaults : oneadmin ! requiretty
Defaults : oneadmin secure_path = / sbin: / bin : / usr /s bin : / usr / bin
2013-08-15 12:04:40 -04:00
2019-09-30 15:15:42 +02:00
< % cmd_sets = sudoers . cmds . keys . sort % >
< % cmd_sets.each do | k | ; l = " ONE_ #{ k } " ; v = aliases [ l ] % >
< % if ! v . nil? % >
2013-08-15 15:05:00 -04:00
Cmnd_Alias < %= l %> = < %= v . join ( " , " ) % >
2019-09-30 15:15:42 +02:00
< % end % >
2013-08-15 13:58:43 -04:00
< % end % >
2013-08-15 12:04:40 -04:00
2019-09-30 15:15:42 +02:00
## Command aliases are enabled individually in dedicated
## sudoers files by each OpenNebula component (server, node).
# oneadmin ALL=(ALL) NOPASSWD: <%= cmd_sets.each.sort.collect{|k| "ONE_#{k}"}.join(", ") %>