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"
38 #include "rpc_server/common/common.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 const 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 const 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_explode(mem_ctx, "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_explode(mem_ctx, "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_build_child(msg,
302 "form-name", r->in.info.info1->form_name,
303 ldb_dn_explode(msg, "CN=Forms,CN=PrintServer"));
304 SET_STRING(sptr_db, msg, "objectClass", "form");
306 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
308 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
310 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
311 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
313 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
314 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
315 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
316 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
319 return WERR_UNKNOWN_LEVEL;
322 ret = samdb_add(sptr_db, mem_ctx, msg);
330 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
331 struct spoolss_SetForm *r)
333 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
334 struct ldb_message *msg,**msgs;
335 const char * const attrs[] = { "flags", NULL};
337 enum spoolss_FormFlags flags;
339 /* TODO: do checks access here
340 * if (!(server->access_mask & desired_access)) {
341 * return WERR_FOOBAR;
345 switch (r->in.level) {
347 if (!r->in.info.info1) {
351 count = sptr_db_search(sptr_db, mem_ctx,
352 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
353 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
354 r->in.info.info1->form_name);
356 if (count == 0) return WERR_FOOBAR;
357 if (count > 1) return WERR_FOOBAR;
358 if (count < 0) return WERR_GENERAL_FAILURE;
360 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
361 if (flags != SPOOLSS_FORM_USER) {
365 msg = ldb_msg_new(mem_ctx);
366 W_ERROR_HAVE_NO_MEMORY(msg);
368 /* add core elements to the ldb_message for the user */
369 msg->dn = msgs[0]->dn;
371 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
373 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
375 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
376 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
378 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
379 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
380 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
381 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
384 return WERR_UNKNOWN_LEVEL;
387 ret = samdb_replace(sptr_db, mem_ctx, msg);
395 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
396 struct spoolss_DeleteForm *r)
398 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
399 struct ldb_message **msgs;
400 const char * const attrs[] = { "flags", NULL};
402 enum spoolss_FormFlags flags;
404 /* TODO: do checks access here
405 * if (!(server->access_mask & desired_access)) {
406 * return WERR_FOOBAR;
410 if (!r->in.form_name) {
414 count = sptr_db_search(sptr_db, mem_ctx,
415 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
416 &msgs, attrs, "(&(form-name=%s)(objectclass=form))",
419 if (count == 0) return WERR_FOOBAR;
420 if (count > 1) return WERR_FOOBAR;
421 if (count < 0) return WERR_GENERAL_FAILURE;
423 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
424 if (flags != SPOOLSS_FORM_USER) {
428 ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
436 /* PrintServer Driver functions */
437 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
438 struct spoolss_EnumPrinterDrivers *r)
443 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
444 struct spoolss_GetPrinterDriverDirectory *r)
446 union spoolss_DriverDirectoryInfo *info;
451 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
452 * are ignoring the r->in.level completely, so we do :-)
456 * TODO: check the server name is ours
457 * - if it's a invalid UNC then return WERR_INVALID_NAME
458 * - if it's the wrong host name return WERR_INVALID_PARAM
459 * - if it's "" then we need to return a local WINDOWS path
461 if (!r->in.server || !r->in.server[0]) {
462 prefix = "C:\\DRIVERS";
464 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
465 W_ERROR_HAVE_NO_MEMORY(prefix);
468 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
471 return WERR_INVALID_ENVIRONMENT;
474 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
475 W_ERROR_HAVE_NO_MEMORY(info);
477 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
478 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
484 /* Printer functions */
485 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
486 struct spoolss_EnumPrinters *r)
488 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
489 struct ldb_message **msgs;
492 union spoolss_PrinterInfo *info;
494 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
495 "(&(objectclass=printer))");
497 if (count == 0) return WERR_OK;
498 if (count < 0) return WERR_GENERAL_FAILURE;
500 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
501 W_ERROR_HAVE_NO_MEMORY(info);
503 switch(r->in.level) {
505 for (i = 0; i < count; i++) {
506 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
508 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
509 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
511 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
512 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
514 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
518 for (i = 0; i < count; i++) {
519 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
520 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
522 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
523 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
525 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
526 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
528 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
529 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
531 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
532 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
534 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
536 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
538 info[i].info2.devmode = NULL;
540 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
542 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
543 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
545 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
546 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
548 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
550 info[i].info2.secdesc = NULL;
552 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
553 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
554 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
555 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
556 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
557 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
558 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
559 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
563 for (i = 0; i < count; i++) {
564 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
565 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
567 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
568 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
570 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
574 for (i = 0; i < count; i++) {
575 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
576 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
578 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
579 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
581 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
582 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
583 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
587 return WERR_UNKNOWN_LEVEL;
591 r->out.count = count;
595 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
596 struct spoolss_OpenPrinterEx *r,
597 const char *printer_name,
598 struct ntptr_GenericHandle **printer)
600 return WERR_INVALID_PRINTER_NAME;
604 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
605 struct spoolss_EnumPorts *r)
607 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
608 struct ldb_message **msgs;
611 union spoolss_PortInfo *info;
613 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
614 "(&(objectclass=port))");
616 if (count == 0) return WERR_OK;
617 if (count < 0) return WERR_GENERAL_FAILURE;
619 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
620 W_ERROR_HAVE_NO_MEMORY(info);
622 switch (r->in.level) {
624 for (i = 0; i < count; i++) {
625 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
626 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
630 for (i=0; i < count; i++) {
631 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
632 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
634 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
635 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
637 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
638 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
640 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
641 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
645 return WERR_UNKNOWN_LEVEL;
649 r->out.count = count;
653 /* monitor functions */
654 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
655 struct spoolss_EnumMonitors *r)
657 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
658 struct ldb_message **msgs;
661 union spoolss_MonitorInfo *info;
663 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
664 "(&(objectclass=monitor))");
666 if (count == 0) return WERR_OK;
667 if (count < 0) return WERR_GENERAL_FAILURE;
669 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
670 W_ERROR_HAVE_NO_MEMORY(info);
672 switch (r->in.level) {
674 for (i = 0; i < count; i++) {
675 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
676 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
680 for (i=0; i < count; i++) {
681 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
682 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
684 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
685 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
687 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
688 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
692 return WERR_UNKNOWN_LEVEL;
696 r->out.count = count;
701 /* Printer Form functions */
702 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
703 struct spoolss_GetForm *r)
705 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
706 struct ldb_message **msgs;
707 const struct ldb_dn *base_dn;
709 union spoolss_FormInfo *info;
711 /* TODO: do checks access here
712 * if (!(printer->access_mask & desired_access)) {
713 * return WERR_FOOBAR;
717 base_dn = ldb_dn_string_compose(mem_ctx, NULL, "CN=Forms, CN=%s, CN=Printers", printer->object_name);
718 W_ERROR_HAVE_NO_MEMORY(base_dn);
720 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
721 "(&(form-name=%s)(objectClass=form))",
724 if (count == 0) return WERR_FOOBAR;
725 if (count > 1) return WERR_FOOBAR;
726 if (count < 0) return WERR_GENERAL_FAILURE;
728 info = talloc(mem_ctx, union spoolss_FormInfo);
729 W_ERROR_HAVE_NO_MEMORY(info);
731 switch (r->in.level) {
733 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
735 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
736 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
738 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
739 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
741 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
742 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
743 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
744 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
747 return WERR_UNKNOWN_LEVEL;
756 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
758 static const struct ntptr_ops ntptr_simple_ldb_ops = {
759 .name = "simple_ldb",
760 .init_context = sptr_init_context,
762 /* PrintServer functions */
763 .OpenPrintServer = sptr_OpenPrintServer,
765 /* PrintServer PrinterData functions */
766 /* .EnumPrintServerData = sptr_EnumPrintServerData,
767 */ .GetPrintServerData = sptr_GetPrintServerData,
768 /* .SetPrintServerData = sptr_SetPrintServerData,
769 .DeletePrintServerData = sptr_DeletePrintServerData,
771 /* PrintServer Form functions */
772 .EnumPrintServerForms = sptr_EnumPrintServerForms,
773 .AddPrintServerForm = sptr_AddPrintServerForm,
774 .SetPrintServerForm = sptr_SetPrintServerForm,
775 .DeletePrintServerForm = sptr_DeletePrintServerForm,
777 /* PrintServer Driver functions */
778 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
779 /* .AddPrinterDriver = sptr_AddPrinterDriver,
780 .DeletePrinterDriver = sptr_DeletePrinterDriver,
781 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
784 .EnumPorts = sptr_EnumPorts,
785 /* .OpenPort = sptr_OpenPort,
787 /* Monitor functions */
788 .EnumMonitors = sptr_EnumMonitors,
789 /* .OpenMonitor = sptr_OpenMonitor,
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,
802 /* Printer Driver functions */
803 /* .GetPrinterDriver = sptr_GetPrinterDriver,
805 /* Printer PrinterData functions */
806 /* .EnumPrinterData = sptr_EnumPrinterData,
807 .GetPrinterData = sptr_GetPrinterData,
808 .SetPrinterData = sptr_SetPrinterData,
809 .DeletePrinterData = sptr_DeletePrinterData,
811 /* Printer Form functions */
812 /* .EnumPrinterForms = sptr_EnumPrinterForms,
813 .AddPrinterForm = sptr_AddPrinterForm,
814 */ .GetPrinterForm = sptr_GetPrinterForm,
815 /* .SetPrinterForm = sptr_SetPrinterForm,
816 .DeletePrinterForm = sptr_DeletePrinterForm,
818 /* Printer Job functions */
819 /* .EnumJobs = sptr_EnumJobs,
820 .AddJob = sptr_AddJob,
821 .ScheduleJob = sptr_ScheduleJob,
822 .GetJob = sptr_GetJob,
823 .SetJob = sptr_SetJob,
825 /* Printer Printing functions */
826 /* .StartDocPrinter = sptr_StartDocPrinter,
827 .EndDocPrinter = sptr_EndDocPrinter,
828 .StartPagePrinter = sptr_StartPagePrinter,
829 .EndPagePrinter = sptr_EndPagePrinter,
830 .WritePrinter = sptr_WritePrinter,
831 .ReadPrinter = sptr_ReadPrinter,
834 NTSTATUS ntptr_simple_ldb_init(void)
838 ret = ntptr_register(&ntptr_simple_ldb_ops);
839 if (!NT_STATUS_IS_OK(ret)) {
840 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
841 ntptr_simple_ldb_ops.name));