/*
- * "$Id: printers.c 6539 2007-05-23 15:08:29Z mike $"
+ * "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $"
*
* Printer routines for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
* cupsdRenamePrinter() - Rename a printer.
* cupsdSaveAllPrinters() - Save all printer definitions to the
* printers.conf file.
+ * cupsdSetAuthInfoRequired() - Set the required authentication info.
* cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
* file.
* cupsdSetPrinterReasons() - Set/update the reasons strings.
#include <cups/dir.h>
-/*
- * Currently Bonjour printers that are shared by CUPS servers are added
- * manually by the user on Mac OS X systems. While these printers *are*
- * remote queues, the current print dialog will not show them if they
- * (correctly) have the CUPS_PRINTER_REMOTE bit set. This may change
- * in future releases, however the code to do this is currently disabled.
- *
- * Define BONJOUR_IS_REMOTE to 1 to get the correct behavior...
- */
-
-#define BONJOUR_IS_REMOTE 0
-
-
/*
* Local functions...
*/
cups_array_t *notifiers; /* Notifier array */
char filename[1024], /* Filename */
*notifier; /* Current notifier */
+ cupsd_policy_t *p; /* Current policy */
static const int nups[] = /* number-up-supported values */
{ 1, 2, 4, 6, 9, 16 };
static const int orients[4] =/* orientation-requested-supported values */
CUPS_GET_PPDS,
CUPS_MOVE_JOB,
CUPS_AUTHENTICATE_JOB,
+ CUPS_GET_PPD,
+ CUPS_GET_DOCUMENT,
IPP_RESTART_JOB
};
static const char * const charsets[] =/* charset-supported values */
/* printer-op-policy-supported */
attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-op-policy-supported", NumPolicies, NULL, NULL);
- for (i = 0; i < NumPolicies; i ++)
- attr->values[i].string.text = _cupsStrAlloc(Policies[i]->name);
+ "printer-op-policy-supported", cupsArrayCount(Policies),
+ NULL, NULL);
+ for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
+ p;
+ i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
+ attr->values[i].string.text = _cupsStrAlloc(p->name);
+
+ ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers",
+ BrowseLocalProtocols != 0 && Browsing);
}
* Skip remote destinations and printer classes...
*/
- if ((printer->type & CUPS_PRINTER_REMOTE) ||
+ if ((printer->type & CUPS_PRINTER_DISCOVERED) ||
(printer->type & CUPS_PRINTER_CLASS) ||
(printer->type & CUPS_PRINTER_IMPLICIT))
continue;
p->auth_info_required[p->num_auth_info_required] = "negotiate";
p->num_auth_info_required ++;
-
- return (1);
}
else if ((end - values) == 6 && !strncmp(values, "domain", 6))
{
}
else
return (0);
+
+ values = (*end) ? end + 1 : end;
}
if (p->num_auth_info_required == 0)
p->num_auth_info_required = 1;
}
+ /*
+ * Update the printer-type value as needed...
+ */
+
+ if (p->num_auth_info_required > 1 ||
+ strcmp(p->auth_info_required[0], "none"))
+ p->type |= CUPS_PRINTER_AUTHENTICATED;
+ else
+ p->type &= ~CUPS_PRINTER_AUTHENTICATED;
+
return (1);
}
if (!attr || attr->num_values > 4)
return (0);
+ /*
+ * Update the printer-type value as needed...
+ */
+
+ if (attr->num_values > 1 ||
+ strcmp(attr->values[0].string.text, "none"))
+ p->type |= CUPS_PRINTER_AUTHENTICATED;
+ else
+ p->type &= ~CUPS_PRINTER_AUTHENTICATED;
+
for (i = 0; i < attr->num_values; i ++)
{
if (!strcmp(attr->values[i].string.text, "none"))
char uri[HTTP_MAX_URI]; /* URI for printer */
char resource[HTTP_MAX_URI]; /* Resource portion of URI */
char filename[1024]; /* Name of PPD file */
+ int num_air; /* Number of auth-info-required values */
+ const char * const *air; /* auth-info-required values */
int num_media; /* Number of media options */
cupsd_location_t *auth; /* Pointer to authentication element */
const char *auth_supported; /* Authentication supported */
- cups_ptype_t printer_type; /* Printer type data */
ppd_file_t *ppd; /* PPD file data */
ppd_option_t *input_slot, /* InputSlot options */
*media_type, /* MediaType options */
"two-sided-long-edge",
"two-sided-short-edge"
};
+ static const char * const air_userpass[] =
+ { /* Basic/Digest authentication */
+ "username",
+ "password"
+ };
+ static const char * const air_negotiate[] =
+ { /* Kerberos authentication */
+ "negotiate"
+ };
+ static const char * const air_none[] =
+ { /* No authentication */
+ "none"
+ };
DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
*/
auth_supported = "requesting-user-name";
- if (!(p->type & CUPS_PRINTER_REMOTE))
+ num_air = 1;
+ air = air_none;
+
+ if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
+ {
+ num_air = p->num_auth_info_required;
+ air = p->auth_info_required;
+
+ if (!strcmp(air[0], "username"))
+ auth_supported = "basic";
+ else
+ auth_supported = "negotiate";
+ }
+ else if (!(p->type & CUPS_PRINTER_DISCOVERED))
{
if (p->type & CUPS_PRINTER_CLASS)
snprintf(resource, sizeof(resource), "/classes/%s", p->name);
if (auth->type == AUTH_BASIC || auth->type == AUTH_BASICDIGEST)
{
auth_supported = "basic";
- cupsdSetAuthInfoRequired(p, "username,password", NULL);
+ num_air = 2;
+ air = air_userpass;
}
else if (auth->type == AUTH_DIGEST)
{
auth_supported = "digest";
- cupsdSetAuthInfoRequired(p, "username,password", NULL);
+ num_air = 2;
+ air = air_userpass;
}
#ifdef HAVE_GSSAPI
else if (auth->type == AUTH_NEGOTIATE)
{
auth_supported = "negotiate";
- cupsdSetAuthInfoRequired(p, "negotiate", NULL);
+ num_air = 1;
+ air = air_negotiate;
}
#endif /* HAVE_GSSAPI */
else
p->type &= ~CUPS_PRINTER_AUTHENTICATED;
}
+ else if (p->type & CUPS_PRINTER_AUTHENTICATED)
+ {
+ num_air = 2;
+ air = air_userpass;
+ }
/*
* Create the required IPP attributes for a printer...
"job-k-limit", p->k_limit);
ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
"job-page-limit", p->page_limit);
- if (p->num_auth_info_required)
- ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "auth-info-required", p->num_auth_info_required,
- NULL, p->auth_info_required);
- else
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "auth-info-required", NULL, "none");
+ ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "auth-info-required", num_air, NULL, air);
- if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_REMOTE))
+ if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_DISCOVERED))
{
/*
* Setup the job-sheets-default attribute...
}
}
- printer_type = p->type;
-
p->raw = 0;
p->remote = 0;
- if (p->type & CUPS_PRINTER_REMOTE)
+ if (p->type & CUPS_PRINTER_DISCOVERED)
{
/*
* Tell the client this is a remote printer of some type...
* Show current and available port monitors for this printer...
*/
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "port-monitor",
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
NULL, p->port_monitor ? p->port_monitor : "none");
-
for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
ppdattr;
i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
i ++;
}
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
"port-monitor-supported", i, NULL, NULL);
attr->values[0].string.text = _cupsStrAlloc("none");
cupsdSetString(&p->product, ppd->product);
#endif /* HAVE_DNSSD */
-#if BONJOUR_IS_REMOTE
- ppdattr = ppdFindAttr(ppd, "APRemoteQueueID", NULL);
-#endif /* BONJOUR_IS_REMOTE */
+ if (ppdFindAttr(ppd, "APRemoteQueueID", NULL))
+ p->type |= CUPS_PRINTER_REMOTE;
/*
* Close the PPD and set the type...
*/
ppdClose(ppd);
-
- printer_type = p->type;
-
-#if BONJOUR_IS_REMOTE
- if (ppdattr)
- {
- /*
- * This is a shared Bonjour printer...
- */
-
- printer_type |= CUPS_PRINTER_REMOTE;
- }
-#endif /* BONJOUR_IS_REMOTE */
}
else if (!access(filename, 0))
{
* Tell the client this is really a hard-wired remote printer.
*/
- printer_type |= CUPS_PRINTER_REMOTE;
+ p->type |= CUPS_PRINTER_REMOTE;
/*
* Point the printer-uri-supported attribute to the
}
/*
- * Save the local printer type value, which may have the CUPS_PRINTER_REMOTE
- * bit set. We use this value when sending the printer-type attribute to
- * clients so they know whether the printer is really remote. Doing it
- * this way prevents the browsing code from timing out hardwired remote
- * printers...
- */
-
- p->external_type = printer_type;
-
- /*
- * Copy the printer options into a browse attributes string we can re-use.
+ * Force sharing off for remote queues...
*/
- if (!(printer_type & CUPS_PRINTER_REMOTE))
+ if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
+ p->shared = 0;
+ else
{
+ /*
+ * Copy the printer options into a browse attributes string we can re-use.
+ */
+
const char *valptr; /* Pointer into value */
char *attrptr; /* Pointer into attribute string */
p->num_reasons = 0;
}
+ if (!strcmp(s, "none"))
+ return;
+
/*
* Loop through all of the reasons...
*/
* Can't set status of remote printers...
*/
- if (p->type & CUPS_PRINTER_REMOTE)
+ if (p->type & CUPS_PRINTER_DISCOVERED)
return;
/*
if (old_state != s)
{
- cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED, p, NULL,
+ cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED :
+ CUPSD_EVENT_PRINTER_STATE_CHANGED, p, NULL,
"%s \"%s\" state changed.",
(p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
p->name);
* Remove remote printers if we are no longer browsing...
*/
- if (!Browsing && (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_REMOTE)))
+ if (!Browsing &&
+ (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_DISCOVERED)))
{
if (p->type & CUPS_PRINTER_IMPLICIT)
cupsArrayRemove(ImplicitPrinters, p);
* Update printer attributes as needed...
*/
- if (!(p->type & CUPS_PRINTER_REMOTE))
+ if (!(p->type & CUPS_PRINTER_DISCOVERED))
cupsdSetPrinterAttrs(p);
}
}
if (dtype)
*dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
- CUPS_PRINTER_REMOTE);
+ CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
return (p->name);
}
if (dtype)
*dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
- CUPS_PRINTER_REMOTE);
+ CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
return (p->name);
}
* data has come from...
*/
- cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
+ cupsFilePuts(fp,
+ "# This file was automatically generated by cupsd(8) from the\n");
cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
ServerRoot);
cupsFilePuts(fp, "# will be lost.\n");
if (DefaultPrinter)
cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
- DefaultPrinter->info, ServerName, DefaultPrinter->name);
+ DefaultPrinter->info, ServerName,
+ DefaultPrinter->name);
for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
p;
p = (cupsd_printer_t *)cupsArrayNext(Printers))
if (p != DefaultPrinter)
cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
- ServerName, p->name);
+ ServerName, p->name);
break;
case PRINTCAP_SOLARIS:
p;
p = (cupsd_printer_t *)cupsArrayNext(Printers))
cupsFilePrintf(fp, "%s:\\\n"
- "\t:bsdaddr=%s,%s:\\\n"
- "\t:description=%s:\n",
- p->name, ServerName, p->name, p->info ? p->info : "");
+ "\t:bsdaddr=%s,%s:\\\n"
+ "\t:description=%s:\n",
+ p->name, ServerName, p->name,
+ p->info ? p->info : "");
break;
}
}
"number-up-default", 1);
if (!cupsGetOption("orientation-requested", p->num_options, p->options))
- ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
- "orientation-requested-default", IPP_PORTRAIT);
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
+ "orientation-requested-default", NULL, NULL);
if (!cupsGetOption("notify-lease-duration", p->num_options, p->options))
ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
/*
- * End of "$Id: printers.c 6539 2007-05-23 15:08:29Z mike $".
+ * End of "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $".
*/