]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
The scheduler now more carefully creates and removes configuration, cache, and
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 11 May 2011 22:17:34 +0000 (22:17 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 11 May 2011 22:17:34 +0000 (22:17 +0000)
state files (STR #3715)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9766 7a7537e8-13f0-0310-91df-b6672ffda945

13 files changed:
CHANGES.txt
cups/ppd-cache.c
scheduler/Makefile
scheduler/classes.c
scheduler/client.c
scheduler/cupsd.h
scheduler/dirsvc.c
scheduler/file.c [new file with mode: 0644]
scheduler/job.c
scheduler/main.c
scheduler/printers.c
scheduler/removefile.c [deleted file]
xcode/CUPS.xcodeproj/project.pbxproj

index beadcb06ccf298101b1c75a334514e1e051a022e..e6e446e6f47490800afcb1db6527ccad10d6823a 100644 (file)
@@ -1,8 +1,10 @@
-CHANGES.txt - 2011-05-10
+CHANGES.txt - 2011-05-11
 ------------------------
 
 CHANGES IN CUPS V1.5b1
 
+       - The scheduler now more carefully creates and removes configuration,
+         cache, and state files (STR #3715)
        - The lpadmin command now allows default option values to be deleted
          (STR #2959)
        - The lpadmin command now allows the cupsIPPSupplies and
index 77a56622c6d1a4fa60edace8b90a0b61a773e191..90b83b758dca991a46137985686d9c59bcd14392 100644 (file)
@@ -1995,6 +1995,7 @@ _ppdCacheWriteFile(
   _pwg_map_t   *map;                   /* Current map */
   cups_option_t        *option;                /* Current option */
   const char   *value;                 /* Filter/pre-filter value */
+  char         newfile[1024];          /* New filename */
 
 
  /*
@@ -2011,7 +2012,8 @@ _ppdCacheWriteFile(
   * Open the file and write with compression...
   */
 
-  if ((fp = cupsFileOpen(filename, "w9")) == NULL)
+  snprintf(newfile, sizeof(newfile), "%s.N", filename);
+  if ((fp = cupsFileOpen(newfile, "w9")) == NULL)
   {
     _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno), 0);
     return (0);
@@ -2142,7 +2144,14 @@ _ppdCacheWriteFile(
   * Close and return...
   */
 
-  return (!cupsFileClose(fp));
+  if (cupsFileClose(fp))
+  {
+    unlink(newfile);
+    return (0);
+  }
+
+  unlink(filename);
+  return (!rename(newfile, filename));
 }
 
 
index 054284196b3ae12dd71e2d8bf6c102c1d3701326..3c7da8e28d502c4f44a9e0df9e10a64edffc5aa6 100644 (file)
@@ -3,7 +3,7 @@
 #
 #   Scheduler Makefile for CUPS.
 #
-#   Copyright 2007-2010 by Apple Inc.
+#   Copyright 2007-2011 by Apple Inc.
 #   Copyright 1997-2007 by Easy Software Products, all rights reserved.
 #
 #   These coded instructions, statements, and computer programs are the
@@ -24,6 +24,7 @@ CUPSDOBJS =   \
                conf.o \
                dirsvc.o \
                env.o \
+               file.o \
                main.o \
                ipp.o \
                listen.o \
@@ -34,7 +35,6 @@ CUPSDOBJS =   \
                printers.o \
                process.o \
                quotas.o \
-               removefile.o \
                select.o \
                server.o \
                statbuf.o \
@@ -570,7 +570,7 @@ sloc:
 #
 # Dependencies...
 #
-  
+
 include Dependencies
 
 
index a4384f989d030005f350111de05f2add51541fb9..7c75deed49aa971f5e97ff4ffa01f6a882354a3f 100644 (file)
@@ -309,13 +309,8 @@ cupsdLoadAllClasses(void)
   */
 
   snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
-  if ((fp = cupsFileOpen(line, "r")) == NULL)
-  {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
-                     strerror(errno));
+  if ((fp = cupsdOpenConfFile(line)) == NULL)
     return;
-  }
 
  /*
   * Read class configurations until we hit EOF...
@@ -691,8 +686,8 @@ void
 cupsdSaveAllClasses(void)
 {
   cups_file_t          *fp;            /* classes.conf file */
-  char                 temp[1024],     /* Temporary string */
-                       backup[1024],   /* printers.conf.O file */
+  char                 filename[1024], /* classes.conf filename */
+                       temp[1024],     /* Temporary string */
                        value[2048],    /* Value string */
                        *name;          /* Current user name */
   cupsd_printer_t      *pclass;        /* Current printer class */
@@ -706,35 +701,12 @@ cupsdSaveAllClasses(void)
   * Create the classes.conf file...
   */
 
-  snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
-  snprintf(backup, sizeof(backup), "%s/classes.conf.O", ServerRoot);
-
-  if (rename(temp, backup))
-  {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup classes.conf - %s",
-                      strerror(errno));
-  }
-
-  if ((fp = cupsFileOpen(temp, "w")) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to save classes.conf - %s",
-                    strerror(errno));
+  snprintf(filename, sizeof(filename), "%s/classes.conf", ServerRoot);
 
-    if (rename(backup, temp))
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to restore classes.conf - %s",
-                      strerror(errno));
+  if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL)
     return;
-  }
-  else
-    cupsdLogMessage(CUPSD_LOG_INFO, "Saving classes.conf...");
-
- /*
-  * Restrict access to the file...
-  */
 
