]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Create the CUPS log directory as needed (STR #2353)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 30 Apr 2007 18:09:30 +0000 (18:09 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 30 Apr 2007 18:09:30 +0000 (18:09 +0000)
scheduler/conf.c:
    - cupsdCheckPermissions(): Added.
    - cupsdReadConfiguration(): Call the new function.
    - check_permissions(): Removed.

scheduler/conf.h:
    - Add prototype for cupsdCheckPermissions().

scheduler/log.c:
    - check_log_file(): Call cupsdCheckPermissions() if the log
      file is in CUPS_LOGDIR.

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

CHANGES.txt
scheduler/conf.c
scheduler/conf.h
scheduler/log.c

index f5b0e3d9b475b811235f8ff259fa630b41e6be94..15bfca5404ec83170d3e191e31800d2a9937176f 100644 (file)
@@ -1,10 +1,12 @@
-CHANGES.txt - 2007-04-25
+CHANGES.txt - 2007-04-30
 ------------------------
 
 CHANGES IN CUPS V1.3
 
        - Documentation updates (STR #1775, STR #2130, STR #2131,
          STR #2356)
+       - The scheduler now recreates the CUPS log directory as
+         needed (STR #2353)
        - cupsLangDefault() now maps new-style Apple locale names
          to the traditional ll_CC form (STR #2357)
         - Add new cupsArrayNew2() API to support hashed lookups
index f9ff5aaa38d3d07e656df7cc2a6945b3f93d4ebb..dd1b9aa786b5003191582f40fe0118ef4790bbf0 100644 (file)
@@ -23,9 +23,9 @@
  *
  * Contents:
  *
- *   cupsdReadConfiguration() - Read the cupsd.conf file.
- *   check_permissions()      - Fix the mode and ownership of a file or
+ *   cupsdCheckPermissions()  - Fix the mode and ownership of a file or
  *                              directory.
+ *   cupsdReadConfiguration() - Read the cupsd.conf file.
  *   get_address()            - Get an address + port number from a line.
  *   get_addr_and_mask()      - Get an IP address and netmask.
  *   parse_aaa()              - Parse authentication, authorization, and
@@ -197,10 +197,6 @@ static unsigned            zeros[4] =
 /*
  * Local functions...
  */
-static int             check_permissions(const char *filename,
-                                         const char *suffix, int mode,
-                                         int user, int group, int is_dir,
-                                         int create_dir);
 static http_addrlist_t *get_address(const char *value, int defport);
 static int             get_addr_and_mask(const char *value, unsigned *ip,
                                          unsigned *mask);
@@ -213,6 +209,115 @@ static int                read_location(cups_file_t *fp, char *name, int linenum);
 static int             read_policy(cups_file_t *fp, char *name, int linenum);
 
 
+/*
+ * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
+ */
+
+int                                    /* O - 0 on success, -1 on error, 1 on warning */
+cupsdCheckPermissions(
+    const char *filename,              /* I - File/directory name */
+    const char *suffix,                        /* I - Additional file/directory name */
+    int        mode,                   /* I - Permissions */
+    int        user,                   /* I - Owner */
+    int        group,                  /* I - Group */
+    int        is_dir,                 /* I - 1 = directory, 0 = file */
+    int        create_dir)             /* I - 1 = create directory, 0 = not */
+{
+  int          dir_created = 0;        /* Did we create a directory? */
+  char         pathname[1024];         /* File name with prefix */
+  struct stat  fileinfo;               /* Stat buffer */
+
+
+ /*
+  * Prepend the given root to the filename before testing it...
+  */
+
+  if (suffix)
+  {
+    snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
+    filename = pathname;
+  }
+
+ /*
+  * See if we can stat the file/directory...
+  */
+
+  if (stat(filename, &fileinfo))
+  {
+    if (errno == ENOENT && create_dir)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"",
+                      filename);
+
+      if (mkdir(filename, mode))
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to create directory \"%s\" - %s", filename,
+                       strerror(errno));
+        return (-1);
+      }
+
+      dir_created = 1;
+    }
+    else
+      return (create_dir ? -1 : 1);
+  }
+
+ /*
+  * Make sure it's a regular file...
+  */
+
+  if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename);
+    return (-1);
+  }
+
+  if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename);
+    return (-1);
+  }
+
+ /*
+  * Fix owner, group, and mode as needed...
+  */
+
+  if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"", filename);
+
+    if (chown(filename, user, group) && !getuid())
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to change ownership of \"%s\" - %s", filename,
+                     strerror(errno));
+      return (1);
+    }
+  }
+
+  if (dir_created || (fileinfo.st_mode & 07777) != mode)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"",
+                    filename);
+
+    if (chmod(filename, mode))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to change permissions of \"%s\" - %s", filename,
+                     strerror(errno));
+      return (1);
+    }
+  }
+
+ /*
+  * Everything is OK...
+  */
+
+  return (0);
+}
+
+
 /*
  * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
  */
