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

Add support for exit codes returned by snapctl commands #97

Merged
merged 8 commits into from
Feb 28, 2021

Conversation

jhenstridge
Copy link
Contributor

This builds on top of PR #95, which adds support for inspecting the value embedded in an error response. The diff will be somewhat smaller once that is merged.

This PR adds new snapd_client_run_snapctl2_* functions that add a new exit_code out parameter. These differ from the previous version in that if an error response is received with kind "unsuccessful", then the stdout, stderr, and exit code will be decoded from the response. At present, snapctl is-connected is the only command that returns these responses, but more could in the future.

I've tried to keep the old run_snapctl_* functions the same, such that they will still set the GError if they receive an unsuccessful error. Things would be a bit simpler if we didn't maintain that part of the API, but there would be no way for users of the old API to check error returns from is-connected otherwise.

I haven't updated the Qt binding yet, with similar concerns. Switching QSnapdRunSnapCtlRequest to use the new API and adding an exitCode() method would be easy, but now code that was expecting a QSnapdError would no longer see it.

I do kind of wonder whether anyone has ever used this part of the snapd-glib API though, so it might not be so bad to take the simpler option.

@jhenstridge
Copy link
Contributor Author

An alternative would be to continue returning a GError when we receive an "unsuccessful" response, but set stdout, stderr, and exit code. This would allow the old API to be a simple wrapper around the new one (rather than having to generate an error where the new one doesn't), and do similar for the Qt API.

@robert-ancell: Do you have any preferences about this?

@robert-ancell
Copy link
Contributor

I'd prefer to only use a GError when the error is a true exception and no futher processing can be done. I think that better matches the way other GLib APIs use it. Please continue with the original proposal.

@jhenstridge
Copy link
Contributor Author

I was just looking through the snapd side for snapctl, and noticed that canonical/snapd#9692 had been merged. If we're adding a new prototype for snapctl, then it should probably support stdin as an argument too so we don't need run_snapctl3.

@jhenstridge
Copy link
Contributor Author

After chatting with Michael, he suggests we ignore the current stdin support: it's only currently used by a full disk encryption setup command, and they don't like the current API because it requires draining stdin completely before making the REST API request.

Adding a const char *stdin arg to run_snapctl2 would just lock us in to a feature that snapd-glib users are unlikely to use and, and may not be compatible with whatever solution they come up with to replace the current naive version.

@jhenstridge jhenstridge marked this pull request as ready for review February 19, 2021 02:53
snapd-qt/client.cpp Outdated Show resolved Hide resolved
@robert-ancell
Copy link
Contributor

Just a couple of small fixes, then LGTM. Thanks @jhenstridge!

@robert-ancell robert-ancell merged commit 77cc5a1 into canonical:master Feb 28, 2021
tillkamppeter referenced this pull request in OpenPrinting/cups Mar 1, 2021
Let the scheduler check whether if an administrative request
(create/modify print queue, delete someone else's jobs, ...) from a
client is from a fully confined Snap and then only grant access if the
client Snap plugs "cups-control". If client Snap plugs "cups" instead
it can only print, check status, or remove the caller's own jobs. For
requests from classically confined Snaps or unsnapped clients access
is always granted.

This is to protect arbitrary Snaps from the Snap Store to do
administrative CUPS tasks. The Snap Store allows automatic connection
only of the "cups" interface, not of the cups-control interface.

This facility is optional, to be activated by configure options,
"--enable-snapped-clients" for unsnapped CUPS and
"--enable-snapped-cupsd" when CUPS itself is also in a Snap. The
former accesses the needed information about the client using
libsnapd-glib (which cannot be used from within a Snap) and latter
uses the "snapctl" utility (which only works from within a Snap). In
both cases also libapparmor is needed to determine whether the client
is actually a Snap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants