Skip to content

Commit 5ae0063

Browse files
committed
Mirror fixes and changes from CUPS 2.x:
- New "claims" argument for cupsJWTNew. - Support CUPS_USERCONFIG and CUPS_SYSCONFIG environment variables. - Add cupsOAuthGetUserId to use the userinfo endpoint, with caching. - Support sharing the metadata, JWKS, and client_id/secret values between the system and user.
1 parent af31f81 commit 5ae0063

File tree

7 files changed

+305
-65
lines changed

7 files changed

+305
-65
lines changed

CHANGES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ Changes in libcups
44
libcups v3.0.0 (YYYY-MM-DD)
55
---------------------------
66

7-
- Added `cupsOAuthGetJWKS` API.
7+
- Added `cupsOAuthGetJWKS` and `cupsOAuthGetUserId` APIs.
88
- Added `httpGetCookieValue` and `httpGetSecurity` APIs.
9+
- Updated the `cupsOAuth` APIs to support sharing of some OAuth values between
10+
the system (root) and per-user cache values.
11+
- Updated the `cupsJWTNew` API to accept an optional JSON claims object.
912
- Updated the `httpSetCookie` API to support multiple "Set-Cookie:" header
1013
values.
1114
- Updated `ippfind` to use `cupsGetClock` API.

cups/globals.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ DllMain(HINSTANCE hinst, // I - DLL module handle
153153
static _cups_globals_t * // O - Pointer to global data
154154
cups_globals_alloc(void)
155155
{
156-
_cups_globals_t *cg = malloc(sizeof(_cups_globals_t));
156+
const char *cups_userconfig = getenv("CUPS_USERCONFIG");
157+
// Location of user config files
158+
_cups_globals_t *cg = calloc(1, sizeof(_cups_globals_t));
157159
// Pointer to global data
158160
#ifdef _WIN32
159161
HKEY key; // Registry key
@@ -231,7 +233,9 @@ cups_globals_alloc(void)
231233

232234
DEBUG_printf("cups_globals_alloc: USERPROFILE=\"%s\"", userprofile);
233235

234-
if (userprofile)
236+
if (cups_userconfig)
237+
cupsCopyString(userconfig, cups_userconfig, sizeof(userconfig));
238+
else if (userprofile)
235239
snprintf(userconfig, sizeof(userconfig), "%s/AppData/Local/cups", userprofile);
236240
else
237241
cupsCopyString(userconfig, "C:/cups", sizeof(userconfig));
@@ -267,15 +271,20 @@ cups_globals_alloc(void)
267271
// the system directories...
268272
cg->datadir = CUPS_DATADIR;
269273
cg->sysconfig = CUPS_SERVERROOT;
274+
275+
cups_userconfig = NULL;
270276
}
271277
else
272278
{
273279
// Allow directories to be overridden by environment variables.
274280
if ((cg->datadir = getenv("CUPS_DATADIR")) == NULL)
275281
cg->datadir = CUPS_DATADIR;
276282

277-
if ((cg->sysconfig = getenv("CUPS_SERVERROOT")) == NULL)
278-
cg->sysconfig = CUPS_SERVERROOT;
283+
if ((cg->sysconfig = getenv("CUPS_SYSCONFIG")) == NULL)
284+
{
285+
if ((cg->sysconfig = getenv("CUPS_SERVERROOT")) == NULL)
286+
cg->sysconfig = CUPS_SERVERROOT;
287+
}
279288
}
280289

281290
if (!getuid())
@@ -284,7 +293,14 @@ cups_globals_alloc(void)
284293
cg->userconfig = strdup(cg->sysconfig);
285294
return (cg);
286295
}
296+
else if (cups_userconfig)
297+
{
298+
// Use the value of the CUPS_USERCONFIG environment variable...
299+
cg->userconfig = strdup(cups_userconfig);
300+
return (cg);
301+
}
287302

303+
// Find the user configuration directory relative to the home directory...
288304
# ifdef __APPLE__
289305
if (!home)
290306
#else

cups/jwt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ cupsJWTMakePublicKey(cups_json_t *jwk) // I - Private JSON Web Key
12281228
//
12291229

12301230
cups_jwt_t * // O - JWT object
1231-
cupsJWTNew(const char *type) // I - JWT type or `NULL` for default ("JWT")
1231+
cupsJWTNew(const char *type, // I - JWT type or `NULL` for default ("JWT")
1232+
cups_json_t *claims) // I - JSON claims or `NULL` for empty
12321233
{
12331234
cups_jwt_t *jwt; // JWT object
12341235

@@ -1239,7 +1240,12 @@ cupsJWTNew(const char *type) // I - JWT type or `NULL` for default ("JWT")
12391240
{
12401241
cupsJSONNewString(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, "typ"), type ? type : "JWT");
12411242

1242-
if ((jwt->claims = cupsJSONNew(NULL, NULL, CUPS_JTYPE_OBJECT)) != NULL)
1243+
if (claims)
1244+
jwt->claims = claims;
1245+
else
1246+
jwt->claims = cupsJSONNew(NULL, NULL, CUPS_JTYPE_OBJECT);
1247+
1248+
if (jwt->claims)
12431249
return (jwt);
12441250
}
12451251
}

cups/jwt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// JSON Web Token API definitions for CUPS.
33
//
4-
// Copyright © 2023-2024 by OpenPrinting.
4+
// Copyright © 2023-2025 by OpenPrinting.
55
//
66
// Licensed under Apache License v2.0. See the file "LICENSE" for more
77
// information.
@@ -79,7 +79,7 @@ extern cups_jwt_t *cupsJWTImportString(const char *s, cups_jws_format_t format)
7979
extern cups_json_t *cupsJWTLoadCredentials(const char *path, const char *common_name) _CUPS_PUBLIC;
8080
extern cups_json_t *cupsJWTMakePrivateKey(cups_jwa_t alg) _CUPS_PUBLIC;
8181
extern cups_json_t *cupsJWTMakePublicKey(cups_json_t *jwk) _CUPS_PUBLIC;
82-
extern cups_jwt_t *cupsJWTNew(const char *type) _CUPS_PUBLIC;
82+
extern cups_jwt_t *cupsJWTNew(const char *type, cups_json_t *claims) _CUPS_PUBLIC;
8383
extern void cupsJWTSetClaimNumber(cups_jwt_t *jwt, const char *claim, double value) _CUPS_PUBLIC;
8484
extern void cupsJWTSetClaimString(cups_jwt_t *jwt, const char *claim, const char *value) _CUPS_PUBLIC;
8585
extern void cupsJWTSetClaimValue(cups_jwt_t *jwt, const char *claim, cups_json_t *value) _CUPS_PUBLIC;

0 commit comments

Comments
 (0)