|
|
a2cf7d |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
a2cf7d |
Date: Mon, 2 Sep 2019 10:40:38 +0000 (+0200)
|
|
|
a2cf7d |
Subject: Add misc/tst-mntent-autofs, testing autofs "ignore" filtering
|
|
|
a2cf7d |
X-Git-Tag: changelog-ends-here~74
|
|
|
a2cf7d |
X-Git-Url: https://sourceware.org/git/?p=glibc.git;a=commitdiff_plain;h=9a1e7257a4292d3aea45c8317df3956f4331d8ce
|
|
|
a2cf7d |
|
|
|
a2cf7d |
Add misc/tst-mntent-autofs, testing autofs "ignore" filtering
|
|
|
a2cf7d |
---
|
|
|
a2cf7d |
|
|
|
a2cf7d |
diff -rup a/misc/Makefile b/misc/Makefile
|
|
|
a2cf7d |
--- a/misc/Makefile 2020-03-25 18:30:42.275895917 -0400
|
|
|
a2cf7d |
+++ b/misc/Makefile 2020-03-25 18:37:55.527738814 -0400
|
|
|
a2cf7d |
@@ -84,7 +84,8 @@ tests := tst-dirname tst-tsearch tst-fds
|
|
|
a2cf7d |
tst-error1 tst-pselect tst-insremque tst-mntent2 bug-hsearch1 \
|
|
|
a2cf7d |
tst-mntent-blank-corrupt tst-mntent-blank-passno bug18240 \
|
|
|
a2cf7d |
tst-preadvwritev tst-preadvwritev64 tst-makedev tst-empty \
|
|
|
a2cf7d |
- tst-preadvwritev2 tst-preadvwritev64v2
|
|
|
a2cf7d |
+ tst-preadvwritev2 tst-preadvwritev64v2 \
|
|
|
a2cf7d |
+ tst-mntent-autofs
|
|
|
a2cf7d |
|
|
|
a2cf7d |
# Tests which need libdl.
|
|
|
a2cf7d |
ifeq (yes,$(build-shared))
|
|
|
a2cf7d |
diff --git a/misc/tst-mntent-autofs.c b/misc/tst-mntent-autofs.c
|
|
|
a2cf7d |
new file mode 100644
|
|
|
a2cf7d |
index 0000000000..bf4d4e73b4
|
|
|
a2cf7d |
--- /dev/null
|
|
|
a2cf7d |
+++ b/misc/tst-mntent-autofs.c
|
|
|
a2cf7d |
@@ -0,0 +1,141 @@
|
|
|
a2cf7d |
+/* Test autofs "ignore" filtering for getment_r.
|
|
|
a2cf7d |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
a2cf7d |
+ This file is part of the GNU C Library.
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
a2cf7d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
a2cf7d |
+ License as published by the Free Software Foundation; either
|
|
|
a2cf7d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
a2cf7d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a2cf7d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
a2cf7d |
+ Lesser General Public License for more details.
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
a2cf7d |
+ License along with the GNU C Library; if not, see
|
|
|
a2cf7d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#include <array_length.h>
|
|
|
a2cf7d |
+#include <errno.h>
|
|
|
a2cf7d |
+#include <mntent.h>
|
|
|
a2cf7d |
+#include <stdio.h>
|
|
|
a2cf7d |
+#include <stdlib.h>
|
|
|
a2cf7d |
+#include <string.h>
|
|
|
a2cf7d |
+#include <support/check.h>
|
|
|
a2cf7d |
+#include <support/temp_file.h>
|
|
|
a2cf7d |
+#include <support/xstdio.h>
|
|
|
a2cf7d |
+#include <support/xunistd.h>
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+struct test_case
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ const char *line;
|
|
|
a2cf7d |
+ struct
|
|
|
a2cf7d |
+ {
|
|
|
a2cf7d |
+ /* Like struct mntent, but with const pointers. */
|
|
|
a2cf7d |
+ const char *mnt_fsname;
|
|
|
a2cf7d |
+ const char *mnt_dir;
|
|
|
a2cf7d |
+ const char *mnt_type;
|
|
|
a2cf7d |
+ const char *mnt_opts;
|
|
|
a2cf7d |
+ int mnt_freq;
|
|
|
a2cf7d |
+ int mnt_passno;
|
|
|
a2cf7d |
+ } expected;
|
|
|
a2cf7d |
+};
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static struct test_case test_cases[] =
|
|
|
a2cf7d |
+ {
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/1 autofs defaults 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/1", "autofs", "defaults", 0, 0 } },
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* These entries are filtered out. */
|
|
|
a2cf7d |
+ { "/etc/auto.2 /mnt/auto/2 autofs ignore 0 0", { NULL, } },
|
|
|
a2cf7d |
+ { "/etc/auto.3 /mnt/auto/3 autofs ignore,other 1 2", { NULL, } },
|
|
|
a2cf7d |
+ { "/etc/auto.4 /mnt/auto/4 autofs other,ignore 3 4", { NULL, } },
|
|
|
a2cf7d |
+ { "/etc/auto.5 /mnt/auto/5 autofs opt1,ignore,opt2 5 6", { NULL, } },
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Dummy entry to make the desynchronization more obvious. */
|
|
|
a2cf7d |
+ { "/dev/sda1 / xfs defaults 0 0",
|
|
|
a2cf7d |
+ { "/dev/sda1", "/", "xfs", "defaults", 0, 0 } },
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* These are not filtered because the file system is not autofs. */
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/6 autofs1 ignore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/6", "autofs1", "ignore", 0, 0 } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/7 autofs1 ignore,other 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/7", "autofs1", "ignore,other", 0, 0 } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/8 autofs1 other,ignore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/8", "autofs1", "other,ignore", 0, 0 } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/9 autofs1 opt1,ignore,opt2 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/9", "autofs1", "opt1,ignore,opt2", } },
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* These are not filtered because the string "ignore" is not an
|
|
|
a2cf7d |
+ option name. */
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/10 autofs noignore 1 2",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/10", "autofs", "noignore", 1, 2 } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/11 autofs noignore,other 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/11", "autofs", "noignore,other", } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/12 autofs other,noignore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/12", "autofs", "other,noignore", } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/13 autofs errors=ignore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/13", "autofs", "errors=ignore", } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/14 autofs errors=ignore,other 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/14", "autofs",
|
|
|
a2cf7d |
+ "errors=ignore,other", } },
|
|
|
a2cf7d |
+ { "/etc/auto.direct /mnt/auto/15 autofs other,errors=ignore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.direct", "/mnt/auto/15", "autofs",
|
|
|
a2cf7d |
+ "other,errors=ignore", } },
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* These are not filtered because the string is escaped. '\151'
|
|
|
a2cf7d |
+ is 'i', but it is not actually decoded by the parser. */
|
|
|
a2cf7d |
+ { "/etc/auto.\\151gnore /mnt/auto/16 autofs \\151gnore 0 0",
|
|
|
a2cf7d |
+ { "/etc/auto.\\151gnore", "/mnt/auto/16", "autofs",
|
|
|
a2cf7d |
+ "\\151gnore", } },
|
|
|
a2cf7d |
+ };
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static int
|
|
|
a2cf7d |
+do_test (void)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ char *path;
|
|
|
a2cf7d |
+ xclose (create_temp_file ("tst-mntent-autofs-", &path));
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Write the test file. */
|
|
|
a2cf7d |
+ FILE *fp = xfopen (path, "w");
|
|
|
a2cf7d |
+ for (size_t i = 0; i < array_length (test_cases); ++i)
|
|
|
a2cf7d |
+ fprintf (fp, "%s\n", test_cases[i].line);
|
|
|
a2cf7d |
+ xfclose (fp);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Open the test file again, this time for parsing. */
|
|
|
a2cf7d |
+ fp = setmntent (path, "r");
|
|
|
a2cf7d |
+ TEST_VERIFY_EXIT (fp != NULL);
|
|
|
a2cf7d |
+ char buffer[512];
|
|
|
a2cf7d |
+ struct mntent me;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ for (size_t i = 0; i < array_length (test_cases); ++i)
|
|
|
a2cf7d |
+ {
|
|
|
a2cf7d |
+ if (test_cases[i].expected.mnt_type == NULL)
|
|
|
a2cf7d |
+ continue;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ memset (buffer, 0xcc, sizeof (buffer));
|
|
|
a2cf7d |
+ memset (&me, 0xcc, sizeof (me));
|
|
|
a2cf7d |
+ struct mntent *pme = getmntent_r (fp, &me, buffer, sizeof (buffer));
|
|
|
a2cf7d |
+ TEST_VERIFY_EXIT (pme != NULL);
|
|
|
a2cf7d |
+ TEST_VERIFY (pme == &me);
|
|
|
a2cf7d |
+ TEST_COMPARE_STRING (test_cases[i].expected.mnt_fsname, me.mnt_fsname);
|
|
|
a2cf7d |
+ TEST_COMPARE_STRING (test_cases[i].expected.mnt_dir, me.mnt_dir);
|
|
|
a2cf7d |
+ TEST_COMPARE_STRING (test_cases[i].expected.mnt_type, me.mnt_type);
|
|
|
a2cf7d |
+ TEST_COMPARE_STRING (test_cases[i].expected.mnt_opts, me.mnt_opts);
|
|
|
a2cf7d |
+ TEST_COMPARE (test_cases[i].expected.mnt_freq, me.mnt_freq);
|
|
|
a2cf7d |
+ TEST_COMPARE (test_cases[i].expected.mnt_passno, me.mnt_passno);
|
|
|
a2cf7d |
+ }
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ TEST_VERIFY (getmntent_r (fp, &me, buffer, sizeof (buffer)) == NULL);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ TEST_COMPARE (feof (fp), 1);
|
|
|
a2cf7d |
+ TEST_COMPARE (ferror (fp), 0);
|
|
|
a2cf7d |
+ errno = 0;
|
|
|
a2cf7d |
+ TEST_COMPARE (endmntent (fp), 1);
|
|
|
a2cf7d |
+ TEST_COMPARE (errno, 0);
|
|
|
a2cf7d |
+ free (path);
|
|
|
a2cf7d |
+ return 0;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#include <support/test-driver.c>
|