2006-04-03 06:46:55 +00:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Andrew Tridgell 2006
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-04-03 06:46:55 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-04-03 06:46:55 +00:00
*/
/*
abstract the various kernel interfaces to change notify into a
single Samba friendly interface
*/
# include "includes.h"
# include "system/filesys.h"
# include "ntvfs/sysdep/sys_notify.h"
2008-12-18 15:01:07 -08:00
# include "../lib/tevent/tevent.h"
2008-10-11 21:31:42 +02:00
# include "../lib/util/dlinklist.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2006-04-03 06:46:55 +00:00
/* list of registered backends */
static struct sys_notify_backend * backends ;
2006-04-05 05:54:10 +00:00
static uint32_t num_backends ;
2006-04-03 06:46:55 +00:00
2007-07-04 04:18:44 +00:00
# define NOTIFY_BACKEND "notify:backend"
2006-07-23 18:43:07 +00:00
2006-04-03 06:46:55 +00:00
/*
initialise a system change notify backend
*/
2006-07-23 18:43:07 +00:00
_PUBLIC_ struct sys_notify_context * sys_notify_context_create ( struct share_config * scfg ,
2006-04-07 14:14:27 +00:00
TALLOC_CTX * mem_ctx ,
2008-12-29 20:24:57 +01:00
struct tevent_context * ev )
2006-04-03 06:46:55 +00:00
{
struct sys_notify_context * ctx ;
const char * bname ;
2006-04-05 05:54:10 +00:00
int i ;
2006-04-03 06:46:55 +00:00
2006-04-05 05:54:10 +00:00
if ( num_backends = = 0 ) {
2006-04-05 04:50:08 +00:00
return NULL ;
}
2006-04-03 06:46:55 +00:00
if ( ev = = NULL ) {
2008-04-17 01:19:53 +02:00
return NULL ;
2006-04-03 06:46:55 +00:00
}
ctx = talloc_zero ( mem_ctx , struct sys_notify_context ) ;
if ( ctx = = NULL ) {
return NULL ;
}
ctx - > ev = ev ;
2006-07-23 18:43:07 +00:00
bname = share_string_option ( scfg , NOTIFY_BACKEND , NULL ) ;
2006-04-04 16:58:28 +00:00
if ( ! bname ) {
2006-04-05 05:54:10 +00:00
if ( num_backends ) {
bname = backends [ 0 ] . name ;
2006-04-04 16:58:28 +00:00
} else {
bname = " __unknown__ " ;
}
2006-04-03 06:46:55 +00:00
}
2006-04-05 05:54:10 +00:00
for ( i = 0 ; i < num_backends ; i + + ) {
2008-11-02 19:32:50 +01:00
char * enable_opt_name ;
bool enabled ;
enable_opt_name = talloc_asprintf ( mem_ctx , " notify:%s " ,
backends [ i ] . name ) ;
enabled = share_bool_option ( scfg , enable_opt_name , true ) ;
talloc_free ( enable_opt_name ) ;
if ( ! enabled )
continue ;
2006-04-05 05:54:10 +00:00
if ( strcasecmp ( backends [ i ] . name , bname ) = = 0 ) {
bname = backends [ i ] . name ;
2006-04-04 16:58:28 +00:00
break ;
}
2006-04-03 06:46:55 +00:00
}
2006-04-04 16:58:28 +00:00
ctx - > name = bname ;
ctx - > notify_watch = NULL ;
2006-04-05 05:54:10 +00:00
if ( i < num_backends ) {
ctx - > notify_watch = backends [ i ] . notify_watch ;
2006-04-03 06:46:55 +00:00
}
return ctx ;
}
/*
add a watch
2006-04-05 05:54:10 +00:00
note that this call must modify the e - > filter and e - > subdir_filter
bits to remove ones handled by this backend . Any remaining bits will
be handled by the generic notify layer
2006-04-03 06:46:55 +00:00
*/
2007-01-28 17:03:10 +00:00
_PUBLIC_ NTSTATUS sys_notify_watch ( struct sys_notify_context * ctx ,
struct notify_entry * e ,
sys_notify_callback_t callback ,
void * private_data , void * handle )
2006-04-03 06:46:55 +00:00
{
2006-04-04 16:58:28 +00:00
if ( ! ctx - > notify_watch ) {
2006-04-05 08:52:03 +00:00
return NT_STATUS_INVALID_SYSTEM_SERVICE ;
2006-04-04 16:58:28 +00:00
}
2007-01-28 17:03:10 +00:00
return ctx - > notify_watch ( ctx , e , callback , private_data , handle ) ;
2006-04-03 06:46:55 +00:00
}
/*
register a notify backend
*/
2006-04-07 14:14:27 +00:00
_PUBLIC_ NTSTATUS sys_notify_register ( struct sys_notify_backend * backend )
2006-04-03 06:46:55 +00:00
{
2006-04-05 05:54:10 +00:00
struct sys_notify_backend * b ;
b = talloc_realloc ( talloc_autofree_context ( ) , backends ,
struct sys_notify_backend , num_backends + 1 ) ;
NT_STATUS_HAVE_NO_MEMORY ( b ) ;
backends = b ;
backends [ num_backends ] = * backend ;
num_backends + + ;
2006-04-03 06:46:55 +00:00
return NT_STATUS_OK ;
}
2006-04-07 13:15:46 +00:00
2006-04-07 14:14:27 +00:00
_PUBLIC_ NTSTATUS sys_notify_init ( void )
2006-04-07 13:15:46 +00:00
{
2007-10-06 22:28:14 +00:00
static bool initialized = false ;
2010-11-01 15:38:37 +11:00
# define _MODULE_PROTO(init) extern NTSTATUS init(void);
STATIC_sys_notify_MODULES_PROTO ;
2007-12-24 01:28:22 -06:00
init_module_fn static_init [ ] = { STATIC_sys_notify_MODULES } ;
2006-04-07 13:15:46 +00:00
if ( initialized ) return NT_STATUS_OK ;
2007-10-06 22:28:14 +00:00
initialized = true ;
2006-04-07 13:15:46 +00:00
run_init_functions ( static_init ) ;
return NT_STATUS_OK ;
}