-  fchown(cupsFileNumber(fp), RunUser, Group);
-  fchmod(cupsFileNumber(fp), ConfigFilePerm);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Saving classes.conf...");
 
  /*
   * Write a small header to the file...
@@ -857,7 +829,7 @@ cupsdSaveAllClasses(void)
     cupsFilePuts(fp, "</Class>\n");
   }
 
-  cupsFileClose(fp);
+  cupsdCloseCreatedConfFile(fp, filename);
 }
 
 
index cfb9b506f36f69dd78eb32812e49bec4e7b7e0f6..08d7803ca5133f31923a02fff582b6cb4625008d 100644 (file)
@@ -3808,60 +3808,42 @@ get_file(cupsd_client_t *con,           /* I  - Client connection */
 static http_status_t                   /* O - Status */
 install_conf_file(cupsd_client_t *con) /* I - Connection */
 {
+  char         filename[1024];         /* Configuration filename */
+  mode_t       mode;                   /* Permissions */
   cups_file_t  *in,                    /* Input file */
                *out;                   /* Output file */
-  char         buffer[1024];           /* Copy buffer */
-  int          bytes;                  /* Number of bytes */
-  char         conffile[1024],         /* Configuration filename */
-               newfile[1024],          /* New config filename */
-               oldfile[1024];          /* Old config filename */
-  struct stat  confinfo;               /* Config file info */
+  char         buffer[16384];          /* Copy buffer */
+  ssize_t      bytes;                  /* Number of bytes */
 
 
  /*
-  * First construct the filenames...
+  * Open the request file...
   */
 
-  snprintf(conffile, sizeof(conffile), "%s%s", ServerRoot, con->uri + 11);
-  snprintf(newfile, sizeof(newfile), "%s%s.N", ServerRoot, con->uri + 11);
-  snprintf(oldfile, sizeof(oldfile), "%s%s.O", ServerRoot, con->uri + 11);
-
-  cupsdLogMessage(CUPSD_LOG_INFO, "Installing config file \"%s\"...", conffile);
-
- /*
-  * Get the owner, group, and permissions of the configuration file.
-  * If it doesn't exist, assign it to the User and Group in the
-  * cupsd.conf file with mode 0640 permissions.
-  */
-
-  if (stat(conffile, &confinfo))
+  if ((in = cupsFileOpen(con->filename, "rb")) == NULL)
   {
-    confinfo.st_uid  = User;
-    confinfo.st_gid  = Group;
-    confinfo.st_mode = ConfigFilePerm;
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open request file \"%s\": %s",
+                    con->filename, strerror(errno));
+    return (HTTP_SERVER_ERROR);
   }
 
  /*
-  * Open the request file and new config file...
+  * Open the new config file...
   */
 
-  if ((in = cupsFileOpen(con->filename, "rb")) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open request file \"%s\" - %s",
-                    con->filename, strerror(errno));
-    return (HTTP_SERVER_ERROR);
-  }
+  snprintf(filename, sizeof(filename), "%s%s", ServerRoot, con->uri + 11);
+  if (!strcmp(con->uri, "/admin/conf/printers.conf"))
+    mode = ConfigFilePerm & 0600;
+  else
+    mode = ConfigFilePerm;
 
-  if ((out = cupsFileOpen(newfile, "wb")) == NULL)
+  if ((out = cupsdCreateConfFile(filename, mode)) == NULL)
   {
     cupsFileClose(in);
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open config file \"%s\" - %s",
-                    newfile, strerror(errno));
     return (HTTP_SERVER_ERROR);
   }
 
-  fchmod(cupsFileNumber(out), confinfo.st_mode);
-  fchown(cupsFileNumber(out), confinfo.st_uid, confinfo.st_gid);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Installing config file \"%s\"...", filename);
 
  /*
   * Copy from the request to the new config file...
@@ -3871,12 +3853,14 @@ install_conf_file(cupsd_client_t *con)  /* I - Connection */
     if (cupsFileWrite(out, buffer, bytes) < bytes)
     {
       cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to copy to config file \"%s\" - %s",
-                     newfile, strerror(errno));
+                      "Unable to copy to config file \"%s\": %s",
+                     filename, strerror(errno));
 
       cupsFileClose(in);
       cupsFileClose(out);
-      unlink(newfile);
+
+      snprintf(filename, sizeof(filename), "%s%s.N", ServerRoot, con->uri + 11);
+      cupsdRemoveFile(filename);
 
       return (HTTP_SERVER_ERROR);
     }
@@ -3886,65 +3870,17 @@ install_conf_file(cupsd_client_t *con)  /* I - Connection */
   */
 
   cupsFileClose(in);
-  if (cupsFileClose(out))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Error file closing config file \"%s\" - %s",
-                    newfile, strerror(errno));
-
-    unlink(newfile);
 
+  if (cupsdCloseCreatedConfFile(out, filename))
     return (HTTP_SERVER_ERROR);
-  }
 
  /*
   * Remove the request file...
   */
 
-  unlink(con->filename);
+  cupsdRemoveFile(con->filename);
   cupsdClearString(&con->filename);
 
- /*
-  * Unlink the old backup, rename the current config file to the backup
-  * filename, and rename the new config file to the config file name...
-  */
-
-  if (unlink(oldfile))
-    if (errno != ENOENT)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to remove backup config file \"%s\" - %s",
-                     oldfile, strerror(errno));
-
-      unlink(newfile);
-
-      return (HTTP_SERVER_ERROR);
-    }
-
-  if (rename(conffile, oldfile))
-    if (errno != ENOENT)
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to rename old config file \"%s\" - %s",
-                     conffile, strerror(errno));
-
-      unlink(newfile);
-
-      return (HTTP_SERVER_ERROR);
-    }
-
-  if (rename(newfile, conffile))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to rename new config file \"%s\" - %s",
-                    newfile, strerror(errno));
-
-    rename(oldfile, conffile);
-    unlink(newfile);
-
-    return (HTTP_SERVER_ERROR);
-  }
-
  /*
   * If the cupsd.conf file was updated, set the NeedReload flag...
   */
index 69fc3581ff69a30e9cb124a2bd6ed0c1570faec7..5d7229d55cd6a976b3890e24d6785013cf01e8df 100644 (file)
@@ -178,57 +178,69 @@ VAR int                   Launchd         VALUE(0);
  * Prototypes...
  */
 
-extern int     cupsdAddString(cups_array_t **a, const char *s);
-extern void    cupsdCheckProcess(void);
-extern void    cupsdClearString(char **s);
-extern void    cupsdFreeStrings(cups_array_t **a);
-extern void    cupsdHoldSignals(void);
-extern char    *cupsdMakeUUID(const char *name, int number,
-                              char *buffer, size_t bufsize);
-extern void    cupsdReleaseSignals(void);
-extern void    cupsdSetString(char **s, const char *v);
-extern void    cupsdSetStringf(char **s, const char *f, ...)
+/* env.c */
+extern void            cupsdInitEnv(void);
+extern int             cupsdLoadEnv(char *envp[], int envmax);
+extern void            cupsdSetEnv(const char *name, const char *value);
+extern void            cupsdSetEnvf(const char *name, const char *value, ...)
 #ifdef __GNUC__
 __attribute__ ((__format__ (__printf__, 2, 3)))
 #endif /* __GNUC__ */
 ;
