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/>.
*/
struct userdata_struct *userdata,
struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec)
{
- nstring name;
+ unstring name;
struct packet_struct *original_packet;
struct subnet_record *orig_broadcast_subnet;
- struct name_record *namerec;
+ struct name_record *namerec = NULL;
uint16 nb_flags;
int num_ips;
int i;
memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)],
sizeof(struct packet_struct *) );
- nb_flags = get_nb_flags( rrec->rdata );
+ if (rrec) {
+ nb_flags = get_nb_flags( rrec->rdata );
+ num_ips = rrec->rdlength / 6;
+ } else {
+ nb_flags = 0;
+ num_ips = 0;
+ }
- num_ips = rrec->rdlength / 6;
if(num_ips == 0) {
DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \
returned for name %s.\n", nmb_namestr(nmbname) ));
if(num_ips == 1) {
iplist = &ip;
} else {
- if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) {
+ if((iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL) {
DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
return;
}
- for(i = 0; i < num_ips; i++)
+ for(i = 0; i < num_ips; i++) {
putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]);
+ }
}
/* Add the queried name to the original subnet as a WINS_PROXY_NAME. */
- if(rrec == PERMANENT_TTL)
+ if(rrec->ttl == PERMANENT_TTL) {
ttl = lp_max_ttl();
+ }
- pull_ascii_nstring(name, nmbname->name);
- namerec = add_name_to_subnet( orig_broadcast_subnet, name,
+ pull_ascii_nstring(name, sizeof(name), nmbname->name);
+ add_name_to_subnet( orig_broadcast_subnet, name,
nmbname->name_type, nb_flags, ttl,
WINS_PROXY_NAME, num_ips, iplist );
- if(iplist != &ip)
+ if(iplist != &ip) {
SAFE_FREE(iplist);
+ }
+
+ namerec = find_name_on_subnet(orig_broadcast_subnet, nmbname, FIND_ANY_NAME);
+ if (!namerec) {
+ DEBUG(0,("wins_proxy_name_query_request_success: failed to add "
+ "name %s to subnet %s !\n",
+ name,
+ orig_broadcast_subnet->subnet_name ));
+ return;
+ }
/*
* Check that none of the IP addresses we are returning is on the
static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata)
{
struct packet_struct *p, *copy_of_p;
- struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len );
+ struct userdata_struct *new_userdata = (struct userdata_struct *)SMB_MALLOC( userdata->userdata_len );
if(new_userdata == NULL)
return NULL;
struct packet_struct *incoming_packet,
struct nmb_name *question_name)
{
- long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) +
- sizeof(struct packet_struct *))/sizeof(long *) + 1];
- struct userdata_struct *userdata = (struct userdata_struct *)ud;
- nstring qname;
-
- memset(ud, '\0', sizeof(ud));
+ union {
+ struct userdata_struct ud;
+ char c[sizeof(struct userdata_struct) + sizeof(struct subrec *) +
+ sizeof(struct packet_struct *)+sizeof(long*)];
+ } ud;
+ struct userdata_struct *userdata = &ud.ud;
+ unstring qname;
+
+ memset(&ud, '\0', sizeof(ud));
userdata->copy_fn = wins_proxy_userdata_copy_fn;
userdata->free_fn = wins_proxy_userdata_free_fn;
sizeof(struct packet_struct *));
/* Now use the unicast subnet to query the name with the WINS server. */
- pull_ascii_nstring(qname, question_name->name);
+ pull_ascii_nstring(qname, sizeof(qname), question_name->name);
query_name( unicast_subnet, qname, question_name->name_type,
wins_proxy_name_query_request_success,
wins_proxy_name_query_request_fail,