node-rdpjs icon indicating copy to clipboard operation
node-rdpjs copied to clipboard

Can I check success connection with login and password?

Open LordJohn42 opened this issue 9 years ago • 1 comments

How i can understand, if i connected with login and password was successful?

LordJohn42 avatar Dec 21 '16 20:12 LordJohn42

The grand undocumented "session" event

What I've found is that there is an undocumented event that gets fired called session. It is fired when this packet is received:

2.2.10.1 Server Save Session Info PDU The Save Session Info PDU is used by the server to transmit session and user logon information back to the client after the user has logged on.

Here are the MSDN docs and the node-rdpjs code that fires the event.

How to use this:

What I've done is to set a timeout on how long I want to wait for the login (after the connect happens) and listen for the session event as the I successfully logged in event. It ends up looking something like this, though I'd turn this into a module that returns a promise and uses resolve/reject:

const rdp = require('node-rdpjs');

function login(userName, domain, password, server, loginTimeoutMs) {
  const clientConfig = {
    userName,
    domain,
    password,
    autoLogin: true
  };

  console.log(`connecting to ${server} using username=${clientConfig.userName} domain=${clientConfig.domain}`);

  let loginTimer = null;
  rdp.createClient(clientConfig)
    .on('connect', function () {
      console.log(`Connection created. This is different than the session being created (being logged in). Waiting ${loginTimeoutMs}ms for session to be created.`);
      //wait loginTimeoutMs before saying session event didn't happen
      loginTimer = setTimeout(() => {
        throw new Error(`Timeout occured after ${loginTimeoutMs}ms waiting on session to be created. There was most likely a problem logging in.`);
      }, loginTimeoutMs);
    })
    .on('session', function () {
      console.log('Session created. Now we are logged in.');
      if (loginTimer) {
        loginTimer.clearTimeout();
      }
      // I have a logged in session!
    })
    .on('error', function (err) {
      throw err;
    })
    .connect(server, 3389);
}

@citronneur does this seem like the correct use of that event or am I misunderstanding what it means?

EddieCanales avatar Sep 01 '17 19:09 EddieCanales