]> andersk Git - moira.git/blobdiff - gen/cups-print.pc
Spit out kerberos principals in krb5 format.
[moira.git] / gen / cups-print.pc
index 633c623cc197a2e337a670acd5a13fe32a451942..74bcb507a183a417d08ebe5345099658e55ceb08 100644 (file)
 #include <string.h>
 
 #include <time.h>
+#ifdef HAVE_KRB4
 #include <krb.h>
+#endif
 #include <krb5.h>
 
 #include "util.h"
 
-
-
 EXEC SQL INCLUDE sqlca;
 
 RCSID("$Header$");
@@ -33,13 +33,16 @@ RCSID("$Header$");
 char *whoami = "cups-print.gen";
 char *db = "moira/moira";
 
+const int krbvers = 5; /* use Kerberos 5 */
+
 /* OMG, I hate this, but it's cleaner, I guess? */
 
-const char *alterjob = "<Limit Send-Document Send-URI Hold-Job Release-Job\
- Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription\
- Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job\
+const char *alterjob = "<Limit Hold-Job Release-Job\
+ Restart-Job Purge-Jobs Reprocess-Job Set-Job-Attributes\
  Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job>";
-const char *submitjob = "<Limit Create-Job Print-Job Print-URI>";
+const char *submitjob = "<Limit Create-Job Print-Job Print-URI Send-Document\
+ Set-Job-Attributes Send-URI Create-Job-Subscription Renew-Subscription\
+ Cancel-Subscription Get-Notifications CUPS-Move-Job>";
 const char *alterpntr = "<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer\
  CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>";
 const char *lpcpntr = "<Limit Pause-Printer Resume-Printer Enable-Printer\
@@ -49,6 +52,7 @@ const char *lpcpntr = "<Limit Pause-Printer Resume-Printer Enable-Printer\
  CUPS-Accept-Jobs CUPS-Reject-Jobs>";
 const char *canceljob = "<Limit Cancel-Job CUPS-Authenticate-Job>";
 const char *catchall = "<Limit All>";
+const char *phost = "printers.MIT.EDU";
 
 void do_host(char *host);
 void sqlerr(void);
@@ -70,7 +74,7 @@ int main(int argc, char **argv)
 
   EXEC SQL DECLARE csr_hosts CURSOR FOR
     SELECT m.name FROM machine m, serverhosts sh
-    WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS' AND sh.enable = 1;
+    WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1;
   EXEC SQL OPEN csr_hosts;
   while (1)
     {
@@ -90,12 +94,22 @@ void printer_user_list(FILE *out, char *type, int id, char *str)
 {
   struct save_queue *sq;
   struct imember *m;
+  char kbuf[MAX_K_NAME_SZ];
+  char *cp;
 
   sq = get_acl(type, id, NULL);
   while (sq_remove_data(sq, &m))
     {
-      if (m->type == 'U')
-        fprintf(out, "%s %s\n", str, m->name);
+      if (m->type != 'S' && m->type != NULL) {
+       /* CUPS wants mmanley/root, not mmanley.root@ATHENA.MIT.EDU */
+        canon_krb(m, krbvers, kbuf, sizeof(kbuf));
+
+       /* now, take out all the @realm */
+        for (cp=kbuf; *cp; cp++) {
+         if (*cp == '@') *cp = '\0';
+       }
+        fprintf(out, "%s %s\n", str, kbuf);
+      }
       freeimember(m);
     }
   sq_destroy(sq);
@@ -128,17 +142,17 @@ void do_host(char *host)
   EXEC SQL SELECT mach_id INTO :rm FROM machine
     WHERE name = :spoolhost;
 
-  sprintf(filename, "%s/print/%s", DCM_DIR, host);
+  sprintf(filename, "%s/cups-print/%s", DCM_DIR, host);
   tf = tarfile_open(filename);
 
   /* printers.conf */
   out = tarfile_start(tf, "/etc/cups/printers.conf", 0644, 0, 0,
-                     "root", "lp", now);
+                     "lp", "lp", now);
 
   EXEC SQL DECLARE csr_printers CURSOR FOR
     SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,
     m.name, pr.banner, pr.location, pr.contact, pr.ka,
-    pr.ac
+    pr.ac, pr.lpc_acl
     FROM printers pr, machine m
     WHERE pr.rm = :rm AND m.mach_id = pr.mach_id
     AND pr.type != 'ALIAS';
@@ -146,7 +160,7 @@ void do_host(char *host)
   while (1)
     {
       EXEC SQL FETCH csr_printers INTO :rp, :name, :duplexname,
-       :hwtype, :hostname, :banner, :location, :contact, :ka, :ac;
+       :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :lpc_acl;
       if (sqlca.sqlcode)
        break;
 
@@ -182,10 +196,10 @@ void do_host(char *host)
       if (location[0])
         fprintf(out, "Location %s\n", location);
       fprintf(out, "ErrorPolicy abort-job\n");
-      if (! ka || ! lpc_acl)
-        fprintf(out, "OpPolicy default\n");
-      else
+      if (ka || lpc_acl)
        fprintf(out, "OpPolicy %s-policy\n", rp);
+      else
+        fprintf(out, "OpPolicy default\n");
 
       /* Access-control list. */
       if (ac)
@@ -193,7 +207,7 @@ void do_host(char *host)
           if (ka)
            fprintf(out, "AuthType Negotiate\n");
          else
-           fprintf(out, "AuthType Negotiate\n");
+           fprintf(out, "AuthType Default\n");
           printer_user_list(out, "LIST", ac, "AllowUser");
         }
 
@@ -210,7 +224,7 @@ void do_host(char *host)
 
   /* aliases are in classes.conf */
   out = tarfile_start(tf, "/etc/cups/classes.conf", 0644, 0, 0,
-                     "root", "root", now);
+                 "lp", "lp", now);
   EXEC SQL DECLARE csr_duplexqs CURSOR FOR
     SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,
     m.name, pr.banner, pr.location, pr.contact, pr.ka, 
