diff options
Diffstat (limited to 'freeradius3-model.lua')
-rw-r--r-- | freeradius3-model.lua | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/freeradius3-model.lua b/freeradius3-model.lua index df85118..4ec9037 100644 --- a/freeradius3-model.lua +++ b/freeradius3-model.lua @@ -17,6 +17,7 @@ local group = "root" local config local configtable +local macauthfiles -- ################################################################################ -- LOCAL FUNCTIONS @@ -297,11 +298,14 @@ local update_passwd_entry_private = function(self, entry, create) end local get_macauth_files = function() - local files + if macauthfiles then + return macauthfiles + end + local result,errtxt = get_config() if result then -- Find the files by searching for modules / files / usersfile where key="%{Calling-Station-Id}" - files = {} + macauthfiles = {} for i,first in ipairs(configtable) do if string.find(first.name, "^modules$") then for j,second in ipairs(first.value) do @@ -314,7 +318,7 @@ local get_macauth_files = function() key = true end if key and file then - files[#files+1] = file + macauthfiles[#macauthfiles+1] = file break end end @@ -323,7 +327,19 @@ local get_macauth_files = function() end end end - return files, errtxt + return macauthfiles, errtxt +end + +local is_valid_macauth_filename = function(filename) + macauthfiles = macauthfiles or get_macauth_files() + if macauthfiles then + for i,f in ipairs(macauthfiles) do + if filename == f then + return true + end + end + end + return false end -- ################################################################################ @@ -603,4 +619,18 @@ function mymodule.list_macauth_files() return cfe({ type="structure", value=retval, label="List of Freeradius MAC authentication files", errtxt=errtxt }) end +function mymodule.get_macauth_file(self, clientdata) + local filename = clientdata.filename + return modelfunctions.getfiledetails(filename, is_valid_macauth_filename) +end + +function mymodule.update_macauth_file(self, filedetails) + local ret = modelfunctions.setfiledetails(self, filedetails, is_valid_macauth_filename) + if not ret.errtxt then + posix.chmod(filedetails.value.filename.value, "rw-r-----") + posix.chown(filedetails.value.filename.value, posix.getpasswd(owner, "uid") or 0, posix.getpasswd(group, "gid") or 0) + end + return ret +end + return mymodule |