-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathefs.c
More file actions
160 lines (145 loc) · 2.91 KB
/
efs.c
File metadata and controls
160 lines (145 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* [MS-RDPEFS]: Remote Desktop Protocol: File System Virtual Channel Extension */
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"
int
sendefsmsg(Rdp* c, Efsmsg* m)
{
int n;
uchar buf[64];
n = putefsmsg(buf, sizeof buf, m);
if(n < 0)
return n;
return sendvc(c, "RDPDR", buf, n);
}
/* 3.2.5.1.3 Sending a Client Announce Reply Message */
static void
clientidconfirm(Rdp* c)
{
Efsmsg t;
t.ctype = CTcore;
t.pakid = CCann; /* 2.2.2.3 Client Announce Reply */
t.vermaj = 1;
t.vermin = 13;
t.cid = c->efs.cid;
if(sendefsmsg(c, &t) < 0)
fprint(2, "clientidconfirm: %r\n");
}
static void
clientnamereq(Rdp* c)
{
Efsmsg t;
t.ctype = CTcore;
t.pakid = CCnrq; /* 2.2.2.4 Client Name Request */
t.cname = c->local;
// fprint(2, "DBG clientnamereq: %s\n", c->local);
if(sendefsmsg(c, &t) < 0)
fprint(2, "clientnamereq: %r\n");
}
/* 3.1.3 Initialization */
static void
serverannounced(Rdp* c, Efsmsg* r)
{
/* r is 2.2.2.2 Server Announce Request */
if(r->vermin >= 12){
c->efs.cid = r->cid;
//fprint(2, "DBG c->efs.cid = %lud\n", (ulong)c->efs.cid);
}else{
c->efs.cid = lrand();
}
clientidconfirm(c);
clientnamereq(c);
/* BUG we'd expect receiving Server Core Capability Request (section 2.2.2.7)
followed by Server Client ID Confirm (2.2.2.6) - but never get them */
}
void
efsvcfn(Rdp* c, uchar* a, uint nb)
{
Efsmsg r;
if(getefsmsg(&r, a, nb) < 0){
fprint(2, "EFS: %r");
return;
}
if(r.ctype != CTcore)
return; // no printing
switch(r.pakid){
case CSann:
serverannounced(c, &r);
break;
default:
fprint(2, "EFS: new msg: %.*H\n", nb, a);
return;
}
}
int
getefsmsg(Efsmsg* m, uchar* a, int nb)
{
if(nb < 4){
werrstr(Eshort);
return -1;
}
/* 2.2.1.1 Shared Header (RDPDR_HEADER)
* ctype[2] pakid[2]
*/
m->ctype = GSHORT(a);
m->pakid = GSHORT(a+2);
switch(m->ctype+m->pakid<<16){
case CTcore+CSann<<16:
/* 2.2.2.2 Server Announce Request */
if(nb < 12){
werrstr(Eshort);
return -1;
}
m->vermaj = GSHORT(a+4);
m->vermin = GSHORT(a+6);
m->cid = GLONG(a+8);
break;
default:
werrstr("unrecognised packet type (%x:%x)",
m->ctype, m->pakid);
return -1;
}
return 0;
}
int
putefsmsg(uchar* a, int nb, Efsmsg* m)
{
int n, len;
n = (2+2);
if(nb < n){
werrstr(Esmall);
return -1;
}
PSHORT(a, m->ctype);
PSHORT(a+2, m->pakid);
switch(m->ctype+m->pakid<<16){
case CTcore+CCann<<16:
/* 2.2.2.3 Client Announce Reply */
n = (2+2)+(2+2+4);
if(nb < n){
werrstr(Esmall);
return -1;
}
PSHORT(a+4, m->vermaj);
PSHORT(a+6, m->vermin);
PLONG(a+8, m->cid);
break;
case CTcore+CCnrq<<16:
/* 2.2.2.4 Client Name Request */
len = strlen(m->cname)+1;
if(nb < 16){
werrstr(Esmall);
return -1;
}
PLONG(a+4, 1); // UnicodeFlag
PLONG(a+8, 0); // CodePage
n = toutf16(a+16, nb-16, m->cname, len);
PLONG(a+12, n);
return 16+n;
default:
werrstr("unrecognised packet type (%x:%x)",
m->ctype, m->pakid);
return -1;
} return n;
}