Skip to content

Commit 23b1be6

Browse files
committed
Complete transition to new dir vars.
1 parent aeaa474 commit 23b1be6

9 files changed

Lines changed: 103 additions & 220 deletions

File tree

cups/auth.c

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,8 @@ cups_local_auth(http_t *http) /* I - HTTP connection to server */
540540

541541
return (1);
542542
#else
543-
int pid; /* Current process ID */
544-
FILE *fp; /* Certificate file */
545-
char trc[16], /* Try Root Certificate parameter */
546-
filename[1024]; /* Certificate filename */
547-
const char *www_auth, /* WWW-Authenticate header */
548-
*schemedata; /* Data for the named auth scheme */
543+
char filename[1024]; /* Certificate filename */
544+
const char *www_auth; /* WWW-Authenticate header */
549545
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
550546

551547

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

600-
if ((schemedata = cups_auth_find(www_auth, "Local")) == NULL)
601-
return (1);
602-
603-
/*
604-
* Try opening a certificate file for this PID. If that fails,
605-
* try the root certificate...
606-
*/
607-
608-
pid = getpid();
609-
snprintf(filename, sizeof(filename), "%s/certs/%d", cg->cups_statedir, pid);
610-
if ((fp = fopen(filename, "r")) == NULL && pid > 0)
611-
{
612-
/*
613-
* No certificate for this PID; see if we can get the root certificate...
614-
*/
615-
616-
DEBUG_printf(("9cups_local_auth: Unable to open file \"%s\": %s", filename, strerror(errno)));
617-
618-
if (!cups_auth_param(schemedata, "trc", trc, sizeof(trc)))
619-
{
620-
/*
621-
* Scheduler doesn't want us to use the root certificate...
622-
*/
623-
624-
return (1);
625-
}
626-
627-
snprintf(filename, sizeof(filename), "%s/certs/0", cg->cups_statedir);
628-
if ((fp = fopen(filename, "r")) == NULL)
629-
DEBUG_printf(("9cups_local_auth: Unable to open file \"%s\": %s", filename, strerror(errno)));
630-
}
631-
632-
if (fp)
633-
{
634-
/*
635-
* Read the certificate from the file...
636-
*/
637-
638-
char certificate[33], /* Certificate string */
639-
*certptr; /* Pointer to certificate string */
640-
641-
certptr = fgets(certificate, sizeof(certificate), fp);
642-
fclose(fp);
643-
644-
if (certptr)
645-
{
646-
/*
647-
* Set the authorization string and return...
648-
*/
649-
650-
httpSetAuthString(http, "Local", certificate);
651-
652-
DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
653-
http->authstring));
654-
655-
return (0);
656-
}
657-
}
658-
659596
return (1);
660597
#endif /* _WIN32 || __EMX__ */
661598
}

