* [LTP] [PATCH v2] make filecaps tests succeed
@ 2010-05-06 14:45 Serge E. Hallyn
2010-05-06 17:43 ` Garrett Cooper
0 siblings, 1 reply; 3+ messages in thread
From: Serge E. Hallyn @ 2010-05-06 14:45 UTC (permalink / raw)
To: LTP list; +Cc: Subrata Modak1
(Garrett I was going to add your ack, but wasn't absolutely sure
whether you meant it should apply to the whole thing or not)
Most of these are belated cleanup after the move to using /opt/ltp.
But come on, replacing 'return' with tst_exit(), are you just trying
to mess with my head?
Changelog:
may 4: address Garrett's feedback
1. single return 0 in print_caps.c
2. use $TMP if defined for location of caps_fifo
3. use tst_brkm in place of tst_resm.
may 5: address Garrett's comment:
don't add 1 to null pointer and then check for 1
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
testcases/kernel/security/filecaps/filecapstest.sh | 10 +++-
testcases/kernel/security/filecaps/print_caps.c | 5 +-
.../kernel/security/filecaps/verify_caps_exec.c | 51 ++++++++------------
3 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/testcases/kernel/security/filecaps/filecapstest.sh b/testcases/kernel/security/filecaps/filecapstest.sh
index 43582dc..8e2ba11 100755
--- a/testcases/kernel/security/filecaps/filecapstest.sh
+++ b/testcases/kernel/security/filecaps/filecapstest.sh
@@ -22,8 +22,12 @@
echo "Running in:"
#rm -f print_caps
#cp $LTPROOT/testcases/bin/print_caps .
-mkfifo caps_fifo
-chmod 777 caps_fifo
+#FIFOFILE="$LTPROOT/testcases/bin/caps_fifo"
+TMP=${TMP:=/tmp}
+FIFOFILE="$TMP/caps_fifo"
+rm -f $FIFOFILE
+mkfifo $FIFOFILE
+chmod 777 $FIFOFILE
exit_code=0
echo "cap_sys_admin tests"
verify_caps_exec 0
@@ -46,5 +50,5 @@ if [ $tmp -ne 0 ]; then
exit_code=$tmp
fi
-unlink caps_fifo
+unlink $FIFOFILE
exit $exit_code
diff --git a/testcases/kernel/security/filecaps/print_caps.c b/testcases/kernel/security/filecaps/print_caps.c
index f0e9bce..1c3fc1b 100644
--- a/testcases/kernel/security/filecaps/print_caps.c
+++ b/testcases/kernel/security/filecaps/print_caps.c
@@ -36,7 +36,7 @@
#include <sys/capability.h>
#endif
-#define FIFOFILE "caps_fifo"
+#define FIFOFILE "/tmp/caps_fifo"
int main(int argc, char *argv[])
{
@@ -65,7 +65,6 @@ int main(int argc, char *argv[])
close(fd);
cap_free(cap);
-#else
- return 0;
#endif
+ return 0;
}
diff --git a/testcases/kernel/security/filecaps/verify_caps_exec.c b/testcases/kernel/security/filecaps/verify_caps_exec.c
index 5250007..605f0f6 100644
--- a/testcases/kernel/security/filecaps/verify_caps_exec.c
+++ b/testcases/kernel/security/filecaps/verify_caps_exec.c
@@ -43,7 +43,7 @@
#include <sys/prctl.h>
#include <test.h>
-#define TSTPATH "./print_caps"
+#define TSTPATH "print_caps"
char *TCID = "filecaps";
int TST_TOTAL=1;
@@ -70,7 +70,7 @@ void print_my_caps()
cap_free(txt);
}
-int drop_root(int keep_perms)
+void drop_root(int keep_perms)
{
int ret;
@@ -78,16 +78,19 @@ int drop_root(int keep_perms)
prctl(PR_SET_KEEPCAPS, 1);
ret = setresuid(1000, 1000, 1000);
if (ret) {
- perror("setresuid");
- tst_resm(TFAIL, "Error dropping root privs\n");
+ tst_brkm(TFAIL | TERRNO, tst_exit, "Error dropping root privs\n");
tst_exit();
}
if (keep_perms) {
cap_t cap = cap_from_text("=eip");
- cap_set_proc(cap);
+ int ret;
+ if (!cap)
+ tst_brkm(TBROK | TERRNO, tst_exit, "cap_from_text failed\n");
+ ret = cap_set_proc(cap);
+ if (ret < 0)
+ tst_brkm(TBROK | TERRNO, tst_exit, "cap_set_proc failed\n");
cap_free(cap);
}
- tst_exit();
}
int perms_test(void)
@@ -114,17 +117,14 @@ int perms_test(void)
return ret;
}
-#define FIFOFILE "caps_fifo"
+#define FIFOFILE "/tmp/caps_fifo"
void create_fifo(void)
{
int ret;
ret = mkfifo(FIFOFILE, S_IRWXU | S_IRWXG | S_IRWXO);
- if (ret == -1 && errno != EEXIST) {
- perror("mkfifo");
- tst_resm(TFAIL, "failed creating %s\n", FIFOFILE);
- tst_exit();
- }
+ if (ret == -1 && errno != EEXIST)
+ tst_brkm(TFAIL | TERRNO, tst_exit, "failed creating %s\n", FIFOFILE);
}
void write_to_fifo(char *buf)
@@ -142,11 +142,8 @@ void read_from_fifo(char *buf)
memset(buf, 0, 200);
fd = open(FIFOFILE, O_RDONLY);
- if (fd < 0) {
- perror("open");
- tst_resm(TFAIL, "Failed opening fifo\n");
- tst_exit();
- }
+ if (fd < 0)
+ tst_brkm(TFAIL | TERRNO, tst_exit, "Failed opening fifo\n");
read(fd, buf, 199);
close(fd);
}
@@ -162,23 +159,18 @@ int fork_drop_and_exec(int keepperms, cap_t expected_caps)
static int seqno = 0;
pid = fork();
- if (pid < 0) {
- perror("fork");
- tst_resm(TFAIL, "%s: failed fork\n", __FUNCTION__);
- tst_exit();
- }
+ if (pid < 0)
+ tst_brkm(TFAIL | TERRNO, tst_exit, "%s: failed fork\n", __FUNCTION__);
if (pid == 0) {
drop_root(keepperms);
print_my_caps();
sprintf(buf, "%d", seqno);
ret = execlp(TSTPATH, TSTPATH, buf, NULL);
- perror("execl");
- tst_resm(TFAIL, "%s: exec failed\n", __FUNCTION__);
capstxt = cap_to_text(expected_caps, NULL);
snprintf(buf, 200, "failed to run as %s\n", capstxt);
cap_free(capstxt);
write_to_fifo(buf);
- tst_exit();
+ tst_brkm(TFAIL, tst_exit, "%s: exec failed\n", __FUNCTION__);
} else {
p = buf;
while (1) {
@@ -190,11 +182,10 @@ int fork_drop_and_exec(int keepperms, cap_t expected_caps)
tst_resm(TINFO, "got a bad seqno (c=%d, s=%d, seqno=%d)",
c, s, seqno);
}
- p = index(buf, '.')+1;
- if (p==(char *)1) {
- tst_resm(TFAIL, "got a bad message from print_caps\n");
- tst_exit();
- }
+ p = index(buf, '.');
+ if (!p)
+ tst_brkm(TFAIL, tst_exit, "got a bad message from print_caps\n");
+ p += 1;
actual_caps = cap_from_text(p);
if (cap_compare(actual_caps, expected_caps) != 0) {
capstxt = cap_to_text(expected_caps, NULL);
--
1.6.0.6
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] make filecaps tests succeed
2010-05-06 14:45 [LTP] [PATCH v2] make filecaps tests succeed Serge E. Hallyn
@ 2010-05-06 17:43 ` Garrett Cooper
2010-05-07 9:00 ` Subrata Modak
0 siblings, 1 reply; 3+ messages in thread
From: Garrett Cooper @ 2010-05-06 17:43 UTC (permalink / raw)
To: Serge E. Hallyn; +Cc: LTP list, Subrata Modak1
On Thu, May 6, 2010 at 7:45 AM, Serge E. Hallyn <serue@us.ibm.com> wrote:
> (Garrett I was going to add your ack, but wasn't absolutely sure
> whether you meant it should apply to the whole thing or not)
>
> Most of these are belated cleanup after the move to using /opt/ltp.
> But come on, replacing 'return' with tst_exit(), are you just trying
> to mess with my head?
>
> Changelog:
> may 4: address Garrett's feedback
> 1. single return 0 in print_caps.c
> 2. use $TMP if defined for location of caps_fifo
> 3. use tst_brkm in place of tst_resm.
> may 5: address Garrett's comment:
> don't add 1 to null pointer and then check for 1
>
> Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Acked-by: Garrett Cooper <yanegomi@gmail.com>
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] make filecaps tests succeed
2010-05-06 17:43 ` Garrett Cooper
@ 2010-05-07 9:00 ` Subrata Modak
0 siblings, 0 replies; 3+ messages in thread
From: Subrata Modak @ 2010-05-07 9:00 UTC (permalink / raw)
To: Garrett Cooper; +Cc: Subrata Modak1, LTP list
On Thu, 2010-05-06 at 10:43 -0700, Garrett Cooper wrote:
> On Thu, May 6, 2010 at 7:45 AM, Serge E. Hallyn <serue@us.ibm.com> wrote:
> > (Garrett I was going to add your ack, but wasn't absolutely sure
> > whether you meant it should apply to the whole thing or not)
> >
> > Most of these are belated cleanup after the move to using /opt/ltp.
> > But come on, replacing 'return' with tst_exit(), are you just trying
> > to mess with my head?
> >
> > Changelog:
> > may 4: address Garrett's feedback
> > 1. single return 0 in print_caps.c
> > 2. use $TMP if defined for location of caps_fifo
> > 3. use tst_brkm in place of tst_resm.
> > may 5: address Garrett's comment:
> > don't add 1 to null pointer and then check for 1
> >
> > Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
>
> Acked-by: Garrett Cooper <yanegomi@gmail.com>
Thanks. Checked in just now.
Regards--
Subrata
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-07 9:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-06 14:45 [LTP] [PATCH v2] make filecaps tests succeed Serge E. Hallyn
2010-05-06 17:43 ` Garrett Cooper
2010-05-07 9:00 ` Subrata Modak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox