# xrdp in jail



## cmoerz (Jan 30, 2022)

I've set up a jail, installed the latest xrdp from ports (and later also tried the current version from github), but my session immediately disconnects after I attempt a connection via remmina.

The logs don't tell me much - session manager tells me, that the session just ended unexpectedly early. I put `exec xterm` in my /usr/local/etc/xrdp/startwm.sh. Logging the output of `xterm` tells me, that the X session just went away.

My /usr/local/etc/xrdp/startwm.sh:

```
#!/bin/sh
#
# This script is an example. Edit this to suit your needs.
# If ${HOME}/startwm.sh exists, xrdp-sesman will execute it instead of this.

#### set environment variables here if you want
export LANG=en_US.UTF-8
xterm > /tmp/xterm.log 2>&1
```

Excerpt from /var/log/xrdp-sesman.log running a session:

```
[20220129-19:57:27] [INFO ] [session start] (display 10): calling auth_start_session from pid 39757
[20220129-19:57:27] [DEBUG] Closed socket 8 (AF_INET 127.0.0.1:3350)
[20220129-19:57:27] [DEBUG] Closed socket 7 (AF_INET 127.0.0.1:3350)
[20220129-19:57:27] [DEBUG] Closed socket 8 (AF_INET 127.0.0.1:3350)
[20220129-19:57:27] [DEBUG] Waiting for X server to start on display 10
[20220129-19:57:27] [INFO ] Starting X server on display 10: Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp  
[20220129-19:57:27] [DEBUG] Waiting for X server to start on display 10
[20220129-19:57:27] [DEBUG] Did not find a running X server at /tmp/.X11-unix/X10
[20220129-19:57:27] [DEBUG] Calling exec (excutable: Xorg, arguments: Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp
)
[20220129-19:57:27] [DEBUG] Did not find a running X server at /tmp/.X11-unix/X10
[20220129-19:57:27] [DEBUG] Did not find a running X server at /tmp/.X10-lock
[20220129-19:57:27] [DEBUG] Did not find a running X server at /tmp/.X10-lock
[20220129-19:57:27] [INFO ] Found X server running at /tmp/.X11-unix/X10
[20220129-19:57:27] [INFO ] Found X server running at /tmp/.X11-unix/X10
[20220129-19:57:27] [INFO ] Session started successfully for user x1 on display 10
[20220129-19:57:27] [INFO ] Starting the xrdp channel server for display 10
[20220129-19:57:27] [INFO ] Session in progress on display 10, waiting until the window manager (pid 40197) exits to end the session
[20220129-19:57:27] [DEBUG] waiting for pid 40197 to exit
[20220129-19:57:27] [INFO ] Found X server running at /tmp/.X11-unix/X10
[20220129-19:57:27] [DEBUG] Calling exec (excutable: /usr/local/sbin/xrdp-chansrv, arguments: /usr/local/sbin/xrdp-chansrv)
[20220129-19:57:27] [DEBUG] The user session on display 10 did not request a specific window manager
[20220129-19:57:27] [DEBUG] The user home directory window manager configuration is enabled but window manager program does not exist: /home/l
clchristianm/startwm.sh
[20220129-19:57:27] [INFO ] Starting the default window manager on display 10: /usr/local/etc/xrdp/startwm.sh
[20220129-19:57:27] [DEBUG] Calling exec (excutable: /usr/local/etc/xrdp/startwm.sh, arguments: /usr/local/etc/xrdp/startwm.sh )
[20220129-19:57:27] [WARN ] Window manager (pid 40197, display 10) exited with non-zero exit code 1 and signal 0. This could indicate a window
 manager config problem
[20220129-19:57:27] [WARN ] Window manager (pid 40197, display 10) exited quickly (0 secs). This could indicate a window manager config proble
m
[20220129-19:57:27] [INFO ] Calling auth_stop_session and auth_end from pid 40009
[20220129-19:57:27] [INFO ] Terminating X server (pid 40603) on display 10
[20220129-19:57:27] [INFO ] Terminating the xrdp channel server (pid 41670) on display 10
[20220129-19:57:27] [DEBUG] waiting for pid 40603 to exit
[20220129-19:57:27] [INFO ] X server on display 10 (pid 40603) returned exit code 1 and signal number 0
[20220129-19:57:27] [DEBUG] waiting for pid 41670 to exit
[20220129-19:57:27] [INFO ] xrdp channel server for display 10 (pid 41670) exit code 0 and signal number 0
[20220129-19:57:27] [INFO ] cleanup_sockets:
[20220129-19:57:27] [DEBUG] cleanup_sockets: deleting /tmp/.xrdp/xrdp_chansrv_audio_out_socket_10
[20220129-19:57:27] [DEBUG] cleanup_sockets: deleting /tmp/.xrdp/xrdp_chansrv_audio_in_socket_10
[20220129-19:57:27] [DEBUG] cleanup_sockets: deleting /tmp/.xrdp/xrdpapi_10
[20220129-19:57:27] [DEBUG] cleanup_sockets: deleting /tmp/.xrdp/xrdp_display_10
[20220129-19:57:27] [DEBUG] cleanup_sockets: deleting /tmp/.xrdp/xrdp_disconnect_display_10
[20220129-19:57:27] [INFO ] ++ terminated session:  username x1, display :10.0, session_pid 39757, ip 192.168.168.168:22744 - socket: 
13
[20220129-19:59:11] [INFO ] shutting down sesman 1
[20220129-19:59:11] [DEBUG] Closed socket 7 (AF_INET 127.0.0.1:3350)
```

Now, I'm wondering - is it even possible to run xrdp in a jail? I understand, I can't run X11 in a jail unless I somehow managed to expose all the necessary memory regions and - if I understand it right - it doesn't work out of the box. Then again, xrdp runs a virtual fb server, I thought?

I've put devfs rules to ruleset zero, exposing all devices, but it didn't make any difference.

If anybody got any pointers, I'd very much appreciate it. Next thing to try is a bhyve vm instead, I suppose.


----------

