]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cups-lpd.c
Full sweep of all Clang warnings, plus some bug fixes for incorrect memcpy usage.
[thirdparty/cups.git] / scheduler / cups-lpd.c
index 4aa320e728eb81feac068f6edc68bb5ac4642e53..a1de09058b32986bc176123dce93b4ffae7d9613 100644 (file)
@@ -1,27 +1,16 @@
 /*
- * "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $"
+ * "$Id$"
  *
- *   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/".
  */
 
 /*
 #  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
@@ -191,7 +173,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   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
   {
@@ -244,7 +226,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     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';
@@ -275,21 +257,21 @@ main(int  argc,                           /* I - Number of command-line arguments */
         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 */
@@ -307,7 +289,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
          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;
@@ -363,7 +345,7 @@ create_job(http_t        *http,             /* I - HTTP connection */
                  NULL, title);
 
   if (docname[0])
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "document-name", 
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "document-name",
                  NULL, docname);
 
   cupsEncodeOptions(request, num_options, options);
@@ -581,7 +563,7 @@ get_printer(http_t        *http,    /* I - HTTP connection */
       }
 
       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!
@@ -655,100 +637,6 @@ get_printer(http_t        *http,  /* I - HTTP connection */
     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...
   */
@@ -770,7 +658,7 @@ get_printer(http_t        *http,    /* I - HTTP connection */
        * 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;
 
        /*
@@ -787,7 +675,7 @@ get_printer(http_t        *http,    /* I - HTTP connection */
        * the loop - we're done!
        */
 
-       if (!strcasecmp(value, name))
+       if (!_cups_strcasecmp(value, name))
        {
           num_options = cupsParseOptions(optptr, num_options, options);
          break;
@@ -845,8 +733,7 @@ print_file(http_t     *http,                /* I - HTTP connection */
     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...
@@ -883,7 +770,8 @@ recv_print_job(
   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 */
@@ -1016,7 +904,7 @@ recv_print_job(
              break;
            }
 
-           strcpy(filename, control);
+           strlcpy(filename, control, sizeof(filename));
          }
          break;
 
@@ -1052,7 +940,7 @@ recv_print_job(
            break;
          }
 
-         strcpy(filename, temp[num_data]);
+         strlcpy(filename, temp[num_data], sizeof(filename));
 
           num_data ++;
          break;
@@ -1067,15 +955,15 @@ recv_print_job(
     * 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)
       {
@@ -1218,7 +1106,7 @@ recv_print_job(
       {
        syslog(LOG_WARNING, "No username specified by client! "
                            "Using \"anonymous\"...");
-       strcpy(user, "anonymous");
+       strlcpy(user, "anonymous", sizeof(user));
       }
 
      /*
@@ -1630,7 +1518,7 @@ send_state(const char *queue,             /* I - Destination */
     */
 
     if (jobstate == IPP_JOB_PROCESSING)
-      strcpy(rankstr, "active");
+      strlcpy(rankstr, "active", sizeof(rankstr));
     else
     {
       snprintf(rankstr, sizeof(rankstr), "%d%s", rank, ranks[rank % 10]);
@@ -1711,7 +1599,7 @@ smart_gets(char *s,                       /* I - Pointer to line buffer */
       break;
     }
     else if (ptr < end)
-      *ptr++ = ch;
+      *ptr++ = (char)ch;
   }
 
   *ptr = '\0';
@@ -1724,5 +1612,5 @@ smart_gets(char *s,                       /* I - Pointer to line buffer */
 
 
 /*
- * End of "$Id: cups-lpd.c 7899 2008-09-03 12:57:17Z mike $".
+ * End of "$Id$".
  */