]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
backen/lpd.c: Fix port reserving behavior for RFC 1179
authorZdenek Dohnal <zdohnal@redhat.com>
Wed, 13 Sep 2023 11:59:18 +0000 (13:59 +0200)
committerZdenek Dohnal <zdohnal@redhat.com>
Wed, 13 Sep 2023 11:59:18 +0000 (13:59 +0200)
From master commit:
https://github.com/OpenPrinting/cups/commit/9f0ce570117aa

Fixes #743

CHANGES.md
backend/lpd.c

index 5832cd13d2ea63a50ae773cd87ab3a0c0f62b758..5c5323d54551934c16ec09a8ef68d7087bc8bad8 100644 (file)
@@ -10,6 +10,7 @@ Changes in CUPS v2.4.7 (TBA)
 - Fixed hanging of `lpstat` on IBM AIX (Issue #773)
 - Fixed printing to stderr if we can't open cups-files.conf (Issue #777)
 - Fixed purging job files via `cancel -x` (Issue #742)
+- Fixed RFC 1179 port reserving behavior in LPD backend (Issue #743)
 - Fixed a bug in the PPD command interpretation code (Issue #768)
 
 
index 425b8512ac0550eb698a92b5ae3fd517aedfb37b..2089b537dfa0b0f14868a018cd4e8c594b39730f 100644 (file)
@@ -70,7 +70,7 @@ static int    abort_job = 0;          /* Non-zero if we get SIGTERM */
  * Local functions...
  */
 
-static int     cups_rresvport(int *port, int family);
+static int     cups_rresvport(int *port, int min, int family);
 static int     lpd_command(int lpd_fd, char *format, ...)
 #    ifdef __GNUC__
 __attribute__ ((__format__ (__printf__, 2, 3)))
@@ -552,6 +552,7 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
 
 static int                             /* O  - Socket or -1 on error */
 cups_rresvport(int *port,              /* IO - Port number to bind to */
+               int min,                        /* I  - Minimim port number use */
                int family)             /* I  - Address family */
 {
   http_addr_t  addr;                   /* Socket address */
@@ -576,7 +577,7 @@ cups_rresvport(int *port,           /* IO - Port number to bind to */
   * Try to bind the socket to a reserved port...
   */
 
-  while (*port > 511)
+  while (*port >= min)
   {
    /*
     * Set the port number...
@@ -801,11 +802,14 @@ lpd_queue(const char      *hostname,      /* I - Host to connect to */
       else
       {
        /*
-       * We're running as root and want to comply with RFC 1179.  Reserve a
-       * privileged lport between 721 and 731...
+       * We're running as root and want to either:
+       * a) comply with RFC 1179 and reserve a lport between 721 and 731
+       * b) just reserve a privileged port between 512 and 1023
        */
 
-       if ((fd = cups_rresvport(&lport, addr->addr.addr.sa_family)) < 0)
+       if ((fd = cups_rresvport(&lport,
+                                reserve == RESERVE_RFC1179 ? 721 : 512,
+                                addr->addr.addr.sa_family)) < 0)
        {
          perror("DEBUG: Unable to reserve port");
          sleep(1);