📄 nmbd_nameregister.c
字号:
/* wins timeouts are special */ wins_registration_timeout(subrec, rrec); return; } DEBUG(5,("register_name_timeout_response: %s in registering name %s on subnet %s.\n", success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); if(success) { /* Enter the registered name into the subnet name database before calling the success function. */ standard_success_register(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); if( rrec->success_fn) (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); } else { if( rrec->fail_fn) (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); /* Remove the name. */ standard_fail_register( subrec, rrec, question_name); } /* Ensure we don't retry. */ remove_response_record(subrec, rrec);}/**************************************************************************** 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, register_name_fail_function fail_fn, struct in_addr ip, const char *tag){ struct userdata_struct *userdata; struct in_addr wins_ip = wins_srv_ip_tag(tag, ip); fstring ip_str; userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1); if (!userdata) { DEBUG(0,("Failed to allocate userdata structure!\n")); return; } ZERO_STRUCTP(userdata); userdata->userdata_len = strlen(tag) + 1; strlcpy(userdata->data, tag, userdata->userdata_len); fstrcpy(ip_str, inet_ntoa(ip)); DEBUG(6,("Registering name %s IP %s with WINS server %s using tag '%s'\n", nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag)); if (queue_register_multihomed_name(unicast_subnet, register_name_response, register_name_timeout_response, success_fn, fail_fn, userdata, nmbname, nb_flags, ip, wins_ip) == NULL) { DEBUG(0,("multihomed_register_one: Failed to send packet trying to register name %s IP %s\n", nmb_namestr(nmbname), inet_ntoa(ip))); } 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.****************************************************************************/static void wins_next_registration(struct response_record *rrec){ struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; struct nmb_name *nmbname = &sent_nmb->question.question_name; uint16 nb_flags = get_nb_flags(sent_nmb->additional->rdata); struct userdata_struct *userdata = rrec->userdata; const char *tag; struct in_addr last_ip; struct subnet_record *subrec; putip(&last_ip,&sent_nmb->additional->rdata[2]); if (!userdata) { /* it wasn't multi-homed */ return; } tag = (const char *)userdata->data; for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { if (ip_equal(last_ip, subrec->myip)) { subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec); break; } } if (!subrec) { /* no more to do! */ return; } switch (sent_nmb->header.opcode) { case NMB_NAME_MULTIHOMED_REG_OPCODE: multihomed_register_one(nmbname, nb_flags, NULL, NULL, subrec->myip, tag); break; case NMB_NAME_REFRESH_OPCODE_8: queue_wins_refresh(nmbname, register_name_response, register_name_timeout_response, nb_flags, subrec->myip, tag); break; }}/**************************************************************************** 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){ /* If we are adding a group name, we just send multiple register name packets to the WINS server (this is an internet group name. If we are adding a unique name, We need first to add our names to the unicast subnet namelist. This is because when a WINS server receives a multihomed registration request, the first thing it does is to send a name query to the registering machine, to see if it has put the name in it's local namelist. We need the name there so the query response code in nmbd_incomingrequests.c will find it. We are adding this name prematurely (we don't really have it yet), but as this is on the unicast subnet only we will get away with this (only the WINS server will ever query names from us on this subnet). */ int num_ips=0; int i, t; 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 = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) { DEBUG(0,("multihomed_register_name: malloc fail !\n")); return; } for (subrec = FIRST_SUBNET, i = 0; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) { ip_list[i] = subrec->myip; } 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); /* get the list of wins tags - we try to register for each of them */ wins_tags = wins_srv_tags(); /* Now try and register the name for each wins tag. Note that at this point we only register our first IP with each wins group. We will register the rest from wins_next_registration() when we get the reply for this one. That follows the way W2K does things (tridge) */ for (t=0; wins_tags && wins_tags[t]; t++) { multihomed_register_one(nmbname, nb_flags, success_fn, fail_fn, ip_list[0], wins_tags[t]); } wins_srv_tags_free(wins_tags); SAFE_FREE(ip_list);}/**************************************************************************** Try and register one of our names.****************************************************************************/void register_name(struct subnet_record *subrec, 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; 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. */ nb_flags |= NB_ACTIVE; if (subrec == unicast_subnet) { /* we now always do multi-homed registration if we are registering to a WINS server. This copes much better with complex WINS setups */ multihomed_register_name(&nmbname, nb_flags, success_fn, fail_fn); return; } if (queue_register_name(subrec, register_name_response, register_name_timeout_response, success_fn, fail_fn, userdata, &nmbname, nb_flags) == NULL) { DEBUG(0,("register_name: Failed to send packet trying to register name %s\n", nmb_namestr(&nmbname))); }}/**************************************************************************** Try and refresh one of our names. This is *only* called for WINS refresh****************************************************************************/void wins_refresh_name(struct name_record *namerec){ int t; char **wins_tags; /* get the list of wins tags - we try to refresh for each of them */ wins_tags = wins_srv_tags(); for (t=0; wins_tags && wins_tags[t]; t++) { queue_wins_refresh(&namerec->name, register_name_response, register_name_timeout_response, namerec->data.nb_flags, namerec->data.ip[0], wins_tags[t]); } wins_srv_tags_free(wins_tags);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -