4 Copyright (C) Stefan Metzmacher 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Component: ldb winsdb module
26 * Description: verify winsdb records before they're written to disk
28 * Author: Stefan Metzmacher
32 #include "nbt_server/nbt_server.h"
33 #include "nbt_server/wins/winsdb.h"
34 #include "lib/ldb/include/ldb.h"
35 #include "lib/ldb/include/ldb_errors.h"
36 #include "lib/ldb/include/ldb_private.h"
38 /* add_record: do things with the sambaPassword attribute */
39 static int wins_ldb_verify(struct ldb_module *module, struct ldb_request *req, const struct ldb_message *msg)
41 struct winsdb_handle *h = talloc_get_type(ldb_get_opaque(module->ldb, "winsdb_handle"),
42 struct winsdb_handle);
46 error = talloc_strdup(module, "WINS_LDB: INTERNAL ERROR: no winsdb_handle present!");
47 ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s", error);
48 ldb_set_errstring(module->ldb, error);
53 case WINSDB_HANDLE_CALLER_NBTD:
54 case WINSDB_HANDLE_CALLER_WREPL:
55 /* we trust our nbt and wrepl code ... */
56 return ldb_next_request(module, req);
58 case WINSDB_HANDLE_CALLER_ADMIN:
59 error = talloc_strdup(module, "WINS_LDB: TODO verify add/modify for WINSDB_HANDLE_CALLER_ADMIN");
60 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "%s\n", error);
61 return ldb_next_request(module, req);
67 static int wins_ldb_request(struct ldb_module *module, struct ldb_request *req)
69 const struct ldb_message *msg = req->op.mod.message;
71 switch (req->operation) {
73 msg = req->op.add.message;
77 msg = req->op.mod.message;
84 if (ldb_dn_is_special(msg->dn)) goto call_next;
86 return wins_ldb_verify(module, req, msg);
89 return ldb_next_request(module, req);
92 static const struct ldb_module_ops wins_ldb_ops = {
94 .request = wins_ldb_request
98 /* the init function */
99 struct ldb_module *wins_ldb_module_init(struct ldb_context *ldb, const char *options[])
101 struct ldb_module *ctx;
102 struct winsdb_handle *h;
106 ctx = talloc(ldb, struct ldb_module);
107 if (!ctx) return NULL;
109 ctx->private_data = NULL;
111 ctx->prev = ctx->next = NULL;
112 ctx->ops = &wins_ldb_ops;
114 owner = lp_parm_string(-1, "winsdb", "local_owner");
116 owner = iface_n_ip(0);
122 h = talloc(ctx, struct winsdb_handle);
125 h->caller = WINSDB_HANDLE_CALLER_ADMIN;
126 h->local_owner = talloc_strdup(h, owner);
127 if (!h->local_owner) goto failed;
129 ret = ldb_set_opaque(ldb, "winsdb_handle", h);
130 if (ret != LDB_SUCCESS) goto failed;