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"
38 connect to the SPOOLSS database
39 return a ldb_context pointer on success, or NULL on failure
41 static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx)
43 return ldb_wrap_connect(mem_ctx, lp_spoolss_url(), 0, NULL);
46 static int sptr_db_search(struct ldb_context *ldb,
49 struct ldb_message ***res,
50 const char * const *attrs,
51 const char *format, ...) PRINTF_ATTRIBUTE(6,7);
53 static int sptr_db_search(struct ldb_context *ldb,
56 struct ldb_message ***res,
57 const char * const *attrs,
58 const char *format, ...)
64 count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
70 #define SET_STRING(ldb, mod, attr, value) do { \
71 if (value == NULL) return WERR_INVALID_PARAM; \
72 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
77 #define SET_UINT(ldb, mod, attr, value) do { \
78 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
83 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
85 struct ldb_context *sptr_db = sptr_db_connect(ntptr);
86 NT_STATUS_HAVE_NO_MEMORY(sptr_db);
88 ntptr->private_data = sptr_db;
93 /* PrintServer functions */
94 static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
95 struct spoolss_OpenPrinterEx *r,
96 const char *server_name,
97 struct ntptr_GenericHandle **_server)
99 struct ntptr_GenericHandle *server;
101 /* TODO: do access check here! */
103 server = talloc(mem_ctx, struct ntptr_GenericHandle);
104 W_ERROR_HAVE_NO_MEMORY(server);
106 server->type = NTPTR_HANDLE_SERVER;
107 server->ntptr = ntptr;
108 server->object_name = talloc_strdup(server, server_name);
109 W_ERROR_HAVE_NO_MEMORY(server->object_name);
110 server->access_mask = 0;
111 server->private_data = NULL;
118 * PrintServer PrinterData functions
120 static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
121 struct spoolss_GetPrinterData *r)
123 if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
124 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
125 r->out.data.value = 0;
127 } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
128 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
129 r->out.data.value = 0;
131 } else if (strcmp("EventLog", r->in.value_name) == 0) {
132 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
133 r->out.data.value = 0;
135 } else if (strcmp("NetPopup", r->in.value_name) == 0) {
136 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
137 r->out.data.value = 0;
139 } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
140 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
141 r->out.data.value = 0;
143 } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
144 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
145 r->out.data.value = 3;
147 } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
148 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
149 r->out.data.value = 0;
151 } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
152 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
153 r->out.data.string = "C:\\PRINTERS";
155 } else if (strcmp("Architecture", r->in.value_name) == 0) {
156 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
157 r->out.data.string = SPOOLSS_ARCHITECTURE_NT_X86;
159 } else if (strcmp("DsPresent", r->in.value_name) == 0) {
160 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_UINT32;
161 r->out.data.value = 1;
163 } else if (strcmp("OSVersion", r->in.value_name) == 0) {
166 struct spoolss_OSVersion os;
168 os.major = dcesrv_common_get_version_major(mem_ctx, NULL);
169 os.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
170 os.build = dcesrv_common_get_version_build(mem_ctx, NULL);
171 os.extra_string = "";
173 status = ndr_push_struct_blob(&blob, mem_ctx, &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
174 if (!NT_STATUS_IS_OK(status)) {
175 return WERR_GENERAL_FAILURE;
178 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
179 r->out.data.binary = blob;
181 } else if (strcmp("OSVersionEx", r->in.value_name) == 0) {
184 struct spoolss_OSVersionEx os_ex;
186 os_ex.major = dcesrv_common_get_version_major(mem_ctx, NULL);
187 os_ex.minor = dcesrv_common_get_version_minor(mem_ctx, NULL);
188 os_ex.build = dcesrv_common_get_version_build(mem_ctx, NULL);
189 os_ex.extra_string = "";
193 status = ndr_push_struct_blob(&blob, mem_ctx, &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
194 if (!NT_STATUS_IS_OK(status)) {
195 return WERR_GENERAL_FAILURE;
198 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_BINARY;
199 r->out.data.binary = blob;
201 } else if (strcmp("DNSMachineName", r->in.value_name) == 0) {
202 if (!lp_realm()) return WERR_INVALID_PARAM;
204 r->out.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
205 r->out.data.string = talloc_asprintf(mem_ctx, "%s.%s",
208 W_ERROR_HAVE_NO_MEMORY(r->out.data.string);
212 return WERR_INVALID_PARAM;
215 /* PrintServer Form functions */
216 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
217 struct spoolss_EnumForms *r)
219 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
220 struct ldb_message **msgs;
223 union spoolss_FormInfo *info;
225 count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, NULL,
226 "(&(objectClass=form))");
228 if (count == 0) return WERR_OK;
229 if (count < 0) return WERR_GENERAL_FAILURE;
231 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
232 W_ERROR_HAVE_NO_MEMORY(info);
234 switch (r->in.level) {
236 for (i=0; i < count; i++) {
237 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
239 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
240 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
242 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
243 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
245 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
246 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
247 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
248 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
252 return WERR_UNKNOWN_LEVEL;
256 r->out.count = count;
260 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
261 struct spoolss_AddForm *r)
263 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
264 struct ldb_message *msg,**msgs;
265 const char * const attrs[] = {"flags", NULL };
268 /* TODO: do checks access here
269 * if (!(server->access_mask & desired_access)) {
270 * return WERR_FOOBAR;
274 switch (r->in.level) {
276 if (!r->in.info.info1) {
279 count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
280 "(&(form-name=%s)(objectClass=form))",
281 r->in.info.info1->form_name);
283 if (count == 1) return WERR_FOOBAR;
284 if (count > 1) return WERR_FOOBAR;
285 if (count < 0) return WERR_GENERAL_FAILURE;
287 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
291 msg = ldb_msg_new(mem_ctx);
292 W_ERROR_HAVE_NO_MEMORY(msg);
294 /* add core elements to the ldb_message for the Form */
295 msg->dn = talloc_asprintf(msg, "form-name=%s,CN=Forms,CN=PrintServer",
296 r->in.info.info1->form_name);
297 SET_STRING(sptr_db, msg, "objectClass", "form");
299 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
301 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
303 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
304 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
306 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
307 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
308 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
309 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
312 return WERR_UNKNOWN_LEVEL;
315 ret = samdb_add(sptr_db, mem_ctx, msg);
323 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
324 struct spoolss_SetForm *r)
326 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
327 struct ldb_message *msg,**msgs;
328 const char * const attrs[] = { "flags", NULL};
330 enum spoolss_FormFlags flags;
332 /* TODO: do checks access here
333 * if (!(server->access_mask & desired_access)) {
334 * return WERR_FOOBAR;
338 switch (r->in.level) {
340 if (!r->in.info.info1) {
344 count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
345 "(&(form-name=%s)(objectClass=form))",
346 r->in.info.info1->form_name);
348 if (count == 0) return WERR_FOOBAR;
349 if (count > 1) return WERR_FOOBAR;
350 if (count < 0) return WERR_GENERAL_FAILURE;
352 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
353 if (flags != SPOOLSS_FORM_USER) {
357 msg = ldb_msg_new(mem_ctx);
358 W_ERROR_HAVE_NO_MEMORY(msg);
360 /* add core elements to the ldb_message for the user */
361 msg->dn = msgs[0]->dn;
363 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
365 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
367 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
368 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
370 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
371 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
372 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
373 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
376 return WERR_UNKNOWN_LEVEL;
379 ret = samdb_replace(sptr_db, mem_ctx, msg);
387 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
388 struct spoolss_DeleteForm *r)
390 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
391 struct ldb_message **msgs;
392 const char * const attrs[] = { "flags", NULL};
394 enum spoolss_FormFlags flags;
396 /* TODO: do checks access here
397 * if (!(server->access_mask & desired_access)) {
398 * return WERR_FOOBAR;
402 if (!r->in.form_name) {
406 count = sptr_db_search(sptr_db, mem_ctx, "CN=Forms,CN=PrintServer", &msgs, attrs,
407 "(&(form-name=%s)(objectclass=form))",
410 if (count == 0) return WERR_FOOBAR;
411 if (count > 1) return WERR_FOOBAR;
412 if (count < 0) return WERR_GENERAL_FAILURE;
414 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
415 if (flags != SPOOLSS_FORM_USER) {
419 ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
427 /* PrintServer Driver functions */
428 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
429 struct spoolss_EnumPrinterDrivers *r)
434 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
435 struct spoolss_GetPrinterDriverDirectory *r)
437 union spoolss_DriverDirectoryInfo *info;
442 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
443 * are ignoring the r->in.level completely, so we do :-)
447 * TODO: check the server name is ours
448 * - if it's a invalid UNC then return WERR_INVALID_NAME
449 * - if it's the wrong host name return WERR_INVALID_PARAM
450 * - if it's "" then we need to return a local WINDOWS path
452 if (!r->in.server || !r->in.server[0]) {
453 prefix = "C:\\DRIVERS";
455 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
456 W_ERROR_HAVE_NO_MEMORY(prefix);
459 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
462 return WERR_INVALID_ENVIRONMENT;
465 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
466 W_ERROR_HAVE_NO_MEMORY(info);
468 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
469 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
475 /* Printer functions */
476 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
477 struct spoolss_EnumPrinters *r)
479 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
480 struct ldb_message **msgs;
483 union spoolss_PrinterInfo *info;
485 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
486 "(&(objectclass=printer))");
488 if (count == 0) return WERR_OK;
489 if (count < 0) return WERR_GENERAL_FAILURE;
491 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
492 W_ERROR_HAVE_NO_MEMORY(info);
494 switch(r->in.level) {
496 for (i = 0; i < count; i++) {
497 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
499 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
500 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
502 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
503 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
505 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
509 for (i = 0; i < count; i++) {
510 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
511 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
513 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
514 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
516 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
517 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
519 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
520 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
522 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
523 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
525 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
527 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
529 info[i].info2.devmode = NULL;
531 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
533 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
534 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
536 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
537 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
539 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
541 info[i].info2.secdesc = NULL;
543 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
544 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
545 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
546 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
547 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
548 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
549 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
550 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
554 for (i = 0; i < count; i++) {
555 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
556 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
558 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
559 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
561 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
565 for (i = 0; i < count; i++) {
566 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
567 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
569 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
570 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
572 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
573 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
574 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
578 return WERR_UNKNOWN_LEVEL;
582 r->out.count = count;
586 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
587 struct spoolss_OpenPrinterEx *r,
588 const char *printer_name,
589 struct ntptr_GenericHandle **printer)
591 return WERR_INVALID_PRINTER_NAME;
595 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
596 struct spoolss_EnumPorts *r)
598 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
599 struct ldb_message **msgs;
602 union spoolss_PortInfo *info;
604 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
605 "(&(objectclass=port))");
607 if (count == 0) return WERR_OK;
608 if (count < 0) return WERR_GENERAL_FAILURE;
610 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
611 W_ERROR_HAVE_NO_MEMORY(info);
613 switch (r->in.level) {
615 for (i = 0; i < count; i++) {
616 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
617 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
621 for (i=0; i < count; i++) {
622 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
623 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
625 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
626 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
628 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
629 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
631 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
632 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
636 return WERR_UNKNOWN_LEVEL;
640 r->out.count = count;
644 /* monitor functions */
645 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
646 struct spoolss_EnumMonitors *r)
648 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
649 struct ldb_message **msgs;
652 union spoolss_MonitorInfo *info;
654 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
655 "(&(objectclass=monitor))");
657 if (count == 0) return WERR_OK;
658 if (count < 0) return WERR_GENERAL_FAILURE;
660 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
661 W_ERROR_HAVE_NO_MEMORY(info);
663 switch (r->in.level) {
665 for (i = 0; i < count; i++) {
666 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
667 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
671 for (i=0; i < count; i++) {
672 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
673 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
675 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
676 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
678 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
679 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
683 return WERR_UNKNOWN_LEVEL;
687 r->out.count = count;
692 /* Printer Form functions */
693 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
694 struct spoolss_GetForm *r)
696 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
697 struct ldb_message **msgs;
700 union spoolss_FormInfo *info;
702 /* TODO: do checks access here
703 * if (!(printer->access_mask & desired_access)) {
704 * return WERR_FOOBAR;
708 base_dn = talloc_asprintf(mem_ctx, "CN=Forms,CN=%s,CN=Printers", printer->object_name);
709 W_ERROR_HAVE_NO_MEMORY(base_dn);
711 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
712 "(&(form-name=%s)(objectClass=form))",
715 if (count == 0) return WERR_FOOBAR;
716 if (count > 1) return WERR_FOOBAR;
717 if (count < 0) return WERR_GENERAL_FAILURE;
719 info = talloc(mem_ctx, union spoolss_FormInfo);
720 W_ERROR_HAVE_NO_MEMORY(info);
722 switch (r->in.level) {
724 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
726 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
727 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
729 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
730 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
732 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
733 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
734 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
735 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
738 return WERR_UNKNOWN_LEVEL;
747 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
749 static const struct ntptr_ops ntptr_simple_ldb_ops = {
750 .name = "simple_ldb",
751 .init_context = sptr_init_context,
753 /* PrintServer functions */
754 .OpenPrintServer = sptr_OpenPrintServer,
756 /* PrintServer PrinterData functions */
757 /* .EnumPrintServerData = sptr_EnumPrintServerData,
758 */ .GetPrintServerData = sptr_GetPrintServerData,
759 /* .SetPrintServerData = sptr_SetPrintServerData,
760 .DeletePrintServerData = sptr_DeletePrintServerData,
762 /* PrintServer Form functions */
763 .EnumPrintServerForms = sptr_EnumPrintServerForms,
764 .AddPrintServerForm = sptr_AddPrintServerForm,
765 .SetPrintServerForm = sptr_SetPrintServerForm,
766 .DeletePrintServerForm = sptr_DeletePrintServerForm,
768 /* PrintServer Driver functions */
769 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
770 /* .AddPrinterDriver = sptr_AddPrinterDriver,
771 .DeletePrinterDriver = sptr_DeletePrinterDriver,
772 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
775 .EnumPorts = sptr_EnumPorts,
776 /* .OpenPort = sptr_OpenPort,
778 /* Monitor functions */
779 .EnumMonitors = sptr_EnumMonitors,
780 /* .OpenMonitor = sptr_OpenMonitor,
782 /* PrintProcessor functions */
783 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
785 /* Printer functions */
786 .EnumPrinters = sptr_EnumPrinters,
787 .OpenPrinter = sptr_OpenPrinter,
788 /* .AddPrinter = sptr_AddPrinter,
789 .GetPrinter = sptr_GetPrinter,
790 .SetPrinter = sptr_SetPrinter,
791 .DeletePrinter = sptr_DeletePrinter,
793 /* Printer Driver functions */
794 /* .GetPrinterDriver = sptr_GetPrinterDriver,
796 /* Printer PrinterData functions */
797 /* .EnumPrinterData = sptr_EnumPrinterData,
798 .GetPrinterData = sptr_GetPrinterData,
799 .SetPrinterData = sptr_SetPrinterData,
800 .DeletePrinterData = sptr_DeletePrinterData,
802 /* Printer Form functions */
803 /* .EnumPrinterForms = sptr_EnumPrinterForms,
804 .AddPrinterForm = sptr_AddPrinterForm,
805 */ .GetPrinterForm = sptr_GetPrinterForm,
806 /* .SetPrinterForm = sptr_SetPrinterForm,
807 .DeletePrinterForm = sptr_DeletePrinterForm,
809 /* Printer Job functions */
810 /* .EnumJobs = sptr_EnumJobs,
811 .AddJob = sptr_AddJob,
812 .ScheduleJob = sptr_ScheduleJob,
813 .GetJob = sptr_GetJob,
814 .SetJob = sptr_SetJob,
816 /* Printer Printing functions */
817 /* .StartDocPrinter = sptr_StartDocPrinter,
818 .EndDocPrinter = sptr_EndDocPrinter,
819 .StartPagePrinter = sptr_StartPagePrinter,
820 .EndPagePrinter = sptr_EndPagePrinter,
821 .WritePrinter = sptr_WritePrinter,
822 .ReadPrinter = sptr_ReadPrinter,
825 NTSTATUS ntptr_simple_ldb_init(void)
829 ret = ntptr_register(&ntptr_simple_ldb_ops);
830 if (!NT_STATUS_IS_OK(ret)) {
831 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
832 ntptr_simple_ldb_ops.name));