Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix print preflight status check #2102

Merged
merged 1 commit into from
Jul 9, 2024
Merged

Fix print preflight status check #2102

merged 1 commit into from
Jul 9, 2024

Conversation

rocodes
Copy link
Contributor

@rocodes rocodes commented Jul 9, 2024

Status

Ready for review

Description

Fixes #2101

Test Plan

  • Visual review
  • CI
  • Print success

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, the AppArmor profile may need to be updated. Please check as applicable:

  • I have updated the AppArmor profile
  • No update to the AppArmor profile is required for these changes
  • I don't know and would appreciate guidance

If these changes modify the database schema, you should include a database migration. Please check as applicable:

  • I have written a migration and upgraded a test database based on main and confirmed that the migration is self-contained and applies cleanly
  • I have written a migration but have not upgraded a test database based on main and would like the reviewer to do so
  • I need help writing a database migration
  • No database schema changes are needed

@rocodes rocodes requested a review from a team as a code owner July 9, 2024 20:32
@rocodes rocodes force-pushed the 2101-printer-status branch from dc45843 to 2a24939 Compare July 9, 2024 20:52
@rocodes
Copy link
Contributor Author

rocodes commented Jul 9, 2024

Tested on Qubes 4.2.2-rc2 + tip of this branch and these changes allow successful printing

@cfm cfm self-assigned this Jul 9, 2024
Copy link
Member

@cfm cfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @rocodes! Nice that the "no surprising return values" and the "no untrusted input" goals converge here. I'll approve and merge based on visual review since (a) you've tested this (and I'm not set up to do so) and (b) this will be retested via freedomofpress/securedrop-workstation#1103.

Noting for future work: could this pattern be factored out into some sort of stderr_to_enum(stderr, Enum) helper so that it's easy to do the right thing for both goals?

@cfm cfm merged commit 937483a into main Jul 9, 2024
58 checks passed
@cfm cfm deleted the 2101-printer-status branch July 9, 2024 22:12
if output_untrusted:
logger.debug(f"Result is {output_untrusted}")

# The final line of stderr is the status.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to document what could come before this and why we're discarding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fair. It's like

# This is a bit messy, but make sure we are just taking the last line
# (no-op if no newline, since we already stripped whitespace above)
(comment farther down in the file) so I was a bit sparse on the documentation. Basically, we know that our status string is the last thing written to stderr, but because we flush stderr there could be other stuff written beforehand (by the OS/another process, not by us) that we don't want to pass on to the calling VM. The errors are written to the appropriate log (or to the journal) in sd-devices, but here, we're only interested in the status value.

legoktm added a commit that referenced this pull request Jul 10, 2024
[0.11.0] Backport printer preflight status fix (#2102)
@deeplow
Copy link
Contributor

deeplow commented Jul 10, 2024

Noting for future work: could this pattern be factored out into some sort of stderr_to_enum(stderr, Enum) helper so that it's easy to do the right thing for both goals?

@cfm not sure if this is similar to what you're talking about but on Dangerzone we are using exceptions instead of Enums. Each exception is mapped to a certain qrexec server process exit code. Then the have one method which reconstructs the exceptions on the client (trusted part), based on the exit codes. This way we basically eliminate any client-side parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Client reports printer preflight failure when check has succeeded
4 participants