Skip to content

Commit

Permalink
Force host name to localhost when listening on localhost.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 16, 2024
1 parent b6daf69 commit 6f6f852
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 68 deletions.
77 changes: 12 additions & 65 deletions pappl/system-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ papplSystemAddListeners(
else
{
// Add named listeners on both IPv4 and IPv6...
if (!strcasecmp(name, "localhost"))
papplSystemSetHostName(system, "localhost");

if (system->port)
{
ret = add_listeners(system, name, system->port, AF_INET) ||
Expand Down Expand Up @@ -768,25 +771,6 @@ papplSystemGetGeoLocation(
}


//
// 'papplSystemGetHostname()' - Get the system hostname.
//
// This function is deprecated. Use the @link papplSystemGetHostName@ function
// instead.
//
// @deprecated@ @exclude all@
//

char * // O - Hostname
papplSystemGetHostname(
pappl_system_t *system, // I - System
char *buffer, // I - String buffer
size_t bufsize) // I - Size of string buffer
{
return (papplSystemGetHostName(system, buffer, bufsize));
}


//
// 'papplSystemGetHostName()' - Get the system hostname.
//
Expand Down Expand Up @@ -1256,24 +1240,6 @@ papplSystemGetPassword(
}


//
// 'papplSystemGetPort()' - Get the port number for network connections to the
// system.
//
// This function is deprecated. Use the @link papplSystemGetHostName@ function
// instead.
//
// @deprecated@ @exclude all@
//

int // O - Port number
papplSystemGetPort(
pappl_system_t *system) // I - System
{
return (system ? system->port : 0);
}


//
// 'papplSystemGetServerHeader()' - Get the Server: header for HTTP responses.
//
Expand Down Expand Up @@ -1938,24 +1904,6 @@ papplSystemSetGeoLocation(
}


//
// 'papplSystemSetHostname()' - Set the system hostname.
//
// This function is deprecated. Use the @link papplSystemSetHostName@ function
// instead.
//
// @deprecated@ @exclude all@
//

void
papplSystemSetHostname(
pappl_system_t *system, // I - System
const char *value) // I - Hostname or `NULL` for default
{
papplSystemSetHostName(system, value);
}


//
// '_papplSystemSetHostNameNoLock()' - Set the system hostname without locking.
//
Expand All @@ -1972,8 +1920,14 @@ _papplSystemSetHostNameNoLock(
*ptr; // Pointer in temporary hostname


if (value)
// If the hostname has been set to "localhost", that means we are running
// locally...
if (system->hostname && !strcasecmp(system->hostname, "localhost"))
return;

if (value && strcasecmp(value, "localhost"))
{
// Save new hostname...
#if !defined(__APPLE__) && !_WIN32
cups_file_t *fp; // Hostname file

Expand All @@ -1984,20 +1938,13 @@ _papplSystemSetHostNameNoLock(
}
#endif // !__APPLE__ && !_WIN32

#if 0
_pappl_dns_sd_t master = _papplDNSSDInit(system);
// DNS-SD master reference

if (master)
avahi_client_set_host_name(master, value);
#endif // 0

#if !_WIN32
sethostname(value, (int)strlen(value));
#endif // !_WIN32
}
else
else if (!value)
{
// Get the current hostname...
cupsDNSSDCopyHostName(system->dns_sd, temp, sizeof(temp));

if ((ptr = strstr(temp, ".lan")) != NULL && !ptr[4])
Expand Down
3 changes: 0 additions & 3 deletions pappl/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ extern char *papplSystemGetDefaultPrintGroup(pappl_system_t *system, char *buff
extern char *papplSystemGetDNSSDName(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern const char *papplSystemGetFooterHTML(pappl_system_t *system) _PAPPL_PUBLIC;
extern char *papplSystemGetGeoLocation(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern char *papplSystemGetHostname(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_DEPRECATED("Use papplSystemGetHostName instead.");
extern char *papplSystemGetHostName(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern int papplSystemGetHostPort(pappl_system_t *system) _PAPPL_PUBLIC;
extern int papplSystemGetIdleShutdown(pappl_system_t *system) _PAPPL_PUBLIC;
Expand All @@ -209,7 +208,6 @@ extern pappl_soptions_t papplSystemGetOptions(pappl_system_t *system) _PAPPL_PUB
extern char *papplSystemGetOrganization(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern char *papplSystemGetOrganizationalUnit(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern char *papplSystemGetPassword(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern int papplSystemGetPort(pappl_system_t *system) _PAPPL_DEPRECATED("Use papplSystemGetHostPort instead.");
extern const char *papplSystemGetServerHeader(pappl_system_t *system) _PAPPL_PUBLIC;
extern char *papplSystemGetSessionKey(pappl_system_t *system, char *buffer, size_t bufsize) _PAPPL_PUBLIC;
extern bool papplSystemGetTLSOnly(pappl_system_t *system) _PAPPL_PUBLIC;
Expand Down Expand Up @@ -241,7 +239,6 @@ extern void papplSystemSetDNSSDName(pappl_system_t *system, const char *value)
extern void papplSystemSetEventCallback(pappl_system_t *system, pappl_event_cb_t event_cb, void *event_data) _PAPPL_PUBLIC;
extern void papplSystemSetFooterHTML(pappl_system_t *system, const char *html) _PAPPL_PUBLIC;
extern void papplSystemSetGeoLocation(pappl_system_t *system, const char *value) _PAPPL_PUBLIC;
extern void papplSystemSetHostname(pappl_system_t *system, const char *value) _PAPPL_DEPRECATED("Use papplSystemSetHostName instead.");
extern void papplSystemSetHostName(pappl_system_t *system, const char *value) _PAPPL_PUBLIC;
extern void papplSystemSetIdleShutdown(pappl_system_t *system, int seconds) _PAPPL_PUBLIC;
extern void papplSystemSetLocation(pappl_system_t *system, const char *value) _PAPPL_PUBLIC;
Expand Down

0 comments on commit 6f6f852

Please sign in to comment.