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"
# include "lib/events/events.h"
2006-08-30 11:29:34 +00:00
# include "lib/util/dlinklist.h"
2006-04-07 13:15:46 +00:00
# include "build.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 ,
struct event_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 ) {
ev = event_context_find ( mem_ctx ) ;
}
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 + + ) {
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
{
static BOOL initialized = False ;
init_module_fn static_init [ ] = STATIC_sys_notify_MODULES ;
init_module_fn * shared_init ;
if ( initialized ) return NT_STATUS_OK ;
initialized = True ;
shared_init = load_samba_modules ( NULL , " sys_notify " ) ;
run_init_functions ( static_init ) ;
run_init_functions ( shared_init ) ;
talloc_free ( shared_init ) ;
return NT_STATUS_OK ;
}