Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Complete transition to new dir vars.
  • Loading branch information
michaelrsweet committed Feb 8, 2023
commit 23b1be68803128ed701d374981c4583bcf9e7bf6
67 changes: 2 additions & 65 deletions cups/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,8 @@ cups_local_auth(http_t *http) /* I - HTTP connection to server */

return (1);
#else
int pid; /* Current process ID */
FILE *fp; /* Certificate file */
char trc[16], /* Try Root Certificate parameter */
filename[1024]; /* Certificate filename */
const char *www_auth, /* WWW-Authenticate header */
*schemedata; /* Data for the named auth scheme */
char filename[1024]; /* Certificate filename */
Comment thread Fixed
const char *www_auth; /* WWW-Authenticate header */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */


Expand Down Expand Up @@ -597,65 +593,6 @@ cups_local_auth(http_t *http) /* I - HTTP connection to server */
}
# endif /* SO_PEERCRED && AF_LOCAL */

if ((schemedata = cups_auth_find(www_auth, "Local")) == NULL)
return (1);

/*
* Try opening a certificate file for this PID. If that fails,
* try the root certificate...
*/

pid = getpid();
snprintf(filename, sizeof(filename), "%s/certs/%d", cg->cups_statedir, pid);
if ((fp = fopen(filename, "r")) == NULL && pid > 0)
{
/*
* No certificate for this PID; see if we can get the root certificate...
*/

DEBUG_printf(("9cups_local_auth: Unable to open file \"%s\": %s", filename, strerror(errno)));

if (!cups_auth_param(schemedata, "trc", trc, sizeof(trc)))
{
/*
* Scheduler doesn't want us to use the root certificate...
*/

return (1);
}

snprintf(filename, sizeof(filename), "%s/certs/0", cg->cups_statedir);
if ((fp = fopen(filename, "r")) == NULL)
DEBUG_printf(("9cups_local_auth: Unable to open file \"%s\": %s", filename, strerror(errno)));
}

if (fp)
{
/*
* Read the certificate from the file...
*/

char certificate[33], /* Certificate string */
*certptr; /* Pointer to certificate string */

certptr = fgets(certificate, sizeof(certificate), fp);
fclose(fp);

if (certptr)
{
/*
* Set the authorization string and return...
*/

httpSetAuthString(http, "Local", certificate);

DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
http->authstring));

return (0);
}
}

return (1);
#endif /* _WIN32 || __EMX__ */
}
59 changes: 14 additions & 45 deletions cups/dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,19 +1578,13 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT
instance = NULL;
}
}
else if (cg->home)
else if (cg->userconfig)
{
/*
* No default in the environment, try the user's lpoptions files...
*/

#if _WIN32
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
#elif defined(__APPLE__)
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
#else
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
#endif // _WIN32
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);

dest_name = cups_get_default(filename, defname, sizeof(defname), &instance);

Expand All @@ -1604,7 +1598,7 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT
* Still not there? Try the system lpoptions file...
*/

snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot);
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->sysconfig);
dest_name = cups_get_default(filename, defname, sizeof(defname), &instance);

if (dest_name)
Expand Down Expand Up @@ -1696,18 +1690,12 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT
* Then add local options...
*/

snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot);
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->sysconfig);
cups_get_dests(filename, dest_name, instance, 0, 1, 1, &dest);

if (cg->home)
if (cg->userconfig)
{
#if _WIN32
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
#elif defined(__APPLE__)
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
#else
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
#endif // _WIN32
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);

cups_get_dests(filename, dest_name, instance, 0, 1, 1, &dest);
}
Expand Down Expand Up @@ -1853,34 +1841,21 @@ cupsSetDests(http_t *http, /* I - Connection to server or @code CUPS_HTTP_
* Figure out which file to write to...
*/

snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot);
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->sysconfig);

if (cg->home)
if (cg->userconfig)
{
/*
* Create ~/.cups subdirectory...
* Create user subdirectory...
*/

#if _WIN32
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups", cg->home);
#elif defined(__APPLE__)
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups", cg->home);
#else
snprintf(filename, sizeof(filename), "%s/.cups", cg->home);
#endif // _WIN32
if (mkdir(filename, 0700) && errno != EEXIST)
if (mkdir(cg->userconfig, 0700) && errno != EEXIST)
{
cupsFreeDests(num_temps, temps);
return (false);
}

#if _WIN32
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
#elif defined(__APPLE__)
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
#else
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
#endif // _WIN32
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
}

/*
Expand Down Expand Up @@ -3016,18 +2991,12 @@ cups_enum_dests(

user_default = _cupsGetUserDefault(data.def_name, sizeof(data.def_name));

snprintf(filename, sizeof(filename), "%s/lpoptions", cg->cups_serverroot);
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->sysconfig);
data.num_dests = cups_get_dests(filename, NULL, NULL, 1, user_default != NULL, data.num_dests, &data.dests);

if (cg->home)
if (cg->userconfig)
{
#if _WIN32
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
#elif defined(__APPLE__)
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
#else
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
#endif // _WIN32
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);

data.num_dests = cups_get_dests(filename, NULL, NULL, 1, user_default != NULL, data.num_dests, &data.dests);
}
Expand Down
70 changes: 29 additions & 41 deletions cups/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ cups_globals_alloc(void)
#ifdef _WIN32
HKEY key; // Registry key
DWORD size; // Size of string
static char homedir[1024] = "", // Home directory
installdir[1024] = "", // Install directory
confdir[1024] = "", // Server root directory
localedir[1024] = ""; // Locale directory
static char installdir[1024] = "", // Install directory
userconfig[1024] = "", // User configuration directory
sysconf[1024] = ""; // Server configuration directory
#endif // _WIN32


Expand Down Expand Up @@ -208,18 +207,12 @@ cups_globals_alloc(void)
#ifdef _WIN32
if (!installdir[0])
{
/*
* Open the registry...
*/

