pycups icon indicating copy to clipboard operation
pycups copied to clipboard

Adds name property for getJobs method

Open jcampbell05 opened this issue 8 years ago • 10 comments

In original cups documentation they allow you to specify a name to view the queue of a printer, pycups only allows you originally to see jobs across all queues. I've now exposed an extra name kwarg which if specified with the name of a printer will filter it to the jobs of that printer.

jcampbell05 avatar Dec 01 '17 22:12 jcampbell05

Hi, thank you for your effort with patch, but would you mind enhancing it? I'm missing some checks.

  1. Code creates static array of char for uri, but it doesn't check if string+name is longer than 1024 - if it is, correct it (like calling debugprintf with message about for example "name is too long, cutting it" and cut the name to correct length).
  2. Code doesn't check if 'name' doesn't contain any reserved characters (except for /)

I know these checks can be done in sw using python-cups and they aren't used in other parts of code, but IMO it is good habit to think about all situations, which can happen.

zdohnal avatar Dec 06 '17 11:12 zdohnal

I've implemented number 1.

I'm not sure how to do number 2, I'm trying to find a good URI validation method. Maybe you could point me in the right direction ?

jcampbell05 avatar Dec 07 '17 11:12 jcampbell05

Ad1) still missing recovering from the issue - cutting 'name' string to be able to get in 'uri' array. This way the bigger string will still overwrite memory behind of memory reserved for 'uri' array -> which can be security issue. Ad2) I think the easiest way is try to find these reserved characters in 'name' string by strchr or by regex.h - reserved characters in URI ( https://tools.ietf.org/html/rfc2396#section-2.2 - only '/' can be in printers uri in 'name' variable according https://tools.ietf.org/html/rfc3510#section-4.6.1 )

zdohnal avatar Dec 07 '17 12:12 zdohnal

Okay added some validation to make sure its not a reserved character. Not sure how we should handle regex failing to compile so maybe you can help point me in right direction.

I now added name trimming (I also moved the debug message to the correct method). Please can you check I'm doing the correct calculations when trimming as I'm not as familiar with manipulating strings in C :)

jcampbell05 avatar Dec 08 '17 15:12 jcampbell05

Looks good - I'll make some tests. Would you mind cleaning up your commits (there are some things which shoudln't be there - like .so files, typos...)?

zdohnal avatar Mar 06 '18 09:03 zdohnal

:) sure will be happy to

jcampbell05 avatar Mar 06 '18 11:03 jcampbell05

Hi, is there any news on this pull request? That's exactly what I need in my project.

EToniolo avatar Sep 09 '20 07:09 EToniolo

@jcampbell05 Hi James,

do you intend to work on the PR?

@EToniolo if James is not interested, will you take over the PR?

zdohnal avatar Sep 09 '20 07:09 zdohnal

Sorry I forgot about this PR - I'm happy for someone to help get this over the line

jcampbell05 avatar Sep 09 '20 15:09 jcampbell05

From what I can see we just need to do a squash to clean up the history and some unit tests written

jcampbell05 avatar Sep 09 '20 15:09 jcampbell05