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 "../lib/util/util_ldb.h"
38 #include "rpc_server/common/common.h"
39 #include "param/param.h"
42 connect to the SPOOLSS database
43 return a ldb_context pointer on success, or NULL on failure
45 static struct ldb_context *sptr_db_connect(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, struct loadparm_context *lp_ctx)
47 return ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, lp_spoolss_url(lp_ctx), system_session(lp_ctx),
51 static int sptr_db_search(struct ldb_context *ldb,
53 struct ldb_dn *basedn,
54 struct ldb_message ***res,
55 const char * const *attrs,
56 const char *format, ...) PRINTF_ATTRIBUTE(6,7);
58 static int sptr_db_search(struct ldb_context *ldb,
60 struct ldb_dn *basedn,
61 struct ldb_message ***res,
62 const char * const *attrs,
63 const char *format, ...)
69 count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
75 #define SET_STRING(ldb, mod, attr, value) do { \
76 if (value == NULL) return WERR_INVALID_PARAM; \
77 if (samdb_msg_add_string(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
82 #define SET_UINT(ldb, mod, attr, value) do { \
83 if (samdb_msg_add_uint(ldb, (TALLOC_CTX *)mod, mod, attr, value) != 0) { \
88 static NTSTATUS sptr_init_context(struct ntptr_context *ntptr)
90 struct ldb_context *sptr_db = sptr_db_connect(ntptr, ntptr->ev_ctx, ntptr->lp_ctx);
91 NT_STATUS_HAVE_NO_MEMORY(sptr_db);
93 ntptr->private_data = sptr_db;
98 /* PrintServer functions */
99 static WERROR sptr_OpenPrintServer(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
100 struct spoolss_OpenPrinterEx *r,
101 const char *server_name,
102 struct ntptr_GenericHandle **_server)
104 struct ntptr_GenericHandle *server;
106 /* TODO: do access check here! */
108 server = talloc(mem_ctx, struct ntptr_GenericHandle);
109 W_ERROR_HAVE_NO_MEMORY(server);
111 server->type = NTPTR_HANDLE_SERVER;
112 server->ntptr = ntptr;
113 server->object_name = talloc_strdup(server, server_name);
114 W_ERROR_HAVE_NO_MEMORY(server->object_name);
115 server->access_mask = 0;
116 server->private_data = NULL;
123 * PrintServer PrinterData functions
125 static WERROR sptr_GetPrintServerData(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
126 struct spoolss_GetPrinterData *r)
128 struct dcerpc_server_info *server_info = lp_dcerpc_server_info(mem_ctx, server->ntptr->lp_ctx);
129 if (strcmp("W3SvcInstalled", r->in.value_name) == 0) {
130 *r->out.type = REG_DWORD;
131 r->out.data->value = 0;
133 } else if (strcmp("BeepEnabled", r->in.value_name) == 0) {
134 *r->out.type = REG_DWORD;
135 r->out.data->value = 0;
137 } else if (strcmp("EventLog", r->in.value_name) == 0) {
138 *r->out.type = REG_DWORD;
139 r->out.data->value = 0;
141 } else if (strcmp("NetPopup", r->in.value_name) == 0) {
142 *r->out.type = REG_DWORD;
143 r->out.data->value = 0;
145 } else if (strcmp("NetPopupToComputer", r->in.value_name) == 0) {
146 *r->out.type = REG_DWORD;
147 r->out.data->value = 0;
149 } else if (strcmp("MajorVersion", r->in.value_name) == 0) {
150 *r->out.type = REG_DWORD;
151 r->out.data->value = 3;
153 } else if (strcmp("MinorVersion", r->in.value_name) == 0) {
154 *r->out.type = REG_DWORD;
155 r->out.data->value = 0;
157 } else if (strcmp("DefaultSpoolDirectory", r->in.value_name) == 0) {
158 *r->out.type = REG_SZ;
159 r->out.data->string = "C:\\PRINTERS";
161 } else if (strcmp("Architecture", r->in.value_name) == 0) {
162 *r->out.type = REG_SZ;
163 r->out.data->string = SPOOLSS_ARCHITECTURE_NT_X86;
165 } else if (strcmp("DsPresent", r->in.value_name) == 0) {
166 *r->out.type = REG_DWORD;
167 r->out.data->value = 1;
169 } else if (strcmp("OSVersion", r->in.value_name) == 0) {
171 enum ndr_err_code ndr_err;
172 struct spoolss_OSVersion os;
174 os.major = server_info->version_major;
175 os.minor = server_info->version_minor;
176 os.build = server_info->version_build;
177 os.extra_string = "";
179 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, lp_iconv_convenience(server->ntptr->lp_ctx), &os, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
180 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
181 return WERR_GENERAL_FAILURE;
184 *r->out.type = REG_BINARY;
185 r->out.data->binary = blob;
187 } else if (strcmp("OSVersionEx", r->in.value_name) == 0) {
189 enum ndr_err_code ndr_err;
190 struct spoolss_OSVersionEx os_ex;
192 os_ex.major = server_info->version_major;
193 os_ex.minor = server_info->version_minor;
194 os_ex.build = server_info->version_build;
195 os_ex.extra_string = "";
196 os_ex.service_pack_major= 0;
197 os_ex.service_pack_minor= 0;
198 os_ex.suite_mask = 0;
199 os_ex.product_type = 0;
202 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, lp_iconv_convenience(server->ntptr->lp_ctx), &os_ex, (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersionEx);
203 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
204 return WERR_GENERAL_FAILURE;
207 *r->out.type = REG_BINARY;
208 r->out.data->binary = blob;
210 } else if (strcmp("DNSMachineName", r->in.value_name) == 0) {
211 const char *dnsdomain = lp_dnsdomain(server->ntptr->lp_ctx);
213 if (dnsdomain == NULL) return WERR_INVALID_PARAM;
215 *r->out.type = REG_SZ;
216 r->out.data->string = talloc_asprintf(mem_ctx, "%s.%s",
217 lp_netbios_name(server->ntptr->lp_ctx),
219 W_ERROR_HAVE_NO_MEMORY(r->out.data->string);
223 return WERR_INVALID_PARAM;
226 /* PrintServer Form functions */
227 static WERROR sptr_EnumPrintServerForms(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
228 struct spoolss_EnumForms *r)
230 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
231 struct ldb_message **msgs;
234 union spoolss_FormInfo *info;
236 count = sptr_db_search(sptr_db, mem_ctx,
237 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
238 &msgs, NULL, "(&(objectClass=form))");
240 if (count == 0) return WERR_OK;
241 if (count < 0) return WERR_GENERAL_FAILURE;
243 info = talloc_array(mem_ctx, union spoolss_FormInfo, count);
244 W_ERROR_HAVE_NO_MEMORY(info);
246 switch (r->in.level) {
248 for (i=0; i < count; i++) {
249 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", SPOOLSS_FORM_BUILTIN);
251 info[i].info1.form_name = samdb_result_string(msgs[i], "form-name", NULL);
252 W_ERROR_HAVE_NO_MEMORY(info[i].info1.form_name);
254 info[i].info1.size.width = samdb_result_uint(msgs[i], "size-width", 0);
255 info[i].info1.size.height = samdb_result_uint(msgs[i], "size-height", 0);
257 info[i].info1.area.left = samdb_result_uint(msgs[i], "area-left", 0);
258 info[i].info1.area.top = samdb_result_uint(msgs[i], "area-top", 0);
259 info[i].info1.area.right = samdb_result_uint(msgs[i], "area-right", 0);
260 info[i].info1.area.bottom = samdb_result_uint(msgs[i], "area-bottom", 0);
264 return WERR_UNKNOWN_LEVEL;
268 *r->out.count = count;
272 static WERROR sptr_AddPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
273 struct spoolss_AddForm *r)
275 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
276 struct ldb_message *msg,**msgs;
277 const char * const attrs[] = {"flags", NULL };
280 /* TODO: do checks access here
281 * if (!(server->access_mask & desired_access)) {
282 * return WERR_FOOBAR;
286 switch (r->in.level) {
288 if (!r->in.info.info1) {
291 count = sptr_db_search(sptr_db, mem_ctx,
292 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
293 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
294 r->in.info.info1->form_name);
296 if (count == 1) return WERR_FOOBAR;
297 if (count > 1) return WERR_FOOBAR;
298 if (count < 0) return WERR_GENERAL_FAILURE;
300 if (r->in.info.info1->flags != SPOOLSS_FORM_USER) {
304 msg = ldb_msg_new(mem_ctx);
305 W_ERROR_HAVE_NO_MEMORY(msg);
307 /* add core elements to the ldb_message for the Form */
308 msg->dn = ldb_dn_new_fmt(msg, sptr_db, "form-name=%s,CN=Forms,CN=PrintServer", r->in.info.info1->form_name);
309 SET_STRING(sptr_db, msg, "objectClass", "form");
311 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
313 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
315 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
316 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
318 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
319 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
320 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
321 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
324 return WERR_UNKNOWN_LEVEL;
327 ret = ldb_add(sptr_db, msg);
335 static WERROR sptr_SetPrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
336 struct spoolss_SetForm *r)
338 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
339 struct ldb_message *msg,**msgs;
340 const char * const attrs[] = { "flags", NULL};
342 enum spoolss_FormFlags flags;
344 /* TODO: do checks access here
345 * if (!(server->access_mask & desired_access)) {
346 * return WERR_FOOBAR;
350 switch (r->in.level) {
352 if (!r->in.info.info1) {
356 count = sptr_db_search(sptr_db, mem_ctx,
357 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
358 &msgs, attrs, "(&(form-name=%s)(objectClass=form))",
359 r->in.info.info1->form_name);
361 if (count == 0) return WERR_FOOBAR;
362 if (count > 1) return WERR_FOOBAR;
363 if (count < 0) return WERR_GENERAL_FAILURE;
365 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
366 if (flags != SPOOLSS_FORM_USER) {
370 msg = ldb_msg_new(mem_ctx);
371 W_ERROR_HAVE_NO_MEMORY(msg);
373 /* add core elements to the ldb_message for the user */
374 msg->dn = msgs[0]->dn;
376 SET_UINT(sptr_db, msg, "flags", r->in.info.info1->flags);
378 SET_STRING(sptr_db, msg, "form-name", r->in.info.info1->form_name);
380 SET_UINT(sptr_db, msg, "size-width", r->in.info.info1->size.width);
381 SET_UINT(sptr_db, msg, "size-height", r->in.info.info1->size.height);
383 SET_UINT(sptr_db, msg, "area-left", r->in.info.info1->area.left);
384 SET_UINT(sptr_db, msg, "area-top", r->in.info.info1->area.top);
385 SET_UINT(sptr_db, msg, "area-right", r->in.info.info1->area.right);
386 SET_UINT(sptr_db, msg, "area-bottom", r->in.info.info1->area.bottom);
389 return WERR_UNKNOWN_LEVEL;
392 ret = dsdb_replace(sptr_db, msg, 0);
400 static WERROR sptr_DeletePrintServerForm(struct ntptr_GenericHandle *server, TALLOC_CTX *mem_ctx,
401 struct spoolss_DeleteForm *r)
403 struct ldb_context *sptr_db = talloc_get_type(server->ntptr->private_data, struct ldb_context);
404 struct ldb_message **msgs;
405 const char * const attrs[] = { "flags", NULL};
407 enum spoolss_FormFlags flags;
409 /* TODO: do checks access here
410 * if (!(server->access_mask & desired_access)) {
411 * return WERR_FOOBAR;
415 if (!r->in.form_name) {
419 count = sptr_db_search(sptr_db, mem_ctx,
420 ldb_dn_new(mem_ctx, sptr_db, "CN=Forms,CN=PrintServer"),
421 &msgs, attrs, "(&(form-name=%s)(objectclass=form))",
424 if (count == 0) return WERR_FOOBAR;
425 if (count > 1) return WERR_FOOBAR;
426 if (count < 0) return WERR_GENERAL_FAILURE;
428 flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
429 if (flags != SPOOLSS_FORM_USER) {
433 ret = ldb_delete(sptr_db, msgs[0]->dn);
441 /* PrintServer Driver functions */
442 static WERROR sptr_EnumPrinterDrivers(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
443 struct spoolss_EnumPrinterDrivers *r)
448 static WERROR sptr_GetPrinterDriverDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
449 struct spoolss_GetPrinterDriverDirectory *r)
451 union spoolss_DriverDirectoryInfo *info;
456 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
457 * are ignoring the r->in.level completely, so we do :-)
461 * TODO: check the server name is ours
462 * - if it's a invalid UNC then return WERR_INVALID_NAME
463 * - if it's the wrong host name return WERR_INVALID_PARAM
464 * - if it's "" then we need to return a local WINDOWS path
466 if (!r->in.server || !r->in.server[0]) {
467 prefix = "C:\\DRIVERS";
469 prefix = talloc_asprintf(mem_ctx, "%s\\print$", r->in.server);
470 W_ERROR_HAVE_NO_MEMORY(prefix);
473 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
476 return WERR_INVALID_ENVIRONMENT;
479 info = talloc(mem_ctx, union spoolss_DriverDirectoryInfo);
480 W_ERROR_HAVE_NO_MEMORY(info);
482 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
483 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
489 /* Printer functions */
490 static WERROR sptr_EnumPrinters(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
491 struct spoolss_EnumPrinters *r)
493 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
494 struct ldb_message **msgs;
497 union spoolss_PrinterInfo *info;
499 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
500 "(&(objectclass=printer))");
502 if (count == 0) return WERR_OK;
503 if (count < 0) return WERR_GENERAL_FAILURE;
505 info = talloc_array(mem_ctx, union spoolss_PrinterInfo, count);
506 W_ERROR_HAVE_NO_MEMORY(info);
508 switch(r->in.level) {
510 for (i = 0; i < count; i++) {
511 info[i].info1.flags = samdb_result_uint(msgs[i], "flags", 0);
513 info[i].info1.name = samdb_result_string(msgs[i], "name", "");
514 W_ERROR_HAVE_NO_MEMORY(info[i].info1.name);
516 info[i].info1.description = samdb_result_string(msgs[i], "description", "");
517 W_ERROR_HAVE_NO_MEMORY(info[i].info1.description);
519 info[i].info1.comment = samdb_result_string(msgs[i], "comment", NULL);
523 for (i = 0; i < count; i++) {
524 info[i].info2.servername = samdb_result_string(msgs[i], "servername", "");
525 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
527 info[i].info2.printername = samdb_result_string(msgs[i], "printername", "");
528 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
530 info[i].info2.sharename = samdb_result_string(msgs[i], "sharename", "");
531 W_ERROR_HAVE_NO_MEMORY(info[i].info2.sharename);
533 info[i].info2.portname = samdb_result_string(msgs[i], "portname", "");
534 W_ERROR_HAVE_NO_MEMORY(info[i].info2.portname);
536 info[i].info2.drivername = samdb_result_string(msgs[i], "drivername", "");
537 W_ERROR_HAVE_NO_MEMORY(info[i].info2.drivername);
539 info[i].info2.comment = samdb_result_string(msgs[i], "comment", NULL);
541 info[i].info2.location = samdb_result_string(msgs[i], "location", NULL);
543 info[i].info2.devmode = NULL;
545 info[i].info2.sepfile = samdb_result_string(msgs[i], "sepfile", NULL);
547 info[i].info2.printprocessor = samdb_result_string(msgs[i], "printprocessor", "");
548 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printprocessor);
550 info[i].info2.datatype = samdb_result_string(msgs[i], "datatype", "");
551 W_ERROR_HAVE_NO_MEMORY(info[i].info2.datatype);
553 info[i].info2.parameters = samdb_result_string(msgs[i], "parameters", NULL);
555 info[i].info2.secdesc = NULL;
557 info[i].info2.attributes = samdb_result_uint(msgs[i], "attributes", 0);
558 info[i].info2.priority = samdb_result_uint(msgs[i], "priority", 0);
559 info[i].info2.defaultpriority = samdb_result_uint(msgs[i], "defaultpriority", 0);
560 info[i].info2.starttime = samdb_result_uint(msgs[i], "starttime", 0);
561 info[i].info2.untiltime = samdb_result_uint(msgs[i], "untiltime", 0);
562 info[i].info2.status = samdb_result_uint(msgs[i], "status", 0);
563 info[i].info2.cjobs = samdb_result_uint(msgs[i], "cjobs", 0);
564 info[i].info2.averageppm = samdb_result_uint(msgs[i], "averageppm", 0);
568 for (i = 0; i < count; i++) {
569 info[i].info4.printername = samdb_result_string(msgs[i], "printername", "");
570 W_ERROR_HAVE_NO_MEMORY(info[i].info2.printername);
572 info[i].info4.servername = samdb_result_string(msgs[i], "servername", "");
573 W_ERROR_HAVE_NO_MEMORY(info[i].info2.servername);
575 info[i].info4.attributes = samdb_result_uint(msgs[i], "attributes", 0);
579 for (i = 0; i < count; i++) {
580 info[i].info5.printername = samdb_result_string(msgs[i], "name", "");
581 W_ERROR_HAVE_NO_MEMORY(info[i].info5.printername);
583 info[i].info5.portname = samdb_result_string(msgs[i], "port", "");
584 W_ERROR_HAVE_NO_MEMORY(info[i].info5.portname);
586 info[i].info5.attributes = samdb_result_uint(msgs[i], "attributes", 0);
587 info[i].info5.device_not_selected_timeout = samdb_result_uint(msgs[i], "device_not_selected_timeout", 0);
588 info[i].info5.transmission_retry_timeout = samdb_result_uint(msgs[i], "transmission_retry_timeout", 0);
592 return WERR_UNKNOWN_LEVEL;
596 *r->out.count = count;
600 static WERROR sptr_OpenPrinter(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
601 struct spoolss_OpenPrinterEx *r,
602 const char *printer_name,
603 struct ntptr_GenericHandle **printer)
605 return WERR_INVALID_PRINTER_NAME;
609 static WERROR sptr_EnumPorts(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
610 struct spoolss_EnumPorts *r)
612 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
613 struct ldb_message **msgs;
616 union spoolss_PortInfo *info;
618 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
619 "(&(objectclass=port))");
621 if (count == 0) return WERR_OK;
622 if (count < 0) return WERR_GENERAL_FAILURE;
624 info = talloc_array(mem_ctx, union spoolss_PortInfo, count);
625 W_ERROR_HAVE_NO_MEMORY(info);
627 switch (r->in.level) {
629 for (i = 0; i < count; i++) {
630 info[i].info1.port_name = samdb_result_string(msgs[i], "port-name", "");
631 W_ERROR_HAVE_NO_MEMORY(info[i].info1.port_name);
635 for (i=0; i < count; i++) {
636 info[i].info2.port_name = samdb_result_string(msgs[i], "port-name", "");
637 W_ERROR_HAVE_NO_MEMORY(info[i].info2.port_name);
639 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
640 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
642 info[i].info2.description = samdb_result_string(msgs[i], "description", "");
643 W_ERROR_HAVE_NO_MEMORY(info[i].info2.description);
645 info[i].info2.port_type = samdb_result_uint(msgs[i], "port-type", SPOOLSS_PORT_TYPE_WRITE);
646 info[i].info2.reserved = samdb_result_uint(msgs[i], "reserved", 0);
650 return WERR_UNKNOWN_LEVEL;
654 *r->out.count = count;
658 /* monitor functions */
659 static WERROR sptr_EnumMonitors(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
660 struct spoolss_EnumMonitors *r)
662 struct ldb_context *sptr_db = talloc_get_type(ntptr->private_data, struct ldb_context);
663 struct ldb_message **msgs;
666 union spoolss_MonitorInfo *info;
668 count = sptr_db_search(sptr_db, mem_ctx, NULL, &msgs, NULL,
669 "(&(objectclass=monitor))");
671 if (count == 0) return WERR_OK;
672 if (count < 0) return WERR_GENERAL_FAILURE;
674 info = talloc_array(mem_ctx, union spoolss_MonitorInfo, count);
675 W_ERROR_HAVE_NO_MEMORY(info);
677 switch (r->in.level) {
679 for (i = 0; i < count; i++) {
680 info[i].info1.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
681 W_ERROR_HAVE_NO_MEMORY(info[i].info1.monitor_name);
685 for (i=0; i < count; i++) {
686 info[i].info2.monitor_name = samdb_result_string(msgs[i], "monitor-name", "");
687 W_ERROR_HAVE_NO_MEMORY(info[i].info2.monitor_name);
689 info[i].info2.environment = samdb_result_string(msgs[i], "environment", "");
690 W_ERROR_HAVE_NO_MEMORY(info[i].info2.environment);
692 info[i].info2.dll_name = samdb_result_string(msgs[i], "dll-name", "");
693 W_ERROR_HAVE_NO_MEMORY(info[i].info2.dll_name);
697 return WERR_UNKNOWN_LEVEL;
701 *r->out.count = count;
705 /* Printer Form functions */
706 static WERROR sptr_GetPrinterForm(struct ntptr_GenericHandle *printer, TALLOC_CTX *mem_ctx,
707 struct spoolss_GetForm *r)
709 struct ldb_context *sptr_db = talloc_get_type(printer->ntptr->private_data, struct ldb_context);
710 struct ldb_message **msgs;
711 struct ldb_dn *base_dn;
713 union spoolss_FormInfo *info;
715 /* TODO: do checks access here
716 * if (!(printer->access_mask & desired_access)) {
717 * return WERR_FOOBAR;
721 base_dn = ldb_dn_new_fmt(mem_ctx, sptr_db, "CN=Forms,CN=%s,CN=Printers", printer->object_name);
722 W_ERROR_HAVE_NO_MEMORY(base_dn);
724 count = sptr_db_search(sptr_db, mem_ctx, base_dn, &msgs, NULL,
725 "(&(form-name=%s)(objectClass=form))",
728 if (count == 0) return WERR_FOOBAR;
729 if (count > 1) return WERR_FOOBAR;
730 if (count < 0) return WERR_GENERAL_FAILURE;
732 info = talloc(mem_ctx, union spoolss_FormInfo);
733 W_ERROR_HAVE_NO_MEMORY(info);
735 switch (r->in.level) {
737 info->info1.flags = samdb_result_uint(msgs[0], "flags", SPOOLSS_FORM_BUILTIN);
739 info->info1.form_name = samdb_result_string(msgs[0], "form-name", NULL);
740 W_ERROR_HAVE_NO_MEMORY(info->info1.form_name);
742 info->info1.size.width = samdb_result_uint(msgs[0], "size-width", 0);
743 info->info1.size.height = samdb_result_uint(msgs[0], "size-height", 0);
745 info->info1.area.left = samdb_result_uint(msgs[0], "area-left", 0);
746 info->info1.area.top = samdb_result_uint(msgs[0], "area-top", 0);
747 info->info1.area.right = samdb_result_uint(msgs[0], "area-right", 0);
748 info->info1.area.bottom = samdb_result_uint(msgs[0], "area-bottom", 0);
751 return WERR_UNKNOWN_LEVEL;
758 static WERROR sptr_GetPrintProcessorDirectory(struct ntptr_context *ntptr, TALLOC_CTX *mem_ctx,
759 struct spoolss_GetPrintProcessorDirectory *r)
761 union spoolss_PrintProcessorDirectoryInfo *info;
766 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
767 * are ignoring the r->in.level completely, so we do :-)
771 * TODO: check the server name is ours
772 * - if it's a invalid UNC then return WERR_INVALID_NAME
773 * - if it's the wrong host name return WERR_INVALID_PARAM
774 * - if it's "" then we need to return a local WINDOWS path
776 if (!r->in.server || !r->in.server[0]) {
777 prefix = "C:\\PRTPROCS";
779 prefix = talloc_asprintf(mem_ctx, "%s\\prnproc$", r->in.server);
780 W_ERROR_HAVE_NO_MEMORY(prefix);
783 if (r->in.environment && strcmp(SPOOLSS_ARCHITECTURE_NT_X86, r->in.environment) == 0) {
786 return WERR_INVALID_ENVIRONMENT;
789 info = talloc(mem_ctx, union spoolss_PrintProcessorDirectoryInfo);
790 W_ERROR_HAVE_NO_MEMORY(info);
792 info->info1.directory_name = talloc_asprintf(mem_ctx, "%s\\%s", prefix, postfix);
793 W_ERROR_HAVE_NO_MEMORY(info->info1.directory_name);
801 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
803 static const struct ntptr_ops ntptr_simple_ldb_ops = {
804 .name = "simple_ldb",
805 .init_context = sptr_init_context,
807 /* PrintServer functions */
808 .OpenPrintServer = sptr_OpenPrintServer,
809 /* .XcvDataPrintServer = sptr_XcvDataPrintServer,
811 /* PrintServer PrinterData functions */
812 /* .EnumPrintServerData = sptr_EnumPrintServerData,
813 */ .GetPrintServerData = sptr_GetPrintServerData,
814 /* .SetPrintServerData = sptr_SetPrintServerData,
815 .DeletePrintServerData = sptr_DeletePrintServerData,
817 /* PrintServer Form functions */
818 .EnumPrintServerForms = sptr_EnumPrintServerForms,
819 .AddPrintServerForm = sptr_AddPrintServerForm,
820 .SetPrintServerForm = sptr_SetPrintServerForm,
821 .DeletePrintServerForm = sptr_DeletePrintServerForm,
823 /* PrintServer Driver functions */
824 .EnumPrinterDrivers = sptr_EnumPrinterDrivers,
825 /* .AddPrinterDriver = sptr_AddPrinterDriver,
826 .DeletePrinterDriver = sptr_DeletePrinterDriver,
827 */ .GetPrinterDriverDirectory = sptr_GetPrinterDriverDirectory,
830 .EnumPorts = sptr_EnumPorts,
831 /* .OpenPort = sptr_OpenPort,
832 .XcvDataPort = sptr_XcvDataPort,
834 /* Monitor functions */
835 .EnumMonitors = sptr_EnumMonitors,
836 /* .OpenMonitor = sptr_OpenMonitor,
837 .XcvDataMonitor = sptr_XcvDataMonitor,
839 /* PrintProcessor functions */
840 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
842 .GetPrintProcessorDirectory = sptr_GetPrintProcessorDirectory,
844 /* Printer functions */
845 .EnumPrinters = sptr_EnumPrinters,
846 .OpenPrinter = sptr_OpenPrinter,
847 /* .AddPrinter = sptr_AddPrinter,
848 .GetPrinter = sptr_GetPrinter,
849 .SetPrinter = sptr_SetPrinter,
850 .DeletePrinter = sptr_DeletePrinter,
851 .XcvDataPrinter = sptr_XcvDataPrinter,
853 /* Printer Driver functions */
854 /* .GetPrinterDriver = sptr_GetPrinterDriver,
856 /* Printer PrinterData functions */
857 /* .EnumPrinterData = sptr_EnumPrinterData,
858 .GetPrinterData = sptr_GetPrinterData,
859 .SetPrinterData = sptr_SetPrinterData,
860 .DeletePrinterData = sptr_DeletePrinterData,
862 /* Printer Form functions */
863 /* .EnumPrinterForms = sptr_EnumPrinterForms,
864 .AddPrinterForm = sptr_AddPrinterForm,
865 */ .GetPrinterForm = sptr_GetPrinterForm,
866 /* .SetPrinterForm = sptr_SetPrinterForm,
867 .DeletePrinterForm = sptr_DeletePrinterForm,
869 /* Printer Job functions */
870 /* .EnumJobs = sptr_EnumJobs,
871 .AddJob = sptr_AddJob,
872 .ScheduleJob = sptr_ScheduleJob,
873 .GetJob = sptr_GetJob,
874 .SetJob = sptr_SetJob,
876 /* Printer Printing functions */
877 /* .StartDocPrinter = sptr_StartDocPrinter,
878 .EndDocPrinter = sptr_EndDocPrinter,
879 .StartPagePrinter = sptr_StartPagePrinter,
880 .EndPagePrinter = sptr_EndPagePrinter,
881 .WritePrinter = sptr_WritePrinter,
882 .ReadPrinter = sptr_ReadPrinter,
885 NTSTATUS ntptr_simple_ldb_init(void)
889 ret = ntptr_register(&ntptr_simple_ldb_ops);
890 if (!NT_STATUS_IS_OK(ret)) {
891 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
892 ntptr_simple_ldb_ops.name));