/*
- * "$Id$"
+ * "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $"
*
* Administration utility API definitions for the Common UNIX Printing
* System (CUPS).
linenum; /* Current line number */
time_t curtime; /* Current time */
struct tm *curdate; /* Current date */
- static const char *pattrs[] = /* Printer attributes we want */
+ static const char * const pattrs[] = /* Printer attributes we want */
{
"job-hold-until-supported",
"job-hold-until-default",
if (!value)
continue;
- if (!strcasecmp(line, "Port"))
- {
- remote_access = 1;
- }
- else if (!strcasecmp(line, "Listen"))
+ if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
{
char *port; /* Pointer to port number, if any */
if ((port = strrchr(value, ':')) != NULL)
*port = '\0';
+ else if (isdigit(*value & 255))
+ {
+ /*
+ * Listen on a port number implies remote access...
+ */
+
+ remote_access = 1;
+ continue;
+ }
- if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1"))
+ if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1")
+#ifdef AF_LOCAL
+ && *value != '/'
+#endif /* AF_LOCAL */
+#ifdef AF_INET6
+ && strcmp(value, "::1")
+#endif /* AF_INET6 */
+ )
remote_access = 1;
}
else if (!strcasecmp(line, "Browsing"))
in_location = 0;
}
else if (!strcasecmp(line, "Allow") && in_admin_location &&
- strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1"))
+ strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
+#ifdef AF_LOCAL
+ && *value != '/'
+#endif /* AF_LOCAL */
+#ifdef AF_INET6
+ && strcmp(value, "::1")
+#endif /* AF_INET6 */
+ )
{
remote_admin = 1;
}
{
int i; /* Looping var */
http_status_t status; /* GET/PUT status */
+ const char *server_port_env; /* SERVER_PORT env var */
+ int server_port; /* IPP port for server */
cups_file_t *cupsd; /* cupsd.conf file */
char cupsdconf[1024]; /* cupsd.conf filename */
int remote; /* Remote cupsd.conf file? */
wrote_root_location = 0;
indent = 0;
+ if ((server_port_env = getenv("SERVER_PORT")) != NULL)
+ {
+ if ((server_port = atoi(server_port_env)) <= 0)
+ server_port = ippPort();
+ }
+ else
+ server_port = ippPort();
+
+ if (server_port <= 0)
+ server_port = IPP_PORT;
+
while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
{
if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
if (share_printers || remote_admin)
{
cupsFilePuts(temp, "# Allow remote access\n");
- cupsFilePrintf(temp, "Port %d\n", ippPort());
+ cupsFilePrintf(temp, "Port %d\n", server_port);
}
else
{
cupsFilePuts(temp, "# Only listen for connections from the local "
"machine.\n");
- cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+ cupsFilePrintf(temp, "Listen localhost:%d\n", server_port);
}
#ifdef CUPS_DEFAULT_DOMAINSOCKET
- if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0))
+ if ((!value || strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)) &&
+ !access(CUPS_DEFAULT_DOMAINSOCKET, 0))
cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
#endif /* CUPS_DEFAULT_DOMAINSOCKET */
}
+ else if (value && value[0] == '/' &&
+ strcmp(CUPS_DEFAULT_DOMAINSOCKET, value))
+ cupsFilePrintf(temp, "Listen %s\n", value);
}
else if (!strcasecmp(line, "Browsing") ||
!strcasecmp(line, "BrowseAddress") ||
{
cupsFilePuts(temp,
"# Only listen for connections from the local machine.\n");
- cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+ cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
}
#ifdef CUPS_DEFAULT_DOMAINSOCKET
{
status = -1;
- _cupsLangPrintf(stderr, _("cupsaddsmb: Unable to run \"%s\": %s\n"),
- command, strerror(errno));
+ if (logfile)
+ _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"),
+ command, strerror(errno));
}
else
{
* Read cupsd.conf via a HTTP GET request...
*/
- if ((fd = cupsTempFd(name, sizeof(name))) < 0)
+ if ((fd = cupsTempFd(name, namesize)) < 0)
{
*name = '\0';
/*
- * End of "$Id$".
+ * End of "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $".
*/