]> 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 573d2e1e2fa9a66afe43356cde1f0df58a6a74bc..b518a93258178774b839d557560eba3ceabc79c6 100644 (file)
@@ -1,20 +1,14 @@
 /*
- * "$Id$"
- *
  * 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.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2018 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/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -33,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 */
@@ -74,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],
@@ -135,6 +132,9 @@ static const char * const PPDTypes[] =      /* ppd-type values */
                          "pdf",
                          "raster",
                          "fax",
+                         "object",
+                         "object-direct",
+                         "object-storage",
                          "unknown",
                          "drv",
                          "archive"
@@ -153,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);
@@ -163,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,
@@ -204,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);
@@ -428,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? */
 {
@@ -442,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)
   {
@@ -469,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
   {
    /*
@@ -511,7 +517,7 @@ cat_ppd(const char *name,           /* I - PPD name */
         cupsdSendIPPTrailer();
       }
 
-      return (1);
+      exit(1);
     }
 
    /*
@@ -541,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);
 }
 
 
@@ -772,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 */
@@ -804,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);
 }
 
 
@@ -900,7 +906,7 @@ get_file(const char *name,          /* I - Name */
        slash > printerDriver))
   {
    /*
-    * Map ppd-name to OS X standard locations...
+    * Map ppd-name to macOS standard locations...
     */
 
     snprintf(buffer, bufsize, "/%s", name);
@@ -998,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 */
@@ -1071,7 +1077,7 @@ list_ppds(int        request_id,  /* I - Request ID */
 
 #ifdef __APPLE__
  /*
-  * Load PPDs from standard OS X locations...
+  * Load PPDs from standard macOS locations...
   */
 
   load_ppds("/Library/Printers",
@@ -1172,11 +1178,11 @@ list_ppds(int        request_id,        /* I - Request ID */
   load_drivers(include, exclude);
 
  /*
-  * Add the raw and IPP Everywhere drivers...
+  * Add the raw driver...
   */
 
-  add_ppd("", "everywhere", "en", "Generic", "IPP Everywhere", "", "", "", 0, 0, 0, PPD_TYPE_UNKNOWN, "everywhere");
-  add_ppd("", "raw", "en", "Raw", "Raw Queue", "", "", "", 0, 0, 0, PPD_TYPE_UNKNOWN, "raw");
+  add_ppd("", "raw", "en", "Raw", "Raw Queue", "", "", "", 0, 0, 0,
+          PPD_TYPE_UNKNOWN, "raw");
 
  /*
   * Send IPP attributes...
@@ -1560,7 +1566,7 @@ list_ppds(int        request_id,  /* I - Request ID */
   if (request_id)
     cupsdSendIPPTrailer();
 
-  return (0);
+  exit(0);
 }
 
 
@@ -1709,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 */
@@ -1842,7 +1848,7 @@ load_drivers(cups_array_t *include,       /* I - Drivers to include */
        psversion[0] = '\0';
        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[^\"]\"",
@@ -2095,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);
@@ -2357,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 */
 
@@ -2378,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);
   }
 
  /*
@@ -2593,7 +2615,7 @@ 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) &&
        (((size_t)fileinfo.st_size - sizeof(ppdsync)) % sizeof(ppd_rec_t)) == 0 &&
@@ -2702,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...
@@ -2900,8 +2922,3 @@ regex_string(const char *s)               /* I - String to compare */
 
   return (NULL);
 }
-
-
-/*
- * End of "$Id$".
- */