/*
- * "$Id: adminutil.c 5240 2006-03-07 21:55:29Z mike $"
+ * "$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",
* Create a temporary output file using the destination buffer...
*/
- if ((dstfp = cupsTempFile2(buffer, bufsize)) < 0)
+ if ((dstfp = cupsTempFile2(buffer, bufsize)) == NULL)
{
cupsFileClose(srcfp);
*/
cupsFilePrintf(dstfp, "*%% Commented out for CUPS Windows Driver...\n"
- "*%%%s", line + 1);
+ "*%%%s\n", line + 1);
continue;
}
else if (!strncmp(line, "*JCLOpenUI", 10))
{
jcloption = 1;
- cupsFilePuts(dstfp, line);
+ cupsFilePrintf(dstfp, "%s\n", line);
}
else if (!strncmp(line, "*JCLCloseUI", 11))
{
jcloption = 0;
- cupsFilePuts(dstfp, line);
+ cupsFilePrintf(dstfp, "%s\n", line);
}
else if (jcloption &&
strncmp(line, "*End", 4) &&
}
snprintf(ptr + 1, sizeof(line) - (ptr - line + 1),
- "%%cupsJobTicket: %s=%s\n\"\n*End\n", option, choice);
+ "%%cupsJobTicket: %s=%s\n\"\n*End", option, choice);
- cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s", line);
+ cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s\n",
+ line);
}
else
- cupsFilePuts(dstfp, line);
+ cupsFilePrintf(dstfp, "%s\n", line);
}
cupsFileClose(srcfp);
const char *samba_password, /* I - Samba password */
FILE *logfile) /* I - Log file, if any */
{
- int status; /* Status of smbclient/rpcclient commands */
+ int status; /* Status of Samba commands */
int have_drivers; /* Have drivers? */
char file[1024], /* File to test for */
authfile[1024], /* Temporary authentication file */
sizeof(cupsdconf), &remote)) == HTTP_OK)
{
if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+ {
+ char message[1024]; /* Message string */
+
+
+ snprintf(message, sizeof(message),
+ _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
+ cupsdconf, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, message);
+ }
}
else
cupsd = NULL;
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());
+ cupsFilePuts(temp, "# Only listen for connections from the local "
+ "machine.\n");
+ 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") ||
if (remote_printers || share_printers)
{
if (remote_printers && share_printers)
- cupsFilePuts(temp, "# Enable printer sharing and shared printers.\n");
+ cupsFilePuts(temp,
+ "# Enable printer sharing and shared printers.\n");
else if (remote_printers)
- cupsFilePuts(temp, "# Show shared printers on the local network.\n");
+ cupsFilePuts(temp,
+ "# Show shared printers on the local network.\n");
else
- cupsFilePuts(temp, "# Share local printers on the local network.\n");
+ cupsFilePuts(temp,
+ "# Share local printers on the local network.\n");
cupsFilePuts(temp, "Browsing On\n");
cupsFilePuts(temp, "BrowseOrder allow,deny\n");
}
else
{
- cupsFilePuts(temp, "# Disable printer sharing and shared printers.\n");
+ cupsFilePuts(temp,
+ "# Disable printer sharing and shared printers.\n");
cupsFilePuts(temp, "Browsing Off\n");
}
}
if (debug_logging)
{
- cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n");
+ cupsFilePuts(temp,
+ "# Show troubleshooting information in error_log.\n");
cupsFilePuts(temp, "LogLevel debug\n");
}
else
wrote_policy = 1;
if (!user_cancel_any)
- cupsFilePuts(temp, " # Only the owner or an administrator can cancel a job...\n"
+ cupsFilePuts(temp, " # Only the owner or an administrator can "
+ "cancel a job...\n"
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Allow @SYSTEM\n"
wrote_conf_location = 1;
if (remote_admin)
- cupsFilePuts(temp, " # Allow remote access to the configuration files...\n");
+ cupsFilePuts(temp, " # Allow remote access to the configuration "
+ "files...\n");
else
- cupsFilePuts(temp, " # Restrict access to the configuration files...\n");
+ cupsFilePuts(temp, " # Restrict access to the configuration "
+ "files...\n");
cupsFilePuts(temp, " Order allow,deny\n");
wrote_root_location = 1;
if (remote_admin && share_printers)
- cupsFilePuts(temp, " # Allow shared printing and remote administration...\n");
+ cupsFilePuts(temp, " # Allow shared printing and remote "
+ "administration...\n");
else if (remote_admin)
cupsFilePuts(temp, " # Allow remote administration...\n");
else if (share_printers)
wrote_policy = 1;
if (!user_cancel_any)
- cupsFilePuts(temp, " # Only the owner or an administrator can cancel a job...\n"
+ cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
+ "a job...\n"
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Require user @OWNER @SYSTEM\n"
}
else
{
- cupsFilePuts(temp, "# Only listen for connections from the local machine.\n");
- cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+ cupsFilePuts(temp,
+ "# Only listen for connections from the local machine.\n");
+ cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
}
#ifdef CUPS_DEFAULT_DOMAINSOCKET
if (!wrote_root_location)
{
if (remote_admin && share_printers)
- cupsFilePuts(temp, "# Allow shared printing and remote administration...\n");
+ cupsFilePuts(temp,
+ "# Allow shared printing and remote administration...\n");
else if (remote_admin)
cupsFilePuts(temp, "# Allow remote administration...\n");
else if (share_printers)
if (!wrote_conf_location)
{
if (remote_admin)
- cupsFilePuts(temp, "# Allow remote access to the configuration files...\n");
+ cupsFilePuts(temp,
+ "# Allow remote access to the configuration files...\n");
else
cupsFilePuts(temp, "# Restrict access to the configuration files...\n");
if (!wrote_policy)
{
cupsFilePuts(temp, "<Policy default>\n"
- " # Job-related operations must be done by the owner or an adminstrator...\n"
+ " # Job-related operations must be done by the owner "
+ "or an adminstrator...\n"
" <Limit Send-Document Send-URI Hold-Job Release-Job "
"Restart-Job Purge-Jobs Set-Job-Attributes "
"Create-Job-Subscription Renew-Subscription "
" Require user @OWNER @SYSTEM\n"
" Order deny,allow\n"
" </Limit>\n"
- " # All administration operations require an adminstrator to authenticate...\n"
+ " # All administration operations require an "
+ "adminstrator to authenticate...\n"
" <Limit Pause-Printer Resume-Printer "
"Set-Printer-Attributes Enable-Printer "
"Disable-Printer Pause-Printer-After-Current-Job "
"</Limit>\n");
if (!user_cancel_any)
- cupsFilePuts(temp, " # Only the owner or an administrator can cancel a job...\n"
+ cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
+ "a job...\n"
" <Limit Cancel-Job>\n"
" Require user @OWNER @SYSTEM\n"
" Order deny,allow\n"
{
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
{
if (stat(name, &info))
{
- *name = '\0';
+ char message[1024]; /* Message string */
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+
+ snprintf(message, sizeof(message),
+ _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
+ name, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, message);
+
+ *name = '\0';
return (HTTP_SERVER_ERROR);
}
* 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: adminutil.c 5240 2006-03-07 21:55:29Z mike $".
+ * End of "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $".
*/