From 29de360eb486521a4e65d6e1452a8c623201c945 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 16 Aug 2008 15:21:41 +0000 Subject: Modified roles and authenticator to delete all data fields when deleting a role or user. Modified all roles code to pass self for future move from text file to database. Roles cannot use authenticator unless or until roles file syntax is changed. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1382 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/authenticator-plaintext.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/authenticator-plaintext.lua') diff --git a/lib/authenticator-plaintext.lua b/lib/authenticator-plaintext.lua index aa3e2e3..e90520d 100644 --- a/lib/authenticator-plaintext.lua +++ b/lib/authenticator-plaintext.lua @@ -9,8 +9,23 @@ create a different file for each field. module (..., package.seeall) +list_fields = function(self, tabl) + if not self or not tabl or tabl == "" then + return {} + end + + local fields = {} + for file in fs.find(".*"..tabl, self.conf.confdir) do + local field = string.match(file, "([^/]*)"..tabl.."$") or "" + if fs.is_file(file) and field ~= "" then + fields[#fields + 1] = field + end + end + return fields +end + read_field = function(self, tabl, field) - if not tabl or tabl == "" or not field then + if not self or not tabl or tabl == "" or not field then return nil end @@ -34,7 +49,7 @@ read_field = function(self, tabl, field) end delete_field = function(self, tabl, field) - if not tabl or tabl == "" or not field then + if not self or not tabl or tabl == "" or not field then return false end local passwd_path = self.conf.confdir .. field .. tabl @@ -95,5 +110,13 @@ delete_entry = function (self, tabl, field, id) fs.write_file(passwd_path, table.concat(output,"\n")) end + -- If deleting the main field, delete all other fields also + if field == "" then + local fields = list_fields(self, tabl) + for i,fld in ipairs(fields) do + delete_entry(self, tabl, fld, id) + end + end + return result end -- cgit v1.2.3