Commit graph

219 commits

Author SHA1 Message Date
Wim Taymans
e317edcfb9 pod: rework the parser
Make a new body.h file with some functions to deal with pod and their
body. Make the iter.h functions use mostly this.

Rework the parser so that it only uses body.h functions. With the separation
of pod+body, we can read and verify the pod once and then use the
verified copy to handle the rest of the body safely.

We do this because iter.h only works in pods in memory that doesn't change
because it is vulnerable to modifications of the data after verifying it.

The new parser is not vulnerable to this and will not cause invalid
memory access when used on shared memory. There is however no need for
atomic operations to read the headers, whever is read is either valid
and useable of invalid and rejected.

See #4822
2025-07-29 15:15:02 +02:00
Wim Taymans
20a4aa8cf9 modules: remove v0 protocol support 2025-07-10 16:26:01 +02:00
Wim Taymans
62035963a3 protocol-native: support abstract socket addresses
They start with @ and do not create a file in the file system.
2025-02-17 16:50:16 +01:00
Wim Taymans
70ca546c6a protocol-native: don't overwrite the intention with remote.name 2025-01-29 12:08:20 +01:00
Wim Taymans
19d78ef195 module: improve loopback docs 2025-01-24 13:13:23 +01:00
Pauli Virtanen
0d80a13771 modules: support config overrides for access & protocol-native
These modules are loaded in default config, but to configure sockets and
their permissions, the args need to be overridden.
2024-11-04 16:50:30 +00:00
Wim Taymans
7af43d87b3 protocol-native: write socket address after adding
Only write the socket address after we managed to add the fd to the main
loop.

Only log a warning when this fails.
2024-10-22 09:33:40 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +02:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Diego Viola
7410755c03 Fix typos
found them with codespell.

Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-05-22 09:19:34 +02:00
Barnabás Pőcze
b3bd026699 pipewire: remove cleanup.h
Since `spa/utils/cleanup.h` is not a private header anymore, there is
no need for a separate `pipewire/cleanup.h` since the definitions of
the cleanup routines can now be moved into the respective headers.
2024-05-16 17:35:58 +02:00
Wim Taymans
232f4f01e4 protocol-native: fail when security context init fails 2024-04-15 16:43:46 +02:00
Wim Taymans
18ce166735 protocol-native: cleanup when starting a server fails 2024-04-10 18:12:14 +02:00
Wim Taymans
8115bf3eeb protocol-native: send debug to right topic 2024-04-10 13:11:17 +02:00
Wim Taymans
c2ba66bef6 protocol-native: clean up security context on unload 2024-03-15 13:00:30 +01:00
Wim Taymans
8a1ed01923 protocol-native: update the properties correctly 2024-03-14 11:10:38 +01:00
Wim Taymans
e7846fc12a protocol-native: add security context API
Add a new extension that can create a server on a user provided socket
with user provided security properties.

This is mainly used in flatpaks that want to create and bind a pipewire
socket with specific permissions for the flatpak app.

The flatpak will also provide an fd that will be closed when the server
can be removed.
2024-03-13 12:53:04 +01:00
Wim Taymans
c5e8da7247 protocol-native: add props to the sockets keys
Make it possible to set extra properties on the sockets created from the
config options with a props key.
2024-03-13 12:44:24 +01:00
Gleb Popov
571fa73455 Fix uninitialized variable usage 2024-02-10 20:52:31 +03:00
Wim Taymans
0ea736e144 protocol-native: use props in server and data
Add props to the protocol_data and server. Instead of storing the
server_info, just add the relevant properties for the server to the
props.

When we get a new client, we can simply copy the server props to the
client props. This makes it possible to create specific servers later
that create clients with specific properties.

Use a subset of the context properties to create servers. We only need
the CORE_NAME for now.
2024-02-08 09:53:13 +01:00
Wim Taymans
92f6239597 protocol-native: set error when add_event fails 2024-02-08 09:48:33 +01:00
Wim Taymans
9a5609de2b modules: move some spa_debug_mem to the log
Instead of dumping to stderr, write it to the log file.
2024-01-11 17:49:50 +01:00
Wim Taymans
a3c6b3acae log: add pw_log_topic_custom_enabled()
Add a function to check if a specfic custom log level has been defined
for a topic.

We can use this to dynamically check if we need to do the connection debug
messages.

We can also get rid of the conn.* pattern hack to disable connection
messages by default.
2024-01-04 17:40:57 +01:00
Pauli Virtanen
fdcb02ed75 modules: add Module Name section to the module reference docs 2023-11-20 08:41:13 +00:00
Pauli Virtanen
eca773fc12 modules: strip "PipeWire Module:" from Doxygen page name
Make them appear nicer in the output.
2023-11-19 16:39:15 +00:00
Pauli Virtanen
72c9fba6d2 module-protocol-native: emit error on bad concurrency
Emit error if message construction is not holding appropriate locks or
runs from wrong thread, so that the flush may be running concurrently.

This generally causes corrputed messages to be sent silently, and can be
fairly hard to debug otherwise in client applications.
2023-11-07 18:07:32 +00:00
Pauli Virtanen
3d32291711 module-protocol-native: use two-socket server by default
If no socket configuration specified for a server, create two sockets,
"CORENAME" and "CORENAME-manager" where CORENAME is the value computed
by get_server_name.
2023-10-16 22:17:44 +03:00
Pauli Virtanen
bb120a070f pipewire: add PW_KEY_SEC_SOCKET and set it in protocol
Add client key PW_KEY_SEC_SOCKET that indicates which socket the client used
to connect to the server.

This can be used by other modules as an access control mechanism.
2023-10-11 19:08:18 +03:00
Pauli Virtanen
72462ebd07 module-protocol-native: add module argument 'sockets'
Add module argument 'sockets' for creating multiple sockets clients can
connect to.

