Xvfb-run as a subprocess in Django running xfreerdp fails

307 Views Asked by At

I have a ThreadPoolExecutor object(rdp_connector_global) in a Dockerized Django application's view method calling the below method(_rdp_connect) via submit as follows:

rdp_connector_global.submit(_rdp_connect, login.ip_address, login.remote_port, login.username, login.password, login.rdp_width_pixels, login.rdp_height_pixels)
def _rdp_connect(hostname_or_ip, port, username, password, rdp_width_pixels=1920, rdp_height_pixels=1080):
    domain = None
    username_simple = username
    if "\\" in username:
        split = username.split["\\"]
        domain = split[0]
        username_simple = split[1]
    elif "@" in username:
        split = username.split["@"]
        username_simple = split[0]
        domain = split[1]
    connection = None
    if domain is None:
        xvfb_args_str = "/usr/bin/xvfb-run /usr/bin/xfreerdp /sec:tls /u:{0} /p:{1} /w:{2} /h:{3} /v:{4}:{5} /cert-ignore".format(username_simple, password, rdp_width_pixels, rdp_height_pixels, hostname_or_ip, port)
        connection = subprocess.Popen(xvfb_args_str, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    else:
        xvfb_args_str = "/usr/bin/xvfb-run /usr/bin/xfreerdp /sec:tls /d:{0} /u:{1} /p:{2} /w:{3} /h:{4} /v:{5}:{6} /cert-ignore".format(domain, username_simple, password, rdp_width_pixels, rdp_height_pixels, hostname_or_ip, port)
        connection = subprocess.Popen(xvfb_args_str, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    logging.info(connection.communicate())
    connection.wait()
    logging.info(connection.communicate())

Xvfb and freerdp are installed in the Docker container correctly. The login command succeeds when I run it from Django shell or the shell inside the Docker. But the same command fails to login to the remote Windows machine when running via code. When running via Django I get a ERRINFO_LOGOFF_BY_USER after 30 seconds of unsuccessful wait to connect to Windows machine.

1

There are 1 best solutions below

0
On

I finally solved the problem. It was nothing to do with freerdp or Docker or Xvfb! The login.password was not decrypted before use, hence the login failure.