]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/process.c
Merge changes from CUPS 1.5svn-r8849.
[thirdparty/cups.git] / scheduler / process.c
index 1b587ca318da04d1fbedd7fb31cfa19577a3c169..d026f0ab0dd5bcd3d66736dd28addde0eca9c6b3 100644 (file)
@@ -287,11 +287,16 @@ cupsdStartProcess(
                     strerror(errno));
 
     if (job && job->printer)
-      cupsdSetPrinterReasons(job->printer, "+cups-missing-filter-warning");
+    {
+      if (cupsdSetPrinterReasons(job->printer, "+cups-missing-filter-warning"))
+       cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, job->printer, NULL,
+                     "Printer driver %s is missing.", command);
+    }
 
     return (0);
   }
-  else if (commandinfo.st_mode & (S_ISUID | S_IWOTH))
+  else if ((commandinfo.st_mode & (S_ISUID | S_IWGRP | S_IWOTH)) ||
+           (!RunUser && commandinfo.st_uid))
   {
     *pid = 0;
 
@@ -306,7 +311,12 @@ cupsdStartProcess(
                    command, commandinfo.st_mode);
 
     if (job && job->printer)
-      cupsdSetPrinterReasons(job->printer, "+cups-insecure-filter-warning");
+    {
+      if (cupsdSetPrinterReasons(job->printer, "+cups-insecure-filter-warning"))
+       cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, job->printer, NULL,
+                     "Printer driver %s has insecure file permissions (0%o).",
+                     command, commandinfo.st_mode);
+    }
 
     errno = EPERM;
 
@@ -379,41 +389,51 @@ cupsdStartProcess(
 
     if (infd != 0)
     {
-      close(0);
-      if (infd > 0)
-        dup(infd);
-      else
-        open("/dev/null", O_RDONLY);
+      if (infd < 0)
+        infd = open("/dev/null", O_RDONLY);
+
+      if (infd != 0)
+      {
+        dup2(infd, 0);
+       close(infd);
+      }
     }
+
     if (outfd != 1)
     {
-      close(1);
-      if (outfd > 0)
-       dup(outfd);
-      else
-        open("/dev/null", O_WRONLY);
+      if (outfd < 0)
+        outfd = open("/dev/null", O_WRONLY);
+
+      if (outfd != 1)
+      {
+        dup2(outfd, 1);
+       close(outfd);
+      }
     }
+
     if (errfd != 2)
     {
-      close(2);
-      if (errfd > 0)
-        dup(errfd);
-      else
-        open("/dev/null", O_WRONLY);
+      if (errfd < 0)
+        errfd = open("/dev/null", O_WRONLY);
+
+      if (errfd != 2)
+      {
+        dup2(errfd, 2);
+       close(errfd);
+      }
     }
-    if (backfd != 3)
+
+    if (backfd != 3 && backfd >= 0)
     {
-      close(3);
-      if (backfd > 0)
-       dup(backfd);
-      else
-        open("/dev/null", O_RDWR);
+      dup2(backfd, 3);
+      close(backfd);
       fcntl(3, F_SETFL, O_NDELAY);
     }
-    if (sidefd != 4 && sidefd > 0)
+
+    if (sidefd != 4 && sidefd >= 0)
     {
-      close(4);
-      dup(sidefd);
+      dup2(sidefd, 4);
+      close(sidefd);
       fcntl(4, F_SETFL, O_NDELAY);
     }