]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cups-driverd.cxx
Fix test suite failure caused by log rotation due to sandboxing warning message.
[thirdparty/cups.git] / scheduler / cups-driverd.cxx
index be3075b9815d52d28afe308ac35c238dc80189b1..b518a93258178774b839d557560eba3ceabc79c6 100644 (file)
@@ -1,48 +1,14 @@
 /*
- * "$Id$"
+ * PPD/driver support for CUPS.
  *
- *   PPD/driver support for CUPS.
+ * This program handles listing and installing static PPD files, PPD files
+ * created from driver information files, and dynamically generated PPD files
+ * using driver helper programs.
  *
- *   This program handles listing and installing static PPD files, PPD files
- *   created from driver information files, and dynamically generated PPD files
- *   using driver helper programs.
+ * Copyright 2007-2018 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
- *
- *   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()        - Scan for drivers and return an IPP response.
- *   add_ppd()        - Add a PPD file.
- *   cat_drv()        - Generate a PPD from a driver info file.
- *   cat_ppd()        - Copy a PPD file to stdout.
- *   copy_static()     - Copy a static PPD file to stdout.
- *   cat_tar()        - Copy an archived PPD file to stdout.
- *   compare_inodes()  - Compare two inodes.
- *   compare_matches() - Compare PPD match scores for sorting.
- *   compare_names()   - Compare PPD filenames for sorting.
- *   compare_ppds()    - Compare PPD file make and model names for sorting.
- *   dump_ppds_dat()   - Dump the contents of the ppds.dat file.
- *   free_array()      - Free an array of strings.
- *   get_file()        - Get the filename associated with a request.
- *   list_ppds()       - List PPD files.
- *   load_drv()        - Load the PPDs from a driver information file.
- *   load_drivers()    - Load driver-generated PPD files.
- *   load_ppd()        - Load a PPD file.
- *   load_ppds()       - Load PPD files recursively.
- *   load_ppds_dat()   - Load the ppds.dat file.
- *   load_tar()        - Load archived PPD files.
- *   read_tar()        - Read a file header from an archive.
- *   regex_device_id() - Compile a regular expression based on the 1284 device
- *                      ID.
- *   regex_string()    - Construct a regular expression to compare a simple
- *                      string.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -61,7 +27,7 @@
  * Constants...
  */
 
-#define PPD_SYNC       0x50504437      /* Sync word for ppds.dat (PPD7) */
+#define PPD_SYNC       0x50504439      /* Sync word for ppds.dat (PPD9) */
 #define PPD_MAX_LANG   32              /* Maximum languages */
 #define PPD_MAX_PROD   32              /* Maximum products */
 #define PPD_MAX_VERS   32              /* Maximum versions */
 #define PPD_TYPE_PDF           1       /* PDF PPD */
 #define PPD_TYPE_RASTER                2       /* CUPS raster PPD */
 #define PPD_TYPE_FAX           3       /* Facsimile/MFD PPD */
-#define PPD_TYPE_UNKNOWN       4       /* Other/hybrid PPD */
-#define PPD_TYPE_DRV           5       /* Driver info file */
-#define PPD_TYPE_ARCHIVE       6       /* Archive file */
+#define PPD_TYPE_OBJECT_ANY    4       /* 3D (AMF/STL/g-code) PPD */
+#define PPD_TYPE_OBJECT_DIRECT 5       /* 3D (AMF/STL/g-code) PPD over any connection */
+#define PPD_TYPE_OBJECT_STORAGE        6       /* 3D (AMF/STL/g-code) PPD for storage to SD card, etc. */
+#define PPD_TYPE_UNKNOWN       7       /* Other/hybrid PPD */
+#define PPD_TYPE_DRV           8       /* Driver info file */
+#define PPD_TYPE_ARCHIVE       9       /* Archive file */
 
 #define TAR_BLOCK      512             /* Number of bytes in a block */
 #define TAR_BLOCKS     10              /* Blocking factor */
@@ -102,7 +71,7 @@ typedef struct                               /**** PPD record ****/
   int          model_number;           /* cupsModelNumber */
   int          type;                   /* ppd-type */
   char         filename[512],          /* Filename */