-extern void    cupsdStartServer(void);
-extern void    cupsdStopServer(void);
-extern void    cupsdClosePipe(int *fds);
-extern int     cupsdOpenPipe(int *fds);
-
-extern void    cupsdInitEnv(void);
-extern int     cupsdLoadEnv(char *envp[], int envmax);
-extern void    cupsdSetEnv(const char *name, const char *value);
-extern void    cupsdSetEnvf(const char *name, const char *value, ...)
+extern void            cupsdUpdateEnv(void);
+
+/* file.c */
+extern void            cupsdCleanFiles(const char *path, const char *pattern);
+extern int             cupsdCloseCreatedConfFile(cups_file_t *fp,
+                                                 const char *filename);
+extern void            cupsdClosePipe(int *fds);
+extern cups_file_t     *cupsdCreateConfFile(const char *filename, mode_t mode);
+extern cups_file_t     *cupsdOpenConfFile(const char *filename);
+extern int             cupsdOpenPipe(int *fds);
+extern int             cupsdRemoveFile(const char *filename);
+
+/* main.c */
+extern int             cupsdAddString(cups_array_t **a, const char *s);
+extern void            cupsdCheckProcess(void);
+extern void            cupsdClearString(char **s);
+extern void            cupsdFreeStrings(cups_array_t **a);
+extern void            cupsdHoldSignals(void);
+extern char            *cupsdMakeUUID(const char *name, int number,
+                                      char *buffer, size_t bufsize);
+extern void            cupsdReleaseSignals(void);
+extern void            cupsdSetString(char **s, const char *v);
+extern void            cupsdSetStringf(char **s, const char *f, ...)
 #ifdef __GNUC__
 __attribute__ ((__format__ (__printf__, 2, 3)))
 #endif /* __GNUC__ */
 ;
-extern void    cupsdUpdateEnv(void);
-
-extern void    *cupsdCreateProfile(int job_id);
-extern void    cupsdDestroyProfile(void *profile);
-extern int     cupsdEndProcess(int pid, int force);
-extern const char *cupsdFinishProcess(int pid, char *name, int namelen,
-                                     int *job_id);
-extern int     cupsdStartProcess(const char *command, char *argv[],
-                                 char *envp[], int infd, int outfd,
-                                 int errfd, int backfd, int sidefd,
-                                 int root, void *profile, cupsd_job_t *job,
-                                 int *pid);
-
-extern int     cupsdAddSelect(int fd, cupsd_selfunc_t read_cb,
-                              cupsd_selfunc_t write_cb, void *data);
-extern int     cupsdDoSelect(long timeout);
+
+/* process.c */
+extern void            *cupsdCreateProfile(int job_id);
+extern void            cupsdDestroyProfile(void *profile);
+extern int             cupsdEndProcess(int pid, int force);
+extern const char      *cupsdFinishProcess(int pid, char *name, int namelen,
+                                           int *job_id);
+extern int             cupsdStartProcess(const char *command, char *argv[],
+                                         char *envp[], int infd, int outfd,
+                                         int errfd, int backfd, int sidefd,
+                                         int root, void *profile,
+                                         cupsd_job_t *job, int *pid);
+
+/* select.c */
+extern int             cupsdAddSelect(int fd, cupsd_selfunc_t read_cb,
+                                      cupsd_selfunc_t write_cb, void *data);
+extern int             cupsdDoSelect(long timeout);
 #ifdef CUPSD_IS_SELECTING
-extern int     cupsdIsSelecting(int fd);
+extern int             cupsdIsSelecting(int fd);
 #endif /* CUPSD_IS_SELECTING */
-extern void    cupsdRemoveSelect(int fd);
-extern void    cupsdStartSelect(void);
-extern void    cupsdStopSelect(void);
+extern void            cupsdRemoveSelect(int fd);
+extern void            cupsdStartSelect(void);
+extern void            cupsdStopSelect(void);
 
-extern int     cupsdRemoveFile(const char *filename);
+/* server.c */
+extern void            cupsdStartServer(void);
+extern void            cupsdStopServer(void);
 
 
 /*
index 901840ac5d172f988a8ded13c82babf81f0db7c2..b28a00bcd0f218ca19e17d34b71c547a5b1de6f5 100644 (file)
@@ -330,7 +330,7 @@ cupsdLoadRemoteCache(void)
   */
 
   snprintf(line, sizeof(line), "%s/remote.cache", CacheDir);
-  if ((fp = cupsFileOpen(line, "r")) == NULL)
+  if ((fp = cupsdOpenConfFile(line)) == NULL)
     return;
 
  /*
@@ -734,8 +734,9 @@ void
 cupsdSaveRemoteCache(void)
 {
   int                  i;              /* Looping var */
-  cups_file_t          *fp;            /* printers.conf file */
-  char                 temp[1024],     /* Temporary string */
+  cups_file_t          *fp;            /* remote.cache file */
+  char                 filename[1024], /* remote.cache filename */
+                       temp[1024],     /* Temporary string */
                        value[2048],    /* Value string */
                        *name;          /* Current user name */
   cupsd_printer_t      *printer;       /* Current printer class */
@@ -748,23 +749,12 @@ cupsdSaveRemoteCache(void)
   * Create the remote.cache file...
   */
 
-  snprintf(temp, sizeof(temp), "%s/remote.cache", CacheDir);
+  snprintf(filename, sizeof(filename), "%s/remote.cache", CacheDir);
 
-  if ((fp = cupsFileOpen(temp, "w")) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to save remote.cache - %s", strerror(errno));
+  if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL)
     return;
-  }
-  else
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Saving remote.cache...");
 
