Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
71 changes: 5 additions & 66 deletions cups/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,14 @@ 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 */
# ifdef DEBUG
char hostaddr[256]; // Host address string
# endif // DEBUG
const char *www_auth; /* WWW-Authenticate header */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */


DEBUG_printf(("7cups_local_auth(http=%p) hostaddr=%s, hostname=\"%s\"", (void *)http, httpAddrGetString(http->hostaddr, filename, sizeof(filename)), http->hostname));
DEBUG_printf(("7cups_local_auth(http=%p) hostaddr=%s, hostname=\"%s\"", (void *)http, httpAddrGetString(http->hostaddr, hostaddr, sizeof(hostaddr)), http->hostname));

/*
* See if we are accessing localhost...
Expand Down Expand Up @@ -597,65 +595,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__ */
}
10 changes: 3 additions & 7 deletions cups/cups-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,9 @@ typedef enum _cups_uatokens_e /**** UserAgentTokens values */
typedef struct _cups_globals_s /**** CUPS global state data ****/
{
/* Multiple places... */
const char *cups_datadir, /* CUPS_DATADIR environment var */
*cups_serverbin,/* CUPS_SERVERBIN environment var */
*cups_serverroot,
/* CUPS_SERVERROOT environment var */
*cups_statedir, /* CUPS_STATEDIR environment var */
*home, /* HOME environment var */
*localedir; /* LOCALDIR environment var */
const char *datadir, // Data directory (CUPS_DATADIR environment var)
*sysconfig, // System config files (CUPS_SERVERROOT environment var)
*userconfig; // User-specific config files (various environment vars)
#ifndef _WIN32
#define PW_BUF_SIZE 16384 /* As per glibc manual page */
char pw_buf[PW_BUF_SIZE];
Expand Down
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
Loading