Skip to content

Commit 0bb31d6

Browse files
authored
Merge commit from fork
Fix various issues in cupsd
2 parents 0ef9183 + 524749b commit 0bb31d6

14 files changed

Lines changed: 149 additions & 18 deletions

File tree

conf/cups-files.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
SystemGroup @CUPS_SYSTEM_GROUPS@
2323
@CUPS_SYSTEM_AUTHKEY@
2424

25+
# Are Unix domain socket peer credentials used for authorization?
26+
PeerCred @CUPS_PEER_CRED@
27+
2528
# User that is substituted for unauthenticated (remote) root accesses...
2629
#RemoteRoot remroot
2730

config-scripts/cups-defaults.m4

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dnl
22
dnl Default cupsd configuration settings for CUPS.
33
dnl
4-
dnl Copyright © 2020-2024 by OpenPrinting.
4+
dnl Copyright © 2020-2025 by OpenPrinting.
55
dnl Copyright © 2007-2018 by Apple Inc.
66
dnl Copyright © 2006-2007 by Easy Software Products, all rights reserved.
77
dnl
@@ -95,6 +95,15 @@ AC_ARG_WITH([log_level], AS_HELP_STRING([--with-log-level], [set default LogLeve
9595
AC_SUBST([CUPS_LOG_LEVEL])
9696
AC_DEFINE_UNQUOTED([CUPS_DEFAULT_LOG_LEVEL], ["$CUPS_LOG_LEVEL"], [Default LogLevel value.])
9797

98+
dnl Default PeerCred
99+
AC_ARG_WITH([peer_cred], AS_HELP_STRING([--with-peer-cred], [set default PeerCred value (on/off/root-only), default=on]), [
100+
CUPS_PEER_CRED="$withval"
101+
], [
102+
CUPS_PEER_CRED="on"
103+
])
104+
AC_SUBST([CUPS_PEER_CRED])
105+
AC_DEFINE_UNQUOTED([CUPS_DEFAULT_PEER_CRED], ["$CUPS_PEER_CRED"], [Default PeerCred value.])
106+
98107
dnl Default AccessLogLevel
99108
AC_ARG_WITH(access_log_level, [ --with-access-log-level set default AccessLogLevel value, default=none],
100109
CUPS_ACCESS_LOG_LEVEL="$withval",

config.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
#define CUPS_DEFAULT_ERROR_POLICY "stop-printer"
8787

8888

89+
/*
90+
* Default PeerCred value...
91+
*/
92+
93+
#define CUPS_DEFAULT_PEER_CRED "on"
94+
95+
8996
/*
9097
* Default MaxCopies value...
9198
*/

configure

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ CUPS_BROWSING
669669
CUPS_SYNC_ON_CLOSE
670670
CUPS_PAGE_LOG_FORMAT
671671
CUPS_ACCESS_LOG_LEVEL
672+
CUPS_PEER_CRED
672673
CUPS_LOG_LEVEL
673674
CUPS_FATAL_ERRORS
674675
CUPS_ERROR_POLICY
@@ -917,6 +918,7 @@ with_max_log_size
917918
with_error_policy
918919
with_fatal_errors
919920
with_log_level
921+
with_peer_cred
920922
with_access_log_level
921923
enable_page_logging
922924
enable_sync_on_close
@@ -1648,6 +1650,8 @@ Optional Packages:
16481650
--with-error-policy set default ErrorPolicy value, default=stop-printer
16491651
--with-fatal-errors set default FatalErrors value, default=config
16501652
--with-log-level set default LogLevel value, default=warn
1653+
--with-peer-cred set default PeerCred value (on/off/root-only),
1654+
default=on
16511655
--with-access-log-level set default AccessLogLevel value, default=none
16521656
--with-local-protocols set default BrowseLocalProtocols, default=""
16531657
--with-cups-user set default user for CUPS
@@ -11290,6 +11294,24 @@ printf "%s\n" "#define CUPS_DEFAULT_LOG_LEVEL \"$CUPS_LOG_LEVEL\"" >>confdefs.h
1129011294

1129111295

1129211296

11297+
# Check whether --with-peer_cred was given.
11298+
if test ${with_peer_cred+y}
11299+
then :
11300+
withval=$with_peer_cred;
11301+
CUPS_PEER_CRED="$withval"
11302+
11303+
else $as_nop
11304+
11305+
CUPS_PEER_CRED="on"
11306+
11307+
fi
11308+
11309+
11310+
11311+
printf "%s\n" "#define CUPS_DEFAULT_PEER_CRED \"$CUPS_PEER_CRED\"" >>confdefs.h
11312+
11313+
11314+
1129311315
# Check whether --with-access_log_level was given.
1129411316
if test ${with_access_log_level+y}
1129511317
then :

doc/help/man-cups-files.conf.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ <h3 id="cups-files.conf-5.description.directives">Directives</h3>
157157
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>PassEnv </strong><em>variable </em>[ ... <em>variable </em>]<br>
158158
Passes the specified environment variable(s) to child processes.
159159
Note: the standard CUPS filter and backend environment variables cannot be overridden using this directive.
160+
</p>
161+
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>PeerCred off</strong><br>
162+
</p>
163+
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>PeerCred on</strong><br>
164+
</p>
165+
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>PeerCred root-only</strong><br>
166+
Specifies whether peer credentials are used for authorization when communicating over the UNIX domain socket.
167+
When <strong>on</strong>, the peer credentials of any user are accepted for authorization.
168+
The value <strong>off</strong> disables the use of peer credentials entirely, while the value <strong>root-only</strong> allows peer credentials only for the root user.
169+
Note: for security reasons, the <strong>on</strong> setting is reduced to <strong>root-only</strong> for authorization of PUT requests.
160170
</p>
161171
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>RemoteRoot </strong><em>username</em><br>
162172
Specifies the username that is associated with unauthenticated accesses by clients claiming to be the root user.
@@ -279,6 +289,6 @@ <h2 id="cups-files.conf-5.see-also">See Also</h2>
279289
CUPS Online Help (<a href="http://localhost:631/help">http://localhost:631/help</a>)
280290
</p>
281291
<h2 id="cups-files.conf-5.copyright">Copyright</h2>
282-
<p>Copyright &copy; 2020-2024 by OpenPrinting.
292+
<p>Copyright &copy; 2020-2025 by OpenPrinting.
283293
</body>
284294
</html>

man/cups-files.conf.5

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.\"
22
.\" cups-files.conf man page for CUPS.
33
.\"
4-
.\" Copyright © 2020-2024 by OpenPrinting.
4+
.\" Copyright © 2020-2025 by OpenPrinting.
55
.\" Copyright © 2007-2019 by Apple Inc.
66
.\" Copyright © 1997-2006 by Easy Software Products.
77
.\"
88
.\" Licensed under Apache License v2.0. See the file "LICENSE" for more
99
.\" information.
1010
.\"
11-
.TH cups-files.conf 5 "CUPS" "2024-04-16" "OpenPrinting"
11+
.TH cups-files.conf 5 "CUPS" "2025-10-08" "OpenPrinting"
1212
.SH NAME
1313
cups\-files.conf \- file and directory configuration file for cups
1414
.SH DESCRIPTION
@@ -170,6 +170,17 @@ The default is "/var/log/cups/page_log".
170170
\fBPassEnv \fIvariable \fR[ ... \fIvariable \fR]
171171
Passes the specified environment variable(s) to child processes.
172172
Note: the standard CUPS filter and backend environment variables cannot be overridden using this directive.
173+
.\"#PeerCred
174+
.TP 5
175+
\fBPeerCred off\fR
176+
.TP 5
177+
\fBPeerCred on\fR
178+
.TP 5
179+
\fBPeerCred root-only\fR
180+
Specifies whether peer credentials are used for authorization when communicating over the UNIX domain socket.
181+
When \fBon\fR, the peer credentials of any user are accepted for authorization.
182+
The value \fBoff\fR disables the use of peer credentials entirely, while the value \fBroot-only\fR allows peer credentials only for the root user.
183+
Note: for security reasons, the \fBon\fR setting is reduced to \fBroot-only\fR for authorization of PUT requests.
173184
.\"#RemoteRoot
174185
.TP 5
175186
\fBRemoteRoot \fIusername\fR
@@ -293,4 +304,4 @@ command is used instead.
293304
.BR subscriptions.conf (5),
294305
CUPS Online Help (http://localhost:631/help)
295306
.SH COPYRIGHT
296-
Copyright \[co] 2020-2024 by OpenPrinting.
307+
Copyright \[co] 2020-2025 by OpenPrinting.

scheduler/auth.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */
462462
}
463463
#endif /* HAVE_AUTHORIZATION_H */
464464
#if defined(SO_PEERCRED) && defined(AF_LOCAL)
465-
else if (!strncmp(authorization, "PeerCred ", 9) &&
465+
else if (PeerCred != CUPSD_PEERCRED_OFF && !strncmp(authorization, "PeerCred ", 9) &&
466466
con->http->hostaddr->addr.sa_family == AF_LOCAL && con->best)
467467
{
468468
/*
@@ -505,6 +505,12 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */
505505
}
506506
#endif /* HAVE_AUTHORIZATION_H */
507507

508+
if ((PeerCred == CUPSD_PEERCRED_ROOTONLY || httpGetState(con->http) == HTTP_STATE_PUT_RECV) && strcmp(authorization + 9, "root"))
509+
{
510+
cupsdLogClient(con, CUPSD_LOG_INFO, "User \"%s\" is not allowed to use peer credentials.", authorization + 9);
511+
return;
512+
}
513+
508514
if ((pwd = getpwnam(authorization + 9)) == NULL)
509515
{
510516
cupsdLogClient(con, CUPSD_LOG_ERROR, "User \"%s\" does not exist.", authorization + 9);

scheduler/auth.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#define CUPSD_AUTH_LIMIT_ALL 127 /* Limit all requests */
4949
#define CUPSD_AUTH_LIMIT_IPP 128 /* Limit IPP requests */
5050

51+
#define CUPSD_PEERCRED_OFF 0 /* Don't allow PeerCred authorization */
52+
#define CUPSD_PEERCRED_ON 1 /* Allow PeerCred authorization for all users */
53+
#define CUPSD_PEERCRED_ROOTONLY 2 /* Allow PeerCred authorization for root user */
54+
5155
#define IPP_ANY_OPERATION (ipp_op_t)0
5256
/* Any IPP operation */
5357
#define IPP_BAD_OPERATION (ipp_op_t)-1
@@ -115,6 +119,9 @@ VAR http_encryption_t DefaultEncryption VALUE(HTTP_ENCRYPTION_REQUIRED);
115119
VAR cups_array_t *Locations VALUE(NULL);
116120
/* Authorization locations */
117121

122+
VAR int PeerCred VALUE(CUPSD_PEERCRED_ON);
123+
/* Allow PeerCred authorization? */
124+
118125
VAR cups_array_t *OAuthGroups VALUE(NULL);
119126
/* OAuthGroup entries */
120127
VAR cups_json_t *OAuthJWKS VALUE(NULL),

scheduler/client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ cupsdSendHeader(
22142214
auth_size = sizeof(auth_str) - (size_t)(auth_key - auth_str);
22152215

22162216
#if defined(SO_PEERCRED) && defined(AF_LOCAL)
2217-
if (httpAddrGetFamily(httpGetAddress(con->http)) == AF_LOCAL)
2217+
if (PeerCred != CUPSD_PEERCRED_OFF && httpAddrGetFamily(httpGetAddress(con->http)) == AF_LOCAL)
22182218
{
22192219
cupsCopyString(auth_key, ", PeerCred", auth_size);
22202220
auth_key += 10;

scheduler/conf.c

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum
4444
{
4545
CUPSD_VARTYPE_INTEGER, /* Integer option */
4646
CUPSD_VARTYPE_TIME, /* Time interval option */
47+
CUPSD_VARTYPE_NULLSTRING, /* String option or NULL/empty string */
4748
CUPSD_VARTYPE_STRING, /* String option */
4849
CUPSD_VARTYPE_BOOLEAN, /* Boolean option */
4950
CUPSD_VARTYPE_PATHNAME, /* File/directory name option */
@@ -65,7 +66,7 @@ typedef struct
6566
static const cupsd_var_t cupsd_vars[] =
6667
{
6768
{ "AutoPurgeJobs", &JobAutoPurge, CUPSD_VARTYPE_BOOLEAN },
68-
{ "BrowseDNSSDSubTypes", &DNSSDSubTypes, CUPSD_VARTYPE_STRING },
69+
{ "BrowseDNSSDSubTypes", &DNSSDSubTypes, CUPSD_VARTYPE_NULLSTRING },
6970
{ "BrowseWebIF", &BrowseWebIF, CUPSD_VARTYPE_BOOLEAN },
7071
{ "Browsing", &Browsing, CUPSD_VARTYPE_BOOLEAN },
7172
{ "Classification", &Classification, CUPSD_VARTYPE_STRING },
@@ -114,7 +115,7 @@ static const cupsd_var_t cupsd_vars[] =
114115
{ "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER },
115116
{ "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser, CUPSD_VARTYPE_INTEGER },
116117
{ "MultipleOperationTimeout", &MultipleOperationTimeout, CUPSD_VARTYPE_TIME },
117-
{ "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_STRING },
118+
{ "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_NULLSTRING },
118119
{ "PreserveJobFiles", &JobFiles, CUPSD_VARTYPE_TIME },
119120
{ "PreserveJobHistory", &JobHistory, CUPSD_VARTYPE_TIME },
120121
{ "ReloadTimeout", &ReloadTimeout, CUPSD_VARTYPE_TIME },
@@ -811,6 +812,13 @@ cupsdReadConfiguration(void)
811812
IdleExitTimeout = 60;
812813
#endif /* HAVE_ONDEMAND */
813814

815+
if (!strcmp(CUPS_DEFAULT_PEER_CRED, "off"))
816+
PeerCred = CUPSD_PEERCRED_OFF;
817+
else if (!strcmp(CUPS_DEFAULT_PEER_CRED, "root-only"))
818+
PeerCred = CUPSD_PEERCRED_ROOTONLY;
819+
else
820+
PeerCred = CUPSD_PEERCRED_ON;
821+
814822
/*
815823
* Setup environment variables...
816824
*/
@@ -1899,7 +1907,7 @@ get_addr_and_mask(const char *value, /* I - String from config file */
18991907

19001908
family = AF_INET6;
19011909

1902-
for (i = 0, ptr = value + 1; *ptr && i < 8; i ++)
1910+
for (i = 0, ptr = value + 1; *ptr && i >= 0 && i < 8; i ++)
19031911
{
19041912
if (*ptr == ']')
19051913
break;
@@ -2045,7 +2053,7 @@ get_addr_and_mask(const char *value, /* I - String from config file */
20452053
#ifdef AF_INET6
20462054
if (family == AF_INET6)
20472055
{
2048-
if (i > 128)
2056+
if (i < 0 || i > 128)
20492057
return (0);
20502058

20512059
i = 128 - i;
@@ -2079,7 +2087,7 @@ get_addr_and_mask(const char *value, /* I - String from config file */
20792087
else
20802088
#endif /* AF_INET6 */
20812089
{
2082-
if (i > 32)
2090+
if (i < 0 || i > 32)
20832091
return (0);
20842092

20852093
mask[0] = 0xffffffff;
@@ -2996,7 +3004,17 @@ parse_variable(
29963004
cupsdSetString((char **)var->ptr, temp);
29973005
break;
29983006

3007+
case CUPSD_VARTYPE_NULLSTRING :
3008+
cupsdSetString((char **)var->ptr, value);
3009+
break;
3010+
29993011
case CUPSD_VARTYPE_STRING :
3012+
if (!value)
3013+
{
3014+
cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d of %s.", line, linenum, filename);
3015+
return (0);
3016+
}
3017+
30003018
cupsdSetString((char **)var->ptr, value);
30013019
break;
30023020
}
@@ -3505,9 +3523,10 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
35053523
line, value ? " " : "", value ? value : "", linenum,
35063524
ConfigurationFile, CupsFilesFile);
35073525
}
3508-
else
3509-
parse_variable(ConfigurationFile, linenum, line, value,
3510-
sizeof(cupsd_vars) / sizeof(cupsd_vars[0]), cupsd_vars);
3526+
else if (!parse_variable(ConfigurationFile, linenum, line, value,
3527+
sizeof(cupsd_vars) / sizeof(cupsd_vars[0]), cupsd_vars) &&
3528+
(FatalErrors & CUPSD_FATAL_CONFIG))
3529+
return (0);
35113530
}
35123531

35133532
return (1);
@@ -3720,6 +3739,31 @@ read_cups_files_conf(cups_file_t *fp) /* I - File to read from */
37203739
break;
37213740
}
37223741
}
3742+
else if (!_cups_strcasecmp(line, "PeerCred") && value)
3743+
{
3744+
/*
3745+
* PeerCred {off,on,root-only}
3746+
*/
3747+
3748+
if (!_cups_strcasecmp(value, "off"))
3749+
{
3750+
PeerCred = CUPSD_PEERCRED_OFF;
3751+
}
3752+
else if (!_cups_strcasecmp(value, "on"))
3753+
{
3754+
PeerCred = CUPSD_PEERCRED_ON;
3755+
}
3756+
else if (!_cups_strcasecmp(value, "root-only"))
3757+
{
3758+
PeerCred = CUPSD_PEERCRED_ROOTONLY;
3759+
}
3760+
else
3761+
{
3762+
cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown PeerCred \"%s\" on line %d of %s.", value, linenum, CupsFilesFile);
3763+
if (FatalErrors & CUPSD_FATAL_CONFIG)
3764+
return (0);
3765+
}
3766+
}
37233767
else if (!_cups_strcasecmp(line, "PrintcapFormat") && value)
37243768
{
37253769
/*

0 commit comments

Comments
 (0)