2 Unix SMB/CIFS implementation.
4 interface functions for the spoolss database
6 Copyright (C) Andrew Tridgell 2004
7 Copyright (C) Tim Potter 2004
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 struct spoolssdb_context {
27 struct ldb_context *ldb;
31 this is used to catch debug messages from ldb
33 void spoolssdb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap)
36 if (DEBUGLEVEL < 4 && level > LDB_DEBUG_WARNING) {
39 vasprintf(&s, fmt, ap);
41 DEBUG(level, ("spoolssdb: %s\n", s));
46 connect to the spoolss database
47 return an opaque context pointer on success, or NULL on failure
49 void *spoolssdb_connect(void)
51 struct spoolssdb_context *ctx;
53 the way that unix fcntl locking works forces us to have a
54 static ldb handle here rather than a much more sensible
55 approach of having the ldb handle as part of the
56 spoolss_OpenPrinter() pipe state. Otherwise we would try to open
57 the ldb more than once, and tdb would rightly refuse the
58 second open due to the broken nature of unix locking.
60 static struct ldb_context *static_spoolss_db;
62 if (static_spoolss_db == NULL) {
63 static_spoolss_db = ldb_connect(lp_spoolss_url(), 0, NULL);
64 if (static_spoolss_db == NULL) {
69 ldb_set_debug(static_spoolss_db, spoolssdb_debug, NULL);
71 ctx = malloc_p(struct spoolssdb_context);
77 ctx->ldb = static_spoolss_db;
82 /* close a connection to the spoolss db */
83 void spoolssdb_close(void *ctx)
85 struct spoolssdb_context *spoolss_ctx = ctx;
86 /* we don't actually close due to broken posix locking semantics */
87 spoolss_ctx->ldb = NULL;
92 search the db for the specified attributes - varargs variant
94 int spoolssdb_search(void *ctx,
97 struct ldb_message ***res,
98 const char * const *attrs,
99 const char *format, ...) _PRINTF_ATTRIBUTE(6,7)
101 struct spoolssdb_context *spoolss_ctx = ctx;
105 va_start(ap, format);
106 count = gendb_search_v(spoolss_ctx->ldb, mem_ctx, basedn, res, attrs, format, ap);