2013-09-27 16:16:37 -07:00
|
|
|
/*
|
2013-10-14 14:34:12 -07:00
|
|
|
* Copyright (c) 2012, 2013
|
2013-09-27 16:16:37 -07:00
|
|
|
* Canonical, Ltd. (All rights reserved)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
|
|
* License published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "profile.h"
|
2014-04-07 03:16:50 -07:00
|
|
|
#include "rule.h"
|
2013-09-27 16:16:37 -07:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
bool deref_profileptr_lt::operator()(Profile * const &lhs, Profile * const &rhs) const
|
|
|
|
{
|
|
|
|
return *lhs < *rhs;
|
|
|
|
};
|
|
|
|
|
|
|
|
pair<ProfileList::iterator,bool> ProfileList::insert(Profile *p)
|
|
|
|
{
|
|
|
|
return list.insert(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileList::erase(ProfileList::iterator pos)
|
|
|
|
{
|
|
|
|
list.erase(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileList::clear(void)
|
|
|
|
{
|
|
|
|
for(ProfileList::iterator i = list.begin(); i != list.end(); ) {
|
|
|
|
ProfileList::iterator k = i++;
|
|
|
|
delete *k;
|
|
|
|
list.erase(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileList::dump(void)
|
|
|
|
{
|
|
|
|
for(ProfileList::iterator i = list.begin(); i != list.end(); i++) {
|
|
|
|
(*i)->dump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileList::dump_profile_names(bool children)
|
|
|
|
{
|
|
|
|
for (ProfileList::iterator i = list.begin(); i != list.end();i++) {
|
|
|
|
(*i)->dump_name(true);
|
|
|
|
printf("\n");
|
|
|
|
if (children && !(*i)->hat_table.empty())
|
|
|
|
(*i)->hat_table.dump_profile_names(children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Profile::~Profile()
|
|
|
|
{
|
|
|
|
hat_table.clear();
|
|
|
|
free_cod_entries(entries);
|
2014-04-07 03:16:50 -07:00
|
|
|
|
|
|
|
for (RuleList::iterator i = rule_ents.begin(); i != rule_ents.end(); i++)
|
|
|
|
delete *i;
|
2013-09-27 16:16:37 -07:00
|
|
|
if (dfa.rules)
|
2014-04-23 10:57:16 -07:00
|
|
|
delete dfa.rules;
|
2013-09-27 16:16:37 -07:00
|
|
|
if (dfa.dfa)
|
|
|
|
free(dfa.dfa);
|
|
|
|
if (policy.rules)
|
2014-04-23 10:57:16 -07:00
|
|
|
delete policy.rules;
|
2013-09-27 16:16:37 -07:00
|
|
|
if (policy.dfa)
|
|
|
|
free(policy.dfa);
|
2013-10-14 14:34:12 -07:00
|
|
|
if (xmatch)
|
|
|
|
free(xmatch);
|
2013-09-27 16:16:37 -07:00
|
|
|
if (name)
|
|
|
|
free(name);
|
|
|
|
if (attachment)
|
|
|
|
free(attachment);
|
|
|
|
if (ns)
|
|
|
|
free(ns);
|
2013-10-14 14:34:12 -07:00
|
|
|
for (int i = (AA_EXEC_LOCAL >> 10) + 1; i < AA_EXEC_COUNT; i++)
|
|
|
|
if (exec_table[i])
|
|
|
|
free(exec_table[i]);
|
2013-09-27 16:16:37 -07:00
|
|
|
if (net.allow)
|
|
|
|
free(net.allow);
|
|
|
|
if (net.audit)
|
|
|
|
free(net.audit);
|
|
|
|
if (net.deny)
|
|
|
|
free(net.deny);
|
|
|
|
if (net.quiet)
|
|
|
|
free(net.quiet);
|
|
|
|
}
|
|
|
|
|