- /*
-  * Restrict access to the file...
-  */
-
-  fchown(cupsFileNumber(fp), getuid(), Group);
-  fchmod(cupsFileNumber(fp), ConfigFilePerm);
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "Saving remote.cache...");
 
  /*
   * Write a small header to the file...
@@ -859,7 +849,7 @@ cupsdSaveRemoteCache(void)
       cupsFilePuts(fp, "</Printer>\n");
   }
 
-  cupsFileClose(fp);
+  cupsdCloseCreatedConfFile(fp, filename);
 }
 
 
diff --git a/scheduler/file.c b/scheduler/file.c
new file mode 100644 (file)
index 0000000..8d33610
--- /dev/null
@@ -0,0 +1,450 @@
+/*
+ * "$Id$"
+ *
+ *   File functions for the CUPS scheduler.
+ *
+ *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 1997-2007 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"
+ *   "LICENSE" which should have been included with this file.  If this
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
+ *
+ * Contents:
+ *
+ *   cupsdCleanFiles()           - Clean out old files.
+ *   cupsdCloseCreatedConfFile() - Close a created configuration file and move
+ *                                 into place.
+ *   cupsdClosePipe()            - Close a pipe as necessary.
+ *   cupsdCreateConfFile()       - Create a configuration file safely.
+ *   cupsdOpenConfFile()         - Open a configuration file.
+ *   cupsdOpenPipe()             - Create a pipe which is closed on exec.
+ *   cupsdRemoveFile()           - Remove a file using the 7-pass US DoD method.
+ *   overwrite_data()            - Overwrite the data in a file.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cupsd.h"
+#include <cups/dir.h>
+#include <fnmatch.h>
+#ifdef HAVE_REMOVEFILE
+#  include <removefile.h>
+#else
+static int     overwrite_data(int fd, const char *buffer, int bufsize,
+                              int filesize);
+#endif /* HAVE_REMOVEFILE */
+
+
+/*
+ * 'cupsdCleanFiles()' - Clean out old files.
+ */
+void
+cupsdCleanFiles(const char *path,      /* I - Directory to clean */
+                const char *pattern)   /* I - Filename pattern or NULL */
+{
+  cups_dir_t   *dir;                   /* Directory */
+  cups_dentry_t        *dent;                  /* Directory entry */
+  char         filename[1024];         /* Filename */
+  int          status;                 /* Status from unlink/rmdir */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG,
+                  "cupsdCleanFiles(path=\"%s\", pattern=\"%s\")", path,
+                 pattern ? pattern : "(null)");
+
+  if ((dir = cupsDirOpen(path)) == NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open directory \"%s\" - %s",
+                   path, strerror(errno));
+    return;
+  }
+
+  cupsdLogMessage(CUPSD_LOG_INFO, "Cleaning out old files in \"%s\"...", path);
+
+  while ((dent = cupsDirRead(dir)) != NULL)
+  {
+    if (pattern && fnmatch(pattern, dent->filename, 0))
+      continue;
+
+    snprintf(filename, sizeof(filename), "%s/%s", path, dent->filename);
+
+    if (S_ISDIR(dent->fileinfo.st_mode))
+    {
+      cupsdCleanFiles(filename, pattern);
+
+      status = rmdir(filename);
+    }
+    else
+      status = unlink(filename);
+
+    if (status)
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove \"%s\" - %s", filename,
+                     strerror(errno));
+    else
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Removed \"%s\"...", filename);
+  }
+
+  cupsDirClose(dir);
+}
+
+
+/*
+ * 'cupsdCloseCreatedConfFile()' - Close a created configuration file and move
+ *                                 into place.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsdCloseCreatedConfFile(
+    cups_file_t *fp,                   /* I - File to close */
+    const char  *filename)             /* I - Filename */
+{
+  char newfile[1024],                  /* filename.N */
+       oldfile[1024];                  /* filename.O */
+
+
+ /*
+  * First close the file...
+  */
+
+  if (cupsFileClose(fp))
+    return (-1);
+
+ /*
+  * Then remove "filename.O", rename "filename" to "filename.O", and rename
+  * "filename.N" to "filename".
+  */
+
+  snprintf(newfile, sizeof(newfile), "%s.N", filename);
+  snprintf(oldfile, sizeof(oldfile), "%s.O", filename);
+
+  if ((cupsdRemoveFile(oldfile) && errno != ENOENT) ||
+      (rename(filename, oldfile) && errno != ENOENT) ||
+      rename(newfile, filename))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to finalize \"%s\": %s",
+                    filename, strerror(errno));
+    return (-1);
+  }
+
+  return (0);
+}
+
+
+/*
+ * 'cupsdClosePipe()' - Close a pipe as necessary.
+ */
+
+void
+cupsdClosePipe(int *fds)               /* I - Pipe file descriptors (2) */
+{
+ /*
+  * Close file descriptors as needed...
+  */
+
+  if (fds[0] >= 0)
+  {
+    close(fds[0]);
+    fds[0] = -1;
+  }
+
+  if (fds[1] >= 0)
+  {
+    close(fds[1]);
+    fds[1] = -1;
+  }
+}
+
+
+/*
+ * 'cupsdCreateConfFile()' - Create a configuration file safely.
+ */
+
+cups_file_t *                          /* O - File pointer */
+cupsdCreateConfFile(
+    const char *filename,              /* I - Filename */
+    mode_t     mode)                   /* I - Permissions */
+{
+  cups_file_t  *fp;                    /* File pointer */
+  char         newfile[1024];          /* filename.N */
+
+
+  snprintf(newfile, sizeof(newfile), "%s.N", filename);
+  if ((fp = cupsFileOpen(newfile, "w")) == NULL)
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create \"%s\": %s", newfile,
+                   strerror(errno));
+  }
+  else
+  {
+    if (!getuid() && fchown(cupsFileNumber(fp), getuid(), Group))
+      cupsdLogMessage(CUPSD_LOG_WARN, "Unable to change group for \"%s\": %s",
+                     newfile, strerror(errno));
+
+    if (fchmod(cupsFileNumber(fp), mode))
+      cupsdLogMessage(CUPSD_LOG_WARN,
+                      "Unable to change permissions for \"%s\": %s",
+                     newfile, strerror(errno));
+  }
+
+  return (fp);
+}
+
+
+/*
+ * 'cupsdOpenConfFile()' - Open a configuration file.
+ *
+ * This function looks for "filename.O" if "filename" does not exist and does
+ * a rename as needed.
+ */
+
+cups_file_t *                          /* O - File pointer */
+cupsdOpenConfFile(const char *filename)        /* I - Filename */
+{
+  cups_file_t  *fp;                    /* File pointer */
+
+
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  {
+    if (errno == ENOENT)
+    {
+     /*
+      * Try opening the backup file...
+      */
+
+      char     oldfile[1024];          /* filename.O */
+
+      snprintf(oldfile, sizeof(oldfile), "%s.O", filename);
+      fp = cupsFileOpen(oldfile, "r");
+    }
+    else
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"%s\": %s", filename,
+                     strerror(errno));
+  }
+
+  return (fp);
+}
+
+
+/*
+ * 'cupsdOpenPipe()' - Create a pipe which is closed on exec.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsdOpenPipe(int *fds)                        /* O - Pipe file descriptors (2) */
+{
+ /*
+  * Create the pipe...
+  */
+
+  if (pipe(fds))
+  {
+    fds[0] = -1;
+    fds[1] = -1;
+
+    return (-1);
+  }
+
+ /*
+  * Set the "close on exec" flag on each end of the pipe...
+  */
+
+  if (fcntl(fds[0], F_SETFD, fcntl(fds[0], F_GETFD) | FD_CLOEXEC))
+  {
+    close(fds[0]);
+    close(fds[1]);
+
+    fds[0] = -1;
+    fds[1] = -1;
+
+    return (-1);
+  }
+
+  if (fcntl(fds[1], F_SETFD, fcntl(fds[1], F_GETFD) | FD_CLOEXEC))
+  {
+    close(fds[0]);
+    close(fds[1]);
+
+    fds[0] = -1;
+    fds[1] = -1;
+
+    return (-1);
+  }
+
+ /*
+  * Return 0 indicating success...
+  */
+
+  return (0);
+}
+
+
+/*
+ * 'cupsdRemoveFile()' - Remove a file using the 7-pass US DoD method.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsdRemoveFile(const char *filename)  /* I - File to remove */
+{
+#ifdef HAVE_REMOVEFILE
+  return (removefile(filename, NULL, REMOVEFILE_SECURE_7_PASS));
+
+#else
+  int                  fd;             /* File descriptor */
+  struct stat          info;           /* File information */
+  char                 buffer[512];    /* Data buffer */
+  int                  i;              /* Looping var */
+
+
+ /*
+  * First open the file for writing in exclusive mode.
+  */
+
+  if ((fd = open(filename, O_WRONLY | O_EXCL)) < 0)
+    return (-1);
+
+ /*
+  * Delete the file now - it will still be around as long as the file is
+  * open...
+  */
+
+  if (unlink(filename))
+  {
+    close(fd);
+    return (-1);
+  }
+
+ /*
+  * Then get the file size...
+  */
+
+  if (fstat(fd, &info))
+  {
+    close(fd);
+    return (-1);
+  }
+
+ /*
+  * Overwrite the file 7 times with 0xF6, 0x00, 0xFF, random, 0x00, 0xFF,
+  * and more random data.
+  */
+
+  memset(buffer, 0xF6, sizeof(buffer));
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  memset(buffer, 0x00, sizeof(buffer));
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  memset(buffer, 0xFF, sizeof(buffer));
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  CUPS_SRAND(time(NULL));
+
+  for (i = 0; i < sizeof(buffer); i ++)
+    buffer[i] = CUPS_RAND();
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  memset(buffer, 0x00, sizeof(buffer));
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  memset(buffer, 0xFF, sizeof(buffer));
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+  for (i = 0; i < sizeof(buffer); i ++)
+    buffer[i] = CUPS_RAND();
+  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+  {
+    close(fd);
+    return (-1);
+  }
+
+ /*
+  * Whew!  Close the file (which will lead to the actual deletion) and
+  * return success...
+  */
+
+  close(fd);
+  return (0);
+#endif /* HAVE_REMOVEFILE */
+}
+
+
+#ifndef HAVE_REMOVEFILE
+/*
+ * 'overwrite_data()' - Overwrite the data in a file.
+ */
+
+static int                             /* O - 0 on success, -1 on error */
+overwrite_data(int        fd,          /* I - File descriptor */
+               const char *buffer,     /* I - Buffer to write */
+              int        bufsize,      /* I - Size of buffer */
+               int        filesize)    /* I - Size of file */
+{
+  int  bytes;                          /* Bytes to write/written */
+
+
+ /*
+  * Start at the beginning of the file...
+  */
+
+  if (lseek(fd, 0, SEEK_SET) < 0)
+    return (-1);
+
+ /*
+  * Fill the file with the provided data...
+  */
+
+  while (filesize > 0)
+  {
+    if (filesize > bufsize)
+      bytes = bufsize;
+    else
+      bytes = filesize;
+
+    if ((bytes = write(fd, buffer, bytes)) < 0)
+      return (-1);
+
+    filesize -= bytes;
+  }
+
+ /*
+  * Force the changes to disk...
+  */
+
+  return (fsync(fd));
+}
+#endif /* HAVE_REMOVEFILE */
+
+
+/*
+ * End of "$Id$".
+ */
index a010e9fc3bd6322b253f451efd221419d67edf2a..eb469c92716a199fdc891f9e88902f61f8ef4b97 100644 (file)
@@ -1311,7 +1311,10 @@ cupsdDeleteJob(cupsd_job_t       *job,   /* I - Job */
 
     snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot,
             job->id);
