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 "rpc_server/common/common.h"
38 #include "param/param.h"
41 connect to the SPOOLSS database
42 return a ldb_context pointer on success, or NULL on failure
44 static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx)
46 return ldb_wrap_connect(mem_ctx, lp_spoolss_url(), system_session(mem_ctx),
50 static int sptr_db_search(struct ldb_context *ldb,
52 struct ldb_dn *basedn,
53 struct ldb_message ***res,
54 const char * const *attrs,
55 const char *format, ...) PRINTF_ATTRIBUTE(6,7);
57 static int sptr_db_search(struct ldb_context *ldb,
59 struct ldb_dn *basedn,
60 struct ldb_message ***res,
61 const char * const *attrs,
62 const char *format, ...)
68 count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
74 #define SET_STRING(ldb, mod, attr, value) do { \
75 if (value == NULL) return WERR_INVALID_PARAM; \
76 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
81 #define SET_UINT(ldb, mod, attr, value) do { \
82 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
87 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
89 struct ldb_context *sptr_db = sptr_db_connect(ntptr);
90 NT_STATUS_HAVE_NO_MEMORY(sptr_db);
92 ntptr->private_data = sptr_db;
97 /* PrintServer functions */
98 static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
99 struct spoolss_OpenPrinterEx *r,
100 const char *server_name,
101 struct ntptr_GenericHandle **_server)
103 struct ntptr_GenericHandle *server;
105 /* TODO: do access check here! */
107 server = talloc(mem_ctx, struct ntptr_GenericHandle);
108 W_ERROR_HAVE_NO_MEMORY(server);
110 server->type = NTPTR_HANDLE_SERVER;
111 server->ntptr = ntptr;
112 server->object_name = talloc_strdup(server, server_name);
113 W_ERROR_HAVE_NO_MEMORY(server->object_name);
114 server->access_mask = 0;
115 server->private_data = NULL;
122 * PrintServer PrinterData functions
124 static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
125 struct spoolss_GetPrinterData *r)
127 if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
128 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
129 r->out.data.value = 0;
131 } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
132 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
133 r->out.data.value = 0;
135 } else if (strcmp("EventLog", r->in.value_name) == 0) {
136 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
137 r->out.data.value = 0;
139 } else if (strcmp("NetPopup", r->in.value_name) == 0) {
140 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
141 r->out.data.value = 0;
143 } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
144 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
145 r->out.data.value = 0;
147 } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
148 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
149 r->out.data.value = 3;
151 } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
152 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
153 r->out.data.value = 0;
155 } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
156 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
157 r->out.data.string = "C:\\PRINTERS";
159 } else if (strcmp("Architecture", r->in.value_name) == 0) {
160 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
161 r->out.data.string = SPOOLSS_ARCHITECTURE_NT_X86;
163 } else if (strcmp("DsPresent", r->in.value_name) == 0) {
164 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
165 r->out.data.value = 1;
167 } else if (strcmp("OSVersion", r->in.value_name) == 0) {
170 struct spoolss_OSVersion os;
172 os.major = dcesrv_common_get_version_major(mem_ctx, NULL);
173 os.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
174 os.build = dcesrv_common_get_version_build(mem_ctx, NULL);
175 os.extra_string = "";
177 status = ndr_push_struct_blob(&blob, mem_ctx, &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
178 if (!NT_STATUS_IS_OK(status)) {
179 return WERR_GENERAL_FAILURE;
182 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
183 r->out.data.binary = blob;
185 } else if (strcmp("OSVersionEx", r->in.value_name) == 0) {
188 struct spoolss_OSVersionEx os_ex;
190 os_ex.major = dcesrv_common_get_version_major(mem_ctx, NULL);
191 os_ex.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
192 os_ex.build = dcesrv_common_get_version_build(mem_ctx, NULL);
193 os_ex.extra_string = "";
197 status = ndr_push_struct_blob(&blob, mem_ctx, &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
198 if (!NT_STATUS_IS_OK(status)) {
199 return WERR_GENERAL_FAILURE;
202 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
203 r->out.data.binary = blob;
205 } else if (strcmp("DNSMachineName", r->in.value_name) == 0) {
206 if (!lp_realm()) return WERR_INVALID_PARAM;
208 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
209 r->out.data.string = talloc_asprintf(mem_ctx, "%s.%s",
212 W_ERROR_HAVE_NO_MEMORY(r->out.data.string);
216 return WERR_INVALID_PARAM;
219 /* PrintServer Form functions */
220 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
221 struct spoolss_EnumForms *r)
223 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
224 struct ldb_message **msgs;
227 union spoolss_FormInfo *info;
229 count = sptr_db_search(sptr_db, mem_ctx,
230 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
231 &msgs, NULL, "(&(objectClass=form))");
233 if (count == 0) return WERR_OK;
234 if (count < 0) return WERR_GENERAL_FAILURE;
236 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
237 W_ERROR_HAVE_NO_MEMORY(info);
239 switch (r->in.level) {
241 for (i=0; i < count; i++) {
242 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
244 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
245 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
247 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
248 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
250 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
251 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
252 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
253 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
257 return WERR_UNKNOWN_LEVEL;
261 r->out.count = count;
265 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
266 struct spoolss_AddForm *r)
268 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
269 struct ldb_message *msg,**msgs;
270 const char * const attrs[] = {"flags", NULL };
273 /* TODO: do checks access here
274 * if (!(server->access_mask & desired_access)) {
275 * return WERR_FOOBAR;
279 switch (r->in.level) {
281 if (!r->in.info.info1) {
284 count = sptr_db_search(sptr_db, mem_ctx,
285 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
286 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
287 r->in.info.info1->form_name);
289 if (count == 1) return WERR_FOOBAR;
290 if (count > 1) return WERR_FOOBAR;
291 if (count < 0) return WERR_GENERAL_FAILURE;
293 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
297 msg = ldb_msg_new(mem_ctx);
298 W_ERROR_HAVE_NO_MEMORY(msg);
300 /* add core elements to the ldb_message for the Form */
301 msg->dn = ldb_dn_new_fmt(msg, sptr_db, "form-name=%s,CN=Forms,CN=PrintServer", r->in.info.info1->form_name);
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_new(mem_ctx, sptr_db, "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_new(mem_ctx, sptr_db, "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 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_new_fmt(mem_ctx, sptr_db, "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,
762 /* .XcvDataPrintServer = sptr_XcvDataPrintServer,
764 /* PrintServer PrinterData functions */
765 /* .EnumPrintServerData = sptr_EnumPrintServerData,
766 */ .GetPrintServerData = sptr_GetPrintServerData,
767 /* .SetPrintServerData = sptr_SetPrintServerData,
768 .DeletePrintServerData = sptr_DeletePrintServerData,
770 /* PrintServer Form functions */
771 .EnumPrintServerForms = sptr_EnumPrintServerForms,
772 .AddPrintServerForm = sptr_AddPrintServerForm,
773 .SetPrintServerForm = sptr_SetPrintServerForm,
774 .DeletePrintServerForm = sptr_DeletePrintServerForm,
776 /* PrintServer Driver functions */
777 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
778 /* .AddPrinterDriver = sptr_AddPrinterDriver,
779 .DeletePrinterDriver = sptr_DeletePrinterDriver,
780 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
783 .EnumPorts = sptr_EnumPorts,
784 /* .OpenPort = sptr_OpenPort,
785 .XcvDataPort = sptr_XcvDataPort,
787 /* Monitor functions */
788 .EnumMonitors = sptr_EnumMonitors,
789 /* .OpenMonitor = sptr_OpenMonitor,
790 .XcvDataMonitor = sptr_XcvDataMonitor,
792 /* PrintProcessor functions */
793 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
795 /* Printer functions */
796 .EnumPrinters = sptr_EnumPrinters,
797 .OpenPrinter = sptr_OpenPrinter,
798 /* .AddPrinter = sptr_AddPrinter,
799 .GetPrinter = sptr_GetPrinter,
800 .SetPrinter = sptr_SetPrinter,
801 .DeletePrinter = sptr_DeletePrinter,
802 .XcvDataPrinter = sptr_XcvDataPrinter,
804 /* Printer Driver functions */
805 /* .GetPrinterDriver = sptr_GetPrinterDriver,
807 /* Printer PrinterData functions */
808 /* .EnumPrinterData = sptr_EnumPrinterData,
809 .GetPrinterData = sptr_GetPrinterData,
810 .SetPrinterData = sptr_SetPrinterData,
811 .DeletePrinterData = sptr_DeletePrinterData,
813 /* Printer Form functions */
814 /* .EnumPrinterForms = sptr_EnumPrinterForms,
815 .AddPrinterForm = sptr_AddPrinterForm,
816 */ .GetPrinterForm = sptr_GetPrinterForm,
817 /* .SetPrinterForm = sptr_SetPrinterForm,
818 .DeletePrinterForm = sptr_DeletePrinterForm,
820 /* Printer Job functions */
821 /* .EnumJobs = sptr_EnumJobs,
822 .AddJob = sptr_AddJob,
823 .ScheduleJob = sptr_ScheduleJob,
824 .GetJob = sptr_GetJob,
825 .SetJob = sptr_SetJob,
827 /* Printer Printing functions */
828 /* .StartDocPrinter = sptr_StartDocPrinter,
829 .EndDocPrinter = sptr_EndDocPrinter,
830 .StartPagePrinter = sptr_StartPagePrinter,
831 .EndPagePrinter = sptr_EndPagePrinter,
832 .WritePrinter = sptr_WritePrinter,
833 .ReadPrinter = sptr_ReadPrinter,
836 NTSTATUS ntptr_simple_ldb_init(void)
840 ret = ntptr_register(&ntptr_simple_ldb_ops);
841 if (!NT_STATUS_IS_OK(ret)) {
842 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
843 ntptr_simple_ldb_ops.name));