]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add CacheDir support and fix some web interface and authentication issues.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 1 Sep 2005 20:51:08 +0000 (20:51 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 1 Sep 2005 20:51:08 +0000 (20:51 +0000)
cgi-bin/admin.c:
    - do_am_printer(): Set ppd-make or requested-attributes when
      showing the lists of makes and models; this is a lot more
      efficient...

cgi-bin/ipp-var.c:
    - ippSetCGIVars(): Add debug fprintf's.

scheduler/auth.c:
    - cupsdCheckGroup(): Added.
    - IsAuthorized(): Use new cupsdCheckGroup(), support @SYSTEM
      group name when doing lookups, and use case-insensitive
      comparisons for user and group names.

scheduler/auth.h:
    - Add cupsdCheckGroup() function and <pwd.h> include.

scheduler/client.c:
    - pipe_command(): Add CUPS_CACHEDIR env var.

scheduler/conf.c:
    - ReadConfiguration(): Add CacheDir support and use @SYSTEM
      instead of listing every system group.
    - read_configuration(): Add CacheDir support, and use @SYSTEM
      instead of listing every system group.

scheduler/conf.h:
    - Add CacheDir variable.

scheduler/cups-driverd.c:
    - main(): Fix command-line processing.
    - list_ppds(): Add debug fprintf's.

scheduler/ipp.c:
    - check_quotas(): Use cupsdCheckGroup() function.
    - get_ppds(): ppd-make is a text attribute, not a keyword
      attribute.
    - get_ppds(): Use URI escaping for spaces.
    - user_allowed(): Use cupsdCheckGroup() function.

scheduler/job.c:
    - StartJob(): Add CUPS_CACHEDIR env var.

scheduler/policy.c:
    - check_group(): Removed.
    - check_ok(): Use cupsdCheckGroup() function.

scheduler/util.c:
    - cupsdSendIPPHeader(): Status code is only 2 bytes, not 4.

test/run-stp-tests.sh:
    - Add CacheDir to sample config file.

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

13 files changed:
cgi-bin/admin.c
cgi-bin/ipp-var.c
scheduler/auth.c
scheduler/auth.h
scheduler/client.c
scheduler/conf.c
scheduler/conf.h
scheduler/cups-driverd.c
scheduler/ipp.c
scheduler/job.c
scheduler/policy.c
scheduler/util.c
test/run-stp-tests.sh

index 0770a8a4db0ee47962a30e31d8acd6679bafb546..576b59409b6cd444524b7a745301e25af5219844 100644 (file)
@@ -858,6 +858,14 @@ do_am_printer(http_t      *http,   /* I - HTTP connection */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, "ipp://localhost/printers/");
 
+
+    if ((var = cgiGetVariable("PPD_MAKE")) != NULL)
+      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT,
+                   "ppd-make", NULL, var);
+    else
+      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+                   "requested-attributes", NULL, "ppd-make");
+
    /*
     * Do the request and get back a response...
     */