@@ -658,20 +763,28 @@ cupsdReadConfiguration(void)
   * writable by the user and group in the cupsd.conf file...
   */
 
-  if (check_permissions(CacheDir, NULL, 0775, RunUser, Group, 1, 1) < 0 ||
-      check_permissions(StateDir, NULL, 0755, RunUser, Group, 1, 1) < 0 ||
-      check_permissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
-                       SystemGroupIDs[0], 1, 1) < 0 ||
-      check_permissions(ServerRoot, NULL, 0755, RunUser, Group, 1, 0) < 0 ||
-      check_permissions(ServerRoot, "ppd", 0755, RunUser, Group, 1, 1) < 0 ||
-      check_permissions(ServerRoot, "ssl", 0700, RunUser, Group, 1, 0) < 0 ||
-      check_permissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
-                        Group, 0, 0) < 0 ||
-      check_permissions(ServerRoot, "classes.conf", 0600, RunUser, Group,
-                        0, 0) < 0 ||
-      check_permissions(ServerRoot, "printers.conf", 0600, RunUser, Group,
-                        0, 0) < 0 ||
-      check_permissions(ServerRoot, "passwd.md5", 0600, User, Group, 0, 0) < 0)
+  if (cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser,
+                           Group, 1, 1) < 0 ||
+      cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser,
+                           Group, 1, 1) < 0 ||
+      cupsdCheckPermissions(StateDir, NULL, 0755, RunUser,
+                           Group, 1, 1) < 0 ||
+      cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
+                           SystemGroupIDs[0], 1, 1) < 0 ||
+      cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser, 
+                           Group, 1, 0) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser,
+                           Group, 1, 1) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser,
+                           Group, 1, 0) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
+                           Group, 0, 0) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser,
+                           Group, 0, 0) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser,
+                           Group, 0, 0) < 0 ||
+      cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User,
+                           Group, 0, 0) < 0)
     return (0);
 
  /*
@@ -710,13 +823,9 @@ cupsdReadConfiguration(void)
   }
 
  /*
-  * Make sure the request and temporary directories have the right
-  * permissions...
+  * Make sure the temporary directory has the right permissions...
   */
 
-  if (check_permissions(RequestRoot, NULL, 0710, RunUser, Group, 1, 1) < 0)
-    return (0);
-
   if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) ||
       access(TempDir, 0))
   {
@@ -725,7 +834,7 @@ cupsdReadConfiguration(void)
     * is under the spool directory or does not exist...
     */
 
-    if (check_permissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0)
+    if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0)
       return (0);
   }
 
@@ -1132,114 +1241,6 @@ cupsdReadConfiguration(void)
 }
 
 
