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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 This implements a NTPTR backend that store
24 all objects (Printers, Ports, Monitors, PrinterDrivers ...)
25 in a ldb database, but doesn't do real printing.
27 This is just used for testing how some of
28 the SPOOLSS protocol details should work
32 #include "ntptr/ntptr.h"
33 #include "librpc/gen_ndr/ndr_spoolss.h"
34 #include "lib/ldb/include/ldb.h"
35 #include "auth/auth.h"
36 #include "dsdb/samdb/samdb.h"
39 connect to the SPOOLSS database
40 return a ldb_context pointer on success, or NULL on failure
42 static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx)
44 return ldb_wrap_connect(mem_ctx, lp_spoolss_url(), system_session(mem_ctx),
48 static int sptr_db_search(struct ldb_context *ldb,
50 const struct ldb_dn *basedn,
51 struct ldb_message ***res,
52 const char * const *attrs,
53 const char *format, ...) PRINTF_ATTRIBUTE(6,7);
55 static int sptr_db_search(struct ldb_context *ldb,
57 const struct ldb_dn *basedn,
58 struct ldb_message ***res,
59 const char * const *attrs,
60 const char *format, ...)
66 count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
72 #define SET_STRING(ldb, mod, attr, value) do { \
73 if (value == NULL) return WERR_INVALID_PARAM; \
74 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
79 #define SET_UINT(ldb, mod, attr, value) do { \
80 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
85 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
87 struct ldb_context *sptr_db = sptr_db_connect(ntptr);
88 NT_STATUS_HAVE_NO_MEMORY(sptr_db);
90 ntptr->private_data = sptr_db;
95 /* PrintServer functions */
96 static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
97 struct spoolss_OpenPrinterEx *r,
98 const char *server_name,
99 struct ntptr_GenericHandle **_server)
101 struct ntptr_GenericHandle *server;
103 /* TODO: do access check here! */
105 server = talloc(mem_ctx, struct ntptr_GenericHandle);
106 W_ERROR_HAVE_NO_MEMORY(server);
108 server->type = NTPTR_HANDLE_SERVER;
109 server->ntptr = ntptr;
110 server->object_name = talloc_strdup(server, server_name);
111 W_ERROR_HAVE_NO_MEMORY(server->object_name);
112 server->access_mask = 0;
113 server->private_data = NULL;
120 * PrintServer PrinterData functions
122 static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
123 struct spoolss_GetPrinterData *r)
125 if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
126 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
127 r->out.data.value = 0;
129 } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
130 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
131 r->out.data.value = 0;
133 } else if (strcmp("EventLog", r->in.value_name) == 0) {
134 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
135 r->out.data.value = 0;
137 } else if (strcmp("NetPopup", r->in.value_name) == 0) {
138 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
139 r->out.data.value = 0;
141 } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
142 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
143 r->out.data.value = 0;
145 } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
146 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
147 r->out.data.value = 3;
149 } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
150 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
151 r->out.data.value = 0;
153 } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
154 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
155 r->out.data.string = "C:\\PRINTERS";
157 } else if (strcmp("Architecture", r->in.value_name) == 0) {
158 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
159 r->out.data.string = SPOOLSS_ARCHITECTURE_NT_X86;
161 } else if (strcmp("DsPresent", r->in.value_name) == 0) {
162 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
163 r->out.data.value = 1;
165 } else if (strcmp("OSVersion", r->in.value_name) == 0) {
168 struct spoolss_OSVersion os;
170 os.major = dcesrv_common_get_version_major(mem_ctx, NULL);
171 os.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
172 os.build = dcesrv_common_get_version_build(mem_ctx, NULL);
173 os.extra_string = "";
175 status = ndr_push_struct_blob(&blob, mem_ctx, &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
176 if (!NT_STATUS_IS_OK(status)) {
177 return WERR_GENERAL_FAILURE;
180 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
181 r->out.data.binary = blob;
183 } else if (strcmp("OSVersionEx", r->in.value_name) == 0) {
186 struct spoolss_OSVersionEx os_ex;
188 os_ex.major = dcesrv_common_get_version_major(mem_ctx, NULL);
189 os_ex.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
190 os_ex.build = dcesrv_common_get_version_build(mem_ctx, NULL);
191 os_ex.extra_string = "";
195 status = ndr_push_struct_blob(&blob, mem_ctx, &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
196 if (!NT_STATUS_IS_OK(status)) {
197 return WERR_GENERAL_FAILURE;
200 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
201 r->out.data.binary = blob;
203 } else if (strcmp("DNSMachineName", r->in.value_name) == 0) {
204 if (!lp_realm()) return WERR_INVALID_PARAM;
206 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
207 r->out.data.string = talloc_asprintf(mem_ctx, "%s.%s",
210 W_ERROR_HAVE_NO_MEMORY(r->out.data.string);
214 return WERR_INVALID_PARAM;
217 /* PrintServer Form functions */
218 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
219 struct spoolss_EnumForms *r)
221 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
222 struct ldb_message **msgs;
225 union spoolss_FormInfo *info;
227 count = sptr_db_search(sptr_db, mem_ctx,
228 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
229 &msgs, NULL, "(&(objectClass=form))");
231 if (count == 0) return WERR_OK;
232 if (count < 0) return WERR_GENERAL_FAILURE;
234 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
235 W_ERROR_HAVE_NO_MEMORY(info);
237 switch (r->in.level) {
239 for (i=0; i < count; i++) {
240 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
242 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
243 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
245 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
246 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
248 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
249 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
250 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
251 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
255 return WERR_UNKNOWN_LEVEL;
259 r->out.count = count;
263 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
264 struct spoolss_AddForm *r)
266 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
267 struct ldb_message *msg,**msgs;
268 const char * const attrs[] = {"flags", NULL };
271 /* TODO: do checks access here
272 * if (!(server->access_mask & desired_access)) {
273 * return WERR_FOOBAR;
277 switch (r->in.level) {
279 if (!r->in.info.info1) {
282 count = sptr_db_search(sptr_db, mem_ctx,
283 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
284 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
285 r->in.info.info1->form_name);
287 if (count == 1) return WERR_FOOBAR;
288 if (count > 1) return WERR_FOOBAR;
289 if (count < 0) return WERR_GENERAL_FAILURE;
291 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
295 msg = ldb_msg_new(mem_ctx);
296 W_ERROR_HAVE_NO_MEMORY(msg);
298 /* add core elements to the ldb_message for the Form */
299 msg->dn = ldb_dn_build_child(msg,
300 "form-name", r->in.info.info1->form_name,
301 ldb_dn_explode(msg, "CN=Forms,CN=PrintServer"));
302 SET_STRING(sptr_db, msg, "objectClass", "form");
304 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
306 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
308 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
309 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
311 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
312 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
313 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
314 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
317 return WERR_UNKNOWN_LEVEL;
320 ret = samdb_add(sptr_db, mem_ctx, msg);
328 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
329 struct spoolss_SetForm *r)
331 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
332 struct ldb_message *msg,**msgs;
333 const char * const attrs[] = { "flags", NULL};
335 enum spoolss_FormFlags flags;
337 /* TODO: do checks access here
338 * if (!(server->access_mask & desired_access)) {
339 * return WERR_FOOBAR;
343 switch (r->in.level) {
345 if (!r->in.info.info1) {
349 count = sptr_db_search(sptr_db, mem_ctx,
350 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
351 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
352 r->in.info.info1->form_name);
354 if (count == 0) return WERR_FOOBAR;
355 if (count > 1) return WERR_FOOBAR;
356 if (count < 0) return WERR_GENERAL_FAILURE;
358 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
359 if (flags != SPOOLSS_FORM_USER) {
363 msg = ldb_msg_new(mem_ctx);
364 W_ERROR_HAVE_NO_MEMORY(msg);
366 /* add core elements to the ldb_message for the user */
367 msg->dn = msgs[0]->dn;
369 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
371 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
373 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
374 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
376 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
377 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
378 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
379 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
382 return WERR_UNKNOWN_LEVEL;
385 ret = samdb_replace(sptr_db, mem_ctx, msg);
393 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
394 struct spoolss_DeleteForm *r)
396 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
397 struct ldb_message **msgs;
398 const char * const attrs[] = { "flags", NULL};
400 enum spoolss_FormFlags flags;
402 /* TODO: do checks access here
403 * if (!(server->access_mask & desired_access)) {
404 * return WERR_FOOBAR;
408 if (!r->in.form_name) {
412 count = sptr_db_search(sptr_db, mem_ctx,
413 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
414 &msgs, attrs, "(&(form-name=%s)(objectclass=form))",
417 if (count == 0) return WERR_FOOBAR;
418 if (count > 1) return WERR_FOOBAR;
419 if (count < 0) return WERR_GENERAL_FAILURE;
421 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
422 if (flags != SPOOLSS_FORM_USER) {
426 ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
434 /* PrintServer Driver functions */
435 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
436 struct spoolss_EnumPrinterDrivers *r)
441 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
442 struct spoolss_GetPrinterDriverDirectory *r)
444 union spoolss_DriverDirectoryInfo *info;
449 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
450 * are ignoring the r->in.level completely, so we do :-)
454 * TODO: check the server name is ours
455 * - if it's a invalid UNC then return WERR_INVALID_NAME
456 * - if it's the wrong host name return WERR_INVALID_PARAM
457 * - if it's "" then we need to return a local WINDOWS path
459 if (!r->in.server || !r->in.server[0]) {
460 prefix = "C:\\DRIVERS";
462 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
463 W_ERROR_HAVE_NO_MEMORY(prefix);
466 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
469 return WERR_INVALID_ENVIRONMENT;
472 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
473 W_ERROR_HAVE_NO_MEMORY(info);
475 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
476 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
482 /* Printer functions */
483 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
484 struct spoolss_EnumPrinters *r)
486 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
487 struct ldb_message **msgs;
490 union spoolss_PrinterInfo *info;
492 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
493 "(&(objectclass=printer))");
495 if (count == 0) return WERR_OK;
496 if (count < 0) return WERR_GENERAL_FAILURE;
498 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
499 W_ERROR_HAVE_NO_MEMORY(info);
501 switch(r->in.level) {
503 for (i = 0; i < count; i++) {
504 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
506 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
507 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
509 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
510 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
512 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
516 for (i = 0; i < count; i++) {
517 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
518 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
520 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
521 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
523 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
524 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
526 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
527 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
529 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
530 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
532 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
534 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
536 info[i].info2.devmode = NULL;
538 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
540 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
541 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
543 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
544 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
546 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
548 info[i].info2.secdesc = NULL;
550 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
551 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
552 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
553 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
554 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
555 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
556 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
557 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
561 for (i = 0; i < count; i++) {
562 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
563 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
565 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
566 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
568 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
572 for (i = 0; i < count; i++) {
573 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
574 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
576 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
577 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
579 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
580 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
581 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
585 return WERR_UNKNOWN_LEVEL;
589 r->out.count = count;
593 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
594 struct spoolss_OpenPrinterEx *r,
595 const char *printer_name,
596 struct ntptr_GenericHandle **printer)
598 return WERR_INVALID_PRINTER_NAME;
602 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
603 struct spoolss_EnumPorts *r)
605 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
606 struct ldb_message **msgs;
609 union spoolss_PortInfo *info;
611 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
612 "(&(objectclass=port))");
614 if (count == 0) return WERR_OK;
615 if (count < 0) return WERR_GENERAL_FAILURE;
617 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
618 W_ERROR_HAVE_NO_MEMORY(info);
620 switch (r->in.level) {
622 for (i = 0; i < count; i++) {
623 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
624 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
628 for (i=0; i < count; i++) {
629 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
630 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
632 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
633 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
635 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
636 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
638 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
639 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
643 return WERR_UNKNOWN_LEVEL;
647 r->out.count = count;
651 /* monitor functions */
652 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
653 struct spoolss_EnumMonitors *r)
655 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
656 struct ldb_message **msgs;
659 union spoolss_MonitorInfo *info;
661 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
662 "(&(objectclass=monitor))");
664 if (count == 0) return WERR_OK;
665 if (count < 0) return WERR_GENERAL_FAILURE;
667 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
668 W_ERROR_HAVE_NO_MEMORY(info);
670 switch (r->in.level) {
672 for (i = 0; i < count; i++) {
673 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
674 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
678 for (i=0; i < count; i++) {
679 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
680 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
682 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
683 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
685 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
686 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
690 return WERR_UNKNOWN_LEVEL;
694 r->out.count = count;
699 /* Printer Form functions */
700 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
701 struct spoolss_GetForm *r)
703 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
704 struct ldb_message **msgs;
705 const struct ldb_dn *base_dn;
707 union spoolss_FormInfo *info;
709 /* TODO: do checks access here
710 * if (!(printer->access_mask & desired_access)) {
711 * return WERR_FOOBAR;
715 base_dn = ldb_dn_string_compose(mem_ctx, NULL, "CN=Forms, CN=%s, CN=Printers", printer->object_name);
716 W_ERROR_HAVE_NO_MEMORY(base_dn);
718 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
719 "(&(form-name=%s)(objectClass=form))",
722 if (count == 0) return WERR_FOOBAR;
723 if (count > 1) return WERR_FOOBAR;
724 if (count < 0) return WERR_GENERAL_FAILURE;
726 info = talloc(mem_ctx, union spoolss_FormInfo);
727 W_ERROR_HAVE_NO_MEMORY(info);
729 switch (r->in.level) {
731 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
733 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
734 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
736 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
737 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
739 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
740 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
741 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
742 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
745 return WERR_UNKNOWN_LEVEL;
754 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
756 static const struct ntptr_ops ntptr_simple_ldb_ops = {
757 .name = "simple_ldb",
758 .init_context = sptr_init_context,
760 /* PrintServer functions */
761 .OpenPrintServer = sptr_OpenPrintServer,
763 /* PrintServer PrinterData functions */
764 /* .EnumPrintServerData = sptr_EnumPrintServerData,
765 */ .GetPrintServerData = sptr_GetPrintServerData,
766 /* .SetPrintServerData = sptr_SetPrintServerData,
767 .DeletePrintServerData = sptr_DeletePrintServerData,
769 /* PrintServer Form functions */
770 .EnumPrintServerForms = sptr_EnumPrintServerForms,
771 .AddPrintServerForm = sptr_AddPrintServerForm,
772 .SetPrintServerForm = sptr_SetPrintServerForm,
773 .DeletePrintServerForm = sptr_DeletePrintServerForm,
775 /* PrintServer Driver functions */
776 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
777 /* .AddPrinterDriver = sptr_AddPrinterDriver,
778 .DeletePrinterDriver = sptr_DeletePrinterDriver,
779 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
782 .EnumPorts = sptr_EnumPorts,
783 /* .OpenPort = sptr_OpenPort,
785 /* Monitor functions */
786 .EnumMonitors = sptr_EnumMonitors,
787 /* .OpenMonitor = sptr_OpenMonitor,
789 /* PrintProcessor functions */
790 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
792 /* Printer functions */
793 .EnumPrinters = sptr_EnumPrinters,
794 .OpenPrinter = sptr_OpenPrinter,
795 /* .AddPrinter = sptr_AddPrinter,
796 .GetPrinter = sptr_GetPrinter,
797 .SetPrinter = sptr_SetPrinter,
798 .DeletePrinter = sptr_DeletePrinter,
800 /* Printer Driver functions */
801 /* .GetPrinterDriver = sptr_GetPrinterDriver,
803 /* Printer PrinterData functions */
804 /* .EnumPrinterData = sptr_EnumPrinterData,
805 .GetPrinterData = sptr_GetPrinterData,
806 .SetPrinterData = sptr_SetPrinterData,
807 .DeletePrinterData = sptr_DeletePrinterData,
809 /* Printer Form functions */
810 /* .EnumPrinterForms = sptr_EnumPrinterForms,
811 .AddPrinterForm = sptr_AddPrinterForm,
812 */ .GetPrinterForm = sptr_GetPrinterForm,
813 /* .SetPrinterForm = sptr_SetPrinterForm,
814 .DeletePrinterForm = sptr_DeletePrinterForm,
816 /* Printer Job functions */
817 /* .EnumJobs = sptr_EnumJobs,
818 .AddJob = sptr_AddJob,
819 .ScheduleJob = sptr_ScheduleJob,
820 .GetJob = sptr_GetJob,
821 .SetJob = sptr_SetJob,
823 /* Printer Printing functions */
824 /* .StartDocPrinter = sptr_StartDocPrinter,
825 .EndDocPrinter = sptr_EndDocPrinter,
826 .StartPagePrinter = sptr_StartPagePrinter,
827 .EndPagePrinter = sptr_EndPagePrinter,
828 .WritePrinter = sptr_WritePrinter,
829 .ReadPrinter = sptr_ReadPrinter,
832 NTSTATUS ntptr_simple_ldb_init(void)
836 ret = ntptr_register(&ntptr_simple_ldb_ops);
837 if (!NT_STATUS_IS_OK(ret)) {
838 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
839 ntptr_simple_ldb_ops.name));