-    unlink(filename);
+    if (Classification)
+      cupsdRemoveFile(filename);
+    else
+      unlink(filename);
   }
 
   cupsdClearString(&job->username);
@@ -1330,7 +1333,10 @@ cupsdDeleteJob(cupsd_job_t       *job,   /* I - Job */
     {
       snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
               job->id, job->num_files);
-      unlink(filename);
+      if (Classification)
+       cupsdRemoveFile(filename);
+      else
+       unlink(filename);
 
       job->num_files --;
     }
@@ -1830,7 +1836,10 @@ cupsdLoadJob(cupsd_job_t *job)           /* I - Job */
 
   job->num_files = 0;
 
-  unlink(jobfile);
+  if (Classification)
+    cupsdRemoveFile(jobfile);
+  else
+    unlink(jobfile);
 
   return (0);
 }
@@ -1945,30 +1954,19 @@ void
 cupsdSaveAllJobs(void)
 {
   int          i;                      /* Looping var */
-  cups_file_t  *fp;                    /* Job cache file */
-  char         temp[1024];             /* Temporary string */
+  cups_file_t  *fp;                    /* job.cache file */
+  char         filename[1024],         /* job.cache filename */
+               temp[1024];             /* Temporary string */
   cupsd_job_t  *job;                   /* Current job */
   time_t       curtime;                /* Current time */
   struct tm    *curdate;               /* Current date */
 
 
-  snprintf(temp, sizeof(temp), "%s/job.cache", CacheDir);
-  if ((fp = cupsFileOpen(temp, "w")) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to create job cache file \"%s\" - %s",
-                    temp, strerror(errno));
+  snprintf(filename, sizeof(filename), "%s/job.cache", CacheDir);
+  if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm)) == NULL)
     return;
-  }
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "Saving job cache file \"%s\"...", temp);
-
- /*
-  * Restrict access to the file...
-  */
-
-  fchown(cupsFileNumber(fp), getuid(), Group);
-  fchmod(cupsFileNumber(fp), ConfigFilePerm);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Saving job.cache...", filename);
 
  /*
   * Write a small header to the file...
@@ -2004,7 +2002,7 @@ cupsdSaveAllJobs(void)
     cupsFilePuts(fp, "</Job>\n");
   }
 
-  cupsFileClose(fp);
+  cupsdCloseCreatedConfFile(fp, filename);
 }
 
 
@@ -2468,7 +2466,10 @@ cupsdSetJobState(
          {
            snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
                     job->id, i);
-           unlink(filename);
+           if (Classification)
+             cupsdRemoveFile(filename);
+           else
+             unlink(filename);
          }
 
          if (job->num_files > 0)
@@ -3641,15 +3642,9 @@ load_job_cache(const char *filename)     /* I - job.cache filename */
   * Open the job.cache file...
   */
 
