ref: 8fb518ad2fb092e8bad347bd0623935a7298eb0d
parent: 72ab06eec3a686b276790c3121ac51561cd2ff01
author: Yaroslav Kolomiiets <yarikos@gmail.com>
date: Sat May 14 19:15:43 EDT 2016
cosmetic touches
--- a/dat.h
+++ b/dat.h
@@ -25,7 +25,6 @@
{
int fd; /* connection I/O descriptor */
long sproto; /* magic to bounce back to server */
- char *label; /* window label */
char *local; /* local system name */
char *user; /* user name for auto logon */
char *windom; /* domain for auto logon */
@@ -50,8 +49,8 @@
};
int starttls(Rdp*);
int rdphandshake(Rdp*);
-int x224connect(Rdp*);
-int x224disconnect(Rdp*);
+int x224handshake(Rdp*);
+int x224hangup(Rdp*);
void sendclientinfo(Rdp*);
void confirmactive(Rdp*);
void assync(Rdp*);
@@ -112,11 +111,13 @@
Mconnected, /* S: MCS Connect Response + GCC Confce Create Resp */
Mactivated, /* C: MCS Confirm Active */
Mclosing, /* S: Disconnect Provider Ultimatum */
- Aflow, /* S: T.128 Flow PDU */
+ Mvcdata, /* S,C: MCS virtual channel data, raw */
Async, /* C: MPAS 2.2.1.14 Client Synchronize PDU */
Actl, /* C: MPAS 2.2.1.15 Control PDU */
Afontls, /* C: MPAS 2.2.1.18 Client Font List PDU */
Ainput, /* C: MPAS (T.128) Input Event */
+ Aupdate, /* S: T.128 ASPDU or a "Fast-Path" RDP PDU */
+ Aflow, /* S: T.128 Flow PDU */
Dclientinfo, /* C: RDP 2.2.1.11 Client Info */
Dsupress, /* C: RDP 2.2.11.3 Suppress Output PDU */
Lneedlicense, /* S: Licensing PDU */
@@ -124,8 +125,6 @@
Lhavechal, /* S: Licensing PDU */
Lnolicense, /* C: Licensing PDU */
Ldone, /* S: Licensing PDU */
- Aupdate, /* S: T.128 ASPDU or a "Fast-Path" RDP PDU */
- Mvcdata, /* S,C: MCS virtual channel data, raw */
};
enum /* Msg.negproto - for msg.c x224.c */
@@ -160,8 +159,7 @@
int mtype; /* Ainput */
ulong msec; /* Ainput */
ulong flags; /* Ainput, Mvcdata */
- int iarg1; /* Ainput */
- int iarg2; /* Ainput */
+ int iarg[2]; /* Ainput */
int action; /* Actl */
int allow; /* Dsupress */
uchar* data; /* Mvcdata, Aupdate */
--- a/kbd.c
+++ b/kbd.c
@@ -111,18 +111,18 @@
kbdsendscan(Rdp* c, int sc, int mod)
{
long msec;
- int f;
+ int x;
- f = 0;
+ x = 0;
if(sc&Sext)
- f = KeyEx;
+ x = KeyEx;
sc &= ~Sext;
msec = time(nil);
if(mod != 0)
passinput(c, msec, InputKeycode, 0, mod, 0);
- passinput(c, msec, InputKeycode, f|0, sc, 0);
- passinput(c, msec, InputKeycode, f|KeyUp, sc, 0);
+ passinput(c, msec, InputKeycode, x|0, sc, 0);
+ passinput(c, msec, InputKeycode, x|KeyUp, sc, 0);
if(mod != 0)
passinput(c, msec, InputKeycode, KeyUp, mod, 0);
}
--- a/mouse.c
+++ b/mouse.c
@@ -18,9 +18,9 @@
static int mfd = -1;
static void
-sendmouse(Rdp* c, Mouse m, int flags)
+sendmouse(Rdp* c, Mouse m, int f)
{
- passinput(c, m.msec, InputMouse, flags, m.xy.x, m.xy.y);
+ passinput(c, m.msec, InputMouse, f, m.xy.x, m.xy.y);
}
static void
--- a/msg.c
+++ b/msg.c
@@ -247,8 +247,8 @@
PLONG(q+4, m->msec);
PSHORT(q+8, m->mtype);
PSHORT(q+10, m->flags);
- PSHORT(q+12, m->iarg1);
- PSHORT(q+14, m->iarg2);
+ PSHORT(q+12, m->iarg[0]);
+ PSHORT(q+14, m->iarg[1]);
return len;
case Lreq:
--- a/rd.c
+++ b/rd.c
@@ -5,7 +5,7 @@
#include "dat.h"
#include "fns.h"
-Rdp rd = {
+Rdp conn = {
.fd = -1,
.depth = 16,
.windom = "",
@@ -41,7 +41,7 @@
}
static int
-startmouseproc(void)
+startmouseproc(Rdp* c)
{
int mpid;
@@ -54,13 +54,13 @@
return mpid;
}
atexit(atexitkiller);
- readdevmouse(&rd);
+ readdevmouse(c);
exits("mouse eof");
return 0;
}
static int
-startkbdproc(void)
+startkbdproc(Rdp* c)
{
int pid;
switch(pid = rfork(RFPROC|RFMEM)){
@@ -72,13 +72,13 @@
return pid;
}
atexit(atexitkiller);
- readkbd(&rd);
+ readkbd(c);
exits("kbd eof");
return 0;
}
static int
-startsnarfproc(void)
+startsnarfproc(Rdp* c)
{
int pid;
@@ -92,7 +92,7 @@
}
atexit(atexitkiller);
initsnarf();
- pollsnarf(&rd);
+ pollsnarf(c);
exits("snarf eof");
return 0;
}
@@ -119,12 +119,12 @@
void
main(int argc, char *argv[])
{
- int doauth, fd;
- char *server, *addr, *keyspec;
+ int doauth;
+ char *server, *addr, *keyspec, *label;
UserPasswd *creds;
+ Rdp* c;
- rd.local = getenv("sysname");
- rd.user = getenv("user");
+ c = &conn;
keyspec = "";
doauth = 1;
@@ -137,25 +137,22 @@
keyspec = EARGF(usage());
break;
case 'T':
- rd.label = strdup(EARGF(usage()));
+ label = strdup(EARGF(usage()));
break;
case 'd':
- rd.windom = strdup(EARGF(usage()));
+ c->windom = strdup(EARGF(usage()));
break;
case 's':
- rd.shell = strdup(EARGF(usage()));
+ c->shell = strdup(EARGF(usage()));
break;
case 'c':
- rd.rwd = strdup(EARGF(usage()));
+ c->rwd = strdup(EARGF(usage()));
break;
- case 'n':
- rd.local = estrdup(EARGF(usage()));
- break;
case 'a':
- rd.depth = atol(EARGF(usage()));
+ c->depth = atol(EARGF(usage()));
break;
case '0':
- rd.wantconsole = 1;
+ c->wantconsole = 1;
break;
default:
usage();
@@ -165,58 +162,59 @@
usage();
server = argv[0];
- if(rd.local == nil)
+
+ c->local = getenv("sysname");
+ c->user = getenv("user");
+ if(c->local == nil)
sysfatal("set $sysname or use -n\n");
- if(rd.user == nil)
+ if(c->user == nil)
sysfatal("set $user");
- if (rd.label == nil)
- rd.label = smprint("rd %s", server);
-
if(doauth){
creds = auth_getuserpasswd(auth_getkey, "proto=pass service=rdp %s", keyspec);
if(creds == nil)
fprint(2, "factotum: %r\n");
else {
- rd.user = creds->user;
- rd.passwd = creds->passwd;
+ c->user = creds->user;
+ c->passwd = creds->passwd;
}
}else
- rd.user = "";
- initvc(&rd);
+ c->user = "";
+ initvc(c);
+
addr = netmkaddr(server, "tcp", "3389");
- fd = dial(addr, nil, nil, nil);
- if(fd < 0)
+ c->fd = dial(addr, nil, nil, nil);
+ if(c->fd < 0)
sysfatal("dial %s: %r", addr);
- rd.fd = fd;
- if(x224connect(&rd) < 0)
- sysfatal("connect: %r");
+ if(x224handshake(c) < 0)
+ sysfatal("X.224 handshake: %r");
- if(initdraw(drawerror, nil, rd.label) < 0)
+ if(label == nil)
+ label = smprint("rd %s", server);
+ if(initdraw(drawerror, nil, label) < 0)
sysfatal("initdraw: %r");
display->locking = 1;
unlockdisplay(display);
- rd.ysz = Dy(screen->r);
- rd.xsz = (Dx(screen->r) +3) & ~3;
+ c->ysz = Dy(screen->r);
+ c->xsz = (Dx(screen->r) +3) & ~3;
- if(rdphandshake(&rd) < 0)
+ if(rdphandshake(c) < 0)
sysfatal("handshake: %r");
atexit(atexitkiller);
atexitkill(getpid());
- atexitkill(startmouseproc());
- atexitkill(startkbdproc());
- atexitkill(startsnarfproc());
+ atexitkill(startmouseproc(c));
+ atexitkill(startkbdproc(c));
+ atexitkill(startsnarfproc(c));
- readnet(&rd);
+ readnet(c);
- x224disconnect(&rd);
-
- if(!rd.active)
+ x224hangup(c);
+ if(!c->active)
exits(nil);
- if(rd.hupreason)
- sysfatal("disconnect reason code %d", rd.hupreason);
+ if(c->hupreason)
+ sysfatal("disconnect reason code %d", c->hupreason);
sysfatal("hangup");
}
--- a/rpc.c
+++ b/rpc.c
@@ -9,7 +9,7 @@
int joinchannel(Rdp*,int,int);
int
-x224connect(Rdp* c)
+x224handshake(Rdp* c)
{
Msg t, r;
@@ -27,16 +27,16 @@
werrstr("server refused STARTTLS");
return -1;
}
+ c->sproto = r.negproto;
if(starttls(c) < 0)
return -1;
- c->sproto = r.negproto;
return 0;
}
int
-x224disconnect(Rdp* c)
+x224hangup(Rdp* c)
{
Msg t;
@@ -61,7 +61,6 @@
t.nvc = c->nvc;
if(writemsg(c, &t) <= 0)
sysfatal("Connect Initial: writemsg: %r");
-
if(readmsg(c, &r) <= 0)
sysfatal("Connect Response: readmsg: %r");
if(r.type != Mconnected)
@@ -142,12 +141,12 @@
mcsuid = c->mcsuid;
userchan = c->userchan;
- if(joinchannel(c, mcsuid, userchan) < 0)
+ if(joinchannel(c, c->mcsuid, c->userchan) < 0)
return -1;
- if(joinchannel(c, mcsuid, GLOBALCHAN) < 0)
+ if(joinchannel(c, c->mcsuid, GLOBALCHAN) < 0)
return -1;
for(i = 0; i < nv; i++)
- if(joinchannel(c, mcsuid, v[i].mcsid) < 0)
+ if(joinchannel(c, c->mcsuid, v[i].mcsid) < 0)
return -1;
sendclientinfo(c);
@@ -363,7 +362,7 @@
}
void
-passinput(Rdp* c, ulong msec, int mtype, int iflags, int iarg1, int iarg2)
+passinput(Rdp* c, ulong msec, int t, int f, int a, int b)
{
Msg t;
@@ -370,11 +369,11 @@
t.type = Ainput;
t.originid = c->userchan;
t.shareid = c->shareid;
- t.mtype = mtype;
t.msec = msec;
- t.flags = iflags;
- t.iarg1 = iarg1;
- t.iarg2 = iarg2;
+ t.mtype = t;
+ t.flags = f;
+ t.iarg[0] = a;
+ t.iarg[1] = b;
if(writemsg(c, &t) <= 0)
sysfatal("passinput: %r");
}