-               name[512],              /* PPD name */
+               name[256],              /* PPD name */
                languages[PPD_MAX_LANG][6],
                                        /* LanguageVersion/cupsLanguages */
                products[PPD_MAX_PROD][128],
@@ -163,6 +132,9 @@ static const char * const PPDTypes[] =      /* ppd-type values */
                          "pdf",
                          "raster",
                          "fax",
+                         "object",
+                         "object-direct",
+                         "object-storage",
                          "unknown",
                          "drv",
                          "archive"
@@ -181,7 +153,7 @@ static ppd_info_t   *add_ppd(const char *filename, const char *name,
                                 size_t size, int model_number, int type,
                                 const char *scheme);
 static int             cat_drv(const char *name, int request_id);
-static int             cat_ppd(const char *name, int request_id);
+static void            cat_ppd(const char *name, int request_id);
 static int             cat_static(const char *name, int request_id);
 static int             cat_tar(const char *name, int request_id);
 static int             compare_inodes(struct stat *a, struct stat *b);
@@ -191,12 +163,12 @@ static int                compare_names(const ppd_info_t *p0,
                                      const ppd_info_t *p1);
 static int             compare_ppds(const ppd_info_t *p0,
                                     const ppd_info_t *p1);
-static int             dump_ppds_dat(const char *filename);
+static void            dump_ppds_dat(const char *filename);
 static void            free_array(cups_array_t *a);
 static cups_file_t     *get_file(const char *name, int request_id,
                                  const char *subdir, char *buffer,
                                  size_t bufsize, char **subfile);
-static int             list_ppds(int request_id, int limit, const char *opt);
+static void            list_ppds(int request_id, int limit, const char *opt);
 static int             load_drivers(cups_array_t *include,
                                     cups_array_t *exclude);
 static int             load_drv(const char *filename, const char *name,
@@ -232,13 +204,13 @@ main(int  argc,                           /* I - Number of command-line args */
   */
 
   if (argc == 3 && !strcmp(argv[1], "cat"))
-    return (cat_ppd(argv[2], 0));
+    cat_ppd(argv[2], 0);
   else if ((argc == 2 || argc == 3) && !strcmp(argv[1], "dump"))
-    return (dump_ppds_dat(argv[2]));
+    dump_ppds_dat(argv[2]);
   else if (argc == 4 && !strcmp(argv[1], "get"))
-    return (cat_ppd(argv[3], atoi(argv[2])));
+    cat_ppd(argv[3], atoi(argv[2]));
   else if (argc == 5 && !strcmp(argv[1], "list"))
-    return (list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]));
+    list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]);
   else
   {
     fputs("Usage: cups-driverd cat ppd-name\n", stderr);
@@ -291,7 +263,7 @@ add_ppd(const char *filename,               /* I - PPD filename */
 
   ppd->found               = 1;
   ppd->record.mtime        = mtime;
-  ppd->record.size         = size;
+  ppd->record.size         = (off_t)size;
   ppd->record.model_number = model_number;
   ppd->record.type         = type;
 
@@ -456,7 +428,7 @@ cat_drv(const char *name,           /* I - PPD name */
  * 'cat_ppd()' - Copy a PPD file to stdout.
  */
 
-static int                             /* O - Exit code */
+static void
 cat_ppd(const char *name,              /* I - PPD name */
         int        request_id)         /* I - Request ID for response? */
 {
@@ -470,6 +442,12 @@ cat_ppd(const char *name,          /* I - PPD name */
   * Figure out if this is a static or dynamic PPD file...
   */
 
+  if (strstr(name, "../"))
+  {
+    fputs("ERROR: Invalid PPD name.\n", stderr);
+    exit(1);
+  }
+
   strlcpy(scheme, name, sizeof(scheme));
   if ((sptr = strchr(scheme, ':')) != NULL)
   {
@@ -497,11 +475,11 @@ cat_ppd(const char *name,         /* I - PPD name */
     puts("Content-Type: application/ipp\n");
 
   if (!scheme[0])
-    return (cat_static(name, request_id));
+    exit(cat_static(name, request_id));
   else if (!strcmp(scheme, "drv"))
-    return (cat_drv(name, request_id));
+    exit(cat_drv(name, request_id));
   else if (!strcmp(scheme, "file"))
-    return (cat_tar(name, request_id));
+    exit(cat_tar(name, request_id));
   else
   {
    /*
@@ -539,7 +517,7 @@ cat_ppd(const char *name,           /* I - PPD name */
         cupsdSendIPPTrailer();
       }
 
-      return (1);
+      exit(1);
     }
 
    /*
@@ -569,15 +547,15 @@ cat_ppd(const char *name,         /* I - PPD name */
 
       fprintf(stderr, "ERROR: [cups-driverd] Unable to execute \"%s\" - %s\n",
               line, strerror(errno));
-      return (1);
+      exit(1);
     }
   }
 
  /*
-  * Return with no errors...
+  * Exit with no errors...
   */
 
-  return (0);
+  exit(0);
 }
 
 
@@ -645,7 +623,7 @@ cat_tar(const char *name,           /* I - PPD name */
   */
 
   if ((fp = get_file(name, request_id, "model", filename, sizeof(filename),
-                     &ppdname)) == NULL)
+                     &ppdname)) == NULL || !ppdname)
     return (1);
 
  /*
@@ -671,10 +649,10 @@ cat_tar(const char *name,         /* I - PPD name */
 
       for (total = 0; total < curinfo.st_size; total += bytes)
       {
-        if ((bytes = (curinfo.st_size - total)) > sizeof(buffer))
+        if ((size_t)(bytes = (curinfo.st_size - total)) > sizeof(buffer))
           bytes = sizeof(buffer);
 
-        if ((bytes = cupsFileRead(fp, buffer, bytes)) < 0)
+        if ((bytes = cupsFileRead(fp, buffer, (size_t)bytes)) < 0)
         {
           if (errno == EINTR || errno == EAGAIN)
           {
@@ -686,7 +664,7 @@ cat_tar(const char *name,           /* I - PPD name */
             break;
           }
         }
-        else if (bytes > 0 && fwrite(buffer, bytes, 1, stdout) != 1)
+        else if (bytes > 0 && fwrite(buffer, (size_t)bytes, 1, stdout) != 1)
           break;
       }
 
@@ -800,7 +778,7 @@ compare_ppds(const ppd_info_t *p0,  /* I - First PPD file */
  * 'dump_ppds_dat()' - Dump the contents of the ppds.dat file.
  */
 
-static int                             /* O - Exit status */
+static void
 dump_ppds_dat(const char *filename)    /* I - Filename */
 {
   char         temp[1024];             /* ppds.dat filename */
@@ -832,7 +810,7 @@ dump_ppds_dat(const char *filename) /* I - Filename */
           ppd->record.make_and_model, ppd->record.device_id,
           ppd->record.scheme);
 
-  return (0);
+  exit(0);
 }
 
 
@@ -928,7 +906,7 @@ get_file(const char *name,          /* I - Name */
        slash > printerDriver))
   {
    /*
-    * Map ppd-name to Mac OS X standard locations...
+    * Map ppd-name to macOS standard locations...
     */
 
     snprintf(buffer, bufsize, "/%s", name);
@@ -1026,7 +1004,7 @@ get_file(const char *name,                /* I - Name */
  * 'list_ppds()' - List PPD files.
  */
 
-static int                             /* O - Exit code */
+static void
 list_ppds(int        request_id,       /* I - Request ID */
           int        limit,            /* I - Limit */
          const char *opt)              /* I - Option argument */
@@ -1053,8 +1031,6 @@ list_ppds(int        request_id,  /* I - Request ID */
                *type_str;              /* ppd-type option */
   int          model_number,           /* ppd-model-number value */
                type,                   /* ppd-type value */
-               make_and_model_len,     /* Length of ppd-make-and-model */
-               product_len,            /* Length of ppd-product */
                send_device_id,         /* Send ppd-device-id? */
                send_make,              /* Send ppd-make? */
                send_make_and_model,    /* Send ppd-make-and-model? */
@@ -1065,6 +1041,8 @@ list_ppds(int        request_id,  /* I - Request ID */
                send_psversion,         /* Send ppd-psversion? */
                send_type,              /* Send ppd-type? */
                sent_header;            /* Sent the IPP header? */
+  size_t       make_and_model_len,     /* Length of ppd-make-and-model */
+               product_len;            /* Length of ppd-product */
   regex_t      *device_id_re,          /* Regular expression for matching device ID */
                *make_and_model_re;     /* Regular expression for matching make and model */
   regmatch_t   re_matches[6];          /* Regular expression matches */
@@ -1099,7 +1077,7 @@ list_ppds(int        request_id,  /* I - Request ID */
 
 #ifdef __APPLE__
  /*
-  * Load PPDs from standard Mac OS X locations...
+  * Load PPDs from standard macOS locations...
   */
 
   load_ppds("/Library/Printers",
@@ -1349,7 +1327,7 @@ list_ppds(int        request_id,  /* I - Request ID */
 
       if (device_id_re &&
          !regexec(device_id_re, ppd->record.device_id,
-                   (int)(sizeof(re_matches) / sizeof(re_matches[0])),
+                   (size_t)(sizeof(re_matches) / sizeof(re_matches[0])),
                   re_matches, 0))
       {
        /*
@@ -1379,13 +1357,13 @@ list_ppds(int        request_id,        /* I - Request ID */
 
       if (make_and_model_re &&
           !regexec(make_and_model_re, ppd->record.make_and_model,
-                  (int)(sizeof(re_matches) / sizeof(re_matches[0])),
+                  (size_t)(sizeof(re_matches) / sizeof(re_matches[0])),
                   re_matches, 0))
       {
        // See how much of the make-and-model string we matched...
        if (re_matches[0].rm_so == 0)
        {
-         if (re_matches[0].rm_eo == make_and_model_len)
+         if ((size_t)re_matches[0].rm_eo == make_and_model_len)
            ppd->matches += 3;          // Exact match
          else
            ppd->matches += 2;          // Prefix match
@@ -1502,52 +1480,52 @@ list_ppds(int        request_id,        /* I - Request ID */
     if (request_id)
     {
       cupsdSendIPPGroup(IPP_TAG_PRINTER);
-  
+
       if (send_name)
        cupsdSendIPPString(IPP_TAG_NAME, "ppd-name", ppd->record.name);
-  
+
       if (send_natural_language)
       {
        cupsdSendIPPString(IPP_TAG_LANGUAGE, "ppd-natural-language",
                           ppd->record.languages[0]);
-  
+
        for (i = 1; i < PPD_MAX_LANG && ppd->record.languages[i][0]; i ++)
          cupsdSendIPPString(IPP_TAG_LANGUAGE, "", ppd->record.languages[i]);
       }
-  
+
       if (send_make)
        cupsdSendIPPString(IPP_TAG_TEXT, "ppd-make", ppd->record.make);
-  
+
       if (send_make_and_model)
        cupsdSendIPPString(IPP_TAG_TEXT, "ppd-make-and-model",
                           ppd->record.make_and_model);
-  
+
       if (send_device_id)
        cupsdSendIPPString(IPP_TAG_TEXT, "ppd-device-id",
                           ppd->record.device_id);
-  
+
       if (send_product)
       {
        cupsdSendIPPString(IPP_TAG_TEXT, "ppd-product",
                           ppd->record.products[0]);
-  
+
        for (i = 1; i < PPD_MAX_PROD && ppd->record.products[i][0]; i ++)
          cupsdSendIPPString(IPP_TAG_TEXT, "", ppd->record.products[i]);
       }
-  
+
       if (send_psversion)
       {
        cupsdSendIPPString(IPP_TAG_TEXT, "ppd-psversion",
                           ppd->record.psversions[0]);
-  
+
        for (i = 1; i < PPD_MAX_VERS && ppd->record.psversions[i][0]; i ++)
          cupsdSendIPPString(IPP_TAG_TEXT, "", ppd->record.psversions[i]);
       }
-  
+
       if (send_type)
        cupsdSendIPPString(IPP_TAG_KEYWORD, "ppd-type",
                           PPDTypes[ppd->record.type]);
-  
+
       if (send_model_number)
        cupsdSendIPPInteger(IPP_TAG_INTEGER, "ppd-model-number",
                            ppd->record.model_number);
@@ -1588,7 +1566,7 @@ list_ppds(int        request_id,  /* I - Request ID */
   if (request_id)
     cupsdSendIPPTrailer();
 
-  return (0);
+  exit(0);
 }
 
 
@@ -1637,8 +1615,7 @@ load_drv(const char  *filename,           /* I - Actual filename */
   * Add a dummy entry for the file...
   */
 
-  add_ppd(name, name, "", "", "", "", "", "", mtime, size, 0,
-          PPD_TYPE_DRV, "drv");
+  add_ppd(name, name, "", "", "", "", "", "", mtime, (size_t)size, 0, PPD_TYPE_DRV, "drv");
   ChangedPPD = 1;
 
  /*
@@ -1696,14 +1673,10 @@ load_drv(const char  *filename,         /* I - Actual filename */
       if (!strcmp(product->name->value, "Product"))
       {
         if (!products_found)
-         ppd = add_ppd(name, uri, "en", d->manufacturer->value, make_model,
-                       device_id ? device_id->value->value : "",
-                       product->value->value,
-                       ps_version ? ps_version->value->value : "(3010) 0",
-                       mtime, size, d->model_number, type, "drv");
+         ppd = add_ppd(name, uri, "en", d->manufacturer->value, make_model, device_id ? device_id->value->value : "", product->value->value,
+                       ps_version ? ps_version->value->value : "(3010) 0", mtime, (size_t)size, d->model_number, type, "drv");
        else if (products_found < PPD_MAX_PROD)
-         strlcpy(ppd->record.products[products_found], product->value->value,
-                 sizeof(ppd->record.products[0]));
+         strlcpy(ppd->record.products[products_found], product->value->value, sizeof(ppd->record.products[0]));
        else
          break;
 
@@ -1711,11 +1684,7 @@ load_drv(const char  *filename,          /* I - Actual filename */
       }
 
     if (!products_found)
-      add_ppd(name, uri, "en", d->manufacturer->value, make_model,
-             device_id ? device_id->value->value : "",
-             d->model_name->value,
-             ps_version ? ps_version->value->value : "(3010) 0",
-             mtime, size, d->model_number, type, "drv");
+      add_ppd(name, uri, "en", d->manufacturer->value, make_model, device_id ? device_id->value->value : "", d->model_name->value, ps_version ? ps_version->value->value : "(3010) 0", mtime, (size_t)size, d->model_number, type, "drv");
   }
 
   src->release();
@@ -1746,7 +1715,7 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
   char         *argv[3],               /* Arguments for command */
                filename[1024],         /* Name of driver */
                line[2048],             /* Line from driver */
-               name[512],              /* ppd-name */
+               name[256],              /* ppd-name */
                make[128],              /* ppd-make */
                make_and_model[128],    /* ppd-make-and-model */
                device_id[256],         /* ppd-device-id */
@@ -1810,7 +1779,7 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
        scheme_end = scheme + strlen(scheme) - 1;
 
        if ((scheme_end > scheme && *scheme_end == '*' &&
-            !strncmp(scheme, dent->filename, scheme_end - scheme)) ||
+            !strncmp(scheme, dent->filename, (size_t)(scheme_end - scheme))) ||
            !strcmp(scheme, dent->filename))
        {
          fputs("DEBUG: [cups-driverd] Yes, exclude!\n", stderr);
@@ -1837,7 +1806,7 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
        scheme_end = scheme + strlen(scheme) - 1;
 
        if ((scheme_end > scheme && *scheme_end == '*' &&
-            !strncmp(scheme, dent->filename, scheme_end - scheme)) ||
+            !strncmp(scheme, dent->filename, (size_t)(scheme_end - scheme))) ||
            !strcmp(scheme, dent->filename))
        {
          fputs("DEBUG: [cups-driverd] Yes, include!\n", stderr);
@@ -1877,9 +1846,9 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
         device_id[0] = '\0';
        product[0]   = '\0';
        psversion[0] = '\0';
-       strcpy(type_str, "postscript");
+       strlcpy(type_str, "postscript", sizeof(type_str));
 
-        if (sscanf(line, "\"%511[^\"]\"%127s%*[ \t]\"%127[^\"]\""
+        if (sscanf(line, "\"%255[^\"]\"%127s%*[ \t]\"%127[^\"]\""
                         "%*[ \t]\"%127[^\"]\"%*[ \t]\"%255[^\"]\""
                         "%*[ \t]\"%127[^\"]\"%*[ \t]\"%127[^\"]\""
                         "%*[ \t]\"%127[^\"]\"",
@@ -1997,7 +1966,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
   cups_array_t *products,              /* Product array */
                *psversions,            /* PSVersion array */
                *cups_languages;        /* cupsLanguages array */
-  int          new_ppd = !ppd;         /* Is this a new PPD? */
+  int          new_ppd;                /* Is this a new PPD? */
   struct                               /* LanguageVersion translation table */
   {
     const char *version,               /* LanguageVersion string */
@@ -2043,7 +2012,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
   manufacturer[0]  = '\0';
   device_id[0]     = '\0';
   lang_encoding[0] = '\0';
-  strcpy(lang_version, "en");
+  strlcpy(lang_version, "en", sizeof(lang_version));
   model_number     = 0;
   install_group    = 0;
   type             = PPD_TYPE_POSTSCRIPT;
@@ -2132,12 +2101,28 @@ load_ppd(const char  *filename,         /* I - Real filename */
       if (!_cups_strncasecmp(ptr, "true", 4))
        type = PPD_TYPE_FAX;
     }
-    else if (!strncmp(line, "*cupsFilter:", 12) && type == PPD_TYPE_POSTSCRIPT)
+    else if ((!strncmp(line, "*cupsFilter:", 12) || !strncmp(line, "*cupsFilter2:", 13)) && type == PPD_TYPE_POSTSCRIPT)
     {
       if (strstr(line + 12, "application/vnd.cups-raster"))
        type = PPD_TYPE_RASTER;
       else if (strstr(line + 12, "application/vnd.cups-pdf"))
        type = PPD_TYPE_PDF;
+      else if (strstr(line + 12, "application/amf") ||
+               strstr(line + 12, "application/g-code") ||
+               strstr(line + 12, "application/sla"))
+       type = PPD_TYPE_OBJECT_ANY;
+    }
+    else if (!strncmp(line, "*cups3DWorkflows:", 17))
+    {
+      int is_direct = strstr(line + 17, "direct") != NULL;
+      int is_storage = strstr(line + 17, "storage") != NULL;
+
+      if (is_direct && !is_storage)
+        type = PPD_TYPE_OBJECT_DIRECT;
+      else if (!is_direct && is_storage)
+        type = PPD_TYPE_OBJECT_STORAGE;
+      else
+        type = PPD_TYPE_OBJECT_ANY;
     }
     else if (!strncmp(line, "*cupsModelNumber:", 17))
       sscanf(line, "*cupsModelNumber:%d", &model_number);
@@ -2166,7 +2151,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
     cupsCharsetToUTF8((cups_utf8_t *)make_model, nick_name,
                      sizeof(make_model), _ppdGetEncoding(lang_encoding));
   else
-    strcpy(make_model, model_name);
+    strlcpy(make_model, model_name, sizeof(make_model));
 
   while (isspace(make_model[0] & 255))
     _cups_strcpy(make_model, make_model + 1);
@@ -2236,13 +2221,13 @@ load_ppd(const char  *filename,         /* I - Real filename */
     if (*ptr && ptr > manufacturer)
       *ptr = '\0';
     else
-      strcpy(manufacturer, "Other");
+      strlcpy(manufacturer, "Other", sizeof(manufacturer));
   }
   else if (!_cups_strncasecmp(manufacturer, "LHAG", 4) ||
           !_cups_strncasecmp(manufacturer, "linotype", 8))
-    strcpy(manufacturer, "LHAG");
+    strlcpy(manufacturer, "LHAG", sizeof(manufacturer));
   else if (!_cups_strncasecmp(manufacturer, "Hewlett", 7))
-    strcpy(manufacturer, "HP");
+    strlcpy(manufacturer, "HP", sizeof(manufacturer));
 
  /*
   * Fix the lang_version as needed...
@@ -2290,7 +2275,7 @@ load_ppd(const char  *filename,           /* I - Real filename */
     * Unknown language; use "xx"...
     */
 
-    strcpy(lang_version, "xx");
+    strlcpy(lang_version, "xx", sizeof(lang_version));
   }
 
  /*
@@ -2307,11 +2292,7 @@ load_ppd(const char  *filename,          /* I - Real filename */
 
     fprintf(stderr, "DEBUG2: [cups-driverd] Adding ppd \"%s\"...\n", name);
 
-    ppd = add_ppd(name, name, lang_version, manufacturer, make_model,
-                 device_id, (char *)cupsArrayFirst(products),
-                 (char *)cupsArrayFirst(psversions),
-                 fileinfo->st_mtime, fileinfo->st_size,
-                 model_number, type, scheme);
+    ppd = add_ppd(name, name, lang_version, manufacturer, make_model, device_id, (char *)cupsArrayFirst(products), (char *)cupsArrayFirst(psversions), fileinfo->st_mtime, (size_t)fileinfo->st_size, model_number, type, scheme);
 
     if (!ppd)
       return;
@@ -2398,7 +2379,7 @@ load_ppds(const char *d,          /* I - Actual directory */
   char         filename[1024],         /* Name of PPD or directory */
                line[256],              /* Line from file */
                *ptr,                   /* Pointer into name */
-               name[128];              /* Name of PPD file */
+               name[256];              /* Name of PPD file */
   ppd_info_t   *ppd,                   /* New PPD file */
                key;                    /* Search key */
 
@@ -2419,7 +2400,7 @@ load_ppds(const char *d,          /* I - Actual directory */
   {
     fprintf(stderr, "ERROR: [cups-driverd] Skipping \"%s\": loop detected!\n",
             d);
-    return (0);
+    return (1);
   }
 
  /*
@@ -2519,8 +2500,8 @@ load_ppds(const char *d,          /* I - Actual directory */
     * See if this file has been scanned before...
     */
 
-    strcpy(key.record.filename, name);
-    strcpy(key.record.name, name);
+    strlcpy(key.record.filename, name, sizeof(key.record.filename));
+    strlcpy(key.record.name, name, sizeof(key.record.name));
 
     ppd = (ppd_info_t *)cupsArrayFind(PPDsByName, &key);
 
@@ -2634,13 +2615,11 @@ load_ppds_dat(char   *filename,         /* I - Filename buffer */
     unsigned ppdsync;                  /* Sync word */
     int      num_ppds;                 /* Number of PPDs */
 
-    if (cupsFileRead(fp, (char *)&ppdsync, sizeof(ppdsync))
-            == sizeof(ppdsync) &&
+    if ((size_t)cupsFileRead(fp, (char *)&ppdsync, sizeof(ppdsync)) == sizeof(ppdsync) &&
         ppdsync == PPD_SYNC &&
         !stat(filename, &fileinfo) &&
-       ((fileinfo.st_size - sizeof(ppdsync)) % sizeof(ppd_rec_t)) == 0 &&
-       (num_ppds = (fileinfo.st_size - sizeof(ppdsync)) /
-                   sizeof(ppd_rec_t)) > 0)
+       (((size_t)fileinfo.st_size - sizeof(ppdsync)) % sizeof(ppd_rec_t)) == 0 &&
+       (num_ppds = ((size_t)fileinfo.st_size - sizeof(ppdsync)) / sizeof(ppd_rec_t)) > 0)
     {
      /*
       * We have a ppds.dat file, so read it!
@@ -2700,8 +2679,9 @@ load_tar(const char  *filename,           /* I - Actual filename */
   * Add a dummy entry for the file...
   */
 
-  add_ppd(name, name, "", "", "", "", "", "", mtime, size, 0,
-          PPD_TYPE_ARCHIVE, "file");
+  (void)filename;
+
+  add_ppd(name, name, "", "", "", "", "", "", mtime, (size_t)size, 0, PPD_TYPE_ARCHIVE, "file");
   ChangedPPD = 1;
 
  /*
@@ -2744,7 +2724,7 @@ read_tar(cups_file_t *fp,         /* I - Archive to read */
   tar_rec_t    record;                 /* Record from file */
 
 
-  while (cupsFileRead(fp, (char *)&record, sizeof(record)) == sizeof(record))
+  while ((size_t)cupsFileRead(fp, (char *)&record, sizeof(record)) == sizeof(record))
   {
    /*
     * Check for a valid tar header...
@@ -2942,8 +2922,3 @@ regex_string(const char *s)               /* I - String to compare */
 
   return (NULL);
 }
-
-
-/*
- * End of "$Id$".
- */