/*
- * "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $"
+ * "$Id: cups-lpd.c 11594 2014-02-14 20:09:01Z msweet $"
*
- * Line Printer Daemon interface for CUPS.
+ * Line Printer Daemon interface for CUPS.
*
- * Copyright 2007-2010 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/".
*/
/*
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,
+ size_t destsize, cups_option_t **options,
int *accepting, int *shared, ipp_pstate_t *state);
static int print_file(http_t *http, int id, const char *filename,
const char *docname, const char *user,
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';
syslog(LOG_INFO, "Receive print job for %s", dest);
/* recv_print_job() sends initial status byte */
- status = recv_print_job(dest, num_defaults, defaults);
+ status = (char)recv_print_job(dest, num_defaults, defaults);
break;
case 0x03 : /* Send queue state (short) */
syslog(LOG_INFO, "Send queue state (short) for %s %s", dest, list);
/* no status byte for this command */
- status = send_state(dest, list, 0);
+ status = (char)send_state(dest, list, 0);
break;
case 0x04 : /* Send queue state (long) */
syslog(LOG_INFO, "Send queue state (long) for %s %s", dest, list);
/* no status byte for this command */
- status = send_state(dest, list, 1);
+ status = (char)send_state(dest, list, 1);
break;
case 0x05 : /* Remove jobs */
syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
- status = remove_jobs(dest, agent, list);
+ status = (char)remove_jobs(dest, agent, list);
}
else
status = 1;
get_printer(http_t *http, /* I - HTTP connection */
const char *name, /* I - Printer name from request */
char *dest, /* I - Destination buffer */
- int destsize, /* I - Size of destination buffer */
+ size_t destsize, /* I - Size of destination buffer */
cups_option_t **options, /* O - Printer options */
int *accepting, /* O - printer-is-accepting-jobs value */
int *shared, /* O - printer-is-shared value */
}
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!
* 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", (char)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)
{
{
syslog(LOG_WARNING, "No username specified by client! "
"Using \"anonymous\"...");
- strcpy(user, "anonymous");
+ strlcpy(user, "anonymous", sizeof(user));
}
/*
*/
if (jobstate == IPP_JOB_PROCESSING)
- strcpy(rankstr, "active");
+ strlcpy(rankstr, "active", sizeof(rankstr));
else
{
snprintf(rankstr, sizeof(rankstr), "%d%s", rank, ranks[rank % 10]);
break;
}
else if (ptr < end)
- *ptr++ = ch;
+ *ptr++ = (char)ch;
}
*ptr = '\0';
/*
- * End of "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $".
+ * End of "$Id: cups-lpd.c 11594 2014-02-14 20:09:01Z msweet $".
*/