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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
Converted to store WINS data in a tdb. Dec 2005. JRA.
*/
TDB_CONTEXT *wins_tdb;
+/****************************************************************************
+ Delete all the temporary name records on the in-memory linked list.
+*****************************************************************************/
+
+static void wins_delete_all_tmp_in_memory_records(void)
+{
+ struct name_record *nr = NULL;
+ struct name_record *nrnext = NULL;
+
+ /* Delete all temporary name records on the wins subnet linked list. */
+ for( nr = wins_server_subnet->namelist; nr; nr = nrnext) {
+ nrnext = nr->next;
+ DLIST_REMOVE(wins_server_subnet->namelist, nr);
+ SAFE_FREE(nr->data.ip);
+ SAFE_FREE(nr);
+ }
+}
+
/****************************************************************************
Convert a wins.tdb record to a struct name_record. Add in our global_scope().
*****************************************************************************/
}
namerec->subnet = wins_server_subnet;
- push_ascii_nstring(namerec->name.name, key.dptr);
+ push_ascii_nstring(namerec->name.name, (const char *)key.dptr);
namerec->name.name_type = key.dptr[sizeof(unstring)];
/* Add the scope. */
push_ascii(namerec->name.scope, global_scope(), 64, STR_TERMINATE);
len = (2 + 1 + (7*4)); /* "wbddddddd" */
len += (namerec->data.num_ips * 4);
- data.dptr = SMB_MALLOC(len);
+ data.dptr = (uint8 *)SMB_MALLOC(len);
if (!data.dptr) {
return data;
}
pull_ascii_nstring(keydata, sizeof(unstring), nmbname->name);
strupper_m(keydata);
keydata[sizeof(unstring)] = nmbname->name_type;
- key.dptr = keydata;
+ key.dptr = (uint8 *)keydata;
key.dsize = sizeof(keydata);
return key;
on the linked list. We will free this later in XXXX().
*****************************************************************************/
-struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOOL self_only)
+struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, bool self_only)
{
TDB_DATA data, key;
struct name_record *nr = NULL;
return NULL;
}
+ /* Self names only - these include permanent names. */
+ if( self_only && (namerec->data.source != SELF_NAME) && (namerec->data.source != PERMANENT_NAME) ) {
+ DEBUG( 9, ( "find_name_on_wins_subnet: self name %s NOT FOUND\n", nmb_namestr(nmbname) ) );
+ SAFE_FREE(namerec->data.ip);
+ SAFE_FREE(namerec);
+ return NULL;
+ }
+
/* Search for this name record on the list. Replace it if found. */
for( nr = wins_server_subnet->namelist; nr; nr = nr->next) {
Overwrite or add a given name in the wins.tdb.
*****************************************************************************/
-static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag)
+static bool store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag)
{
TDB_DATA key, data;
int ret;
Overwrite a given name in the wins.tdb.
*****************************************************************************/
-BOOL wins_store_changed_namerec(const struct name_record *namerec)
+bool wins_store_changed_namerec(const struct name_record *namerec)
{
return store_or_replace_wins_namerec(namerec, TDB_REPLACE);
}
Primary interface into creating and overwriting records in the wins.tdb.
*****************************************************************************/
-BOOL add_name_to_wins_subnet(const struct name_record *namerec)
+bool add_name_to_wins_subnet(const struct name_record *namerec)
{
return store_or_replace_wins_namerec(namerec, TDB_INSERT);
}
on the linked list.
*****************************************************************************/
-BOOL remove_name_from_wins_namelist(struct name_record *namerec)
+bool remove_name_from_wins_namelist(struct name_record *namerec)
{
TDB_DATA key;
int ret;
Return the general ID value and increase it if requested.
*****************************************************************************/
-static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update)
+static void get_global_id_and_update(SMB_BIG_UINT *current_id, bool update)
{
/*
* it's kept as a static here, to prevent people from messing
Determine if this packet should be allocated to the WINS server.
*****************************************************************************/
-BOOL packet_is_for_wins_server(struct packet_struct *packet)
+bool packet_is_for_wins_server(struct packet_struct *packet)
{
struct nmb_packet *nmb = &packet->packet.nmb;
Load or create the WINS database.
*****************************************************************************/
-BOOL initialise_wins(void)
+bool initialise_wins(void)
{
time_t time_now = time(NULL);
XFILE *fp;
int ttl;
const char *ptr;
char *p;
- BOOL got_token;
- BOOL was_ip;
+ bool got_token;
+ bool was_ip;
int i;
unsigned int hash;
int version;
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
- BOOL group = (nb_flags & NB_GROUP) ? True : False;
+ bool group = (nb_flags & NB_GROUP) ? True : False;
struct name_record *namerec = NULL;
int ttl = get_ttl_from_packet(nmb);
struct in_addr from_ip;
unstring name;
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
int ttl = get_ttl_from_packet(nmb);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;
+ bool registering_group_name = (nb_flags & NB_GROUP) ? True : False;
struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
putip((char *)&from_ip,&nmb->additional->rdata[2]);
if ( namerec != NULL ) {
pull_ascii_nstring(name, sizeof(name), namerec->name.name);
if( is_myname(name) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
int ttl = get_ttl_from_packet(nmb);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL group = (nb_flags & NB_GROUP) ? True : False;
+ bool group = (nb_flags & NB_GROUP) ? True : False;
struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
unstring qname;
*/
if((namerec != NULL) && (is_myname(namerec->name.name)) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
num_ips = 0;
+ /* First, clear the in memory list - we're going to re-populate
+ it with the tdb_traversal in fetch_all_active_wins_1b_names. */
+
+ wins_delete_all_tmp_in_memory_records();
+
fetch_all_active_wins_1b_names();
for( namerec = subrec->namelist; namerec; namerec = namerec->next ) {
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
+ bool releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
putip((char *)&from_ip,&nmb->additional->rdata[2]);
static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
time_t t = *(time_t *)state;
- BOOL store_record = False;
+ bool store_record = False;
struct name_record *namerec = NULL;
struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
/* handle records, samba is the wins owner */
if (ip_equal(namerec->data.wins_ip, our_fake_ip)) {
- switch (namerec->data.wins_flags | WINS_STATE_MASK) {
+ switch (namerec->data.wins_flags & WINS_STATE_MASK) {
case WINS_ACTIVE:
namerec->data.wins_flags&=~WINS_STATE_MASK;
namerec->data.wins_flags|=WINS_RELEASED;
goto done;
}
} else {
- switch (namerec->data.wins_flags | WINS_STATE_MASK) {
+ switch (namerec->data.wins_flags & WINS_STATE_MASK) {
case WINS_ACTIVE:
/* that's not as MS says it should be */
namerec->data.wins_flags&=~WINS_STATE_MASK;
void initiate_wins_processing(time_t t)
{
static time_t lasttime = 0;
- struct name_record *nr = NULL;
- struct name_record *nrnext = NULL;
if (!lasttime) {
lasttime = t;
tdb_traverse(wins_tdb, wins_processing_traverse_fn, &t);
-
- /* Delete all temporary name records on the wins subnet linked list. */
- for( nr = wins_server_subnet->namelist; nr; nr = nrnext) {
- nrnext = nr->next;
- DLIST_REMOVE(wins_server_subnet->namelist, nr);
- SAFE_FREE(nr->data.ip);
- SAFE_FREE(nr);
- }
+ wins_delete_all_tmp_in_memory_records();
wins_write_database(t, True);
}
-void wins_write_database(time_t t, BOOL background)
+void wins_write_database(time_t t, bool background)
{
static time_t last_write_time = 0;
pstring fname, fnamenew;
if (tdb_reopen(wins_tdb)) {
DEBUG(0,("wins_write_database: tdb_reopen failed. Error was %s\n",
strerror(errno)));
+ _exit(0);
return;
}
}
Process a internal Samba message receiving a wins record.
***************************************************************************/
-void nmbd_wins_new_entry(int msg_type, struct process_id src,
- void *buf, size_t len)
+void nmbd_wins_new_entry(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id server_id,
+ DATA_BLOB *data)
{
WINS_RECORD *record;
struct name_record *namerec = NULL;
struct name_record *new_namerec = NULL;
struct nmb_name question;
- BOOL overwrite=False;
+ bool overwrite=False;
struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
int i;