Line data Source code
1 : /* 2 : ldb database module 3 : 4 : Copyright (C) Stefan Metzmacher 2006 5 : 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 3 of the License, or 9 : (at your option) any later version. 10 : 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. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : /* 21 : * Name: ldb 22 : * 23 : * Component: ldb winsdb module 24 : * 25 : * Description: verify winsdb records before they're written to disk 26 : * 27 : * Author: Stefan Metzmacher 28 : */ 29 : 30 : #include "includes.h" 31 : #include "lib/events/events.h" 32 : #include "nbt_server/nbt_server.h" 33 : #include "nbt_server/wins/winsdb.h" 34 : #include <ldb_module.h> 35 : #include "system/network.h" 36 : #include "lib/socket/netif.h" 37 : #include "param/param.h" 38 : 39 1312 : static int wins_ldb_verify(struct ldb_module *module, struct ldb_request *req) 40 : { 41 1312 : struct ldb_context *ldb = ldb_module_get_ctx(module); 42 1312 : struct winsdb_handle *h = talloc_get_type(ldb_get_opaque(ldb, "winsdb_handle"), 43 : struct winsdb_handle); 44 0 : const struct ldb_message *msg; 45 : 46 1312 : switch (req->operation) { 47 208 : case LDB_ADD: 48 208 : msg = req->op.add.message; 49 208 : break; 50 : 51 1104 : case LDB_MODIFY: 52 1104 : msg = req->op.mod.message; 53 1104 : break; 54 : 55 0 : default: 56 0 : return ldb_next_request(module, req); 57 : } 58 : 59 : /* do not manipulate our control entries */ 60 1312 : if (ldb_dn_is_special(msg->dn)) { 61 0 : return ldb_next_request(module, req); 62 : } 63 : 64 1312 : if (!h) { 65 0 : ldb_debug_set(ldb, LDB_DEBUG_FATAL, "%s", "WINS_LDB: INTERNAL ERROR: no winsdb_handle present!"); 66 0 : return LDB_ERR_OTHER; 67 : } 68 : 69 1312 : switch (h->caller) { 70 1312 : case WINSDB_HANDLE_CALLER_NBTD: 71 : case WINSDB_HANDLE_CALLER_WREPL: 72 : /* we trust our nbt and wrepl code ... */ 73 1312 : return ldb_next_request(module, req); 74 : 75 0 : case WINSDB_HANDLE_CALLER_ADMIN: 76 0 : ldb_debug(ldb, LDB_DEBUG_WARNING, "%s\n", "WINS_LDB: TODO verify add/modify for WINSDB_HANDLE_CALLER_ADMIN"); 77 0 : return ldb_next_request(module, req); 78 : } 79 : 80 0 : return LDB_ERR_OTHER; 81 : } 82 : 83 139 : static int wins_ldb_init(struct ldb_module *module) 84 : { 85 139 : struct ldb_context *ldb = ldb_module_get_ctx(module); 86 4 : struct winsdb_handle *h; 87 4 : const char *owner; 88 139 : struct loadparm_context *lp_ctx = ldb_get_opaque(ldb, "loadparm"); 89 : 90 139 : ldb_module_set_private(module, NULL); 91 : 92 139 : owner = lpcfg_parm_string(lp_ctx, NULL, "winsdb", "local_owner"); 93 139 : if (!owner) { 94 4 : struct interface *ifaces; 95 139 : load_interface_list(module, lp_ctx, &ifaces); 96 139 : owner = iface_list_first_v4(ifaces); 97 139 : if (!owner) { 98 0 : owner = "0.0.0.0"; 99 : } 100 : } 101 : 102 139 : h = talloc_zero(module, struct winsdb_handle); 103 139 : if (!h) goto failed; 104 139 : h->ldb = ldb; 105 139 : h->caller = WINSDB_HANDLE_CALLER_ADMIN; 106 139 : h->local_owner = talloc_strdup(h, owner); 107 139 : if (!h->local_owner) goto failed; 108 : 109 139 : return ldb_set_opaque(ldb, "winsdb_handle", h); 110 : 111 0 : failed: 112 0 : talloc_free(h); 113 0 : return LDB_ERR_OTHER; 114 : } 115 : 116 : static const struct ldb_module_ops ldb_wins_ldb_module_ops = { 117 : .name = "wins_ldb", 118 : .add = wins_ldb_verify, 119 : .modify = wins_ldb_verify, 120 : .init_context = wins_ldb_init 121 : }; 122 : 123 6040 : int ldb_wins_ldb_module_init(const char *version) 124 : { 125 6040 : LDB_MODULE_CHECK_VERSION(version); 126 6040 : return ldb_register_module(&ldb_wins_ldb_module_ops); 127 : }