1#!/opt/local/bin/ruby 2 3AUTH_SUCCESS = "1" 4AUTH_FAILURE = "0" 5 6def respond_with(value, control_path = ENV["auth_control_file"]) 7 File.open(control_path, "w+") do |f| 8 f.puts(value) 9 end 10 exit 0 11end 12 13username = ENV["username"] 14password = ENV["password"] 15 16if password.start_with?("SCRV1") 17 # static-challenge password, need to do some more work 18 require "base64" 19 20 # SCRV1:<b64 password>:<b64 response> 21 _, password, challenge_response = password.split(":", 3) 22 password = Base64.decode64(password) 23 challenge_response = Base64.decode64(challenge_response) 24end 25 26if username == "root" && password == "root" 27 if defined?(challenge_response) 28 respond_with(AUTH_SUCCESS) if challenge_response == "root" 29 else 30 # No challenge response, we're good to go 31 respond_with(AUTH_SUCCESS) 32 end 33end 34 35respond_with(AUTH_FAILURE) 36