s4 dns: Add a simple dns lookup helper
[Samba/gebeck_regimport.git] / source4 / ntvfs / sysdep / sys_notify.c
blob00300cd25a6332b4111bc96f1698a25cc50040c1
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
21 abstract the various kernel interfaces to change notify into a
22 single Samba friendly interface
25 #include "includes.h"
26 #include "system/filesys.h"
27 #include "ntvfs/sysdep/sys_notify.h"
28 #include <tevent.h>
29 #include "../lib/util/dlinklist.h"
30 #include "param/param.h"
31 #include "lib/util/samba_modules.h"
33 /* list of registered backends */
34 static struct sys_notify_backend *backends;
35 static uint32_t num_backends;
37 #define NOTIFY_BACKEND "notify:backend"
40 initialise a system change notify backend
42 _PUBLIC_ struct sys_notify_context *sys_notify_context_create(struct share_config *scfg,
43 TALLOC_CTX *mem_ctx,
44 struct tevent_context *ev)
46 struct sys_notify_context *ctx;
47 const char *bname;
48 int i;
50 if (num_backends == 0) {
51 return NULL;
54 if (ev == NULL) {
55 return NULL;
58 ctx = talloc_zero(mem_ctx, struct sys_notify_context);
59 if (ctx == NULL) {
60 return NULL;
63 ctx->ev = ev;
65 bname = share_string_option(scfg, NOTIFY_BACKEND, NULL);
66 if (!bname) {
67 if (num_backends) {
68 bname = backends[0].name;
69 } else {
70 bname = "__unknown__";
74 for (i=0;i<num_backends;i++) {
75 char *enable_opt_name;
76 bool enabled;
78 enable_opt_name = talloc_asprintf(mem_ctx, "notify:%s",
79 backends[i].name);
80 enabled = share_bool_option(scfg, enable_opt_name, true);
81 talloc_free(enable_opt_name);
83 if (!enabled)
84 continue;
86 if (strcasecmp(backends[i].name, bname) == 0) {
87 bname = backends[i].name;
88 break;
92 ctx->name = bname;
93 ctx->notify_watch = NULL;
95 if (i < num_backends) {
96 ctx->notify_watch = backends[i].notify_watch;
99 return ctx;
103 add a watch
105 note that this call must modify the e->filter and e->subdir_filter
106 bits to remove ones handled by this backend. Any remaining bits will
107 be handled by the generic notify layer
109 _PUBLIC_ NTSTATUS sys_notify_watch(struct sys_notify_context *ctx,
110 struct notify_entry *e,
111 sys_notify_callback_t callback,
112 void *private_data, void *handle)
114 if (!ctx->notify_watch) {
115 return NT_STATUS_INVALID_SYSTEM_SERVICE;
117 return ctx->notify_watch(ctx, e, callback, private_data, handle);
121 register a notify backend
123 _PUBLIC_ NTSTATUS sys_notify_register(struct sys_notify_backend *backend)
125 struct sys_notify_backend *b;
126 b = talloc_realloc(talloc_autofree_context(), backends,
127 struct sys_notify_backend, num_backends+1);
128 NT_STATUS_HAVE_NO_MEMORY(b);
129 backends = b;
130 backends[num_backends] = *backend;
131 num_backends++;
132 return NT_STATUS_OK;
135 _PUBLIC_ NTSTATUS sys_notify_init(void)
137 static bool initialized = false;
138 #define _MODULE_PROTO(init) extern NTSTATUS init(void);
139 STATIC_sys_notify_MODULES_PROTO;
140 init_module_fn static_init[] = { STATIC_sys_notify_MODULES };
142 if (initialized) return NT_STATUS_OK;
143 initialized = true;
145 run_init_functions(static_init);
147 return NT_STATUS_OK;