/*
- * "$Id: adminutil.c 6930 2007-09-08 00:28:06Z mike $"
+ * "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $"
*
* Administration utility API definitions for the Common UNIX Printing
* System (CUPS).
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2009 by Apple Inc.
* Copyright 2001-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
/*
* 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
*/
char * /* O - PPD file or NULL */
cupsAdminCreateWindowsPPD(
- http_t *http, /* I - Connection to server */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
const char *dest, /* I - Printer or class */
char *buffer, /* I - Filename buffer */
int bufsize) /* I - Size of filename buffer */
if (buffer)
*buffer = '\0';
+ if (!http)
+ http = _cupsConnect();
+
if (!http || !dest || !buffer || bufsize < 2)
return (NULL);
if ((ptr = strchr(line, ':')) == NULL)
{
snprintf(line, sizeof(line),
- _cupsLangString(language, _("Missing value on line %d!")),
- linenum);
- _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+ _cupsLangString(language, _("Missing value on line %d!")),
+ linenum);
+ _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
_cupsLangString(language,
_("Missing double quote on line %d!")),
linenum);
- _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+ _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
_cupsLangString(language,
_("Bad option + choice on line %d!")),
linenum);
- _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+ _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
if (linenum == 0)
{
- snprintf(line, sizeof(line),
- _cupsLangString(language, _("Empty PPD file!")),
- linenum);
- _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+ _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, _("Empty PPD file!"), 1);
cupsFileClose(dstfp);
unlink(buffer);
{
write_option(dstfp, jclorder ++, "cupsJobSheetsStart", "Start Banner",
"job-sheets", suppattr, defattr, 0, 2);
- write_option(dstfp, jclorder ++, "cupsJobSheetsEnd", "End Banner",
+ write_option(dstfp, jclorder, "cupsJobSheetsEnd", "End Banner",
"job-sheets", suppattr, defattr, 1, 2);
}
/*
* 'cupsAdminExportSamba()' - Export a printer to Samba.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
if (!dest || !ppd || !samba_server || !samba_user || !samba_password)
{
- _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+ _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
return (0);
}
if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
return (0);
}
_("Unable to copy Windows 2000 printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to copy CUPS printer driver "
"files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to install Windows 2000 printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to copy Windows 9x printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to install Windows 9x printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to copy 64-bit Windows printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to copy 64-bit CUPS printer driver "
"files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
_("Unable to install Windows 2000 printer "
"driver files (%d)!")), status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
"are installed!")),
sizeof(message));
- _cupsSetError(IPP_NOT_FOUND, message);
+ _cupsSetError(IPP_NOT_FOUND, message, 0);
_cupsLangPrintf(logfile, "%s\n", message);
}
if (have_drivers == 0)
{
- _cupsSetError(IPP_NOT_FOUND, message);
+ _cupsSetError(IPP_NOT_FOUND, message, 0);
unlink(authfile);
_("Unable to set Windows printer driver (%d)!")),
status);
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
* The returned settings should be freed with cupsFreeOptions() when
* you are done with them.
*
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
cupsAdminGetServerSettings(
- http_t *http, /* I - Connection to server */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
int *num_settings, /* O - Number of settings */
cups_option_t **settings) /* O - Settings */
{
int /* O - 1 on success, 0 on failure */
_cupsAdminGetServerSettings(
- http_t *http, /* I - Connection to server */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
int *num_settings, /* O - Number of settings */
cups_option_t **settings) /* O - Settings */
{
* Range check input...
*/
+ if (!http)
+ {
+ /*
+ * See if we are connected to the same server...
+ */
+
+ if (cg->http)
+ {
+ /*
+ * Compare the connection hostname, port, and encryption settings to
+ * the cached defaults; these were initialized the first time we
+ * connected...
+ */
+
+ if (strcmp(cg->http->hostname, cg->server) ||
+ cg->ipp_port != _httpAddrPort(cg->http->hostaddr) ||
+ (cg->http->encryption != cg->encryption &&
+ cg->http->encryption == HTTP_ENCRYPT_NEVER))
+ {
+ /*
+ * Need to close the current connection because something has changed...
+ */
+
+ httpClose(cg->http);
+ cg->http = NULL;
+ }
+ }
+
+ /*
+ * (Re)connect as needed...
+ */
+
+ if (!cg->http)
+ {
+ if ((cg->http = _httpCreate(cupsServer(), ippPort(),
+ cupsEncryption())) == NULL)
+ {
+ if (errno)
+ _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+ else
+ _cupsSetError(IPP_SERVICE_UNAVAILABLE,
+ _("Unable to connect to host."), 1);
+
+ if (num_settings)
+ *num_settings = 0;
+
+ if (settings)
+ *settings = NULL;
+
+ return (0);
+ }
+ }
+
+ http = cg->http;
+ }
+
if (!http || !num_settings || !settings)
{
- _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+ _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
if (num_settings)
*num_settings = 0;
snprintf(message, sizeof(message),
- _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
+ _cupsLangString(cupsLangDefault(), _("Open of %s failed: %s")),
cupsdconf, strerror(errno));
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
}
}
else
if (!value && strncmp(line, "</", 2))
value = line + strlen(line);
- if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
+ if ((!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")) && value)
{
char *port; /* Pointer to port number, if any */
{
in_policy = 0;
}
- else if (!strcasecmp(line, "<Limit") && in_policy)
+ else if (!strcasecmp(line, "<Limit") && in_policy && value)
{
/*
* See if the policy limit is for the Cancel-Job operation...
{
cancel_policy = 0;
}
- else if (!strcasecmp(line, "<Location"))
+ else if (!strcasecmp(line, "<Location") && value)
{
in_admin_location = !strcasecmp(value, "/admin");
in_location = 1;
in_admin_location = 0;
in_location = 0;
}
- else if (!strcasecmp(line, "Allow") &&
+ else if (!strcasecmp(line, "Allow") && value &&
strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
#ifdef AF_LOCAL
&& *value != '/'
else if (!strcasecmp(value, "all"))
remote_any = 1;
}
- else if (line[0] != '<' && !in_location && !in_policy)
+ else if (line[0] != '<' && !in_location && !in_policy &&
+ strcasecmp(line, "Allow") &&
+ strcasecmp(line, "AuthType") &&
+ strcasecmp(line, "Deny") &&
+ strcasecmp(line, "Order") &&
+ strcasecmp(line, "Require") &&
+ strcasecmp(line, "Satisfy"))
cg->cupsd_num_settings = cupsAddOption(line, value,
cg->cupsd_num_settings,
&(cg->cupsd_settings));
/*
* 'cupsAdminSetServerSettings()' - Set settings on the server.
*
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
*/
int /* O - 1 on success, 0 on failure */
cupsAdminSetServerSettings(
- http_t *http, /* I - Connection to server */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
int num_settings, /* I - Number of settings */
cups_option_t *settings) /* I - Settings */
{
int /* O - 1 on success, 0 on failure */
_cupsAdminSetServerSettings(
- http_t *http, /* I - Connection to server */
+ http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
int num_settings, /* I - Number of settings */
cups_option_t *settings) /* I - Settings */
{
* Range check input...
*/
+ if (!http)
+ http = _cupsConnect();
+
if (!http || !num_settings || !settings)
{
- _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+ _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
return (0);
}
* Get the cupsd.conf file...
*/
- if ((status = get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
- &remote)) == HTTP_OK)
+ if (get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
+ &remote) == HTTP_OK)
{
if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
return (0);
}
}
if (remote)
unlink(cupsdconf);
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
return (0);
}
{
cupsFilePuts(temp, "BrowseAllow all\n");
- if (!remotep || !*remotep)
- cupsFilePuts(temp, "BrowseRemoteProtocols "
- CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS "\n");
- else if (remotep)
- cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
+ if (!remotep)
+ remotep = CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS;
+
+ cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
}
else
cupsFilePuts(temp, "BrowseRemoteProtocols\n");
+ cupsd_num_settings = cupsAddOption("BrowseRemoteProtocols", remotep,
+ cupsd_num_settings,
+ &cupsd_settings);
+
if (new_share_printers)
{
cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
- if (!localp || !*localp)
- cupsFilePuts(temp, "BrowseLocalProtocols "
- CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "\n");
- else if (localp)
- cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
+ if (!localp)
+ localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS;
+
+ cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
}
else
cupsFilePuts(temp, "BrowseLocalProtocols\n");
+
+ cupsd_num_settings = cupsAddOption("BrowseLocalProtocols", localp,
+ cupsd_num_settings,
+ &cupsd_settings);
}
else
{
else
{
cupsFilePuts(temp, "# Show general information in error_log.\n");
- cupsFilePuts(temp, "LogLevel info\n");
+ cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n");
}
}
else if (!strcasecmp(line, "<Policy"))
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Require user @OWNER "
- CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+ CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
" </Limit>\n");
}
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Require user @OWNER "
- CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+ CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
" </Limit>\n");
in_cancel_job = 0;
else if ((((in_admin_location || in_conf_location || in_root_location) &&
remote_admin >= 0) ||
(in_root_location && share_printers >= 0)) &&
- (((!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny")) &&
- !strcasecmp(value, "@LOCAL")) ||
+ (!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny") ||
!strcasecmp(line, "Order")))
continue;
else if (in_cancel_job == 2)
else
{
cupsFilePuts(temp, "# Show general information in error_log.\n");
- cupsFilePuts(temp, "LogLevel info\n");
+ cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n");
}
}
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Require user @OWNER "
- CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+ CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
" </Limit>\n");
cupsFilePuts(temp, " <Limit All>\n"
if (logfile)
_cupsLangPuts(logfile, "\n");
- DEBUG_printf(("status=%d\n", status));
+ DEBUG_printf(("9do_samba_command: status=%d", status));
if (WIFEXITED(status))
return (WEXITSTATUS(status));
snprintf(message, sizeof(message),
_cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
name, strerror(errno));
- _cupsSetError(IPP_INTERNAL_ERROR, message);
+ _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
*name = '\0';
{
*name = '\0';
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
invalidate_cupsd_cache(cg);
/*
- * End of "$Id: adminutil.c 6930 2007-09-08 00:28:06Z mike $".
+ * End of "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $".
*/