From 93bdd10eec39ec5984fa860d76301b54556d095a Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Oct 10 2007 11:24:24 +0000 Subject: - Use ppdev for parallel port Device ID retrieval (bug #311671). --- diff --git a/cups-parallel-id.patch b/cups-parallel-id.patch new file mode 100644 index 0000000..164c10a --- /dev/null +++ b/cups-parallel-id.patch @@ -0,0 +1,133 @@ +diff -up cups-1.2.12/backend/ieee1284.c.parallel-id cups-1.2.12/backend/ieee1284.c +--- cups-1.2.12/backend/ieee1284.c.parallel-id 2006-08-23 04:03:49.000000000 +0100 ++++ cups-1.2.12/backend/ieee1284.c 2007-10-10 12:06:58.000000000 +0100 +@@ -41,6 +41,10 @@ + # include + # define IOCNR_GET_DEVICE_ID 1 + # define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len) ++# include ++# include ++# include ++# include + #endif /* __linux */ + + #ifdef __sun +@@ -77,6 +81,7 @@ backendGetDeviceID( + int manulen; /* Length of manufacturer string */ + #ifdef __linux + int length; /* Length of device ID info */ ++ int got_id = 0; + #endif /* __linux */ + #if defined(__sun) && defined(ECPPIOC_GETDEVID) + struct ecpp_device_id did; /* Device ID buffer */ +@@ -104,15 +109,79 @@ backendGetDeviceID( + *device_id = '\0'; + *make_model = '\0'; + +- if (uri) +- *uri = '\0'; +- + /* + * Get the device ID string... + */ + + #ifdef __linux +- if (!ioctl(fd, LPIOC_GET_DEVICE_ID(device_id_size), device_id)) ++ if (ioctl(fd, LPIOC_GET_DEVICE_ID(device_id_size), device_id)) ++ { ++# ifdef DEBUG ++ printf("backendGetDeviceID: ioctl failed - %s\n", strerror(errno)); ++# endif /* DEBUG */ ++ ++ if (!strcmp (scheme, "parallel") && ++ uri && !strncmp (uri, "parallel:/dev/", 14)) ++ { ++ const char *n; ++ char devparport[16]; ++ int devparportfd; ++ n = uri + strcspn (uri, "0123456789"); ++ strcpy (devparport, "/dev/parport"); ++ strncpy (devparport + 12, n, 3); ++ devparport[15] = '\0'; ++ devparportfd = open (devparport, O_RDWR | O_NOCTTY); ++ if (devparportfd != -1) ++ { ++ /* Put the device into Device ID mode */ ++ int err = ioctl (devparportfd, PPCLAIM); ++ int m = IEEE1284_MODE_COMPAT; ++ ++ if (err) ++ { ++ close (devparportfd); ++ devparportfd = -1; ++ } ++ ++ if (!err) ++ err = ioctl (devparportfd, PPNEGOT, &m); ++ ++ if (!err) ++ { ++ m = IEEE1284_MODE_NIBBLE | IEEE1284_DEVICEID; ++ err = ioctl (devparportfd, PPNEGOT, &m); ++ } ++ ++ /* Make the file descriptor non-blocking to guard against ++ * bugs in the device. */ ++ if (!err) ++ { ++ int f = fcntl (devparportfd, F_GETFL); ++ f |= O_NONBLOCK; ++ err = fcntl (devparportfd, F_SETFL, f); ++ } ++ ++ /* Read the ID */ ++ if (!err) ++ { ++ if (read (devparportfd, device_id, device_id_size) < 2) ++ err = 1; ++ else ++ got_id = 1; ++ } ++ ++ if (devparportfd > -1) ++ { ++ ioctl (devparportfd, PPRELEASE); ++ close (devparportfd); ++ } ++ } ++ } ++ } ++ else ++ got_id = 1; ++ ++ if (got_id) + { + /* + * Extract the length of the device ID string from the first two +@@ -174,6 +243,9 @@ backendGetDeviceID( + + DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id)); + ++ if (uri) ++ *uri = '\0'; ++ + if (!*device_id) + return (-1); + +diff -up cups-1.2.12/backend/parallel.c.parallel-id cups-1.2.12/backend/parallel.c +--- cups-1.2.12/backend/parallel.c.parallel-id 2007-01-03 18:51:27.000000000 +0000 ++++ cups-1.2.12/backend/parallel.c 2007-10-10 12:06:58.000000000 +0100 +@@ -348,9 +348,12 @@ list_devices(void) + * Now grab the IEEE 1284 device ID string... + */ + ++ char device_uri[255 + 9]; ++ strcpy (device_uri, "parallel:"); ++ strcpy (device_uri + 9, device); + if (!backendGetDeviceID(fd, device_id, sizeof(device_id), + make_model, sizeof(make_model), +- NULL, NULL, 0)) ++ "parallel", device_uri, sizeof (device_uri))) + printf("direct parallel:%s \"%s\" \"%s LPT #%d\" \"%s\"\n", device, + make_model, make_model, i + 1, device_id); + else diff --git a/cups.spec b/cups.spec index 6820fc3..d7db989 100644 --- a/cups.spec +++ b/cups.spec @@ -6,7 +6,7 @@ Summary: Common Unix Printing System Name: cups Version: 1.2.12 -Release: 4%{?dist} +Release: 5%{?dist} License: GPL Group: System Environment/Daemons Source: ftp://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2 @@ -37,6 +37,7 @@ Patch11: cups-paps.patch Patch12: cups-wbuffer.patch Patch13: cups-direct-usb.patch Patch14: cups-lpr-help.patch +Patch15: cups-parallel-id.patch Patch16: cups-pid.patch Patch17: cups-relro.patch Patch18: cups-directed-broadcast.patch @@ -146,6 +147,7 @@ lpd emulation. %patch12 -p1 -b .wbuffer %patch13 -p1 -b .direct-usb %patch14 -p1 -b .lpr-help +%patch15 -p1 -b .parallel-id %patch16 -p1 -b .pid %patch17 -p1 -b .relro %patch18 -p1 -b .directed-broadcast @@ -443,6 +445,9 @@ rm -rf $RPM_BUILD_ROOT %{cups_serverbin}/daemon/cups-lpd %changelog +* Wed Oct 10 2007 Tim Waugh 1:1.2.12-5 +- Use ppdev for parallel port Device ID retrieval (bug #311671). + * Thu Aug 9 2007 Tim Waugh 1:1.2.12-4 - Applied patch to fix CVE-2007-3387 (bug #251518).