r25363: Move service code to separate module.
[samba.git] / source / nbt_server / register.c
index 7d178991efb6b3b0869210790a56177bb06d127a..af067d071c55fe3ee94b82c6207bd63fd3ff50a1 100644 (file)
@@ -7,7 +7,7 @@
    
    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/>.
 */
 
 #include "includes.h"
 #include "lib/events/events.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
 #include "nbt_server/nbt_server.h"
 #include "smbd/service_task.h"
 #include "libcli/composite/composite.h"
 #include "librpc/gen_ndr/ndr_samr.h"
 #include "nbt_server/wins/winsserver.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
-
+#include "dsdb/samdb/samdb.h"
+#include "param/param.h"
 
 static void nbtd_start_refresh_timer(struct nbtd_iface_name *iname);
 
@@ -117,7 +117,7 @@ static void name_refresh_handler(struct event_context *ev, struct timed_event *t
 static void nbtd_start_refresh_timer(struct nbtd_iface_name *iname)
 {
        uint32_t refresh_time;
-       uint32_t max_refresh_time = lp_parm_int(-1, "nbtd", "max_refresh_time", 7200);
+       uint32_t max_refresh_time = lp_parm_int(NULL, "nbtd", "max_refresh_time", 7200);
 
        refresh_time = MIN(max_refresh_time, iname->ttl/2);
        
@@ -187,7 +187,7 @@ static void nbtd_register_name_iface(struct nbtd_interface *iface,
                iname->name.scope = NULL;
        }
        iname->nb_flags          = nb_flags;
-       iname->ttl               = lp_parm_int(-1, "nbtd", "bcast_ttl", 300000);
+       iname->ttl               = lp_parm_int(NULL, "nbtd", "bcast_ttl", 300000);
        iname->registration_time = timeval_zero();
        iname->wins_server       = NULL;
 
@@ -226,9 +226,9 @@ static void nbtd_register_name_iface(struct nbtd_interface *iface,
 /*
   register one name on all our interfaces
 */
-static void nbtd_register_name(struct nbtd_server *nbtsrv, 
-                              const char *name, enum nbt_name_type type,
-                              uint16_t nb_flags)
+void nbtd_register_name(struct nbtd_server *nbtsrv, 
+                       const char *name, enum nbt_name_type type,
+                       uint16_t nb_flags)
 {
        struct nbtd_interface *iface;
        
@@ -271,15 +271,14 @@ void nbtd_register_names(struct nbtd_server *nbtsrv)
                aliases++;
        }
 
-       switch (lp_server_role()) {
-       case ROLE_DOMAIN_PDC:
-               nbtd_register_name(nbtsrv, lp_workgroup(),    NBT_NAME_PDC, nb_flags);
-               nbtd_register_name(nbtsrv, lp_workgroup(),    NBT_NAME_LOGON, nb_flags | NBT_NM_GROUP);
-               break;
-       case ROLE_DOMAIN_BDC:
-               nbtd_register_name(nbtsrv, lp_workgroup(),    NBT_NAME_LOGON, nb_flags | NBT_NM_GROUP);
-       default:
-               break;
+       if (lp_server_role() == ROLE_DOMAIN_CONTROLLER) {
+               BOOL is_pdc = samdb_is_pdc(nbtsrv->sam_ctx);
+               if (is_pdc) {
+                       nbtd_register_name(nbtsrv, lp_workgroup(),
+                                          NBT_NAME_PDC, nb_flags);
+               }
+               nbtd_register_name(nbtsrv, lp_workgroup(),
+                                  NBT_NAME_LOGON, nb_flags | NBT_NM_GROUP);
        }
 
        nb_flags |= NBT_NM_GROUP;