/*
- * "$Id: cups-lpd.c 7221 2008-01-16 22:20:08Z mike $"
+ * "$Id: cups-lpd.c 11623 2014-02-19 20:18:10Z msweet $"
*
- * Line Printer Daemon interface for the Common UNIX Printing System (CUPS).
+ * Line Printer Daemon interface for CUPS.
*
- * Copyright 2007-2008 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products, all rights reserved.
*
- * These coded instructions, statements, and computer programs are the
- * 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:
- *
- * main() - Process an incoming LPD request...
- * create_job() - Create a new print job.
- * get_printer() - Get the named printer and its options.
- * print_file() - Add a file to the current job.
- * recv_print_job() - Receive a print job from the client.
- * remove_jobs() - Cancel one or more jobs.
- * send_state() - Send the queue state.
- * smart_gets() - Get a line of text, removing the trailing CR and/or LF.
+ * These coded instructions, statements, and computer programs are the
+ * 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/".
*/
/*
* Include necessary headers...
*/
-#include <cups/http-private.h>
-#include <cups/cups.h>
-#include <cups/string.h>
-#include <cups/language.h>
-#include <stdlib.h>
-#include <errno.h>
+#include <cups/cups-private.h>
#include <syslog.h>
-#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
-
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
# include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
-#ifdef HAVE_COREFOUNDATION_H
-# include <CoreFoundation/CoreFoundation.h>
-#endif /* HAVE_COREFOUNDATION_H */
-#ifdef HAVE_CFPRIV_H
-# include <CoreFoundation/CFPriv.h>
-#endif /* HAVE_CFPRIV_H */
-
/*
* LPD "mini-daemon" for CUPS. This program must be used in conjunction
*/
static int create_job(http_t *http, const char *dest, const char *title,
- const char *user, int num_options,
- cups_option_t *options);
+ const char *docname, const char *user,
+ int num_options, cups_option_t *options);
static int get_printer(http_t *http, const char *name, char *dest,
int destsize, cups_option_t **options,
int *accepting, int *shared, ipp_pstate_t *state);
{
switch (argv[i][1])
{
+ case 'h' : /* -h hostname[:port] */
+ if (argv[i][2])
+ cupsSetServer(argv[i] + 2);
+ else
+ {
+ i ++;
+ if (i < argc)
+ cupsSetServer(argv[i]);
+ else
+ syslog(LOG_WARNING, "Expected hostname string after -h option!");
+ }
+ break;
+
case 'o' : /* Option */
if (argv[i][2])
num_defaults = cupsParseOptions(argv[i] + 2, num_defaults,
if (getpeername(0, (struct sockaddr *)&hostaddr, &hostlen))
{
syslog(LOG_WARNING, "Unable to get client address - %s", strerror(errno));
- strcpy(hostname, "unknown");
+ strlcpy(hostname, "unknown", sizeof(hostname));
}
else
{
list = NULL;
else
{
- for (list = dest + 1; *list && !isspace(*list & 255); list ++);
+ for (list = dest; *list && !isspace(*list & 255); list ++);
while (isspace(*list & 255))
*list++ = '\0';
break;
case 0x05 : /* Remove jobs */
- /*
- * Grab the agent and skip to the list of users and/or jobs.
- */
+ if (list)
+ {
+ /*
+ * Grab the agent and skip to the list of users and/or jobs.
+ */
- agent = list;
+ agent = list;
- for (; *list && !isspace(*list & 255); list ++);
- while (isspace(*list & 255))
- *list++ = '\0';
+ for (; *list && !isspace(*list & 255); list ++);
+ while (isspace(*list & 255))
+ *list++ = '\0';
- syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
+ syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
- status = remove_jobs(dest, agent, list);
+ status = remove_jobs(dest, agent, list);
+ }
+ else
+ status = 1;
putchar(status);
break;
create_job(http_t *http, /* I - HTTP connection */
const char *dest, /* I - Destination name */
const char *title, /* I - job-name */
+ const char *docname, /* I - Name of job file */
const char *user, /* I - requesting-user-name */
int num_options, /* I - Number of options for job */
cups_option_t *options) /* I - Options for job */
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, user);
- if (title)
+ if (title[0])
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
NULL, title);
+ if (docname[0])
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "document-name",
+ NULL, docname);
+
cupsEncodeOptions(request, num_options, options);
/*
}
if (info_attr && name_attr &&
- !strcasecmp(name, info_attr->values[0].string.text))
+ !_cups_strcasecmp(name, info_attr->values[0].string.text))
{
/*
* Found a match, use this one!
ippDelete(response);
}
- /*
- * Override shared value for LPD using system-specific APIs...
- */
-
-#ifdef HAVE_CFPRIV_H /* MacOS X */
- if (shared && *shared)
- {
- CFURLRef prefsurl; /* URL for preferences file */
- CFDataRef xmldata; /* XML data from preferences file */
- CFPropertyListRef plist; /* Property list from XML data */
- CFStringRef queueid; /* CFString of destination name */
- CFArrayRef lprqarray; /* Array of shared "LPR" printers */
- CFBooleanRef serverflag; /* State of the print service */
- static const char printerprefsfile[] =
- "/Library/Preferences/com.apple.printservice.plist";
- /* Preferences file */
-
-
- /*
- * See if we are running on MacOS X Server...
- */
-
- CFDictionaryRef versdict = _CFCopyServerVersionDictionary();
-
- if (versdict)
- {
- /*
- * Yes, use the LPR sharing preference...
- */
-
- CFRelease(versdict);
-
- *shared = 0;
-
- prefsurl = CFURLCreateFromFileSystemRepresentation(
- kCFAllocatorDefault,
- (const UInt8 *)printerprefsfile,
- (CFIndex)strlen(printerprefsfile),
- false);
- if (prefsurl)
- {
- if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
- prefsurl, &xmldata, NULL,
- NULL, NULL))
- {
- plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmldata,
- kCFPropertyListImmutable,
- NULL);
- if (plist)
- {
- serverflag = (CFBooleanRef)CFDictionaryGetValue(
- (CFDictionaryRef)plist,
- CFSTR("serviceState"));
-
- if (serverflag && CFBooleanGetValue(serverflag))
- {
- lprqarray = (CFArrayRef)CFDictionaryGetValue(
- (CFDictionaryRef)plist,
- CFSTR("lprSharedQueues"));
-
- if (lprqarray)
- {
- queueid = CFStringCreateWithCString(CFAllocatorGetDefault(),
- dest,
- kCFStringEncodingUTF8);
-
- if (queueid)
- {
- *shared = CFArrayContainsValue(lprqarray,
- CFRangeMake(0,
- CFArrayGetCount(lprqarray)),
- queueid);
-
- CFRelease(queueid);
- }
- }
- }
-
- CFRelease(plist);
- }
-
- CFRelease(xmldata);
- }
-
- CFRelease(prefsurl);
- }
-
- if (!shared)
- syslog(LOG_ERR, "Warning - Print Service sharing disabled for LPD "
- "on queue: %s", name);
- }
- }
-#endif /* HAVE_CFPRIV_H */
-
/*
* Next look for the printer in the lpoptions file...
*/
* Make sure we have "Dest name options" or "Default name options"...
*/
- if ((strcasecmp(line, "Dest") && strcasecmp(line, "Default")) || !value)
+ if ((_cups_strcasecmp(line, "Dest") && _cups_strcasecmp(line, "Default")) || !value)
continue;
/*
* the loop - we're done!
*/
- if (!strcasecmp(value, name))
+ if (!_cups_strcasecmp(value, name))
{
num_options = cupsParseOptions(optptr, num_options, options);
break;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
"document-format", NULL, format);
- if (last)
- ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
+ ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", last);
/*
* Do the request...
int fd; /* Temporary file */
FILE *fp; /* File pointer */
char filename[1024]; /* Temporary filename */
- int bytes; /* Bytes received */
+ ssize_t bytes; /* Bytes received */
+ size_t total; /* Total bytes */
char line[256], /* Line from file/stdin */
command, /* Command from line */
*count, /* Number of bytes */
break;
}
- strcpy(filename, control);
+ strlcpy(filename, control, sizeof(filename));
}
break;
break;
}
- strcpy(filename, temp[num_data]);
+ strlcpy(filename, temp[num_data], sizeof(filename));
num_data ++;
break;
* Copy the data or control file from the client...
*/
- for (i = atoi(count); i > 0; i -= bytes)
+ for (total = (size_t)strtoll(count, NULL, 10); total > 0; total -= (size_t)bytes)
{
- if (i > sizeof(line))
- bytes = sizeof(line);
+ if (total > sizeof(line))
+ bytes = (ssize_t)sizeof(line);
else
- bytes = i;
+ bytes = (ssize_t)total;
- if ((bytes = fread(line, 1, bytes, stdin)) > 0)
- bytes = write(fd, line, bytes);
+ if ((bytes = (ssize_t)fread(line, 1, (size_t)bytes, stdin)) > 0)
+ bytes = write(fd, line, (size_t)bytes);
if (bytes < 1)
{
* Grab the job information...
*/
- title[0] = '\0';
- user[0] = '\0';
- doccount = 0;
+ title[0] = '\0';
+ user[0] = '\0';
+ docname[0] = '\0';
+ doccount = 0;
while (smart_gets(line, sizeof(line), fp) != NULL)
{
strlcpy(title, line + 1, sizeof(title));
break;
+ case 'N' : /* Document name */
+ strlcpy(docname, line + 1, sizeof(docname));
+ break;
+
case 'P' : /* User identification */
strlcpy(user, line + 1, sizeof(user));
break;
{
syslog(LOG_WARNING, "No username specified by client! "
"Using \"anonymous\"...");
- strcpy(user, "anonymous");
+ strlcpy(user, "anonymous", sizeof(user));
}
/*
* Create the job...
*/
- if ((id = create_job(http, dest, title, user, num_options, options)) < 0)
+ if ((id = create_job(http, dest, title, docname, user, num_options,
+ options)) < 0)
status = 1;
else
{
*/
if (jobstate == IPP_JOB_PROCESSING)
- strcpy(rankstr, "active");
+ strlcpy(rankstr, "active", sizeof(rankstr));
else
{
snprintf(rankstr, sizeof(rankstr), "%d%s", rank, ranks[rank % 10]);
/*
- * End of "$Id: cups-lpd.c 7221 2008-01-16 22:20:08Z mike $".
+ * End of "$Id: cups-lpd.c 11623 2014-02-19 20:18:10Z msweet $".
*/