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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
/*
* Unix SMB/CIFS implementation.
*
* SPOOLSS RPC Pipe server / winreg client routines
*
* Copyright (c) 2010 Andreas Schneider <asn@samba.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "rpc_server/rpc_ncacn_np.h"
#include "../lib/tsocket/tsocket.h"
#include "../librpc/gen_ndr/ndr_spoolss.h"
#include "../librpc/gen_ndr/ndr_winreg.h"
#include "srv_spoolss_util.h"
#include "rpc_client/cli_winreg_spoolss.h"
WERROR winreg_printer_binding_handle(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
struct dcerpc_binding_handle **winreg_binding_handle)
{
struct tsocket_address *local;
NTSTATUS status;
int rc;
rc = tsocket_address_inet_from_strings(mem_ctx,
"ip",
"127.0.0.1",
0,
&local);
if (rc < 0) {
return WERR_NOMEM;
}
status = rpcint_binding_handle(mem_ctx,
&ndr_table_winreg,
local,
session_info,
msg_ctx,
winreg_binding_handle);
talloc_free(local);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("winreg_printer_binding_handle: Could not connect to winreg pipe: %s\n",
nt_errstr(status)));
return ntstatus_to_werror(status);
}
return WERR_OK;
}
WERROR winreg_delete_printer_key_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key)
{
WERROR result;
struct dcerpc_binding_handle *b;
TALLOC_CTX *tmp_ctx;
tmp_ctx = talloc_stackframe();
if (tmp_ctx == NULL) {
return WERR_NOMEM;
}
result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
if (!W_ERROR_IS_OK(result)) {
talloc_free(tmp_ctx);
return result;
}
result = winreg_delete_printer_key(tmp_ctx,
b,
printer,
key);
talloc_free(tmp_ctx);
return result;
}
WERROR winreg_printer_update_changeid_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer)
{
WERROR result;
struct dcerpc_binding_handle *b;
TALLOC_CTX *tmp_ctx;
tmp_ctx = talloc_stackframe();
if (tmp_ctx == NULL) {
return WERR_NOMEM;
}
result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
if (!W_ERROR_IS_OK(result)) {
talloc_free(tmp_ctx);
return result;
}
result = winreg_printer_update_changeid(mem_ctx,
b,
printer);
talloc_free(tmp_ctx);
return result;
}
WERROR winreg_printer_get_changeid_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
uint32_t *pchangeid)
{
WERROR result;
struct dcerpc_binding_handle *b;
TALLOC_CTX *tmp_ctx;
tmp_ctx = talloc_stackframe();
if (tmp_ctx == NULL) {
return WERR_NOMEM;
}
result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
if (!W_ERROR_IS_OK(result)) {
talloc_free(tmp_ctx);
return result;
}
result = winreg_printer_get_changeid(mem_ctx,
b,
printer,
pchangeid);
talloc_free(tmp_ctx);
return result;
}
WERROR winreg_get_printer_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
struct spoolss_PrinterInfo2 **pinfo2)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_get_printer(mem_ctx, b,
printer,
pinfo2);
}
WERROR winreg_create_printer_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *sharename)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_create_printer(mem_ctx, b,
sharename);
}
WERROR winreg_update_printer_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *sharename,
uint32_t info2_mask,
struct spoolss_SetPrinterInfo2 *info2,
struct spoolss_DeviceMode *devmode,
struct security_descriptor *secdesc)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_update_printer(mem_ctx, b,
sharename,
info2_mask,
info2,
devmode,
secdesc);
}
WERROR winreg_set_printer_dataex_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key,
const char *value,
enum winreg_Type type,
uint8_t *data,
uint32_t data_size)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_set_printer_dataex(mem_ctx, b,
printer,
key,
value,
type,
data,
data_size);
}
WERROR winreg_enum_printer_dataex_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key,
uint32_t *pnum_values,
struct spoolss_PrinterEnumValues **penum_values)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_enum_printer_dataex(mem_ctx, b,
printer,
key,
pnum_values,
penum_values);
}
WERROR winreg_get_printer_dataex_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key,
const char *value,
enum winreg_Type *type,
uint8_t **data,
uint32_t *data_size)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_get_printer_dataex(mem_ctx, b,
printer,
key,
value,
type,
data,
data_size);
}
WERROR winreg_delete_printer_dataex_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key,
const char *value)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_delete_printer_dataex(mem_ctx, b,
printer,
key,
value);
}
WERROR winreg_get_driver_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *architecture,
const char *driver_name,
uint32_t driver_version,
struct spoolss_DriverInfo8 **_info8)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_get_driver(mem_ctx, b,
architecture,
driver_name,
driver_version,
_info8);
}
WERROR winreg_get_driver_list_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *architecture,
uint32_t version,
uint32_t *num_drivers,
const char ***drivers_p)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_get_driver_list(mem_ctx, b,
architecture,
version,
num_drivers,
drivers_p);
}
WERROR winreg_del_driver_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
struct spoolss_DriverInfo8 *info8,
uint32_t version)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_del_driver(mem_ctx, b,
info8,
version);
}
WERROR winreg_add_driver_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
struct spoolss_AddDriverInfoCtr *r,
const char **driver_name,
uint32_t *driver_version)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_add_driver(mem_ctx, b,
r,
driver_name,
driver_version);
}
WERROR winreg_get_printer_secdesc_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *sharename,
struct spoolss_security_descriptor **psecdesc)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_get_printer_secdesc(mem_ctx, b,
sharename,
psecdesc);
}
WERROR winreg_set_printer_secdesc_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *sharename,
const struct spoolss_security_descriptor *secdesc)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_set_printer_secdesc(mem_ctx, b,
sharename,
secdesc);
}
WERROR winreg_printer_enumforms1_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
uint32_t *pnum_info,
union spoolss_FormInfo **pinfo)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_printer_enumforms1(mem_ctx, b,
pnum_info,
pinfo);
}
WERROR winreg_printer_getform1_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *form_name,
struct spoolss_FormInfo1 *r)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_printer_getform1(mem_ctx, b,
form_name,
r);
}
WERROR winreg_printer_addform1_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
struct spoolss_AddFormInfo1 *form)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_printer_addform1(mem_ctx, b,
form);
}
WERROR winreg_printer_setform1_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *form_name,
struct spoolss_AddFormInfo1 *form)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_printer_setform1(mem_ctx, b,
form_name,
form);
}
WERROR winreg_printer_deleteform1_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *form_name)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_printer_deleteform1(mem_ctx, b,
form_name);
}
WERROR winreg_enum_printer_key_internal(TALLOC_CTX *mem_ctx,
const struct auth_session_info *session_info,
struct messaging_context *msg_ctx,
const char *printer,
const char *key,
uint32_t *pnum_subkeys,
const char ***psubkeys)
{
WERROR result;
struct dcerpc_binding_handle *b;
result = winreg_printer_binding_handle(mem_ctx, session_info, msg_ctx, &b);
W_ERROR_NOT_OK_RETURN(result);
return winreg_enum_printer_key(mem_ctx, b,
printer,
key,
pnum_subkeys,
psubkeys);
}
|