-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.go
306 lines (284 loc) · 17 KB
/
server.go
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package emsmdb
import (
"context"
"fmt"
"strings"
"unicode/utf16"
dcerpc "github.com/oiweiwei/go-msrpc/dcerpc"
errors "github.com/oiweiwei/go-msrpc/dcerpc/errors"
uuid "github.com/oiweiwei/go-msrpc/midl/uuid"
ndr "github.com/oiweiwei/go-msrpc/ndr"
)
var (
_ = context.Background
_ = fmt.Errorf
_ = utf16.Encode
_ = strings.TrimPrefix
_ = ndr.ZeroString
_ = (*uuid.UUID)(nil)
_ = (*dcerpc.SyntaxID)(nil)
_ = (*errors.Error)(nil)
)
// emsmdb server interface.
type EmsmdbServer interface {
// Opnum0Reserved operation.
// Opnum0Reserved
// The EcDoDisconnect method closes a Session Context with the server. The server destroys
// the Session Context and releases all associated server state, objects, and resources
// that are associated with the Session Context. This call requires an active session
// context handle from the EcDoConnectEx method, as specified in section 3.1.4.1.
//
// Return Values: If the method succeeds, the return value is 0. If the method fails,
// the return value is an implementation-specific error code.
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol as specified in [MS-RPCE].
DoDisconnect(context.Context, *DoDisconnectRequest) (*DoDisconnectResponse, error)
// Opnum2Reserved operation.
// Opnum2Reserved
// Opnum3Reserved operation.
// Opnum3Reserved
// The EcRRegisterPushNotification method registers a callback address with the server
// for a Session Context. The server MAY<26> support the EcRRegisterPushNotification
// method.
//
// The callback address is used to notify the client of pending events on the server.
// This call requires an active session context handle from the EcDoConnectEx method,
// as specified in section 3.1.4.1. The server MUST store the callback address and the
// opaque context data in the Session Context. To notify the client of pending events,
// the server sends a packet containing just the opaque context data to the callback
// address. The callback address specifies which network transport is to be used to
// send the data packet.
//
// For more information about notification handling, see [MS-OXCNOTIF].
//
// Return Values: If the method succeeds, the return value is 0. If the method fails,
// the return value is an implementation-specific error code or one of the protocol-defined
// error codes listed in the following table.
//
// +-----------------+------------+------------------------------------------------------+
// | ERROR CODE | | |
// | NAME | VALUE | MEANING |
// | | | |
// +-----------------+------------+------------------------------------------------------+
// +-----------------+------------+------------------------------------------------------+
// | ecInvalidParam | 0x80070057 | A parameter passed was not valid for the call. |
// +-----------------+------------+------------------------------------------------------+
// | ecNotSupported | 0x80040102 | The callback address is not supported on the server. |
// +-----------------+------------+------------------------------------------------------+
// | ecTooBig | 0x80040305 | Opaque context data is too large. |
// +-----------------+------------+------------------------------------------------------+
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol as specified in [MS-RPCE].
RegisterPushNotification(context.Context, *RegisterPushNotificationRequest) (*RegisterPushNotificationResponse, error)
// Opnum5Reserved operation.
// Opnum5Reserved
// The EcDummyRpc method returns a SUCCESS. A client can use it to determine whether
// it can communicate with the server.
//
// Return Values: The function MUST succeed and return 0.
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol as specified in [MS-RPCE].
DummyRPC(context.Context, *DummyRPCRequest) (*DummyRPCResponse, error)
// Opnum7Reserved operation.
// Opnum7Reserved
// Opnum8Reserved operation.
// Opnum8Reserved
// Opnum9Reserved operation.
// Opnum9Reserved
// The EcDoConnectEx method establishes a new Session Context with the server. The Session
// Context is persisted on the server until the client disconnects by using the EcDoDisconnect
// method, as specified in section 3.1.4.3. The EcDoConnectEx method returns a session
// context handle to be used by a client in subsequent calls.
//
// Return Values: If the method succeeds, the return value is 0. If the method fails,
// the return value is an implementation-specific error code or one of the protocol-defined
// error codes listed in the following table.
//
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ERROR CODE | | |
// | NAME | VALUE | MEANING |
// | | | |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecAccessDenied<14> | 0x80070005 | The authentication context associated with the binding handle does not have |
// | | | enough privilege or the szUserDN parameter is empty. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecNotEncrypted | 0x00000970 | The server is configured to require encryption and the authentication for |
// | | | the binding handle contained in the hBinding parameter is not set with |
// | | | RPC_C_AUTHN_LEVEL_PKT_PRIVACY. For more information about setting the |
// | | | authentication and authorization, see [MSDN-RpcBindingSetAuthInfoEx]. The client |
// | | | attempts the call again with new binding handle that is encrypted. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecClientVerDisallowed | 0x000004DF | 1. The server requires encryption, but the client is not encrypted and the |
// | | | client does not support receiving error code ecNotEncrypted being returned by |
// | | | the server. For details about which client versions do not support receiving |
// | | | error code ecNotEncrypted, see section 3.1.4.1.3 and section 3.2.4.1.3. 2. The |
// | | | client version has been blocked by the administrator. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecLoginFailure | 0x80040111 | Server is unable to log in user to the mailbox or public folder database. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecUnknownUser | 0x000003EB | The server does not recognize the szUserDN parameter as a valid enabled mailbox. |
// | | | For more details, see [MS-OXCSTOR] section 3.1.4.1. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecLoginPerm | 0x000003F2 | The connection is requested for administrative access, but the authentication |
// | | | context associated with the binding handle does not have enough privilege. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecVersionMismatch | 0x80040110 | The client and server versions are not compatible. The client protocol version |
// | | | is earlier than that required by the server. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecCachedModeRequired | 0x000004E1 | The server requires the client to be running in cache mode. For details about |
// | | | which client versions understand this error code, see section 3.2.4.1.3. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecRpcHttpDisallowed | 0x000004E0 | The server requires the client to not be connected via RPC over HTTP. For |
// | | | details about which client versions understand this error code, see section |
// | | | 3.1.4.1.3. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
// | ecProtocolDisabled | 0x000007D8 | The server disallows the user to access the server via this protocol interface. |
// | | | This could be done if the user is only capable of accessing their mailbox |
// | | | information through a different means (for example, Webmail, POP, or IMAP). |
// | | | For details about which client versions understand this error code, see section |
// | | | 3.1.4.1.3. |
// +-----------------------+------------+----------------------------------------------------------------------------------+
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol, as specified in [MS-RPCE].
DoConnectEx(context.Context, *DoConnectExRequest) (*DoConnectExResponse, error)
// The EcDoRpcExt2 method passes generic ROP commands to the server for processing within
// a Session Context. Each call can contain multiple ROP commands. The server returns
// the results of each ROP command to the client. This call requires an active session
// context handle returned from the EcDoConnectEx method.
//
// Return Values: If the method succeeds, the return value is 0. If the method fails,
// the return value is an implementation-specific error code or the protocol-defined
// error code listed in the following table.
//
// +-----------------+------------+----------------------------------------------------------------------------------+
// | ERROR CODE | | |
// | NAME | VALUE | MEANING |
// | | | |
// +-----------------+------------+----------------------------------------------------------------------------------+
// +-----------------+------------+----------------------------------------------------------------------------------+
// | ecRpcFormat | 0x000004B6 | The format of the request was found to be invalid. This is a generic error that |
// | | | means the length was found to be invalid or the content was found to be invalid. |
// +-----------------+------------+----------------------------------------------------------------------------------+
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol as specified in [MS-RPCE].
DoRPCExt2(context.Context, *DoRPCExt2Request) (*DoRPCExt2Response, error)
// Opnum12Reserved operation.
// Opnum12Reserved
// Opnum13Reserved operation.
// Opnum13Reserved
// The EcDoAsyncConnectEx method binds a session context handle returned from the EcDoConnectEx
// method, as specified in section 3.1.4.1, to a new asynchronous context handle that
// can be used in calls to the EcDoAsyncWaitEx method in the AsyncEMSMDB interface,
// as specified in section 3.3.4.1. This call requires that an active session context
// handle be returned from the EcDoConnectEx method.
//
// This method is part of notification handling. For more information about notifications,
// see [MS-OXCNOTIF].
//
// Return Values: If the method succeeds, the return value is 0. If the method fails,
// the return value is an implementation-specific error code or the protocol-defined
// error code listed in the following table.
//
// +-----------------+------------+----------------------------------------------------------------------------------+
// | ERROR CODE | | |
// | NAME | VALUE | MEANING |
// | | | |
// +-----------------+------------+----------------------------------------------------------------------------------+
// +-----------------+------------+----------------------------------------------------------------------------------+
// | ecRejected<25> | 0x000007EE | Server has asynchronous RPC notifications disabled. Client either polls |
// | | | for notifications or calls the EcRRegisterPushNotifications method (section |
// | | | 3.1.4.5). |
// +-----------------+------------+----------------------------------------------------------------------------------+
//
// Exceptions Thrown: No exceptions are thrown beyond those thrown by the underlying
// RPC protocol as specified in [MS-RPCE].
DoAsyncConnectEx(context.Context, *DoAsyncConnectExRequest) (*DoAsyncConnectExResponse, error)
}
func RegisterEmsmdbServer(conn dcerpc.Conn, o EmsmdbServer, opts ...dcerpc.Option) {
conn.RegisterServer(NewEmsmdbServerHandle(o), append(opts, dcerpc.WithAbstractSyntax(EmsmdbSyntaxV0_81))...)
}
func NewEmsmdbServerHandle(o EmsmdbServer) dcerpc.ServerHandle {
return func(ctx context.Context, opNum int, r ndr.Reader) (dcerpc.Operation, error) {
return EmsmdbServerHandle(ctx, o, opNum, r)
}
}
func EmsmdbServerHandle(ctx context.Context, o EmsmdbServer, opNum int, r ndr.Reader) (dcerpc.Operation, error) {
switch opNum {
case 0: // Opnum0Reserved
// Opnum0Reserved
return nil, nil
case 1: // EcDoDisconnect
in := &DoDisconnectRequest{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.DoDisconnect(ctx, in)
return resp.xxx_ToOp(ctx), err
case 2: // Opnum2Reserved
// Opnum2Reserved
return nil, nil
case 3: // Opnum3Reserved
// Opnum3Reserved
return nil, nil
case 4: // EcRRegisterPushNotification
in := &RegisterPushNotificationRequest{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.RegisterPushNotification(ctx, in)
return resp.xxx_ToOp(ctx), err
case 5: // Opnum5Reserved
// Opnum5Reserved
return nil, nil
case 6: // EcDummyRpc
in := &DummyRPCRequest{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.DummyRPC(ctx, in)
return resp.xxx_ToOp(ctx), err
case 7: // Opnum7Reserved
// Opnum7Reserved
return nil, nil
case 8: // Opnum8Reserved
// Opnum8Reserved
return nil, nil
case 9: // Opnum9Reserved
// Opnum9Reserved
return nil, nil
case 10: // EcDoConnectEx
in := &DoConnectExRequest{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.DoConnectEx(ctx, in)
return resp.xxx_ToOp(ctx), err
case 11: // EcDoRpcExt2
in := &DoRPCExt2Request{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.DoRPCExt2(ctx, in)
return resp.xxx_ToOp(ctx), err
case 12: // Opnum12Reserved
// Opnum12Reserved
return nil, nil
case 13: // Opnum13Reserved
// Opnum13Reserved
return nil, nil
case 14: // EcDoAsyncConnectEx
in := &DoAsyncConnectExRequest{}
if err := in.UnmarshalNDR(ctx, r); err != nil {
return nil, err
}
resp, err := o.DoAsyncConnectEx(ctx, in)
return resp.xxx_ToOp(ctx), err
}
return nil, nil
}