@@ -868,16 +876,7 @@ do_am_printer(http_t      *http,   /* I - HTTP connection */
       * Got the list of PPDs, see if the user has selected a make...
       */
 
-      if ((var = cgiGetVariable("PPD_MAKE")) != NULL)
-      {
-       /*
-        * Yes, copy those attributes, but check if the make doesn't
-       * exist...
-       */
-
-        if (ippSetCGIVars(response, "ppd-make", var, NULL, 0) <= 0)
-         var = NULL;
-      }
+      ippSetCGIVars(response, NULL, NULL, NULL, 0);
 
       if (var == NULL)
       {
index 95d2105b55287b6b49eee049c748977ffb56cb29..24870fc95c0f39bed3a9e5426ee48330200b05a3 100644 (file)
@@ -357,9 +357,9 @@ ippSetCGIVars(ipp_t      *response, /* I - Response data to be copied... */
   struct tm            *date;          /* Date information */
 
 
-  DEBUG_printf(("<P>ippSetCGIVars(response=%p, filter_name=\"%s\", filter_value=\"%s\", prefix=\"%s\")\n",
-                response, filter_name, filter_value, prefix));
-  
+  fprintf(stderr, "DEBUG2: ippSetCGIVars(response=%p, filter_name=\"%s\", filter_value=\"%s\", prefix=\"%s\", parent_el=%d)\n",
+          response, filter_name, filter_value, prefix, parent_el);
+
  /*
   * Set common CGI template variables...
   */
@@ -375,7 +375,7 @@ ippSetCGIVars(ipp_t      *response, /* I - Response data to be copied... */
 
   if (!prefix)
     while (attr && attr->group_tag == IPP_TAG_OPERATION)
-     attr = attr->next;
+      attr = attr->next;
 
   for (element = parent_el; attr != NULL; attr = attr->next, element ++)
   {
@@ -388,12 +388,12 @@ ippSetCGIVars(ipp_t      *response,       /* I - Response data to be copied... */
       for (filter = attr;
            filter != NULL && filter->group_tag != IPP_TAG_ZERO;
            filter = filter->next)
-        if (filter->name && strcmp(filter->name, filter_name) == 0 &&
+        if (filter->name && !strcmp(filter->name, filter_name) &&
            (filter->value_tag == IPP_TAG_STRING ||
             (filter->value_tag >= IPP_TAG_TEXTLANG &&
              filter->value_tag <= IPP_TAG_MIMETYPE)) &&
            filter->values[0].string.text != NULL &&
-           strcasecmp(filter->values[0].string.text, filter_value) == 0)
+           !strcasecmp(filter->values[0].string.text, filter_value))
          break;
 
       if (!filter)
@@ -558,7 +558,7 @@ ippSetCGIVars(ipp_t      *response, /* I - Response data to be copied... */
       {
         cgiSetArray(name, element, value);
 
-        DEBUG_printf(("<P>%s[%d]=\"%s\"\n", name, element, value));
+        fprintf(stderr, "DEBUG2: %s[%d]=\"%s\"\n", name, element, value);
       }
     }
 
@@ -566,7 +566,7 @@ ippSetCGIVars(ipp_t      *response, /* I - Response data to be copied... */
       break;
   }
 
-  DEBUG_puts("<P>Leaving ippSetCGIVars()...");
+  fprintf(stderr, "DEBUG2: Returing %d from ippSetCGIVars()...\n", element + 1);
 
   return (element + 1);
 }
index 385568f8aa2e9a214afc9fcc0142865a5c20ea31..9dd98f9a39ef54cb7a4b53b186ba99dc3c97aba7 100644 (file)
@@ -30,6 +30,7 @@
  *   AllowIP()            - Add an IP address or network that is allowed to
  *                          access the location.
  *   CheckAuth()          - Check authorization masks.
+ *   cupsdCheckGroup()    - Check for a user's group membership.
  *   CopyLocation()       - Make a copy of a location...
  *   DeleteAllLocations() - Free all memory used for location authorization.
  *   DenyHost()           - Add a host name that is not allowed to access the
@@ -54,7 +55,6 @@
  */
 
 #include "cupsd.h"
-#include <pwd.h>
 #include <grp.h>
 #ifdef HAVE_SHADOW_H
 #  include <shadow.h>
@@ -429,6 +429,74 @@ CheckAuth(unsigned   ip[4],        /* I - Client address */
 }
 
 
+/*
+ * 'cupsdCheckGroup()' - Check for a user's group membership.
+ */
+
+int                                    /* O - 1 if user is a member, 0 otherwise */
+cupsdCheckGroup(
+    const char    *username,           /* I - User name */
+    struct passwd *user,               /* I - System user info */
+    const char    *groupname)          /* I - Group name */
+{
+  int                  i;              /* Looping var */
+  struct group         *group;         /* System group info */
+  char                 junk[33];       /* MD5 password (not used) */
+
+
+  LogMessage(L_DEBUG2, "cupsdCheckGroup(username=\"%s\", user=%p, groupname=\"%s\")\n",
+             username, user, groupname);
+
+ /*
+  * Validate input...
+  */
+
+  if (!username || !groupname)
+    return (0);
+
+ /*
+  * Check to see if the user is a member of the named group...
+  */
+
+  group = getgrnam(groupname);
+  endgrent();
+
+  if (group != NULL)
+  {
+   /*
+    * Group exists, check it...
+    */
+
+    for (i = 0; group->gr_mem[i]; i ++)
+      if (!strcasecmp(username, group->gr_mem[i]))
+       return (1);
+  }
+
+ /*
+  * Group doesn't exist or user not in group list, check the group ID
+  * against the user's group ID...
+  */
+
+  if (user && group && group->gr_gid == user->pw_gid)
+    return (1);
+
+ /*
+  * Username not found, group not found, or user is not part of the
+  * system group...  Check for a user and group in the MD5 password
+  * file...
+  */
+
+  if (GetMD5Passwd(username, groupname, junk) != NULL)
+    return (1);
+
+ /*
+  * If we get this far, then the user isn't part of the named group...
+  */
+
+  return (0);
+}
+
+
 /*
  * 'CopyLocation()' - Make a copy of a location...
  */
@@ -465,7 +533,7 @@ CopyLocation(location_t **loc)      /* IO - Original location */
   * Copy the information from the original location to the new one.
   */
 
-  temp->limit = (*loc)->limit;
+  temp->limit      = (*loc)->limit;
   temp->order_type = (*loc)->order_type;
   temp->type       = (*loc)->type;
   temp->level      = (*loc)->level;
@@ -918,7 +986,6 @@ IsAuthorized(client_t *con) /* I - Connection */
   location_t   *best;          /* Best match for location so far */
   int          hostlen;        /* Length of hostname */
   struct passwd        *pw;            /* User password data */
-  struct group *grp;           /* Group data */
   char         nonce[HTTP_MAX_VALUE],
                                /* Nonce value from client */
                md5[33],        /* MD5 password */
@@ -1296,8 +1363,19 @@ IsAuthorized(client_t *con)      /* I - Connection */
            LogMessage(L_DEBUG2, "IsAuthorized: num_names = %d", best->num_names);
 
             for (i = 0; i < best->num_names; i ++)
-             if (GetMD5Passwd(con->username, best->names[i], md5))
+           {
+             if (!strcasecmp(best->names[i], "@SYSTEM"))
+             {
+               for (j = 0; j < NumSystemGroups; j ++)
+                 if (GetMD5Passwd(con->username, SystemGroups[j], md5))
+                   break;
+
+                if (j < NumSystemGroups)
+                 break;
+             }
+             else if (GetMD5Passwd(con->username, best->names[i], md5))
                break;
+            }
 
             if (i >= best->num_names)
              md5[0] = '\0';
@@ -1332,8 +1410,19 @@ IsAuthorized(client_t *con)      /* I - Connection */
            LogMessage(L_DEBUG2, "IsAuthorized: num_names = %d", best->num_names);
 
             for (i = 0; i < best->num_names; i ++)
-             if (GetMD5Passwd(con->username, best->names[i], md5))
+           {
+             if (!strcasecmp(best->names[i], "@SYSTEM"))
+             {
+               for (j = 0; j < NumSystemGroups; j ++)
+                 if (GetMD5Passwd(con->username, SystemGroups[j], md5))
+                   break;
+
+                if (j < NumSystemGroups)
+                 break;
+             }
+             else if (GetMD5Passwd(con->username, best->names[i], md5))
                break;
+            }
 
             if (i >= best->num_names)
              md5[0] = '\0';
@@ -1395,7 +1484,7 @@ IsAuthorized(client_t *con)       /* I - Connection */
     */
 
     for (i = 0; i < best->num_names; i ++)
-      if (!strcmp(con->username, best->names[i]))
+      if (!strcasecmp(con->username, best->names[i]))
         return (HTTP_OK);
 
     return (HTTP_UNAUTHORIZED);
@@ -1418,26 +1507,14 @@ IsAuthorized(client_t *con)     /* I - Connection */
       LogMessage(L_DEBUG2, "IsAuthorized: Checking group \"%s\" membership...",
                  best->names[i]);
 
-      grp = getgrnam(best->names[i]);
-      endgrent();
-
-      if (grp == NULL)                 /* No group by that name??? */
+      if (!strcasecmp(best->names[i], "@SYSTEM"))
       {
-       LogMessage(L_WARN, "IsAuthorized: Group \"%s\" does not exist!",
-                  best->names[i]);
-       return (HTTP_FORBIDDEN);
+        for (j = 0; j < NumSystemGroups; j ++)
+         if (cupsdCheckGroup(con->username, pw, SystemGroups[j]))
+           return (HTTP_OK);
       }
-
-      for (j = 0; grp->gr_mem[j] != NULL; j ++)
-       if (!strcmp(con->username, grp->gr_mem[j]))
-         return (HTTP_OK);
-
-     /*
-      * Check to see if the default group ID matches for the user...
-      */
-
-      if (pw != NULL && grp->gr_gid == pw->pw_gid)
-       return (HTTP_OK);
+      else if (cupsdCheckGroup(con->username, pw, best->names[i]))
+        return (HTTP_OK);
     }
 
    /*
index fc4af8bc944e453a71a8a402269a16997a4f7279..02ce1271a70959b68fef04bb0a771c0c1491da63 100644 (file)
  *         WWW: http://www.cups.org
  */
 
+/*
+ * Include necessary headers...
+ */
+
+#include <pwd.h>
+
+
 /*
  * HTTP authorization types and levels...
  */
@@ -123,6 +130,9 @@ extern void         AllowIP(location_t *loc, unsigned address[4],
                                unsigned netmask[4]);
 extern int             CheckAuth(unsigned ip[4], char *name, int namelen,
                                  int num_masks, authmask_t *masks);
+extern int             cupsdCheckGroup(const char *username,
+                                       struct passwd *user,
+                                       const char *groupname);
 extern location_t      *CopyLocation(location_t **loc);
 extern void            DeleteAllLocations(void);
 extern void            DenyHost(location_t *loc, char *name);
index 70de34f998abd59a52a1fc31e1aaf8ff8b6dc543..2e72a89fecc61f6eca964570d9713c3a491afc0c 100644 (file)
@@ -2958,6 +2958,7 @@ pipe_command(client_t *con,               /* I - Client connection */
                *envp[100];             /* Environment variables */
   char         content_length[1024],   /* CONTENT_LENGTH environment variable */
                content_type[1024],     /* CONTENT_TYPE environment variable */
+               cups_cachedir[1024],    /* CUPS_CACHEDIR environment variable */
                cups_datadir[1024],     /* CUPS_DATADIR environment variable */
                cups_docroot[1024],     /* CUPS_DOCROOT environment variable */
                cups_serverbin[1024],   /* CUPS_SERVERBIN environment variable */
@@ -3161,6 +3162,7 @@ pipe_command(client_t *con,               /* I - Client connection */
                  sizeof(remote_addr) - 12);
   snprintf(remote_user, sizeof(remote_user), "REMOTE_USER=%s", con->username);
   snprintf(tmpdir, sizeof(tmpdir), "TMPDIR=%s", TempDir);
+  snprintf(cups_cachedir, sizeof(cups_cachedir), "CUPS_CACHEDIR=%s", CacheDir);
   snprintf(cups_datadir, sizeof(cups_datadir), "CUPS_DATADIR=%s", DataDir);
   snprintf(cups_docroot, sizeof(cups_docroot), "CUPS_DOCROOT=%s", DocumentRoot);
   snprintf(cups_serverbin, sizeof(cups_serverbin), "CUPS_SERVERBIN=%s", ServerBin);
@@ -3190,6 +3192,7 @@ pipe_command(client_t *con,               /* I - Client connection */
   envp[envc ++] = lang;
   envp[envc ++] = TZ;
   envp[envc ++] = tmpdir;
+  envp[envc ++] = cups_cachedir;
   envp[envc ++] = cups_datadir;
   envp[envc ++] = cups_docroot;
   envp[envc ++] = cups_serverbin;
index d7a5c26ce5f01e7ac6a6d36a62473975befc73dd..55818d29ad54b66524e35d7c15c369407f4a4ee6 100644 (file)
@@ -39,7 +39,6 @@
 
 #include "cupsd.h"
 #include <stdarg.h>
-#include <pwd.h>
 #include <grp.h>
 #include <sys/utsname.h>
 #include <cups/dir.h>
@@ -98,6 +97,7 @@ static var_t  variables[] =
   { "BrowseShortNames",                &BrowseShortNames,      VAR_BOOLEAN },
   { "BrowseTimeout",           &BrowseTimeout,         VAR_INTEGER },
   { "Browsing",                        &Browsing,              VAR_BOOLEAN },
+  { "CacheDir",                        &CacheDir,              VAR_STRING },
   { "Classification",          &Classification,        VAR_STRING },
   { "ClassifyOverride",                &ClassifyOverride,      VAR_BOOLEAN },
   { "ConfigFilePerm",          &ConfigFilePerm,        VAR_INTEGER },
@@ -279,8 +279,9 @@ ReadConfiguration(void)
   SetStringf(&ServerAdmin, "root@%s", temp);
   SetString(&ServerBin, CUPS_SERVERBIN);
   SetString(&RequestRoot, CUPS_REQUESTS);
-  SetString(&DocumentRoot, CUPS_DOCROOT);
+  SetString(&CacheDir, CUPS_CACHEDIR);
   SetString(&DataDir, CUPS_DATADIR);
+  SetString(&DocumentRoot, CUPS_DOCROOT);
   SetString(&AccessLog, CUPS_LOGDIR "/access_log");
   SetString(&ErrorLog, CUPS_LOGDIR "/error_log");
   SetString(&PageLog, CUPS_LOGDIR "/page_log");
@@ -507,6 +508,12 @@ ReadConfiguration(void)
   if (ServerBin[0] != '/')
     SetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin);
 
+  if (StateDir[0] != '/')
+    SetStringf(&StateDir, "%s/%s", ServerRoot, StateDir);
+
+  if (CacheDir[0] != '/')
+    SetStringf(&CacheDir, "%s/%s", ServerRoot, CacheDir);
+
 #ifdef HAVE_SSL
   if (ServerCertificate[0] != '/')
     SetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate);
@@ -528,6 +535,15 @@ ReadConfiguration(void)
   * writable by the user and group in the cupsd.conf file...
   */
 
+  chown(CacheDir, RunUser, Group);
+  chmod(CacheDir, 0775);
+
+  snprintf(temp, sizeof(temp), "%s/ppd", CacheDir);
+  if (access(temp, 0))
+    mkdir(temp, 0755);
+  chown(temp, RunUser, Group);
+  chmod(temp, 0755);
+
   chown(StateDir, RunUser, Group);
   chmod(StateDir, 0775);
 
@@ -537,12 +553,6 @@ ReadConfiguration(void)
   chown(temp, RunUser, Group);
   chmod(temp, 0711);
 
-  snprintf(temp, sizeof(temp), "%s/ppd", StateDir);
-  if (access(temp, 0))
-    mkdir(temp, 0755);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0755);
-
   chown(ServerRoot, RunUser, Group);
   chmod(ServerRoot, 0775);
 
@@ -701,7 +711,6 @@ ReadConfiguration(void)
   {
     policy_t   *p;                     /* New policy */
     policyop_t *po;                    /* New policy operation */
-    char       groupname[255];         /* Group name */
 
 
     if (DefaultPolicy)
@@ -729,13 +738,10 @@ ReadConfiguration(void)
       po->order_type = POLICY_DENY;
 
       AddPolicyOpName(po, POLICY_ALLOW, "@OWNER");
+      LogMessage(L_INFO, "Allow @OWNER");
 
-      for (i = 0; i < NumSystemGroups; i ++)
-      {
-        snprintf(groupname, sizeof(groupname), "@%s", SystemGroups[i]);
-       AddPolicyOpName(po, POLICY_ALLOW, groupname);
-       LogMessage(L_INFO, "Allow @%s", groupname);
-      }
+      AddPolicyOpName(po, POLICY_ALLOW, "@SYSTEM");
+      LogMessage(L_INFO, "Allow @SYSTEM");
 
       AddPolicyOp(p, po, IPP_SEND_URI);
       AddPolicyOp(p, po, IPP_CANCEL_JOB);
@@ -773,12 +779,8 @@ ReadConfiguration(void)
       po->order_type   = POLICY_DENY;
       po->authenticate = 1;
 
-      for (i = 0; i < NumSystemGroups; i ++)
-      {
-        snprintf(groupname, sizeof(groupname), "@%s", SystemGroups[i]);
-       AddPolicyOpName(po, POLICY_ALLOW, groupname);
-       LogMessage(L_INFO, "Allow @%s", groupname);
-      }
+      AddPolicyOpName(po, POLICY_ALLOW, "@SYSTEM");
+      LogMessage(L_INFO, "Allow @SYSTEM");
 
       AddPolicyOp(p, po, IPP_RESUME_PRINTER);
       AddPolicyOp(p, po, IPP_SET_PRINTER_ATTRIBUTES);
@@ -1817,7 +1819,6 @@ read_location(cups_file_t *fp,            /* I - Configuration file */
               char        *location,   /* I - Location name/path */
              int         linenum)      /* I - Current line number */
 {
-  int          i;                      /* Looping var */
   location_t   *loc,                   /* New location */
                *parent;                /* Parent location */
   char         line[HTTP_MAX_BUFFER],  /* Line buffer */
@@ -2071,15 +2072,7 @@ read_location(cups_file_t *fp,           /* I - Configuration file */
       {
         loc->level = AUTH_GROUP;
 
-       /*
-        * Use the default system group if none is defined so far...
-       */
-
-        if (NumSystemGroups)
-         NumSystemGroups = 1;
-
-       for (i = 0; i < NumSystemGroups; i ++)
-         AddName(loc, SystemGroups[i]);
+        AddName(loc, "@SYSTEM");
       }
       else
         LogMessage(L_WARN, "Unknown authorization class %s on line %d.",
index 98520847cd5425218a59c0ee0f731f781a2871c5..8afa75166ee89587420b8b8d182b0ebb6496a931 100644 (file)
@@ -80,6 +80,8 @@ VAR char              *SystemGroups[MAX_SYSTEM_GROUPS],
                                        /* Error log filename */
                        *PageLog                VALUE(NULL),
                                        /* Page log filename */
+                       *CacheDir               VALUE(NULL),
+                                       /* Cache file directory */
                        *DataDir                VALUE(NULL),
                                        /* Data file directory */
                        *DefaultLanguage        VALUE(NULL),
index 9c5032246f75d49cdf0aed10f7b312f02b976d35..db6cf4167ac05f75c9bc49330a1a98206eb2a298 100644 (file)
@@ -98,26 +98,19 @@ main(int  argc,                             /* I - Number of command-line args */
      char *argv[])                     /* I - Command-line arguments */
 {
  /*
-  * Check the command-line...
+  * Install or list PPDs...
   */
 
-  if (argc < 3 ||
-      (!strcmp(argv[1], "cat") && argc != 3) ||
-      (!strcmp(argv[1], "list") && argc != 5))
+  if (!strcmp(argv[1], "cat") && argc == 3)
+    return (cat_ppd(argv[2]));
+  else if (!strcmp(argv[1], "list") && argc == 5)
+    return (list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]));
+  else
   {
     fputs("Usage: cups-driverd cat ppd-name\n", stderr);
     fputs("Usage: cups-driverd list request_id limit options\n", stderr);
     return (1);
   }
-
- /*
-  * Install or list PPDs...
-  */
-
-  if (!strcmp(argv[1], "cat"))
-    return (cat_ppd(argv[2]));
-  else
-    return (list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]));
 }
 
 
@@ -267,6 +260,9 @@ list_ppds(int        request_id,    /* I - Request ID */
                send_name;              /* Send ppd-name attribute? */
 
 
+  fprintf(stderr, "DEBUG2: [cups-driverd] list_ppds(request_id=%d, limit=%d, opt=\"%s\"\n",
+          request_id, limit, opt);
+
  /*
   * See if we a PPD database file...
   */
@@ -373,7 +369,7 @@ list_ppds(int        request_id,    /* I - Request ID */
               filename, NumPPDs);
     }
     else
-      fprintf(stderr, "ERROR: [cups-driverd] Unable to write \"%s\" - %s",
+      fprintf(stderr, "ERROR: [cups-driverd] Unable to write \"%s\" - %s\n",
               filename, strerror(errno));
   }
   else
@@ -407,6 +403,9 @@ list_ppds(int        request_id,    /* I - Request ID */
   requested   = cupsGetOption("requested-attributes", num_options, options);
   make        = cupsGetOption("ppd-make", num_options, options);
 
+  fprintf(stderr, "DEBUG: [cups-driverd] requested=\"%s\"\n",
+          requested ? requested : "(nil)");
+
   if (!requested || strstr(requested, "all"))
   {
     send_name             = 1;
@@ -443,6 +442,9 @@ list_ppds(int        request_id,    /* I - Request ID */
       * Send this PPD...
       */
 
+      fprintf(stderr, "DEBUG: [cups-driverd] Sending %s (%s)...\n",
+              ppd->record.name, ppd->record.make_and_model);
+
       count --;
 
       cupsdSendIPPGroup(IPP_TAG_PRINTER);
index a1d524dad0bad613dc70f987ba5b42c999bb1851..8d8666a13d068280df438db2d5705d1db51c4ac9 100644 (file)
@@ -88,8 +88,6 @@
  */
 
 #include "cupsd.h"
-#include <pwd.h>
-#include <grp.h>
 
 #ifdef HAVE_LIBPAPER
 #  include <paper.h>
@@ -2326,12 +2324,11 @@ static int                              /* O - 1 if OK, 0 if not */
 check_quotas(client_t  *con,           /* I - Client connection */
              printer_t *p)             /* I - Printer or class */
 {
-  int          i, j;                   /* Looping vars */
+  int          i;                      /* Looping var */
   ipp_attribute_t *attr;               /* Current attribute */
   char         username[33];           /* Username */
   quota_t      *q;                     /* Quota data */
   struct passwd        *pw;                    /* User password data */
-  struct group *grp;                   /* Group data */
 
 
   LogMessage(L_DEBUG2, "check_quotas(%p[%d], %p[%s])\n",
@@ -2411,29 +2408,8 @@ check_quotas(client_t  *con,             /* I - Client connection */
         * Check group membership...
        */
 
-        grp = getgrnam(p->users[i] + 1);
-       endgrent();
-
-        if (grp)
-       {
-        /*
-         * Check primary group...
-         */
-
-         if (pw && grp->gr_gid == pw->pw_gid)
-           break;
-
-         /*
-         * Check usernames in group...
-         */
-
-          for (j = 0; grp->gr_mem[j]; j ++)
-           if (!strcasecmp(username, grp->gr_mem[j]))
-             break;
-
-          if (grp->gr_mem[j])
-           break;
-       }
+        if (cupsdCheckGroup(username, pw, p->users[i] + 1))
+         break;
       }
       else if (!strcasecmp(username, p->users[i]))
        break;
@@ -4370,7 +4346,7 @@ get_ppds(client_t *con)                   /* I - Client connection */
   */
 
   limit     = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER);
-  make      = ippFindAttribute(con->request, "ppd-make", IPP_TAG_KEYWORD);
+  make      = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT);
   requested = ippFindAttribute(con->request, "requested-attributes",
                                IPP_TAG_KEYWORD);
 
@@ -4413,11 +4389,11 @@ get_ppds(client_t *con)                 /* I - Client connection */
 
   snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
   snprintf(options, sizeof(options),
-           "cups-driverd %d+%d+requested-attributes=%s%s%s",
+           "cups-driverd list+%d+%d+requested-attributes=%s%s%s",
            con->request->request.op.request_id,
            limit ? limit->values[0].integer : 0,
           attrs,
-          make ? " ppd-make=" : "",
+          make ? "%20ppd-make=" : "",
           make ? make->values[0].string.text : "");
 
   if (SendCommand(con, command, options, 0))
@@ -7528,9 +7504,8 @@ static int                                /* O - 0 if not allowed, 1 if allowed */
 user_allowed(printer_t  *p,            /* I - Printer or class */
              const char *username)     /* I - Username */
 {
-  int          i, j;                   /* Looping vars */
+  int          i;                      /* Looping var */
   struct passwd        *pw;                    /* User password data */
-  struct group *grp;                   /* Group data */
 
 
   if (p->num_users == 0)
@@ -7550,29 +7525,8 @@ user_allowed(printer_t  *p,              /* I - Printer or class */
       * Check group membership...
       */
 
-      grp = getgrnam(p->users[i] + 1);
-      endgrent();
-
-      if (grp)
-      {
-       /*
-       * Check primary group...
-       */
-
-       if (pw && grp->gr_gid == pw->pw_gid)
-         break;
-
-       /*
-       * Check usernames in group...
-       */
-
-        for (j = 0; grp->gr_mem[j]; j ++)
-         if (!strcasecmp(username, grp->gr_mem[j]))
-           break;
-
-        if (grp->gr_mem[j])
-         break;
-      }
+      if (cupsdCheckGroup(username, pw, p->users[i] + 1))
+        break;
     }
     else if (!strcasecmp(username, p->users[i]))
       break;
index ab8706f8c9341dea8867732a159dac5626bf6907..8da443fa4a6bc3301a642e782a5b15f8c783e64e 100644 (file)
@@ -1367,6 +1367,7 @@ StartJob(int       id,                    /* I - Job ID */
                ppd[1024],              /* PPD environment variable */
                class_name[255],        /* CLASS environment variable */
                printer_name[255],      /* PRINTER environment variable */
+               cups_cachedir[1024],    /* CUPS_CACHEDIR environment variable */
                cups_datadir[1024],     /* CUPS_DATADIR environment variable */
                cups_docroot[1024],     /* CUPS_DOCROOT environment variable */
                cups_fontpath[1024],    /* CUPS_FONTPATH environment variable */
@@ -1931,6 +1932,7 @@ StartJob(int       id,                    /* I - Job ID */
   snprintf(ppd, sizeof(ppd), "PPD=%s/ppd/%s.ppd", ServerRoot, printer->name);
   snprintf(printer_name, sizeof(printer_name), "PRINTER=%s", printer->name);
   snprintf(cache, sizeof(cache), "RIP_MAX_CACHE=%s", RIPCache);
+  snprintf(cups_cachedir, sizeof(cups_cachedir), "CUPS_CACHEDIR=%s", CacheDir);
   snprintf(cups_datadir, sizeof(cups_datadir), "CUPS_DATADIR=%s", DataDir);
   snprintf(cups_docroot, sizeof(cups_docroot), "CUPS_DOCROOT=%s", DocumentRoot);
   snprintf(cups_fontpath, sizeof(cups_fontpath), "CUPS_FONTPATH=%s", FontPath);
@@ -1950,6 +1952,7 @@ StartJob(int       id,                    /* I - Job ID */
   if (TZ && TZ[0])
     envp[envc ++] = TZ;
   envp[envc ++] = ppd;
+  envp[envc ++] = cups_cachedir;
   envp[envc ++] = cups_datadir;
   envp[envc ++] = cups_docroot;
   envp[envc ++] = cups_fontpath;
index 7a7c64e1eb36ea31ca89b24039eff215c50b3dad..a3e0f89ae09eca613f019a78217b5eb17ed1a1be 100644 (file)
@@ -30,7 +30,6 @@
  */
 
 #include "cupsd.h"
-#include <pwd.h>
 #include <grp.h>
 #ifdef HAVE_USERSEC_H
 #  include <usersec.h>
@@ -41,7 +40,6 @@
  * Local functions...
  */
 
-static int     check_group(const char *name, const char *group);
 static int     check_op(policyop_t *po, int allow_deny, const char *name,
                         const char *owner);
 
@@ -376,129 +374,6 @@ FindPolicyOp(policy_t *p,         /* I - Policy */
 }
 
 
-/*
- * 'validate_user()' - Validate the user for the request.
- */
-
-static int                             /* O - 1 if permitted, 0 otherwise */
-check_group(const char *username,      /* I - Authenticated username */
-            const char *groupname)     /* I - Group name */
-{
-  int                  i;              /* Looping var */
-  struct passwd                *user;          /* User info */
-  struct group         *group;         /* System group info */
-  char                 junk[33];       /* MD5 password (not used) */
-
-
-  LogMessage(L_DEBUG2, "check_group(%s, %s)\n", username, groupname);
-
- /*
-  * Validate input...
-  */
-
-  if (!username || !groupname)
-    return (0);
-
- /*
-  * Check to see if the user is a member of the named group...
-  */
-
-  user = getpwnam(username);
-  endpwent();
-
-  group = getgrnam(groupname);
-  endgrent();
-
-  if (group != NULL)
-  {
-   /*
-    * Group exists, check it...
-    */
-
-    for (i = 0; group->gr_mem[i]; i ++)
-      if (!strcasecmp(username, group->gr_mem[i]))
-       return (1);
-  }
-
- /*
-  * Group doesn't exist or user not in group list, check the group ID
-  * against the user's group ID...
-  */
-
-  if (user && group && group->gr_gid == user->pw_gid)
-    return (1);
-
- /*
-  * Username not found, group not found, or user is not part of the
-  * system group...  Check for a user and group in the MD5 password
-  * file...
-  */
-
-  if (GetMD5Passwd(username, groupname, junk) != NULL)
-    return (1);
-
- /*
-  * If we get this far, then the user isn't part of the named group...
-  */
-
-  return (0);
-
-
-#if 0 //// OLD OLD OLD OLD OLD
-  if (strcasecmp(username, owner) != 0 && strcasecmp(username, "root") != 0)
-  {
-   /*
-    * Not the owner or root; check to see if the user is a member of the
-    * system group...
-    */
-
-    user = getpwnam(username);
-    endpwent();
-
-    for (i = 0, j = 0, group = NULL; i < NumSystemGroups; i ++)
-    {
-      group = getgrnam(SystemGroups[i]);
-      endgrent();
-
-      if (group != NULL)
-      {
-       for (j = 0; group->gr_mem[j]; j ++)
-          if (strcasecmp(username, group->gr_mem[j]) == 0)
-           break;
-
-        if (group->gr_mem[j])
-         break;
-      }
-      else
-       j = 0;
-    }
-
-    if (user == NULL || group == NULL ||
-        (group->gr_mem[j] == NULL && group->gr_gid != user->pw_gid))
-    {
-     /*
-      * Username not found, group not found, or user is not part of the
-      * system group...  Check for a user and group in the MD5 password
-      * file...
-      */
-
-      for (i = 0; i < NumSystemGroups; i ++)
-        if (GetMD5Passwd(username, SystemGroups[i], junk) != NULL)
-         return (1);
-
-     /*
-      * Nope, not an MD5 user, either.  Return 0 indicating no-go...
-      */
-
-      return (0);
-    }
-  }
-
-  return (1);
-#endif //// 0
-}
-
-
 /*
  * 'check_op()' - Check the current operation.
  */
@@ -509,10 +384,14 @@ check_op(policyop_t *po,          /* I - Policy operation */
          const char *name,             /* I - User name */
         const char *owner)             /* I - Owner name */
 {
-  int          i;                      /* Looping vars */
+  int          i, j;                   /* Looping vars */
   policyname_t *pn;                    /* Current policy name */
+  struct passwd        *pw;                    /* User's password entry */
 
 
+  pw = getpwnam(name);
+  endpwent();
+
   for (i = po->num_names, pn = po->names; i > 0; i --, pn ++)
   {
     if (pn->allow_deny != allow_deny)
@@ -523,9 +402,15 @@ check_op(policyop_t *po,           /* I - Policy operation */
       if (owner && !strcasecmp(name, owner))
         return (1);
     }
+    else if (!strcasecmp(pn->name, "@SYSTEM"))
+    {
+      for (j = 0; j < NumSystemGroups; j ++)
+        if (cupsdCheckGroup(name, pw, SystemGroups[j]))
+          return (1);
+    }
     else if (pn->name[0] == '@')
     {
-      if (check_group(name, pn->name + 1))
+      if (cupsdCheckGroup(name, pw, pn->name + 1))
         return (1);
     }
     else if (!strcasecmp(name, pn->name))
index bdb16db6339d271f5fe4b05092fe176f0af6982a..ee26d23357f891b76f5d668dce1e907188d7500a 100644 (file)
@@ -177,14 +177,12 @@ cupsdSendIPPHeader(
 {
  /*
   * Send IPP/1.1 response header: version number (2 bytes), status code
-  * (4 bytes), and request ID (4 bytes)...
+  * (2 bytes), and request ID (4 bytes)...
   */
 
   putchar(1);
   putchar(1);
 
-  putchar(status_code >> 24);
-  putchar(status_code >> 16);
   putchar(status_code >> 8);
   putchar(status_code);
 
index d83b165f5d23eb53d44672c8c84ab9785f119d25..7081059e2a9f3c4451fa076ab3d9e268ab7f6579 100755 (executable)
@@ -246,6 +246,7 @@ User $user
 ServerRoot /tmp/$user
 StateDir /tmp/$user
 ServerBin /tmp/$user/bin
+CacheDir /tmp/$user/share
 DataDir /tmp/$user/share
 FontPath /tmp/$user/share/fonts
 DocumentRoot $root/doc