/* $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
#include "util.h"
+#define MACHINE_CHWADDR_SIZE 18
+
EXEC SQL INCLUDE sqlca;
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];
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++)
{
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
}
strcpy(ohwaddr, hwaddr);
+ hwcolonify(hwaddr, chwaddr);
+
strtrim(name);
strtrim(addr);
strtrim(logaddr);
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");
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);