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