2 Unix SMB/CIFS implementation.
4 Simple LDB NTPTR backend
6 Copyright (C) Stefan (metze) Metzmacher 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 This implements a NTPTR backend that store
23 all objects (Printers, Ports, Monitors, PrinterDrivers ...)
24 in a ldb database, but doesn't do real printing.
26 This is just used for testing how some of
27 the SPOOLSS protocol details should work
31 #include "ntptr/ntptr.h"
32 #include "librpc/gen_ndr/ndr_spoolss.h"
33 #include "lib/ldb/include/ldb.h"
34 #include "auth/auth.h"
35 #include "dsdb/samdb/samdb.h"
37 #include "../lib/util/util_ldb.h"
38 #include "rpc_server/common/common.h"
39 #include "param/param.h"
42 connect to the SPOOLSS database
43 return a ldb_context pointer on success, or NULL on failure
45 static struct ldb_context
*sptr_db_connect(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev_ctx
, struct loadparm_context
*lp_ctx
)
47 return ldb_wrap_connect(mem_ctx
, ev_ctx
, lp_ctx
, lp_spoolss_url(lp_ctx
), system_session(mem_ctx
, lp_ctx
),
51 static int sptr_db_search(struct ldb_context
*ldb
,
53 struct ldb_dn
*basedn
,
54 struct ldb_message
***res
,
55 const char * const *attrs
,
56 const char *format
, ...) PRINTF_ATTRIBUTE(6,7);
58 static int sptr_db_search(struct ldb_context
*ldb
,
60 struct ldb_dn
*basedn
,
61 struct ldb_message
***res
,
62 const char * const *attrs
,
63 const char *format
, ...)
69 count
= gendb_search_v(ldb
, mem_ctx
, basedn
, res
, attrs
, format
, ap
);
75 #define SET_STRING(ldb, mod, attr, value) do { \
76 if (value == NULL) return WERR_INVALID_PARAM; \
77 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
82 #define SET_UINT(ldb, mod, attr, value) do { \
83 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
88 static NTSTATUS
sptr_init_context(struct ntptr_context
*ntptr
)
90 struct ldb_context
*sptr_db
= sptr_db_connect(ntptr
, ntptr
->ev_ctx
, ntptr
->lp_ctx
);
91 NT_STATUS_HAVE_NO_MEMORY(sptr_db
);
93 ntptr
->private_data
= sptr_db
;
98 /* PrintServer functions */
99 static WERROR
sptr_OpenPrintServer(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
100 struct spoolss_OpenPrinterEx
*r
,
101 const char *server_name
,
102 struct ntptr_GenericHandle
**_server
)
104 struct ntptr_GenericHandle
*server
;
106 /* TODO: do access check here! */
108 server
= talloc(mem_ctx
, struct ntptr_GenericHandle
);
109 W_ERROR_HAVE_NO_MEMORY(server
);
111 server
->type
= NTPTR_HANDLE_SERVER
;
112 server
->ntptr
= ntptr
;
113 server
->object_name
= talloc_strdup(server
, server_name
);
114 W_ERROR_HAVE_NO_MEMORY(server
->object_name
);
115 server
->access_mask
= 0;
116 server
->private_data
= NULL
;
123 * PrintServer PrinterData functions
126 static WERROR
sptr_PrintServerData(struct ntptr_GenericHandle
*server
,
128 const char *value_name
,
129 union spoolss_PrinterData
*r
,
130 enum winreg_Type
*type
)
132 struct dcerpc_server_info
*server_info
= lp_dcerpc_server_info(mem_ctx
, server
->ntptr
->lp_ctx
);
133 if (strcmp("W3SvcInstalled", value_name
) == 0) {
137 } else if (strcmp("BeepEnabled", value_name
) == 0) {
141 } else if (strcmp("EventLog", value_name
) == 0) {
145 } else if (strcmp("NetPopup", value_name
) == 0) {
149 } else if (strcmp("NetPopupToComputer", value_name
) == 0) {
153 } else if (strcmp("MajorVersion", value_name
) == 0) {
157 } else if (strcmp("MinorVersion", value_name
) == 0) {
161 } else if (strcmp("DefaultSpoolDirectory", value_name
) == 0) {
163 r
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
164 W_ERROR_HAVE_NO_MEMORY(r
->string
);
166 } else if (strcmp("Architecture", value_name
) == 0) {
168 r
->string
= talloc_strdup(mem_ctx
, SPOOLSS_ARCHITECTURE_NT_X86
);
169 W_ERROR_HAVE_NO_MEMORY(r
->string
);
171 } else if (strcmp("DsPresent", value_name
) == 0) {
175 } else if (strcmp("OSVersion", value_name
) == 0) {
177 enum ndr_err_code ndr_err
;
178 struct spoolss_OSVersion os
;
180 os
.major
= server_info
->version_major
;
181 os
.minor
= server_info
->version_minor
;
182 os
.build
= server_info
->version_build
;
183 os
.extra_string
= "";
185 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, lp_iconv_convenience(server
->ntptr
->lp_ctx
), &os
, (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
186 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
187 return WERR_GENERAL_FAILURE
;
193 } else if (strcmp("OSVersionEx", value_name
) == 0) {
195 enum ndr_err_code ndr_err
;
196 struct spoolss_OSVersionEx os_ex
;
198 os_ex
.major
= server_info
->version_major
;
199 os_ex
.minor
= server_info
->version_minor
;
200 os_ex
.build
= server_info
->version_build
;
201 os_ex
.extra_string
= "";
202 os_ex
.service_pack_major
= 0;
203 os_ex
.service_pack_minor
= 0;
204 os_ex
.suite_mask
= 0;
205 os_ex
.product_type
= 0;
208 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, lp_iconv_convenience(server
->ntptr
->lp_ctx
), &os_ex
, (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersionEx
);
209 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
210 return WERR_GENERAL_FAILURE
;
216 } else if (strcmp("DNSMachineName", value_name
) == 0) {
217 if (!lp_realm(server
->ntptr
->lp_ctx
)) return WERR_INVALID_PARAM
;
220 r
->string
= talloc_asprintf(mem_ctx
, "%s.%s",
221 lp_netbios_name(server
->ntptr
->lp_ctx
),
222 lp_realm(server
->ntptr
->lp_ctx
));
223 W_ERROR_HAVE_NO_MEMORY(r
->string
);
227 return WERR_INVALID_PARAM
;
230 static WERROR
sptr_GetPrintServerData(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
231 struct spoolss_GetPrinterData
*r
)
234 union spoolss_PrinterData data
;
236 enum ndr_err_code ndr_err
;
238 result
= sptr_PrintServerData(server
, mem_ctx
, r
->in
.value_name
, &data
, r
->out
.type
);
239 if (!W_ERROR_IS_OK(result
)) {
243 ndr_err
= ndr_push_union_blob(&blob
, mem_ctx
, lp_iconv_convenience(server
->ntptr
->lp_ctx
),
244 &data
, *r
->out
.type
, (ndr_push_flags_fn_t
)ndr_push_spoolss_PrinterData
);
245 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
246 return WERR_GENERAL_FAILURE
;
249 *r
->out
.needed
= blob
.length
;
251 if (r
->in
.offered
>= *r
->out
.needed
) {
252 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
258 /* PrintServer Form functions */
259 static WERROR
sptr_EnumPrintServerForms(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
260 struct spoolss_EnumForms
*r
)
262 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
263 struct ldb_message
**msgs
;
266 union spoolss_FormInfo
*info
;
268 count
= sptr_db_search(sptr_db
, mem_ctx
,
269 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
270 &msgs
, NULL
, "(&(objectClass=form))");
272 if (count
== 0) return WERR_OK
;
273 if (count
< 0) return WERR_GENERAL_FAILURE
;
275 info
= talloc_array(mem_ctx
, union spoolss_FormInfo
, count
);
276 W_ERROR_HAVE_NO_MEMORY(info
);
278 switch (r
->in
.level
) {
280 for (i
=0; i
< count
; i
++) {
281 info
[i
].info1
.flags
= samdb_result_uint(msgs
[i
], "flags", SPOOLSS_FORM_BUILTIN
);
283 info
[i
].info1
.form_name
= samdb_result_string(msgs
[i
], "form-name", NULL
);
284 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.form_name
);
286 info
[i
].info1
.size
.width
= samdb_result_uint(msgs
[i
], "size-width", 0);
287 info
[i
].info1
.size
.height
= samdb_result_uint(msgs
[i
], "size-height", 0);
289 info
[i
].info1
.area
.left
= samdb_result_uint(msgs
[i
], "area-left", 0);
290 info
[i
].info1
.area
.top
= samdb_result_uint(msgs
[i
], "area-top", 0);
291 info
[i
].info1
.area
.right
= samdb_result_uint(msgs
[i
], "area-right", 0);
292 info
[i
].info1
.area
.bottom
= samdb_result_uint(msgs
[i
], "area-bottom", 0);
296 return WERR_UNKNOWN_LEVEL
;
300 *r
->out
.count
= count
;
304 static WERROR
sptr_AddPrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
305 struct spoolss_AddForm
*r
)
307 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
308 struct ldb_message
*msg
,**msgs
;
309 const char * const attrs
[] = {"flags", NULL
};
312 /* TODO: do checks access here
313 * if (!(server->access_mask & desired_access)) {
314 * return WERR_FOOBAR;
318 switch (r
->in
.level
) {
320 if (!r
->in
.info
.info1
) {
323 count
= sptr_db_search(sptr_db
, mem_ctx
,
324 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
325 &msgs
, attrs
, "(&(form-name=%s)(objectClass=form))",
326 r
->in
.info
.info1
->form_name
);
328 if (count
== 1) return WERR_FOOBAR
;
329 if (count
> 1) return WERR_FOOBAR
;
330 if (count
< 0) return WERR_GENERAL_FAILURE
;
332 if (r
->in
.info
.info1
->flags
!= SPOOLSS_FORM_USER
) {
336 msg
= ldb_msg_new(mem_ctx
);
337 W_ERROR_HAVE_NO_MEMORY(msg
);
339 /* add core elements to the ldb_message for the Form */
340 msg
->dn
= ldb_dn_new_fmt(msg
, sptr_db
, "form-name=%s,CN=Forms,CN=PrintServer", r
->in
.info
.info1
->form_name
);
341 SET_STRING(sptr_db
, msg
, "objectClass", "form");
343 SET_UINT(sptr_db
, msg
, "flags", r
->in
.info
.info1
->flags
);
345 SET_STRING(sptr_db
, msg
, "form-name", r
->in
.info
.info1
->form_name
);
347 SET_UINT(sptr_db
, msg
, "size-width", r
->in
.info
.info1
->size
.width
);
348 SET_UINT(sptr_db
, msg
, "size-height", r
->in
.info
.info1
->size
.height
);
350 SET_UINT(sptr_db
, msg
, "area-left", r
->in
.info
.info1
->area
.left
);
351 SET_UINT(sptr_db
, msg
, "area-top", r
->in
.info
.info1
->area
.top
);
352 SET_UINT(sptr_db
, msg
, "area-right", r
->in
.info
.info1
->area
.right
);
353 SET_UINT(sptr_db
, msg
, "area-bottom", r
->in
.info
.info1
->area
.bottom
);
356 return WERR_UNKNOWN_LEVEL
;
359 ret
= ldb_add(sptr_db
, msg
);
367 static WERROR
sptr_SetPrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
368 struct spoolss_SetForm
*r
)
370 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
371 struct ldb_message
*msg
,**msgs
;
372 const char * const attrs
[] = { "flags", NULL
};
374 enum spoolss_FormFlags flags
;
376 /* TODO: do checks access here
377 * if (!(server->access_mask & desired_access)) {
378 * return WERR_FOOBAR;
382 switch (r
->in
.level
) {
384 if (!r
->in
.info
.info1
) {
388 count
= sptr_db_search(sptr_db
, mem_ctx
,
389 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
390 &msgs
, attrs
, "(&(form-name=%s)(objectClass=form))",
391 r
->in
.info
.info1
->form_name
);
393 if (count
== 0) return WERR_FOOBAR
;
394 if (count
> 1) return WERR_FOOBAR
;
395 if (count
< 0) return WERR_GENERAL_FAILURE
;
397 flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
398 if (flags
!= SPOOLSS_FORM_USER
) {
402 msg
= ldb_msg_new(mem_ctx
);
403 W_ERROR_HAVE_NO_MEMORY(msg
);
405 /* add core elements to the ldb_message for the user */
406 msg
->dn
= msgs
[0]->dn
;
408 SET_UINT(sptr_db
, msg
, "flags", r
->in
.info
.info1
->flags
);
410 SET_STRING(sptr_db
, msg
, "form-name", r
->in
.info
.info1
->form_name
);
412 SET_UINT(sptr_db
, msg
, "size-width", r
->in
.info
.info1
->size
.width
);
413 SET_UINT(sptr_db
, msg
, "size-height", r
->in
.info
.info1
->size
.height
);
415 SET_UINT(sptr_db
, msg
, "area-left", r
->in
.info
.info1
->area
.left
);
416 SET_UINT(sptr_db
, msg
, "area-top", r
->in
.info
.info1
->area
.top
);
417 SET_UINT(sptr_db
, msg
, "area-right", r
->in
.info
.info1
->area
.right
);
418 SET_UINT(sptr_db
, msg
, "area-bottom", r
->in
.info
.info1
->area
.bottom
);
421 return WERR_UNKNOWN_LEVEL
;
424 ret
= samdb_replace(sptr_db
, mem_ctx
, msg
);
432 static WERROR
sptr_DeletePrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
433 struct spoolss_DeleteForm
*r
)
435 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
436 struct ldb_message
**msgs
;
437 const char * const attrs
[] = { "flags", NULL
};
439 enum spoolss_FormFlags flags
;
441 /* TODO: do checks access here
442 * if (!(server->access_mask & desired_access)) {
443 * return WERR_FOOBAR;
447 if (!r
->in
.form_name
) {
451 count
= sptr_db_search(sptr_db
, mem_ctx
,
452 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
453 &msgs
, attrs
, "(&(form-name=%s)(objectclass=form))",
456 if (count
== 0) return WERR_FOOBAR
;
457 if (count
> 1) return WERR_FOOBAR
;
458 if (count
< 0) return WERR_GENERAL_FAILURE
;
460 flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
461 if (flags
!= SPOOLSS_FORM_USER
) {
465 ret
= ldb_delete(sptr_db
, msgs
[0]->dn
);
473 /* PrintServer Driver functions */
474 static WERROR
sptr_EnumPrinterDrivers(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
475 struct spoolss_EnumPrinterDrivers
*r
)
480 static WERROR
sptr_GetPrinterDriverDirectory(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
481 struct spoolss_GetPrinterDriverDirectory
*r
)
483 union spoolss_DriverDirectoryInfo
*info
;
488 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
489 * are ignoring the r->in.level completely, so we do :-)
493 * TODO: check the server name is ours
494 * - if it's a invalid UNC then return WERR_INVALID_NAME
495 * - if it's the wrong host name return WERR_INVALID_PARAM
496 * - if it's "" then we need to return a local WINDOWS path
498 if (!r
->in
.server
|| !r
->in
.server
[0]) {
499 prefix
= "C:\\DRIVERS";
501 prefix
= talloc_asprintf(mem_ctx
, "%s\\print$", r
->in
.server
);
502 W_ERROR_HAVE_NO_MEMORY(prefix
);
505 if (r
->in
.environment
&& strcmp(SPOOLSS_ARCHITECTURE_NT_X86
, r
->in
.environment
) == 0) {
508 return WERR_INVALID_ENVIRONMENT
;
511 info
= talloc(mem_ctx
, union spoolss_DriverDirectoryInfo
);
512 W_ERROR_HAVE_NO_MEMORY(info
);
514 info
->info1
.directory_name
= talloc_asprintf(mem_ctx
, "%s\\%s", prefix
, postfix
);
515 W_ERROR_HAVE_NO_MEMORY(info
->info1
.directory_name
);
521 /* Printer functions */
522 static WERROR
sptr_EnumPrinters(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
523 struct spoolss_EnumPrinters
*r
)
525 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
526 struct ldb_message
**msgs
;
529 union spoolss_PrinterInfo
*info
;
531 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
532 "(&(objectclass=printer))");
534 if (count
== 0) return WERR_OK
;
535 if (count
< 0) return WERR_GENERAL_FAILURE
;
537 info
= talloc_array(mem_ctx
, union spoolss_PrinterInfo
, count
);
538 W_ERROR_HAVE_NO_MEMORY(info
);
540 switch(r
->in
.level
) {
542 for (i
= 0; i
< count
; i
++) {
543 info
[i
].info1
.flags
= samdb_result_uint(msgs
[i
], "flags", 0);
545 info
[i
].info1
.name
= samdb_result_string(msgs
[i
], "name", "");
546 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.name
);
548 info
[i
].info1
.description
= samdb_result_string(msgs
[i
], "description", "");
549 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.description
);
551 info
[i
].info1
.comment
= samdb_result_string(msgs
[i
], "comment", NULL
);
555 for (i
= 0; i
< count
; i
++) {
556 info
[i
].info2
.servername
= samdb_result_string(msgs
[i
], "servername", "");
557 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.servername
);
559 info
[i
].info2
.printername
= samdb_result_string(msgs
[i
], "printername", "");
560 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printername
);
562 info
[i
].info2
.sharename
= samdb_result_string(msgs
[i
], "sharename", "");
563 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.sharename
);
565 info
[i
].info2
.portname
= samdb_result_string(msgs
[i
], "portname", "");
566 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.portname
);
568 info
[i
].info2
.drivername
= samdb_result_string(msgs
[i
], "drivername", "");
569 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.drivername
);
571 info
[i
].info2
.comment
= samdb_result_string(msgs
[i
], "comment", NULL
);
573 info
[i
].info2
.location
= samdb_result_string(msgs
[i
], "location", NULL
);
575 info
[i
].info2
.devmode
= NULL
;
577 info
[i
].info2
.sepfile
= samdb_result_string(msgs
[i
], "sepfile", NULL
);
579 info
[i
].info2
.printprocessor
= samdb_result_string(msgs
[i
], "printprocessor", "");
580 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printprocessor
);
582 info
[i
].info2
.datatype
= samdb_result_string(msgs
[i
], "datatype", "");
583 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.datatype
);
585 info
[i
].info2
.parameters
= samdb_result_string(msgs
[i
], "parameters", NULL
);
587 info
[i
].info2
.secdesc
= NULL
;
589 info
[i
].info2
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
590 info
[i
].info2
.priority
= samdb_result_uint(msgs
[i
], "priority", 0);
591 info
[i
].info2
.defaultpriority
= samdb_result_uint(msgs
[i
], "defaultpriority", 0);
592 info
[i
].info2
.starttime
= samdb_result_uint(msgs
[i
], "starttime", 0);
593 info
[i
].info2
.untiltime
= samdb_result_uint(msgs
[i
], "untiltime", 0);
594 info
[i
].info2
.status
= samdb_result_uint(msgs
[i
], "status", 0);
595 info
[i
].info2
.cjobs
= samdb_result_uint(msgs
[i
], "cjobs", 0);
596 info
[i
].info2
.averageppm
= samdb_result_uint(msgs
[i
], "averageppm", 0);
600 for (i
= 0; i
< count
; i
++) {
601 info
[i
].info4
.printername
= samdb_result_string(msgs
[i
], "printername", "");
602 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printername
);
604 info
[i
].info4
.servername
= samdb_result_string(msgs
[i
], "servername", "");
605 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.servername
);
607 info
[i
].info4
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
611 for (i
= 0; i
< count
; i
++) {
612 info
[i
].info5
.printername
= samdb_result_string(msgs
[i
], "name", "");
613 W_ERROR_HAVE_NO_MEMORY(info
[i
].info5
.printername
);
615 info
[i
].info5
.portname
= samdb_result_string(msgs
[i
], "port", "");
616 W_ERROR_HAVE_NO_MEMORY(info
[i
].info5
.portname
);
618 info
[i
].info5
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
619 info
[i
].info5
.device_not_selected_timeout
= samdb_result_uint(msgs
[i
], "device_not_selected_timeout", 0);
620 info
[i
].info5
.transmission_retry_timeout
= samdb_result_uint(msgs
[i
], "transmission_retry_timeout", 0);
624 return WERR_UNKNOWN_LEVEL
;
628 *r
->out
.count
= count
;
632 static WERROR
sptr_OpenPrinter(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
633 struct spoolss_OpenPrinterEx
*r
,
634 const char *printer_name
,
635 struct ntptr_GenericHandle
**printer
)
637 return WERR_INVALID_PRINTER_NAME
;
641 static WERROR
sptr_EnumPorts(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
642 struct spoolss_EnumPorts
*r
)
644 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
645 struct ldb_message
**msgs
;
648 union spoolss_PortInfo
*info
;
650 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
651 "(&(objectclass=port))");
653 if (count
== 0) return WERR_OK
;
654 if (count
< 0) return WERR_GENERAL_FAILURE
;
656 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, count
);
657 W_ERROR_HAVE_NO_MEMORY(info
);
659 switch (r
->in
.level
) {
661 for (i
= 0; i
< count
; i
++) {
662 info
[i
].info1
.port_name
= samdb_result_string(msgs
[i
], "port-name", "");
663 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.port_name
);
667 for (i
=0; i
< count
; i
++) {
668 info
[i
].info2
.port_name
= samdb_result_string(msgs
[i
], "port-name", "");
669 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.port_name
);
671 info
[i
].info2
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
672 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.monitor_name
);
674 info
[i
].info2
.description
= samdb_result_string(msgs
[i
], "description", "");
675 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.description
);
677 info
[i
].info2
.port_type
= samdb_result_uint(msgs
[i
], "port-type", SPOOLSS_PORT_TYPE_WRITE
);
678 info
[i
].info2
.reserved
= samdb_result_uint(msgs
[i
], "reserved", 0);
682 return WERR_UNKNOWN_LEVEL
;
686 *r
->out
.count
= count
;
690 /* monitor functions */
691 static WERROR
sptr_EnumMonitors(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
692 struct spoolss_EnumMonitors
*r
)
694 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
695 struct ldb_message
**msgs
;
698 union spoolss_MonitorInfo
*info
;
700 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
701 "(&(objectclass=monitor))");
703 if (count
== 0) return WERR_OK
;
704 if (count
< 0) return WERR_GENERAL_FAILURE
;
706 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, count
);
707 W_ERROR_HAVE_NO_MEMORY(info
);
709 switch (r
->in
.level
) {
711 for (i
= 0; i
< count
; i
++) {
712 info
[i
].info1
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
713 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.monitor_name
);
717 for (i
=0; i
< count
; i
++) {
718 info
[i
].info2
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
719 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.monitor_name
);
721 info
[i
].info2
.environment
= samdb_result_string(msgs
[i
], "environment", "");
722 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.environment
);
724 info
[i
].info2
.dll_name
= samdb_result_string(msgs
[i
], "dll-name", "");
725 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.dll_name
);
729 return WERR_UNKNOWN_LEVEL
;
733 *r
->out
.count
= count
;
737 /* Printer Form functions */
738 static WERROR
sptr_GetPrinterForm(struct ntptr_GenericHandle
*printer
, TALLOC_CTX
*mem_ctx
,
739 struct spoolss_GetForm
*r
)
741 struct ldb_context
*sptr_db
= talloc_get_type(printer
->ntptr
->private_data
, struct ldb_context
);
742 struct ldb_message
**msgs
;
743 struct ldb_dn
*base_dn
;
745 union spoolss_FormInfo
*info
;
747 /* TODO: do checks access here
748 * if (!(printer->access_mask & desired_access)) {
749 * return WERR_FOOBAR;
753 base_dn
= ldb_dn_new_fmt(mem_ctx
, sptr_db
, "CN=Forms,CN=%s,CN=Printers", printer
->object_name
);
754 W_ERROR_HAVE_NO_MEMORY(base_dn
);
756 count
= sptr_db_search(sptr_db
, mem_ctx
, base_dn
, &msgs
, NULL
,
757 "(&(form-name=%s)(objectClass=form))",
760 if (count
== 0) return WERR_FOOBAR
;
761 if (count
> 1) return WERR_FOOBAR
;
762 if (count
< 0) return WERR_GENERAL_FAILURE
;
764 info
= talloc(mem_ctx
, union spoolss_FormInfo
);
765 W_ERROR_HAVE_NO_MEMORY(info
);
767 switch (r
->in
.level
) {
769 info
->info1
.flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
771 info
->info1
.form_name
= samdb_result_string(msgs
[0], "form-name", NULL
);
772 W_ERROR_HAVE_NO_MEMORY(info
->info1
.form_name
);
774 info
->info1
.size
.width
= samdb_result_uint(msgs
[0], "size-width", 0);
775 info
->info1
.size
.height
= samdb_result_uint(msgs
[0], "size-height", 0);
777 info
->info1
.area
.left
= samdb_result_uint(msgs
[0], "area-left", 0);
778 info
->info1
.area
.top
= samdb_result_uint(msgs
[0], "area-top", 0);
779 info
->info1
.area
.right
= samdb_result_uint(msgs
[0], "area-right", 0);
780 info
->info1
.area
.bottom
= samdb_result_uint(msgs
[0], "area-bottom", 0);
783 return WERR_UNKNOWN_LEVEL
;
790 static WERROR
sptr_GetPrintProcessorDirectory(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
791 struct spoolss_GetPrintProcessorDirectory
*r
)
793 union spoolss_PrintProcessorDirectoryInfo
*info
;
798 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
799 * are ignoring the r->in.level completely, so we do :-)
803 * TODO: check the server name is ours
804 * - if it's a invalid UNC then return WERR_INVALID_NAME
805 * - if it's the wrong host name return WERR_INVALID_PARAM
806 * - if it's "" then we need to return a local WINDOWS path
808 if (!r
->in
.server
|| !r
->in
.server
[0]) {
809 prefix
= "C:\\PRTPROCS";
811 prefix
= talloc_asprintf(mem_ctx
, "%s\\prnproc$", r
->in
.server
);
812 W_ERROR_HAVE_NO_MEMORY(prefix
);
815 if (r
->in
.environment
&& strcmp(SPOOLSS_ARCHITECTURE_NT_X86
, r
->in
.environment
) == 0) {
818 return WERR_INVALID_ENVIRONMENT
;
821 info
= talloc(mem_ctx
, union spoolss_PrintProcessorDirectoryInfo
);
822 W_ERROR_HAVE_NO_MEMORY(info
);
824 info
->info1
.directory_name
= talloc_asprintf(mem_ctx
, "%s\\%s", prefix
, postfix
);
825 W_ERROR_HAVE_NO_MEMORY(info
->info1
.directory_name
);
833 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
835 static const struct ntptr_ops ntptr_simple_ldb_ops
= {
836 .name
= "simple_ldb",
837 .init_context
= sptr_init_context
,
839 /* PrintServer functions */
840 .OpenPrintServer
= sptr_OpenPrintServer
,
841 /* .XcvDataPrintServer = sptr_XcvDataPrintServer,
843 /* PrintServer PrinterData functions */
844 /* .EnumPrintServerData = sptr_EnumPrintServerData,
845 */ .GetPrintServerData
= sptr_GetPrintServerData
,
846 /* .SetPrintServerData = sptr_SetPrintServerData,
847 .DeletePrintServerData = sptr_DeletePrintServerData,
849 /* PrintServer Form functions */
850 .EnumPrintServerForms
= sptr_EnumPrintServerForms
,
851 .AddPrintServerForm
= sptr_AddPrintServerForm
,
852 .SetPrintServerForm
= sptr_SetPrintServerForm
,
853 .DeletePrintServerForm
= sptr_DeletePrintServerForm
,
855 /* PrintServer Driver functions */
856 .EnumPrinterDrivers
= sptr_EnumPrinterDrivers
,
857 /* .AddPrinterDriver = sptr_AddPrinterDriver,
858 .DeletePrinterDriver = sptr_DeletePrinterDriver,
859 */ .GetPrinterDriverDirectory
= sptr_GetPrinterDriverDirectory
,
862 .EnumPorts
= sptr_EnumPorts
,
863 /* .OpenPort = sptr_OpenPort,
864 .XcvDataPort = sptr_XcvDataPort,
866 /* Monitor functions */
867 .EnumMonitors
= sptr_EnumMonitors
,
868 /* .OpenMonitor = sptr_OpenMonitor,
869 .XcvDataMonitor = sptr_XcvDataMonitor,
871 /* PrintProcessor functions */
872 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
874 .GetPrintProcessorDirectory
= sptr_GetPrintProcessorDirectory
,
876 /* Printer functions */
877 .EnumPrinters
= sptr_EnumPrinters
,
878 .OpenPrinter
= sptr_OpenPrinter
,
879 /* .AddPrinter = sptr_AddPrinter,
880 .GetPrinter = sptr_GetPrinter,
881 .SetPrinter = sptr_SetPrinter,
882 .DeletePrinter = sptr_DeletePrinter,
883 .XcvDataPrinter = sptr_XcvDataPrinter,
885 /* Printer Driver functions */
886 /* .GetPrinterDriver = sptr_GetPrinterDriver,
888 /* Printer PrinterData functions */
889 /* .EnumPrinterData = sptr_EnumPrinterData,
890 .GetPrinterData = sptr_GetPrinterData,
891 .SetPrinterData = sptr_SetPrinterData,
892 .DeletePrinterData = sptr_DeletePrinterData,
894 /* Printer Form functions */
895 /* .EnumPrinterForms = sptr_EnumPrinterForms,
896 .AddPrinterForm = sptr_AddPrinterForm,
897 */ .GetPrinterForm
= sptr_GetPrinterForm
,
898 /* .SetPrinterForm = sptr_SetPrinterForm,
899 .DeletePrinterForm = sptr_DeletePrinterForm,
901 /* Printer Job functions */
902 /* .EnumJobs = sptr_EnumJobs,
903 .AddJob = sptr_AddJob,
904 .ScheduleJob = sptr_ScheduleJob,
905 .GetJob = sptr_GetJob,
906 .SetJob = sptr_SetJob,
908 /* Printer Printing functions */
909 /* .StartDocPrinter = sptr_StartDocPrinter,
910 .EndDocPrinter = sptr_EndDocPrinter,
911 .StartPagePrinter = sptr_StartPagePrinter,
912 .EndPagePrinter = sptr_EndPagePrinter,
913 .WritePrinter = sptr_WritePrinter,
914 .ReadPrinter = sptr_ReadPrinter,
917 NTSTATUS
ntptr_simple_ldb_init(void)
921 ret
= ntptr_register(&ntptr_simple_ldb_ops
);
922 if (!NT_STATUS_IS_OK(ret
)) {
923 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
924 ntptr_simple_ldb_ops
.name
));