@@ -251,10 +265,10 @@ void do_host(char *host)
           if (location[0])
             fprintf(out, "Location %s\n", location);
           fprintf(out, "ErrorPolicy abort-job\n");
-          if (! ka || ! lpc_acl)
-            fprintf(out, "OpPolicy default\n");
-          else
+          if (ka || lpc_acl)
                    fprintf(out, "OpPolicy %s-policy\n", rp);
+          else
+            fprintf(out, "OpPolicy default\n");
     
           /* Access-control list. */
           if (ac)
@@ -262,7 +276,7 @@ void do_host(char *host)
               if (ka)
                        fprintf(out, "AuthType Negotiate\n");
              else
-                       fprintf(out, "AuthType Negotiate\n");
+               fprintf(out, "AuthType Default\n");
               printer_user_list(out, "LIST", ac, "AllowUser");
             }
     
@@ -296,10 +310,10 @@ void do_host(char *host)
           if (location[0])
             fprintf(out, "Location %s\n", location);
           fprintf(out, "ErrorPolicy abort-job\n");
-          if (! ka || ! lpc_acl)
-            fprintf(out, "OpPolicy default\n");
-          else
+          if (ka || lpc_acl)
                    fprintf(out, "OpPolicy %s-policy\n", rp);
+          else
+            fprintf(out, "OpPolicy default\n");
     
           /* Access-control list. */
           if (ac)
@@ -307,7 +321,7 @@ void do_host(char *host)
               if (ka)
                        fprintf(out, "AuthType Negotiate\n");
              else
-                       fprintf(out, "AuthType Negotiate\n");
+               fprintf(out, "AuthType Default\n");
               printer_user_list(out, "LIST", ac, "AllowUser");
             }
     
@@ -337,13 +351,19 @@ void do_host(char *host)
   fprintf(out, "ServerCertificate /etc/cups/ssl/%s-ipp-crt.pem\n", lhost);
   fprintf(out, "ServerKey /etc/cups/ssl/%s-ipp-key.pem\n", lhost);
   fprintf(out, "ServerName %s\n", lhost);
+  fprintf(out, "ServerAlias %s\n", phost);
   fprintf(out, "Krb5Keytab /etc/krb5-ipp.keytab\n");
-  fprintf(out, "Browsing On\n");
-  fprintf(out, "BrowseProtocols cups\n");
 
   /* The other CUPS servers should be aware of the other hosts'
      queues, so we'll let them browse each other. */
+  fprintf(out, "Include cups.local.conf\n");
+  fprintf(out, "Include cups.locations.conf\n");
+  fprintf(out, "Include cups.policies.conf\n");
+  tarfile_end(tf);
 
+  /* cups.hosts.conf */
+  out = tarfile_start(tf, "/etc/cups/cups.hosts.conf", 0755, 1, 1,
+                     "root", "lp", now);
   EXEC SQL DECLARE csr_cupshosts CURSOR FOR
     SELECT m.name AS cupshosts FROM machine m, printservers ps
     WHERE m.mach_id = ps.mach_id AND ps.kind = 'CUPS';
@@ -361,8 +381,6 @@ void do_host(char *host)
          fprintf(out, "BrowsePoll %s\n", cupshosts);
     }
   EXEC SQL CLOSE csr_cupshosts;
-  fprintf(out, "Include cups.locations.conf\n");
-  fprintf(out, "Include cups.policies.conf\n");
 
   tarfile_end(tf);
 
@@ -384,8 +402,9 @@ void do_host(char *host)
       fprintf (out, "Order deny,allow\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", submitjob);
-      fprintf (out, "AuthType Default\n");
+      fprintf (out, "AuthType None\n");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", alterpntr);
       fprintf (out, "AuthType Default\n");
@@ -403,9 +422,12 @@ void do_host(char *host)
       fprintf (out, "Require user @OWNER @SYSTEM\n");
       printer_user_list(out, "LIST", top_lpc_acl, "Require user");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", catchall);
+      fprintf (out, "AuthType None\n");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "</Policy>\n");
     }
@@ -432,6 +454,7 @@ void do_host(char *host)
       fprintf (out, "Require user @OWNER @SYSTEM\n");
       printer_user_list(out, "LIST", lpc_acl, "Require user");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", submitjob);
       /* If the printer is Kerberized? */
@@ -445,6 +468,7 @@ void do_host(char *host)
       else if (ka)
         fprintf (out, "Require valid-user\n");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", alterpntr);
       fprintf (out, "AuthType Default\n");
@@ -466,9 +490,12 @@ void do_host(char *host)
       printer_user_list(out, "LIST", lpc_acl, "Require user");
       printer_user_list(out, "LIST", top_lpc_acl, "Require user");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "%s\n", catchall);
+      fprintf (out, "AuthType None\n");
       fprintf (out, "Order deny,allow\n");
+      fprintf (out, "Allow from all\n");
       fprintf (out, "</Limit>\n");
       fprintf (out, "</Policy>\n");
     }
This page took 0.037293 seconds and 4 git commands to generate.