/*
- * "$Id: cups-lpd.c,v 1.31 2002/01/02 17:59:15 mike Exp $"
+ * "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $"
*
* Line Printer Daemon interface for the Common UNIX Printing System (CUPS).
*
int hostlen; /* Size of client address */
unsigned hostip; /* (32-bit) IP address */
struct sockaddr_in hostaddr; /* Address of client */
- struct hostent *hostname; /* Name of client */
+ struct hostent *hostent; /* Host entry of client */
+ char hostname[256]; /* Hostname of client */
/*
hostlen = sizeof(hostaddr);
if (getpeername(0, (struct sockaddr *)&hostaddr, &hostlen))
+ {
syslog(LOG_WARNING, "Unable to get client address - %s", strerror(errno));
+ strcpy(hostname, "unknown");
+ }
else
{
hostip = ntohl(hostaddr.sin_addr.s_addr);
- hostname = gethostbyaddr((void *)&(hostaddr.sin_addr), hostlen, AF_INET);
+ hostent = gethostbyaddr((void *)&(hostaddr.sin_addr), hostlen, AF_INET);
+
+ if (hostent)
+ {
+ strncpy(hostname, hostent->h_name, sizeof(hostname) - 1);
+ hostname[sizeof(hostname) - 1] = '\0';
+ }
+ else
+ {
+ snprintf(hostname, sizeof(hostname), "%d.%d.%d.%d",
+ (hostip >> 24) & 255, (hostip >> 16) & 255,
+ (hostip >> 8) & 255, hostip & 255);
+ }
syslog(LOG_INFO, "Connection from %s (%d.%d.%d.%d)",
- hostname ? hostname->h_name : "unknown",
- (hostip >> 24) & 255, (hostip >> 16) & 255,
+ hostname, (hostip >> 24) & 255, (hostip >> 16) & 255,
(hostip >> 8) & 255, hostip & 255);
}
num_defaults = 0;
defaults = NULL;
+ num_defaults = cupsAddOption("job-originating-host-name", hostname,
+ num_defaults, &defaults);
+
for (i = 1; i < argc; i ++)
if (argv[i][0] == '-')
{
/*
- * End of "$Id: cups-lpd.c,v 1.31 2002/01/02 17:59:15 mike Exp $".
+ * End of "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $".
*/
/*
- * "$Id: ipp.c,v 1.156 2002/02/13 17:35:10 mike Exp $"
+ * "$Id: ipp.c,v 1.157 2002/04/29 17:25:26 mike Exp $"
*
* IPP routines for the Common UNIX Printing System (CUPS) scheduler.
*
attr->name = strdup("job-originating-user-name");
}
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-host-name", NULL, con->http.hostname);
+ if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+ IPP_TAG_ZERO)) != NULL)
+ {
+ /*
+ * Request contains a job-originating-host-name attribute; validate it...
+ */
+
+ if (attr->value_tag != IPP_TAG_NAME ||
+ attr->num_values != 1 ||
+ strcmp(con->http.hostname, "localhost") != 0)
+ {
+ /*
+ * Can't override the value if we aren't connected via localhost.
+ * Also, we can only have 1 value and it must be a name value.
+ */
+
+ int i; /* Looping var */
+
+ switch (attr->value_tag)
+ {
+ case IPP_TAG_STRING :
+ case IPP_TAG_TEXTLANG :
+ case IPP_TAG_NAMELANG :
+ case IPP_TAG_TEXT :
+ case IPP_TAG_NAME :
+ case IPP_TAG_KEYWORD :
+ case IPP_TAG_URI :
+ case IPP_TAG_URISCHEME :
+ case IPP_TAG_CHARSET :
+ case IPP_TAG_LANGUAGE :
+ case IPP_TAG_MIMETYPE :
+ /*
+ * Free old strings...
+ */
+
+ for (i = 0; i < attr->num_values; i ++)
+ {
+ free(attr->values[i].string.text);
+ attr->values[i].string.text = NULL;
+ if (attr->values[i].string.charset)
+ {
+ free(attr->values[i].string.charset);
+ attr->values[i].string.charset = NULL;
+ }
+ }
+
+ default :
+ break;
+ }
+
+ /*
+ * Use the default connection hostname instead...
+ */
+
+ attr->value_tag = IPP_TAG_NAME;
+ attr->num_values = 1;
+ attr->values[0].string.text = strdup(con->http.hostname);
+ }
+ }
+ else
+ {
+ /*
+ * No job-originating-host-name attribute, so use the hostname from
+ * the connection...
+ */
+
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
+ "job-originating-host-name", NULL, con->http.hostname);
+ }
+
ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
time(NULL));
attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
* Add remaining job attributes...
*/
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-host-name", NULL, con->http.hostname);
+ if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+ IPP_TAG_ZERO)) != NULL)
+ {
+ /*
+ * Request contains a job-originating-host-name attribute; validate it...
+ */
+
+ if (attr->value_tag != IPP_TAG_NAME ||
+ attr->num_values != 1 ||
+ strcmp(con->http.hostname, "localhost") != 0)
+ {
+ /*
+ * Can't override the value if we aren't connected via localhost.
+ * Also, we can only have 1 value and it must be a name value.
+ */
+
+ int i; /* Looping var */
+
+ switch (attr->value_tag)
+ {
+ case IPP_TAG_STRING :
+ case IPP_TAG_TEXTLANG :
+ case IPP_TAG_NAMELANG :
+ case IPP_TAG_TEXT :
+ case IPP_TAG_NAME :
+ case IPP_TAG_KEYWORD :
+ case IPP_TAG_URI :
+ case IPP_TAG_URISCHEME :
+ case IPP_TAG_CHARSET :
+ case IPP_TAG_LANGUAGE :
+ case IPP_TAG_MIMETYPE :
+ /*
+ * Free old strings...
+ */
+
+ for (i = 0; i < attr->num_values; i ++)
+ {
+ free(attr->values[i].string.text);
+ attr->values[i].string.text = NULL;
+ if (attr->values[i].string.charset)
+ {
+ free(attr->values[i].string.charset);
+ attr->values[i].string.charset = NULL;
+ }
+ }
+
+ default :
+ break;
+ }
+
+ /*
+ * Use the default connection hostname instead...
+ */
+
+ attr->value_tag = IPP_TAG_NAME;
+ attr->num_values = 1;
+ attr->values[0].string.text = strdup(con->http.hostname);
+ }
+ }
+ else
+ {
+ /*
+ * No job-originating-host-name attribute, so use the hostname from
+ * the connection...
+ */
+
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
+ "job-originating-host-name", NULL, con->http.hostname);
+ }
+
ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
"job-state", IPP_JOB_PENDING);
/*
- * End of "$Id: ipp.c,v 1.156 2002/02/13 17:35:10 mike Exp $".
+ * End of "$Id: ipp.c,v 1.157 2002/04/29 17:25:26 mike Exp $".
*/