attach.c revision 0b98289ef95e83fcd493ba6688e57aa8b4fb53f7
/* liblxcapi
*
* Copyright © 2013 Oracle.
*
* Authors:
* Dwight Engen <dwight.engen@oracle.com>
*
* 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.
*/
#include <lxc/lxccontainer.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#define TSTNAME "lxc-attach-test"
} while (0)
static const char *lsm_config_key = NULL;
static void test_lsm_detect(void)
{
if (lsm_enabled()) {
lsm_config_key = "lxc.se_context";
}
lsm_config_key = "lxc.aa_profile";
lsm_label = "lxc-container-default";
}
else {
}
}
}
#if HAVE_APPARMOR || HAVE_SELINUX
{
}
static int test_attach_lsm_func_func(void* payload)
{
return 0;
}
{
int ret;
int pipefd[2];
char result[1024];
printf("Testing attach lsm label with func...\n");
if (ret < 0) {
return ret;
}
if (ret < 0) {
TSTERR("attach failed");
goto err1;
}
if (ret < 0) {
goto err2;
}
ret = -1;
goto err2;
}
ret = 0;
err2:
err1:
return ret;
}
{
int ret;
int pipefd[2];
char result[1024];
char *space;
printf("Testing attach lsm label with cmd...\n");
if (ret < 0) {
return ret;
}
if (ret < 0) {
TSTERR("attach failed");
goto err1;
}
if (ret < 0) {
goto err2;
}
if (space)
*space = '\0';
if (space)
*space = '\0';
ret = -1;
goto err2;
}
ret = 0;
err2:
err1:
return ret;
}
#else
#endif /* HAVE_APPARMOR || HAVE_SELINUX */
static int test_attach_func_func(void* payload)
{
return 0;
}
{
int ret;
int pipefd[2];
char result[1024];
printf("Testing attach with func...\n");
/* XXX: We can't just use &nspid and have test_attach_func_func fill
* it in because the function doesn't run in our process context but
* in a fork()ed from us context. We read the result through a pipe.
*/
if (ret < 0) {
return ret;
}
if (ret < 0) {
TSTERR("attach failed");
goto err1;
}
if (ret < 0) {
goto err2;
}
/* There is a small chance the pid is reused inside the NS, so we
* just print it and don't actually do this check
*
* if (pid == nspid) TSTERR(...)
*/
ret = 0;
err2:
err1:
return ret;
}
{
int ret;
printf("Testing attach with success command...\n");
if (ret < 0) {
TSTERR("attach failed");
return ret;
}
if (ret < 0) {
return ret;
}
printf("Testing attach with failure command...\n");
if (ret < 0) {
TSTERR("attach failed");
return ret;
}
if (ret == 0) {
return -1;
}
return 0;
}
/* test_ct_destroy: stop and destroy the test container
*
* @ct : the container
*/
{
}
/* test_ct_create: create and start test container
*
* @lxcpath : the lxcpath in which to create the container
* @group : name of the container group or NULL for default "lxc"
* @name : name of the container
* @template : template to use when creating the container
*/
const char *template)
{
int ret;
if (lxcpath) {
goto out1;
}
}
goto out1;
}
}
goto out2;
}
if (lsm_enabled())
goto out2;
}
return ct;
out2:
out1:
return ct;
}
{
int ret = -1;
struct lxc_container *ct;
if (!ct)
goto err1;
if (ret < 0) {
TSTERR("attach cmd test failed");
goto err2;
}
if (ret < 0) {
TSTERR("attach func test failed");
goto err2;
}
if (lsm_enabled()) {
if (ret < 0) {
TSTERR("attach lsm cmd test failed");
goto err2;
}
if (ret < 0) {
TSTERR("attach lsm func test failed");
goto err2;
}
}
ret = 0;
err2:
err1:
return ret;
}
{
int ret;
if (ret < 0)
return EXIT_FAILURE;
printf("\n");
if (ret < 0)
return EXIT_FAILURE;
printf("All tests passed\n");
return EXIT_SUCCESS;
}