]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use HTTP_AUTHORIZATION in CGI programs (Issue #246)
authorMichael R Sweet <msweet@msweet.org>
Wed, 16 Apr 2025 16:49:00 +0000 (12:49 -0400)
committerMichael R Sweet <msweet@msweet.org>
Wed, 16 Apr 2025 16:49:00 +0000 (12:49 -0400)
cgi-bin/admin.c
cgi-bin/classes.c
cgi-bin/jobs.c
cgi-bin/printers.c

index d02caf3239cd36996bef8333607095e703afb848..7d19971137328be64e506e8560b8993fa9ab3c41 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Administration CGI for CUPS.
  *
- * Copyright © 2021-2024 by OpenPrinting
+ * Copyright © 2021-2025 by OpenPrinting
  * Copyright © 2007-2021 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products.
  *
@@ -65,17 +65,21 @@ main(void)
 
   fputs("DEBUG: admin.cgi started...\n", stderr);
 
-  http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
-
-  if (!http)
+  if ((http = httpConnect2(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC,  cupsGetEncryption(), /*blocking*/1, /*msec*/30000, /*cancel*/NULL)) == NULL)
   {
-    perror("ERROR: Unable to connect to cupsd");
-    fprintf(stderr, "DEBUG: cupsServer()=\"%s\"\n",
-            cupsServer() ? cupsServer() : "(null)");
-    fprintf(stderr, "DEBUG: ippPort()=%d\n", ippPort());
-    fprintf(stderr, "DEBUG: cupsEncryption()=%d\n", cupsEncryption());
+    fprintf(stderr, "ERROR: Unable to connect to cupsd: %s\n", cupsGetErrorString());
+    fprintf(stderr, "DEBUG: cupsGetServer()=\"%s\"\n", cupsGetServer() ? cupsGetServer() : "(null)");
+    fprintf(stderr, "DEBUG: ippGetPort()=%d\n", ippGetPort());
+    fprintf(stderr, "DEBUG: cupsGetEncryption()=%d\n", cupsGetEncryption());
     exit(1);
   }
+  else
+  {
+    const char *authorization;         /* HTTP_AUTHORIZATION value */
+
+    if ((authorization = getenv("HTTP_AUTHORIZATION")) != NULL && !strncmp(authorization, "Bearer ", 7))
+      httpSetAuthString(http, "Bearer", authorization + 7);
+  }
 
   fprintf(stderr, "DEBUG: http=%p\n", (void *)http);
 
index eb83a920d666c3c1119cc6aeaedaeaca2736c513..c176500677f3cc83a20ef4ee29bc98d96e0a3ff5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Class status CGI for CUPS.
  *
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
  * Copyright © 2007-2016 by Apple Inc.
  * Copyright © 1997-2006 by Easy Software Products.
  *
@@ -9,10 +9,6 @@
  * information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cgi-private.h"
 
 
@@ -87,7 +83,23 @@ main(void)
   * Connect to the HTTP server...
   */
 
-  http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
+  if ((http = httpConnect2(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC,  cupsGetEncryption(), /*blocking*/1, /*msec*/30000, /*cancel*/NULL)) == NULL)
+  {
+    fprintf(stderr, "ERROR: Unable to connect to cupsd: %s\n", cupsGetErrorString());
+    fprintf(stderr, "DEBUG: cupsGetServer()=\"%s\"\n", cupsGetServer() ? cupsGetServer() : "(null)");
+    fprintf(stderr, "DEBUG: ippGetPort()=%d\n", ippGetPort());
+    fprintf(stderr, "DEBUG: cupsGetEncryption()=%d\n", cupsGetEncryption());
+    exit(1);
+  }
+  else
+  {
+    const char *authorization;         /* HTTP_AUTHORIZATION value */
+
+    if ((authorization = getenv("HTTP_AUTHORIZATION")) != NULL && !strncmp(authorization, "Bearer ", 7))
+      httpSetAuthString(http, "Bearer", authorization + 7);
+  }
+
+  fprintf(stderr, "DEBUG: http=%p\n", (void *)http);
 
  /*
   * Get the default printer...
index 66a4f81a2ad9cb5332239e3ec35789456c78872c..3bbf18488561a3eeb9d61111ff05712837ff845e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Job status CGI for CUPS.
  *
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
  * Copyright © 2007-2014 by Apple Inc.
  * Copyright © 1997-2006 by Easy Software Products.
  *
@@ -9,10 +9,6 @@
  * information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cgi-private.h"
 
 
@@ -53,7 +49,23 @@ main(void)
   * Connect to the HTTP server...
   */
 
-  http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
+  if ((http = httpConnect2(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC,  cupsGetEncryption(), /*blocking*/1, /*msec*/30000, /*cancel*/NULL)) == NULL)
+  {
+    fprintf(stderr, "ERROR: Unable to connect to cupsd: %s\n", cupsGetErrorString());
+    fprintf(stderr, "DEBUG: cupsGetServer()=\"%s\"\n", cupsGetServer() ? cupsGetServer() : "(null)");
+    fprintf(stderr, "DEBUG: ippGetPort()=%d\n", ippGetPort());
+    fprintf(stderr, "DEBUG: cupsGetEncryption()=%d\n", cupsGetEncryption());
+    exit(1);
+  }
+  else
+  {
+    const char *authorization;         /* HTTP_AUTHORIZATION value */
+
+    if ((authorization = getenv("HTTP_AUTHORIZATION")) != NULL && !strncmp(authorization, "Bearer ", 7))
+      httpSetAuthString(http, "Bearer", authorization + 7);
+  }
+
+  fprintf(stderr, "DEBUG: http=%p\n", (void *)http);
 
  /*
   * Get the job ID, if any...
index b20c0a9ff24282d28c9975a9c56054f1f1409c72..9aeab33b4622382da3f7a773d78b501e518a5618 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Printer status CGI for CUPS.
  *
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
  * Copyright © 2007-2016 by Apple Inc.
  * Copyright © 1997-2006 by Easy Software Products.
  *
@@ -9,10 +9,6 @@
  * information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cgi-private.h"
 #include <errno.h>
 
@@ -88,7 +84,23 @@ main(void)
   * Connect to the HTTP server...
   */
 
-  http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
+  if ((http = httpConnect2(cupsGetServer(), ippGetPort(), /*addrlist*/NULL, AF_UNSPEC,  cupsGetEncryption(), /*blocking*/1, /*msec*/30000, /*cancel*/NULL)) == NULL)
+  {
+    fprintf(stderr, "ERROR: Unable to connect to cupsd: %s\n", cupsGetErrorString());
+    fprintf(stderr, "DEBUG: cupsGetServer()=\"%s\"\n", cupsGetServer() ? cupsGetServer() : "(null)");
+    fprintf(stderr, "DEBUG: ippGetPort()=%d\n", ippGetPort());
+    fprintf(stderr, "DEBUG: cupsGetEncryption()=%d\n", cupsGetEncryption());
+    exit(1);
+  }
+  else
+  {
+    const char *authorization;         /* HTTP_AUTHORIZATION value */
+
+    if ((authorization = getenv("HTTP_AUTHORIZATION")) != NULL && !strncmp(authorization, "Bearer ", 7))
+      httpSetAuthString(http, "Bearer", authorization + 7);
+  }
+
+  fprintf(stderr, "DEBUG: http=%p\n", (void *)http);
 
  /*
   * Get the default printer...