Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I check success connection with login and password? #24

Open
LordJohn42 opened this issue Dec 21, 2016 · 1 comment
Open

Can I check success connection with login and password? #24

LordJohn42 opened this issue Dec 21, 2016 · 1 comment

Comments

@LordJohn42
Copy link

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

@EddieCanales
Copy link

EddieCanales commented Sep 1, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants