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(mem_ctx
, 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 if (!lp_realm(server
->ntptr
->lp_ctx
)) return WERR_INVALID_PARAM
;
213 *r
->out
.type
= REG_SZ
;
214 r
->out
.data
->string
= talloc_asprintf(mem_ctx
, "%s.%s",
215 lp_netbios_name(server
->ntptr
->lp_ctx
),
216 lp_realm(server
->ntptr
->lp_ctx
));
217 W_ERROR_HAVE_NO_MEMORY(r
->out
.data
->string
);
221 return WERR_INVALID_PARAM
;
224 /* PrintServer Form functions */
225 static WERROR
sptr_EnumPrintServerForms(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
226 struct spoolss_EnumForms
*r
)
228 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
229 struct ldb_message
**msgs
;
232 union spoolss_FormInfo
*info
;
234 count
= sptr_db_search(sptr_db
, mem_ctx
,
235 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
236 &msgs
, NULL
, "(&(objectClass=form))");
238 if (count
== 0) return WERR_OK
;
239 if (count
< 0) return WERR_GENERAL_FAILURE
;
241 info
= talloc_array(mem_ctx
, union spoolss_FormInfo
, count
);
242 W_ERROR_HAVE_NO_MEMORY(info
);
244 switch (r
->in
.level
) {
246 for (i
=0; i
< count
; i
++) {
247 info
[i
].info1
.flags
= samdb_result_uint(msgs
[i
], "flags", SPOOLSS_FORM_BUILTIN
);
249 info
[i
].info1
.form_name
= samdb_result_string(msgs
[i
], "form-name", NULL
);
250 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.form_name
);
252 info
[i
].info1
.size
.width
= samdb_result_uint(msgs
[i
], "size-width", 0);
253 info
[i
].info1
.size
.height
= samdb_result_uint(msgs
[i
], "size-height", 0);
255 info
[i
].info1
.area
.left
= samdb_result_uint(msgs
[i
], "area-left", 0);
256 info
[i
].info1
.area
.top
= samdb_result_uint(msgs
[i
], "area-top", 0);
257 info
[i
].info1
.area
.right
= samdb_result_uint(msgs
[i
], "area-right", 0);
258 info
[i
].info1
.area
.bottom
= samdb_result_uint(msgs
[i
], "area-bottom", 0);
262 return WERR_UNKNOWN_LEVEL
;
266 *r
->out
.count
= count
;
270 static WERROR
sptr_AddPrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
271 struct spoolss_AddForm
*r
)
273 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
274 struct ldb_message
*msg
,**msgs
;
275 const char * const attrs
[] = {"flags", NULL
};
278 /* TODO: do checks access here
279 * if (!(server->access_mask & desired_access)) {
280 * return WERR_FOOBAR;
284 switch (r
->in
.level
) {
286 if (!r
->in
.info
.info1
) {
289 count
= sptr_db_search(sptr_db
, mem_ctx
,
290 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
291 &msgs
, attrs
, "(&(form-name=%s)(objectClass=form))",
292 r
->in
.info
.info1
->form_name
);
294 if (count
== 1) return WERR_FOOBAR
;
295 if (count
> 1) return WERR_FOOBAR
;
296 if (count
< 0) return WERR_GENERAL_FAILURE
;
298 if (r
->in
.info
.info1
->flags
!= SPOOLSS_FORM_USER
) {
302 msg
= ldb_msg_new(mem_ctx
);
303 W_ERROR_HAVE_NO_MEMORY(msg
);
305 /* add core elements to the ldb_message for the Form */
306 msg
->dn
= ldb_dn_new_fmt(msg
, sptr_db
, "form-name=%s,CN=Forms,CN=PrintServer", r
->in
.info
.info1
->form_name
);
307 SET_STRING(sptr_db
, msg
, "objectClass", "form");
309 SET_UINT(sptr_db
, msg
, "flags", r
->in
.info
.info1
->flags
);
311 SET_STRING(sptr_db
, msg
, "form-name", r
->in
.info
.info1
->form_name
);
313 SET_UINT(sptr_db
, msg
, "size-width", r
->in
.info
.info1
->size
.width
);
314 SET_UINT(sptr_db
, msg
, "size-height", r
->in
.info
.info1
->size
.height
);
316 SET_UINT(sptr_db
, msg
, "area-left", r
->in
.info
.info1
->area
.left
);
317 SET_UINT(sptr_db
, msg
, "area-top", r
->in
.info
.info1
->area
.top
);
318 SET_UINT(sptr_db
, msg
, "area-right", r
->in
.info
.info1
->area
.right
);
319 SET_UINT(sptr_db
, msg
, "area-bottom", r
->in
.info
.info1
->area
.bottom
);
322 return WERR_UNKNOWN_LEVEL
;
325 ret
= ldb_add(sptr_db
, msg
);
333 static WERROR
sptr_SetPrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
334 struct spoolss_SetForm
*r
)
336 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
337 struct ldb_message
*msg
,**msgs
;
338 const char * const attrs
[] = { "flags", NULL
};
340 enum spoolss_FormFlags flags
;
342 /* TODO: do checks access here
343 * if (!(server->access_mask & desired_access)) {
344 * return WERR_FOOBAR;
348 switch (r
->in
.level
) {
350 if (!r
->in
.info
.info1
) {
354 count
= sptr_db_search(sptr_db
, mem_ctx
,
355 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
356 &msgs
, attrs
, "(&(form-name=%s)(objectClass=form))",
357 r
->in
.info
.info1
->form_name
);
359 if (count
== 0) return WERR_FOOBAR
;
360 if (count
> 1) return WERR_FOOBAR
;
361 if (count
< 0) return WERR_GENERAL_FAILURE
;
363 flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
364 if (flags
!= SPOOLSS_FORM_USER
) {
368 msg
= ldb_msg_new(mem_ctx
);
369 W_ERROR_HAVE_NO_MEMORY(msg
);
371 /* add core elements to the ldb_message for the user */
372 msg
->dn
= msgs
[0]->dn
;
374 SET_UINT(sptr_db
, msg
, "flags", r
->in
.info
.info1
->flags
);
376 SET_STRING(sptr_db
, msg
, "form-name", r
->in
.info
.info1
->form_name
);
378 SET_UINT(sptr_db
, msg
, "size-width", r
->in
.info
.info1
->size
.width
);
379 SET_UINT(sptr_db
, msg
, "size-height", r
->in
.info
.info1
->size
.height
);
381 SET_UINT(sptr_db
, msg
, "area-left", r
->in
.info
.info1
->area
.left
);
382 SET_UINT(sptr_db
, msg
, "area-top", r
->in
.info
.info1
->area
.top
);
383 SET_UINT(sptr_db
, msg
, "area-right", r
->in
.info
.info1
->area
.right
);
384 SET_UINT(sptr_db
, msg
, "area-bottom", r
->in
.info
.info1
->area
.bottom
);
387 return WERR_UNKNOWN_LEVEL
;
390 ret
= samdb_replace(sptr_db
, mem_ctx
, msg
);
398 static WERROR
sptr_DeletePrintServerForm(struct ntptr_GenericHandle
*server
, TALLOC_CTX
*mem_ctx
,
399 struct spoolss_DeleteForm
*r
)
401 struct ldb_context
*sptr_db
= talloc_get_type(server
->ntptr
->private_data
, struct ldb_context
);
402 struct ldb_message
**msgs
;
403 const char * const attrs
[] = { "flags", NULL
};
405 enum spoolss_FormFlags flags
;
407 /* TODO: do checks access here
408 * if (!(server->access_mask & desired_access)) {
409 * return WERR_FOOBAR;
413 if (!r
->in
.form_name
) {
417 count
= sptr_db_search(sptr_db
, mem_ctx
,
418 ldb_dn_new(mem_ctx
, sptr_db
, "CN=Forms,CN=PrintServer"),
419 &msgs
, attrs
, "(&(form-name=%s)(objectclass=form))",
422 if (count
== 0) return WERR_FOOBAR
;
423 if (count
> 1) return WERR_FOOBAR
;
424 if (count
< 0) return WERR_GENERAL_FAILURE
;
426 flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
427 if (flags
!= SPOOLSS_FORM_USER
) {
431 ret
= ldb_delete(sptr_db
, msgs
[0]->dn
);
439 /* PrintServer Driver functions */
440 static WERROR
sptr_EnumPrinterDrivers(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
441 struct spoolss_EnumPrinterDrivers
*r
)
446 static WERROR
sptr_GetPrinterDriverDirectory(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
447 struct spoolss_GetPrinterDriverDirectory
*r
)
449 union spoolss_DriverDirectoryInfo
*info
;
454 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
455 * are ignoring the r->in.level completely, so we do :-)
459 * TODO: check the server name is ours
460 * - if it's a invalid UNC then return WERR_INVALID_NAME
461 * - if it's the wrong host name return WERR_INVALID_PARAM
462 * - if it's "" then we need to return a local WINDOWS path
464 if (!r
->in
.server
|| !r
->in
.server
[0]) {
465 prefix
= "C:\\DRIVERS";
467 prefix
= talloc_asprintf(mem_ctx
, "%s\\print$", r
->in
.server
);
468 W_ERROR_HAVE_NO_MEMORY(prefix
);
471 if (r
->in
.environment
&& strcmp(SPOOLSS_ARCHITECTURE_NT_X86
, r
->in
.environment
) == 0) {
474 return WERR_INVALID_ENVIRONMENT
;
477 info
= talloc(mem_ctx
, union spoolss_DriverDirectoryInfo
);
478 W_ERROR_HAVE_NO_MEMORY(info
);
480 info
->info1
.directory_name
= talloc_asprintf(mem_ctx
, "%s\\%s", prefix
, postfix
);
481 W_ERROR_HAVE_NO_MEMORY(info
->info1
.directory_name
);
487 /* Printer functions */
488 static WERROR
sptr_EnumPrinters(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
489 struct spoolss_EnumPrinters
*r
)
491 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
492 struct ldb_message
**msgs
;
495 union spoolss_PrinterInfo
*info
;
497 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
498 "(&(objectclass=printer))");
500 if (count
== 0) return WERR_OK
;
501 if (count
< 0) return WERR_GENERAL_FAILURE
;
503 info
= talloc_array(mem_ctx
, union spoolss_PrinterInfo
, count
);
504 W_ERROR_HAVE_NO_MEMORY(info
);
506 switch(r
->in
.level
) {
508 for (i
= 0; i
< count
; i
++) {
509 info
[i
].info1
.flags
= samdb_result_uint(msgs
[i
], "flags", 0);
511 info
[i
].info1
.name
= samdb_result_string(msgs
[i
], "name", "");
512 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.name
);
514 info
[i
].info1
.description
= samdb_result_string(msgs
[i
], "description", "");
515 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.description
);
517 info
[i
].info1
.comment
= samdb_result_string(msgs
[i
], "comment", NULL
);
521 for (i
= 0; i
< count
; i
++) {
522 info
[i
].info2
.servername
= samdb_result_string(msgs
[i
], "servername", "");
523 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.servername
);
525 info
[i
].info2
.printername
= samdb_result_string(msgs
[i
], "printername", "");
526 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printername
);
528 info
[i
].info2
.sharename
= samdb_result_string(msgs
[i
], "sharename", "");
529 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.sharename
);
531 info
[i
].info2
.portname
= samdb_result_string(msgs
[i
], "portname", "");
532 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.portname
);
534 info
[i
].info2
.drivername
= samdb_result_string(msgs
[i
], "drivername", "");
535 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.drivername
);
537 info
[i
].info2
.comment
= samdb_result_string(msgs
[i
], "comment", NULL
);
539 info
[i
].info2
.location
= samdb_result_string(msgs
[i
], "location", NULL
);
541 info
[i
].info2
.devmode
= NULL
;
543 info
[i
].info2
.sepfile
= samdb_result_string(msgs
[i
], "sepfile", NULL
);
545 info
[i
].info2
.printprocessor
= samdb_result_string(msgs
[i
], "printprocessor", "");
546 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printprocessor
);
548 info
[i
].info2
.datatype
= samdb_result_string(msgs
[i
], "datatype", "");
549 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.datatype
);
551 info
[i
].info2
.parameters
= samdb_result_string(msgs
[i
], "parameters", NULL
);
553 info
[i
].info2
.secdesc
= NULL
;
555 info
[i
].info2
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
556 info
[i
].info2
.priority
= samdb_result_uint(msgs
[i
], "priority", 0);
557 info
[i
].info2
.defaultpriority
= samdb_result_uint(msgs
[i
], "defaultpriority", 0);
558 info
[i
].info2
.starttime
= samdb_result_uint(msgs
[i
], "starttime", 0);
559 info
[i
].info2
.untiltime
= samdb_result_uint(msgs
[i
], "untiltime", 0);
560 info
[i
].info2
.status
= samdb_result_uint(msgs
[i
], "status", 0);
561 info
[i
].info2
.cjobs
= samdb_result_uint(msgs
[i
], "cjobs", 0);
562 info
[i
].info2
.averageppm
= samdb_result_uint(msgs
[i
], "averageppm", 0);
566 for (i
= 0; i
< count
; i
++) {
567 info
[i
].info4
.printername
= samdb_result_string(msgs
[i
], "printername", "");
568 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.printername
);
570 info
[i
].info4
.servername
= samdb_result_string(msgs
[i
], "servername", "");
571 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.servername
);
573 info
[i
].info4
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
577 for (i
= 0; i
< count
; i
++) {
578 info
[i
].info5
.printername
= samdb_result_string(msgs
[i
], "name", "");
579 W_ERROR_HAVE_NO_MEMORY(info
[i
].info5
.printername
);
581 info
[i
].info5
.portname
= samdb_result_string(msgs
[i
], "port", "");
582 W_ERROR_HAVE_NO_MEMORY(info
[i
].info5
.portname
);
584 info
[i
].info5
.attributes
= samdb_result_uint(msgs
[i
], "attributes", 0);
585 info
[i
].info5
.device_not_selected_timeout
= samdb_result_uint(msgs
[i
], "device_not_selected_timeout", 0);
586 info
[i
].info5
.transmission_retry_timeout
= samdb_result_uint(msgs
[i
], "transmission_retry_timeout", 0);
590 return WERR_UNKNOWN_LEVEL
;
594 *r
->out
.count
= count
;
598 static WERROR
sptr_OpenPrinter(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
599 struct spoolss_OpenPrinterEx
*r
,
600 const char *printer_name
,
601 struct ntptr_GenericHandle
**printer
)
603 return WERR_INVALID_PRINTER_NAME
;
607 static WERROR
sptr_EnumPorts(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
608 struct spoolss_EnumPorts
*r
)
610 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
611 struct ldb_message
**msgs
;
614 union spoolss_PortInfo
*info
;
616 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
617 "(&(objectclass=port))");
619 if (count
== 0) return WERR_OK
;
620 if (count
< 0) return WERR_GENERAL_FAILURE
;
622 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, count
);
623 W_ERROR_HAVE_NO_MEMORY(info
);
625 switch (r
->in
.level
) {
627 for (i
= 0; i
< count
; i
++) {
628 info
[i
].info1
.port_name
= samdb_result_string(msgs
[i
], "port-name", "");
629 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.port_name
);
633 for (i
=0; i
< count
; i
++) {
634 info
[i
].info2
.port_name
= samdb_result_string(msgs
[i
], "port-name", "");
635 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.port_name
);
637 info
[i
].info2
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
638 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.monitor_name
);
640 info
[i
].info2
.description
= samdb_result_string(msgs
[i
], "description", "");
641 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.description
);
643 info
[i
].info2
.port_type
= samdb_result_uint(msgs
[i
], "port-type", SPOOLSS_PORT_TYPE_WRITE
);
644 info
[i
].info2
.reserved
= samdb_result_uint(msgs
[i
], "reserved", 0);
648 return WERR_UNKNOWN_LEVEL
;
652 *r
->out
.count
= count
;
656 /* monitor functions */
657 static WERROR
sptr_EnumMonitors(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
658 struct spoolss_EnumMonitors
*r
)
660 struct ldb_context
*sptr_db
= talloc_get_type(ntptr
->private_data
, struct ldb_context
);
661 struct ldb_message
**msgs
;
664 union spoolss_MonitorInfo
*info
;
666 count
= sptr_db_search(sptr_db
, mem_ctx
, NULL
, &msgs
, NULL
,
667 "(&(objectclass=monitor))");
669 if (count
== 0) return WERR_OK
;
670 if (count
< 0) return WERR_GENERAL_FAILURE
;
672 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, count
);
673 W_ERROR_HAVE_NO_MEMORY(info
);
675 switch (r
->in
.level
) {
677 for (i
= 0; i
< count
; i
++) {
678 info
[i
].info1
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
679 W_ERROR_HAVE_NO_MEMORY(info
[i
].info1
.monitor_name
);
683 for (i
=0; i
< count
; i
++) {
684 info
[i
].info2
.monitor_name
= samdb_result_string(msgs
[i
], "monitor-name", "");
685 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.monitor_name
);
687 info
[i
].info2
.environment
= samdb_result_string(msgs
[i
], "environment", "");
688 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.environment
);
690 info
[i
].info2
.dll_name
= samdb_result_string(msgs
[i
], "dll-name", "");
691 W_ERROR_HAVE_NO_MEMORY(info
[i
].info2
.dll_name
);
695 return WERR_UNKNOWN_LEVEL
;
699 *r
->out
.count
= count
;
703 /* Printer Form functions */
704 static WERROR
sptr_GetPrinterForm(struct ntptr_GenericHandle
*printer
, TALLOC_CTX
*mem_ctx
,
705 struct spoolss_GetForm
*r
)
707 struct ldb_context
*sptr_db
= talloc_get_type(printer
->ntptr
->private_data
, struct ldb_context
);
708 struct ldb_message
**msgs
;
709 struct ldb_dn
*base_dn
;
711 union spoolss_FormInfo
*info
;
713 /* TODO: do checks access here
714 * if (!(printer->access_mask & desired_access)) {
715 * return WERR_FOOBAR;
719 base_dn
= ldb_dn_new_fmt(mem_ctx
, sptr_db
, "CN=Forms,CN=%s,CN=Printers", printer
->object_name
);
720 W_ERROR_HAVE_NO_MEMORY(base_dn
);
722 count
= sptr_db_search(sptr_db
, mem_ctx
, base_dn
, &msgs
, NULL
,
723 "(&(form-name=%s)(objectClass=form))",
726 if (count
== 0) return WERR_FOOBAR
;
727 if (count
> 1) return WERR_FOOBAR
;
728 if (count
< 0) return WERR_GENERAL_FAILURE
;
730 info
= talloc(mem_ctx
, union spoolss_FormInfo
);
731 W_ERROR_HAVE_NO_MEMORY(info
);
733 switch (r
->in
.level
) {
735 info
->info1
.flags
= samdb_result_uint(msgs
[0], "flags", SPOOLSS_FORM_BUILTIN
);
737 info
->info1
.form_name
= samdb_result_string(msgs
[0], "form-name", NULL
);
738 W_ERROR_HAVE_NO_MEMORY(info
->info1
.form_name
);
740 info
->info1
.size
.width
= samdb_result_uint(msgs
[0], "size-width", 0);
741 info
->info1
.size
.height
= samdb_result_uint(msgs
[0], "size-height", 0);
743 info
->info1
.area
.left
= samdb_result_uint(msgs
[0], "area-left", 0);
744 info
->info1
.area
.top
= samdb_result_uint(msgs
[0], "area-top", 0);
745 info
->info1
.area
.right
= samdb_result_uint(msgs
[0], "area-right", 0);
746 info
->info1
.area
.bottom
= samdb_result_uint(msgs
[0], "area-bottom", 0);
749 return WERR_UNKNOWN_LEVEL
;
756 static WERROR
sptr_GetPrintProcessorDirectory(struct ntptr_context
*ntptr
, TALLOC_CTX
*mem_ctx
,
757 struct spoolss_GetPrintProcessorDirectory
*r
)
759 union spoolss_PrintProcessorDirectoryInfo
*info
;
764 * NOTE: normally r->in.level is 1, but both w2k3 and nt4 sp6a
765 * are ignoring the r->in.level completely, so we do :-)
769 * TODO: check the server name is ours
770 * - if it's a invalid UNC then return WERR_INVALID_NAME
771 * - if it's the wrong host name return WERR_INVALID_PARAM
772 * - if it's "" then we need to return a local WINDOWS path
774 if (!r
->in
.server
|| !r
->in
.server
[0]) {
775 prefix
= "C:\\PRTPROCS";
777 prefix
= talloc_asprintf(mem_ctx
, "%s\\prnproc$", r
->in
.server
);
778 W_ERROR_HAVE_NO_MEMORY(prefix
);
781 if (r
->in
.environment
&& strcmp(SPOOLSS_ARCHITECTURE_NT_X86
, r
->in
.environment
) == 0) {
784 return WERR_INVALID_ENVIRONMENT
;
787 info
= talloc(mem_ctx
, union spoolss_PrintProcessorDirectoryInfo
);
788 W_ERROR_HAVE_NO_MEMORY(info
);
790 info
->info1
.directory_name
= talloc_asprintf(mem_ctx
, "%s\\%s", prefix
, postfix
);
791 W_ERROR_HAVE_NO_MEMORY(info
->info1
.directory_name
);
799 initialialise the simble ldb backend, registering ourselves with the ntptr subsystem
801 static const struct ntptr_ops ntptr_simple_ldb_ops
= {
802 .name
= "simple_ldb",
803 .init_context
= sptr_init_context
,
805 /* PrintServer functions */
806 .OpenPrintServer
= sptr_OpenPrintServer
,
807 /* .XcvDataPrintServer = sptr_XcvDataPrintServer,
809 /* PrintServer PrinterData functions */
810 /* .EnumPrintServerData = sptr_EnumPrintServerData,
811 */ .GetPrintServerData
= sptr_GetPrintServerData
,
812 /* .SetPrintServerData = sptr_SetPrintServerData,
813 .DeletePrintServerData = sptr_DeletePrintServerData,
815 /* PrintServer Form functions */
816 .EnumPrintServerForms
= sptr_EnumPrintServerForms
,
817 .AddPrintServerForm
= sptr_AddPrintServerForm
,
818 .SetPrintServerForm
= sptr_SetPrintServerForm
,
819 .DeletePrintServerForm
= sptr_DeletePrintServerForm
,
821 /* PrintServer Driver functions */
822 .EnumPrinterDrivers
= sptr_EnumPrinterDrivers
,
823 /* .AddPrinterDriver = sptr_AddPrinterDriver,
824 .DeletePrinterDriver = sptr_DeletePrinterDriver,
825 */ .GetPrinterDriverDirectory
= sptr_GetPrinterDriverDirectory
,
828 .EnumPorts
= sptr_EnumPorts
,
829 /* .OpenPort = sptr_OpenPort,
830 .XcvDataPort = sptr_XcvDataPort,
832 /* Monitor functions */
833 .EnumMonitors
= sptr_EnumMonitors
,
834 /* .OpenMonitor = sptr_OpenMonitor,
835 .XcvDataMonitor = sptr_XcvDataMonitor,
837 /* PrintProcessor functions */
838 /* .EnumPrintProcessors = sptr_EnumPrintProcessors,
840 .GetPrintProcessorDirectory
= sptr_GetPrintProcessorDirectory
,
842 /* Printer functions */
843 .EnumPrinters
= sptr_EnumPrinters
,
844 .OpenPrinter
= sptr_OpenPrinter
,
845 /* .AddPrinter = sptr_AddPrinter,
846 .GetPrinter = sptr_GetPrinter,
847 .SetPrinter = sptr_SetPrinter,
848 .DeletePrinter = sptr_DeletePrinter,
849 .XcvDataPrinter = sptr_XcvDataPrinter,
851 /* Printer Driver functions */
852 /* .GetPrinterDriver = sptr_GetPrinterDriver,
854 /* Printer PrinterData functions */
855 /* .EnumPrinterData = sptr_EnumPrinterData,
856 .GetPrinterData = sptr_GetPrinterData,
857 .SetPrinterData = sptr_SetPrinterData,
858 .DeletePrinterData = sptr_DeletePrinterData,
860 /* Printer Form functions */
861 /* .EnumPrinterForms = sptr_EnumPrinterForms,
862 .AddPrinterForm = sptr_AddPrinterForm,
863 */ .GetPrinterForm
= sptr_GetPrinterForm
,
864 /* .SetPrinterForm = sptr_SetPrinterForm,
865 .DeletePrinterForm = sptr_DeletePrinterForm,
867 /* Printer Job functions */
868 /* .EnumJobs = sptr_EnumJobs,
869 .AddJob = sptr_AddJob,
870 .ScheduleJob = sptr_ScheduleJob,
871 .GetJob = sptr_GetJob,
872 .SetJob = sptr_SetJob,
874 /* Printer Printing functions */
875 /* .StartDocPrinter = sptr_StartDocPrinter,
876 .EndDocPrinter = sptr_EndDocPrinter,
877 .StartPagePrinter = sptr_StartPagePrinter,
878 .EndPagePrinter = sptr_EndPagePrinter,
879 .WritePrinter = sptr_WritePrinter,
880 .ReadPrinter = sptr_ReadPrinter,
883 NTSTATUS
ntptr_simple_ldb_init(void)
887 ret
= ntptr_register(&ntptr_simple_ldb_ops
);
888 if (!NT_STATUS_IS_OK(ret
)) {
889 DEBUG(0,("Failed to register NTPTR '%s' backend!\n",
890 ntptr_simple_ldb_ops
.name
));