Also allow setting socket file permissions.
2023-10-11 19:08:18 +03:00
Wim Taymans
d225a192a1 Revert "modules: enforce equal library and compiler versions"
This reverts commit 697daeedf7.

This is too much, we should do better and only disallow incompatible
versions.
2023-07-12 11:16:56 +02:00
Wim Taymans
697daeedf7 modules: enforce equal library and compiler versions
For all the modules that include the private header we require that the
library and compiler versions match.

Otherwise we might end up poking into new or old fields that got moved or
changed in the private struct and crash.

See #3243
2023-07-11 19:50:36 +02:00
Wim Taymans
17bc9d520e protocol-native: move compat_v2 to protocol 2023-07-11 16:13:38 +02:00
Wim Taymans
fdc860c71b protocol-native: give an error when loading twice
Instead of silently ignoring the problem. It's possible that it is
loaded with different settings, which would then silently be ignored.
2023-07-06 13:51:37 +02:00
Wim Taymans
8db98b114d module-protocol-native: close fds from zombie clients
When a client is zombie, close the fds we got in the discarded message
or else we leak them.

See #1840
2023-06-05 13:28:04 +02:00
Wim Taymans
9eb1633b02 protocol-native: don't remove all fds in clear
When we consumed all the buffer data, don't clear all the fds but only
those that were already consumed in the message. It is possible that we
already have fds for the next message and we don't want to discard
those.

Fixes some intermittend memory map errors.
2023-04-27 11:03:53 +02:00
Wim Taymans
bf18ba839f protocol-native: add some more debug 2023-04-21 15:07:29 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
c8850f8766 env vars should override everything
Always first use the env var and then check the properties. So that
PIPEWIRE_CORE=pipewire-1 PIPEWIRE_REMOTE=pipewire-1 make run runs
everything on pipewire-1 sockets regardless of the config files.

Also PIPEWIRE_NODE always needs to be taken into account first.
2023-01-24 17:39:54 +01:00
Wim Taymans
f0328a1f8d protocol-native: improve logging
Add an end marker in the log for the message.
Log the output messages with the right log topic.
2022-10-27 18:04:14 +02:00
Wim Taymans
0532d194ad protocol-native: small cleanups
Style fixes.
Use new variable for fd to avoid casts.
Generate an error when  the fd is invalid.
2022-08-17 19:56:52 +02:00
Cameron Nemo
0883a0163b protocol-native: write socket address into fd
Support fork-free readiness notifications.

Without this, a service supervisor that does not implement socket
activation has no way of knowing whether or not pipewire is ready to
accept connections on the socket.

s6 is the most popular service manager that supports this mechanism.
See here: https://skarnet.org/software/s6/notifywhenup.html
2022-08-17 17:41:21 +00:00
Wim Taymans
ca8b61e984 protocol-native: improve connection disconnect
The connection is created in new, therefore free it in destroy, not in
disconnect.
Connect sets the fd, so unset the fd in disconnect.
2022-08-11 12:07:59 +02:00
Wim Taymans
78c069ff87 potocol-native: improve error handling
Init the compat types map a little earlier so that it is initialized
when we try to clear it on error.
Add the client listener earlier so that we can use the events to clean
up the map, source and connection.
2022-08-11 12:06:28 +02:00
Lucas Holt
6a15a02ec2 Add support for MidnightBSD
Fix build issue

Fix build issue
2022-06-19 18:22:47 +00:00
Barnabás Pőcze
211abaef5e protocol-native: remove destroyed client from client list
When the client destroys the protocol-native module, the server
and the client are destroyed but the client is still reffed (not freed).
It will be unreffed after its messages are processed, after which point
it will be freed and removed from the server client_list that is already
destroyed.

Fix this by removing the client from the server list when it is
destroyed.

See #565
2022-05-07 14:08:55 +02:00
Wim Taymans
19e3e20c47 protocol-native: improve client and resource refcounts
Add a refcount to resource and client so that we can keep them alive
while the native protocol is using them.

One problem might be that the protocol destroys the client or resource
while handling it and that would cause errors.

Fixes #565
2022-05-06 13:25:57 +02:00
Wim Taymans
e78b886785 module: update docs 2022-04-24 11:21:04 +02:00
Pauli Virtanen
a9accd1668 protocol-native: footer pre_demarshal must come first
Message footer should be handled before attempting to find the object
the main message is sent to / checking permissions, because it is not
aimed at a specific object.  E.g. the registry generation updates should
be handled regardless of whether the main message is valid or not,
because the updates will not be re-sent.

Fixes registry generation updates sometimes going missing.
2022-02-26 17:48:51 +00:00
Pauli Virtanen
bf9ef440c3 protocol-native: check invariant for marshaled data
There's an assumption that marshaled messages consist of a single POD,
since we now tag on a footer after it.  This is true for the
protocol-native implementations, which all wrap the message in a single
POD Struct.

To catch protocol-native implementation bugs here later, add assert that
marshaling produces a single POD.
2022-02-20 18:19:13 +02:00
Pauli Virtanen
680c33d3eb protocol-native: extend v3 protocol with message footers
Extend version 3 protocol with message footers, which are for passing
around global state data that is not addressed to a specific object.

The extension is backward compatible with previous v3 clients, and won't
e.g. result to error spam in logs.

The footer is a single SPA POD, appended after the main message POD.
Because both the protocol message and the message POD record their
length, it's possible to append trailing data. Earlier clients will
ignore any data trailing the message POD.

The footer POD contains a sequence [Id opcode, Struct {...}]*,
so there is room to extend with new opcodes later as necessary.

There are separate marshal/demarshal routines for messages aimed at
resources and proxies.
2022-02-20 16:59:25 +02:00