-  if ((fp = cupsFileOpen(filename, "r")) == NULL)
+  if ((fp = cupsdOpenConfFile(filename)) == NULL)
   {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to open job cache file \"%s\": %s",
-                      filename, strerror(errno));
-
     load_request_root();
-
     return;
   }
 
index 4c429059d8537ca44e2fe0aa366e82c263184404..ce309013c4dd809060557b940bab4d2d7c500982 100644 (file)
  *   cupsdAddString()      - Copy and add a string to an array.
  *   cupsdCheckProcess()   - Tell the main loop to check for dead children.
  *   cupsdClearString()    - Clear a string.
- *   cupsdClosePipe()      - Close a pipe as necessary.
  *   cupsdFreeStrings()    - Free an array of strings.
  *   cupsdHoldSignals()    - Hold child and termination signals.
- *   cupsdOpenPipe()       - Create a pipe which is closed on exec.
  *   cupsdReleaseSignals() - Release signals for delivery.
  *   cupsdSetString()      - Set a string value.
  *   cupsdSetStringf()     - Set a formatted string value.
- *   cupsd_clean_files()   - Clean out old files.
  *   launchd_checkin()     - Check-in with launchd and collect the listening
  *                           fds.
  *   launchd_checkout()    - Update the launchd KeepAlive file as needed.
@@ -48,8 +45,6 @@
 #include <sys/resource.h>
 #include <syslog.h>
 #include <grp.h>
-#include <cups/dir.h>
-#include <fnmatch.h>
 
 #ifdef HAVE_LAUNCH_H
 #  include <launch.h>
@@ -79,8 +74,6 @@
  * Local functions...
  */
 
-static void            cupsd_clean_files(const char *path,
-                                         const char *pattern);
 #ifdef HAVE_LAUNCHD
 static void            launchd_checkin(void);
 static void            launchd_checkout(void);
@@ -510,9 +503,9 @@ main(int  argc,                             /* I - Number of command-line args */
   */
 
   if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)))
-    cupsd_clean_files(TempDir, NULL);
+    cupsdCleanFiles(TempDir, NULL);
 
-  cupsd_clean_files(CacheDir, "*.ipp");
+  cupsdCleanFiles(CacheDir, "*.ipp");
 
 #if HAVE_LAUNCHD
   if (Launchd)
@@ -1231,31 +1224,6 @@ cupsdClearString(char **s)               /* O - String value */
 }
 
 
-/*
- * 'cupsdClosePipe()' - Close a pipe as necessary.
- */
-
-void
-cupsdClosePipe(int *fds)               /* I - Pipe file descriptors (2) */
-{
- /*
-  * Close file descriptors as needed...
-  */
-
-  if (fds[0] >= 0)
-  {
-    close(fds[0]);
-    fds[0] = -1;
-  }
-
-  if (fds[1] >= 0)
-  {
-    close(fds[1]);
-    fds[1] = -1;
-  }
-}
-
-
 /*
  * 'cupsdFreeStrings()' - Free an array of strings.
  */
@@ -1299,59 +1267,6 @@ cupsdHoldSignals(void)
 }
 
 
-/*
- * 'cupsdOpenPipe()' - Create a pipe which is closed on exec.
- */
-
-int                                    /* O - 0 on success, -1 on error */
-cupsdOpenPipe(int *fds)                        /* O - Pipe file descriptors (2) */
-{
- /*
-  * Create the pipe...
-  */
-
-  if (pipe(fds))
-  {
-    fds[0] = -1;
-    fds[1] = -1;
-
-    return (-1);
-  }
-
- /*
-  * Set the "close on exec" flag on each end of the pipe...
-  */
-
-  if (fcntl(fds[0], F_SETFD, fcntl(fds[0], F_GETFD) | FD_CLOEXEC))
-  {
-    close(fds[0]);
-    close(fds[1]);
-
-    fds[0] = -1;
-    fds[1] = -1;
-
-    return (-1);
-  }
-
-  if (fcntl(fds[1], F_SETFD, fcntl(fds[1], F_GETFD) | FD_CLOEXEC))
-  {
-    close(fds[0]);
-    close(fds[1]);
-
-    fds[0] = -1;
-    fds[1] = -1;
-
-    return (-1);
-  }
-
- /*
-  * Return 0 indicating success...
-  */
-
-  return (0);
-}
-
-
 /*
  * 'cupsdReleaseSignals()' - Release signals for delivery.
  */
@@ -1428,60 +1343,6 @@ cupsdSetStringf(char       **s,          /* O - New string */
 }
 
 
-/*
- * 'cupsd_clean_files()' - Clean out old files.
- */
-static void
-cupsd_clean_files(const char *path,    /* I - Directory to clean */
-                  const char *pattern) /* I - Filename pattern or NULL */
-{
-  cups_dir_t   *dir;                   /* Directory */
-  cups_dentry_t        *dent;                  /* Directory entry */
-  char         filename[1024];         /* Filename */
-  int          status;                 /* Status from unlink/rmdir */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG,
-                  "cupsd_clean_files(path=\"%s\", pattern=\"%s\")", path,
-                 pattern ? pattern : "(null)");
-
-  if ((dir = cupsDirOpen(path)) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open directory \"%s\" - %s",
-                   path, strerror(errno));
-    return;
-  }
-
-  cupsdLogMessage(CUPSD_LOG_INFO, "Cleaning out old files in \"%s\"...", path);
-
-  while ((dent = cupsDirRead(dir)) != NULL)
-  {
-    if (pattern && fnmatch(pattern, dent->filename, 0))
-      continue;
-
-    snprintf(filename, sizeof(filename), "%s/%s", path, dent->filename);
-
-    if (S_ISDIR(dent->fileinfo.st_mode))
-    {
-      cupsd_clean_files(filename, pattern);
-
-      status = rmdir(filename);
-    }
-    else
-      status = unlink(filename);
-
-    if (status)
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to remove \"%s\" - %s", filename,
-                     strerror(errno));
-    else
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "Removed \"%s\"...", filename);
-  }
-
-  cupsDirClose(dir);
-}
-
-
 #ifdef HAVE_LAUNCHD
 /*
  * 'launchd_checkin()' - Check-in with launchd and collect the listening fds.
index e664509e2b8da154f807339a8314e9aaece941d4..f47b10bc666b63552b0b3c940afbefb4c34dc6cc 100644 (file)
@@ -955,13 +955,8 @@ cupsdLoadAllPrinters(void)
   */
 
   snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
