]> andersk Git - moira.git/blobdiff - gen/dhcp.pc
Command line printer manipulation client, and build goo.
[moira.git] / gen / dhcp.pc
index 71bca886cd998032f2cfacb33020e6c39db7e0b6..19de4a3a69fead07ea0d0e107cdaba363d48a09d 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$
  *
- * This generates the dhcpd.conf.pring and associated files.
+ * This generates the dhcpd.conf.print and associated files.
  *
  * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
  * For copying and distribution information, please see the file
@@ -20,6 +20,8 @@
 
 #include "util.h"
 
+#define MACHINE_CHWADDR_SIZE 18
+
 EXEC SQL INCLUDE sqlca;
 
 RCSID("$Header$");
@@ -27,12 +29,15 @@ RCSID("$Header$");
 char *whoami = "dhcp.gen";
 char *db = "moira/moira";
 
+void hwcolonify(char *from, char *to);
+
 void sqlerr(void);
 
 int main(int argc, char **argv)
 {
   EXEC SQL BEGIN DECLARE SECTION;
   char name[MACHINE_NAME_SIZE], hwaddr[MACHINE_HWADDR_SIZE];
+  char chwaddr[MACHINE_CHWADDR_SIZE];
   char ohwaddr[MACHINE_HWADDR_SIZE], hwtype[PRINTERS_HWTYPE_SIZE];
   char addr[MACHINE_ADDRESS_SIZE], location[PRINTERS_LOCATION_SIZE];
   char contact[PRINTERS_CONTACT_SIZE], logaddr[MACHINE_ADDRESS_SIZE];
@@ -57,14 +62,24 @@ int main(int argc, char **argv)
 
   EXEC SQL WHENEVER SQLERROR DO sqlerr();
 
+  if (argc != 2)
+    {
+      fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
+      exit(MR_ARGS);
+    }
+
   /* Get print spoolers for allow lists. */
-  EXEC SQL SELECT COUNT(service) INTO :alcount FROM serverhosts
-    WHERE service = 'PRINT';
+  EXEC SQL SELECT COUNT(service) INTO :alcount FROM serverhosts sh, machine m
+    WHERE (sh.service = 'PRINT' OR sh.service = 'CUPS-PRINT') 
+    AND sh.mach_id = m.mach_id 
+    AND m.status = 1 AND m.address != 'unassigned';
   allowlist = malloc(alcount * sizeof(*allowlist));
 
   EXEC SQL DECLARE csr_spool CURSOR FOR
     SELECT m.address, sh.value3 FROM machine m, serverhosts sh
-    WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT';
+    WHERE m.mach_id = sh.mach_id AND 
+    (sh.service = 'PRINT' OR sh.service = 'CUPS-PRINT')
+    AND m.status = 1 AND m.address != 'unassigned';
   EXEC SQL OPEN csr_spool;
   for (i = 0; i < alcount; i++)
     {
@@ -77,12 +92,11 @@ int main(int argc, char **argv)
   EXEC SQL CLOSE csr_spool;
 
   /* Now build the tar file. */
-  sprintf(filename, "%s/dhcp.out", DCM_DIR);
-  tf = tarfile_open(filename);
+  tf = tarfile_open(argv[1]);
 
-  /* Build dhcp.conf.print */
+  /* Build dhcpd.conf.print */
 
-  out = tarfile_start(tf, "/var/boot/dhcp.conf.print", 0755, 0, 0,
+  out = tarfile_start(tf, "/var/boot/dhcpd.conf.print", 0755, 0, 0,
                      "root", "root", now);
   ohwaddr[0] = '\0';
   EXEC SQL DECLARE csr_boot CURSOR FOR
@@ -110,6 +124,8 @@ int main(int argc, char **argv)
        }
       strcpy(ohwaddr, hwaddr);
 
+      hwcolonify(hwaddr, chwaddr); 
+
       strtrim(name);
       strtrim(addr);
       strtrim(logaddr);
@@ -129,9 +145,12 @@ int main(int argc, char **argv)
        continue;
 
       fprintf(out, "# %s: %s\n# contact: %s\nhost %s {\n\t"
-             "hardware ethernet %s;\n\tfixed-address %s;\n"
-             "\toption log-servers %s;\n",
-             shortname, location, contact, name, hwaddr, addr, logaddr);
+             "hardware ethernet %s;\n\tfixed-address %s;\n",
+             shortname, location, contact, name, chwaddr, addr);
+      
+      if (strlen(logaddr) != 0)
+             fprintf(out, "\toption log-servers %s;\n", logaddr);
+             
       if (!strncmp(hwtype, "HP", 2))
        fprintf(out, "\toption option-144 \"/hp/%s\";\n", shortname);
       fprintf(out, "}\n\n");
@@ -219,6 +238,23 @@ int main(int argc, char **argv)
   exit(MR_SUCCESS);
 }
 
+void hwcolonify(char *from, char *to)
+{
+  int f = 0, t = 0;
+  int mod = 2;
+
+  for (f = 0 ; f < MACHINE_HWADDR_SIZE - 1 ; )
+    {
+      to[t++] = from[f++];
+      if (f % mod == 0)
+       to[t++] = ':';
+    }
+       
+  if (f % mod == 0)
+    t--;
+  to[t] = '\0';
+}
+
 void sqlerr(void)
 {
   db_error(sqlca.sqlcode);
This page took 0.291677 seconds and 4 git commands to generate.