From: mike Date: Sat, 25 Feb 2006 02:11:44 +0000 (+0000) Subject: Make sure that TMPDIR is set to a valid directory; if not, use the default X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d173821490a9a2548cd31706c040474ea59ea3ea;p=thirdparty%2Fcups.git Make sure that TMPDIR is set to a valid directory; if not, use the default TempDir setting unless overridden in cupsd.conf (STR #1438) git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5167 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/scheduler/conf.c b/scheduler/conf.c index 86d42e2c59..ebcf6d002a 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -222,6 +222,9 @@ cupsdReadConfiguration(void) struct group *group; /* Default group */ char *old_serverroot, /* Old ServerRoot */ *old_requestroot; /* Old RequestRoot */ + const char *tmpdir; /* TMPDIR environment variable */ + struct stat tmpinfo; /* Temporary directory info */ + /* * Save the old root paths... @@ -315,10 +318,7 @@ cupsdReadConfiguration(void) cupsdSetString(&RIPCache, "8m"); - if (getenv("TMPDIR") == NULL) - cupsdSetString(&TempDir, CUPS_REQUESTS "/tmp"); - else - cupsdSetString(&TempDir, getenv("TMPDIR")); + cupsdSetString(&TempDir, NULL); /* * Find the default user... @@ -628,6 +628,41 @@ cupsdReadConfiguration(void) check_permissions(ServerRoot, "printers.conf", 0600, RunUser, Group, 0, 0); check_permissions(ServerRoot, "passwd.md5", 0600, User, Group, 0, 0); + /* + * Update TempDir to the default if it hasn't been set already... + */ + + if (!TempDir) + { + if ((tmpdir = getenv("TMPDIR")) != NULL) + { + /* + * TMPDIR is defined, see if it is OK for us to use... + */ + + if (stat(tmpdir, &tmpinfo)) + cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s", + tmpdir, strerror(errno)); + else if (!S_ISDIR(tmpinfo.st_mode)) + cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory!", + tmpdir); + else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) && + (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) && + !(tmpinfo.st_mode & S_IWOTH)) + cupsdLogMessage(CUPSD_LOG_ERROR, + "TMPDIR (%s) has the wrong permissions!", tmpdir); + else + cupsdSetString(&TempDir, tmpdir); + + if (!TempDir) + cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...", + RequestRoot); + } + + if (!TempDir) + cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot); + } + /* * Make sure the request and temporary directories have the right * permissions...