Blame tests/39-basic-api_level.c
|
Packit |
56e23f |
/**
|
|
Packit |
56e23f |
* Seccomp Library test program
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* Copyright (c) 2017 Red Hat <pmoore@redhat.com>
|
|
Packit |
56e23f |
* Author: Paul Moore <paul@paul-moore.com>
|
|
Packit |
56e23f |
*/
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
/*
|
|
Packit |
56e23f |
* This library is free software; you can redistribute it and/or modify it
|
|
Packit |
56e23f |
* under the terms of version 2.1 of the GNU Lesser General Public License as
|
|
Packit |
56e23f |
* published by the Free Software Foundation.
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
56e23f |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit |
56e23f |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
Packit |
56e23f |
* for more details.
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
56e23f |
* along with this library; if not, see <http://www.gnu.org/licenses>.
|
|
Packit |
56e23f |
*/
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
#include <errno.h>
|
|
Packit |
56e23f |
#include <unistd.h>
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
#include <seccomp.h>
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
int main(int argc, char *argv[])
|
|
Packit |
56e23f |
{
|
|
Packit |
56e23f |
int rc;
|
|
Packit |
56e23f |
unsigned int api;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
api = seccomp_api_get();
|
|
Packit |
56e23f |
if (api < 1)
|
|
Packit |
56e23f |
return -1;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_api_set(1);
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
return -2;
|
|
Packit |
56e23f |
api = seccomp_api_get();
|
|
Packit |
56e23f |
if (api != 1)
|
|
Packit |
56e23f |
return -3;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_api_set(2);
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
return -4;
|
|
Packit |
56e23f |
api = seccomp_api_get();
|
|
Packit |
56e23f |
if (api != 2)
|
|
Packit |
56e23f |
return -5;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_api_set(3);
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
return -6;
|
|
Packit |
56e23f |
api = seccomp_api_get();
|
|
Packit |
56e23f |
if (api != 3)
|
|
Packit |
56e23f |
return -7;
|
|
Packit |
56e23f |
|
|
Packit Service |
10c312 |
rc = seccomp_api_set(4);
|
|
Packit Service |
10c312 |
if (rc != 0)
|
|
Packit Service |
10c312 |
return -8;
|
|
Packit Service |
10c312 |
api = seccomp_api_get();
|
|
Packit Service |
10c312 |
if (api != 4)
|
|
Packit Service |
10c312 |
return -9;
|
|
Packit Service |
10c312 |
|
|
Packit Service |
10c312 |
rc = seccomp_api_set(5);
|
|
Packit Service |
10c312 |
if (rc != 0)
|
|
Packit Service |
10c312 |
return -10;
|
|
Packit Service |
10c312 |
api = seccomp_api_get();
|
|
Packit Service |
10c312 |
if (api != 5)
|
|
Packit Service |
10c312 |
return -11;
|
|
Packit Service |
10c312 |
|
|
Packit Service |
10c312 |
rc = seccomp_api_set(6);
|
|
Packit Service |
10c312 |
if (rc != 0)
|
|
Packit Service |
10c312 |
return -12;
|
|
Packit Service |
10c312 |
api = seccomp_api_get();
|
|
Packit Service |
10c312 |
if (api != 6)
|
|
Packit Service |
10c312 |
return -13;
|
|
Packit Service |
10c312 |
|
|
Packit |
56e23f |
/* Attempt to set a high, invalid API level */
|
|
Packit |
56e23f |
rc = seccomp_api_set(1024);
|
|
Packit |
56e23f |
if (rc != -EINVAL)
|
|
Packit Service |
10c312 |
return -1001;
|
|
Packit |
56e23f |
/* Ensure that the previously set API level didn't change */
|
|
Packit |
56e23f |
api = seccomp_api_get();
|
|
Packit Service |
10c312 |
if (api != 6)
|
|
Packit Service |
10c312 |
return -1002;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
return 0;
|
|
Packit |
56e23f |
}
|