diff --git a/src/authd/client.cr b/src/authd/client.cr index 5e177ef..1a05633 100644 --- a/src/authd/client.cr +++ b/src/authd/client.cr @@ -99,6 +99,10 @@ module AuthD ], read end + def exit + send_now Request::Exit.new + end + def validate_user(login : String, activation_key : String) send_now Request::ValidateUser.new login, activation_key parse_message [ diff --git a/src/better-parser.cr b/src/better-parser.cr index aa1ce0e..55b7a29 100644 --- a/src/better-parser.cr +++ b/src/better-parser.cr @@ -79,6 +79,15 @@ parser = OptionParser.new do |parser| unrecognized_args_to_context_args.call parser, 2 end + parser.on "exit", "Kill the service." do + parser.banner = "Usage: exit" + Baguette::Log.info "Kill the service." + Context.command = "exit" + opt_authd_login.call parser + opt_help.call parser + unrecognized_args_to_context_args.call parser, 0 + end + parser.on "migration-script", "Add a batch of users from old code base." do parser.banner = "usage: migration-script user-db.txt" Baguette::Log.info "Add a batch of users." diff --git a/src/client.cr b/src/client.cr index 7002690..ff20ca8 100644 --- a/src/client.cr +++ b/src/client.cr @@ -66,6 +66,7 @@ class Actions @the_call["user-migrate"] = ->user_migrate @the_call["migration-script"] = ->migration_script @the_call["user-mod"] = ->user_mod + @the_call["exit"] = ->kill_service @the_call["permission-set"] = ->permission_set @the_call["permission-check"] = ->permission_check @@ -192,6 +193,14 @@ class Actions puts "error: #{e.message}" end + def kill_service + puts "Kill the service." + authd.exit + rescue e : AuthD::Exception + puts "error: #{e.message}" + end + + def user_change_password args = Context.args.not_nil! login = args[0] diff --git a/src/requests/admin.cr b/src/requests/admin.cr index 1e1e0d2..dbf669f 100644 --- a/src/requests/admin.cr +++ b/src/requests/admin.cr @@ -120,4 +120,23 @@ class AuthD::Request end end AuthD.requests << DecodeToken + + IPC::JSON.message Exit, 248 do + def initialize + end + + def to_s(io : IO) + super io + end + + def handle(authd : AuthD::Service, fd : Int32) + logged_user = authd.get_logged_user_full? fd + return Response::ErrorMustBeAuthenticated.new if logged_user.nil? + logged_user.assert_permission("authd", "*", User::PermissionLevel::Admin) + + Baguette::Log.warning "exit requested, bye" + exit 0 + end + end + AuthD.requests << Exit end