libext2fs, tests: allow /etc/mtab file to be missing

The environment variable EXT2FS_NO_MTAB_OK will suppress the error
code EXT2_NO_MTAB_FILE when the /etc/mtab file can not be found.  This
allows the e2fsprogs regression test suite to be run in chroots which
might not have an /etc/mtab file.

By default will still want to complain if the /etc/mtab file is
missing, since we really don't want to discourage distributions and
purveyors of embedded systems from running without an /etc/mtab file.
But if it's missing it only results in a missing sanity check that
might cause file system corruption if the file system is mounted when
programs such as e2fsck, tune2fs, or resize2fs is running, so there is
no potential security problems that might result if this environment
variable is set inappropriately.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian-1.42.9
Theodore Ts'o 2013-07-08 12:08:44 -04:00
parent 0595812245
commit 42b61c50e5
2 changed files with 11 additions and 2 deletions

View File

@ -53,8 +53,15 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
int fd;
*mount_flags = 0;
if ((f = setmntent (mtab_file, "r")) == NULL)
return (errno == ENOENT ? EXT2_NO_MTAB_FILE : errno);
if ((f = setmntent (mtab_file, "r")) == NULL) {
if (errno == ENOENT) {
if (getenv("EXT2FS_NO_MTAB_OK"))
return 0;
else
return EXT2_NO_MTAB_FILE;
}
return errno;
}
if (stat(file, &st_buf) == 0) {
if (S_ISBLK(st_buf.st_mode)) {
#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */

View File

@ -34,3 +34,5 @@ MKE2FS_CONFIG=./mke2fs.conf
export MKE2FS_CONFIG
E2FSPROGS_SKIP_PROGRESS=yes
export E2FSPROGS_SKIP_PROGRESS
EXT2FS_NO_MTAB_OK=yes
export EXT2FS_NO_MTAB_OK