Skip to content

Commit 2994a57

Browse files
committed
Sanitize requesting-user-name as needed (Issue #1145)
1 parent dc5ebe3 commit 2994a57

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

backend/ipp.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ main(int argc, /* I - Number of command-line args */
195195
hostname[1024], /* Hostname */
196196
resource[1024], /* Resource info (printer name) */
197197
addrname[256], /* Address name */
198+
username[IPP_MAX_NAME], /* Requesting user name */
198199
*optptr, /* Pointer to URI options */
199200
*name, /* Name of option */
200201
*value, /* Value of option */
@@ -311,6 +312,8 @@ main(int argc, /* I - Number of command-line args */
311312
return (CUPS_BACKEND_STOP);
312313
}
313314

315+
cupsCopyString(username, argv[2], sizeof(username));
316+
314317
/*
315318
* Get the device URI...
316319
*/
@@ -1437,7 +1440,7 @@ main(int argc, /* I - Number of command-line args */
14371440

14381441
monitor.uri = uri;
14391442
monitor.hostname = hostname;
1440-
monitor.user = argv[2];
1443+
monitor.user = username;
14411444
monitor.resource = resource;
14421445
monitor.port = port;
14431446
monitor.version = version;
@@ -1474,7 +1477,7 @@ main(int argc, /* I - Number of command-line args */
14741477

14751478
while (!job_canceled && validate_job)
14761479
{
1477-
request = new_request(IPP_OP_VALIDATE_JOB, version, uri, argv[2],
1480+
request = new_request(IPP_OP_VALIDATE_JOB, version, uri, username,
14781481
monitor.job_name, num_options, options, compression,
14791482
copies_sup ? copies : 1, document_format, pc, ppd,
14801483
media_col_sup, doc_handling_sup, print_color_mode_sup, print_scaling_sup);
@@ -1514,6 +1517,26 @@ main(int argc, /* I - Number of command-line args */
15141517
}
15151518
}
15161519
}
1520+
else if ((ipp_status == IPP_STATUS_ERROR_BAD_REQUEST || ipp_status == IPP_STATUS_ERROR_INTERNAL) && !strcmp(username, argv[2]))
1521+
{
1522+
/*
1523+
* Issue #1145: Some printers have trouble with valid character in the
1524+
* requesting-user-name attribute. Sanitize the username and try again
1525+
* if so...
1526+
*/
1527+
1528+
char *argptr = argv[2], /* Pointer into local username */
1529+
*userptr = username; /* Pointer into requesting-user-name value */
1530+
1531+
while (*argptr && userptr < (username + sizeof(username) - 1))
1532+
{
1533+
if (isalnum(*argptr & 255))
1534+
*userptr++ = *argptr;
1535+
argptr ++;
1536+
}
1537+
1538+
*userptr = '\0';
1539+
}
15171540

15181541
ippDelete(response);
15191542

@@ -1597,7 +1620,7 @@ main(int argc, /* I - Number of command-line args */
15971620

15981621
request = new_request((num_files > 1 || create_job) ? IPP_OP_CREATE_JOB :
15991622
IPP_OP_PRINT_JOB,
1600-
version, uri, argv[2], monitor.job_name, num_options,
1623+
version, uri, username, monitor.job_name, num_options,
16011624
options, compression, copies_sup ? copies : 1,
16021625
document_format, pc, ppd, media_col_sup,
16031626
doc_handling_sup, print_color_mode_sup, print_scaling_sup);
@@ -1809,9 +1832,9 @@ main(int argc, /* I - Number of command-line args */
18091832
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
18101833
job_id);
18111834

1812-
if (argv[2][0])
1835+
if (username[0])
18131836
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1814-
"requesting-user-name", NULL, argv[2]);
1837+
"requesting-user-name", NULL, username);
18151838

18161839
ippAddBoolean(request, IPP_TAG_OPERATION, "last-document",
18171840
(i + 1) >= num_files);
@@ -1929,7 +1952,7 @@ main(int argc, /* I - Number of command-line args */
19291952

19301953
fputs("JOBSTATE: cups-retry-as-raster\n", stderr);
19311954
if (job_id > 0)
1932-
cancel_job(http, uri, job_id, resource, argv[2], version);
1955+
cancel_job(http, uri, job_id, resource, username, version);
19331956

19341957
goto cleanup;
19351958
}
@@ -1945,7 +1968,7 @@ main(int argc, /* I - Number of command-line args */
19451968
*/
19461969

19471970
if (job_id > 0)
1948-
cancel_job(http, uri, job_id, resource, argv[2], version);
1971+
cancel_job(http, uri, job_id, resource, username, version);
19491972

19501973
goto cleanup;
19511974
}
@@ -1984,7 +2007,7 @@ main(int argc, /* I - Number of command-line args */
19842007
ipp_status = IPP_STATUS_ERROR_INTERNAL;
19852008

19862009
if (job_id > 0)
1987-
cancel_job(http, uri, job_id, resource, argv[2], version);
2010+
cancel_job(http, uri, job_id, resource, username, version);
19882011

19892012
goto cleanup;
19902013
}
@@ -2032,7 +2055,7 @@ main(int argc, /* I - Number of command-line args */
20322055
* Check printer state...
20332056
*/
20342057

2035-
check_printer_state(http, uri, resource, argv[2], version);
2058+
check_printer_state(http, uri, resource, username, version);
20362059

20372060
if (cupsGetError() <= IPP_STATUS_OK_CONFLICTING)
20382061
password_tries = 0;
@@ -2050,9 +2073,9 @@ main(int argc, /* I - Number of command-line args */
20502073
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
20512074
job_id);
20522075

2053-
if (argv[2][0])
2076+
if (username[0])
20542077
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
2055-
"requesting-user-name", NULL, argv[2]);
2078+
"requesting-user-name", NULL, username);
20562079

20572080
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
20582081
"requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]),
@@ -2179,7 +2202,7 @@ main(int argc, /* I - Number of command-line args */
21792202

21802203
if (job_canceled > 0 && job_id > 0)
21812204
{
2182-
cancel_job(http, uri, job_id, resource, argv[2], version);
2205+
cancel_job(http, uri, job_id, resource, username, version);
21832206

21842207
if (cupsGetError() > IPP_STATUS_OK_CONFLICTING)
21852208
_cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job."));
@@ -2189,7 +2212,7 @@ main(int argc, /* I - Number of command-line args */
21892212
* Check the printer state and report it if necessary...
21902213
*/
21912214

2192-
check_printer_state(http, uri, resource, argv[2], version);
2215+
check_printer_state(http, uri, resource, username, version);
21932216

21942217
if (cupsGetError() <= IPP_STATUS_OK_CONFLICTING)
21952218
password_tries = 0;

0 commit comments

Comments
 (0)