From 0aca3eec9586aa1ba46355731c4334c447da0288 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 22 Feb 2017 14:23:41 +0000 Subject: Adjust passwd and macauth to check for files config at root (cherry picked from commit a9e25de22f10a5521bd141bdebe76175ebec7a53) --- freeradius3-model.lua | 58 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'freeradius3-model.lua') diff --git a/freeradius3-model.lua b/freeradius3-model.lua index fd799a1..6530b05 100644 --- a/freeradius3-model.lua +++ b/freeradius3-model.lua @@ -109,19 +109,26 @@ local get_passwd_files = function() local configs local result,errtxt = get_config() if result then - -- Find the files by searching for modules / passwd + -- Find the files by searching for [modules] / passwd files = {} configs = {} + + function checkpasswd(value) + for k,third in ipairs(value) do + if string.find(third.name, "^filename$") then + files[#files+1] = third.value + configs[#configs+1] = value + end + end + end + for i,first in ipairs(configtable) do - if string.find(first.name, "^modules$") then + if string.find(first.name, "^passwd ") then + checkpasswd(first.value) + elseif string.find(first.name, "^modules$") then for j,second in ipairs(first.value) do if string.find(second.name, "^passwd ") then - for k,third in ipairs(second.value) do - if string.find(third.name, "^filename$") then - files[#files+1] = third.value - configs[#configs+1] = second.value - end - end + checkpasswd(second.value) end end end @@ -314,24 +321,31 @@ local get_macauth_files = function() local result,errtxt = get_config() if result then - -- Find the files by searching for modules / files / usersfile where key="%{Calling-Station-Id}" + -- Find the files by searching for [modules] / files / usersfile where key="%{Calling-Station-Id}" macauthfiles = {} + + function checkfiles(value) + local key,file + for k,third in ipairs(value) do + if string.find(third.name, "^usersfile$") then + file = third.value + elseif string.find(third.name, "^key$") and string.find(third.value, format.escapemagiccharacters("%{Calling-Station-Id}")) then + key = true + end + if key and file then + macauthfiles[#macauthfiles+1] = file + break + end + end + end + for i,first in ipairs(configtable) do - if string.find(first.name, "^modules$") then + if string.find(first.name, "^files ") then + checkfiles(first.value) + elseif string.find(first.name, "^modules$") then for j,second in ipairs(first.value) do if string.find(second.name, "^files ") then - local key,file - for k,third in ipairs(second.value) do - if string.find(third.name, "^usersfile$") then - file = third.value - elseif string.find(third.name, "^key$") and string.find(third.value, format.escapemagiccharacters("%{Calling-Station-Id}")) then - key = true - end - if key and file then - macauthfiles[#macauthfiles+1] = file - break - end - end + checkfiles(second.value) end end end -- cgit v1.2.3