cups/dest.c

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,19 +1578,13 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT
15781578
instance = NULL;
15791579
}
15801580
}
1581-
else if (cg->home)
1581+
else if (cg->userconfig)
15821582
{
15831583
/*
15841584
* No default in the environment, try the user's lpoptions files...
15851585
*/
15861586

1587-
#if _WIN32
1588-
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
1589-
#elif defined(__APPLE__)
1590-
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
1591-
#else
1592-
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
1593-
#endif // _WIN32
1587+
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
15941588

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

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

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

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

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

1702-
if (cg->home)
1696+
if (cg->userconfig)
17031697
{
1704-
#if _WIN32
1705-
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
1706-
#elif defined(__APPLE__)
1707-
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
1708-
#else
1709-
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
1710-
#endif // _WIN32
1698+
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
17111699

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

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

1858-
if (cg->home)
1846+
if (cg->userconfig)
18591847
{
18601848
/*
1861-
* Create ~/.cups subdirectory...
1849+
* Create user subdirectory...
18621850
*/
18631851

1864-
#if _WIN32
1865-
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups", cg->home);
1866-
#elif defined(__APPLE__)
1867-
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups", cg->home);
1868-
#else
1869-
snprintf(filename, sizeof(filename), "%s/.cups", cg->home);
1870-
#endif // _WIN32
1871-
if (mkdir(filename, 0700) && errno != EEXIST)
1852+
if (mkdir(cg->userconfig, 0700) && errno != EEXIST)
18721853
{
18731854
cupsFreeDests(num_temps, temps);
18741855
return (false);
18751856
}
18761857

1877-
#if _WIN32
1878-
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
1879-
#elif defined(__APPLE__)
1880-
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
1881-
#else
1882-
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
1883-
#endif // _WIN32
1858+
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
18841859
}
18851860

18861861
/*
@@ -3016,18 +2991,12 @@ cups_enum_dests(
30162991

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

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

3022-
if (cg->home)
2997+
if (cg->userconfig)
30232998
{
3024-
#if _WIN32
3025-
snprintf(filename, sizeof(filename), "%s/AppData/Local/cups/lpoptions", cg->home);
3026-
#elif defined(__APPLE__)
3027-
snprintf(filename, sizeof(filename), "%s/Library/Application Support/cups/lpoptions", cg->home);
3028-
#else
3029-
snprintf(filename, sizeof(filename), "%s/.cups/lpoptions", cg->home);
3030-
#endif // _WIN32
2999+
snprintf(filename, sizeof(filename), "%s/lpoptions", cg->userconfig);
30313000

30323001
data.num_dests = cups_get_dests(filename, NULL, NULL, 1, user_default != NULL, data.num_dests, &data.dests);
30333002
}

cups/globals.c

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ cups_globals_alloc(void)
170170
#ifdef _WIN32
171171
HKEY key; // Registry key
172172
DWORD size; // Size of string
173-
static char homedir[1024] = "", // Home directory
174-
installdir[1024] = "", // Install directory
175-
confdir[1024] = "", // Server root directory
176-
localedir[1024] = ""; // Locale directory
173+
static char installdir[1024] = "", // Install directory
174+
userconfig[1024] = "", // User configuration directory
175+
sysconf[1024] = ""; // Server configuration directory
177176
#endif // _WIN32
178177

179178

@@ -208,18 +207,12 @@ cups_globals_alloc(void)
208207
#ifdef _WIN32
209208
if (!installdir[0])
210209
{
211-
/*
212-
* Open the registry...
213-
*/
214-
210+
// Open the registry...
215211
cupsCopyString(installdir, "C:/Program Files/cups.org", sizeof(installdir));
216212

217213
if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ, &key))
218214
{
219-
/*
220-
* Grab the installation directory...
221-
*/
222-
215+
// Grab the installation directory...
223216
char *ptr; // Pointer into installdir
224217

225218
size = sizeof(installdir);
@@ -236,51 +229,45 @@ cups_globals_alloc(void)
236229
*ptr = '\0'; // Strip trailing "\"
237230
}
238231
else if (*ptr == '/' && !ptr[1])
232+
{
239233
*ptr = '\0'; // Strip trailing "/"
234+
}
240235
else
236+
{
241237
ptr ++;
238+
}
242239
}
243240
}
244241

245-
snprintf(confdir, sizeof(confdir), "%s/conf", installdir);
246-
snprintf(localedir, sizeof(localedir), "%s/locale", installdir);
242+
snprintf(sysconfig, sizeof(sysconfig), "%s/conf", installdir);
247243
}
248244

