summaryrefslogtreecommitdiff
path: root/cups/globals.c
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2019-11-14 15:30:00 -0500
committerMichael R Sweet <michael.r.sweet@gmail.com>2019-11-14 15:30:00 -0500
commite2eb28cfcf10ef163253a65f631e0cc98fe34804 (patch)
treecb7e7018323e6084ef4cf0ec60bd26c0b726ed78 /cups/globals.c
parent3ff5a8e3932907c5794165b27ecefa1e8d7b1321 (diff)
downloadcups-e2eb28cfcf10ef163253a65f631e0cc98fe34804.tar.gz
Sandboxed applications were not able to get the default printer (Issue #5676)
- Add "home" global pointing to the user's home directory. - Use it instead of getenv("HOME") everywhere we needed it.
Diffstat (limited to 'cups/globals.c')
-rw-r--r--cups/globals.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/cups/globals.c b/cups/globals.c
index b75434f2c..e5c87f14a 100644
--- a/cups/globals.c
+++ b/cups/globals.c
@@ -1,10 +1,11 @@
/*
* Global variable access routines for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright © 2007-2019 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
@@ -12,6 +13,9 @@
*/
#include "cups-private.h"
+#ifndef _WIN32
+# include <pwd.h>
+#endif /* !_WIN32 */
/*
@@ -269,6 +273,8 @@ cups_globals_alloc(void)
if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
cg->localedir = localedir;
+ cg->home = getenv("HOME");
+
#else
# ifdef HAVE_GETEUID
if ((geteuid() != getuid() && getuid()) || getegid() != getgid())
@@ -307,9 +313,23 @@ cups_globals_alloc(void)
if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
cg->localedir = CUPS_LOCALEDIR;
+
+# ifndef __APPLE__ /* Sandboxing now exposes the container as the home directory */
+ cg->home = getenv("HOME");
+#endif /* !__APPLE__ */
+ }
+
+ if (!cg->home)
+ {
+ struct passwd *pw; /* User info */
+
+ if ((pw = getpwuid(getuid())) != NULL)
+ cg->home = _cupsStrAlloc(pw->pw_dir);
}
#endif /* _WIN32 */
+ fprintf(stderr, "Using \"%s\" as home directory.\n", cg->home);
+
return (cg);
}