Skip to content

Commit

Permalink
account for numeric usernames (#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Feb 10, 2025
1 parent 6ae8278 commit d1c7cc8
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions mod_ood_proxy/lib/ood/user_map.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@

--[[
actual_username
What we get from the user mapping script can be an actual
alphanumeric username, UID, or numeric username.
This helper distinguishes between numeric values that are usernames
and numeric values that are infact UIDs.
--]]
function actual_username(username)

local num = tonumber(username)
if num then
local pwd = require "posix.pwd"
local data = pwd.getpwnam(num)

-- it's a numeric username.
if data then
return data.pw_name

-- not a numeric username, so must be a UID.
else
data = pwd.getpwuid(num)
return data.pw_name
end

-- it's not numeric, so just return the string.
else
return username
end
end

--[[
map
Expand All @@ -17,11 +49,7 @@ function map(r, user_map_match, user_map_cmd, remote_user)
handle:close()
end

-- if sys_user is a number, then it's the uid, so convert to username
if tonumber(sys_user) then
local pwd = require "posix.pwd"
sys_user = pwd.getpwuid(tonumber(sys_user)).pw_name
end
sys_user = actual_username(sys_user)

time_user_map = (r:clock() - now)/1000.0
r:debug("Mapped '" .. remote_user .. "' => '" .. (sys_user or "") .. "' [" .. time_user_map .. " ms]")
Expand Down

0 comments on commit d1c7cc8

Please sign in to comment.