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
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011
Free Software Foundation, Inc.
Copyright (C) 2011 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......
......@@ -11,6 +11,7 @@ debugspec
decode2047
encode2047
fltst
fsaf
listop
mailcap
prop
......
......@@ -46,6 +46,7 @@ noinst_PROGRAMS = \
decode2047\
encode2047\
fltst\
fsaf\
listop\
mailcap\
prop\
......@@ -70,6 +71,7 @@ TESTSUITE_AT = \
decode2047.at\
encode2047.at\
fromflt.at\
fsaf.at\
hdrflt.at\
inline-comment.at\
linecon.at\
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2011 Free Software Foundation, Inc.
#
# GNU Mailutils 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; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_BANNER(File Safety)
dnl ------------------------------------------------------------
dnl FSAF(CRITERIA, CODE, [STDOUT = `'], [RUN-IF-FAIL],
dnl [RUN-IF-PASS], [NAME])
dnl
m4_pushdef([FSAFCODE],[
AT_SETUP([m4_if([$6],,$1,$6)])
AT_KEYWORDS([fsaf])
AT_CHECK([
$2
fsaf $1 file
],
[0],
[file: $3
],
[],
[$4],
[$5])
AT_CLEANUP
])
m4_pushdef([FSAF],[
FSAFCODE([$1],
[> file
m4_if([$2],,,[chmod $2 file])],[$3],[$4],[$5],[$6])
])
dnl ------------------------------------------------------------
FSAF([], [], [Success], [], [], [default])
FSAF([+awrfil], [o+w], [World writable file])
FSAF([+gwrfil], [g+w], [Group writable file])
FSAFCODE([+linkwrdir],
[mkdir dir
chmod g+w dir
> data
cd dir
ln ../data file
],
[Linked file in a writable directory])
FSAFCODE([+awrdir],
[mkdir dir
chmod o+w dir
cd dir
> file
],
[File in world writable directory])
FSAFCODE([+gwrdir],
[mkdir dir
chmod g+w dir
cd dir
> file
],
[File in group writable directory])
FSAF([+ardfil], [o+r], [World readable file])
FSAF([+grdfil], [g+r], [Group readable file])
m4_popdef([FSAFCODE])
m4_popdef([FSAF])
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011 Free Software Foundation, Inc.
GNU Mailutils 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; either version 3, or (at your option)
any later version.
GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mailutils/types.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/util.h>
int
main (int argc, char **argv)
{
int i;
int mode = MU_FILE_SAFETY_OWNER_MISMATCH, rc, m;
mu_list_t idlist;
uid_t uid;
if (argc == 1)
{
mu_error ("usage: %s [+-]mode... file...", argv[0]);
exit (1);
}
rc = mu_list_create (&idlist);
if (rc)
{
mu_error ("mu_list_create: %s", mu_strerror (rc));
exit (1);
}
uid = getuid ();
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-' || argv[i][0] == '+')
{
rc = mu_file_safety_name_to_code (argv[i] + 1, &m);
if (rc)
{
mu_error ("%s: %s", argv[i], mu_strerror (rc));
exit (1);
}
if (argv[i][0] == '-')
mode &= ~m;
else
mode |= m;
}
else
{
rc = mu_file_safety_check (argv[i], mode, uid, idlist);
printf ("%s: %s\n", argv[i], mu_strerror (rc));
}
}
exit (0);
}
......@@ -77,3 +77,4 @@ m4_include([hdrflt.at])
m4_include([linecon.at])
m4_include([debugspec.at])
m4_include([fsaf.at])
\ No newline at end of file
......