mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
Add a testcase for fchdir, and test steps to verify we didn't break
normal chdir/fchdir. Minor formatting changes to chdir.c.
This commit is contained in:
parent
3256de5ffa
commit
53c97e6696
5 changed files with 89 additions and 4 deletions
|
@ -27,6 +27,7 @@ SRC=access.c \
|
|||
exec.c \
|
||||
exec_qual.c \
|
||||
exec_qual2.c \
|
||||
fchdir.c \
|
||||
fchgrp.c \
|
||||
fchmod.c \
|
||||
fchown.c \
|
||||
|
@ -112,6 +113,7 @@ TESTS=access \
|
|||
environ \
|
||||
exec \
|
||||
exec_qual \
|
||||
fchdir \
|
||||
fork \
|
||||
i18n \
|
||||
link \
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2){
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s dir\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (chdir(argv[1]) == 0){
|
||||
if (chdir(argv[1]) == 0) {
|
||||
printf("PASS\n");
|
||||
}else{
|
||||
} else {
|
||||
printf("FAIL - %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,9 @@ mkdir $dir
|
|||
|
||||
# CHDIR TEST
|
||||
|
||||
# no profile, verify we didn't break normal chdir
|
||||
runchecktest "CHDIR" pass $dir
|
||||
|
||||
# null profile, verify chdir (x) functions
|
||||
genprofile
|
||||
|
||||
runchecktest "CHDIR" pass $dir
|
||||
|
|
45
tests/regression/subdomain/fchdir.c
Normal file
45
tests/regression/subdomain/fchdir.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2002-2007 Novell/SUSE
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation, version 2 of the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int dirfd;
|
||||
char *dir = argv[1];
|
||||
|
||||
if (argc != 2){
|
||||
fprintf(stderr, "usage: %s dir\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dirfd = open(dir, O_RDONLY | O_DIRECTORY);
|
||||
if (dirfd == -1) {
|
||||
fprintf(stderr, "FAIL: open %s failed - %s\n",
|
||||
dir, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fchdir(dirfd) == 0) {
|
||||
printf("PASS\n");
|
||||
} else {
|
||||
printf("FAIL - %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
36
tests/regression/subdomain/fchdir.sh
Executable file
36
tests/regression/subdomain/fchdir.sh
Executable file
|
@ -0,0 +1,36 @@
|
|||
#! /bin/bash
|
||||
# $Id$
|
||||
|
||||
# Copyright (C) 2002-2005 Novell/SUSE
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, version 2 of the
|
||||
# License.
|
||||
|
||||
#=NAME chdir
|
||||
#=DESCRIPTION
|
||||
# Verify change directory functions correctly for a confined process. Subdomain
|
||||
# should allow 'x' access on a directory without it being explicitly listed in
|
||||
# tasks profile.
|
||||
#=END
|
||||
|
||||
pwd=`dirname $0`
|
||||
pwd=`cd $pwd ; /bin/pwd`
|
||||
|
||||
bin=$pwd
|
||||
|
||||
. $bin/prologue.inc
|
||||
|
||||
dir=$tmpdir/tmpdir
|
||||
|
||||
mkdir $dir
|
||||
|
||||
# CHDIR TEST
|
||||
|
||||
# no profile, verify we didn't break normal fchdir
|
||||
runchecktest "FCHDIR/no profile" pass $dir
|
||||
|
||||
# null profile, verify fchdir (x) functions
|
||||
genprofile
|
||||
runchecktest "FCHDIR/profile" pass $dir
|
Loading…
Add table
Reference in a new issue