// Open the registry...
cupsCopyString(installdir, "C:/Program Files/cups.org", sizeof(installdir));

if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ, &key))
{
/*
* Grab the installation directory...
*/

// Grab the installation directory...
char *ptr; // Pointer into installdir

size = sizeof(installdir);
Expand All @@ -236,51 +229,45 @@ cups_globals_alloc(void)
*ptr = '\0'; // Strip trailing "\"
}
else if (*ptr == '/' && !ptr[1])
{
*ptr = '\0'; // Strip trailing "/"
}
else
{
ptr ++;
}
}
}

snprintf(confdir, sizeof(confdir), "%s/conf", installdir);
snprintf(localedir, sizeof(localedir), "%s/locale", installdir);
snprintf(sysconfig, sizeof(sysconfig), "%s/conf", installdir);
}

if ((cg->cups_datadir = getenv("CUPS_DATADIR")) == NULL)
cg->cups_datadir = installdir;

if ((cg->cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
cg->cups_serverbin = installdir;

if ((cg->cups_serverroot = getenv("CUPS_SERVERROOT")) == NULL)
cg->cups_serverroot = confdir;
if ((cg->datadir = getenv("CUPS_DATADIR")) == NULL)
cg->datadir = installdir;

if ((cg->cups_statedir = getenv("CUPS_STATEDIR")) == NULL)
cg->cups_statedir = confdir;
if ((cg->sysconfig = getenv("CUPS_SERVERROOT")) == NULL)
cg->sysconfig = sysconfig;

if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
cg->localedir = localedir;

if (!homedir[0])
if (!userconfig[0])
{
const char *userprofile = getenv("USERPROFILE");
// User profile (home) directory
char *homeptr; // Pointer into homedir

DEBUG_printf(("cups_globals_alloc: USERPROFILE=\"%s\"", userprofile));

snprintf(homedir, sizeof(homedir), "%s/AppData/Local/cups", userprofile);
for (homeptr = homedir; *homeptr; homeptr ++)
snprintf(userconfig, sizeof(userconfig), "%s/AppData/Local/cups", userprofile);
for (userptr = userconfig; *userptr; userptr ++)
{
// Convert back slashes to forward slashes
if (*homeptr == '\\')
*homeptr = '/';
if (*userptr == '\\')
*userptr = '/';
}

DEBUG_printf(("cups_globals_alloc: homedir=\"%s\"", homedir));
DEBUG_printf(("cups_globals_alloc: userconfig=\"%s\"", userconfig));
}

cg->home = homedir;
cg->userconfig = userconfig;

#else
const char *home = getenv("HOME"); // HOME environment variable
Expand Down Expand Up @@ -339,40 +326,41 @@ cups_globals_alloc(void)
# ifdef __APPLE__
if (home)
{
// macOS uses ~/Library/Application Support/FOO
snprintf(temp, sizeof(temp), "%s/Library/Application Support/cups", home);
cg->userconfig = _cupsStrAlloc(temp);
}
else
{
// Something went wrong, use temporary directory...
snprintf(temp, sizeof(temp), "/private/tmp/cups%u", (unsigned)getuid());
cg->userconfig = _cupsStrAlloc(temp);
}

# else
if (snap_common)
{
// Snaps use $SNAP_COMMON/FOO
snprintf(temp, sizeof(temp), "%s/cups", snap_common);
cg->userconfig = _cupsStrAlloc(temp);
}
else if (xdg_config_home)
{
// XDG uses $XDG_CONFIG_HOME/FOO
snprintf(temp, sizeof(temp), "%s/cups", xdg_config_home);
cg->userconfig = _cupsStrAlloc(temp);
}
else if (home)
{
// Use ~/.cups if it exists, otherwise ~/.config/cups
// Use ~/.cups if it exists, otherwise ~/.config/cups (XDG standard)
snprintf(temp, sizeof(temp), "%s/.cups", home);
if (access(temp, 0))
snprintf(temp, sizeof(temp), "%s/.config/cups", home);
cg->userconfig = _cupsStrAlloc(temp);
}
else
{
// Something went wrong, use temporary directory...
snprintf(temp, sizeof(temp), "/tmp/cups%u", (unsigned)getuid());
cg->userconfig = _cupsStrAlloc(temp);
}
# endif // __APPLE__

cg->userconfig = _cupsStrAlloc(temp);
#endif // _WIN32

return (cg);
Expand Down
8 changes: 4 additions & 4 deletions cups/raster-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ cupsRasterInitHeader(
h->cupsPageSize[0] = 72.0f * media->width / 2540.0f;
h->cupsPageSize[1] = 72.0f * media->length / 2540.0f;

h->ImagingBoundingBox[0] = (unsigned)(72.0f * media->left / 2540.0f);
h->ImagingBoundingBox[1] = (unsigned)(72.0f * media->bottom / 2540.0f);
h->ImagingBoundingBox[2] = (unsigned)(72.0f * (media->width - media->right) / 2540.0f);
h->ImagingBoundingBox[3] = (unsigned)(72.0f * (media->length - media->top) / 2540.0f);
h->ImagingBoundingBox[0] = (unsigned)(72 * media->left / 2540);
h->ImagingBoundingBox[1] = (unsigned)(72 * media->bottom / 2540);
h->ImagingBoundingBox[2] = (unsigned)(72 * (media->width - media->right) / 2540);
h->ImagingBoundingBox[3] = (unsigned)(72 * (media->length - media->top) / 2540);

h->HWResolution[0] = (unsigned)xdpi;
h->HWResolution[1] = (unsigned)ydpi;
Expand Down
Loading