2005-02-12 14:33:42 +03:00
/*
Unix SMB / CIFS implementation .
WINS database routines
Copyright ( C ) Andrew Tridgell 2005
2005-12-13 22:45:24 +03:00
Copyright ( C ) Stefan Metzmacher 2005
2005-02-12 14:33:42 +03:00
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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
# include "nbt_server/nbt_server.h"
2005-02-19 02:53:52 +03:00
# include "nbt_server/wins/winsdb.h"
2005-02-12 14:33:42 +03:00
# include "lib/ldb/include/ldb.h"
2005-09-24 19:42:15 +04:00
# include "lib/ldb/include/ldb_errors.h"
2005-02-14 08:00:22 +03:00
# include "system/time.h"
2005-12-28 18:38:36 +03:00
# include "auth/auth.h"
2005-02-12 14:33:42 +03:00
2006-01-02 17:27:54 +03:00
uint64_t winsdb_get_maxVersion ( struct winsdb_handle * h )
{
int ret ;
struct ldb_context * ldb = h - > ldb ;
struct ldb_dn * dn ;
struct ldb_result * res = NULL ;
TALLOC_CTX * tmp_ctx = talloc_new ( ldb ) ;
uint64_t maxVersion = 0 ;
dn = ldb_dn_explode ( tmp_ctx , " CN=VERSION " ) ;
if ( ! dn ) goto failed ;
/* find the record in the WINS database */
ret = ldb_search ( ldb , dn , LDB_SCOPE_BASE ,
NULL , NULL , & res ) ;
if ( ret ! = LDB_SUCCESS ) goto failed ;
talloc_steal ( tmp_ctx , res ) ;
if ( res - > count > 1 ) goto failed ;
if ( res - > count = = 1 ) {
maxVersion = ldb_msg_find_uint64 ( res - > msgs [ 0 ] , " maxVersion " , 0 ) ;
}
failed :
talloc_free ( tmp_ctx ) ;
return maxVersion ;
}
2005-02-16 18:19:49 +03:00
/*
2006-01-02 17:27:54 +03:00
if newVersion = = 0 return the old maxVersion + 1 and save it
if newVersion > 0 return MAX ( oldMaxVersion , newMaxVersion ) and save it
2005-02-16 18:19:49 +03:00
*/
2006-01-02 17:27:54 +03:00
uint64_t winsdb_set_maxVersion ( struct winsdb_handle * h , uint64_t newMaxVersion )
2005-02-16 18:19:49 +03:00
{
2005-10-14 18:02:47 +04:00
int trans ;
2005-10-14 16:47:57 +04:00
int ret ;
struct ldb_dn * dn ;
2005-11-08 03:11:45 +03:00
struct ldb_result * res = NULL ;
2005-10-14 16:47:57 +04:00
struct ldb_message * msg = NULL ;
2005-12-30 23:08:52 +03:00
struct ldb_context * wins_db = h - > ldb ;
2005-11-23 14:34:46 +03:00
TALLOC_CTX * tmp_ctx = talloc_new ( wins_db ) ;
2006-01-02 17:27:54 +03:00
uint64_t oldMaxVersion = 0 ;
2005-02-16 18:19:49 +03:00
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_start ( wins_db ) ;
2005-10-14 18:02:47 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-16 18:19:49 +03:00
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
dn = ldb_dn_explode ( tmp_ctx , " CN=VERSION " ) ;
if ( ! dn ) goto failed ;
2005-02-16 18:19:49 +03:00
2005-10-14 18:02:47 +04:00
/* find the record in the WINS database */
2005-11-23 14:34:46 +03:00
ret = ldb_search ( wins_db , dn , LDB_SCOPE_BASE , NULL , NULL , & res ) ;
2005-11-08 03:11:45 +03:00
if ( ret ! = LDB_SUCCESS ) goto failed ;
if ( res - > count > 1 ) goto failed ;
2005-10-14 18:02:47 +04:00
2005-11-08 03:11:45 +03:00
talloc_steal ( tmp_ctx , res ) ;
if ( res - > count = = 1 ) {
2006-01-02 17:27:54 +03:00
oldMaxVersion = ldb_msg_find_uint64 ( res - > msgs [ 0 ] , " maxVersion " , 0 ) ;
}
if ( newMaxVersion = = 0 ) {
newMaxVersion = oldMaxVersion + 1 ;
} else {
newMaxVersion = MAX ( oldMaxVersion , newMaxVersion ) ;
2005-02-16 18:19:49 +03:00
}
2005-10-14 16:47:57 +04:00
msg = ldb_msg_new ( tmp_ctx ) ;
if ( ! msg ) goto failed ;
msg - > dn = dn ;
2005-10-14 18:02:47 +04:00
ret = ldb_msg_add_empty ( msg , " objectClass " , LDB_FLAG_MOD_REPLACE ) ;
if ( ret ! = 0 ) goto failed ;
ret = ldb_msg_add_string ( msg , " objectClass " , " winsMaxVersion " ) ;
if ( ret ! = 0 ) goto failed ;
ret = ldb_msg_add_empty ( msg , " maxVersion " , LDB_FLAG_MOD_REPLACE ) ;
2005-10-14 16:47:57 +04:00
if ( ret ! = 0 ) goto failed ;
2006-01-02 17:27:54 +03:00
ret = ldb_msg_add_fmt ( msg , " maxVersion " , " %llu " , ( long long ) newMaxVersion ) ;
2005-10-14 16:47:57 +04:00
if ( ret ! = 0 ) goto failed ;
2005-02-16 18:19:49 +03:00
2005-11-23 14:34:46 +03:00
ret = ldb_modify ( wins_db , msg ) ;
if ( ret ! = 0 ) ret = ldb_add ( wins_db , msg ) ;
2005-02-16 18:19:49 +03:00
if ( ret ! = 0 ) goto failed ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_commit ( wins_db ) ;
2005-10-14 18:02:47 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-16 18:19:49 +03:00
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
talloc_free ( tmp_ctx ) ;
2006-01-02 17:27:54 +03:00
return newMaxVersion ;
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
2005-02-16 18:19:49 +03:00
failed :
2005-11-23 14:34:46 +03:00
if ( trans = = LDB_SUCCESS ) ldb_transaction_cancel ( wins_db ) ;
2005-10-14 16:47:57 +04:00
talloc_free ( tmp_ctx ) ;
return 0 ;
2005-02-16 18:19:49 +03:00
}
2006-01-02 17:27:54 +03:00
uint64_t winsdb_get_seqnumber ( struct winsdb_handle * h )
{
int ret ;
struct ldb_context * ldb = h - > ldb ;
struct ldb_dn * dn ;
struct ldb_result * res = NULL ;
TALLOC_CTX * tmp_ctx = talloc_new ( ldb ) ;
uint64_t seqnumber = 0 ;
dn = ldb_dn_explode ( tmp_ctx , " @BASEINFO " ) ;
if ( ! dn ) goto failed ;
/* find the record in the WINS database */
ret = ldb_search ( ldb , dn , LDB_SCOPE_BASE ,
NULL , NULL , & res ) ;
if ( ret ! = LDB_SUCCESS ) goto failed ;
talloc_steal ( tmp_ctx , res ) ;
if ( res - > count > 1 ) goto failed ;
if ( res - > count = = 1 ) {
seqnumber = ldb_msg_find_uint64 ( res - > msgs [ 0 ] , " sequenceNumber " , 0 ) ;
}
failed :
talloc_free ( tmp_ctx ) ;
return seqnumber ;
}
2005-02-16 18:19:49 +03:00
/*
2005-10-14 16:51:36 +04:00
return a DN for a nbt_name
2005-02-16 18:19:49 +03:00
*/
2005-10-14 16:51:36 +04:00
static struct ldb_dn * winsdb_dn ( TALLOC_CTX * mem_ctx , struct nbt_name * name )
2005-02-16 18:19:49 +03:00
{
2005-10-14 16:51:36 +04:00
struct ldb_dn * dn ;
2005-10-14 16:55:59 +04:00
dn = ldb_dn_string_compose ( mem_ctx , NULL , " type=0x%02X " , name - > type ) ;
2005-10-14 16:51:36 +04:00
if ( dn & & name - > name & & * name - > name ) {
dn = ldb_dn_string_compose ( mem_ctx , dn , " name=%s " , name - > name ) ;
}
if ( dn & & name - > scope & & * name - > scope ) {
dn = ldb_dn_string_compose ( mem_ctx , dn , " scope=%s " , name - > scope ) ;
2005-02-16 18:19:49 +03:00
}
2005-10-14 16:51:36 +04:00
return dn ;
2005-02-16 18:19:49 +03:00
}
2005-10-14 16:55:59 +04:00
static NTSTATUS winsdb_nbt_name ( TALLOC_CTX * mem_ctx , struct ldb_dn * dn , struct nbt_name * * _name )
2005-10-14 16:54:26 +04:00
{
2005-10-14 16:55:59 +04:00
NTSTATUS status ;
2005-10-14 16:54:26 +04:00
struct nbt_name * name ;
uint32_t cur = 0 ;
name = talloc ( mem_ctx , struct nbt_name ) ;
2005-10-14 16:55:59 +04:00
if ( ! name ) {
status = NT_STATUS_NO_MEMORY ;
goto failed ;
}
2005-10-14 16:54:26 +04:00
if ( dn - > comp_num > 3 ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
2005-10-14 16:54:26 +04:00
goto failed ;
}
if ( dn - > comp_num > cur & & strcasecmp ( " scope " , dn - > components [ cur ] . name ) = = 0 ) {
name - > scope = talloc_steal ( name , dn - > components [ cur ] . value . data ) ;
cur + + ;
} else {
name - > scope = NULL ;
}
if ( dn - > comp_num > cur & & strcasecmp ( " name " , dn - > components [ cur ] . name ) = = 0 ) {
name - > name = talloc_steal ( name , dn - > components [ cur ] . value . data ) ;
cur + + ;
} else {
name - > name = talloc_strdup ( name , " " ) ;
2005-10-14 16:55:59 +04:00
if ( ! name - > name ) {
status = NT_STATUS_NO_MEMORY ;
goto failed ;
}
2005-10-14 16:54:26 +04:00
}
if ( dn - > comp_num > cur & & strcasecmp ( " type " , dn - > components [ cur ] . name ) = = 0 ) {
2005-10-14 16:55:59 +04:00
name - > type = strtoul ( ( char * ) dn - > components [ cur ] . value . data , NULL , 0 ) ;
2005-10-14 16:54:26 +04:00
cur + + ;
} else {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
2005-10-14 16:54:26 +04:00
goto failed ;
}
2005-10-14 16:55:59 +04:00
* _name = name ;
return NT_STATUS_OK ;
2005-10-14 16:54:26 +04:00
failed :
talloc_free ( name ) ;
2005-10-14 16:55:59 +04:00
return status ;
2005-10-14 16:54:26 +04:00
}
2005-02-16 18:19:49 +03:00
/*
2005-10-14 16:51:36 +04:00
decode the winsdb_addr ( " address " ) attribute :
" 172.31.1.1 " or
2005-10-14 16:55:59 +04:00
" 172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z; "
2005-10-14 16:51:36 +04:00
are valid records
2005-02-16 18:19:49 +03:00
*/
2005-12-31 00:12:15 +03:00
static NTSTATUS winsdb_addr_decode ( struct winsdb_handle * h , struct winsdb_record * rec , struct ldb_val * val ,
2005-10-14 17:00:36 +04:00
TALLOC_CTX * mem_ctx , struct winsdb_addr * * _addr )
2005-02-16 18:19:49 +03:00
{
2005-10-14 17:00:36 +04:00
NTSTATUS status ;
struct winsdb_addr * addr ;
2005-12-31 00:12:15 +03:00
const char * address ;
const char * wins_owner ;
const char * expire_time ;
2005-10-14 17:00:36 +04:00
char * p ;
addr = talloc ( mem_ctx , struct winsdb_addr ) ;
if ( ! addr ) {
status = NT_STATUS_NO_MEMORY ;
goto failed ;
}
address = ( char * ) val - > data ;
p = strchr ( address , ' ; ' ) ;
if ( ! p ) {
/* support old entries, with only the address */
addr - > address = talloc_steal ( addr , val - > data ) ;
2005-10-14 18:02:47 +04:00
addr - > wins_owner = talloc_reference ( addr , rec - > wins_owner ) ;
if ( ! addr - > wins_owner ) {
status = NT_STATUS_NO_MEMORY ;
goto failed ;
2005-10-14 16:51:36 +04:00
}
2005-10-14 16:50:11 +04:00
addr - > expire_time = rec - > expire_time ;
2005-10-14 16:55:59 +04:00
* _addr = addr ;
return NT_STATUS_OK ;
2005-10-14 16:50:11 +04:00
}
* p = ' \0 ' ; p + + ;
addr - > address = talloc_strdup ( addr , address ) ;
if ( ! addr - > address ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_NO_MEMORY ;
goto failed ;
2005-10-14 16:50:11 +04:00
}
if ( strncmp ( " winsOwner: " , p , 10 ) ! = 0 ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
2005-10-14 16:50:11 +04:00
}
wins_owner = p + 10 ;
p = strchr ( wins_owner , ' ; ' ) ;
if ( ! p ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
2005-10-14 16:50:11 +04:00
}
* p = ' \0 ' ; p + + ;
2005-12-31 00:12:15 +03:00
if ( strcmp ( wins_owner , " 0.0.0.0 " ) = = 0 ) {
wins_owner = h - > local_owner ;
}
2005-10-14 16:50:11 +04:00
addr - > wins_owner = talloc_strdup ( addr , wins_owner ) ;
if ( ! addr - > wins_owner ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_NO_MEMORY ;
goto failed ;
2005-10-14 16:50:11 +04:00
}
if ( strncmp ( " expireTime: " , p , 11 ) ! = 0 ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
2005-10-14 16:50:11 +04:00
}
expire_time = p + 11 ;
2005-10-14 16:55:59 +04:00
p = strchr ( expire_time , ' ; ' ) ;
if ( ! p ) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
}
2005-10-14 16:50:11 +04:00
2005-10-14 16:55:59 +04:00
* p = ' \0 ' ; p + + ;
2005-10-14 18:02:47 +04:00
addr - > expire_time = ldb_string_to_time ( expire_time ) ;
2005-10-14 16:49:55 +04:00
2005-10-14 16:55:59 +04:00
* _addr = addr ;
return NT_STATUS_OK ;
failed :
talloc_free ( addr ) ;
return status ;
2005-10-14 16:49:36 +04:00
}
2005-10-14 16:50:11 +04:00
/*
encode the winsdb_addr ( " address " ) attribute like this :
2005-10-14 16:55:59 +04:00
" 172.31.1.1;winsOwner:172.31.9.202;expireTime:20050923032330.0Z; "
2005-10-14 16:50:11 +04:00
*/
2005-10-14 18:02:47 +04:00
static int ldb_msg_add_winsdb_addr ( struct ldb_message * msg ,
2005-10-14 16:49:55 +04:00
const char * attr_name , struct winsdb_addr * addr )
2005-10-14 16:49:36 +04:00
{
struct ldb_val val ;
2005-10-14 16:50:11 +04:00
const char * str ;
2006-01-07 13:56:55 +03:00
char * expire_time ;
2005-10-14 16:50:11 +04:00
2006-01-07 13:56:55 +03:00
expire_time = ldb_timestring ( msg , addr - > expire_time ) ;
if ( ! expire_time ) return - 1 ;
2005-10-14 16:55:59 +04:00
str = talloc_asprintf ( msg , " %s;winsOwner:%s;expireTime:%s; " ,
2005-10-14 16:50:11 +04:00
addr - > address , addr - > wins_owner ,
2006-01-07 13:56:55 +03:00
expire_time ) ;
talloc_free ( expire_time ) ;
2005-10-14 16:50:11 +04:00
if ( ! str ) return - 1 ;
2005-10-14 16:49:36 +04:00
2005-10-14 16:50:11 +04:00
val . data = discard_const_p ( uint8_t , str ) ;
val . length = strlen ( str ) ;
2005-10-14 16:49:36 +04:00
2005-10-14 18:02:47 +04:00
return ldb_msg_add_value ( msg , attr_name , & val ) ;
2005-10-14 16:49:36 +04:00
}
2005-10-14 16:49:55 +04:00
struct winsdb_addr * * winsdb_addr_list_make ( TALLOC_CTX * mem_ctx )
{
struct winsdb_addr * * addresses ;
addresses = talloc_array ( mem_ctx , struct winsdb_addr * , 1 ) ;
if ( ! addresses ) return NULL ;
addresses [ 0 ] = NULL ;
return addresses ;
}
2005-10-14 16:50:11 +04:00
struct winsdb_addr * * winsdb_addr_list_add ( struct winsdb_addr * * addresses , const char * address ,
const char * wins_owner , time_t expire_time )
2005-10-14 16:49:55 +04:00
{
size_t len = winsdb_addr_list_length ( addresses ) ;
addresses = talloc_realloc ( addresses , addresses , struct winsdb_addr * , len + 2 ) ;
if ( ! addresses ) return NULL ;
addresses [ len ] = talloc ( addresses , struct winsdb_addr ) ;
if ( ! addresses [ len ] ) {
talloc_free ( addresses ) ;
return NULL ;
}
addresses [ len ] - > address = talloc_strdup ( addresses [ len ] , address ) ;
if ( ! addresses [ len ] - > address ) {
talloc_free ( addresses ) ;
2005-10-14 16:50:11 +04:00
return NULL ;
2005-10-14 16:49:55 +04:00
}
2005-10-14 16:50:11 +04:00
addresses [ len ] - > wins_owner = talloc_strdup ( addresses [ len ] , wins_owner ) ;
if ( ! addresses [ len ] - > wins_owner ) {
talloc_free ( addresses ) ;
return NULL ;
}
addresses [ len ] - > expire_time = expire_time ;
2005-10-14 16:49:55 +04:00
addresses [ len + 1 ] = NULL ;
return addresses ;
}
void winsdb_addr_list_remove ( struct winsdb_addr * * addresses , const char * address )
{
size_t i ;
for ( i = 0 ; addresses [ i ] ; i + + ) {
if ( strcmp ( addresses [ i ] - > address , address ) = = 0 ) {
break ;
}
}
if ( ! addresses [ i ] ) return ;
for ( ; addresses [ i ] ; i + + ) {
addresses [ i ] = addresses [ i + 1 ] ;
}
return ;
}
struct winsdb_addr * winsdb_addr_list_check ( struct winsdb_addr * * addresses , const char * address )
{
size_t i ;
for ( i = 0 ; addresses [ i ] ; i + + ) {
if ( strcmp ( addresses [ i ] - > address , address ) = = 0 ) {
return addresses [ i ] ;
}
}
return NULL ;
}
size_t winsdb_addr_list_length ( struct winsdb_addr * * addresses )
{
size_t i ;
for ( i = 0 ; addresses [ i ] ; i + + ) ;
return i ;
}
const char * * winsdb_addr_string_list ( TALLOC_CTX * mem_ctx , struct winsdb_addr * * addresses )
{
size_t len = winsdb_addr_list_length ( addresses ) ;
2005-12-28 07:55:53 +03:00
const char * * str_list = NULL ;
2005-10-14 16:49:55 +04:00
size_t i ;
for ( i = 0 ; i < len ; i + + ) {
2005-12-28 07:55:53 +03:00
str_list = str_list_add ( str_list , addresses [ i ] - > address ) ;
2005-10-14 16:49:55 +04:00
if ( ! str_list [ i ] ) {
return NULL ;
}
}
2005-12-28 07:55:53 +03:00
talloc_steal ( mem_ctx , str_list ) ;
2005-10-14 16:49:55 +04:00
return str_list ;
}
2005-02-12 14:33:42 +03:00
/*
load a WINS entry from the database
*/
2005-12-30 23:08:52 +03:00
NTSTATUS winsdb_lookup ( struct winsdb_handle * h ,
2005-10-14 16:55:59 +04:00
struct nbt_name * name ,
TALLOC_CTX * mem_ctx ,
struct winsdb_record * * _rec )
2005-02-12 14:33:42 +03:00
{
2005-10-14 16:55:59 +04:00
NTSTATUS status ;
2005-11-08 03:11:45 +03:00
struct ldb_result * res = NULL ;
2005-02-12 14:33:42 +03:00
int ret ;
struct winsdb_record * rec ;
2005-12-30 23:08:52 +03:00
struct ldb_context * wins_db = h - > ldb ;
2005-02-12 14:33:42 +03:00
TALLOC_CTX * tmp_ctx = talloc_new ( mem_ctx ) ;
/* find the record in the WINS database */
2005-10-14 16:55:59 +04:00
ret = ldb_search ( wins_db , winsdb_dn ( tmp_ctx , name ) , LDB_SCOPE_BASE ,
2005-09-16 07:18:49 +04:00
NULL , NULL , & res ) ;
2005-11-08 03:11:45 +03:00
if ( ret ! = LDB_SUCCESS | | res - > count > 1 ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
2005-11-08 03:11:45 +03:00
} else if ( res - > count = = 0 ) {
status = NT_STATUS_OBJECT_NAME_NOT_FOUND ;
goto failed ;
2005-10-14 16:55:59 +04:00
}
2005-02-12 14:33:42 +03:00
2005-11-08 03:11:45 +03:00
talloc_steal ( tmp_ctx , res ) ;
2005-12-31 00:12:15 +03:00
status = winsdb_record ( h , res - > msgs [ 0 ] , tmp_ctx , & rec ) ;
2005-10-14 16:55:59 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) goto failed ;
2005-10-14 16:53:50 +04:00
/* see if it has already expired */
2005-10-14 18:02:47 +04:00
if ( rec - > state = = WREPL_STATE_ACTIVE & &
2005-10-14 16:53:50 +04:00
rec - > expire_time < = time ( NULL ) ) {
DEBUG ( 5 , ( " WINS: expiring name %s (expired at %s) \n " ,
nbt_name_string ( tmp_ctx , rec - > name ) , timestring ( tmp_ctx , rec - > expire_time ) ) ) ;
2005-10-14 18:02:47 +04:00
rec - > state = WREPL_STATE_RELEASED ;
2005-10-14 16:53:50 +04:00
}
talloc_steal ( mem_ctx , rec ) ;
talloc_free ( tmp_ctx ) ;
2005-10-14 16:55:59 +04:00
* _rec = rec ;
return NT_STATUS_OK ;
2005-10-14 16:53:50 +04:00
failed :
talloc_free ( tmp_ctx ) ;
2005-10-14 16:55:59 +04:00
return status ;
2005-10-14 16:53:50 +04:00
}
2005-12-31 00:12:15 +03:00
NTSTATUS winsdb_record ( struct winsdb_handle * h , struct ldb_message * msg , TALLOC_CTX * mem_ctx , struct winsdb_record * * _rec )
2005-10-14 16:53:50 +04:00
{
2005-10-14 16:55:59 +04:00
NTSTATUS status ;
2005-10-14 16:53:50 +04:00
struct winsdb_record * rec ;
struct ldb_message_element * el ;
2005-12-02 18:30:25 +03:00
struct nbt_name * name ;
2005-11-23 14:34:46 +03:00
uint32_t i , num_values ;
2005-10-14 16:53:50 +04:00
rec = talloc ( mem_ctx , struct winsdb_record ) ;
2005-10-14 16:55:59 +04:00
if ( rec = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto failed ;
}
2005-12-02 18:30:25 +03:00
status = winsdb_nbt_name ( rec , msg - > dn , & name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) goto failed ;
2005-02-12 14:33:42 +03:00
2005-10-14 18:02:47 +04:00
if ( strlen ( name - > name ) > 15 ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
}
2005-10-14 18:02:47 +04:00
if ( name - > scope & & strlen ( name - > scope ) > 238 ) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
2005-10-14 16:57:23 +04:00
goto failed ;
}
/* parse it into a more convenient winsdb_record structure */
2005-10-14 18:02:47 +04:00
rec - > name = name ;
rec - > type = ldb_msg_find_int ( msg , " recordType " , WREPL_TYPE_UNIQUE ) ;
rec - > state = ldb_msg_find_int ( msg , " recordState " , WREPL_STATE_RELEASED ) ;
rec - > node = ldb_msg_find_int ( msg , " nodeType " , WREPL_NODE_B ) ;
rec - > is_static = ldb_msg_find_int ( msg , " isStatic " , 0 ) ;
rec - > expire_time = ldb_string_to_time ( ldb_msg_find_string ( msg , " expireTime " , NULL ) ) ;
rec - > version = ldb_msg_find_uint64 ( msg , " versionID " , 0 ) ;
rec - > wins_owner = ldb_msg_find_string ( msg , " winsOwner " , NULL ) ;
rec - > registered_by = ldb_msg_find_string ( msg , " registeredBy " , NULL ) ;
2005-10-14 16:57:23 +04:00
talloc_steal ( rec , rec - > wins_owner ) ;
talloc_steal ( rec , rec - > registered_by ) ;
2005-12-31 00:12:15 +03:00
if ( ! rec - > wins_owner | | strcmp ( rec - > wins_owner , " 0.0.0.0 " ) = = 0 ) {
rec - > wins_owner = h - > local_owner ;
2005-10-14 18:02:47 +04:00
}
2005-10-14 16:57:23 +04:00
el = ldb_msg_find_element ( msg , " address " ) ;
2005-11-23 14:34:46 +03:00
if ( el ) {
num_values = el - > num_values ;
} else {
num_values = 0 ;
2005-10-14 16:57:23 +04:00
}
2005-10-14 18:02:47 +04:00
if ( rec - > type = = WREPL_TYPE_UNIQUE | | rec - > type = = WREPL_TYPE_GROUP ) {
2005-11-23 14:34:46 +03:00
if ( num_values ! = 1 ) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
}
}
if ( rec - > state = = WREPL_STATE_ACTIVE ) {
if ( num_values < 1 ) {
2005-10-14 18:02:47 +04:00
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
}
2005-10-14 16:57:00 +04:00
}
2005-12-31 00:25:38 +03:00
if ( num_values > 25 ) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION ;
goto failed ;
}
2005-10-14 16:57:00 +04:00
2005-11-23 14:34:46 +03:00
rec - > addresses = talloc_array ( rec , struct winsdb_addr * , num_values + 1 ) ;
2005-10-14 16:57:00 +04:00
if ( rec - > addresses = = NULL ) {
2005-10-14 16:55:59 +04:00
status = NT_STATUS_NO_MEMORY ;
goto failed ;
}
2005-02-12 14:33:42 +03:00
2005-11-23 14:34:46 +03:00
for ( i = 0 ; i < num_values ; i + + ) {
2005-12-31 00:12:15 +03:00
status = winsdb_addr_decode ( h , rec , & el - > values [ i ] , rec - > addresses , & rec - > addresses [ i ] ) ;
2005-10-14 16:55:59 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) goto failed ;
2005-02-12 14:33:42 +03:00
}
rec - > addresses [ i ] = NULL ;
2006-01-08 23:57:26 +03:00
if ( rec - > is_static & & rec - > state = = WREPL_STATE_ACTIVE ) {
2005-12-22 12:56:14 +03:00
rec - > expire_time = get_time_t_max ( ) ;
for ( i = 0 ; rec - > addresses [ i ] ; i + + ) {
rec - > addresses [ i ] - > expire_time = rec - > expire_time ;
}
}
2005-10-14 16:55:59 +04:00
* _rec = rec ;
return NT_STATUS_OK ;
2005-02-12 14:33:42 +03:00
failed :
2005-10-14 16:55:59 +04:00
if ( NT_STATUS_EQUAL ( NT_STATUS_INTERNAL_DB_CORRUPTION , status ) ) {
DEBUG ( 1 , ( " winsdb_record: corrupted record: %s \n " , ldb_dn_linearize ( rec , msg - > dn ) ) ) ;
}
2005-10-14 16:53:50 +04:00
talloc_free ( rec ) ;
2005-10-14 16:55:59 +04:00
return status ;
2005-02-12 14:33:42 +03:00
}
/*
form a ldb_message from a winsdb_record
*/
2005-10-14 16:53:50 +04:00
struct ldb_message * winsdb_message ( struct ldb_context * ldb ,
struct winsdb_record * rec , TALLOC_CTX * mem_ctx )
2005-02-12 14:33:42 +03:00
{
int i , ret = 0 ;
2005-11-25 13:46:38 +03:00
size_t addr_count ;
2006-01-07 13:56:55 +03:00
const char * expire_time ;
2005-02-12 14:33:42 +03:00
struct ldb_message * msg = ldb_msg_new ( mem_ctx ) ;
2006-01-08 23:57:26 +03:00
if ( msg = = NULL ) goto failed ;
2005-02-12 14:33:42 +03:00
2006-01-08 23:57:26 +03:00
if ( rec - > is_static & & rec - > state = = WREPL_STATE_ACTIVE ) {
2005-12-22 12:56:14 +03:00
rec - > expire_time = get_time_t_max ( ) ;
for ( i = 0 ; rec - > addresses [ i ] ; i + + ) {
rec - > addresses [ i ] - > expire_time = rec - > expire_time ;
}
}
2005-11-25 13:46:38 +03:00
/* make sure we don't put in corrupted records */
addr_count = winsdb_addr_list_length ( rec - > addresses ) ;
if ( rec - > state = = WREPL_STATE_ACTIVE & & addr_count = = 0 ) {
rec - > state = WREPL_STATE_RELEASED ;
}
2005-12-05 15:18:16 +03:00
if ( rec - > type = = WREPL_TYPE_UNIQUE & & addr_count > 1 ) {
rec - > type = WREPL_TYPE_MHOMED ;
}
2005-11-25 13:46:38 +03:00
2006-01-07 13:56:55 +03:00
expire_time = ldb_timestring ( msg , rec - > expire_time ) ;
if ( ! expire_time ) {
goto failed ;
}
2005-09-16 07:18:49 +04:00
msg - > dn = winsdb_dn ( msg , rec - > name ) ;
2005-02-12 14:33:42 +03:00
if ( msg - > dn = = NULL ) goto failed ;
2005-10-15 14:15:42 +04:00
ret | = ldb_msg_add_fmt ( msg , " type " , " 0x%02X " , rec - > name - > type ) ;
2005-10-15 14:55:30 +04:00
if ( rec - > name - > name & & * rec - > name - > name ) {
2005-10-15 14:15:42 +04:00
ret | = ldb_msg_add_string ( msg , " name " , rec - > name - > name ) ;
}
2005-10-15 14:55:30 +04:00
if ( rec - > name - > scope & & * rec - > name - > scope ) {
2005-10-15 14:15:42 +04:00
ret | = ldb_msg_add_string ( msg , " scope " , rec - > name - > scope ) ;
}
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
ret | = ldb_msg_add_fmt ( msg , " objectClass " , " winsRecord " ) ;
ret | = ldb_msg_add_fmt ( msg , " recordType " , " %u " , rec - > type ) ;
ret | = ldb_msg_add_fmt ( msg , " recordState " , " %u " , rec - > state ) ;
ret | = ldb_msg_add_fmt ( msg , " nodeType " , " %u " , rec - > node ) ;
ret | = ldb_msg_add_fmt ( msg , " isStatic " , " %u " , rec - > is_static ) ;
2006-01-07 13:56:55 +03:00
ret | = ldb_msg_add_string ( msg , " expireTime " , expire_time ) ;
2005-11-30 05:08:15 +03:00
ret | = ldb_msg_add_fmt ( msg , " versionID " , " %llu " , ( long long ) rec - > version ) ;
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
ret | = ldb_msg_add_string ( msg , " winsOwner " , rec - > wins_owner ) ;
2005-11-25 13:46:38 +03:00
ret | = ldb_msg_add_empty ( msg , " address " , 0 ) ;
2005-02-12 14:33:42 +03:00
for ( i = 0 ; rec - > addresses [ i ] ; i + + ) {
r11048: r10539@SERNOX: metze | 2005-09-27 14:59:47 +0200
fix the build for changes from SAMBA_4_0 branch
metze
r10541@SERNOX: metze | 2005-09-27 15:05:33 +0200
use a transaction when we allocate a new version
metze
r10549@SERNOX: metze | 2005-09-27 18:58:37 +0200
- add first start of wins pull replication
- we not yet apply records to our database but we fetch them correct form our partners
(we need conflict handling for this)
- we also need to filter out our own records!
metze
r10568@SERNOX: metze | 2005-09-28 11:33:04 +0200
move composite helpers to a seperate file, create a a seperate file for the conflict resolving logic
metze
r10571@SERNOX: metze | 2005-09-28 12:00:17 +0200
add forward declarations...to fix the build
metze
r10612@SERNOX: metze | 2005-09-29 16:11:06 +0200
we have a nbt_name now, and don't need to parse it
metze
r10614@SERNOX: metze | 2005-09-29 16:38:35 +0200
filter out our own records
metze
r10620@SERNOX: metze | 2005-09-29 18:07:08 +0200
- handle mutliple addresses in WREPL_REPL_SEND_REPLY
- make strings always valid talloc pointers
metze
r10621@SERNOX: metze | 2005-09-29 18:09:41 +0200
use debug level 2
metze
r10622@SERNOX: metze | 2005-09-29 18:48:05 +0200
- add one more debug message when we reply no record
- fix min max logic
metze
r10623@SERNOX: metze | 2005-09-29 20:49:06 +0200
build fixes...
metze
r10629@SERNOX: metze | 2005-09-30 00:11:41 +0200
- use seperate attributes for type, state, nodetype, is_static
... the winserver.c code needs some more updates to correctly,
create special group and multihomed registrations...
metze
r10640@SERNOX: metze | 2005-09-30 04:07:34 +0200
- add some short path for the composite helper functions
they will be used in the next commit
metze
r10642@SERNOX: metze | 2005-09-30 06:29:06 +0200
fix the build
metze
r10655@SERNOX: metze | 2005-09-30 17:36:49 +0200
- implement the WREPL_REPL_UPDATE* and WREPL_REPL_INFORM*
this includes the connection fliping into a client connection
for WREPL_REPL_UPDATE*
NOTE: I not yet found out how to get the w2k server to use INFORM against samba4
it uses inform against w2k and w2k3 but UPDATE against nt4 and samba4
what's left now is to be able to initiate INFORM and UPDATE requests to notify
our pull partners
metze
r10727@SERNOX: metze | 2005-10-05 14:11:05 +0200
fix the build
metze
r10770@SERNOX: metze | 2005-10-06 16:56:01 +0200
- move the table filling to a seperate function, will be reused later
- fix the build, wrepl_nbt_name fixes
- remove state -> update_state
metze
r10771@SERNOX: metze | 2005-10-06 17:04:48 +0200
add a function to create a wreplsrv_in_connection from a client connection
metze
r10772@SERNOX: metze | 2005-10-06 17:13:51 +0200
- make the connection code more generic to handle the pull cached connection,
push cached connection or given connections
- when we don't use a cached connection, disconnection when a pull_cycle is done
- fix the build and use the configured source ip
metze
r10773@SERNOX: metze | 2005-10-06 17:18:49 +0200
- add composite functions for push notification
metze
r10774@SERNOX: metze | 2005-10-06 17:23:46 +0200
- use periodic push notifycation, this is just for now
as it needs to be configurable and and be triggered when the local database
has changes since the last notify
- I also need to work out how to decide if the partner supports
persistent connections and WREPL_REPL_INFORM* messages
metze
r10923@SERNOX: metze | 2005-10-12 16:52:34 +0200
fix the build becuse of conflicts with main SAMBA_4_0 tree
metze
(This used to be commit 6d97dd6e50423758d081459ec551f4e04dfd818d)
2005-10-14 17:02:00 +04:00
ret | = ldb_msg_add_winsdb_addr ( msg , " address " , rec - > addresses [ i ] ) ;
2005-02-12 14:33:42 +03:00
}
2005-11-25 13:46:38 +03:00
ret | = ldb_msg_add_empty ( msg , " registeredBy " , 0 ) ;
2005-11-23 14:34:46 +03:00
if ( rec - > registered_by ) {
ret | = ldb_msg_add_string ( msg , " registeredBy " , rec - > registered_by ) ;
if ( ret ! = 0 ) goto failed ;
}
2005-02-12 14:33:42 +03:00
return msg ;
failed :
talloc_free ( msg ) ;
return NULL ;
}
/*
save a WINS record into the database
*/
2005-12-30 23:08:52 +03:00
uint8_t winsdb_add ( struct winsdb_handle * h , struct winsdb_record * rec , uint32_t flags )
2005-02-12 14:33:42 +03:00
{
struct ldb_message * msg ;
2005-12-30 23:08:52 +03:00
struct ldb_context * wins_db = h - > ldb ;
2005-11-23 14:34:46 +03:00
TALLOC_CTX * tmp_ctx = talloc_new ( wins_db ) ;
2005-09-24 19:42:15 +04:00
int trans = - 1 ;
int ret = 0 ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_start ( wins_db ) ;
2005-09-24 19:42:15 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-12 14:33:42 +03:00
2005-11-23 14:34:46 +03:00
if ( flags & WINSDB_FLAG_ALLOC_VERSION ) {
2006-01-02 17:27:54 +03:00
/* passing '0' means auto-allocate a new one */
rec - > version = winsdb_set_maxVersion ( h , 0 ) ;
2005-11-23 14:34:46 +03:00
if ( rec - > version = = 0 ) goto failed ;
}
if ( flags & WINSDB_FLAG_TAKE_OWNERSHIP ) {
2005-12-31 00:12:15 +03:00
rec - > wins_owner = h - > local_owner ;
2005-11-23 14:34:46 +03:00
}
2005-02-16 18:19:49 +03:00
2005-11-23 14:34:46 +03:00
msg = winsdb_message ( wins_db , rec , tmp_ctx ) ;
2005-02-12 14:33:42 +03:00
if ( msg = = NULL ) goto failed ;
2005-11-23 14:34:46 +03:00
ret = ldb_add ( wins_db , msg ) ;
2005-02-12 14:33:42 +03:00
if ( ret ! = 0 ) goto failed ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_commit ( wins_db ) ;
2005-09-24 19:42:15 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-12 14:33:42 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_OK ;
failed :
2005-11-23 14:34:46 +03:00
if ( trans = = LDB_SUCCESS ) ldb_transaction_cancel ( wins_db ) ;
2005-02-12 14:33:42 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_SVR ;
}
/*
modify a WINS record in the database
*/
2005-12-30 23:08:52 +03:00
uint8_t winsdb_modify ( struct winsdb_handle * h , struct winsdb_record * rec , uint32_t flags )
2005-02-12 14:33:42 +03:00
{
struct ldb_message * msg ;
2005-12-30 23:08:52 +03:00
struct ldb_context * wins_db = h - > ldb ;
2005-11-23 14:34:46 +03:00
TALLOC_CTX * tmp_ctx = talloc_new ( wins_db ) ;
2005-09-24 19:42:15 +04:00
int trans ;
2005-02-12 14:33:42 +03:00
int ret ;
int i ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_start ( wins_db ) ;
2005-09-24 19:42:15 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-11-23 14:34:46 +03:00
if ( flags & WINSDB_FLAG_ALLOC_VERSION ) {
2006-01-02 17:27:54 +03:00
/* passing '0' means auto-allocate a new one */
rec - > version = winsdb_set_maxVersion ( h , 0 ) ;
2005-11-23 14:34:46 +03:00
if ( rec - > version = = 0 ) goto failed ;
}
if ( flags & WINSDB_FLAG_TAKE_OWNERSHIP ) {
2005-12-31 00:12:15 +03:00
rec - > wins_owner = h - > local_owner ;
2005-11-23 14:34:46 +03:00
}
2005-02-16 18:19:49 +03:00
2005-11-23 14:34:46 +03:00
msg = winsdb_message ( wins_db , rec , tmp_ctx ) ;
2005-02-12 14:33:42 +03:00
if ( msg = = NULL ) goto failed ;
for ( i = 0 ; i < msg - > num_elements ; i + + ) {
msg - > elements [ i ] . flags = LDB_FLAG_MOD_REPLACE ;
}
2005-11-23 14:34:46 +03:00
ret = ldb_modify ( wins_db , msg ) ;
2005-02-12 14:33:42 +03:00
if ( ret ! = 0 ) goto failed ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_commit ( wins_db ) ;
2005-09-24 19:42:15 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-12 14:33:42 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_OK ;
failed :
2005-11-23 14:34:46 +03:00
if ( trans = = LDB_SUCCESS ) ldb_transaction_cancel ( wins_db ) ;
2005-02-12 14:33:42 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_SVR ;
}
2005-02-14 08:00:22 +03:00
/*
delete a WINS record from the database
*/
2005-12-30 23:08:52 +03:00
uint8_t winsdb_delete ( struct winsdb_handle * h , struct winsdb_record * rec )
2005-02-14 08:00:22 +03:00
{
2005-12-30 23:08:52 +03:00
struct ldb_context * wins_db = h - > ldb ;
2005-11-23 14:34:46 +03:00
TALLOC_CTX * tmp_ctx = talloc_new ( wins_db ) ;
2005-08-18 19:02:01 +04:00
const struct ldb_dn * dn ;
2005-09-24 19:42:15 +04:00
int trans ;
int ret ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_start ( wins_db ) ;
2005-10-14 18:02:47 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-09-16 07:18:49 +04:00
dn = winsdb_dn ( tmp_ctx , rec - > name ) ;
2005-02-14 08:00:22 +03:00
if ( dn = = NULL ) goto failed ;
2005-11-23 14:34:46 +03:00
ret = ldb_delete ( wins_db , dn ) ;
2005-02-14 08:00:22 +03:00
if ( ret ! = 0 ) goto failed ;
2005-11-23 14:34:46 +03:00
trans = ldb_transaction_commit ( wins_db ) ;
2005-09-24 19:42:15 +04:00
if ( trans ! = LDB_SUCCESS ) goto failed ;
2005-02-14 08:00:22 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_OK ;
failed :
2005-11-23 14:34:46 +03:00
if ( trans = = LDB_SUCCESS ) ldb_transaction_cancel ( wins_db ) ;
2005-02-14 08:00:22 +03:00
talloc_free ( tmp_ctx ) ;
return NBT_RCODE_SVR ;
}
2005-12-30 23:08:52 +03:00
struct winsdb_handle * winsdb_connect ( TALLOC_CTX * mem_ctx )
2005-02-12 14:33:42 +03:00
{
2005-12-30 23:08:52 +03:00
struct winsdb_handle * h = NULL ;
2005-12-31 00:12:15 +03:00
const char * owner ;
2005-12-30 23:08:52 +03:00
h = talloc ( mem_ctx , struct winsdb_handle ) ;
if ( ! h ) return NULL ;
h - > ldb = ldb_wrap_connect ( h , lock_path ( h , lp_wins_url ( ) ) ,
system_session ( h ) , NULL , 0 , NULL ) ;
if ( ! h - > ldb ) goto failed ;
2005-12-31 00:12:15 +03:00
owner = lp_parm_string ( - 1 , " winsdb " , " local_owner " ) ;
if ( ! owner ) {
owner = iface_n_ip ( 0 ) ;
}
h - > local_owner = talloc_strdup ( h , owner ) ;
if ( ! h - > local_owner ) goto failed ;
2005-12-30 23:08:52 +03:00
return h ;
failed :
talloc_free ( h ) ;
return NULL ;
2005-02-12 14:33:42 +03:00
}