*
* IPP routines for the Common UNIX Printing System (CUPS) scheduler.
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* This file contains Kerberos support code, copyright 2006 by
con->http.fd, con->response->request.status.status_code,
ippErrorString(con->response->request.status.status_code));
- if (cupsdSendHeader(con, HTTP_OK, "application/ipp", AUTH_NONE))
+ if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
{
#ifdef CUPSD_USE_CHUNKING
/*
* 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
*/
-void
+int /* O - 0 on success, -1 on error */
cupsdTimeoutJob(cupsd_job_t *job) /* I - Job to timeout */
{
cupsd_printer_t *printer; /* Destination printer or class */
cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Adding end banner page \"%s\".",
job->id, attr->values[1].string.text);
- kbytes = copy_banner(NULL, job, attr->values[1].string.text);
+ if ((kbytes = copy_banner(NULL, job, attr->values[1].string.text)) < 0)
+ return (-1);
cupsdUpdateQuota(printer, job->username, 0, kbytes);
}
+
+ return (0);
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
con, con->http.fd, printer, printer->name,
- filetype, filetype->super, filetype->type);
+ filetype, filetype ? filetype->super : "none",
+ filetype ? filetype->type : "none");
/*
* Check remote printing to non-shared printer...
*/
if (auth_info)
- {
- if (job->attrs->prev)
- job->attrs->prev->next = auth_info->next;
- else
- job->attrs->attrs = auth_info->next;
-
- if (job->attrs->last == auth_info)
- job->attrs->last = job->attrs->prev;
-
- _ippFreeAttr(auth_info);
- }
+ ippDeleteAttribute(job->attrs, auth_info);
}
if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
"[Job %d] Adding start banner page \"%s\".",
job->id, attr->values[0].string.text);
- kbytes = copy_banner(con, job, attr->values[0].string.text);
+ if ((kbytes = copy_banner(con, job, attr->values[0].string.text)) < 0)
+ return (NULL);
cupsdUpdateQuota(printer, job->username, 0, kbytes);
}
need_restart_job = 1;
supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
- IPP_TAG_KEYWORD);
- for (i = 0; i < supported->num_values; i ++)
- if (!strcmp(supported->values[i].string.text,
- attr->values[0].string.text))
- break;
+ IPP_TAG_NAME);
+ if (supported)
+ {
+ for (i = 0; i < supported->num_values; i ++)
+ if (!strcmp(supported->values[i].string.text,
+ attr->values[0].string.text))
+ break;
+ }
- if (i >= supported->num_values)
+ if (!supported || i >= supported->num_values)
{
send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
attr->values[0].string.text);
cupsd_job_t *job; /* Job information */
cups_ptype_t dtype; /* Destination type (printer/class) */
cupsd_printer_t *printer; /* Printer data */
+ int purge; /* Purge the job? */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
jobid = atoi(resource + 6);
}
+ /*
+ * Look for the "purge-job" attribute...
+ */
+
+ if ((attr = ippFindAttribute(con->request, "purge-job",
+ IPP_TAG_BOOLEAN)) != NULL)
+ purge = attr->values[0].boolean;
+ else
+ purge = 0;
+
/*
* See if the job exists...
*/
* we can't cancel...
*/
- if (job->state_value >= IPP_JOB_CANCELED)
+ if (job->state_value >= IPP_JOB_CANCELED && !purge)
{
switch (job->state_value)
{
* Cancel the job and return...
*/
- cupsdCancelJob(job, 0, IPP_JOB_CANCELED);
+ cupsdCancelJob(job, purge, IPP_JOB_CANCELED);
cupsdCheckJobs();
- cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Canceled by \"%s\".", jobid,
- username);
+ if (purge)
+ cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Purged by \"%s\".", jobid,
+ username);
+ else
+ cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Canceled by \"%s\".", jobid,
+ username);
con->response->request.status.status_code = IPP_OK;
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])",
con, con->http.fd, p, p->name);
- /*
- * Check input...
- */
-
- if (!con || !p)
- return (0);
-
/*
* Figure out who is printing...
*/
*/
if (add_file(con, job, banner->filetype, 0))
- return (0);
+ return (-1);
snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
job->num_files);
"copy_model: Running \"cups-driverd cat %s\"...", from);
if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
- -1, -1, 0, &temppid))
+ -1, -1, 0, DefaultProfile, &temppid))
{
close(tempfd);
unlink(tempfile);
+
return (-1);
}
printer->recoverable);
#endif /* __APPLE__ */
+ if (!ra || cupsArrayFind(ra, "marker-change-time"))
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "marker-change-time", printer->marker_time);
+
if (printer->alert && (!ra || cupsArrayFind(ra, "printer-alert")))
ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING,
"printer-alert", NULL, printer->alert);
ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
ippTimeToDate(curtime));
+#ifdef HAVE_DNSSD
+ if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
+ {
+ if (printer->reg_name)
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "printer-dns-sd-name", NULL, printer->reg_name);
+ else
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
+ "printer-dns-sd-name", 0);
+ }
+#endif /* HAVE_DNSSD */
+
if (!ra || cupsArrayFind(ra, "printer-error-policy"))
ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
"printer-error-policy", NULL, printer->error_policy);
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: job->id = %d", job->id);
+ if (!job->dest || !job->username)
+ cupsdLoadJob(job);
+
+ if (!job->dest || !job->username)
+ continue;
+
if ((dest && strcmp(job->dest, dest)) &&
(!job->printer || !dest || strcmp(job->printer->name, dest)))
continue;
return;
}
- /*
- * Check policy...
- */
-
- if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con,
- NULL)) != HTTP_OK)
- {
- send_http_error(con, status, dprinter);
- return;
- }
-
/*
* See if we have a job URI or a printer URI...
*/
}
}
+ /*
+ * Check the policy of the destination printer...
+ */
+
+ if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con,
+ job ? job->username : NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status, dprinter);
+ return;
+ }
+
/*
* Now move the job or jobs...
*/
* See if we need to add the ending sheet...
*/
- cupsdTimeoutJob(job);
+ if (cupsdTimeoutJob(job))
+ return;
/*
* Log and save the job...
cupsFilePrintf(fp, "%s\n", line);
if (!strcmp(dest->auth_info_required[i], "username"))
- cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s",
+ cupsdSetStringf(&job->auth_username, "CUPSD_AUTH_USERNAME=%s",
auth_info->values[i].string.text);
else if (!strcmp(dest->auth_info_required[i], "domain"))
- cupsdSetStringf(&job->auth_domain, "AUTH_DOMAIN=%s",
+ cupsdSetStringf(&job->auth_domain, "CUPSD_AUTH_DOMAIN=%s",
auth_info->values[i].string.text);
else if (!strcmp(dest->auth_info_required[i], "password"))
- cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s",
+ cupsdSetStringf(&job->auth_password, "CUPSD_AUTH_PASSWORD=%s",
auth_info->values[i].string.text);
}
}
httpEncode64_2(line, sizeof(line), con->username, strlen(con->username));
cupsFilePrintf(fp, "%s\n", line);
- cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s", con->username);
+ cupsdSetStringf(&job->auth_username, "CUPSD_AUTH_USERNAME=%s", con->username);
cupsdClearString(&job->auth_domain);
/*
httpEncode64_2(line, sizeof(line), con->password, strlen(con->password));
cupsFilePrintf(fp, "%s\n", line);
- cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s", con->password);
+ cupsdSetStringf(&job->auth_password, "CUPSD_AUTH_PASSWORD=%s", con->password);
}
/*
krb5_error_code error; /* Kerberos error code */
OM_uint32 major_status, /* Major status code */
minor_status; /* Minor status code */
-# ifdef HAVE_KRB5_CC_NEW_UNIQUE
krb5_principal principal; /* Kerberos principal */
-# endif /* HAVE_KRB5_CC_NEW_UNIQUE */
# ifdef __APPLE__
if ((error = krb5_cc_new_unique(KerberosContext, "FILE", NULL,
&(job->ccache))) != 0)
# else /* HAVE_HEIMDAL */
- if ((error = krb5_cc_gen_new(krb_context, &krb5_fcc_ops,
+ if ((error = krb5_cc_gen_new(KerberosContext, &krb5_fcc_ops,
&(job->ccache))) != 0)
# endif /* HAVE_KRB5_CC_NEW_UNIQUE */
{
* See if we need to add the ending sheet...
*/
- cupsdTimeoutJob(job);
+ if (cupsdTimeoutJob(job))
+ return;
if (job->state_value == IPP_JOB_STOPPED)
{
if (status == HTTP_UNAUTHORIZED &&
printer && printer->num_auth_info_required > 0 &&
!strcmp(printer->auth_info_required[0], "negotiate"))
- cupsdSendError(con, status, AUTH_NEGOTIATE);
+ cupsdSendError(con, status, CUPSD_AUTH_NEGOTIATE);
else if (printer)
{
char resource[HTTP_MAX_URI]; /* Resource portion of URI */
snprintf(resource, sizeof(resource), "/printers/%s", printer->name);
if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
- auth->type == AUTH_NONE)
+ auth->type == CUPSD_AUTH_NONE)
auth = cupsdFindPolicyOp(printer->op_policy_ptr, IPP_PRINT_JOB);
- cupsdSendError(con, status, auth ? auth->type : AUTH_NONE);
+ cupsdSendError(con, status, auth ? auth->type : CUPSD_AUTH_NONE);
}
else
- cupsdSendError(con, status, AUTH_NONE);
+ cupsdSendError(con, status, CUPSD_AUTH_NONE);
ippDelete(con->response);
con->response = NULL;
else if (con->response->request.status.status_code == IPP_OK)
{
cupsdSetJobPriority(job, attr->values[0].integer);
- event |= CUPSD_EVENT_JOB_CONFIG_CHANGED;
+ event |= CUPSD_EVENT_JOB_CONFIG_CHANGED |
+ CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED;
}
}
else if (!strcmp(attr->name, "job-state"))
* Send events as needed...
*/
+ if (event & CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED)
+ cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED, job->printer, job,
+ "Job priority changed by user.");
+
if (event & CUPSD_EVENT_JOB_STATE)
cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job,
job->state_value == IPP_JOB_HELD ?
{
int i; /* Looping var */
struct passwd *pw; /* User password data */
+ char baseuser[256], /* Base username */
+ *baseptr; /* Pointer to "@" in base username */
if (p->num_users == 0)
if (!strcmp(username, "root"))
return (1);
+ if (strchr(username, '@'))
+ {
+ /*
+ * Strip @REALM for username check...
+ */
+
+ strlcpy(baseuser, username, sizeof(baseuser));
+
+ if ((baseptr = strchr(baseuser, '@')) != NULL)
+ *baseptr = '\0';
+
+ username = baseuser;
+ }
+
pw = getpwnam(username);
endpwent();
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
"userlen=%d)",
- job ? job->id : 0, con->http.fd, owner ? owner : "(null)",
- username, userlen);
+ job->id, con ? con->http.fd : 0,
+ owner ? owner : "(null)", username, userlen);
/*
* Validate input...