Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The library will remain open source and MIT licensed and can still be used, fork
- **Minimum Java version: 21**
- **Removed** all methods, members and classes marked as deprecated
- Update JUnit to Version 6
- Remove `throws IOException` from `AbstractConnectionBase.close()` (Issue #287)
- Remove `throws IOException` from `AbstractConnectionBase.close()` ([#287](https://github.com/hypfvieh/dbus-java/issues/287))
- Support usage of `Struct`s as return value (as alternative to `Tuple` with generics) (based on discussion in #285)
- Updated dependencies and plugins
- Added support to use `Struct` datatypes as return values instead of `Tuple`#
Expand All @@ -87,6 +87,8 @@ The library will remain open source and MIT licensed and can still be used, fork
- This can be enabled using the `DBusConnectionBuilder`, example: `DBusConnection sessionConnection = DBusConnectionBuilder.forSystemBus().receivingThreadConfig().withAllVirtualThreads(true).connectionConfig().build()`
- Virtual-Threads can be enabled/disabled for each of the different executor services used in `ReceivingService`: `SIGNAL`, `ERROR`, `METHODCALL`, `METHODRETURN`
- default remains native threads on all executors
- Fixed possible NullPointerException in SASL auth ([#294](https://github.com/hypfvieh/dbus-java/issues/294))
- Fixed SASL authentication issue when running in server mode in combination with unix sockets ([#298](https://github.com/hypfvieh/dbus-java/issues/298))

##### Changes in 5.2.0 (2025-12-21):
- removed properties from dbus-java.version which causes issues with reproducable builds ([PR#279](https://github.com/hypfvieh/dbus-java/issues/279))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,24 +598,18 @@ public boolean auth(SocketChannel _sock, AbstractTransport _transport) throws IO
case SERVER:
switch (state) {
case INITIAL_STATE:
ByteBuffer buf = ByteBuffer.allocate(1);
if (_sock != null) {
_sock.read(buf); // 0
try {
int kuid = -1;
if (_transport instanceof AbstractUnixTransport aut) {
kuid = aut.getUid(_sock);
}
if (kuid >= 0) {
kernelUid = stupidlyEncode("" + kuid);
}
state = SaslAuthState.WAIT_AUTH;
} else {
try {
int kuid = -1;
if (_transport instanceof AbstractUnixTransport aut) {
kuid = aut.getUid(null);
}
if (kuid >= 0) {
kernelUid = stupidlyEncode("" + kuid);
}
state = SaslAuthState.WAIT_AUTH;

} catch (SocketException _ex) {
state = SaslAuthState.FAILED;
}
} catch (SocketException _ex) {
state = SaslAuthState.FAILED;
}
break;
case WAIT_AUTH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public void setPreConnectCallback(Consumer<AbstractTransport> _run) {
* @throws IOException on any error
*/
private void authenticate(SocketChannel _sock) throws IOException {
if (_sock == null) {
throw new IOException("SocketChannel instance required");
}
SASL sasl = new SASL(config.getSaslConfig());
try {
if (!sasl.auth(_sock, this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ private NativeUnixSocketHelper() {}

/**
* Get the UID of peer credentials.
* <p>
* Gathering the UID of SO_PEERCRED directly is not obvious when it comes to JDK native unix sockets.<br>
* based on the implementation in {@code sun.nio.fs.UnixUserPrincipals.User},<br>
* calling {@code hashCode()} on the {@link UserPrincipal} will give you either the UID or the hashCode of the name.
* </p><p>
* This method ensures that a proper UID is returned and not the hashCode of the name.
* If there is no UID, -1 is returned.
* </p>
*
* @param _sock socket to read from
* @return UID, -1 if given {@link SocketChannel} was null
* @return UID, -1 if given {@link SocketChannel} was {@code null} or UID could not be determined
*
* @throws IOException when socket channel fails to read SO_PEERCRED option
*/
Expand All @@ -27,7 +35,12 @@ public static int getUid(SocketChannel _sock) throws IOException {
UnixDomainPrincipal creds = _sock.getOption(ExtendedSocketOptions.SO_PEERCRED);
UserPrincipal user = creds.user();

return Integer.parseInt(user.getName());
int uid = -1;
if (user != null && user.hashCode() != user.getName().hashCode()) {
uid = user.hashCode();
}

return uid;
}

}
Loading