From 06f12e51f6a31a06008a482058107f1511ba2ebf Mon Sep 17 00:00:00 2001 From: Nathan Angelacos Date: Mon, 29 Sep 2008 20:16:06 +0000 Subject: Auditing functions in place git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1536 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/modelfunctions.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib/modelfunctions.lua') diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua index ef0513c..d311ff6 100644 --- a/lib/modelfunctions.lua +++ b/lib/modelfunctions.lua @@ -103,3 +103,37 @@ function validatemulti(multi) end return true end + + +function write_file_with_audit (self, path, str) + local pre = "" + local post = "" + local tmpfile = (self.conf.sessiondir or "/tmp/") .. + (self.sessiondata.userinfo.userid or "unknown") .. "-" .. + os.time() .. ".tmp" + + if type(self.conf) == "table" then + -- we make temporary globals for expand_bash_syntax_vars + local a,b,c = TEMPFILE,CONFFILE,_G.self + TEMPFILE=tmpfile + CONFFILE=path + _G.self=self + + pre = format.expand_bash_syntax_vars(self.conf.audit_precommit or "" ) + post = format.expand_bash_syntax_vars(self.conf.audit_postcommit or "") + TEMPFILE,CONFFILE,_G.self = a,b,c + end + + fs.write_file(tmpfile,str) + + if #pre then + os.execute(pre) + end + + os.rename (tmpfile, path) + + if #post then + os.execute(post) + end + return +end -- cgit v1.2.3