Commit e9a329bf e9a329bfe70d903fb0a78007adaff6b565ddfc6b by Sergey Poznyakoff

Add testcases for file safety checking functions.

* libmailutils/tests/fsaf.at: New testcase.
* libmailutils/tests/fsaf.c: New file.
* libmailutils/tests/.gitignore: Add fsaf
* libmailutils/tests/Makefile.am: Likewise.
* libmailutils/tests/testsuite.at: Include fsaf.at.
1 parent 442711bc
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 2 Copyright (C) 2011 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 3
5 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
......
...@@ -11,6 +11,7 @@ debugspec ...@@ -11,6 +11,7 @@ debugspec
11 decode2047 11 decode2047
12 encode2047 12 encode2047
13 fltst 13 fltst
14 fsaf
14 listop 15 listop
15 mailcap 16 mailcap
16 prop 17 prop
......
...@@ -46,6 +46,7 @@ noinst_PROGRAMS = \ ...@@ -46,6 +46,7 @@ noinst_PROGRAMS = \
46 decode2047\ 46 decode2047\
47 encode2047\ 47 encode2047\
48 fltst\ 48 fltst\
49 fsaf\
49 listop\ 50 listop\
50 mailcap\ 51 mailcap\
51 prop\ 52 prop\
...@@ -70,6 +71,7 @@ TESTSUITE_AT = \ ...@@ -70,6 +71,7 @@ TESTSUITE_AT = \
70 decode2047.at\ 71 decode2047.at\
71 encode2047.at\ 72 encode2047.at\
72 fromflt.at\ 73 fromflt.at\
74 fsaf.at\
73 hdrflt.at\ 75 hdrflt.at\
74 inline-comment.at\ 76 inline-comment.at\
75 linecon.at\ 77 linecon.at\
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2011 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_BANNER(File Safety)
18
19 dnl ------------------------------------------------------------
20 dnl FSAF(CRITERIA, CODE, [STDOUT = `'], [RUN-IF-FAIL],
21 dnl [RUN-IF-PASS], [NAME])
22 dnl
23
24 m4_pushdef([FSAFCODE],[
25 AT_SETUP([m4_if([$6],,$1,$6)])
26 AT_KEYWORDS([fsaf])
27 AT_CHECK([
28 $2
29 fsaf $1 file
30 ],
31 [0],
32 [file: $3
33 ],
34 [],
35 [$4],
36 [$5])
37 AT_CLEANUP
38 ])
39
40 m4_pushdef([FSAF],[
41 FSAFCODE([$1],
42 [> file
43 m4_if([$2],,,[chmod $2 file])],[$3],[$4],[$5],[$6])
44 ])
45
46 dnl ------------------------------------------------------------
47
48 FSAF([], [], [Success], [], [], [default])
49
50 FSAF([+awrfil], [o+w], [World writable file])
51 FSAF([+gwrfil], [g+w], [Group writable file])
52
53 FSAFCODE([+linkwrdir],
54 [mkdir dir
55 chmod g+w dir
56 > data
57 cd dir
58 ln ../data file
59 ],
60 [Linked file in a writable directory])
61
62 FSAFCODE([+awrdir],
63 [mkdir dir
64 chmod o+w dir
65 cd dir
66 > file
67 ],
68 [File in world writable directory])
69
70 FSAFCODE([+gwrdir],
71 [mkdir dir
72 chmod g+w dir
73 cd dir
74 > file
75 ],
76 [File in group writable directory])
77
78 FSAF([+ardfil], [o+r], [World readable file])
79 FSAF([+grdfil], [g+r], [Group readable file])
80
81 m4_popdef([FSAFCODE])
82 m4_popdef([FSAF])
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2011 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <mailutils/types.h>
24 #include <mailutils/error.h>
25 #include <mailutils/errno.h>
26 #include <mailutils/util.h>
27
28 int
29 main (int argc, char **argv)
30 {
31 int i;
32 int mode = MU_FILE_SAFETY_OWNER_MISMATCH, rc, m;
33 mu_list_t idlist;
34 uid_t uid;
35
36 if (argc == 1)
37 {
38 mu_error ("usage: %s [+-]mode... file...", argv[0]);
39 exit (1);
40 }
41
42 rc = mu_list_create (&idlist);
43 if (rc)
44 {
45 mu_error ("mu_list_create: %s", mu_strerror (rc));
46 exit (1);
47 }
48 uid = getuid ();
49
50 for (i = 1; i < argc; i++)
51 {
52 if (argv[i][0] == '-' || argv[i][0] == '+')
53 {
54 rc = mu_file_safety_name_to_code (argv[i] + 1, &m);
55 if (rc)
56 {
57 mu_error ("%s: %s", argv[i], mu_strerror (rc));
58 exit (1);
59 }
60 if (argv[i][0] == '-')
61 mode &= ~m;
62 else
63 mode |= m;
64 }
65 else
66 {
67 rc = mu_file_safety_check (argv[i], mode, uid, idlist);
68 printf ("%s: %s\n", argv[i], mu_strerror (rc));
69 }
70 }
71 exit (0);
72 }
...@@ -77,3 +77,4 @@ m4_include([hdrflt.at]) ...@@ -77,3 +77,4 @@ m4_include([hdrflt.at])
77 m4_include([linecon.at]) 77 m4_include([linecon.at])
78 m4_include([debugspec.at]) 78 m4_include([debugspec.at])
79 79
80 m4_include([fsaf.at])
...\ No newline at end of file ...\ No newline at end of file
......