2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "dlinklist.h"
25 #include "nbt_server/nbt_server.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/composite/composite.h"
30 start a timer to refresh this name
32 static void nbt_start_refresh_timer(struct nbt_iface_name *iname)
38 a name registration has completed
40 static void nbt_register_handler(struct smbcli_composite *req)
42 struct nbt_iface_name *iname = talloc_get_type(req->async.private, struct nbt_iface_name);
45 status = nbt_name_register_bcast_recv(req);
46 if (NT_STATUS_IS_OK(status)) {
47 /* good - nobody complained about our registration */
48 iname->nb_flags |= NBT_NM_ACTIVE;
49 DEBUG(3,("Registered %s<%02x> on interface %s\n",
50 iname->name.name, iname->name.type, iname->iface->bcast_address));
51 nbt_start_refresh_timer(iname);
55 /* someone must have replied with an objection! */
56 iname->nb_flags |= NBT_NM_CONFLICT;
58 DEBUG(1,("Error registering %s<%02x> on interface %s - %s\n",
59 iname->name.name, iname->name.type, iname->iface->bcast_address,
65 register a name on a network interface
67 static void nbt_register_name_iface(struct nbt_interface *iface,
68 const char *name, enum nbt_name_type type,
71 struct nbt_iface_name *iname;
72 const char *scope = lp_netbios_scope();
73 struct nbt_name_register_bcast io;
74 struct smbcli_composite *req;
76 iname = talloc(iface, struct nbt_iface_name);
80 iname->name.name = talloc_strdup(iname, name);
81 iname->name.type = type;
82 if (scope && *scope) {
83 iname->name.scope = talloc_strdup(iname, scope);
85 iname->name.scope = NULL;
87 iname->nb_flags = nb_flags;
88 iname->ttl = lp_parm_int(-1, "nbtd", "bcast_ttl", 300000);
89 iname->registration_time = timeval_zero();
91 DLIST_ADD_END(iface->names, iname, struct nbt_iface_name *);
93 if (nb_flags & NBT_NM_PERMANENT) {
94 /* permanent names are not announced and are immediately active */
95 iname->nb_flags |= NBT_NM_ACTIVE;
100 /* setup a broadcast name registration request */
101 io.in.name = iname->name;
102 io.in.dest_addr = iface->bcast_address;
103 io.in.address = iface->ip_address;
104 io.in.nb_flags = nb_flags;
105 io.in.ttl = iname->ttl;
107 req = nbt_name_register_bcast_send(iface->nbtsock, &io);
108 if (req == NULL) return;
110 req->async.fn = nbt_register_handler;
111 req->async.private = iname;
116 register one name on all our interfaces
118 static void nbt_register_name(struct nbt_server *nbtsrv,
119 const char *name, enum nbt_name_type type,
122 struct nbt_interface *iface;
124 /* register with all the local interfaces */
125 for (iface=nbtsrv->interfaces;iface;iface=iface->next) {
126 nbt_register_name_iface(iface, name, type, nb_flags);
129 /* register on our general broadcast interface as a permanent name */
130 nbt_register_name_iface(nbtsrv->bcast_interface, name, type, nb_flags | NBT_NM_PERMANENT);
132 /* TODO: register with our WINS servers */
137 register our names on all interfaces
139 void nbt_register_names(struct nbt_server *nbtsrv)
141 uint16_t nb_flags = NBT_NODE_M;
143 /* note that we don't initially mark the names "ACTIVE". They are
144 marked active once registration is successful */
145 nbt_register_name(nbtsrv, lp_netbios_name(), NBT_NAME_CLIENT, nb_flags);
146 nbt_register_name(nbtsrv, lp_netbios_name(), NBT_NAME_USER, nb_flags);
147 nbt_register_name(nbtsrv, lp_netbios_name(), NBT_NAME_SERVER, nb_flags);
149 nb_flags |= NBT_NM_GROUP;
150 nbt_register_name(nbtsrv, lp_workgroup(), NBT_NAME_CLIENT, nb_flags);
152 nb_flags |= NBT_NM_PERMANENT;
153 nbt_register_name(nbtsrv, "__SAMBA__", NBT_NAME_CLIENT, nb_flags);
154 nbt_register_name(nbtsrv, "__SAMBA__", NBT_NAME_SERVER, nb_flags);
155 nbt_register_name(nbtsrv, "*", NBT_NAME_CLIENT, nb_flags);