Skip to content

Commit

Permalink
In the Snap patch PAPPL to allow normal-user clients access the Snap'…
Browse files Browse the repository at this point in the history
…s server

The server run by the Snap runs as root, as a Snap is installed into
the system, not into the user's home directory and so a process
started by the Snap installation must be a system process and that is
why Snaps run daemons as root.

Running the Printer Application as a client (from the command line) it
runs as the calling user and PAPPL does not associate it with the
system-wide server which the Snap has started as root. PAPPL always
creates the socket file with the user ID in the file name, so the call
as client uses its own socket file name, does not find the Snap's
server and fires up its own server.

See michaelrsweet/pappl#148

When building the Snap we are patching PAPPL now in a way that if a
client does not find a server uder the user's socket name, it tries
root's socket name (the system-wide server of the Snap in our case),
and only if this also fails it fires up its own server.
  • Loading branch information
tillkamppeter committed Feb 10, 2021
1 parent c772ea0 commit 8bb880b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
71 changes: 71 additions & 0 deletions patches/pappl-system-wide-server-socket-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/pappl/mainloop-private.h b/pappl/mainloop-private.h
index 5af4695..9bde73a 100644
--- a/pappl/mainloop-private.h
+++ b/pappl/mainloop-private.h
@@ -59,7 +59,7 @@ extern void _papplMainloopAddPrinterURI(ipp_t *request, const char *printer_name
extern http_t *_papplMainloopConnect(const char *base_name, bool auto_start) _PAPPL_PRIVATE;
extern http_t *_papplMainloopConnectURI(const char *base_name, const char *printer_uri, char *resource, size_t rsize) _PAPPL_PRIVATE;
extern char *_papplMainloopGetDefaultPrinter(http_t *http, char *buffer, size_t bufsize) _PAPPL_PRIVATE;
-extern char *_papplMainloopGetServerPath(const char *base_name, char *buffer, size_t bufsize) _PAPPL_PRIVATE;
+ extern char *_papplMainloopGetServerPath(const char *base_name, bool system_wide, char *buffer, size_t bufsize) _PAPPL_PRIVATE;


//
diff --git a/pappl/mainloop-subcommands.c b/pappl/mainloop-subcommands.c
index a572d6e..a79ac03 100644
--- a/pappl/mainloop-subcommands.c
+++ b/pappl/mainloop-subcommands.c
@@ -605,7 +605,7 @@ _papplMainloopRunServer(
papplSystemSetPrinterDrivers(system, num_drivers, drivers, autoadd_cb, /* create_cb */NULL, driver_cb, data);

// Listen for connections...
- papplSystemAddListeners(system, _papplMainloopGetServerPath(base_name, sockname, sizeof(sockname)));
+ papplSystemAddListeners(system, _papplMainloopGetServerPath(base_name, false, sockname, sizeof(sockname)));

// Finish initialization...
if (!system->save_cb)
diff --git a/pappl/mainloop-support.c b/pappl/mainloop-support.c
index e54f438..deb5d94 100644
--- a/pappl/mainloop-support.c
+++ b/pappl/mainloop-support.c
@@ -316,8 +316,12 @@ _papplMainloopConnect(
char sockname[1024]; // Socket filename


- // See if the server is running...
- http = httpConnect2(_papplMainloopGetServerPath(base_name, sockname, sizeof(sockname)), 0, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+ // See if a user server is running...
+ http = httpConnect2(_papplMainloopGetServerPath(base_name, false, sockname, sizeof(sockname)), 0, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+
+ // See if there is a system-wide server
+ if (!http)
+ http = httpConnect2(_papplMainloopGetServerPath(base_name, true, sockname, sizeof(sockname)), 0, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);

if (!http && auto_start)
{
@@ -333,6 +337,8 @@ _papplMainloopConnect(
NULL
};

+ _papplMainloopGetServerPath(base_name, false, sockname, sizeof(sockname));
+
posix_spawnattr_init(&server_attrs);
posix_spawnattr_setpgroup(&server_attrs, 0);

@@ -449,6 +455,7 @@ _papplMainloopGetDefaultPrinter(
char * // O - Socket filename
_papplMainloopGetServerPath(
const char *base_name, // I - Base name
+ bool system_wide, // I - System-wide server
char *buffer, // I - Buffer for filename
size_t bufsize) // I - Size of buffer
{
@@ -463,7 +470,7 @@ _papplMainloopGetServerPath(
tmpdir = "/tmp";
#endif // __APPLE__

- snprintf(buffer, bufsize, "%s/%s%d.sock", tmpdir, base_name, (int)getuid());
+ snprintf(buffer, bufsize, "%s/%s%d.sock", tmpdir, base_name, (system_wide ? 0 : (int)getuid()));
_PAPPL_DEBUG("Creating domain socket as '%s'.\n", buffer);

return (buffer);
13 changes: 12 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ apps:
plugs: [avahi-control, home, network, network-bind, raw-usb]

parts:
patches:
plugin: dump
source: patches
organize:
'*' : patches/
override-prime: ""

jpeglib:
plugin: autotools
source: https://www.ijg.org/files/jpegsrc.v9d.tar.gz
Expand All @@ -45,6 +52,10 @@ parts:
source: https://github.com/michaelrsweet/pappl
source-type: git
plugin: autotools
override-build: |
set -eux
patch -p1 < $SNAPCRAFT_STAGE/patches/pappl-system-wide-server-socket-support.patch
snapcraftctl build
configflags: [--prefix=/usr, --enable-libjpeg,--enable-libpng,--enable-libusb,--with-dnssd=avahi]
build-packages: [libavahi-client-dev, libgnutls28-dev, libjpeg-dev, libpam-dev, libpng-dev, libusb-1.0-0-dev, zlib1g-dev]
stage-packages: [libavahi-client3, libpng16-16, libusb-1.0-0]
Expand All @@ -62,7 +73,7 @@ parts:
- lib
- usr/lib
- usr/lib/libpappl.so.1
after: [jpeglib]
after: [patches, jpeglib]

qpdf:
source: https://github.com/qpdf/qpdf/releases/download/release-qpdf-10.0.1/qpdf-10.0.1.tar.gz
Expand Down

0 comments on commit 8bb880b

Please sign in to comment.