aa.c revision 198b363fff1de9afcee2f26b9aa847316f589afe
/* liblxcapi
*
* Copyright � 2014 Serge Hallyn <serge.hallyn@ubuntu.com>.
* Copyright � 2014 Canonical Ltd.
*
* it under the terms of the GNU General Public License version 2, as
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* Test apparmor rules */
#include <lxc/lxccontainer.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define MYNAME "test-aa"
static void try_to_remove(void)
{
struct lxc_container *c;
if (c) {
if (c->is_defined(c))
c->destroy(c);
}
}
static int test_attach_write_file(void* payload)
{
FILE *f;
if (f) {
printf("yes\n");
fclose(f);
return 1;
}
printf("no\n");
return 0;
}
/*
* try opening a file attached to a container. Return 0 on open fail. Return
* 1 if the file open succeeded. Return -1 if attach itself failed - perhas an
* older kernel.
*/
{
int fret = -1;
int ret;
int pipefd[2];
char result[1024];
if (ret < 0) {
return fret;
}
if (ret < 0) {
goto err1;
}
if (ret < 0) {
goto err2;
}
fret = 1;
fret = 0;
err2:
err1:
return fret;
}
NULL };
"/sys/kernel/uevent_helper",
"/sys/kernel/mm/ksm/pages_to_scan",
NULL };
static bool test_aa_policy(struct lxc_container *c)
{
int i, ret;
for (i = 0; files_to_deny[i]; i++) {
if (ret < 0) {
return true;
}
if (ret > 0) {
files_to_deny[i]);
return false;
}
}
for (i = 0; files_to_allow[i]; i++) {
if (ret < 0) {
return true;
}
if (ret == 0) {
files_to_allow[i]);
return false;
}
}
return true;
}
{
struct lxc_container *c;
if (!c) {
exit(1);
}
if (c->is_defined(c)) {
goto err;
}
goto err;
}
c->save_config(c, NULL);
if (!c->createl(c, "download", NULL, NULL, 0, "-d", "ubuntu", "-r", "trusty", "-a", "amd64", NULL)) {
goto err;
}
c->want_daemonize(c, true);
goto err;
}
if (!test_aa_policy(c)) {
c->stop(c);
goto err;
}
c->stop(c);
exit(0);
err:
exit(1);
}