Logs: clean user info, not just a file descriptor.
This commit is contained in:
parent
d9da42eeeb
commit
f92cadf634
@ -61,8 +61,11 @@ class DNSManager::Service < IPC
|
|||||||
self.service_init @configuration.service_name
|
self.service_init @configuration.service_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_logged_user(event : IPC::Event)
|
def get_logged_user(fd : Int32) : AuthD::User::Public?
|
||||||
@logged_users[event.fd]?
|
@logged_users[fd]?
|
||||||
|
end
|
||||||
|
def get_logged_user(event : IPC::Event) : AuthD::User::Public?
|
||||||
|
get_logged_user event.fd
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode_token(token : String)
|
def decode_token(token : String)
|
||||||
@ -92,6 +95,17 @@ class DNSManager::Service < IPC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# `log_user_info` provides a string composed from either the user
|
||||||
|
# id in case the user was authenticated or the file descriptor of
|
||||||
|
# the connection.
|
||||||
|
def log_user_info(fd : Int32) : String
|
||||||
|
if user = get_logged_user fd
|
||||||
|
"userid #{user.uid}"
|
||||||
|
else
|
||||||
|
"fd #{"%4d" % fd}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_request(event : IPC::Event)
|
def handle_request(event : IPC::Event)
|
||||||
request_start = Time.utc
|
request_start = Time.utc
|
||||||
|
|
||||||
@ -105,38 +119,39 @@ class DNSManager::Service < IPC
|
|||||||
end
|
end
|
||||||
|
|
||||||
reqname = request.class.name.sub /^DNSManager::Request::/, ""
|
reqname = request.class.name.sub /^DNSManager::Request::/, ""
|
||||||
|
connection_info_str = log_user_info event.fd
|
||||||
|
|
||||||
response = begin
|
response = begin
|
||||||
request.handle self, event
|
request.handle self, event
|
||||||
rescue e : AuthorizationException
|
rescue e : AuthorizationException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} authorization error"
|
Baguette::Log.error "(#{connection_info_str}) #{request} authorization error"
|
||||||
Response::Error.new "authorization error"
|
Response::Error.new "authorization error"
|
||||||
rescue e : DomainNotFoundException
|
rescue e : DomainNotFoundException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} domain not found"
|
Baguette::Log.error "(#{connection_info_str}) #{request} domain not found"
|
||||||
Response::DomainNotFound.new
|
Response::DomainNotFound.new
|
||||||
rescue e : CannotCheckPermissionsException
|
rescue e : CannotCheckPermissionsException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} cannot check permissions of user '#{e.uid}' on resource '#{e.resource}'"
|
Baguette::Log.error "(#{connection_info_str}) #{request} cannot check permissions of user '#{e.uid}' on resource '#{e.resource}'"
|
||||||
Response::InsufficientRights.new
|
Response::InsufficientRights.new
|
||||||
rescue e : UnknownUserException
|
rescue e : UnknownUserException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} unknown user"
|
Baguette::Log.error "(#{connection_info_str}) #{request} unknown user"
|
||||||
Response::UnknownUser.new
|
Response::UnknownUser.new
|
||||||
rescue e : NoOwnershipException
|
rescue e : NoOwnershipException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} no ownership error"
|
Baguette::Log.error "(#{connection_info_str}) #{request} no ownership error"
|
||||||
Response::NoOwnership.new
|
Response::NoOwnership.new
|
||||||
rescue e : NotLoggedException
|
rescue e : NotLoggedException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} user not logged"
|
Baguette::Log.error "(#{connection_info_str}) #{request} user not logged"
|
||||||
Response::Error.new "user not logged"
|
Response::Error.new "user not logged"
|
||||||
rescue e : RRNotFoundException
|
rescue e : RRNotFoundException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} RR not found"
|
Baguette::Log.error "(#{connection_info_str}) #{request} RR not found"
|
||||||
Response::RRNotFound.new
|
Response::RRNotFound.new
|
||||||
rescue e : TokenNotFoundException
|
rescue e : TokenNotFoundException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} Token not found"
|
Baguette::Log.error "(#{connection_info_str}) #{request} Token not found"
|
||||||
Response::Error.new "token not found"
|
Response::Error.new "token not found"
|
||||||
rescue e : RRReadOnlyException
|
rescue e : RRReadOnlyException
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} RR is read only"
|
Baguette::Log.error "(#{connection_info_str}) #{request} RR is read only"
|
||||||
Response::RRReadOnly.new e.domain, e.rr
|
Response::RRReadOnly.new e.domain, e.rr
|
||||||
rescue e # Generic case
|
rescue e # Generic case
|
||||||
Baguette::Log.error "(fd #{"%4d" % event.fd}) #{request} generic error #{e}"
|
Baguette::Log.error "(#{connection_info_str}) #{request} generic error #{e}"
|
||||||
Response::Error.new "generic error"
|
Response::Error.new "generic error"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -149,10 +164,10 @@ class DNSManager::Service < IPC
|
|||||||
duration = Time.utc - request_start
|
duration = Time.utc - request_start
|
||||||
|
|
||||||
if response.is_a? DNSManager::Response::Error
|
if response.is_a? DNSManager::Response::Error
|
||||||
Baguette::Log.warning "fd #{"%4d" % event.fd} (#{duration}) #{request} >> #{response}"
|
Baguette::Log.warning "(#{connection_info_str}) (#{duration}) #{request} >> #{response}"
|
||||||
else
|
else
|
||||||
if reqname != "KeepAlive" || should_display? DNSMESSAGE::KEEPALIVE
|
if reqname != "KeepAlive" || should_display? DNSMESSAGE::KEEPALIVE
|
||||||
Baguette::Log.debug "fd #{"%4d" % event.fd} (#{duration}) #{request} >> #{response}"
|
Baguette::Log.debug "(#{connection_info_str}) (#{duration}) #{request} >> #{response}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user