- For rpm itself forging global umask on init is kinda convenient, but can
be troublesome for API users. This is especially bad in python bindings
where just importing the rpm module silently changes process umask with
no good reason.
- Instead of global setting on init, only change the umask to 022 default
for the duration of rpmtsRun() where it's necessary for consistent
transaction results on implicitly created directories and files created
by scriptlets. This way we dont affect callers and provide better
"protection" for ourselves too - we don't know if API users change
umask again behind our back if we just set it on initialization.
- To make matters more fun, Lua scripts can change our umask. Save
and restore umask when running Lua scriptlets.
int rpmReadConfigFiles(const char * file, const char * target)
{
- mode_t mode = 0022;
- /* Reset umask to its default umask(2) value. */
- mode = umask(mode);
-
/* Force preloading of dlopen()'ed libraries in case we go chrooting */
(void) gethostbyname("localhost");
(void) rpmInitCrypto();
var = rpmluavFree(var);
rpmluaPop(lua);
- /* Lua scripts can change our cwd, save and restore */
+ /* Lua scripts can change our cwd and umask, save and restore */
cwd = open(".", O_RDONLY);
if (cwd != -1) {
int xx;
+ mode_t oldmask = umask(0);
+ umask(oldmask);
+
if (chdir("/") == 0 && rpmluaRunScript(lua, script, sname) == 0) {
rc = RPMRC_OK;
}
/* XXX no way to return error from restore meaningfully atm */
xx = fchdir(cwd);
close(cwd);
+ umask(oldmask);
}
rpmluaDelVar(lua, "arg");
int rc = -1; /* assume failure */
rpmlock lock = NULL;
rpmps tsprobs = NULL;
+ /* Force default 022 umask during transaction for consistent results */
+ mode_t oldmask = umask(022);
/* XXX programmer error segfault avoidance. */
if (rpmtsNElements(ts) <= 0) {
exit:
/* Finish up... */
+ (void) umask(oldmask);
(void) rpmtsFinish(ts);
tsprobs = rpmpsFree(tsprobs);
rpmlockFree(lock);