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"
40 connect to the SPOOLSS database
41 return a ldb_context pointer on success, or NULL on failure
43 static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx)
45 return ldb_wrap_connect(mem_ctx, lp_spoolss_url(), system_session(mem_ctx),
49 static int sptr_db_search(struct ldb_context *ldb,
51 struct ldb_dn *basedn,
52 struct ldb_message ***res,
53 const char * const *attrs,
54 const char *format, ...) PRINTF_ATTRIBUTE(6,7);
56 static int sptr_db_search(struct ldb_context *ldb,
58 struct ldb_dn *basedn,
59 struct ldb_message ***res,
60 const char * const *attrs,
61 const char *format, ...)
67 count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
73 #define SET_STRING(ldb, mod, attr, value) do { \
74 if (value == NULL) return WERR_INVALID_PARAM; \
75 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
80 #define SET_UINT(ldb, mod, attr, value) do { \
81 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
86 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
88 struct ldb_context *sptr_db = sptr_db_connect(ntptr);
89 NT_STATUS_HAVE_NO_MEMORY(sptr_db);
91 ntptr->private_data = sptr_db;
96 /* PrintServer functions */
97 static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
98 struct spoolss_OpenPrinterEx *r,
99 const char *server_name,
100 struct ntptr_GenericHandle **_server)
102 struct ntptr_GenericHandle *server;
104 /* TODO: do access check here! */
106 server = talloc(mem_ctx, struct ntptr_GenericHandle);
107 W_ERROR_HAVE_NO_MEMORY(server);
109 server->type = NTPTR_HANDLE_SERVER;
110 server->ntptr = ntptr;
111 server->object_name = talloc_strdup(server, server_name);
112 W_ERROR_HAVE_NO_MEMORY(server->object_name);
113 server->access_mask = 0;
114 server->private_data = NULL;
121 * PrintServer PrinterData functions
123 static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
124 struct spoolss_GetPrinterData *r)
126 if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
127 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
128 r->out.data.value = 0;
130 } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
131 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
132 r->out.data.value = 0;
134 } else if (strcmp("EventLog", r->in.value_name) == 0) {
135 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
136 r->out.data.value = 0;
138 } else if (strcmp("NetPopup", r->in.value_name) == 0) {
139 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
140 r->out.data.value = 0;
142 } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
143 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
144 r->out.data.value = 0;
146 } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
147 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
148 r->out.data.value = 3;
150 } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
151 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
152 r->out.data.value = 0;
154 } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
155 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
156 r->out.data.string = "C:\\PRINTERS";
158 } else if (strcmp("Architecture", r->in.value_name) == 0) {
159 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
160 r->out.data.string = SPOOLSS_ARCHITECTURE_NT_X86;
162 } else if (strcmp("DsPresent", r->in.value_name) == 0) {
163 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
164 r->out.data.value = 1;
166 } else if (strcmp("OSVersion", r->in.value_name) == 0) {
169 struct spoolss_OSVersion os;
171 os.major = dcesrv_common_get_version_major(mem_ctx, NULL);
172 os.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
173 os.build = dcesrv_common_get_version_build(mem_ctx, NULL);
174 os.extra_string = "";
176 status = ndr_push_struct_blob(&blob, mem_ctx, &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
177 if (!NT_STATUS_IS_OK(status)) {
178 return WERR_GENERAL_FAILURE;
181 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
182 r->out.data.binary = blob;
184 } else if (strcmp("OSVersionEx", r->in.value_name) == 0) {
187 struct spoolss_OSVersionEx os_ex;
189 os_ex.major = dcesrv_common_get_version_major(mem_ctx, NULL);
190 os_ex.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
191 os_ex.build = dcesrv_common_get_version_build(mem_ctx, NULL);
192 os_ex.extra_string = "";
196 status = ndr_push_struct_blob(&blob, mem_ctx, &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
197 if (!NT_STATUS_IS_OK(status)) {
198 return WERR_GENERAL_FAILURE;
201 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
202 r->out.data.binary = blob;
204 } else if (strcmp("DNSMachineName", r->in.value_name) == 0) {
205 if (!lp_realm()) return WERR_INVALID_PARAM;
207 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
208 r->out.data.string = talloc_asprintf(mem_ctx, "%s.%s",
211 W_ERROR_HAVE_NO_MEMORY(r->out.data.string);
215 return WERR_INVALID_PARAM;
218 /* PrintServer Form functions */
219 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
220 struct spoolss_EnumForms *r)
222 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
223 struct ldb_message **msgs;
226 union spoolss_FormInfo *info;
228 count = sptr_db_search(sptr_db, mem_ctx,
229 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
230 &msgs, NULL, "(&(objectClass=form))");
232 if (count == 0) return WERR_OK;
233 if (count < 0) return WERR_GENERAL_FAILURE;
235 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
236 W_ERROR_HAVE_NO_MEMORY(info);
238 switch (r->in.level) {
240 for (i=0; i < count; i++) {
241 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
243 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
244 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
246 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
247 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
249 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
250 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
251 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
252 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
256 return WERR_UNKNOWN_LEVEL;
260 r->out.count = count;
264 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
265 struct spoolss_AddForm *r)
267 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
268 struct ldb_message *msg,**msgs;
269 const char * const attrs[] = {"flags", NULL };
272 /* TODO: do checks access here
273 * if (!(server->access_mask & desired_access)) {
274 * return WERR_FOOBAR;
278 switch (r->in.level) {
280 if (!r->in.info.info1) {
283 count = sptr_db_search(sptr_db, mem_ctx,
284 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
285 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
286 r->in.info.info1->form_name);
288 if (count == 1) return WERR_FOOBAR;
289 if (count > 1) return WERR_FOOBAR;
290 if (count < 0) return WERR_GENERAL_FAILURE;
292 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
296 msg = ldb_msg_new(mem_ctx);
297 W_ERROR_HAVE_NO_MEMORY(msg);
299 /* add core elements to the ldb_message for the Form */
300 msg->dn = ldb_dn_new_fmt(msg, sptr_db, "form-name=%s,CN=Forms,CN=PrintServer", r->in.info.info1->form_name);
301 SET_STRING(sptr_db, msg, "objectClass", "form");
303 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
305 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
307 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
308 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
310 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
311 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
312 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
313 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
316 return WERR_UNKNOWN_LEVEL;
319 ret = samdb_add(sptr_db, mem_ctx, msg);
327 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
328 struct spoolss_SetForm *r)
330 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
331 struct ldb_message *msg,**msgs;
332 const char * const attrs[] = { "flags", NULL};
334 enum spoolss_FormFlags flags;
336 /* TODO: do checks access here
337 * if (!(server->access_mask & desired_access)) {
338 * return WERR_FOOBAR;
342 switch (r->in.level) {
344 if (!r->in.info.info1) {
348 count = sptr_db_search(sptr_db, mem_ctx,
349 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
350 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
351 r->in.info.info1->form_name);
353 if (count == 0) return WERR_FOOBAR;
354 if (count > 1) return WERR_FOOBAR;
355 if (count < 0) return WERR_GENERAL_FAILURE;
357 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
358 if (flags != SPOOLSS_FORM_USER) {
362 msg = ldb_msg_new(mem_ctx);
363 W_ERROR_HAVE_NO_MEMORY(msg);
365 /* add core elements to the ldb_message for the user */
366 msg->dn = msgs[0]->dn;
368 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
370 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
372 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
373 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
375 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
376 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
377 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
378 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
381 return WERR_UNKNOWN_LEVEL;
384 ret = samdb_replace(sptr_db, mem_ctx, msg);
392 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
393 struct spoolss_DeleteForm *r)
395 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
396 struct ldb_message **msgs;
397 const char * const attrs[] = { "flags", NULL};
399 enum spoolss_FormFlags flags;
401 /* TODO: do checks access here
402 * if (!(server->access_mask & desired_access)) {
403 * return WERR_FOOBAR;
407 if (!r->in.form_name) {
411 count = sptr_db_search(sptr_db, mem_ctx,
412 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
413 &msgs, attrs, "(&(form-name=%s)(objectclass=form))",
416 if (count == 0) return WERR_FOOBAR;
417 if (count > 1) return WERR_FOOBAR;
418 if (count < 0) return WERR_GENERAL_FAILURE;
420 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
421 if (flags != SPOOLSS_FORM_USER) {
425 ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
433 /* PrintServer Driver functions */
434 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
435 struct spoolss_EnumPrinterDrivers *r)
440 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
441 struct spoolss_GetPrinterDriverDirectory *r)
443 union spoolss_DriverDirectoryInfo *info;
448 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
449 * are ignoring the r->in.level completely, so we do :-)
453 * TODO: check the server name is ours
454 * - if it's a invalid UNC then return WERR_INVALID_NAME
455 * - if it's the wrong host name return WERR_INVALID_PARAM
456 * - if it's "" then we need to return a local WINDOWS path
458 if (!r->in.server || !r->in.server[0]) {
459 prefix = "C:\\DRIVERS";
461 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
462 W_ERROR_HAVE_NO_MEMORY(prefix);
465 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
468 return WERR_INVALID_ENVIRONMENT;
471 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
472 W_ERROR_HAVE_NO_MEMORY(info);
474 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
475 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
481 /* Printer functions */
482 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
483 struct spoolss_EnumPrinters *r)
485 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
486 struct ldb_message **msgs;
489 union spoolss_PrinterInfo *info;
491 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
492 "(&(objectclass=printer))");
494 if (count == 0) return WERR_OK;
495 if (count < 0) return WERR_GENERAL_FAILURE;
497 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
498 W_ERROR_HAVE_NO_MEMORY(info);
500 switch(r->in.level) {
502 for (i = 0; i < count; i++) {
503 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
505 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
506 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
508 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
509 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
511 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
515 for (i = 0; i < count; i++) {
516 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
517 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
519 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
520 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
522 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
523 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
525 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
526 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
528 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
529 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
531 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
533 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
535 info[i].info2.devmode = NULL;
537 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
539 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
540 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
542 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
543 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
545 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
547 info[i].info2.secdesc = NULL;
549 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
550 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
551 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
552 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
553 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
554 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
555 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
556 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
560 for (i = 0; i < count; i++) {
561 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
562 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
564 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
565 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
567 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
571 for (i = 0; i < count; i++) {
572 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
573 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
575 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
576 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
578 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
579 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
580 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
584 return WERR_UNKNOWN_LEVEL;
588 r->out.count = count;
592 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
593 struct spoolss_OpenPrinterEx *r,
594 const char *printer_name,
595 struct ntptr_GenericHandle **printer)
597 return WERR_INVALID_PRINTER_NAME;
601 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
602 struct spoolss_EnumPorts *r)
604 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
605 struct ldb_message **msgs;
608 union spoolss_PortInfo *info;
610 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
611 "(&(objectclass=port))");
613 if (count == 0) return WERR_OK;
614 if (count < 0) return WERR_GENERAL_FAILURE;
616 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
617 W_ERROR_HAVE_NO_MEMORY(info);
619 switch (r->in.level) {
621 for (i = 0; i < count; i++) {
622 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
623 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
627 for (i=0; i < count; i++) {
628 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
629 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
631 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
632 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
634 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
635 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
637 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
638 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
642 return WERR_UNKNOWN_LEVEL;
646 r->out.count = count;
650 /* monitor functions */
651 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
652 struct spoolss_EnumMonitors *r)
654 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
655 struct ldb_message **msgs;
658 union spoolss_MonitorInfo *info;
660 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
661 "(&(objectclass=monitor))");
663 if (count == 0) return WERR_OK;
664 if (count < 0) return WERR_GENERAL_FAILURE;
666 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
667 W_ERROR_HAVE_NO_MEMORY(info);
669 switch (r->in.level) {
671 for (i = 0; i < count; i++) {
672 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
673 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
677 for (i=0; i < count; i++) {
678 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
679 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
681 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
682 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
684 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
685 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
689 return WERR_UNKNOWN_LEVEL;
693 r->out.count = count;
698 /* Printer Form functions */
699 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
700 struct spoolss_GetForm *r)
702 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
703 struct ldb_message **msgs;
704 struct ldb_dn *base_dn;
706 union spoolss_FormInfo *info;
708 /* TODO: do checks access here
709 * if (!(printer->access_mask & desired_access)) {
710 * return WERR_FOOBAR;
714 base_dn = ldb_dn_new_fmt(mem_ctx, sptr_db, "CN=Forms,CN=%s,CN=Printers", printer->object_name);
715 W_ERROR_HAVE_NO_MEMORY(base_dn);
717 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
718 "(&(form-name=%s)(objectClass=form))",
721 if (count == 0) return WERR_FOOBAR;
722 if (count > 1) return WERR_FOOBAR;
723 if (count < 0) return WERR_GENERAL_FAILURE;
725 info = talloc(mem_ctx, union spoolss_FormInfo);
726 W_ERROR_HAVE_NO_MEMORY(info);
728 switch (r->in.level) {
730 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
732 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
733 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
735 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
736 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
738 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
739 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
740 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
741 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
744 return WERR_UNKNOWN_LEVEL;
753 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
755 static const struct ntptr_ops ntptr_simple_ldb_ops = {
756 .name = "simple_ldb",
757 .init_context = sptr_init_context,
759 /* PrintServer functions */
760 .OpenPrintServer = sptr_OpenPrintServer,
761 /* .XcvDataPrintServer = sptr_XcvDataPrintServer,
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,
784 .XcvDataPort = sptr_XcvDataPort,
786 /* Monitor functions */
787 .EnumMonitors = sptr_EnumMonitors,
788 /* .OpenMonitor = sptr_OpenMonitor,
789 .XcvDataMonitor = sptr_XcvDataMonitor,
791 /* PrintProcessor functions */
792 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
794 /* Printer functions */
795 .EnumPrinters = sptr_EnumPrinters,
796 .OpenPrinter = sptr_OpenPrinter,
797 /* .AddPrinter = sptr_AddPrinter,
798 .GetPrinter = sptr_GetPrinter,
799 .SetPrinter = sptr_SetPrinter,
800 .DeletePrinter = sptr_DeletePrinter,
801 .XcvDataPrinter = sptr_XcvDataPrinter,
803 /* Printer Driver functions */
804 /* .GetPrinterDriver = sptr_GetPrinterDriver,
806 /* Printer PrinterData functions */
807 /* .EnumPrinterData = sptr_EnumPrinterData,
808 .GetPrinterData = sptr_GetPrinterData,
809 .SetPrinterData = sptr_SetPrinterData,
810 .DeletePrinterData = sptr_DeletePrinterData,
812 /* Printer Form functions */
813 /* .EnumPrinterForms = sptr_EnumPrinterForms,
814 .AddPrinterForm = sptr_AddPrinterForm,
815 */ .GetPrinterForm = sptr_GetPrinterForm,
816 /* .SetPrinterForm = sptr_SetPrinterForm,
817 .DeletePrinterForm = sptr_DeletePrinterForm,
819 /* Printer Job functions */
820 /* .EnumJobs = sptr_EnumJobs,
821 .AddJob = sptr_AddJob,
822 .ScheduleJob = sptr_ScheduleJob,
823 .GetJob = sptr_GetJob,
824 .SetJob = sptr_SetJob,
826 /* Printer Printing functions */
827 /* .StartDocPrinter = sptr_StartDocPrinter,
828 .EndDocPrinter = sptr_EndDocPrinter,
829 .StartPagePrinter = sptr_StartPagePrinter,
830 .EndPagePrinter = sptr_EndPagePrinter,
831 .WritePrinter = sptr_WritePrinter,
832 .ReadPrinter = sptr_ReadPrinter,
835 NTSTATUS ntptr_simple_ldb_init(void)
839 ret = ntptr_register(&ntptr_simple_ldb_ops);
840 if (!NT_STATUS_IS_OK(ret)) {
841 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
842 ntptr_simple_ldb_ops.name));