-/*
- * 'check_permissions()' - Fix the mode and ownership of a file or directory.
- */
-
-static int                             /* O - 0 on success, -1 on error, 1 on warning */
-check_permissions(const char *filename,        /* I - File/directory name */
-                  const char *suffix,  /* I - Additional file/directory name */
-                  int        mode,     /* I - Permissions */
-                 int        user,      /* I - Owner */
-                 int        group,     /* I - Group */
-                 int        is_dir,    /* I - 1 = directory, 0 = file */
-                 int        create_dir)/* I - 1 = create directory, 0 = not */
-{
-  int          dir_created = 0;        /* Did we create a directory? */
-  char         pathname[1024];         /* File name with prefix */
-  struct stat  fileinfo;               /* Stat buffer */
-
-
- /*
-  * Prepend the given root to the filename before testing it...
-  */
-
-  if (suffix)
-  {
-    snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
-    filename = pathname;
-  }
-
- /*
-  * See if we can stat the file/directory...
-  */
-
-  if (stat(filename, &fileinfo))
-  {
-    if (errno == ENOENT && create_dir)
-    {
-      cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"",
-                      filename);
-
-      if (mkdir(filename, mode))
-      {
-        cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to create directory \"%s\" - %s", filename,
-                       strerror(errno));
-        return (-1);
-      }
-
-      dir_created = 1;
-    }
-    else
-      return (create_dir ? -1 : 1);
-  }
-
- /*
-  * Make sure it's a regular file...
-  */
-
-  if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename);
-    return (-1);
-  }
-
-  if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename);
-    return (-1);
-  }
-
- /*
-  * Fix owner, group, and mode as needed...
-  */
-
-  if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"", filename);
-
-    if (chown(filename, user, group) && !getuid())
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to change ownership of \"%s\" - %s", filename,
-                     strerror(errno));
-      return (1);
-    }
-  }
-
-  if (dir_created || (fileinfo.st_mode & 07777) != mode)
-  {
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"",
-                    filename);
-
-    if (chmod(filename, mode))
-    {
-      cupsdLogMessage(CUPSD_LOG_ERROR,
-                      "Unable to change permissions of \"%s\" - %s", filename,
-                     strerror(errno));
-      return (1);
-    }
-  }
-
- /*
-  * Everything is OK...
-  */
-
-  return (0);
-}
-
-
 /*
  * 'get_address()' - Get an address + port number from a line.
  */
index 5fe6b41d466b23402a83fede9a07bb9fef63e327..242f0516b1f3cd164cbd2f9d7843376be60462b9 100644 (file)
@@ -218,8 +218,11 @@ VAR char           *SystemGroupAuthKey     VALUE(NULL);
  * Prototypes...
  */
 
+extern int     cupsdCheckPermissions(const char *filename,
+                                     const char *suffix, int mode,
+                                     int user, int group, int is_dir,
+                                     int create_dir);
 extern char    *cupsdGetDateTime(time_t t);
-extern int     cupsdReadConfiguration(void);
 #ifdef HAVE_GSSAPI
 extern int     cupsdLogGSSMessage(int level, int major_status,
                                   int minor_status,
@@ -232,6 +235,7 @@ __attribute__ ((__format__ (__printf__, 2, 3)))
 ;
 extern int     cupsdLogPage(cupsd_job_t *job, const char *page);
 extern int     cupsdLogRequest(cupsd_client_t *con, http_status_t code);
+extern int     cupsdReadConfiguration(void);
 
 
 /*
index ecfa8751c65a6411cb16c2a231b0e260f85ff51d..353deb456c154f758dcf52d1b0145b4327d62d65 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Log file routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -546,10 +546,23 @@ check_log_file(cups_file_t **lf,  /* IO - Log file */
 
     if ((*lf = cupsFileOpen(filename, "a")) == NULL)
     {
-      syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
-             strerror(errno));
+     /*
+      * If the file is in CUPS_LOGDIR then try to create a missing directory...
+      */
 
-      return (0);
+      if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR)))
+      {
+        cupsdCheckPermissions(CUPS_LOGDIR, NULL, 0755, RunUser, Group, 1, 1);
+
+        *lf = cupsFileOpen(filename, "a");
+      }
+
+      if (*lf == NULL)
+      {
+       syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
+              strerror(errno));
+       return (0);
+      }
     }
 
     if (strncmp(filename, "/dev/", 5))