NBT netbios routines and daemon - version 2
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Luke Kenneth Casson Leighton 1994-1998
- Copyright (C) Jeremy Allison 1994-1998
+ Copyright (C) Jeremy Allison 1994-2003
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,
#include "includes.h"
-extern fstring global_myworkgroup;
-
/* forward declarations */
static void wins_next_registration(struct response_record *rrec);
*/
#if 1 /* OLD_SAMBA_SERVER_HACK */
- if((nmb->header.rcode == ACT_ERR) && strequal(global_myworkgroup, answer_name->name) &&
+ unstring ans_name;
+ pull_ascii_nstring(ans_name, sizeof(ans_name), answer_name->name);
+ if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), ans_name) &&
(answer_name->name_type == 0x1b)) {
/* Pretend we did not get this. */
rrec->num_msgs--;
success = False;
} else {
/* Unicast - check to see if the response allows us to have the name. */
- if(nmb->header.rcode != 0) {
- /* Error code - we didn't get the name. */
- success = False;
-
- DEBUG(0,("register_name_response: %sserver at IP %s rejected our name registration of %s IP %s with error code %d.\n",
- subrec==unicast_subnet?"WINS ":"",
- inet_ntoa(p->ip),
- nmb_namestr(answer_name),
- reg_name,
- nmb->header.rcode));
- } else if (nmb->header.opcode == NMB_WACK_OPCODE) {
+ if (nmb->header.opcode == NMB_WACK_OPCODE) {
/* WINS server is telling us to wait. Pretend we didn't get
the response but don't send out any more register requests. */
rrec->repeat_time = p->timestamp + nmb->answers->ttl;
rrec->num_msgs--;
return;
+ } else if (nmb->header.rcode != 0) {
+ /* Error code - we didn't get the name. */
+ success = False;
+
+ DEBUG(0,("register_name_response: %sserver at IP %s rejected our name registration of %s IP %s with error code %d.\n",
+ subrec==unicast_subnet?"WINS ":"",
+ inet_ntoa(p->ip),
+ nmb_namestr(answer_name),
+ reg_name,
+ nmb->header.rcode));
} else {
success = True;
/* Get the data we need to pass to the success function. */
remove_response_record(subrec, rrec);
}
-
/****************************************************************************
Deal with a timeout of a WINS registration request
****************************************************************************/
+
static void wins_registration_timeout(struct subnet_record *subrec,
struct response_record *rrec)
{
us trying to register with each of our failover wins servers */
}
-
/****************************************************************************
Deal with a timeout when registering one of our names.
****************************************************************************/
remove_response_record(subrec, rrec);
}
-
/****************************************************************************
-initiate one multi-homed name registration packet
+ Initiate one multi-homed name registration packet.
****************************************************************************/
+
static void multihomed_register_one(struct nmb_name *nmbname,
uint16 nb_flags,
register_name_success_function success_fn,
struct in_addr wins_ip = wins_srv_ip_tag(tag, ip);
fstring ip_str;
- userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1);
+ userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1);
if (!userdata) {
DEBUG(0,("Failed to allocate userdata structure!\n"));
return;
free(userdata);
}
-
/****************************************************************************
-we have finished the registration of one IP and need to see if we have
-any more IPs left to register with this group of wins server for this name
+ We have finished the registration of one IP and need to see if we have
+ any more IPs left to register with this group of wins server for this name.
****************************************************************************/
+
static void wins_next_registration(struct response_record *rrec)
{
struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
/****************************************************************************
Try and register one of our names on the unicast subnet - multihomed.
****************************************************************************/
+
static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
register_name_success_function success_fn,
register_name_fail_function fail_fn)
struct subnet_record *subrec;
char **wins_tags;
struct in_addr *ip_list;
+ unstring name;
for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
num_ips++;
- if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) {
+ if((ip_list = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) {
DEBUG(0,("multihomed_register_name: malloc fail !\n"));
return;
}
ip_list[i] = subrec->myip;
}
- add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type,
+ pull_ascii_nstring(name, sizeof(name), nmbname->name);
+ add_name_to_subnet(unicast_subnet, name, nmbname->name_type,
nb_flags, lp_max_ttl(), SELF_NAME,
num_ips, ip_list);
SAFE_FREE(ip_list);
}
-
/****************************************************************************
Try and register one of our names.
****************************************************************************/
+
void register_name(struct subnet_record *subrec,
- char *name, int type, uint16 nb_flags,
+ const char *name, int type, uint16 nb_flags,
register_name_success_function success_fn,
register_name_fail_function fail_fn,
struct userdata_struct *userdata)
{
struct nmb_name nmbname;
-
- make_nmb_name(&nmbname, name, type);
+ nstring nname;
+
+ errno = 0;
+ push_ascii_nstring(nname, name);
+ if (errno == E2BIG) {
+ unstring tname;
+ pull_ascii_nstring(tname, sizeof(tname), nname);
+ DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n",
+ name, tname));
+ make_nmb_name(&nmbname, tname, type);
+ } else {
+ make_nmb_name(&nmbname, name, type);
+ }
/* Always set the NB_ACTIVE flag on the name we are
registering. Doesn't make sense without it.
}
}
-
/****************************************************************************
Try and refresh one of our names. This is *only* called for WINS refresh
****************************************************************************/
+
void wins_refresh_name(struct name_record *namerec)
{
int t;