-  if ((fp = cupsFileOpen(line, "r")) == NULL)
-  {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
-                     strerror(errno));
+  if ((fp = cupsdOpenConfFile(line)) == NULL)
     return;
-  }
 
  /*
   * Read printer configurations until we hit EOF...
@@ -1455,8 +1450,8 @@ cupsdSaveAllPrinters(void)
 {
   int                  i;              /* Looping var */
   cups_file_t          *fp;            /* printers.conf file */
-  char                 temp[1024],     /* Temporary string */
-                       backup[1024],   /* printers.conf.O file */
+  char                 filename[1024], /* printers.conf filename */
+                       temp[1024],     /* Temporary string */
                        value[2048],    /* Value string */
                        *ptr,           /* Pointer into value */
                        *name;          /* Current user/group name */
@@ -1471,35 +1466,12 @@ cupsdSaveAllPrinters(void)
   * Create the printers.conf file...
   */
 
-  snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
-  snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);
-
-  if (rename(temp, backup))
-  {
-    if (errno != ENOENT)
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to backup printers.conf - %s", strerror(errno));
-  }
-
-  if ((fp = cupsFileOpen(temp, "w")) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "Unable to save printers.conf - %s", strerror(errno));
+  snprintf(filename, sizeof(filename), "%s/printers.conf", ServerRoot);
 
-    if (rename(backup, temp))
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to restore printers.conf - %s", strerror(errno));
+  if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm & 0600)) == NULL)
     return;
-  }
-  else
-    cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
 
- /*
-  * Restrict access to the file...
-  */
-
-  fchown(cupsFileNumber(fp), getuid(), Group);
-  fchmod(cupsFileNumber(fp), ConfigFilePerm & 0600);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
 
  /*
   * Write a small header to the file...
@@ -1754,7 +1726,7 @@ cupsdSaveAllPrinters(void)
 #endif /* __sgi */
   }
 
-  cupsFileClose(fp);
+  cupsdCloseCreatedConfFile(fp, filename);
 }
 
 
diff --git a/scheduler/removefile.c b/scheduler/removefile.c
deleted file mode 100644 (file)
index d1a10f7..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * "$Id$"
- *
- *   "Secure" file removal function for the CUPS scheduler.
- *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2007 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"
- *   "LICENSE" which should have been included with this file.  If this
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   cupsdRemoveFile() - Remove a file using the 7-pass US DoD method.
- *   overwrite_data()  - Overwrite the data in a file.
- */
-
-/*
- * Include necessary headers...
- */
-
-#include "cupsd.h"
-#ifdef HAVE_REMOVEFILE
-#  include <removefile.h>
-#else
-static int     overwrite_data(int fd, const char *buffer, int bufsize,
-                              int filesize);
-#endif /* HAVE_REMOVEFILE */
-
-
-/*
- * 'cupsdRemoveFile()' - Remove a file using the 7-pass US DoD method.
- */
-
-int                                    /* O - 0 on success, -1 on error */
-cupsdRemoveFile(const char *filename)  /* I - File to remove */
-{
-#ifdef HAVE_REMOVEFILE
-  int                  ret;            /* Return value */
-  removefile_state_t   s;              /* Remove state variable */
-
-
-  s   = removefile_state_alloc();
-  ret = removefile(filename, s, REMOVEFILE_SECURE_7_PASS);
-
-  removefile_state_free(s);
-
-  return (ret);
-
-#else
-  int                  fd;             /* File descriptor */
-  struct stat          info;           /* File information */
-  char                 buffer[512];    /* Data buffer */
-  int                  i;              /* Looping var */
-
-
- /*
-  * First open the file for writing in exclusive mode.
-  */
-
-  if ((fd = open(filename, O_WRONLY | O_EXCL)) < 0)
-    return (-1);
-
- /*
-  * Delete the file now - it will still be around as long as the file is
-  * open...
-  */
-
-  unlink(filename);
-
- /*
-  * Then get the file size...
-  */
-
-  if (fstat(fd, &info))
-  {
-    close(fd);
-    return (-1);
-  }
-
- /*
-  * Overwrite the file 7 times with 0xF6, 0x00, 0xFF, random, 0x00, 0xFF,
-  * and more random data.
-  */
-
-  memset(buffer, 0xF6, sizeof(buffer));
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  memset(buffer, 0x00, sizeof(buffer));
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  memset(buffer, 0xFF, sizeof(buffer));
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  CUPS_SRAND(time(NULL));
-
-  for (i = 0; i < sizeof(buffer); i ++)
-    buffer[i] = CUPS_RAND();
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  memset(buffer, 0x00, sizeof(buffer));
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  memset(buffer, 0xFF, sizeof(buffer));
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
-  for (i = 0; i < sizeof(buffer); i ++)
-    buffer[i] = CUPS_RAND();
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
-  {
-    close(fd);
-    return (-1);
-  }
-
- /*
-  * Whew!  Close the file (which will lead to the actual deletion) and
-  * return success...
-  */
-
-  close(fd);
-  return (0);
-#endif /* HAVE_REMOVEFILE */
-}
-
-
-#ifndef HAVE_REMOVEFILE
-/*
- * 'overwrite_data()' - Overwrite the data in a file.
- */
-
-static int                             /* O - 0 on success, -1 on error */
-overwrite_data(int        fd,          /* I - File descriptor */
-               const char *buffer,     /* I - Buffer to write */
-              int        bufsize,      /* I - Size of buffer */
-               int        filesize)    /* I - Size of file */
-{
-  int  bytes;                          /* Bytes to write/written */
-
-
- /*
-  * Start at the beginning of the file...
-  */
-
-  if (lseek(fd, 0, SEEK_SET) < 0)
-    return (-1);
-
- /*
-  * Fill the file with the provided data...
-  */
-
-  while (filesize > 0)
-  {
-    if (filesize > bufsize)
-      bytes = bufsize;
-    else
-      bytes = filesize;
-
-    if ((bytes = write(fd, buffer, bytes)) < 0)
-      return (-1);
-
-    filesize -= bytes;
-  }
-
- /*
-  * Force the changes to disk...
-  */
-
-  return (fsync(fd));
-}
-#endif /* HAVE_REMOVEFILE */
-
-
-#ifdef TEST
-#  define testmain main
-int
-testmain(void)
-{
-  FILE *fp;
-
-
-  fp = fopen("testfile.secure", "w");
-  fputs("Hello, World!\n", fp);
-  fputs("Now is the time for all good men to come to the aid of their "
-        "country.\n", fp);
-  fclose(fp);
-
-  if (cupsdRemoveFile("testfile.secure"))
-  {
-    printf("cupsdRemoveFile: FAIL (%s)\n", strerror(errno));
-    return (1);
-  }
-  else
-  {
-    puts("cupsdRemoveFile: PASS");
-    return (0);
-  }
-}
-#endif /* TEST */
-
-
-/*
- * End of "$Id$".
- */
index 208f545d7a5af7c163fb7a439cee6ea3664b94e1..f9511ed7e22996bfeff30ca4f31dd2e3915b1f7b 100644 (file)
                72220F9F13330B0C00FCA411 /* printers.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8313330B0C00FCA411 /* printers.c */; };
                72220FA013330B0C00FCA411 /* process.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8513330B0C00FCA411 /* process.c */; };
                72220FA113330B0C00FCA411 /* quotas.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8613330B0C00FCA411 /* quotas.c */; };
