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,
48 const struct ldb_dn *basedn,
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,
55 const struct ldb_dn *basedn,
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,
226 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
227 &msgs, NULL, "(&(objectClass=form))");
229 if (count == 0) return WERR_OK;
230 if (count < 0) return WERR_GENERAL_FAILURE;
232 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
233 W_ERROR_HAVE_NO_MEMORY(info);
235 switch (r->in.level) {
237 for (i=0; i < count; i++) {
238 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
240 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
241 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
243 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
244 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
246 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
247 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
248 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
249 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
253 return WERR_UNKNOWN_LEVEL;
257 r->out.count = count;
261 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
262 struct spoolss_AddForm *r)
264 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
265 struct ldb_message *msg,**msgs;
266 const char * const attrs[] = {"flags", NULL };
269 /* TODO: do checks access here
270 * if (!(server->access_mask & desired_access)) {
271 * return WERR_FOOBAR;
275 switch (r->in.level) {
277 if (!r->in.info.info1) {
280 count = sptr_db_search(sptr_db, mem_ctx,
281 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
282 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
283 r->in.info.info1->form_name);
285 if (count == 1) return WERR_FOOBAR;
286 if (count > 1) return WERR_FOOBAR;
287 if (count < 0) return WERR_GENERAL_FAILURE;
289 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
293 msg = ldb_msg_new(mem_ctx);
294 W_ERROR_HAVE_NO_MEMORY(msg);
296 /* add core elements to the ldb_message for the Form */
297 msg->dn = ldb_dn_build_child(msg,
298 "form-name", r->in.info.info1->form_name,
299 ldb_dn_explode(msg, "CN=Forms,CN=PrintServer"));
300 SET_STRING(sptr_db, msg, "objectClass", "form");
302 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
304 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
306 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
307 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
309 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
310 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
311 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
312 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
315 return WERR_UNKNOWN_LEVEL;
318 ret = samdb_add(sptr_db, mem_ctx, msg);
326 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
327 struct spoolss_SetForm *r)
329 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
330 struct ldb_message *msg,**msgs;
331 const char * const attrs[] = { "flags", NULL};
333 enum spoolss_FormFlags flags;
335 /* TODO: do checks access here
336 * if (!(server->access_mask & desired_access)) {
337 * return WERR_FOOBAR;
341 switch (r->in.level) {
343 if (!r->in.info.info1) {
347 count = sptr_db_search(sptr_db, mem_ctx,
348 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
349 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
350 r->in.info.info1->form_name);
352 if (count == 0) return WERR_FOOBAR;
353 if (count > 1) return WERR_FOOBAR;
354 if (count < 0) return WERR_GENERAL_FAILURE;
356 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
357 if (flags != SPOOLSS_FORM_USER) {
361 msg = ldb_msg_new(mem_ctx);
362 W_ERROR_HAVE_NO_MEMORY(msg);
364 /* add core elements to the ldb_message for the user */
365 msg->dn = msgs[0]->dn;
367 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
369 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
371 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
372 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
374 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
375 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
376 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
377 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
380 return WERR_UNKNOWN_LEVEL;
383 ret = samdb_replace(sptr_db, mem_ctx, msg);
391 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
392 struct spoolss_DeleteForm *r)
394 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
395 struct ldb_message **msgs;
396 const char * const attrs[] = { "flags", NULL};
398 enum spoolss_FormFlags flags;
400 /* TODO: do checks access here
401 * if (!(server->access_mask & desired_access)) {
402 * return WERR_FOOBAR;
406 if (!r->in.form_name) {
410 count = sptr_db_search(sptr_db, mem_ctx,
411 ldb_dn_explode(mem_ctx, "CN=Forms,CN=PrintServer"),
412 &msgs, attrs, "(&(form-name=%s)(objectclass=form))",
415 if (count == 0) return WERR_FOOBAR;
416 if (count > 1) return WERR_FOOBAR;
417 if (count < 0) return WERR_GENERAL_FAILURE;
419 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
420 if (flags != SPOOLSS_FORM_USER) {
424 ret = samdb_delete(sptr_db, mem_ctx, msgs[0]->dn);
432 /* PrintServer Driver functions */
433 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
434 struct spoolss_EnumPrinterDrivers *r)
439 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
440 struct spoolss_GetPrinterDriverDirectory *r)
442 union spoolss_DriverDirectoryInfo *info;
447 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
448 * are ignoring the r->in.level completely, so we do :-)
452 * TODO: check the server name is ours
453 * - if it's a invalid UNC then return WERR_INVALID_NAME
454 * - if it's the wrong host name return WERR_INVALID_PARAM
455 * - if it's "" then we need to return a local WINDOWS path
457 if (!r->in.server || !r->in.server[0]) {
458 prefix = "C:\\DRIVERS";
460 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
461 W_ERROR_HAVE_NO_MEMORY(prefix);
464 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
467 return WERR_INVALID_ENVIRONMENT;
470 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
471 W_ERROR_HAVE_NO_MEMORY(info);
473 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
474 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
480 /* Printer functions */
481 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
482 struct spoolss_EnumPrinters *r)
484 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
485 struct ldb_message **msgs;
488 union spoolss_PrinterInfo *info;
490 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
491 "(&(objectclass=printer))");
493 if (count == 0) return WERR_OK;
494 if (count < 0) return WERR_GENERAL_FAILURE;
496 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
497 W_ERROR_HAVE_NO_MEMORY(info);
499 switch(r->in.level) {
501 for (i = 0; i < count; i++) {
502 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
504 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
505 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
507 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
508 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
510 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
514 for (i = 0; i < count; i++) {
515 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
516 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
518 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
519 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
521 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
522 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
524 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
525 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
527 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
528 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
530 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
532 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
534 info[i].info2.devmode = NULL;
536 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
538 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
539 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
541 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
542 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
544 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
546 info[i].info2.secdesc = NULL;
548 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
549 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
550 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
551 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
552 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
553 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
554 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
555 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
559 for (i = 0; i < count; i++) {
560 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
561 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
563 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
564 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
566 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
570 for (i = 0; i < count; i++) {
571 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
572 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
574 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
575 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
577 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
578 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
579 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
583 return WERR_UNKNOWN_LEVEL;
587 r->out.count = count;
591 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
592 struct spoolss_OpenPrinterEx *r,
593 const char *printer_name,
594 struct ntptr_GenericHandle **printer)
596 return WERR_INVALID_PRINTER_NAME;
600 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
601 struct spoolss_EnumPorts *r)
603 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
604 struct ldb_message **msgs;
607 union spoolss_PortInfo *info;
609 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
610 "(&(objectclass=port))");
612 if (count == 0) return WERR_OK;
613 if (count < 0) return WERR_GENERAL_FAILURE;
615 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
616 W_ERROR_HAVE_NO_MEMORY(info);
618 switch (r->in.level) {
620 for (i = 0; i < count; i++) {
621 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
622 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
626 for (i=0; i < count; i++) {
627 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
628 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
630 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
631 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
633 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
634 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
636 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
637 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
641 return WERR_UNKNOWN_LEVEL;
645 r->out.count = count;
649 /* monitor functions */
650 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
651 struct spoolss_EnumMonitors *r)
653 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
654 struct ldb_message **msgs;
657 union spoolss_MonitorInfo *info;
659 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
660 "(&(objectclass=monitor))");
662 if (count == 0) return WERR_OK;
663 if (count < 0) return WERR_GENERAL_FAILURE;
665 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
666 W_ERROR_HAVE_NO_MEMORY(info);
668 switch (r->in.level) {
670 for (i = 0; i < count; i++) {
671 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
672 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
676 for (i=0; i < count; i++) {
677 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
678 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
680 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
681 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
683 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
684 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
688 return WERR_UNKNOWN_LEVEL;
692 r->out.count = count;
697 /* Printer Form functions */
698 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
699 struct spoolss_GetForm *r)
701 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
702 struct ldb_message **msgs;
703 const struct ldb_dn *base_dn;
705 union spoolss_FormInfo *info;
707 /* TODO: do checks access here
708 * if (!(printer->access_mask & desired_access)) {
709 * return WERR_FOOBAR;
713 base_dn = ldb_dn_string_compose(mem_ctx, NULL, "CN=Forms, CN=%s, CN=Printers", printer->object_name);
714 W_ERROR_HAVE_NO_MEMORY(base_dn);
716 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
717 "(&(form-name=%s)(objectClass=form))",
720 if (count == 0) return WERR_FOOBAR;
721 if (count > 1) return WERR_FOOBAR;
722 if (count < 0) return WERR_GENERAL_FAILURE;
724 info = talloc(mem_ctx, union spoolss_FormInfo);
725 W_ERROR_HAVE_NO_MEMORY(info);
727 switch (r->in.level) {
729 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
731 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
732 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
734 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
735 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
737 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
738 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
739 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
740 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
743 return WERR_UNKNOWN_LEVEL;
752 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
754 static const struct ntptr_ops ntptr_simple_ldb_ops = {
755 .name = "simple_ldb",
756 .init_context = sptr_init_context,
758 /* PrintServer functions */
759 .OpenPrintServer = sptr_OpenPrintServer,
761 /* PrintServer PrinterData functions */
762 /* .EnumPrintServerData = sptr_EnumPrintServerData,
763 */ .GetPrintServerData = sptr_GetPrintServerData,
764 /* .SetPrintServerData = sptr_SetPrintServerData,
765 .DeletePrintServerData = sptr_DeletePrintServerData,
767 /* PrintServer Form functions */
768 .EnumPrintServerForms = sptr_EnumPrintServerForms,
769 .AddPrintServerForm = sptr_AddPrintServerForm,
770 .SetPrintServerForm = sptr_SetPrintServerForm,
771 .DeletePrintServerForm = sptr_DeletePrintServerForm,
773 /* PrintServer Driver functions */
774 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
775 /* .AddPrinterDriver = sptr_AddPrinterDriver,
776 .DeletePrinterDriver = sptr_DeletePrinterDriver,
777 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
780 .EnumPorts = sptr_EnumPorts,
781 /* .OpenPort = sptr_OpenPort,
783 /* Monitor functions */
784 .EnumMonitors = sptr_EnumMonitors,
785 /* .OpenMonitor = sptr_OpenMonitor,
787 /* PrintProcessor functions */
788 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
790 /* Printer functions */
791 .EnumPrinters = sptr_EnumPrinters,
792 .OpenPrinter = sptr_OpenPrinter,
793 /* .AddPrinter = sptr_AddPrinter,
794 .GetPrinter = sptr_GetPrinter,
795 .SetPrinter = sptr_SetPrinter,
796 .DeletePrinter = sptr_DeletePrinter,
798 /* Printer Driver functions */
799 /* .GetPrinterDriver = sptr_GetPrinterDriver,
801 /* Printer PrinterData functions */
802 /* .EnumPrinterData = sptr_EnumPrinterData,
803 .GetPrinterData = sptr_GetPrinterData,
804 .SetPrinterData = sptr_SetPrinterData,
805 .DeletePrinterData = sptr_DeletePrinterData,
807 /* Printer Form functions */
808 /* .EnumPrinterForms = sptr_EnumPrinterForms,
809 .AddPrinterForm = sptr_AddPrinterForm,
810 */ .GetPrinterForm = sptr_GetPrinterForm,
811 /* .SetPrinterForm = sptr_SetPrinterForm,
812 .DeletePrinterForm = sptr_DeletePrinterForm,
814 /* Printer Job functions */
815 /* .EnumJobs = sptr_EnumJobs,
816 .AddJob = sptr_AddJob,
817 .ScheduleJob = sptr_ScheduleJob,
818 .GetJob = sptr_GetJob,
819 .SetJob = sptr_SetJob,
821 /* Printer Printing functions */
822 /* .StartDocPrinter = sptr_StartDocPrinter,
823 .EndDocPrinter = sptr_EndDocPrinter,
824 .StartPagePrinter = sptr_StartPagePrinter,
825 .EndPagePrinter = sptr_EndPagePrinter,
826 .WritePrinter = sptr_WritePrinter,
827 .ReadPrinter = sptr_ReadPrinter,
830 NTSTATUS ntptr_simple_ldb_init(void)
834 ret = ntptr_register(&ntptr_simple_ldb_ops);
835 if (!NT_STATUS_IS_OK(ret)) {
836 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
837 ntptr_simple_ldb_ops.name));