X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/688f820e65ca062c8128659911caa6aaec060cde..87a02088f451073ac5fbf197e4ce414edb5ab4ad:/gen/dhcp.pc diff --git a/gen/dhcp.pc b/gen/dhcp.pc index 66ebe4f7..8ece8a47 100644 --- a/gen/dhcp.pc +++ b/gen/dhcp.pc @@ -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]; @@ -58,13 +63,15 @@ int main(int argc, char **argv) EXEC SQL WHENEVER SQLERROR DO sqlerr(); /* 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' 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' + AND m.status = 1 AND m.address != 'unassigned'; EXEC SQL OPEN csr_spool; for (i = 0; i < alcount; i++) { @@ -110,6 +117,8 @@ int main(int argc, char **argv) } strcpy(ohwaddr, hwaddr); + hwcolonify(hwaddr, chwaddr); + strtrim(name); strtrim(addr); strtrim(logaddr); @@ -129,9 +138,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 +231,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);