-               72220FA213330B0C00FCA411 /* removefile.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8713330B0C00FCA411 /* removefile.c */; };
                72220FA313330B0C00FCA411 /* select.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8813330B0C00FCA411 /* select.c */; };
                72220FA413330B0C00FCA411 /* server.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8913330B0C00FCA411 /* server.c */; };
                72220FA513330B0C00FCA411 /* statbuf.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220F8A13330B0C00FCA411 /* statbuf.c */; };
                726AD70D135E8B11002C930D /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220F4C133306BB00FCA411 /* SystemConfiguration.framework */; };
                726AD70E135E8B5E002C930D /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220F51133308C100FCA411 /* libiconv.dylib */; };
                7271883D1374AB14001A2036 /* mime-private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7271883C1374AB14001A2036 /* mime-private.h */; };
+               72C16CB9137B195D007E4BF4 /* file.c in Sources */ = {isa = PBXBuildFile; fileRef = 72C16CB8137B195D007E4BF4 /* file.c */; };
                72F75A5C1336F988004BB496 /* cupstestppd.c in Sources */ = {isa = PBXBuildFile; fileRef = 72F75A5B1336F988004BB496 /* cupstestppd.c */; };
                72F75A671336FA38004BB496 /* libcups.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups.dylib */; };
                72F75A6C1336FA8A004BB496 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 72F75A691336FA8A004BB496 /* error.c */; };
                72220F8413330B0C00FCA411 /* printers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = printers.h; path = ../scheduler/printers.h; sourceTree = SOURCE_ROOT; };
                72220F8513330B0C00FCA411 /* process.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = process.c; path = ../scheduler/process.c; sourceTree = SOURCE_ROOT; };
                72220F8613330B0C00FCA411 /* quotas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = quotas.c; path = ../scheduler/quotas.c; sourceTree = SOURCE_ROOT; };
-               72220F8713330B0C00FCA411 /* removefile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = removefile.c; path = ../scheduler/removefile.c; sourceTree = SOURCE_ROOT; };
                72220F8813330B0C00FCA411 /* select.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = select.c; path = ../scheduler/select.c; sourceTree = SOURCE_ROOT; };
                72220F8913330B0C00FCA411 /* server.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = server.c; path = ../scheduler/server.c; sourceTree = SOURCE_ROOT; };
                72220F8A13330B0C00FCA411 /* statbuf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = statbuf.c; path = ../scheduler/statbuf.c; sourceTree = SOURCE_ROOT; };
                7271883A137498E4001A2036 /* image.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = image.c; path = ../filter/image.c; sourceTree = "<group>"; };
                7271883B137498E4001A2036 /* image.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = image.h; path = ../filter/image.h; sourceTree = "<group>"; };
                7271883C1374AB14001A2036 /* mime-private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "mime-private.h"; path = "../scheduler/mime-private.h"; sourceTree = "<group>"; };
+               72C16CB8137B195D007E4BF4 /* file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = file.c; path = ../scheduler/file.c; sourceTree = SOURCE_ROOT; };
                72F75A4C1336F31B004BB496 /* libcups_static.a */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libcups_static.a; sourceTree = BUILT_PRODUCTS_DIR; };
                72F75A521336F950004BB496 /* cupstestppd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cupstestppd; sourceTree = BUILT_PRODUCTS_DIR; };
                72F75A5B1336F988004BB496 /* cupstestppd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cupstestppd.c; path = ../systemv/cupstestppd.c; sourceTree = "<group>"; };
                                72220F7613330B0C00FCA411 /* dirsvc.c */,
                                72220F7713330B0C00FCA411 /* dirsvc.h */,
                                72220F7813330B0C00FCA411 /* env.c */,
+                               72C16CB8137B195D007E4BF4 /* file.c */,
                                72220F7913330B0C00FCA411 /* ipp.c */,
                                72220F7A13330B0C00FCA411 /* job.c */,
                                72220F7B13330B0C00FCA411 /* job.h */,
                                72220F8413330B0C00FCA411 /* printers.h */,
                                72220F8513330B0C00FCA411 /* process.c */,
                                72220F8613330B0C00FCA411 /* quotas.c */,
-                               72220F8713330B0C00FCA411 /* removefile.c */,
                                72220F8813330B0C00FCA411 /* select.c */,
                                72220F8913330B0C00FCA411 /* server.c */,
                                72220F8A13330B0C00FCA411 /* statbuf.c */,
                                72220F9F13330B0C00FCA411 /* printers.c in Sources */,
                                72220FA013330B0C00FCA411 /* process.c in Sources */,
                                72220FA113330B0C00FCA411 /* quotas.c in Sources */,
-                               72220FA213330B0C00FCA411 /* removefile.c in Sources */,
                                72220FA313330B0C00FCA411 /* select.c in Sources */,
                                72220FA413330B0C00FCA411 /* server.c in Sources */,
                                72220FA513330B0C00FCA411 /* statbuf.c in Sources */,
                                72220FA613330B0C00FCA411 /* subscriptions.c in Sources */,
                                72220FA713330B0C00FCA411 /* sysman.c in Sources */,
+                               72C16CB9137B195D007E4BF4 /* file.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };