]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add support for libcups v3 client credentials API.
authorMichael R Sweet <msweet@msweet.org>
Sat, 19 Oct 2024 19:26:35 +0000 (15:26 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sat, 19 Oct 2024 19:26:35 +0000 (15:26 -0400)
cups/cups-private.h
cups/globals.c
cups/usersys.c

index 98c7aa2c262dfb3dba26a5ee1caf7cfbb4dbfd42..ec5f0f602a55c82d4f424deca9a10ae2fe2fc9d8 100644 (file)
@@ -166,8 +166,7 @@ typedef struct _cups_globals_s              // CUPS global state data
   void                 *oauth_data;    // OAuth user data
   cups_password_cb2_t  password_cb;    // Password callback
   void                 *password_data; // Password user data
-  _http_tls_credentials_t *tls_credentials;
-                                       // Default client credentials, if any
+  _http_tls_credentials_t *credentials;        // Default client credentials, if any
   cups_client_cert_cb_t        client_cert_cb; // Client certificate callback @deprecated@
   void                 *client_cert_data;
                                        // Client certificate user data @deprecated@
index fe7a2adc1aecd2ec51507669e1fb269d111b70eb..724611bea77d37b4c22ece1caffd32cdef8b488c 100644 (file)
@@ -425,7 +425,7 @@ cups_globals_free(_cups_globals_t *cg)      /* I - Pointer to global data */
 
   httpClose(cg->http);
 
-  _httpFreeCredentials(cg->tls_credentials);
+  _httpFreeCredentials(cg->credentials);
 
   cupsFileClose(cg->stdio_files[0]);
   cupsFileClose(cg->stdio_files[1]);
index 9a9b69013175806151afd29c4078bb1ca7a06042..1a000e642d2c20aca7e58a120f163fbea08a98ef 100644 (file)
@@ -330,6 +330,34 @@ cupsSetClientCertCB(
 }
 
 
+//
+// 'cupsSetClientCredentials()' - Set the default credentials to be used for TLS connections.
+//
+// Note: The default credentials are tracked separately for each thread in a
+// program. Multi-threaded programs that override the setting need to do so in
+// each thread for the same setting to be used.
+//
+// @since CUPS 2.5@
+//
+
+bool                                   // O - `true` on success, `false` on failure
+cupsSetClientCredentials(
+    const char *credentials,           // I - PEM-encoded X.509 credentials string
+    const char *key)                   // I - PEM-encoded private key
+{
+  _cups_globals_t *cg = _cupsGlobals();        // Pointer to library globals
+
+
+  if (!credentials || !*credentials || !key || !*key)
+    return (false);
+
+  _httpFreeCredentials(cg->credentials);
+  cg->credentials = _httpCreateCredentials(credentials, key);
+
+  return (cg->credentials != NULL);
+}
+
+
 /*
  * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS
  *                         connections.