ApparmorReporting.hpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                     _     _   _   _     __     _                     |
00004 |                    | |   | | | \_/ |   /  \   | |                    |
00005 |                    | |   | | | |_| |  / /\ \  | |                    |
00006 |                    | |__ | | | | | | / ____ \ | |__                  |
00007 |                    |____||_| |_| |_|/ /    \ \|____|                 |
00008 |                                                                      |
00009 |                             apparmor-reporting library                          |
00010 |                                                                      |
00011 |                                         (C) SUSE Linux Products GmbH |
00012 \----------------------------------------------------------------------/
00013 
00014   File:       ApparmorReporting.hpp
00015 
00016   Author:     Matt Barringer <mbarringer@suse.de>
00017   Maintainer: Matt Barringer <mbarringer@suse.de>
00018 
00019   Purpose: To provide an API to work with AppArmor's reporting configuration files,
00020            which consists of an XML file, /etc/apparmor/reports.conf and a crontab,
00021            /etc/apparmor/reports.crontab
00022 /-*/
00027 #ifndef   LIMAL_APPARMOR_REPORTING_HPP
00028 #define   LIMAL_APPARMOR_REPORTING_HPP
00029 
00030 #include <limal/apparmor-reporting/config.h>
00031 #include <blocxx/String.hpp>
00032 #include <blocxx/COWIntrusiveReference.hpp>
00033 #include <blocxx/Map.hpp>
00034 #include <libxml/tree.h>
00035 
00036 namespace LIMAL_NAMESPACE
00037 {
00038 namespace APPARMOR_REPORTING_NAMESPACE
00039 {
00040 
00041 class ReportData
00042 {
00043 public:
00044         ReportData()
00045         {
00046                 mExportCSV = false;
00047                 mExportHTML = false;
00048                 mRunDay = -1;
00049                 mRunHour = 0;
00050                 mRunMinute = 59;
00051         }
00052 
00053         ReportData(const ReportData& data)
00054                 : mReportName(data.mReportName),
00055                   mReportProgram(data.mReportProgram),
00056                   mProfileName(data.mProfileName),
00057                   mResource(data.mResource),
00058                   mAccessMode(data.mAccessMode),
00059                   mApparmorEvent(data.mApparmorEvent),
00060                   mExportPath(data.mExportPath),
00061                   mEmailOne(data.mEmailOne),
00062                   mEmailTwo(data.mEmailTwo),
00063                   mEmailThree(data.mEmailThree),
00064                   mPid(data.mPid),
00065                   mSeverity(data.mSeverity),
00066                   mExportCSV(data.mExportCSV),
00067                   mExportHTML(data.mExportHTML),
00068                   mTimestamp(data.mTimestamp),
00069                   mRunDay(data.mRunDay),
00070                   mRunDayOfWeek(data.mRunDayOfWeek),
00071                   mRunHour(data.mRunHour),
00072                   mRunMinute(data.mRunMinute)
00073         {}
00074 
00075         ReportData* clone() const
00076         {
00077                 return new ReportData(*this);
00078         }
00079 
00080         ReportData& operator=(const ReportData &data)
00081         {
00082                 if (this != &data)
00083                 {
00084                         mReportName = data.mReportName;
00085                         mReportProgram = data.mReportProgram;
00086                         mProfileName = data.mProfileName;
00087                         mResource = data.mResource;
00088                         mAccessMode = data.mAccessMode;
00089                         mApparmorEvent = data.mApparmorEvent;
00090                         mExportPath = data.mExportPath;
00091                         mEmailOne = data.mEmailOne;
00092                         mEmailTwo = data.mEmailTwo;
00093                         mEmailThree = data.mEmailThree;
00094                         mPid = data.mPid;
00095                         mSeverity = data.mSeverity;
00096                         mExportCSV = data.mExportCSV;
00097                         mExportHTML = data.mExportHTML;
00098                         mTimestamp = data.mTimestamp;
00099                         mRunDay = data.mRunDay;
00100                         mRunDayOfWeek = data.mRunDayOfWeek;
00101                         mRunHour = data.mRunHour;
00102                         mRunMinute = data.mRunMinute;
00103                 }
00104                 return *this;
00105         }
00106 
00107         blocxx::String getReportName() { return mReportName; }
00108         void setReportName(const blocxx::String& reportName) { mReportName = reportName; }
00109 
00110         blocxx::String getReportProgram() { return mReportProgram; }
00111         void setReportProgram(const blocxx::String& reportProgram) { mReportProgram = reportProgram; }
00112 
00113         blocxx::String getProfileName() { return mProfileName; }
00114         void setProfileName(const blocxx::String& profileName) { mProfileName = profileName; }
00115 
00116         blocxx::String getResource() { return mResource; }
00117         void setResource(const blocxx::String& resource) { mResource = resource; }
00118 
00119         blocxx::String getAccessMode() { return mAccessMode; }
00120         void setAccessMode(const blocxx::String& accessMode) { mAccessMode = accessMode; }
00121 
00122         blocxx::String getApparmorEvent() { return mApparmorEvent; }
00123         void setApparmorEvent(const blocxx::String& apparmorEvent) { mApparmorEvent = apparmorEvent; }
00124         blocxx::String getExportPath() { return mExportPath; }
00125         void setExportPath(const blocxx::String& exportPath) { mExportPath = exportPath; }
00126 
00127         blocxx::String getEmailOne() { return mEmailOne; }
00128         void setEmailOne(const blocxx::String& emailOne) { mEmailOne = emailOne; }
00129 
00130         blocxx::String getEmailTwo() { return mEmailTwo; }
00131         void setEmailTwo(const blocxx::String& emailTwo) { mEmailTwo = emailTwo; }
00132 
00133         blocxx::String getEmailThree() { return mEmailThree; }
00134         void setEmailThree(const blocxx::String& emailThree) { mEmailThree = emailThree; }
00135 
00136         blocxx::String getPid() { return mPid; }
00137         void setPid(const blocxx::String& pid) { mPid = pid; }
00138 
00139         blocxx::String getSeverity() { return mSeverity; }
00140         void setSeverity(const blocxx::String& severity) { mSeverity = severity; }
00141 
00142         blocxx::String getTimestamp() { return mTimestamp; }
00143         void setTimestamp(const blocxx::String& timestamp) { mTimestamp = timestamp; }
00144 
00145         bool getExportCSV() { return mExportCSV; }
00146         void setExportCSV(bool exportCSV) { mExportCSV = exportCSV; }
00147 
00148         bool getExportHTML() { return mExportHTML; }
00149         void setExportHTML(bool exportHTML) { mExportHTML = exportHTML; }
00150 
00151         int getRunDay() { return mRunDay; }
00152         void setRunDay(int runDay) { mRunDay = runDay; }
00153 
00154         blocxx::String getRunDayOfWeek() { return mRunDayOfWeek; }
00155         void setRunDayOfWeek(const blocxx::String& runDayOfWeek) { mRunDayOfWeek = runDayOfWeek; }
00156 
00157         int getRunHour() { return mRunHour; }
00158         void setRunHour(int runHour) { mRunHour = runHour; }
00159 
00160         int getRunMinute() { return mRunMinute; }
00161         void setRunMinute(int runMinute) { mRunMinute = runMinute; }
00162 
00163 private:
00164         blocxx::String mReportName;
00165         blocxx::String mReportProgram;
00166         blocxx::String mProfileName;
00167         blocxx::String mResource;
00168         blocxx::String mAccessMode; // The access mode that caused the event (r/w/l/m/x)
00169         blocxx::String mApparmorEvent; // ([P]ermit/[R]eject/[A]udit
00170         blocxx::String mExportPath;
00171         blocxx::String mEmailOne;
00172         blocxx::String mEmailTwo;
00173         blocxx::String mEmailThree;
00174         blocxx::String mPid;
00175         blocxx::String mSeverity;
00176         bool mExportCSV;
00177         bool mExportHTML;
00178         blocxx::String mTimestamp;
00179         // Then, the data contained in the crontab
00180         int mRunDay;
00181         blocxx::String mRunDayOfWeek;
00182         int mRunHour;
00183         int mRunMinute;
00184 };
00185 
00186 typedef blocxx::Map<blocxx::String, ReportData> ReportConfig;
00187 
00188 class ApparmorReportingConfig
00189 {
00190 public:
00194         ApparmorReportingConfig(const blocxx::String& xmlPath = "/etc/apparmor/reports.conf",
00195                                 const blocxx::String& crontabPath = "/etc/apparmor/reports.crontab");
00196 
00200         ~ApparmorReportingConfig();
00201 
00207         ReportConfig
00208         readConfig();
00209 
00216         bool
00217         writeConfig(ReportConfig& config);
00218 
00224         void
00225         removeReport(const blocxx::String& name);
00226 
00233         void
00234         writeReport(const blocxx::String& currentName,
00235                      const blocxx::String& newName,
00236                      const ReportData& reportData);
00242         bool
00243         reportExists(const blocxx::String& name);
00244 
00250         ReportData
00251         findReport(const blocxx::String& name);
00257         blocxx::String
00258         getXMLPath();
00259         
00265         void
00266         setXMLPath(const blocxx::String& xmlPath);
00267 
00273         blocxx::String
00274         getCrontabPath();
00275 
00281         void
00282         setCrontabPath(const blocxx::String& crontabPath);
00283 
00284 private:
00285         class Data;
00286         blocxx::COWIntrusiveReference<Data> m_data;
00287         void loadXML();
00288         blocxx::String find_text(xmlNodePtr currentElement, const char *tag);
00289         blocxx::String find_attribute(xmlNodePtr currentElement, const char *tag, const char *attribute);
00290         bool find_crontab_data(ReportData& data);
00291 };
00292 
00293 }      // End of APPARMOR_REPORTING_NAMESPACE
00294 
00295 namespace Apparmor
00296 {
00297         using limal::apparmor_reporting::ApparmorReportingConfig;
00298 }
00299 
00300 
00301 }      // End of LIMAL_NAMESPACE
00302 
00303 #endif // LIMAL_APPARMOR_REPORTING_HPP
00304 

Generated on Sun Sep 23 12:57:55 2007 for limal-apparmor-reporting by  doxygen 1.5.3