2018-10-19 20:26:52 +02:00
|
|
|
/*
|
|
|
|
* This test makes sure that the log files created by the server correctly honor the server's umask
|
|
|
|
* as set in SERVER-22829
|
2018-11-16 16:06:02 +01:00
|
|
|
*
|
|
|
|
* @tags: [ requires_wiredtiger ]
|
2018-10-19 20:26:52 +02:00
|
|
|
*/
|
|
|
|
(function() {
|
2019-07-27 00:20:35 +02:00
|
|
|
'use strict';
|
|
|
|
// We only test this on POSIX since that's the only platform where umasks make sense
|
|
|
|
if (_isWindows()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
const oldUmask = new Number(umask(0));
|
|
|
|
jsTestLog("Setting umask to really permissive 000 mode, old mode was " + oldUmask.toString(8));
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
const defaultUmask = Number.parseInt("600", 8);
|
|
|
|
const permissiveUmask = Number.parseInt("666", 8);
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Any files that have some explicit permissions set on them should be added to this list
|
|
|
|
const exceptions = [
|
|
|
|
// The lock file gets created with explicit 644 permissions
|
|
|
|
'mongod.lock',
|
|
|
|
// Mobile se files get created with 644 permissions when honoring the system umask
|
|
|
|
'mobile.sqlite',
|
|
|
|
'mobile.sqlite-shm',
|
|
|
|
'mobile.sqlite-wal',
|
|
|
|
];
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
let mongodOptions = MongoRunner.mongodOptions({
|
|
|
|
useLogFiles: true,
|
|
|
|
cleanData: true,
|
|
|
|
});
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
if (buildInfo()["modules"].some((mod) => {
|
|
|
|
return mod == "enterprise";
|
|
|
|
})) {
|
|
|
|
mongodOptions.auditDestination = "file";
|
|
|
|
mongodOptions.auditPath = mongodOptions.dbpath + "/audit.log";
|
|
|
|
mongodOptions.auditFormat = "JSON";
|
|
|
|
}
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
const checkMask = (topDir, expected, honoringUmask) => {
|
|
|
|
const maybeNot = honoringUmask ? "" : " not";
|
|
|
|
const processDirectory = (dir) => {
|
|
|
|
jsTestLog(`Checking ${dir}`);
|
|
|
|
ls(dir).forEach((file) => {
|
|
|
|
if (file.endsWith("/")) {
|
|
|
|
return processDirectory(file);
|
|
|
|
} else if (exceptions.some((exception) => {
|
|
|
|
return file.endsWith(exception);
|
|
|
|
})) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const mode = new Number(getFileMode(file));
|
|
|
|
const modeStr = mode.toString(8);
|
|
|
|
const msg = `Mode for ${file} is ${modeStr} when${maybeNot} honoring system umask`;
|
|
|
|
assert.eq(mode.valueOf(), expected, msg);
|
|
|
|
});
|
2018-10-19 20:26:52 +02:00
|
|
|
};
|
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
processDirectory(topDir);
|
|
|
|
};
|
|
|
|
|
|
|
|
// First we start up the mongod normally, all the files except mongod.lock should have the mode
|
|
|
|
// 0600
|
|
|
|
let conn = MongoRunner.runMongod(mongodOptions);
|
|
|
|
MongoRunner.stopMongod(conn);
|
|
|
|
checkMask(conn.fullOptions.dbpath, defaultUmask, false);
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Restart the mongod with honorSystemUmask, all files should have the mode 0666
|
|
|
|
mongodOptions.setParameter = {
|
|
|
|
honorSystemUmask: true
|
|
|
|
};
|
|
|
|
conn = MongoRunner.runMongod(mongodOptions);
|
|
|
|
MongoRunner.stopMongod(conn);
|
|
|
|
checkMask(conn.fullOptions.dbpath, permissiveUmask, false);
|
2018-10-19 20:26:52 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
umask(oldUmask.valueOf());
|
2018-10-19 20:26:52 +02:00
|
|
|
})();
|