249-
if ((cg->cups_datadir = getenv("CUPS_DATADIR")) == NULL)
250-
cg->cups_datadir = installdir;
251-
252-
if ((cg->cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
253-
cg->cups_serverbin = installdir;
254-
255-
if ((cg->cups_serverroot = getenv("CUPS_SERVERROOT")) == NULL)
256-
cg->cups_serverroot = confdir;
245+
if ((cg->datadir = getenv("CUPS_DATADIR")) == NULL)
246+
cg->datadir = installdir;
257247

258-
if ((cg->cups_statedir = getenv("CUPS_STATEDIR")) == NULL)
259-
cg->cups_statedir = confdir;
248+
if ((cg->sysconfig = getenv("CUPS_SERVERROOT")) == NULL)
249+
cg->sysconfig = sysconfig;
260250

261-
if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
262-
cg->localedir = localedir;
263-
264-
if (!homedir[0])
251+
if (!userconfig[0])
265252
{
266253
const char *userprofile = getenv("USERPROFILE");
267254
// User profile (home) directory
268255
char *homeptr; // Pointer into homedir
269256

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

272-
snprintf(homedir, sizeof(homedir), "%s/AppData/Local/cups", userprofile);
273-
for (homeptr = homedir; *homeptr; homeptr ++)
259+
snprintf(userconfig, sizeof(userconfig), "%s/AppData/Local/cups", userprofile);
260+
for (userptr = userconfig; *userptr; userptr ++)
274261
{
275262
// Convert back slashes to forward slashes
276-
if (*homeptr == '\\')
277-
*homeptr = '/';
263+
if (*userptr == '\\')
264+
*userptr = '/';
278265
}
279266

280-
DEBUG_printf(("cups_globals_alloc: homedir=\"%s\"", homedir));
267+
DEBUG_printf(("cups_globals_alloc: userconfig=\"%s\"", userconfig));
281268
}
282269

283-
cg->home = homedir;
270+
cg->userconfig = userconfig;
284271

285272
#else
286273
const char *home = getenv("HOME"); // HOME environment variable
@@ -339,40 +326,41 @@ cups_globals_alloc(void)
339326
# ifdef __APPLE__
340327
if (home)
341328
{
329+
// macOS uses ~/Library/Application Support/FOO
342330
snprintf(temp, sizeof(temp), "%s/Library/Application Support/cups", home);
343-
cg->userconfig = _cupsStrAlloc(temp);
344331
}
345332
else
346333
{
334+
// Something went wrong, use temporary directory...
347335
snprintf(temp, sizeof(temp), "/private/tmp/cups%u", (unsigned)getuid());
348-
cg->userconfig = _cupsStrAlloc(temp);
349336
}
350337

351338
# else
352339
if (snap_common)
353340
{
341+
// Snaps use $SNAP_COMMON/FOO
354342
snprintf(temp, sizeof(temp), "%s/cups", snap_common);
355-
cg->userconfig = _cupsStrAlloc(temp);
356343
}
357344
else if (xdg_config_home)
358345
{
346+
// XDG uses $XDG_CONFIG_HOME/FOO
359347
snprintf(temp, sizeof(temp), "%s/cups", xdg_config_home);
360-
cg->userconfig = _cupsStrAlloc(temp);
361348
}
362349
else if (home)
363350
{
364-
// Use ~/.cups if it exists, otherwise ~/.config/cups
351+
// Use ~/.cups if it exists, otherwise ~/.config/cups (XDG standard)
365352
snprintf(temp, sizeof(temp), "%s/.cups", home);
366353
if (access(temp, 0))
367354
snprintf(temp, sizeof(temp), "%s/.config/cups", home);
368-
cg->userconfig = _cupsStrAlloc(temp);
369355
}
370356
else
371357
{
358+
// Something went wrong, use temporary directory...
372359
snprintf(temp, sizeof(temp), "/tmp/cups%u", (unsigned)getuid());
373-
cg->userconfig = _cupsStrAlloc(temp);
374360
}
375361
# endif // __APPLE__
362+
363+
cg->userconfig = _cupsStrAlloc(temp);
376364
#endif // _WIN32
377365

378366
return (cg);

cups/raster-stream.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ cupsRasterInitHeader(
334334
h->cupsPageSize[0] = 72.0f * media->width / 2540.0f;
335335
h->cupsPageSize[1] = 72.0f * media->length / 2540.0f;
336336

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

342342
h->HWResolution[0] = (unsigned)xdpi;
343343
h->HWResolution[1] = (unsigned)ydpi;

0 commit comments

Comments
 (0)