sync 3.0 into HEAD for the last time
authorGerald Carter <jerry@samba.org>
Tue, 9 Sep 2003 04:07:32 +0000 (04:07 +0000)
committerGerald Carter <jerry@samba.org>
Tue, 9 Sep 2003 04:07:32 +0000 (04:07 +0000)
(This used to be commit c17a7dc9a190156a069da3e861c18fd3f81224ad)

260 files changed:
source3/.cvsignore
source3/Makefile.in
source3/VERSION [new file with mode: 0644]
source3/aclocal.m4
source3/auth/auth.c
source3/auth/auth_domain.c
source3/auth/auth_rhosts.c
source3/auth/auth_sam.c
source3/auth/auth_util.c
source3/auth/auth_winbind.c
source3/auth/pampass.c
source3/autogen.sh
source3/bin/.cvsignore
source3/client/client.c
source3/client/clitar.c
source3/client/mount.cifs.c
source3/client/smbmnt.c
source3/client/smbmount.c
source3/configure.in
source3/groupdb/mapping.c
source3/include/.cvsignore
source3/include/ads.h
source3/include/charset.h
source3/include/includes.h
source3/include/nameserv.h
source3/include/ntdomain.h
source3/include/ntioctl.h
source3/include/ntlmssp.h
source3/include/ntquotas.h
source3/include/rpc_dce.h
source3/include/rpc_ds.h
source3/include/rpc_lsa.h
source3/include/rpc_samr.h
source3/include/rpc_spoolss.h
source3/include/safe_string.h
source3/include/secrets.h
source3/include/smb.h
source3/include/smb_macros.h
source3/include/spnego.h [new file with mode: 0644]
source3/include/trans2.h
source3/include/version.h
source3/include/vfs.h
source3/include/vfs_macros.h
source3/intl/lang_tdb.c
source3/lib/access.c
source3/lib/afs.c [new file with mode: 0644]
source3/lib/charcnv.c
source3/lib/dummyroot.c [new file with mode: 0644]
source3/lib/fault.c
source3/lib/gencache.c
source3/lib/hash.c
source3/lib/module.c
source3/lib/ms_fnmatch.c
source3/lib/popt_common.c
source3/lib/readline.c
source3/lib/replace1.c [new file with mode: 0644]
source3/lib/smbldap.c
source3/lib/substitute.c
source3/lib/system.c
source3/lib/util.c
source3/lib/util_file.c
source3/lib/util_sid.c
source3/lib/util_str.c
source3/lib/version.c [new file with mode: 0644]
source3/libads/ads_status.c
source3/libads/authdata.c
source3/libads/kerberos_verify.c
source3/libads/krb5_setpw.c
source3/libads/ldap.c
source3/libads/ldap_utils.c
source3/libads/sasl.c
source3/libsmb/cliconnect.c
source3/libsmb/clientgen.c
source3/libsmb/clifile.c
source3/libsmb/clikrb5.c
source3/libsmb/climessage.c
source3/libsmb/cliprint.c
source3/libsmb/clirap.c
source3/libsmb/clirap2.c
source3/libsmb/clireadwrite.c
source3/libsmb/clisecdesc.c
source3/libsmb/clispnego.c
source3/libsmb/namequery.c
source3/libsmb/namequery_dc.c
source3/libsmb/nmblib.c
source3/libsmb/ntlmssp.c
source3/libsmb/ntlmssp_parse.c
source3/libsmb/ntlmssp_sign.c
source3/libsmb/smb_signing.c
source3/libsmb/smbencrypt.c
source3/libsmb/spnego.c [new file with mode: 0644]
source3/libsmb/trusts_util.c
source3/locking/locking.c
source3/modules/CP437.c [new file with mode: 0644]
source3/modules/CP850.c [new file with mode: 0644]
source3/modules/getdate.c [new file with mode: 0644]
source3/modules/getdate.h [new file with mode: 0644]
source3/modules/getdate.y [new file with mode: 0644]
source3/modules/vfs_cap.c [new file with mode: 0644]
source3/modules/vfs_default_quota.c [new file with mode: 0644]
source3/modules/vfs_readonly.c [new file with mode: 0644]
source3/modules/vfs_recycle.c
source3/msdfs/README [deleted file]
source3/msdfs/msdfs.c
source3/nmbd/asyncdns.c
source3/nmbd/nmbd.c
source3/nmbd/nmbd_become_dmb.c
source3/nmbd/nmbd_become_lmb.c
source3/nmbd/nmbd_browserdb.c
source3/nmbd/nmbd_browsesync.c
source3/nmbd/nmbd_elections.c
source3/nmbd/nmbd_incomingdgrams.c
source3/nmbd/nmbd_incomingrequests.c
source3/nmbd/nmbd_lmhosts.c
source3/nmbd/nmbd_logonnames.c
source3/nmbd/nmbd_mynames.c
source3/nmbd/nmbd_namelistdb.c
source3/nmbd/nmbd_namequery.c
source3/nmbd/nmbd_nameregister.c
source3/nmbd/nmbd_nodestatus.c
source3/nmbd/nmbd_packets.c
source3/nmbd/nmbd_processlogon.c
source3/nmbd/nmbd_responserecordsdb.c
source3/nmbd/nmbd_sendannounce.c
source3/nmbd/nmbd_serverlistdb.c
source3/nmbd/nmbd_subnetdb.c
source3/nmbd/nmbd_synclists.c
source3/nmbd/nmbd_winsproxy.c
source3/nmbd/nmbd_winsserver.c
source3/nmbd/nmbd_workgroupdb.c
source3/nsswitch/pam_winbind.h
source3/nsswitch/wb_client.c
source3/nsswitch/wbinfo.c
source3/nsswitch/winbindd.c
source3/nsswitch/winbindd_acct.c
source3/nsswitch/winbindd_ads.c
source3/nsswitch/winbindd_cache.c
source3/nsswitch/winbindd_cm.c
source3/nsswitch/winbindd_group.c
source3/nsswitch/winbindd_misc.c
source3/nsswitch/winbindd_nss.h
source3/nsswitch/winbindd_pam.c
source3/nsswitch/winbindd_rpc.c
source3/nsswitch/winbindd_sid.c
source3/nsswitch/winbindd_user.c
source3/nsswitch/winbindd_util.c
source3/nsswitch/wins.c
source3/param/loadparm.c
source3/passdb/lookup_sid.c [new file with mode: 0644]
source3/passdb/passdb.c
source3/passdb/pdb_interface.c
source3/passdb/pdb_ldap.c
source3/passdb/pdb_mysql.c
source3/passdb/pdb_plugin.c
source3/passdb/pdb_tdb.c
source3/passdb/secrets.c
source3/printing/lpq_parse.c
source3/printing/nt_printing.c
source3/python/py_lsa.c
source3/python/py_smb.c
source3/python/py_spoolss_drivers.c
source3/python/py_winbind.c
source3/rpc_client/cli_netlogon.c
source3/rpc_client/cli_pipe.c
source3/rpc_client/cli_spoolss.c
source3/rpc_parse/parse_echo.c
source3/rpc_parse/parse_net.c
source3/rpc_parse/parse_prs.c
source3/rpc_parse/parse_reg.c
source3/rpc_parse/parse_samr.c
source3/rpc_parse/parse_spoolss.c
source3/rpc_server/srv_dfs.c
source3/rpc_server/srv_dfs_nt.c
source3/rpc_server/srv_echo.c
source3/rpc_server/srv_lsa.c
source3/rpc_server/srv_lsa_ds.c [new file with mode: 0644]
source3/rpc_server/srv_lsa_ds_nt.c [new file with mode: 0644]
source3/rpc_server/srv_lsa_nt.c
source3/rpc_server/srv_netlog.c
source3/rpc_server/srv_pipe.c
source3/rpc_server/srv_pipe_hnd.c
source3/rpc_server/srv_reg.c
source3/rpc_server/srv_samr.c
source3/rpc_server/srv_samr_nt.c
source3/rpc_server/srv_spoolss.c
source3/rpc_server/srv_spoolss_nt.c
source3/rpc_server/srv_srvsvc.c
source3/rpc_server/srv_util.c
source3/rpc_server/srv_wkssvc.c
source3/rpcclient/cmd_ds.c
source3/rpcclient/cmd_netlogon.c
source3/rpcclient/cmd_spoolss.c
source3/rpcclient/rpcclient.c
source3/sam/idmap_ldap.c
source3/sam/idmap_tdb.c
source3/sam/idmap_util.c
source3/script/.cvsignore
source3/script/find_missing_doc.pl [deleted file]
source3/script/findsmb.in
source3/script/gap.awk [new file with mode: 0644]
source3/script/gaptab.awk [new file with mode: 0644]
source3/script/gen-8bit-gap.awk [new file with mode: 0644]
source3/script/gen-8bit-gap.sh.in [new file with mode: 0755]
source3/script/installmodules.sh
source3/script/installswat.sh
source3/script/linkmodules.sh [new file with mode: 0755]
source3/script/mkproto.awk
source3/script/mkproto.sh
source3/script/mkversion.sh [new file with mode: 0755]
source3/smbadduser
source3/smbadduser.in [new file with mode: 0644]
source3/smbd/blocking.c
source3/smbd/change_trust_pw.c
source3/smbd/chgpasswd.c
source3/smbd/fileio.c
source3/smbd/filename.c
source3/smbd/files.c
source3/smbd/lanman.c
source3/smbd/mangle_hash2.c
source3/smbd/message.c
source3/smbd/notify.c
source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/password.c
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/sec_ctx.c
source3/smbd/server.c
source3/smbd/service.c
source3/smbd/sesssetup.c
source3/smbd/statcache.c
source3/smbd/trans2.c
source3/smbd/uid.c
source3/smbd/utmp.c
source3/smbd/vfs-wrap.c
source3/smbd/vfs.c
source3/tdb/tdb.c
source3/torture/cmd_vfs.c
source3/torture/masktest.c
source3/torture/rpctorture.c
source3/torture/smbiconv.c
source3/utils/log2pcaphex.c [new file with mode: 0644]
source3/utils/net.c
source3/utils/net_ads.c
source3/utils/net_ads_cldap.c
source3/utils/net_groupmap.c
source3/utils/net_help.c
source3/utils/net_lookup.c
source3/utils/net_rpc.c
source3/utils/net_rpc_samsync.c
source3/utils/nmblookup.c
source3/utils/ntlm_auth.c
source3/utils/profiles.c
source3/utils/smbcacls.c
source3/utils/smbgroupedit.c [deleted file]
source3/utils/status.c
source3/utils/testparm.c
source3/web/statuspage.c
source3/web/swat.c
source3/wrepld/server.c

index 074a88cef2bfa95616ae41b45e28428b5430ed74..31dd2c3a7a9884dfb7484cf30bdf5ffb0a29eacf 100644 (file)
@@ -28,3 +28,4 @@ testtmp
 trace.out
 typescript*
 configure
+smbadduser
index 4674fd07ae5702770a5d16372564039cb4f7f0ac..f7ec500d06a7e7befd1b16789770c0d30941c5fc 100644 (file)
@@ -3,7 +3,7 @@
 # Copyright Andrew Tridgell 1992-1998
 # Copyright (C) 2001 by Martin Pool <mbp@samba.org>
 # Copyright Andrew Bartlett 2002
-# Copyright (C) 2003 Jim McDonough <aliguor@us.ibm.com>
+# Copyright (C) 2003 Jim McDonough <jmcd@us.ibm.com>
 # Copyright (C) 2002-2003 Jelmer Vernooij <jelmer@samba.org>
 ###########################################################################
 
@@ -27,13 +27,13 @@ PERL=@PERL@
 
 TERMLDFLAGS=@TERMLDFLAGS@
 TERMLIBS=@TERMLIBS@
-PRINTLIBS=@PRINTLIBS@
-AUTHLIBS=@AUTHLIBS@
-ACLLIBS=@ACLLIBS@
-PASSDBLIBS=@PASSDBLIBS@
+PRINT_LIBS=@PRINT_LIBS@
+AUTH_LIBS=@AUTH_LIBS@
+ACL_LIBS=@ACL_LIBS@
+PASSDB_LIBS=@PASSDB_LIBS@
 IDMAP_LIBS=@IDMAP_LIBS@
 KRB5LIBS=@KRB5_LIBS@
-LDAPLIBS=@LDAP_LIBS@
+LDAP_LIBS=@LDAP_LIBS@
 
 LINK=$(CC) $(FLAGS) $(LDFLAGS)
 
@@ -51,7 +51,7 @@ SHELL=/bin/sh
 # /bin/sh on some platforms.  I guess it's not a big problem -- mbp
 
 # See the autoconf manual "Installation Directory Variables" for a
-# discussion of thesubtle use of these variables.
+# discussion of the subtle use of these variables.
 
 BASEDIR= @prefix@
 BINDIR = @bindir@
@@ -139,7 +139,8 @@ TORTURE_PROGS = bin/smbtorture@EXEEXT@ bin/msgtest@EXEEXT@ \
 
 BIN_PROGS = $(BIN_PROGS1) $(BIN_PROGS2) $(BIN_PROGS3) @EXTRA_BIN_PROGS@
 
-EVERYTHING_PROGS = bin/debug2html@EXEEXT@ bin/smbfilter@EXEEXT@ bin/talloctort@EXEEXT@
+EVERYTHING_PROGS = bin/debug2html@EXEEXT@ bin/smbfilter@EXEEXT@ bin/talloctort@EXEEXT@ \
+       bin/log2pcap@EXEEXT@
 
 SHLIBS = @SHLIB_PROGS@ @LIBSMBCLIENT@
 
@@ -162,7 +163,7 @@ TDB_OBJ = $(TDBBASE_OBJ) tdb/tdbutil.o tdb/tdbback.o
 
 SMBLDAP_OBJ = @SMBLDAP@
 
-LIB_OBJ = lib/charcnv.o lib/debug.o lib/fault.o \
+LIB_OBJ = lib/version.o lib/charcnv.o lib/debug.o lib/fault.o \
           lib/getsmbpass.o lib/interface.o lib/md4.o \
           lib/interfaces.o lib/pidfile.o lib/replace.o lib/replace1.o \
           lib/signal.o lib/system.o lib/sendfile.o lib/time.o \
@@ -186,6 +187,8 @@ LIB_SMBD_OBJ = lib/system_smbd.o lib/util_smbd.o
 
 READLINE_OBJ = lib/readline.o
 
+# Also depends on  $(SECRETS_OBJ) $(LIBSAMBA_OBJ)
+# Be sure to include them into your application
 POPT_LIB_OBJ = lib/popt_common.o 
 
 UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
@@ -242,6 +245,8 @@ RPC_SAMR_OBJ = rpc_server/srv_samr.o rpc_server/srv_samr_nt.o \
 
 RPC_REG_OBJ =  rpc_server/srv_reg.o rpc_server/srv_reg_nt.o
 
+RPC_LSA_DS_OBJ =  rpc_server/srv_lsa_ds.o rpc_server/srv_lsa_ds_nt.o
+
 RPC_SVC_OBJ = rpc_server/srv_srvsvc.o rpc_server/srv_srvsvc_nt.o
 
 RPC_WKS_OBJ =  rpc_server/srv_wkssvc.o rpc_server/srv_wkssvc_nt.o
@@ -278,11 +283,13 @@ PASSDB_GET_SET_OBJ = passdb/pdb_get_set.o
 
 PASSDB_OBJ = $(PASSDB_GET_SET_OBJ) passdb/passdb.o passdb/pdb_interface.o \
                passdb/machine_sid.o passdb/util_sam_sid.o passdb/pdb_compat.o \
-               passdb/privileges.o @PDB_STATIC@ 
+               passdb/privileges.o passdb/lookup_sid.o @PDB_STATIC@ 
 
 XML_OBJ = passdb/pdb_xml.o
 MYSQL_OBJ = passdb/pdb_mysql.o
-DEVEL_HELP_OBJ = modules/weird.o
+DEVEL_HELP_WEIRD_OBJ = modules/weird.o
+DEVEL_HELP_CP850_OBJ = modules/CP850.o
+DEVEL_HELP_CP437_OBJ = modules/CP437.o
 
 GROUPDB_OBJ = groupdb/mapping.o
 
@@ -300,6 +307,8 @@ VFS_FAKE_PERMS_OBJ = modules/vfs_fake_perms.o
 VFS_RECYCLE_OBJ = modules/vfs_recycle.o
 VFS_NETATALK_OBJ = modules/vfs_netatalk.o
 VFS_DEFAULT_QUOTA_OBJ = modules/vfs_default_quota.o
+VFS_READONLY_OBJ = modules/vfs_readonly.o modules/getdate.o
+VFS_CAP_OBJ = modules/vfs_cap.o
 
 PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o
 
@@ -338,7 +347,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \
               smbd/process.o smbd/service.o smbd/error.o \
               printing/printfsp.o lib/util_seaccess.o \
                lib/sysquotas.o smbd/change_trust_pw.o smbd/fake_file.o \
-              smbd/quotas.o smbd/ntquotas.o \
+              smbd/quotas.o smbd/ntquotas.o lib/afs.o \
               $(MANGLE_OBJ) @VFS_STATIC@
 
 SMBD_OBJ_BASE = $(PARAM_OBJ) $(SMBD_OBJ_SRV) $(MSDFS_OBJ) $(LIBSMB_OBJ) \
@@ -396,18 +405,20 @@ SMBSH_OBJ = smbwrapper/smbsh.o smbwrapper/shared.o \
 
 STATUS_OBJ = utils/status.o $(LOCKING_OBJ) $(PARAM_OBJ) \
              $(UBIQX_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ) \
-            lib/dummyroot.o libsmb/errormap.o
+            $(SECRETS_OBJ) $(LIBSAMBA_OBJ) lib/dummyroot.o libsmb/errormap.o 
 
 SMBCONTROL_OBJ = utils/smbcontrol.o $(LOCKING_OBJ) $(PARAM_OBJ) \
        $(UBIQX_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ) \
+       $(SECRETS_OBJ) $(LIBSAMBA_OBJ) \
        printing/notify.o printing/printing_db.o lib/dummyroot.o libsmb/errormap.o
 
 SMBTREE_OBJ = utils/smbtree.o $(LOCKING_OBJ) $(PARAM_OBJ) \
              $(UBIQX_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) $(LIBSMB_OBJ) \
-            $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ)
+            $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ) 
 
 TESTPARM_OBJ = utils/testparm.o \
-               $(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ)
+               $(PARAM_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ) \
+              $(SECRETS_OBJ) $(LIBSAMBA_OBJ)
 
 TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(PRINTING_OBJ) $(UBIQX_OBJ) \
                $(LIB_OBJ)
@@ -435,7 +446,7 @@ RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \
             $(LIBADS_OBJ) $(SECRETS_OBJ) $(POPT_LIB_OBJ) \
             $(SMBLDAP_OBJ) $(DCUTIL_OBJ) lib/dummyroot.o
 
-PAM_WINBIND_OBJ = nsswitch/pam_winbind.po nsswitch/wb_common.po lib/replace1.po lib/snprintf.po
+PAM_WINBIND_PICOBJ = nsswitch/pam_winbind.po nsswitch/wb_common.po lib/replace1.po lib/snprintf.po
 
 SMBW_OBJ1 = smbwrapper/smbw.o \
                smbwrapper/smbw_dir.o smbwrapper/smbw_stat.o \
@@ -469,7 +480,7 @@ CLIENT_OBJ1 = client/client.o client/clitar.o
 
 CLIENT_OBJ = $(CLIENT_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
             $(LIB_OBJ) $(KRBCLIENT_OBJ) \
-             $(READLINE_OBJ) $(POPT_LIB_OBJ) 
+             $(READLINE_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ)
 
 NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_ads_cldap.o utils/net_help.o \
           utils/net_rap.o utils/net_rpc.o utils/net_rpc_samsync.o \
@@ -481,20 +492,20 @@ NET_OBJ = $(NET_OBJ1) $(PARAM_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \
          $(KRBCLIENT_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) \
          $(LIBMSRPC_OBJ) $(IDMAP_OBJ) \
          $(LIBADS_OBJ) $(LIBADS_SERVER_OBJ) $(POPT_LIB_OBJ) \
-         $(SMBLDAP_OBJ) $(DCUTIL_OBJ) lib/dummyroot.o lib/server_mutex.o
+         $(SMBLDAP_OBJ) $(DCUTIL_OBJ) lib/dummyroot.o lib/server_mutex.o lib/afs.o
 
 CUPS_OBJ = client/smbspool.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
-         $(LIB_OBJ) $(KRBCLIENT_OBJ)
+         $(LIB_OBJ) $(KRBCLIENT_OBJ) $(SECRETS_OBJ)
 
 MOUNT_OBJ = client/smbmount.o \
              $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) $(UBIQX_OBJ) $(LIB_OBJ) 
 
-MNT_OBJ = client/smbmnt.o              
+MNT_OBJ = client/smbmnt.o lib/version.o lib/snprintf.o
 
 UMOUNT_OBJ = client/smbumount.o
 
 NMBLOOKUP_OBJ = utils/nmblookup.o $(PARAM_OBJ) $(UBIQX_OBJ) $(LIBNMB_OBJ) \
-               $(LIB_OBJ) $(POPT_LIB_OBJ)
+               $(LIB_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ) $(LIBSAMBA_OBJ)
 
 SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/utable.o \
                torture/denytest.o torture/mangle_test.o 
@@ -516,7 +527,9 @@ NSSTEST_OBJ = torture/nsstest.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) \
 
 VFSTEST_OBJ = torture/cmd_vfs.o torture/vfstest.o $(SMBD_OBJ_BASE) $(READLINE_OBJ)
 
-SMBICONV_OBJ = $(PARAM_OBJ) torture/smbiconv.o $(LIB_OBJ) $(UBIQX_OBJ) $(POPT_LIB_OBJ)
+SMBICONV_OBJ = $(PARAM_OBJ) torture/smbiconv.o $(LIB_OBJ) $(UBIQX_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ) $(LIBSAMBA_OBJ)
+
+LOG2PCAP_OBJ = utils/log2pcaphex.o
 
 LOCKTEST2_OBJ = torture/locktest2.o $(PARAM_OBJ) $(LOCKING_OBJ) $(LIBSMB_OBJ) \
                $(KRBCLIENT_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
@@ -558,12 +571,12 @@ PROTO_OBJ = $(SMBD_OBJ_MAIN) \
            $(PASSDB_OBJ) $(GROUPDB_OBJ) $(MSDFS_OBJ) \
            $(READLINE_OBJ) $(PROFILE_OBJ) $(LIBADS_OBJ) $(LIBADS_SERVER_OBJ) \
            $(LIB_SMBD_OBJ) $(SAM_OBJ) $(REGISTRY_OBJ) $(POPT_LIB_OBJ) \
-           $(RPC_LSA_OBJ) $(RPC_NETLOG_OBJ) $(RPC_SAMR_OBJ) $(RPC_REG_OBJ) \
+           $(RPC_LSA_OBJ) $(RPC_NETLOG_OBJ) $(RPC_SAMR_OBJ) $(RPC_REG_OBJ) $(RPC_LSA_DS_OBJ) \
            $(RPC_SVC_OBJ) $(RPC_WKS_OBJ) $(RPC_DFS_OBJ) $(RPC_SPOOLSS_OBJ) \
            $(RPC_ECHO_OBJ) $(SMBLDAP_OBJ) $(IDMAP_OBJ) libsmb/spnego.o
 
 WINBIND_WINS_NSS_OBJ = nsswitch/wins.o $(PARAM_OBJ) $(UBIQX_OBJ) \
-       $(LIBSMB_OBJ) $(LIB_OBJ) $(NSSWINS_OBJ)
+       $(LIBSMB_OBJ) $(LIB_OBJ) $(NSSWINS_OBJ) $(KRBCLIENT_OBJ)
 
 WINBIND_WINS_NSS_PICOBJS = $(WINBIND_WINS_NSS_OBJ:.o=.po)
 
@@ -572,9 +585,8 @@ LIBSMBCLIENT_PICOBJS = $(LIBSMBCLIENT_OBJ:.o=.po)
 
 PAM_SMBPASS_OBJ_0 = pam_smbpass/pam_smb_auth.o pam_smbpass/pam_smb_passwd.o \
                pam_smbpass/pam_smb_acct.o pam_smbpass/support.o \
-               libsmb/smbencrypt.o libsmb/smbdes.o libsmb/nterr.o \
-               $(PARAM_OBJ) $(LIB_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \
-               $(SECRETS_OBJ) $(UBIQX_OBJ)
+               lib/dummyroot.o $(PARAM_OBJ) $(LIB_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \
+               $(SECRETS_OBJ) $(UBIQX_OBJ) $(SMBLDAP_OBJ) $(LIBSAMBA_OBJ)
 
 PAM_SMBPASS_PICOOBJ = $(PAM_SMBPASS_OBJ_0:.o=.po)
 
@@ -617,7 +629,10 @@ POPT_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
 TDBBACKUP_OBJ = tdb/tdbbackup.o tdb/tdbback.o $(TDBBASE_OBJ)
 
 NTLM_AUTH_OBJ = utils/ntlm_auth.o $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
-               libsmb/asn1.o libsmb/spnego.o
+               libsmb/asn1.o libsmb/spnego.o libsmb/clikrb5.o libads/kerberos.o \
+               libads/kerberos_verify.o $(SECRETS_OBJ) lib/server_mutex.o \
+               libads/authdata.o rpc_parse/parse_prs.o rpc_parse/parse_misc.o \
+               libsmb/doserr.o
 
 ######################################################################
 # now the rules...
@@ -660,7 +675,8 @@ wins : SHOWFLAGS @WINBIND_WINS_NSS@
 
 modules: SHOWFLAGS proto_exists $(MODULES)
 
-everything: all libsmbclient debug2html smbfilter talloctort modules torture
+everything: all libsmbclient debug2html smbfilter talloctort modules torture \
+       $(EVERYTHING_PROGS)
 
 .SUFFIXES:
 .SUFFIXES: .c .o .po .lo
@@ -694,7 +710,6 @@ MAKEDIR = || exec false; \
 # rebuild it's a bit hard.
 
 dynconfig.o: dynconfig.c Makefile
-       @$(MAKE) modules_clean
        @echo Compiling $*.c
        @$(CC) $(FLAGS) $(PATH_FLAGS) -c $< -o $@ 
 
@@ -706,6 +721,18 @@ dynconfig.po: dynconfig.c Makefile
 @BROKEN_CC@    -mv `echo $@ | sed -e 's%^.*/%%g' -e 's%\.po$$%.o%'` $@
 @POBAD_CC@     @mv $*.po.o $@
 
+lib/version.o: lib/version.c include/version.h
+       @echo Compiling $*.c
+       @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) -c $< -o $@ 
+
+lib/version.po: lib/version.c include/version.h
+       @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \
+         dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi
+       @echo Compiling $*.c with @PICFLAG@
+       @$(CC) -I. -I$(srcdir) $(FLAGS) $(PATH_FLAGS) @PICFLAG@ -c $< -o $*.@PICSUFFIX@
+@BROKEN_CC@    -mv `echo $@ | sed -e 's%^.*/%%g' -e 's%\.po$$%.o%'` $@
+@POBAD_CC@     @mv $*.po.o $@
+
 smbd/build_options.o: smbd/build_options.c Makefile include/config.h include/build_env.h include/proto.h
        @echo Compiling $*.c
        @$(CC) $(FLAGS) $(PATH_FLAGS) -c $< -o $@
@@ -729,12 +756,12 @@ bin/.dummy:
 
 bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBD_OBJ) $(KRB5LIBS) $(LDAPLIBS) $(LDFLAGS) $(DYNEXP) $(PRINTLIBS) \
-         $(AUTHLIBS) $(ACLLIBS) $(PASSDBLIBS) $(LIBS) @POPTLIBS@
+       @$(CC) $(FLAGS) -o $@ $(SMBD_OBJ) $(KRB5LIBS) $(LDAP_LIBS) $(LDFLAGS) $(DYNEXP) $(PRINT_LIBS) \
+         $(AUTH_LIBS) $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@
 
 bin/nmbd@EXEEXT@: $(NMBD_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(NMBD_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(NMBD_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/wrepld@EXEEXT@: $(WREPL_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
@@ -742,20 +769,20 @@ bin/wrepld@EXEEXT@: $(WREPL_OBJ) @BUILD_POPT@ bin/.dummy
 
 bin/swat@EXEEXT@: $(SWAT_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SWAT_OBJ) $(LDFLAGS) $(DYNEXP) $(PRINTLIBS) \
-         $(AUTHLIBS) $(LIBS) $(PASSDBLIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SWAT_OBJ) $(LDFLAGS) $(DYNEXP) $(PRINT_LIBS) \
+         $(AUTH_LIBS) $(LIBS) $(PASSDB_LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/rpcclient@EXEEXT@: $(RPCCLIENT_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(PASSDBLIBS) $(RPCCLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(PASSDB_LIBS) $(RPCCLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbclient@EXEEXT@: $(CLIENT_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(CLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(CLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/net@EXEEXT@: $(NET_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(NET_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS) $(PASSDBLIBS)
+       @$(CC) $(FLAGS) -o $@ $(NET_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) $(PASSDB_LIBS)
 
 bin/profiles@EXEEXT@: $(PROFILES_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
@@ -767,11 +794,11 @@ bin/editreg@EXEEXT@: $(EDITREG_OBJ) @BUILD_POPT@ bin/.dummy
 
 bin/smbspool@EXEEXT@: $(CUPS_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(CUPS_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(CUPS_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbmount@EXEEXT@: $(MOUNT_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(MOUNT_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(MOUNT_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbmnt@EXEEXT@: $(MNT_OBJ) bin/.dummy
        @echo Linking $@
@@ -787,39 +814,42 @@ bin/testparm@EXEEXT@: $(TESTPARM_OBJ) @BUILD_POPT@ bin/.dummy
 
 bin/testprns@EXEEXT@: $(TESTPRNS_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(TESTPRNS_OBJ) $(LDFLAGS) $(DYNEXP) $(PRINTLIBS) $(LIBS)
+       @$(CC) $(FLAGS) -o $@ $(TESTPRNS_OBJ) $(LDFLAGS) $(DYNEXP) $(PRINT_LIBS) $(LIBS)
 
 bin/smbstatus@EXEEXT@: $(STATUS_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(STATUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@
+       @$(CC) $(FLAGS) -o $@ $(STATUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) \
+       @POPTLIBS@
 
 bin/smbcontrol@EXEEXT@: $(SMBCONTROL_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) -DUSING_SMBCONTROL $(FLAGS) -o $@ $(SMBCONTROL_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@
+       @$(CC) -DUSING_SMBCONTROL $(FLAGS) -o $@ $(SMBCONTROL_OBJ) $(DYNEXP) \
+       $(LDFLAGS) $(LIBS) \
+       @POPTLIBS@
 
 bin/smbtree@EXEEXT@: $(SMBTREE_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBTREE_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBTREE_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) 
 
 bin/smbpasswd@EXEEXT@: $(SMBPASSWD_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBPASSWD_OBJ) $(PASSDBLIBS) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBPASSWD_OBJ) $(PASSDB_LIBS) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) 
 
 bin/pdbedit@EXEEXT@: $(PDBEDIT_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(PDBEDIT_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDBLIBS)
+       @$(CC) $(FLAGS) -o $@ $(PDBEDIT_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDB_LIBS)
 
 bin/samtest@EXEEXT@: $(SAMTEST_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SAMTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDBLIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SAMTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDB_LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/nmblookup@EXEEXT@: $(NMBLOOKUP_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(NMBLOOKUP_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(NMBLOOKUP_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(LDAP_LIBS)
 
 bin/smbtorture@EXEEXT@: $(SMBTORTURE_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBTORTURE_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBTORTURE_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(SECRETS_OBJ)
 
 bin/talloctort@EXEEXT@: $(TALLOCTORT_OBJ) bin/.dummy
        @echo Linking $@
@@ -827,43 +857,47 @@ bin/talloctort@EXEEXT@: $(TALLOCTORT_OBJ) bin/.dummy
 
 bin/masktest@EXEEXT@: $(MASKTEST_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(MASKTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(MASKTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(SECRETS_OBJ)
 
 bin/msgtest@EXEEXT@: $(MSGTEST_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(MSGTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(MSGTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) 
 
 bin/smbcacls@EXEEXT@: $(SMBCACLS_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBCACLS_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBCACLS_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbcquotas@EXEEXT@: $(SMBCQUOTAS_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBCQUOTAS_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBCQUOTAS_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/locktest@EXEEXT@: $(LOCKTEST_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(LOCKTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(LOCKTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/nsstest@EXEEXT@: $(NSSTEST_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(NSSTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS)  $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(NSSTEST_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS)  $(LDAP_LIBS)
 
 bin/vfstest@EXEEXT@: $(VFSTEST_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINTLIBS) $(AUTHLIBS) $(ACLLIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) $(ACL_LIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbiconv@EXEEXT@: $(SMBICONV_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
        @$(CC) $(FLAGS) -o $@ $(SMBICONV_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(LIBS) @POPTLIBS@
 
+bin/log2pcap@EXEEXT@: $(LOG2PCAP_OBJ) @BUILD_POPT@ bin/.dummy
+       @echo Linking $@
+       @$(CC) $(FLAGS) -o $@ $(LOG2PCAP_OBJ) $(LDFLAGS) @POPTLIBS@ $(LIBS)
+
 bin/locktest2@EXEEXT@: $(LOCKTEST2_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(LOCKTEST2_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(LOCKTEST2_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/rpctorture@EXEEXT@: $(RPCTORTURE_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(RPCTORTURE_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(RPCTORTURE_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/debug2html@EXEEXT@: $(DEBUG2HTML_OBJ) bin/.dummy
        @echo Linking $@
@@ -871,11 +905,11 @@ bin/debug2html@EXEEXT@: $(DEBUG2HTML_OBJ) bin/.dummy
 
 bin/smbfilter@EXEEXT@: $(SMBFILTER_OBJ) bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBFILTER_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBFILTER_OBJ) $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbw_sample@EXEEXT@: $(SMBW_OBJ) utils/smbw_sample.o bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) -o $@ $(SMBW_OBJ) utils/smbw_sample.o $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAPLIBS)
+       @$(CC) $(FLAGS) -o $@ $(SMBW_OBJ) utils/smbw_sample.o $(LDFLAGS) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/smbsh@EXEEXT@: $(SMBSH_OBJ) bin/.dummy
        @echo Linking $@
@@ -884,13 +918,13 @@ bin/smbsh@EXEEXT@: $(SMBSH_OBJ) bin/.dummy
 bin/smbwrapper.@SHLIBEXT@: $(PICOBJS) bin/.dummy
        @echo Linking shared library $@
        @$(SHLD) $(LDSHFLAGS) -o $@ $(PICOBJS) $(LIBS) \
-               $(KRB5LIBS) $(LDAPLIBS) \
+               $(KRB5LIBS) $(LDAP_LIBS) \
                @SONAMEFLAG@`basename $@`
 
 bin/libsmbclient.@SHLIBEXT@: $(LIBSMBCLIENT_PICOBJS)
        @echo Linking libsmbclient shared library $@
        @$(SHLD) $(LDSHFLAGS) -o $@ $(LIBSMBCLIENT_PICOBJS) $(LDFLAGS) $(LIBS) \
-               $(KRB5LIBS) $(LDAPLIBS) \
+               $(KRB5LIBS) $(LDAP_LIBS) \
                @SONAMEFLAG@`basename $@`.$(LIBSMBCLIENT_MAJOR)
 
 bin/libsmbclient.a: $(LIBSMBCLIENT_PICOBJS)
@@ -901,7 +935,7 @@ bin/libsmbclient.a: $(LIBSMBCLIENT_PICOBJS)
 bin/libbigballofmud.@SHLIBEXT@: $(LIBBIGBALLOFMUD_PICOBJS)
        @echo Linking bigballofmud shared library $@
        @$(SHLD) $(LDSHFLAGS) -o $@ $(LIBBIGBALLOFMUD_PICOBJS) $(LIBS) \
-               $(PASSDBLIBS) $(IDMAP_LIBS) $(KRB5LIBS) $(LDAPLIBS) \
+               $(PASSDB_LIBS) $(IDMAP_LIBS) $(KRB5LIBS) $(LDAP_LIBS) \
                @SONAMEFLAG@`basename $@`.$(LIBBIGBALLOFMUD_MAJOR)
        ln -snf libbigballofmud.so bin/libbigballofmud.so.0
 
@@ -942,6 +976,11 @@ bin/librpc_winreg.@SHLIBEXT@: $(RPC_REG_OBJ)
        @$(SHLD) $(LDSHFLAGS) -o $@ $(RPC_REG_OBJ) -lc \
                @SONAMEFLAG@`basename $@`
 
+bin/librpc_lsa_ds.@SHLIBEXT@: $(RPC_LSA_DS_OBJ)
+       @echo "Linking $@"
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(RPC_LSA_DS_OBJ) -lc \
+               @SONAMEFLAG@`basename $@`
+
 bin/librpc_spoolss.@SHLIBEXT@: $(RPC_SPOOLSS_OBJ)
        @echo "Linking $@"
        @$(SHLD) $(LDSHFLAGS) -o $@ $(RPC_SPOOLSS_OBJ) -lc \
@@ -959,7 +998,10 @@ bin/librpc_echo.@SHLIBEXT@: $(RPC_ECHO_OBJ)
 
 bin/winbindd@EXEEXT@: $(WINBINDD_OBJ) @BUILD_POPT@ bin/.dummy
        @echo "Linking $@"
-       @$(LINK) -o $@ $(WINBINDD_OBJ) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAPLIBS) 
+       @$(LINK) -o $@ $(WINBINDD_OBJ) $(DYNEXP) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) 
+
+# Please don't add .o files to libnss_winbind, libnss_wins, or the pam_winbind
+# libraries.  Add to the appropriate PICOBJ variable instead.
 
 @WINBIND_NSS@: $(WINBIND_NSS_PICOBJS)
        @echo "Linking $@"
@@ -969,12 +1011,12 @@ bin/winbindd@EXEEXT@: $(WINBINDD_OBJ) @BUILD_POPT@ bin/.dummy
 @WINBIND_WINS_NSS@: $(WINBIND_WINS_NSS_PICOBJS)
        @echo "Linking $@"
        @$(SHLD) $(LDSHFLAGS) -o $@ $(WINBIND_WINS_NSS_PICOBJS) \
-               $(KRBCLIENT_OBJ) $(LDAPLIBS) $(KRB5LIBS) -lc \
+               $(LDAP_LIBS) $(KRB5LIBS) -lc \
                @SONAMEFLAG@`basename $@`
 
-nsswitch/pam_winbind.@SHLIBEXT@: $(PAM_WINBIND_OBJ) bin/.dummy
+nsswitch/pam_winbind.@SHLIBEXT@: $(PAM_WINBIND_PICOBJ) bin/.dummy
        @echo "Linking $@"
-       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_WINBIND_OBJ) \
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_WINBIND_PICOBJ) \
                @SONAMEFLAG@`basename $@` -lpam
 
 bin/rhosts.@SHLIBEXT@: $(AUTH_RHOSTS_OBJ:.o=.po)
@@ -989,7 +1031,7 @@ bin/domain.@SHLIBEXT@: $(AUTH_DOMAIN_OBJ:.o=.po)
        @echo "Building plugin $@"
        @$(SHLD) $(LDSHFLAGS) -o $@ $(AUTH_DOMAIN_OBJ:.o=.po) @SONAMEFLAG@`basename $@`
 
-bin/server.@SHLIBEXT@: $(AUTH_SERVER_OBJ:.o=.po)
+bin/smbserver.@SHLIBEXT@: $(AUTH_SERVER_OBJ:.o=.po)
        @echo "Building plugin $@"
        @$(SHLD) $(LDSHFLAGS) -o $@ $(AUTH_SERVER_OBJ:.o=.po) @SONAMEFLAG@`basename $@`
 
@@ -1012,7 +1054,7 @@ bin/mysql.@SHLIBEXT@: $(MYSQL_OBJ:.o=.po)
 
 bin/ldapsam.@SHLIBEXT@: passdb/pdb_ldap.po
        @echo "Building plugin $@"
-       @$(SHLD) $(LDSHFLAGS) $(LDAPLIBS) -o $@ passdb/pdb_ldap.po \
+       @$(SHLD) $(LDSHFLAGS) $(LDAP_LIBS) -o $@ passdb/pdb_ldap.po \
                @SONAMEFLAG@`basename $@`
 
 bin/tdbsam.@SHLIBEXT@: passdb/pdb_tdb.po
@@ -1025,9 +1067,19 @@ bin/smbpasswd.@SHLIBEXT@: passdb/pdb_smbpasswd.po
        @$(SHLD) $(LDSHFLAGS) -o $@ passdb/pdb_smbpasswd.po \
                @SONAMEFLAG@`basename $@`
 
-bin/weird.@SHLIBEXT@: $(DEVEL_HELP_OBJ:.o=.po)
+bin/weird.@SHLIBEXT@: $(DEVEL_HELP_WEIRD_OBJ:.o=.po)
+       @echo "Building plugin $@"
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(DEVEL_HELP_WEIRD_OBJ:.o=.po) \
+               @SONAMEFLAG@`basename $@`
+
+bin/CP850.@SHLIBEXT@: $(DEVEL_HELP_CP850_OBJ:.o=.po)
        @echo "Building plugin $@"
-       @$(SHLD) $(LDSHFLAGS) -o $@ $(DEVEL_HELP_OBJ:.o=.po) \
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(DEVEL_HELP_CP850_OBJ:.o=.po) \
+               @SONAMEFLAG@`basename $@`
+
+bin/CP437.@SHLIBEXT@: $(DEVEL_HELP_CP437_OBJ:.o=.po)
+       @echo "Building plugin $@"
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(DEVEL_HELP_CP437_OBJ:.o=.po) \
                @SONAMEFLAG@`basename $@`
 
 bin/xml.@SHLIBEXT@: $(XML_OBJ:.o=.po)
@@ -1065,6 +1117,16 @@ bin/default_quota.@SHLIBEXT@: $(VFS_DEFAULT_QUOTA_OBJ:.o=.po)
        @$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_DEFAULT_QUOTA_OBJ:.o=.po) \
                @SONAMEFLAG@`basename $@`
 
+bin/readonly.@SHLIBEXT@: $(VFS_READONLY_OBJ:.o=.po)
+       @echo "Building plugin $@"
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_READONLY_OBJ:.o=.po) \
+               @SONAMEFLAG@`basename $@`
+
+bin/cap.@SHLIBEXT@: $(VFS_CAP_OBJ:.o=.po)
+       @echo "Building plugin $@"
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_CAP_OBJ:.o=.po) \
+               @SONAMEFLAG@`basename $@`
+
 bin/wbinfo@EXEEXT@: $(WBINFO_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
        @$(LINK) -o $@ $(WBINFO_OBJ) $(LIBS) @POPTLIBS@
@@ -1073,11 +1135,11 @@ bin/ntlm_auth@EXEEXT@: $(NTLM_AUTH_OBJ) $(PARAM_OBJ) $(LIB_OBJ) \
                $(UBIQX_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
        @$(LINK) -o $@ $(NTLM_AUTH_OBJ) $(PARAM_OBJ) $(LIB_OBJ) \
-               $(UBIQX_OBJ) $(LIBS) @POPTLIBS@
+               $(UBIQX_OBJ) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS)
 
 bin/pam_smbpass.@SHLIBEXT@: $(PAM_SMBPASS_PICOOBJ)
        @echo "Linking shared library $@"
-       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_SMBPASS_PICOOBJ) -lpam $(DYNEXP) $(LIBS) -lc
+       @$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_SMBPASS_PICOOBJ) -lpam $(DYNEXP) $(LIBS) -lc $(LDAP_LIBS) $(KRB5LIBS)
 
 bin/libmsrpc.a: $(LIBMSRPC_PICOBJ)
        @-$(AR) -rc $@ $(LIBMSRPC_PICOBJ) 
@@ -1099,7 +1161,7 @@ bin/t_push_ucs2@EXEEXT@: bin/libbigballofmud.@SHLIBEXT@ torture/t_push_ucs2.o
 
 bin/t_snprintf@EXEEXT@: lib/snprintf.c
        $(CC) $(FLAGS) -o $@ -DTEST_SNPRINTF lib/snprintf.c -lm
-install: installbin installman installscripts installdat installswat installmodules
+install: installbin installman installscripts installdat installswat installmodules @INSTALLCLIENT@
 
 install-everything: install installmodules
 
@@ -1129,6 +1191,13 @@ installmodules: modules installdirs
        @$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(IDMAPLIBDIR) $(IDMAP_MODULES)
        @$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(CHARSETLIBDIR) $(CHARSET_MODULES)
        @$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(AUTHLIBDIR) $(AUTH_MODULES)
+       @# These symlinks are required for the 'probing' of modules. 
+       @# This mechanism should go at some point..
+       @$(SHELL) $(srcdir)/script/linkmodules.sh $(DESTDIR)$(PDBLIBDIR) ldapsam.@SHLIBEXT@ ldapsam_compat.@SHLIBEXT@
+       @$(SHELL) $(srcdir)/script/linkmodules.sh $(DESTDIR)$(AUTHLIBDIR) rhosts.@SHLIBEXT@ hostsequiv.@SHLIBEXT@
+       @$(SHELL) $(srcdir)/script/linkmodules.sh $(DESTDIR)$(AUTHLIBDIR) sam.@SHLIBEXT@ sam_ignoredomain.@SHLIBEXT@
+       @$(SHELL) $(srcdir)/script/linkmodules.sh $(DESTDIR)$(AUTHLIBDIR) domain.@SHLIBEXT@ trustdomain.@SHLIBEXT@ ntdomain.@SHLIBEXT@
+       @$(SHELL) $(srcdir)/script/linkmodules.sh $(DESTDIR)$(AUTHLIBDIR) builtin.@SHLIBEXT@ guest.@SHLIBEXT@ fixed_challenge.@SHLIBEXT@ name_to_ntstatus.@SHLIBEXT@
 
 installscripts: installdirs
        @$(SHELL) $(srcdir)/script/installscripts.sh $(INSTALLPERMS) $(DESTDIR)$(BINDIR) $(SCRIPTS)
@@ -1160,7 +1229,7 @@ python_ext: $(PYTHON_PICOBJS)
        fi
        PYTHON_OBJS="$(PYTHON_PICOBJS)" \
        PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS) $(FLAGS)" \
-       LIBS="$(LIBS) $(PASSDBLIBS) $(IDMAP_LIBS) $(KRB5LIBS) $(LDAPLIBS)" \
+       LIBS="$(LIBS) $(PASSDB_LIBS) $(IDMAP_LIBS) $(KRB5LIBS) $(LDAP_LIBS)" \
                $(PYTHON) python/setup.py build
 
 python_install: $(PYTHON_PICOBJS)
@@ -1223,11 +1292,6 @@ clean: delheaders python_clean
                $(TOPFILES) $(BIN_PROGS) $(SBIN_PROGS) $(MODULES) $(TORTURE_PROGS) \
                $(LIBSMBCLIENT) $(EVERYTHING_PROGS) .headers.stamp
 
-# This is quite ugly actually.. But we need to make 
-# sure the changes to include/config.h are used.
-modules_clean:
-       @-rm -f auth/auth.o passdb/pdb_interface.o smbd/server.o lib/iconv.o smbd/vfs.o sam/idmap.o
-
 # Making this target will just make sure that the prototype files
 # exist, not necessarily that they are up to date.  Since they're
 # removed by "make clean" this will always be run when you do anything
@@ -1315,6 +1379,11 @@ distclean: realclean
        -rm -f config.status config.cache so_locations
        -rm -rf .deps
 
+realdistclean: distclean
+       -rm -f include/config.h.in
+       -rm -f include/version.h
+       -rm -f configure
+
 # this target is really just for my use. It only works on a limited
 # range of machines and is used to produce a list of potentially
 # dead (ie. unused) functions in the code. (tridge)
diff --git a/source3/VERSION b/source3/VERSION
new file mode 100644 (file)
index 0000000..9cf8b11
--- /dev/null
@@ -0,0 +1,123 @@
+########################################################
+# SAMBA Version                                        #
+#                                                      #
+# script/mkversion.sh                                  #
+# will use this file to create                         #
+# include/version.h                                    #
+#                                                      #
+########################################################
+
+########################################################
+# This are the main SAMBA version numbers              #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>                            #
+#                                                      #
+# e.g. SAMBA_VERSION_MAJOR=3                           #
+#      SAMBA_VERSION_MINOR=0                           #
+#      SAMBA_VERSION_RELEASE=0                         #
+#  ->  "3.0.0"                                         #
+########################################################
+SAMBA_VERSION_MAJOR=3
+SAMBA_VERSION_MINOR=0
+SAMBA_VERSION_RELEASE=1
+
+########################################################
+# If a official release has a serious bug              #
+# a security release will have 'a' sufffix             #
+#                                                      #
+# so SAMBA's version will be                           #
+# <MAJOR>.<MINOR>.<RELEASE><REVISION>                  #
+#                                                      #
+# e.g. SAMBA_VERSION_PRE_RELEASE=a                     #
+#  ->  "2.2.8a"                                        #
+########################################################
+SAMBA_VERSION_REVISION=
+
+########################################################
+# For 'pre' releases the version will be               #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>pre<PRE_RELEASE>            #
+#                                                      #
+# e.g. SAMBA_VERSION_PRE_RELEASE=1                     #
+#  ->  "2.2.9pre1"                                     #
+########################################################
+SAMBA_VERSION_PRE_RELEASE=1
+
+########################################################
+# For 'rc' releases the version will be                #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>rc<RC_RELEASE>              #
+#                                                      #
+# e.g. SAMBA_VERSION_RC_RELEASE=1                      #
+#  ->  "3.0.0rc1"                                      #
+########################################################
+SAMBA_VERSION_RC_RELEASE=
+
+########################################################
+# For 'beta' releases the version will be              #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>beta<BETA_RELEASE>          #
+#                                                      #
+# e.g. SAMBA_VERSION_BETA_RELEASE=3                    #
+#  ->  "3.0.0beta3"                                    #
+########################################################
+SAMBA_VERSION_BETA_RELEASE=
+
+########################################################
+# For 'alpha' releases the version will be             #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>alpha<ALPHA_RELEASE>        #
+#                                                      #
+# e.g. SAMBA_VERSION_ALPHA_RELEASE=1                   #
+#  ->  "4.0.0alpha1"                                   #
+########################################################
+SAMBA_VERSION_ALPHA_RELEASE=
+
+########################################################
+# For 'test' releases the version will be              #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>test<TEST_RELEASE>          #
+#                                                      #
+# e.g. SAMBA_VERSION_TEST_RELEASE=1                    #
+#  ->  "4.0.0test1"                                    #
+########################################################
+SAMBA_VERSION_TEST_RELEASE=
+
+########################################################
+# To mark CVS snapshots this should be set to 'yes'    #
+# in the development BRANCH, and set to 'no' only in   #
+# the SAMBA_X_X_RELEASE BRANCH                         #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>[...]cvs                    #
+#                                                      #
+# e.g. SAMBA_VERSION_IS_CVS_SNAPSHOT=yes               #
+#  ->  "CVS 3.0.0rc2"                                  #
+########################################################
+SAMBA_VERSION_IS_CVS_SNAPSHOT=yes
+
+########################################################
+# This can be set by vendors if they want...           #
+# This can be a string constant or a function which    #
+# returns a string (const char *)                      #
+#                                                      #
+# <MAJOR>.<MINOR>.<RELEASE>[...]-<VENDOR_SUFFIX>       #
+#                                                      #
+# Note the '-' is automaticaly added                   #
+#                                                      #
+# e.g. SAMBA_VERSION_VENDOR_SUFFIX="VendorVersion"     #
+#  ->  "CVS 3.0.0rc2-VendorVersion"                    #
+#                                                      #
+# Note: If you want to use a function,                 #
+#       then patch lib/version.c and add this function #
+#       there, because the symbol must be available in #
+#       binary.                                        #
+#                                                      #
+# const char *vendor_version(void)                     #
+# {                                                    #
+#      return "VendorVersion";                        #
+# }                                                    #
+#                                                      #
+# e.g. SAMBA_VERSION_VENDOR_SUFFIX=vendor_version()    #
+#  ->  "CVS 3.0.0rc2-VendorVersion"                    #
+########################################################
+SAMBA_VERSION_VENDOR_SUFFIX=
index 3a49f7e24975fb5c13444c77700b95eb0db2e892..52396e56d6c379a87a2f9a2d6c7272718c29df4e 100644 (file)
@@ -54,6 +54,7 @@ AC_DEFUN(SMB_MODULE,
                $4_MODULES="$$4_MODULES $3"
                AC_MSG_RESULT([shared])
                [$6]
+               string_shared_modules="$string_shared_modules $1"
        elif test x"$DEST" = xSTATIC; then
                [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z]) $1_init();"
                string_static_modules="$string_static_modules $1"
@@ -62,6 +63,7 @@ AC_DEFUN(SMB_MODULE,
                [$5]
                AC_MSG_RESULT([static])
        else
+           string_ignored_modules="$string_ignored_modules $1"
                AC_MSG_RESULT([not])
        fi
 ])
@@ -71,6 +73,7 @@ AC_DEFUN(SMB_SUBSYSTEM,
        AC_SUBST($1_STATIC)
        AC_SUBST($1_MODULES)
        AC_DEFINE_UNQUOTED([static_init_]translit([$1], [A-Z], [a-z]), [{$init_static_modules_]translit([$1], [A-Z], [a-z])[}], [Static init functions])
+       ifelse([$2], , :, [touch $2])
 ])
 
 dnl AC_PROG_CC_FLAG(flag)
@@ -448,8 +451,6 @@ AC_ARG_WITH(mysql-prefix,[  --with-mysql-prefix=PFX   Prefix where MYSQL is inst
             mysql_prefix="$withval", mysql_prefix="")
 AC_ARG_WITH(mysql-exec-prefix,[  --with-mysql-exec-prefix=PFX Exec prefix where MYSQL is installed (optional)],
             mysql_exec_prefix="$withval", mysql_exec_prefix="")
-AC_ARG_ENABLE(mysqltest, [  --disable-mysqltest       Do not try to compile and run a test MYSQL program],
-         , enable_mysqltest=yes)
 
   if test x$mysql_exec_prefix != x ; then
      mysql_args="$mysql_args --exec-prefix=$mysql_exec_prefix"
@@ -466,143 +467,21 @@ AC_ARG_ENABLE(mysqltest, [  --disable-mysqltest       Do not try to compile and
 
   AC_REQUIRE([AC_CANONICAL_TARGET])
   AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no)
-  min_mysql_version=ifelse([$1], ,0.11.0,$1)
-  AC_MSG_CHECKING(for MYSQL - version >= $min_mysql_version)
+  AC_MSG_CHECKING(for MYSQL)
   no_mysql=""
   if test "$MYSQL_CONFIG" = "no" ; then
-    no_mysql=yes
+    MYSQL_CFLAGS=""
+    MYSQL_LIBS=""
+    AC_MSG_RESULT(no)
+     ifelse([$2], , :, [$2])
   else
     MYSQL_CFLAGS=`$MYSQL_CONFIG $mysqlconf_args --cflags | sed -e "s/'//g"`
     MYSQL_LIBS=`$MYSQL_CONFIG $mysqlconf_args --libs | sed -e "s/'//g"`
-
-    mysql_major_version=`$MYSQL_CONFIG $mysql_args --version | \
-           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
-    mysql_minor_version=`$MYSQL_CONFIG $mysql_args --version | \
-           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
-    mysql_micro_version=`$MYSQL_CONFIG $mysql_config_args --version | \
-           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
-    if test "x$enable_mysqltest" = "xyes" ; then
-      ac_save_CFLAGS="$CFLAGS"
-      ac_save_LIBS="$LIBS"
-      CFLAGS="$CFLAGS $MYSQL_CFLAGS"
-      LIBS="$LIBS $MYSQL_LIBS"
-dnl
-dnl Now check if the installed MYSQL is sufficiently new. (Also sanity
-dnl checks the results of mysql_config to some extent
-dnl
-      rm -f conf.mysqltest
-      AC_TRY_RUN([
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <mysql.h>
-
-char*
-my_strdup (char *str)
-{
-  char *new_str;
-
-  if (str)
-    {
-      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
-      strcpy (new_str, str);
-    }
-  else
-    new_str = NULL;
-
-  return new_str;
-}
-
-int main (int argc, char *argv[])
-{
-int major, minor, micro;
-  char *tmp_version;
-
-  /* This hangs on some systems (?)
-  system ("touch conf.mysqltest");
-  */
-  { FILE *fp = fopen("conf.mysqltest", "a"); if ( fp ) fclose(fp); }
-
-  /* HP/UX 9 (%@#!) writes to sscanf strings */
-  tmp_version = my_strdup("$min_mysql_version");
-  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
-     printf("%s, bad version string\n", "$min_mysql_version");
-     exit(1);
-   }
-
-   if (($mysql_major_version > major) ||
-      (($mysql_major_version == major) && ($mysql_minor_version > minor)) ||
-      (($mysql_major_version == major) && ($mysql_minor_version == minor) && ($mysql_micro_version >= micro)))
-    {
-      return 0;
-    }
-  else
-    {
-      printf("\n*** 'mysql_config --version' returned %d.%d.%d, but the minimum version\n", $mysql_major_version, $mysql_minor_version, $mysql_micro_version);
-      printf("*** of MYSQL required is %d.%d.%d. If mysql_config is correct, then it is\n", major, minor, micro);
-      printf("*** best to upgrade to the required version.\n");
-      printf("*** If mysql_config was wrong, set the environment variable MYSQL_CONFIG\n");
-      printf("*** to point to the correct copy of mysql_config, and remove the file\n");
-      printf("*** config.cache before re-running configure\n");
-      return 1;
-    }
-}
-
-],, no_mysql=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
-       CFLAGS="$ac_save_CFLAGS"
-       LIBS="$ac_save_LIBS"
-     fi
-  fi
-  if test "x$no_mysql" = x ; then
-     AC_MSG_RESULT(yes)
-     ifelse([$2], , :, [$2])
-  else
-     AC_MSG_RESULT(no)
-     if test "$MYSQL_CONFIG" = "no" ; then
-       echo "*** The mysql_config script installed by MYSQL could not be found"
-       echo "*** If MYSQL was installed in PREFIX, make sure PREFIX/bin is in"
-       echo "*** your path, or set the MYSQL_CONFIG environment variable to the"
-       echo "*** full path to mysql_config."
-     else
-       if test -f conf.mysqltest ; then
-        :
-       else
-          echo "*** Could not run MYSQL test program, checking why..."
-          CFLAGS="$CFLAGS $MYSQL_CFLAGS"
-          LIBS="$LIBS $MYSQL_LIBS"
-          AC_TRY_LINK([
-#include <stdio.h>
-#include <mysql.h>
-
-int main(int argc, char *argv[])
-{ return 0; }
-#undef  main
-#define main K_and_R_C_main
-],      [ return 0; ],
-        [ echo "*** The test program compiled, but did not run. This usually means"
-          echo "*** that the run-time linker is not finding MYSQL or finding the wrong"
-          echo "*** version of MYSQL. If it is not finding MYSQL, you'll need to set your"
-          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
-          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
-          echo "*** is required on your system"
-    echo "***"
-          echo "*** If you have an old version installed, it is best to remove it, although"
-          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
-        [ echo "*** The test program failed to compile or link. See the file config.log for the"
-          echo "*** exact error that occured. This usually means MYSQL was incorrectly installed"
-          echo "*** or that you have moved MYSQL since it was installed. In the latter case, you"
-          echo "*** may want to edit the mysql_config script: $MYSQL_CONFIG" ])
-          CFLAGS="$ac_save_CFLAGS"
-          LIBS="$ac_save_LIBS"
-       fi
-     fi
-     MYSQL_CFLAGS=""
-     MYSQL_LIBS=""
-     ifelse([$3], , :, [$3])
+    AC_MSG_RESULT(yes)
+    ifelse([$1], , :, [$1])
   fi
   AC_SUBST(MYSQL_CFLAGS)
   AC_SUBST(MYSQL_LIBS)
-  rm -f conf.mysqltest
 ])
 
 dnl Removes -I/usr/include/? from given variable
@@ -733,6 +612,22 @@ AC_DEFUN(jm_ICONV,
   fi
 ])
 
+AC_DEFUN(rjs_CHARSET,[
+  dnl Find out if we can convert from $1 to UCS2-LE
+  AC_MSG_CHECKING([can we convert from $1 to UCS2-LE?])
+  AC_TRY_RUN([
+#include <$jm_cv_include>
+main(){
+    iconv_t cd = iconv_open("$1", "UCS-2LE");
+    if (cd == 0 || cd == (iconv_t)-1) {
+       return -1;
+    }
+    return 0;
+}
+  ],ICONV_CHARSET=$1,ICONV_CHARSET=no,ICONV_CHARSET=cross)
+  AC_MSG_RESULT($ICONV_CHARSET)
+])
+
 dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR)
 dnl This function doesn't add -I/usr/include into CFLAGS
 AC_DEFUN(CFLAGS_ADD_DIR,[
index 8316c4b61798607e9aaf1a6f33f1d6abaa5d64e3..553d9a686e31b82a6d52b4c5088d1aa67bd12d01 100644 (file)
@@ -131,7 +131,7 @@ static const uint8 *get_ntlm_challenge(struct auth_context *auth_context)
        
        DEBUG(5, ("auth_context challenge created by %s\n", challenge_set_by));
        DEBUG(5, ("challenge is: \n"));
-       dump_data(5, auth_context->challenge.data, auth_context->challenge.length);
+       dump_data(5, (const char *)auth_context->challenge.data, auth_context->challenge.length);
        
        SMB_ASSERT(auth_context->challenge.length == 8);
 
@@ -228,7 +228,7 @@ static NTSTATUS check_ntlm_password(const struct auth_context *auth_context,
                                        auth_context->challenge_set_by));
 
        DEBUG(10, ("challenge is: \n"));
-       dump_data(5, auth_context->challenge.data, auth_context->challenge.length);
+       dump_data(5, (const char *)auth_context->challenge.data, auth_context->challenge.length);
 
 #ifdef DEBUG_PASSWORD
        DEBUG(100, ("user_info has passwords of length %d and %d\n", 
@@ -373,10 +373,10 @@ BOOL load_auth_module(struct auth_context *auth_context,
        if (p) {
                *p = 0;
                module_params = p+1;
-               trim_string(module_params, " ", " ");
+               trim_char(module_params, ' ', ' ');
        }
        
-       trim_string(module_name, " ", " ");
+       trim_char(module_name, ' ', ' ');
        
        entry = auth_find_backend_entry(module_name);
        
index aacea261febddf86eaa41e47c2bae2feb68a62a3..43e7597cd9626356243688eaa8da2b8c33259606 100644 (file)
@@ -26,9 +26,6 @@
 
 extern BOOL global_machine_password_needs_changing;
 
-extern userdom_struct current_user_info;
-
-
 /**
  * Connect to a remote server for domain security authenticaion.
  *
index fab2d551f29c4e43f66dd41a9e09e97418d7a92c..b295df9328f2be655242bdb4695fec72f3e9dede 100644 (file)
@@ -40,7 +40,7 @@ static BOOL check_user_equiv(const char *user, const char *remote, const char *e
   if (! lines) return False;
   for (i=0; lines[i]; i++) {
     char *buf = lines[i];
-    trim_string(buf," "," ");
+    trim_char(buf,' ',' ');
 
     if (buf[0] != '#' && buf[0] != '\n') 
     {
index fb66d53cd4fee0bd8d4df8a00444a5c70c82ed50..ce97bd7df267c61da055687b2a59e8c05889626e 100644 (file)
@@ -27,8 +27,9 @@
 #define DBGC_CLASS DBGC_AUTH
 
 /****************************************************************************
-core of smb password checking routine.
+ Core of smb password checking routine.
 ****************************************************************************/
+
 static BOOL smb_pwd_check_ntlmv1(const DATA_BLOB *nt_response,
                                 const uchar *part_passwd,
                                 const DATA_BLOB *sec_blob,
@@ -54,8 +55,7 @@ static BOOL smb_pwd_check_ntlmv1(const DATA_BLOB *nt_response,
        }
 
        SMBOWFencrypt(part_passwd, sec_blob->data, p24);
-       if (user_sess_key != NULL)
-       {
+       if (user_sess_key != NULL) {
                SMBsesskeygen_ntv1(part_passwd, NULL, user_sess_key);
        }
        
@@ -74,12 +74,11 @@ static BOOL smb_pwd_check_ntlmv1(const DATA_BLOB *nt_response,
   return (memcmp(p24, nt_response->data, 24) == 0);
 }
 
-
 /****************************************************************************
-core of smb password checking routine. (NTLMv2, LMv2)
-
-Note:  The same code works with both NTLMv2 and LMv2.
+ Core of smb password checking routine. (NTLMv2, LMv2)
+ Note:  The same code works with both NTLMv2 and LMv2.
 ****************************************************************************/
+
 static BOOL smb_pwd_check_ntlmv2(const DATA_BLOB *ntv2_response,
                                 const uchar *part_passwd,
                                 const DATA_BLOB *sec_blob,
@@ -92,8 +91,7 @@ static BOOL smb_pwd_check_ntlmv2(const DATA_BLOB *ntv2_response,
        uchar client_response[16];
        DATA_BLOB client_key_data;
 
-       if (part_passwd == NULL)
-       {
+       if (part_passwd == NULL) {
                DEBUG(10,("No password set - DISALLOWING access\n"));
                /* No password set - always False */
                return False;
@@ -121,8 +119,7 @@ static BOOL smb_pwd_check_ntlmv2(const DATA_BLOB *ntv2_response,
        }
 
        SMBOWFencrypt_ntv2(kr, sec_blob, &client_key_data, value_from_encryption);
-       if (user_sess_key != NULL)
-       {
+       if (user_sess_key != NULL) {
                SMBsesskeygen_ntv2(kr, value_from_encryption, user_sess_key);
        }
 
@@ -142,11 +139,11 @@ static BOOL smb_pwd_check_ntlmv2(const DATA_BLOB *ntv2_response,
        return (memcmp(value_from_encryption, client_response, 16) == 0);
 }
 
-
 /****************************************************************************
  Do a specific test for an smb password being correct, given a smb_password and
  the lanman and NT responses.
 ****************************************************************************/
+
 static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                                TALLOC_CTX *mem_ctx,
                                SAM_ACCOUNT *sampass, 
@@ -158,15 +155,11 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
        uint32 auth_flags;
 
        acct_ctrl = pdb_get_acct_ctrl(sampass);
-       if (acct_ctrl & ACB_PWNOTREQ) 
-       {
-               if (lp_null_passwords()) 
-               {
+       if (acct_ctrl & ACB_PWNOTREQ) {
+               if (lp_null_passwords()) {
                        DEBUG(3,("Account for user '%s' has no password and null passwords are allowed.\n", pdb_get_username(sampass)));
                        return(NT_STATUS_OK);
-               } 
-               else 
-               {
+               } else {
                        DEBUG(3,("Account for user '%s' has no password and null passwords are NOT allowed.\n", pdb_get_username(sampass)));
                        return(NT_STATUS_LOGON_FAILURE);
                }               
@@ -191,8 +184,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                                          nt_pw, &auth_context->challenge, 
                                          user_info->smb_name.str, 
                                          user_info->client_domain.str,
-                                         user_sess_key))
-               {
+                                         user_sess_key)) {
                        return NT_STATUS_OK;
                }
 
@@ -201,9 +193,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                                          nt_pw, &auth_context->challenge, 
                                          user_info->smb_name.str, 
                                          "",
-                                         user_sess_key))
-                   
-               {
+                                         user_sess_key)) {
                        return NT_STATUS_OK;
                } else {
                        DEBUG(3,("sam_password_ok: NTLMv2 password check failed\n"));
@@ -218,8 +208,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                        DEBUG(4,("sam_password_ok: Checking NT MD4 password\n"));
                        if (smb_pwd_check_ntlmv1(&user_info->nt_resp, 
                                                 nt_pw, &auth_context->challenge,
-                                                user_sess_key)) 
-                       {
+                                                user_sess_key)) {
                                return NT_STATUS_OK;
                        } else {
                                DEBUG(3,("sam_password_ok: NT MD4 password check failed for user %s\n",pdb_get_username(sampass)));
@@ -247,8 +236,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                        DEBUG(4,("sam_password_ok: Checking LM password\n"));
                        if (smb_pwd_check_ntlmv1(&user_info->lm_resp, 
                                                 lm_pw, &auth_context->challenge,
-                                                user_sess_key)) 
-                       {
+                                                user_sess_key)) {
                                return NT_STATUS_OK;
                        }
                }
@@ -268,8 +256,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                                          nt_pw, &auth_context->challenge, 
                                          user_info->smb_name.str, 
                                          user_info->client_domain.str,
-                                         user_sess_key))
-               {
+                                         user_sess_key)) {
                        return NT_STATUS_OK;
                }
 
@@ -278,8 +265,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                                          nt_pw, &auth_context->challenge, 
                                          user_info->smb_name.str, 
                                          "",
-                                         user_sess_key))
-               {
+                                         user_sess_key)) {
                        return NT_STATUS_OK;
                }
 
@@ -287,12 +273,10 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
                   - I think this is related to Win9X pass-though authentication
                */
                DEBUG(4,("sam_password_ok: Checking NT MD4 password in LM field\n"));
-               if (lp_ntlm_auth()) 
-               {
+               if (lp_ntlm_auth()) {
                        if (smb_pwd_check_ntlmv1(&user_info->lm_resp, 
                                                 nt_pw, &auth_context->challenge,
-                                                user_sess_key)) 
-                       {
+                                                user_sess_key)) {
                                return NT_STATUS_OK;
                        }
                        DEBUG(3,("sam_password_ok: LM password, NT MD4 password in LM field and LMv2 failed for user %s\n",pdb_get_username(sampass)));
@@ -313,6 +297,7 @@ static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
  Do a specific test for a SAM_ACCOUNT being vaild for this connection 
  (ie not disabled, expired and the like).
 ****************************************************************************/
+
 static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
                               SAM_ACCOUNT *sampass, 
                               const auth_usersupplied_info *user_info)
@@ -325,16 +310,22 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
 
        /* Quit if the account was disabled. */
        if (acct_ctrl & ACB_DISABLED) {
-               DEBUG(1,("Account for user '%s' was disabled.\n", pdb_get_username(sampass)));
+               DEBUG(1,("sam_account_ok: Account for user '%s' was disabled.\n", pdb_get_username(sampass)));
                return NT_STATUS_ACCOUNT_DISABLED;
        }
 
+       /* Quit if the account was locked out. */
+       if (acct_ctrl & ACB_AUTOLOCK) {
+               DEBUG(1,("sam_account_ok: Account for user %s was locked out.\n", pdb_get_username(sampass)));
+               return NT_STATUS_ACCOUNT_LOCKED_OUT;
+       }
+
        /* Test account expire time */
        
        kickoff_time = pdb_get_kickoff_time(sampass);
        if (kickoff_time != 0 && time(NULL) > kickoff_time) {
-               DEBUG(1,("Account for user '%s' has expired.\n", pdb_get_username(sampass)));
-               DEBUG(3,("Account expired at '%ld' unix time.\n", (long)kickoff_time));
+               DEBUG(1,("sam_account_ok: Account for user '%s' has expired.\n", pdb_get_username(sampass)));
+               DEBUG(3,("sam_account_ok: Account expired at '%ld' unix time.\n", (long)kickoff_time));
                return NT_STATUS_ACCOUNT_EXPIRED;
        }
 
@@ -344,14 +335,14 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
 
                /* check for immediate expiry "must change at next logon" */
                if (must_change_time == 0 && last_set_time != 0) {
-                       DEBUG(1,("Account for user '%s' password must change!.\n", pdb_get_username(sampass)));
+                       DEBUG(1,("sam_account_ok: Account for user '%s' password must change!.\n", pdb_get_username(sampass)));
                        return NT_STATUS_PASSWORD_MUST_CHANGE;
                }
 
                /* check for expired password */
                if (must_change_time < time(NULL) && must_change_time != 0) {
-                       DEBUG(1,("Account for user '%s' password expired!.\n", pdb_get_username(sampass)));
-                       DEBUG(1,("Password expired at '%s' (%ld) unix time.\n", http_timestring(must_change_time), (long)must_change_time));
+                       DEBUG(1,("sam_account_ok: Account for user '%s' password expired!.\n", pdb_get_username(sampass)));
+                       DEBUG(1,("sam_account_ok: Password expired at '%s' (%ld) unix time.\n", http_timestring(must_change_time), (long)must_change_time));
                        return NT_STATUS_PASSWORD_EXPIRED;
                }
        }
@@ -359,8 +350,8 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
        /* Test workstation. Workstation list is comma separated. */
 
        workstation_list = talloc_strdup(mem_ctx, pdb_get_workstations(sampass));
-
-       if (!workstation_list) return NT_STATUS_NO_MEMORY;
+       if (!workstation_list)
+               return NT_STATUS_NO_MEMORY;
 
        if (*workstation_list) {
                BOOL invalid_ws = True;
@@ -369,7 +360,7 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
                fstring tok;
                        
                while (next_token(&s, tok, ",", sizeof(tok))) {
-                       DEBUG(10,("checking for workstation match %s and %s (len=%d)\n",
+                       DEBUG(10,("sam_account_ok: checking for workstation match %s and %s (len=%d)\n",
                                  tok, user_info->wksta_name.str, user_info->wksta_name.len));
                        if(strequal(tok, user_info->wksta_name.str)) {
                                invalid_ws = False;
@@ -399,7 +390,6 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
-
 /****************************************************************************
 check if a username/password is OK assuming the password is a 24 byte
 SMB hash supplied in the user_info structure
@@ -434,9 +424,8 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
        ret = pdb_getsampwnam(sampass, user_info->internal_username.str);
        unbecome_root();
 
-       if (ret == False)
-       {
-               DEBUG(3,("Couldn't find user '%s' in passdb file.\n", user_info->internal_username.str));
+       if (ret == False) {
+               DEBUG(3,("check_sam_security: Couldn't find user '%s' in passdb file.\n", user_info->internal_username.str));
                pdb_free_sam(&sampass);
                return NT_STATUS_NO_SUCH_USER;
        }
index 5403ee8c39a5999b0eb5d1084d441513bf59cb43..952aa8ba590c3d5669690bafb1eea3a19734d70e 100644 (file)
@@ -216,8 +216,8 @@ NTSTATUS make_user_info_map(auth_usersupplied_info **user_info,
              client_domain, smb_name, wksta_name));
        
        /* don't allow "" as a domain, fixes a Win9X bug 
-                  where it doens't supply a domain for logon script
-          'net use' commands.*/
+          where it doens't supply a domain for logon script
+          'net use' commands.                                 */
 
        if ( *client_domain )
                domain = client_domain;
@@ -227,7 +227,7 @@ NTSTATUS make_user_info_map(auth_usersupplied_info **user_info,
        /* do what win2k does.  Always map unknown domains to our own
           and let the "passdb backend" handle unknown users. */
 
-       if ( !is_trusted_domain(domain) ) 
+       if ( !is_trusted_domain(domain) && !strequal(domain, get_global_sam_name()) 
                domain = get_default_sam_name();
        
        /* we know that it is a trusted domain (and we are allowing them) or it is our domain */
@@ -393,7 +393,7 @@ BOOL make_user_info_for_reply(auth_usersupplied_info **user_info,
                dump_data(100, plaintext_password.data, plaintext_password.length);
 #endif
 
-               SMBencrypt( (const uchar *)plaintext_password.data, (const uchar*)chal, local_lm_response);
+               SMBencrypt( (const char *)plaintext_password.data, (const uchar*)chal, local_lm_response);
                local_lm_blob = data_blob(local_lm_response, 24);
                
                /* We can't do an NT hash here, as the password needs to be
@@ -646,43 +646,66 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups,
  * of groups.
  ******************************************************************************/
 
-static NTSTATUS get_user_groups_from_local_sam(const char *username, uid_t uid, gid_t gid,
-                                              int *n_groups, DOM_SID **groups, gid_t **unix_groups)
+static NTSTATUS get_user_groups(const char *username, uid_t uid, gid_t gid,
+                                int *n_groups, DOM_SID **groups, gid_t **unix_groups)
 {
-       int               n_unix_groups;
-       int               i;
+       int             n_unix_groups;
+       int             i;
 
        *n_groups = 0;
        *groups   = NULL;
+       
+       /* Try winbind first */
 
-       n_unix_groups = groups_max();
-       if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) {
-               DEBUG(0, ("get_user_groups_from_local_sam: Out of memory allocating unix group list\n"));
-               return NT_STATUS_NO_MEMORY;
+       if ( strchr(username, *lp_winbind_separator()) ) {
+               n_unix_groups = winbind_getgroups( username, unix_groups );
+
+               DEBUG(10,("get_user_groups: winbind_getgroups(%s): result = %s\n", username, 
+                         n_unix_groups == -1 ? "FAIL" : "SUCCESS"));
+                         
+               if ( n_unix_groups == -1 )
+                       return NT_STATUS_NO_SUCH_USER; /* what should this return value be? */  
        }
-       
-       if (sys_getgrouplist(username, gid, *unix_groups, &n_unix_groups) == -1) {
-               gid_t *groups_tmp;
-               groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups);
-               if (!groups_tmp) {
-                       SAFE_FREE(*unix_groups);
+       else {
+               /* fallback to getgrouplist() */
+               
+               n_unix_groups = groups_max();
+               
+               if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) {
+                       DEBUG(0, ("get_user_groups: Out of memory allocating unix group list\n"));
                        return NT_STATUS_NO_MEMORY;
                }
-               *unix_groups = groups_tmp;
-
+       
                if (sys_getgrouplist(username, gid, *unix_groups, &n_unix_groups) == -1) {
-                       DEBUG(0, ("get_user_groups_from_local_sam: failed to get the unix group list\n"));
-                       SAFE_FREE(*unix_groups);
-                       return NT_STATUS_NO_SUCH_USER; /* what should this return value be? */
+               
+                       gid_t *groups_tmp;
+                       
+                       groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups);
+                       
+                       if (!groups_tmp) {
+                               SAFE_FREE(*unix_groups);
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       *unix_groups = groups_tmp;
+
+                       if (sys_getgrouplist(username, gid, *unix_groups, &n_unix_groups) == -1) {
+                               DEBUG(0, ("get_user_groups: failed to get the unix group list\n"));
+                               SAFE_FREE(*unix_groups);
+                               return NT_STATUS_NO_SUCH_USER; /* what should this return value be? */
+                       }
                }
        }
 
        debug_unix_user_token(DBGC_CLASS, 5, uid, gid, n_unix_groups, *unix_groups);
        
+       /* now setup the space for storing the SIDS */
+       
        if (n_unix_groups > 0) {
+       
                *groups   = malloc(sizeof(DOM_SID) * n_unix_groups);
+               
                if (!*groups) {
-                       DEBUG(0, ("get_user_group_from_local_sam: malloc() failed for DOM_SID list!\n"));
+                       DEBUG(0, ("get_user_group: malloc() failed for DOM_SID list!\n"));
                        SAFE_FREE(*unix_groups);
                        return NT_STATUS_NO_MEMORY;
                }
@@ -692,7 +715,8 @@ static NTSTATUS get_user_groups_from_local_sam(const char *username, uid_t uid,
 
        for (i = 0; i < *n_groups; i++) {
                if (!NT_STATUS_IS_OK(gid_to_sid(&(*groups)[i], (*unix_groups)[i]))) {
-                       DEBUG(1, ("get_user_groups_from_local_sam: failed to convert gid %ld to a sid!\n", (long int)(*unix_groups)[i+1]));
+                       DEBUG(1, ("get_user_groups: failed to convert gid %ld to a sid!\n", 
+                               (long int)(*unix_groups)[i+1]));
                        SAFE_FREE(*groups);
                        SAFE_FREE(*unix_groups);
                        return NT_STATUS_NO_SUCH_USER;
@@ -743,10 +767,9 @@ static NTSTATUS add_user_groups(auth_serversupplied_info **server_info,
        BOOL is_guest;
        uint32 rid;
 
-       nt_status = get_user_groups_from_local_sam(pdb_get_username(sampass),
-                                                  uid, gid, 
-                                                  &n_groupSIDs, &groupSIDs,
-                                                  &unix_groups);
+       nt_status = get_user_groups(pdb_get_username(sampass), uid, gid, 
+               &n_groupSIDs, &groupSIDs, &unix_groups);
+               
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(4,("get_user_groups_from_local_sam failed\n"));
                free_server_info(server_info);
@@ -1068,11 +1091,11 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
        /* Store the user group information in the server_info 
           returned to the caller. */
        
-       nt_status = get_user_groups_from_local_sam((*server_info)->unix_name,
+       nt_status = get_user_groups((*server_info)->unix_name,
                uid, gid, &n_lgroupSIDs, &lgroupSIDs, &unix_groups);
-       if ( !NT_STATUS_IS_OK(nt_status) )
-       {
-               DEBUG(4,("get_user_groups_from_local_sam failed\n"));
+               
+       if ( !NT_STATUS_IS_OK(nt_status) ) {
+               DEBUG(4,("get_user_groups failed\n"));
                return nt_status;
        }
 
@@ -1080,9 +1103,9 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
        (*server_info)->n_groups = n_lgroupSIDs;
        
        /* Create a 'combined' list of all SIDs we might want in the SD */
-       all_group_SIDs   = malloc(sizeof(DOM_SID) * 
-                                 (n_lgroupSIDs + info3->num_groups2 +
-                                  info3->num_other_sids));
+       
+       all_group_SIDs = malloc(sizeof(DOM_SID) * (info3->num_groups2 +info3->num_other_sids));
+       
        if (!all_group_SIDs) {
                DEBUG(0, ("malloc() failed for DOM_SID list!\n"));
                SAFE_FREE(lgroupSIDs);
@@ -1090,20 +1113,30 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
+#if 0  /* JERRY -- no such thing as local groups in current code */
        /* Copy the 'local' sids */
        memcpy(all_group_SIDs, lgroupSIDs, sizeof(DOM_SID) * n_lgroupSIDs);
        SAFE_FREE(lgroupSIDs);
+#endif
 
        /* and create (by appending rids) the 'domain' sids */
+       
        for (i = 0; i < info3->num_groups2; i++) {
-               sid_copy(&all_group_SIDs[i+n_lgroupSIDs], &(info3->dom_sid.sid));
-               if (!sid_append_rid(&all_group_SIDs[i+n_lgroupSIDs], info3->gids[i].g_rid)) {
+       
+               sid_copy(&all_group_SIDs[i], &(info3->dom_sid.sid));
+               
+               if (!sid_append_rid(&all_group_SIDs[i], info3->gids[i].g_rid)) {
+               
                        nt_status = NT_STATUS_INVALID_PARAMETER;
+                       
                        DEBUG(3,("could not append additional group rid 0x%x\n",
                                info3->gids[i].g_rid));                 
+                               
                        SAFE_FREE(lgroupSIDs);
                        free_server_info(server_info);
+                       
                        return nt_status;
+                       
                }
        }
 
@@ -1113,19 +1146,20 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
            http://www.microsoft.com/windows2000/techinfo/administration/security/sidfilter.asp
          */
 
-       for (i = 0; i < info3->num_other_sids; i++) 
-               sid_copy(&all_group_SIDs[
-                                n_lgroupSIDs + info3->num_groups2 + i],
+       for (i = 0; i < info3->num_other_sids; i++) {
+               sid_copy(&all_group_SIDs[info3->num_groups2 + i],
                         &info3->other_sids[i].sid);
+       }
        
        /* Where are the 'global' sids... */
 
        /* can the user be guest? if yes, where is it stored? */
-       if (!NT_STATUS_IS_OK(
-                   nt_status = create_nt_user_token(
-                           &user_sid, &group_sid,
-                           n_lgroupSIDs + info3->num_groups2 + info3->num_other_sids, 
-                           all_group_SIDs, False, &token))) {
+       
+       nt_status = create_nt_user_token(&user_sid, &group_sid,
+               info3->num_groups2 + info3->num_other_sids,
+               all_group_SIDs, False, &token);
+               
+       if ( !NT_STATUS_IS_OK(nt_status) ) {
                DEBUG(4,("create_nt_user_token failed\n"));
                SAFE_FREE(all_group_SIDs);
                free_server_info(server_info);
index aa8f345a5b97789ef4139cb6dda22d9cedbb06b7..cae7aadd0c72fa48d6206a6650a10f9b6aa72c74 100644 (file)
@@ -36,7 +36,7 @@ static NTSTATUS get_info3_from_ndr(TALLOC_CTX *mem_ctx, struct winbindd_response
                if (!prs_init(&ps, len, mem_ctx, UNMARSHALL)) {
                        return NT_STATUS_NO_MEMORY;
                }
-               prs_copy_data_in(&ps, info3_ndr, len);
+               prs_copy_data_in(&ps, (char *)info3_ndr, len);
                prs_set_offset(&ps,0);
                if (!net_io_user_info3("", info3, &ps, 1, 3)) {
                        DEBUG(2, ("get_info3_from_ndr: could not parse info3 struct!\n"));
index d666e439b0dc1c742bafdf1d2ff29600c9785e56..3239686a20d49629e42c89fec95d4ae9622d47b5 100644 (file)
@@ -230,7 +230,7 @@ static struct chat_struct *make_pw_chat(char *p)
                special_char_sub(prompt);
                fstrcpy(t->prompt, prompt);
                strlower_m(t->prompt);
-               trim_string(t->prompt, " ", " ");
+               trim_char(t->prompt, ' ', ' ');
 
                if (!next_token(&p, reply, NULL, sizeof(fstring)))
                        break;
@@ -241,7 +241,7 @@ static struct chat_struct *make_pw_chat(char *p)
                special_char_sub(reply);
                fstrcpy(t->reply, reply);
                strlower_m(t->reply);
-               trim_string(t->reply, " ", " ");
+               trim_char(t->reply, ' ', ' ');
 
        }
        return list;
@@ -304,7 +304,7 @@ static int smb_pam_passchange_conv(int num_msg,
                case PAM_PROMPT_ECHO_ON:
                        DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: PAM said: %s\n", msg[replies]->msg));
                        fstrcpy(current_prompt, msg[replies]->msg);
-                       trim_string(current_prompt, " ", " ");
+                       trim_char(current_prompt, ' ', ' ');
                        for (t=pw_chat; t; t=t->next) {
 
                                DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n",
@@ -335,7 +335,7 @@ static int smb_pam_passchange_conv(int num_msg,
                case PAM_PROMPT_ECHO_OFF:
                        DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: PAM said: %s\n", msg[replies]->msg));
                        fstrcpy(current_prompt, msg[replies]->msg);
-                       trim_string(current_prompt, " ", " ");
+                       trim_char(current_prompt, ' ', ' ');
                        for (t=pw_chat; t; t=t->next) {
 
                                DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n",
index 2d91173f4a8d094e78b3c873b7cb56803298e558..6042b82cdce7cb6e5c730dad7537092deb9a8a6d 100755 (executable)
@@ -55,6 +55,11 @@ $AUTOHEADER || exit 1
 echo "$0: running $AUTOCONF"
 $AUTOCONF || exit 1
 
+echo "$0: running script/mkversion.sh"
+./script/mkversion.sh || exit 1
+
+rm -rf autom4te.cache autom4te-2.53.cache
+
 echo "Now run ./configure and then make."
 exit 0
 
index 770100fd3128b4859f949fcdd41423cd284dcb0a..31af1fe22d83e4e3014f36df210e2ba45adbb97d 100644 (file)
@@ -37,6 +37,7 @@ smbstatus
 smbtorture
 smbtree
 smbumount
+smbiconv
 swat
 t_push_ucs2
 t_snprintf
@@ -47,6 +48,7 @@ tdbbackup
 testparm
 testprns
 vfstest
+log2pcap
 wbinfo
 winbindd
 wrepld
index ec29f44e6e0d261f3112c8d12410edd22574c15e..ecece8942ec74e5ff9cac2ce8ee62cf8c09e5226 100644 (file)
@@ -102,9 +102,10 @@ static double dir_total;
 static struct cli_state *do_connect(const char *server, const char *share);
 
 /****************************************************************************
-write to a local file with CR/LF->LF translation if appropriate. return the 
-number taken from the buffer. This may not equal the number written.
+ Write to a local file with CR/LF->LF translation if appropriate. Return the 
+ number taken from the buffer. This may not equal the number written.
 ****************************************************************************/
+
 static int writefile(int f, char *b, int n)
 {
        int i;
@@ -129,9 +130,10 @@ static int writefile(int f, char *b, int n)
 }
 
 /****************************************************************************
 read from a file with LF->CR/LF translation if appropriate. return the 
 number read. read approx n bytes.
Read from a file with LF->CR/LF translation if appropriate. Return the 
+ number read. read approx n bytes.
 ****************************************************************************/
+
 static int readfile(char *b, int n, XFILE *f)
 {
        int i;
@@ -156,10 +158,10 @@ static int readfile(char *b, int n, XFILE *f)
        return(i);
 }
  
-
 /****************************************************************************
-send a message
+ Send a message.
 ****************************************************************************/
+
 static void send_message(void)
 {
        int total_len = 0;
@@ -206,11 +208,10 @@ static void send_message(void)
        }      
 }
 
-
-
 /****************************************************************************
-check the space on a device
+ Check the space on a device.
 ****************************************************************************/
+
 static int do_dskattr(void)
 {
        int total, bsize, avail;
@@ -227,8 +228,9 @@ static int do_dskattr(void)
 }
 
 /****************************************************************************
-show cd/pwd
+ Show cd/pwd.
 ****************************************************************************/
+
 static int cmd_pwd(void)
 {
        d_printf("Current directory is %s",service);
@@ -236,10 +238,10 @@ static int cmd_pwd(void)
        return 0;
 }
 
-
 /****************************************************************************
-change directory - inner section
+ Change directory - inner section.
 ****************************************************************************/
+
 static int do_cd(char *newdir)
 {
        char *p = newdir;
@@ -276,8 +278,9 @@ static int do_cd(char *newdir)
 }
 
 /****************************************************************************
-change directory
+ Change directory.
 ****************************************************************************/
+
 static int cmd_cd(void)
 {
        fstring buf;
@@ -291,13 +294,14 @@ static int cmd_cd(void)
        return rc;
 }
 
-
 /*******************************************************************
-  decide if a file should be operated on
-  ********************************************************************/
+ Decide if a file should be operated on.
+********************************************************************/
+
 static BOOL do_this_one(file_info *finfo)
 {
-       if (finfo->mode & aDIR) return(True);
+       if (finfo->mode & aDIR)
+               return(True);
 
        if (*fileselection && 
            !mask_match(finfo->name,fileselection,False)) {
@@ -319,8 +323,9 @@ static BOOL do_this_one(file_info *finfo)
 }
 
 /****************************************************************************
-  display info about a file
-  ****************************************************************************/
+ Display info about a file.
+****************************************************************************/
+
 static void display_finfo(file_info *finfo)
 {
        if (do_this_one(finfo)) {
@@ -334,10 +339,10 @@ static void display_finfo(file_info *finfo)
        }
 }
 
-
 /****************************************************************************
-   accumulate size of a file
-  ****************************************************************************/
+ Accumulate size of a file.
+****************************************************************************/
+
 static void do_du(file_info *finfo)
 {
        if (do_this_one(finfo)) {
@@ -354,8 +359,8 @@ static long do_list_queue_end = 0;
 static void (*do_list_fn)(file_info *);
 
 /****************************************************************************
-functions for do_list_queue
-  ****************************************************************************/
+ Functions for do_list_queue.
+****************************************************************************/
 
 /*
  * The do_list_queue is a NUL-separated list of strings stored in a
@@ -368,6 +373,7 @@ functions for do_list_queue
  * Functions check to ensure that do_list_queue is non-NULL before
  * accessing it.
  */
+
 static void reset_do_list_queue(void)
 {
        SAFE_FREE(do_list_queue);
@@ -396,14 +402,11 @@ static void adjust_do_list_queue(void)
         * If the starting point of the queue is more than half way through,
         * move everything toward the beginning.
         */
-       if (do_list_queue && (do_list_queue_start == do_list_queue_end))
-       {
+       if (do_list_queue && (do_list_queue_start == do_list_queue_end)) {
                DEBUG(4,("do_list_queue is empty\n"));
                do_list_queue_start = do_list_queue_end = 0;
                *do_list_queue = '\0';
-       }
-       else if (do_list_queue_start > (do_list_queue_size / 2))
-       {
+       } else if (do_list_queue_start > (do_list_queue_size / 2)) {
                DEBUG(4,("sliding do_list_queue backward\n"));
                memmove(do_list_queue,
                        do_list_queue + do_list_queue_start,
@@ -411,15 +414,13 @@ static void adjust_do_list_queue(void)
                do_list_queue_end -= do_list_queue_start;
                do_list_queue_start = 0;
        }
-          
 }
 
 static void add_to_do_list_queue(const char* entry)
 {
        char *dlq;
        long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
-       while (new_end > do_list_queue_size)
-       {
+       while (new_end > do_list_queue_size) {
                do_list_queue_size *= 2;
                DEBUG(4,("enlarging do_list_queue to %d\n",
                         (int)do_list_queue_size));
@@ -428,16 +429,13 @@ static void add_to_do_list_queue(const char* entry)
                        d_printf("failure enlarging do_list_queue to %d bytes\n",
                                 (int)do_list_queue_size);
                        reset_do_list_queue();
-               }
-               else
-               {
+               } else {
                        do_list_queue = dlq;
                        memset(do_list_queue + do_list_queue_size / 2,
                               0, do_list_queue_size / 2);
                }
        }
-       if (do_list_queue)
-       {
+       if (do_list_queue) {
                safe_strcpy_base(do_list_queue + do_list_queue_end, 
                                 entry, do_list_queue, do_list_queue_size);
                do_list_queue_end = new_end;
@@ -453,8 +451,7 @@ static char *do_list_queue_head(void)
 
 static void remove_do_list_queue_head(void)
 {
-       if (do_list_queue_end > do_list_queue_start)
-       {
+       if (do_list_queue_end > do_list_queue_start) {
                do_list_queue_start += strlen(do_list_queue_head()) + 1;
                adjust_do_list_queue();
                DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n",
@@ -468,8 +465,9 @@ static int do_list_queue_empty(void)
 }
 
 /****************************************************************************
-a helper for do_list
-  ****************************************************************************/
+ A helper for do_list.
+****************************************************************************/
+
 static void do_list_helper(file_info *f, const char *mask, void *state)
 {
        if (f->mode & aDIR) {
@@ -489,7 +487,8 @@ static void do_list_helper(file_info *f, const char *mask, void *state)
 
                        pstrcpy(mask2, mask);
                        p = strrchr_m(mask2,'\\');
-                       if (!p) return;
+                       if (!p)
+                               return;
                        p[1] = 0;
                        pstrcat(mask2, f->name);
                        pstrcat(mask2,"\\*");
@@ -503,16 +502,15 @@ static void do_list_helper(file_info *f, const char *mask, void *state)
        }
 }
 
-
 /****************************************************************************
-a wrapper around cli_list that adds recursion
-  ****************************************************************************/
+ A wrapper around cli_list that adds recursion.
+****************************************************************************/
+
 void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
 {
        static int in_do_list = 0;
 
-       if (in_do_list && rec)
-       {
+       if (in_do_list && rec) {
                fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
                exit(1);
        }
@@ -523,13 +521,11 @@ void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec,
        do_list_dirs = dirs;
        do_list_fn = fn;
 
-       if (rec)
-       {
+       if (rec) {
                init_do_list_queue();
                add_to_do_list_queue(mask);
                
-               while (! do_list_queue_empty())
-               {
+               while (! do_list_queue_empty()) {
                        /*
                         * Need to copy head so that it doesn't become
                         * invalid inside the call to cli_list.  This
@@ -541,30 +537,24 @@ void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec,
                        pstrcpy(head, do_list_queue_head());
                        cli_list(cli, head, attribute, do_list_helper, NULL);
                        remove_do_list_queue_head();
-                       if ((! do_list_queue_empty()) && (fn == display_finfo))
-                       {
+                       if ((! do_list_queue_empty()) && (fn == display_finfo)) {
                                char* next_file = do_list_queue_head();
                                char* save_ch = 0;
                                if ((strlen(next_file) >= 2) &&
                                    (next_file[strlen(next_file) - 1] == '*') &&
-                                   (next_file[strlen(next_file) - 2] == '\\'))
-                               {
+                                   (next_file[strlen(next_file) - 2] == '\\')) {
                                        save_ch = next_file +
                                                strlen(next_file) - 2;
                                        *save_ch = '\0';
                                }
                                d_printf("\n%s\n",next_file);
-                               if (save_ch)
-                               {
+                               if (save_ch) {
                                        *save_ch = '\\';
                                }
                        }
                }
-       }
-       else
-       {
-               if (cli_list(cli, mask, attribute, do_list_helper, NULL) == -1)
-               {
+       } else {
+               if (cli_list(cli, mask, attribute, do_list_helper, NULL) == -1) {
                        d_printf("%s listing %s\n", cli_errstr(cli), mask);
                }
        }
@@ -574,8 +564,9 @@ void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec,
 }
 
 /****************************************************************************
-  get a directory listing
-  ****************************************************************************/
+ Get a directory listing.
+****************************************************************************/
+
 static int cmd_dir(void)
 {
        uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
@@ -595,8 +586,7 @@ static int cmd_dir(void)
                        pstrcpy(mask,p);
                else
                        pstrcat(mask,p);
-       }
-       else {
+       } else {
                pstrcat(mask,"*");
        }
 
@@ -609,10 +599,10 @@ static int cmd_dir(void)
        return rc;
 }
 
-
 /****************************************************************************
-  get a directory listing
-  ****************************************************************************/
+ Get a directory listing.
+****************************************************************************/
+
 static int cmd_du(void)
 {
        uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
@@ -645,10 +635,10 @@ static int cmd_du(void)
        return rc;
 }
 
-
 /****************************************************************************
-  get a file from rname to lname
-  ****************************************************************************/
+ Get a file from rname to lname
+****************************************************************************/
+
 static int do_get(char *rname, char *lname, BOOL reget)
 {  
        int handle = 0, fnum;
@@ -718,7 +708,8 @@ static int do_get(char *rname, char *lname, BOOL reget)
        while (1) {
                int n = cli_read(cli, fnum, data, nread + start, read_size);
 
-               if (n <= 0) break;
+               if (n <= 0)
+                       break;
  
                if (writefile(handle,data, n) != n) {
                        d_printf("Error writing local file\n");
@@ -770,10 +761,10 @@ static int do_get(char *rname, char *lname, BOOL reget)
        return rc;
 }
 
-
 /****************************************************************************
-  get a file
-  ****************************************************************************/
+ Get a file.
+****************************************************************************/
+
 static int cmd_get(void)
 {
        pstring lname;
@@ -797,10 +788,10 @@ static int cmd_get(void)
        return do_get(rname, lname, False);
 }
 
-
 /****************************************************************************
-  do a mget operation on one file
-  ****************************************************************************/
+ Do an mget operation on one file.
+****************************************************************************/
+
 static void do_mget(file_info *finfo)
 {
        pstring rname;
@@ -823,7 +814,8 @@ static void do_mget(file_info *finfo)
                slprintf(quest,sizeof(pstring)-1,
                         "Get file %s? ",finfo->name);
 
-       if (prompt && !yesno(quest)) return;
+       if (prompt && !yesno(quest))
+               return;
 
        if (!(finfo->mode & aDIR)) {
                pstrcpy(rname,cur_dir);
@@ -863,10 +855,10 @@ static void do_mget(file_info *finfo)
        pstrcpy(cur_dir,saved_curdir);
 }
 
-
 /****************************************************************************
-view the file using the pager
+ View the file using the pager.
 ****************************************************************************/
+
 static int cmd_more(void)
 {
        fstring rname,lname,pager_cmd;
@@ -904,11 +896,10 @@ static int cmd_more(void)
        return rc;
 }
 
-
-
 /****************************************************************************
-do a mget command
+ Do a mget command.
 ****************************************************************************/
+
 static int cmd_mget(void)
 {
        uint16 attribute = aSYSTEM | aHIDDEN;
@@ -946,10 +937,10 @@ static int cmd_mget(void)
        return 0;
 }
 
-
 /****************************************************************************
-make a directory of name "name"
+ Make a directory of name "name".
 ****************************************************************************/
+
 static BOOL do_mkdir(char *name)
 {
        if (!cli_mkdir(cli, name)) {
@@ -962,8 +953,9 @@ static BOOL do_mkdir(char *name)
 }
 
 /****************************************************************************
-show 8.3 name of a file
+ Show 8.3 name of a file.
 ****************************************************************************/
+
 static BOOL do_altname(char *name)
 {
        fstring altname;
@@ -977,10 +969,10 @@ static BOOL do_altname(char *name)
        return(True);
 }
 
-
 /****************************************************************************
  Exit client.
 ****************************************************************************/
+
 static int cmd_quit(void)
 {
        cli_shutdown(cli);
@@ -989,10 +981,10 @@ static int cmd_quit(void)
        return 0;
 }
 
-
 /****************************************************************************
-  make a directory
-  ****************************************************************************/
+ Make a directory.
+****************************************************************************/
+
 static int cmd_mkdir(void)
 {
        pstring mask;
@@ -1014,7 +1006,7 @@ static int cmd_mkdir(void)
                *ddir2 = 0;
                
                pstrcpy(ddir,mask);
-               trim_string(ddir,".",NULL);
+               trim_char(ddir,'.','\0');
                p = strtok(ddir,"/\\");
                while (p) {
                        pstrcat(ddir2,p);
@@ -1031,10 +1023,10 @@ static int cmd_mkdir(void)
        return 0;
 }
 
-
 /****************************************************************************
-  show alt name
-  ****************************************************************************/
+ Show alt name.
+****************************************************************************/
+
 static int cmd_altname(void)
 {
        pstring name;
@@ -1054,10 +1046,10 @@ static int cmd_altname(void)
        return 0;
 }
 
-
 /****************************************************************************
-  put a single file
-  ****************************************************************************/
+ Put a single file.
+****************************************************************************/
+
 static int do_put(char *rname, char *lname, BOOL reput)
 {
        int fnum;
@@ -1111,7 +1103,6 @@ static int do_put(char *rname, char *lname, BOOL reput)
                d_printf("Error opening local file %s\n",lname);
                return 1;
        }
-
   
        DEBUG(1,("putting file %s as %s ",lname,
                 rname));
@@ -1183,11 +1174,10 @@ static int do_put(char *rname, char *lname, BOOL reput)
        return rc;
 }
 
-
 /****************************************************************************
-  put a file
-  ****************************************************************************/
+ Put a file.
+****************************************************************************/
+
 static int cmd_put(void)
 {
        pstring lname;
@@ -1226,7 +1216,7 @@ static int cmd_put(void)
 }
 
 /*************************************
-  File list structure
+ File list structure.
 *************************************/
 
 static struct file_list {
@@ -1236,15 +1226,14 @@ static struct file_list {
 } *file_list;
 
 /****************************************************************************
-  Free a file_list structure
+ Free a file_list structure.
 ****************************************************************************/
 
 static void free_file_list (struct file_list * list)
 {
        struct file_list *tmp;
        
-       while (list)
-       {
+       while (list) {
                tmp = list;
                DLIST_REMOVE(list, list);
                SAFE_FREE(tmp->file_path);
@@ -1253,9 +1242,10 @@ static void free_file_list (struct file_list * list)
 }
 
 /****************************************************************************
-  seek in a directory/file list until you get something that doesn't start with
-  the specified name
-  ****************************************************************************/
+ Seek in a directory/file list until you get something that doesn't start with
+ the specified name.
+****************************************************************************/
+
 static BOOL seek_list(struct file_list *list, char *name)
 {
        while (list) {
@@ -1270,8 +1260,9 @@ static BOOL seek_list(struct file_list *list, char *name)
 }
 
 /****************************************************************************
-  set the file selection mask
-  ****************************************************************************/
+ Set the file selection mask.
+****************************************************************************/
+
 static int cmd_select(void)
 {
        pstrcpy(fileselection,"");
@@ -1284,6 +1275,7 @@ static int cmd_select(void)
   Recursive file matching function act as find
   match must be always set to True when calling this function
 ****************************************************************************/
+
 static int file_find(struct file_list **list, const char *directory, 
                      const char *expression, BOOL match)
 {
@@ -1296,11 +1288,14 @@ static int file_find(struct file_list **list, const char *directory,
        const char *dname;
 
         dir = opendir(directory);
-       if (!dir) return -1;
+       if (!dir)
+               return -1;
        
         while ((dname = readdirname(dir))) {
-               if (!strcmp("..", dname)) continue;
-               if (!strcmp(".", dname)) continue;
+               if (!strcmp("..", dname))
+                       continue;
+               if (!strcmp(".", dname))
+                       continue;
                
                if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
                        continue;
@@ -1344,8 +1339,9 @@ static int file_find(struct file_list **list, const char *directory,
 }
 
 /****************************************************************************
-  mput some files
-  ****************************************************************************/
+ mput some files.
+****************************************************************************/
+
 static int cmd_mput(void)
 {
        fstring buf;
@@ -1425,10 +1421,10 @@ static int cmd_mput(void)
        return 0;
 }
 
-
 /****************************************************************************
-  cancel a print job
-  ****************************************************************************/
+ Cancel a print job.
+****************************************************************************/
+
 static int do_cancel(int job)
 {
        if (cli_printjob_del(cli, job)) {
@@ -1440,10 +1436,10 @@ static int do_cancel(int job)
        }
 }
 
-
 /****************************************************************************
-  cancel a print job
-  ****************************************************************************/
+ Cancel a print job.
+****************************************************************************/
+
 static int cmd_cancel(void)
 {
        fstring buf;
@@ -1461,10 +1457,10 @@ static int cmd_cancel(void)
        return 0;
 }
 
-
 /****************************************************************************
-  print a file
-  ****************************************************************************/
+ Print a file.
+****************************************************************************/
+
 static int cmd_print(void)
 {
        pstring lname;
@@ -1489,18 +1485,19 @@ static int cmd_print(void)
        return do_put(rname, lname, False);
 }
 
-
 /****************************************************************************
- show a print queue entry
+ Show a print queue entry.
 ****************************************************************************/
+
 static void queue_fn(struct print_job_info *p)
 {
        d_printf("%-6d   %-9d    %s\n", (int)p->id, (int)p->size, p->name);
 }
 
 /****************************************************************************
- show a print queue
+ Show a print queue.
 ****************************************************************************/
+
 static int cmd_queue(void)
 {
        cli_print_queue(cli, queue_fn);
@@ -1509,8 +1506,9 @@ static int cmd_queue(void)
 }
 
 /****************************************************************************
-delete some files
+ Delete some files.
 ****************************************************************************/
+
 static void do_del(file_info *finfo)
 {
        pstring mask;
@@ -1527,8 +1525,9 @@ static void do_del(file_info *finfo)
 }
 
 /****************************************************************************
-delete some files
+ Delete some files.
 ****************************************************************************/
+
 static int cmd_del(void)
 {
        pstring mask;
@@ -1553,6 +1552,7 @@ static int cmd_del(void)
 
 /****************************************************************************
 ****************************************************************************/
+
 static int cmd_open(void)
 {
        pstring mask;
@@ -1573,8 +1573,9 @@ static int cmd_open(void)
 
 
 /****************************************************************************
-remove a directory
+ Remove a directory.
 ****************************************************************************/
+
 static int cmd_rmdir(void)
 {
        pstring mask;
@@ -1739,8 +1740,9 @@ static int cmd_chown(void)
 }
 
 /****************************************************************************
-rename some files
+ Rename some file.
 ****************************************************************************/
+
 static int cmd_rename(void)
 {
        pstring src,dest;
@@ -1766,10 +1768,10 @@ static int cmd_rename(void)
        return 0;
 }
 
-
 /****************************************************************************
-toggle the prompt flag
+ Toggle the prompt flag.
 ****************************************************************************/
+
 static int cmd_prompt(void)
 {
        prompt = !prompt;
@@ -1778,10 +1780,10 @@ static int cmd_prompt(void)
        return 1;
 }
 
-
 /****************************************************************************
-set the newer than time
+ Set the newer than time.
 ****************************************************************************/
+
 static int cmd_newer(void)
 {
        fstring buf;
@@ -1806,8 +1808,9 @@ static int cmd_newer(void)
 }
 
 /****************************************************************************
-set the archive level
+ Set the archive level.
 ****************************************************************************/
+
 static int cmd_archive(void)
 {
        fstring buf;
@@ -1821,8 +1824,9 @@ static int cmd_archive(void)
 }
 
 /****************************************************************************
-toggle the lowercaseflag
+ Toggle the lowercaseflag.
 ****************************************************************************/
+
 static int cmd_lowercase(void)
 {
        lowercase = !lowercase;
@@ -1831,12 +1835,10 @@ static int cmd_lowercase(void)
        return 0;
 }
 
-
-
-
 /****************************************************************************
-toggle the recurse flag
+ Toggle the recurse flag.
 ****************************************************************************/
+
 static int cmd_recurse(void)
 {
        recurse = !recurse;
@@ -1846,8 +1848,9 @@ static int cmd_recurse(void)
 }
 
 /****************************************************************************
-toggle the translate flag
+ Toggle the translate flag.
 ****************************************************************************/
+
 static int cmd_translate(void)
 {
        translation = !translation;
@@ -1857,10 +1860,10 @@ static int cmd_translate(void)
        return 0;
 }
 
-
 /****************************************************************************
-do a printmode command
+ Do a printmode command.
 ****************************************************************************/
+
 static int cmd_printmode(void)
 {
        fstring buf;
@@ -1877,8 +1880,7 @@ static int cmd_printmode(void)
                }
        }
 
-       switch(printmode)
-               {
+       switch(printmode) {
                case 0: 
                        fstrcpy(mode,"text");
                        break;
@@ -1888,7 +1890,7 @@ static int cmd_printmode(void)
                default: 
                        slprintf(mode,sizeof(mode)-1,"%d",printmode);
                        break;
-               }
+       }
        
        DEBUG(2,("the printmode is now %s\n",mode));
 
@@ -1896,8 +1898,9 @@ static int cmd_printmode(void)
 }
 
 /****************************************************************************
- do the lcd command
+ Do the lcd command.
  ****************************************************************************/
+
 static int cmd_lcd(void)
 {
        fstring buf;
@@ -1911,8 +1914,9 @@ static int cmd_lcd(void)
 }
 
 /****************************************************************************
- get a file restarting at end of local file
+ Get a file restarting at end of local file.
  ****************************************************************************/
+
 static int cmd_reget(void)
 {
        pstring local_name;
@@ -1937,8 +1941,9 @@ static int cmd_reget(void)
 }
 
 /****************************************************************************
- put a file restarting at end of local file
+ Put a file restarting at end of local file.
  ****************************************************************************/
+
 static int cmd_reput(void)
 {
        pstring local_name;
@@ -1971,10 +1976,10 @@ static int cmd_reput(void)
        return do_put(remote_name, local_name, True);
 }
 
-
 /****************************************************************************
- list a share name
+ List a share name.
  ****************************************************************************/
+
 static void browse_fn(const char *name, uint32 m, 
                       const char *comment, void *state)
 {
@@ -2000,10 +2005,10 @@ static void browse_fn(const char *name, uint32 m,
                name,typestr,comment);
 }
 
-
 /****************************************************************************
-try and browse available connections on a host
+ Try and browse available connections on a host.
 ****************************************************************************/
+
 static BOOL browse_host(BOOL sort)
 {
        int ret;
@@ -2018,8 +2023,9 @@ static BOOL browse_host(BOOL sort)
 }
 
 /****************************************************************************
-list a server name
+ List a server name.
 ****************************************************************************/
+
 static void server_fn(const char *name, uint32 m, 
                       const char *comment, void *state)
 {
@@ -2027,11 +2033,13 @@ static void server_fn(const char *name, uint32 m,
 }
 
 /****************************************************************************
-try and browse available connections on a host
+ Try and browse available connections on a host.
 ****************************************************************************/
+
 static BOOL list_servers(char *wk_grp)
 {
-       if (!cli->server_domain) return False;
+       if (!cli->server_domain)
+               return False;
        
         d_printf("\n\tServer               Comment\n");
         d_printf("\t---------            -------\n");
@@ -2062,8 +2070,7 @@ static struct
   int (*fn)(void);
   const char *description;
   char compl_args[2];      /* Completion argument info */
-} commands[] = 
-{
+} commands[] = {
   {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
   {"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
   {"archive",cmd_archive,"<level>\n0=ignore archive bit\n1=only get archive files\n2=only get archive files and reset archive bit\n3=get all files and reset archive bit",{COMPL_NONE,COMPL_NONE}},
@@ -2117,11 +2124,11 @@ static struct
   {NULL,NULL,NULL,{COMPL_NONE,COMPL_NONE}}
 };
 
-
 /*******************************************************************
-  lookup a command string in the list of commands, including 
-  abbreviations
-  ******************************************************************/
+ Lookup a command string in the list of commands, including 
+ abbreviations.
+******************************************************************/
+
 static int process_tok(fstring tok)
 {
        int i = 0, matches = 0;
@@ -2149,8 +2156,9 @@ static int process_tok(fstring tok)
 }
 
 /****************************************************************************
-help
+ Help.
 ****************************************************************************/
+
 static int cmd_help(void)
 {
        int i=0,j;
@@ -2172,8 +2180,9 @@ static int cmd_help(void)
 }
 
 /****************************************************************************
-process a -c command string
+ Process a -c command string.
 ****************************************************************************/
+
 static int process_command_string(char *cmd)
 {
        pstring line;
@@ -2198,7 +2207,8 @@ static int process_command_string(char *cmd)
                        line[1000] = '\0';
                        cmd += strlen(cmd);
                } else {
-                       if (p - cmd > 999) p = cmd + 999;
+                       if (p - cmd > 999)
+                               p = cmd + 999;
                        strncpy(line, cmd, p - cmd);
                        line[p - cmd] = '\0';
                        cmd = p + 1;
@@ -2403,8 +2413,9 @@ cleanup:
 }
 
 /****************************************************************************
-make sure we swallow keepalives during idle time
+ Make sure we swallow keepalives during idle time.
 ****************************************************************************/
+
 static void readline_callback(void)
 {
        fd_set fds;
@@ -2414,7 +2425,8 @@ static void readline_callback(void)
 
        t = time(NULL);
 
-       if (t - last_t < 5) return;
+       if (t - last_t < 5)
+               return;
 
        last_t = t;
 
@@ -2442,10 +2454,10 @@ static void readline_callback(void)
        cli_chkpath(cli, "\\");
 }
 
-
 /****************************************************************************
-process commands on stdin
+ Process commands on stdin.
 ****************************************************************************/
+
 static void process_stdin(void)
 {
        const char *ptr;
@@ -2485,10 +2497,10 @@ static void process_stdin(void)
        }
 }
 
-
 /***************************************************** 
-return a connection to a server
+ Return a connection to a server.
 *******************************************************/
+
 static struct cli_state *do_connect(const char *server, const char *share)
 {
        struct cli_state *c;
@@ -2560,6 +2572,7 @@ static struct cli_state *do_connect(const char *server, const char *share)
                char *pass = getpass("Password: ");
                if (pass) {
                        pstrcpy(password, pass);
+                       got_pass = 1;
                }
        }
 
@@ -2602,10 +2615,10 @@ static struct cli_state *do_connect(const char *server, const char *share)
        return c;
 }
 
-
 /****************************************************************************
-  process commands from the client
+ Process commands from the client.
 ****************************************************************************/
+
 static int process(char *base_directory)
 {
        int rc = 0;
@@ -2628,8 +2641,9 @@ static int process(char *base_directory)
 }
 
 /****************************************************************************
-handle a -L query
+ Handle a -L query.
 ****************************************************************************/
+
 static int do_host_query(char *query_host)
 {
        cli = do_connect(query_host, "IPC$");
@@ -2637,6 +2651,22 @@ static int do_host_query(char *query_host)
                return 1;
 
        browse_host(True);
+
+       if (port != 139) {
+
+               /* Workgroups simply don't make sense over anything
+                  else but port 139... */
+
+               cli_shutdown(cli);
+               port = 139;
+               cli = do_connect(query_host, "IPC$");
+       }
+
+       if (cli == NULL) {
+               d_printf("NetBIOS over TCP disabled -- no workgroup available\n");
+               return 1;
+       }
+
        list_servers(lp_workgroup());
 
        cli_shutdown(cli);
@@ -2646,8 +2676,9 @@ static int do_host_query(char *query_host)
 
 
 /****************************************************************************
-handle a tar operation
+ Handle a tar operation.
 ****************************************************************************/
+
 static int do_tar_op(char *base_directory)
 {
        int ret;
@@ -2671,8 +2702,9 @@ static int do_tar_op(char *base_directory)
 }
 
 /****************************************************************************
-handle a message operation
+ Handle a message operation.
 ****************************************************************************/
+
 static int do_message_op(void)
 {
        struct in_addr ip;
@@ -2715,6 +2747,7 @@ static int do_message_op(void)
  * We don't actually do anything yet -- we just stash the name in a
  * global variable and do the query when all options have been read.
  **/
+
 static void remember_query_host(const char *arg,
                                pstring query_host)
 {
@@ -2729,12 +2762,13 @@ static void remember_query_host(const char *arg,
        }
 }
 
-
 /****************************************************************************
   main program
 ****************************************************************************/
+
  int main(int argc,char *argv[])
 {
+       extern BOOL AllowDebugChange;
        fstring base_directory;
        int opt;
        pstring query_host;
@@ -2745,6 +2779,7 @@ static void remember_query_host(const char *arg,
        poptContext pc;
        char *p;
        int rc = 0;
+       fstring new_workgroup;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
 
@@ -2775,14 +2810,17 @@ static void remember_query_host(const char *arg,
 
        *query_host = 0;
        *base_directory = 0;
+       
+       /* initialize the workgroup name so we can determine whether or 
+          not it was set by a command line option */
+          
+       set_global_myworkgroup( "" );
 
-       setup_logging(argv[0],True);
+        /* set default debug level to 0 regardless of what smb.conf sets */
+       DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
+       dbf = x_stderr;
+       x_setbuf( x_stderr, NULL );
 
-       if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
-               fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
-                       argv[0], dyn_CONFIGFILE);
-       }
-       
        pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 
                                POPT_CONTEXT_KEEP_FIRST);
        poptSetOtherOptionHelp(pc, "service <password>");
@@ -2798,7 +2836,8 @@ static void remember_query_host(const char *arg,
                         */
                        name_type = 0x03; 
                        pstrcpy(desthost,poptGetOptArg(pc));
-                       if( 0 == port ) port = 139;
+                       if( 0 == port )
+                               port = 139;
                        message = True;
                        break;
                case 'I':
@@ -2853,7 +2892,29 @@ static void remember_query_host(const char *arg,
 
        poptGetArg(pc);
        
+       /*
+        * Don't load debug level from smb.conf. It should be
+        * set by cmdline arg or remain default (0)
+        */
+       AllowDebugChange = False;
+       
+       /* save the workgroup...
+       
+          FIXME!! do we need to do tyhis for other options as well 
+          (or maybe a generic way to keep lp_load() from overwriting 
+          everything)?  */
+       
+       fstrcpy( new_workgroup, lp_workgroup() );               
+       
+       if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
+               fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
+                       argv[0], dyn_CONFIGFILE);
+       }
+       
        load_interfaces();
+       
+       if ( strlen(new_workgroup) != 0 )
+               set_global_myworkgroup( new_workgroup );
 
        if(poptPeekArg(pc)) {
                pstrcpy(service,poptGetArg(pc));  
@@ -2890,7 +2951,7 @@ static void remember_query_host(const char *arg,
        use_kerberos = cmdline_auth_info.use_kerberos;
        got_pass = cmdline_auth_info.got_pass;
 
-       DEBUG( 3, ( "Client started (version %s).\n", VERSION ) );
+       DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING));
 
        if (tar_type) {
                if (cmdstr)
index 5295de8010ba75fa51c063a54bd640b5e6373c56..b01de5b8e705fc4a9c0486e0f7b69b7b3ac65552 100644 (file)
@@ -122,7 +122,7 @@ static void writetarheader(int f,  const char *aname, SMB_BIG_UINT size, time_t
 static void do_atar(char *rname,char *lname,file_info *finfo1);
 static void do_tar(file_info *finfo);
 static void oct_it(SMB_BIG_UINT value, int ndgs, char *p);
-static void fixtarname(char *tptr, const char *fp, int l);
+static void fixtarname(char *tptr, const char *fp, size_t l);
 static int dotarbuf(int f, char *b, int n);
 static void dozerobuf(int f, int n);
 static void dotareof(int f);
@@ -171,7 +171,10 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m
        memset(hb.dummy, 0, sizeof(hb.dummy));
   
        l=strlen(aname);
-       if (l >= NAMSIZ - 1) {
+       /* We will be prepending a '.' in fixtarheader so use +2 to
+        * take care of the . and terminating zero. JRA.
+        */
+       if (l+2 >= NAMSIZ) {
                /* write a GNU tar style long header */
                char *b;
                b = (char *)malloc(l+TBLOCK+100);
@@ -181,15 +184,14 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m
                }
                writetarheader(f, "/./@LongLink", l+2, 0, "     0 \0", 'L');
                memset(b, 0, l+TBLOCK+100);
-               fixtarname(b, aname, l);
+               fixtarname(b, aname, l+2);
                i = strlen(b)+1;
                DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b)));
                dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1));
                SAFE_FREE(b);
        }
 
-       /* use l + 1 to do the null too */
-       fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1);
+       fixtarname(hb.dbuf.name, aname, (l+2 >= NAMSIZ) ? NAMSIZ : l + 2);
 
        if (lowercase)
                strlower_m(hb.dbuf.name);
@@ -419,13 +421,14 @@ static void dotareof(int f)
 (Un)mangle DOS pathname, make nonabsolute
 ****************************************************************************/
 
-static void fixtarname(char *tptr, const char *fp, int l)
+static void fixtarname(char *tptr, const char *fp, size_t l)
 {
        /* add a '.' to start of file name, convert from ugly dos \'s in path
         * to lovely unix /'s :-} */
        *tptr++='.';
+       l--;
 
-       safe_strcpy(tptr, fp, l);
+       StrnCpy(tptr, fp, l-1);
        string_replace(tptr, '\\', '/');
 }
 
@@ -1477,7 +1480,7 @@ accordingly.
 static int read_inclusion_file(char *filename)
 {
        XFILE *inclusion = NULL;
-       char buf[MAXPATHLEN + 1];
+       char buf[PATH_MAX + 1];
        char *inclusion_buffer = NULL;
        int inclusion_buffer_size = 0;
        int inclusion_buffer_sofar = 0;
@@ -1487,7 +1490,7 @@ static int read_inclusion_file(char *filename)
        int error = 0;
 
        clipn = 0;
-       buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */
+       buf[PATH_MAX] = '\0'; /* guarantee null-termination */
        if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) {
                /* XXX It would be better to include a reason for failure, but without
                 * autoconf, it's hard to use strerror, sys_errlist, etc.
@@ -1583,7 +1586,7 @@ static int read_inclusion_file(char *filename)
 Parse tar arguments. Sets tar_type, tar_excl, etc.
 ***************************************************************************/
 
-int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind)
+int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
 {
        int newOptind = Optind;
        char tar_clipfl='\0';
@@ -1775,6 +1778,10 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind)
                if (tarhandle == 1)  {
                        dbf = x_stderr;
                }
+               if (!argv[Optind]) {
+                       DEBUG(0,("Must specify tar filename\n"));
+                       return 0;
+               }
                if (!strcmp(argv[Optind], "-")) {
                        newOptind++;
                }
index 9592dbdf96673099be77717e58072e8f08f0ae53..7ab17a2b0284845fb8968098f7122732a10921b3 100755 (executable)
@@ -32,6 +32,15 @@ static char * user_name = NULL;
 char * mountpassword = NULL;
 
 
+/* BB finish BB
+
+        cifs_umount
+        open nofollow - avoid symlink exposure? 
+        get owner of dir see if matches self or if root
+        call system(umount argv) etc.
+                
+BB end finish BB */
+
 void mount_cifs_usage()
 {
        printf("\nUsage:  %s remotetarget dir\n", thisprogram);
@@ -155,17 +164,36 @@ int parse_options(char * options)
                if (value && *value) {
                        got_gid = 1;
                }
-       } /* else if (strnicmp(data, "file_mode", 4) == 0) {
-               if (value && *value) {
-                       vol->file_mode =
-                               simple_strtoul(value, &value, 0);
+       /* fmask and dmask synonyms for people used to smbfs syntax */
+       } else if (strcmp(data, "file_mode") == 0 || strcmp(data, "fmask")==0) {
+               if (!value || !*value) {
+                       printf ("Option '%s' requires a numerical argument\n", data);
+                       return 1;
                }
-       } else if (strnicmp(data, "dir_mode", 3) == 0) {
-               if (value && *value) {
-                       vol->dir_mode =
-                               simple_strtoul(value, &value, 0);
+
+               if (value[0] != '0') {
+                       printf ("WARNING: '%s' not expressed in octal.\n", data);
                }
-       } else if (strnicmp(data, "port", 4) == 0) {
+
+               if (strcmp (data, "fmask") == 0) {
+                       printf ("WARNING: CIFS mount option 'fmask' is deprecated. Use 'file_mode' instead.\n");
+                       data = "file_mode";
+                }
+        } else if (strcmp(data, "dir_mode") == 0 || strcmp(data, "dmask")==0) {
+                if (!value || !*value) {
+                        printf ("Option '%s' requires a numerical argument\n", data);
+                        return 1;
+                }
+
+                if (value[0] != '0') {
+                        printf ("WARNING: '%s' not expressed in octal.\n", data);
+                }
+
+                if (strcmp (data, "dmask") == 0) {
+                        printf ("WARNING: CIFS mount option 'dmask' is deprecated. Use 'dir_mode' instead.\n");
+                        data = "dir_mode";
+                }
+       } /* else if (strnicmp(data, "port", 4) == 0) {
                if (value && *value) {
                        vol->port =
                                simple_strtoul(value, &value, 0);
@@ -446,18 +474,28 @@ int main(int argc, char ** argv)
 
        /* canonicalize the path in argv[1]? */
 
+       /* BB save off path and pop after mount returns */
+       if(chdir(mountpoint)) {
+               printf("mount error: can not change directory into mount target %s\n",mountpoint);
+       }
+
        if(stat (mountpoint, &statbuf)) {
                printf("mount error: mount point %s does not exist\n",mountpoint);
                return -1;
        }
+
        if (S_ISDIR(statbuf.st_mode) == 0) {
                printf("mount error: mount point %s is not a directory\n",mountpoint);
                return -1;
        }
 
-       if(geteuid()) {
-               printf("mount error: permission denied, not superuser and cifs.mount not installed SUID\n"); 
-               return -1;
+       if((getuid() != 0) && (geteuid() == 0)) {
+               if((statbuf.st_uid == getuid()) && (S_IRWXU == statbuf.st_mode & S_IRWXU)) {
+                       printf("setuid mount allowed\n");
+               } else {
+                       printf("mount error: permission denied, not superuser and cifs.mount not installed SUID\n"); 
+                       return -1;
+               }
        }
 
        ipaddr = parse_server(share_name);
index ce406179cfdd9d71f2e56f0a49f4e9616a52d17c..c04be3b7af22b412770c6843d8f614c1a3f7b8bd 100644 (file)
@@ -38,7 +38,7 @@ help(void)
 {
         printf("\n");
         printf("Usage: smbmnt mount-point [options]\n");
-       printf("Version %s\n\n",VERSION);
+       printf("Version %s\n\n",SAMBA_VERSION_STRING);
         printf("-s share       share name on server\n"
                "-r             mount read-only\n"
                "-u uid         mount as uid\n"
@@ -94,9 +94,9 @@ parse_args(int argc, char *argv[], struct smb_mount_data *data, char **share)
 static char *
 fullpath(const char *p)
 {
-        char path[MAXPATHLEN];
+        char path[PATH_MAX+1];
 
-       if (strlen(p) > MAXPATHLEN-1) {
+       if (strlen(p) > PATH_MAX) {
                return NULL;
        }
 
index 343d4f267576b7b7cf2821f8d9016817763f38ea..6e8d9f5bca7e9710055d118ad331ef76b368d161 100644 (file)
@@ -428,7 +428,7 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat
  **/
 static void init_mount(void)
 {
-       char mount_point[MAXPATHLEN+1];
+       char mount_point[PATH_MAX+1];
        pstring tmp;
        pstring svc2;
        struct cli_state *c;
@@ -663,7 +663,7 @@ static void usage(void)
 {
        printf("Usage: mount.smbfs service mountpoint [-o options,...]\n");
 
-       printf("Version %s\n\n",VERSION);
+       printf("Version %s\n\n",SAMBA_VERSION_STRING);
 
        printf(
 "Options:\n\
@@ -923,7 +923,7 @@ static void parse_mount_smb(int argc, char **argv)
                read_credentials_file(credentials);
        }
 
-       DEBUG(3,("mount.smbfs started (version %s)\n", VERSION));
+       DEBUG(3,("mount.smbfs started (version %s)\n", SAMBA_VERSION_STRING));
 
        if (*workgroup == 0) {
                pstrcpy(workgroup,lp_workgroup());
index f964bc719f71527d4586673382f3162039bce373..a2e04b5d480a7dae30cf8dbfdc758bdd9b5cc9be 100644 (file)
@@ -145,14 +145,15 @@ AC_SUBST(PICFLAG)
 AC_SUBST(PICSUFFIX)
 AC_SUBST(POBAD_CC)
 AC_SUBST(SHLIBEXT)
+AC_SUBST(INSTALLCLIENT)
 AC_SUBST(INSTALLCLIENTCMD_SH)
 AC_SUBST(INSTALLCLIENTCMD_A)
 AC_SUBST(LIBSMBCLIENT_SHARED)
 AC_SUBST(LIBSMBCLIENT)
-AC_SUBST(PRINTLIBS)
-AC_SUBST(AUTHLIBS)
-AC_SUBST(ACLLIBS)
-AC_SUBST(PASSDBLIBS)
+AC_SUBST(PRINT_LIBS)
+AC_SUBST(AUTH_LIBS)
+AC_SUBST(ACL_LIBS)
+AC_SUBST(PASSDB_LIBS)
 AC_SUBST(IDMAP_LIBS)
 AC_SUBST(KRB5_LIBS)
 AC_SUBST(LDAP_LIBS)
@@ -284,10 +285,10 @@ DYNEXP=
 
 dnl Add modules that have to be built by default here
 dnl These have to be built static:
-default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_reg rpc_wks rpc_net rpc_dfs rpc_srv rpc_spoolss auth_rhosts auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin"
+default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_reg rpc_lsa_ds rpc_wks rpc_net rpc_dfs rpc_srv rpc_spoolss auth_rhosts auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin"
 
 dnl These are preferably build shared, and static if dlopen() is not available
-default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_netatalk vfs_fake_perms vfs_default_quota"
+default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap charset_CP850 charset_CP437"
 
 if test "x$developer" = xyes; then
    default_static_modules="$default_static_modules rpc_echo"
@@ -358,8 +359,11 @@ case "$host_os" in
 # recommendations on large file support, however it makes the
 # compile work using gcc 2.7 and 2.8, whereas using the Sun
 # recommendation makes the compile fail on gcc2.7. JRA.
+#
+# Solaris uses SYSV printing.  Make sure to set that here.  --jerry
 #
        *solaris*)
+               AC_DEFINE(SYSV, 1, [Whether to enable System V compatibility])
                case `uname -r` in
                        5.0*|5.1*|5.2*|5.3*|5.5*)
                                AC_MSG_RESULT([no large file support])
@@ -390,6 +394,16 @@ case "$host_os" in
                esac
                ;;
 #
+# IRIX uses SYSV printing.  Make sure to set that here
+#
+       *irix*)
+               AC_DEFINE(SYSV, 1, [Whether to enable System V compatibility])
+               ;;
+       *freebsd*)
+               AC_DEFINE(FREEBSD, 1, [Whether the host os is FreeBSD])
+               ;;
+
+#
 # VOS may need to have POSIX support and System V compatibility enabled.
 #
     *vos*)
@@ -407,7 +421,7 @@ case "$host_os" in
          *)
                CPPFLAGS="$CPPFLAGS -D_SYSV"
                AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility])
-    esac
+   esac
     ;;
 #
 # Tests needed for SINIX large file support.
@@ -591,7 +605,7 @@ if test x$enable_cups != xno; then
                         AC_DEFINE(HAVE_CUPS,1,[Whether we have CUPS])
                CFLAGS="$CFLAGS `$CUPS_CONFIG --cflags`"
                LDFLAGS="$LDFLAGS `$CUPS_CONFIG --ldflags`"
-               PRINTLIBS="$PRINTLIBS `$CUPS_CONFIG --libs`"
+               PRINT_LIBS="$PRINT_LIBS `$CUPS_CONFIG --libs`"
         fi
 fi
 
@@ -1090,6 +1104,8 @@ if test "$enable_shared" = "yes"; then
                                LDSHFLAGS="-B symbolic -b -z"
                                SONAMEFLAG="+h "
                                PICFLAG="+z"
+                       elif test "${GCC}" = "yes"; then
+                               PICFLAG="-fPIC"
                        fi
                        DYNEXP="-Wl,-E"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,8192,[The size of a block])
@@ -1533,7 +1549,8 @@ AC_ARG_WITH(libiconv,
     AC_MSG_ERROR(I won't take no for an answer)
   else
      if test "$withval" != "yes" ; then
-        LOOK_DIRS="$withval $LOOK_DIRS"
+       ICONV_PATH_SPEC=yes
+        LOOK_DIRS="$withval"
      fi
   fi
 ])
@@ -1543,51 +1560,108 @@ for i in $LOOK_DIRS ; do
     save_LIBS=$LIBS
     save_LDFLAGS=$LDFLAGS
     save_CPPFLAGS=$CPPFLAGS
-    CPPFLAGS="-I$i/include"
-    LDFLAGS="-L$i/lib"
+    CPPFLAGS="$CPPFLAGS -I$i/include"
+dnl This is here to handle -withval stuff for --with-libiconv
+    if test x"$ICONV_PATH_SPEC" = "xyes" ; then
+       LDFLAGS="-L$i/lib"
+    fi
     LIBS=
     export LDFLAGS LIBS CPPFLAGS
 dnl Try to find iconv(3)
     jm_ICONV($i)
 
-    CPPFLAGS=$save_CPPFLAGS
     if test "$ICONV_FOUND" = yes; then
-        LDFLAGS=$save_LDFLAGS
         LIB_ADD_DIR(LDFLAGS, "$i/lib")
         CFLAGS_ADD_DIR(CPPFLAGS, "$i/include")
         LIBS="$save_LIBS $LIBS"
         ICONV_LOCATION=$i
         export LDFLAGS LIBS CPPFLAGS
-        break
-    else
-       LDFLAGS=$save_LDFLAGS
-        LIBS=$save_LIBS
-        export LDFLAGS LIBS CPPFLAGS
+dnl Now, check for a working iconv ... we want to do it here because
+dnl there might be a working iconv further down the list of LOOK_DIRS
+
+        ############
+        # check for iconv in libc
+        ic_save_LIBS="$LIBS"
+        if test x"$ICONV_PATH_SPEC" = "xyes" ; then
+           LIBS="$LIBS -L$ICONV_LOCATION/lib"
+        fi
+dnl        AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[
+       default_dos_charset=no
+       default_display_charset=no
+       default_unix_charset=no
+       echo
+
+       # check for default dos charset name
+       for j in CP850 IBM850 ; do
+           rjs_CHARSET($j)
+           if test x"$ICONV_CHARSET" = x"$j"; then
+               default_dos_charset="\"$j\""
+               break
+           fi
+       done
+       # check for default display charset name
+       for j in ASCII 646 ; do
+           rjs_CHARSET($j)
+           if test x"$ICONV_CHARSET" = x"$j"; then
+               default_display_charset="\"$j\""
+               break
+           fi
+       done
+       # check for default unix charset name
+       for j in UTF-8 UTF8 ; do
+           rjs_CHARSET($j)
+           if test x"$ICONV_CHARSET" = x"$j"; then
+               default_unix_charset="\"$j\""
+               break
+           fi
+       done
+       
+       if test "$default_dos_charset" != "no" -a \
+               "$default_dos_charset" != "cross" -a \
+               "$default_display_charset" != "no" -a \ 
+               "$default_display_charset" != "cross" -a \
+               "$default_unix_charset" != "no" -a \
+               "$default_unix_charset" != "cross"
+       then
+               samba_cv_HAVE_NATIVE_ICONV=yes
+       else if test "$default_dos_charset" = "cross" -o \
+                    "$default_display_charset" = "cross" -o \
+                    "$default_unix_charset" = "cross"
+       then
+               samba_cv_HAVE_NATIVE_ICONV=cross
+       else
+               samba_cv_HAVE_NATIVE_ICONV=no
+       fi
+       fi
+dnl ])
+
+        LIBS="$ic_save_LIBS"
+        if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then
+               CPPFLAGS=$save_CPPFLAGS
+               CFLAGS_ADD_DIR(CPPFLAGS, "$i/include")
+               export CPPFLAGS
+           AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv])
+          AC_DEFINE_UNQUOTED(DEFAULT_DOS_CHARSET,$default_dos_charset,[Default dos charset name])
+          AC_DEFINE_UNQUOTED(DEFAULT_DISPLAY_CHARSET,$default_display_charset,[Default display charset name])
+          AC_DEFINE_UNQUOTED(DEFAULT_UNIX_CHARSET,$default_unix_charset,[Default unix charset name])
+           break
+        fi
+dnl We didn't find a working iconv, so keep going
     fi
+dnl We only need to clean these up here for the next pass through the loop
+    CPPFLAGS=$save_CPPFLAGS
+    LDFLAGS=$save_LDFLAGS
+    LIBS=$save_LIBS
+    export LDFLAGS LIBS CPPFLAGS
 done
 
-############
-# check for iconv in libc
-ic_save_LIBS="$LIBS"
-LIBS="$LIBS -L$ICONV_LOCATION/lib"
-AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[
-AC_TRY_RUN([
-#include <$jm_cv_include>
-main() {
-       iconv_t cd = iconv_open("ASCII", "UCS-2LE");
-       if (cd == 0 || cd == (iconv_t)-1) return -1;
-       return 0;
-}
-],
-samba_cv_HAVE_NATIVE_ICONV=yes,samba_cv_HAVE_NATIVE_ICONV=no,samba_cv_HAVE_NATIVE_ICONV=cross)])
-if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then
-    AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv])
-fi
-LIBS="$ic_save_LIBS"
 
 if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then
     AC_MSG_WARN([Sufficient support for iconv function was not found. 
     Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!])
+   AC_DEFINE_UNQUOTED(DEFAULT_DOS_CHARSET,"CP850",[Default dos charset name])
+   AC_DEFINE_UNQUOTED(DEFAULT_DISPLAY_CHARSET,"ASCII",[Default display charset name])
+   AC_DEFINE_UNQUOTED(DEFAULT_UNIX_CHARSET,"UTF8",[Default unix charset name])
 fi
 
 
@@ -2109,6 +2183,22 @@ AC_ARG_WITH(afs,
   AC_MSG_RESULT(no)
 )
 
+####################################################
+# check for Linux-specific AFS fake-kaserver support
+AC_MSG_CHECKING(whether to use AFS fake-kaserver)
+AC_ARG_WITH(fake-kaserver,
+[  --with-fake-kaserver    Include AFS fake-kaserver support (default=no) ],
+[ case "$withval" in
+  yes)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_FAKE_KASERVER,1,[Whether to include AFS fake-kaserver support])
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
 
 #################################################
 # check for the DFS clear-text auth system
@@ -2471,12 +2561,32 @@ if test x"$with_ads_support" != x"no"; then
       [krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC_MD5;],
       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=yes,
       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=no)])
-
-  if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes"; then
+  AC_CACHE_CHECK([for KEYTYPE_ARCFOUR_56],
+                 samba_cv_HAVE_KEYTYPE_ARCFOUR_56,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_keytype keytype; keytype = KEYTYPE_ARCFOUR_56;],
+      samba_cv_HAVE_KEYTYPE_ARCFOUR_56=yes,
+      samba_cv_HAVE_KEYTYPE_ARCFOUR_56=no)])
+# Heimdals with KEYTYPE_ARCFOUR but not KEYTYPE_ARCFOUR_56 are broken
+# w.r.t. arcfour and windows, so we must not enable it here
+  if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes" -a\
+          x"$samba_cv_HAVE_KEYTYPE_ARCFOUR_56" = x"yes"; then
     AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,1,
               [Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type is available])
   fi
 
+  AC_CACHE_CHECK([for AP_OPTS_USE_SUBKEY],
+                 samba_cv_HAVE_AP_OPTS_USE_SUBKEY,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_flags ap_options; ap_options = AP_OPTS_USE_SUBKEY;],
+      samba_cv_HAVE_AP_OPTS_USE_SUBKEY=yes,
+      samba_cv_HAVE_AP_OPTS_USE_SUBKEY=no)])
+
+  if test x"$samba_cv_HAVE_AP_OPTS_USE_SUBKEY" = x"yes"; then
+    AC_DEFINE(HAVE_AP_OPTS_USE_SUBKEY,1,
+              [Whether the AP_OPTS_USE_SUBKEY ap option is available])
+  fi
+
   AC_CACHE_CHECK([for the krb5_princ_component macro],
                 samba_cv_HAVE_KRB5_PRINC_COMPONENT,[
     AC_TRY_LINK([#include <krb5.h>],
@@ -2489,6 +2599,28 @@ if test x"$with_ads_support" != x"no"; then
                [Whether krb5_princ_component is available])
   fi
 
+  AC_CACHE_CHECK([for memory keytab support],
+                samba_cv_HAVE_MEMORY_KEYTAB,[
+    AC_TRY_RUN([
+#include<krb5.h>
+  main()
+  {
+    krb5_context context;
+    krb5_keytab keytab;
+    
+    krb5_init_context(&context);
+    if (krb5_kt_resolve(context, "MEMORY:", &keytab))
+      exit(0);
+    exit(1);
+  }], 
+  samba_cv_HAVE_MEMORY_KEYTAB=no,
+  samba_cv_HAVE_MEMORY_KEYTAB=yes)])
+
+  if test x"$samba_cv_HAVE_MEMORY_KEYTAB" = x"yes"; then
+      AC_DEFINE(HAVE_MEMORY_KEYTAB,1,
+               [Whether in-memory keytabs are supported])
+  fi
+
 
   if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" = x"yes"; then
     AC_DEFINE(HAVE_KRB5,1,[Whether to have KRB5 support])
@@ -2530,7 +2662,7 @@ AC_ARG_WITH(expsam,
       ;;
     mysql)
       ## pdb_mysql
-      AM_PATH_MYSQL([0.11.0],[default_shared_modules="$default_shared_modules pdb_mysql"],[])
+      AM_PATH_MYSQL([default_shared_modules="$default_shared_modules pdb_mysql"],[])
       CFLAGS="$CFLAGS $MYSQL_CFLAGS"
       ;;
     no)
@@ -2596,8 +2728,15 @@ AC_ARG_WITH(pam,
 [ case "$withval" in
   yes)
     AC_MSG_RESULT(yes)
+    if test x"$ac_cv_header_security_pam_appl_h" = x"no"; then
+       if test x"$ac_cv_header_security_pam_modules_h" = x"no"; then
+         if test x"$ac_cv_header_security__pam_macros_h" = x"no"; then
+            AC_MSG_ERROR(--with-pam specified but no PAM headers found)
+         fi
+       fi
+    fi
     AC_DEFINE(WITH_PAM,1,[Whether to include PAM support])
-    AUTHLIBS="$AUTHLIBS -lpam"
+    AUTH_LIBS="$AUTH_LIBS -lpam"
     with_pam_for_crypt=yes
     ;;
   *)
@@ -2619,13 +2758,16 @@ AC_ARG_WITH(pam_smbpass,
   yes)
     AC_MSG_RESULT(yes)
 
-# Conditions under which pam_smbpass should not be built.
+       # Conditions under which pam_smbpass should not be built.
 
        if test x$PICFLAG = x; then
-          AC_MSG_RESULT([No support for PIC code - disabling pam_smbpass])
+          AC_MSG_ERROR([No support for PIC code])
+       elif test x"$ac_cv_header_security_pam_appl_h" = x"no"; then
+         AC_MSG_ERROR([No security/pam_appl.h found])
        elif test x$ac_cv_lib_pam_pam_get_data = xno; then
-          AC_MSG_RESULT([No libpam found -- disabling pam_smbpass])
+          AC_MSG_ERROR([No libpam found])
        else
+         AUTH_LIBS="$AUTH_LIBS -lpam"
           SHLIB_PROGS="$SHLIB_PROGS bin/pam_smbpass.$SHLIBEXT"
        fi
     ;;
@@ -2640,7 +2782,7 @@ AC_ARG_WITH(pam_smbpass,
 ###############################################
 # test for where we get crypt() from
 AC_SEARCH_LIBS(crypt, [crypt],
-  [test "$ac_cv_search_crypt" = "none required" || AUTHLIBS="-lcrypt $AUTHLIBS"
+  [test "$ac_cv_search_crypt" = "none required" || AUTH_LIBS="-lcrypt $AUTH_LIBS"
   AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function])])
 
 ##
@@ -2652,7 +2794,7 @@ AC_SEARCH_LIBS(crypt, [crypt],
 if test $with_pam_for_crypt = no; then
 AC_CACHE_CHECK([for a crypt that needs truncated salt],samba_cv_HAVE_TRUNCATED_SALT,[
 crypt_LIBS="$LIBS"
-LIBS="$AUTHLIBS $LIBS"
+LIBS="$AUTH_LIBS $LIBS"
 AC_TRY_RUN([#include "${srcdir-.}/tests/crypttest.c"],
        samba_cv_HAVE_TRUNCATED_SALT=no,samba_cv_HAVE_TRUNCATED_SALT=yes,samba_cv_HAVE_TRUNCATED_SALT=cross)
 LIBS="$crypt_LIBS"])
@@ -3085,6 +3227,7 @@ AC_ARG_WITH(manpages-langs,
 
 INSTALLCLIENTCMD_SH=:
 INSTALLCLIENTCMD_A=:
+INSTALLCLIENT=
 LIBSMBCLIENT_SHARED=
 LIBSMBCLIENT=
 AC_MSG_CHECKING(whether to build the libsmbclient shared library)
@@ -3097,6 +3240,8 @@ AC_ARG_WITH(libsmbclient,
   *)
      if test $BLDSHARED = true; then
         INSTALLCLIENTCMD_SH="\$(INSTALLCMD)"
+       ## build the static version of libsmbclient as well
+       INSTALLCLIENTCMD_A="\$(INSTALLCMD)"
         LIBSMBCLIENT_SHARED=bin/libsmbclient.$SHLIBEXT
         LIBSMBCLIENT=libsmbclient
         AC_MSG_RESULT(yes)
@@ -3108,6 +3253,7 @@ AC_ARG_WITH(libsmbclient,
         INSTALLCLIENTCMD_A="\$(INSTALLCMD)"
         LIBSMBCLIENT=libsmbclient
      fi
+     INSTALLCLIENT=installclientlib
      ;;
   esac ],
 [
@@ -3125,6 +3271,7 @@ AC_ARG_WITH(libsmbclient,
      INSTALLCLIENTCMD_A="\$(INSTALLCMD)"
      LIBSMBCLIENT=libsmbclient
   fi]
+  INSTALLCLIENT=installclientlib
 )
 
 
@@ -3392,7 +3539,7 @@ AC_ARG_WITH(acl-support,
        *osf*)
                AC_MSG_RESULT(Using Tru64 ACLs)
                AC_DEFINE(HAVE_TRU64_ACLS,1,[Whether Tru64 ACLs are available])
-               ACLLIBS="$ACLLIBS -lpacl"
+               ACL_LIBS="$ACL_LIBS -lpacl"
                ;;
        *freebsd5*)
                AC_MSG_RESULT(Using FreeBSD posix ACLs)
@@ -3400,8 +3547,8 @@ AC_ARG_WITH(acl-support,
                AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
                ;;
        *linux*)
-               AC_CHECK_LIB(attr,getxattr,[ACLLIBS="$ACLLIBS -lattr"])
-                       AC_CHECK_LIB(acl,acl_get_file,[ACLLIBS="$ACLLIBS -lacl"])
+               AC_CHECK_LIB(attr,getxattr,[ACL_LIBS="$ACL_LIBS -lattr"])
+                       AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
                AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
                acl_LIBS=$LIBS
                LIBS="$LIBS -lacl"
@@ -3427,7 +3574,7 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)
                        fi
             ;;
          *)
-               AC_CHECK_LIB(acl,acl_get_file,[ACLLIBS="$ACLLIBS -lacl"])
+               AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
                AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
                acl_LIBS=$LIBS
                LIBS="$LIBS -lacl"
@@ -3910,22 +4057,23 @@ fi ])
 ## contributed pdb_modules
 
 SMB_MODULE(pdb_xml, passdb/pdb_xml.o, "bin/xml.$SHLIBEXT", PDB,
-                 [ PASSDBLIBS="$PASSDBLIBS $XML_LIBS" ] )
+                 [ PASSDB_LIBS="$PASSDB_LIBS $XML_LIBS" ] )
 SMB_MODULE(pdb_mysql, passdb/pdb_mysql.o, "bin/mysql.$SHLIBEXT", PDB, 
-                  [ PASSDBLIBS="$PASSDBLIBS $MYSQL_LIBS" ]     )
+                  [ PASSDB_LIBS="$PASSDB_LIBS $MYSQL_LIBS" ]   )
 
 ## end of contributed pdb_modules
 ###########################################################################
 
 SMB_MODULE(pdb_ldap, passdb/pdb_ldap.o, "bin/ldapsam.$SHLIBEXT", PDB, 
-                  [ PASSDBLIBS="$PASSDBLIBS $LDAP_LIBS" ] )
+                  [ PASSDB_LIBS="$PASSDB_LIBS $LDAP_LIBS" ] )
 SMB_MODULE(pdb_smbpasswd, passdb/pdb_smbpasswd.o, "bin/smbpasswd.$SHLIBEXT", PDB)
 SMB_MODULE(pdb_tdbsam, passdb/pdb_tdb.o, "bin/tdbsam.$SHLIBEXT", PDB)
 SMB_MODULE(pdb_guest, passdb/pdb_guest.o, "bin/guest.$SHLIBEXT", PDB)
-SMB_SUBSYSTEM(PDB)
+SMB_SUBSYSTEM(PDB,passdb/pdb_interface.c)
 
 SMB_MODULE(rpc_lsa, \$(RPC_LSA_OBJ), "bin/librpc_lsarpc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_reg, \$(RPC_REG_OBJ), "bin/librpc_winreg.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_lsa_ds, \$(RPC_LSA_DS_OBJ), "bin/librpc_lsa_ds.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_wks, \$(RPC_WKS_OBJ), "bin/librpc_wkssvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_net, \$(RPC_NETLOG_OBJ), "bin/librpc_NETLOGON.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_dfs, \$(RPC_DFS_OBJ), "bin/librpc_netdfs.$SHLIBEXT", RPC)
@@ -3933,23 +4081,25 @@ SMB_MODULE(rpc_srv, \$(RPC_SVC_OBJ), "bin/librpc_srvsvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_spoolss, \$(RPC_SPOOLSS_OBJ), "bin/librpc_spoolss.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_echo, \$(RPC_ECHO_OBJ), "bin/librpc_echo.$SHLIBEXT", RPC)
-SMB_SUBSYSTEM(RPC)
+SMB_SUBSYSTEM(RPC,smbd/server.c)
 
 SMB_MODULE(idmap_ldap, sam/idmap_ldap.o, "bin/idmap_ldap.$SHLIBEXT", IDMAP)
 SMB_MODULE(idmap_tdb, sam/idmap_tdb.o, "bin/idmap_tdb.$SHLIBEXT", IDMAP)
-SMB_SUBSYSTEM(IDMAP)
+SMB_SUBSYSTEM(IDMAP,sam/idmap.c)
 
 SMB_MODULE(charset_weird, modules/weird.o, "bin/weird.$SHLIBEXT", CHARSET)
-SMB_SUBSYSTEM(CHARSET)
+SMB_MODULE(charset_CP850, modules/CP850.o, "bin/CP850.$SHLIBEXT", CHARSET)
+SMB_MODULE(charset_CP437, modules/CP437.o, "bin/CP437.$SHLIBEXT", CHARSET)
+SMB_SUBSYSTEM(CHARSET,lib/iconv.c)
 
 SMB_MODULE(auth_rhosts, \$(AUTH_RHOSTS_OBJ), "bin/rhosts.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_sam, \$(AUTH_SAM_OBJ), "bin/sam.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_unix, \$(AUTH_UNIX_OBJ), "bin/unix.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_winbind, \$(AUTH_WINBIND_OBJ), "bin/winbind.$SHLIBEXT", AUTH)
-SMB_MODULE(auth_server, \$(AUTH_SERVER_OBJ), "bin/server.$SHLIBEXT", AUTH)
+SMB_MODULE(auth_server, \$(AUTH_SERVER_OBJ), "bin/smbserver.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_domain, \$(AUTH_DOMAIN_OBJ), "bin/domain.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_builtin, \$(AUTH_BUILTIN_OBJ), "bin/builtin.$SHLIBEXT", AUTH)
-SMB_SUBSYSTEM(AUTH)
+SMB_SUBSYSTEM(AUTH,auth/auth.c)
 
 SMB_MODULE(vfs_recycle, \$(VFS_RECYCLE_OBJ), "bin/recycle.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_audit, \$(VFS_AUDIT_OBJ), "bin/audit.$SHLIBEXT", VFS)
@@ -3957,7 +4107,9 @@ SMB_MODULE(vfs_extd_audit, \$(VFS_EXTD_AUDIT_OBJ), "bin/extd_audit.$SHLIBEXT", V
 SMB_MODULE(vfs_netatalk, \$(VFS_NETATALK_OBJ), "bin/netatalk.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_fake_perms, \$(VFS_FAKE_PERMS_OBJ), "bin/fake_perms.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_default_quota, \$(VFS_DEFAULT_QUOTA_OBJ), "bin/default_quota.$SHLIBEXT", VFS)
-SMB_SUBSYSTEM(VFS)
+SMB_MODULE(vfs_readonly, \$(VFS_READONLY_OBJ), "bin/readonly.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_cap, \$(VFS_CAP_OBJ), "bin/cap.$SHLIBEXT", VFS)
+SMB_SUBSYSTEM(VFS,smbd/vfs.c)
 
 AC_DEFINE_UNQUOTED(STRING_STATIC_MODULES, "$string_static_modules", [String list of builtin modules])
 
@@ -3979,6 +4131,7 @@ fi
 if test x"$with_ldap_support" != x"no"; then
    AC_MSG_RESULT([    LDAP_LIBS = $LDAP_LIBS])
 fi
+AC_MSG_RESULT([    AUTH_LIBS = $AUTH_LIBS])
 
 #################################################
 # final configure stuff
@@ -4000,7 +4153,7 @@ dnl Remove -I/usr/include/? from CFLAGS and CPPFLAGS
 CFLAGS_REMOVE_USR_INCLUDE(CFLAGS)
 CFLAGS_REMOVE_USR_INCLUDE(CPPFLAGS)
 
-AC_OUTPUT(include/stamp-h Makefile script/findsmb)
+AC_OUTPUT(include/stamp-h Makefile script/findsmb smbadduser script/gen-8bit-gap.sh)
 
 #################################################
 # Print very concise instructions on building/use
index cd903fa28be1e38af839ed4eaeabba453a45db17..7a07b5c344816bc3879204de654bed5bd772f2f9 100644 (file)
@@ -234,7 +234,7 @@ static BOOL get_group_map_from_sid(DOM_SID sid, GROUP_MAP *map)
        TDB_DATA kbuf, dbuf;
        pstring key;
        fstring string_sid;
-       int ret;
+       int ret = 0;
        
        if(!init_group_mapping()) {
                DEBUG(0,("failed to initialize group mapping"));
@@ -257,6 +257,11 @@ static BOOL get_group_map_from_sid(DOM_SID sid, GROUP_MAP *map)
                                &map->gid, &map->sid_name_use, &map->nt_name, &map->comment);
 
        SAFE_FREE(dbuf.dptr);
+       
+       if ( ret == -1 ) {
+               DEBUG(3,("get_group_map_from_sid: tdb_unpack failure\n"));
+               return False;
+       }
 
        sid_copy(&map->sid, &sid);
        
@@ -299,6 +304,11 @@ static BOOL get_group_map_from_gid(gid_t gid, GROUP_MAP *map)
 
                SAFE_FREE(dbuf.dptr);
 
+               if ( ret == -1 ) {
+                       DEBUG(3,("get_group_map_from_gid: tdb_unpack failure\n"));
+                       return False;
+               }
+       
                if (gid==map->gid) {
                        SAFE_FREE(kbuf.dptr);
                        return True;
@@ -343,6 +353,11 @@ static BOOL get_group_map_from_ntname(const char *name, GROUP_MAP *map)
                                 &map->gid, &map->sid_name_use, &map->nt_name, &map->comment);
 
                SAFE_FREE(dbuf.dptr);
+               
+               if ( ret == -1 ) {
+                       DEBUG(3,("get_group_map_from_ntname: tdb_unpack failure\n"));
+                       return False;
+               }
 
                if (StrCaseCmp(name, map->nt_name)==0) {
                        SAFE_FREE(kbuf.dptr);
@@ -429,6 +444,11 @@ static BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **rmap,
 
                SAFE_FREE(dbuf.dptr);
 
+               if ( ret == -1 ) {
+                       DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
+                       continue;
+               }
+       
                /* list only the type or everything if UNKNOWN */
                if (sid_name_use!=SID_NAME_UNKNOWN  && sid_name_use!=map.sid_name_use) {
                        DEBUG(11,("enum_group_mapping: group %s is not of the requested type\n", map.nt_name));
@@ -510,8 +530,9 @@ BOOL get_domain_group_from_sid(DOM_SID sid, GROUP_MAP *map)
        }
 
        DEBUG(10, ("get_domain_group_from_sid: SID is mapped to gid:%lu\n",(unsigned long)map->gid));
-
-       if ( (grp=getgrgid(map->gid)) == NULL) {
+       
+       grp = getgrgid(map->gid);
+       if ( !grp ) {
                DEBUG(10, ("get_domain_group_from_sid: gid DOESN'T exist in UNIX security\n"));
                return False;
        }
@@ -553,9 +574,12 @@ BOOL get_local_group_from_sid(DOM_SID sid, GROUP_MAP *map)
 
                sid_peek_rid(&sid, &alias_rid);
                map->gid=pdb_group_rid_to_gid(alias_rid);
-
-               if ((grp=getgrgid(map->gid)) == NULL)
+               
+               grp = getgrgid(map->gid);
+               if ( !grp ) {
+                       DEBUG(3,("get_local_group_from_sid: No unix group for [%ul]\n", map->gid));
                        return False;
+               }
 
                map->sid_name_use=SID_NAME_ALIAS;
 
index bff248727f295353845ac9b5e5343cde47898d53..7dff121f14338863e7821a978306d60cf7afe341 100644 (file)
@@ -4,3 +4,4 @@ stamp-h
 proto.h
 wrepld_proto.h
 config.h.in
+version.h
index 0961c9581c90dbf8d53a68da3e198096737aed99..b85ad21fba961e799b8ea6dec958bf9771dab2cb 100644 (file)
@@ -218,6 +218,6 @@ typedef void **ADS_MODLIST;
 /* The older versions of heimdal that don't have this
    define don't seem to use it anyway.  I'm told they
    always use a subkey */
-#ifndef AP_OPTS_USE_SUBKEY
+#ifndef HAVE_AP_OPTS_USE_SUBKEY
 #define AP_OPTS_USE_SUBKEY 0
 #endif
index f999a9cf7205c4cd9ff1fbc6142a7e8605df4469..7a9b12ef55dfd4727de646bf2e9df8205e299f7d 100644 (file)
@@ -38,3 +38,90 @@ struct charset_functions {
        struct charset_functions *prev, *next;
 };
 
+/*
+ * This is auxiliary struct used by source/script/gen-8-bit-gap.sh script
+ * during generation of an encoding table for charset module
+ *     */
+
+struct charset_gap_table {
+  uint16 start;
+  uint16 end;
+  int32 idx;
+};
+
+/*
+ *   Define stub for charset module which implements 8-bit encoding with gaps.
+ *   Encoding tables for such module should be produced from glibc's CHARMAPs
+ *   using script source/script/gen-8bit-gap.sh
+ *   CHARSETNAME is CAPITALIZED charset name
+ *
+ *     */
+#define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME)                                     \
+static size_t CHARSETNAME ## _push(void *cd, char **inbuf, size_t *inbytesleft,                        \
+                        char **outbuf, size_t *outbytesleft)                                   \
+{                                                                                              \
+       while (*inbytesleft >= 2 && *outbytesleft >= 1) {                                       \
+               int i;                                                                          \
+               int done = 0;                                                                   \
+                                                                                               \
+               uint16 ch = SVAL(*inbuf,0);                                                     \
+                                                                                               \
+               for (i=0; from_idx[i].start != 0xffff; i++) {                                   \
+                       if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) {             \
+                               ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
+                               (*inbytesleft) -= 2;                                            \
+                               (*outbytesleft) -= 1;                                           \
+                               (*inbuf)  += 2;                                                 \
+                               (*outbuf) += 1;                                                 \
+                               done = 1;                                                       \
+                               break;                                                          \
+                       }                                                                       \
+               }                                                                               \
+               if (!done) {                                                                    \
+                       errno = EINVAL;                                                         \
+                       return -1;                                                              \
+               }                                                                               \
+                                                                                               \
+       }                                                                                       \
+                                                                                               \
+       if (*inbytesleft == 1) {                                                                \
+               errno = EINVAL;                                                                 \
+               return -1;                                                                      \
+       }                                                                                       \
+                                                                                               \
+       if (*inbytesleft > 1) {                                                                 \
+               errno = E2BIG;                                                                  \
+               return -1;                                                                      \
+       }                                                                                       \
+                                                                                               \
+       return 0;                                                                               \
+}                                                                                              \
+                                                                                               \
+static size_t CHARSETNAME ## _pull(void *cd, char **inbuf, size_t *inbytesleft,                                \
+                        char **outbuf, size_t *outbytesleft)                                   \
+{                                                                                              \
+       while (*inbytesleft >= 1 && *outbytesleft >= 2) {                                       \
+               *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]];                   \
+               (*inbytesleft)  -= 1;                                                           \
+               (*outbytesleft) -= 2;                                                           \
+               (*inbuf)  += 1;                                                                 \
+               (*outbuf) += 2;                                                                 \
+       }                                                                                       \
+                                                                                               \
+       if (*inbytesleft > 0) {                                                                 \
+               errno = E2BIG;                                                                  \
+               return -1;                                                                      \
+       }                                                                                       \
+                                                                                               \
+       return 0;                                                                               \
+}                                                                                              \
+                                                                                               \
+struct charset_functions CHARSETNAME ## _functions =                                           \
+               {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push};                     \
+                                                                                               \
+NTSTATUS charset_ ## CHARSETNAME ## _init(void)                                                        \
+{                                                                                              \
+       return smb_register_charset(& CHARSETNAME ## _functions);                               \
+}                                                                                              \
+
+
index eb7f73b9d35c68b364a9bbde03dc1f397019f704..29bb53980fe0c6dd0d532aaa17c87f1c870f2c2c 100644 (file)
 #include <com_err.h>
 #endif
 
+#if HAVE_SYS_ATTRIBUTES_H
+#include <sys/attributes.h>
+#endif
+
 #if HAVE_ATTR_XATTR_H
 #include <attr/xattr.h>
 #endif
@@ -958,10 +962,6 @@ struct smb_ldap_privates;
 #define SYNC_DNS 1
 #endif
 
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 256
-#endif
-
 #ifndef SEEK_SET
 #define SEEK_SET 0
 #endif
@@ -1278,7 +1278,7 @@ time_t timegm(struct tm *tm);
 
 #if defined(HAVE_KRB5)
 
-#ifndef KRB5_SET_REAL_TIME
+#ifndef HAVE_KRB5_SET_REAL_TIME
 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
 #endif
 
index 14561cf44d1e0ae3f6f2ea5c9e06b633c689807a..1e867d620bc6975b52244950c206715335fb5559 100644 (file)
@@ -176,124 +176,116 @@ enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
 enum packet_type {NMB_PACKET, DGRAM_PACKET};
 
-enum master_state
-{
-  MST_NONE,
-  MST_POTENTIAL,
-  MST_BACKUP,
-  MST_MSB,
-  MST_BROWSER,
-  MST_UNBECOMING_MASTER
+enum master_state {
+       MST_NONE,
+       MST_POTENTIAL,
+       MST_BACKUP,
+       MST_MSB,
+       MST_BROWSER,
+       MST_UNBECOMING_MASTER
 };
 
-enum domain_state
-{
-  DOMAIN_NONE,
-  DOMAIN_WAIT,
-  DOMAIN_MST
+enum domain_state {
+       DOMAIN_NONE,
+       DOMAIN_WAIT,
+       DOMAIN_MST
 };
 
-enum logon_state
-{
-  LOGON_NONE,
-  LOGON_WAIT,
-  LOGON_SRV
+enum logon_state {
+       LOGON_NONE,
+       LOGON_WAIT,
+       LOGON_SRV
 };
 
 struct subnet_record;
 
-struct nmb_data
-{
-  uint16 nb_flags;         /* Netbios flags. */
-  int num_ips;             /* Number of ip entries. */
-  struct in_addr *ip;      /* The ip list for this name. */
+struct nmb_data {
+       uint16 nb_flags;         /* Netbios flags. */
+       int num_ips;             /* Number of ip entries. */
+       struct in_addr *ip;      /* The ip list for this name. */
 
-  enum name_source source; /* Where the name came from. */
+       enum name_source source; /* Where the name came from. */
 
-  time_t death_time; /* The time the record must be removed (do not remove if 0). */
-  time_t refresh_time; /* The time the record should be refreshed. */
+       time_t death_time; /* The time the record must be removed (do not remove if 0). */
+       time_t refresh_time; /* The time the record should be refreshed. */
   
-  SMB_BIG_UINT id;             /* unique id */
-  struct in_addr wins_ip;      /* the adress of the wins server this record comes from */
+       SMB_BIG_UINT id;                /* unique id */
+       struct in_addr wins_ip; /* the adress of the wins server this record comes from */
 
-  int wins_flags;              /* similar to the netbios flags but different ! */
+       int wins_flags;         /* similar to the netbios flags but different ! */
 };
 
 /* This structure represents an entry in a local netbios name list. */
-struct name_record
-  {
-  ubi_trNode            node[1];
-  struct subnet_record *subnet;
-  struct nmb_name       name;    /* The netbios name. */
-  struct nmb_data       data;    /* The netbios data. */
-  };
+struct name_record {
+       ubi_trNode            node[1];
+       struct subnet_record *subnet;
+       struct nmb_name       name;    /* The netbios name. */
+       struct nmb_data       data;    /* The netbios data. */
+};
 
 /* Browser cache for synchronising browse lists. */
-struct browse_cache_record
-  {
-  ubi_dlNode     node[1];
-  pstring        lmb_name;
-  pstring        work_group;
-  struct in_addr ip;
-  time_t         sync_time;
-  time_t         death_time; /* The time the record must be removed. */
-  };
+struct browse_cache_record {
+       ubi_dlNode     node[1];
+       nstring        lmb_name;
+       nstring        work_group;
+       struct in_addr ip;
+       time_t         sync_time;
+       time_t         death_time; /* The time the record must be removed. */
+};
 
 /* This is used to hold the list of servers in my domain, and is
    contained within lists of domains. */
 
-struct server_record
-{
-  struct server_record *next;
-  struct server_record *prev;
+struct server_record {
+       struct server_record *next;
+       struct server_record *prev;
 
-  struct subnet_record *subnet;
+       struct subnet_record *subnet;
 
-  struct server_info_struct serv;
-  time_t death_time;  
+       struct server_info_struct serv;
+       time_t death_time;  
 };
 
 /* A workgroup structure. It contains a list of servers. */
-struct work_record
-{
-  struct work_record *next;
-  struct work_record *prev;
+struct work_record {
+       struct work_record *next;
+       struct work_record *prev;
 
-  struct subnet_record *subnet;
+       struct subnet_record *subnet;
 
-  struct server_record *serverlist;
+       struct server_record *serverlist;
 
-  /* Stage of development from non-local-master up to local-master browser. */
-  enum master_state mst_state;
+       /* Stage of development from non-local-master up to local-master browser. */
+       enum master_state mst_state;
 
-  /* Stage of development from non-domain-master to domain-master browser. */
-  enum domain_state dom_state;
+       /* Stage of development from non-domain-master to domain-master browser. */
+       enum domain_state dom_state;
 
-  /* Stage of development from non-logon-server to logon server. */
-  enum logon_state log_state;
+       /* Stage of development from non-logon-server to logon server. */
+       enum logon_state log_state;
 
-  /* Work group info. */
-  fstring work_group;
-  int     token;        /* Used when communicating with backup browsers. */
-  fstring local_master_browser_name;      /* Current local master browser. */
+       /* Work group info. */
+       nstring work_group;
+       int     token;        /* Used when communicating with backup browsers. */
+       nstring local_master_browser_name;      /* Current local master browser. */
 
-  /* Announce info. */
-  time_t lastannounce_time;
-  int announce_interval;
-  BOOL    needannounce;
+       /* Announce info. */
+       time_t lastannounce_time;
+       int announce_interval;
+       BOOL    needannounce;
 
-  /* Timeout time for this workgroup. 0 means permanent. */
-  time_t death_time;  
+       /* Timeout time for this workgroup. 0 means permanent. */
+       time_t death_time;  
 
-  /* Election info */
-  BOOL    RunningElection;
-  BOOL    needelection;
-  int     ElectionCount;
-  uint32  ElectionCriterion;
+       /* Election info */
+       BOOL    RunningElection;
+       BOOL    needelection;
+       int     ElectionCount;
+       uint32  ElectionCriterion;
 
-  /* Domain master browser info. Used for efficient syncs. */
-  struct nmb_name dmb_name;
-  struct in_addr dmb_addr;
+       /* Domain master browser info. Used for efficient syncs. */
+       struct nmb_name dmb_name;
+       struct in_addr dmb_addr;
 };
 
 /* typedefs needed to define copy & free functions for userdata. */
@@ -305,10 +297,10 @@ typedef void (*userdata_free_fn)(struct userdata_struct *);
 /* Structure to define any userdata passed around. */
 
 struct userdata_struct {
-  userdata_copy_fn copy_fn;
-  userdata_free_fn free_fn;
-  unsigned int userdata_len;
-  char data[16]; /* 16 is to ensure alignment/padding on all systems */
+       userdata_copy_fn copy_fn;
+       userdata_free_fn free_fn;
+       unsigned int userdata_len;
+       char data[16]; /* 16 is to ensure alignment/padding on all systems */
 };
 
 struct response_record;
@@ -382,33 +374,32 @@ typedef void (*node_status_fail_function)( struct subnet_record *,
 
 /* Initiated name queries are recorded in this list to track any responses. */
 
-struct response_record
-{
-  struct response_record *next;
-  struct response_record *prev;
+struct response_record {
+       struct response_record *next;
+       struct response_record *prev;
 
-  uint16 response_id;
+       uint16 response_id;
 
-  /* Callbacks for packets received or not. */ 
-  response_function resp_fn;
-  timeout_response_function timeout_fn;
+       /* Callbacks for packets received or not. */ 
+       response_function resp_fn;
+       timeout_response_function timeout_fn;
 
-  /* Callbacks for the request succeeding or not. */
-  success_function success_fn;
-  fail_function fail_fn;
+       /* Callbacks for the request succeeding or not. */
+       success_function success_fn;
+       fail_function fail_fn;
  
-  struct packet_struct *packet;
+       struct packet_struct *packet;
 
-  struct userdata_struct *userdata;
+       struct userdata_struct *userdata;
 
-  int num_msgs;
+       int num_msgs;
 
-  time_t repeat_time;
-  time_t repeat_interval;
-  int    repeat_count;
+       time_t repeat_time;
+       time_t repeat_interval;
+       int    repeat_count;
 
-  /* Recursion protection. */
-  BOOL in_expiration_processing;
+       /* Recursion protection. */
+       BOOL in_expiration_processing;
 };
 
 /* A subnet structure. It contains a list of workgroups and netbios names. */
@@ -420,42 +411,41 @@ struct response_record
 */
 
 enum subnet_type {
-  NORMAL_SUBNET              = 0,  /* Subnet listed in interfaces list. */
-  UNICAST_SUBNET             = 1,  /* Subnet for unicast packets. */
-  REMOTE_BROADCAST_SUBNET    = 2,  /* Subnet for remote broadcasts. */
-  WINS_SERVER_SUBNET         = 3   /* Only created if we are a WINS server. */
+       NORMAL_SUBNET              = 0,  /* Subnet listed in interfaces list. */
+       UNICAST_SUBNET             = 1,  /* Subnet for unicast packets. */
+       REMOTE_BROADCAST_SUBNET    = 2,  /* Subnet for remote broadcasts. */
+       WINS_SERVER_SUBNET         = 3   /* Only created if we are a WINS server. */
 };
 
-struct subnet_record
-{
-  struct subnet_record *next;
-  struct subnet_record *prev;
+struct subnet_record {
+       struct subnet_record *next;
+       struct subnet_record *prev;
 
-  char  *subnet_name;      /* For Debug identification. */
-  enum subnet_type type;   /* To catagorize the subnet. */
+       char  *subnet_name;      /* For Debug identification. */
+       enum subnet_type type;   /* To catagorize the subnet. */
 
-  struct work_record     *workgrouplist; /* List of workgroups. */
-  ubi_trRoot              namelist[1];   /* List of netbios names. */
-  struct response_record *responselist;  /* List of responses expected. */
+       struct work_record     *workgrouplist; /* List of workgroups. */
+       ubi_trRoot              namelist[1];   /* List of netbios names. */
+       struct response_record *responselist;  /* List of responses expected. */
 
-  BOOL namelist_changed;
-  BOOL work_changed;
+       BOOL namelist_changed;
+       BOOL work_changed;
 
-  struct in_addr bcast_ip;
-  struct in_addr mask_ip;
-  struct in_addr myip;
-  int nmb_sock;               /* socket to listen for unicast 137. */
-  int dgram_sock;             /* socket to listen for unicast 138. */
+       struct in_addr bcast_ip;
+       struct in_addr mask_ip;
+       struct in_addr myip;
+       int nmb_sock;               /* socket to listen for unicast 137. */
+       int dgram_sock;             /* socket to listen for unicast 138. */
 };
 
 /* A resource record. */
 struct res_rec {
-  struct nmb_name rr_name;
-  int rr_type;
-  int rr_class;
-  int ttl;
-  int rdlength;
-  char rdata[MAX_DGRAM_SIZE];
+       struct nmb_name rr_name;
+       int rr_type;
+       int rr_class;
+       int ttl;
+       int rdlength;
+       char rdata[MAX_DGRAM_SIZE];
 };
 
 /* Define these so we can pass info back to caller of name_query */
@@ -467,35 +457,34 @@ struct res_rec {
 #define NM_FLAGS_B  0x01 /* Broadcast           */
 
 /* An nmb packet. */
-struct nmb_packet
-{
-  struct {
-    int name_trn_id;
-    int opcode;
-    BOOL response;
-    struct {
-      BOOL bcast;
-      BOOL recursion_available;
-      BOOL recursion_desired;
-      BOOL trunc;
-      BOOL authoritative;
-    } nm_flags;
-    int rcode;
-    int qdcount;
-    int ancount;
-    int nscount;
-    int arcount;
-  } header;
-
-  struct {
-    struct nmb_name question_name;
-    int question_type;
-    int question_class;
-  } question;
-
-  struct res_rec *answers;
-  struct res_rec *nsrecs;
-  struct res_rec *additional;
+struct nmb_packet {
+       struct {
+               int name_trn_id;
+               int opcode;
+               BOOL response;
+               struct {
+                       BOOL bcast;
+                       BOOL recursion_available;
+                       BOOL recursion_desired;
+                       BOOL trunc;
+                       BOOL authoritative;
+               } nm_flags;
+               int rcode;
+               int qdcount;
+               int ancount;
+               int nscount;
+               int arcount;
+       } header;
+
+       struct {
+               struct nmb_name question_name;
+               int question_type;
+               int question_class;
+       } question;
+
+       struct res_rec *answers;
+       struct res_rec *nsrecs;
+       struct res_rec *additional;
 };
 
 /* msg_type field options - from rfc1002. */
@@ -511,23 +500,23 @@ struct nmb_packet
 /* A datagram - this normally contains SMB data in the data[] array. */
 
 struct dgram_packet {
-  struct {
-    int msg_type;
-    struct {
-      enum node_type node_type;
-      BOOL first;
-      BOOL more;
-    } flags;
-    int dgm_id;
-    struct in_addr source_ip;
-    int source_port;
-    int dgm_length;
-    int packet_offset;
-  } header;
-  struct nmb_name source_name;
-  struct nmb_name dest_name;
-  int datasize;
-  char data[MAX_DGRAM_SIZE];
+       struct {
+               int msg_type;
+               struct {
+                       enum node_type node_type;
+                       BOOL first;
+                       BOOL more;
+               } flags;
+               int dgm_id;
+               struct in_addr source_ip;
+               int source_port;
+               int dgm_length;
+               int packet_offset;
+       } header;
+       struct nmb_name source_name;
+       struct nmb_name dest_name;
+       int datasize;
+       char data[MAX_DGRAM_SIZE];
 };
 
 /* Define a structure used to queue packets. This will be a linked
@@ -535,18 +524,18 @@ struct dgram_packet {
 
 struct packet_struct
 {
-  struct packet_struct *next;
-  struct packet_struct *prev;
-  BOOL locked;
-  struct in_addr ip;
-  int port;
-  int fd;
-  time_t timestamp;
-  enum packet_type packet_type;
-  union {
-    struct nmb_packet nmb;
-    struct dgram_packet dgram;
-  } packet;
+       struct packet_struct *next;
+       struct packet_struct *prev;
+       BOOL locked;
+       struct in_addr ip;
+       int port;
+       int fd;
+       time_t timestamp;
+       enum packet_type packet_type;
+       union {
+               struct nmb_packet nmb;
+               struct dgram_packet dgram;
+       } packet;
 };
 
 /* NETLOGON opcodes */
index b6ab4fd0c50ede3795c95a623edc4499c5d7c24a..ccbc190c59d65e67e2142580ef3bf4f035fb2f6c 100644 (file)
@@ -165,10 +165,21 @@ struct dcinfo
 
 };
 
+typedef struct pipe_rpc_fns {
+
+       struct pipe_rpc_fns *next, *prev;
+       
+       /* RPC function table associated with the current rpc_bind (associated by context) */
+       
+       struct api_struct *cmds;
+       int n_cmds;
+       uint32 context_id;
+       
+} PIPE_RPC_FNS;
+
 /*
  * DCE/RPC-specific samba-internal-specific handling of data on
  * NamedPipes.
- *
  */
 
 typedef struct pipes_struct
@@ -180,7 +191,12 @@ typedef struct pipes_struct
 
        fstring name;
        fstring pipe_srv_name;
-
+       
+       /* linked list of rpc dispatch tables associated 
+          with the open rpc contexts */
+          
+       PIPE_RPC_FNS *contexts;
+       
        RPC_HDR hdr; /* Incoming RPC header. */
        RPC_HDR_REQ hdr_req; /* Incoming request header. */
 
index 17791fde18f13b8ba2353106bf7783dad73ce462..9814c88e5e5c3741f47b43bd158a6b3b6dfb00fb 100644 (file)
@@ -23,6 +23,8 @@
   we only need the sparse flag
 */
 
+#ifndef _NTIOCTL_H
+#define _NTIOCTL_H
 
 /* IOCTL information */
 /* List of ioctl function codes that look to be of interest to remote clients like this. */
@@ -53,6 +55,8 @@
 #define FSCTL_SIS_COPYFILE           0x00090100
 #define FSCTL_SIS_LINK_FILES         0x0009C104
 
+#define FSCTL_GET_SHADOW_COPY_DATA   0x00144064   /* KJC -- Shadow Copy information */
+
 #if 0
 #define FSCTL_SECURITY_ID_CHECK
 #define FSCTL_DISMOUNT_VOLUME
 #define IO_REPARSE_TAG_MOUNT_POINT   0xA0000003
 #define IO_REPARSE_TAG_HSM           0xC0000004
 #define IO_REPARSE_TAG_SIS           0x80000007
+
+
+/* For FSCTL_GET_SHADOW_COPY_DATA ...*/
+typedef char SHADOW_COPY_LABEL[25];
+
+typedef struct shadow_copy_data {
+       TALLOC_CTX *mem_ctx;
+       /* Total number of shadow volumes currently mounted */
+       uint32 num_volumes;
+       /* Concatenated list of labels */
+       SHADOW_COPY_LABEL *labels;
+} SHADOW_COPY_DATA;
+
+
+#endif /* _NTIOCTL_H */
index 562e4853ccc76577e984d1674e1c330a7440514a..f1b1bc25e43ea6d7dfc5c6f19db23d29c44f7b46 100644 (file)
@@ -100,6 +100,7 @@ typedef struct ntlmssp_client_state
        char *domain;
        char *workstation;
        char *password;
+       char *server_domain;
 
        const char *(*get_global_myname)(void);
        const char *(*get_domain)(void);
index 1425e59bb84657b3c876f6dca7df3aa637b9e8ef..dac1173770b49cafffd192402d3818a11774d7ca 100644 (file)
@@ -72,7 +72,7 @@ typedef struct _SMB_NTQUOTA_STRUCT {
        SMB_BIG_UINT usedspace;
        SMB_BIG_UINT softlim;
        SMB_BIG_UINT hardlim;
-       enum SMB_QUOTA_TYPE qflags;
+       uint32 qflags;
        DOM_SID sid;
 } SMB_NTQUOTA_STRUCT;
 
index dc82f4536853d46441d8598bcbac260b975de7b9..2e4a418bb7d186b7510a3f412877d5b273619610 100644 (file)
@@ -78,8 +78,8 @@ enum netsec_direction
 #define AUTH_PIPE_NETSEC  0x0008
 
 /* Maximum PDU fragment size. */
-#define MAX_PDU_FRAG_LEN 0x1630
-/* #define MAX_PDU_FRAG_LEN 0x10b8             this is what w2k sets */
+/* #define MAX_PDU_FRAG_LEN 0x1630             this is what wnt sets */
+#define MAX_PDU_FRAG_LEN 0x10b8                        /* this is what w2k sets */
 
 /*
  * Actual structure of a DCE UUID
@@ -136,8 +136,8 @@ typedef struct rpc_hdr_info
 typedef struct rpc_hdr_req_info
 {
   uint32 alloc_hint;   /* allocation hint - data size (bytes) minus header and tail. */
-  uint16 context_id;   /* 0 - presentation context identifier */
-  uint16  opnum;        /* opnum */
+  uint16 context_id;   /* presentation context identifier */
+  uint16  opnum;       /* opnum */
 
 } RPC_HDR_REQ;
 
index 7350fdba1f9a7f52146a57596f067c0230a3d04e..e2622be532c2e2925ce7c8fad55012b1d76a574d 100644 (file)
@@ -27,6 +27,7 @@
 /* Opcodes available on PIPE_LSARPC_DS */
 
 #define DS_GETPRIMDOMINFO      0x00
+#define DS_NOP                 0xFF    /* no op -- placeholder */
 
 /* Opcodes available on PIPE_NETLOGON */
 
 
 /* macros for RPC's */
 
+/* DSROLE_PRIMARY_DOMAIN_INFO_BASIC */
+
+/* flags */
+
 #define DSROLE_PRIMARY_DS_RUNNING           0x00000001
 #define DSROLE_PRIMARY_DS_MIXED_MODE        0x00000002
 #define DSROLE_UPGRADE_IN_PROGRESS          0x00000004
 #define DSROLE_PRIMARY_DOMAIN_GUID_PRESENT  0x01000000
 
+/* machine role */
+
+#define DSROLE_STANDALONE_SRV          2       
+#define DSROLE_DOMAIN_MEMBER_SRV       3
+#define DSROLE_BDC                     4
+#define DSROLE_PDC                     5
+
+
 typedef struct
 {
        uint16          machine_role;
index 135fd76d6c9cd21642403a680486d9f49072c0f1..fa49d76c88588c0d2a48581356edc64ed9d23b1c 100644 (file)
 
 /* Opcodes available on PIPE_LSARPC */
 
+#if 0  /* UNIMPLEMENTED */
+
+#define LSA_LOOKUPSIDS2                0x39
+
+#endif
+
 #define LSA_CLOSE              0x00
 #define LSA_DELETE             0x01
 #define LSA_ENUM_PRIVS         0x02
index 8ec274176a7aa846ae9a15cfbbc67715b0689b46..4d9ad0b2e1897a1a5d5b7d1a8399dfb17d493ab6 100644 (file)
@@ -127,7 +127,7 @@ SamrTestPrivateFunctionsUser
 #define SAMR_UNKNOWN_2a        0x2a
 #define SAMR_UNKNOWN_2b        0x2b
 #define SAMR_GET_USRDOM_PWINFO 0x2c
-#define SAMR_UNKNOWN_2D        0x2d
+#define SAMR_REMOVE_USER_FOREIGN_DOMAIN        0x2d
 #define SAMR_UNKNOWN_2E        0x2e /* looks like an alias for SAMR_QUERY_DOMAIN_INFO */
 #define SAMR_UNKNOWN_2f        0x2f
 #define SAMR_QUERY_DISPINFO3   0x30 /* Alias for SAMR_QUERY_DISPINFO
@@ -1786,21 +1786,21 @@ typedef struct r_samr_chgpasswd_user_info
 } SAMR_R_CHGPASSWD_USER;
 
 
-/* SAMR_Q_UNKNOWN_2D */
-typedef struct q_samr_unknown_2d_info
+/* SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN */
+typedef struct q_samr_remove_user_foreign_domain_info
 {
        POLICY_HND dom_pol;   /* policy handle */
        DOM_SID2 sid;         /* SID */
 
-} SAMR_Q_UNKNOWN_2D;
+} SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN;
 
 
-/* SAMR_R_UNKNOWN_2D - probably an open */
-typedef struct r_samr_unknown_2d_info
+/* SAMR_R_REMOVE_USER_FOREIGN_DOMAIN */
+typedef struct r_samr_remove_user_foreign_domain_info
 {
        NTSTATUS status;         /* return status */
 
-} SAMR_R_UNKNOWN_2D;
+} SAMR_R_REMOVE_USER_FOREIGN_DOMAIN;
 
 
 
index c2e3d92787c4784b3e153008f39eaac28c7c6aa6..f96b4fa96ab340ce5ab020131a9c17920d1dab8d 100755 (executable)
@@ -1302,6 +1302,12 @@ typedef struct s_port_info_2
 }
 PORT_INFO_2;
 
+/* Port Type bits */
+#define PORT_TYPE_WRITE         0x0001
+#define PORT_TYPE_READ          0x0002
+#define PORT_TYPE_REDIRECTED    0x0004
+#define PORT_TYPE_NET_ATTACHED  0x0008
+
 typedef struct spool_q_enumports
 {
        uint32 name_ptr;
index 6656f4f6bbb804fbc61d7713895c9dd7d393c535..07578b2424c3d00ffcaa2394c201b90e9726fc40 100644 (file)
@@ -124,6 +124,7 @@ size_t __unsafe_string_function_usage_here_char__(void);
 #define pstrcat(d,s) safe_strcat((d), (s),sizeof(pstring)-1)
 #define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
 #define fstrcat(d,s) safe_strcat((d),(s),sizeof(fstring)-1)
+#define nstrcpy(d,s) safe_strcpy((d), (s),sizeof(nstring)-1)
 
 /* the addition of the DEVELOPER checks in safe_strcpy means we must
  * update a lot of code. To make this a little easier here are some
index dacfef26ead28525dd16878392e0f4f97e8e2309..cb4fbd043a7a8ff5a4a105dc17f5e31f184b3893 100644 (file)
@@ -77,5 +77,22 @@ typedef struct trustdom {
        DOM_SID sid;
 } TRUSTDOM;
 
+/*
+ * Format of an OpenAFS keyfile
+ */
+
+#define SECRETS_AFS_MAXKEYS 8
+
+struct afs_key {
+       uint32 kvno;
+       char key[8];
+};
+
+struct afs_keyfile {
+       uint32 nkeys;
+       struct afs_key entry[SECRETS_AFS_MAXKEYS];
+};
+
+#define SECRETS_AFS_KEYFILE "SECRETS/AFS_KEYFILE"
 
 #endif /* _SECRETS_H */
index deeb61034da3c3eaf9c94f5faabbd2f5f9fb1c73..8c6f47f23fbbb087d8d5a7a1f2c163e9bb05a15a 100644 (file)
@@ -390,7 +390,9 @@ typedef struct files_struct
        SMB_OFF_T pos;
        SMB_BIG_UINT size;
        SMB_BIG_UINT initial_allocation_size; /* Faked up initial allocation on disk. */
+       SMB_BIG_UINT position_information;
        mode_t mode;
+       uint16 file_pid;
        uint16 vuid;
        write_bmpx_struct *wbmpx_ptr;
        write_cache *wcp;
@@ -1482,17 +1484,19 @@ struct cnotify_fns {
 
 #include "smb_macros.h"
 
+typedef char nstring[16];
+
 /* A netbios name structure. */
 struct nmb_name {
-  char         name[17];
-  char         scope[64];
-  unsigned int name_type;
+       nstring      name;
+       char         scope[64];
+       unsigned int name_type;
 };
 
 
 /* A netbios node status array element. */
 struct node_status {
-       char name[16];
+       nstring name;
        unsigned char type;
        unsigned char flags;
 };
index 21ccdf295c4554ffb0f0e9a687d7fe0fe88d7aba..178fd9c3580923851da2e53a157f56cdbd293394 100644 (file)
 #define OPEN_CONN(conn)    ((conn) && (conn)->open)
 #define IS_IPC(conn)       ((conn) && (conn)->ipc)
 #define IS_PRINT(conn)       ((conn) && (conn)->printer)
+#define FSP_BELONGS_CONN(fsp,conn) do {\
+                       extern struct current_user current_user;\
+                       if (!((fsp) && (conn) && ((conn)==(fsp)->conn) && (current_user.vuid==(fsp)->vuid))) \
+                               return(ERROR_DOS(ERRDOS,ERRbadfid));\
+                       } while(0)
+
 #define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn && current_user.vuid==(fsp)->vuid)
 
 #define CHECK_FSP(fsp,conn) do {\
diff --git a/source3/include/spnego.h b/source3/include/spnego.h
new file mode 100644 (file)
index 0000000..b6492ee
--- /dev/null
@@ -0,0 +1,65 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   RFC2478 Compliant SPNEGO implementation
+
+   Copyright (C) Jim McDonough <jmcd@us.ibm.com>   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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#ifndef SAMBA_SPNEGO_H
+#define SAMBA_SPNEGO_H
+
+#define SPNEGO_DELEG_FLAG    0x01
+#define SPNEGO_MUTUAL_FLAG   0x02
+#define SPNEGO_REPLAY_FLAG   0x04
+#define SPNEGO_SEQUENCE_FLAG 0x08
+#define SPNEGO_ANON_FLAG     0x10
+#define SPNEGO_CONF_FLAG     0x20
+#define SPNEGO_INTEG_FLAG    0x40
+#define SPNEGO_REQ_FLAG      0x80
+
+#define SPNEGO_NEG_TOKEN_INIT 0
+#define SPNEGO_NEG_TOKEN_TARG 1
+
+typedef enum _spnego_negResult {
+       SPNEGO_ACCEPT_COMPLETED = 0,
+       SPNEGO_ACCEPT_INCOMPLETE = 1,
+       SPNEGO_REJECT = 2
+} negResult_t;
+
+typedef struct spnego_negTokenInit {
+       const char **mechTypes;
+       int reqFlags;
+       DATA_BLOB mechToken;
+       DATA_BLOB mechListMIC;
+} negTokenInit_t;
+
+typedef struct spnego_negTokenTarg {
+       uint8 negResult;
+       const char *supportedMech;
+       DATA_BLOB responseToken;
+       DATA_BLOB mechListMIC;
+} negTokenTarg_t;
+
+typedef struct spnego_spnego {
+       int type;
+       negTokenInit_t negTokenInit;
+       negTokenTarg_t negTokenTarg;
+} SPNEGO_DATA;
+
+#endif
index eb5b1bc79f9273e3299242a98baaac734f309986..168e6477210db65c64c005469488e81aaf745d1e 100644 (file)
@@ -230,6 +230,8 @@ Byte offset   Type     name                description
 #define SMB_FIND_FILE_FULL_DIRECTORY_INFO      0x102
 #define SMB_FIND_FILE_NAMES_INFO               0x103
 #define SMB_FIND_FILE_BOTH_DIRECTORY_INFO      0x104
+#define SMB_FIND_FILE_LEVEL_261                        0x105
+#define SMB_FIND_FILE_LEVEL_262                        0x106
 
 #define SMB_SET_FILE_BASIC_INFO                0x101
 #define SMB_SET_FILE_DISPOSITION_INFO  0x102
index 68bc140dafbf65f5e91369ff3cdd090ef83f6c14..51e8c408e60cb0a3c42640199770999a75caf8b6 100644 (file)
@@ -1 +1,8 @@
-#define VERSION "3.0.0rc1"
+/* Autogenerated by script/mkversion.sh */
+#define SAMBA_VERSION_MAJOR 3
+#define SAMBA_VERSION_MINOR 0
+#define SAMBA_VERSION_RELEASE 1
+#define SAMBA_VERSION_PRE_RELEASE 1
+#define SAMBA_VERSION_IS_CVS_SNAPSHOT 1
+#define SAMBA_VERSION_OFFICIAL_STRING "CVS 3.0.1pre1"
+#define SAMBA_VERSION_STRING samba_version_string()
index 452f4dc23b94c35b78b74c0a33a59cbbfcb53233..dd489702aa9a5d62b2f1532e52f1f02128b8a45e 100644 (file)
@@ -50,8 +50,8 @@
 /* Changed to version 6 for the new module system, fixed cascading and quota functions. --metze */
 /* Changed to version 7 to include the get_nt_acl info parameter. JRA. */
 /* Changed to version 8 includes EA calls. JRA. */
-
-#define SMB_VFS_INTERFACE_VERSION 8
+/* Changed to version 9 to include the get_shadow_data call. --metze */
+#define SMB_VFS_INTERFACE_VERSION 9
 
 
 /* to bug old modules witch are trying to compile with the old functions */
@@ -91,6 +91,8 @@ typedef enum _vfs_op_type {
        SMB_VFS_OP_DISK_FREE,
        SMB_VFS_OP_GET_QUOTA,
        SMB_VFS_OP_SET_QUOTA,
+       SMB_VFS_OP_GET_SHADOW_COPY_DATA,
+
 
        /* Directory operations */
 
@@ -196,6 +198,7 @@ struct vfs_ops {
                        SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
                int (*get_quota)(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt);
                int (*set_quota)(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt);
+               int (*get_shadow_copy_data)(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels);
                
                /* Directory operations */
                
@@ -293,6 +296,7 @@ struct vfs_ops {
                struct vfs_handle_struct *disk_free;
                struct vfs_handle_struct *get_quota;
                struct vfs_handle_struct *set_quota;
+               struct vfs_handle_struct *get_shadow_copy_data;
 
                /* Directory operations */
 
@@ -379,6 +383,7 @@ struct vfs_ops {
                struct vfs_handle_struct *setxattr;
                struct vfs_handle_struct *lsetxattr;
                struct vfs_handle_struct *fsetxattr;
+
        } handles;
 };
 
index fdbc1516e310cce0dca9e04c658c95a7f763f9bf..c4f63c352e4c335679029c19d937d8fb995eea9b 100644 (file)
@@ -33,6 +33,7 @@
 #define SMB_VFS_DISK_FREE(conn, path, small_query, bsize, dfree ,dsize) ((conn)->vfs.ops.disk_free((conn)->vfs.handles.disk_free, (conn), (path), (small_query), (bsize), (dfree), (dsize)))
 #define SMB_VFS_GET_QUOTA(conn, qtype, id, qt) ((conn)->vfs.ops.get_quota((conn)->vfs.handles.get_quota, (conn), (qtype), (id), (qt)))
 #define SMB_VFS_SET_QUOTA(conn, qtype, id, qt) ((conn)->vfs.ops.set_quota((conn)->vfs.handles.set_quota, (conn), (qtype), (id), (qt)))
+#define SMB_VFS_GET_SHADOW_COPY_DATA(fsp,shadow_copy_data,labels) ((fsp)->conn->vfs.ops.get_shadow_copy_data((fsp)->conn->vfs.handles.get_shadow_copy_data,(fsp),(shadow_copy_data),(labels)))
 
 /* Directory operations */
 #define SMB_VFS_OPENDIR(conn, fname) ((conn)->vfs.ops.opendir((conn)->vfs.handles.opendir, (conn), (fname)))
 #define SMB_VFS_OPAQUE_DISK_FREE(conn, path, small_query, bsize, dfree ,dsize) ((conn)->vfs_opaque.ops.disk_free((conn)->vfs_opaque.handles.disk_free, (conn), (path), (small_query), (bsize), (dfree), (dsize)))
 #define SMB_VFS_OPAQUE_GET_QUOTA(conn, qtype, id, qt) ((conn)->vfs_opaque.ops.get_quota((conn)->vfs_opaque.handles.get_quota, (conn), (qtype), (id), (qt)))
 #define SMB_VFS_OPAQUE_SET_QUOTA(conn, qtype, id, qt) ((conn)->vfs_opaque.ops.set_quota((conn)->vfs_opaque.handles.set_quota, (conn), (qtype), (id), (qt)))
+#define SMB_VFS_OPAQUE_GET_SHADOW_COPY_DATA(fsp,shadow_copy_data,labels) ((fsp)->conn->vfs_opaque.ops.get_shadow_copy_data((fsp)->conn->vfs_opaque.handles.get_shadow_copy_data,(fsp),(shadow_copy_data),(labels)))
 
 /* Directory operations */
 #define SMB_VFS_OPAQUE_OPENDIR(conn, fname) ((conn)->vfs_opaque.ops.opendir((conn)->vfs_opaque.handles.opendir, (conn), (fname)))
 #define SMB_VFS_NEXT_DISK_FREE(handle, conn, path, small_query, bsize, dfree ,dsize) ((handle)->vfs_next.ops.disk_free((handle)->vfs_next.handles.disk_free, (conn), (path), (small_query), (bsize), (dfree), (dsize)))
 #define SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, qt) ((handle)->vfs_next.ops.get_quota((handle)->vfs_next.handles.get_quota, (conn), (qtype), (id), (qt)))
 #define SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, qt) ((handle)->vfs_next.ops.set_quota((handle)->vfs_next.handles.set_quota, (conn), (qtype), (id), (qt)))
+#define SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data ,labels) ((handle)->vfs_next.ops.get_shadow_copy_data((handle)->vfs_next.handles.get_shadow_copy_data,(fsp),(shadow_copy_data),(labels)))
 
 /* Directory operations */
 #define SMB_VFS_NEXT_OPENDIR(handle, conn, fname) ((handle)->vfs_next.ops.opendir((handle)->vfs_next.handles.opendir, (conn), (fname)))
index 87ef4e39c7bb1cd15a2b936b2001ae0877e60886..f12b9b6f1511797a8a972698e9db160f7b5855b4 100644 (file)
@@ -53,8 +53,8 @@ static BOOL load_msg(const char *msg_file)
                }
                if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) {
                        msgstr = lines[i] + 8;
-                       trim_string(msgid, NULL, "\"");
-                       trim_string(msgstr, NULL, "\"");
+                       trim_char(msgid, '\0', '\"');
+                       trim_char(msgstr, '\0', '\"');
                        if (*msgstr == 0) {
                                msgstr = msgid;
                        }
index c30b3c33cc2867897c659b1ade86933c4d522682..a874c8b1e2065e01a06c898ff4510bfbd85a5192 100644 (file)
@@ -281,13 +281,12 @@ static BOOL only_ipaddrs_in_list(const char** list)
                }
                
                if (!is_ipaddress(*list)) {
-                       char *p;
                        /* 
                         * if we failed, make sure that it was not because the token
                         * was a network/netmask pair.  Only network/netmask pairs
                         * have a '/' in them
                         */
-                       if ((p=strchr_m(*list, '/')) == NULL) {
+                       if ((strchr_m(*list, '/')) == NULL) {
                                only_ip = False;
                                DEBUG(3,("only_ipaddrs_in_list: list has non-ip address (%s)\n", *list));
                                break;
diff --git a/source3/lib/afs.c b/source3/lib/afs.c
new file mode 100644 (file)
index 0000000..b96703e
--- /dev/null
@@ -0,0 +1,248 @@
+/* 
+ *  Unix SMB/CIFS implementation.
+ *  Generate AFS tickets
+ *  Copyright (C) Volker Lendecke 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
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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.
+ */
+
+#include "includes.h"
+
+#ifdef WITH_FAKE_KASERVER
+
+#include <afs/stds.h>
+#include <afs/afs.h>
+#include <afs/auth.h>
+#include <afs/venus.h>
+#include <asm/unistd.h>
+#include <openssl/des.h>
+
+_syscall5(int, afs_syscall, int, subcall,
+         char *, path,
+         int, cmd,
+         char *, cmarg,
+         int, follow);
+
+char *afs_cell(void)
+{
+       static char *cell = NULL;
+
+       if (cell == NULL) {
+               cell = strdup(lp_realm());
+               strlower_m(cell);
+       }
+
+       return cell;
+}
+
+struct ClearToken {
+       uint32 AuthHandle;
+       char HandShakeKey[8];
+       uint32 ViceId;
+       uint32 BeginTimestamp;
+       uint32 EndTimestamp;
+};
+
+/*
+  Put an AFS token into the Kernel so that it can authenticate against
+  the AFS server. This assumes correct local uid settings.
+
+  This is currently highly Linux and OpenAFS-specific. The correct API
+  call for this would be ktc_SetToken. But to do that we would have to
+  import a REALLY big bunch of libraries which I would currently like
+  to avoid. 
+*/
+
+static BOOL afs_settoken(char *username, const struct ClearToken *ctok,
+                        char *v4tkt_data, int v4tkt_length)
+{
+       int ret;
+       struct {
+               char *in, *out;
+               uint16 in_size, out_size;
+       } iob;
+
+       char buf[1024];
+       char *p = buf;
+       int tmp;
+
+       memcpy(p, &v4tkt_length, sizeof(uint32));
+       p += sizeof(uint32);
+       memcpy(p, v4tkt_data, v4tkt_length);
+       p += v4tkt_length;
+
+       tmp = sizeof(struct ClearToken);
+       memcpy(p, &tmp, sizeof(uint32));
+       p += sizeof(uint32);
+       memcpy(p, ctok, tmp);
+       p += tmp;
+
+       tmp = 0;
+
+       memcpy(p, &tmp, sizeof(uint32));
+       p += sizeof(uint32);
+
+       tmp = strlen(afs_cell());
+       if (tmp >= MAXKTCREALMLEN) {
+               DEBUG(1, ("Realm too long\n"));
+               return False;
+       }
+
+       strncpy(p, afs_cell(), tmp);
+       p += tmp;
+       *p = 0;
+       p +=1;
+
+       iob.in = buf;
+       iob.in_size = PTR_DIFF(p,buf);
+       iob.out = buf;
+       iob.out_size = sizeof(buf);
+
+#if 0
+       file_save("/tmp/ioctlbuf", iob.in, iob.in_size);
+#endif
+
+       ret = afs_syscall(AFSCALL_PIOCTL, 0, VIOCSETTOK, (char *)&iob, 0);
+
+       DEBUG(10, ("afs VIOCSETTOK returned %d\n", ret));
+       return (ret == 0);
+}
+
+/*
+  This routine takes a radical approach completely defeating the
+  Kerberos idea of security and using AFS simply as an intelligent
+  file backend. Samba has persuaded itself somehow that the user is
+  actually correctly identified and then we create a ticket that the
+  AFS server hopefully accepts using its KeyFile that the admin has
+  kindly stored to our secrets.tdb.
+
+  Thanks to the book "Network Security -- PRIVATE Communication in a
+  PUBLIC World" by Charlie Kaufman, Radia Perlman and Mike Speciner
+  Kerberos 4 tickets are not really hard to construct.
+
+  For the comments "Alice" is the User to be auth'ed, and "Bob" is the
+  AFS server.  */
+
+BOOL afs_login(char *username)
+{
+       fstring ticket;
+       char *p = ticket;
+       uint32 len;
+       struct afs_key key;
+
+       struct ClearToken ct;
+
+       uint32 now;             /* I assume time() returns 32 bit */
+
+       des_key_schedule key_schedule;
+
+       DEBUG(10, ("Trying to log into AFS for user %s@%s\n",
+                  username, afs_cell()));
+
+       if (!secrets_init()) 
+               return False;
+
+       if (!secrets_fetch_afs_key(afs_cell(), &key)) {
+               DEBUG(5, ("Could not fetch AFS service key\n"));
+               return False;
+       }
+
+       ct.AuthHandle = key.kvno;
+
+       /* Build the ticket. This is going to be encrypted, so in our
+           way we fill in ct while we still have the unencrypted
+           form. */
+
+       p = ticket;
+
+       /* The byte-order */
+       *p = 1;
+       p += 1;
+
+       /* "Alice", the client username */
+       strncpy(p, username, sizeof(ticket)-PTR_DIFF(p,ticket)-1);
+       p += strlen(p)+1;
+       strncpy(p, "", sizeof(ticket)-PTR_DIFF(p,ticket)-1);
+       p += strlen(p)+1;
+       strncpy(p, afs_cell(), sizeof(ticket)-PTR_DIFF(p,ticket)-1);
+       p += strlen(p)+1;
+
+       ct.ViceId = getuid();
+       DEBUG(10, ("Creating Token for uid %d\n", ct.ViceId));
+
+       /* Alice's network layer address. At least Openafs-1.2.10
+           ignores this, so we fill in a dummy value here. */
+       SIVAL(p, 0, 0);
+       p += 4;
+
+       /* We need to create a session key */
+       generate_random_buffer(p, 8, False);
+
+       /* Our client code needs the the key in the clear, it does not
+           know the server-key ... */
+       memcpy(ct.HandShakeKey, p, 8);
+
+       p += 8;
+
+       /* Ticket lifetime. We fake everything here, so go as long as
+          possible. This is in 5-minute intervals, so 255 is 21 hours
+          and 15 minutes.*/
+       *p = 255;
+       p += 1;
+
+       /* Ticket creation time */
+       now = time(NULL);
+       SIVAL(p, 0, now);
+       ct.BeginTimestamp = now;
+
+       ct.EndTimestamp = now + (255*60*5);
+       if (((ct.EndTimestamp - ct.BeginTimestamp) & 1) == 1) {
+               ct.BeginTimestamp += 1; /* Lifetime must be even */
+       }
+       p += 4;
+
+       /* And here comes Bob's name and instance, in this case the
+           AFS server. */
+       strncpy(p, "afs", sizeof(ticket)-PTR_DIFF(p,ticket)-1);
+       p += strlen(p)+1;
+       strncpy(p, "", sizeof(ticket)-PTR_DIFF(p,ticket)-1);
+       p += strlen(p)+1;
+
+       /* And zero-pad to a multiple of 8 bytes */
+       len = PTR_DIFF(p, ticket);
+       if (len & 7) {
+               uint32 extra_space = 8-(len & 7);
+               memset(p, 0, extra_space);
+               p+=extra_space;
+       }
+       len = PTR_DIFF(p, ticket);
+
+       des_key_sched((const_des_cblock *)key.key, key_schedule);
+       des_pcbc_encrypt(ticket, ticket,
+                        len, key_schedule, (C_Block *)key.key, 1);
+
+       ZERO_STRUCT(key);
+
+       return afs_settoken(username, &ct, ticket, len);
+}
+
+#else
+
+BOOL afs_login(char *username)
+{
+       return True;
+}
+
+#endif /* WITH_FAKE_KASERVER */
index ca5e378970cb59d7dc8a45e70c435f58bad211ed..5f3cf64a6852723a95e156dea8fe346aeb858947 100644 (file)
@@ -40,7 +40,7 @@
 
 
 static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
-
+static BOOL conv_silent; /* Should we do a debug if the conversion fails ? */
 
 /**
  * Return the name of a charset to give to iconv().
@@ -141,21 +141,28 @@ void init_iconv(void)
                /* XXX: Does this really get called every time the dos
                 * codepage changes? */
                /* XXX: Is the did_reload test too strict? */
+               conv_silent = True;
                init_doschar_table();
                init_valid_table();
+               conv_silent = False;
        }
 }
 
 /**
  * Convert string from one encoding to another, making error checking etc
+ * Slow path version - uses (slow) iconv.
  *
  * @param src pointer to source string (multibyte or singlebyte)
  * @param srclen length of the source string in bytes
  * @param dest pointer to destination string (multibyte or singlebyte)
  * @param destlen maximal length allowed for string
  * @returns the number of bytes occupied in the destination
+ *
+ * Ensure the srclen contains the terminating zero.
+ *
  **/
-size_t convert_string(charset_t from, charset_t to,
+
+static size_t convert_string_internal(charset_t from, charset_t to,
                      void const *src, size_t srclen, 
                      void *dest, size_t destlen)
 {
@@ -165,18 +172,14 @@ size_t convert_string(charset_t from, charset_t to,
        char* outbuf = (char*)dest;
        smb_iconv_t descriptor;
 
-       if (srclen == (size_t)-1)
-               srclen = strlen(src)+1;
-
        lazy_initialize_conv();
 
        descriptor = conv_handles[from][to];
 
        if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
-               /* conversion not supported, use as is */
-               size_t len = MIN(srclen,destlen);
-               memcpy(dest,src,len);
-               return len;
+               if (!conv_silent)
+                       DEBUG(0,("convert_string_internal: Conversion not supported.\n"));
+               goto use_as_is;
        }
 
        i_len=srclen;
@@ -187,67 +190,208 @@ size_t convert_string(charset_t from, charset_t to,
                switch(errno) {
                        case EINVAL:
                                reason="Incomplete multibyte sequence";
-                               break;
+                               if (!conv_silent)
+                                       DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
+                               goto use_as_is;
                        case E2BIG:
                                reason="No more room"; 
-                               DEBUG(0, ("convert_string: Required %lu, available %lu\n",
-                                       (unsigned long)srclen, (unsigned long)destlen));
+                               if (!conv_silent)
+                                       DEBUG(3, ("convert_string_internal: Required %lu, available %lu\n",
+                                               (unsigned long)srclen, (unsigned long)destlen));
                                /* we are not sure we need srclen bytes,
                                  may be more, may be less.
                                  We only know we need more than destlen
                                  bytes ---simo */
                               break;
                        case EILSEQ:
-                              reason="Illegal multibyte sequence";
-                              break;
+                               reason="Illegal multibyte sequence";
+                               if (!conv_silent)
+                                       DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
+                               goto use_as_is;
+                       default:
+                               if (!conv_silent)
+                                       DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",reason,inbuf));
+                               break;
                }
                /* smb_panic(reason); */
        }
        return destlen-o_len;
+
+ use_as_is:
+
+       /* conversion not supported, use as is */
+       {
+               size_t len = MIN(srclen,destlen);
+               if (len)
+                       memcpy(dest,src,len);
+               return len;
+       }
+}
+
+/**
+ * Convert string from one encoding to another, making error checking etc
+ * Fast path version - handles ASCII first.
+ *
+ * @param src pointer to source string (multibyte or singlebyte)
+ * @param srclen length of the source string in bytes
+ * @param dest pointer to destination string (multibyte or singlebyte)
+ * @param destlen maximal length allowed for string
+ * @returns the number of bytes occupied in the destination
+ *
+ * Ensure the srclen contains the terminating zero.
+ *
+ * This function has been hand-tuned to provide a fast path.
+ * Don't change unless you really know what you are doing. JRA.
+ **/
+
+size_t convert_string(charset_t from, charset_t to,
+                     void const *src, size_t srclen, 
+                     void *dest, size_t destlen)
+{
+       if (srclen == 0)
+               return 0;
+
+       if (from != CH_UCS2 && to != CH_UCS2) {
+               const unsigned char *p = (const unsigned char *)src;
+               unsigned char *q = (unsigned char *)dest;
+               unsigned char lastp;
+               size_t retval = 0;
+
+               /* If all characters are ascii, fast path here. */
+               while (srclen && destlen) {
+                       if ((lastp = *p) <= 0x7f) {
+                               *q++ = *p++;
+                               if (srclen != (size_t)-1) {
+                                       srclen--;
+                               }
+                               destlen--;
+                               retval++;
+                               if (!lastp)
+                                       break;
+                       } else {
+                               if (srclen == (size_t)-1) {
+                                       srclen = strlen(p)+1;
+                               }
+                               return retval + convert_string_internal(from, to, p, srclen, q, destlen);
+                       }
+               }
+               return retval;
+       } else if (from == CH_UCS2 && to != CH_UCS2) {
+               const unsigned char *p = (const unsigned char *)src;
+               unsigned char *q = (unsigned char *)dest;
+               size_t retval = 0;
+               unsigned char lastp;
+
+               /* If all characters are ascii, fast path here. */
+               while ((srclen >= 2) && destlen) {
+                       if ((lastp = *p) <= 0x7f && p[1] == 0) {
+                               *q++ = *p;
+                               if (srclen != (size_t)-1) {
+                                       srclen -= 2;
+                               }
+                               p += 2;
+                               destlen--;
+                               retval++;
+                               if (!lastp)
+                                       break;
+                       } else {
+                               if (srclen == (size_t)-1) {
+                                       srclen = strlen_w((const void *)p)+2;
+                               }
+                               return retval + convert_string_internal(from, to, p, srclen, q, destlen);
+                       }
+               }
+               return retval;
+       } else if (from != CH_UCS2 && to == CH_UCS2) {
+               const unsigned char *p = (const unsigned char *)src;
+               unsigned char *q = (unsigned char *)dest;
+               size_t retval = 0;
+               unsigned char lastp;
+
+               /* If all characters are ascii, fast path here. */
+               while (srclen && (destlen >= 2)) {
+                       if ((lastp = *p) <= 0x7F) {
+                               *q++ = *p++;
+                               *q++ = '\0';
+                               if (srclen != (size_t)-1) {
+                                       srclen--;
+                               }
+                               destlen -= 2;
+                               retval += 2;
+                               if (!lastp)
+                                       break;
+                       } else {
+                               if (srclen == (size_t)-1) {
+                                       srclen = strlen(p)+1;
+                               }
+                               return retval + convert_string_internal(from, to, p, srclen, q, destlen);
+                       }
+               }
+               return retval;
+       }
+       return convert_string_internal(from, to, src, srclen, dest, destlen);
 }
 
 /**
  * Convert between character sets, allocating a new buffer for the result.
  *
+ * @param ctx TALLOC_CTX to use to allocate with. If NULL use malloc.
  * @param srclen length of source buffer.
  * @param dest always set at least to NULL
  * @note -1 is not accepted for srclen.
  *
  * @returns Size in bytes of the converted string; or -1 in case of error.
+ *
+ * Ensure the srclen contains the terminating zero.
  **/
 
-size_t convert_string_allocate(charset_t from, charset_t to,
+size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
                               void const *src, size_t srclen, void **dest)
 {
-       size_t i_len, o_len, destlen;
+       size_t i_len, o_len, destlen = MAX(srclen, 512);
        size_t retval;
        const char *inbuf = (const char *)src;
-       char *outbuf, *ob;
+       char *outbuf = NULL, *ob = NULL;
        smb_iconv_t descriptor;
 
        *dest = NULL;
 
        if (src == NULL || srclen == (size_t)-1)
                return (size_t)-1;
+       if (srclen == 0)
+               return 0;
 
        lazy_initialize_conv();
 
        descriptor = conv_handles[from][to];
 
        if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
-               /* conversion not supported, return -1*/
-               DEBUG(3, ("convert_string_allocate: conversion not supported!\n"));
-               return -1;
+               if (!conv_silent)
+                       DEBUG(0,("convert_string_allocate: Conversion not supported.\n"));
+               goto use_as_is;
        }
 
-       destlen = MAX(srclen, 512);
-       outbuf = NULL;
 convert:
-       destlen = destlen * 2;
-       ob = (char *)Realloc(outbuf, destlen);
+       if ((destlen*2) < destlen) {
+               /* wrapped ! abort. */
+               if (!conv_silent)
+                       DEBUG(0, ("convert_string_allocate: destlen wrapped !\n"));
+               if (!ctx)
+                       SAFE_FREE(outbuf);
+               return (size_t)-1;
+       } else {
+               destlen = destlen * 2;
+       }
+
+       if (ctx)
+               ob = (char *)talloc_realloc(ctx, ob, destlen);
+       else
+               ob = (char *)Realloc(ob, destlen);
+
        if (!ob) {
                DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
-               SAFE_FREE(outbuf);
+               if (!ctx)
+                       SAFE_FREE(outbuf);
                return (size_t)-1;
        } else {
                outbuf = ob;
@@ -262,27 +406,59 @@ convert:
                switch(errno) {
                        case EINVAL:
                                reason="Incomplete multibyte sequence";
-                               break;
+                               if (!conv_silent)
+                                       DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
+                               goto use_as_is;
                        case E2BIG:
                                goto convert;           
                        case EILSEQ:
                                reason="Illegal multibyte sequence";
-                               break;
+                               if (!conv_silent)
+                                       DEBUG(3,("convert_string_allocate: Conversion error: %s(%s)\n",reason,inbuf));
+                               goto use_as_is;
                }
-               DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf));
+               if (!conv_silent)
+                       DEBUG(0,("Conversion error: %s(%s)\n",reason,inbuf));
                /* smb_panic(reason); */
                return (size_t)-1;
        }
        
        destlen = destlen - o_len;
-       *dest = (char *)Realloc(ob,destlen);
+       if (ctx)
+               *dest = (char *)talloc_realloc(ctx,ob,destlen);
+       else
+               *dest = (char *)Realloc(ob,destlen);
        if (destlen && !*dest) {
                DEBUG(0, ("convert_string_allocate: out of memory!\n"));
-               SAFE_FREE(ob);
+               if (!ctx)
+                       SAFE_FREE(ob);
                return (size_t)-1;
        }
 
        return destlen;
+
+  use_as_is:
+
+       /* conversion not supported, use as is */
+       {
+               if (srclen && (destlen != srclen)) {
+                       destlen = srclen;
+                       if (ctx)
+                               ob = (char *)talloc_realloc(ctx, ob, destlen);
+                       else
+                               ob = (char *)Realloc(ob, destlen);
+                       if (!ob) {
+                               DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
+                               if (!ctx)
+                                       SAFE_FREE(outbuf);
+                               return (size_t)-1;
+                       }
+               }
+               if (srclen && ob)
+                       memcpy(ob,(const char *)src,srclen);
+               *dest = (char *)ob;
+               return srclen;
+       }
 }
 
 
@@ -298,17 +474,12 @@ convert:
 static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
                                void const *src, size_t srclen, void **dest)
 {
-       void *alloced_string;
        size_t dest_len;
 
-       /* FIXME: Ridiculous to allocate two buffers and then copy the string! */
-       
        *dest = NULL;
-       dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string);
+       dest_len=convert_string_allocate(ctx, from, to, src, srclen, dest);
        if (dest_len == (size_t)-1)
                return (size_t)-1;
-       *dest = talloc_memdup(ctx, alloced_string, dest_len);
-       SAFE_FREE(alloced_string);
        if (*dest == NULL)
                return (size_t)-1;
        return dest_len;
@@ -335,29 +506,49 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
 
 /**
  strdup() a unix string to upper case.
+ Max size is pstring.
 **/
 
 char *strdup_upper(const char *s)
 {
-       size_t size;
-       smb_ucs2_t *buffer;
-       char *out_buffer;
-       
-       size = push_ucs2_allocate(&buffer, s);
-       if (size == -1) {
-               return NULL;
+       pstring out_buffer;
+       const unsigned char *p = (const unsigned char *)s;
+       unsigned char *q = (unsigned char *)out_buffer;
+
+       /* this is quite a common operation, so we want it to be
+          fast. We optimise for the ascii case, knowing that all our
+          supported multi-byte character sets are ascii-compatible
+          (ie. they match for the first 128 chars) */
+
+       while (1) {
+               if (*p & 0x80)
+                       break;
+               *q++ = toupper(*p);
+               if (!*p)
+                       break;
+               p++;
+               if (p - ( const unsigned char *)s >= sizeof(pstring))
+                       break;
        }
 
-       strupper_w(buffer);
-       
-       size = pull_ucs2_allocate(&out_buffer, buffer);
-       SAFE_FREE(buffer);
+       if (*p) {
+               /* MB case. */
+               size_t size;
+               wpstring buffer;
+               size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer));
+               if (size == -1) {
+                       return NULL;
+               }
 
-       if (size == -1) {
-               return NULL;
-       }
+               strupper_w(buffer);
        
-       return out_buffer;
+               size = convert_string(CH_UCS2, CH_UNIX, buffer, sizeof(buffer), out_buffer, sizeof(out_buffer));
+               if (size == -1) {
+                       return NULL;
+               }
+       }
+
+       return strdup(out_buffer);
 }
 
 size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
@@ -365,7 +556,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
        size_t size;
        smb_ucs2_t *buffer;
        
-       size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen,
+       size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen,
                                       (void **) &buffer);
        if (size == -1) {
                smb_panic("failed to create UCS2 buffer");
@@ -459,6 +650,11 @@ size_t push_ascii_pstring(void *dest, const char *src)
        return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE);
 }
 
+size_t push_ascii_nstring(void *dest, const char *src)
+{
+       return push_ascii(dest, src, sizeof(nstring), STR_TERMINATE);
+}
+
 /**
  * Copy a string from a dos codepage source to a unix char* destination.
  *
@@ -512,6 +708,11 @@ size_t pull_ascii_fstring(char *dest, const void *src)
        return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE);
 }
 
+size_t pull_ascii_nstring(char *dest, const void *src)
+{
+       return pull_ascii(dest, src, sizeof(nstring), sizeof(nstring), STR_TERMINATE);
+}
+
 /**
  * Copy a string from a char* src to a unicode destination.
  *
@@ -528,22 +729,26 @@ size_t pull_ascii_fstring(char *dest, const void *src)
  * @param dest_len is the maximum length allowed in the
  * destination. If dest_len is -1 then no maxiumum is used.
  **/
+
 size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags)
 {
        size_t len=0;
-       size_t src_len = strlen(src);
+       size_t src_len;
 
        /* treat a pstring as "unlimited" length */
        if (dest_len == (size_t)-1)
                dest_len = sizeof(pstring);
 
        if (flags & STR_TERMINATE)
-               src_len++;
+               src_len = (size_t)-1;
+       else
+               src_len = strlen(src);
 
        if (ucs2_align(base_ptr, dest, flags)) {
                *(char *)dest = 0;
                dest = (void *)((char *)dest + 1);
-               if (dest_len) dest_len--;
+               if (dest_len)
+                       dest_len--;
                len++;
        }
 
@@ -599,7 +804,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
        size_t src_len = strlen(src)+1;
 
        *dest = NULL;
-       return convert_string_allocate(CH_UNIX, CH_UCS2, src, src_len, (void **)dest);  
+       return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest);    
 }
 
 /**
@@ -667,7 +872,7 @@ size_t push_utf8_allocate(char **dest, const char *src)
        size_t src_len = strlen(src)+1;
 
        *dest = NULL;
-       return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest);  
+       return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest);    
 }
 
 /**
@@ -695,9 +900,8 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_
        }
 
        if (flags & STR_TERMINATE) {
-               if (src_len == (size_t)-1) {
-                       src_len = strlen_w(src)*2 + 2;
-               } else {
+               /* src_len -1 is the default for null terminated strings. */
+               if (src_len != (size_t)-1) {
                        size_t len = strnlen_w(src, src_len/2);
                        if (len < src_len/2)
                                len++;
@@ -755,7 +959,7 @@ size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src)
 {
        size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
        *dest = NULL;
-       return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, (void **)dest);  
+       return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest);    
 }
 
 /**
@@ -785,7 +989,7 @@ size_t pull_utf8_allocate(void **dest, const char *src)
 {
        size_t src_len = strlen(src)+1;
        *dest = NULL;
-       return convert_string_allocate(CH_UTF8, CH_UNIX, src, src_len, dest);   
+       return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, dest);     
 }
  
 /**
@@ -845,8 +1049,10 @@ size_t push_string_fn(const char *function, unsigned int line, const void *base_
 
 size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
 {
+#ifdef DEVELOPER
        if (dest_len != (size_t)-1)
                clobber_region(function, line, dest, dest_len);
+#endif
 
        if (!(flags & STR_ASCII) && \
            ((flags & STR_UNICODE || \
@@ -865,4 +1071,3 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
        }
        return 0;
 }
-
diff --git a/source3/lib/dummyroot.c b/source3/lib/dummyroot.c
new file mode 100644 (file)
index 0000000..c8465cb
--- /dev/null
@@ -0,0 +1,33 @@
+/* 
+   Unix SMB/CIFS implementation.
+   RPC pipe client
+
+   Copyright (C) Tim Potter 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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+/* Stupid dummy functions required due to the horrible dependency mess
+   in Samba. */
+
+void become_root(void)
+{
+        return;
+}
+
+void unbecome_root(void)
+{
+        return;
+}
index a9e1b7bbb92b338bc2ab1619a1eda224d0600851..df7830ef83b4b1f310a10a22fbee8428a505a9c7 100644 (file)
@@ -34,7 +34,7 @@ static void fault_report(int sig)
        counter++;
 
        DEBUG(0,("===============================================================\n"));
-       DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),VERSION));
+       DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),SAMBA_VERSION_STRING));
        DEBUG(0,("\nPlease read the appendix Bugs of the Samba HOWTO collection\n"));
        DEBUG(0,("===============================================================\n"));
   
index f3740e3e12789b2a3e89b831c43b55936f765914..da8808af1640d2d07d9ba48c3965749bc9d5c606 100644 (file)
@@ -121,10 +121,11 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout)
        keybuf.dsize = strlen(keystr)+1;
        databuf.dptr = strdup(valstr);
        databuf.dsize = strlen(valstr)+1;
-       DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout \
-                  = %s (%d seconds %s)\n", keybuf.dptr, value, ctime(&timeout),
-                  (int)(timeout - time(NULL)), timeout > time(NULL) ? "ahead" : "in the past"));
-               
+       DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
+                  " %s (%d seconds %s)\n", keybuf.dptr, value,ctime(&timeout),
+                  (int)(timeout - time(NULL)), 
+                  timeout > time(NULL) ? "ahead" : "in the past"));
+
        ret = tdb_store(cache, keybuf, databuf, 0);
        SAFE_FREE(valstr);
        SAFE_FREE(keybuf.dptr);
index c7b1493b4cc7d66625af08891ef8fc28367359ef..18b6534dec2fb27be0cbe76dac461f20e4ead751 100644 (file)
@@ -84,21 +84,20 @@ BOOL hash_table_init(hash_table *table, unsigned num_buckets, compare_function c
  *     For the last few chars that cannot be int'ed, use char instead.
  *     The function returns the bucket index number for the hashed 
  *     key.
+ *     JRA. Use a djb-algorithm hash for speed.
  **************************************************************
  */
 
 static int string_hash(int hash_size, const char *key)
 {
-       u32 value;      /* Used to compute the hash value.  */
-       u32   i;        /* Used to cycle through random values. */
-
-       for (value = 0x238F13AF, i=0; key[i]; i++)
-               value = (value + (key[i] << (i*5 % 24)));
-
-       return (1103515243 * value + 12345) % hash_size;  
+       u32 n = 0;
+       const char *p;
+       for (p = key; *p != '\0'; p++) {
+               n = ((n << 5) + n) ^ (u32)(*p);
+       }
+       return (n % hash_size);
 }
 
-
 /* *************************************************************************
  *     Search the hash table for the entry in the hash chain.
  *     The function returns the pointer to the 
index ac4fe57a2c8a3b86463532bbed60aede178712f6..e2c6f6dcf51fc1465b6fe682d466522a0b16986c 100644 (file)
 #include "includes.h"
 
 #ifdef HAVE_DLOPEN
-NTSTATUS smb_load_module(const char *module_name)
+
+/* Load a dynamic module.  Only log a level 0 error if we are not checking 
+   for the existence of a module (probling). */
+
+static NTSTATUS do_smb_load_module(const char *module_name, BOOL is_probe)
 {
        void *handle;
        init_module_function *init;
@@ -37,17 +41,21 @@ NTSTATUS smb_load_module(const char *module_name)
        handle = sys_dlopen(module_name, RTLD_LAZY);
 
        if(!handle) {
-               DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror()));
+               int level = is_probe ? 2 : 0;
+               DEBUG(level, ("Error loading module '%s': %s\n", module_name, 
+                             sys_dlerror()));
+
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       init = sys_dlsym(handle, "init_module");
+       init = (init_module_function *)sys_dlsym(handle, "init_module");
 
        /* we must check sys_dlerror() to determine if it worked, because
            sys_dlsym() can validly return NULL */
        error = sys_dlerror();
        if (error) {
-               DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error));
+               DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", 
+                         module_name, error));
                return NT_STATUS_UNSUCCESSFUL;
        }
 
@@ -58,6 +66,11 @@ NTSTATUS smb_load_module(const char *module_name)
        return status;
 }
 
+NTSTATUS smb_load_module(const char *module_name)
+{
+       return do_smb_load_module(module_name, False);
+}
+
 /* Load all modules in list and return number of 
  * modules that has been successfully loaded */
 int smb_load_modules(const char **modules)
@@ -85,8 +98,11 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module)
        /* if we make any 'samba multibyte string' 
           calls here, we break 
           for loading string modules */
+
+       DEBUG(5, ("Probing module '%s'\n", module));
+
        if (module[0] == '/')
-               return smb_load_module(module);
+               return do_smb_load_module(module, True);
        
        pstrcpy(full_path, lib_path(subsystem));
        pstrcat(full_path, "/");
@@ -94,9 +110,9 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module)
        pstrcat(full_path, ".");
        pstrcat(full_path, shlib_ext());
 
-       DEBUG(5, ("Probing module %s: Trying to load from %s\n", module, full_path));
+       DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path));
        
-       return smb_load_module(full_path);
+       return do_smb_load_module(full_path, True);
 }
 
 #else /* HAVE_DLOPEN */
index 106efa5bbcf449120ebf92b3c26622fc68f7b400..24232c3b523b1293e32f43b2e0c24574aa008324 100644 (file)
@@ -35,7 +35,8 @@
    of the protocol. This is not yet perfect, but its a lot
    better than what we had */
 static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern, 
-                                 const smb_ucs2_t *string)
+                                 const smb_ucs2_t *string,
+                                 BOOL case_sensitive)
 {
        const smb_ucs2_t *p = pattern, *n = string;
        smb_ucs2_t c;
@@ -61,8 +62,8 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern,
                case UCS2_CHAR('>'):
                        if (! *n) goto next;
                        if (n[0] == UCS2_CHAR('.')) {
-                               if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match;
-                               if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+                               if (! n[1] && ms_fnmatch_lanman_core(p, n+1, case_sensitive) == 0) goto match;
+                               if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match;
                                goto nomatch;
                        }
                        n++;
@@ -72,13 +73,13 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern,
                        if (! *n) goto next;
                        if (! *p) goto match;
                        for (; *n; n++) {
-                               if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+                               if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match;
                        }
                        break;
 
                case UCS2_CHAR('<'):
                        for (; *n; n++) {
-                               if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+                               if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match;
                                if (*n == UCS2_CHAR('.') && 
                                    !strchr_w(n+1,UCS2_CHAR('.'))) {
                                        n++;
@@ -88,13 +89,17 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern,
                        break;
 
                case UCS2_CHAR('"'):
-                       if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match;
+                       if (*n == 0 && ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match;
                        if (*n != UCS2_CHAR('.')) goto nomatch;
                        n++;
                        break;
 
                default:
-                       if (c != *n) goto nomatch;
+                       if (case_sensitive) {
+                               if (c != *n) goto nomatch;
+                       } else {
+                               if (tolower_w(c) != tolower_w(*n)) goto nomatch;
+                       }
                        n++;
                }
        }
@@ -108,7 +113,7 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern,
        return -1;
 
 next:
-       if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+       if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match;
         goto nomatch;
 
  match:
@@ -118,7 +123,8 @@ next:
        return 0;
 }
 
-static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *string)
+static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, 
+                             const smb_ucs2_t *string, BOOL case_sensitive)
 {
        if (!strpbrk_wa(pattern, "?*<>\"")) {
                smb_ucs2_t s[] = {UCS2_CHAR('.'), 0};
@@ -129,11 +135,11 @@ static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *strin
        if (strcmp_wa(string,"..") == 0 || strcmp_wa(string,".") == 0) {
                smb_ucs2_t dot[] = {UCS2_CHAR('.'), 0};
                smb_ucs2_t dotdot[] = {UCS2_CHAR('.'), UCS2_CHAR('.'), 0};
-               return ms_fnmatch_lanman_core(pattern, dotdot) &&
-                       ms_fnmatch_lanman_core(pattern, dot);
+               return ms_fnmatch_lanman_core(pattern, dotdot, case_sensitive) &&
+                       ms_fnmatch_lanman_core(pattern, dot, case_sensitive);
        }
 
-       return ms_fnmatch_lanman_core(pattern, string);
+       return ms_fnmatch_lanman_core(pattern, string, case_sensitive);
 }
 
 
@@ -145,13 +151,14 @@ static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *strin
 
    Returns 0 on match, -1 on fail.
 */
-static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int protocol)
+static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, 
+                       int protocol, BOOL case_sensitive)
 {
        const smb_ucs2_t *p = pattern, *n = string;
        smb_ucs2_t c;
 
        if (protocol <= PROTOCOL_LANMAN2) {
-               return ms_fnmatch_lanman1(pattern, string);
+               return ms_fnmatch_lanman1(pattern, string, case_sensitive);
        }
 
        while ((c = *p++)) {
@@ -163,23 +170,23 @@ static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int
 
                case UCS2_CHAR('>'):
                        if (n[0] == UCS2_CHAR('.')) {
-                               if (! n[1] && ms_fnmatch_w(p, n+1, protocol) == 0) return 0;
-                               if (ms_fnmatch_w(p, n, protocol) == 0) return 0;
+                               if (! n[1] && ms_fnmatch_w(p, n+1, protocol, case_sensitive) == 0) return 0;
+                               if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0;
                                return -1;
                        }
-                       if (! *n) return ms_fnmatch_w(p, n, protocol);
+                       if (! *n) return ms_fnmatch_w(p, n, protocol, case_sensitive);
                        n++;
                        break;
 
                case UCS2_CHAR('*'):
                        for (; *n; n++) {
-                               if (ms_fnmatch_w(p, n, protocol) == 0) return 0;
+                               if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0;
                        }
                        break;
 
                case UCS2_CHAR('<'):
                        for (; *n; n++) {
-                               if (ms_fnmatch_w(p, n, protocol) == 0) return 0;
+                               if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0;
                                if (*n == UCS2_CHAR('.') && !strchr_wa(n+1,'.')) {
                                        n++;
                                        break;
@@ -188,13 +195,17 @@ static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int
                        break;
 
                case UCS2_CHAR('"'):
-                       if (*n == 0 && ms_fnmatch_w(p, n, protocol) == 0) return 0;
+                       if (*n == 0 && ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0;
                        if (*n != UCS2_CHAR('.')) return -1;
                        n++;
                        break;
 
                default:
-                       if (c != *n) return -1;
+                       if (case_sensitive) {
+                               if (c != *n) return -1;
+                       } else {
+                               if (tolower_w(c) != tolower_w(*n)) return -1;
+                       }
                        n++;
                }
        }
@@ -204,22 +215,35 @@ static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int
        return -1;
 }
 
-
-int ms_fnmatch(const char *pattern, const char *string, int protocol)
+int ms_fnmatch(const char *pattern, const char *string, int protocol, 
+              BOOL case_senstive)
 {
-       wpstring p, s;
+       wpstring buffer_pattern, buffer_string;
        int ret;
+       size_t size;
+
+       size = push_ucs2(NULL, buffer_pattern, pattern, sizeof(buffer_pattern), STR_TERMINATE);
+       if (size == (size_t)-1) {
+               return -1;
+               /* Not quite the right answer, but finding the right one
+                  under this failure case is expensive, and it's pretty close */
+       }
+       
+       size = push_ucs2(NULL, buffer_string, string, sizeof(buffer_string), STR_TERMINATE);
+       if (size == (size_t)-1) {
+               return -1;
+               /* Not quite the right answer, but finding the right one
+                  under this failure case is expensive, and it's pretty close */
+       }
 
-       pstrcpy_wa(p, pattern);
-       pstrcpy_wa(s, string);
+       ret = ms_fnmatch_w(buffer_pattern, buffer_string, protocol, case_senstive);
+       DEBUG(10,("ms_fnmatch(%s,%s) -> %d\n", pattern, string, ret));
 
-       ret = ms_fnmatch_w(p, s, protocol);
-/*     DEBUG(0,("ms_fnmatch(%s,%s) -> %d\n", pattern, string, ret)); */
        return ret;
 }
 
 /* a generic fnmatch function - uses for non-CIFS pattern matching */
 int gen_fnmatch(const char *pattern, const char *string)
 {
-       return ms_fnmatch(pattern, string, PROTOCOL_NT1);
+       return ms_fnmatch(pattern, string, PROTOCOL_NT1, True);
 }
index af1cbcfe80caff856d5a0f76fb3dc1991089237b..9a5a11202255e77aada34e8c29e3d47ae90cf887 100644 (file)
@@ -69,7 +69,7 @@ static void popt_common_callback(poptContext con,
                break;
 
        case 'V':
-               printf( "Version %s\n", VERSION );
+               printf( "Version %s\n", SAMBA_VERSION_STRING);
                exit(0);
                break;
 
@@ -119,6 +119,7 @@ struct poptOption popt_common_connection[] = {
        { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" },
        { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" },
        { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" },
+
        POPT_TABLEEND
 };
 
@@ -259,6 +260,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info)
  *             -k,--use-kerberos
  *             -N,--no-pass
  *             -S,--signing
+ *              -P --machine-pass
  */
 
 
@@ -335,7 +337,8 @@ static void popt_common_credentials_callback(poptContext con,
                        cmdline_auth_info.signing_state = -1;
                        if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false"))
                                cmdline_auth_info.signing_state = False;
-                       else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true"))
+                       else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") ||
+                                       strequal(arg, "auto") )
                                cmdline_auth_info.signing_state = True;
                        else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced"))
                                cmdline_auth_info.signing_state = Required;
@@ -345,6 +348,33 @@ static void popt_common_credentials_callback(poptContext con,
                        }
                }
                break;
+       case 'P':
+               {
+                       char *opt_password = NULL;
+                       /* it is very useful to be able to make ads queries as the
+                          machine account for testing purposes and for domain leave */
+                       
+                       if (!secrets_init()) {
+                               d_printf("ERROR: Unable to open secrets database\n");
+                               exit(1);
+                       }
+                       
+                       opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
+                       
+                       if (!opt_password) {
+                               d_printf("ERROR: Unable to fetch machine password\n");
+                               exit(1);
+                       }
+                       pstr_sprintf(cmdline_auth_info.username, "%s$", 
+                                    global_myname());
+                       pstrcpy(cmdline_auth_info.password,opt_password);
+                       SAFE_FREE(opt_password);
+
+                       /* machine accounts only work with kerberos */
+                       cmdline_auth_info.use_kerberos = True;
+                       cmdline_auth_info.got_pass = True;
+               }
+               break;
        }
 }
 
@@ -357,5 +387,6 @@ struct poptOption popt_common_credentials[] = {
        { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" },
        { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
        { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" },
+       {"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" },
        POPT_TABLEEND
 };
index ceb02ef749c061f932fcc62e005e65d5e7fbabed..78b99fd7fb03168fe78c71d1e4d8feea61e6d1cb 100644 (file)
@@ -51,7 +51,7 @@
 ****************************************************************************/
 
 static char *smb_readline_replacement(char *prompt, void (*callback)(void), 
-                               char **(completion_fn)(char *text, int start, int end))
+                               char **(completion_fn)(const char *text, int start, int end))
 {
        fd_set fds;
        static pstring line;
@@ -83,7 +83,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void),
 ****************************************************************************/
 
 char *smb_readline(char *prompt, void (*callback)(void), 
-                  char **(completion_fn)(char *text, int start, int end))
+                  char **(completion_fn)(const char *text, int start, int end))
 {
 #if HAVE_LIBREADLINE
        if (isatty(x_fileno(x_stdin))) {
diff --git a/source3/lib/replace1.c b/source3/lib/replace1.c
new file mode 100644 (file)
index 0000000..e1be56e
--- /dev/null
@@ -0,0 +1,42 @@
+/* 
+   Unix SMB/CIFS implementation.
+   replacement routines for broken systems
+   Copyright (C) Andrew Tridgell 1992-1998
+   
+   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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#include "includes.h"
+
+ void replace1_dummy(void);
+ void replace1_dummy(void) {}
+
+#ifndef HAVE_SETENV
+ int setenv(const char *name, const char *value, int overwrite) 
+{
+       char *p = NULL;
+       int ret = -1;
+
+       asprintf(&p, "%s=%s", name, value);
+
+       if (overwrite || getenv(name)) {
+               if (p) ret = putenv(p);
+       } else {
+               ret = 0;
+       }
+
+       return ret;     
+}
+#endif
index 3f56d066ec0e400c778d566634b46e0c8d391473..1ce03491da175b270039882ef65e335c76e85de3 100644 (file)
@@ -1172,6 +1172,9 @@ static NTSTATUS add_new_domain_info(struct smbldap_state *ldap_state,
        LDAPMessage *result = NULL;
        int num_result;
        char **attr_list;
+       uid_t u_low, u_high;
+       gid_t g_low, g_high;
+       uint32 rid_low, rid_high;
 
        slprintf (filter, sizeof (filter) - 1, "(&(%s=%s)(objectclass=%s))", 
                  get_attr_key2string(dominfo_attr_list, LDAP_ATTR_DOMAIN), 
@@ -1217,6 +1220,30 @@ static NTSTATUS add_new_domain_info(struct smbldap_state *ldap_state,
        smbldap_set_mod(&mods, LDAP_MOD_ADD, get_attr_key2string(dominfo_attr_list, LDAP_ATTR_ALGORITHMIC_RID_BASE), 
                        algorithmic_rid_base_string);
        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectclass", LDAP_OBJ_DOMINFO);
+       
+       /* add the sambaNext[User|Group]Rid attributes if the idmap ranges are set.
+          TODO: fix all the places where the line between idmap and normal operations
+          needed by smbd gets fuzzy   --jerry 2003-08-11                              */
+       
+       if ( lp_idmap_uid(&u_low, &u_high) && lp_idmap_gid(&g_low, &g_high)
+               && get_free_rid_range(&rid_low, &rid_high) ) 
+       {
+               fstring rid_str;
+               
+               fstr_sprintf( rid_str, "%i", rid_high|USER_RID_TYPE );
+               DEBUG(10,("setting next available user rid [%s]\n", rid_str));
+               smbldap_set_mod(&mods, LDAP_MOD_ADD, 
+                       get_attr_key2string(dominfo_attr_list, LDAP_ATTR_NEXT_USERRID), 
+                       rid_str);
+                       
+               fstr_sprintf( rid_str, "%i", rid_high|GROUP_RID_TYPE );
+               DEBUG(10,("setting next available group rid [%s]\n", rid_str));
+               smbldap_set_mod(&mods, LDAP_MOD_ADD, 
+                       get_attr_key2string(dominfo_attr_list, LDAP_ATTR_NEXT_GROUPRID), 
+                       rid_str);
+               
+        }
+
 
        switch(ldap_op)
        {
index c0d0096806aa1c5c5a2eed919e0651673c0e1fa5..28466e43f29172b0586cae3ad0756b98eb78549e 100644 (file)
@@ -57,7 +57,7 @@ void set_local_machine_name(const char* local_name, BOOL perm)
        already_perm = perm;
 
        fstrcpy(tmp_local_machine,local_name);
-       trim_string(tmp_local_machine," "," ");
+       trim_char(tmp_local_machine,' ',' ');
        alpha_strcpy(local_machine,tmp_local_machine,SAFE_NETBIOS_CHARS,sizeof(local_machine)-1);
        strlower_m(local_machine);
 }
@@ -79,7 +79,7 @@ void set_remote_machine_name(const char* remote_name, BOOL perm)
        already_perm = perm;
 
        fstrcpy(tmp_remote_machine,remote_name);
-       trim_string(tmp_remote_machine," "," ");
+       trim_char(tmp_remote_machine,' ',' ');
        alpha_strcpy(remote_machine,tmp_remote_machine,SAFE_NETBIOS_CHARS,sizeof(remote_machine)-1);
        strlower_m(remote_machine);
 }
@@ -98,23 +98,36 @@ const char* get_local_machine_name(void)
        return local_machine;
 }
 
+/*******************************************************************
+ Setup the string used by %U substitution.
+********************************************************************/
 
-/*
-  setup the string used by %U substitution 
-*/
 void sub_set_smb_name(const char *name)
 {
        fstring tmp;
 
        /* don't let anonymous logins override the name */
-       if (! *name) return;
+       if (! *name)
+               return;
 
        fstrcpy(tmp,name);
-       trim_string(tmp," "," ");
+       trim_char(tmp,' ',' ');
        strlower_m(tmp);
        alpha_strcpy(smb_user_name,tmp,SAFE_NETBIOS_CHARS,sizeof(smb_user_name)-1);
 }
 
+/*******************************************************************
+ Setup the strings used by substitutions. Called per packet. Ensure
+ %U name is set correctly also.
+********************************************************************/
+
+void set_current_user_info(const userdom_struct *pcui)
+{
+       current_user_info = *pcui;
+       /* The following is safe as current_user_info.smb_name
+        * has already been sanitised in register_vuid. */
+       fstrcpy(smb_user_name, current_user_info.smb_name);
+}
 
 /*******************************************************************
  Given a pointer to a %$(NAME) expand it as an environment variable.
@@ -384,7 +397,7 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len)
                        string_sub(p,"%m", get_remote_machine_name(),l);
                        break;
                case 'v' :
-                       string_sub(p,"%v", VERSION,l);
+                       string_sub(p,"%v", SAMBA_VERSION_STRING,l);
                        break;
                case '$' :
                        p += expand_env_var(p,l);
@@ -539,7 +552,7 @@ char *alloc_sub_basic(const char *smb_name, const char *str)
                        t = realloc_string_sub(t, "%m", remote_machine);
                        break;
                case 'v' :
-                       t = realloc_string_sub(t, "%v", VERSION);
+                       t = realloc_string_sub(t, "%v", SAMBA_VERSION_STRING);
                        break;
                case '$' :
                        t = realloc_expand_env_var(t, p); /* Expand environment variables */
index a7024c852dfaa5cdfdc5e8d6b39b8d8839a3bbda..b020a20373054b8233fe4a09409598f4fe30b29b 100644 (file)
@@ -1263,6 +1263,16 @@ ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t si
 {
 #if defined(HAVE_GETXATTR)
        return getxattr(path, name, value, size);
+#elif defined(HAVE_ATTR_GET)
+       int retval, flags = 0;
+       int valuelength = (int)size;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+
+       return retval ? retval : valuelength;
 #else
        errno = ENOSYS;
        return -1;
@@ -1273,6 +1283,16 @@ ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t s
 {
 #if defined(HAVE_LGETXATTR)
        return lgetxattr(path, name, value, size);
+#elif defined(HAVE_ATTR_GET)
+       int retval, flags = ATTR_DONTFOLLOW;
+       int valuelength = (int)size;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+
+       return retval ? retval : valuelength;
 #else
        errno = ENOSYS;
        return -1;
@@ -1283,16 +1303,96 @@ ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
 {
 #if defined(HAVE_FGETXATTR)
        return fgetxattr(filedes, name, value, size);
+#elif defined(HAVE_ATTR_GETF)
+       int retval, flags = 0;
+       int valuelength = (int)size;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
+
+       return retval ? retval : valuelength;
 #else
        errno = ENOSYS;
        return -1;
 #endif
 }
 
+#if defined(HAVE_ATTR_LIST)
+static char attr_buffer[ATTR_MAX_VALUELEN];
+
+static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
+{
+       int retval = 0, index;
+       attrlist_cursor_t *cursor = 0;
+       int total_size = 0;
+       attrlist_t * al = (attrlist_t *)attr_buffer;
+       attrlist_ent_t *ae;
+       size_t ent_size, left = size;
+       char *bp = list;
+
+       while (True) {
+           if (filedes)
+               retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+           else
+               retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+           if (retval) break;
+           for (index = 0; index < al->al_count; index++) {
+               ae = ATTR_ENTRY(attr_buffer, index);
+               ent_size = strlen(ae->a_name) + sizeof("user.");
+               if (left >= ent_size) {
+                   strncpy(bp, "user.", sizeof("user."));
+                   strncat(bp, ae->a_name, ent_size - sizeof("user."));
+                   bp += ent_size;
+                   left -= ent_size;
+               } else if (size) {
+                   errno = ERANGE;
+                   retval = -1;
+                   break;
+               }
+               total_size += ent_size;
+           }
+           if (al->al_more == 0) break;
+       }
+       if (retval == 0) {
+           flags |= ATTR_ROOT;
+           cursor = 0;
+           while (True) {
+               if (filedes)
+                   retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+               else
+                   retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+               if (retval) break;
+               for (index = 0; index < al->al_count; index++) {
+                   ae = ATTR_ENTRY(attr_buffer, index);
+                   ent_size = strlen(ae->a_name) + sizeof("system.");
+                   if (left >= ent_size) {
+                       strncpy(bp, "system.", sizeof("system."));
+                       strncat(bp, ae->a_name, ent_size - sizeof("system."));
+                       bp += ent_size;
+                       left -= ent_size;
+                   } else if (size) {
+                       errno = ERANGE;
+                       retval = -1;
+                       break;
+                   }
+                   total_size += ent_size;
+               }
+               if (al->al_more == 0) break;
+           }
+       }
+       return (ssize_t)(retval ? retval : total_size);
+}
+
+#endif
+
 ssize_t sys_listxattr (const char *path, char *list, size_t size)
 {
 #if defined(HAVE_LISTXATTR)
        return listxattr(path, list, size);
+#elif defined(HAVE_ATTR_LIST)
+       return irix_attr_list(path, 0, list, size, 0);
 #else
        errno = ENOSYS;
        return -1;
@@ -1301,8 +1401,10 @@ ssize_t sys_listxattr (const char *path, char *list, size_t size)
 
 ssize_t sys_llistxattr (const char *path, char *list, size_t size)
 {
-#if defined(HAVE_GETXATTR)
+#if defined(HAVE_LLISTXATTR)
        return llistxattr(path, list, size);
+#elif defined(HAVE_ATTR_LIST)
+       return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
 #else
        errno = ENOSYS;
        return -1;
@@ -1313,6 +1415,8 @@ ssize_t sys_flistxattr (int filedes, char *list, size_t size)
 {
 #if defined(HAVE_FLISTXATTR)
        return flistxattr(filedes, list, size);
+#elif defined(HAVE_ATTR_LISTF)
+       return irix_attr_list(NULL, filedes, list, size, 0);
 #else
        errno = ENOSYS;
        return -1;
@@ -1323,6 +1427,13 @@ int sys_removexattr (const char *path, const char *name)
 {
 #if defined(HAVE_REMOVEXATTR)
        return removexattr(path, name);
+#elif defined(HAVE_ATTR_REMOVE)
+       int flags = 0;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       return attr_remove(path, attrname, flags);
 #else
        errno = ENOSYS;
        return -1;
@@ -1333,6 +1444,13 @@ int sys_lremovexattr (const char *path, const char *name)
 {
 #if defined(HAVE_LREMOVEXATTR)
        return lremovexattr(path, name);
+#elif defined(HAVE_ATTR_REMOVE)
+       int flags = ATTR_DONTFOLLOW;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       return attr_remove(path, attrname, flags);
 #else
        errno = ENOSYS;
        return -1;
@@ -1343,16 +1461,37 @@ int sys_fremovexattr (int filedes, const char *name)
 {
 #if defined(HAVE_FREMOVEXATTR)
        return fremovexattr(filedes, name);
+#elif defined(HAVE_ATTR_REMOVEF)
+       int flags = 0;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       return attr_removef(filedes, attrname, flags);
 #else
        errno = ENOSYS;
        return -1;
 #endif
 }
 
+#if !defined(HAVE_SETXATTR)
+#define XATTR_CREATE  0x1       /* set value, fail if attr already exists */
+#define XATTR_REPLACE 0x2       /* set value, fail if attr does not exist */
+#endif
+
 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
 {
 #if defined(HAVE_SETXATTR)
        return setxattr(path, name, value, size, flags);
+#elif defined(HAVE_ATTR_SET)
+       int myflags = 0;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+       return attr_set(path, attrname, (const char *)value, size, myflags);
 #else
        errno = ENOSYS;
        return -1;
@@ -1363,6 +1502,15 @@ int sys_lsetxattr (const char *path, const char *name, const void *value, size_t
 {
 #if defined(HAVE_LSETXATTR)
        return lsetxattr(path, name, value, size, flags);
+#elif defined(HAVE_ATTR_SET)
+       int myflags = ATTR_DONTFOLLOW;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+       return attr_set(path, attrname, (const char *)value, size, myflags);
 #else
        errno = ENOSYS;
        return -1;
@@ -1373,6 +1521,15 @@ int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size
 {
 #if defined(HAVE_FSETXATTR)
        return fsetxattr(filedes, name, value, size, flags);
+#elif defined(HAVE_ATTR_SETF)
+       int myflags = 0;
+       char *attrname = strchr(name,'.') +1;
+       
+       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+       return attr_setf(filedes, attrname, (const char *)value, size, myflags);
 #else
        errno = ENOSYS;
        return -1;
index eaa232a5494eb550ee012a6a0b233aa51486383e..766c5041b4e13ff241fa9c3cbc85aa996de9e7d3 100644 (file)
@@ -261,7 +261,7 @@ BOOL init_names(void)
        }                       
 
        fstrcpy( local_machine, global_myname() );
-       trim_string( local_machine, " ", " " );
+       trim_char( local_machine, ' ', ' ' );
        p = strchr( local_machine, ' ' );
        if (p)
                *p = 0;
@@ -311,7 +311,7 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, const gid_t *groups)
 
 static const char *Atoic(const char *p, int *n, const char *c)
 {
-       if (!isdigit((const int)*p)) {
+       if (!isdigit((int)*p)) {
                DEBUG(5, ("Atoic: malformed number\n"));
                return NULL;
        }
@@ -605,68 +605,6 @@ void unix_clean_name(char *s)
        trim_string(s,NULL,"/..");
 }
 
-/*******************************************************************
- Convert '\' to '/'.
- Reduce a file name, removing or reducing /../ , /./ , // elements.
- Remove also any trailing . and /
- Return a new allocated string.
-********************************************************************/
-
-smb_ucs2_t *unix_clean_path(const smb_ucs2_t *s)
-{
-       smb_ucs2_t *ns;
-       smb_ucs2_t *p, *r, *t;
-
-       DEBUG(3, ("unix_clean_path\n")); /*  [%unicode]\n")); */
-       if(!s)
-               return NULL;
-
-       /* convert '\' to '/' */
-       ns = strdup_w(s);
-       if (!ns)
-               return NULL;
-       unix_format_w(ns);
-
-       /* remove all double slashes */
-       p = ns;
-       ns = all_string_sub_wa(p, "//", "/");
-       SAFE_FREE(p);
-       if (!ns)
-               return NULL;
-
-       /* remove any /./ */
-       p = ns;
-       ns = all_string_sub_wa(p, "/./", "/");
-       SAFE_FREE(p);
-       if (!ns)
-               return NULL;
-
-       /* reduce any /../ */
-       t = ns;
-       while (*t && (r = strstr_wa(t, "/.."))) {
-               t = &(r[3]);
-               if (*t == UCS2_CHAR('/') || *t == 0) {
-                       *r = 0;
-                       p = strrchr_w(ns, UCS2_CHAR('/'));
-                       if (!p)
-                               p = ns;
-                       if (*t == 0)
-                               *p = 0;
-                       else
-                               memmove(p, t, (strlen_w(t) + 1) * sizeof(smb_ucs2_t));
-                       t = p;
-               }
-       }
-
-       /* remove any leading ./ trailing /. */
-       trim_string_wa(ns, "./", "/.");
-
-       /* remove any leading and trailing / */
-       trim_string_wa(ns, "/", "/");
-
-       return ns;
-}
-
 /****************************************************************************
  Make a dir struct.
 ****************************************************************************/
@@ -2205,7 +2143,7 @@ char *lock_path(const char *name)
        static pstring fname;
 
        pstrcpy(fname,lp_lockdir());
-       trim_string(fname,"","/");
+       trim_char(fname,'\0','/');
        
        if (!directory_exist(fname,NULL))
                mkdir(fname,0755);
@@ -2225,7 +2163,7 @@ char *pid_path(const char *name)
        static pstring fname;
 
        pstrcpy(fname,lp_piddir());
-       trim_string(fname,"","/");
+       trim_char(fname,'\0','/');
 
        if (!directory_exist(fname,NULL))
                mkdir(fname,0755);
@@ -2335,21 +2273,12 @@ BOOL ms_has_wild_w(const smb_ucs2_t *s)
 
 BOOL mask_match(const char *string, char *pattern, BOOL is_case_sensitive)
 {
-       fstring p2, s2;
-
        if (strcmp(string,"..") == 0)
                string = ".";
        if (strcmp(pattern,".") == 0)
                return False;
        
-       if (is_case_sensitive)
-               return ms_fnmatch(pattern, string, Protocol) == 0;
-
-       fstrcpy(p2, pattern);
-       fstrcpy(s2, string);
-       strlower_m(p2); 
-       strlower_m(s2);
-       return ms_fnmatch(p2, s2, Protocol) == 0;
+       return ms_fnmatch(pattern, string, Protocol, is_case_sensitive) == 0;
 }
 
 /*********************************************************
index 638a6ca3429161115b61dcddcdc3b2fb3ff05637..bd505ac921c37f0f89098da39677f4c646bf92e6 100644 (file)
 
 #include "includes.h"
 
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+
 static int gotalarm;
 
 /***************************************************************
index 00f14d7d26b059c12504e0f2c52a30e0d0e15967..fbb393770d5357179190798877d98c7feda8fd76 100644 (file)
@@ -93,7 +93,7 @@ static const struct {
        {SID_NAME_UNKNOWN, "UNKNOWN"},
        {SID_NAME_COMPUTER, "Computer"},
 
-       {0, NULL}
+       {(enum SID_NAME_USE)0, NULL}
 };
 
 const char *sid_type_lookup(uint32 sid_type) 
index 7569a39e6acf40b8911322886a70fec5f186546e..82b312e24150f1562d73dd001927609f68b56845 100644 (file)
@@ -37,7 +37,7 @@
  **/
 BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
 {
-       const char *s;
+       char *s;
        char *pbuf;
        BOOL quoted;
        size_t len=1;
@@ -45,7 +45,7 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
        if (!ptr)
                return(False);
 
-       s = *ptr;
+       s = (char *)*ptr;
 
        /* default to simple separators */
        if (!sep)
@@ -88,7 +88,7 @@ BOOL next_token_nr(const char **ptr,char *buff, const char *sep, size_t bufsize)
 {
        BOOL ret;
        if (!ptr)
-               ptr = (const char **)&last_ptr;
+               ptr = &last_ptr;
 
        ret = next_token(ptr, buff, sep, bufsize);
        last_ptr = *ptr;
@@ -109,7 +109,7 @@ void set_first_token(char *ptr)
 
 char **toktocliplist(int *ctok, const char *sep)
 {
-       char *s=last_ptr;
+       char *s=(char *)last_ptr;
        int ictok=0;
        char **ret, **iret;
 
@@ -132,7 +132,7 @@ char **toktocliplist(int *ctok, const char *sep)
        } while(*s);
        
        *ctok=ictok;
-       s=last_ptr;
+       s=(char *)last_ptr;
        
        if (!(ret=iret=malloc(ictok*sizeof(char *))))
                return NULL;
@@ -364,9 +364,27 @@ BOOL strisnormal(const char *s)
 
 void string_replace(pstring s,char oldc,char newc)
 {
-       push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
+       unsigned char *p;
+
+       /* this is quite a common operation, so we want it to be
+          fast. We optimise for the ascii case, knowing that all our
+          supported multi-byte character sets are ascii-compatible
+          (ie. they match for the first 128 chars) */
+
+       for (p = (unsigned char *)s; *p; p++) {
+               if (*p & 0x80) /* mb string - slow path. */
+                       break;
+               if (*p == oldc)
+                       *p = newc;
+       }
+
+       if (!*p)
+               return;
+
+       /* Slow (mb) path. */
+       push_ucs2(NULL, tmpbuf, p, sizeof(tmpbuf), STR_TERMINATE);
        string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
-       pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
+       pull_ucs2(NULL, p, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
 }
 
 /**
@@ -406,6 +424,59 @@ size_t str_ascii_charnum(const char *s)
        return strlen(tmpbuf2);
 }
 
+BOOL trim_char(char *s,char cfront,char cback)
+{
+       BOOL ret = False;
+       char *ep;
+       char *fp = s;
+
+       /* Ignore null or empty strings. */
+       if (!s || (s[0] == '\0'))
+               return False;
+
+       if (cfront) {
+               while (*fp && *fp == cfront)
+                       fp++;
+               if (!*fp) {
+                       /* We ate the string. */
+                       s[0] = '\0';
+                       return True;
+               }
+               if (fp != s)
+                       ret = True;
+       }
+
+       ep = fp + strlen(fp) - 1;
+       if (cback) {
+               /* Attempt ascii only. Bail for mb strings. */
+               while ((ep >= fp) && (*ep == cback)) {
+                       ret = True;
+                       if ((ep > fp) && (((unsigned char)ep[-1]) & 0x80)) {
+                               /* Could be mb... bail back to tim_string. */
+                               char fs[2], bs[2];
+                               if (cfront) {
+                                       fs[0] = cfront;
+                                       fs[1] = '\0';
+                               }
+                               bs[0] = cback;
+                               bs[1] = '\0';
+                               return trim_string(s, cfront ? fs : NULL, bs);
+                       } else {
+                               ep--;
+                       }
+               }
+               if (ep < fp) {
+                       /* We ate the string. */
+                       s[0] = '\0';
+                       return True;
+               }
+       }
+
+       ep[1] = '\0';
+       memmove(s, fp, ep-fp+2);
+       return ret;
+}
+
 /**
  Trim the specified elements off the front and back of a string.
 **/
@@ -428,7 +499,9 @@ BOOL trim_string(char *s,const char *front,const char *back)
 
        if (front_len) {
                while (len && strncmp(s, front, front_len)==0) {
-                       memcpy(s, s+front_len, (len-front_len)+1);
+                       /* Must use memmove here as src & dest can
+                        * easily overlap. Found by valgrind. JRA. */
+                       memmove(s, s+front_len, (len-front_len)+1);
                        len -= front_len;
                        ret=True;
                }
@@ -501,7 +574,9 @@ char *safe_strcpy_fn(const char *fn, int line, char *dest,const char *src, size_
                return NULL;
        }
 
+#ifdef DEVELOPER
        clobber_region(fn,line,dest, maxlength+1);
+#endif
 
        if (!src) {
                *dest = 0;
@@ -540,7 +615,9 @@ char *safe_strcat_fn(const char *fn, int line, char *dest, const char *src, size
        src_len = strnlen(src, maxlength + 1);
        dest_len = strnlen(dest, maxlength + 1);
 
+#ifdef DEVELOPER
        clobber_region(fn, line, dest + dest_len, maxlength + 1 - dest_len);
+#endif
 
        if (src_len + dest_len > maxlength) {
                DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n",
@@ -567,7 +644,9 @@ char *alpha_strcpy_fn(const char *fn, int line, char *dest, const char *src, con
 {
        size_t len, i;
 
+#ifdef DEVELOPER
        clobber_region(fn, line, dest, maxlength);
+#endif
 
        if (!dest) {
                DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
@@ -607,7 +686,9 @@ char *StrnCpy_fn(const char *fn, int line,char *dest,const char *src,size_t n)
 {
        char *d = dest;
 
+#ifdef DEVELOPER
        clobber_region(fn, line, dest, n+1);
+#endif
 
        if (!dest)
                return(NULL);
@@ -637,8 +718,9 @@ static char *strncpyn(char *dest, const char *src, size_t n, char c)
        char *p;
        size_t str_len;
 
+#ifdef DEVELOPER
        clobber_region(dest, n+1);
-
+#endif
        p = strchr_m(src, c);
        if (p == NULL) {
                DEBUG(5, ("strncpyn: separator character (%c) not found\n", c));
@@ -910,6 +992,7 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
        
        while ((p = strstr(s,pattern))) {
                if (ld > 0) {
+                       int offset = PTR_DIFF(s,string);
                        char *t = Realloc(string, ls + ld + 1);
                        if (!t) {
                                DEBUG(0, ("realloc_string_sub: out of memory!\n"));
@@ -917,7 +1000,7 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
                                return NULL;
                        }
                        string = t;
-                       p = t + (p - s);
+                       p = t + offset + (p - s);
                }
                if (li != lp) {
                        memmove(p+li,p+lp,strlen(p+lp)+1);
@@ -1098,6 +1181,19 @@ char *strchr_m(const char *s, char c)
        pstring s2;
        smb_ucs2_t *p;
 
+       /* this is quite a common operation, so we want it to be
+          fast. We optimise for the ascii case, knowing that all our
+          supported multi-byte character sets are ascii-compatible
+          (ie. they match for the first 128 chars) */
+
+       while (*s && (((unsigned char)s[0]) & 0x80)) {
+               if (*s == c)
+                       return s;
+       }
+
+       if (!*s)
+               return NULL;
+
        push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
        p = strchr_w(ws, UCS2_CHAR(c));
        if (!p)
@@ -1109,17 +1205,53 @@ char *strchr_m(const char *s, char c)
 
 char *strrchr_m(const char *s, char c)
 {
-       wpstring ws;
-       pstring s2;
-       smb_ucs2_t *p;
+       /* this is quite a common operation, so we want it to be
+          fast. We optimise for the ascii case, knowing that all our
+          supported multi-byte character sets are ascii-compatible
+          (ie. they match for the first 128 chars). Also, in Samba
+          we only search for ascii characters in 'c' and that
+          in all mb character sets with a compound character
+          containing c, if 'c' is not a match at position
+          p, then p[-1] > 0x7f. JRA. */
 
-       push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
-       p = strrchr_w(ws, UCS2_CHAR(c));
-       if (!p)
-               return NULL;
-       *p = 0;
-       pull_ucs2_pstring(s2, ws);
-       return (char *)(s+strlen(s2));
+       {
+               size_t len = strlen(s);
+               const char *cp = s;
+               BOOL got_mb = False;
+
+               if (len == 0)
+                       return NULL;
+               cp += (len - 1);
+               do {
+                       if (c == *cp) {
+                               /* Could be a match. Part of a multibyte ? */
+                               if ((cp > s) && (((unsigned char)cp[-1]) & 0x80)) {
+                                       /* Yep - go slow :-( */
+                                       got_mb = True;
+                                       break;
+                               }
+                               /* No - we have a match ! */
+                               return cp;
+                       }
+               } while (cp-- != s);
+               if (!got_mb)
+                       return NULL;
+       }
+
+       /* String contained a non-ascii char. Slow path. */
+       {
+               wpstring ws;
+               pstring s2;
+               smb_ucs2_t *p;
+
+               push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
+               p = strrchr_w(ws, UCS2_CHAR(c));
+               if (!p)
+                       return NULL;
+               *p = 0;
+               pull_ucs2_pstring(s2, ws);
+               return (char *)(s+strlen(s2));
+       }
 }
 
 /***********************************************************************
@@ -1409,6 +1541,35 @@ void str_list_free(char ***list)
        SAFE_FREE(*list);
 }
 
+/******************************************************************************
+ version of standard_sub_basic() for string lists; uses alloc_sub_basic() 
+ for the work
+ *****************************************************************************/
+BOOL str_list_sub_basic( char **list, const char *smb_name )
+{
+       char *s, *tmpstr;
+       
+       while ( *list ) {
+               s = *list;
+               tmpstr = alloc_sub_basic(smb_name, s);
+               if ( !tmpstr ) {
+                       DEBUG(0,("str_list_sub_basic: alloc_sub_basic() return NULL!\n"));
+                       return False;
+               }
+
+               *list = tmpstr;
+                       
+               list++;
+       }
+
+       return True;
+}
+
+/******************************************************************************
+ substritute a specific pattern in a string list
+ *****************************************************************************/
 BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
 {
        char *p, *s, *t;
@@ -1464,6 +1625,7 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
                        }       
                }
                
+               
                list++;
        }
        
diff --git a/source3/lib/version.c b/source3/lib/version.c
new file mode 100644 (file)
index 0000000..99f836c
--- /dev/null
@@ -0,0 +1,42 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba Version functions
+   
+   Copyright (C) Stefan Metzmacher     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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#include "includes.h"
+
+const char *samba_version_string(void)
+{
+#ifndef SAMBA_VERSION_VENDOR_SUFFIX
+       return SAMBA_VERSION_OFFICIAL_STRING;
+#else
+       static fstring samba_version;
+       static BOOL init_samba_version;
+
+       if (init_samba_version)
+               return samba_version;
+
+       snprintf(samba_version,sizeof(samba_version),"%s-%s",
+               SAMBA_VERSION_OFFICIAL_STRING,
+               SAMBA_VERSION_VENDOR_SUFFIX);
+
+       init_samba_version = True;
+       return samba_version;
+#endif
+}
index 80fdb99eac0567f068c205723788020c3446b868..11f9d66b92df386d618d4b1ccc59ed46475b4313 100644 (file)
@@ -87,7 +87,7 @@ NTSTATUS ads_ntstatus(ADS_STATUS status)
 */
 const char *ads_errstr(ADS_STATUS status)
 {
-       int msg_ctx;
+       uint32 msg_ctx;
        static char *ret;
 
        SAFE_FREE(ret);
index 50a9ef271893efdc7f6f50cd949e3c32801a610b..29170af377e00de50e88df04334d570accf73b39 100644 (file)
@@ -39,6 +39,7 @@ static DATA_BLOB unwrap_pac(DATA_BLOB *auth_data)
        asn1_end_tag(&data);
        asn1_end_tag(&data);
        asn1_end_tag(&data);
+       asn1_free(&data);
        return pac_contents;
 }
 
@@ -422,7 +423,7 @@ static BOOL pac_io_pac_signature_data(const char *desc,
        if (!prs_uint32("type", ps, depth, &data->type))
                return False;
        if (UNMARSHALLING(ps)) {
-               data->signature = prs_alloc_mem(ps, siglen);
+               data->signature = (unsigned char *)prs_alloc_mem(ps, siglen);
                if (!data->signature) {
                        DEBUG(3, ("No memory available\n"));
                        return False;
@@ -600,9 +601,11 @@ PAC_DATA *decode_pac_data(DATA_BLOB *auth_data, TALLOC_CTX *ctx)
 
        DEBUG(5,("dump_pac_data\n"));
        prs_init(&ps, pac_data_blob.length, ctx, UNMARSHALL);
-       prs_copy_data_in(&ps, pac_data_blob.data, pac_data_blob.length);
+       prs_copy_data_in(&ps, (char *)pac_data_blob.data, pac_data_blob.length);
        prs_set_offset(&ps, 0);
 
+       data_blob_free(&pac_data_blob);
+
        pac_data = (PAC_DATA *) talloc_zero(ctx, sizeof(PAC_DATA));
        pac_io_pac_data("pac data", pac_data, &ps, 0);
 
index 48b61cd1f2d054e9f4e89b9a9a508d248cc29ff2..4ae89aa01f3fdef53b4936d970e05a28720ed8ea 100644 (file)
@@ -4,6 +4,8 @@
    Copyright (C) Andrew Tridgell 2001
    Copyright (C) Remus Koos 2001
    Copyright (C) Luke Howard 2003   
+   Copyright (C) Guenther Deschner 2003
+   Copyright (C) Jim McDonough (jmcd@us.ibm.com) 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
 
 #ifdef HAVE_KRB5
 
+static void free_keytab(krb5_context context, krb5_keytab keytab)
+{
+       int ret=0;
+       
+       if (keytab) 
+               ret = krb5_kt_close(context, keytab);
+       if (ret) {
+               DEBUG(3, ("krb5_kt_close failed (%s)\n",
+                         error_message(ret)));
+       }
+}
+
+#ifdef HAVE_MEMORY_KEYTAB
+static krb5_error_code create_keytab(krb5_context context,
+                                    krb5_principal host_princ,
+                                    char *host_princ_s,
+                                    krb5_data password,
+                                    krb5_enctype *enctypes,
+                                    krb5_keytab *keytab,
+                                    char *keytab_name)
+{
+       krb5_keytab_entry entry;
+       krb5_kvno kvno = 1;
+       krb5_error_code ret;
+       krb5_keyblock *key;
+       int i;
+
+       DEBUG(10,("creating keytab: %s\n", keytab_name));
+       ret = krb5_kt_resolve(context, keytab_name, keytab);
+       if (ret) 
+               return ret;
+
+       if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) {
+               return ENOMEM;
+       }
+       
+       /* add keytab entries for all encryption types */
+       for ( i=0; enctypes[i]; i++ ) {
+               
+               if (create_kerberos_key_from_string(context, host_princ, &password, key, enctypes[i])) {
+                       continue;
+               }
+
+               entry.principal = host_princ;
+               entry.vno       = kvno;
+               /* this will have to be detected in configure...heimdal
+                  calls it keyblock, MIT calls it key, but it does not
+                  matter we are creating keytabs with MIT */
+               entry.keyblock  = *key;
+
+               DEBUG(10,("adding keytab-entry for (%s) with encryption type (%d)\n",
+                               host_princ_s, enctypes[i]));
+               ret = krb5_kt_add_entry(context, *keytab, &entry);
+               if (ret) {
+                       DEBUG(1,("adding entry to keytab failed (%s)\n", 
+                                error_message(ret)));
+                       free_keytab(context, *keytab);
+                       return ret;
+               }
+       }
+       krb5_free_keyblock(context, key);
+       
+       return 0;
+}
+#endif
+
+static BOOL setup_keytab(krb5_context context,
+                        krb5_principal host_princ,
+                        char *host_princ_s,
+                        krb5_data password,
+                        krb5_enctype *enctypes,
+                        krb5_keytab *keytab)
+{
+       char *keytab_name = NULL;
+       krb5_error_code ret;
+
+       /* check if we have to setup a keytab - not currently enabled
+          I've put this in so that the else block below functions 
+          the same way that it will when this code is turned on */
+       if (0 /* will later be *lp_keytab() */) {
+
+               /* use a file-keytab */
+               asprintf(&keytab_name, "%s:%s", 
+                        "" 
+                        /* KRB5_KT_FILE_PREFIX, "FILE" or 
+                           "WRFILE" depending on HEeimdal or MIT */, 
+                        "" /* will later be lp_keytab() */);
+
+               DEBUG(10,("will use filebased keytab: %s\n", keytab_name));
+               ret = krb5_kt_resolve(context, keytab_name, keytab);
+               if (ret) {
+                       DEBUG(3,("cannot resolve keytab name %s (%s)\n",
+                                keytab_name, 
+                                error_message(ret)));
+                       SAFE_FREE(keytab_name);
+                       return False;
+               }
+
+       }
+
+#if defined(HAVE_MEMORY_KEYTAB)
+       else {
+
+               /* setup a in-memory-keytab */
+               asprintf(&keytab_name, "MEMORY:");
+
+               ret = create_keytab(context, host_princ, host_princ_s, password, enctypes, 
+                       keytab, keytab_name);
+               if (ret) {
+                       DEBUG(3,("unable to create MEMORY: keytab (%s)\n",
+                                error_message(ret)));
+                       SAFE_FREE(keytab_name);
+                       return False;
+               }
+       }
+#endif
+       SAFE_FREE(keytab_name);
+       return True;
+}
+       
+
 /*
   verify an incoming ticket and parse out the principal name and 
   authorization_data if available 
 */
-NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, 
+NTSTATUS ads_verify_ticket(const char *realm, const DATA_BLOB *ticket, 
                           char **principal, DATA_BLOB *auth_data,
                           DATA_BLOB *ap_rep,
                           uint8 session_key[16])
@@ -79,7 +202,7 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket,
                return NT_STATUS_LOGON_FAILURE;
        }
 
-       ret = krb5_set_default_realm(context, ads->auth.realm);
+       ret = krb5_set_default_realm(context, realm);
        if (ret) {
                DEBUG(1,("ads_verify_ticket: krb5_set_default_realm failed (%s)\n", error_message(ret)));
                sret = NT_STATUS_LOGON_FAILURE;
@@ -128,11 +251,6 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket,
 
        /* CIFS doesn't use addresses in tickets. This would breat NAT. JRA */
 
-       if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) {
-               sret = NT_STATUS_NO_MEMORY;
-               goto out;
-       }
-       
        if ((ret = get_kerberos_allowed_etypes(context, &enctypes))) {
                DEBUG(1,("ads_verify_ticket: krb5_get_permitted_enctypes failed (%s)\n", 
                         error_message(ret)));
@@ -149,22 +267,40 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket,
                goto out;
        }
 
+       if (!setup_keytab(context, host_princ, host_princ_s, password,
+                         enctypes, &keytab)) {
+               DEBUG(3,("ads_verify_ticket: unable to setup keytab\n"));
+               sret = NT_STATUS_LOGON_FAILURE;
+               goto out;
+       }
+       
        /* We need to setup a auth context with each possible encoding type in turn. */
        for (i=0;enctypes[i];i++) {
+               if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) {
+                       sret = NT_STATUS_NO_MEMORY;
+                       goto out;
+               }
+       
                if (create_kerberos_key_from_string(context, host_princ, &password, key, enctypes[i])) {
                        continue;
                }
 
                krb5_auth_con_setuseruserkey(context, auth_context, key);
 
+               krb5_free_keyblock(context, key);
+
                packet.length = ticket->length;
                packet.data = (krb5_pointer)ticket->data;
 
                if (!(ret = krb5_rd_req(context, &auth_context, &packet, 
-                                      NULL, keytab, NULL, &tkt))) {
+#ifdef HAVE_MEMORY_KEYTAB
+                                       host_princ, 
+#else
+                                       NULL,
+#endif
+                                       keytab, NULL, &tkt))) {
                        DEBUG(10,("ads_verify_ticket: enc type [%u] decrypted message !\n",
                                (unsigned int)enctypes[i] ));
-                       free_kerberos_etypes(context, enctypes);
                        auth_ok = True;
                        break;
                }
@@ -217,8 +353,13 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket,
                file_save("/tmp/authdata.dat",
                          tkt->enc_part2->authorization_data[0]->contents,
                          tkt->enc_part2->authorization_data[0]->length);
+       }
 #endif
 
+               
+       /* get rid of all resources associated with the keytab */
+       if (keytab) free_keytab(context, keytab);
+               
        if ((ret = krb5_unparse_name(context, get_principal_from_tkt(tkt),
                                     principal))) {
                DEBUG(3,("ads_verify_ticket: krb5_unparse_name failed (%s)\n", 
@@ -237,8 +378,12 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket,
        if (!NT_STATUS_IS_OK(sret))
                data_blob_free(ap_rep);
 
-       SAFE_FREE(host_princ_s);
+       krb5_free_principal(context, host_princ);
+       if (tkt != NULL)
+               krb5_free_ticket(context, tkt);
+       free_kerberos_etypes(context, enctypes);
        SAFE_FREE(password_s);
+       SAFE_FREE(host_princ_s);
 
        if (auth_context)
                krb5_auth_con_free(context, auth_context);
index 80ef6cdf01c55d623d8783e9a7044aa045c25493..9cf15221a8dd2417ca96415c300d4bdccdd5075f 100644 (file)
@@ -143,7 +143,7 @@ static krb5_error_code build_kpasswd_request(uint16 pversion,
        else
                return EINVAL;
 
-       encoded_setpw.data = setpw.data;
+       encoded_setpw.data = (char *)setpw.data;
        encoded_setpw.length = setpw.length;
 
        ret = krb5_mk_priv(context, auth_context,
@@ -664,25 +664,22 @@ ADS_STATUS kerberos_set_password(const char *kpasswd_server,
  * @return status of password change
  **/
 ADS_STATUS ads_set_machine_password(ADS_STRUCT *ads,
-                                   const char *hostname, 
+                                   const char *machine_account,
                                    const char *password)
 {
        ADS_STATUS status;
-       char *host = strdup(hostname);
-       char *principal; 
-
-       strlower_m(host);
+       char *principal = NULL; 
 
        /*
-         we need to use the '$' form of the name here, as otherwise the
-         server might end up setting the password for a user instead
+         we need to use the '$' form of the name here (the machine account name), 
+         as otherwise the server might end up setting the password for a user
+         instead
         */
-       asprintf(&principal, "%s$@%s", host, ads->config.realm);
+       asprintf(&principal, "%s@%s", machine_account, ads->config.realm);
        
        status = ads_krb5_set_password(ads->auth.kdc_server, principal, 
                                       password, ads->auth.time_offset);
        
-       free(host);
        free(principal);
 
        return status;
index 5a12288b167308247d16f23397d5aee891f108d5..e925750e0a05c922dfa322c210cb093e0ff0ba22 100644 (file)
@@ -1045,7 +1045,7 @@ static ADS_STATUS ads_add_machine_acct(ADS_STRUCT *ads, const char *hostname,
        ads_mod_str(ctx, &mods, "dNSHostName", hostname);
        ads_mod_str(ctx, &mods, "userAccountControl", controlstr);
        ads_mod_str(ctx, &mods, "operatingSystem", "Samba");
-       ads_mod_str(ctx, &mods, "operatingSystemVersion", VERSION);
+       ads_mod_str(ctx, &mods, "operatingSystemVersion", SAMBA_VERSION_STRING);
 
        ret = ads_gen_add(ads, new_dn, mods);
 
@@ -1777,7 +1777,7 @@ ADS_STATUS ads_USN(ADS_STRUCT *ads, uint32 *usn)
        ADS_STATUS status;
        void *res;
 
-       status = ads_do_search(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res);
+       status = ads_do_search_retry(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res);
        if (!ADS_ERR_OK(status)) return status;
 
        if (ads_count_replies(ads, res) != 1) {
@@ -1900,7 +1900,7 @@ ADS_STATUS ads_domain_sid(ADS_STRUCT *ads, DOM_SID *sid)
        void *res;
        ADS_STATUS rc;
 
-       rc = ads_do_search(ads, ads->config.bind_path, LDAP_SCOPE_BASE, "(objectclass=*)", 
+       rc = ads_do_search_retry(ads, ads->config.bind_path, LDAP_SCOPE_BASE, "(objectclass=*)", 
                           attrs, &res);
        if (!ADS_ERR_OK(rc)) return rc;
        if (!ads_pull_sid(ads, res, "objectSid", sid)) {
index 68556002880ec3e1bebede1ebdecb41fdf1b86f8..1fa9ebfc975e9fce943cb37aa3c4d33dcd924975 100644 (file)
@@ -73,7 +73,10 @@ ADS_STATUS ads_do_search_retry(ADS_STRUCT *ads, const char *bind_path, int scope
        }
        free(bp);
 
-       DEBUG(1,("ads reopen failed after error %s\n", ads_errstr(status)));
+       if (!ADS_ERR_OK(status))
+               DEBUG(1,("ads reopen failed after error %s\n", 
+                        ads_errstr(status)));
+
        return status;
 }
 
index 910ff3f4dc6682e1fcdcc619b43ec4796a859e5f..51228035974b1036bb1c8486c6edf4ebff5ea1a5 100644 (file)
@@ -60,7 +60,7 @@ static ADS_STATUS ads_sasl_spnego_ntlmssp_bind(ADS_STRUCT *ads)
        msg1 = gen_negTokenTarg(mechs, blob);
        data_blob_free(&blob);
 
-       cred.bv_val = msg1.data;
+       cred.bv_val = (char *)msg1.data;
        cred.bv_len = msg1.length;
 
        rc = ldap_sasl_bind_s(ads->ld, NULL, "GSS-SPNEGO", &cred, NULL, NULL, &scred);
@@ -106,7 +106,7 @@ static ADS_STATUS ads_sasl_spnego_ntlmssp_bind(ADS_STRUCT *ads)
        data_blob_free(&blob);
 
        /* now send the auth packet and we should be done */
-       cred.bv_val = auth.data;
+       cred.bv_val = (char *)auth.data;
        cred.bv_len = auth.length;
 
        rc = ldap_sasl_bind_s(ads->ld, NULL, "GSS-SPNEGO", &cred, NULL, NULL, &scred);
@@ -134,7 +134,7 @@ static ADS_STATUS ads_sasl_spnego_krb5_bind(ADS_STRUCT *ads, const char *princip
        }
 
        /* now send the auth packet and we should be done */
-       cred.bv_val = blob.data;
+       cred.bv_val = (char *)blob.data;
        cred.bv_len = blob.length;
 
        rc = ldap_sasl_bind_s(ads->ld, NULL, "GSS-SPNEGO", &cred, NULL, NULL, &scred);
@@ -227,13 +227,13 @@ failed:
 */
 static ADS_STATUS ads_sasl_gssapi_bind(ADS_STRUCT *ads)
 {
-       int minor_status;
+       uint32 minor_status;
        gss_name_t serv_name;
        gss_buffer_desc input_name;
        gss_ctx_id_t context_handle;
        gss_OID mech_type = GSS_C_NULL_OID;
        gss_buffer_desc output_token, input_token;
-       OM_uint32 ret_flags, conf_state;
+       uint32 ret_flags, conf_state;
        struct berval cred;
        struct berval *scred;
        int i=0;
@@ -328,7 +328,7 @@ static ADS_STATUS ads_sasl_gssapi_bind(ADS_STRUCT *ads)
        gss_release_name(&minor_status, &serv_name);
 
        gss_rc = gss_unwrap(&minor_status,context_handle,&input_token,&output_token,
-                           &conf_state,NULL);
+                           (int *)&conf_state,NULL);
        if (gss_rc) {
                status = ADS_ERROR_GSS(gss_rc, minor_status);
                goto failed;
@@ -353,13 +353,13 @@ static ADS_STATUS ads_sasl_gssapi_bind(ADS_STRUCT *ads)
        *p++ = max_msg_size>>16;
        *p++ = max_msg_size>>8;
        *p++ = max_msg_size;
-       snprintf(p, strlen(ads->config.bind_path)+4, "dn:%s", ads->config.bind_path);
-       p += strlen(p);
+       snprintf((char *)p, strlen(ads->config.bind_path)+4, "dn:%s", ads->config.bind_path);
+       p += strlen((const char *)p);
 
        output_token.length = PTR_DIFF(p, output_token.value);
 
        gss_rc = gss_wrap(&minor_status, context_handle,0,GSS_C_QOP_DEFAULT,
-                         &output_token, &conf_state,
+                         &output_token, (int *)&conf_state,
                          &input_token);
        if (gss_rc) {
                status = ADS_ERROR_GSS(gss_rc, minor_status);
index 94fe04a480d081db48e1e9b81bacaba275920cf1..48bcb61f9266111daa5a1ab310d1e63fa781d4a8 100644 (file)
@@ -190,7 +190,7 @@ static BOOL cli_session_setup_plaintext(struct cli_state *cli, const char *user,
        char *p;
        fstring lanman;
        
-       fstr_sprintf( lanman, "Samba %s", VERSION );
+       fstr_sprintf( lanman, "Samba %s", SAMBA_VERSION_STRING);
 
        set_message(cli->outbuf,13,0,True);
        SCVAL(cli->outbuf,smb_com,SMBsesssetupX);
@@ -247,7 +247,8 @@ static void set_cli_session_key (struct cli_state *cli, DATA_BLOB session_key)
 }
 
 /****************************************************************************
-   do a NT1 NTLM/LM encrypted session setup
+   do a NT1 NTLM/LM encrypted session setup - for when extended security
+   is not negotiated.
    @param cli client state to create do session setup on
    @param user username
    @param pass *either* cleartext password (passlen !=24) or LM response.
@@ -267,7 +268,9 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, const char *user,
        BOOL ret = False;
        char *p;
 
-       if (passlen != 24) {
+       if (passlen == 0) {
+               /* do nothing - guest login */
+       } else if (passlen != 24) {
                if (lp_client_ntlmv2_auth()) {
                        DATA_BLOB server_chal;
                        DATA_BLOB names_blob;
@@ -351,7 +354,7 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, const char *user,
                goto end;
        }
 
-       show_msg(cli->inbuf);
+       /* show_msg(cli->inbuf); */
 
        if (cli_is_error(cli)) {
                ret = False;
@@ -610,6 +613,7 @@ static BOOL cli_session_setup_ntlmssp(struct cli_state *cli, const char *user,
        } while (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED));
 
        if (NT_STATUS_IS_OK(nt_status)) {
+               fstrcpy(cli->server_domain, ntlmssp_state->server_domain);
                set_cli_session_key(cli, ntlmssp_state->session_key);
        }
 
@@ -619,7 +623,7 @@ static BOOL cli_session_setup_ntlmssp(struct cli_state *cli, const char *user,
        if (!NT_STATUS_IS_OK(ntlmssp_client_end(&ntlmssp_state))) {
                return False;
        }
-
+       
        return (NT_STATUS_IS_OK(nt_status));
 }
 
@@ -627,8 +631,8 @@ static BOOL cli_session_setup_ntlmssp(struct cli_state *cli, const char *user,
  Do a spnego encrypted session setup.
 ****************************************************************************/
 
-static BOOL cli_session_setup_spnego(struct cli_state *cli, const char *user, 
-                                    const char *pass, const char *workgroup)
+BOOL cli_session_setup_spnego(struct cli_state *cli, const char *user, 
+                             const char *pass, const char *workgroup)
 {
        char *principal;
        char *OIDs[ASN1_MAX_OIDS];
@@ -677,7 +681,7 @@ static BOOL cli_session_setup_spnego(struct cli_state *cli, const char *user,
         * and do not store results */
 
        if (got_kerberos_mechanism && cli->use_kerberos) {
-               if (*pass) {
+               if (pass && *pass) {
                        int ret;
                        
                        use_in_memory_ccache();
@@ -1024,22 +1028,27 @@ BOOL cli_negprot(struct cli_state *cli)
                                    smb_buflen(cli->inbuf)-8, STR_UNICODE|STR_NOALIGN);
                }
 
-               if ((cli->sec_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED)) {
-                       /* Fail if signing is mandatory and we don't want to support it. */
+               /*
+                * As signing is slow we only turn it on if either the client or
+                * the server require it. JRA.
+                */
+
+               if (cli->sec_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED) {
+                       /* Fail if server says signing is mandatory and we don't want to support it. */
                        if (!cli->sign_info.allow_smb_signing) {
                                DEBUG(1,("cli_negprot: SMB signing is mandatory and we have disabled it.\n"));
                                return False;
                        }
                        cli->sign_info.negotiated_smb_signing = True;
-               }
-
-               if ((cli->sec_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) && cli->sign_info.allow_smb_signing)
+                       cli->sign_info.mandatory_signing = True;
+               } else if (cli->sign_info.mandatory_signing && cli->sign_info.allow_smb_signing) {
+                       /* Fail if client says signing is mandatory and the server doesn't support it. */
+                       if (!(cli->sec_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED)) {
+                               DEBUG(1,("cli_negprot: SMB signing is mandatory and the server doesn't support it.\n"));
+                               return False;
+                       }
                        cli->sign_info.negotiated_smb_signing = True;
-
-               /* Fail if signing is mandatory and the server doesn't support it. */
-               if (cli->sign_info.mandatory_signing && !(cli->sign_info.negotiated_smb_signing)) {
-                       DEBUG(1,("cli_negprot: SMB signing is mandatory and the server doesn't support it.\n"));
-                       return False;
+                       cli->sign_info.mandatory_signing = True;
                }
 
        } else if (cli->protocol >= PROTOCOL_LANMAN1) {
@@ -1223,7 +1232,7 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
  Initialise client credentials for authenticated pipe access.
 ****************************************************************************/
 
-static void init_creds(struct ntuser_creds *creds, const char* username,
+void init_creds(struct ntuser_creds *creds, const char* username,
                       const char* domain, const char* password)
 {
        ZERO_STRUCTP(creds);
@@ -1239,30 +1248,21 @@ static void init_creds(struct ntuser_creds *creds, const char* username,
 }
 
 /**
-   establishes a connection right up to doing tconX, password specified.
+   establishes a connection to after the negprot. 
    @param output_cli A fully initialised cli structure, non-null only on success
    @param dest_host The netbios name of the remote host
    @param dest_ip (optional) The the destination IP, NULL for name based lookup
    @param port (optional) The destination port (0 for default)
-   @param service (optional) The share to make the connection to.  Should be 'unqualified' in any way.
-   @param service_type The 'type' of serivice. 
-   @param user Username, unix string
-   @param domain User's domain
-   @param password User's password, unencrypted unix string.
    @param retry BOOL. Did this connection fail with a retryable error ?
-*/
 
-NTSTATUS cli_full_connection(struct cli_state **output_cli, 
-                            const char *my_name, 
-                            const char *dest_host, 
-                            struct in_addr *dest_ip, int port,
-                            const char *service, const char *service_type,
-                            const char *user, const char *domain, 
-                            const char *password, int flags,
-                            int signing_state,
-                            BOOL *retry) 
+*/
+NTSTATUS cli_start_connection(struct cli_state **output_cli, 
+                             const char *my_name, 
+                             const char *dest_host, 
+                             struct in_addr *dest_ip, int port,
+                             int signing_state, int flags,
+                             BOOL *retry) 
 {
-       struct ntuser_creds creds;
        NTSTATUS nt_status;
        struct nmb_name calling;
        struct nmb_name called;
@@ -1295,7 +1295,7 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
 
 again:
 
-       DEBUG(3,("Connecting to host=%s share=%s\n", dest_host, service));
+       DEBUG(3,("Connecting to host=%s\n", dest_host));
        
        if (!cli_connect(cli, dest_host, &ip)) {
                DEBUG(1,("cli_full_connection: failed to connect to %s (%s)\n",
@@ -1336,6 +1336,46 @@ again:
                return nt_status;
        }
 
+       *output_cli = cli;
+       return NT_STATUS_OK;
+}
+
+
+/**
+   establishes a connection right up to doing tconX, password specified.
+   @param output_cli A fully initialised cli structure, non-null only on success
+   @param dest_host The netbios name of the remote host
+   @param dest_ip (optional) The the destination IP, NULL for name based lookup
+   @param port (optional) The destination port (0 for default)
+   @param service (optional) The share to make the connection to.  Should be 'unqualified' in any way.
+   @param service_type The 'type' of serivice. 
+   @param user Username, unix string
+   @param domain User's domain
+   @param password User's password, unencrypted unix string.
+   @param retry BOOL. Did this connection fail with a retryable error ?
+*/
+
+NTSTATUS cli_full_connection(struct cli_state **output_cli, 
+                            const char *my_name, 
+                            const char *dest_host, 
+                            struct in_addr *dest_ip, int port,
+                            const char *service, const char *service_type,
+                            const char *user, const char *domain, 
+                            const char *password, int flags,
+                            int signing_state,
+                            BOOL *retry) 
+{
+       struct ntuser_creds creds;
+       NTSTATUS nt_status;
+       struct cli_state *cli = NULL;
+
+       nt_status = cli_start_connection(&cli, my_name, dest_host, 
+                                        dest_ip, port, signing_state, flags, retry);
+       
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               return nt_status;
+       }
+
        if (!cli_session_setup(cli, user, password, strlen(password)+1, 
                               password, strlen(password)+1, 
                               domain)) {
index bc5f1462cc248bfaf1039142bab8f96852812412..0a134f715dcbd6e4276468441e0877d4b2f7fbc9 100644 (file)
@@ -299,9 +299,12 @@ struct cli_state *cli_initialise(struct cli_state *cli)
        memset(cli->outbuf, 0, cli->bufsize);
        memset(cli->inbuf, 0, cli->bufsize);
 
+
+#if defined(DEVELOPER)
        /* just because we over-allocate, doesn't mean it's right to use it */
        clobber_region(FUNCTION_MACRO, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN);
        clobber_region(FUNCTION_MACRO, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN);
+#endif
 
        /* initialise signing */
        cli_null_set_signing(cli);
@@ -339,7 +342,9 @@ void cli_nt_session_close(struct cli_state *cli)
                ntlmssp_client_end(&cli->ntlmssp_pipe_state);
        }
 
-       cli_close(cli, cli->nt_pipe_fnum);
+       if (cli->nt_pipe_fnum != 0)
+               cli_close(cli, cli->nt_pipe_fnum);
+
        cli->nt_pipe_fnum = 0;
        cli->pipe_idx = -1;
 }
index f021076a46cdc9339de59c8cf9c1e01da4b9a671..c7f0cdb84b587325a916686f7e90b5dd3040e539 100644 (file)
@@ -951,8 +951,9 @@ BOOL cli_chkpath(struct cli_state *cli, const char *path)
        char *p;
        
        pstrcpy(path2,path);
-       trim_string(path2,NULL,"\\");
-       if (!*path2) *path2 = '\\';
+       trim_char(path2,'\0','\\');
+       if (!*path2)
+               *path2 = '\\';
        
        memset(cli->outbuf,'\0',smb_size);
        set_message(cli->outbuf,0,0,True);
index beac8cb2c1d3f18f17e99e4e060fbd456258a8a2..1fccc04a013b34107af999280bd0d6536a574afe 100644 (file)
@@ -74,7 +74,7 @@
 {
        pkaddr->addrtype = ADDRTYPE_INET;
        pkaddr->length = sizeof(((struct sockaddr_in *)paddr)->sin_addr);
-       pkaddr->contents = (char *)&(((struct sockaddr_in *)paddr)->sin_addr);
+       pkaddr->contents = (krb5_octet *)&(((struct sockaddr_in *)paddr)->sin_addr);
 }
 #else
  __ERROR__XX__UNKNOWN_ADDRTYPE
@@ -97,7 +97,9 @@
                return ret;
        }
        krb5_use_enctype(context, &eblock, enctype);
-       return krb5_string_to_key(context, &eblock, key, password, &salt);
+       ret = krb5_string_to_key(context, &eblock, key, password, &salt);
+       SAFE_FREE(salt.data);
+       return ret;
 }
 #elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT)
  int create_kerberos_key_from_string(krb5_context context,
@@ -369,29 +371,27 @@ failed:
 
  BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16], BOOL remote)
  {
-#ifdef ENCTYPE_ARCFOUR_HMAC
        krb5_keyblock *skey;
-#endif
-       BOOL ret = False;
        krb5_error_code err;
+       BOOL ret = False;
 
        memset(session_key, 0, 16);
 
-#ifdef ENCTYPE_ARCFOUR_HMAC
        if (remote)
                err = krb5_auth_con_getremotesubkey(context, auth_context, &skey);
        else
                err = krb5_auth_con_getlocalsubkey(context, auth_context, &skey);
        if (err == 0 && skey != NULL) {
-               if (KRB5_KEY_TYPE(skey) ==
-                   ENCTYPE_ARCFOUR_HMAC
-                   && KRB5_KEY_LENGTH(skey) == 16) {
+               DEBUG(10, ("Got KRB5 session key of length %d\n",  KRB5_KEY_LENGTH(skey)));
+               if (KRB5_KEY_LENGTH(skey) == 16) {
                        memcpy(session_key, KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey));
+                       dump_data_pw("KRB5 Session Key:\n", session_key, 16);
                        ret = True;
                }
                krb5_free_keyblock(context, skey);
+       } else {
+               DEBUG(10, ("KRB5 error getting session key %d\n", err));
        }
-#endif /* ENCTYPE_ARCFOUR_HMAC */
 
        return ret;
  }
index 8ce8416487a8e15ef6ff229a4210fd15ee33dc61..035088212c7a40e109f0be56aebddfd6d512a12b 100644 (file)
@@ -87,7 +87,7 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
        p = smb_buf(cli->outbuf);
        *p++ = 1;
 
-       if ((lendos = convert_string_allocate(CH_UNIX, CH_DOS, msg,len, (void **) &msgdos)) < 0 || !msgdos) {
+       if ((lendos = convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **) &msgdos)) < 0 || !msgdos) {
                DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
                SSVAL(p, 0, len); p += 2;
                memcpy(p, msg, len);
index f302c045a5d51537d2b18a70a151dfad666100fd..2fb0e59acacc3a8fa457a9eca21793da86032a30 100644 (file)
@@ -55,7 +55,7 @@ int cli_print_queue(struct cli_state *cli,
        char *rparam = NULL;
        char *rdata = NULL;
        char *p;
-       int rdrcnt, rprcnt;
+       unsigned int rdrcnt, rprcnt;
        pstring param;
        int result_code=0;
        int i = -1;
@@ -125,7 +125,8 @@ int cli_printjob_del(struct cli_state *cli, int job)
        char *rparam = NULL;
        char *rdata = NULL;
        char *p;
-       int rdrcnt,rprcnt, ret = -1;
+       unsigned int rdrcnt,rprcnt;
+       int ret = -1;
        pstring param;
 
        memset(param,'\0',sizeof(param));
index a307ac6ccf8f90bf7c3a9bc1ec8f619864187a7a..79ad38fc8c34a59d9912a606390631a064dfe3e5 100644 (file)
@@ -76,7 +76,7 @@ BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
        char *rparam = NULL;
        char *rdata = NULL;
        char *p;
-       int rdrcnt,rprcnt;
+       unsigned int rdrcnt,rprcnt;
        pstring param;
 
        memset(param, 0, sizeof(param));
@@ -137,7 +137,7 @@ int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, co
        char *rparam = NULL;
        char *rdata = NULL;
        char *p;
-       int rdrcnt,rprcnt;
+       unsigned int rdrcnt,rprcnt;
        pstring param;
        int count = -1;
 
@@ -211,7 +211,7 @@ BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
 {
        char *rparam = NULL;
        char *rdata = NULL;
-       int rdrcnt,rprcnt;
+       unsigned int rdrcnt,rprcnt;
        char *p;
        pstring param;
        int uLevel = 1;
@@ -256,7 +256,7 @@ BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                const char *cmnt = comment_offset?(rdata+comment_offset):"";
                                pstring s1, s2;
 
-                               if (comment_offset < 0 || comment_offset > rdrcnt) continue;
+                               if (comment_offset < 0 || comment_offset > (int)rdrcnt) continue;
 
                                stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
 
@@ -290,7 +290,7 @@ BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char
   unsigned int param_len = 0;
   char *rparam = NULL;
   char *rdata = NULL;
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   pstring dos_new_password;
 
   if (strlen(user) >= sizeof(fstring)-1) {
index 669b33860dae88d8ce9f4620d471ab67edabfc99..12a3d63aff35542b1e81fe621e9434509cda9836 100644 (file)
@@ -153,7 +153,8 @@ int cli_NetGroupDelete(struct cli_state *cli, const char *group_name )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt, res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                    /* api number    */
            +sizeof(RAP_NetGroupDel_REQ) /* parm string   */
            +1                           /* no ret string */
@@ -204,7 +205,8 @@ int cli_NetGroupAdd(struct cli_state *cli, RAP_GROUP_INFO_1 * grinfo )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt,res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                    /* api number    */
            +sizeof(RAP_NetGroupAdd_REQ) /* req string    */
            +sizeof(RAP_GROUP_INFO_L1)   /* return string */
@@ -272,7 +274,7 @@ int cli_RNetGroupEnum(struct cli_state *cli, void (*fn)(const char *, const char
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
   
@@ -332,7 +334,8 @@ int cli_NetGroupDelUser(struct cli_state * cli, const char *group_name, const ch
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt,res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                        /* api number    */
            +sizeof(RAP_NetGroupDelUser_REQ) /* parm string   */
            +1                               /* no ret string */
@@ -390,7 +393,8 @@ int cli_NetGroupAddUser(struct cli_state * cli, const char *group_name, const ch
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt,res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                        /* api number    */
            +sizeof(RAP_NetGroupAddUser_REQ) /* parm string   */
            +1                               /* no ret string */
@@ -446,7 +450,7 @@ int cli_NetGroupGetUsers(struct cli_state * cli, const char *group_name, void (*
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   int res = -1;
   char param[WORDSIZE                        /* api number    */
            +sizeof(RAP_NetGroupGetUsers_REQ)/* parm string   */
@@ -501,7 +505,7 @@ int cli_NetUserGetGroups(struct cli_state * cli, const char *user_name, void (*f
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   int res = -1;
   char param[WORDSIZE                        /* api number    */
            +sizeof(RAP_NetUserGetGroups_REQ)/* parm string   */
@@ -560,7 +564,8 @@ int cli_NetUserDelete(struct cli_state *cli, const char * user_name )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt, res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                    /* api number    */
            +sizeof(RAP_NetGroupDel_REQ) /* parm string   */
            +1                           /* no ret string */
@@ -614,7 +619,8 @@ int cli_NetUserAdd(struct cli_state *cli, RAP_USER_INFO_1 * userinfo )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;                                          
-  int rdrcnt,rprcnt,res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                    /* api number    */
            +sizeof(RAP_NetUserAdd2_REQ) /* req string    */
            +sizeof(RAP_USER_INFO_L1)    /* data string   */
@@ -702,7 +708,7 @@ int cli_RNetUserEnum(struct cli_state *cli, void (*fn)(const char *, const char
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
 
@@ -770,7 +776,7 @@ int cli_NetFileClose(struct cli_state *cli, uint32 file_id )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char param[WORDSIZE                    /* api number    */
            +sizeof(RAP_WFileClose2_REQ) /* req string    */
            +1                           /* no ret string */
@@ -816,7 +822,8 @@ int cli_NetFileGetInfo(struct cli_state *cli, uint32 file_id, void (*fn)(const c
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt, res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                      /* api number      */
            +sizeof(RAP_WFileGetInfo2_REQ) /* req string      */
            +sizeof(RAP_FILE_INFO_L3)      /* return string   */
@@ -893,7 +900,7 @@ int cli_NetFileEnum(struct cli_state *cli, char * user, char * base_path, void (
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char param[WORDSIZE                   /* api number      */
            +sizeof(RAP_WFileEnum2_REQ) /* req string      */
            +sizeof(RAP_FILE_INFO_L3)   /* return string   */
@@ -965,7 +972,8 @@ int cli_NetShareAdd(struct cli_state *cli, RAP_SHARE_INFO_2 * sinfo )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt,res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                  /* api number    */
            +sizeof(RAP_WShareAdd_REQ) /* req string    */
            +sizeof(RAP_SHARE_INFO_L2) /* return string */
@@ -1035,7 +1043,8 @@ int cli_NetShareDelete(struct cli_state *cli, const char * share_name )
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt, res;
+  unsigned int rdrcnt,rprcnt;
+  int res;
   char param[WORDSIZE                  /* api number    */
            +sizeof(RAP_WShareDel_REQ) /* req string    */
            +1                         /* no ret string */
@@ -1097,7 +1106,7 @@ BOOL cli_get_pdc_name(struct cli_state *cli, char *workgroup, char *pdc_name)
 {
   char *rparam = NULL;
   char *rdata = NULL;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char *p;
   char param[WORDSIZE                       /* api number    */
            +sizeof(RAP_NetServerEnum2_REQ) /* req string    */
@@ -1177,7 +1186,7 @@ BOOL cli_get_server_domain(struct cli_state *cli)
 {
   char *rparam = NULL;
   char *rdata = NULL;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char *p;
   char param[WORDSIZE                      /* api number    */
            +sizeof(RAP_WWkstaGetInfo_REQ) /* req string    */
@@ -1242,7 +1251,7 @@ BOOL cli_get_server_type(struct cli_state *cli, uint32 *pstype)
 {
   char *rparam = NULL;
   char *rdata = NULL;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char *p;
   char param[WORDSIZE                       /* api number    */
            +sizeof(RAP_WserverGetInfo_REQ) /* req string    */
@@ -1309,7 +1318,7 @@ BOOL cli_ns_check_server_type(struct cli_state *cli, char *workgroup, uint32 sty
 {
   char *rparam = NULL;
   char *rdata = NULL;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char *p;
   char param[WORDSIZE                       /* api number    */
            +sizeof(RAP_NetServerEnum2_REQ) /* req string    */
@@ -1378,7 +1387,7 @@ BOOL cli_NetWkstaUserLogoff(struct cli_state *cli,char *user, char *workstation)
   char *rparam = NULL;
   char *rdata = NULL;
   char *p;
-  int rdrcnt,rprcnt;
+  unsigned int rdrcnt,rprcnt;
   char param[WORDSIZE                           /* api number    */
            +sizeof(RAP_NetWkstaUserLogoff_REQ) /* req string    */
            +sizeof(RAP_USER_LOGOFF_INFO_L1)    /* return string */
@@ -1436,7 +1445,7 @@ int cli_NetPrintQEnum(struct cli_state *cli,
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
 
@@ -1540,7 +1549,7 @@ int cli_NetPrintQGetInfo(struct cli_state *cli, const char *printer,
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
 
@@ -1639,7 +1648,7 @@ int cli_RNetServiceEnum(struct cli_state *cli, void (*fn)(const char *, const ch
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
   
@@ -1708,7 +1717,7 @@ int cli_NetSessionEnum(struct cli_state *cli, void (*fn)(char *, char *, uint16,
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
   memset(param, '\0', sizeof(param));
@@ -1784,7 +1793,7 @@ int cli_NetSessionGetInfo(struct cli_state *cli, const char *workstation, void (
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
   
 
@@ -1858,7 +1867,7 @@ int cli_NetSessionDel(struct cli_state *cli, const char *workstation)
   char *p;
   char *rparam = NULL;
   char *rdata = NULL;
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res;
 
   memset(param, '\0', sizeof(param));
@@ -1903,7 +1912,7 @@ int cli_NetConnectionEnum(struct cli_state *cli, const char *qualifier, void (*f
   char *p;
   char *rparam = NULL;
   char *rdata = NULL; 
-  int rprcnt, rdrcnt;
+  unsigned int rprcnt, rdrcnt;
   int res = -1;
 
   memset(param, '\0', sizeof(param));
index 0715aa7f1a59439ac3f35f52f4a4fc1d63c64f00..8eac7d07d8be3bdac338be38d1e1b5e4ae430620 100644 (file)
@@ -326,7 +326,7 @@ ssize_t cli_write(struct cli_state *cli,
        int issued = 0;
        int received = 0;
        int mpx = MAX(cli->max_mux-1, 1);
-       int block = (cli->max_xmit - (smb_size+32)) & ~1023;
+       int block = cli->max_xmit - (smb_size+32);
        int blocks = (size + (block-1)) / block;
 
        while (received < blocks) {
index d86a9022a6954f6ca2a944b919511c7bb2a13b95..548cd6ec1878033b265aa7a8d57f7a7494232f75 100644 (file)
@@ -28,7 +28,7 @@ SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
 {
        char param[8];
        char *rparam=NULL, *rdata=NULL;
-       int rparam_count=0, rdata_count=0;
+       unsigned int rparam_count=0, rdata_count=0;
        prs_struct pd;
        SEC_DESC *psd = NULL;
 
@@ -78,7 +78,7 @@ BOOL cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd)
 {
        char param[8];
        char *rparam=NULL, *rdata=NULL;
-       int rparam_count=0, rdata_count=0;
+       unsigned int rparam_count=0, rdata_count=0;
        uint32 sec_info = 0;
        TALLOC_CTX *mem_ctx;
        prs_struct pd;
index b0570b09b604295e0a351a7ff53547941beacfba..63076a1a1ce661d9327a61e2da9406cbc27fd447 100644 (file)
@@ -331,6 +331,9 @@ DATA_BLOB spnego_gen_negTokenTarg(const char *principal, int time_offset, unsign
        /* get a kerberos ticket for the service and extract the session key */
        tkt = cli_krb5_get_ticket(principal, time_offset, session_key_krb5);
 
+       if (tkt.data == NULL)
+               return tkt;
+
        /* wrap that up in a nice GSS-API wrapping */
        tkt_wrapped = spnego_gen_krb5_wrap(tkt, TOK_ID_KRB_AP_REQ);
 
index 9875f77c72e43adb5bcfdda4beb92b0d05f85cd3..1de74137117191840af849b2eb02b47074eff443 100644 (file)
@@ -61,7 +61,7 @@ static struct node_status *parse_node_status(char *p, int *num_names)
        p++;
        for (i=0;i< *num_names;i++) {
                StrnCpy(ret[i].name,p,15);
-               trim_string(ret[i].name,NULL," ");
+               trim_char(ret[i].name,'\0',' ');
                ret[i].type = CVAL(p,15);
                ret[i].flags = p[16];
                p += 18;
index c9d45a7acc19b5dd4b3d2501bbbd49c3f021b214..a596f00ddb9b0ab8c896426d6a26e39a152c0761 100644 (file)
@@ -161,18 +161,28 @@ BOOL get_dc_name(const char *domain, fstring srv_name, struct in_addr *ip_out)
 {
        struct in_addr dc_ip;
        BOOL ret;
+       BOOL our_domain = False;
 
        zero_ip(&dc_ip);
 
        ret = False;
-       if (lp_security() == SEC_ADS)
+       
+       if ( strequal(lp_workgroup(), domain) || strequal(lp_realm(), domain) )
+               our_domain = True;
+       
+       /* always try to obey what the admin specified in smb.conf.
+          If it is not our domain, assume that domain names with periods 
+          in them are realm names */
+       
+       if ( (our_domain && lp_security()==SEC_ADS) || strchr_m(domain, '.') ) {
                ret = ads_dc_name(domain, &dc_ip, srv_name);
-
+       }
+       
        if (!ret) {
                /* fall back on rpc methods if the ADS methods fail */
                ret = rpc_dc_name(domain, srv_name, &dc_ip);
        }
-
+               
        *ip_out = dc_ip;
 
        return ret;
index 6ee05f010452c326d2d6b2b9914b7cc13f197db8..ff38245435dcbb09753488d6a97a7cd3a46c179b 100644 (file)
@@ -310,21 +310,24 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
 }
 
 /*******************************************************************
-  useful for debugging messages
-  ******************************************************************/
+ Useful for debugging messages.
+******************************************************************/
+
 char *nmb_namestr(struct nmb_name *n)
 {
-  static int i=0;
-  static fstring ret[4];
-  char *p = ret[i];
-
-  if (!n->scope[0])
-    slprintf(p,sizeof(fstring)-1, "%s<%02x>",n->name,n->name_type);
-  else
-    slprintf(p,sizeof(fstring)-1, "%s<%02x>.%s",n->name,n->name_type,n->scope);
-
-  i = (i+1)%4;
-  return(p);
+       static int i=0;
+       static fstring ret[4];
+       fstring name;
+       char *p = ret[i];
+
+       pull_ascii_fstring(name, n->name);
+       if (!n->scope[0])
+               slprintf(p,sizeof(fstring)-1, "%s<%02x>",name,n->name_type);
+       else
+               slprintf(p,sizeof(fstring)-1, "%s<%02x>.%s",name,n->name_type,n->scope);
+
+       i = (i+1)%4;
+       return(p);
 }
 
 /*******************************************************************
@@ -820,10 +823,9 @@ static int build_dgram(char *buf,struct packet_struct *p)
 void make_nmb_name( struct nmb_name *n, const char *name, int type)
 {
        memset( (char *)n, '\0', sizeof(struct nmb_name) );
-       push_ascii(n->name, name, 16, STR_TERMINATE|STR_UPPER);
+       push_ascii(n->name, name, sizeof(n->name), STR_TERMINATE|STR_UPPER);
        n->name_type = (unsigned int)type & 0xFF;
-       StrnCpy( n->scope, global_scope(), 63 );
-       strupper_m( n->scope );
+       push_ascii(n->scope,  global_scope(), 64, STR_TERMINATE);
 }
 
 /*******************************************************************
index a50ae9b70ff479709b69067116d4f1f8a8c9a086..42bf18d1d26516f85d9eba897ecded27b1224a7a 100644 (file)
@@ -140,7 +140,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
                                 &cliname,
                                 &domname)) {
                        DEBUG(1, ("ntlmssp_server_negotiate: failed to parse NTLMSSP:\n"));
-                       dump_data(2, request.data, request.length);
+                       dump_data(2, (const char *)request.data, request.length);
                        return NT_STATUS_INVALID_PARAMETER;
                }
                
@@ -172,6 +172,9 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
        target_name = ntlmssp_target_name(ntlmssp_state, 
                                          neg_flags, &chal_flags); 
 
+       if (target_name == NULL)
+               return NT_STATUS_INVALID_PARAMETER;
+
        /* This should be a 'netbios domain -> DNS domain' mapping */
        dnsdomname[0] = '\0';
        get_mydomname(dnsdomname);
@@ -273,7 +276,7 @@ static NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
                         &sess_key,
                         &neg_flags)) {
                DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP:\n"));
-               dump_data(2, request.data, request.length);
+               dump_data(2, (const char *)request.data, request.length);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -412,6 +415,8 @@ static NTSTATUS ntlmssp_client_initial(struct ntlmssp_client_state *ntlmssp_stat
        if (ntlmssp_state->use_ntlmv2) {
                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
        }
+
+       ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
        
        /* generate the ntlmssp negotiate packet */
        msrpc_gen(next_request, "CddAA",
@@ -446,16 +451,7 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
        DATA_BLOB lm_response = data_blob(NULL, 0);
        DATA_BLOB nt_response = data_blob(NULL, 0);
        DATA_BLOB session_key = data_blob(NULL, 0);
-       uint8 datagram_sess_key[16];
-       size_t datagram_sess_key_len;
-
-#if 0 /* until we know what flag to tigger it on */
-       generate_random_buffer(datagram_sess_key, sizeof(datagram_sess_key), False);    
-       datagram_sess_key_len = sizeof(datagram_sess_key);
-#else
-       ZERO_STRUCT(datagram_sess_key);
-       datagram_sess_key_len = 0;
-#endif
+       DATA_BLOB encrypted_session_key = data_blob(NULL, 0);
 
        if (!msrpc_parse(&reply, "CdBd",
                         "NTLMSSP",
@@ -463,7 +459,7 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                         &server_domain_blob,
                         &chal_flags)) {
                DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#1)\n"));
-               dump_data(2, reply.data, reply.length);
+               dump_data(2, (const char *)reply.data, reply.length);
 
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -489,7 +485,9 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                } else {
                        chal_parse_string = "CdAdbdd";
                }
+
                auth_gen_string = "CdBBAAABd";
+
                ntlmssp_state->unicode = False;
                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE;
                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM;
@@ -513,6 +511,10 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128;
        }
 
+       if (!(chal_flags & NTLMSSP_NEGOTIATE_KEY_EXCH)) {
+               ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_KEY_EXCH;
+       }
+
        DEBUG(3, ("NTLMSSP: Set final flags:\n"));
        debug_ntlmssp_flags(ntlmssp_state->neg_flags);
 
@@ -525,17 +527,22 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                         &unkn1, &unkn2,
                         &struct_blob)) {
                DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#2)\n"));
-               dump_data(2, reply.data, reply.length);
+               dump_data(2, (const char *)reply.data, reply.length);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
+       ntlmssp_state->server_domain = talloc_strdup(ntlmssp_state->mem_ctx,
+                                                    server_domain);
+
        SAFE_FREE(server_domain);
        if (challenge_blob.length != 8) {
                data_blob_free(&struct_blob);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       if (ntlmssp_state->use_ntlmv2) {
+       if (!ntlmssp_state->password) {
+               /* do nothing - blobs are zero length */
+       } else if (ntlmssp_state->use_ntlmv2) {
 
                if (!struct_blob.length) {
                        /* be lazy, match win2k - we can't do NTLMv2 without it */
@@ -554,7 +561,38 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                        data_blob_free(&struct_blob);
                        return NT_STATUS_NO_MEMORY;
                }
+       } else if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
+               struct MD5Context md5_session_nonce_ctx;
+               uchar nt_hash[16];
+               uchar session_nonce[16];
+               uchar session_nonce_hash[16];
+               uchar nt_session_key[16];
+               E_md4hash(ntlmssp_state->password, nt_hash);
+               
+               lm_response = data_blob(NULL, 24);
+               generate_random_buffer(lm_response.data, 8, False);
+               memset(lm_response.data+8, 0, 16);
+
+               memcpy(session_nonce, challenge_blob.data, 8);
+               memcpy(&session_nonce[8], lm_response.data, 8);
+       
+               MD5Init(&md5_session_nonce_ctx);
+               MD5Update(&md5_session_nonce_ctx, challenge_blob.data, 8);
+               MD5Update(&md5_session_nonce_ctx, lm_response.data, 8);
+               MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
+               
+               nt_response = data_blob(NULL, 24);
+               SMBNTencrypt(ntlmssp_state->password,
+                            session_nonce_hash,
+                            nt_response.data);
+
+               session_key = data_blob(NULL, 16);
+
+               SMBsesskeygen_ntv1(nt_hash, NULL, nt_session_key);
+               hmac_md5(nt_session_key, session_nonce, sizeof(session_nonce), session_key.data);
        } else {
+               
+               
                uchar lm_hash[16];
                uchar nt_hash[16];
                E_deshash(ntlmssp_state->password, lm_hash);
@@ -565,15 +603,15 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                        lm_response = data_blob(NULL, 24);
                        SMBencrypt(ntlmssp_state->password,challenge_blob.data,
                                   lm_response.data);
-               }
+                       }
                
                nt_response = data_blob(NULL, 24);
                SMBNTencrypt(ntlmssp_state->password,challenge_blob.data,
                             nt_response.data);
-
+               
                session_key = data_blob(NULL, 16);
                if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY) 
-                     && lp_client_lanman_auth()) {
+                   && lp_client_lanman_auth()) {
                        SMBsesskeygen_lmv1(lm_hash, lm_response.data, 
                                           session_key.data);
                } else {
@@ -582,6 +620,18 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
        }
        data_blob_free(&struct_blob);
 
+       /* Key exchange encryptes a new client-generated session key with
+          the password-derived key */
+       if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
+               uint8 client_session_key[16];
+               
+               generate_random_buffer(client_session_key, sizeof(client_session_key), False);  
+               encrypted_session_key = data_blob(client_session_key, sizeof(client_session_key));
+               SamOEMhash(encrypted_session_key.data, session_key.data, encrypted_session_key.length);
+               data_blob_free(&session_key);
+               session_key = data_blob(client_session_key, sizeof(client_session_key));
+       }
+
        /* this generates the actual auth packet */
        if (!msrpc_gen(next_request, auth_gen_string, 
                       "NTLMSSP", 
@@ -591,7 +641,7 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                       ntlmssp_state->domain, 
                       ntlmssp_state->user, 
                       ntlmssp_state->get_global_myname(), 
-                      datagram_sess_key, datagram_sess_key_len,
+                      encrypted_session_key.data, encrypted_session_key.length,
                       ntlmssp_state->neg_flags)) {
                
                data_blob_free(&lm_response);
@@ -600,6 +650,8 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_st
                return NT_STATUS_NO_MEMORY;
        }
 
+       data_blob_free(&encrypted_session_key);
+
        data_blob_free(&ntlmssp_state->chal);
        data_blob_free(&ntlmssp_state->lm_resp);
        data_blob_free(&ntlmssp_state->nt_resp);
@@ -638,6 +690,8 @@ NTSTATUS ntlmssp_client_start(NTLMSSP_CLIENT_STATE **ntlmssp_state)
        (*ntlmssp_state)->neg_flags = 
                NTLMSSP_NEGOTIATE_128 |
                NTLMSSP_NEGOTIATE_NTLM |
+               NTLMSSP_NEGOTIATE_NTLM2 |
+               NTLMSSP_NEGOTIATE_KEY_EXCH |
                NTLMSSP_REQUEST_TARGET;
 
        (*ntlmssp_state)->ref_count = 1;
@@ -706,9 +760,13 @@ NTSTATUS ntlmssp_set_username(NTLMSSP_CLIENT_STATE *ntlmssp_state, const char *u
 
 NTSTATUS ntlmssp_set_password(NTLMSSP_CLIENT_STATE *ntlmssp_state, const char *password) 
 {
-       ntlmssp_state->password = talloc_strdup(ntlmssp_state->mem_ctx, password);
-       if (!ntlmssp_state->password) {
-               return NT_STATUS_NO_MEMORY;
+       if (!password) {
+               ntlmssp_state->password = NULL;
+       } else {
+               ntlmssp_state->password = talloc_strdup(ntlmssp_state->mem_ctx, password);
+               if (!ntlmssp_state->password) {
+                       return NT_STATUS_NO_MEMORY;
+               }
        }
        return NT_STATUS_OK;
 }
index 3c6da349e4e46bf6f3ef3af77973c57ea136e6f1..60cb4ab04aec20849eab2e372125ec5ea94c4afc 100644 (file)
@@ -153,7 +153,8 @@ BOOL msrpc_gen(DATA_BLOB *blob,
                        SSVAL(blob->data, head_ofs, n); head_ofs += 2;
                        SSVAL(blob->data, head_ofs, n); head_ofs += 2;
                        SIVAL(blob->data, head_ofs, data_ofs); head_ofs += 4;
-                       memcpy(blob->data+data_ofs, b, n);
+                       if (n && b) /* don't follow null pointers... */
+                               memcpy(blob->data+data_ofs, b, n);
                        data_ofs += n;
                        break;
                case 'd':
index ecaef808c9b553d720992d33788a7915c7ff3d81..ff2f97c2e888048a6545e8195d93047c747d383d 100644 (file)
@@ -91,8 +91,8 @@ static void calc_ntlmv2_hash(unsigned char hash[16], char digest[16],
 
        MD5Init(&ctx3);
        MD5Update(&ctx3, session_key.data, session_key.length);
-       MD5Update(&ctx3, constant, strlen(constant));
-       MD5Final(digest, &ctx3);
+       MD5Update(&ctx3, (const unsigned char *)constant, strlen(constant));
+       MD5Final((unsigned char *)digest, &ctx3);
 
        calc_hash(hash, digest, 16);
 }
@@ -113,8 +113,8 @@ static NTSTATUS ntlmssp_make_packet_signature(NTLMSSP_CLIENT_STATE *ntlmssp_stat
                uchar digest[16];
                SIVAL(seq_num, 0, ntlmssp_state->ntlmssp_seq_num);
 
-               hmac_md5_init_limK_to_64(ntlmssp_state->cli_sign_const, 16, &ctx);
-               hmac_md5_update(seq_num, 4, &ctx);
+               hmac_md5_init_limK_to_64((const unsigned char *)(ntlmssp_state->cli_sign_const), 16, &ctx);
+               hmac_md5_update((const unsigned char *)seq_num, 4, &ctx);
                hmac_md5_update(data, length, &ctx);
                hmac_md5_final(digest, &ctx);
 
@@ -132,7 +132,7 @@ static NTSTATUS ntlmssp_make_packet_signature(NTLMSSP_CLIENT_STATE *ntlmssp_stat
                }
        } else {
                uint32 crc;
-               crc = crc32_calc_buffer(data, length);
+               crc = crc32_calc_buffer((const char *)data, length);
                if (!msrpc_gen(sig, "dddd", NTLMSSP_SIGN_VERSION, 0, crc, ntlmssp_state->ntlmssp_seq_num)) {
                        return NT_STATUS_NO_MEMORY;
                }
@@ -183,10 +183,10 @@ NTSTATUS ntlmssp_client_check_packet(NTLMSSP_CLIENT_STATE *ntlmssp_state,
        
        if (memcmp(sig->data+sig->length - 8, local_sig.data+local_sig.length - 8, 8) != 0) {
                DEBUG(5, ("BAD SIG: wanted signature of\n"));
-               dump_data(5, local_sig.data, local_sig.length);
+               dump_data(5, (const char *)local_sig.data, local_sig.length);
                
                DEBUG(5, ("BAD SIG: got signature of\n"));
-               dump_data(5, sig->data, sig->length);
+               dump_data(5, (const char *)(sig->data), sig->length);
 
                DEBUG(0, ("NTLMSSP packet check failed due to invalid signature!\n"));
                return NT_STATUS_ACCESS_DENIED;
@@ -216,8 +216,8 @@ NTSTATUS ntlmssp_client_seal_packet(NTLMSSP_CLIENT_STATE *ntlmssp_state,
                uchar digest[16];
                SIVAL(seq_num, 0, ntlmssp_state->ntlmssp_seq_num);
 
-               hmac_md5_init_limK_to_64(ntlmssp_state->cli_sign_const, 16, &ctx);
-               hmac_md5_update(seq_num, 4, &ctx);
+               hmac_md5_init_limK_to_64((const unsigned char *)(ntlmssp_state->cli_sign_const), 16, &ctx);
+               hmac_md5_update((const unsigned char *)seq_num, 4, &ctx);
                hmac_md5_update(data, length, &ctx);
                hmac_md5_final(digest, &ctx);
 
@@ -236,7 +236,7 @@ NTSTATUS ntlmssp_client_seal_packet(NTLMSSP_CLIENT_STATE *ntlmssp_state,
                NTLMSSPcalc_ap(ntlmssp_state->cli_sign_hash,  sig->data+4, sig->length-4);
        } else {
                uint32 crc;
-               crc = crc32_calc_buffer(data, length);
+               crc = crc32_calc_buffer((const char *)data, length);
                if (!msrpc_gen(sig, "dddd", NTLMSSP_SIGN_VERSION, 0, crc, ntlmssp_state->ntlmssp_seq_num)) {
                        return NT_STATUS_NO_MEMORY;
                }
@@ -335,7 +335,7 @@ NTSTATUS ntlmssp_client_sign_init(NTLMSSP_CLIENT_STATE *ntlmssp_state)
                
                DEBUG(5, ("NTLMSSP Sign/Seal - using LM KEY\n"));
 
-               calc_hash(ntlmssp_state->ntlmssp_hash, ntlmssp_state->session_key.data, 8);
+               calc_hash(ntlmssp_state->ntlmssp_hash, (const char *)(ntlmssp_state->session_key.data), 8);
                dump_data_pw("NTLMSSP hash:\n", ntlmssp_state->ntlmssp_hash,
                             sizeof(ntlmssp_state->ntlmssp_hash));
        } else {
@@ -347,7 +347,7 @@ NTSTATUS ntlmssp_client_sign_init(NTLMSSP_CLIENT_STATE *ntlmssp_state)
                
                DEBUG(5, ("NTLMSSP Sign/Seal - using NT KEY\n"));
 
-               calc_hash(ntlmssp_state->ntlmssp_hash, ntlmssp_state->session_key.data, 16);
+               calc_hash(ntlmssp_state->ntlmssp_hash, (const char *)(ntlmssp_state->session_key.data), 16);
                dump_data_pw("NTLMSSP hash:\n", ntlmssp_state->ntlmssp_hash,
                             sizeof(ntlmssp_state->ntlmssp_hash));
        }
index 4167452953985698e50b0172e449e9d8a17c1b37..08ff655a3f89dd5497b98725e1d78bd1ae8a7267 100644 (file)
@@ -25,6 +25,7 @@
 struct outstanding_packet_lookup {
        uint16 mid;
        uint32 reply_seq_num;
+       BOOL deferred_packet;
        struct outstanding_packet_lookup *prev, *next;
 };
 
@@ -43,7 +44,7 @@ struct smb_basic_signing_context {
 };
 
 static void store_sequence_for_reply(struct outstanding_packet_lookup **list, 
-                                    uint16 mid, uint32 reply_seq_num) 
+                                    uint16 mid, uint32 reply_seq_num, BOOL deferred_pkt
 {
        struct outstanding_packet_lookup *t;
        struct outstanding_packet_lookup *tmp;
@@ -54,19 +55,25 @@ static void store_sequence_for_reply(struct outstanding_packet_lookup **list,
        DLIST_ADD_END(*list, t, tmp);
        t->mid = mid;
        t->reply_seq_num = reply_seq_num;
-       DEBUG(10,("store_sequence_for_reply: stored seq = %u mid = %u\n",
+       t->deferred_packet = deferred_pkt;
+
+       DEBUG(10,("store_sequence_for_reply: stored %sseq = %u mid = %u\n",
+                       deferred_pkt ? "deferred " : "",
                        (unsigned int)reply_seq_num, (unsigned int)mid ));
 }
 
 static BOOL get_sequence_for_reply(struct outstanding_packet_lookup **list,
-                                  uint16 mid, uint32 *reply_seq_num) 
+                                  uint16 mid, uint32 *reply_seq_num, BOOL *def
 {
        struct outstanding_packet_lookup *t;
 
        for (t = *list; t; t = t->next) {
                if (t->mid == mid) {
                        *reply_seq_num = t->reply_seq_num;
-                       DEBUG(10,("get_sequence_for_reply: found seq = %u mid = %u\n",
+                       if (def)
+                               *def = t->deferred_packet;
+                       DEBUG(10,("get_sequence_for_reply: found %sseq = %u mid = %u\n",
+                               (t->deferred_packet) ? "deferred " : "",
                                (unsigned int)t->reply_seq_num, (unsigned int)t->mid ));
                        DLIST_REMOVE(*list, t);
                        SAFE_FREE(t);
@@ -76,6 +83,22 @@ static BOOL get_sequence_for_reply(struct outstanding_packet_lookup **list,
        return False;
 }
 
+/***********************************************************
+ A reply is pending if there is a non-deferred packet on the queue.
+************************************************************/
+
+static BOOL is_reply_pending(struct outstanding_packet_lookup *list)
+{
+       for (; list; list = list->next) {
+               if (!list->deferred_packet) {
+                       DEBUG(10,("is_reply_pending: True.\n"));
+                       return True;
+               }
+       }
+       DEBUG(10,("is_reply_pending: False.\n"));
+       return False;
+}
+
 /***********************************************************
  SMB signing - Common code before we set a new signing implementation
 ************************************************************/
@@ -188,7 +211,7 @@ static void free_signing_context(struct smb_sign_info *si)
 }
 
 
-static BOOL signing_good(char *inbuf, struct smb_sign_info *si, BOOL good) 
+static BOOL signing_good(char *inbuf, struct smb_sign_info *si, BOOL good, uint32 seq
 {
        if (good && !si->doing_signing) {
                si->doing_signing = True;
@@ -200,7 +223,8 @@ static BOOL signing_good(char *inbuf, struct smb_sign_info *si, BOOL good)
 
                        /* W2K sends a bad first signature but the sign engine is on.... JRA. */
                        if (data->send_seq_num > 1)
-                               DEBUG(1, ("signing_good: SMB signature check failed!\n"));
+                               DEBUG(1, ("signing_good: SMB signature check failed on seq %u!\n",
+                                                       (unsigned int)seq ));
 
                        return False;
                } else {
@@ -290,10 +314,10 @@ static void client_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
        else
                send_seq_num = data->send_seq_num;
 
-       simple_packet_signature(data, outbuf, send_seq_num, calc_md5_mac);
+       simple_packet_signature(data, (const unsigned char *)outbuf, send_seq_num, calc_md5_mac);
 
        DEBUG(10, ("client_sign_outgoing_message: sent SMB signature of\n"));
-       dump_data(10, calc_md5_mac, 8);
+       dump_data(10, (const char *)calc_md5_mac, 8);
 
        memcpy(&outbuf[smb_ss_field], calc_md5_mac, 8);
 
@@ -306,7 +330,7 @@ static void client_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
        data->send_seq_num++;
        store_sequence_for_reply(&data->outstanding_packet_list, 
                                 SVAL(outbuf,smb_mid),
-                                data->send_seq_num);
+                                data->send_seq_num, False);
        data->send_seq_num++;
 }
 
@@ -318,6 +342,7 @@ static BOOL client_check_incoming_message(char *inbuf, struct smb_sign_info *si)
 {
        BOOL good;
        uint32 reply_seq_number;
+       uint32 saved_seq;
        unsigned char calc_md5_mac[16];
        unsigned char *server_sent_mac;
 
@@ -335,29 +360,30 @@ static BOOL client_check_incoming_message(char *inbuf, struct smb_sign_info *si)
                reply_seq_number = data->trans_info->reply_seq_num;
        } else if (!get_sequence_for_reply(&data->outstanding_packet_list, 
                                    SVAL(inbuf, smb_mid), 
-                                   &reply_seq_number)) {
+                                   &reply_seq_number, NULL)) {
                DEBUG(1, ("client_check_incoming_message: failed to get sequence number %u for reply.\n",
                                        (unsigned int) SVAL(inbuf, smb_mid) ));
                return False;
        }
 
-       simple_packet_signature(data, inbuf, reply_seq_number, calc_md5_mac);
+       saved_seq = reply_seq_number;
+       simple_packet_signature(data, (const unsigned char *)inbuf, reply_seq_number, calc_md5_mac);
 
-       server_sent_mac = &inbuf[smb_ss_field];
+       server_sent_mac = (unsigned char *)&inbuf[smb_ss_field];
        good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0);
        
        if (!good) {
                DEBUG(5, ("client_check_incoming_message: BAD SIG: wanted SMB signature of\n"));
-               dump_data(5, calc_md5_mac, 8);
+               dump_data(5, (const char *)calc_md5_mac, 8);
                
                DEBUG(5, ("client_check_incoming_message: BAD SIG: got SMB signature of\n"));
-               dump_data(5, server_sent_mac, 8);
+               dump_data(5, (const char *)server_sent_mac, 8);
 #if 1 /* JRATEST */
                {
                        int i;
                        reply_seq_number -= 5;
                        for (i = 0; i < 10; i++, reply_seq_number++) {
-                               simple_packet_signature(data, inbuf, reply_seq_number, calc_md5_mac);
+                               simple_packet_signature(data, (const unsigned char *)inbuf, reply_seq_number, calc_md5_mac);
                                if (memcmp(server_sent_mac, calc_md5_mac, 8) == 0) {
                                        DEBUG(0,("client_check_incoming_message: out of seq. seq num %u matches.\n",
                                                        reply_seq_number ));
@@ -369,9 +395,9 @@ static BOOL client_check_incoming_message(char *inbuf, struct smb_sign_info *si)
 
        } else {
                DEBUG(10, ("client_check_incoming_message:: seq %u: got good SMB signature of\n", (unsigned int)reply_seq_number));
-               dump_data(10, server_sent_mac, 8);
+               dump_data(10, (const char *)server_sent_mac, 8);
        }
-       return signing_good(inbuf, si, good);
+       return signing_good(inbuf, si, good, saved_seq);
 }
 
 /***********************************************************
@@ -428,12 +454,12 @@ BOOL cli_simple_set_signing(struct cli_state *cli, const uchar user_session_key[
        memcpy(&data->mac_key.data[0], user_session_key, 16);
 
        DEBUG(10, ("cli_simple_set_signing: user_session_key\n"));
-       dump_data(10, user_session_key, 16);
+       dump_data(10, (const char *)user_session_key, 16);
 
        if (response.length) {
                memcpy(&data->mac_key.data[16],response.data, response.length);
                DEBUG(10, ("cli_simple_set_signing: response_data\n"));
-               dump_data(10, response.data, response.length);
+               dump_data(10, (const char *)response.data, response.length);
        } else {
                DEBUG(10, ("cli_simple_set_signing: NULL response_data\n"));
        }
@@ -584,17 +610,6 @@ BOOL cli_check_sign_mac(struct cli_state *cli)
        return True;
 }
 
-static BOOL packet_is_oplock_break(char *buf)
-{
-       if (CVAL(buf,smb_com) != SMBlockingX)
-               return False;
-
-       if (CVAL(buf,smb_vwv3) != LOCKING_ANDX_OPLOCK_RELEASE)
-               return False;
-
-       return True;
-}
-
 /***********************************************************
  SMB signing - Server implementation - send the MAC.
 ************************************************************/
@@ -608,25 +623,6 @@ static void srv_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
        uint16 mid;
 
        if (!si->doing_signing) {
-               if (si->allow_smb_signing && si->negotiated_smb_signing) {
-                       mid = SVAL(outbuf, smb_mid);
-
-                       was_deferred_packet = get_sequence_for_reply(&data->outstanding_packet_list, 
-                                                   mid, &send_seq_number);
-                       if (!was_deferred_packet) {
-                               /*
-                                * Is this an outgoing oplock break ? If so, store the
-                                * mid in the outstanding list. 
-                                */
-
-                               if (packet_is_oplock_break(outbuf)) {
-                                       store_sequence_for_reply(&data->outstanding_packet_list, 
-                                                                mid, data->send_seq_num);
-                               }
-
-                               data->send_seq_num++;
-                       }
-               }
                return;
        }
 
@@ -643,7 +639,7 @@ static void srv_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
        mid = SVAL(outbuf, smb_mid);
 
        /* See if this is a reply for a deferred packet. */
-       was_deferred_packet = get_sequence_for_reply(&data->outstanding_packet_list, mid, &send_seq_number);
+       get_sequence_for_reply(&data->outstanding_packet_list, mid, &send_seq_number, &was_deferred_packet);
 
        if (data->trans_info && (data->trans_info->mid == mid)) {
                /* This is a reply in a trans stream. Use the sequence
@@ -651,10 +647,10 @@ static void srv_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
                send_seq_number = data->trans_info->send_seq_num;
        }
 
-       simple_packet_signature(data, outbuf, send_seq_number, calc_md5_mac);
+       simple_packet_signature(data, (const unsigned char *)outbuf, send_seq_number, calc_md5_mac);
 
        DEBUG(10, ("srv_sign_outgoing_message: seq %u: sent SMB signature of\n", (unsigned int)send_seq_number));
-       dump_data(10, calc_md5_mac, 8);
+       dump_data(10, (const char *)calc_md5_mac, 8);
 
        memcpy(&outbuf[smb_ss_field], calc_md5_mac, 8);
 
@@ -662,7 +658,7 @@ static void srv_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
        Uncomment this to test if the remote server actually verifies signatures...*/
 
        if (!was_deferred_packet) {
-               if (!data->trans_info) {
+                       if (!data->trans_info) {
                        /* Always increment if not in a trans stream. */
                        data->send_seq_num++;
                } else if ((data->trans_info->send_seq_num == data->send_seq_num) || (data->trans_info->mid != mid)) {
@@ -670,7 +666,23 @@ static void srv_sign_outgoing_message(char *outbuf, struct smb_sign_info *si)
                         * packet that doesn't belong to this stream (different mid). */
                        data->send_seq_num++;
                }
-       }
+       } 
+}
+
+/***********************************************************
+ Is an incoming packet an oplock break reply ?
+************************************************************/
+
+static BOOL is_oplock_break(char *inbuf)
+{
+       if (CVAL(inbuf,smb_com) != SMBlockingX)
+               return False;
+
+       if (!(CVAL(inbuf,smb_vwv3) & LOCKING_ANDX_OPLOCK_RELEASE))
+               return False;
+
+       DEBUG(10,("is_oplock_break: Packet is oplock break\n"));
+       return True;
 }
 
 /***********************************************************
@@ -682,6 +694,7 @@ static BOOL srv_check_incoming_message(char *inbuf, struct smb_sign_info *si)
        BOOL good;
        struct smb_basic_signing_context *data = si->signing_context;
        uint32 reply_seq_number = data->send_seq_num;
+       uint32 saved_seq;
        unsigned char calc_md5_mac[16];
        unsigned char *server_sent_mac;
        uint mid;
@@ -703,30 +716,37 @@ static BOOL srv_check_incoming_message(char *inbuf, struct smb_sign_info *si)
        } else {
                /* We always increment the sequence number. */
                data->send_seq_num++;
-               /* Oplock break requests store an outgoing mid in the packet list. */
-               if (packet_is_oplock_break(inbuf))
-                       get_sequence_for_reply(&data->outstanding_packet_list, mid, &reply_seq_number);
+
+               /* If we get an asynchronous oplock break reply and there
+                * isn't a reply pending we need to re-sync the sequence
+                * number.
+                */
+               if (is_oplock_break(inbuf) && !is_reply_pending(data->outstanding_packet_list))
+                       data->send_seq_num++;
        }
 
-       simple_packet_signature(data, inbuf, reply_seq_number, calc_md5_mac);
+       saved_seq = reply_seq_number;
+       simple_packet_signature(data, (const unsigned char *)inbuf, reply_seq_number, calc_md5_mac);
 
-       server_sent_mac = &inbuf[smb_ss_field];
+       server_sent_mac = (unsigned char *)&inbuf[smb_ss_field];
        good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0);
        
        if (!good) {
 
-               DEBUG(5, ("srv_check_incoming_message: BAD SIG: wanted SMB signature of\n"));
-               dump_data(5, calc_md5_mac, 8);
+               DEBUG(5, ("srv_check_incoming_message: BAD SIG: seq %u wanted SMB signature of\n",
+                                       (unsigned int)saved_seq));
+               dump_data(5, (const char *)calc_md5_mac, 8);
                
-               DEBUG(5, ("srv_check_incoming_message: BAD SIG: got SMB signature of\n"));
-               dump_data(5, server_sent_mac, 8);
+               DEBUG(5, ("srv_check_incoming_message: BAD SIG: seq %u got SMB signature of\n",
+                                       (unsigned int)saved_seq));
+               dump_data(5, (const char *)server_sent_mac, 8);
 
 #if 1 /* JRATEST */
                {
                        int i;
                        reply_seq_number -= 5;
                        for (i = 0; i < 10; i++, reply_seq_number++) {
-                               simple_packet_signature(data, inbuf, reply_seq_number, calc_md5_mac);
+                               simple_packet_signature(data, (const unsigned char *)inbuf, reply_seq_number, calc_md5_mac);
                                if (memcmp(server_sent_mac, calc_md5_mac, 8) == 0) {
                                        DEBUG(0,("srv_check_incoming_message: out of seq. seq num %u matches.\n",
                                                        reply_seq_number ));
@@ -737,10 +757,10 @@ static BOOL srv_check_incoming_message(char *inbuf, struct smb_sign_info *si)
 #endif /* JRATEST */
 
        } else {
-               DEBUG(10, ("srv_check_incoming_message: seq %u: got good SMB signature of\n", (unsigned int)reply_seq_number));
-               dump_data(10, server_sent_mac, 8);
+               DEBUG(10, ("srv_check_incoming_message: seq %u: (current is %u) got good SMB signature of\n", (unsigned int)reply_seq_number, (unsigned int)data->send_seq_num));
+               dump_data(10, (const char *)server_sent_mac, 8);
        }
-       return signing_good(inbuf, si, good);
+       return signing_good(inbuf, si, good, saved_seq);
 }
 
 /***********************************************************
@@ -800,7 +820,7 @@ void srv_calculate_sign_mac(char *outbuf)
  Called by server to defer an outgoing packet.
 ************************************************************/
 
-void srv_defer_sign_response(uint16 mid)
+void srv_defer_sign_response(uint16 mid, BOOL deferred_packet)
 {
        struct smb_basic_signing_context *data;
 
@@ -813,7 +833,7 @@ void srv_defer_sign_response(uint16 mid)
                return;
 
        store_sequence_for_reply(&data->outstanding_packet_list, 
-                                mid, data->send_seq_num);
+                                mid, data->send_seq_num, deferred_packet);
        data->send_seq_num++;
 }
 
@@ -837,7 +857,7 @@ void srv_cancel_sign_response(uint16 mid)
 
        DEBUG(10,("srv_cancel_sign_response: for mid %u\n", (unsigned int)mid ));
 
-       while (get_sequence_for_reply(&data->outstanding_packet_list, mid, &dummy_seq))
+       while (get_sequence_for_reply(&data->outstanding_packet_list, mid, &dummy_seq,NULL))
                ;
 }
 
index 7a1a2d7d1894d84cd4064fb2447b490a670c9bc2..ec31bb5dbaabe8552421e497ecfc24100d226163 100644 (file)
@@ -81,7 +81,7 @@ void E_deshash(const char *passwd, uchar p16[16])
        push_ascii(dospwd, passwd, sizeof(dospwd), STR_UPPER|STR_TERMINATE);
 
        /* Only the fisrt 14 chars are considered, password need not be null terminated. */
-       E_P16(dospwd, p16);
+       E_P16((const unsigned char *)dospwd, p16);
 
        ZERO_STRUCT(dospwd);    
 }
@@ -247,7 +247,7 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[
        return True;
 }
 
-/* Does the md5 encryption from the NT hash for NTLMv2. */
+/* Does the md5 encryption from the Key Response for NTLMv2. */
 void SMBOWFencrypt_ntv2(const uchar kr[16],
                        const DATA_BLOB *srv_chal,
                        const DATA_BLOB *cli_chal,
diff --git a/source3/libsmb/spnego.c b/source3/libsmb/spnego.c
new file mode 100644 (file)
index 0000000..50caf7b
--- /dev/null
@@ -0,0 +1,343 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   RFC2478 Compliant SPNEGO implementation
+
+   Copyright (C) Jim McDonough <jmcd@us.ibm.com>   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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_AUTH
+
+static BOOL read_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
+{
+       ZERO_STRUCTP(token);
+
+       asn1_start_tag(asn1, ASN1_CONTEXT(0));
+       asn1_start_tag(asn1, ASN1_SEQUENCE(0));
+
+       while (!asn1->has_error && 0 < asn1_tag_remaining(asn1)) {
+               int i;
+
+               switch (asn1->data[asn1->ofs]) {
+               /* Read mechTypes */
+               case ASN1_CONTEXT(0):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(0));
+                       asn1_start_tag(asn1, ASN1_SEQUENCE(0));
+
+                       token->mechTypes = malloc(sizeof(*token->mechTypes));
+                       for (i = 0; !asn1->has_error &&
+                                    0 < asn1_tag_remaining(asn1); i++) {
+                               token->mechTypes = 
+                                       realloc(token->mechTypes, (i + 2) *
+                                               sizeof(*token->mechTypes));
+                               asn1_read_OID(asn1, token->mechTypes + i);
+                       }
+                       token->mechTypes[i] = NULL;
+                       
+                       asn1_end_tag(asn1);
+                       asn1_end_tag(asn1);
+                       break;
+               /* Read reqFlags */
+               case ASN1_CONTEXT(1):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(1));
+                       asn1_read_Integer(asn1, &token->reqFlags);
+                       token->reqFlags |= SPNEGO_REQ_FLAG;
+                       asn1_end_tag(asn1);
+                       break;
+                /* Read mechToken */
+               case ASN1_CONTEXT(2):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(2));
+                       asn1_read_OctetString(asn1, &token->mechToken);
+                       asn1_end_tag(asn1);
+                       break;
+               /* Read mecListMIC */
+               case ASN1_CONTEXT(3):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(3));
+                       if (asn1->data[asn1->ofs] == ASN1_OCTET_STRING) {
+                               asn1_read_OctetString(asn1,
+                                                     &token->mechListMIC);
+                       } else {
+                               /* RFC 2478 says we have an Octet String here,
+                                  but W2k sends something different... */
+                               char *mechListMIC;
+                               asn1_push_tag(asn1, ASN1_SEQUENCE(0));
+                               asn1_push_tag(asn1, ASN1_CONTEXT(0));
+                               asn1_read_GeneralString(asn1, &mechListMIC);
+                               asn1_pop_tag(asn1);
+                               asn1_pop_tag(asn1);
+
+                               token->mechListMIC =
+                                       data_blob(mechListMIC, strlen(mechListMIC));
+                               SAFE_FREE(mechListMIC);
+                       }
+                       asn1_end_tag(asn1);
+                       break;
+               default:
+                       asn1->has_error = True;
+                       break;
+               }
+       }
+
+       asn1_end_tag(asn1);
+       asn1_end_tag(asn1);
+
+       return !asn1->has_error;
+}
+
+static BOOL write_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
+{
+       asn1_push_tag(asn1, ASN1_CONTEXT(0));
+       asn1_push_tag(asn1, ASN1_SEQUENCE(0));
+
+       /* Write mechTypes */
+       if (token->mechTypes && *token->mechTypes) {
+               int i;
+
+               asn1_push_tag(asn1, ASN1_CONTEXT(0));
+               asn1_push_tag(asn1, ASN1_SEQUENCE(0));
+               for (i = 0; token->mechTypes[i]; i++) {
+                       asn1_write_OID(asn1, token->mechTypes[i]);
+               }
+               asn1_pop_tag(asn1);
+               asn1_pop_tag(asn1);
+       }
+
+       /* write reqFlags */
+       if (token->reqFlags & SPNEGO_REQ_FLAG) {
+               int flags = token->reqFlags & ~SPNEGO_REQ_FLAG;
+
+               asn1_push_tag(asn1, ASN1_CONTEXT(1));
+               asn1_write_Integer(asn1, flags);
+               asn1_pop_tag(asn1);
+       }
+
+       /* write mechToken */
+       if (token->mechToken.data) {
+               asn1_push_tag(asn1, ASN1_CONTEXT(2));
+               asn1_write_OctetString(asn1, token->mechToken.data,
+                                      token->mechToken.length);
+               asn1_pop_tag(asn1);
+       }
+
+       /* write mechListMIC */
+       if (token->mechListMIC.data) {
+               asn1_push_tag(asn1, ASN1_CONTEXT(3));
+#if 0
+               /* This is what RFC 2478 says ... */
+               asn1_write_OctetString(asn1, token->mechListMIC.data,
+                                      token->mechListMIC.length);
+#else
+               /* ... but unfortunately this is what Windows
+                  sends/expects */
+               asn1_push_tag(asn1, ASN1_SEQUENCE(0));
+               asn1_push_tag(asn1, ASN1_CONTEXT(0));
+               asn1_push_tag(asn1, ASN1_GENERAL_STRING);
+               asn1_write(asn1, token->mechListMIC.data,
+                          token->mechListMIC.length);
+               asn1_pop_tag(asn1);
+               asn1_pop_tag(asn1);
+               asn1_pop_tag(asn1);
+#endif         
+               asn1_pop_tag(asn1);
+       }
+
+       asn1_pop_tag(asn1);
+       asn1_pop_tag(asn1);
+
+       return !asn1->has_error;
+}
+
+static BOOL read_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
+{
+       ZERO_STRUCTP(token);
+
+       asn1_start_tag(asn1, ASN1_CONTEXT(1));
+       asn1_start_tag(asn1, ASN1_SEQUENCE(0));
+
+       while (!asn1->has_error && 0 < asn1_tag_remaining(asn1)) {
+               switch (asn1->data[asn1->ofs]) {
+               case ASN1_CONTEXT(0):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(0));
+                       asn1_start_tag(asn1, ASN1_ENUMERATED);
+                       asn1_read_uint8(asn1, &token->negResult);
+                       asn1_end_tag(asn1);
+                       asn1_end_tag(asn1);
+                       break;
+               case ASN1_CONTEXT(1):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(1));
+                       asn1_read_OID(asn1, &token->supportedMech);
+                       asn1_end_tag(asn1);
+                       break;
+               case ASN1_CONTEXT(2):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(2));
+                       asn1_read_OctetString(asn1, &token->responseToken);
+                       asn1_end_tag(asn1);
+                       break;
+               case ASN1_CONTEXT(3):
+                       asn1_start_tag(asn1, ASN1_CONTEXT(3));
+                       asn1_read_OctetString(asn1, &token->mechListMIC);
+                       asn1_end_tag(asn1);
+                       break;
+               default:
+                       asn1->has_error = True;
+                       break;
+               }
+       }
+
+       asn1_end_tag(asn1);
+       asn1_end_tag(asn1);
+
+       return !asn1->has_error;
+}
+
+static BOOL write_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
+{
+       asn1_push_tag(asn1, ASN1_CONTEXT(1));
+       asn1_push_tag(asn1, ASN1_SEQUENCE(0));
+
+       asn1_push_tag(asn1, ASN1_CONTEXT(0));
+       asn1_write_enumerated(asn1, token->negResult);
+       asn1_pop_tag(asn1);
+
+       if (token->supportedMech) {
+               asn1_push_tag(asn1, ASN1_CONTEXT(1));
+               asn1_write_OID(asn1, token->supportedMech);
+               asn1_pop_tag(asn1);
+       }
+
+       if (token->responseToken.data) {
+               asn1_push_tag(asn1, ASN1_CONTEXT(2));
+               asn1_write_OctetString(asn1, token->responseToken.data,
+                                      token->responseToken.length);
+               asn1_pop_tag(asn1);
+       }
+
+       if (token->mechListMIC.data) {
+               asn1_push_tag(asn1, ASN1_CONTEXT(3));
+               asn1_write_OctetString(asn1, token->mechListMIC.data,
+                                     token->mechListMIC.length);
+               asn1_pop_tag(asn1);
+       }
+
+       asn1_pop_tag(asn1);
+       asn1_pop_tag(asn1);
+
+       return !asn1->has_error;
+}
+
+ssize_t read_spnego_data(DATA_BLOB data, SPNEGO_DATA *token)
+{
+       ASN1_DATA asn1;
+       ssize_t ret = -1;
+
+       ZERO_STRUCTP(token);
+       ZERO_STRUCT(asn1);
+       asn1_load(&asn1, data);
+
+       switch (asn1.data[asn1.ofs]) {
+       case ASN1_APPLICATION(0):
+               asn1_start_tag(&asn1, ASN1_APPLICATION(0));
+               asn1_check_OID(&asn1, OID_SPNEGO);
+               if (read_negTokenInit(&asn1, &token->negTokenInit)) {
+                       token->type = SPNEGO_NEG_TOKEN_INIT;
+               }
+               asn1_end_tag(&asn1);
+               break;
+       case ASN1_CONTEXT(1):
+               if (read_negTokenTarg(&asn1, &token->negTokenTarg)) {
+                       token->type = SPNEGO_NEG_TOKEN_TARG;
+               }
+               break;
+       default:
+               break;
+       }
+
+       if (!asn1.has_error) ret = asn1.ofs;
+       asn1_free(&asn1);
+
+       return ret;
+}
+
+ssize_t write_spnego_data(DATA_BLOB *blob, SPNEGO_DATA *spnego)
+{
+       ASN1_DATA asn1;
+       ssize_t ret = -1;
+
+       ZERO_STRUCT(asn1);
+
+       switch (spnego->type) {
+       case SPNEGO_NEG_TOKEN_INIT:
+               asn1_push_tag(&asn1, ASN1_APPLICATION(0));
+               asn1_write_OID(&asn1, OID_SPNEGO);
+               write_negTokenInit(&asn1, &spnego->negTokenInit);
+               asn1_pop_tag(&asn1);
+               break;
+       case SPNEGO_NEG_TOKEN_TARG:
+               write_negTokenTarg(&asn1, &spnego->negTokenTarg);
+               break;
+       default:
+               asn1.has_error = True;
+               break;
+       }
+
+       if (!asn1.has_error) {
+               *blob = data_blob(asn1.data, asn1.length);
+               ret = asn1.ofs;
+       }
+       asn1_free(&asn1);
+
+       return ret;
+}
+
+BOOL free_spnego_data(SPNEGO_DATA *spnego)
+{
+       BOOL ret = True;
+
+       if (!spnego) goto out;
+
+       switch(spnego->type) {
+       case SPNEGO_NEG_TOKEN_INIT:
+               if (spnego->negTokenInit.mechTypes) {
+                       int i;
+                       for (i = 0; spnego->negTokenInit.mechTypes[i]; i++) {
+                               free(spnego->negTokenInit.mechTypes[i]);
+                       }
+                       free(spnego->negTokenInit.mechTypes);
+               }
+               data_blob_free(&spnego->negTokenInit.mechToken);
+               data_blob_free(&spnego->negTokenInit.mechListMIC);
+               break;
+       case SPNEGO_NEG_TOKEN_TARG:
+               if (spnego->negTokenTarg.supportedMech) {
+                       free(spnego->negTokenTarg.supportedMech);
+               }
+               data_blob_free(&spnego->negTokenTarg.responseToken);
+               data_blob_free(&spnego->negTokenTarg.mechListMIC);
+               break;
+       default:
+               ret = False;
+               break;
+       }
+       ZERO_STRUCTP(spnego);
+out:
+       return ret;
+}
+
index 610f4b3c03133333719526a80ab6ae51342add66..4e02b29f92c2ab3d77eb7890fa1d5fd7ae224be9 100644 (file)
@@ -35,16 +35,15 @@ static NTSTATUS just_change_the_password(struct cli_state *cli, TALLOC_CTX *mem_
                                         uint32 sec_channel_type)
 {
        NTSTATUS result;
-       uint32 neg_flags = 0x000001ff;
 
-       result = cli_nt_setup_creds(cli, sec_channel_type, orig_trust_passwd_hash, &neg_flags, 2);
-       
-       if (!NT_STATUS_IS_OK(result)) {
+       /* ensure that schannel uses the right domain */
+       fstrcpy(cli->domain, lp_workgroup());
+       if (! NT_STATUS_IS_OK(result = cli_nt_establish_netlogon(cli, sec_channel_type, orig_trust_passwd_hash))) {
                DEBUG(3,("just_change_the_password: unable to setup creds (%s)!\n",
                         nt_errstr(result)));
                return result;
        }
-
+       
        result = cli_net_srv_pwset(cli, mem_ctx, global_myname(), new_trust_passwd_hash);
 
        if (!NT_STATUS_IS_OK(result)) {
index 4475f1446f90f6196e53ba25ce601dafe14438b5..91bc20af90f1d8db43e9a4c66cabd4a28873048c 100644 (file)
@@ -419,10 +419,10 @@ int get_share_modes(connection_struct *conn,
        struct locking_data *data;
        int num_share_modes;
        share_mode_entry *shares = NULL;
-
+       TDB_DATA key = locking_key(dev, inode);
        *pp_shares = NULL;
 
-       dbuf = tdb_fetch(tdb, locking_key(dev, inode));
+       dbuf = tdb_fetch(tdb, key);
        if (!dbuf.dptr)
                return 0;
 
@@ -469,7 +469,7 @@ int get_share_modes(connection_struct *conn,
                        /* The record has shrunk a bit */
                        dbuf.dsize -= del_count * sizeof(share_mode_entry);
 
-                       if (tdb_store(tdb, locking_key(dev, inode), dbuf, TDB_REPLACE) == -1) {
+                       if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1) {
                                SAFE_FREE(shares);
                                SAFE_FREE(dbuf.dptr);
                                return 0;
@@ -544,12 +544,13 @@ ssize_t del_share_entry( SMB_DEV_T dev, SMB_INO_T inode,
        int i, del_count=0;
        share_mode_entry *shares;
        ssize_t count = 0;
+       TDB_DATA key = locking_key(dev, inode);
 
        if (ppse)
                *ppse = NULL;
 
        /* read in the existing share modes */
-       dbuf = tdb_fetch(tdb, locking_key(dev, inode));
+       dbuf = tdb_fetch(tdb, key);
        if (!dbuf.dptr)
                return -1;
 
@@ -590,10 +591,10 @@ ssize_t del_share_entry( SMB_DEV_T dev, SMB_INO_T inode,
 
                /* store it back in the database */
                if (data->u.num_share_mode_entries == 0) {
-                       if (tdb_delete(tdb, locking_key(dev, inode)) == -1)
+                       if (tdb_delete(tdb, key) == -1)
                                count = -1;
                } else {
-                       if (tdb_store(tdb, locking_key(dev, inode), dbuf, TDB_REPLACE) == -1)
+                       if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1)
                                count = -1;
                }
        }
@@ -630,10 +631,11 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
        struct locking_data *data;
        char *p=NULL;
        int size;
+       TDB_DATA key = locking_key_fsp(fsp);
        BOOL ret = True;
                
        /* read in the existing share modes if any */
-       dbuf = tdb_fetch(tdb, locking_key_fsp(fsp));
+       dbuf = tdb_fetch(tdb, key);
        if (!dbuf.dptr) {
                size_t offset;
                /* we'll need to create a new record */
@@ -658,7 +660,7 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
                fill_share_mode(p + sizeof(*data), fsp, port, op_type);
                dbuf.dptr = p;
                dbuf.dsize = size;
-               if (tdb_store(tdb, locking_key_fsp(fsp), dbuf, TDB_REPLACE) == -1)
+               if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1)
                        ret = False;
 
                print_share_mode_table((struct locking_data *)p);
@@ -688,7 +690,7 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
        SAFE_FREE(dbuf.dptr);
        dbuf.dptr = p;
        dbuf.dsize = size;
-       if (tdb_store(tdb, locking_key_fsp(fsp), dbuf, TDB_REPLACE) == -1)
+       if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1)
                ret = False;
        print_share_mode_table((struct locking_data *)p);
        SAFE_FREE(p);
@@ -709,9 +711,10 @@ static BOOL mod_share_mode( SMB_DEV_T dev, SMB_INO_T inode, share_mode_entry *en
        share_mode_entry *shares;
        BOOL need_store=False;
        BOOL ret = True;
+       TDB_DATA key = locking_key(dev, inode);
 
        /* read in the existing share modes */
-       dbuf = tdb_fetch(tdb, locking_key(dev, inode));
+       dbuf = tdb_fetch(tdb, key);
        if (!dbuf.dptr)
                return False;
 
@@ -729,10 +732,10 @@ static BOOL mod_share_mode( SMB_DEV_T dev, SMB_INO_T inode, share_mode_entry *en
        /* if the mod fn was called then store it back */
        if (need_store) {
                if (data->u.num_share_mode_entries == 0) {
-                       if (tdb_delete(tdb, locking_key(dev, inode)) == -1)
+                       if (tdb_delete(tdb, key) == -1)
                                ret = False;
                } else {
-                       if (tdb_store(tdb, locking_key(dev, inode), dbuf, TDB_REPLACE) == -1)
+                       if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1)
                                ret = False;
                }
        }
@@ -808,9 +811,10 @@ BOOL modify_delete_flag( SMB_DEV_T dev, SMB_INO_T inode, BOOL delete_on_close)
        struct locking_data *data;
        int i;
        share_mode_entry *shares;
+       TDB_DATA key = locking_key(dev, inode);
 
        /* read in the existing share modes */
-       dbuf = tdb_fetch(tdb, locking_key(dev, inode));
+       dbuf = tdb_fetch(tdb, key);
        if (!dbuf.dptr)
                return False;
 
@@ -826,7 +830,7 @@ BOOL modify_delete_flag( SMB_DEV_T dev, SMB_INO_T inode, BOOL delete_on_close)
 
        /* store it back */
        if (data->u.num_share_mode_entries) {
-               if (tdb_store(tdb, locking_key(dev,inode), dbuf, TDB_REPLACE)==-1) {
+               if (tdb_store(tdb, key, dbuf, TDB_REPLACE)==-1) {
                        SAFE_FREE(dbuf.dptr);
                        return False;
                }
diff --git a/source3/modules/CP437.c b/source3/modules/CP437.c
new file mode 100644 (file)
index 0000000..b7e7409
--- /dev/null
@@ -0,0 +1,136 @@
+/* 
+ * Conversion table for CP437 charset also known as IBM437
+ *
+ * Copyright (C) Alexander Bokovoy             2003
+ *
+ * Conversion tables are generated using GNU libc 2.2.5's 
+ * localedata/charmaps/IBM437 table and source/script/gen-8bit-gap.sh script
+ *
+ * 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
+ * (at your option) any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+#include "includes.h"
+
+static const uint16 to_ucs2[256] = {
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
+ 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
+ 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
+ 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
+ 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+ 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
+ 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
+ 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
+ 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
+ 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
+ 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+ 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
+ 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+ 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
+ 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+ 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
+ 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0,
+};
+
+static const struct charset_gap_table from_idx[] = {
+  { 0x0000, 0x007f,     0 },
+  { 0x00a0, 0x00c9,   -32 },
+  { 0x00d1, 0x00ff,   -39 },
+  { 0x0192, 0x0192,  -185 },
+  { 0x0393, 0x0398,  -697 },
+  { 0x03a3, 0x03a9,  -707 },
+  { 0x03b1, 0x03b5,  -714 },
+  { 0x03c0, 0x03c6,  -724 },
+  { 0x207f, 0x207f, -8076 },
+  { 0x20a7, 0x20a7, -8115 },
+  { 0x2219, 0x221e, -8484 },
+  { 0x2229, 0x2229, -8494 },
+  { 0x2248, 0x2248, -8524 },
+  { 0x2261, 0x2265, -8548 },
+  { 0x2310, 0x2310, -8718 },
+  { 0x2320, 0x2321, -8733 },
+  { 0x2500, 0x2502, -9211 },
+  { 0x250c, 0x251c, -9220 },
+  { 0x2524, 0x2524, -9227 },
+  { 0x252c, 0x252c, -9234 },
+  { 0x2534, 0x2534, -9241 },
+  { 0x253c, 0x253c, -9248 },
+  { 0x2550, 0x256c, -9267 },
+  { 0x2580, 0x2593, -9286 },
+  { 0x25a0, 0x25a0, -9298 },
+  { 0xffff, 0xffff,     0 }
+};
+
+static const unsigned char from_ucs2[] = {
+
+  '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
+  '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
+  '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
+  '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
+  '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
+  '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
+  '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
+  '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
+  '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47',
+  '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f',
+  '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57',
+  '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f',
+  '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67',
+  '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f',
+  '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77',
+  '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f',
+  '\xff', '\xad', '\x9b', '\x9c', '\x00', '\x9d', '\x00', '\x00',
+  '\x00', '\x00', '\xa6', '\xae', '\xaa', '\x00', '\x00', '\x00',
+  '\xf8', '\xf1', '\xfd', '\x00', '\x00', '\xe6', '\x00', '\xfa',
+  '\x00', '\x00', '\xa7', '\xaf', '\xac', '\xab', '\x00', '\xa8',
+  '\x00', '\x00', '\x00', '\x00', '\x8e', '\x8f', '\x92', '\x80',
+  '\x00', '\x90', '\xa5', '\x00', '\x00', '\x00', '\x00', '\x99',
+  '\x00', '\x00', '\x00', '\x00', '\x00', '\x9a', '\x00', '\x00',
+  '\xe1', '\x85', '\xa0', '\x83', '\x00', '\x84', '\x86', '\x91',
+  '\x87', '\x8a', '\x82', '\x88', '\x89', '\x8d', '\xa1', '\x8c',
+  '\x8b', '\x00', '\xa4', '\x95', '\xa2', '\x93', '\x00', '\x94',
+  '\xf6', '\x00', '\x97', '\xa3', '\x96', '\x81', '\x00', '\x00',
+  '\x98', '\x9f', '\xe2', '\x00', '\x00', '\x00', '\x00', '\xe9',
+  '\xe4', '\x00', '\x00', '\xe8', '\x00', '\x00', '\xea', '\xe0',
+  '\x00', '\x00', '\xeb', '\xee', '\xe3', '\x00', '\x00', '\xe5',
+  '\xe7', '\x00', '\xed', '\xfc', '\x9e', '\xf9', '\xfb', '\x00',
+  '\x00', '\x00', '\xec', '\xef', '\xf7', '\xf0', '\x00', '\x00',
+  '\xf3', '\xf2', '\xa9', '\xf4', '\xf5', '\xc4', '\x00', '\xb3',
+  '\xda', '\x00', '\x00', '\x00', '\xbf', '\x00', '\x00', '\x00',
+  '\xc0', '\x00', '\x00', '\x00', '\xd9', '\x00', '\x00', '\x00',
+  '\xc3', '\xb4', '\xc2', '\xc1', '\xc5', '\xcd', '\xba', '\xd5',
+  '\xd6', '\xc9', '\xb8', '\xb7', '\xbb', '\xd4', '\xd3', '\xc8',
+  '\xbe', '\xbd', '\xbc', '\xc6', '\xc7', '\xcc', '\xb5', '\xb6',
+  '\xb9', '\xd1', '\xd2', '\xcb', '\xcf', '\xd0', '\xca', '\xd8',
+  '\xd7', '\xce', '\xdf', '\x00', '\x00', '\x00', '\xdc', '\x00',
+  '\x00', '\x00', '\xdb', '\x00', '\x00', '\x00', '\xdd', '\x00',
+  '\x00', '\x00', '\xde', '\xb0', '\xb1', '\xb2', '\xfe',
+};
+
+SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CP437)
diff --git a/source3/modules/CP850.c b/source3/modules/CP850.c
new file mode 100644 (file)
index 0000000..311d651
--- /dev/null
@@ -0,0 +1,122 @@
+/* 
+ * Conversion table for CP850 charset also known as IBM850.
+ *
+ * Copyright (C) Alexander Bokovoy             2003
+ *
+ * Conversion tables are generated using GNU libc 2.2.5's 
+ * localedata/charmaps/IBM850 table and source/script/gen-8bit-gap.sh script
+ *
+ * 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
+ * (at your option) any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+#include "includes.h"
+
+static const uint16 to_ucs2[256] = {
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
+ 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
+ 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
+ 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
+ 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+ 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
+ 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
+ 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
+ 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
+ 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
+ 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+ 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE,
+ 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
+ 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
+ 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
+ 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
+ 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0,
+};
+
+static const struct charset_gap_table from_idx[] = {
+    /* start, end, idx */
+  { 0x0000, 0x007f, 0 },
+  { 0x00a0, 0x00ff, -32 },
+  { 0x0131, 0x0131, -81 },
+  { 0x0192, 0x0192, -177 },
+  { 0x2017, 0x2017, -7989 },
+  { 0x2500, 0x2502, -9245 },
+  { 0x250c, 0x251c, -9254 },
+  { 0x2524, 0x2524, -9261 },
+  { 0x252c, 0x252c, -9268 },
+  { 0x2534, 0x2534, -9275 },
+  { 0x253c, 0x253c, -9282 },
+  { 0x2550, 0x256c, -9301 },
+  { 0x2580, 0x2588, -9320 },
+  { 0x2591, 0x2593, -9328 },
+  { 0x25a0, 0x25a0, -9340 },
+  { 0xffff, 0xffff, 0 }
+};
+static const unsigned char from_ucs2[] = {
+
+  '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
+  '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
+  '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
+  '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
+  '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
+  '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
+  '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
+  '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
+  '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47',
+  '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f',
+  '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57',
+  '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f',
+  '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67',
+  '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f',
+  '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77',
+  '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f',
+  '\xff', '\xad', '\xbd', '\x9c', '\xcf', '\xbe', '\xdd', '\xf5',
+  '\xf9', '\xb8', '\xa6', '\xae', '\xaa', '\xf0', '\xa9', '\xee',
+  '\xf8', '\xf1', '\xfd', '\xfc', '\xef', '\xe6', '\xf4', '\xfa',
+  '\xf7', '\xfb', '\xa7', '\xaf', '\xac', '\xab', '\xf3', '\xa8',
+  '\xb7', '\xb5', '\xb6', '\xc7', '\x8e', '\x8f', '\x92', '\x80',
+  '\xd4', '\x90', '\xd2', '\xd3', '\xde', '\xd6', '\xd7', '\xd8',
+  '\xd1', '\xa5', '\xe3', '\xe0', '\xe2', '\xe5', '\x99', '\x9e',
+  '\x9d', '\xeb', '\xe9', '\xea', '\x9a', '\xed', '\xe8', '\xe1',
+  '\x85', '\xa0', '\x83', '\xc6', '\x84', '\x86', '\x91', '\x87',
+  '\x8a', '\x82', '\x88', '\x89', '\x8d', '\xa1', '\x8c', '\x8b',
+  '\xd0', '\xa4', '\x95', '\xa2', '\x93', '\xe4', '\x94', '\xf6',
+  '\x9b', '\x97', '\xa3', '\x96', '\x81', '\xec', '\xe7', '\x98',
+  '\xd5', '\x9f', '\xf2', '\xc4', '\x00', '\xb3', '\xda', '\x00',
+  '\x00', '\x00', '\xbf', '\x00', '\x00', '\x00', '\xc0', '\x00',
+  '\x00', '\x00', '\xd9', '\x00', '\x00', '\x00', '\xc3', '\xb4',
+  '\xc2', '\xc1', '\xc5', '\xcd', '\xba', '\x00', '\x00', '\xc9',
+  '\x00', '\x00', '\xbb', '\x00', '\x00', '\xc8', '\x00', '\x00',
+  '\xbc', '\x00', '\x00', '\xcc', '\x00', '\x00', '\xb9', '\x00',
+  '\x00', '\xcb', '\x00', '\x00', '\xca', '\x00', '\x00', '\xce',
+  '\xdf', '\x00', '\x00', '\x00', '\xdc', '\x00', '\x00', '\x00',
+  '\xdb', '\xb0', '\xb1', '\xb2', '\xfe',
+};
+
+SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CP850)
+
diff --git a/source3/modules/getdate.c b/source3/modules/getdate.c
new file mode 100644 (file)
index 0000000..491c512
--- /dev/null
@@ -0,0 +1,2460 @@
+/* A Bison parser, made by GNU Bison 1.875a.  */
+
+/* Skeleton parser for Yacc-like parsing with Bison,
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
+   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, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+/* Written by Richard Stallman by simplifying the original so called
+   ``semantic'' parser.  */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+   infringing on user name space.  This should be done even for local
+   variables, as they might otherwise be expanded by user macros.
+   There are some unavoidable exceptions within include files to
+   define necessary library symbols; they are noted "INFRINGES ON
+   USER NAME SPACE" below.  */
+
+/* Identify Bison output.  */
+#define YYBISON 1
+
+/* Skeleton name.  */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers.  */
+#define YYPURE 1
+
+/* Using locations.  */
+#define YYLSP_NEEDED 0
+
+
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     tAGO = 258,
+     tDST = 259,
+     tDAY = 260,
+     tDAY_UNIT = 261,
+     tDAYZONE = 262,
+     tHOUR_UNIT = 263,
+     tLOCAL_ZONE = 264,
+     tMERIDIAN = 265,
+     tMINUTE_UNIT = 266,
+     tMONTH = 267,
+     tMONTH_UNIT = 268,
+     tSEC_UNIT = 269,
+     tYEAR_UNIT = 270,
+     tZONE = 271,
+     tSNUMBER = 272,
+     tUNUMBER = 273
+   };
+#endif
+#define tAGO 258
+#define tDST 259
+#define tDAY 260
+#define tDAY_UNIT 261
+#define tDAYZONE 262
+#define tHOUR_UNIT 263
+#define tLOCAL_ZONE 264
+#define tMERIDIAN 265
+#define tMINUTE_UNIT 266
+#define tMONTH 267
+#define tMONTH_UNIT 268
+#define tSEC_UNIT 269
+#define tYEAR_UNIT 270
+#define tZONE 271
+#define tSNUMBER 272
+#define tUNUMBER 273
+
+
+
+
+/* Copy the first part of user declarations.  */
+#line 1 "getdate.y"
+
+/* Parse a string into an internal time stamp.
+   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+
+   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, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Originally written by Steven M. Bellovin <smb@research.att.com> while
+   at the University of North Carolina at Chapel Hill.  Later tweaked by
+   a couple of people on Usenet.  Completely overhauled by Rich $alz
+   <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
+
+   Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
+   the right thing about local DST.  Unlike previous versions, this
+   version is reentrant.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+# ifdef HAVE_ALLOCA_H
+#  include <alloca.h>
+# endif
+#endif
+
+/* Since the code of getdate.y is not included in the Emacs executable
+   itself, there is no need to #define static in this file.  Even if
+   the code were included in the Emacs executable, it probably
+   wouldn't do any harm to #undef it here; this will only cause
+   problems if we try to write to a static variable, which I don't
+   think this code needs to do.  */
+#ifdef emacs
+# undef static
+#endif
+
+#include <ctype.h>
+
+#if HAVE_STDLIB_H
+# include <stdlib.h> /* for `free'; used by Bison 1.27 */
+#endif
+
+#if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii (c)
+#endif
+
+#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
+#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
+#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
+#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
+
+/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
+   - Its arg may be any int or unsigned int; it need not be an unsigned char.
+   - It's guaranteed to evaluate its argument exactly once.
+   - It's typically faster.
+   POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
+   ISDIGIT_LOCALE unless it's important to use the locale's definition
+   of `digit' even when the host does not conform to POSIX.  */
+#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+
+#if STDC_HEADERS || HAVE_STRING_H
+# include <string.h>
+#endif
+
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+#endif
+
+#ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+#endif
+
+#define EPOCH_YEAR 1970
+#define TM_YEAR_BASE 1900
+
+#define HOUR(x) ((x) * 60)
+
+/* An integer value, and the number of digits in its textual
+   representation.  */
+typedef struct
+{
+  int value;
+  int digits;
+} textint;
+
+/* An entry in the lexical lookup table.  */
+typedef struct
+{
+  char const *name;
+  int type;
+  int value;
+} table;
+
+/* Meridian: am, pm, or 24-hour style.  */
+enum { MERam, MERpm, MER24 };
+
+/* Information passed to and from the parser.  */
+typedef struct
+{
+  /* The input string remaining to be parsed. */
+  const char *input;
+
+  /* N, if this is the Nth Tuesday.  */
+  int day_ordinal;
+
+  /* Day of week; Sunday is 0.  */
+  int day_number;
+
+  /* tm_isdst flag for the local zone.  */
+  int local_isdst;
+
+  /* Time zone, in minutes east of UTC.  */
+  int time_zone;
+
+  /* Style used for time.  */
+  int meridian;
+
+  /* Gregorian year, month, day, hour, minutes, and seconds.  */
+  textint year;
+  int month;
+  int day;
+  int hour;
+  int minutes;
+  int seconds;
+
+  /* Relative year, month, day, hour, minutes, and seconds.  */
+  int rel_year;
+  int rel_month;
+  int rel_day;
+  int rel_hour;
+  int rel_minutes;
+  int rel_seconds;
+
+  /* Counts of nonterminals of various flavors parsed so far.  */
+  int dates_seen;
+  int days_seen;
+  int local_zones_seen;
+  int rels_seen;
+  int times_seen;
+  int zones_seen;
+
+  /* Table of local time zone abbrevations, terminated by a null entry.  */
+  table local_time_zone_table[3];
+} parser_control;
+
+#define PC (* (parser_control *) parm)
+#define YYLEX_PARAM parm
+#define YYPARSE_PARAM parm
+
+static int yyerror ();
+static int yylex ();
+
+
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+#line 172 "getdate.y"
+typedef union YYSTYPE {
+  int intval;
+  textint textintval;
+} YYSTYPE;
+/* Line 191 of yacc.c.  */
+#line 281 "getdate.c"
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations.  */
+
+
+/* Line 214 of yacc.c.  */
+#line 293 "getdate.c"
+
+#if ! defined (yyoverflow) || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols.  */
+
+# if YYSTACK_USE_ALLOCA
+#  define YYSTACK_ALLOC alloca
+# else
+#  ifndef YYSTACK_USE_ALLOCA
+#   if defined (alloca) || defined (_ALLOCA_H)
+#    define YYSTACK_ALLOC alloca
+#   else
+#    ifdef __GNUC__
+#     define YYSTACK_ALLOC __builtin_alloca
+#    endif
+#   endif
+#  endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+   /* Pacify GCC's `empty if-body' warning. */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+#  if defined (__STDC__) || defined (__cplusplus)
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T size_t
+#  endif
+#  define YYSTACK_ALLOC malloc
+#  define YYSTACK_FREE free
+# endif
+#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+
+
+#if (! defined (yyoverflow) \
+     && (! defined (__cplusplus) \
+        || (YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member.  */
+union yyalloc
+{
+  short yyss;
+  YYSTYPE yyvs;
+  };
+
+/* The size of the maximum gap between one aligned stack and the next.  */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+   N elements.  */
+# define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (short) + sizeof (YYSTYPE))                                \
+      + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO.  The source and destination do
+   not overlap.  */
+# ifndef YYCOPY
+#  if 1 < __GNUC__
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+#  else
+#   define YYCOPY(To, From, Count)             \
+      do                                       \
+       {                                       \
+         register YYSIZE_T yyi;                \
+         for (yyi = 0; yyi < (Count); yyi++)   \
+           (To)[yyi] = (From)[yyi];            \
+       }                                       \
+      while (0)
+#  endif
+# endif
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack)                                       \
+    do                                                                 \
+      {                                                                        \
+       YYSIZE_T yynewbytes;                                            \
+       YYCOPY (&yyptr->Stack, Stack, yysize);                          \
+       Stack = &yyptr->Stack;                                          \
+       yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+       yyptr += yynewbytes / sizeof (*yyptr);                          \
+      }                                                                        \
+    while (0)
+
+#endif
+
+#if defined (__STDC__) || defined (__cplusplus)
+   typedef signed char yysigned_char;
+#else
+   typedef short yysigned_char;
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL  2
+/* YYLAST -- Last index in YYTABLE.  */
+#define YYLAST   52
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS  22
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS  12
+/* YYNRULES -- Number of rules. */
+#define YYNRULES  54
+/* YYNRULES -- Number of states. */
+#define YYNSTATES  64
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
+#define YYUNDEFTOK  2
+#define YYMAXUTOK   273
+
+#define YYTRANSLATE(YYX)                                               \
+  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+static const unsigned char yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,    20,     2,     2,    21,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,    19,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
+       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17,    18
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+   YYRHS.  */
+static const unsigned char yyprhs[] =
+{
+       0,     0,     3,     4,     7,     9,    11,    13,    15,    17,
+      19,    21,    24,    29,    34,    41,    48,    50,    53,    55,
+      57,    60,    62,    65,    68,    72,    78,    82,    86,    89,
+      94,    97,   101,   104,   106,   109,   112,   114,   117,   120,
+     122,   125,   128,   130,   133,   136,   138,   141,   144,   146,
+     149,   152,   154,   156,   157
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yysigned_char yyrhs[] =
+{
+      23,     0,    -1,    -1,    23,    24,    -1,    25,    -1,    26,
+      -1,    27,    -1,    29,    -1,    28,    -1,    30,    -1,    32,
+      -1,    18,    10,    -1,    18,    19,    18,    33,    -1,    18,
+      19,    18,    17,    -1,    18,    19,    18,    19,    18,    33,
+      -1,    18,    19,    18,    19,    18,    17,    -1,     9,    -1,
+       9,     4,    -1,    16,    -1,     7,    -1,    16,     4,    -1,
+       5,    -1,     5,    20,    -1,    18,     5,    -1,    18,    21,
+      18,    -1,    18,    21,    18,    21,    18,    -1,    18,    17,
+      17,    -1,    18,    12,    17,    -1,    12,    18,    -1,    12,
+      18,    20,    18,    -1,    18,    12,    -1,    18,    12,    18,
+      -1,    31,     3,    -1,    31,    -1,    18,    15,    -1,    17,
+      15,    -1,    15,    -1,    18,    13,    -1,    17,    13,    -1,
+      13,    -1,    18,     6,    -1,    17,     6,    -1,     6,    -1,
+      18,     8,    -1,    17,     8,    -1,     8,    -1,    18,    11,
+      -1,    17,    11,    -1,    11,    -1,    18,    14,    -1,    17,
+      14,    -1,    14,    -1,    18,    -1,    -1,    10,    -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+static const unsigned short yyrline[] =
+{
+       0,   188,   188,   190,   194,   196,   198,   200,   202,   204,
+     206,   210,   217,   224,   232,   239,   251,   253,   258,   260,
+     262,   267,   272,   277,   285,   290,   310,   317,   325,   330,
+     336,   341,   350,   359,   363,   365,   367,   369,   371,   373,
+     375,   377,   379,   381,   383,   385,   387,   389,   391,   393,
+     395,   397,   402,   439,   440
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE
+/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+  "$end", "error", "$undefined", "tAGO", "tDST", "tDAY", "tDAY_UNIT", 
+  "tDAYZONE", "tHOUR_UNIT", "tLOCAL_ZONE", "tMERIDIAN", "tMINUTE_UNIT", 
+  "tMONTH", "tMONTH_UNIT", "tSEC_UNIT", "tYEAR_UNIT", "tZONE", "tSNUMBER", 
+  "tUNUMBER", "':'", "','", "'/'", "$accept", "spec", "item", "time", 
+  "local_zone", "zone", "day", "date", "rel", "relunit", "number", 
+  "o_merid", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+   token YYLEX-NUM.  */
+static const unsigned short yytoknum[] =
+{
+       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
+     265,   266,   267,   268,   269,   270,   271,   272,   273,    58,
+      44,    47
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
+static const unsigned char yyr1[] =
+{
+       0,    22,    23,    23,    24,    24,    24,    24,    24,    24,
+      24,    25,    25,    25,    25,    25,    26,    26,    27,    27,
+      27,    28,    28,    28,    29,    29,    29,    29,    29,    29,
+      29,    29,    30,    30,    31,    31,    31,    31,    31,    31,
+      31,    31,    31,    31,    31,    31,    31,    31,    31,    31,
+      31,    31,    32,    33,    33
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
+static const unsigned char yyr2[] =
+{
+       0,     2,     0,     2,     1,     1,     1,     1,     1,     1,
+       1,     2,     4,     4,     6,     6,     1,     2,     1,     1,
+       2,     1,     2,     2,     3,     5,     3,     3,     2,     4,
+       2,     3,     2,     1,     2,     2,     1,     2,     2,     1,
+       2,     2,     1,     2,     2,     1,     2,     2,     1,     2,
+       2,     1,     1,     0,     1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+   means the default is an error.  */
+static const unsigned char yydefact[] =
+{
+       2,     0,     1,    21,    42,    19,    45,    16,    48,     0,
+      39,    51,    36,    18,     0,    52,     3,     4,     5,     6,
+       8,     7,     9,    33,    10,    22,    17,    28,    20,    41,
+      44,    47,    38,    50,    35,    23,    40,    43,    11,    46,
+      30,    37,    49,    34,     0,     0,     0,    32,     0,    27,
+      31,    26,    53,    24,    29,    54,    13,     0,    12,     0,
+      53,    25,    15,    14
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yysigned_char yydefgoto[] =
+{
+      -1,     1,    16,    17,    18,    19,    20,    21,    22,    23,
+      24,    58
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+   STATE-NUM.  */
+#define YYPACT_NINF -17
+static const yysigned_char yypact[] =
+{
+     -17,     0,   -17,     1,   -17,   -17,   -17,    19,   -17,   -14,
+     -17,   -17,   -17,    32,    26,    14,   -17,   -17,   -17,   -17,
+     -17,   -17,   -17,    27,   -17,   -17,   -17,    22,   -17,   -17,
+     -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,
+     -16,   -17,   -17,   -17,    29,    25,    30,   -17,    31,   -17,
+     -17,   -17,    28,    23,   -17,   -17,   -17,    33,   -17,    34,
+      -7,   -17,   -17,   -17
+};
+
+/* YYPGOTO[NTERM-NUM].  */
+static const yysigned_char yypgoto[] =
+{
+     -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,   -17,
+     -17,   -10
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+   positive, shift that token.  If negative, reduce the rule which
+   number is the opposite.  If zero, do what YYDEFACT says.
+   If YYTABLE_NINF, syntax error.  */
+#define YYTABLE_NINF -1
+static const unsigned char yytable[] =
+{
+       2,    49,    50,    55,    27,     3,     4,     5,     6,     7,
+      62,     8,     9,    10,    11,    12,    13,    14,    15,    35,
+      36,    25,    37,    26,    38,    39,    40,    41,    42,    43,
+      47,    44,    29,    45,    30,    46,    28,    31,    55,    32,
+      33,    34,    48,    52,    59,    56,    51,    57,    53,    54,
+      63,    60,    61
+};
+
+static const unsigned char yycheck[] =
+{
+       0,    17,    18,    10,    18,     5,     6,     7,     8,     9,
+      17,    11,    12,    13,    14,    15,    16,    17,    18,     5,
+       6,    20,     8,     4,    10,    11,    12,    13,    14,    15,
+       3,    17,     6,    19,     8,    21,     4,    11,    10,    13,
+      14,    15,    20,    18,    21,    17,    17,    19,    18,    18,
+      60,    18,    18
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+   symbol of state STATE-NUM.  */
+static const unsigned char yystos[] =
+{
+       0,    23,     0,     5,     6,     7,     8,     9,    11,    12,
+      13,    14,    15,    16,    17,    18,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    20,     4,    18,     4,     6,
+       8,    11,    13,    14,    15,     5,     6,     8,    10,    11,
+      12,    13,    14,    15,    17,    19,    21,     3,    20,    17,
+      18,    17,    18,    18,    18,    10,    17,    19,    33,    21,
+      18,    18,    17,    33
+};
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok                (yyerrstatus = 0)
+#define yyclearin      (yychar = YYEMPTY)
+#define YYEMPTY                (-2)
+#define YYEOF          0
+
+#define YYACCEPT       goto yyacceptlab
+#define YYABORT                goto yyabortlab
+#define YYERROR                goto yyerrlab1
+
+
+/* Like YYERROR except do call yyerror.  This remains here temporarily
+   to ease the transition to the new meaning of YYERROR, for GCC.
+   Once GCC version 2 has supplanted version 1, this can go.  */
+
+#define YYFAIL         goto yyerrlab
+
+#define YYRECOVERING()  (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value)                                 \
+do                                                             \
+  if (yychar == YYEMPTY && yylen == 1)                         \
+    {                                                          \
+      yychar = (Token);                                                \
+      yylval = (Value);                                                \
+      yytoken = YYTRANSLATE (yychar);                          \
+      YYPOPSTACK;                                              \
+      goto yybackup;                                           \
+    }                                                          \
+  else                                                         \
+    {                                                          \
+      yyerror ("syntax error: cannot back up");\
+      YYERROR;                                                 \
+    }                                                          \
+while (0)
+
+#define YYTERROR       1
+#define YYERRCODE      256
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+   are run).  */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)         \
+  Current.first_line   = Rhs[1].first_line;      \
+  Current.first_column = Rhs[1].first_column;    \
+  Current.last_line    = Rhs[N].last_line;       \
+  Current.last_column  = Rhs[N].last_column;
+#endif
+
+/* YYLEX -- calling `yylex' with the right arguments.  */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval)
+#endif
+
+/* Enable debugging if requested.  */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args)                       \
+do {                                           \
+  if (yydebug)                                 \
+    YYFPRINTF Args;                            \
+} while (0)
+
+# define YYDSYMPRINT(Args)                     \
+do {                                           \
+  if (yydebug)                                 \
+    yysymprint Args;                           \
+} while (0)
+
+# define YYDSYMPRINTF(Title, Token, Value, Location)           \
+do {                                                           \
+  if (yydebug)                                                 \
+    {                                                          \
+      YYFPRINTF (stderr, "%s ", Title);                                \
+      yysymprint (stderr,                                      \
+                  Token, Value);       \
+      YYFPRINTF (stderr, "\n");                                        \
+    }                                                          \
+} while (0)
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (cinluded).                                                   |
+`------------------------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_stack_print (short *bottom, short *top)
+#else
+static void
+yy_stack_print (bottom, top)
+    short *bottom;
+    short *top;
+#endif
+{
+  YYFPRINTF (stderr, "Stack now");
+  for (/* Nothing. */; bottom <= top; ++bottom)
+    YYFPRINTF (stderr, " %d", *bottom);
+  YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top)                           \
+do {                                                           \
+  if (yydebug)                                                 \
+    yy_stack_print ((Bottom), (Top));                          \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced.  |
+`------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_reduce_print (int yyrule)
+#else
+static void
+yy_reduce_print (yyrule)
+    int yyrule;
+#endif
+{
+  int yyi;
+  unsigned int yylineno = yyrline[yyrule];
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
+             yyrule - 1, yylineno);
+  /* Print the symbols being reduced, and their result.  */
+  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+    YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
+  YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
+}
+
+# define YY_REDUCE_PRINT(Rule)         \
+do {                                   \
+  if (yydebug)                         \
+    yy_reduce_print (Rule);            \
+} while (0)
+
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINT(Args)
+# define YYDSYMPRINTF(Title, Token, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef        YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#if YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+\f
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+#  if defined (__GLIBC__) && defined (_STRING_H)
+#   define yystrlen strlen
+#  else
+/* Return the length of YYSTR.  */
+static YYSIZE_T
+#   if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+#   else
+yystrlen (yystr)
+     const char *yystr;
+#   endif
+{
+  register const char *yys = yystr;
+
+  while (*yys++ != '\0')
+    continue;
+
+  return yys - yystr - 1;
+}
+#  endif
+# endif
+
+# ifndef yystpcpy
+#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+static char *
+#   if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+#   else
+yystpcpy (yydest, yysrc)
+     char *yydest;
+     const char *yysrc;
+#   endif
+{
+  register char *yyd = yydest;
+  register const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+\f
+
+#if YYDEBUG
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yysymprint (yyoutput, yytype, yyvaluep)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE *yyvaluep;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvaluep;
+
+  if (yytype < YYNTOKENS)
+    {
+      YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+      YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+    }
+  else
+    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+  switch (yytype)
+    {
+      default:
+        break;
+    }
+  YYFPRINTF (yyoutput, ")");
+}
+
+#endif /* ! YYDEBUG */
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yydestruct (int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yytype, yyvaluep)
+    int yytype;
+    YYSTYPE *yyvaluep;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvaluep;
+
+  switch (yytype)
+    {
+
+      default:
+        break;
+    }
+}
+\f
+
+/* Prevent warnings from -Wmissing-prototypes.  */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM);
+# else
+int yyparse ();
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse.  |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+  void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+  /* The lookahead symbol.  */
+int yychar;
+
+/* The semantic value of the lookahead symbol.  */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far.  */
+int yynerrs;
+
+  register int yystate;
+  register int yyn;
+  int yyresult;
+  /* Number of tokens to shift before error messages enabled.  */
+  int yyerrstatus;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yytoken = 0;
+
+  /* Three stacks and their tools:
+     `yyss': related to states,
+     `yyvs': related to semantic values,
+     `yyls': related to locations.
+
+     Refer to the stacks thru separate pointers, to allow yyoverflow
+     to reallocate them elsewhere.  */
+
+  /* The state stack.  */
+  short        yyssa[YYINITDEPTH];
+  short *yyss = yyssa;
+  register short *yyssp;
+
+  /* The semantic value stack.  */
+  YYSTYPE yyvsa[YYINITDEPTH];
+  YYSTYPE *yyvs = yyvsa;
+  register YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK   (yyvsp--, yyssp--)
+
+  YYSIZE_T yystacksize = YYINITDEPTH;
+
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+
+
+  /* When reducing, the number of symbols on the RHS of the reduced
+     rule.  */
+  int yylen;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yystate = 0;
+  yyerrstatus = 0;
+  yynerrs = 0;
+  yychar = YYEMPTY;            /* Cause a token to be read.  */
+
+  /* Initialize stack pointers.
+     Waste one element of value and location stack
+     so that they stay on the same level as the state stack.
+     The wasted elements are never initialized.  */
+
+  yyssp = yyss;
+  yyvsp = yyvs;
+
+  goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate.  |
+`------------------------------------------------------------*/
+ yynewstate:
+  /* In all cases, when you get here, the value and location stacks
+     have just been pushed. so pushing a state here evens the stacks.
+     */
+  yyssp++;
+
+ yysetstate:
+  *yyssp = yystate;
+
+  if (yyss + yystacksize - 1 <= yyssp)
+    {
+      /* Get the current used size of the three stacks, in elements.  */
+      YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+      {
+       /* Give user a chance to reallocate the stack. Use copies of
+          these so that the &'s don't force the real ones into
+          memory.  */
+       YYSTYPE *yyvs1 = yyvs;
+       short *yyss1 = yyss;
+
+
+       /* Each stack pointer address is followed by the size of the
+          data in use in that stack, in bytes.  This used to be a
+          conditional around just the two extra args, but that might
+          be undefined if yyoverflow is a macro.  */
+       yyoverflow ("parser stack overflow",
+                   &yyss1, yysize * sizeof (*yyssp),
+                   &yyvs1, yysize * sizeof (*yyvsp),
+
+                   &yystacksize);
+
+       yyss = yyss1;
+       yyvs = yyvs1;
+      }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+      goto yyoverflowlab;
+# else
+      /* Extend the stack our own way.  */
+      if (YYMAXDEPTH <= yystacksize)
+       goto yyoverflowlab;
+      yystacksize *= 2;
+      if (YYMAXDEPTH < yystacksize)
+       yystacksize = YYMAXDEPTH;
+
+      {
+       short *yyss1 = yyss;
+       union yyalloc *yyptr =
+         (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+       if (! yyptr)
+         goto yyoverflowlab;
+       YYSTACK_RELOCATE (yyss);
+       YYSTACK_RELOCATE (yyvs);
+
+#  undef YYSTACK_RELOCATE
+       if (yyss1 != yyssa)
+         YYSTACK_FREE (yyss1);
+      }
+# endif
+#endif /* no yyoverflow */
+
+      yyssp = yyss + yysize - 1;
+      yyvsp = yyvs + yysize - 1;
+
+
+      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+                 (unsigned long int) yystacksize));
+
+      if (yyss + yystacksize - 1 <= yyssp)
+       YYABORT;
+    }
+
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+  goto yybackup;
+
+/*-----------.
+| yybackup.  |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state.  */
+/* Read a lookahead token if we need one and don't already have one.  */
+/* yyresume: */
+
+  /* First try to decide what to do without reference to lookahead token.  */
+
+  yyn = yypact[yystate];
+  if (yyn == YYPACT_NINF)
+    goto yydefault;
+
+  /* Not known => get a lookahead token if don't already have one.  */
+
+  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
+  if (yychar == YYEMPTY)
+    {
+      YYDPRINTF ((stderr, "Reading a token: "));
+      yychar = YYLEX;
+    }
+
+  if (yychar <= YYEOF)
+    {
+      yychar = yytoken = YYEOF;
+      YYDPRINTF ((stderr, "Now at end of input.\n"));
+    }
+  else
+    {
+      yytoken = YYTRANSLATE (yychar);
+      YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
+    }
+
+  /* If the proper action on seeing token YYTOKEN is to reduce or to
+     detect an error, take that action.  */
+  yyn += yytoken;
+  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+    goto yydefault;
+  yyn = yytable[yyn];
+  if (yyn <= 0)
+    {
+      if (yyn == 0 || yyn == YYTABLE_NINF)
+       goto yyerrlab;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  /* Shift the lookahead token.  */
+  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
+
+  /* Discard the token being shifted unless it is eof.  */
+  if (yychar != YYEOF)
+    yychar = YYEMPTY;
+
+  *++yyvsp = yylval;
+
+
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state.  |
+`-----------------------------------------------------------*/
+yydefault:
+  yyn = yydefact[yystate];
+  if (yyn == 0)
+    goto yyerrlab;
+  goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction.  |
+`-----------------------------*/
+yyreduce:
+  /* yyn is the number of a rule to reduce with.  */
+  yylen = yyr2[yyn];
+
+  /* If YYLEN is nonzero, implement the default value of the action:
+     `$$ = $1'.
+
+     Otherwise, the following line sets YYVAL to garbage.
+     This behavior is undocumented and Bison
+     users should not rely upon it.  Assigning to YYVAL
+     unconditionally makes the parser a bit smaller, and it avoids a
+     GCC warning that YYVAL may be used uninitialized.  */
+  yyval = yyvsp[1-yylen];
+
+
+  YY_REDUCE_PRINT (yyn);
+  switch (yyn)
+    {
+        case 4:
+#line 195 "getdate.y"
+    { PC.times_seen++; }
+    break;
+
+  case 5:
+#line 197 "getdate.y"
+    { PC.local_zones_seen++; }
+    break;
+
+  case 6:
+#line 199 "getdate.y"
+    { PC.zones_seen++; }
+    break;
+
+  case 7:
+#line 201 "getdate.y"
+    { PC.dates_seen++; }
+    break;
+
+  case 8:
+#line 203 "getdate.y"
+    { PC.days_seen++; }
+    break;
+
+  case 9:
+#line 205 "getdate.y"
+    { PC.rels_seen++; }
+    break;
+
+  case 11:
+#line 211 "getdate.y"
+    {
+       PC.hour = yyvsp[-1].textintval.value;
+       PC.minutes = 0;
+       PC.seconds = 0;
+       PC.meridian = yyvsp[0].intval;
+      }
+    break;
+
+  case 12:
+#line 218 "getdate.y"
+    {
+       PC.hour = yyvsp[-3].textintval.value;
+       PC.minutes = yyvsp[-1].textintval.value;
+       PC.seconds = 0;
+       PC.meridian = yyvsp[0].intval;
+      }
+    break;
+
+  case 13:
+#line 225 "getdate.y"
+    {
+       PC.hour = yyvsp[-3].textintval.value;
+       PC.minutes = yyvsp[-1].textintval.value;
+       PC.meridian = MER24;
+       PC.zones_seen++;
+       PC.time_zone = yyvsp[0].textintval.value % 100 + (yyvsp[0].textintval.value / 100) * 60;
+      }
+    break;
+
+  case 14:
+#line 233 "getdate.y"
+    {
+       PC.hour = yyvsp[-5].textintval.value;
+       PC.minutes = yyvsp[-3].textintval.value;
+       PC.seconds = yyvsp[-1].textintval.value;
+       PC.meridian = yyvsp[0].intval;
+      }
+    break;
+
+  case 15:
+#line 240 "getdate.y"
+    {
+       PC.hour = yyvsp[-5].textintval.value;
+       PC.minutes = yyvsp[-3].textintval.value;
+       PC.seconds = yyvsp[-1].textintval.value;
+       PC.meridian = MER24;
+       PC.zones_seen++;
+       PC.time_zone = yyvsp[0].textintval.value % 100 + (yyvsp[0].textintval.value / 100) * 60;
+      }
+    break;
+
+  case 16:
+#line 252 "getdate.y"
+    { PC.local_isdst = yyvsp[0].intval; }
+    break;
+
+  case 17:
+#line 254 "getdate.y"
+    { PC.local_isdst = yyvsp[-1].intval < 0 ? 1 : yyvsp[-1].intval + 1; }
+    break;
+
+  case 18:
+#line 259 "getdate.y"
+    { PC.time_zone = yyvsp[0].intval; }
+    break;
+
+  case 19:
+#line 261 "getdate.y"
+    { PC.time_zone = yyvsp[0].intval + 60; }
+    break;
+
+  case 20:
+#line 263 "getdate.y"
+    { PC.time_zone = yyvsp[-1].intval + 60; }
+    break;
+
+  case 21:
+#line 268 "getdate.y"
+    {
+       PC.day_ordinal = 1;
+       PC.day_number = yyvsp[0].intval;
+      }
+    break;
+
+  case 22:
+#line 273 "getdate.y"
+    {
+       PC.day_ordinal = 1;
+       PC.day_number = yyvsp[-1].intval;
+      }
+    break;
+
+  case 23:
+#line 278 "getdate.y"
+    {
+       PC.day_ordinal = yyvsp[-1].textintval.value;
+       PC.day_number = yyvsp[0].intval;
+      }
+    break;
+
+  case 24:
+#line 286 "getdate.y"
+    {
+       PC.month = yyvsp[-2].textintval.value;
+       PC.day = yyvsp[0].textintval.value;
+      }
+    break;
+
+  case 25:
+#line 291 "getdate.y"
+    {
+       /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
+          otherwise as MM/DD/YY.
+          The goal in recognizing YYYY/MM/DD is solely to support legacy
+          machine-generated dates like those in an RCS log listing.  If
+          you want portability, use the ISO 8601 format.  */
+       if (4 <= yyvsp[-4].textintval.digits)
+         {
+           PC.year = yyvsp[-4].textintval;
+           PC.month = yyvsp[-2].textintval.value;
+           PC.day = yyvsp[0].textintval.value;
+         }
+       else
+         {
+           PC.month = yyvsp[-4].textintval.value;
+           PC.day = yyvsp[-2].textintval.value;
+           PC.year = yyvsp[0].textintval;
+         }
+      }
+    break;
+
+  case 26:
+#line 311 "getdate.y"
+    {
+       /* ISO 8601 format.  YYYY-MM-DD.  */
+       PC.year = yyvsp[-2].textintval;
+       PC.month = -yyvsp[-1].textintval.value;
+       PC.day = -yyvsp[0].textintval.value;
+      }
+    break;
+
+  case 27:
+#line 318 "getdate.y"
+    {
+       /* e.g. 17-JUN-1992.  */
+       PC.day = yyvsp[-2].textintval.value;
+       PC.month = yyvsp[-1].intval;
+       PC.year.value = -yyvsp[0].textintval.value;
+       PC.year.digits = yyvsp[0].textintval.digits;
+      }
+    break;
+
+  case 28:
+#line 326 "getdate.y"
+    {
+       PC.month = yyvsp[-1].intval;
+       PC.day = yyvsp[0].textintval.value;
+      }
+    break;
+
+  case 29:
+#line 331 "getdate.y"
+    {
+       PC.month = yyvsp[-3].intval;
+       PC.day = yyvsp[-2].textintval.value;
+       PC.year = yyvsp[0].textintval;
+      }
+    break;
+
+  case 30:
+#line 337 "getdate.y"
+    {
+       PC.day = yyvsp[-1].textintval.value;
+       PC.month = yyvsp[0].intval;
+      }
+    break;
+
+  case 31:
+#line 342 "getdate.y"
+    {
+       PC.day = yyvsp[-2].textintval.value;
+       PC.month = yyvsp[-1].intval;
+       PC.year = yyvsp[0].textintval;
+      }
+    break;
+
+  case 32:
+#line 351 "getdate.y"
+    {
+       PC.rel_seconds = -PC.rel_seconds;
+       PC.rel_minutes = -PC.rel_minutes;
+       PC.rel_hour = -PC.rel_hour;
+       PC.rel_day = -PC.rel_day;
+       PC.rel_month = -PC.rel_month;
+       PC.rel_year = -PC.rel_year;
+      }
+    break;
+
+  case 34:
+#line 364 "getdate.y"
+    { PC.rel_year += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 35:
+#line 366 "getdate.y"
+    { PC.rel_year += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 36:
+#line 368 "getdate.y"
+    { PC.rel_year += yyvsp[0].intval; }
+    break;
+
+  case 37:
+#line 370 "getdate.y"
+    { PC.rel_month += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 38:
+#line 372 "getdate.y"
+    { PC.rel_month += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 39:
+#line 374 "getdate.y"
+    { PC.rel_month += yyvsp[0].intval; }
+    break;
+
+  case 40:
+#line 376 "getdate.y"
+    { PC.rel_day += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 41:
+#line 378 "getdate.y"
+    { PC.rel_day += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 42:
+#line 380 "getdate.y"
+    { PC.rel_day += yyvsp[0].intval; }
+    break;
+
+  case 43:
+#line 382 "getdate.y"
+    { PC.rel_hour += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 44:
+#line 384 "getdate.y"
+    { PC.rel_hour += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 45:
+#line 386 "getdate.y"
+    { PC.rel_hour += yyvsp[0].intval; }
+    break;
+
+  case 46:
+#line 388 "getdate.y"
+    { PC.rel_minutes += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 47:
+#line 390 "getdate.y"
+    { PC.rel_minutes += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 48:
+#line 392 "getdate.y"
+    { PC.rel_minutes += yyvsp[0].intval; }
+    break;
+
+  case 49:
+#line 394 "getdate.y"
+    { PC.rel_seconds += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 50:
+#line 396 "getdate.y"
+    { PC.rel_seconds += yyvsp[-1].textintval.value * yyvsp[0].intval; }
+    break;
+
+  case 51:
+#line 398 "getdate.y"
+    { PC.rel_seconds += yyvsp[0].intval; }
+    break;
+
+  case 52:
+#line 403 "getdate.y"
+    {
+       if (PC.dates_seen
+           && ! PC.rels_seen && (PC.times_seen || 2 < yyvsp[0].textintval.digits))
+         PC.year = yyvsp[0].textintval;
+       else
+         {
+           if (4 < yyvsp[0].textintval.digits)
+             {
+               PC.dates_seen++;
+               PC.day = yyvsp[0].textintval.value % 100;
+               PC.month = (yyvsp[0].textintval.value / 100) % 100;
+               PC.year.value = yyvsp[0].textintval.value / 10000;
+               PC.year.digits = yyvsp[0].textintval.digits - 4;
+             }
+           else
+             {
+               PC.times_seen++;
+               if (yyvsp[0].textintval.digits <= 2)
+                 {
+                   PC.hour = yyvsp[0].textintval.value;
+                   PC.minutes = 0;
+                 }
+               else
+                 {
+                   PC.hour = yyvsp[0].textintval.value / 100;
+                   PC.minutes = yyvsp[0].textintval.value % 100;
+                 }
+               PC.seconds = 0;
+               PC.meridian = MER24;
+             }
+         }
+      }
+    break;
+
+  case 53:
+#line 439 "getdate.y"
+    { yyval.intval = MER24; }
+    break;
+
+  case 54:
+#line 441 "getdate.y"
+    { yyval.intval = yyvsp[0].intval; }
+    break;
+
+
+    }
+
+/* Line 999 of yacc.c.  */
+#line 1593 "getdate.c"
+\f
+  yyvsp -= yylen;
+  yyssp -= yylen;
+
+
+  YY_STACK_PRINT (yyss, yyssp);
+
+  *++yyvsp = yyval;
+
+
+  /* Now `shift' the result of the reduction.  Determine what state
+     that goes to, based on the state we popped back to and the rule
+     number reduced by.  */
+
+  yyn = yyr1[yyn];
+
+  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+    yystate = yytable[yystate];
+  else
+    yystate = yydefgoto[yyn - YYNTOKENS];
+
+  goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+  /* If not already recovering from an error, report this error.  */
+  if (!yyerrstatus)
+    {
+      ++yynerrs;
+#if YYERROR_VERBOSE
+      yyn = yypact[yystate];
+
+      if (YYPACT_NINF < yyn && yyn < YYLAST)
+       {
+         YYSIZE_T yysize = 0;
+         int yytype = YYTRANSLATE (yychar);
+         char *yymsg;
+         int yyx, yycount;
+
+         yycount = 0;
+         /* Start YYX at -YYN if negative to avoid negative indexes in
+            YYCHECK.  */
+         for (yyx = yyn < 0 ? -yyn : 0;
+              yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
+           if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+             yysize += yystrlen (yytname[yyx]) + 15, yycount++;
+         yysize += yystrlen ("syntax error, unexpected ") + 1;
+         yysize += yystrlen (yytname[yytype]);
+         yymsg = (char *) YYSTACK_ALLOC (yysize);
+         if (yymsg != 0)
+           {
+             char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
+             yyp = yystpcpy (yyp, yytname[yytype]);
+
+             if (yycount < 5)
+               {
+                 yycount = 0;
+                 for (yyx = yyn < 0 ? -yyn : 0;
+                      yyx < (int) (sizeof (yytname) / sizeof (char *));
+                      yyx++)
+                   if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+                     {
+                       const char *yyq = ! yycount ? ", expecting " : " or ";
+                       yyp = yystpcpy (yyp, yyq);
+                       yyp = yystpcpy (yyp, yytname[yyx]);
+                       yycount++;
+                     }
+               }
+             yyerror (yymsg);
+             YYSTACK_FREE (yymsg);
+           }
+         else
+           yyerror ("syntax error; also virtual memory exhausted");
+       }
+      else
+#endif /* YYERROR_VERBOSE */
+       yyerror ("syntax error");
+    }
+
+
+
+  if (yyerrstatus == 3)
+    {
+      /* If just tried and failed to reuse lookahead token after an
+        error, discard it.  */
+
+      /* Return failure if at end of input.  */
+      if (yychar == YYEOF)
+        {
+         /* Pop the error token.  */
+          YYPOPSTACK;
+         /* Pop the rest of the stack.  */
+         while (yyss < yyssp)
+           {
+             YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+             yydestruct (yystos[*yyssp], yyvsp);
+             YYPOPSTACK;
+           }
+         YYABORT;
+        }
+
+      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
+      yydestruct (yytoken, &yylval);
+      yychar = YYEMPTY;
+
+    }
+
+  /* Else will try to reuse lookahead token after shifting the error
+     token.  */
+  goto yyerrlab1;
+
+
+/*----------------------------------------------------.
+| yyerrlab1 -- error raised explicitly by an action.  |
+`----------------------------------------------------*/
+yyerrlab1:
+  yyerrstatus = 3;     /* Each real token shifted decrements this.  */
+
+  for (;;)
+    {
+      yyn = yypact[yystate];
+      if (yyn != YYPACT_NINF)
+       {
+         yyn += YYTERROR;
+         if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+           {
+             yyn = yytable[yyn];
+             if (0 < yyn)
+               break;
+           }
+       }
+
+      /* Pop the current state because it cannot handle the error token.  */
+      if (yyssp == yyss)
+       YYABORT;
+
+      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+      yydestruct (yystos[yystate], yyvsp);
+      yyvsp--;
+      yystate = *--yyssp;
+
+      YY_STACK_PRINT (yyss, yyssp);
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  YYDPRINTF ((stderr, "Shifting error token, "));
+
+  *++yyvsp = yylval;
+
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here.  |
+`-------------------------------------*/
+yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here.  |
+`-----------------------------------*/
+yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here.  |
+`----------------------------------------------*/
+yyoverflowlab:
+  yyerror ("parser stack overflow");
+  yyresult = 2;
+  /* Fall through.  */
+#endif
+
+yyreturn:
+#ifndef yyoverflow
+  if (yyss != yyssa)
+    YYSTACK_FREE (yyss);
+#endif
+  return yyresult;
+}
+
+
+#line 444 "getdate.y"
+
+
+/* Include this file down here because bison inserts code above which
+   may define-away `const'.  We want the prototype for get_date to have
+   the same signature as the function definition.  */
+#include "modules/getdate.h"
+
+#ifndef gmtime
+struct tm *gmtime ();
+#endif
+#ifndef localtime
+struct tm *localtime ();
+#endif
+#ifndef mktime
+time_t mktime ();
+#endif
+
+static table const meridian_table[] =
+{
+  { "AM",   tMERIDIAN, MERam },
+  { "A.M.", tMERIDIAN, MERam },
+  { "PM",   tMERIDIAN, MERpm },
+  { "P.M.", tMERIDIAN, MERpm },
+  { 0, 0, 0 }
+};
+
+static table const dst_table[] =
+{
+  { "DST", tDST, 0 }
+};
+
+static table const month_and_day_table[] =
+{
+  { "JANUARY", tMONTH,  1 },
+  { "FEBRUARY",        tMONTH,  2 },
+  { "MARCH",   tMONTH,  3 },
+  { "APRIL",   tMONTH,  4 },
+  { "MAY",     tMONTH,  5 },
+  { "JUNE",    tMONTH,  6 },
+  { "JULY",    tMONTH,  7 },
+  { "AUGUST",  tMONTH,  8 },
+  { "SEPTEMBER",tMONTH,         9 },
+  { "SEPT",    tMONTH,  9 },
+  { "OCTOBER", tMONTH, 10 },
+  { "NOVEMBER",        tMONTH, 11 },
+  { "DECEMBER",        tMONTH, 12 },
+  { "SUNDAY",  tDAY,    0 },
+  { "MONDAY",  tDAY,    1 },
+  { "TUESDAY", tDAY,    2 },
+  { "TUES",    tDAY,    2 },
+  { "WEDNESDAY",tDAY,   3 },
+  { "WEDNES",  tDAY,    3 },
+  { "THURSDAY",        tDAY,    4 },
+  { "THUR",    tDAY,    4 },
+  { "THURS",   tDAY,    4 },
+  { "FRIDAY",  tDAY,    5 },
+  { "SATURDAY",        tDAY,    6 },
+  { 0, 0, 0 }
+};
+
+static table const time_units_table[] =
+{
+  { "YEAR",    tYEAR_UNIT,      1 },
+  { "MONTH",   tMONTH_UNIT,     1 },
+  { "FORTNIGHT",tDAY_UNIT,     14 },
+  { "WEEK",    tDAY_UNIT,       7 },
+  { "DAY",     tDAY_UNIT,       1 },
+  { "HOUR",    tHOUR_UNIT,      1 },
+  { "MINUTE",  tMINUTE_UNIT,    1 },
+  { "MIN",     tMINUTE_UNIT,    1 },
+  { "SECOND",  tSEC_UNIT,       1 },
+  { "SEC",     tSEC_UNIT,       1 },
+  { 0, 0, 0 }
+};
+
+/* Assorted relative-time words. */
+static table const relative_time_table[] =
+{
+  { "TOMORROW",        tMINUTE_UNIT,   24 * 60 },
+  { "YESTERDAY",tMINUTE_UNIT,  - (24 * 60) },
+  { "TODAY",   tMINUTE_UNIT,    0 },
+  { "NOW",     tMINUTE_UNIT,    0 },
+  { "LAST",    tUNUMBER,       -1 },
+  { "THIS",    tUNUMBER,        0 },
+  { "NEXT",    tUNUMBER,        1 },
+  { "FIRST",   tUNUMBER,        1 },
+/*{ "SECOND",  tUNUMBER,        2 }, */
+  { "THIRD",   tUNUMBER,        3 },
+  { "FOURTH",  tUNUMBER,        4 },
+  { "FIFTH",   tUNUMBER,        5 },
+  { "SIXTH",   tUNUMBER,        6 },
+  { "SEVENTH", tUNUMBER,        7 },
+  { "EIGHTH",  tUNUMBER,        8 },
+  { "NINTH",   tUNUMBER,        9 },
+  { "TENTH",   tUNUMBER,       10 },
+  { "ELEVENTH",        tUNUMBER,       11 },
+  { "TWELFTH", tUNUMBER,       12 },
+  { "AGO",     tAGO,            1 },
+  { 0, 0, 0 }
+};
+
+/* The time zone table.  This table is necessarily incomplete, as time
+   zone abbreviations are ambiguous; e.g. Australians interpret "EST"
+   as Eastern time in Australia, not as US Eastern Standard Time.
+   You cannot rely on getdate to handle arbitrary time zone
+   abbreviations; use numeric abbreviations like `-0500' instead.  */
+static table const time_zone_table[] =
+{
+  { "GMT",     tZONE,     HOUR ( 0) }, /* Greenwich Mean */
+  { "UT",      tZONE,     HOUR ( 0) }, /* Universal (Coordinated) */
+  { "UTC",     tZONE,     HOUR ( 0) },
+  { "WET",     tZONE,     HOUR ( 0) }, /* Western European */
+  { "WEST",    tDAYZONE,  HOUR ( 0) }, /* Western European Summer */
+  { "BST",     tDAYZONE,  HOUR ( 0) }, /* British Summer */
+  { "ART",     tZONE,    -HOUR ( 3) }, /* Argentina */
+  { "BRT",     tZONE,    -HOUR ( 3) }, /* Brazil */
+  { "BRST",    tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
+  { "NST",     tZONE,   -(HOUR ( 3) + 30) },   /* Newfoundland Standard */
+  { "NDT",     tDAYZONE,-(HOUR ( 3) + 30) },   /* Newfoundland Daylight */
+  { "AST",     tZONE,    -HOUR ( 4) }, /* Atlantic Standard */
+  { "ADT",     tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
+  { "CLT",     tZONE,    -HOUR ( 4) }, /* Chile */
+  { "CLST",    tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
+  { "EST",     tZONE,    -HOUR ( 5) }, /* Eastern Standard */
+  { "EDT",     tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
+  { "CST",     tZONE,    -HOUR ( 6) }, /* Central Standard */
+  { "CDT",     tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
+  { "MST",     tZONE,    -HOUR ( 7) }, /* Mountain Standard */
+  { "MDT",     tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
+  { "PST",     tZONE,    -HOUR ( 8) }, /* Pacific Standard */
+  { "PDT",     tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
+  { "AKST",    tZONE,    -HOUR ( 9) }, /* Alaska Standard */
+  { "AKDT",    tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
+  { "HST",     tZONE,    -HOUR (10) }, /* Hawaii Standard */
+  { "HAST",    tZONE,    -HOUR (10) }, /* Hawaii-Aleutian Standard */
+  { "HADT",    tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
+  { "SST",     tZONE,    -HOUR (12) }, /* Samoa Standard */
+  { "WAT",     tZONE,     HOUR ( 1) }, /* West Africa */
+  { "CET",     tZONE,     HOUR ( 1) }, /* Central European */
+  { "CEST",    tDAYZONE,  HOUR ( 1) }, /* Central European Summer */
+  { "MET",     tZONE,     HOUR ( 1) }, /* Middle European */
+  { "MEZ",     tZONE,     HOUR ( 1) }, /* Middle European */
+  { "MEST",    tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
+  { "MESZ",    tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
+  { "EET",     tZONE,     HOUR ( 2) }, /* Eastern European */
+  { "EEST",    tDAYZONE,  HOUR ( 2) }, /* Eastern European Summer */
+  { "CAT",     tZONE,     HOUR ( 2) }, /* Central Africa */
+  { "SAST",    tZONE,     HOUR ( 2) }, /* South Africa Standard */
+  { "EAT",     tZONE,     HOUR ( 3) }, /* East Africa */
+  { "MSK",     tZONE,     HOUR ( 3) }, /* Moscow */
+  { "MSD",     tDAYZONE,  HOUR ( 3) }, /* Moscow Daylight */
+  { "IST",     tZONE,    (HOUR ( 5) + 30) },   /* India Standard */
+  { "SGT",     tZONE,     HOUR ( 8) }, /* Singapore */
+  { "KST",     tZONE,     HOUR ( 9) }, /* Korea Standard */
+  { "JST",     tZONE,     HOUR ( 9) }, /* Japan Standard */
+  { "GST",     tZONE,     HOUR (10) }, /* Guam Standard */
+  { "NZST",    tZONE,     HOUR (12) }, /* New Zealand Standard */
+  { "NZDT",    tDAYZONE,  HOUR (12) }, /* New Zealand Daylight */
+  { 0, 0, 0  }
+};
+
+/* Military time zone table. */
+static table const military_table[] =
+{
+  { "A", tZONE,        -HOUR ( 1) },
+  { "B", tZONE,        -HOUR ( 2) },
+  { "C", tZONE,        -HOUR ( 3) },
+  { "D", tZONE,        -HOUR ( 4) },
+  { "E", tZONE,        -HOUR ( 5) },
+  { "F", tZONE,        -HOUR ( 6) },
+  { "G", tZONE,        -HOUR ( 7) },
+  { "H", tZONE,        -HOUR ( 8) },
+  { "I", tZONE,        -HOUR ( 9) },
+  { "K", tZONE,        -HOUR (10) },
+  { "L", tZONE,        -HOUR (11) },
+  { "M", tZONE,        -HOUR (12) },
+  { "N", tZONE,         HOUR ( 1) },
+  { "O", tZONE,         HOUR ( 2) },
+  { "P", tZONE,         HOUR ( 3) },
+  { "Q", tZONE,         HOUR ( 4) },
+  { "R", tZONE,         HOUR ( 5) },
+  { "S", tZONE,         HOUR ( 6) },
+  { "T", tZONE,         HOUR ( 7) },
+  { "U", tZONE,         HOUR ( 8) },
+  { "V", tZONE,         HOUR ( 9) },
+  { "W", tZONE,         HOUR (10) },
+  { "X", tZONE,         HOUR (11) },
+  { "Y", tZONE,         HOUR (12) },
+  { "Z", tZONE,         HOUR ( 0) },
+  { 0, 0, 0 }
+};
+
+\f
+
+static int
+to_hour (int hours, int meridian)
+{
+  switch (meridian)
+    {
+    case MER24:
+      return 0 <= hours && hours < 24 ? hours : -1;
+    case MERam:
+      return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
+    case MERpm:
+      return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
+    default:
+      abort ();
+    }
+  /* NOTREACHED */
+    return 0;
+}
+
+static int
+to_year (textint textyear)
+{
+  int year = textyear.value;
+
+  if (year < 0)
+    year = -year;
+
+  /* XPG4 suggests that years 00-68 map to 2000-2068, and
+     years 69-99 map to 1969-1999.  */
+  if (textyear.digits == 2)
+    year += year < 69 ? 2000 : 1900;
+
+  return year;
+}
+
+static table const *
+lookup_zone (parser_control const *pc, char const *name)
+{
+  table const *tp;
+
+  /* Try local zone abbreviations first; they're more likely to be right.  */
+  for (tp = pc->local_time_zone_table; tp->name; tp++)
+    if (strcmp (name, tp->name) == 0)
+      return tp;
+
+  for (tp = time_zone_table; tp->name; tp++)
+    if (strcmp (name, tp->name) == 0)
+      return tp;
+
+  return 0;
+}
+
+#if ! HAVE_TM_GMTOFF
+/* Yield the difference between *A and *B,
+   measured in seconds, ignoring leap seconds.
+   The body of this function is taken directly from the GNU C Library;
+   see src/strftime.c.  */
+static int
+tm_diff (struct tm const *a, struct tm const *b)
+{
+  /* Compute intervening leap days correctly even if year is negative.
+     Take care to avoid int overflow in leap day calculations,
+     but it's OK to assume that A and B are close to each other.  */
+  int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
+  int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
+  int a100 = a4 / 25 - (a4 % 25 < 0);
+  int b100 = b4 / 25 - (b4 % 25 < 0);
+  int a400 = a100 >> 2;
+  int b400 = b100 >> 2;
+  int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
+  int years = a->tm_year - b->tm_year;
+  int days = (365 * years + intervening_leap_days
+             + (a->tm_yday - b->tm_yday));
+  return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
+               + (a->tm_min - b->tm_min))
+         + (a->tm_sec - b->tm_sec));
+}
+#endif /* ! HAVE_TM_GMTOFF */
+
+static table const *
+lookup_word (parser_control const *pc, char *word)
+{
+  char *p;
+  char *q;
+  size_t wordlen;
+  table const *tp;
+  int i;
+  int abbrev;
+
+  /* Make it uppercase.  */
+  for (p = word; *p; p++)
+    if (ISLOWER ((unsigned char) *p))
+      *p = toupper ((unsigned char) *p);
+
+  for (tp = meridian_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* See if we have an abbreviation for a month. */
+  wordlen = strlen (word);
+  abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
+
+  for (tp = month_and_day_table; tp->name; tp++)
+    if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
+      return tp;
+
+  if ((tp = lookup_zone (pc, word)))
+    return tp;
+
+  if (strcmp (word, dst_table[0].name) == 0)
+    return dst_table;
+
+  for (tp = time_units_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* Strip off any plural and try the units table again. */
+  if (word[wordlen - 1] == 'S')
+    {
+      word[wordlen - 1] = '\0';
+      for (tp = time_units_table; tp->name; tp++)
+       if (strcmp (word, tp->name) == 0)
+         return tp;
+      word[wordlen - 1] = 'S'; /* For "this" in relative_time_table.  */
+    }
+
+  for (tp = relative_time_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* Military time zones. */
+  if (wordlen == 1)
+    for (tp = military_table; tp->name; tp++)
+      if (word[0] == tp->name[0])
+       return tp;
+
+  /* Drop out any periods and try the time zone table again. */
+  for (i = 0, p = q = word; (*p = *q); q++)
+    if (*q == '.')
+      i = 1;
+    else
+      p++;
+  if (i && (tp = lookup_zone (pc, word)))
+    return tp;
+
+  return 0;
+}
+
+static int
+yylex (YYSTYPE *lvalp, parser_control *pc)
+{
+  unsigned char c;
+  int count;
+
+  for (;;)
+    {
+      while (c = *pc->input, ISSPACE (c))
+       pc->input++;
+
+      if (ISDIGIT (c) || c == '-' || c == '+')
+       {
+         char const *p;
+         int sign;
+         int value;
+         if (c == '-' || c == '+')
+           {
+             sign = c == '-' ? -1 : 1;
+             c = *++pc->input;
+             if (! ISDIGIT (c))
+               /* skip the '-' sign */
+               continue;
+           }
+         else
+           sign = 0;
+         p = pc->input;
+         value = 0;
+         do
+           {
+             value = 10 * value + c - '0';
+             c = *++p;
+           }
+         while (ISDIGIT (c));
+         lvalp->textintval.value = sign < 0 ? -value : value;
+         lvalp->textintval.digits = p - pc->input;
+         pc->input = p;
+         return sign ? tSNUMBER : tUNUMBER;
+       }
+
+      if (ISALPHA (c))
+       {
+         char buff[20];
+         char *p = buff;
+         table const *tp;
+
+         do
+           {
+             if (p < buff + sizeof buff - 1)
+               *p++ = c;
+             c = *++pc->input;
+           }
+         while (ISALPHA (c) || c == '.');
+
+         *p = '\0';
+         tp = lookup_word (pc, buff);
+         if (! tp)
+           return '?';
+         lvalp->intval = tp->value;
+         return tp->type;
+       }
+
+      if (c != '(')
+       return *pc->input++;
+      count = 0;
+      do
+       {
+         c = *pc->input++;
+         if (c == '\0')
+           return c;
+         if (c == '(')
+           count++;
+         else if (c == ')')
+           count--;
+       }
+      while (count > 0);
+    }
+}
+
+/* Do nothing if the parser reports an error.  */
+static int
+yyerror (char *s ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+/* Parse a date/time string P.  Return the corresponding time_t value,
+   or (time_t) -1 if there is an error.  P can be an incomplete or
+   relative time specification; if so, use *NOW as the basis for the
+   returned time.  */
+time_t
+get_date (const char *p, const time_t *now)
+{
+  time_t Start = now ? *now : time (0);
+  struct tm *tmp = localtime (&Start);
+  struct tm tm;
+  struct tm tm0;
+  parser_control pc;
+
+  if (! tmp)
+    return -1;
+
+  pc.input = p;
+  pc.year.value = tmp->tm_year + TM_YEAR_BASE;
+  pc.year.digits = 4;
+  pc.month = tmp->tm_mon + 1;
+  pc.day = tmp->tm_mday;
+  pc.hour = tmp->tm_hour;
+  pc.minutes = tmp->tm_min;
+  pc.seconds = tmp->tm_sec;
+  tm.tm_isdst = tmp->tm_isdst;
+
+  pc.meridian = MER24;
+  pc.rel_seconds = 0;
+  pc.rel_minutes = 0;
+  pc.rel_hour = 0;
+  pc.rel_day = 0;
+  pc.rel_month = 0;
+  pc.rel_year = 0;
+  pc.dates_seen = 0;
+  pc.days_seen = 0;
+  pc.rels_seen = 0;
+  pc.times_seen = 0;
+  pc.local_zones_seen = 0;
+  pc.zones_seen = 0;
+
+#if HAVE_STRUCT_TM_TM_ZONE
+  pc.local_time_zone_table[0].name = tmp->tm_zone;
+  pc.local_time_zone_table[0].type = tLOCAL_ZONE;
+  pc.local_time_zone_table[0].value = tmp->tm_isdst;
+  pc.local_time_zone_table[1].name = 0;
+
+  /* Probe the names used in the next three calendar quarters, looking
+     for a tm_isdst different from the one we already have.  */
+  {
+    int quarter;
+    for (quarter = 1; quarter <= 3; quarter++)
+      {
+       time_t probe = Start + quarter * (90 * 24 * 60 * 60);
+       struct tm *probe_tm = localtime (&probe);
+       if (probe_tm && probe_tm->tm_zone
+           && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
+         {
+             {
+               pc.local_time_zone_table[1].name = probe_tm->tm_zone;
+               pc.local_time_zone_table[1].type = tLOCAL_ZONE;
+               pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
+               pc.local_time_zone_table[2].name = 0;
+             }
+           break;
+         }
+      }
+  }
+#else
+#if HAVE_TZNAME
+  {
+# ifndef tzname
+    extern char *tzname[];
+# endif
+    int i;
+    for (i = 0; i < 2; i++)
+      {
+       pc.local_time_zone_table[i].name = tzname[i];
+       pc.local_time_zone_table[i].type = tLOCAL_ZONE;
+       pc.local_time_zone_table[i].value = i;
+      }
+    pc.local_time_zone_table[i].name = 0;
+  }
+#else
+  pc.local_time_zone_table[0].name = 0;
+#endif
+#endif
+
+  if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
+      && ! strcmp (pc.local_time_zone_table[0].name,
+                  pc.local_time_zone_table[1].name))
+    {
+      /* This locale uses the same abbrevation for standard and
+        daylight times.  So if we see that abbreviation, we don't
+        know whether it's daylight time.  */
+      pc.local_time_zone_table[0].value = -1;
+      pc.local_time_zone_table[1].name = 0;
+    }
+
+  if (yyparse (&pc) != 0
+      || 1 < pc.times_seen || 1 < pc.dates_seen || 1 < pc.days_seen
+      || 1 < (pc.local_zones_seen + pc.zones_seen)
+      || (pc.local_zones_seen && 1 < pc.local_isdst))
+    return -1;
+
+  tm.tm_year = to_year (pc.year) - TM_YEAR_BASE + pc.rel_year;
+  tm.tm_mon = pc.month - 1 + pc.rel_month;
+  tm.tm_mday = pc.day + pc.rel_day;
+  if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
+    {
+      tm.tm_hour = to_hour (pc.hour, pc.meridian);
+      if (tm.tm_hour < 0)
+       return -1;
+      tm.tm_min = pc.minutes;
+      tm.tm_sec = pc.seconds;
+    }
+  else
+    {
+      tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+    }
+
+  /* Let mktime deduce tm_isdst if we have an absolute time stamp,
+     or if the relative time stamp mentions days, months, or years.  */
+  if (pc.dates_seen | pc.days_seen | pc.times_seen | pc.rel_day
+      | pc.rel_month | pc.rel_year)
+    tm.tm_isdst = -1;
+
+  /* But if the input explicitly specifies local time with or without
+     DST, give mktime that information.  */
+  if (pc.local_zones_seen)
+    tm.tm_isdst = pc.local_isdst;
+
+  tm0 = tm;
+
+  Start = mktime (&tm);
+
+  if (Start == (time_t) -1)
+    {
+
+      /* Guard against falsely reporting errors near the time_t boundaries
+         when parsing times in other time zones.  For example, if the min
+         time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
+         of UTC, then the min localtime value is 1970-01-01 08:00:00; if
+         we apply mktime to 1970-01-01 00:00:00 we will get an error, so
+         we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
+         zone by 24 hours to compensate.  This algorithm assumes that
+         there is no DST transition within a day of the time_t boundaries.  */
+      if (pc.zones_seen)
+       {
+         tm = tm0;
+         if (tm.tm_year <= EPOCH_YEAR - TM_YEAR_BASE)
+           {
+             tm.tm_mday++;
+             pc.time_zone += 24 * 60;
+           }
+         else
+           {
+             tm.tm_mday--;
+             pc.time_zone -= 24 * 60;
+           }
+         Start = mktime (&tm);
+       }
+
+      if (Start == (time_t) -1)
+       return Start;
+    }
+
+  if (pc.days_seen && ! pc.dates_seen)
+    {
+      tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
+                    + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
+      tm.tm_isdst = -1;
+      Start = mktime (&tm);
+      if (Start == (time_t) -1)
+       return Start;
+    }
+
+  if (pc.zones_seen)
+    {
+      int delta = pc.time_zone * 60;
+#ifdef HAVE_TM_GMTOFF
+      delta -= tm.tm_gmtoff;
+#else
+      struct tm *gmt = gmtime (&Start);
+      if (! gmt)
+       return -1;
+      delta -= tm_diff (&tm, gmt);
+#endif
+      if ((Start < Start - delta) != (delta < 0))
+       return -1;      /* time_t overflow */
+      Start -= delta;
+    }
+
+  /* Add relative hours, minutes, and seconds.  Ignore leap seconds;
+     i.e. "+ 10 minutes" means 600 seconds, even if one of them is a
+     leap second.  Typically this is not what the user wants, but it's
+     too hard to do it the other way, because the time zone indicator
+     must be applied before relative times, and if mktime is applied
+     again the time zone will be lost.  */
+  {
+    time_t t0 = Start;
+    long d1 = 60 * 60 * (long) pc.rel_hour;
+    time_t t1 = t0 + d1;
+    long d2 = 60 * (long) pc.rel_minutes;
+    time_t t2 = t1 + d2;
+    int d3 = pc.rel_seconds;
+    time_t t3 = t2 + d3;
+    if ((d1 / (60 * 60) ^ pc.rel_hour)
+       | (d2 / 60 ^ pc.rel_minutes)
+       | ((t0 + d1 < t0) ^ (d1 < 0))
+       | ((t1 + d2 < t1) ^ (d2 < 0))
+       | ((t2 + d3 < t2) ^ (d3 < 0)))
+      return -1;
+    Start = t3;
+  }
+
+  return Start;
+}
+
+#if TEST
+
+#include <stdio.h>
+
+int
+main (int ac, char **av)
+{
+  char buff[BUFSIZ];
+  time_t d;
+
+  printf ("Enter date, or blank line to exit.\n\t> ");
+  fflush (stdout);
+
+  buff[BUFSIZ - 1] = 0;
+  while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
+    {
+      d = get_date (buff, 0);
+      if (d == (time_t) -1)
+       printf ("Bad format - couldn't convert.\n");
+      else
+       printf ("%s", ctime (&d));
+      printf ("\t> ");
+      fflush (stdout);
+    }
+  return 0;
+}
+#endif /* defined TEST */
+
+
diff --git a/source3/modules/getdate.h b/source3/modules/getdate.h
new file mode 100644 (file)
index 0000000..674c474
--- /dev/null
@@ -0,0 +1,46 @@
+/*  Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
+
+   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, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+#  define PARAMS(Args) Args
+# else
+#  define PARAMS(Args) ()
+# endif
+#endif
+
+#ifdef vms
+# include <types.h>
+# include <time.h>
+#else
+# include <sys/types.h>
+# if TIME_WITH_SYS_TIME
+#  include <sys/time.h>
+#  include <time.h>
+# else
+#  if HAVE_SYS_TIME_H
+#   include <sys/time.h>
+#  else
+#   include <time.h>
+#  endif
+# endif
+#endif /* defined (vms) */
+
+time_t get_date PARAMS ((const char *p, const time_t *now));
diff --git a/source3/modules/getdate.y b/source3/modules/getdate.y
new file mode 100644 (file)
index 0000000..aab37f4
--- /dev/null
@@ -0,0 +1,1115 @@
+%{
+/* Parse a string into an internal time stamp.
+   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+
+   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, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Originally written by Steven M. Bellovin <smb@research.att.com> while
+   at the University of North Carolina at Chapel Hill.  Later tweaked by
+   a couple of people on Usenet.  Completely overhauled by Rich $alz
+   <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
+
+   Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
+   the right thing about local DST.  Unlike previous versions, this
+   version is reentrant.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+# ifdef HAVE_ALLOCA_H
+#  include <alloca.h>
+# endif
+#endif
+
+/* Since the code of getdate.y is not included in the Emacs executable
+   itself, there is no need to #define static in this file.  Even if
+   the code were included in the Emacs executable, it probably
+   wouldn't do any harm to #undef it here; this will only cause
+   problems if we try to write to a static variable, which I don't
+   think this code needs to do.  */
+#ifdef emacs
+# undef static
+#endif
+
+#include <ctype.h>
+
+#if HAVE_STDLIB_H
+# include <stdlib.h> /* for `free'; used by Bison 1.27 */
+#endif
+
+#if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii (c)
+#endif
+
+#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
+#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
+#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
+#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
+
+/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
+   - Its arg may be any int or unsigned int; it need not be an unsigned char.
+   - It's guaranteed to evaluate its argument exactly once.
+   - It's typically faster.
+   POSIX says that only '0' through '9' are digits.  Prefer ISDIGIT to
+   ISDIGIT_LOCALE unless it's important to use the locale's definition
+   of `digit' even when the host does not conform to POSIX.  */
+#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+
+#if STDC_HEADERS || HAVE_STRING_H
+# include <string.h>
+#endif
+
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+#endif
+
+#ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+#endif
+
+#define EPOCH_YEAR 1970
+#define TM_YEAR_BASE 1900
+
+#define HOUR(x) ((x) * 60)
+
+/* An integer value, and the number of digits in its textual
+   representation.  */
+typedef struct
+{
+  int value;
+  int digits;
+} textint;
+
+/* An entry in the lexical lookup table.  */
+typedef struct
+{
+  char const *name;
+  int type;
+  int value;
+} table;
+
+/* Meridian: am, pm, or 24-hour style.  */
+enum { MERam, MERpm, MER24 };
+
+/* Information passed to and from the parser.  */
+typedef struct
+{
+  /* The input string remaining to be parsed. */
+  const char *input;
+
+  /* N, if this is the Nth Tuesday.  */
+  int day_ordinal;
+
+  /* Day of week; Sunday is 0.  */
+  int day_number;
+
+  /* tm_isdst flag for the local zone.  */
+  int local_isdst;
+
+  /* Time zone, in minutes east of UTC.  */
+  int time_zone;
+
+  /* Style used for time.  */
+  int meridian;
+
+  /* Gregorian year, month, day, hour, minutes, and seconds.  */
+  textint year;
+  int month;
+  int day;
+  int hour;
+  int minutes;
+  int seconds;
+
+  /* Relative year, month, day, hour, minutes, and seconds.  */
+  int rel_year;
+  int rel_month;
+  int rel_day;
+  int rel_hour;
+  int rel_minutes;
+  int rel_seconds;
+
+  /* Counts of nonterminals of various flavors parsed so far.  */
+  int dates_seen;
+  int days_seen;
+  int local_zones_seen;
+  int rels_seen;
+  int times_seen;
+  int zones_seen;
+
+  /* Table of local time zone abbrevations, terminated by a null entry.  */
+  table local_time_zone_table[3];
+} parser_control;
+
+#define PC (* (parser_control *) parm)
+#define YYLEX_PARAM parm
+#define YYPARSE_PARAM parm
+
+static int yyerror ();
+static int yylex ();
+
+%}
+
+/* We want a reentrant parser.  */
+%pure_parser
+
+/* This grammar has 13 shift/reduce conflicts. */
+%expect 13
+
+%union
+{
+  int intval;
+  textint textintval;
+}
+
+%token tAGO tDST
+
+%token <intval> tDAY tDAY_UNIT tDAYZONE tHOUR_UNIT tLOCAL_ZONE tMERIDIAN
+%token <intval> tMINUTE_UNIT tMONTH tMONTH_UNIT tSEC_UNIT tYEAR_UNIT tZONE
+
+%token <textintval> tSNUMBER tUNUMBER
+
+%type <intval> o_merid
+
+%%
+
+spec:
+    /* empty */
+  | spec item
+  ;
+
+item:
+    time
+      { PC.times_seen++; }
+  | local_zone
+      { PC.local_zones_seen++; }
+  | zone
+      { PC.zones_seen++; }
+  | date
+      { PC.dates_seen++; }
+  | day
+      { PC.days_seen++; }
+  | rel
+      { PC.rels_seen++; }
+  | number
+  ;
+
+time:
+    tUNUMBER tMERIDIAN
+      {
+       PC.hour = $1.value;
+       PC.minutes = 0;
+       PC.seconds = 0;
+       PC.meridian = $2;
+      }
+  | tUNUMBER ':' tUNUMBER o_merid
+      {
+       PC.hour = $1.value;
+       PC.minutes = $3.value;
+       PC.seconds = 0;
+       PC.meridian = $4;
+      }
+  | tUNUMBER ':' tUNUMBER tSNUMBER
+      {
+       PC.hour = $1.value;
+       PC.minutes = $3.value;
+       PC.meridian = MER24;
+       PC.zones_seen++;
+       PC.time_zone = $4.value % 100 + ($4.value / 100) * 60;
+      }
+  | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid
+      {
+       PC.hour = $1.value;
+       PC.minutes = $3.value;
+       PC.seconds = $5.value;
+       PC.meridian = $6;
+      }
+  | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER
+      {
+       PC.hour = $1.value;
+       PC.minutes = $3.value;
+       PC.seconds = $5.value;
+       PC.meridian = MER24;
+       PC.zones_seen++;
+       PC.time_zone = $6.value % 100 + ($6.value / 100) * 60;
+      }
+  ;
+
+local_zone:
+    tLOCAL_ZONE
+      { PC.local_isdst = $1; }
+  | tLOCAL_ZONE tDST
+      { PC.local_isdst = $1 < 0 ? 1 : $1 + 1; }
+  ;
+
+zone:
+    tZONE
+      { PC.time_zone = $1; }
+  | tDAYZONE
+      { PC.time_zone = $1 + 60; }
+  | tZONE tDST
+      { PC.time_zone = $1 + 60; }
+  ;
+
+day:
+    tDAY
+      {
+       PC.day_ordinal = 1;
+       PC.day_number = $1;
+      }
+  | tDAY ','
+      {
+       PC.day_ordinal = 1;
+       PC.day_number = $1;
+      }
+  | tUNUMBER tDAY
+      {
+       PC.day_ordinal = $1.value;
+       PC.day_number = $2;
+      }
+  ;
+
+date:
+    tUNUMBER '/' tUNUMBER
+      {
+       PC.month = $1.value;
+       PC.day = $3.value;
+      }
+  | tUNUMBER '/' tUNUMBER '/' tUNUMBER
+      {
+       /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
+          otherwise as MM/DD/YY.
+          The goal in recognizing YYYY/MM/DD is solely to support legacy
+          machine-generated dates like those in an RCS log listing.  If
+          you want portability, use the ISO 8601 format.  */
+       if (4 <= $1.digits)
+         {
+           PC.year = $1;
+           PC.month = $3.value;
+           PC.day = $5.value;
+         }
+       else
+         {
+           PC.month = $1.value;
+           PC.day = $3.value;
+           PC.year = $5;
+         }
+      }
+  | tUNUMBER tSNUMBER tSNUMBER
+      {
+       /* ISO 8601 format.  YYYY-MM-DD.  */
+       PC.year = $1;
+       PC.month = -$2.value;
+       PC.day = -$3.value;
+      }
+  | tUNUMBER tMONTH tSNUMBER
+      {
+       /* e.g. 17-JUN-1992.  */
+       PC.day = $1.value;
+       PC.month = $2;
+       PC.year.value = -$3.value;
+       PC.year.digits = $3.digits;
+      }
+  | tMONTH tUNUMBER
+      {
+       PC.month = $1;
+       PC.day = $2.value;
+      }
+  | tMONTH tUNUMBER ',' tUNUMBER
+      {
+       PC.month = $1;
+       PC.day = $2.value;
+       PC.year = $4;
+      }
+  | tUNUMBER tMONTH
+      {
+       PC.day = $1.value;
+       PC.month = $2;
+      }
+  | tUNUMBER tMONTH tUNUMBER
+      {
+       PC.day = $1.value;
+       PC.month = $2;
+       PC.year = $3;
+      }
+  ;
+
+rel:
+    relunit tAGO
+      {
+       PC.rel_seconds = -PC.rel_seconds;
+       PC.rel_minutes = -PC.rel_minutes;
+       PC.rel_hour = -PC.rel_hour;
+       PC.rel_day = -PC.rel_day;
+       PC.rel_month = -PC.rel_month;
+       PC.rel_year = -PC.rel_year;
+      }
+  | relunit
+  ;
+
+relunit:
+    tUNUMBER tYEAR_UNIT
+      { PC.rel_year += $1.value * $2; }
+  | tSNUMBER tYEAR_UNIT
+      { PC.rel_year += $1.value * $2; }
+  | tYEAR_UNIT
+      { PC.rel_year += $1; }
+  | tUNUMBER tMONTH_UNIT
+      { PC.rel_month += $1.value * $2; }
+  | tSNUMBER tMONTH_UNIT
+      { PC.rel_month += $1.value * $2; }
+  | tMONTH_UNIT
+      { PC.rel_month += $1; }
+  | tUNUMBER tDAY_UNIT
+      { PC.rel_day += $1.value * $2; }
+  | tSNUMBER tDAY_UNIT
+      { PC.rel_day += $1.value * $2; }
+  | tDAY_UNIT
+      { PC.rel_day += $1; }
+  | tUNUMBER tHOUR_UNIT
+      { PC.rel_hour += $1.value * $2; }
+  | tSNUMBER tHOUR_UNIT
+      { PC.rel_hour += $1.value * $2; }
+  | tHOUR_UNIT
+      { PC.rel_hour += $1; }
+  | tUNUMBER tMINUTE_UNIT
+      { PC.rel_minutes += $1.value * $2; }
+  | tSNUMBER tMINUTE_UNIT
+      { PC.rel_minutes += $1.value * $2; }
+  | tMINUTE_UNIT
+      { PC.rel_minutes += $1; }
+  | tUNUMBER tSEC_UNIT
+      { PC.rel_seconds += $1.value * $2; }
+  | tSNUMBER tSEC_UNIT
+      { PC.rel_seconds += $1.value * $2; }
+  | tSEC_UNIT
+      { PC.rel_seconds += $1; }
+  ;
+
+number:
+    tUNUMBER
+      {
+       if (PC.dates_seen
+           && ! PC.rels_seen && (PC.times_seen || 2 < $1.digits))
+         PC.year = $1;
+       else
+         {
+           if (4 < $1.digits)
+             {
+               PC.dates_seen++;
+               PC.day = $1.value % 100;
+               PC.month = ($1.value / 100) % 100;
+               PC.year.value = $1.value / 10000;
+               PC.year.digits = $1.digits - 4;
+             }
+           else
+             {
+               PC.times_seen++;
+               if ($1.digits <= 2)
+                 {
+                   PC.hour = $1.value;
+                   PC.minutes = 0;
+                 }
+               else
+                 {
+                   PC.hour = $1.value / 100;
+                   PC.minutes = $1.value % 100;
+                 }
+               PC.seconds = 0;
+               PC.meridian = MER24;
+             }
+         }
+      }
+  ;
+
+o_merid:
+    /* empty */
+      { $$ = MER24; }
+  | tMERIDIAN
+      { $$ = $1; }
+  ;
+
+%%
+
+/* Include this file down here because bison inserts code above which
+   may define-away `const'.  We want the prototype for get_date to have
+   the same signature as the function definition.  */
+#include "modules/getdate.h"
+
+#ifndef gmtime
+struct tm *gmtime ();
+#endif
+#ifndef localtime
+struct tm *localtime ();
+#endif
+#ifndef mktime
+time_t mktime ();
+#endif
+
+static table const meridian_table[] =
+{
+  { "AM",   tMERIDIAN, MERam },
+  { "A.M.", tMERIDIAN, MERam },
+  { "PM",   tMERIDIAN, MERpm },
+  { "P.M.", tMERIDIAN, MERpm },
+  { 0, 0, 0 }
+};
+
+static table const dst_table[] =
+{
+  { "DST", tDST, 0 }
+};
+
+static table const month_and_day_table[] =
+{
+  { "JANUARY", tMONTH,  1 },
+  { "FEBRUARY",        tMONTH,  2 },
+  { "MARCH",   tMONTH,  3 },
+  { "APRIL",   tMONTH,  4 },
+  { "MAY",     tMONTH,  5 },
+  { "JUNE",    tMONTH,  6 },
+  { "JULY",    tMONTH,  7 },
+  { "AUGUST",  tMONTH,  8 },
+  { "SEPTEMBER",tMONTH,         9 },
+  { "SEPT",    tMONTH,  9 },
+  { "OCTOBER", tMONTH, 10 },
+  { "NOVEMBER",        tMONTH, 11 },
+  { "DECEMBER",        tMONTH, 12 },
+  { "SUNDAY",  tDAY,    0 },
+  { "MONDAY",  tDAY,    1 },
+  { "TUESDAY", tDAY,    2 },
+  { "TUES",    tDAY,    2 },
+  { "WEDNESDAY",tDAY,   3 },
+  { "WEDNES",  tDAY,    3 },
+  { "THURSDAY",        tDAY,    4 },
+  { "THUR",    tDAY,    4 },
+  { "THURS",   tDAY,    4 },
+  { "FRIDAY",  tDAY,    5 },
+  { "SATURDAY",        tDAY,    6 },
+  { 0, 0, 0 }
+};
+
+static table const time_units_table[] =
+{
+  { "YEAR",    tYEAR_UNIT,      1 },
+  { "MONTH",   tMONTH_UNIT,     1 },
+  { "FORTNIGHT",tDAY_UNIT,     14 },
+  { "WEEK",    tDAY_UNIT,       7 },
+  { "DAY",     tDAY_UNIT,       1 },
+  { "HOUR",    tHOUR_UNIT,      1 },
+  { "MINUTE",  tMINUTE_UNIT,    1 },
+  { "MIN",     tMINUTE_UNIT,    1 },
+  { "SECOND",  tSEC_UNIT,       1 },
+  { "SEC",     tSEC_UNIT,       1 },
+  { 0, 0, 0 }
+};
+
+/* Assorted relative-time words. */
+static table const relative_time_table[] =
+{
+  { "TOMORROW",        tMINUTE_UNIT,   24 * 60 },
+  { "YESTERDAY",tMINUTE_UNIT,  - (24 * 60) },
+  { "TODAY",   tMINUTE_UNIT,    0 },
+  { "NOW",     tMINUTE_UNIT,    0 },
+  { "LAST",    tUNUMBER,       -1 },
+  { "THIS",    tUNUMBER,        0 },
+  { "NEXT",    tUNUMBER,        1 },
+  { "FIRST",   tUNUMBER,        1 },
+/*{ "SECOND",  tUNUMBER,        2 }, */
+  { "THIRD",   tUNUMBER,        3 },
+  { "FOURTH",  tUNUMBER,        4 },
+  { "FIFTH",   tUNUMBER,        5 },
+  { "SIXTH",   tUNUMBER,        6 },
+  { "SEVENTH", tUNUMBER,        7 },
+  { "EIGHTH",  tUNUMBER,        8 },
+  { "NINTH",   tUNUMBER,        9 },
+  { "TENTH",   tUNUMBER,       10 },
+  { "ELEVENTH",        tUNUMBER,       11 },
+  { "TWELFTH", tUNUMBER,       12 },
+  { "AGO",     tAGO,            1 },
+  { 0, 0, 0 }
+};
+
+/* The time zone table.  This table is necessarily incomplete, as time
+   zone abbreviations are ambiguous; e.g. Australians interpret "EST"
+   as Eastern time in Australia, not as US Eastern Standard Time.
+   You cannot rely on getdate to handle arbitrary time zone
+   abbreviations; use numeric abbreviations like `-0500' instead.  */
+static table const time_zone_table[] =
+{
+  { "GMT",     tZONE,     HOUR ( 0) }, /* Greenwich Mean */
+  { "UT",      tZONE,     HOUR ( 0) }, /* Universal (Coordinated) */
+  { "UTC",     tZONE,     HOUR ( 0) },
+  { "WET",     tZONE,     HOUR ( 0) }, /* Western European */
+  { "WEST",    tDAYZONE,  HOUR ( 0) }, /* Western European Summer */
+  { "BST",     tDAYZONE,  HOUR ( 0) }, /* British Summer */
+  { "ART",     tZONE,    -HOUR ( 3) }, /* Argentina */
+  { "BRT",     tZONE,    -HOUR ( 3) }, /* Brazil */
+  { "BRST",    tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
+  { "NST",     tZONE,   -(HOUR ( 3) + 30) },   /* Newfoundland Standard */
+  { "NDT",     tDAYZONE,-(HOUR ( 3) + 30) },   /* Newfoundland Daylight */
+  { "AST",     tZONE,    -HOUR ( 4) }, /* Atlantic Standard */
+  { "ADT",     tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
+  { "CLT",     tZONE,    -HOUR ( 4) }, /* Chile */
+  { "CLST",    tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
+  { "EST",     tZONE,    -HOUR ( 5) }, /* Eastern Standard */
+  { "EDT",     tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
+  { "CST",     tZONE,    -HOUR ( 6) }, /* Central Standard */
+  { "CDT",     tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
+  { "MST",     tZONE,    -HOUR ( 7) }, /* Mountain Standard */
+  { "MDT",     tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
+  { "PST",     tZONE,    -HOUR ( 8) }, /* Pacific Standard */
+  { "PDT",     tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
+  { "AKST",    tZONE,    -HOUR ( 9) }, /* Alaska Standard */
+  { "AKDT",    tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
+  { "HST",     tZONE,    -HOUR (10) }, /* Hawaii Standard */
+  { "HAST",    tZONE,    -HOUR (10) }, /* Hawaii-Aleutian Standard */
+  { "HADT",    tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
+  { "SST",     tZONE,    -HOUR (12) }, /* Samoa Standard */
+  { "WAT",     tZONE,     HOUR ( 1) }, /* West Africa */
+  { "CET",     tZONE,     HOUR ( 1) }, /* Central European */
+  { "CEST",    tDAYZONE,  HOUR ( 1) }, /* Central European Summer */
+  { "MET",     tZONE,     HOUR ( 1) }, /* Middle European */
+  { "MEZ",     tZONE,     HOUR ( 1) }, /* Middle European */
+  { "MEST",    tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
+  { "MESZ",    tDAYZONE,  HOUR ( 1) }, /* Middle European Summer */
+  { "EET",     tZONE,     HOUR ( 2) }, /* Eastern European */
+  { "EEST",    tDAYZONE,  HOUR ( 2) }, /* Eastern European Summer */
+  { "CAT",     tZONE,     HOUR ( 2) }, /* Central Africa */
+  { "SAST",    tZONE,     HOUR ( 2) }, /* South Africa Standard */
+  { "EAT",     tZONE,     HOUR ( 3) }, /* East Africa */
+  { "MSK",     tZONE,     HOUR ( 3) }, /* Moscow */
+  { "MSD",     tDAYZONE,  HOUR ( 3) }, /* Moscow Daylight */
+  { "IST",     tZONE,    (HOUR ( 5) + 30) },   /* India Standard */
+  { "SGT",     tZONE,     HOUR ( 8) }, /* Singapore */
+  { "KST",     tZONE,     HOUR ( 9) }, /* Korea Standard */
+  { "JST",     tZONE,     HOUR ( 9) }, /* Japan Standard */
+  { "GST",     tZONE,     HOUR (10) }, /* Guam Standard */
+  { "NZST",    tZONE,     HOUR (12) }, /* New Zealand Standard */
+  { "NZDT",    tDAYZONE,  HOUR (12) }, /* New Zealand Daylight */
+  { 0, 0, 0  }
+};
+
+/* Military time zone table. */
+static table const military_table[] =
+{
+  { "A", tZONE,        -HOUR ( 1) },
+  { "B", tZONE,        -HOUR ( 2) },
+  { "C", tZONE,        -HOUR ( 3) },
+  { "D", tZONE,        -HOUR ( 4) },
+  { "E", tZONE,        -HOUR ( 5) },
+  { "F", tZONE,        -HOUR ( 6) },
+  { "G", tZONE,        -HOUR ( 7) },
+  { "H", tZONE,        -HOUR ( 8) },
+  { "I", tZONE,        -HOUR ( 9) },
+  { "K", tZONE,        -HOUR (10) },
+  { "L", tZONE,        -HOUR (11) },
+  { "M", tZONE,        -HOUR (12) },
+  { "N", tZONE,         HOUR ( 1) },
+  { "O", tZONE,         HOUR ( 2) },
+  { "P", tZONE,         HOUR ( 3) },
+  { "Q", tZONE,         HOUR ( 4) },
+  { "R", tZONE,         HOUR ( 5) },
+  { "S", tZONE,         HOUR ( 6) },
+  { "T", tZONE,         HOUR ( 7) },
+  { "U", tZONE,         HOUR ( 8) },
+  { "V", tZONE,         HOUR ( 9) },
+  { "W", tZONE,         HOUR (10) },
+  { "X", tZONE,         HOUR (11) },
+  { "Y", tZONE,         HOUR (12) },
+  { "Z", tZONE,         HOUR ( 0) },
+  { 0, 0, 0 }
+};
+
+\f
+
+static int
+to_hour (int hours, int meridian)
+{
+  switch (meridian)
+    {
+    case MER24:
+      return 0 <= hours && hours < 24 ? hours : -1;
+    case MERam:
+      return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
+    case MERpm:
+      return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
+    default:
+      abort ();
+    }
+  /* NOTREACHED */
+    return 0;
+}
+
+static int
+to_year (textint textyear)
+{
+  int year = textyear.value;
+
+  if (year < 0)
+    year = -year;
+
+  /* XPG4 suggests that years 00-68 map to 2000-2068, and
+     years 69-99 map to 1969-1999.  */
+  if (textyear.digits == 2)
+    year += year < 69 ? 2000 : 1900;
+
+  return year;
+}
+
+static table const *
+lookup_zone (parser_control const *pc, char const *name)
+{
+  table const *tp;
+
+  /* Try local zone abbreviations first; they're more likely to be right.  */
+  for (tp = pc->local_time_zone_table; tp->name; tp++)
+    if (strcmp (name, tp->name) == 0)
+      return tp;
+
+  for (tp = time_zone_table; tp->name; tp++)
+    if (strcmp (name, tp->name) == 0)
+      return tp;
+
+  return 0;
+}
+
+#if ! HAVE_TM_GMTOFF
+/* Yield the difference between *A and *B,
+   measured in seconds, ignoring leap seconds.
+   The body of this function is taken directly from the GNU C Library;
+   see src/strftime.c.  */
+static int
+tm_diff (struct tm const *a, struct tm const *b)
+{
+  /* Compute intervening leap days correctly even if year is negative.
+     Take care to avoid int overflow in leap day calculations,
+     but it's OK to assume that A and B are close to each other.  */
+  int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
+  int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
+  int a100 = a4 / 25 - (a4 % 25 < 0);
+  int b100 = b4 / 25 - (b4 % 25 < 0);
+  int a400 = a100 >> 2;
+  int b400 = b100 >> 2;
+  int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
+  int years = a->tm_year - b->tm_year;
+  int days = (365 * years + intervening_leap_days
+             + (a->tm_yday - b->tm_yday));
+  return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
+               + (a->tm_min - b->tm_min))
+         + (a->tm_sec - b->tm_sec));
+}
+#endif /* ! HAVE_TM_GMTOFF */
+
+static table const *
+lookup_word (parser_control const *pc, char *word)
+{
+  char *p;
+  char *q;
+  size_t wordlen;
+  table const *tp;
+  int i;
+  int abbrev;
+
+  /* Make it uppercase.  */
+  for (p = word; *p; p++)
+    if (ISLOWER ((unsigned char) *p))
+      *p = toupper ((unsigned char) *p);
+
+  for (tp = meridian_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* See if we have an abbreviation for a month. */
+  wordlen = strlen (word);
+  abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
+
+  for (tp = month_and_day_table; tp->name; tp++)
+    if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
+      return tp;
+
+  if ((tp = lookup_zone (pc, word)))
+    return tp;
+
+  if (strcmp (word, dst_table[0].name) == 0)
+    return dst_table;
+
+  for (tp = time_units_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* Strip off any plural and try the units table again. */
+  if (word[wordlen - 1] == 'S')
+    {
+      word[wordlen - 1] = '\0';
+      for (tp = time_units_table; tp->name; tp++)
+       if (strcmp (word, tp->name) == 0)
+         return tp;
+      word[wordlen - 1] = 'S'; /* For "this" in relative_time_table.  */
+    }
+
+  for (tp = relative_time_table; tp->name; tp++)
+    if (strcmp (word, tp->name) == 0)
+      return tp;
+
+  /* Military time zones. */
+  if (wordlen == 1)
+    for (tp = military_table; tp->name; tp++)
+      if (word[0] == tp->name[0])
+       return tp;
+
+  /* Drop out any periods and try the time zone table again. */
+  for (i = 0, p = q = word; (*p = *q); q++)
+    if (*q == '.')
+      i = 1;
+    else
+      p++;
+  if (i && (tp = lookup_zone (pc, word)))
+    return tp;
+
+  return 0;
+}
+
+static int
+yylex (YYSTYPE *lvalp, parser_control *pc)
+{
+  unsigned char c;
+  int count;
+
+  for (;;)
+    {
+      while (c = *pc->input, ISSPACE (c))
+       pc->input++;
+
+      if (ISDIGIT (c) || c == '-' || c == '+')
+       {
+         char const *p;
+         int sign;
+         int value;
+         if (c == '-' || c == '+')
+           {
+             sign = c == '-' ? -1 : 1;
+             c = *++pc->input;
+             if (! ISDIGIT (c))
+               /* skip the '-' sign */
+               continue;
+           }
+         else
+           sign = 0;
+         p = pc->input;
+         value = 0;
+         do
+           {
+             value = 10 * value + c - '0';
+             c = *++p;
+           }
+         while (ISDIGIT (c));
+         lvalp->textintval.value = sign < 0 ? -value : value;
+         lvalp->textintval.digits = p - pc->input;
+         pc->input = p;
+         return sign ? tSNUMBER : tUNUMBER;
+       }
+
+      if (ISALPHA (c))
+       {
+         char buff[20];
+         char *p = buff;
+         table const *tp;
+
+         do
+           {
+             if (p < buff + sizeof buff - 1)
+               *p++ = c;
+             c = *++pc->input;
+           }
+         while (ISALPHA (c) || c == '.');
+
+         *p = '\0';
+         tp = lookup_word (pc, buff);
+         if (! tp)
+           return '?';
+         lvalp->intval = tp->value;
+         return tp->type;
+       }
+
+      if (c != '(')
+       return *pc->input++;
+      count = 0;
+      do
+       {
+         c = *pc->input++;
+         if (c == '\0')
+           return c;
+         if (c == '(')
+           count++;
+         else if (c == ')')
+           count--;
+       }
+      while (count > 0);
+    }
+}
+
+/* Do nothing if the parser reports an error.  */
+static int
+yyerror (char *s ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+/* Parse a date/time string P.  Return the corresponding time_t value,
+   or (time_t) -1 if there is an error.  P can be an incomplete or
+   relative time specification; if so, use *NOW as the basis for the
+   returned time.  */
+time_t
+get_date (const char *p, const time_t *now)
+{
+  time_t Start = now ? *now : time (0);
+  struct tm *tmp = localtime (&Start);
+  struct tm tm;
+  struct tm tm0;
+  parser_control pc;
+
+  if (! tmp)
+    return -1;
+
+  pc.input = p;
+  pc.year.value = tmp->tm_year + TM_YEAR_BASE;
+  pc.year.digits = 4;
+  pc.month = tmp->tm_mon + 1;
+  pc.day = tmp->tm_mday;
+  pc.hour = tmp->tm_hour;
+  pc.minutes = tmp->tm_min;
+  pc.seconds = tmp->tm_sec;
+  tm.tm_isdst = tmp->tm_isdst;
+
+  pc.meridian = MER24;
+  pc.rel_seconds = 0;
+  pc.rel_minutes = 0;
+  pc.rel_hour = 0;
+  pc.rel_day = 0;
+  pc.rel_month = 0;
+  pc.rel_year = 0;
+  pc.dates_seen = 0;
+  pc.days_seen = 0;
+  pc.rels_seen = 0;
+  pc.times_seen = 0;
+  pc.local_zones_seen = 0;
+  pc.zones_seen = 0;
+
+#if HAVE_STRUCT_TM_TM_ZONE
+  pc.local_time_zone_table[0].name = tmp->tm_zone;
+  pc.local_time_zone_table[0].type = tLOCAL_ZONE;
+  pc.local_time_zone_table[0].value = tmp->tm_isdst;
+  pc.local_time_zone_table[1].name = 0;
+
+  /* Probe the names used in the next three calendar quarters, looking
+     for a tm_isdst different from the one we already have.  */
+  {
+    int quarter;
+    for (quarter = 1; quarter <= 3; quarter++)
+      {
+       time_t probe = Start + quarter * (90 * 24 * 60 * 60);
+       struct tm *probe_tm = localtime (&probe);
+       if (probe_tm && probe_tm->tm_zone
+           && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
+         {
+             {
+               pc.local_time_zone_table[1].name = probe_tm->tm_zone;
+               pc.local_time_zone_table[1].type = tLOCAL_ZONE;
+               pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
+               pc.local_time_zone_table[2].name = 0;
+             }
+           break;
+         }
+      }
+  }
+#else
+#if HAVE_TZNAME
+  {
+# ifndef tzname
+    extern char *tzname[];
+# endif
+    int i;
+    for (i = 0; i < 2; i++)
+      {
+       pc.local_time_zone_table[i].name = tzname[i];
+       pc.local_time_zone_table[i].type = tLOCAL_ZONE;
+       pc.local_time_zone_table[i].value = i;
+      }
+    pc.local_time_zone_table[i].name = 0;
+  }
+#else
+  pc.local_time_zone_table[0].name = 0;
+#endif
+#endif
+
+  if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
+      && ! strcmp (pc.local_time_zone_table[0].name,
+                  pc.local_time_zone_table[1].name))
+    {
+      /* This locale uses the same abbrevation for standard and
+        daylight times.  So if we see that abbreviation, we don't
+        know whether it's daylight time.  */
+      pc.local_time_zone_table[0].value = -1;
+      pc.local_time_zone_table[1].name = 0;
+    }
+
+  if (yyparse (&pc) != 0
+      || 1 < pc.times_seen || 1 < pc.dates_seen || 1 < pc.days_seen
+      || 1 < (pc.local_zones_seen + pc.zones_seen)
+      || (pc.local_zones_seen && 1 < pc.local_isdst))
+    return -1;
+
+  tm.tm_year = to_year (pc.year) - TM_YEAR_BASE + pc.rel_year;
+  tm.tm_mon = pc.month - 1 + pc.rel_month;
+  tm.tm_mday = pc.day + pc.rel_day;
+  if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
+    {
+      tm.tm_hour = to_hour (pc.hour, pc.meridian);
+      if (tm.tm_hour < 0)
+       return -1;
+      tm.tm_min = pc.minutes;
+      tm.tm_sec = pc.seconds;
+    }
+  else
+    {
+      tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+    }
+
+  /* Let mktime deduce tm_isdst if we have an absolute time stamp,
+     or if the relative time stamp mentions days, months, or years.  */
+  if (pc.dates_seen | pc.days_seen | pc.times_seen | pc.rel_day
+      | pc.rel_month | pc.rel_year)
+    tm.tm_isdst = -1;
+
+  /* But if the input explicitly specifies local time with or without
+     DST, give mktime that information.  */
+  if (pc.local_zones_seen)
+    tm.tm_isdst = pc.local_isdst;
+
+  tm0 = tm;
+
+  Start = mktime (&tm);
+
+  if (Start == (time_t) -1)
+    {
+
+      /* Guard against falsely reporting errors near the time_t boundaries
+         when parsing times in other time zones.  For example, if the min
+         time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
+         of UTC, then the min localtime value is 1970-01-01 08:00:00; if
+         we apply mktime to 1970-01-01 00:00:00 we will get an error, so
+         we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
+         zone by 24 hours to compensate.  This algorithm assumes that
+         there is no DST transition within a day of the time_t boundaries.  */
+      if (pc.zones_seen)
+       {
+         tm = tm0;
+         if (tm.tm_year <= EPOCH_YEAR - TM_YEAR_BASE)
+           {
+             tm.tm_mday++;
+             pc.time_zone += 24 * 60;
+           }
+         else
+           {
+             tm.tm_mday--;
+             pc.time_zone -= 24 * 60;
+           }
+         Start = mktime (&tm);
+       }
+
+      if (Start == (time_t) -1)
+       return Start;
+    }
+
+  if (pc.days_seen && ! pc.dates_seen)
+    {
+      tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
+                    + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
+      tm.tm_isdst = -1;
+      Start = mktime (&tm);
+      if (Start == (time_t) -1)
+       return Start;
+    }
+
+  if (pc.zones_seen)
+    {
+      int delta = pc.time_zone * 60;
+#ifdef HAVE_TM_GMTOFF
+      delta -= tm.tm_gmtoff;
+#else
+      struct tm *gmt = gmtime (&Start);
+      if (! gmt)
+       return -1;
+      delta -= tm_diff (&tm, gmt);
+#endif
+      if ((Start < Start - delta) != (delta < 0))
+       return -1;      /* time_t overflow */
+      Start -= delta;
+    }
+
+  /* Add relative hours, minutes, and seconds.  Ignore leap seconds;
+     i.e. "+ 10 minutes" means 600 seconds, even if one of them is a
+     leap second.  Typically this is not what the user wants, but it's
+     too hard to do it the other way, because the time zone indicator
+     must be applied before relative times, and if mktime is applied
+     again the time zone will be lost.  */
+  {
+    time_t t0 = Start;
+    long d1 = 60 * 60 * (long) pc.rel_hour;
+    time_t t1 = t0 + d1;
+    long d2 = 60 * (long) pc.rel_minutes;
+    time_t t2 = t1 + d2;
+    int d3 = pc.rel_seconds;
+    time_t t3 = t2 + d3;
+    if ((d1 / (60 * 60) ^ pc.rel_hour)
+       | (d2 / 60 ^ pc.rel_minutes)
+       | ((t0 + d1 < t0) ^ (d1 < 0))
+       | ((t1 + d2 < t1) ^ (d2 < 0))
+       | ((t2 + d3 < t2) ^ (d3 < 0)))
+      return -1;
+    Start = t3;
+  }
+
+  return Start;
+}
+
+#if TEST
+
+#include <stdio.h>
+
+int
+main (int ac, char **av)
+{
+  char buff[BUFSIZ];
+  time_t d;
+
+  printf ("Enter date, or blank line to exit.\n\t> ");
+  fflush (stdout);
+
+  buff[BUFSIZ - 1] = 0;
+  while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
+    {
+      d = get_date (buff, 0);
+      if (d == (time_t) -1)
+       printf ("Bad format - couldn't convert.\n");
+      else
+       printf ("%s", ctime (&d));
+      printf ("\t> ");
+      fflush (stdout);
+    }
+  return 0;
+}
+#endif /* defined TEST */
diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c
new file mode 100644 (file)
index 0000000..0526276
--- /dev/null
@@ -0,0 +1,448 @@
+/* 
+ * CAP VFS module for Samba 3.x Version 0.3
+ *
+ * Copyright (C) Tim Potter, 1999-2000
+ * Copyright (C) Alexander Bokovoy, 2002-2003
+ * Copyright (C) Stefan (metze) Metzmacher, 2003
+ * Copyright (C) TAKAHASHI Motonobu (monyo), 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
+ * (at your option) any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+
+#include "includes.h"
+
+/* cap functions */
+static char *capencode(char *to, const char *from);
+static char *capdecode(char *to, const char *from);
+
+static SMB_BIG_UINT cap_disk_free(vfs_handle_struct *handle, connection_struct *conn, const char *path,
+       BOOL small_query, SMB_BIG_UINT *bsize,
+       SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+{
+        pstring cappath;
+        capencode(cappath, path);
+       return SMB_VFS_NEXT_DISK_FREE(handle, conn, cappath, small_query, bsize, 
+                                        dfree, dsize);
+}
+
+static DIR *cap_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname)
+{
+        pstring capname;
+        capencode(capname, fname);
+       return SMB_VFS_NEXT_OPENDIR(handle, conn, capname);
+}
+
+static struct dirent *cap_readdir(vfs_handle_struct *handle, connection_struct *conn, DIR *dirp)
+{
+        struct dirent *result;
+       DEBUG(3,("cap: cap_readdir\n"));
+       result = SMB_VFS_NEXT_READDIR(handle, conn, dirp);
+       if (result) {
+         DEBUG(3,("cap: cap_readdir: %s\n", result->d_name));
+         capdecode(result->d_name, result->d_name);
+        }
+        return result;
+}
+
+static int cap_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode)
+{
+       pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_MKDIR(handle, conn, cappath, mode);
+}
+
+static int cap_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path)
+{
+        pstring cappath;
+        capencode(cappath, path);
+       return SMB_VFS_NEXT_RMDIR(handle, conn, cappath);
+}
+
+static int cap_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode)
+{
+        pstring capname;
+       DEBUG(3,("cap: cap_open for %s\n", fname));
+       capencode(capname, fname);
+       return SMB_VFS_NEXT_OPEN(handle, conn, capname, flags, mode);
+}
+
+static int cap_rename(vfs_handle_struct *handle, connection_struct *conn, const char *old, const char *new)
+{
+       pstring capold, capnew;
+       capencode(capold, old);
+       capencode(capnew, new);
+
+       return SMB_VFS_NEXT_RENAME(handle, conn, capold, capnew);
+}
+
+static int cap_stat(vfs_handle_struct *handle, connection_struct *conn, const char *fname, SMB_STRUCT_STAT *sbuf)
+{
+        pstring capname;
+       capencode(capname, fname);
+       return SMB_VFS_NEXT_STAT(handle, conn, capname, sbuf);
+}
+
+static int cap_lstat(vfs_handle_struct *handle, connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf)
+{
+       pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_LSTAT(handle, conn, cappath, sbuf);
+}
+
+static int cap_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path)
+{
+       pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_UNLINK(handle, conn, cappath);
+}
+
+static int cap_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_CHMOD(handle, conn, cappath, mode);
+}
+
+static int cap_chown(vfs_handle_struct *handle, connection_struct *conn, const char *path, uid_t uid, gid_t gid)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_CHOWN(handle, conn, cappath, uid, gid);
+}
+
+static int cap_chdir(vfs_handle_struct *handle, connection_struct *conn, const char *path)
+{
+        pstring cappath;
+       DEBUG(3,("cap: cap_chdir for %s\n", path));
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_CHDIR(handle, conn, cappath);
+}
+
+static int cap_utime(vfs_handle_struct *handle, connection_struct *conn, const char *path, struct utimbuf *times)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_UTIME(handle, conn, cappath, times);
+}
+
+
+static BOOL cap_symlink(vfs_handle_struct *handle, connection_struct *conn, const char *oldpath, const char *newpath)
+{
+        pstring capoldpath, capnewpath;
+        capencode(capoldpath, oldpath);
+        capencode(capnewpath, newpath);
+       return SMB_VFS_NEXT_SYMLINK(handle, conn, capoldpath, capnewpath);
+}
+
+static BOOL cap_readlink(vfs_handle_struct *handle, connection_struct *conn, const char *path, char *buf, size_t bufsiz)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_READLINK(handle, conn, cappath, buf, bufsiz);
+}
+
+static int cap_link(vfs_handle_struct *handle, connection_struct *conn, const char *oldpath, const char *newpath)
+{
+        pstring capoldpath, capnewpath;
+        capencode(capoldpath, oldpath);
+        capencode(capnewpath, newpath);
+       return SMB_VFS_NEXT_LINK(handle, conn, capoldpath, capnewpath);
+}
+
+static int cap_mknod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode, SMB_DEV_T dev)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_MKNOD(handle, conn, cappath, mode, dev);
+}
+
+static char *cap_realpath(vfs_handle_struct *handle, connection_struct *conn, const char *path, char *resolved_path)
+{
+        /* monyo need capencode'ed and capdecode'ed? */
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_REALPATH(handle, conn, path, resolved_path);
+}
+
+static BOOL cap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, struct security_descriptor_info *psd)
+{
+        pstring capname;
+       capencode(capname, name);
+       return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, capname, security_info_sent, psd);
+}
+
+static int cap_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *name, mode_t mode)
+{
+        pstring capname;
+       capencode(capname, name);
+
+       /* If the underlying VFS doesn't have ACL support... */
+       if (!handle->vfs_next.ops.chmod_acl) {
+               errno = ENOSYS;
+               return -1;
+       }
+       return SMB_VFS_NEXT_CHMOD_ACL(handle, conn, capname, mode);
+}
+
+static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle, connection_struct *conn, const char *path_p, SMB_ACL_TYPE_T type)
+{
+        pstring cappath_p;
+       capencode(cappath_p, path_p);
+       return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, conn, cappath_p, type);
+}
+
+static int cap_sys_acl_set_file(vfs_handle_struct *handle, connection_struct *conn, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
+{
+        pstring capname;
+       capencode(capname, name);
+       return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, conn, capname, acltype, theacl);
+}
+
+static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, connection_struct *conn, const char *path)
+{
+        pstring cappath;
+       capencode(cappath, path);
+       return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, conn, cappath);
+}
+
+static ssize_t cap_getxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, void *value, size_t size)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_GETXATTR(handle, conn, cappath, capname, value, size);
+}
+
+static ssize_t cap_lgetxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, void *value, size_t
+size)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_LGETXATTR(handle, conn, cappath, capname, value, size);
+}
+
+static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, void *value, size_t size)
+{
+        pstring capname;
+       capencode(capname, name);
+        return SMB_VFS_NEXT_FGETXATTR(handle, fsp, fd, capname, value, size);
+}
+
+static ssize_t cap_listxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, char *list, size_t size)
+{
+        pstring cappath;
+       capencode(cappath, path);
+        return SMB_VFS_NEXT_LISTXATTR(handle, conn, cappath, list, size);
+}
+
+static ssize_t cap_llistxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, char *list, size_t size)
+{
+        pstring cappath;
+       capencode(cappath, path);
+        return SMB_VFS_NEXT_LLISTXATTR(handle, conn, cappath, list, size);
+}
+
+static int cap_removexattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_REMOVEXATTR(handle, conn, cappath, capname);
+}
+
+static int cap_lremovexattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_LREMOVEXATTR(handle, conn, cappath, capname);
+}
+
+static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name)
+{
+        pstring capname;
+       capencode(capname, name);
+        return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, fd, capname);
+}
+
+static int cap_setxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, const void *value, size_t size, int flags)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_SETXATTR(handle, conn, cappath, capname, value, size, flags);
+}
+
+static int cap_lsetxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, const void *value, size_t size, int flags)
+{
+        pstring cappath, capname;
+       capencode(cappath, path);
+       capencode(capname, name);
+        return SMB_VFS_NEXT_LSETXATTR(handle, conn, cappath, capname, value, size, flags);
+}
+
+static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, const void *value, size_t size, int flags)
+{
+        pstring capname;
+       capencode(capname, name);
+        return SMB_VFS_NEXT_FSETXATTR(handle, fsp, fd, capname, value, size, flags);
+}
+
+/* VFS operations structure */
+
+static vfs_op_tuple cap_op_tuples[] = {
+
+       /* Disk operations */
+
+       {SMB_VFS_OP(cap_disk_free),                     SMB_VFS_OP_DISK_FREE,           SMB_VFS_LAYER_TRANSPARENT},
+       
+       /* Directory operations */
+
+       {SMB_VFS_OP(cap_opendir),                       SMB_VFS_OP_OPENDIR,             SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_readdir),                       SMB_VFS_OP_READDIR,             SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_mkdir),                 SMB_VFS_OP_MKDIR,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_rmdir),                 SMB_VFS_OP_RMDIR,               SMB_VFS_LAYER_TRANSPARENT},
+
+       /* File operations */
+
+       {SMB_VFS_OP(cap_open),                          SMB_VFS_OP_OPEN,                SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_rename),                        SMB_VFS_OP_RENAME,              SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_stat),                          SMB_VFS_OP_STAT,                SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_lstat),                 SMB_VFS_OP_LSTAT,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_unlink),                        SMB_VFS_OP_UNLINK,              SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_chmod),                 SMB_VFS_OP_CHMOD,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_chown),                 SMB_VFS_OP_CHOWN,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_chdir),                 SMB_VFS_OP_CHDIR,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_utime),                 SMB_VFS_OP_UTIME,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_symlink),                       SMB_VFS_OP_SYMLINK,             SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_readlink),                      SMB_VFS_OP_READLINK,            SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_link),                          SMB_VFS_OP_LINK,                SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_mknod),                 SMB_VFS_OP_MKNOD,               SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_realpath),                      SMB_VFS_OP_REALPATH,            SMB_VFS_LAYER_TRANSPARENT},
+
+       /* NT File ACL operations */
+
+       {SMB_VFS_OP(cap_set_nt_acl),                    SMB_VFS_OP_SET_NT_ACL,          SMB_VFS_LAYER_TRANSPARENT},
+
+       /* POSIX ACL operations */
+
+       {SMB_VFS_OP(cap_chmod_acl),                     SMB_VFS_OP_CHMOD_ACL,           SMB_VFS_LAYER_TRANSPARENT},
+
+       {SMB_VFS_OP(cap_sys_acl_get_file),              SMB_VFS_OP_SYS_ACL_GET_FILE,            SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_sys_acl_set_file),              SMB_VFS_OP_SYS_ACL_SET_FILE,            SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_sys_acl_delete_def_file),       SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,     SMB_VFS_LAYER_TRANSPARENT},
+       
+       /* EA operations. */
+       {SMB_VFS_OP(cap_getxattr),                      SMB_VFS_OP_GETXATTR,                    SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_lgetxattr),                     SMB_VFS_OP_LGETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_fgetxattr),                     SMB_VFS_OP_FGETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_listxattr),                     SMB_VFS_OP_LISTXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_llistxattr),                    SMB_VFS_OP_LLISTXATTR,                  SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_removexattr),                   SMB_VFS_OP_REMOVEXATTR,                 SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_lremovexattr),                  SMB_VFS_OP_LREMOVEXATTR,                SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_fremovexattr),                  SMB_VFS_OP_FREMOVEXATTR,                SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_setxattr),                      SMB_VFS_OP_SETXATTR,                    SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_lsetxattr),                     SMB_VFS_OP_LSETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(cap_fsetxattr),                     SMB_VFS_OP_FSETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
+
+       {NULL,                                          SMB_VFS_OP_NOOP,                        SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_cap_init(void)
+{
+       return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "cap", cap_op_tuples);
+}
+
+/* For CAP functions */
+#define hex_tag ':'
+#define hex2bin(c)             hex2bin_table[(unsigned char)(c)]
+#define bin2hex(c)             bin2hex_table[(unsigned char)(c)]
+#define is_hex(s)              ((s)[0] == hex_tag)
+
+static unsigned char hex2bin_table[256] = {
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
+0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x40 */
+0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
+0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x60 */
+0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  /* 0xf0 */
+};
+static unsigned char bin2hex_table[256] = "0123456789abcdef";
+
+/*******************************************************************
+  original code -> ":xx"  - CAP format
+********************************************************************/
+static char *capencode(char *to, const char *from)
+{
+  pstring cvtbuf;
+  char *out;
+
+  if (to == from) {
+    from = pstrcpy ((char *) cvtbuf, from);
+  }
+
+  for (out = to; *from && (out - to < sizeof(pstring)-7);) {
+    /* buffer husoku error */
+    if ((unsigned char)*from >= 0x80) {
+      *out++ = hex_tag;
+      *out++ = bin2hex (((*from)>>4)&0x0f);
+      *out++ = bin2hex ((*from)&0x0f);
+      from++;
+    } 
+    else {
+      *out++ = *from++;
+    }
+  }
+  *out = '\0';
+  return to;
+}
+
+/*******************************************************************
+  CAP -> original code
+********************************************************************/
+/* ":xx" -> a byte */
+static char *capdecode(char *to, const char *from)
+{
+  pstring cvtbuf;
+  char *out;
+
+  if (to == from) {
+    from = pstrcpy ((char *) cvtbuf, from);
+  }
+  for (out = to; *from && (out - to < sizeof(pstring)-3);) {
+    if (is_hex(from)) {
+      *out++ = (hex2bin (from[1])<<4) | (hex2bin (from[2]));
+      from += 3;
+    } else {
+      *out++ = *from++;
+    }
+  }
+  *out = '\0';
+  return to;
+}
diff --git a/source3/modules/vfs_default_quota.c b/source3/modules/vfs_default_quota.c
new file mode 100644 (file)
index 0000000..1294a51
--- /dev/null
@@ -0,0 +1,180 @@
+/* 
+ * Store default Quotas in a specified quota record
+ *
+ * Copyright (C) Stefan (metze) Metzmacher 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
+ * (at your option) any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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.
+ */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_VFS
+
+#define DEFAULT_QUOTA_NAME "default_quota"
+
+#define DEFAULT_QUOTA_UID_DEFAULT              0
+#define DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT      True
+#define DEFAULT_QUOTA_GID_DEFAULT              0
+#define DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT      True
+
+#define DEFAULT_QUOTA_UID(handle) \
+       (uid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid",DEFAULT_QUOTA_UID_DEFAULT)
+
+#define DEFAULT_QUOTA_UID_NOLIMIT(handle) \
+       lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"uid nolimit",DEFAULT_QUOTA_UID_NOLIMIT_DEFAULT)
+
+#define DEFAULT_QUOTA_GID(handle) \
+       (gid_t)lp_parm_int(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid",DEFAULT_QUOTA_GID_DEFAULT)
+
+#define DEFAULT_QUOTA_GID_NOLIMIT(handle) \
+       lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT)
+
+static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
+{
+       int ret = -1;
+
+       if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, dq))!=0) {
+               return ret;
+       }
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use id.uid == 0 for default quotas */
+                       if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
+                               DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
+                               SMB_QUOTAS_SET_NO_LIMIT(dq);
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       /* we use id.gid == 0 for default quotas */
+                       if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
+                               DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
+                               SMB_QUOTAS_SET_NO_LIMIT(dq);
+                       }
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       {
+                               unid_t qid;
+                               uint32 qflags = dq->qflags;
+                               qid.uid = DEFAULT_QUOTA_UID(handle);
+                               SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
+                               dq->qflags = qflags;
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_FS_QUOTA_TYPE:
+                       {
+                               unid_t qid;
+                               uint32 qflags = dq->qflags;
+                               qid.gid = DEFAULT_QUOTA_GID(handle);
+                               SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
+                               dq->qflags = qflags;
+                       }
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               default:
+                       errno = ENOSYS;
+                       return -1;
+                       break;
+       }
+
+       return ret;
+}
+
+static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq)
+{
+       int ret = -1;
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       /* we use id.uid == 0 for default quotas */
+                       if ((id.uid==DEFAULT_QUOTA_UID(handle)) &&
+                               DEFAULT_QUOTA_UID_NOLIMIT(handle)) {
+                               return -1;
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       /* we use id.gid == 0 for default quotas */
+                       if ((id.gid==DEFAULT_QUOTA_GID(handle)) &&
+                               DEFAULT_QUOTA_GID_NOLIMIT(handle)) {
+                               return -1;
+                       }
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_FS_QUOTA_TYPE:
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               default:
+                       errno = ENOSYS;
+                       return -1;
+                       break;
+       }
+
+       if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, dq))!=0) {
+               return ret;
+       }
+
+       switch (qtype) {
+               case SMB_USER_QUOTA_TYPE:
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_QUOTA_TYPE:
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               case SMB_USER_FS_QUOTA_TYPE:
+                       {
+                               unid_t qid;
+                               qid.uid = DEFAULT_QUOTA_UID(handle);
+                               ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq);
+                       }
+                       break;
+#ifdef HAVE_GROUP_QUOTA
+               case SMB_GROUP_FS_QUOTA_TYPE:
+                       {
+                               unid_t qid;
+                               qid.gid = DEFAULT_QUOTA_GID(handle);
+                               ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq);
+                       }
+                       break;
+#endif /* HAVE_GROUP_QUOTA */
+               default:
+                       errno = ENOSYS;
+                       return -1;
+                       break;
+       }
+
+       return ret;
+}
+
+/* VFS operations structure */
+
+static vfs_op_tuple default_quota_ops[] = {    
+       {SMB_VFS_OP(default_quota_get_quota),   SMB_VFS_OP_GET_QUOTA,   SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(default_quota_set_quota),   SMB_VFS_OP_SET_QUOTA,   SMB_VFS_LAYER_TRANSPARENT},
+
+       {SMB_VFS_OP(NULL),                      SMB_VFS_OP_NOOP,        SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_default_quota_init(void)
+{
+       return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops);
+}
diff --git a/source3/modules/vfs_readonly.c b/source3/modules/vfs_readonly.c
new file mode 100644 (file)
index 0000000..ee9e40c
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+   Unix SMB/Netbios implementation.
+   Version 1.9.
+   VFS module to perform read-only limitation based on a time period
+   Copyright (C) Alexander Bokovoy 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
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+
+   This work was sponsored by Optifacio Software Services, Inc.
+*/
+
+#include "includes.h"
+#include "getdate.h"
+
+/*
+  This module performs a read-only limitation for specified share 
+  (or all of them if it is loaded in a [global] section) based on period
+  definition in smb.conf. You can stack this module multiple times under 
+  different names to get multiple limit intervals.
+
+  The module uses get_date() function from coreutils' date utility to parse
+  specified dates according to date(1) rules. Look into info page for date(1)
+  to understand the syntax.
+
+  The module accepts one parameter: 
+
+  readonly: period = "begin date","end date"
+
+  where "begin date" and "end date" are mandatory and should comply with date(1) 
+  syntax for date strings.
+
+  Example:
+
+  readonly: period = "today 14:00","today 15:00"
+
+  Default:
+
+  readonly: period = "today 0:0:0","tomorrow 0:0:0"
+
+  The default covers whole day thus making the share readonly
+
+ */
+
+#define MODULE_NAME "readonly"
+static int readonly_connect(vfs_handle_struct *handle, 
+                           connection_struct *conn, 
+                           const char *service, 
+                           const char *user)    
+{
+  const char *period_def[] = {"today 0:0:0", "tomorrow 0:0:0"};
+
+  const char **period = lp_parm_string_list(SNUM(handle->conn),
+                                            (handle->param ? handle->param : MODULE_NAME),
+                                            "period", period_def); 
+
+  if (period && period[0] && period[1]) {
+    time_t current_time = time(NULL);
+    time_t begin_period = get_date(period[0], &current_time);
+    time_t end_period   = get_date(period[1], &current_time);
+
+    if ((current_time >= begin_period) && (current_time <= end_period)) {
+      conn->read_only = True;
+    }
+
+    return SMB_VFS_NEXT_CONNECT(handle, conn, service, user);
+
+  } else {
+    
+    return 1;
+    
+  }
+}
+
+
+/* VFS operations structure */
+
+static vfs_op_tuple readonly_op_tuples[] = {
+       /* Disk operations */
+  {SMB_VFS_OP(readonly_connect),       SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
+  {SMB_VFS_OP(NULL),                   SMB_VFS_OP_NOOP,    SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_readonly_init(void)
+{
+  return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples);
+}
index e725daedba43067010cffa982fa1149ebde1e703..b1b2ac03538f798511ca444a31b5780a4d065c8d 100644 (file)
@@ -336,7 +336,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co
        repository = alloc_sub_conn(conn, recycle_repository(handle));
        ALLOC_CHECK(repository, done);
        /* shouldn't we allow absolute path names here? --metze */
-       trim_string(repository, "/", "/");
+       trim_char(repository, '/', '/');
        
        if(!repository || *(repository) == '\0') {
                DEBUG(3, ("recycle: repository path not set, purging %s...\n", file_name));
@@ -455,7 +455,8 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co
        /* rename file we move to recycle bin */
        i = 1;
        while (recycle_file_exist(handle, final_name)) {
-               snprintf(final_name, PATH_MAX -1, "%s/Copy #%d of %s", temp_name, i++, base);
+               SAFE_FREE(final_name);
+               asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base);
        }
 
        DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name));
diff --git a/source3/msdfs/README b/source3/msdfs/README
deleted file mode 100644 (file)
index 0e924b3..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-Setting up MS Dfs in Samba
-kalele@veritas.com March 2000
-
-Currently, MS Dfs support is a configure time parameter (--with-msdfs). Can be changed later to always compile it in..
-
-To have a server announce itself as a Dfs server, add a "host msdfs=yes" entry to smb.conf.
-
-To make a share a Dfs root, add a "msdfs root=yes" entry to the share definition 
-in the smb.conf file.
-e.g. 
-[pub]
-       path = /export/publicsmb
-       msdfs root = yes
-
-To create dfs volumes/junctions in the share, create symbolic links of the
-format msdfs:server1\share1,server2\share2 and so on.
-
-In the above example, create a dfs volume "dfsstorage" in the [pub] share as:
-cd /export/publicsmb
-ln -s msdfs:serverA\\share dfsstorage
-
-Clicking on dfsstorage from a dfs-aware client will show you the contents of 
-\\serverA\share
-
-Shares with "msdfs root = no" (which is the default) entries are served as normal 
-shares and the client stops talking Dfs with Samba after a tconX.
-
-NOTES: 
-* Windows clients need to be rebooted if a non-dfs root is made a dfs root or
-  vice versa. A better option is to introduce a new share and make it the dfs root.
-* Currently there's a restriction that msdfs symlink names should be all 
-  lowercase.
index ce6e64d9157ddfc02f29e68450a1edd81a370813..4c86cd0f94bb29e06e58d94de3603259df9387c7 100644 (file)
@@ -40,7 +40,7 @@ static BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp)
 
        ZERO_STRUCTP(pdp);
 
-       trim_string(temp,"\\","\\");
+       trim_char(temp,'\\','\\');
        DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp));
 
        /* now tokenize */
@@ -87,8 +87,16 @@ static BOOL create_conn_struct( connection_struct *conn, int snum, char *path)
        conn->connectpath = path;
        pstring_sub(conn->connectpath , "%S", lp_servicename(snum));
 
+       /* needed for smbd_vfs_init() */
+       
+        if ( (conn->mem_ctx=talloc_init("connection_struct")) == NULL ) {
+                DEBUG(0,("talloc_init(connection_struct) failed!\n"));
+                return False;
+        }
+       
        if (!smbd_vfs_init(conn)) {
                DEBUG(0,("create_conn_struct: smbd_vfs_init failed.\n"));
+               talloc_destroy( conn->mem_ctx );
                return False;
        }
        return True;
@@ -267,7 +275,7 @@ static BOOL resolve_dfs_path(char* dfspath, struct dfs_path* dp,
                                char *q;
                                pstring buf;
                                pstrcpy(buf, dfspath);
-                               trim_string(buf, NULL, "\\");
+                               trim_char(buf, '\0', '\\');
                                for (; consumed_level; consumed_level--) {
                                        q = strrchr(buf, '\\');
                                        if (q) *q = 0;
@@ -339,6 +347,7 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
        struct connection_struct* conn = &conns;
        pstring conn_path;
        int snum;
+       BOOL ret = False;
 
        BOOL self_referral = False;
 
@@ -381,16 +390,15 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
        if (!lp_msdfs_root(SNUM(conn))) {
                DEBUG(3,("get_referred_path: .%s. in dfs path %s is not a dfs root.\n",
                         dp.servicename, pathname));
-               return False;
+               goto out;
        }
 
        if (*lp_msdfs_proxy(snum) != '\0') {
                struct referral* ref;
                jn->referral_count = 1;
-               if ((ref = (struct referral*) malloc(sizeof(struct referral)))
-                   == NULL) {
+               if ((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
                        DEBUG(0, ("malloc failed for referral\n"));
-                       return False;
+                       goto out;
                }
 
                pstrcpy(ref->alternate_path, lp_msdfs_proxy(snum));
@@ -401,7 +409,8 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
                jn->referral_list = ref;
                if (consumedcntp)
                        *consumedcntp = strlen(pathname);
-               return True;
+               ret = True;
+               goto out;
        }
 
        /* If not remote & not a self referral, return False */
@@ -410,7 +419,7 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
                              self_referralp, consumedcntp)) {
                if (!*self_referralp) {
                        DEBUG(3,("get_referred_path: No valid referrals for path %s\n", pathname));
-                       return False;
+                       goto out;
                }
        }
        
@@ -418,10 +427,9 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
        if (*self_referralp) {
                struct referral* ref;
                jn->referral_count = 1;
-               if((ref = (struct referral*) malloc(sizeof(struct referral)))
-                  == NULL) {
+               if((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
                        DEBUG(0,("malloc failed for referral\n"));
-                       return False;
+                       goto out;
                }
       
                pstrcpy(ref->alternate_path,pathname);
@@ -431,8 +439,12 @@ BOOL get_referred_path(char *pathname, struct junction_map* jn,
                if (consumedcntp)
                        *consumedcntp = strlen(pathname);
        }
-
-       return True;
+       
+       ret = True;
+out:
+       talloc_destroy( conn->mem_ctx );
+       
+       return ret;
 }
 
 static int setup_ver2_dfs_referral(char* pathname, char** ppdata, 
@@ -758,6 +770,7 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
        connection_struct *conn = &conns;
        int i=0;
        BOOL insert_comma = False;
+       BOOL ret = False;
 
        if(!junction_to_local_path(jn, path, sizeof(path), conn))
                return False;
@@ -767,7 +780,7 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
        for(i=0; i<jn->referral_count; i++) {
                char* refpath = jn->referral_list[i].alternate_path;
       
-               trim_string(refpath, "\\", "\\");
+               trim_char(refpath, '\\', '\\');
                if(*refpath == '\0') {
                        if (i == 0)
                                insert_comma = False;
@@ -786,14 +799,20 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
 
        if(exists)
                if(SMB_VFS_UNLINK(conn,path)!=0)
-                       return False;
+                       goto out;
 
        if(SMB_VFS_SYMLINK(conn, msdfs_link, path) < 0) {
                DEBUG(1,("create_msdfs_link: symlink failed %s -> %s\nError: %s\n", 
                                path, msdfs_link, strerror(errno)));
-               return False;
+               goto out;
        }
-       return True;
+       
+       
+       ret = True;
+       
+out:
+       talloc_destroy( conn->mem_ctx );
+       return ret;
 }
 
 BOOL remove_msdfs_link(struct junction_map* jn)
@@ -801,14 +820,16 @@ BOOL remove_msdfs_link(struct junction_map* jn)
        pstring path;
        connection_struct conns;
        connection_struct *conn = &conns;
+       BOOL ret = False;
 
-       if(!junction_to_local_path(jn, path, sizeof(path), conn))
-               return False;
-     
-       if(SMB_VFS_UNLINK(conn, path)!=0)
-               return False;
-  
-       return True;
+       if( junction_to_local_path(jn, path, sizeof(path), conn) ) {
+               if( SMB_VFS_UNLINK(conn, path) == 0 )
+                       ret = True;
+
+               talloc_destroy( conn->mem_ctx );
+       }
+       
+       return ret;
 }
 
 static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
@@ -821,6 +842,7 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
        connection_struct conns;
        connection_struct *conn = &conns;
        struct referral *ref = NULL;
+       BOOL ret = False;
  
        pstrcpy(connect_path,lp_pathname(snum));
 
@@ -846,7 +868,7 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
                = (struct referral*) malloc(sizeof(struct referral));
        if (jn[cnt].referral_list == NULL) {
                DEBUG(0, ("Malloc failed!\n"));
-               return False;
+               goto out;
        }
 
        ref->proximity = 0;
@@ -854,7 +876,8 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
        if (*lp_msdfs_proxy(snum) != '\0') {
                pstrcpy(ref->alternate_path, lp_msdfs_proxy(snum));
                *jn_count = ++cnt;
-               return True;
+               ret = True;
+               goto out;
        }
                
        slprintf(ref->alternate_path, sizeof(pstring)-1,
@@ -864,7 +887,7 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
        /* Now enumerate all dfs links */
        dirp = SMB_VFS_OPENDIR(conn, connect_path);
        if(!dirp)
-               return False;
+               goto out;
 
        while((dname = vfs_readdirname(conn, dirp)) != NULL) {
                pstring pathreal;
@@ -883,7 +906,9 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
        
        SMB_VFS_CLOSEDIR(conn,dirp);
        *jn_count = cnt;
-       return True;
+out:
+       talloc_destroy(conn->mem_ctx);
+       return ret;
 }
 
 int enum_msdfs_links(struct junction_map* jn)
@@ -892,9 +917,9 @@ int enum_msdfs_links(struct junction_map* jn)
        int jn_count = 0;
 
        if(!lp_host_msdfs())
-               return -1;
+               return 0;
 
-       for(i=0;*lp_servicename(i);i++) {
+       for(i=0;i < lp_numservices();i++) {
                if(lp_msdfs_root(i)) 
                        form_junctions(i,jn,&jn_count);
        }
index c86ee69a097db639d9a5f3a3f64519730fad0995..6d5d487b112f5826ed55d8229e14ce3bfa4d6286 100644 (file)
 
 static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr)
 {
-  int name_type = question->name_type;
-  char *qname = question->name;
-  
+       int name_type = question->name_type;
+       nstring qname;
+
+       pull_ascii_nstring(qname, question->name);
   
-  if (!addr.s_addr) {
-    /* add the fail to WINS cache of names. give it 1 hour in the cache */
-    DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname));
-    (void)add_name_to_subnet( wins_server_subnet, qname, name_type,
-                              NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr );
-    return( NULL );
-  }
-
-  /* add it to our WINS cache of names. give it 2 hours in the cache */
-  DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr)));
-
-  return( add_name_to_subnet( wins_server_subnet, qname, name_type,
-                              NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) );
-}
+       if (!addr.s_addr) {
+               /* add the fail to WINS cache of names. give it 1 hour in the cache */
+               DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname));
+               (void)add_name_to_subnet( wins_server_subnet, qname, name_type,
+                               NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr );
+               return( NULL );
+       }
 
+       /* add it to our WINS cache of names. give it 2 hours in the cache */
+       DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr)));
 
+       return( add_name_to_subnet( wins_server_subnet, qname, name_type,
+                              NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) );
+}
 
 #ifndef SYNC_DNS
 
@@ -70,6 +69,7 @@ static struct packet_struct *dns_current;
   return the fd used to gather async dns replies. This is added to the select
   loop
   ****************************************************************************/
+
 int asyncdns_fd(void)
 {
        return fd_in;
@@ -110,7 +110,7 @@ static void asyncdns_process(void)
 
 static void sig_term(int sig)
 {
-  _exit(0);
+       _exit(0);
 }
 
 /***************************************************************************
@@ -224,10 +224,10 @@ void run_dns_queue(void)
                if (query_current(&r)) {
                        DEBUG(3,("DNS calling send_wins_name_query_response\n"));
                        in_dns = 1;
-                        if(namerec == NULL)
-                          send_wins_name_query_response(NAM_ERR, dns_current, NULL);
-                        else
-                         send_wins_name_query_response(0,dns_current,namerec);
+                       if(namerec == NULL)
+                               send_wins_name_query_response(NAM_ERR, dns_current, NULL);
+                       else
+                               send_wins_name_query_response(0,dns_current,namerec);
                        in_dns = 0;
                }
 
@@ -245,10 +245,10 @@ void run_dns_queue(void)
                if (nmb_name_equal(question, &r.name)) {
                        DEBUG(3,("DNS calling send_wins_name_query_response\n"));
                        in_dns = 1;
-                        if(namerec == NULL)
-                         send_wins_name_query_response(NAM_ERR, p, NULL);
-                        else
-                          send_wins_name_query_response(0,p,namerec);
+                       if(namerec == NULL)
+                               send_wins_name_query_response(NAM_ERR, p, NULL);
+                       else
+                               send_wins_name_query_response(0,p,namerec);
                        in_dns = 0;
                        p->locked = False;
 
@@ -269,7 +269,8 @@ void run_dns_queue(void)
        if (dns_queue) {
                dns_current = dns_queue;
                dns_queue = dns_queue->next;
-               if (dns_queue) dns_queue->prev = NULL;
+               if (dns_queue)
+                       dns_queue->prev = NULL;
                dns_current->next = NULL;
 
                if (!write_child(dns_current)) {
@@ -277,12 +278,12 @@ void run_dns_queue(void)
                        return;
                }
        }
-
 }
 
 /***************************************************************************
 queue a DNS query
   ****************************************************************************/
+
 BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
                     struct name_record **n)
 {
@@ -315,11 +316,14 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
 /***************************************************************************
   we use this when we can't do async DNS lookups
   ****************************************************************************/
+
 BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
                     struct name_record **n)
 {
-       char *qname = question->name;
        struct in_addr dns_ip;
+       nstring qname;
+
+       pull_ascii_nstring(qname, question->name);
 
        DEBUG(3,("DNS search for %s - ", nmb_namestr(question)));
 
@@ -332,18 +336,19 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
         BlockSignals(True, SIGTERM);
 
        *n = add_dns_result(question, dns_ip);
-        if(*n == NULL)
-          send_wins_name_query_response(NAM_ERR, p, NULL);
-        else
-          send_wins_name_query_response(0, p, *n);
+       if(*n == NULL)
+               send_wins_name_query_response(NAM_ERR, p, NULL);
+       else
+               send_wins_name_query_response(0, p, *n);
        return False;
 }
 
 /***************************************************************************
  With sync dns there is no child to kill on SIGTERM.
   ****************************************************************************/
+
 void kill_async_dns_child(void)
 {
-  return;
+       return;
 }
 #endif
index 2801e54551d43a90311c48c60f38464aa28f201b..25ba07c8a7ad5a4cfc3c372521f6496dfecab479 100644 (file)
@@ -231,7 +231,8 @@ static BOOL reload_interfaces(time_t t)
                        DEBUG(2,("Found new interface %s\n", 
                                 inet_ntoa(iface->ip)));
                        subrec = make_normal_subnet(iface);
-                       if (subrec) register_my_workgroup_one_subnet(subrec);
+                       if (subrec)
+                               register_my_workgroup_one_subnet(subrec);
                }
        }
 
@@ -303,6 +304,7 @@ static BOOL reload_nmbd_services(BOOL test)
  * We use buf here to return BOOL result to process() when reload_interfaces()
  * detects that there are no subnets.
  **************************************************************************** */
+
 static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t len)
 {
        write_browse_list( 0, True );
@@ -650,126 +652,120 @@ static BOOL open_sockets(BOOL isdaemon, int port)
                log_stdout = True;
        }
 
-  if ( log_stdout && Fork ) {
-    DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
-    exit(1);
-  }
+       if ( log_stdout && Fork ) {
+               DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
+               exit(1);
+       }
 
-  setup_logging( argv[0], log_stdout );
+       setup_logging( argv[0], log_stdout );
 
-  reopen_logs();
+       reopen_logs();
 
-  DEBUG( 0, ( "Netbios nameserver version %s started.\n", VERSION ) );
-  DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) );
+       DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) );
+       DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) );
 
-  if ( !reload_nmbd_services(False) )
-    return(-1);
+       if ( !reload_nmbd_services(False) )
+               return(-1);
 
-  if(!init_names())
-    return -1;
+       if(!init_names())
+               return -1;
 
-  reload_nmbd_services( True );
+       reload_nmbd_services( True );
 
-  if (strequal(lp_workgroup(),"*"))
-  {
-    DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n"));
-    exit(1);
-  }
+       if (strequal(lp_workgroup(),"*")) {
+               DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n"));
+               exit(1);
+       }
 
-  set_samba_nb_type();
+       set_samba_nb_type();
 
-  if (!is_daemon && !is_a_socket(0))
-  {
-    DEBUG(0,("standard input is not a socket, assuming -D option\n"));
-    is_daemon = True;
-  }
+       if (!is_daemon && !is_a_socket(0)) {
+               DEBUG(0,("standard input is not a socket, assuming -D option\n"));
+               is_daemon = True;
+       }
   
-  if (is_daemon && !opt_interactive)
-  {
-    DEBUG( 2, ( "Becoming a daemon.\n" ) );
-    become_daemon(Fork);
-  }
+       if (is_daemon && !opt_interactive) {
+               DEBUG( 2, ( "Becoming a daemon.\n" ) );
+               become_daemon(Fork);
+       }
 
 #if HAVE_SETPGID
-  /*
-   * If we're interactive we want to set our own process group for 
-   * signal management.
-   */
-  if (opt_interactive)
-    setpgid( (pid_t)0, (pid_t)0 );
+       /*
+        * If we're interactive we want to set our own process group for 
+        * signal management.
+        */
+       if (opt_interactive)
+               setpgid( (pid_t)0, (pid_t)0 );
 #endif
 
 #ifndef SYNC_DNS
-  /* Setup the async dns. We do it here so it doesn't have all the other
-     stuff initialised and thus chewing memory and sockets */
-  if(lp_we_are_a_wins_server() && lp_dns_proxy()) {
-         start_async_dns();
-  }
+       /* Setup the async dns. We do it here so it doesn't have all the other
+               stuff initialised and thus chewing memory and sockets */
+       if(lp_we_are_a_wins_server() && lp_dns_proxy()) {
+               start_async_dns();
+       }
 #endif
 
-  if (!directory_exist(lp_lockdir(), NULL)) {
-         mkdir(lp_lockdir(), 0755);
-  }
-
-  pidfile_create("nmbd");
-  message_init();
-  message_register(MSG_FORCE_ELECTION, nmbd_message_election);
-  message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry);
-  message_register(MSG_SHUTDOWN, nmbd_terminate);
-  message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services);
-
-  DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) );
-
-  if ( !open_sockets( is_daemon, global_nmb_port ) ) {
-    kill_async_dns_child();
-    return 1;
-  }
-
-  /* Determine all the IP addresses we have. */
-  load_interfaces();
-
-  /* Create an nmbd subnet record for each of the above. */
-  if( False == create_subnets() )
-  {
-    DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
-    kill_async_dns_child();
-    exit(1);
-  }
-
-  /* Load in any static local names. */ 
-  load_lmhosts_file(dyn_LMHOSTSFILE);
-  DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE));
-
-  /* If we are acting as a WINS server, initialise data structures. */
-  if( !initialise_wins() )
-  {
-    DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
-    kill_async_dns_child();
-    exit(1);
-  }
-
-  /* 
-   * Register nmbd primary workgroup and nmbd names on all
-   * the broadcast subnets, and on the WINS server (if specified).
-   * Also initiate the startup of our primary workgroup (start
-   * elections if we are setup as being able to be a local
-   * master browser.
-   */
-
-  if( False == register_my_workgroup_and_names() )
-  {
-    DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
-    kill_async_dns_child();
-    exit(1);
-  }
-
-  /* We can only take signals in the select. */
-  BlockSignals( True, SIGTERM );
-
-  process();
-
-  if (dbf)
-    x_fclose(dbf);
-  kill_async_dns_child();
-  return(0);
+       if (!directory_exist(lp_lockdir(), NULL)) {
+               mkdir(lp_lockdir(), 0755);
+       }
+
+       pidfile_create("nmbd");
+       message_init();
+       message_register(MSG_FORCE_ELECTION, nmbd_message_election);
+       message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry);
+       message_register(MSG_SHUTDOWN, nmbd_terminate);
+       message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services);
+
+       DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) );
+
+       if ( !open_sockets( is_daemon, global_nmb_port ) ) {
+               kill_async_dns_child();
+               return 1;
+       }
+
+       /* Determine all the IP addresses we have. */
+       load_interfaces();
+
+       /* Create an nmbd subnet record for each of the above. */
+       if( False == create_subnets() ) {
+               DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
+               kill_async_dns_child();
+               exit(1);
+       }
+
+       /* Load in any static local names. */ 
+       load_lmhosts_file(dyn_LMHOSTSFILE);
+       DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE));
+
+       /* If we are acting as a WINS server, initialise data structures. */
+       if( !initialise_wins() ) {
+               DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
+               kill_async_dns_child();
+               exit(1);
+       }
+
+       /* 
+        * Register nmbd primary workgroup and nmbd names on all
+        * the broadcast subnets, and on the WINS server (if specified).
+        * Also initiate the startup of our primary workgroup (start
+        * elections if we are setup as being able to be a local
+        * master browser.
+        */
+
+       if( False == register_my_workgroup_and_names() ) {
+               DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
+               kill_async_dns_child();
+               exit(1);
+       }
+
+       /* We can only take signals in the select. */
+       BlockSignals( True, SIGTERM );
+
+       process();
+
+       if (dbf)
+               x_fclose(dbf);
+       kill_async_dns_child();
+       return(0);
 }
index 2e76e51f453676cd3354afdf91f2b06e498ba3d9..46d37fbb817801bc59887c4ca8ebf94f6020fd96 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -37,36 +37,37 @@ static void become_domain_master_fail(struct subnet_record *subrec,
                                       struct response_record *rrec,
                                       struct nmb_name *fail_name)
 {
-  struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name);
-  struct server_record *servrec;
-
-  if(!work)
-  {
-    DEBUG(0,("become_domain_master_fail: Error - cannot find \
-workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name));
-    return;
-  }
-
-  /* Set the state back to DOMAIN_NONE. */
-  work->dom_state = DOMAIN_NONE;
-
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \
+       nstring failname;
+       struct work_record *work;
+       struct server_record *servrec;
+
+       pull_ascii_nstring(failname, fail_name->name);
+       work = find_workgroup_on_subnet(subrec, failname);
+       if(!work) {
+               DEBUG(0,("become_domain_master_fail: Error - cannot find \
+workgroup %s on subnet %s\n", failname, subrec->subnet_name));
+               return;
+       }
+
+       /* Set the state back to DOMAIN_NONE. */
+       work->dom_state = DOMAIN_NONE;
+
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), work->work_group, subrec->subnet_name));
-    return;
-  }
+                       global_myname(), work->work_group, subrec->subnet_name));
+               return;
+       }
 
-  /* Update our server status. */
-  servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER;
+       /* Update our server status. */
+       servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER;
 
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
 
-  DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \
+       DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \
 workgroup %s on subnet %s. Couldn't register name %s.\n",
-       work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
+               work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
 }
 
 /****************************************************************************
@@ -79,115 +80,112 @@ static void become_domain_master_stage2(struct subnet_record *subrec,
                                         uint16 nb_flags,
                                         int ttl, struct in_addr registered_ip)
 {
-  struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name);
-  struct server_record *servrec;
-
-  if(!work)
-  {
-    DEBUG(0,("become_domain_master_stage2: Error - cannot find \
-workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name));
-    return;
-  }
-
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \
+       nstring regname;
+       struct work_record *work;
+       struct server_record *servrec;
+
+       pull_ascii_nstring(regname, registered_name->name);
+       work = find_workgroup_on_subnet( subrec, regname);
+
+       if(!work) {
+               DEBUG(0,("become_domain_master_stage2: Error - cannot find \
+workgroup %s on subnet %s\n", regname, subrec->subnet_name));
+               return;
+       }
+
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \
 in workgroup %s on subnet %s\n", 
-       global_myname(), registered_name->name, subrec->subnet_name));
-    work->dom_state = DOMAIN_NONE;
-    return;
-  }
-
-  /* Set the state in the workgroup structure. */
-  work->dom_state = DOMAIN_MST; /* Become domain master. */
-
-  /* Update our server status. */
-  servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER);
-
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
-
-  if( DEBUGLVL( 0 ) )
-    {
-    dbgtext( "*****\n\nSamba server %s ", global_myname() );
-    dbgtext( "is now a domain master browser for " );
-    dbgtext( "workgroup %s ", work->work_group );
-    dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
-    }
-
-  if( subrec == unicast_subnet )
-  {
-    struct nmb_name nmbname;
-    struct in_addr my_first_ip;
-
-    /* Put our name and first IP address into the 
-       workgroup struct as domain master browser. This
-       will stop us syncing with ourself if we are also
-       a local master browser. */
-
-    make_nmb_name(&nmbname, global_myname(), 0x20);
-
-    work->dmb_name = nmbname;
-    /* Pick the first interface ip address as the domain master browser ip. */
-    my_first_ip = *iface_n_ip(0);
-
-    putip((char *)&work->dmb_addr, &my_first_ip);
-
-    /* We successfully registered by unicast with the
-       WINS server.  We now expect to become the domain
-       master on the local subnets. If this fails, it's
-       probably a 1.9.16p2 to 1.9.16p11 server's fault.
-
-       This is a configuration issue that should be addressed
-       by the network administrator - you shouldn't have
-       several machines configured as a domain master browser
-       for the same WINS scope (except if they are 1.9.17 or
-       greater, and you know what you're doing.
-
-       see docs/DOMAIN.txt.
-
-     */
-    become_domain_master_browser_bcast(work->work_group);
-  }
-  else
-  {
-    /*
-     * Now we are a domain master on a broadcast subnet, we need to add
-     * the WORKGROUP<1b> name to the unicast subnet so that we can answer
-     * unicast requests sent to this name. This bug wasn't found for a while
-     * as it is strange to have a DMB without using WINS. JRA.
-     */
-    insert_permanent_name_into_unicast(subrec, registered_name, nb_flags);
-  }
+               global_myname(), regname, subrec->subnet_name));
+               work->dom_state = DOMAIN_NONE;
+               return;
+       }
+
+       /* Set the state in the workgroup structure. */
+       work->dom_state = DOMAIN_MST; /* Become domain master. */
+
+       /* Update our server status. */
+       servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER);
+
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
+
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "*****\n\nSamba server %s ", global_myname() );
+               dbgtext( "is now a domain master browser for " );
+               dbgtext( "workgroup %s ", work->work_group );
+               dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
+       }
+
+       if( subrec == unicast_subnet ) {
+               struct nmb_name nmbname;
+               struct in_addr my_first_ip;
+
+               /* Put our name and first IP address into the 
+                  workgroup struct as domain master browser. This
+                  will stop us syncing with ourself if we are also
+                  a local master browser. */
+
+               make_nmb_name(&nmbname, global_myname(), 0x20);
+
+               work->dmb_name = nmbname;
+               /* Pick the first interface ip address as the domain master browser ip. */
+               my_first_ip = *iface_n_ip(0);
+
+               putip((char *)&work->dmb_addr, &my_first_ip);
+
+               /* We successfully registered by unicast with the
+                  WINS server.  We now expect to become the domain
+                  master on the local subnets. If this fails, it's
+                  probably a 1.9.16p2 to 1.9.16p11 server's fault.
+
+                  This is a configuration issue that should be addressed
+                  by the network administrator - you shouldn't have
+                  several machines configured as a domain master browser
+                  for the same WINS scope (except if they are 1.9.17 or
+                  greater, and you know what you're doing.
+
+                  see docs/DOMAIN.txt.
+
+               */
+               become_domain_master_browser_bcast(work->work_group);
+       } else {
+               /*
+                * Now we are a domain master on a broadcast subnet, we need to add
+                * the WORKGROUP<1b> name to the unicast subnet so that we can answer
+                * unicast requests sent to this name. This bug wasn't found for a while
+                * as it is strange to have a DMB without using WINS. JRA.
+                */
+               insert_permanent_name_into_unicast(subrec, registered_name, nb_flags);
+       }
 }
 
 /****************************************************************************
   Start the name registration process when becoming a Domain Master Browser
   on a subnet.
-  ****************************************************************************/
+****************************************************************************/
 
-static void become_domain_master_stage1(struct subnet_record *subrec, char *wg_name)
+static void become_domain_master_stage1(struct subnet_record *subrec, const char *wg_name)
 { 
-  struct work_record *work;
+       struct work_record *work;
 
-  DEBUG(2,("become_domain_master_stage1: Becoming domain master browser for \
+       DEBUG(2,("become_domain_master_stage1: Becoming domain master browser for \
 workgroup %s on subnet %s\n", wg_name, subrec->subnet_name));
 
-  /* First, find the workgroup on the subnet. */
-  if((work = find_workgroup_on_subnet( subrec, wg_name )) == NULL)
-  {
-    DEBUG(0,("become_domain_master_stage1: Error - unable to find workgroup %s on subnet %s.\n",
-          wg_name, subrec->subnet_name));
-    return;
-  }
-
-  DEBUG(3,("become_domain_master_stage1: go to first stage: register <1b> name\n"));
-  work->dom_state = DOMAIN_WAIT;
-
-  /* WORKGROUP<1b> is the domain master browser name. */
-  register_name(subrec, work->work_group,0x1b,samba_nb_type,
-                become_domain_master_stage2,
-                become_domain_master_fail, NULL);
+       /* First, find the workgroup on the subnet. */
+       if((work = find_workgroup_on_subnet( subrec, wg_name )) == NULL) {
+               DEBUG(0,("become_domain_master_stage1: Error - unable to find workgroup %s on subnet %s.\n",
+                       wg_name, subrec->subnet_name));
+               return;
+       }
+
+       DEBUG(3,("become_domain_master_stage1: go to first stage: register <1b> name\n"));
+       work->dom_state = DOMAIN_WAIT;
+
+       /* WORKGROUP<1b> is the domain master browser name. */
+       register_name(subrec, work->work_group,0x1b,samba_nb_type,
+                       become_domain_master_stage2,
+                       become_domain_master_fail, NULL);
 }
 
 /****************************************************************************
@@ -202,37 +200,35 @@ static void become_domain_master_query_success(struct subnet_record *subrec,
                         struct nmb_name *nmbname, struct in_addr ip, 
                         struct res_rec *rrec)
 {
-  /* If the given ip is not ours, then we can't become a domain
-     controler as the name is already registered.
-   */
-
- /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast
-    address or zero ip for this query. Pretend this is ok. */
-
-  if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip))
-  {
-    if( DEBUGLVL( 3 ) )
-    {
-      dbgtext( "become_domain_master_query_success():\n" );
-      dbgtext( "Our address (%s) ", inet_ntoa(ip) );
-      dbgtext( "returned in query for name %s ", nmb_namestr(nmbname) );
-      dbgtext( "(domain master browser name) " );
-      dbgtext( "on subnet %s.\n", subrec->subnet_name );
-      dbgtext( "Continuing with domain master code.\n" );
-    }
-
-    become_domain_master_stage1(subrec, nmbname->name);
-  }
-  else
-  {
-    if( DEBUGLVL( 0 ) )
-      {
-      dbgtext( "become_domain_master_query_success:\n" );
-      dbgtext( "There is already a domain master browser at " );
-      dbgtext( "IP %s for workgroup %s ", inet_ntoa(ip), nmbname->name );
-      dbgtext( "registered on subnet %s.\n", subrec->subnet_name );
-      }
-  }
+       nstring name;
+       pull_ascii_nstring(name, nmbname->name);
+
+       /* If the given ip is not ours, then we can't become a domain
+               controler as the name is already registered.
+       */
+
+       /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast
+               address or zero ip for this query. Pretend this is ok. */
+
+       if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) {
+               if( DEBUGLVL( 3 ) ) {
+                       dbgtext( "become_domain_master_query_success():\n" );
+                       dbgtext( "Our address (%s) ", inet_ntoa(ip) );
+                       dbgtext( "returned in query for name %s ", nmb_namestr(nmbname) );
+                       dbgtext( "(domain master browser name) " );
+                       dbgtext( "on subnet %s.\n", subrec->subnet_name );
+                       dbgtext( "Continuing with domain master code.\n" );
+               }
+
+               become_domain_master_stage1(subrec, name);
+       } else {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "become_domain_master_query_success:\n" );
+                       dbgtext( "There is already a domain master browser at " );
+                       dbgtext( "IP %s for workgroup %s ", inet_ntoa(ip), name );
+                       dbgtext( "registered on subnet %s.\n", subrec->subnet_name );
+               }
+       }
 }
 
 /****************************************************************************
@@ -245,18 +241,21 @@ static void become_domain_master_query_fail(struct subnet_record *subrec,
                                     struct response_record *rrec,
                                     struct nmb_name *question_name, int fail_code)
 {
-  /* If the query was unicast, and the error is not NAM_ERR (name didn't exist),
-     then this is a failure. Otherwise, not finding the name is what we want. */
-  if((subrec == unicast_subnet) && (fail_code != NAM_ERR))
-  {
-    DEBUG(0,("become_domain_master_query_fail: Error %d returned when \
+       nstring name;
+
+       /* If the query was unicast, and the error is not NAM_ERR (name didn't exist),
+               then this is a failure. Otherwise, not finding the name is what we want. */
+
+       if((subrec == unicast_subnet) && (fail_code != NAM_ERR)) {
+               DEBUG(0,("become_domain_master_query_fail: Error %d returned when \
 querying WINS server for name %s.\n", 
-                  fail_code, nmb_namestr(question_name)));
-    return;
-  }
+                       fail_code, nmb_namestr(question_name)));
+               return;
+       }
 
-  /* Otherwise - not having the name allows us to register it. */
-  become_domain_master_stage1(subrec, question_name->name);
+       /* Otherwise - not having the name allows us to register it. */
+       pull_ascii_nstring(name, question_name->name);
+       become_domain_master_stage1(subrec, name);
 }
 
 /****************************************************************************
@@ -265,47 +264,43 @@ querying WINS server for name %s.\n",
 
 static void become_domain_master_browser_bcast(const char *workgroup_name)
 {
-  struct subnet_record *subrec;
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  { 
-    struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name);
-
-    if (work && (work->dom_state == DOMAIN_NONE))
-    {
-      struct nmb_name nmbname;
-      make_nmb_name(&nmbname,workgroup_name,0x1b);
-
-      /*
-       * Check for our name on the given broadcast subnet first, only initiate
-       * further processing if we cannot find it.
-       */
-
-      if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL)
-      {
-        if( DEBUGLVL( 0 ) )
-          {
-          dbgtext( "become_domain_master_browser_bcast:\n" );
-          dbgtext( "Attempting to become domain master browser on " );
-          dbgtext( "workgroup %s on subnet %s\n",
-                    workgroup_name, subrec->subnet_name );
-          }
-
-        /* Send out a query to establish whether there's a 
-           domain controller on the local subnet. If not,
-           we can become a domain controller. 
-         */
-
-        DEBUG(0,("become_domain_master_browser_bcast: querying subnet %s \
+       struct subnet_record *subrec;
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { 
+               struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name);
+
+               if (work && (work->dom_state == DOMAIN_NONE)) {
+                       struct nmb_name nmbname;
+                       make_nmb_name(&nmbname,workgroup_name,0x1b);
+
+                       /*
+                        * Check for our name on the given broadcast subnet first, only initiate
+                        * further processing if we cannot find it.
+                        */
+
+                       if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) {
+                               if( DEBUGLVL( 0 ) ) {
+                                       dbgtext( "become_domain_master_browser_bcast:\n" );
+                                       dbgtext( "Attempting to become domain master browser on " );
+                                       dbgtext( "workgroup %s on subnet %s\n",
+                                               workgroup_name, subrec->subnet_name );
+                               }
+
+                               /* Send out a query to establish whether there's a 
+                                  domain controller on the local subnet. If not,
+                                  we can become a domain controller. 
+                               */
+
+                               DEBUG(0,("become_domain_master_browser_bcast: querying subnet %s \
 for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_name));
 
-        query_name(subrec, nmbname.name, nmbname.name_type,
-                   become_domain_master_query_success, 
-                   become_domain_master_query_fail,
-                   NULL);
-      }
-    }
-  }
+                               query_name(subrec, workgroup_name, nmbname.name_type,
+                                       become_domain_master_query_success, 
+                                       become_domain_master_query_fail,
+                                       NULL);
+                       }
+               }
+       }
 }
 
 /****************************************************************************
@@ -314,46 +309,43 @@ for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_nam
 
 static void become_domain_master_browser_wins(const char *workgroup_name)
 {
-  struct work_record *work;
+       struct work_record *work;
 
-  work = find_workgroup_on_subnet(unicast_subnet, workgroup_name);
+       work = find_workgroup_on_subnet(unicast_subnet, workgroup_name);
 
-  if (work && (work->dom_state == DOMAIN_NONE))
-  {
-    struct nmb_name nmbname;
+       if (work && (work->dom_state == DOMAIN_NONE)) {
+               struct nmb_name nmbname;
 
-    make_nmb_name(&nmbname,workgroup_name,0x1b);
+               make_nmb_name(&nmbname,workgroup_name,0x1b);
 
-    /*
-     * Check for our name on the unicast subnet first, only initiate
-     * further processing if we cannot find it.
-     */
+               /*
+                * Check for our name on the unicast subnet first, only initiate
+                * further processing if we cannot find it.
+                */
 
-    if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL)
-    {
-      if( DEBUGLVL( 0 ) )
-        {
-        dbgtext( "become_domain_master_browser_wins:\n" );
-        dbgtext( "Attempting to become domain master browser " );
-        dbgtext( "on workgroup %s, subnet %s.\n",
-                  workgroup_name, unicast_subnet->subnet_name );
-        }
+               if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL) {
+                       if( DEBUGLVL( 0 ) ) {
+                               dbgtext( "become_domain_master_browser_wins:\n" );
+                               dbgtext( "Attempting to become domain master browser " );
+                               dbgtext( "on workgroup %s, subnet %s.\n",
+                                       workgroup_name, unicast_subnet->subnet_name );
+                       }
 
-      /* Send out a query to establish whether there's a 
-         domain master broswer registered with WINS. If not,
-         we can become a domain master browser. 
-       */
+                       /* Send out a query to establish whether there's a 
+                          domain master broswer registered with WINS. If not,
+                          we can become a domain master browser. 
+                       */
 
-      DEBUG(0,("become_domain_master_browser_wins: querying WINS server from IP %s \
+                       DEBUG(0,("become_domain_master_browser_wins: querying WINS server from IP %s \
 for domain master browser name %s on workgroup %s\n",
-         inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name));
-
-      query_name(unicast_subnet, nmbname.name, nmbname.name_type,
-                   become_domain_master_query_success,
-                   become_domain_master_query_fail,
-                   NULL);
-    }
-  }
+                               inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name));
+
+                       query_name(unicast_subnet, workgroup_name, nmbname.name_type,
+                               become_domain_master_query_success,
+                               become_domain_master_query_fail,
+                               NULL);
+               }
+       }
 }
 
 /****************************************************************************
@@ -363,34 +355,32 @@ for domain master browser name %s on workgroup %s\n",
 
 void add_domain_names(time_t t)
 {
-  static time_t lastrun = 0;
-
-  if ((lastrun != 0) && (t < lastrun + (CHECK_TIME_ADD_DOM_NAMES * 60)))
-    return;
-
-  lastrun = t;
-
-  /* Do the "internet group" - <1c> names. */
-  if (lp_domain_logons())
-    add_logon_names();
-
-  /* Do the domain master names. */
-  if(lp_domain_master())
-  {
-    if(we_are_a_wins_client())
-    {
-      /* We register the WORKGROUP<1b> name with the WINS
-         server first, and call add_domain_master_bcast()
-         only if this is successful.
-
-         This results in domain logon services being gracefully provided,
-         as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11.
-         1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c,
-         cannot provide domain master / domain logon services.
-       */
-      become_domain_master_browser_wins(lp_workgroup());
-    }
-    else
-      become_domain_master_browser_bcast(lp_workgroup());
-  }
+       static time_t lastrun = 0;
+
+       if ((lastrun != 0) && (t < lastrun + (CHECK_TIME_ADD_DOM_NAMES * 60)))
+               return;
+
+       lastrun = t;
+
+       /* Do the "internet group" - <1c> names. */
+       if (lp_domain_logons())
+               add_logon_names();
+
+       /* Do the domain master names. */
+       if(lp_domain_master()) {
+               if(we_are_a_wins_client()) {
+                       /* We register the WORKGROUP<1b> name with the WINS
+                               server first, and call add_domain_master_bcast()
+                               only if this is successful.
+
+                               This results in domain logon services being gracefully provided,
+                               as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11.
+                               1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c,
+                               cannot provide domain master / domain logon services.
+                       */
+                       become_domain_master_browser_wins(lp_workgroup());
+               } else {
+                       become_domain_master_browser_bcast(lp_workgroup());
+               }
+       }
 }
index d390bf72e9547cc8cc62f4e2a2705187fe7b2ad4..2370c7ba3668ff30f84e1a7076fe652717dba9f0 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -33,21 +33,20 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */
 void insert_permanent_name_into_unicast( struct subnet_record *subrec, 
                                                 struct nmb_name *nmbname, uint16 nb_type )
 {
-  struct name_record *namerec;
-
-  if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL)
-  {
-    /* The name needs to be created on the unicast subnet. */
-    (void)add_name_to_subnet( unicast_subnet, nmbname->name,
-                              nmbname->name_type, nb_type,
-                              PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip);
-  }
-  else
-  {
-    /* The name already exists on the unicast subnet. Add our local
-       IP for the given broadcast subnet to the name. */
-    add_ip_to_name_record( namerec, subrec->myip);
-  }
+       nstring name;
+       struct name_record *namerec;
+
+       if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) {
+               pull_ascii_nstring(name, nmbname->name);
+               /* The name needs to be created on the unicast subnet. */
+               (void)add_name_to_subnet( unicast_subnet, name,
+                               nmbname->name_type, nb_type,
+                               PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip);
+       } else {
+               /* The name already exists on the unicast subnet. Add our local
+               IP for the given broadcast subnet to the name. */
+               add_ip_to_name_record( namerec, subrec->myip);
+       }
 }
 
 /*******************************************************************
@@ -57,15 +56,14 @@ void insert_permanent_name_into_unicast( struct subnet_record *subrec,
 static void remove_permanent_name_from_unicast( struct subnet_record *subrec,
                                                 struct nmb_name *nmbname )
 {
-  struct name_record *namerec;
-
-  if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL)
-  {
-    /* Remove this broadcast subnet IP address from the name. */
-    remove_ip_from_name_record( namerec, subrec->myip);
-    if(namerec->data.num_ips == 0)
-      remove_name_from_namelist( unicast_subnet, namerec);
-  }
+       struct name_record *namerec;
+
+       if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL) {
+               /* Remove this broadcast subnet IP address from the name. */
+               remove_ip_from_name_record( namerec, subrec->myip);
+               if(namerec->data.num_ips == 0)
+                       remove_name_from_namelist( unicast_subnet, namerec);
+       }
 }
 
 /*******************************************************************
@@ -73,60 +71,58 @@ static void remove_permanent_name_from_unicast( struct subnet_record *subrec,
  state back to potential browser, or none.
 ******************************************************************/
 
-static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name,
+static void reset_workgroup_state( struct subnet_record *subrec, const char *workgroup_name,
                                    BOOL force_new_election )
 {
-  struct work_record *work;
-  struct server_record *servrec;
-  struct nmb_name nmbname;
+       struct work_record *work;
+       struct server_record *servrec;
+       struct nmb_name nmbname;
 
-  if((work = find_workgroup_on_subnet( subrec, workgroup_name)) == NULL)
-  {
-    DEBUG(0,("reset_workgroup_state: Error - cannot find workgroup %s on \
+       if((work = find_workgroup_on_subnet( subrec, workgroup_name)) == NULL) {
+               DEBUG(0,("reset_workgroup_state: Error - cannot find workgroup %s on \
 subnet %s.\n", workgroup_name, subrec->subnet_name ));
-    return;
-  }
+               return;
+       }
 
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), work->work_group, subrec->subnet_name));
-    work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
-    return;
-  }
+                       global_myname(), work->work_group, subrec->subnet_name));
+               work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+               return;
+       }
 
-  /* Update our server status - remove any master flag and replace
-   it with the potential browser flag. */
-  servrec->serv.type &= ~SV_TYPE_MASTER_BROWSER;
-  servrec->serv.type |= (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0);
+       /* Update our server status - remove any master flag and replace
+               it with the potential browser flag. */
+       servrec->serv.type &= ~SV_TYPE_MASTER_BROWSER;
+       servrec->serv.type |= (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0);
 
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
 
-  /* Reset our election flags. */
-  work->ElectionCriterion &= ~0x4;
+       /* Reset our election flags. */
+       work->ElectionCriterion &= ~0x4;
 
-  work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+       work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
 
-  /* Forget who the local master browser was for
-     this workgroup. */
+       /* Forget who the local master browser was for
+               this workgroup. */
 
-  set_workgroup_local_master_browser_name( work, "");
+       set_workgroup_local_master_browser_name( work, "");
 
-  /*
-   * Ensure the IP address of this subnet is not registered as one
-   * of the IP addresses of the WORKGROUP<1d> name on the unicast
-   * subnet. This undoes what we did below when we became a local
-   * master browser.
-   */
+       /*
+        * Ensure the IP address of this subnet is not registered as one
+        * of the IP addresses of the WORKGROUP<1d> name on the unicast
+        * subnet. This undoes what we did below when we became a local
+        * master browser.
+        */
 
-  make_nmb_name(&nmbname, work->work_group, 0x1d);
+       make_nmb_name(&nmbname, work->work_group, 0x1d);
 
-  remove_permanent_name_from_unicast( subrec, &nmbname);
+       remove_permanent_name_from_unicast( subrec, &nmbname);
 
-  if(force_new_election)
-    work->needelection = True;
+       if(force_new_election)
+               work->needelection = True;
 }
 
 /*******************************************************************
@@ -138,24 +134,25 @@ static void unbecome_local_master_success(struct subnet_record *subrec,
                              struct nmb_name *released_name,
                              struct in_addr released_ip)
 { 
-  BOOL force_new_election = False;
+       BOOL force_new_election = False;
+       nstring relname;
 
-  memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
+       memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
 
-  DEBUG(3,("unbecome_local_master_success: released name %s.\n",
-             nmb_namestr(released_name)));
+       DEBUG(3,("unbecome_local_master_success: released name %s.\n",
+               nmb_namestr(released_name)));
 
-  /* Now reset the workgroup and server state. */
-  reset_workgroup_state( subrec, released_name->name, force_new_election );
+       /* Now reset the workgroup and server state. */
+       pull_ascii_nstring(relname, released_name->name);
+       reset_workgroup_state( subrec, relname, force_new_election );
 
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "*****\n\n" );
-    dbgtext( "Samba name server %s ", global_myname() );
-    dbgtext( "has stopped being a local master browser " );
-    dbgtext( "for workgroup %s ", released_name->name );
-    dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
-  }
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "*****\n\n" );
+               dbgtext( "Samba name server %s ", global_myname() );
+               dbgtext( "has stopped being a local master browser " );
+               dbgtext( "for workgroup %s ", relname );
+               dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
+       }
 
 }
 
@@ -166,67 +163,66 @@ static void unbecome_local_master_success(struct subnet_record *subrec,
 static void unbecome_local_master_fail(struct subnet_record *subrec, struct response_record *rrec,
                        struct nmb_name *fail_name)
 {
-  struct name_record *namerec;
-  struct userdata_struct *userdata = rrec->userdata;
-  BOOL force_new_election = False;
+       struct name_record *namerec;
+       struct userdata_struct *userdata = rrec->userdata;
+       BOOL force_new_election = False;
+       nstring failname;
 
-  memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
+       memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
 
-  DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \
+       DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \
 Removing from namelist anyway.\n", nmb_namestr(fail_name)));
 
-  /* Do it anyway. */
-  namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME);
-  if(namerec)
-    remove_name_from_namelist(subrec, namerec);
-
-  /* Now reset the workgroup and server state. */
-  reset_workgroup_state( subrec, fail_name->name, force_new_election );
-
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "*****\n\n" );
-    dbgtext( "Samba name server %s ", global_myname() );
-    dbgtext( "has stopped being a local master browser " );
-    dbgtext( "for workgroup %s ", fail_name->name );
-    dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
-  }
+       /* Do it anyway. */
+       namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME);
+       if(namerec)
+               remove_name_from_namelist(subrec, namerec);
+
+       /* Now reset the workgroup and server state. */
+       pull_ascii_nstring(failname, fail_name->name);
+       reset_workgroup_state( subrec, failname, force_new_election );
+
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "*****\n\n" );
+               dbgtext( "Samba name server %s ", global_myname() );
+               dbgtext( "has stopped being a local master browser " );
+               dbgtext( "for workgroup %s ", failname );
+               dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
+       }
 }
 
 /*******************************************************************
  Utility function to remove the WORKGROUP<1d> name.
 ******************************************************************/
 
-static void release_1d_name( struct subnet_record *subrec, char *workgroup_name,
+static void release_1d_name( struct subnet_record *subrec, const char *workgroup_name,
                              BOOL force_new_election)
 {
-  struct nmb_name nmbname;
-  struct name_record *namerec;
-
-  make_nmb_name(&nmbname, workgroup_name, 0x1d);
-  if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL)
-  {
-    struct userdata_struct *userdata;
-    size_t size = sizeof(struct userdata_struct) + sizeof(BOOL);
-
-    if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
-    {
-      DEBUG(0,("release_1d_name: malloc fail.\n"));
-      return;
-    }
-
-    userdata->copy_fn = NULL;
-    userdata->free_fn = NULL;
-    userdata->userdata_len = sizeof(BOOL);
-    memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL));
-
-    release_name(subrec, namerec,
-                 unbecome_local_master_success,
-                 unbecome_local_master_fail,
-                 userdata);
-
-    zero_free(userdata, size);
-  }
+       struct nmb_name nmbname;
+       struct name_record *namerec;
+
+       make_nmb_name(&nmbname, workgroup_name, 0x1d);
+       if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) {
+               struct userdata_struct *userdata;
+               size_t size = sizeof(struct userdata_struct) + sizeof(BOOL);
+
+               if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+                       DEBUG(0,("release_1d_name: malloc fail.\n"));
+                       return;
+               }
+
+               userdata->copy_fn = NULL;
+               userdata->free_fn = NULL;
+               userdata->userdata_len = sizeof(BOOL);
+               memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL));
+
+               release_name(subrec, namerec,
+                       unbecome_local_master_success,
+                       unbecome_local_master_fail,
+                       userdata);
+
+               zero_free(userdata, size);
+       }
 }
 
 /*******************************************************************
@@ -238,11 +234,11 @@ static void release_msbrowse_name_success(struct subnet_record *subrec,
                       struct nmb_name *released_name,
                       struct in_addr released_ip)
 {
-  DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.",
-           nmb_namestr(released_name), subrec->subnet_name ));
+       DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.",
+               nmb_namestr(released_name), subrec->subnet_name ));
 
-  /* Remove the permanent MSBROWSE name added into the unicast subnet. */
-  remove_permanent_name_from_unicast( subrec, released_name);
+       /* Remove the permanent MSBROWSE name added into the unicast subnet. */
+       remove_permanent_name_from_unicast( subrec, released_name);
 }
 
 /*******************************************************************
@@ -253,18 +249,18 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec,
                        struct response_record *rrec,
                        struct nmb_name *fail_name)
 {
-  struct name_record *namerec;
+       struct name_record *namerec;
 
-  DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.",
-           nmb_namestr(fail_name), subrec->subnet_name ));
+       DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.",
+               nmb_namestr(fail_name), subrec->subnet_name ));
 
-  /* Release the name anyway. */
-  namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME);
-  if(namerec)
-    remove_name_from_namelist(subrec, namerec);
+       /* Release the name anyway. */
+       namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME);
+       if(namerec)
+               remove_name_from_namelist(subrec, namerec);
 
-  /* Remove the permanent MSBROWSE name added into the unicast subnet. */
-  remove_permanent_name_from_unicast( subrec, fail_name);
+       /* Remove the permanent MSBROWSE name added into the unicast subnet. */
+       remove_permanent_name_from_unicast( subrec, fail_name);
 }
 
 /*******************************************************************
@@ -275,50 +271,48 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec,
 void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work,
                                    BOOL force_new_election)
 {
-  struct name_record *namerec;
-  struct nmb_name nmbname;
+       struct name_record *namerec;
+       struct nmb_name nmbname;
 
   /* Sanity check. */
 
-  DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \
+       DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \
 on subnet %s\n",work->work_group, subrec->subnet_name));
   
-  if(find_server_in_workgroup( work, global_myname()) == NULL)
-  {
-    DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \
+       if(find_server_in_workgroup( work, global_myname()) == NULL) {
+               DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), work->work_group, subrec->subnet_name));
-    work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
-    return;
-  }
+                       global_myname(), work->work_group, subrec->subnet_name));
+                       work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+               return;
+       }
   
-  /* Set the state to unbecoming. */
-  work->mst_state = MST_UNBECOMING_MASTER;
-
-  /*
-   * Release the WORKGROUP<1d> name asap to allow another machine to
-   * claim it.
-   */
-
-  release_1d_name( subrec, work->work_group, force_new_election);
-
-  /* Deregister any browser names we may have. */
-  make_nmb_name(&nmbname, MSBROWSE, 0x1);
-  if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL)
-  {
-    release_name(subrec, namerec,
-                 release_msbrowse_name_success,
-                 release_msbrowse_name_fail,
-                 NULL);
-  }
-
-  /*
-   * Ensure we have sent and processed these release packets
-   * before returning - we don't want to process any election
-   * packets before dealing with the 1d release.
-   */
-
-  retransmit_or_expire_response_records(time(NULL));
+       /* Set the state to unbecoming. */
+       work->mst_state = MST_UNBECOMING_MASTER;
+
+       /*
+        * Release the WORKGROUP<1d> name asap to allow another machine to
+        * claim it.
+        */
+
+       release_1d_name( subrec, work->work_group, force_new_election);
+
+       /* Deregister any browser names we may have. */
+       make_nmb_name(&nmbname, MSBROWSE, 0x1);
+       if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) {
+               release_name(subrec, namerec,
+                       release_msbrowse_name_success,
+                       release_msbrowse_name_fail,
+                       NULL);
+       }
+
+       /*
+        * Ensure we have sent and processed these release packets
+        * before returning - we don't want to process any election
+        * packets before dealing with the 1d release.
+        */
+
+       retransmit_or_expire_response_records(time(NULL));
 }
 
 /****************************************************************************
@@ -332,104 +326,107 @@ static void become_local_master_stage2(struct subnet_record *subrec,
                                         uint16 nb_flags,
                                         int ttl, struct in_addr registered_ip)
 {
-  int i = 0;
-  struct server_record *sl;
-  struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name);
-  struct server_record *servrec;
-
-  if(!work)
-  {
-    DEBUG(0,("become_local_master_stage2: Error - cannot find \
-workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name));
-    return;
-  }
-
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \
+       int i = 0;
+       struct server_record *sl;
+       struct work_record *work;
+       struct server_record *servrec;
+       nstring regname;
+
+       pull_ascii_nstring(regname, registered_name->name);
+       work = find_workgroup_on_subnet( subrec, regname);
+
+       if(!work) {
+               DEBUG(0,("become_local_master_stage2: Error - cannot find \
+workgroup %s on subnet %s\n", regname, subrec->subnet_name));
+               return;
+       }
+
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), registered_name->name, subrec->subnet_name));
-    work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
-    return;
-  }
+                       global_myname(), regname, subrec->subnet_name));
+                       work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+               return;
+       }
   
-  DEBUG(3,("become_local_master_stage2: registered as master browser for workgroup %s \
+       DEBUG(3,("become_local_master_stage2: registered as master browser for workgroup %s \
 on subnet %s\n", work->work_group, subrec->subnet_name));
 
-  work->mst_state = MST_BROWSER; /* registering WORKGROUP(1d) succeeded */
-
-  /* update our server status */
-  servrec->serv.type |= SV_TYPE_MASTER_BROWSER;
-  servrec->serv.type &= ~SV_TYPE_POTENTIAL_BROWSER;
-
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
-
-  /* Add this name to the workgroup as local master browser. */
-  set_workgroup_local_master_browser_name( work, global_myname());
-
-  /* Count the number of servers we have on our list. If it's
-     less than 10 (just a heuristic) request the servers
-     to announce themselves.
-   */
-  for( sl = work->serverlist; sl != NULL; sl = sl->next)
-    i++;
-
-  if (i < 10)
-  {
-    /* Ask all servers on our local net to announce to us. */
-    broadcast_announce_request(subrec, work);
-  }
-
-  /*
-   * Now we are a local master on a broadcast subnet, we need to add
-   * the WORKGROUP<1d> name to the unicast subnet so that we can answer
-   * unicast requests sent to this name. We can create this name directly on
-   * the unicast subnet as a WINS server always returns true when registering
-   * this name, and discards the registration. We use the number of IP
-   * addresses registered to this name as a reference count, as we
-   * remove this broadcast subnet IP address from it when we stop becoming a local
-   * master browser for this broadcast subnet.
-   */
-
-  insert_permanent_name_into_unicast( subrec, registered_name, nb_flags);
-
-  /* Reset the announce master browser timer so that we try and tell a domain
-     master browser as soon as possible that we are a local master browser. */
-  reset_announce_timer();
-
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "*****\n\n" );
-    dbgtext( "Samba name server %s ", global_myname() );
-    dbgtext( "is now a local master browser " );
-    dbgtext( "for workgroup %s ", work->work_group );
-    dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
-  }
-
+       work->mst_state = MST_BROWSER; /* registering WORKGROUP(1d) succeeded */
+
+       /* update our server status */
+       servrec->serv.type |= SV_TYPE_MASTER_BROWSER;
+       servrec->serv.type &= ~SV_TYPE_POTENTIAL_BROWSER;
+
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
+
+       /* Add this name to the workgroup as local master browser. */
+       set_workgroup_local_master_browser_name( work, global_myname());
+
+       /* Count the number of servers we have on our list. If it's
+               less than 10 (just a heuristic) request the servers
+               to announce themselves.
+       */
+       for( sl = work->serverlist; sl != NULL; sl = sl->next)
+               i++;
+
+       if (i < 10) {
+               /* Ask all servers on our local net to announce to us. */
+               broadcast_announce_request(subrec, work);
+       }
+
+       /*
+        * Now we are a local master on a broadcast subnet, we need to add
+        * the WORKGROUP<1d> name to the unicast subnet so that we can answer
+        * unicast requests sent to this name. We can create this name directly on
+        * the unicast subnet as a WINS server always returns true when registering
+        * this name, and discards the registration. We use the number of IP
+        * addresses registered to this name as a reference count, as we
+        * remove this broadcast subnet IP address from it when we stop becoming a local
+        * master browser for this broadcast subnet.
+        */
+
+       insert_permanent_name_into_unicast( subrec, registered_name, nb_flags);
+
+       /* Reset the announce master browser timer so that we try and tell a domain
+               master browser as soon as possible that we are a local master browser. */
+       reset_announce_timer();
+
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "*****\n\n" );
+               dbgtext( "Samba name server %s ", global_myname() );
+               dbgtext( "is now a local master browser " );
+               dbgtext( "for workgroup %s ", work->work_group );
+               dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name );
+       }
 }
 
 /****************************************************************************
   Failed to register the WORKGROUP<1d> name.
   ****************************************************************************/
+
 static void become_local_master_fail2(struct subnet_record *subrec,
                                       struct response_record *rrec,
                                       struct nmb_name *fail_name)
 {
-  struct work_record *work = find_workgroup_on_subnet( subrec, fail_name->name);
+       nstring failname;
+       struct work_record *work;
 
-  DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \
+       DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \
 Failed to become a local master browser.\n", nmb_namestr(fail_name), subrec->subnet_name));
 
-  if(!work)
-  {
-    DEBUG(0,("become_local_master_fail2: Error - cannot find \
-workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name));
-    return;
-  }
+       pull_ascii_nstring(failname, fail_name->name);
+       work = find_workgroup_on_subnet( subrec, failname);
 
-  /* Roll back all the way by calling unbecome_local_master_browser(). */
-  unbecome_local_master_browser(subrec, work, False);
+       if(!work) {
+               DEBUG(0,("become_local_master_fail2: Error - cannot find \
+workgroup %s on subnet %s\n", failname, subrec->subnet_name));
+               return;
+       }
+
+       /* Roll back all the way by calling unbecome_local_master_browser(). */
+       unbecome_local_master_browser(subrec, work, False);
 }
 
 /****************************************************************************
@@ -442,35 +439,34 @@ static void become_local_master_stage1(struct subnet_record *subrec,
                                         uint16 nb_flags,
                                         int ttl, struct in_addr registered_ip)
 {
-  char *work_name = userdata->data;
-  struct work_record *work = find_workgroup_on_subnet( subrec, work_name);
-
-  if(!work)
-  {
-    DEBUG(0,("become_local_master_stage1: Error - cannot find \
-workgroup %s on subnet %s\n", work_name, subrec->subnet_name));
-    return;
-  }
-
-  DEBUG(3,("become_local_master_stage1: go to stage 2: register the %s<1d> name.\n",
-            work->work_group));
-
-  work->mst_state = MST_MSB; /* Registering MSBROWSE was successful. */
-
-  /*
-   * We registered the MSBROWSE name on a broadcast subnet, now need to add
-   * the MSBROWSE name to the unicast subnet so that we can answer
-   * unicast requests sent to this name. We create this name directly on
-   * the unicast subnet.
-   */
-
-  insert_permanent_name_into_unicast( subrec, registered_name, nb_flags);
-
-  /* Attempt to register the WORKGROUP<1d> name. */
-  register_name(subrec, work->work_group,0x1d,samba_nb_type,
-                become_local_master_stage2,
-                become_local_master_fail2,
-                NULL);
+       char *work_name = userdata->data;
+       struct work_record *work = find_workgroup_on_subnet( subrec, work_name);
+
+       if(!work) {
+               DEBUG(0,("become_local_master_stage1: Error - cannot find \
+                       %s on subnet %s\n", work_name, subrec->subnet_name));
+               return;
+       }
+
+       DEBUG(3,("become_local_master_stage1: go to stage 2: register the %s<1d> name.\n",
+               work->work_group));
+
+       work->mst_state = MST_MSB; /* Registering MSBROWSE was successful. */
+
+       /*
+        * We registered the MSBROWSE name on a broadcast subnet, now need to add
+        * the MSBROWSE name to the unicast subnet so that we can answer
+        * unicast requests sent to this name. We create this name directly on
+        * the unicast subnet.
+        */
+
+       insert_permanent_name_into_unicast( subrec, registered_name, nb_flags);
+
+       /* Attempt to register the WORKGROUP<1d> name. */
+       register_name(subrec, work->work_group,0x1d,samba_nb_type,
+               become_local_master_stage2,
+               become_local_master_fail2,
+               NULL);
 }
 
 /****************************************************************************
@@ -481,29 +477,27 @@ static void become_local_master_fail1(struct subnet_record *subrec,
                                       struct response_record *rrec,
                                       struct nmb_name *fail_name)
 {
-  char *work_name = rrec->userdata->data;
-  struct work_record *work = find_workgroup_on_subnet(subrec, work_name);
+       char *work_name = rrec->userdata->data;
+       struct work_record *work = find_workgroup_on_subnet(subrec, work_name);
 
-  if(!work)
-  {
-    DEBUG(0,("become_local_master_fail1: Error - cannot find \
+       if(!work) {
+               DEBUG(0,("become_local_master_fail1: Error - cannot find \
 workgroup %s on subnet %s\n", work_name, subrec->subnet_name));
-    return;
-  }
+               return;
+       }
 
-  if(find_server_in_workgroup(work, global_myname()) == NULL)
-  {
-    DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \
+       if(find_server_in_workgroup(work, global_myname()) == NULL) {
+               DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), work->work_group, subrec->subnet_name));
-    return;
-  }
+                       global_myname(), work->work_group, subrec->subnet_name));
+               return;
+       }
 
-  reset_workgroup_state( subrec, work->work_group, False );
+       reset_workgroup_state( subrec, work->work_group, False );
 
-  DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \
+       DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \
 workgroup %s on subnet %s. Couldn't register name %s.\n",
-       work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
+               work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
 }
 
 /******************************************************************
@@ -517,61 +511,57 @@ workgroup %s on subnet %s. Couldn't register name %s.\n",
 
 void become_local_master_browser(struct subnet_record *subrec, struct work_record *work)
 {
-  struct userdata_struct *userdata;
-  size_t size = sizeof(struct userdata_struct) + sizeof(fstring) + 1;
-
-  /* Sanity check. */
-  if (!lp_local_master())
-  { 
-    DEBUG(0,("become_local_master_browser: Samba not configured as a local master browser.\n"));
-    return;
-  }
-
-  if(!AM_POTENTIAL_MASTER_BROWSER(work))
-  {
-    DEBUG(2,("become_local_master_browser: Awaiting potential browser state. Current state is %d\n",
-              work->mst_state ));
-    return;
-  }
-
-  if(find_server_in_workgroup( work, global_myname()) == NULL)
-  {
-    DEBUG(0,("become_local_master_browser: Error - cannot find server %s \
+       struct userdata_struct *userdata;
+       size_t size = sizeof(struct userdata_struct) + sizeof(fstring) + 1;
+
+       /* Sanity check. */
+       if (!lp_local_master()) { 
+               DEBUG(0,("become_local_master_browser: Samba not configured as a local master browser.\n"));
+               return;
+       }
+
+       if(!AM_POTENTIAL_MASTER_BROWSER(work)) {
+               DEBUG(2,("become_local_master_browser: Awaiting potential browser state. Current state is %d\n",
+                       work->mst_state ));
+               return;
+       }
+
+       if(find_server_in_workgroup( work, global_myname()) == NULL) {
+               DEBUG(0,("become_local_master_browser: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), work->work_group, subrec->subnet_name));
-    return;
-  }
+                       global_myname(), work->work_group, subrec->subnet_name));
+               return;
+       }
 
-  DEBUG(2,("become_local_master_browser: Starting to become a master browser for workgroup \
+       DEBUG(2,("become_local_master_browser: Starting to become a master browser for workgroup \
 %s on subnet %s\n", work->work_group, subrec->subnet_name));
   
-  DEBUG(3,("become_local_master_browser: first stage - attempt to register ^1^2__MSBROWSE__^2^1\n"));
-  work->mst_state = MST_BACKUP; /* an election win was successful */
+       DEBUG(3,("become_local_master_browser: first stage - attempt to register ^1^2__MSBROWSE__^2^1\n"));
+       work->mst_state = MST_BACKUP; /* an election win was successful */
 
-  work->ElectionCriterion |= 0x5;
+       work->ElectionCriterion |= 0x5;
 
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
 
-  /* Setup the userdata_struct. */
-  if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
-  {
-    DEBUG(0,("become_local_master_browser: malloc fail.\n"));
-    return;
-  }
+       /* Setup the userdata_struct. */
+       if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+               DEBUG(0,("become_local_master_browser: malloc fail.\n"));
+               return;
+       }
 
-  userdata->copy_fn = NULL;
-  userdata->free_fn = NULL;
-  userdata->userdata_len = strlen(work->work_group)+1;
-  overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1);
+       userdata->copy_fn = NULL;
+       userdata->free_fn = NULL;
+       userdata->userdata_len = strlen(work->work_group)+1;
+       overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1);
 
-  /* Register the special browser group name. */
-  register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP,
-                become_local_master_stage1,
-                become_local_master_fail1,
-                userdata);
+       /* Register the special browser group name. */
+       register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP,
+               become_local_master_stage1,
+               become_local_master_fail1,
+               userdata);
 
-  zero_free(userdata, size);
+       zero_free(userdata, size);
 }
 
 /***************************************************************
@@ -583,7 +573,7 @@ in workgroup %s on subnet %s\n",
 
 void set_workgroup_local_master_browser_name( struct work_record *work, const char *newname)
 {
-  DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \
+       DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \
 for workgroup %s.\n", newname, work->work_group ));
 
 #if 0
@@ -600,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n",
   }
 #endif
 
-  fstrcpy(work->local_master_browser_name, newname);
+       nstrcpy(work->local_master_browser_name, newname);
 }
index 4a302ddfd411e2e8760a071f08d337aed89c4b64..443edf599d058eaa5d5486435e51aeb5a7ce2bab 100644 (file)
@@ -80,8 +80,8 @@ void update_browser_death_time( struct browse_cache_record *browc )
  *
  * ************************************************************************** **
  */
-struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, 
-                                                         char *browser_name, 
+struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, 
+                                                         const char *browser_name, 
                                                          struct in_addr ip )
 {
        struct browse_cache_record *browc;
@@ -106,8 +106,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
        /* Allow the new lmb to miss an announce period before we remove it. */
        browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
 
-       pstrcpy(  browc->lmb_name, browser_name);
-       pstrcpy(  browc->work_group, work_name);
+       nstrcpy(  browc->lmb_name, browser_name);
+       nstrcpy(  browc->work_group, work_name);
        strupper_m( browc->lmb_name );
        strupper_m( browc->work_group );
   
@@ -134,7 +134,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
  *
  * ************************************************************************** **
  */
-struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
+struct browse_cache_record *find_browser_in_lmb_cache( const char *browser_name )
 {
        struct browse_cache_record *browc;
 
index 26d4735744fa791847c09dac874d50713bf73a36..6cde88651f9cbd3f9877bf02242b674f08d0a79f 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -29,74 +29,70 @@ extern ubi_dlList lmb_browserlist[];
 /****************************************************************************
 As a domain master browser, do a sync with a local master browser.
 **************************************************************************/
+
 static void sync_with_lmb(struct browse_cache_record *browc)
 {                     
-  struct work_record *work;
-
-  if( !(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group)) )
-  {
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "sync_with_lmb:\n" );
-      dbgtext( "Failed to get a workgroup for a local master browser " );
-      dbgtext( "cache entry workgroup " );
-      dbgtext( "%s, server %s\n", browc->work_group, browc->lmb_name );
-    }
-    return;
-  }
+       struct work_record *work;
 
-  /* We should only be doing this if we are a domain master browser for
-     the given workgroup. Ensure this is so. */
-
-  if(!AM_DOMAIN_MASTER_BROWSER(work))
-  {
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "sync_with_lmb:\n" );
-      dbgtext( "We are trying to sync with a local master browser " );
-      dbgtext( "%s for workgroup %s\n", browc->lmb_name, browc->work_group );
-      dbgtext( "and we are not a domain master browser on this workgroup.\n" );
-      dbgtext( "Error!\n" );
-    }
-    return;
-  }
+       if( !(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group)) ) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "sync_with_lmb:\n" );
+                       dbgtext( "Failed to get a workgroup for a local master browser " );
+                       dbgtext( "cache entry workgroup " );
+                       dbgtext( "%s, server %s\n", browc->work_group, browc->lmb_name );
+               }
+               return;
+       }
 
-  if( DEBUGLVL( 2 ) )
-  {
-    dbgtext( "sync_with_lmb:\n" );
-    dbgtext( "Initiating sync with local master browser " );
-    dbgtext( "%s<0x20> at IP %s ", browc->lmb_name, inet_ntoa(browc->ip) );
-    dbgtext( "for workgroup %s\n", browc->work_group );
-  }
+       /* We should only be doing this if we are a domain master browser for
+               the given workgroup. Ensure this is so. */
 
-  sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True);
+       if(!AM_DOMAIN_MASTER_BROWSER(work)) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "sync_with_lmb:\n" );
+                       dbgtext( "We are trying to sync with a local master browser " );
+                       dbgtext( "%s for workgroup %s\n", browc->lmb_name, browc->work_group );
+                       dbgtext( "and we are not a domain master browser on this workgroup.\n" );
+                       dbgtext( "Error!\n" );
+               }
+               return;
+       }
+
+       if( DEBUGLVL( 2 ) ) {
+               dbgtext( "sync_with_lmb:\n" );
+               dbgtext( "Initiating sync with local master browser " );
+               dbgtext( "%s<0x20> at IP %s ", browc->lmb_name, inet_ntoa(browc->ip) );
+               dbgtext( "for workgroup %s\n", browc->work_group );
+       }
+
+       sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True);
 
-  browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60);
+       browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60);
 }
 
 /****************************************************************************
 Sync or expire any local master browsers.
 **************************************************************************/
+
 void dmb_expire_and_sync_browser_lists(time_t t)
 {
-  static time_t last_run = 0;
-  struct browse_cache_record *browc;
+       static time_t last_run = 0;
+       struct browse_cache_record *browc;
 
-  /* Only do this every 20 seconds. */  
-  if (t - last_run < 20) 
-   return;
+       /* Only do this every 20 seconds. */  
+       if (t - last_run < 20) 
+               return;
 
-  last_run = t;
+       last_run = t;
 
-  expire_lmb_browsers(t);
+       expire_lmb_browsers(t);
 
-  for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
-       browc;
-       browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
-  {
-    if (browc->sync_time < t)
-      sync_with_lmb(browc);
-  }
+       for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+                       browc;
+                       browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) {
+               if (browc->sync_time < t)
+                       sync_with_lmb(browc);
+       }
 }
 
 /****************************************************************************
@@ -105,46 +101,43 @@ As a local master browser, send an announce packet to the domain master browser.
 
 static void announce_local_master_browser_to_domain_master_browser( struct work_record *work)
 {
-  pstring outbuf;
-  fstring myname;
-  char *p;
-
-  if(ismyip(work->dmb_addr))
-  {
-    if( DEBUGLVL( 2 ) )
-    {
-      dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
-      dbgtext( "We are both a domain and a local master browser for " );
-      dbgtext( "workgroup %s.  ", work->work_group );
-      dbgtext( "Do not announce to ourselves.\n" );
-    }
-    return;
-  }
+       pstring outbuf;
+       fstring myname;
+       char *p;
+
+       if(ismyip(work->dmb_addr)) {
+               if( DEBUGLVL( 2 ) ) {
+                       dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
+                       dbgtext( "We are both a domain and a local master browser for " );
+                       dbgtext( "workgroup %s.  ", work->work_group );
+                       dbgtext( "Do not announce to ourselves.\n" );
+               }
+               return;
+       }
 
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf;
-  SCVAL(p,0,ANN_MasterAnnouncement);
-  p++;
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf;
+       SCVAL(p,0,ANN_MasterAnnouncement);
+       p++;
 
-  fstrcpy(myname, global_myname());
-  strupper_m(myname);
-  myname[15]='\0';
-  push_pstring_base(p, myname, outbuf);
+       fstrcpy(myname, global_myname());
+       strupper_m(myname);
+       myname[15]='\0';
+       /* The call below does CH_UNIX -> CH_DOS conversion. JRA */
+       push_pstring_base(p, myname, outbuf);
 
-  p = skip_string(p,1);
+       p = skip_string(p,1);
 
-  if( DEBUGLVL( 4 ) )
-  {
-    dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
-    dbgtext( "Sending local master announce to " );
-    dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name),
-                                       work->work_group );
-  }
+       if( DEBUGLVL( 4 ) ) {
+               dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
+               dbgtext( "Sending local master announce to " );
+               dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name),
+                                       work->work_group );
+       }
 
-  send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
+       send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
                global_myname(), 0x0, work->dmb_name.name, 0x0, 
                work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT);
-
 }
 
 /****************************************************************************
@@ -153,17 +146,19 @@ As a local master browser, do a sync with a domain master browser.
 
 static void sync_with_dmb(struct work_record *work)
 {
-  if( DEBUGLVL( 2 ) )
-  {
-    dbgtext( "sync_with_dmb:\n" );
-    dbgtext( "Initiating sync with domain master browser " );
-    dbgtext( "%s ", nmb_namestr(&work->dmb_name) );
-    dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) );
-    dbgtext( "for workgroup %s\n", work->work_group );
-  }
+       nstring dmb_name;
+
+       if( DEBUGLVL( 2 ) ) {
+               dbgtext( "sync_with_dmb:\n" );
+               dbgtext( "Initiating sync with domain master browser " );
+               dbgtext( "%s ", nmb_namestr(&work->dmb_name) );
+               dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) );
+               dbgtext( "for workgroup %s\n", work->work_group );
+       }
 
-  sync_browse_lists(work, work->dmb_name.name, work->dmb_name.name_type, 
-                    work->dmb_addr, False, True);
+       pull_ascii_nstring(dmb_name, work->dmb_name.name);
+       sync_browse_lists(work, dmb_name, work->dmb_name.name_type, 
+               work->dmb_addr, False, True);
 }
 
 /****************************************************************************
@@ -175,78 +170,69 @@ static void domain_master_node_status_success(struct subnet_record *subrec,
                                               struct res_rec *answers,
                                               struct in_addr from_ip)
 {
-  struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data);
-
-  if( work == NULL )
-  {
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "domain_master_node_status_success:\n" );
-      dbgtext( "Unable to find workgroup " );
-      dbgtext( "%s on subnet %s.\n", userdata->data, subrec->subnet_name );
-    }
-    return;
-  }
+       struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data);
 
-  if( DEBUGLVL( 3 ) )
-  {
-    dbgtext( "domain_master_node_status_success:\n" );
-    dbgtext( "Success in node status for workgroup " );
-    dbgtext( "%s from ip %s\n", work->work_group, inet_ntoa(from_ip) );
-  }
+       if( work == NULL ) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "domain_master_node_status_success:\n" );
+                       dbgtext( "Unable to find workgroup " );
+                       dbgtext( "%s on subnet %s.\n", userdata->data, subrec->subnet_name );
+               }
+               return;
+       }
+
+       if( DEBUGLVL( 3 ) ) {
+               dbgtext( "domain_master_node_status_success:\n" );
+               dbgtext( "Success in node status for workgroup " );
+               dbgtext( "%s from ip %s\n", work->work_group, inet_ntoa(from_ip) );
+       }
 
   /* Go through the list of names found at answers->rdata and look for
      the first SERVER<0x20> name. */
 
-  if(answers->rdata != NULL)
-  {
-    char *p = answers->rdata;
-    int numnames = CVAL(p, 0);
+       if(answers->rdata != NULL) {
+               char *p = answers->rdata;
+               int numnames = CVAL(p, 0);
 
-    p += 1;
+               p += 1;
 
-    while (numnames--)
-    {
-      char qname[17];
-      uint16 nb_flags;
-      int name_type;
+               while (numnames--) {
+                       nstring qname;
+                       uint16 nb_flags;
+                       int name_type;
 
-      StrnCpy(qname,p,15);
-      name_type = CVAL(p,15);
-      nb_flags = get_nb_flags(&p[16]);
-      trim_string(qname,NULL," ");
+                       pull_ascii_nstring(qname, p);
+                       name_type = CVAL(p,15);
+                       nb_flags = get_nb_flags(&p[16]);
+                       trim_char(qname,'\0',' ');
 
-      p += 18;
+                       p += 18;
 
-      if(!(nb_flags & NB_GROUP) && (name_type == 0x20))
-      {
-        struct nmb_name nmbname;
+                       if(!(nb_flags & NB_GROUP) && (name_type == 0x20)) {
+                               struct nmb_name nmbname;
 
-        make_nmb_name(&nmbname, qname, name_type);
+                               make_nmb_name(&nmbname, qname, name_type);
 
-        /* Copy the dmb name and IP address
-           into the workgroup struct. */
+                               /* Copy the dmb name and IP address
+                                       into the workgroup struct. */
 
-        work->dmb_name = nmbname;
-        putip((char *)&work->dmb_addr, &from_ip);
+                               work->dmb_name = nmbname;
+                               putip((char *)&work->dmb_addr, &from_ip);
 
-        /* Do the local master browser announcement to the domain
-           master browser name and IP. */
-        announce_local_master_browser_to_domain_master_browser( work );
+                               /* Do the local master browser announcement to the domain
+                                       master browser name and IP. */
+                               announce_local_master_browser_to_domain_master_browser( work );
 
-        /* Now synchronise lists with the domain master browser. */
-        sync_with_dmb(work);
-        break;
-      }
-    }
-  }
-  else
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "domain_master_node_status_success:\n" );
-      dbgtext( "Failed to find a SERVER<0x20> name in reply from IP " );
-      dbgtext( "%s.\n", inet_ntoa(from_ip) );
-    }
+                               /* Now synchronise lists with the domain master browser. */
+                               sync_with_dmb(work);
+                               break;
+                       }
+               }
+       } else if( DEBUGLVL( 0 ) ) {
+               dbgtext( "domain_master_node_status_success:\n" );
+               dbgtext( "Failed to find a SERVER<0x20> name in reply from IP " );
+               dbgtext( "%s.\n", inet_ntoa(from_ip) );
+       }
 }
 
 /****************************************************************************
@@ -256,16 +242,15 @@ static void domain_master_node_status_success(struct subnet_record *subrec,
 static void domain_master_node_status_fail(struct subnet_record *subrec,
                        struct response_record *rrec)
 {
-  struct userdata_struct *userdata = rrec->userdata;
-
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "domain_master_node_status_fail:\n" );
-    dbgtext( "Doing a node status request to the domain master browser\n" );
-    dbgtext( "for workgroup %s ", userdata ? userdata->data : "NULL" );
-    dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) );
-    dbgtext( "Cannot sync browser lists.\n" );
-  }
+       struct userdata_struct *userdata = rrec->userdata;
+
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "domain_master_node_status_fail:\n" );
+               dbgtext( "Doing a node status request to the domain master browser\n" );
+               dbgtext( "for workgroup %s ", userdata ? userdata->data : "NULL" );
+               dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) );
+               dbgtext( "Cannot sync browser lists.\n" );
+       }
 }
 
 /****************************************************************************
@@ -276,100 +261,99 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec,
                         struct userdata_struct *userdata_in,
                         struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec)
 {
-  /* 
-   * Unfortunately, finding the IP address of the Domain Master Browser,
-   * as we have here, is not enough. We need to now do a sync to the
-   * SERVERNAME<0x20> NetBIOS name, as only recent NT servers will
-   * respond to the SMBSERVER name. To get this name from IP
-   * address we do a Node status request, and look for the first
-   * NAME<0x20> in the response, and take that as the server name.
-   * We also keep a cache of the Domain Master Browser name for this
-   * workgroup in the Workgroup struct, so that if the same IP addess
-   * is returned every time, we don't need to do the node status
-   * request.
-   */
-
-  struct work_record *work;
-  struct nmb_name nmbname;
-  struct userdata_struct *userdata;
-  size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1;
-
-  if( !(work = find_workgroup_on_subnet(subrec, q_name->name)) )
-  {
-    if( DEBUGLVL( 0 ) )
-      {
-      dbgtext( "find_domain_master_name_query_success:\n" );
-      dbgtext( "Failed to find workgroup %s\n", q_name->name );
-      }
-    return;
+       /* 
+        * Unfortunately, finding the IP address of the Domain Master Browser,
+        * as we have here, is not enough. We need to now do a sync to the
+        * SERVERNAME<0x20> NetBIOS name, as only recent NT servers will
+        * respond to the SMBSERVER name. To get this name from IP
+        * address we do a Node status request, and look for the first
+        * NAME<0x20> in the response, and take that as the server name.
+        * We also keep a cache of the Domain Master Browser name for this
+        * workgroup in the Workgroup struct, so that if the same IP addess
+        * is returned every time, we don't need to do the node status
+        * request.
+        */
+
+       struct work_record *work;
+       struct nmb_name nmbname;
+       struct userdata_struct *userdata;
+       size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1;
+       nstring qname;
+
+       pull_ascii_nstring(qname, q_name->name);
+       if( !(work = find_workgroup_on_subnet(subrec, qname)) ) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "find_domain_master_name_query_success:\n" );
+                       dbgtext( "Failed to find workgroup %s\n", qname);
+               }
+       return;
   }
 
   /* First check if we already have a dmb for this workgroup. */
 
-  if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip))
-  {
-    /* Do the local master browser announcement to the domain
-       master browser name and IP. */
-    announce_local_master_browser_to_domain_master_browser( work );
+       if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) {
+               /* Do the local master browser announcement to the domain
+                       master browser name and IP. */
+               announce_local_master_browser_to_domain_master_browser( work );
 
-    /* Now synchronise lists with the domain master browser. */
-    sync_with_dmb(work);
-    return;
-  }
-  else
-    zero_ip(&work->dmb_addr);
-
-  /* Now initiate the node status request. */
-
-  /* We used to use the name "*",0x0 here, but some Windows
-   * servers don't answer that name. However we *know* they
-   * have the name workgroup#1b (as we just looked it up).
-   * So do the node status request on this name instead.
-   * Found at LBL labs. JRA.
-   */
-
-  make_nmb_name(&nmbname,work->work_group,0x1b);
-
-  /* Put the workgroup name into the userdata so we know
-     what workgroup we're talking to when the reply comes
-     back. */
-
-  /* Setup the userdata_struct - this is copied so we can use
-     a stack variable for this. */
-  if((userdata = (struct userdata_struct *)malloc(size)) == NULL)
-  {
-    DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n"));
-    return;
-  }
+               /* Now synchronise lists with the domain master browser. */
+               sync_with_dmb(work);
+               return;
+       } else {
+               zero_ip(&work->dmb_addr);
+       }
 
-  userdata->copy_fn = NULL;
-  userdata->free_fn = NULL;
-  userdata->userdata_len = strlen(work->work_group)+1;
-  overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1);
+       /* Now initiate the node status request. */
 
-  node_status( subrec, &nmbname, answer_ip, 
-               domain_master_node_status_success,
-               domain_master_node_status_fail,
-               userdata);
+       /* We used to use the name "*",0x0 here, but some Windows
+        * servers don't answer that name. However we *know* they
+        * have the name workgroup#1b (as we just looked it up).
+        * So do the node status request on this name instead.
+        * Found at LBL labs. JRA.
+        */
 
-  zero_free(userdata, size);
+       make_nmb_name(&nmbname,work->work_group,0x1b);
+
+       /* Put the workgroup name into the userdata so we know
+        what workgroup we're talking to when the reply comes
+        back. */
+
+       /* Setup the userdata_struct - this is copied so we can use
+       a stack variable for this. */
+
+       if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+               DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n"));
+               return;
+       }
+
+       userdata->copy_fn = NULL;
+       userdata->free_fn = NULL;
+       userdata->userdata_len = strlen(work->work_group)+1;
+       overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1);
+
+       node_status( subrec, &nmbname, answer_ip, 
+               domain_master_node_status_success,
+               domain_master_node_status_fail,
+               userdata);
+
+       zero_free(userdata, size);
 }
 
 /****************************************************************************
   Function called when a query for a WORKGROUP<1b> name fails.
   ****************************************************************************/
+
 static void find_domain_master_name_query_fail(struct subnet_record *subrec,
                                     struct response_record *rrec,
                                     struct nmb_name *question_name, int fail_code)
 {
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "find_domain_master_name_query_fail:\n" );
-    dbgtext( "Unable to find the Domain Master Browser name " );
-    dbgtext( "%s for the workgroup %s.\n",
-             nmb_namestr(question_name), question_name->name );
-    dbgtext( "Unable to sync browse lists in this workgroup.\n" );
-  }
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "find_domain_master_name_query_fail:\n" );
+               dbgtext( "Unable to find the Domain Master Browser name " );
+               dbgtext( "%s for the workgroup %s.\n",
+                       nmb_namestr(question_name), question_name->name );
+               dbgtext( "Unable to sync browse lists in this workgroup.\n" );
+       }
 }
 
 /****************************************************************************
@@ -381,27 +365,20 @@ full domain browse lists from it onto the given subnet.
 void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec,
                                                    struct work_record *work)
 {
-  struct nmb_name nmbname;
-
-  /* Only do this if we are using a WINS server. */
-  if(we_are_a_wins_client() == False)
-  {
-    if( DEBUGLVL( 10 ) )
-    {
-      dbgtext( "announce_and_sync_with_domain_master_browser:\n" );
-      dbgtext( "Ignoring, as we are not a WINS client.\n" );
-    }
-    return;
-  }
-
-  make_nmb_name(&nmbname,work->work_group,0x1b);
+       /* Only do this if we are using a WINS server. */
+       if(we_are_a_wins_client() == False) {
+               if( DEBUGLVL( 10 ) ) {
+                       dbgtext( "announce_and_sync_with_domain_master_browser:\n" );
+                       dbgtext( "Ignoring, as we are not a WINS client.\n" );
+               }
+               return;
+       }
 
-  /* First, query for the WORKGROUP<1b> name from the WINS server. */
-  query_name(unicast_subnet, nmbname.name, nmbname.name_type,
+       /* First, query for the WORKGROUP<1b> name from the WINS server. */
+       query_name(unicast_subnet, work->work_group, 0x1b,
              find_domain_master_name_query_success,
              find_domain_master_name_query_fail,
              NULL);
-
 }
 
 /****************************************************************************
@@ -421,89 +398,81 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub
                                               struct res_rec *answers,
                                               struct in_addr from_ip)
 {
-  struct work_record *work;
-  fstring server_name;
+       struct work_record *work;
+       fstring server_name;
 
-  server_name[0] = 0;
+       server_name[0] = 0;
 
-  if( DEBUGLVL( 3 ) )
-  {
-    dbgtext( "get_domain_master_name_node_status_success:\n" );
-    dbgtext( "Success in node status from ip %s\n", inet_ntoa(from_ip) );
-  }
+       if( DEBUGLVL( 3 ) ) {
+               dbgtext( "get_domain_master_name_node_status_success:\n" );
+               dbgtext( "Success in node status from ip %s\n", inet_ntoa(from_ip) );
+       }
 
-  /* 
-   * Go through the list of names found at answers->rdata and look for
-   * the first WORKGROUP<0x1b> name.
-   */
-
-  if(answers->rdata != NULL)
-  {
-    char *p = answers->rdata;
-    int numnames = CVAL(p, 0);
-
-    p += 1;
-
-    while (numnames--)
-    {
-      char qname[17];
-      uint16 nb_flags;
-      int name_type;
-
-      StrnCpy(qname,p,15);
-      name_type = CVAL(p,15);
-      nb_flags = get_nb_flags(&p[16]);
-      trim_string(qname,NULL," ");
-
-      p += 18;
-
-      if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && 
-        server_name[0] == 0) {
-             /* this is almost certainly the server netbios name */
-             fstrcpy(server_name, qname);
-             continue;
-      }
-
-      if(!(nb_flags & NB_GROUP) && (name_type == 0x1b))
-      {
-        if( DEBUGLVL( 5 ) )
-        {
-          dbgtext( "get_domain_master_name_node_status_success:\n" );
-          dbgtext( "%s(%s) ", server_name, inet_ntoa(from_ip) );
-          dbgtext( "is a domain master browser for workgroup " );
-          dbgtext( "%s. Adding this name.\n", qname );
-        }
-
-        /* 
-         * If we don't already know about this workgroup, add it
-         * to the workgroup list on the unicast_subnet.
-         */
-        if((work = find_workgroup_on_subnet( subrec, qname)) == NULL)
-       {
-               struct nmb_name nmbname;
-               /* 
-                * Add it - with an hour in the cache.
-                */
-               if(!(work= create_workgroup_on_subnet(subrec, qname, 60*60)))
-                       return;
-
-               /* remember who the master is */
-               fstrcpy(work->local_master_browser_name, server_name);
-               make_nmb_name(&nmbname, server_name, 0x20);
-               work->dmb_name = nmbname;
-               work->dmb_addr = from_ip;
-        }
-        break;
-      }
-    }
-  }
-  else
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "get_domain_master_name_node_status_success:\n" );
-      dbgtext( "Failed to find a WORKGROUP<0x1b> name in reply from IP " );
-      dbgtext( "%s.\n", inet_ntoa(from_ip) );
-    }
+       /* 
+        * Go through the list of names found at answers->rdata and look for
+        * the first WORKGROUP<0x1b> name.
+        */
+
+       if(answers->rdata != NULL) {
+               char *p = answers->rdata;
+               int numnames = CVAL(p, 0);
+
+               p += 1;
+
+               while (numnames--) {
+                       nstring qname;
+                       uint16 nb_flags;
+                       int name_type;
+
+                       pull_ascii_nstring(qname, p);
+                       name_type = CVAL(p,15);
+                       nb_flags = get_nb_flags(&p[16]);
+                       trim_char(qname,'\0',' ');
+
+                       p += 18;
+
+                       if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && 
+                                       server_name[0] == 0) {
+                               /* this is almost certainly the server netbios name */
+                               fstrcpy(server_name, qname);
+                               continue;
+                       }
+
+                       if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) {
+                               if( DEBUGLVL( 5 ) ) {
+                                       dbgtext( "get_domain_master_name_node_status_success:\n" );
+                                       dbgtext( "%s(%s) ", server_name, inet_ntoa(from_ip) );
+                                       dbgtext( "is a domain master browser for workgroup " );
+                                       dbgtext( "%s. Adding this name.\n", qname );
+                               }
+
+                               /* 
+                                * If we don't already know about this workgroup, add it
+                                * to the workgroup list on the unicast_subnet.
+                                */
+
+                               if((work = find_workgroup_on_subnet( subrec, qname)) == NULL) {
+                                       struct nmb_name nmbname;
+                                       /* 
+                                        * Add it - with an hour in the cache.
+                                        */
+                                       if(!(work= create_workgroup_on_subnet(subrec, qname, 60*60)))
+                                               return;
+
+                                       /* remember who the master is */
+                                       nstrcpy(work->local_master_browser_name, server_name);
+                                       make_nmb_name(&nmbname, server_name, 0x20);
+                                       work->dmb_name = nmbname;
+                                       work->dmb_addr = from_ip;
+                               }
+                               break;
+                       }
+               }
+       } else if( DEBUGLVL( 0 ) ) {
+               dbgtext( "get_domain_master_name_node_status_success:\n" );
+               dbgtext( "Failed to find a WORKGROUP<0x1b> name in reply from IP " );
+               dbgtext( "%s.\n", inet_ntoa(from_ip) );
+       }
 }
 
 /****************************************************************************
@@ -513,13 +482,12 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub
 static void get_domain_master_name_node_status_fail(struct subnet_record *subrec,
                        struct response_record *rrec)
 {
-  if( DEBUGLVL( 0 ) )
-  {
-    dbgtext( "get_domain_master_name_node_status_fail:\n" );
-    dbgtext( "Doing a node status request to the domain master browser " );
-    dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) );
-    dbgtext( "Cannot get workgroup name.\n" );
-  }
+       if( DEBUGLVL( 0 ) ) {
+               dbgtext( "get_domain_master_name_node_status_fail:\n" );
+               dbgtext( "Doing a node status request to the domain master browser " );
+               dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) );
+               dbgtext( "Cannot get workgroup name.\n" );
+       }
 }
 
 /****************************************************************************
@@ -530,58 +498,53 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub
                         struct userdata_struct *userdata_in,
                         struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec)
 {
-  /* 
-   * We now have a list of all the domain master browsers for all workgroups
-   * that have registered with the WINS server. Now do a node status request
-   * to each one and look for the first 1b name in the reply. This will be
-   * the workgroup name that we will add to the unicast subnet as a 'non-local'
-   * workgroup.
-   */
-
-  struct nmb_name nmbname;
-  struct in_addr send_ip;
-  int i;
-
-  if( DEBUGLVL( 5 ) )
-  {
-    dbgtext( "find_all_domain_master_names_query_succes:\n" );
-    dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) );
-    dbgtext( "IP addresses for Domain Master Browsers.\n" );
-  }
+       /* 
+        * We now have a list of all the domain master browsers for all workgroups
+        * that have registered with the WINS server. Now do a node status request
+        * to each one and look for the first 1b name in the reply. This will be
+        * the workgroup name that we will add to the unicast subnet as a 'non-local'
+        * workgroup.
+        */
+
+       struct nmb_name nmbname;
+       struct in_addr send_ip;
+       int i;
+
+       if( DEBUGLVL( 5 ) ) {
+               dbgtext( "find_all_domain_master_names_query_succes:\n" );
+               dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) );
+               dbgtext( "IP addresses for Domain Master Browsers.\n" );
+       }
 
-  for(i = 0; i < rrec->rdlength / 6; i++)
-  {
-    /* Initiate the node status requests. */
-    make_nmb_name(&nmbname, "*", 0);
-
-    putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]);
-
-    /* 
-     * Don't send node status requests to ourself.
-     */
-
-    if(ismyip( send_ip ))
-    {
-      if( DEBUGLVL( 5 ) )
-      {
-        dbgtext( "find_all_domain_master_names_query_succes:\n" );
-        dbgtext( "Not sending node status to our own IP " );
-        dbgtext( "%s.\n", inet_ntoa(send_ip) );
-      }
-      continue;
-    }
-
-    if( DEBUGLVL( 5 ) )
-    {
-      dbgtext( "find_all_domain_master_names_query_success:\n" );
-      dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) );
-    }
-
-    node_status( subrec, &nmbname, send_ip, 
-                 get_domain_master_name_node_status_success,
-                 get_domain_master_name_node_status_fail,
-                 NULL);
-  }
+       for(i = 0; i < rrec->rdlength / 6; i++) {
+               /* Initiate the node status requests. */
+               make_nmb_name(&nmbname, "*", 0);
+
+               putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]);
+
+               /* 
+                * Don't send node status requests to ourself.
+                */
+
+               if(ismyip( send_ip )) {
+                       if( DEBUGLVL( 5 ) ) {
+                               dbgtext( "find_all_domain_master_names_query_succes:\n" );
+                               dbgtext( "Not sending node status to our own IP " );
+                               dbgtext( "%s.\n", inet_ntoa(send_ip) );
+                       }
+                       continue;
+               }
+
+               if( DEBUGLVL( 5 ) ) {
+                       dbgtext( "find_all_domain_master_names_query_success:\n" );
+                       dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) );
+               }
+
+               node_status( subrec, &nmbname, send_ip, 
+                               get_domain_master_name_node_status_success,
+                               get_domain_master_name_node_status_fail,
+                               NULL);
+       }
 }
 
 /****************************************************************************
@@ -591,13 +554,12 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec
                                     struct response_record *rrec,
                                     struct nmb_name *question_name, int fail_code)
 {
-  if( DEBUGLVL( 10 ) )
-  {
-    dbgtext( "find_domain_master_name_query_fail:\n" );
-    dbgtext( "WINS server did not reply to a query for name " );
-    dbgtext( "%s.\nThis means it ", nmb_namestr(question_name) );
-    dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" );
-  }
+       if( DEBUGLVL( 10 ) ) {
+               dbgtext( "find_domain_master_name_query_fail:\n" );
+               dbgtext( "WINS server did not reply to a query for name " );
+               dbgtext( "%s.\nThis means it ", nmb_namestr(question_name) );
+               dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" );
+       }
 }
 
 /****************************************************************************
@@ -608,43 +570,39 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec
  <1b> name in the reply - this is the workgroup name. Add this to the unicast
  subnet. This is expensive, so we only do this every 15 minutes.
 **************************************************************************/
+
 void collect_all_workgroup_names_from_wins_server(time_t t)
 {
-  static time_t lastrun = 0;
-  struct work_record *work;
-  struct nmb_name nmbname;
-
-  /* Only do this if we are using a WINS server. */
-  if(we_are_a_wins_client() == False)
-    return;
-
-  /* Check to see if we are a domain master browser on the unicast subnet. */
-  if((work = find_workgroup_on_subnet( unicast_subnet, lp_workgroup())) == NULL)
-  {
-    if( DEBUGLVL( 0 ) )
-    {
-      dbgtext( "collect_all_workgroup_names_from_wins_server:\n" );
-      dbgtext( "Cannot find my workgroup %s ", lp_workgroup() );
-      dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name );
-    }
-    return;
-  }
+       static time_t lastrun = 0;
+       struct work_record *work;
 
-  if(!AM_DOMAIN_MASTER_BROWSER(work))
-    return;
+       /* Only do this if we are using a WINS server. */
+       if(we_are_a_wins_client() == False)
+               return;
 
-  if ((lastrun != 0) && (t < lastrun + (15 * 60)))
-    return;
-     
-  lastrun = t;
+       /* Check to see if we are a domain master browser on the unicast subnet. */
+       if((work = find_workgroup_on_subnet( unicast_subnet, lp_workgroup())) == NULL) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "collect_all_workgroup_names_from_wins_server:\n" );
+                       dbgtext( "Cannot find my workgroup %s ", lp_workgroup() );
+                       dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name );
+               }
+               return;
+       }
+
+       if(!AM_DOMAIN_MASTER_BROWSER(work))
+               return;
 
-  make_nmb_name(&nmbname,"*",0x1b);
+       if ((lastrun != 0) && (t < lastrun + (15 * 60)))
+               return;
+     
+       lastrun = t;
 
-  /* First, query for the *<1b> name from the WINS server. */
-  query_name(unicast_subnet, nmbname.name, nmbname.name_type,
-             find_all_domain_master_names_query_success,
-             find_all_domain_master_names_query_fail,
-             NULL);
+       /* First, query for the *<1b> name from the WINS server. */
+       query_name(unicast_subnet, "*", 0x1b,
+               find_all_domain_master_names_query_success,
+               find_all_domain_master_names_query_fail,
+               NULL);
 } 
 
 
@@ -656,6 +614,7 @@ To prevent exponential network traffic with large numbers of workgroups
 we use a randomised system where sync probability is inversely proportional
 to the number of known workgroups
 **************************************************************************/
+
 void sync_all_dmbs(time_t t)
 {
        static time_t lastrun = 0;
@@ -669,7 +628,8 @@ void sync_all_dmbs(time_t t)
        /* Check to see if we are a domain master browser on the
            unicast subnet. */
        work = find_workgroup_on_subnet(unicast_subnet, lp_workgroup());
-       if (!work) return;
+       if (!work)
+               return;
 
        if (!AM_DOMAIN_MASTER_BROWSER(work))
                return;
@@ -679,15 +639,18 @@ void sync_all_dmbs(time_t t)
      
        /* count how many syncs we might need to do */
        for (work=unicast_subnet->workgrouplist; work; work = work->next) {
-               if (strcmp(lp_workgroup(), work->work_group)) {
+               if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) {
                        count++;
                }
        }
 
        /* sync with a probability of 1/count */
        for (work=unicast_subnet->workgrouplist; work; work = work->next) {
-               if (strcmp(lp_workgroup(), work->work_group)) {
-                       if (((unsigned)sys_random()) % count != 0) continue;
+               if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) {
+                       nstring dmb_name;
+
+                       if (((unsigned)sys_random()) % count != 0)
+                               continue;
 
                        lastrun = t;
 
@@ -699,13 +662,15 @@ void sync_all_dmbs(time_t t)
                                              0x20);
                        }
 
+                       pull_ascii_nstring(dmb_name, work->dmb_name.name);
+
                        DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n",
-                                work->dmb_name.name, 
-                                inet_ntoa(work->dmb_addr)));
+                                dmb_name, inet_ntoa(work->dmb_addr)));
+
                        sync_browse_lists(work, 
-                                         work->dmb_name.name,
+                                         dmb_name,
                                          work->dmb_name.name_type, 
                                          work->dmb_addr, False, False);
                }
        }
-} 
+}
index b948eb9d04ea5bef6a19adb9fd636a440dd08244..fabc0eddca2120894a22a5596a6a7d8cd7a77fe0 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -29,32 +29,36 @@ extern time_t StartupTime;
 /****************************************************************************
   Send an election datagram packet.
 **************************************************************************/
+
 static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name,
                                 uint32 criterion, int timeup,const char *server_name)
 {
-  pstring outbuf;
-  char *p;
-
-  DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n",
-       workgroup_name, subrec->subnet_name ));
-
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf;
-  SCVAL(p,0,ANN_Election); /* Election opcode. */
-  p++;
-
-  SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION));
-  SIVAL(p,1,criterion);
-  SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */
-  p += 13;
-  pstrcpy_base(p, server_name, outbuf);
-  strupper_m(p);
-  p = skip_string(p,1);
+       pstring outbuf;
+       fstring srv_name;
+       char *p;
+
+       DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n",
+               workgroup_name, subrec->subnet_name ));
+
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf;
+       SCVAL(p,0,ANN_Election); /* Election opcode. */
+       p++;
+
+       SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION));
+       SIVAL(p,1,criterion);
+       SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */
+       p += 13;
+       fstrcpy(srv_name, server_name);
+       strupper_m(srv_name);
+       /* The following call does UNIX -> DOS charset conversion. */
+       pstrcpy_base(p, srv_name, outbuf);
+       p = skip_string(p,1);
   
-  send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
-                global_myname(), 0,
-                workgroup_name, 0x1e,
-                subrec->bcast_ip, subrec->myip, DGRAM_PORT);
+       send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
+               global_myname(), 0,
+               workgroup_name, 0x1e,
+               subrec->bcast_ip, subrec->myip, DGRAM_PORT);
 }
 
 /*******************************************************************
@@ -66,8 +70,10 @@ static void check_for_master_browser_success(struct subnet_record *subrec,
                                  struct nmb_name *answer_name,
                                  struct in_addr answer_ip, struct res_rec *rrec)
 {
-  DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \
-IP %s (just checking).\n", answer_name->name, inet_ntoa(answer_ip) ));
+       nstring aname;
+       pull_ascii_nstring(aname, answer_name->name);
+       DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \
+IP %s (just checking).\n", aname, inet_ntoa(answer_ip) ));
 }
 
 /*******************************************************************
@@ -79,41 +85,39 @@ static void check_for_master_browser_fail( struct subnet_record *subrec,
                                            struct nmb_name *question_name,
                                            int fail_code)
 {
-  char *workgroup_name = question_name->name;
-  struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name);
-
-  if(work == NULL)
-  {
-    DEBUG(0,("check_for_master_browser_fail: Unable to find workgroup %s on subnet %s.=\n",
-          workgroup_name, subrec->subnet_name ));
-    return;
-  }
-
-  if (strequal(work->work_group, lp_workgroup()))
-  {
-
-    if (lp_local_master())
-    {
-      /* We have discovered that there is no local master
-         browser, and we are configured to initiate
-         an election that we will participate in.
-       */
-      DEBUG(2,("check_for_master_browser_fail: Forcing election on workgroup %s subnet %s\n",
-               work->work_group, subrec->subnet_name ));
-
-      /* Setting this means we will participate when the
-         election is run in run_elections(). */
-      work->needelection = True;
-    }
-    else
-    {
-      /* We need to force an election, because we are configured
-         not to become the local master, but we still need one,
-         having detected that one doesn't exist.
-       */
-      send_election_dgram(subrec, work->work_group, 0, 0, "");
-    }
-  }
+       nstring workgroup_name;
+       struct work_record *work;
+
+       pull_ascii_nstring(workgroup_name,question_name->name);
+
+       work = find_workgroup_on_subnet(subrec, workgroup_name);
+       if(work == NULL) {
+               DEBUG(0,("check_for_master_browser_fail: Unable to find workgroup %s on subnet %s.=\n",
+                       workgroup_name, subrec->subnet_name ));
+               return;
+       }
+
+       if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
+
+               if (lp_local_master()) {
+                       /* We have discovered that there is no local master
+                               browser, and we are configured to initiate
+                               an election that we will participate in.
+                       */
+                       DEBUG(2,("check_for_master_browser_fail: Forcing election on workgroup %s subnet %s\n",
+                               work->work_group, subrec->subnet_name ));
+
+                       /* Setting this means we will participate when the
+                               election is run in run_elections(). */
+                       work->needelection = True;
+               } else {
+                       /* We need to force an election, because we are configured
+                               not to become the local master, but we still need one,
+                               having detected that one doesn't exist.
+                       */
+                       send_election_dgram(subrec, work->work_group, 0, 0, "");
+               }
+       }
 }
 
 /*******************************************************************
@@ -123,36 +127,33 @@ static void check_for_master_browser_fail( struct subnet_record *subrec,
 
 void check_master_browser_exists(time_t t)
 {
-  static time_t lastrun=0;
-  struct subnet_record *subrec;
-  const char *workgroup_name = lp_workgroup();
-
-  if (!lastrun)
-    lastrun = t;
-
-  if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60)))
-    return;
-
-  lastrun = t;
-
-  dump_workgroups(False);
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work;
-
-    for (work = subrec->workgrouplist; work; work = work->next)
-    {
-      if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work))
-      {
-        /* Do a name query for the local master browser on this net. */
-        query_name( subrec, work->work_group, 0x1d,
-                    check_for_master_browser_success,
-                    check_for_master_browser_fail,
-                    NULL);
-      }
-    }
-  }
+       static time_t lastrun=0;
+       struct subnet_record *subrec;
+       const char *workgroup_name = lp_workgroup();
+
+       if (!lastrun)
+               lastrun = t;
+
+       if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60)))
+               return;
+
+       lastrun = t;
+
+       dump_workgroups(False);
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work;
+
+               for (work = subrec->workgrouplist; work; work = work->next) {
+                       if (strnequal(work->work_group, workgroup_name, sizeof(nstring)-1) && !AM_LOCAL_MASTER_BROWSER(work)) {
+                               /* Do a name query for the local master browser on this net. */
+                               query_name( subrec, work->work_group, 0x1d,
+                                       check_for_master_browser_success,
+                                       check_for_master_browser_fail,
+                                       NULL);
+                       }
+               }
+       }
 }
 
 /*******************************************************************
@@ -161,56 +162,52 @@ void check_master_browser_exists(time_t t)
 
 void run_elections(time_t t)
 {
-  static time_t lastime = 0;
+       static time_t lastime = 0;
   
-  struct subnet_record *subrec;
+       struct subnet_record *subrec;
   
-  /* Send election packets once every 2 seconds - note */
-  if (lastime && (t - lastime < 2))
-    return;
+       /* Send election packets once every 2 seconds - note */
+       if (lastime && (t - lastime < 2))
+               return;
   
-  lastime = t;
+       lastime = t;
   
-  START_PROFILE(run_elections);
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work;
-
-    for (work = subrec->workgrouplist; work; work = work->next)
-    {
-      if (work->RunningElection)
-      {
-        /*
-         * We can only run an election for a workgroup if we have
-         * registered the WORKGROUP<1e> name, as that's the name
-         * we must listen to.
-         */
-        struct nmb_name nmbname;
-
-        make_nmb_name(&nmbname, work->work_group, 0x1e);
-        if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
-          DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \
+       START_PROFILE(run_elections);
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work;
+
+               for (work = subrec->workgrouplist; work; work = work->next) {
+                       if (work->RunningElection) {
+                               /*
+                                * We can only run an election for a workgroup if we have
+                                * registered the WORKGROUP<1e> name, as that's the name
+                                * we must listen to.
+                                */
+                               struct nmb_name nmbname;
+
+                               make_nmb_name(&nmbname, work->work_group, 0x1e);
+                               if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
+                                       DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \
 yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
-          continue;
-        }
+                                       continue;
+                               }
 
-        send_election_dgram(subrec, work->work_group, work->ElectionCriterion,
-                      t - StartupTime, global_myname());
+                               send_election_dgram(subrec, work->work_group, work->ElectionCriterion,
+                                               t - StartupTime, global_myname());
              
-        if (work->ElectionCount++ >= 4)
-        {
-          /* Won election (4 packets were sent out uncontested. */
-          DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n",
-                    work->work_group, subrec->subnet_name ));
-
-          work->RunningElection = False;
-
-          become_local_master_browser(subrec, work);
-        }
-      }
-    }
-  }
-  END_PROFILE(run_elections);
+                               if (work->ElectionCount++ >= 4) {
+                                       /* Won election (4 packets were sent out uncontested. */
+                                       DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n",
+                                               work->work_group, subrec->subnet_name ));
+
+                                       work->RunningElection = False;
+
+                                       become_local_master_browser(subrec, work);
+                               }
+                       }
+               }
+       }
+       END_PROFILE(run_elections);
 }
 
 /*******************************************************************
@@ -218,44 +215,42 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
 ******************************************************************/
 
 static BOOL win_election(struct work_record *work, int version,
-                         uint32 criterion, int timeup, char *server_name)
+                         uint32 criterion, int timeup, const char *server_name)
 {  
-  int mytimeup = time(NULL) - StartupTime;
-  uint32 mycriterion = work->ElectionCriterion;
-
-  /* If local master is false then never win
-     in election broadcasts. */
-  if(!lp_local_master())
-  {
-    DEBUG(3,("win_election: Losing election as local master == False\n"));
-    return False;
-  }
+       int mytimeup = time(NULL) - StartupTime;
+       uint32 mycriterion = work->ElectionCriterion;
+
+       /* If local master is false then never win in election broadcasts. */
+       if(!lp_local_master()) {
+               DEBUG(3,("win_election: Losing election as local master == False\n"));
+               return False;
+       }
  
-  DEBUG(4,("win_election: election comparison: %x:%x %x:%x %d:%d %s:%s\n",
-        version, ELECTION_VERSION,
-        criterion, mycriterion,
-        timeup, mytimeup,
-        server_name, global_myname()));
-
-  if (version > ELECTION_VERSION)
-    return(False);
-  if (version < ELECTION_VERSION)
-    return(True);
+       DEBUG(4,("win_election: election comparison: %x:%x %x:%x %d:%d %s:%s\n",
+                       version, ELECTION_VERSION,
+                       criterion, mycriterion,
+                       timeup, mytimeup,
+                       server_name, global_myname()));
+
+       if (version > ELECTION_VERSION)
+               return(False);
+       if (version < ELECTION_VERSION)
+               return(True);
   
-  if (criterion > mycriterion)
-    return(False);
-  if (criterion < mycriterion)
-    return(True);
-
-  if (timeup > mytimeup)
-    return(False);
-  if (timeup < mytimeup)
-    return(True);
-
-  if (strcasecmp(global_myname(), server_name) > 0)
-    return(False);
+       if (criterion > mycriterion)
+               return(False);
+       if (criterion < mycriterion)
+               return(True);
+
+       if (timeup > mytimeup)
+               return(False);
+       if (timeup < mytimeup)
+               return(True);
+
+       if (strcasecmp(global_myname(), server_name) > 0)
+               return(False);
   
-  return(True);
+       return(True);
 }
 
 /*******************************************************************
@@ -264,66 +259,63 @@ static BOOL win_election(struct work_record *work, int version,
 
 void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int version = CVAL(buf,0);
-  uint32 criterion = IVAL(buf,1);
-  int timeup = IVAL(buf,5)/1000;
-  char *server_name = buf+13;
-  struct work_record *work;
-  char *workgroup_name = dgram->dest_name.name;
-
-  START_PROFILE(election);
-  server_name[15] = 0;  
-
-  DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n",
-      server_name,inet_ntoa(p->ip), subrec->subnet_name, workgroup_name ));
-
-  DEBUG(5,("process_election: vers=%d criterion=%08x timeup=%d\n", version,criterion,timeup));
-
-  if(( work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL)
-  {
-    DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n",
-          workgroup_name, subrec->subnet_name ));
-    goto done;
-  }
-
-  if (!strequal(work->work_group, lp_workgroup()))
-  {
-    DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int version = CVAL(buf,0);
+       uint32 criterion = IVAL(buf,1);
+       int timeup = IVAL(buf,5)/1000;
+       nstring server_name;
+       struct work_record *work;
+       nstring workgroup_name;
+
+       pull_ascii_nstring(server_name, buf+13);
+       pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
+
+       START_PROFILE(election);
+       server_name[15] = 0;  
+
+       DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n",
+               server_name,inet_ntoa(p->ip), subrec->subnet_name, workgroup_name ));
+
+       DEBUG(5,("process_election: vers=%d criterion=%08x timeup=%d\n", version,criterion,timeup));
+
+       if(( work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) {
+               DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n",
+                       workgroup_name, subrec->subnet_name ));
+               goto done;
+       }
+
+       if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
+               DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \
 is not my workgroup.\n", work->work_group, subrec->subnet_name ));
-    goto done;
-  }
-
-  if (win_election(work, version,criterion,timeup,server_name))
-  {
-    /* We take precedence over the requesting server. */
-    if (!work->RunningElection)
-    {
-      /* We weren't running an election - start running one. */
-
-      work->needelection = True;
-      work->ElectionCount=0;
-    }
-
-    /* Note that if we were running an election for this workgroup on this
-       subnet already, we just ignore the server we take precedence over. */
-  }
-  else
-  {
-    /* We lost. Stop participating. */
-    work->needelection = False;
-
-    if (work->RunningElection || AM_LOCAL_MASTER_BROWSER(work))
-    {
-      work->RunningElection = False;
-      DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n",
-            work->work_group, subrec->subnet_name ));
-      if (AM_LOCAL_MASTER_BROWSER(work))
-        unbecome_local_master_browser(subrec, work, False);
-    }
-  }
+               goto done;
+       }
+
+       if (win_election(work, version,criterion,timeup,server_name)) {
+               /* We take precedence over the requesting server. */
+               if (!work->RunningElection) {
+                       /* We weren't running an election - start running one. */
+
+                       work->needelection = True;
+                       work->ElectionCount=0;
+               }
+
+               /* Note that if we were running an election for this workgroup on this
+                       subnet already, we just ignore the server we take precedence over. */
+       } else {
+               /* We lost. Stop participating. */
+               work->needelection = False;
+
+               if (work->RunningElection || AM_LOCAL_MASTER_BROWSER(work)) {
+                       work->RunningElection = False;
+                       DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n",
+                               work->work_group, subrec->subnet_name ));
+                       if (AM_LOCAL_MASTER_BROWSER(work))
+                               unbecome_local_master_browser(subrec, work, False);
+               }
+       }
 done:
-  END_PROFILE(election);
+
+       END_PROFILE(election);
 }
 
 /****************************************************************************
@@ -335,57 +327,53 @@ done:
 
 BOOL check_elections(void)
 {
-  struct subnet_record *subrec;
-  BOOL run_any_election = False;
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work;
-    for (work = subrec->workgrouplist; work; work = work->next)
-    {
-      run_any_election |= work->RunningElection;
-
-      /* 
-       * Start an election if we have any chance of winning.
-       * Note this is a change to the previous code, that would
-       * only run an election if nmbd was in the potential browser
-       * state. We need to run elections in any state if we're told
-       * to. JRA.
-       */
-
-      if (work->needelection && !work->RunningElection && lp_local_master())
-      {
-        /*
-         * We can only run an election for a workgroup if we have
-         * registered the WORKGROUP<1e> name, as that's the name
-         * we must listen to.
-         */
-        struct nmb_name nmbname;
-
-        make_nmb_name(&nmbname, work->work_group, 0x1e);
-        if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
-          DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \
+       struct subnet_record *subrec;
+       BOOL run_any_election = False;
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work;
+               for (work = subrec->workgrouplist; work; work = work->next) {
+                       run_any_election |= work->RunningElection;
+
+                       /* 
+                        * Start an election if we have any chance of winning.
+                        * Note this is a change to the previous code, that would
+                        * only run an election if nmbd was in the potential browser
+                        * state. We need to run elections in any state if we're told
+                        * to. JRA.
+                        */
+
+                       if (work->needelection && !work->RunningElection && lp_local_master()) {
+                               /*
+                                * We can only run an election for a workgroup if we have
+                                * registered the WORKGROUP<1e> name, as that's the name
+                                * we must listen to.
+                                */
+                               struct nmb_name nmbname;
+
+                               make_nmb_name(&nmbname, work->work_group, 0x1e);
+                               if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
+                                       DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \
 yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
-          continue;
-        }
-
-        DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n",
-              work->work_group, subrec->subnet_name ));
-
-        work->ElectionCount = 0;
-        work->RunningElection = True;
-        work->needelection = False;
-      }
-    }
-  }
-  return run_any_election;
-}
+                                       continue;
+                               }
 
+                               DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n",
+                                       work->work_group, subrec->subnet_name ));
 
+                               work->ElectionCount = 0;
+                               work->RunningElection = True;
+                               work->needelection = False;
+                       }
+               }
+       }
+       return run_any_election;
+}
 
 /****************************************************************************
-process a internal Samba message forcing an election
+ Process a internal Samba message forcing an election.
 ***************************************************************************/
+
 void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len)
 {
        struct subnet_record *subrec;
@@ -393,7 +381,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len)
        for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
                struct work_record *work;
                for (work = subrec->workgrouplist; work; work = work->next) {
-                       if (strequal(work->work_group, lp_workgroup())) {
+                       if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
                                work->needelection = True;
                                work->ElectionCount=0;
                                work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
index 80465ada0dc4d0e5ecaabeb4e4ef4cacd48e5e60..f646e397162a424c5f71ac02a24c2fc3def0771d 100644 (file)
@@ -95,102 +95,99 @@ void tell_become_backup(void)
 
 void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int ttl = IVAL(buf,1)/1000;
-  char *announce_name = buf+5;
-  uint32 servertype = IVAL(buf,23);
-  char *comment = buf+31;
-  struct work_record *work;
-  struct server_record *servrec;
-  const char *work_name;
-  char *source_name = dgram->source_name.name;
-
-  START_PROFILE(host_announce);
-  comment[43] = 0;
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int ttl = IVAL(buf,1)/1000;
+       nstring announce_name;
+       uint32 servertype = IVAL(buf,23);
+       fstring comment;
+       struct work_record *work;
+       struct server_record *servrec;
+       nstring work_name;
+       nstring source_name;
+
+       START_PROFILE(host_announce);
+
+       pull_ascii_fstring(comment, buf+31);
+       comment[42] = 0;
   
-  DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \
+       pull_ascii_nstring(announce_name, buf+5);
+       pull_ascii_nstring(source_name, dgram->source_name.name);
+
+       DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \
 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              nmb_namestr(&dgram->dest_name),announce_name));
+                       nmb_namestr(&dgram->dest_name),announce_name));
 
-  DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n",
-          ttl, servertype,comment));
+       DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n",
+               ttl, servertype,comment));
 
-  /* Filter servertype to remove impossible bits. */
-  servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
+       /* Filter servertype to remove impossible bits. */
+       servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
 
-  /* A host announcement must be sent to the name WORKGROUP<1d>. */
-  if(dgram->dest_name.name_type != 0x1d)
-  {
-    DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \
+       /* A host announcement must be sent to the name WORKGROUP<1d>. */
+       if(dgram->dest_name.name_type != 0x1d) {
+               DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \
 (was %02x) should be 0x1d. Allowing packet anyway.\n",
-              inet_ntoa(p->ip), dgram->dest_name.name_type));
-    /* Change it so it was. */
-    dgram->dest_name.name_type = 0x1d;
-  }
-
-  /* For a host announce the workgroup name is the destination name. */
-  work_name = dgram->dest_name.name;
-
-  /*
-   * Syntax servers version 5.1 send HostAnnounce packets to
-   * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
-   * instead of WORKGROUP<1d> name. So to fix this we check if
-   * the workgroup name is our own name, and if so change it
-   * to be our primary workgroup name.
-   */
-
-  if(strequal(work_name, global_myname()))
-    work_name = lp_workgroup();
-
-  /*
-   * We are being very agressive here in adding a workgroup
-   * name on the basis of a host announcing itself as being
-   * in that workgroup. Maybe we should wait for the workgroup
-   * announce instead ? JRA.
-   */
-
-  work = find_workgroup_on_subnet(subrec, work_name);
-
-  if(servertype != 0)
-  {
-    if (work ==NULL )
-    {
-      /* We have no record of this workgroup. Add it. */
-      if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
-        goto done;
-    }
+                       inet_ntoa(p->ip), dgram->dest_name.name_type));
+               /* Change it so it was. */
+               dgram->dest_name.name_type = 0x1d;
+       }
+
+       /* For a host announce the workgroup name is the destination name. */
+       pull_ascii_nstring(work_name, dgram->dest_name.name);
+
+       /*
+        * Syntax servers version 5.1 send HostAnnounce packets to
+        * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
+        * instead of WORKGROUP<1d> name. So to fix this we check if
+        * the workgroup name is our own name, and if so change it
+        * to be our primary workgroup name.
+        */
+
+       if(strequal(work_name, global_myname()))
+               nstrcpy(work_name,lp_workgroup());
+
+       /*
+        * We are being very agressive here in adding a workgroup
+        * name on the basis of a host announcing itself as being
+        * in that workgroup. Maybe we should wait for the workgroup
+        * announce instead ? JRA.
+        */
+
+       work = find_workgroup_on_subnet(subrec, work_name);
+
+       if(servertype != 0) {
+               if (work ==NULL ) {
+                       /* We have no record of this workgroup. Add it. */
+                       if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
+                               goto done;
+               }
   
-    if((servrec = find_server_in_workgroup( work, announce_name))==NULL)
-    {
-      /* If this server is not already in the workgroup, add it. */
-      create_server_on_workgroup(work, announce_name, 
-                                 servertype|SV_TYPE_LOCAL_LIST_ONLY, 
-                                 ttl, comment);
-    }
-    else
-    {
-      /* Update the record. */
-      servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
-      update_server_ttl( servrec, ttl);
-      fstrcpy(servrec->serv.comment,comment);
-    }
-  }
-  else
-  {
-    /*
-     * This server is announcing it is going down. Remove it from the 
-     * workgroup.
-     */
-    if(!is_myname(announce_name) && (work != NULL) &&
-       ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)
-      )
-    {
-      remove_server_from_workgroup( work, servrec);
-    }
-  }
-  subrec->work_changed = True;
+               if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
+                       /* If this server is not already in the workgroup, add it. */
+                       create_server_on_workgroup(work, announce_name, 
+                               servertype|SV_TYPE_LOCAL_LIST_ONLY, 
+                               ttl, comment);
+               } else {
+                       /* Update the record. */
+                       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
+                       update_server_ttl( servrec, ttl);
+                       fstrcpy(servrec->serv.comment,comment);
+               }
+       } else {
+               /*
+                * This server is announcing it is going down. Remove it from the 
+                * workgroup.
+                */
+               if(!is_myname(announce_name) && (work != NULL) &&
+                               ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
+                       remove_server_from_workgroup( work, servrec);
+               }
+       }
+
+       subrec->work_changed = True;
 done:
-  END_PROFILE(host_announce);
+
+       END_PROFILE(host_announce);
 }
 
 /*******************************************************************
@@ -199,53 +196,55 @@ done:
 
 void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int ttl = IVAL(buf,1)/1000;
-  char *workgroup_announce_name = buf+5;
-  uint32 servertype = IVAL(buf,23);
-  char *master_name = buf+31;
-  struct work_record *work;
-  char *source_name = dgram->source_name.name;
-
-  START_PROFILE(workgroup_announce);
-  master_name[43] = 0;
-
-  DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int ttl = IVAL(buf,1)/1000;
+       nstring workgroup_announce_name;
+       nstring master_name;
+       uint32 servertype = IVAL(buf,23);
+       struct work_record *work;
+       nstring source_name;
+       nstring dest_name;
+
+       START_PROFILE(workgroup_announce);
+
+       pull_ascii_nstring(workgroup_announce_name,buf+5);
+       pull_ascii_nstring(master_name,buf+31);
+       pull_ascii_nstring(source_name,dgram->source_name.name);
+       pull_ascii_nstring(dest_name,dgram->dest_name.name);
+
+       DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \
 %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              nmb_namestr(&dgram->dest_name),workgroup_announce_name));
-
-  DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n",
-           ttl, servertype, master_name));
-
-  /* Workgroup announcements must only go to the MSBROWSE name. */
-  if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1))
-  {
-    DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
-              inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
-    goto done;
-  }
+                       nmb_namestr(&dgram->dest_name),workgroup_announce_name));
+
+       DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n",
+               ttl, servertype, master_name));
+
+       /* Workgroup announcements must only go to the MSBROWSE name. */
+       if (!strequal(dest_name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) {
+               DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n",
+                       inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
+               goto done;
+       }
+
+       if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) {
+               /* We have no record of this workgroup. Add it. */
+               if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL)
+                       goto done;
+       } else {
+               /* Update the workgroup death_time. */
+               update_workgroup_ttl(work, ttl);
+       }
+
+       if(*work->local_master_browser_name == '\0') {
+               /* Set the master browser name. */
+               set_workgroup_local_master_browser_name( work, master_name );
+       }
+
+       subrec->work_changed = True;
 
-  if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL)
-  {
-    /* We have no record of this workgroup. Add it. */
-    if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL)
-      goto done;
-  }
-  else
-  {
-    /* Update the workgroup death_time. */
-    update_workgroup_ttl(work, ttl);
-  }
-
-  if(*work->local_master_browser_name == '\0')
-  {
-    /* Set the master browser name. */
-    set_workgroup_local_master_browser_name( work, master_name );
-  }
-
-  subrec->work_changed = True;
 done:
-  END_PROFILE(workgroup_announce);
+
+       END_PROFILE(workgroup_announce);
 }
 
 /*******************************************************************
@@ -254,117 +253,110 @@ done:
 
 void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int ttl = IVAL(buf,1)/1000;
-  char *server_name = buf+5;
-  uint32 servertype = IVAL(buf,23);
-  char *comment = buf+31;
-  char *work_name;
-  struct work_record *work;
-  struct server_record *servrec;
-  char *source_name = dgram->source_name.name;
-
-  START_PROFILE(local_master_announce);
-  comment[43] = 0;
-
-  DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int ttl = IVAL(buf,1)/1000;
+       nstring server_name;
+       uint32 servertype = IVAL(buf,23);
+       fstring comment;
+       nstring work_name;
+       struct work_record *work;
+       struct server_record *servrec;
+       nstring source_name;
+
+       START_PROFILE(local_master_announce);
+
+       pull_ascii_nstring(server_name,buf+5);
+       pull_ascii_fstring(comment, buf+31);
+       comment[42] = 0;
+       pull_ascii_nstring(source_name, dgram->source_name.name);
+       pull_ascii_nstring(work_name, dgram->dest_name.name);
+
+       DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \
 %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              nmb_namestr(&dgram->dest_name),server_name));
+               nmb_namestr(&dgram->dest_name),server_name));
 
-  DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
-           ttl, servertype, comment));
+       DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n",
+               ttl, servertype, comment));
 
-  /* A local master announcement must be sent to the name WORKGROUP<1e>. */
-  if(dgram->dest_name.name_type != 0x1e)
-  {
-    DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \
+       /* A local master announcement must be sent to the name WORKGROUP<1e>. */
+       if(dgram->dest_name.name_type != 0x1e) {
+               DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \
 (was %02x) should be 0x1e. Ignoring packet.\n",
-              inet_ntoa(p->ip), dgram->dest_name.name_type));
-    goto done;
-  }
-
-  /* Filter servertype to remove impossible bits. */
-  servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
-
-  /* For a local master announce the workgroup name is the destination name. */
-  work_name = dgram->dest_name.name;
-
-  if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL)
-  {
-    /* Don't bother adding if it's a local master release announce. */
-    if(servertype == 0)
-      goto done;
-
-    /* We have no record of this workgroup. Add it. */
-    if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
-      goto done;
-  }
-
-  /* If we think we're the local master browser for this workgroup,
-     we should never have got this packet. We don't see our own
-     packets.
-   */
-  if(AM_LOCAL_MASTER_BROWSER(work))
-  {
-    DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \
+                       inet_ntoa(p->ip), dgram->dest_name.name_type));
+               goto done;
+       }
+
+       /* Filter servertype to remove impossible bits. */
+       servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
+
+       /* For a local master announce the workgroup name is the destination name. */
+
+       if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) {
+               /* Don't bother adding if it's a local master release announce. */
+               if(servertype == 0)
+                       goto done;
+
+               /* We have no record of this workgroup. Add it. */
+               if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
+                       goto done;
+       }
+
+       /* If we think we're the local master browser for this workgroup,
+               we should never have got this packet. We don't see our own
+               packets.
+       */
+       if(AM_LOCAL_MASTER_BROWSER(work)) {
+               DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \
 a local master browser for workgroup %s and we think we are master. Forcing election.\n",
-      server_name, inet_ntoa(p->ip), work_name));
+                       server_name, inet_ntoa(p->ip), work_name));
 
-    /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when
-       they have become a local master browser once, they will never
-       stop sending local master announcements. To fix this we send
-       them a reset browser packet, with level 0x2 on the __SAMBA__
-       name that only they should be listening to. */
+               /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when
+                they have become a local master browser once, they will never
+                stop sending local master announcements. To fix this we send
+                them a reset browser packet, with level 0x2 on the __SAMBA__
+                name that only they should be listening to. */
    
-    send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip);
-
-    /* We should demote ourself and force an election. */
-
-    unbecome_local_master_browser( subrec, work, True);
-
-    /* The actual election requests are handled in
-       nmbd_election.c */
-    goto done;
-  }  
-
-  /* Find the server record on this workgroup. If it doesn't exist, add it. */
-
-  if(servertype != 0)
-  {
-    if((servrec = find_server_in_workgroup( work, server_name))==NULL)
-    {
-      /* If this server is not already in the workgroup, add it. */
-      create_server_on_workgroup(work, server_name, 
-                                 servertype|SV_TYPE_LOCAL_LIST_ONLY, 
-                                 ttl, comment);
-    }
-    else
-    {
-      /* Update the record. */
-      servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
-      update_server_ttl(servrec, ttl);
-      fstrcpy(servrec->serv.comment,comment);
-    }
-
-    set_workgroup_local_master_browser_name( work, server_name );
-  }
-  else
-  {
-    /*
-     * This server is announcing it is going down. Remove it from the
-     * workgroup.
-     */
-    if(!is_myname(server_name) && (work != NULL) &&
-       ((servrec = find_server_in_workgroup( work, server_name))!=NULL)
-      )
-    {
-      remove_server_from_workgroup( work, servrec);
-    }
-  }
-
-  subrec->work_changed = True;
+               send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip);
+
+               /* We should demote ourself and force an election. */
+
+               unbecome_local_master_browser( subrec, work, True);
+
+               /* The actual election requests are handled in nmbd_election.c */
+               goto done;
+       }  
+
+       /* Find the server record on this workgroup. If it doesn't exist, add it. */
+
+       if(servertype != 0) {
+               if((servrec = find_server_in_workgroup( work, server_name))==NULL) {
+                       /* If this server is not already in the workgroup, add it. */
+                       create_server_on_workgroup(work, server_name, 
+                               servertype|SV_TYPE_LOCAL_LIST_ONLY, 
+                               ttl, comment);
+               } else {
+                       /* Update the record. */
+                       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
+                       update_server_ttl(servrec, ttl);
+                       fstrcpy(servrec->serv.comment,comment);
+               }
+       
+               set_workgroup_local_master_browser_name( work, server_name );
+       } else {
+               /*
+                * This server is announcing it is going down. Remove it from the
+                * workgroup.
+                */
+               if(!is_myname(server_name) && (work != NULL) &&
+                               ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) {
+                       remove_server_from_workgroup( work, servrec);
+               }
+       }
+
+       subrec->work_changed = True;
 done:
-  END_PROFILE(local_master_announce);
+
+       END_PROFILE(local_master_announce);
 }
 
 /*******************************************************************
@@ -377,50 +369,49 @@ done:
 void process_master_browser_announce(struct subnet_record *subrec, 
                                      struct packet_struct *p,char *buf)
 {
-  char *local_master_name = buf;
-  struct work_record *work;
-  struct browse_cache_record *browrec;
+       nstring local_master_name;
+       struct work_record *work;
+       struct browse_cache_record *browrec;
 
-  START_PROFILE(master_browser_announce);
-  local_master_name[15] = 0;
+       START_PROFILE(master_browser_announce);
+
+       pull_ascii_nstring(local_master_name,buf);
   
-  DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n",
-           local_master_name, inet_ntoa(p->ip)));
+       DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n",
+               local_master_name, inet_ntoa(p->ip)));
   
-  if (!lp_domain_master()) 
-  {
-    DEBUG(0,("process_master_browser_announce: Not configured as domain \
+       if (!lp_domain_master()) {
+               DEBUG(0,("process_master_browser_announce: Not configured as domain \
 master - ignoring master announce.\n"));
-    goto done;
-  }
+               goto done;
+       }
   
-  if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL)
-  {
-    DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n",
-           lp_workgroup(), subrec->subnet_name));
-    goto done;
-  }
-
-  if(!AM_DOMAIN_MASTER_BROWSER(work))
-  {
-    DEBUG(0,("process_master_browser_announce: Local master announce made to us from \
+       if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) {
+               DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n",
+                       lp_workgroup(), subrec->subnet_name));
+               goto done;
+       }
+
+       if(!AM_DOMAIN_MASTER_BROWSER(work)) {
+               DEBUG(0,("process_master_browser_announce: Local master announce made to us from \
 %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip)));
-    goto done;
-  }
+               goto done;
+       }
 
-  /* Add this host as a local master browser entry on the browse lists.
-     This causes a sync request to be made to it at a later date.
-   */
+       /* Add this host as a local master browser entry on the browse lists.
+               This causes a sync request to be made to it at a later date.
+       */
+
+       if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) {
+               /* Add it. */
+               create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip);
+       } else {
+               update_browser_death_time(browrec);
+       }
 
-  if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL)
-  {
-    /* Add it. */
-    create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip);
-  }
-  else
-    update_browser_death_time(browrec);
 done:
-  END_PROFILE(master_browser_announce);
+
+       END_PROFILE(master_browser_announce);
 }
 
 /*******************************************************************
@@ -429,123 +420,117 @@ done:
 
 void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  uint32 servertype = IVAL(buf,1);
-  int osmajor=CVAL(buf,5);           /* major version of node software */
-  int osminor=CVAL(buf,6);           /* minor version of node software */
-  int ttl = SVAL(buf,7);
-  char *announce_name = buf+9;
-  struct work_record *work;
-  struct server_record *servrec;
-  const char *work_name;
-  char *source_name = dgram->source_name.name;
-  pstring comment;
-  char *s = buf+9;
-
-  START_PROFILE(lm_host_announce);
-  s = skip_string(s,1);
-  StrnCpy(comment, s, 43);
-
-  DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \
-%s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip),
-              nmb_namestr(&dgram->dest_name),announce_name));
-
-  DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
-          osmajor, osminor, ttl, servertype,comment));
-
-  if ((osmajor < 36) || (osmajor > 38) || (osminor !=0))
-  {
-    DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       uint32 servertype = IVAL(buf,1);
+       int osmajor=CVAL(buf,5);           /* major version of node software */
+       int osminor=CVAL(buf,6);           /* minor version of node software */
+       int ttl = SVAL(buf,7);
+       nstring announce_name;
+       struct work_record *work;
+       struct server_record *servrec;
+       nstring work_name;
+       nstring source_name;
+       fstring comment;
+       char *s = buf+9;
+
+       START_PROFILE(lm_host_announce);
+       s = skip_string(s,1);
+       pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE);
+
+       pull_ascii_nstring(announce_name,buf+9);
+       pull_ascii_nstring(source_name,dgram->source_name.name);
+       /* For a LanMan host announce the workgroup name is the destination name. */
+       pull_ascii_nstring(work_name,dgram->dest_name.name);
+
+       DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \
+%s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+               nmb_namestr(&dgram->dest_name),announce_name));
+
+       DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n",
+               osmajor, osminor, ttl, servertype,comment));
+
+       if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) {
+               DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \
 originate from OS/2 Warp client. Ignoring packet.\n"));
-    /* Could have been from a Windows machine (with its LM Announce enabled),
-       or a Samba server. Then don't disrupt the current browse list. */
-    goto done;
-  }
+               /* Could have been from a Windows machine (with its LM Announce enabled),
+                       or a Samba server. Then don't disrupt the current browse list. */
+               goto done;
+       }
 
-  /* Filter servertype to remove impossible bits. */
-  servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
+       /* Filter servertype to remove impossible bits. */
+       servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM);
 
-  /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */
-  if(dgram->dest_name.name_type != 0x00)
-  {
-    DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \
+       /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */
+       if(dgram->dest_name.name_type != 0x00) {
+               DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \
 (was %02x) should be 0x00. Allowing packet anyway.\n",
-              inet_ntoa(p->ip), dgram->dest_name.name_type));
-    /* Change it so it was. */
-    dgram->dest_name.name_type = 0x00;
-  }
-
-  /* For a LanMan host announce the workgroup name is the destination name. */
-  work_name = dgram->dest_name.name;
-
-  /*
-   * Syntax servers version 5.1 send HostAnnounce packets to
-   * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
-   * instead of WORKGROUP<1d> name. So to fix this we check if
-   * the workgroup name is our own name, and if so change it
-   * to be our primary workgroup name. This code is probably
-   * not needed in the LanMan announce code, but it won't hurt.
-   */
-
-  if(strequal(work_name, global_myname()))
-    work_name = lp_workgroup();
-
-  /*
-   * We are being very agressive here in adding a workgroup
-   * name on the basis of a host announcing itself as being
-   * in that workgroup. Maybe we should wait for the workgroup
-   * announce instead ? JRA.
-   */
+                       inet_ntoa(p->ip), dgram->dest_name.name_type));
+               /* Change it so it was. */
+               dgram->dest_name.name_type = 0x00;
+       }
+
+       /*
+        * Syntax servers version 5.1 send HostAnnounce packets to
+        * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00>
+        * instead of WORKGROUP<1d> name. So to fix this we check if
+        * the workgroup name is our own name, and if so change it
+        * to be our primary workgroup name. This code is probably
+        * not needed in the LanMan announce code, but it won't hurt.
+        */
+
+       if(strequal(work_name, global_myname()))
+               nstrcpy(work_name,lp_workgroup());
+
+       /*
+        * We are being very agressive here in adding a workgroup
+        * name on the basis of a host announcing itself as being
+        * in that workgroup. Maybe we should wait for the workgroup
+        * announce instead ? JRA.
+        */
+
+       work = find_workgroup_on_subnet(subrec, work_name);
+
+       if(servertype != 0) {
+               if (work == NULL) {
+                       /* We have no record of this workgroup. Add it. */
+                       if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
+                               goto done;
+               }
+
+               if((servrec = find_server_in_workgroup( work, announce_name))==NULL) {
+                       /* If this server is not already in the workgroup, add it. */
+                       create_server_on_workgroup(work, announce_name,
+                                       servertype|SV_TYPE_LOCAL_LIST_ONLY,
+                                       ttl, comment);
+               } else {
+                       /* Update the record. */
+                       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
+                       update_server_ttl( servrec, ttl);
+                       fstrcpy(servrec->serv.comment,comment);
+               }
+       } else {
+               /*
+                * This server is announcing it is going down. Remove it from the
+                * workgroup.
+                */
+               if(!is_myname(announce_name) && (work != NULL) &&
+                               ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) {
+                       remove_server_from_workgroup( work, servrec);
+               }
+       }
+
+       subrec->work_changed = True;
+       found_lm_clients = True;
 
-  work = find_workgroup_on_subnet(subrec, work_name);
-
-  if(servertype != 0)
-  {
-    if (work == NULL)
-    {
-      /* We have no record of this workgroup. Add it. */
-      if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL)
-        goto done;
-    }
-
-    if((servrec = find_server_in_workgroup( work, announce_name))==NULL)
-    {
-      /* If this server is not already in the workgroup, add it. */
-      create_server_on_workgroup(work, announce_name,
-                                 servertype|SV_TYPE_LOCAL_LIST_ONLY,
-                                 ttl, comment);
-    }
-    else
-    {
-      /* Update the record. */
-      servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
-      update_server_ttl( servrec, ttl);
-      fstrcpy(servrec->serv.comment,comment);
-    }
-  }
-  else
-  {
-    /*
-     * This server is announcing it is going down. Remove it from the
-     * workgroup.
-     */
-    if(!is_myname(announce_name) && (work != NULL) &&
-       ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)
-      )
-    {
-      remove_server_from_workgroup( work, servrec);
-    }
-  }
-
-  subrec->work_changed = True;
-  found_lm_clients = True;
 done:
-  END_PROFILE(lm_host_announce);
+
+       END_PROFILE(lm_host_announce);
 }
 
 /****************************************************************************
   Send a backup list response.
 *****************************************************************************/
+
 static void send_backup_list_response(struct subnet_record *subrec, 
                                      struct work_record *work,
                                      struct nmb_name *send_to_name,
@@ -553,40 +538,41 @@ static void send_backup_list_response(struct subnet_record *subrec,
                                      uint32 token, struct in_addr sendto_ip,
                                      int port)
 {                     
-  char outbuf[1024];
-  char *p, *countptr;
-  unsigned int count = 0;
+       char outbuf[1024];
+       char *p, *countptr;
+       unsigned int count = 0;
+       nstring send_to_namestr;
 #if 0
   struct server_record *servrec;
 #endif
-  fstring myname;
+       fstring myname;
 
-  memset(outbuf,'\0',sizeof(outbuf));
+       memset(outbuf,'\0',sizeof(outbuf));
 
-  DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
-          work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
+       DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n",
+               work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip)));
   
-  p = outbuf;
+       p = outbuf;
   
-  SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
-  p++;
+       SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */
+       p++;
 
-  countptr = p;
-  p++;
+       countptr = p;
+       p++;
 
-  SIVAL(p,0,token); /* The sender's unique info. */
-  p += 4;
+       SIVAL(p,0,token); /* The sender's unique info. */
+       p += 4;
   
-  /* We always return at least one name - our own. */
-  count = 1;
-  fstrcpy(myname, global_myname());
-  strupper_m(myname);
-  myname[15]='\0';
-  push_pstring_base(p, myname, outbuf);
+       /* We always return at least one name - our own. */
+       count = 1;
+       fstrcpy(myname, global_myname());
+       strupper_m(myname);
+       myname[15]='\0';
+       push_pstring_base(p, myname, outbuf);
 
-  p = skip_string(p,1);
+       p = skip_string(p,1);
 
-  /* Look for backup browsers in this workgroup. */
+       /* Look for backup browsers in this workgroup. */
 
 #if 0
   /* we don't currently send become_backup requests so we should never
@@ -624,16 +610,18 @@ static void send_backup_list_response(struct subnet_record *subrec,
   }
 #endif
 
-  SCVAL(countptr, 0, count);
+       SCVAL(countptr, 0, count);
+
+       pull_ascii_nstring(send_to_namestr, send_to_name->name);
 
-  DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
-          send_to_name->name, inet_ntoa(sendto_ip), count));
+       DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n",
+               send_to_namestr, inet_ntoa(sendto_ip), count));
 
-  send_mailslot(True, BROWSE_MAILSLOT,
-                outbuf,PTR_DIFF(p,outbuf),
-                global_myname(), 0, 
-                send_to_name->name,0,
-                sendto_ip, subrec->myip, port);
+       send_mailslot(True, BROWSE_MAILSLOT,
+               outbuf,PTR_DIFF(p,outbuf),
+               global_myname(), 0, 
+               send_to_namestr,0,
+               sendto_ip, subrec->myip, port);
 }
 
 /*******************************************************************
@@ -649,80 +637,74 @@ static void send_backup_list_response(struct subnet_record *subrec,
 void process_get_backup_list_request(struct subnet_record *subrec,
                                      struct packet_struct *p,char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  struct work_record *work;
-  unsigned char max_number_requested = CVAL(buf,0);
-  uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */
-  int name_type = dgram->dest_name.name_type;
-  char *workgroup_name = dgram->dest_name.name;
-  struct subnet_record *search_subrec = subrec;
-
-  START_PROFILE(get_backup_list);
-  DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
-           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
-           nmb_namestr(&dgram->dest_name)));
+       struct dgram_packet *dgram = &p->packet.dgram;
+       struct work_record *work;
+       unsigned char max_number_requested = CVAL(buf,0);
+       uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */
+       int name_type = dgram->dest_name.name_type;
+       nstring workgroup_name;
+       struct subnet_record *search_subrec = subrec;
+
+       START_PROFILE(get_backup_list);
+       pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
+
+       DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n",
+               nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+               nmb_namestr(&dgram->dest_name)));
   
-  /* We have to be a master browser, or a domain master browser
-     for the requested workgroup. That means it must be our
-     workgroup. */
-
-  if(strequal(workgroup_name, lp_workgroup()) == False)
-  {
-    DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n",
-           workgroup_name));
-    goto done;
-  }
-
-  if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL)
-  {
-    DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
+       /* We have to be a master browser, or a domain master browser
+               for the requested workgroup. That means it must be our
+               workgroup. */
+
+       if(strequal(workgroup_name, lp_workgroup()) == False) {
+               DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n",
+                       workgroup_name));
+               goto done;
+       }
+
+       if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) {
+               DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \
 subnet %s.\n", workgroup_name, search_subrec->subnet_name));
-    goto done;
-  }
+               goto done;
+       }
 
-  /* 
-   * If the packet was sent to WORKGROUP<1b> instead
-   * of WORKGROUP<1d> then it was unicast to us a domain master
-   * browser. Change search subrec to unicast.
-   */
+       /* 
+        * If the packet was sent to WORKGROUP<1b> instead
+        * of WORKGROUP<1d> then it was unicast to us a domain master
+        * browser. Change search subrec to unicast.
+        */
 
-  if(name_type == 0x1b)
-  {
-    /* We must be a domain master browser in order to
-       process this packet. */
+       if(name_type == 0x1b) {
+               /* We must be a domain master browser in order to
+                       process this packet. */
 
-    if(!AM_DOMAIN_MASTER_BROWSER(work))
-    {
-      DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
+               if(!AM_DOMAIN_MASTER_BROWSER(work)) {
+                       DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
 and I am not a domain master browser.\n", workgroup_name));
-      goto done;
-    }
+                       goto done;
+               }
 
-    search_subrec = unicast_subnet;
-  }
-  else if (name_type == 0x1d)
-  {
-    /* We must be a local master browser in order to
-       process this packet. */
+               search_subrec = unicast_subnet;
+       } else if (name_type == 0x1d) {
+               /* We must be a local master browser in order to process this packet. */
 
-    if(!AM_LOCAL_MASTER_BROWSER(work))
-    {
-      DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
+               if(!AM_LOCAL_MASTER_BROWSER(work)) {
+                       DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \
 and I am not a local master browser.\n", workgroup_name));
-      goto done;
-    }
-  }
-  else
-  {
-    DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n",
-            name_type));
-    goto done;
-  }
+                       goto done;
+               }
+       } else {
+               DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n",
+                       name_type));
+               goto done;
+       }
+
+       send_backup_list_response(subrec, work, &dgram->source_name,
+                       max_number_requested, token, p->ip, p->port);
 
-  send_backup_list_response(subrec, work, &dgram->source_name, 
-                            max_number_requested, token, p->ip, p->port);
 done:
-  END_PROFILE(get_backup_list);
+
+       END_PROFILE(get_backup_list);
 }
 
 /*******************************************************************
@@ -738,49 +720,46 @@ done:
 void process_reset_browser(struct subnet_record *subrec,
                                   struct packet_struct *p,char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int state = CVAL(buf,0);
-  struct subnet_record *sr;
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int state = CVAL(buf,0);
+       struct subnet_record *sr;
 
-  START_PROFILE(reset_browser);
-  DEBUG(1,("process_reset_browser: received diagnostic browser reset \
-request from %s IP %s state=0x%X\n",
-             nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
+       START_PROFILE(reset_browser);
 
-  /* Stop being a local master browser on all our broadcast subnets. */
-  if (state & 0x1)
-  {
-    for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr))
-    {
-      struct work_record *work;
-      for (work = sr->workgrouplist; work; work = work->next)
-      {
-        if (AM_LOCAL_MASTER_BROWSER(work))
-          unbecome_local_master_browser(sr, work, True);
-      }
-    }
-  }
+       DEBUG(1,("process_reset_browser: received diagnostic browser reset \
+request from %s IP %s state=0x%X\n",
+               nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state));
+
+       /* Stop being a local master browser on all our broadcast subnets. */
+       if (state & 0x1) {
+               for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) {
+                       struct work_record *work;
+                       for (work = sr->workgrouplist; work; work = work->next) {
+                               if (AM_LOCAL_MASTER_BROWSER(work))
+                                       unbecome_local_master_browser(sr, work, True);
+                       }
+               }
+       }
   
-  /* Discard our browse lists. */
-  if (state & 0x2)
-  {
-    /*
-     * Calling expire_workgroups_and_servers with a -1
-     * time causes all servers not marked with a PERMANENT_TTL
-     * on the workgroup lists to be discarded, and all 
-     * workgroups with empty server lists to be discarded.
-     * This means we keep our own server names and workgroup
-     * as these have a PERMANENT_TTL.
-     */
-
-    expire_workgroups_and_servers(-1);
-  }
+       /* Discard our browse lists. */
+       if (state & 0x2) {
+               /*
+                * Calling expire_workgroups_and_servers with a -1
+                * time causes all servers not marked with a PERMANENT_TTL
+                * on the workgroup lists to be discarded, and all 
+                * workgroups with empty server lists to be discarded.
+                * This means we keep our own server names and workgroup
+                * as these have a PERMANENT_TTL.
+                */
+
+               expire_workgroups_and_servers(-1);
+       }
   
-  /* Request to stop browsing altogether. */
-  if (state & 0x4)
-    DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n"));
+       /* Request to stop browsing altogether. */
+       if (state & 0x4)
+               DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n"));
 
-  END_PROFILE(reset_browser);
+       END_PROFILE(reset_browser);
 }
 
 /*******************************************************************
@@ -793,33 +772,34 @@ request from %s IP %s state=0x%X\n",
 
 void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  struct work_record *work;
-  char *workgroup_name = dgram->dest_name.name;
+       struct dgram_packet *dgram = &p->packet.dgram;
+       struct work_record *work;
+       nstring workgroup_name;
  
-  START_PROFILE(announce_request);
-  DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
-           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
-           nmb_namestr(&dgram->dest_name)));
-  
-  /* We only send announcement requests on our workgroup. */
-  if(strequal(workgroup_name, lp_workgroup()) == False)
-  {
-    DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n",
-           workgroup_name));
-    goto done;
-  }
-
-  if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL)
-  {
-    DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
-            workgroup_name));
-    goto done;
-  }
+       START_PROFILE(announce_request);
 
-  work->needannounce = True;
+       pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
+       DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n",
+               nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+               nmb_namestr(&dgram->dest_name)));
+  
+       /* We only send announcement requests on our workgroup. */
+       if(strequal(workgroup_name, lp_workgroup()) == False) {
+               DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n",
+                       workgroup_name));
+               goto done;
+       }
+
+       if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) {
+               DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
+                       workgroup_name));
+               goto done;
+       }
+
+       work->needannounce = True;
 done:
-  END_PROFILE(lm_host_announce);
+
+       END_PROFILE(lm_host_announce);
 }
 
 /*******************************************************************
@@ -833,30 +813,32 @@ done:
 
 void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  char *workgroup_name = dgram->dest_name.name;
+       struct dgram_packet *dgram = &p->packet.dgram;
+       nstring workgroup_name;
 
-  START_PROFILE(lm_announce_request);
-  DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
-           nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
-           nmb_namestr(&dgram->dest_name)));
+       START_PROFILE(lm_announce_request);
 
-  /* We only send announcement requests on our workgroup. */
-  if(strequal(workgroup_name, lp_workgroup()) == False)
-  {
-    DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n",
-           workgroup_name));
-    goto done;
-  }
+       pull_ascii_nstring(workgroup_name, dgram->dest_name.name);
+       DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n",
+               nmb_namestr(&dgram->source_name), inet_ntoa(p->ip),
+               nmb_namestr(&dgram->dest_name)));
 
-  if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL)
-  {
-    DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
-            workgroup_name));
-    goto done;
-  }
+       /* We only send announcement requests on our workgroup. */
+       if(strequal(workgroup_name, lp_workgroup()) == False) {
+               DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n",
+                       workgroup_name));
+               goto done;
+       }
+
+       if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) {
+               DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n",
+                       workgroup_name));
+               goto done;
+       }
+
+       found_lm_clients = True;
 
-  found_lm_clients = True;
 done:
-  END_PROFILE(lm_host_announce);
+
+       END_PROFILE(lm_host_announce);
 }
index a3faf5e1046aeb7d7bc9c81f9725b3e8d7009c3c..dd999fbdf774832e21da6741e497700aad753410 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -33,18 +33,18 @@ Send a name release response.
 
 static void send_name_release_response(int rcode, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  char rdata[6];
+       struct nmb_packet *nmb = &p->packet.nmb;
+       char rdata[6];
 
-  memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
+       memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
   
-  reply_netbios_packet(p,                            /* Packet to reply to. */
-                       rcode,                        /* Result code. */
-                       NMB_REL,                      /* nmbd type code. */
-                       NMB_NAME_RELEASE_OPCODE,      /* opcode. */
-                       0,                            /* ttl. */
-                       rdata,                        /* data to send. */
-                       6);                           /* data length. */
+       reply_netbios_packet(p,                       /* Packet to reply to. */
+                       rcode,                        /* Result code. */
+                       NMB_REL,                      /* nmbd type code. */
+                       NMB_NAME_RELEASE_OPCODE,      /* opcode. */
+                       0,                            /* ttl. */
+                       rdata,                        /* data to send. */
+                       6);                           /* data length. */
 }
 
 /****************************************************************************
@@ -55,76 +55,74 @@ Ignore it if it's not one of our names.
 void process_name_release_request(struct subnet_record *subrec, 
                                   struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct in_addr owner_ip;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  BOOL group = (nb_flags & NB_GROUP) ? True : False;
-  struct name_record *namerec;
-  int rcode = 0;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct in_addr owner_ip;
+       struct nmb_name *question = &nmb->question.question_name;
+       nstring qname;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       struct name_record *namerec;
+       int rcode = 0;
   
-  putip((char *)&owner_ip,&nmb->additional->rdata[2]);  
+       putip((char *)&owner_ip,&nmb->additional->rdata[2]);  
   
-  if(!bcast)
-  {
-    /* We should only get broadcast name release packets here.
-       Anyone trying to release unicast should be going to a WINS
-       server. If the code gets here, then either we are not a wins
-       server and they sent it anyway, or we are a WINS server and
-       the request was malformed. Either way, log an error here.
-       and send an error reply back.
-     */
-    DEBUG(0,("process_name_release_request: unicast name release request \
+       if(!bcast) {
+               /* We should only get broadcast name release packets here.
+                  Anyone trying to release unicast should be going to a WINS
+                  server. If the code gets here, then either we are not a wins
+                  server and they sent it anyway, or we are a WINS server and
+                  the request was malformed. Either way, log an error here.
+                  and send an error reply back.
+               */
+               DEBUG(0,("process_name_release_request: unicast name release request \
 received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name));      
+                       nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name));      
 
-    send_name_release_response(FMT_ERR, p);
-    return;
-  }
+               send_name_release_response(FMT_ERR, p);
+               return;
+       }
 
-  DEBUG(3,("process_name_release_request: Name release on name %s, \
+       DEBUG(3,("process_name_release_request: Name release on name %s, \
 subnet %s from owner IP %s\n",
-           nmb_namestr(&nmb->question.question_name),
-           subrec->subnet_name, inet_ntoa(owner_ip)));
+               nmb_namestr(&nmb->question.question_name),
+               subrec->subnet_name, inet_ntoa(owner_ip)));
   
-  /* If someone is releasing a broadcast group name, just ignore it. */
-  if( group && !ismyip(owner_ip) )
-    return;
-
-  /*
-   * Code to work around a bug in FTP OnNet software NBT implementation.
-   * They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e>
-   * names and *don't set the group bit* !!!!!
-   */
-
-  if( !group && !ismyip(owner_ip) && strequal(question->name, lp_workgroup()) && 
-      ((question->name_type == 0x0) || (question->name_type == 0x1e)))
-  {
-    DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \
+       /* If someone is releasing a broadcast group name, just ignore it. */
+       if( group && !ismyip(owner_ip) )
+               return;
+
+       /*
+        * Code to work around a bug in FTP OnNet software NBT implementation.
+        * They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e>
+        * names and *don't set the group bit* !!!!!
+        */
+
+       pull_ascii_nstring(qname, question->name);
+       if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && 
+                       ((question->name_type == 0x0) || (question->name_type == 0x1e))) {
+               DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \
 group release name %s from IP %s on subnet %s with no group bit set.\n",
-        nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name ));
-    return;
-  }
-
-  namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_ANY_NAME);
-
-  /* We only care about someone trying to release one of our names. */
-  if( namerec
-   && ( (namerec->data.source == SELF_NAME)
-     || (namerec->data.source == PERMANENT_NAME) ) )
-  {
-    rcode = ACT_ERR;
-    DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \
+                       nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name ));
+               return;
+       }
+
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+
+       /* We only care about someone trying to release one of our names. */
+       if( namerec && ( (namerec->data.source == SELF_NAME)
+                       || (namerec->data.source == PERMANENT_NAME) ) ) {
+               rcode = ACT_ERR;
+               DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \
 on subnet %s being rejected as it is one of our names.\n", 
-          nmb_namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name));
-  }
+               nmb_namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name));
+       }
 
-  if(rcode == 0)
-    return;
+       if(rcode == 0)
+               return;
 
-  /* Send a NAME RELEASE RESPONSE (pos/neg) see rfc1002.txt 4.2.10-11 */
-  send_name_release_response(rcode, p);
+       /* Send a NAME RELEASE RESPONSE (pos/neg) see rfc1002.txt 4.2.10-11 */
+       send_name_release_response(rcode, p);
 }
 
 /****************************************************************************
@@ -133,18 +131,18 @@ Send a name registration response.
 
 static void send_name_registration_response(int rcode, int ttl, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  char rdata[6];
+       struct nmb_packet *nmb = &p->packet.nmb;
+       char rdata[6];
 
-  memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
+       memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
   
-  reply_netbios_packet(p,                             /* Packet to reply to. */
-                       rcode,                         /* Result code. */
-                       NMB_REG,                       /* nmbd type code. */
-                       NMB_NAME_REG_OPCODE,           /* opcode. */
-                       ttl,                           /* ttl. */
-                       rdata,                         /* data to send. */
-                       6);                            /* data length. */
+       reply_netbios_packet(p,                                /* Packet to reply to. */
+                               rcode,                         /* Result code. */
+                               NMB_REG,                       /* nmbd type code. */
+                               NMB_NAME_REG_OPCODE,           /* opcode. */
+                               ttl,                           /* ttl. */
+                               rdata,                         /* data to send. */
+                               6);                            /* data length. */
 }
 
 /****************************************************************************
@@ -154,38 +152,34 @@ Process a name refresh request on a broadcast subnet.
 void process_name_refresh_request(struct subnet_record *subrec,
                                   struct packet_struct *p)
 {    
-     
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  struct in_addr from_ip;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       struct in_addr from_ip;
   
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-
-  if(!bcast)
-  { 
-    /* We should only get broadcast name refresh packets here.
-       Anyone trying to refresh unicast should be going to a WINS
-       server. If the code gets here, then either we are not a wins
-       server and they sent it anyway, or we are a WINS server and
-       the request was malformed. Either way, log an error here.
-       and send an error reply back.
-     */
-    DEBUG(0,("process_name_refresh_request: unicast name registration request \
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+
+       if(!bcast) { 
+               /* We should only get broadcast name refresh packets here.
+                  Anyone trying to refresh unicast should be going to a WINS
+                  server. If the code gets here, then either we are not a wins
+                  server and they sent it anyway, or we are a WINS server and
+                  the request was malformed. Either way, log an error here.
+                  and send an error reply back.
+               */
+               DEBUG(0,("process_name_refresh_request: unicast name registration request \
 received for name %s from IP %s on subnet %s.\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    DEBUG(0,("Error - should be sent to WINS server\n"));
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               DEBUG(0,("Error - should be sent to WINS server\n"));
     
-    send_name_registration_response(FMT_ERR, 0, p);
-    return;
-  } 
+               send_name_registration_response(FMT_ERR, 0, p);
+               return;
+       
 
-  /* Just log a message. We really don't care about broadcast name
-     refreshes. */
+       /* Just log a message. We really don't care about broadcast name refreshes. */
      
-  DEBUG(3,("process_name_refresh_request: Name refresh for name %s \
+       DEBUG(3,("process_name_refresh_request: Name refresh for name %s \
 IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-     
 }
     
 /****************************************************************************
@@ -195,92 +189,83 @@ Process a name registration request on a broadcast subnet.
 void process_name_registration_request(struct subnet_record *subrec, 
                                        struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  BOOL group = (nb_flags & NB_GROUP) ? True : False;
-  struct name_record *namerec = NULL;
-  int ttl = nmb->additional->ttl;
-  struct in_addr from_ip;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       struct name_record *namerec = NULL;
+       int ttl = nmb->additional->ttl;
+       struct in_addr from_ip;
   
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
   
-  if(!bcast)
-  {
-    /* We should only get broadcast name registration packets here.
-       Anyone trying to register unicast should be going to a WINS
-       server. If the code gets here, then either we are not a wins
-       server and they sent it anyway, or we are a WINS server and
-       the request was malformed. Either way, log an error here.
-       and send an error reply back.
-     */
-    DEBUG(0,("process_name_registration_request: unicast name registration request \
+       if(!bcast) {
+               /* We should only get broadcast name registration packets here.
+                  Anyone trying to register unicast should be going to a WINS
+                  server. If the code gets here, then either we are not a wins
+                  server and they sent it anyway, or we are a WINS server and
+                  the request was malformed. Either way, log an error here.
+                  and send an error reply back.
+               */
+               DEBUG(0,("process_name_registration_request: unicast name registration request \
 received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));      
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));      
 
-    send_name_registration_response(FMT_ERR, 0, p);
-    return;
-  }
+               send_name_registration_response(FMT_ERR, 0, p);
+               return;
+       }
 
-  DEBUG(3,("process_name_registration_request: Name registration for name %s \
+       DEBUG(3,("process_name_registration_request: Name registration for name %s \
 IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
   
-  /* See if the name already exists. */
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+       /* See if the name already exists. */
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
  
-  /* 
-   * If the name being registered exists and is a WINS_PROXY_NAME 
-   * then delete the WINS proxy name entry so we don't reply erroneously
-   * later to queries.
-   */
-
-  if((namerec != NULL) && (namerec->data.source == WINS_PROXY_NAME))
-  {
-    remove_name_from_namelist( subrec, namerec );
-    namerec = NULL;
-  }
-
-  if (!group)
-  {
-    /* Unique name. */
-
-    if( (namerec != NULL)
-     && ( (namerec->data.source == SELF_NAME)
-       || (namerec->data.source == PERMANENT_NAME)
-       || NAME_GROUP(namerec) ) )
-    {
-      /* No-one can register one of Samba's names, nor can they
-         register a name that's a group name as a unique name */
-
-      send_name_registration_response(ACT_ERR, 0, p);
-      return;
-    }
-    else if(namerec != NULL)
-    {
-      /* Update the namelist record with the new information. */
-      namerec->data.ip[0] = from_ip;
-      update_name_ttl(namerec, ttl);
-
-      DEBUG(3,("process_name_registration_request: Updated name record %s \
+       /* 
+        * If the name being registered exists and is a WINS_PROXY_NAME 
+        * then delete the WINS proxy name entry so we don't reply erroneously
+        * later to queries.
+        */
+
+       if((namerec != NULL) && (namerec->data.source == WINS_PROXY_NAME)) {
+               remove_name_from_namelist( subrec, namerec );
+               namerec = NULL;
+       }
+
+       if (!group) {
+               /* Unique name. */
+
+               if( (namerec != NULL)
+                               && ( (namerec->data.source == SELF_NAME)
+                               || (namerec->data.source == PERMANENT_NAME)
+                               || NAME_GROUP(namerec) ) ) {
+                       /* No-one can register one of Samba's names, nor can they
+                               register a name that's a group name as a unique name */
+
+                       send_name_registration_response(ACT_ERR, 0, p);
+                       return;
+               } else if(namerec != NULL) {
+                       /* Update the namelist record with the new information. */
+                       namerec->data.ip[0] = from_ip;
+                       update_name_ttl(namerec, ttl);
+
+                       DEBUG(3,("process_name_registration_request: Updated name record %s \
 with IP %s on subnet %s\n",nmb_namestr(&namerec->name),inet_ntoa(from_ip), subrec->subnet_name));
-      return;
-    }
-  }
-  else
-  {
-    /* Group name. */
-
-    if( (namerec != NULL)
-     && !NAME_GROUP(namerec)
-     && ( (namerec->data.source == SELF_NAME)
-       || (namerec->data.source == PERMANENT_NAME) ) )
-    {
-      /* Disallow group names when we have a unique name. */
-      send_name_registration_response(ACT_ERR, 0, p);  
-      return;  
-    }  
-  }
+                       return;
+               }
+       } else {
+               /* Group name. */
+
+               if( (namerec != NULL)
+                               && !NAME_GROUP(namerec)
+                               && ( (namerec->data.source == SELF_NAME)
+                               || (namerec->data.source == PERMANENT_NAME) ) ) {
+                       /* Disallow group names when we have a unique name. */
+                       send_name_registration_response(ACT_ERR, 0, p);  
+                       return;  
+               }  
+       }
 }
 
 /****************************************************************************
@@ -290,147 +275,150 @@ We put our own names first, then in alphabetical order.
 
 static int status_compare(char *n1,char *n2)
 {
-  int l1,l2,l3;
-
-  /* It's a bit tricky because the names are space padded */
-  for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) ;
-  for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) ;
-  l3 = strlen(global_myname());
-
-  if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && 
-      (l2!=l3 || strncmp(n2,global_myname(),l3) != 0))
-    return -1;
-
-  if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && 
-      (l1!=l3 || strncmp(n1,global_myname(),l3) != 0))
-    return 1;
-
-  return memcmp(n1,n2,18);
+       nstring name1, name2;
+       int l1,l2,l3;
+
+       pull_ascii_nstring(name1, n1);
+       pull_ascii_nstring(name2, n2);
+       n1 = name1;
+       n2 = name2;
+
+       /* It's a bit tricky because the names are space padded */
+       for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++)
+               ;
+       for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++)
+               ;
+       l3 = strlen(global_myname());
+
+       if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && 
+                       (l2!=l3 || strncmp(n2,global_myname(),l3) != 0))
+               return -1;
+
+       if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && 
+                       (l1!=l3 || strncmp(n1,global_myname(),l3) != 0))
+               return 1;
+
+       return memcmp(n1,n2,sizeof(nstring));
 }
 
-
 /****************************************************************************
   Process a node status query
   ****************************************************************************/
 
 void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  char *qname   = nmb->question.question_name.name;
-  int ques_type = nmb->question.question_name.name_type;
-  char rdata[MAX_DGRAM_SIZE];
-  char *countptr, *buf, *bufend, *buf0;
-  int names_added,i;
-  struct name_record *namerec;
-
-  DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \
-subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip),
-          subrec->subnet_name));
-
-  if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name,
-                                    FIND_SELF_NAME)) == 0)
-  {
-    DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \
+       struct nmb_packet *nmb = &p->packet.nmb;
+       nstring qname;
+       int ques_type = nmb->question.question_name.name_type;
+       char rdata[MAX_DGRAM_SIZE];
+       char *countptr, *buf, *bufend, *buf0;
+       int names_added,i;
+       struct name_record *namerec;
+
+       pull_ascii_nstring(qname, nmb->question.question_name.name);
+
+       DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \
+subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name));
+
+       if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_SELF_NAME)) == 0) {
+               DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \
 subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name),
-          inet_ntoa(p->ip), subrec->subnet_name));
+                       inet_ntoa(p->ip), subrec->subnet_name));
 
-    return;
-  }
+               return;
+       }
  
-  /* this is not an exact calculation. the 46 is for the stats buffer
-     and the 60 is to leave room for the header etc */
-  bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60);
-  countptr = buf = rdata;
-  buf += 1;
-  buf0 = buf;
-
-  names_added = 0;
-
-  namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-
-  while (buf < bufend) 
-  {
-    if( (namerec->data.source == SELF_NAME)
-     || (namerec->data.source == PERMANENT_NAME) )
-    {
-      int name_type = namerec->name.name_type;
-      
-      if (!strequal(namerec->name.name,"*") &&
-          !strequal(namerec->name.name,"__SAMBA__") &&
-          (name_type < 0x1b || name_type >= 0x20 || 
-           ques_type < 0x1b || ques_type >= 0x20 ||
-           strequal(qname, namerec->name.name)))
-      {
-        /* Start with the name. */
-        memset(buf,'\0',18);
-        slprintf(buf, 17, "%-15.15s",namerec->name.name);
-        strupper_m(buf);
-        
-        /* Put the name type and netbios flags in the buffer. */
-        buf[15] = name_type;
-        set_nb_flags( &buf[16],namerec->data.nb_flags );
-        buf[16] |= NB_ACTIVE; /* all our names are active */
-
-        buf += 18;
-
-        names_added++;
-      }
-    }
-
-    /* Remove duplicate names. */
-    if (names_added > 1) {
-           qsort( buf0, names_added, 18, QSORT_CAST status_compare );
-    }
-
-    for( i=1; i < names_added ; i++ )
-    {
-      if (memcmp(buf0 + 18*i,buf0 + 18*(i-1),16) == 0) 
-      {
-        names_added--;
-        if (names_added == i)
-          break;
-        memmove(buf0 + 18*i,buf0 + 18*(i+1),18*(names_added-i));
-        i--;
-      }
-    }
-
-    buf = buf0 + 18*names_added;
-
-    namerec = (struct name_record *)ubi_trNext( namerec );
-
-    if (!namerec)
-    {
-      /* End of the subnet specific name list. Now 
-         add the names on the unicast subnet . */
-      struct subnet_record *uni_subrec = unicast_subnet;
-
-      if (uni_subrec != subrec)
-      {
-        subrec = uni_subrec;
-        namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-      }
-    }
-    if (!namerec)
-      break;
-
-  }
+       /* this is not an exact calculation. the 46 is for the stats buffer
+               and the 60 is to leave room for the header etc */
+       bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60);
+       countptr = buf = rdata;
+       buf += 1;
+       buf0 = buf;
+
+       names_added = 0;
+
+       namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
+
+       while (buf < bufend) {
+               if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) {
+                       int name_type = namerec->name.name_type;
+                       nstring name;
+
+                       pull_ascii_nstring(name, namerec->name.name);
+                       strupper_m(name);
+                       if (!strequal(name,"*") &&
+                                       !strequal(name,"__SAMBA__") &&
+                                       (name_type < 0x1b || name_type >= 0x20 || 
+                                       ques_type < 0x1b || ques_type >= 0x20 ||
+                                       strequal(qname, name))) {
+                               /* Start with the name. */
+                               nstring tmp_name;
+                               memset(tmp_name,'\0',sizeof(tmp_name));
+                               snprintf(tmp_name, sizeof(tmp_name), "%-15.15s",name);
+                               push_ascii_nstring(buf, tmp_name);
+
+                               /* Put the name type and netbios flags in the buffer. */
+
+                               buf[15] = name_type;
+                               set_nb_flags( &buf[16],namerec->data.nb_flags );
+                               buf[16] |= NB_ACTIVE; /* all our names are active */
+
+                               buf += 18;
+
+                               names_added++;
+                       }
+               }
+
+               /* Remove duplicate names. */
+               if (names_added > 1) {
+                       qsort( buf0, names_added, 18, QSORT_CAST status_compare );
+               }
+
+               for( i=1; i < names_added ; i++ ) {
+                       if (memcmp(buf0 + 18*i,buf0 + 18*(i-1),16) == 0) {
+                               names_added--;
+                               if (names_added == i)
+                                       break;
+                               memmove(buf0 + 18*i,buf0 + 18*(i+1),18*(names_added-i));
+                               i--;
+                       }
+               }
+
+               buf = buf0 + 18*names_added;
+
+               namerec = (struct name_record *)ubi_trNext( namerec );
+
+               if (!namerec) {
+                       /* End of the subnet specific name list. Now 
+                               add the names on the unicast subnet . */
+                       struct subnet_record *uni_subrec = unicast_subnet;
+
+                       if (uni_subrec != subrec) {
+                               subrec = uni_subrec;
+                               namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
+                       }
+               }
+               if (!namerec)
+                       break;
+
+       }
   
-  SCVAL(countptr,0,names_added);
+       SCVAL(countptr,0,names_added);
   
-  /* We don't send any stats as they could be used to attack
-     the protocol. */
-  memset(buf,'\0',46);
+       /* We don't send any stats as they could be used to attack
+               the protocol. */
+       memset(buf,'\0',46);
   
-  buf += 46;
+       buf += 46;
   
-  /* Send a NODE STATUS RESPONSE */
-  reply_netbios_packet(p,                            /* Packet to reply to. */
-                       0,                            /* Result code. */
-                       NMB_STATUS,                   /* nmbd type code. */
-                       NMB_NAME_QUERY_OPCODE,        /* opcode. */
-                      0,                            /* ttl. */
-                       rdata,                        /* data to send. */
-                       PTR_DIFF(buf,rdata));         /* data length. */
+       /* Send a NODE STATUS RESPONSE */
+       reply_netbios_packet(p,                               /* Packet to reply to. */
+                               0,                            /* Result code. */
+                               NMB_STATUS,                   /* nmbd type code. */
+                               NMB_NAME_QUERY_OPCODE,        /* opcode. */
+                               0,                            /* ttl. */
+                               rdata,                        /* data to send. */
+                               PTR_DIFF(buf,rdata));         /* data length. */
 }
 
 
index 3c067d8ed4ea5a9ccc4ddb348afa537aaff7496c..b14e13f3a47e15da9142148ad7b8d4a0eacd1b35 100644 (file)
 /****************************************************************************
 Load a lmhosts file.
 ****************************************************************************/
+
 void load_lmhosts_file(char *fname)
 {  
-  pstring name;
-  int name_type;
-  struct in_addr ipaddr;
-  XFILE *fp = startlmhosts( fname );
-
-  if (!fp) {
-    DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
-             fname, strerror(errno)));
-    return;
-  }
+       pstring name;
+       int name_type;
+       struct in_addr ipaddr;
+       XFILE *fp = startlmhosts( fname );
+
+       if (!fp) {
+               DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
+                       fname, strerror(errno)));
+               return;
+       }
    
-  while (getlmhostsent(fp, name, &name_type, &ipaddr) )
-  {
-    struct subnet_record *subrec = NULL;
-    enum name_source source = LMHOSTS_NAME;
-
-    /* We find a relevent subnet to put this entry on, then add it. */
-    /* Go through all the broadcast subnets and see if the mask matches. */
-    for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    {
-      if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
-        break;
-    }
+       while (getlmhostsent(fp, name, &name_type, &ipaddr) ) {
+               struct subnet_record *subrec = NULL;
+               enum name_source source = LMHOSTS_NAME;
+
+               /* We find a relevent subnet to put this entry on, then add it. */
+               /* Go through all the broadcast subnets and see if the mask matches. */
+               for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+                       if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
+                               break;
+               }
   
-    /* If none match add the name to the remote_broadcast_subnet. */
-    if(subrec == NULL)
-      subrec = remote_broadcast_subnet;
-
-    if(name_type == -1)
-    {
-      /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
-      (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
-      (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
-    }
-    else
-    {
-      /* Add the given name type to the subnet namelist. */
-      (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
-    }
-  }
+               /* If none match add the name to the remote_broadcast_subnet. */
+               if(subrec == NULL)
+                       subrec = remote_broadcast_subnet;
+
+               if(name_type == -1) {
+                       /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
+                       (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+                       (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+               } else {
+                       /* Add the given name type to the subnet namelist. */
+                       (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
+               }
+       }
    
-  endlmhosts(fp);
+       endlmhosts(fp);
 }
 
 /****************************************************************************
@@ -82,17 +78,16 @@ void load_lmhosts_file(char *fname)
 
 BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp)
 {
-  struct name_record *namerec;
+       struct name_record *namerec;
 
-  *namerecp = NULL;
+       *namerecp = NULL;
 
-  if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, 
-                                 FIND_ANY_NAME))==NULL)
-    return False;
+       if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL)
+               return False;
 
-  if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))
-    return False;
+       if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME))
+               return False;
 
-  *namerecp = namerec;
-  return True;
+       *namerecp = namerec;
+       return True;
 }
index b73586aa4535fe3d37d947e52d2aedf8185c51fa..f79fc56f7bd0fab34c0dcdf52d7e67ea90e0054e 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -29,38 +29,40 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
 
 /****************************************************************************
   Fail to become a Logon server on a subnet.
-  ****************************************************************************/
+****************************************************************************/
+
 static void become_logon_server_fail(struct subnet_record *subrec,
                                       struct response_record *rrec,
                                       struct nmb_name *fail_name)
 {
-  struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name);
-  struct server_record *servrec;
-
-  if(!work)
-  {
-    DEBUG(0,("become_logon_server_fail: Error - cannot find \
-workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name));
-    return;
-  }
-
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
+       nstring failname;
+       struct work_record *work;
+       struct server_record *servrec;
+
+       pull_ascii_nstring(failname, fail_name->name);
+       work = find_workgroup_on_subnet(subrec, failname);
+       if(!work) {
+               DEBUG(0,("become_logon_server_fail: Error - cannot find \
+workgroup %s on subnet %s\n", failname, subrec->subnet_name));
+               return;
+       }
+
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), fail_name->name, subrec->subnet_name));
-    work->log_state = LOGON_NONE;
-    return;
-  }
+                       global_myname(), failname, subrec->subnet_name));
+               work->log_state = LOGON_NONE;
+               return;
+       }
 
-  /* Set the state back to LOGON_NONE. */
-  work->log_state = LOGON_NONE;
+       /* Set the state back to LOGON_NONE. */
+       work->log_state = LOGON_NONE;
 
-  servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
+       servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
 
-  DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
+       DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
 workgroup %s on subnet %s. Couldn't register name %s.\n",
-       work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
+               work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
 
 }
 
@@ -74,49 +76,51 @@ static void become_logon_server_success(struct subnet_record *subrec,
                                         uint16 nb_flags,
                                         int ttl, struct in_addr registered_ip)
 {
-  struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name);
-  struct server_record *servrec;
-
-  if(!work)
-  {
-    DEBUG(0,("become_logon_server_success: Error - cannot find \
-workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name));
-    return;
-  }
-
-  if((servrec = find_server_in_workgroup( work, global_myname())) == NULL)
-  {
-    DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
+       nstring reg_name;
+       struct work_record *work;
+       struct server_record *servrec;
+
+       pull_ascii_nstring(reg_name, registered_name->name);
+       work = find_workgroup_on_subnet( subrec, reg_name);
+       if(!work) {
+               DEBUG(0,("become_logon_server_success: Error - cannot find \
+workgroup %s on subnet %s\n", reg_name, subrec->subnet_name));
+               return;
+       }
+
+       if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) {
+               DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
 in workgroup %s on subnet %s\n",
-       global_myname(), registered_name->name, subrec->subnet_name));
-    work->log_state = LOGON_NONE;
-    return;
-  }
-
-  /* Set the state in the workgroup structure. */
-  work->log_state = LOGON_SRV; /* Become domain master. */
-
-  /* Update our server status. */
-  servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
-  /* To allow Win95 policies to load we need to set type domain
-     controller.
-   */
-  servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
-
-  /* Tell the namelist writer to write out a change. */
-  subrec->work_changed = True;
-
-  /*
-   * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address
-   * for this subnet so we will respond to queries on this name.
-   */
-  {
-         struct nmb_name nmbname;
-         make_nmb_name(&nmbname,lp_workgroup(),0x1c);
-         insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c);
-  }
-
-  DEBUG(0,("become_logon_server_success: Samba is now a logon server \
+                       global_myname(), reg_name, subrec->subnet_name));
+               work->log_state = LOGON_NONE;
+               return;
+       }
+
+       /* Set the state in the workgroup structure. */
+       work->log_state = LOGON_SRV; /* Become domain master. */
+
+       /* Update our server status. */
+       servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
+       /* To allow Win95 policies to load we need to set type domain
+               controller.
+       */
+       servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
+
+       /* Tell the namelist writer to write out a change. */
+       subrec->work_changed = True;
+
+       /*
+        * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address
+        * for this subnet so we will respond to queries on this name.
+        */
+
+       {
+               struct nmb_name nmbname;
+               make_nmb_name(&nmbname,lp_workgroup(),0x1c);
+               insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c);
+       }
+
+       DEBUG(0,("become_logon_server_success: Samba is now a logon server \
 for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
 }
 
@@ -128,45 +132,42 @@ for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
 static void become_logon_server(struct subnet_record *subrec,
                                 struct work_record *work)
 {
-  DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
+       DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
 on subnet %s\n", work->work_group,subrec->subnet_name));
 
-  DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
-          work->work_group));
-  work->log_state = LOGON_WAIT;
+       DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
+               work->work_group));
+       work->log_state = LOGON_WAIT;
 
-  register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
-                become_logon_server_success,
-                become_logon_server_fail, NULL);
+       register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
+                       become_logon_server_success,
+                       become_logon_server_fail, NULL);
 }
 
 /*****************************************************************************
   Add the internet group <1c> logon names by unicast and broadcast.
   ****************************************************************************/
+
 void add_logon_names(void)
 {
-  struct subnet_record *subrec;
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
-
-    if (work && (work->log_state == LOGON_NONE))
-    {
-      struct nmb_name nmbname;
-      make_nmb_name(&nmbname,lp_workgroup(),0x1c);
-
-      if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL)
-      {
-        if( DEBUGLVL( 0 ) )
-        {
-          dbgtext( "add_domain_logon_names:\n" );
-          dbgtext( "Attempting to become logon server " );
-          dbgtext( "for workgroup %s ", lp_workgroup() );
-          dbgtext( "on subnet %s\n", subrec->subnet_name );
-        }
-        become_logon_server(subrec, work);
-      }
-    }
-  }
+       struct subnet_record *subrec;
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
+
+               if (work && (work->log_state == LOGON_NONE)) {
+                       struct nmb_name nmbname;
+                       make_nmb_name(&nmbname,lp_workgroup(),0x1c);
+
+                       if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) {
+                               if( DEBUGLVL( 0 ) ) {
+                                       dbgtext( "add_domain_logon_names:\n" );
+                                       dbgtext( "Attempting to become logon server " );
+                                       dbgtext( "for workgroup %s ", lp_workgroup() );
+                                       dbgtext( "on subnet %s\n", subrec->subnet_name );
+                               }
+                               become_logon_server(subrec, work);
+                       }
+               }
+       }
 }
index dd668218395adeea0c135b9d490c776f26943788..f02fbe1640f411c08c19e897cf1dddbdb45a5c7f 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -27,20 +27,21 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
 
 /****************************************************************************
  Fail funtion when registering my netbios names.
-  **************************************************************************/
+**************************************************************************/
 
 static void my_name_register_failed(struct subnet_record *subrec,
                               struct response_record *rrec, struct nmb_name *nmbname)
 {
-  DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n",
-            nmb_namestr(nmbname), subrec->subnet_name));
+       DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n",
+               nmb_namestr(nmbname), subrec->subnet_name));
 }
 
 
 /****************************************************************************
   Add my workgroup and my given names to one subnet
   Also add the magic Samba names.
-  **************************************************************************/
+**************************************************************************/
+
 void register_my_workgroup_one_subnet(struct subnet_record *subrec)
 {
        int i;
@@ -84,111 +85,104 @@ Exiting.\n", lp_workgroup(), subrec->subnet_name));
 static void insert_refresh_name_into_unicast( struct subnet_record *subrec,
                                                 struct nmb_name *nmbname, uint16 nb_type )
 {
-  struct name_record *namerec;
-
-  if (!we_are_a_wins_client()) {
-    insert_permanent_name_into_unicast(subrec, nmbname, nb_type);
-    return;
-  }
-
-  if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL)
-  {
-    /* The name needs to be created on the unicast subnet. */
-    (void)add_name_to_subnet( unicast_subnet, nmbname->name,
-                              nmbname->name_type, nb_type,
-                              MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip);
-  }
-  else
-  {
-    /* The name already exists on the unicast subnet. Add our local
-       IP for the given broadcast subnet to the name. */
-    add_ip_to_name_record( namerec, subrec->myip);
-  }
+       struct name_record *namerec;
+
+       if (!we_are_a_wins_client()) {
+               insert_permanent_name_into_unicast(subrec, nmbname, nb_type);
+               return;
+       }
+
+       if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) {
+               nstring name;
+               pull_ascii_nstring(name, nmbname->name);
+               /* The name needs to be created on the unicast subnet. */
+               (void)add_name_to_subnet( unicast_subnet, name,
+                               nmbname->name_type, nb_type,
+                               MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip);
+       } else {
+               /* The name already exists on the unicast subnet. Add our local
+                       IP for the given broadcast subnet to the name. */
+               add_ip_to_name_record( namerec, subrec->myip);
+       }
 }
 
 /****************************************************************************
   Add my workgroup and my given names to the subnet lists.
   Also add the magic Samba names.
-  **************************************************************************/
+**************************************************************************/
 
 BOOL register_my_workgroup_and_names(void)
 {
-  struct subnet_record *subrec;
-  int i;
-
-  for(subrec = FIRST_SUBNET; 
-      subrec; 
-      subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-         register_my_workgroup_one_subnet(subrec);
-  }
-
-  /* We still need to add the magic Samba
-     names and the netbios names to the unicast subnet directly. This is
-     to allow unicast node status requests and queries to still work
-     in a broadcast only environment. */
-
-  add_samba_names_to_subnet(unicast_subnet);
-
-  for (i=0; my_netbios_names(i); i++)
-  {
-    for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    {
-      /*
-       * Ensure all the IP addresses are added if we are multihomed.
-       */
-      struct nmb_name nmbname;
-
-      make_nmb_name(&nmbname, my_netbios_names(i),0x20);
-      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
-
-      make_nmb_name(&nmbname, my_netbios_names(i),0x3);
-      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
-
-      make_nmb_name(&nmbname, my_netbios_names(i),0x0);
-      insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
-    }
-  }
-
-  /*
-   * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet
-   * also for the same reasons.
-   */
-
-  for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    /*
-     * Ensure all the IP addresses are added if we are multihomed.
-     */
-    struct nmb_name nmbname;
-
-    make_nmb_name(&nmbname, lp_workgroup(), 0x0);
-    insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
-
-    make_nmb_name(&nmbname, lp_workgroup(), 0x1e);
-    insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
-  }
-
-  /*
-   * We need to add the Samba names to the remote broadcast subnet,
-   * as NT 4.x does directed broadcast requests to the *<0x0> name.
-   */
-  add_samba_names_to_subnet(remote_broadcast_subnet);
-
-  return True;
+       struct subnet_record *subrec;
+       int i;
+
+       for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               register_my_workgroup_one_subnet(subrec);
+       }
+
+       /* We still need to add the magic Samba
+               names and the netbios names to the unicast subnet directly. This is
+               to allow unicast node status requests and queries to still work
+               in a broadcast only environment. */
+
+       add_samba_names_to_subnet(unicast_subnet);
+
+       for (i=0; my_netbios_names(i); i++) {
+               for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+                       /*
+                        * Ensure all the IP addresses are added if we are multihomed.
+                        */
+                       struct nmb_name nmbname;
+
+                       make_nmb_name(&nmbname, my_netbios_names(i),0x20);
+                       insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
+
+                       make_nmb_name(&nmbname, my_netbios_names(i),0x3);
+                       insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
+
+                       make_nmb_name(&nmbname, my_netbios_names(i),0x0);
+                       insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type);
+               }
+       }
+
+       /*
+        * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet
+        * also for the same reasons.
+        */
+
+       for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               /*
+                * Ensure all the IP addresses are added if we are multihomed.
+                */
+               struct nmb_name nmbname;
+
+               make_nmb_name(&nmbname, lp_workgroup(), 0x0);
+               insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
+
+               make_nmb_name(&nmbname, lp_workgroup(), 0x1e);
+               insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
+       }
+
+       /*
+        * We need to add the Samba names to the remote broadcast subnet,
+        * as NT 4.x does directed broadcast requests to the *<0x0> name.
+        */
+
+       add_samba_names_to_subnet(remote_broadcast_subnet);
+
+       return True;
 }
 
 /****************************************************************************
   Remove all the names we registered.
 **************************************************************************/
+
 void release_wins_names(void)
 {
        struct subnet_record *subrec = unicast_subnet;
        struct name_record *namerec, *nextnamerec;
 
-       for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-            namerec;
-            namerec = nextnamerec) {
+       for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = nextnamerec) {
                nextnamerec = (struct name_record *)ubi_trNext( namerec );
                if( (namerec->data.source == SELF_NAME)
                    && !NAME_IS_DEREGISTERING(namerec) )
@@ -199,12 +193,14 @@ void release_wins_names(void)
 
 /*******************************************************************
   Refresh our registered names with WINS
-  ******************************************************************/
+******************************************************************/
+
 void refresh_my_names(time_t t)
 {
        struct name_record *namerec;
 
-       if (wins_srv_count() < 1) return;
+       if (wins_srv_count() < 1)
+               return;
 
        for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist);
             namerec;
index 3f6d2f3b64358e43e402911bb36388a878ca237f..d1c9afd6081a61dde01b88bbe35ad125c6d8fbe5 100644 (file)
@@ -3,7 +3,7 @@
    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
 uint16 samba_nb_type = 0; /* samba's NetBIOS name type */
 
 
-/* ************************************************************************** **
Set Samba's NetBIOS name type.
- * ************************************************************************** **
- */
+/**************************************************************************
+ Set Samba's NetBIOS name type.
+***************************************************************************/
+
 void set_samba_nb_type(void)
-  {
-  if( lp_wins_support() || wins_srv_count() )
-    samba_nb_type = NB_HFLAG;               /* samba is a 'hybrid' node type. */
-  else
-    samba_nb_type = NB_BFLAG;           /* samba is broadcast-only node type. */
-  } /* set_samba_nb_type */
-
-/* ************************************************************************** **
Convert a NetBIOS name to upper case.
- * ************************************************************************** **
- */
+{
+       if( lp_wins_support() || wins_srv_count() )
+               samba_nb_type = NB_HFLAG;               /* samba is a 'hybrid' node type. */
+       else
+               samba_nb_type = NB_BFLAG;           /* samba is broadcast-only node type. */
+}
+
+/***************************************************************************
+ Convert a NetBIOS name to upper case.
+***************************************************************************/
+
 static void upcase_name( struct nmb_name *target, struct nmb_name *source )
-  {
-  int i;
-
-  if( NULL != source )
-    (void)memcpy( target, source, sizeof( struct nmb_name ) );
-
-  strupper_m( target->name );
-  strupper_m( target->scope );
-
-  /* fudge... We're using a byte-by-byte compare, so we must be sure that
-   * unused space doesn't have garbage in it.
-   */
-  for( i = strlen( target->name ); i < sizeof( target->name ); i++ )
-    target->name[i] = '\0';
-  for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ )
-    target->scope[i] = '\0';
-  } /* upcase_name */
-
-/* ************************************************************************** **
- * Add a new or overwrite an existing namelist entry.
- * ************************************************************************** **
- */
+{
+       int i;
+       nstring targ;
+       fstring scope;
+
+       if( NULL != source )
+               memcpy( target, source, sizeof( struct nmb_name ) );
+
+       pull_ascii_nstring(targ, target->name);
+       strupper_m( targ );
+       push_ascii_nstring( target->name, targ);
+
+       pull_ascii(scope, target->scope, 64, -1, STR_TERMINATE);
+       strupper_m( scope );
+       push_ascii(target->scope, scope, 64, STR_TERMINATE);
+
+       /* fudge... We're using a byte-by-byte compare, so we must be sure that
+        * unused space doesn't have garbage in it.
+        */
+
+       for( i = strlen( target->name ); i < sizeof( target->name ); i++ )
+               target->name[i] = '\0';
+       for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ )
+               target->scope[i] = '\0';
+}
+
+/**************************************************************************
+  Add a new or overwrite an existing namelist entry.
+***************************************************************************/
+
 static void update_name_in_namelist( struct subnet_record *subrec,
                               struct name_record   *namerec )
-  {
-  struct name_record *oldrec = NULL;
-
-  (void)ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec );
-  if( oldrec )
-    {
-    SAFE_FREE( oldrec->data.ip );
-    SAFE_FREE( oldrec );
-    }
-  } /* update_name_in_namelist */
-
-/* ************************************************************************** **
- * Remove a name from the namelist.
- * ************************************************************************** **
- */
-void remove_name_from_namelist( struct subnet_record *subrec, 
-                                struct name_record   *namerec )
-  {
-  (void)ubi_trRemove( subrec->namelist, namerec );
+{
+       struct name_record *oldrec = NULL;
 
-  SAFE_FREE(namerec->data.ip);
+       ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec );
+       if( oldrec ) {
+               SAFE_FREE( oldrec->data.ip );
+               SAFE_FREE( oldrec );
+       }
+}
 
-  ZERO_STRUCTP(namerec);
-  SAFE_FREE(namerec);
+/**************************************************************************
+ Remove a name from the namelist.
+***************************************************************************/
+
+void remove_name_from_namelist( struct subnet_record *subrec, 
+                                struct name_record   *namerec )
+{
+       ubi_trRemove( subrec->namelist, namerec );
+       SAFE_FREE(namerec->data.ip);
+       ZERO_STRUCTP(namerec);
+       SAFE_FREE(namerec);
+       subrec->namelist_changed = True;
+}
 
-  subrec->namelist_changed = True;
-  } /* remove_name_from_namelist */
+/**************************************************************************
+ Find a name in a subnet.
+**************************************************************************/
 
-/* ************************************************************************** **
- * Find a name in a subnet.
- * ************************************************************************** **
- */
 struct name_record *find_name_on_subnet( struct subnet_record *subrec,
                                          struct nmb_name      *nmbname,
                                          BOOL                  self_only )
-  {
-  struct nmb_name     uc_name[1];
-  struct name_record *name_ret;
-
-  upcase_name( uc_name, nmbname );
-  name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name );
-  if( name_ret )
-    {
-    /* Self names only - these include permanent names. */
-    if( self_only
-     && (name_ret->data.source != SELF_NAME)
-     && (name_ret->data.source != PERMANENT_NAME) )
-      {
-      DEBUG( 9, 
-             ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n",
-               subrec->subnet_name, nmb_namestr(nmbname) ) );
-      return( NULL );
-      }
-    DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n",
-               subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) );
-    return( name_ret );
-    }
-  DEBUG( 9, 
-         ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n",
-           subrec->subnet_name, nmb_namestr(nmbname) ) );
-  return( NULL );
-  } /* find_name_on_subnet */
-
-/* ************************************************************************** **
- * Find a name over all known broadcast subnets.
- * ************************************************************************** **
- */
+{
+       struct nmb_name     uc_name[1];
+       struct name_record *name_ret;
+
+       upcase_name( uc_name, nmbname );
+       name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name );
+       if( name_ret ) {
+               /* Self names only - these include permanent names. */
+               if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) {
+                       DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n",
+                                               subrec->subnet_name, nmb_namestr(nmbname) ) );
+                       return( NULL );
+               }
+
+               DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n",
+                       subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) );
+               return( name_ret );
+       }
+
+       DEBUG( 9, ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n",
+               subrec->subnet_name, nmb_namestr(nmbname) ) );
+       return( NULL );
+}
+
+/**************************************************************************
+ Find a name over all known broadcast subnets.
+************************************************************************/
+
 struct name_record *find_name_for_remote_broadcast_subnet(
                                                    struct nmb_name *nmbname,
                                                    BOOL             self_only )
-  {
-  struct subnet_record *subrec;
-  struct name_record   *namerec = NULL;
-
-  for( subrec = FIRST_SUBNET;
-       subrec;
-       subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
-    {
-    if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) )
-      break;
-    }
-
-  return( namerec );
-  } /* find_name_for_remote_broadcast_subnet */
+{
+       struct subnet_record *subrec;
+       struct name_record   *namerec = NULL;
+
+       for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) {
+               if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) )
+                       break;
+       }
+
+       return( namerec );
+}
   
-/* ************************************************************************** **
Update the ttl of an entry in a subnet name list.
- * ************************************************************************** **
- */
+/**************************************************************************
+ Update the ttl of an entry in a subnet name list.
+***************************************************************************/
+
 void update_name_ttl( struct name_record *namerec, int ttl )
 {
-  time_t time_now = time(NULL);
+       time_t time_now = time(NULL);
 
-  if( namerec->data.death_time != PERMANENT_TTL )
-    namerec->data.death_time = time_now + ttl;
+       if( namerec->data.death_time != PERMANENT_TTL )
+               namerec->data.death_time = time_now + ttl;
 
-  namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
+       namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
+
+       namerec->subnet->namelist_changed = True;
+}
 
-  namerec->subnet->namelist_changed = True;
-} /* update_name_ttl */
+/**************************************************************************
+ Add an entry to a subnet name list.
+***********************************************************************/
 
-/* ************************************************************************** **
- * Add an entry to a subnet name list.
- * ************************************************************************** **
- */
 struct name_record *add_name_to_subnet( struct subnet_record *subrec,
                                         const char           *name,
                                         int                   type,
@@ -181,70 +178,66 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec,
                                         int                   num_ips,
                                         struct in_addr       *iplist)
 {
-  struct name_record *namerec;
-  time_t time_now = time(NULL);
+       struct name_record *namerec;
+       time_t time_now = time(NULL);
 
-  namerec = (struct name_record *)malloc( sizeof(*namerec) );
-  if( NULL == namerec )
-  {
-    DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
-    return( NULL );
-  }
+       namerec = (struct name_record *)malloc( sizeof(*namerec) );
+       if( NULL == namerec ) {
+               DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
+               return( NULL );
+       }
 
-  memset( (char *)namerec, '\0', sizeof(*namerec) );
-  namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) 
-                                               * num_ips );
-  if( NULL == namerec->data.ip )
-  {
-     DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
+       memset( (char *)namerec, '\0', sizeof(*namerec) );
+       namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips );
+       if( NULL == namerec->data.ip ) {
+               DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
+               ZERO_STRUCTP(namerec);
+               SAFE_FREE(namerec);
+               return NULL;
+       }
 
-     ZERO_STRUCTP(namerec);
-     SAFE_FREE(namerec);
-     return NULL;
-  }
+       namerec->subnet = subrec;
 
-  namerec->subnet = subrec;
+       make_nmb_name(&namerec->name, name, type);
+       upcase_name(&namerec->name, NULL );
 
-  make_nmb_name(&namerec->name, name, type);
-  upcase_name(&namerec->name, NULL );
+       /* Enter the name as active. */
+       namerec->data.nb_flags = nb_flags | NB_ACTIVE;
+       namerec->data.wins_flags = WINS_ACTIVE;
 
-  /* Enter the name as active. */
-  namerec->data.nb_flags = nb_flags | NB_ACTIVE;
-  namerec->data.wins_flags = WINS_ACTIVE;
+       /* If it's our primary name, flag it as so. */
+       if( strequal( my_netbios_names(0), name ) )
+               namerec->data.nb_flags |= NB_PERM;
 
-  /* If it's our primary name, flag it as so. */
-  if( strequal( my_netbios_names(0), name ) )
-    namerec->data.nb_flags |= NB_PERM;
+       /* Copy the IPs. */
+       namerec->data.num_ips = num_ips;
+       memcpy( (namerec->data.ip), iplist, num_ips * sizeof(struct in_addr) );
 
-  /* Copy the IPs. */
-  namerec->data.num_ips = num_ips;
-  memcpy( (namerec->data.ip), iplist, num_ips * sizeof(struct in_addr) );
+       /* Data source. */
+       namerec->data.source = source;
 
-  /* Data source. */
-  namerec->data.source = source;
+       /* Setup the death_time and refresh_time. */
+       if( ttl == PERMANENT_TTL )
+               namerec->data.death_time = PERMANENT_TTL;
+       else
+               namerec->data.death_time = time_now + ttl;
 
-  /* Setup the death_time and refresh_time. */
-  if( ttl == PERMANENT_TTL )
-    namerec->data.death_time = PERMANENT_TTL;
-  else
-    namerec->data.death_time = time_now + ttl;
+       namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
 
-  namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
+       /* Now add the record to the name list. */    
+       update_name_in_namelist( subrec, namerec );
 
-  /* Now add the record to the name list. */    
-  update_name_in_namelist( subrec, namerec );
-
-  DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \
+       DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \
 ttl=%d nb_flags=%2x to subnet %s\n",
-           nmb_namestr( &namerec->name ),
-            inet_ntoa( *iplist ),
-            ttl,
-            (unsigned int)nb_flags,
-            subrec->subnet_name ) );
+               nmb_namestr( &namerec->name ),
+               inet_ntoa( *iplist ),
+               ttl,
+               (unsigned int)nb_flags,
+               subrec->subnet_name ) );
 
-  subrec->namelist_changed = True;
+       subrec->namelist_changed = True;
 
-  return(namerec);
+       return(namerec);
 }
 
 /*******************************************************************
@@ -258,14 +251,17 @@ void standard_success_register(struct subnet_record *subrec,
                              struct nmb_name *nmbname, uint16 nb_flags, int ttl,
                              struct in_addr registered_ip)
 {
-  struct name_record *namerec;
-
-  namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME );
-  if( NULL == namerec )
-    (void)add_name_to_subnet( subrec, nmbname->name, nmbname->name_type,
-                              nb_flags, ttl, SELF_NAME, 1, &registered_ip );
-  else
-    update_name_ttl( namerec, ttl );
+       struct name_record *namerec;
+
+       namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME );
+       if( NULL == namerec ) {
+               nstring name;
+               pull_ascii_nstring(name, nmbname->name);
+               add_name_to_subnet( subrec, name, nmbname->name_type,
+                       nb_flags, ttl, SELF_NAME, 1, &registered_ip );
+       } else {
+               update_name_ttl( namerec, ttl );
+       }
 }
 
 /*******************************************************************
@@ -279,17 +275,16 @@ void standard_fail_register( struct subnet_record   *subrec,
                              struct response_record *rrec,
                              struct nmb_name        *nmbname )
 {
-  struct name_record *namerec;
+       struct name_record *namerec;
 
-  namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME );
+       namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME );
 
-  DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \
-on subnet %s\n",
-            nmb_namestr(nmbname), subrec->subnet_name) );
+       DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \
+on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) );
 
-  /* Remove the name from the subnet. */
-  if( namerec )
-    remove_name_from_namelist(subrec, namerec);
+       /* Remove the name from the subnet. */
+       if( namerec )
+               remove_name_from_namelist(subrec, namerec);
 }
 
 /*******************************************************************
@@ -298,13 +293,13 @@ on subnet %s\n",
 
 static void remove_nth_ip_in_record( struct name_record *namerec, int ind)
 {
-  if( ind != namerec->data.num_ips )
-    memmove( (char *)(&namerec->data.ip[ind]),
-             (char *)(&namerec->data.ip[ind+1]), 
-             ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) );
+       if( ind != namerec->data.num_ips )
+               memmove( (char *)(&namerec->data.ip[ind]),
+                               (char *)(&namerec->data.ip[ind+1]), 
+                               ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) );
 
-  namerec->data.num_ips--;
-  namerec->subnet->namelist_changed = True;
+       namerec->data.num_ips--;
+       namerec->subnet->namelist_changed = True;
 }
 
 /*******************************************************************
@@ -313,13 +308,13 @@ static void remove_nth_ip_in_record( struct name_record *namerec, int ind)
 
 BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip )
 {
-  int i;
+       int i;
 
-  for(i = 0; i < namerec->data.num_ips; i++)
-    if(ip_equal( namerec->data.ip[i], ip))
-      return True;
+       for(i = 0; i < namerec->data.num_ips; i++)
+               if(ip_equal( namerec->data.ip[i], ip))
+                       return True;
 
-  return False;
+       return False;
 }
 
 /*******************************************************************
@@ -328,30 +323,26 @@ BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip )
 
 void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip )
 {
-  struct in_addr *new_list;
+       struct in_addr *new_list;
 
-  /* Don't add one we already have. */
-  if( find_ip_in_name_record( namerec, new_ip ) )
-    return;
+       /* Don't add one we already have. */
+       if( find_ip_in_name_record( namerec, new_ip ) )
+               return;
   
-  new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1)
-                                       * sizeof(struct in_addr) );
-  if( NULL == new_list )
-  {
-    DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
-    return;
-  }
-
-  memcpy( (char *)new_list,
-          (char *)namerec->data.ip,
-          namerec->data.num_ips * sizeof(struct in_addr) );
-  new_list[namerec->data.num_ips] = new_ip;
-
-  SAFE_FREE(namerec->data.ip);
-  namerec->data.ip = new_list;
-  namerec->data.num_ips += 1;
-
-  namerec->subnet->namelist_changed = True;
+       new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) * sizeof(struct in_addr) );
+       if( NULL == new_list ) {
+               DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
+               return;
+       }
+
+       memcpy( (char *)new_list, (char *)namerec->data.ip, namerec->data.num_ips * sizeof(struct in_addr) );
+       new_list[namerec->data.num_ips] = new_ip;
+
+       SAFE_FREE(namerec->data.ip);
+       namerec->data.ip = new_list;
+       namerec->data.num_ips += 1;
+
+       namerec->subnet->namelist_changed = True;
 }
 
 /*******************************************************************
@@ -361,16 +352,16 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip )
 void remove_ip_from_name_record( struct name_record *namerec,
                                  struct in_addr      remove_ip )
 {
-  /* Try and find the requested ip address - remove it. */
-  int i;
-  int orig_num = namerec->data.num_ips;
-
-  for(i = 0; i < orig_num; i++)
-    if( ip_equal( remove_ip, namerec->data.ip[i]) )
-    {
-      remove_nth_ip_in_record( namerec, i);
-      break;
-    }
+       /* Try and find the requested ip address - remove it. */
+       int i;
+       int orig_num = namerec->data.num_ips;
+
+       for(i = 0; i < orig_num; i++) {
+               if( ip_equal( remove_ip, namerec->data.ip[i]) ) {
+                       remove_nth_ip_in_record( namerec, i);
+                       break;
+               }
+       }
 }
 
 /*******************************************************************
@@ -384,85 +375,67 @@ void standard_success_release( struct subnet_record   *subrec,
                                struct nmb_name        *nmbname,
                                struct in_addr          released_ip )
 {
-  struct name_record *namerec;
-
-  namerec = find_name_on_subnet( subrec, nmbname, FIND_ANY_NAME );
-
-  if( namerec == NULL )
-  {
-    DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \
-on subnet %s. Name was not found on subnet.\n",
-                nmb_namestr(nmbname),
-                inet_ntoa(released_ip),
-                subrec->subnet_name) );
-    return;
-  }
-  else
-  {
-    int orig_num = namerec->data.num_ips;
-
-    remove_ip_from_name_record( namerec, released_ip );
-
-    if( namerec->data.num_ips == orig_num )
-      DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \
-on subnet %s. This ip is not known for this name.\n",
-                nmb_namestr(nmbname),
-                inet_ntoa(released_ip),
-                subrec->subnet_name ) );
-  }
-
-  if( namerec->data.num_ips == 0 )
-    remove_name_from_namelist( subrec, namerec );
+       struct name_record *namerec;
+
+       namerec = find_name_on_subnet( subrec, nmbname, FIND_ANY_NAME );
+       if( namerec == NULL ) {
+               DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \
+on subnet %s. Name was not found on subnet.\n", nmb_namestr(nmbname), inet_ntoa(released_ip),
+                               subrec->subnet_name) );
+               return;
+       } else {
+               int orig_num = namerec->data.num_ips;
+
+               remove_ip_from_name_record( namerec, released_ip );
+
+               if( namerec->data.num_ips == orig_num )
+                       DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \
+on subnet %s. This ip is not known for this name.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) );
+       }
+
+       if( namerec->data.num_ips == 0 )
+               remove_name_from_namelist( subrec, namerec );
 }
 
 /*******************************************************************
   Expires old names in a subnet namelist.
-  ******************************************************************/
+******************************************************************/
 
 void expire_names_on_subnet(struct subnet_record *subrec, time_t t)
 {
-  struct name_record *namerec;
-  struct name_record *next_namerec;
-
-  for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-       namerec;
-       namerec = next_namerec )
-  {
-    next_namerec = (struct name_record *)ubi_trNext( namerec );
-    if( (namerec->data.death_time != PERMANENT_TTL)
-     && (namerec->data.death_time < t) )
-    {
-      if( namerec->data.source == SELF_NAME )
-      {
-        DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \
-name %s\n", 
-                    subrec->subnet_name, nmb_namestr(&namerec->name) ) );
-        namerec->data.death_time += 300;
-        namerec->subnet->namelist_changed = True;
-        continue;
-      }
-      DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n",
-                 subrec->subnet_name, nmb_namestr(&namerec->name)));
+       struct name_record *namerec;
+       struct name_record *next_namerec;
+
+       for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = next_namerec ) {
+               next_namerec = (struct name_record *)ubi_trNext( namerec );
+               if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) {
+                       if( namerec->data.source == SELF_NAME ) {
+                               DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \
+name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name) ) );
+                               namerec->data.death_time += 300;
+                               namerec->subnet->namelist_changed = True;
+                               continue;
+                       }
+
+                       DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n",
+                               subrec->subnet_name, nmb_namestr(&namerec->name)));
   
-      remove_name_from_namelist( subrec, namerec );
-    }
-  }
+                       remove_name_from_namelist( subrec, namerec );
+               }
+       }
 }
 
 /*******************************************************************
   Expires old names in all subnet namelists.
-  ******************************************************************/
+******************************************************************/
 
 void expire_names(time_t t)
 {
-  struct subnet_record *subrec;
-
-  for( subrec = FIRST_SUBNET;
-       subrec;
-       subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) )
-  {
-    expire_names_on_subnet( subrec, t );
-  }
+       struct subnet_record *subrec;
+
+       for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) {
+               expire_names_on_subnet( subrec, t );
+       }
 }
 
 /****************************************************************************
@@ -475,46 +448,39 @@ void expire_names(time_t t)
 
 void add_samba_names_to_subnet( struct subnet_record *subrec )
 {
-  struct in_addr *iplist = &subrec->myip;
-  int num_ips = 1;
-
-  /* These names are added permanently (ttl of zero) and will NOT be
-     refreshed.  */
-
-  if( (subrec == unicast_subnet)
-   || (subrec == wins_server_subnet)
-   || (subrec == remote_broadcast_subnet) )
-  {
-    struct subnet_record *bcast_subrecs;
-    int i;
-    /* Create an IP list containing all our known subnets. */
-
-    num_ips = iface_count();
-    iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) );
-    if( NULL == iplist )
-    {
-      DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
-      return;
-    }
-
-    for( bcast_subrecs = FIRST_SUBNET, i = 0;
-         bcast_subrecs; 
-         bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ )
-      iplist[i] = bcast_subrecs->myip;
-
-  }
-
-  (void)add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL,
-                           PERMANENT_NAME, num_ips, iplist);
-  (void)add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL,
-                           PERMANENT_NAME, num_ips, iplist);
-  (void)add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL,
-                           PERMANENT_NAME, num_ips, iplist);
-  (void)add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL,
-                           PERMANENT_NAME, num_ips, iplist);
-
-  if(iplist != &subrec->myip)
-    SAFE_FREE(iplist);
+       struct in_addr *iplist = &subrec->myip;
+       int num_ips = 1;
+
+       /* These names are added permanently (ttl of zero) and will NOT be refreshed.  */
+
+       if( (subrec == unicast_subnet) || (subrec == wins_server_subnet) || (subrec == remote_broadcast_subnet) ) {
+               struct subnet_record *bcast_subrecs;
+               int i;
+
+               /* Create an IP list containing all our known subnets. */
+
+               num_ips = iface_count();
+               iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) );
+               if( NULL == iplist ) {
+                       DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
+                       return;
+               }
+
+               for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ )
+                       iplist[i] = bcast_subrecs->myip;
+       }
+
+       add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL,
+                               PERMANENT_NAME, num_ips, iplist);
+       add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL,
+                               PERMANENT_NAME, num_ips, iplist);
+       add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL,
+                               PERMANENT_NAME, num_ips, iplist);
+       add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL,
+                               PERMANENT_NAME, num_ips, iplist);
+
+       if(iplist != &subrec->myip)
+               SAFE_FREE(iplist);
 }
 
 /****************************************************************************
@@ -524,68 +490,65 @@ void add_samba_names_to_subnet( struct subnet_record *subrec )
 
 static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
 {
-  struct name_record *namerec;
-  const char *src_type;
-  struct tm *tm;
-  int i;
-
-  x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
-  for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-       namerec;
-       namerec = (struct name_record *)ubi_trNext( namerec ) )
-  {
-    x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
-    switch(namerec->data.source)
-    {
-      case LMHOSTS_NAME:
-        src_type = "LMHOSTS_NAME";
-        break;
-      case WINS_PROXY_NAME:
-        src_type = "WINS_PROXY_NAME";
-        break;
-      case REGISTER_NAME:
-        src_type = "REGISTER_NAME";
-        break;
-      case SELF_NAME:
-        src_type = "SELF_NAME";
-        break;
-      case DNS_NAME:
-        src_type = "DNS_NAME";
-        break;
-      case DNSFAIL_NAME:
-        src_type = "DNSFAIL_NAME";
-        break;
-      case PERMANENT_NAME:
-        src_type = "PERMANENT_NAME";
-        break;
-      default:
-        src_type = "unknown!";
-        break;
-    }
-    x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
-
-    if(namerec->data.death_time != PERMANENT_TTL)
-    {
-      tm = LocalTime(&namerec->data.death_time);
-      x_fprintf(fp, "death_time = %s\t", asctime(tm));
-    }
-    else
-      x_fprintf(fp, "death_time = PERMANENT\t");
-
-    if(namerec->data.refresh_time != PERMANENT_TTL)
-    {
-      tm = LocalTime(&namerec->data.refresh_time);
-      x_fprintf(fp, "refresh_time = %s\n", asctime(tm));
-    }
-    else
-      x_fprintf(fp, "refresh_time = PERMANENT\n");
-
-    x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
-    for(i = 0; i < namerec->data.num_ips; i++)
-      x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
-
-    x_fprintf(fp, "\n\n");
-  }
+       struct name_record *namerec;
+       const char *src_type;
+       struct tm *tm;
+       int i;
+
+       x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
+       for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec;
+                               namerec = (struct name_record *)ubi_trNext( namerec ) ) {
+
+               x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
+               switch(namerec->data.source) {
+                       case LMHOSTS_NAME:
+                               src_type = "LMHOSTS_NAME";
+                               break;
+                       case WINS_PROXY_NAME:
+                               src_type = "WINS_PROXY_NAME";
+                               break;
+                       case REGISTER_NAME:
+                               src_type = "REGISTER_NAME";
+                               break;
+                       case SELF_NAME:
+                               src_type = "SELF_NAME";
+                               break;
+                       case DNS_NAME:
+                               src_type = "DNS_NAME";
+                               break;
+                       case DNSFAIL_NAME:
+                               src_type = "DNSFAIL_NAME";
+                               break;
+                       case PERMANENT_NAME:
+                               src_type = "PERMANENT_NAME";
+                               break;
+                       default:
+                               src_type = "unknown!";
+                               break;
+               }
+
+               x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
+
+               if(namerec->data.death_time != PERMANENT_TTL) {
+                       tm = LocalTime(&namerec->data.death_time);
+                       x_fprintf(fp, "death_time = %s\t", asctime(tm));
+               } else {
+                       x_fprintf(fp, "death_time = PERMANENT\t");
+               }
+
+               if(namerec->data.refresh_time != PERMANENT_TTL) {
+                       tm = LocalTime(&namerec->data.refresh_time);
+                       x_fprintf(fp, "refresh_time = %s\n", asctime(tm));
+               } else {
+                       x_fprintf(fp, "refresh_time = PERMANENT\n");
+               }
+
+               x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
+               for(i = 0; i < namerec->data.num_ips; i++)
+                       x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
+
+               x_fprintf(fp, "\n\n");
+       }
 }
 
 /****************************************************************************
@@ -595,30 +558,27 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
 
 void dump_all_namelists(void)
 {
-  XFILE *fp; 
-  struct subnet_record *subrec;
+       XFILE *fp; 
+       struct subnet_record *subrec;
 
-  fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644);
+       fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644);
      
-  if (!fp)
-  { 
-    DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n",
-              "namelist.debug",strerror(errno)));
-    return;
-  }
+       if (!fp) { 
+               DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n",
+                       "namelist.debug",strerror(errno)));
+               return;
+       }
       
-  for( subrec = FIRST_SUBNET;
-       subrec;
-       subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) )
-    dump_subnet_namelist( subrec, fp );
+       for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) )
+               dump_subnet_namelist( subrec, fp );
 
-  if( !we_are_a_wins_client() )
-    dump_subnet_namelist( unicast_subnet, fp );
+       if( !we_are_a_wins_client() )
+               dump_subnet_namelist( unicast_subnet, fp );
 
-  if( remote_broadcast_subnet->namelist != NULL )
-    dump_subnet_namelist( remote_broadcast_subnet, fp );
+       if( remote_broadcast_subnet->namelist != NULL )
+               dump_subnet_namelist( remote_broadcast_subnet, fp );
 
-  if( wins_server_subnet != NULL )
-    dump_subnet_namelist( wins_server_subnet, fp );
-  x_fclose( fp );
+       if( wins_server_subnet != NULL )
+               dump_subnet_namelist( wins_server_subnet, fp );
+       x_fclose( fp );
 }
index 8995e9ac522acc10249ebab9b61d5244b058183a..1b07852f111b9e5415a6285b5049822e80ebef31 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -31,106 +31,95 @@ static void query_name_response( struct subnet_record   *subrec,
                                  struct response_record *rrec,
                                  struct packet_struct   *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  BOOL success = False;
-  struct nmb_name *question_name = 
-                           &rrec->packet->packet.nmb.question.question_name;
-  struct in_addr answer_ip;
-
-  zero_ip(&answer_ip);
-
-  /* Ensure we don't retry the query but leave the response record cleanup
-     to the timeout code. We may get more answer responses in which case
-     we should mark the name in conflict.. */
-  rrec->repeat_count = 0;
-
-  if(rrec->num_msgs == 1)
-  {
-    /* This is the first response. */
-
-    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 query requests. */
-
-      if( DEBUGLVL( 5 ) )
-        {
-        dbgtext( "query_name_response: " );
-        dbgtext( "WACK from WINS server %s ", inet_ntoa(p->ip) );
-        dbgtext( "in querying name %s ", nmb_namestr(question_name) );
-        dbgtext( "on subnet %s.\n", subrec->subnet_name );
-        }
+       struct nmb_packet *nmb = &p->packet.nmb;
+       BOOL success = False;
+       struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
+       struct in_addr answer_ip;
+
+       zero_ip(&answer_ip);
+
+       /* Ensure we don't retry the query but leave the response record cleanup
+               to the timeout code. We may get more answer responses in which case
+               we should mark the name in conflict.. */
+       rrec->repeat_count = 0;
+
+       if(rrec->num_msgs == 1) {
+               /* This is the first response. */
+
+               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 query requests. */
+
+                       if( DEBUGLVL( 5 ) ) {
+                               dbgtext( "query_name_response: " );
+                               dbgtext( "WACK from WINS server %s ", inet_ntoa(p->ip) );
+                               dbgtext( "in querying name %s ", nmb_namestr(question_name) );
+                               dbgtext( "on subnet %s.\n", subrec->subnet_name );
+                       }
   
-      rrec->repeat_count = 0;
-      /* How long we should wait for. */
-      rrec->repeat_time = p->timestamp + nmb->answers->ttl;
-      rrec->num_msgs--;
-      return;
-    }
-    else if(nmb->header.rcode != 0)
-    {
-      success = False;
-
-      if( DEBUGLVL( 5 ) )
-        {
-        dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
-        dbgtext( "- negative response from IP %s ", inet_ntoa(p->ip) );
-        dbgtext( "for name %s. ", nmb_namestr(question_name) );
-        dbgtext( "Error code was %d.\n", nmb->header.rcode );
-        }
-    }
-    else
-    {
-      if (!nmb->answers)
-      {
-        dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
-       dbgtext( "IP %s ", inet_ntoa(p->ip) );
-       dbgtext( "returned a success response with no answer\n" );
-       return;
-      }
-
-      success = True;
-
-      putip((char *)&answer_ip,&nmb->answers->rdata[2]);
-      if( DEBUGLVL( 5 ) )
-        {
-        dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
-        dbgtext( "- positive response from IP %s ", inet_ntoa(p->ip) );
-        dbgtext( "for name %s.  ", nmb_namestr(question_name) );
-        dbgtext( "IP of that name is %s\n", inet_ntoa(answer_ip) );
-        }
-
-      /* Interestingly, we could add these names to our namelists, and
-         change nmbd to a model that checked its own name cache first,
-         before sending out a query. This is a task for another day, though.
-       */
-    }
-  }
-  else if( rrec->num_msgs > 1)
-  {
-    if( DEBUGLVL( 0 ) )
-      {
-      if (nmb->answers)
-        putip( (char *)&answer_ip, &nmb->answers->rdata[2] );
-      dbgtext( "query_name_response: " );
-      dbgtext( "Multiple (%d) responses ", rrec->num_msgs );
-      dbgtext( "received for a query on subnet %s ", subrec->subnet_name );
-      dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) );
-      dbgtext( "was from IP %s, reporting ", inet_ntoa(p->ip) );
-      dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) );
-      }
-
-    /* We have already called the success or fail function, so we
-       don't call again here. Leave the response record around in
-       case we get more responses. */
-
-    return; 
-  }
+                       rrec->repeat_count = 0;
+                       /* How long we should wait for. */
+                       rrec->repeat_time = p->timestamp + nmb->answers->ttl;
+                       rrec->num_msgs--;
+                       return;
+               } else if(nmb->header.rcode != 0) {
+
+                       success = False;
+
+                       if( DEBUGLVL( 5 ) ) {
+                               dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
+                               dbgtext( "- negative response from IP %s ", inet_ntoa(p->ip) );
+                               dbgtext( "for name %s. ", nmb_namestr(question_name) );
+                               dbgtext( "Error code was %d.\n", nmb->header.rcode );
+                       }
+               } else {
+                       if (!nmb->answers) {
+                               dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
+                               dbgtext( "IP %s ", inet_ntoa(p->ip) );
+                               dbgtext( "returned a success response with no answer\n" );
+                               return;
+                       }
+
+                       success = True;
+
+                       putip((char *)&answer_ip,&nmb->answers->rdata[2]);
+       
+                       if( DEBUGLVL( 5 ) ) {
+                               dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name );
+                               dbgtext( "- positive response from IP %s ", inet_ntoa(p->ip) );
+                               dbgtext( "for name %s.  ", nmb_namestr(question_name) );
+                               dbgtext( "IP of that name is %s\n", inet_ntoa(answer_ip) );
+                       }
+
+                       /* Interestingly, we could add these names to our namelists, and
+                               change nmbd to a model that checked its own name cache first,
+                               before sending out a query. This is a task for another day, though.
+                       */
+               }
+       } else if( rrec->num_msgs > 1) {
+
+               if( DEBUGLVL( 0 ) ) {
+                       if (nmb->answers)
+                               putip( (char *)&answer_ip, &nmb->answers->rdata[2] );
+                       dbgtext( "query_name_response: " );
+                       dbgtext( "Multiple (%d) responses ", rrec->num_msgs );
+                       dbgtext( "received for a query on subnet %s ", subrec->subnet_name );
+                       dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) );
+                       dbgtext( "was from IP %s, reporting ", inet_ntoa(p->ip) );
+                       dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) );
+               }
+
+               /* We have already called the success or fail function, so we
+                       don't call again here. Leave the response record around in
+                       case we get more responses. */
+
+               return; 
+       }
   
-  if(success && rrec->success_fn)
-    (*(query_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers);
-  else if( rrec->fail_fn)
-    (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode);
+       if(success && rrec->success_fn)
+               (*(query_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers);
+       else if( rrec->fail_fn)
+               (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode);
 
 }
 
@@ -141,32 +130,30 @@ static void query_name_response( struct subnet_record   *subrec,
 static void query_name_timeout_response(struct subnet_record *subrec,
                        struct response_record *rrec)
 {
-  struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
-  /* We can only fail here, never succeed. */
-  BOOL failed = True;
-  struct nmb_name *question_name = &sent_nmb->question.question_name;
-
-  if(rrec->num_msgs != 0)
-  {
-    /* We got at least one response, and have called the success/fail
-       function already. */
-
-    failed = False; 
-  }
-
-  if(failed)
-  {
-    if( DEBUGLVL( 5 ) )
-      {
-      dbgtext( "query_name_timeout_response: No response to " );
-      dbgtext( "query for name %s ", nmb_namestr(question_name) );
-      dbgtext( "on subnet %s.\n", subrec->subnet_name );
-      }
-    if(rrec->fail_fn)
-      (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, 0);
-  }
-
-  remove_response_record(subrec, rrec);
+       struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
+       /* We can only fail here, never succeed. */
+       BOOL failed = True;
+       struct nmb_name *question_name = &sent_nmb->question.question_name;
+
+       if(rrec->num_msgs != 0) {
+               /* We got at least one response, and have called the success/fail
+                       function already. */
+
+               failed = False; 
+       }
+
+       if(failed) {
+               if( DEBUGLVL( 5 ) ) {
+                       dbgtext( "query_name_timeout_response: No response to " );
+                       dbgtext( "query for name %s ", nmb_namestr(question_name) );
+                       dbgtext( "on subnet %s.\n", subrec->subnet_name );
+               }
+
+               if(rrec->fail_fn)
+                       (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, 0);
+       }
+
+       remove_response_record(subrec, rrec);
 }
 
 /****************************************************************************
@@ -177,98 +164,83 @@ static void query_name_timeout_response(struct subnet_record *subrec,
 static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name *nmbname,
                                   struct name_record **namerecp) 
 {
-  struct name_record *namerec;
+       struct name_record *namerec;
 
-  *namerecp = NULL;
+       *namerecp = NULL;
 
-  if(find_name_in_lmhosts(nmbname, namerecp))
-    return True;
+       if(find_name_in_lmhosts(nmbname, namerecp))
+               return True;
   
-  if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL)
-    return False;
-
-  if( NAME_IS_ACTIVE(namerec)
-   && ( (namerec->data.source == SELF_NAME)
-     || (namerec->data.source == LMHOSTS_NAME) ) )
-  {
-    *namerecp = namerec;
-    return True;
-  } 
-  return False;
+       if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL)
+               return False;
+
+       if( NAME_IS_ACTIVE(namerec) && ( (namerec->data.source == SELF_NAME) || (namerec->data.source == LMHOSTS_NAME) ) ) {
+               *namerecp = namerec;
+               return True;
+       } 
+       return False;
 }
 
 /****************************************************************************
  Try and query for a name.
 ****************************************************************************/
 
-BOOL query_name(struct subnet_record *subrec, char *name, int type,
+BOOL query_name(struct subnet_record *subrec, const char *name, int type,
                    query_name_success_function success_fn,
                    query_name_fail_function fail_fn, 
                    struct userdata_struct *userdata)
 {
-  struct nmb_name nmbname;
-  struct name_record *namerec;
-
-  make_nmb_name(&nmbname, name, type);
-
-  /*
-   * We need to check our local namelists first.
-   * It may be an magic name, lmhosts name or just
-   * a name we have registered.
-   */
-
-  if(query_local_namelists(subrec, &nmbname, &namerec) == True)
-  {
-    struct res_rec rrec;
-    int i;
-
-    memset((char *)&rrec, '\0', sizeof(struct res_rec));
-
-    /* Fake up the needed res_rec just in case it's used. */
-    rrec.rr_name = nmbname;
-    rrec.rr_type = RR_TYPE_NB;
-    rrec.rr_class = RR_CLASS_IN;
-    rrec.ttl = PERMANENT_TTL;
-    rrec.rdlength = namerec->data.num_ips * 6;
-    if(rrec.rdlength > MAX_DGRAM_SIZE)
-    {
-      if( DEBUGLVL( 0 ) )
-        {
-        dbgtext( "query_name: nmbd internal error - " );
-        dbgtext( "there are %d ip addresses ", namerec->data.num_ips );
-        dbgtext( "for name %s.\n", nmb_namestr(&nmbname) );
-        }
-      return False;
-    }
-
-    for( i = 0; i < namerec->data.num_ips; i++)
-    {
-      set_nb_flags( &rrec.rdata[i*6], namerec->data.nb_flags );
-      putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->data.ip[i]);
-    }
-
-    /* Call the success function directly. */
-    if(success_fn)
-      (*(query_name_success_function)success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec);
-    return False;
-  }
-
-  if(queue_query_name( subrec,
-        query_name_response,
-        query_name_timeout_response,
-        success_fn,
-        fail_fn,
-        userdata,
-        &nmbname) == NULL)
-  {
-    if( DEBUGLVL( 0 ) )
-      {
-      dbgtext( "query_name: Failed to send packet " );
-      dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) );
-      }
-    return True;
-  }
-  return False;
+       struct nmb_name nmbname;
+       struct name_record *namerec;
+
+       make_nmb_name(&nmbname, name, type);
+
+       /*
+        * We need to check our local namelists first.
+        * It may be an magic name, lmhosts name or just
+        * a name we have registered.
+        */
+
+       if(query_local_namelists(subrec, &nmbname, &namerec) == True) {
+               struct res_rec rrec;
+               int i;
+
+               memset((char *)&rrec, '\0', sizeof(struct res_rec));
+
+               /* Fake up the needed res_rec just in case it's used. */
+               rrec.rr_name = nmbname;
+               rrec.rr_type = RR_TYPE_NB;
+               rrec.rr_class = RR_CLASS_IN;
+               rrec.ttl = PERMANENT_TTL;
+               rrec.rdlength = namerec->data.num_ips * 6;
+               if(rrec.rdlength > MAX_DGRAM_SIZE) {
+                       if( DEBUGLVL( 0 ) ) {
+                               dbgtext( "query_name: nmbd internal error - " );
+                               dbgtext( "there are %d ip addresses ", namerec->data.num_ips );
+                               dbgtext( "for name %s.\n", nmb_namestr(&nmbname) );
+                       }
+                       return False;
+               }
+
+               for( i = 0; i < namerec->data.num_ips; i++) {
+                       set_nb_flags( &rrec.rdata[i*6], namerec->data.nb_flags );
+                       putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->data.ip[i]);
+               }
+
+               /* Call the success function directly. */
+               if(success_fn)
+                       (*(query_name_success_function)success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec);
+               return False;
+       }
+
+       if(queue_query_name( subrec, query_name_response, query_name_timeout_response, success_fn, fail_fn, userdata, &nmbname) == NULL) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "query_name: Failed to send packet " );
+                       dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) );
+               }
+               return True;
+       }
+       return False;
 }
 
 /****************************************************************************
@@ -276,29 +248,21 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type,
 ****************************************************************************/
 
 BOOL query_name_from_wins_server(struct in_addr ip_to, 
-                   char *name, int type,
+                   const char *name, int type,
                    query_name_success_function success_fn,
                    query_name_fail_function fail_fn, 
                    struct userdata_struct *userdata)
 {
-  struct nmb_name nmbname;
-
-  make_nmb_name(&nmbname, name, type);
-
-  if(queue_query_name_from_wins_server( ip_to,
-        query_name_response,
-        query_name_timeout_response,
-        success_fn,
-        fail_fn,
-        userdata,
-        &nmbname) == NULL)
-  {
-    if( DEBUGLVL( 0 ) )
-      {
-      dbgtext( "query_name_from_wins_server: Failed to send packet " );
-      dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) );
-      }
-    return True;
-  }
-  return False;
+       struct nmb_name nmbname;
+
+       make_nmb_name(&nmbname, name, type);
+
+       if(queue_query_name_from_wins_server( ip_to, query_name_response, query_name_timeout_response, success_fn, fail_fn, userdata, &nmbname) == NULL) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "query_name_from_wins_server: Failed to send packet " );
+                       dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) );
+               }
+               return True;
+       }
+       return False;
 }
index 7bf2584053ff2ece40c75b9f75fb9b5b2b31923c..0397f56512524275fac3cbbcc87ed5e4f2029b76 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -85,7 +85,9 @@ static void register_name_response(struct subnet_record *subrec,
                 */
                
 #if 1 /* OLD_SAMBA_SERVER_HACK */
-               if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), answer_name->name) &&
+               nstring ans_name;
+               pull_ascii_nstring(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--;
@@ -161,10 +163,10 @@ static void register_name_response(struct subnet_record *subrec,
        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)
 {
@@ -233,7 +235,6 @@ static void wins_registration_timeout(struct subnet_record *subrec,
           us trying to register with each of our failover wins servers */
 }
 
-
 /****************************************************************************
  Deal with a timeout when registering one of our names.
 ****************************************************************************/
@@ -290,10 +291,10 @@ static void register_name_timeout_response(struct subnet_record *subrec,
        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,
@@ -336,11 +337,11 @@ static void multihomed_register_one(struct nmb_name *nmbname,
        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;
@@ -388,6 +389,7 @@ static void wins_next_registration(struct response_record *rrec)
 /****************************************************************************
  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)
@@ -416,6 +418,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
        struct subnet_record *subrec;
        char **wins_tags;
        struct in_addr *ip_list;
+       nstring name;
 
        for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
                num_ips++;
@@ -431,7 +434,8 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
                ip_list[i] = subrec->myip;
        }
 
-       add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type,
+       pull_ascii_nstring(name, nmbname->name);
+       add_name_to_subnet(unicast_subnet, name, nmbname->name_type,
                           nb_flags, lp_max_ttl(), SELF_NAME,
                           num_ips, ip_list);
 
@@ -456,10 +460,10 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags,
        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,
@@ -467,8 +471,18 @@ void register_name(struct subnet_record *subrec,
                    struct userdata_struct *userdata)
 {
        struct nmb_name nmbname;
-       
-       make_nmb_name(&nmbname, name, type);
+       nstring nname;
+
+        if (strlen(name)+1 > sizeof(nstring)) {
+               memcpy(nname, name,sizeof(nstring)-1);
+               nname[sizeof(nstring)-1] = '\0';
+               DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n",
+                       name, nname));
+       } else {
+               nstrcpy(nname,name);
+       }
+
+       make_nmb_name(&nmbname, nname, type);
 
        /* Always set the NB_ACTIVE flag on the name we are
           registering. Doesn't make sense without it.
@@ -498,10 +512,10 @@ void register_name(struct subnet_record *subrec,
        }
 }
 
-
 /****************************************************************************
  Try and refresh one of our names. This is *only* called for WINS refresh
 ****************************************************************************/
+
 void wins_refresh_name(struct name_record *namerec)
 {
        int t;
index 993e4d9d1751e1f68216d32645695ec131b0aa2d..0ea5d6a8182b872fe2e2db04bd0c69a73587b0ba 100644 (file)
@@ -3,7 +3,7 @@
    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
 /****************************************************************************
  Deal with a successful node status response.
 ****************************************************************************/
+
 static void node_status_response(struct subnet_record *subrec,
                        struct response_record *rrec, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
-  struct nmb_name *answer_name = &nmb->answers->rr_name;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
+       struct nmb_name *answer_name = &nmb->answers->rr_name;
 
-  /* Sanity check. Ensure that the answer name in the incoming packet is the
-     same as the requested name in the outgoing packet. */
+       /* Sanity check. Ensure that the answer name in the incoming packet is the
+               same as the requested name in the outgoing packet. */
 
-  if(!nmb_name_equal(question_name, answer_name))
-  {
-    DEBUG(0,("node_status_response: Answer name %s differs from question \
+       if(!nmb_name_equal(question_name, answer_name)) {
+               DEBUG(0,("node_status_response: Answer name %s differs from question \
 name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name)));
-    return;
-  }
+               return;
+       }
 
-  DEBUG(5,("node_status_response: response from name %s on subnet %s.\n",
-        nmb_namestr(answer_name), subrec->subnet_name));
+       DEBUG(5,("node_status_response: response from name %s on subnet %s.\n",
+               nmb_namestr(answer_name), subrec->subnet_name));
 
-  /* Just send the whole answer resource record for the success function
-     to parse. */
-  if(rrec->success_fn)
-    (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip);
+       /* Just send the whole answer resource record for the success function to parse. */
+       if(rrec->success_fn)
+               (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip);
 
-  /* Ensure we don't retry. */
-  remove_response_record(subrec, rrec);
+       /* Ensure we don't retry. */
+       remove_response_record(subrec, rrec);
 }
 
 /****************************************************************************
  Deal with a timeout when requesting a node status.
 ****************************************************************************/
+
 static void node_status_timeout_response(struct subnet_record *subrec,
                        struct response_record *rrec)
 {
-  struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
-  struct nmb_name *question_name = &sent_nmb->question.question_name;
+       struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
+       struct nmb_name *question_name = &sent_nmb->question.question_name;
 
-  DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n",
-           nmb_namestr(question_name), subrec->subnet_name));
+       DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n",
+               nmb_namestr(question_name), subrec->subnet_name));
 
-  if( rrec->fail_fn)
-    (*rrec->fail_fn)(subrec, rrec);
+       if( rrec->fail_fn)
+               (*rrec->fail_fn)(subrec, rrec);
 
-  /* Ensure we don't retry. */
-  remove_response_record(subrec, rrec);
+       /* Ensure we don't retry. */
+       remove_response_record(subrec, rrec);
 }
 
 /****************************************************************************
@@ -82,13 +82,11 @@ BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname,
                  struct in_addr send_ip, node_status_success_function success_fn, 
                  node_status_fail_function fail_fn, struct userdata_struct *userdata)
 {
-  if(queue_node_status( subrec, 
-              node_status_response, node_status_timeout_response,
-              success_fn, fail_fn, userdata, nmbname, send_ip)==NULL)
-  {
-    DEBUG(0,("node_status: Failed to send packet trying to get node status for \
+       if(queue_node_status( subrec, node_status_response, node_status_timeout_response,
+                               success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) {
+               DEBUG(0,("node_status: Failed to send packet trying to get node status for \
 name %s, IP address %s\n", nmb_namestr(nmbname), inet_ntoa(send_ip)));
-    return True;
-  } 
-  return False;
+               return True;
+       
+       return False;
 }
index 6c3446d6c84dadf8bd7ae7e44d2e804b5eb67304..72eb1b501994732691b31406dffe7f2e89c49e65 100644 (file)
@@ -3,7 +3,7 @@
    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
@@ -50,13 +50,13 @@ Utility function to find the specific fd to send a packet out on.
 
 static int find_subnet_fd_for_address( struct in_addr local_ip )
 {
-  struct subnet_record *subrec;
+       struct subnet_record *subrec;
 
-  for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    if(ip_equal(local_ip, subrec->myip))
-      return subrec->nmb_sock;
+       for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
+               if(ip_equal(local_ip, subrec->myip))
+                       return subrec->nmb_sock;
 
-  return ClientNMB;
+       return ClientNMB;
 }
 
 /***************************************************************************
@@ -65,13 +65,13 @@ Utility function to find the specific fd to send a mailslot packet out on.
 
 static int find_subnet_mailslot_fd_for_address( struct in_addr local_ip )
 {
-  struct subnet_record *subrec;
+       struct subnet_record *subrec;
 
-  for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    if(ip_equal(local_ip, subrec->myip))
-      return subrec->dgram_sock;
+       for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
+               if(ip_equal(local_ip, subrec->myip))
+                       return subrec->dgram_sock;
 
-  return ClientDGRAM;
+       return ClientDGRAM;
 }
 
 /***************************************************************************
@@ -80,13 +80,13 @@ Get/Set problematic nb_flags as network byte order 16 bit int.
 
 uint16 get_nb_flags(char *buf)
 {
-  return ((((uint16)*buf)&0xFFFF) & NB_FLGMSK);
+       return ((((uint16)*buf)&0xFFFF) & NB_FLGMSK);
 }
 
 void set_nb_flags(char *buf, uint16 nb_flags)
 {
-  *buf++ = ((nb_flags & NB_FLGMSK) & 0xFF);
-  *buf = '\0';
+       *buf++ = ((nb_flags & NB_FLGMSK) & 0xFF);
+       *buf = '\0';
 }
 
 /***************************************************************************
@@ -95,37 +95,34 @@ Dumps out the browse packet data.
 
 static void debug_browse_data(char *outbuf, int len)
 {
-  int i,j;
-
-  DEBUG( 4, ( "debug_browse_data():\n" ) );
-  for (i = 0; i < len; i+= 16)
-  {
-    DEBUGADD( 4, ( "%3x char ", i ) );
-
-    for (j = 0; j < 16; j++)
-    {
-      unsigned char x;
-      if (i+j >= len)
-        break;
-
-      x = outbuf[i+j];
-      if (x < 32 || x > 127) 
-        x = '.';
+       int i,j;
+
+       DEBUG( 4, ( "debug_browse_data():\n" ) );
+       for (i = 0; i < len; i+= 16) {
+               DEBUGADD( 4, ( "%3x char ", i ) );
+
+               for (j = 0; j < 16; j++) {
+                       unsigned char x;
+                       if (i+j >= len)
+                               break;
+
+                       x = outbuf[i+j];
+                       if (x < 32 || x > 127) 
+                               x = '.';
            
-      DEBUGADD( 4, ( "%c", x ) );
-    }
+                       DEBUGADD( 4, ( "%c", x ) );
+               }
 
-    DEBUGADD( 4, ( "%*s hex", 16-j, "" ) );
+               DEBUGADD( 4, ( "%*s hex", 16-j, "" ) );
 
-    for (j = 0; j < 16; j++)
-    {
-      if (i+j >= len) 
-        break;
-      DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) );
-    }
+               for (j = 0; j < 16; j++) {
+                       if (i+j >= len) 
+                               break;
+                       DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) );
+               }
 
-    DEBUGADD( 4, ("\n") );
-  }
+               DEBUGADD( 4, ("\n") );
+       }
 }
 
 /***************************************************************************
@@ -136,13 +133,11 @@ static uint16 name_trn_id=0;
 
 static uint16 generate_name_trn_id(void)
 {
-
-  if (!name_trn_id)
-  {
-    name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100);
-  }
-  name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF;
-  return name_trn_id;
+       if (!name_trn_id) {
+               name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100);
+       }
+       name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF;
+       return name_trn_id;
 }
 
 /***************************************************************************
@@ -151,28 +146,25 @@ static uint16 generate_name_trn_id(void)
 
 static BOOL send_netbios_packet(struct packet_struct *p)
 {
-  BOOL loopback_this_packet = False;
-
-  /* Check if we are sending to or from ourselves as a WINS server. */
-  if(ismyip(p->ip) && (p->port == global_nmb_port))
-    loopback_this_packet = True;
-
-  if(loopback_this_packet)
-  {
-    struct packet_struct *lo_packet = NULL;
-    DEBUG(5,("send_netbios_packet: sending packet to ourselves.\n"));
-    if((lo_packet = copy_packet(p)) == NULL)
-      return False;
-    queue_packet(lo_packet);
-  }
-  else if (!send_packet(p))
-  {
-    DEBUG(0,("send_netbios_packet: send_packet() to IP %s port %d failed\n",
-                         inet_ntoa(p->ip),p->port));
-    return False;
-  }
+       BOOL loopback_this_packet = False;
+
+       /* Check if we are sending to or from ourselves as a WINS server. */
+       if(ismyip(p->ip) && (p->port == global_nmb_port))
+               loopback_this_packet = True;
+
+       if(loopback_this_packet) {
+               struct packet_struct *lo_packet = NULL;
+               DEBUG(5,("send_netbios_packet: sending packet to ourselves.\n"));
+               if((lo_packet = copy_packet(p)) == NULL)
+                       return False;
+               queue_packet(lo_packet);
+       } else if (!send_packet(p)) {
+               DEBUG(0,("send_netbios_packet: send_packet() to IP %s port %d failed\n",
+                       inet_ntoa(p->ip),p->port));
+               return False;
+       }
   
-  return True;
+       return True;
 } 
 
 /***************************************************************************
@@ -188,45 +180,44 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb
                                                             BOOL bcast, BOOL rec_des,
                                                             struct in_addr to_ip)
 {
-  struct packet_struct *packet = NULL;
-  struct nmb_packet *nmb = NULL;
-
-  /* Allocate the packet_struct we will return. */
-  if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL)
-  {
-    DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
-    return NULL;
-  }
+       struct packet_struct *packet = NULL;
+       struct nmb_packet *nmb = NULL;
+
+       /* Allocate the packet_struct we will return. */
+       if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) {
+               DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
+               return NULL;
+       }
     
-  memset((char *)packet,'\0',sizeof(*packet));
+       memset((char *)packet,'\0',sizeof(*packet));
 
-  nmb = &packet->packet.nmb;
+       nmb = &packet->packet.nmb;
 
-  nmb->header.name_trn_id = generate_name_trn_id();
-  nmb->header.response = False;
-  nmb->header.nm_flags.recursion_desired = rec_des;
-  nmb->header.nm_flags.recursion_available = False;
-  nmb->header.nm_flags.trunc = False;
-  nmb->header.nm_flags.authoritative = False;
-  nmb->header.nm_flags.bcast = bcast;
+       nmb->header.name_trn_id = generate_name_trn_id();
+       nmb->header.response = False;
+       nmb->header.nm_flags.recursion_desired = rec_des;
+       nmb->header.nm_flags.recursion_available = False;
+       nmb->header.nm_flags.trunc = False;
+       nmb->header.nm_flags.authoritative = False;
+       nmb->header.nm_flags.bcast = bcast;
   
-  nmb->header.rcode = 0;
-  nmb->header.qdcount = 1;
-  nmb->header.ancount = 0;
-  nmb->header.nscount = 0;
-
-  nmb->question.question_name = *nmbname;
-  nmb->question.question_type = QUESTION_TYPE_NB_QUERY;
-  nmb->question.question_class = QUESTION_CLASS_IN;
-
-  packet->ip = to_ip;
-  packet->port = NMB_PORT;
-  packet->fd = ClientNMB;
-  packet->timestamp = time(NULL);
-  packet->packet_type = NMB_PACKET;
-  packet->locked = False;
+       nmb->header.rcode = 0;
+       nmb->header.qdcount = 1;
+       nmb->header.ancount = 0;
+       nmb->header.nscount = 0;
+
+       nmb->question.question_name = *nmbname;
+       nmb->question.question_type = QUESTION_TYPE_NB_QUERY;
+       nmb->question.question_class = QUESTION_CLASS_IN;
+
+       packet->ip = to_ip;
+       packet->port = NMB_PORT;
+       packet->fd = ClientNMB;
+       packet->timestamp = time(NULL);
+       packet->packet_type = NMB_PACKET;
+       packet->locked = False;
   
-  return packet; /* Caller must free. */
+       return packet; /* Caller must free. */
 }
 
 /***************************************************************************
@@ -283,20 +274,20 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet,
 
 static BOOL initiate_name_query_packet( struct packet_struct *packet)
 {
-  struct nmb_packet *nmb = NULL;
+       struct nmb_packet *nmb = NULL;
 
-  nmb = &packet->packet.nmb;
+       nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
-  nmb->header.arcount = 0;
+       nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
+       nmb->header.arcount = 0;
 
-  nmb->header.nm_flags.recursion_desired = True;
+       nmb->header.nm_flags.recursion_desired = True;
 
-  DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n",
-          nmb_namestr(&nmb->question.question_name), 
-           BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n",
+               nmb_namestr(&nmb->question.question_name), 
+               BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
 
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 }
 
 /***************************************************************************
@@ -305,20 +296,20 @@ static BOOL initiate_name_query_packet( struct packet_struct *packet)
 
 static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *packet)
 {   
-  struct nmb_packet *nmb = NULL;
+       struct nmb_packet *nmb = NULL;
   
-  nmb = &packet->packet.nmb;
+       nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
-  nmb->header.arcount = 0;
+       nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
+       nmb->header.arcount = 0;
     
-  nmb->header.nm_flags.recursion_desired = False;
+       nmb->header.nm_flags.recursion_desired = False;
   
-  DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n",
-           nmb_namestr(&nmb->question.question_name),
-           BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n",
+               nmb_namestr(&nmb->question.question_name),
+               BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
     
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 } 
 
 /***************************************************************************
@@ -328,21 +319,21 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p
 static BOOL initiate_name_register_packet( struct packet_struct *packet,
                                     uint16 nb_flags, struct in_addr *register_ip)
 {
-  struct nmb_packet *nmb = &packet->packet.nmb;
+       struct nmb_packet *nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_REG_OPCODE;
-  nmb->header.arcount = 1;
+       nmb->header.opcode = NMB_NAME_REG_OPCODE;
+       nmb->header.arcount = 1;
 
-  nmb->header.nm_flags.recursion_desired = True;
+       nmb->header.nm_flags.recursion_desired = True;
 
-  if(create_and_init_additional_record(packet, nb_flags, register_ip) == False)
-    return False;
+       if(create_and_init_additional_record(packet, nb_flags, register_ip) == False)
+               return False;
 
-  DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n",
-          nmb_namestr(&nmb->additional->rr_name),
-           BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n",
+               nmb_namestr(&nmb->additional->rr_name),
+               BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
 
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 }
 
 /***************************************************************************
@@ -380,21 +371,21 @@ for name %s IP %s (bcast=%s) to IP %s\n",
 static BOOL initiate_name_refresh_packet( struct packet_struct *packet,
                                    uint16 nb_flags, struct in_addr *refresh_ip)
 {
-  struct nmb_packet *nmb = &packet->packet.nmb;
+       struct nmb_packet *nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_REFRESH_OPCODE_8;
-  nmb->header.arcount = 1;
+       nmb->header.opcode = NMB_NAME_REFRESH_OPCODE_8;
+       nmb->header.arcount = 1;
 
-  nmb->header.nm_flags.recursion_desired = False;
+       nmb->header.nm_flags.recursion_desired = False;
 
-  if(create_and_init_additional_record(packet, nb_flags, refresh_ip) == False)
-    return False;
+       if(create_and_init_additional_record(packet, nb_flags, refresh_ip) == False)
+               return False;
 
-  DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n",
-          nmb_namestr(&nmb->additional->rr_name),
-           BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n",
+               nmb_namestr(&nmb->additional->rr_name),
+               BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
 
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 } 
 
 /***************************************************************************
@@ -404,21 +395,21 @@ static BOOL initiate_name_refresh_packet( struct packet_struct *packet,
 static BOOL initiate_name_release_packet( struct packet_struct *packet,
                                    uint16 nb_flags, struct in_addr *release_ip)
 {
-  struct nmb_packet *nmb = &packet->packet.nmb;
+       struct nmb_packet *nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_RELEASE_OPCODE;
-  nmb->header.arcount = 1;
+       nmb->header.opcode = NMB_NAME_RELEASE_OPCODE;
+       nmb->header.arcount = 1;
 
-  nmb->header.nm_flags.recursion_desired = False;
+       nmb->header.nm_flags.recursion_desired = False;
 
-  if(create_and_init_additional_record(packet, nb_flags, release_ip) == False)
-    return False;
+       if(create_and_init_additional_record(packet, nb_flags, release_ip) == False)
+               return False;
 
-  DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n",
-          nmb_namestr(&nmb->additional->rr_name),
-           BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n",
+               nmb_namestr(&nmb->additional->rr_name),
+               BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip)));
 
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 } 
 
 /***************************************************************************
@@ -427,20 +418,20 @@ static BOOL initiate_name_release_packet( struct packet_struct *packet,
 
 static BOOL initiate_node_status_packet( struct packet_struct *packet )
 {
-  struct nmb_packet *nmb = &packet->packet.nmb;
+       struct nmb_packet *nmb = &packet->packet.nmb;
 
-  nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
-  nmb->header.arcount = 0;
+       nmb->header.opcode = NMB_NAME_QUERY_OPCODE;
+       nmb->header.arcount = 0;
 
-  nmb->header.nm_flags.recursion_desired = False;
+       nmb->header.nm_flags.recursion_desired = False;
 
-  nmb->question.question_type = QUESTION_TYPE_NB_STATUS;
+       nmb->question.question_type = QUESTION_TYPE_NB_STATUS;
 
-  DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n",
-          nmb_namestr(&nmb->question.question_name),
-           inet_ntoa(packet->ip)));
+       DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n",
+               nmb_namestr(&nmb->question.question_name),
+               inet_ntoa(packet->ip)));
 
-  return send_netbios_packet( packet );
+       return send_netbios_packet( packet );
 }
 
 /****************************************************************************
@@ -456,13 +447,12 @@ static BOOL initiate_node_status_packet( struct packet_struct *packet )
 
 static BOOL assert_check_subnet(struct subnet_record *subrec)
 {
-  if( subrec == remote_broadcast_subnet)
-  {
-    DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \
+       if( subrec == remote_broadcast_subnet) {
+               DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \
 This is a bug.\n"));
-    return True;
-  }
-  return False;
+               return True;
+       }
+       return False;
 }
 
 /****************************************************************************
@@ -478,46 +468,42 @@ struct response_record *queue_register_name( struct subnet_record *subrec,
                           struct nmb_name *nmbname,
                           uint16 nb_flags)
 {
-  struct packet_struct *p;
-  struct response_record *rrec;
-
-  if(assert_check_subnet(subrec))
-    return NULL;
-
-  /* note that all name registration requests have RD set (rfc1002 -
-     section 4.2.2 */
-  if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), True,
-                                         subrec->bcast_ip)) == NULL)
-    return NULL;
-
-  if(initiate_name_register_packet( p, nb_flags, 
-                                    iface_ip(subrec->bcast_ip)) == False)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  if((rrec = make_response_record(subrec,           /* subnet record. */
-           p,                     /* packet we sent. */
-           resp_fn,               /* function to call on response. */
-           timeout_fn,            /* function to call on timeout. */
-           (success_function)success_fn,            /* function to call on operation success. */
-           (fail_function)fail_fn,               /* function to call on operation fail. */
-           userdata)) == NULL)  
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  return rrec;
-}
+       struct packet_struct *p;
+       struct response_record *rrec;
+
+       if(assert_check_subnet(subrec))
+               return NULL;
+
+       /* note that all name registration requests have RD set (rfc1002 - section 4.2.2 */
+       if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), True,
+                               subrec->bcast_ip)) == NULL)
+               return NULL;
+
+       if(initiate_name_register_packet( p, nb_flags, iface_ip(subrec->bcast_ip)) == False) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       if((rrec = make_response_record(subrec,        /* subnet record. */
+                               p,                     /* packet we sent. */
+                               resp_fn,               /* function to call on response. */
+                               timeout_fn,            /* function to call on timeout. */
+                               (success_function)success_fn,            /* function to call on operation success. */
+                               (fail_function)fail_fn,               /* function to call on operation fail. */
+                               userdata)) == NULL)  {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
 
+       return rrec;
+}
 
 /****************************************************************************
  Queue a refresh name packet to the broadcast address of a subnet.
 ****************************************************************************/
+
 void queue_wins_refresh(struct nmb_name *nmbname,
                        response_function resp_fn,
                        timeout_response_function timeout_fn,
@@ -648,47 +634,44 @@ struct response_record *queue_release_name( struct subnet_record *subrec,
                                            struct in_addr release_ip,
                                            struct in_addr dest_ip)
 {
-  struct packet_struct *p;
-  struct response_record *rrec;
-
-  if(assert_check_subnet(subrec))
-    return NULL;
-
-  if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False,
-                                         dest_ip)) == NULL)
-    return NULL;
-
-  if(initiate_name_release_packet( p, nb_flags, &release_ip) == False)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  if((rrec = make_response_record(subrec,           /* subnet record. */
-                    p,                     /* packet we sent. */
-                    resp_fn,               /* function to call on response. */
-                    timeout_fn,            /* function to call on timeout. */
-                    (success_function)success_fn,            /* function to call on operation success. */
-                    (fail_function)fail_fn,               /* function to call on operation fail. */
-                    userdata)) == NULL)  
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  /*
-   * For a broadcast release packet, only send once.
-   * This will cause us to remove the name asap. JRA.
-   */
-
-  if (subrec != unicast_subnet) {
-         rrec->repeat_count = 0;
-         rrec->repeat_time = 0;
-  }
-
-  return rrec;
+       struct packet_struct *p;
+       struct response_record *rrec;
+
+       if(assert_check_subnet(subrec))
+               return NULL;
+
+       if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, dest_ip)) == NULL)
+               return NULL;
+
+       if(initiate_name_release_packet( p, nb_flags, &release_ip) == False) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       if((rrec = make_response_record(subrec,                /* subnet record. */
+                                       p,                     /* packet we sent. */
+                                       resp_fn,               /* function to call on response. */
+                                       timeout_fn,            /* function to call on timeout. */
+                                       (success_function)success_fn,            /* function to call on operation success. */
+                                       (fail_function)fail_fn,               /* function to call on operation fail. */
+                                       userdata)) == NULL)  {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       /*
+        * For a broadcast release packet, only send once.
+        * This will cause us to remove the name asap. JRA.
+        */
+
+       if (subrec != unicast_subnet) {
+               rrec->repeat_count = 0;
+               rrec->repeat_time = 0;
+       }
+
+       return rrec;
 }
 
 /****************************************************************************
@@ -703,80 +686,80 @@ struct response_record *queue_query_name( struct subnet_record *subrec,
                           struct userdata_struct *userdata,
                           struct nmb_name *nmbname)
 {
-  struct packet_struct *p;
-  struct response_record *rrec;
-  struct in_addr to_ip;
+       struct packet_struct *p;
+       struct response_record *rrec;
+       struct in_addr to_ip;
 
-  if(assert_check_subnet(subrec))
-    return NULL;
+       if(assert_check_subnet(subrec))
+               return NULL;
 
-  to_ip = subrec->bcast_ip;
+       to_ip = subrec->bcast_ip;
   
-  /* queries to the WINS server turn up here as queries to IP 0.0.0.0 
-     These need to be handled a bit differently */
-  if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) {
-         /* what we really need to do is loop over each of our wins
-          * servers and wins server tags here, but that just doesn't
-          * fit our architecture at the moment (userdata may already
-          * be used when we get here). For now we just query the first
-          * active wins server on the first tag. */
-         char **tags = wins_srv_tags();
-         if (!tags) {
-                 return NULL;
-         }
-         to_ip = wins_srv_ip_tag(tags[0], to_ip);
-         wins_srv_tags_free(tags);
-  }
-
-  if(( p = create_and_init_netbios_packet(nmbname, 
-                                         (subrec != unicast_subnet)
-                                         (subrec == unicast_subnet), 
-                                         to_ip)) == NULL)
-    return NULL;
-
-  if(lp_bind_interfaces_only()) {
-    int i;
-
-    DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n"));
-    for(i = 0; i < iface_count(); i++) {
-      struct in_addr *ifip = iface_n_ip(i);
-
-      if(ifip == NULL) {
-        DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i));
-        continue;
-      }
-
-      if (ip_equal(*ifip,loopback_ip)) {
-        DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i));
-        continue;
-      }
-
-      DEBUG(10,("queue_query_name: using source IP %s\n",inet_ntoa(*ifip)));
-      p->fd = find_subnet_fd_for_address( *ifip );
-      break;
-    }
-  }
-
-  if(initiate_name_query_packet( p ) == False) {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  if((rrec = make_response_record(subrec,           /* subnet record. */
-               p,                     /* packet we sent. */
-               resp_fn,               /* function to call on response. */
-               timeout_fn,            /* function to call on timeout. */
-               (success_function)success_fn,            /* function to call on operation success. */
-               (fail_function)fail_fn,               /* function to call on operation fail. */
-               userdata)) == NULL)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  return rrec;
+       /* queries to the WINS server turn up here as queries to IP 0.0.0.0 
+                       These need to be handled a bit differently */
+       if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) {
+               /* What we really need to do is loop over each of our wins
+                * servers and wins server tags here, but that just doesn't
+                * fit our architecture at the moment (userdata may already
+                * be used when we get here). For now we just query the first
+                * active wins server on the first tag.
+                */ 
+               char **tags = wins_srv_tags();
+               if (!tags) {
+                       return NULL;
+               }
+               to_ip = wins_srv_ip_tag(tags[0], to_ip);
+               wins_srv_tags_free(tags);
+       }
+
+       if(( p = create_and_init_netbios_packet(nmbname
+                                       (subrec != unicast_subnet), 
+                                       (subrec == unicast_subnet), 
+                                       to_ip)) == NULL)
+               return NULL;
+
+       if(lp_bind_interfaces_only()) {
+               int i;
+
+               DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n"));
+               for(i = 0; i < iface_count(); i++) {
+                       struct in_addr *ifip = iface_n_ip(i);
+
+                       if(ifip == NULL) {
+                               DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i));
+                               continue;
+                       }
+
+                       if (ip_equal(*ifip,loopback_ip)) {
+                               DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i));
+                               continue;
+                       }
+
+                       DEBUG(10,("queue_query_name: using source IP %s\n",inet_ntoa(*ifip)));
+                               p->fd = find_subnet_fd_for_address( *ifip );
+                               break;
+               }
+       }
+
+       if(initiate_name_query_packet( p ) == False) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       if((rrec = make_response_record(subrec,                /* subnet record. */
+                                       p,                     /* packet we sent. */
+                                       resp_fn,               /* function to call on response. */
+                                       timeout_fn,            /* function to call on timeout. */
+                                       (success_function)success_fn,            /* function to call on operation success. */
+                                       (fail_function)fail_fn,               /* function to call on operation fail. */
+                                       userdata)) == NULL) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       return rrec;
 }
 
 /****************************************************************************
@@ -791,33 +774,31 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip,
                           struct userdata_struct *userdata,
                           struct nmb_name *nmbname)
 {
-  struct packet_struct *p;
-  struct response_record *rrec;
-
-  if ((p = create_and_init_netbios_packet(nmbname, False, False, to_ip)) == NULL)
-    return NULL;
-
-  if(initiate_name_query_packet_from_wins_server( p ) == False)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  if((rrec = make_response_record(wins_server_subnet,           /* subnet record. */
-               p,                     /* packet we sent. */
-               resp_fn,               /* function to call on response. */
-               timeout_fn,            /* function to call on timeout. */
-               (success_function)success_fn,            /* function to call on operation success. */
-               (fail_function)fail_fn,               /* function to call on operation fail. */
-               userdata)) == NULL)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  return rrec;
+       struct packet_struct *p;
+       struct response_record *rrec;
+
+       if ((p = create_and_init_netbios_packet(nmbname, False, False, to_ip)) == NULL)
+               return NULL;
+
+       if(initiate_name_query_packet_from_wins_server( p ) == False) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       if((rrec = make_response_record(wins_server_subnet,            /* subnet record. */
+                                               p,                     /* packet we sent. */
+                                               resp_fn,               /* function to call on response. */
+                                               timeout_fn,            /* function to call on timeout. */
+                                               (success_function)success_fn,            /* function to call on operation success. */
+                                               (fail_function)fail_fn,               /* function to call on operation fail. */
+                                               userdata)) == NULL) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       return rrec;
 }
 
 /****************************************************************************
@@ -833,45 +814,41 @@ struct response_record *queue_node_status( struct subnet_record *subrec,
                           struct nmb_name *nmbname,
                           struct in_addr send_ip)
 {
-  struct packet_struct *p;
-  struct response_record *rrec;
+       struct packet_struct *p;
+       struct response_record *rrec;
 
-  /* Sanity check. */
-  if(subrec != unicast_subnet)
-  {
-    DEBUG(0,("queue_register_multihomed_name: should only be done on \
+       /* Sanity check. */
+       if(subrec != unicast_subnet) {
+               DEBUG(0,("queue_register_multihomed_name: should only be done on \
 unicast subnet. subnet is %s\n.", subrec->subnet_name ));
-    return NULL;
-  }
-
-  if(assert_check_subnet(subrec))
-    return NULL;
-
-  if(( p = create_and_init_netbios_packet(nmbname, False, False,
-                                         send_ip)) == NULL)
-    return NULL;
-
-  if(initiate_node_status_packet(p) == False)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  } 
-
-  if((rrec = make_response_record(subrec,           /* subnet record. */
-                   p,                     /* packet we sent. */
-                   resp_fn,               /* function to call on response. */
-                   timeout_fn,            /* function to call on timeout. */
-                   (success_function)success_fn,            /* function to call on operation success. */
-                   (fail_function)fail_fn,               /* function to call on operation fail. */
-                   userdata)) == NULL)
-  {
-    p->locked = False;
-    free_packet(p);
-    return NULL;
-  }
-
-  return rrec;
+               return NULL;
+       }
+
+       if(assert_check_subnet(subrec))
+               return NULL;
+
+       if(( p = create_and_init_netbios_packet(nmbname, False, False, send_ip)) == NULL)
+               return NULL;
+
+       if(initiate_node_status_packet(p) == False) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       } 
+
+       if((rrec = make_response_record(subrec,           /* subnet record. */
+                                       p,                     /* packet we sent. */
+                                       resp_fn,               /* function to call on response. */
+                                       timeout_fn,            /* function to call on timeout. */
+                                       (success_function)success_fn,            /* function to call on operation success. */
+                                       (fail_function)fail_fn,               /* function to call on operation fail. */
+                                       userdata)) == NULL) {
+               p->locked = False;
+               free_packet(p);
+               return NULL;
+       }
+
+       return rrec;
 }
 
 /****************************************************************************
@@ -882,169 +859,145 @@ void reply_netbios_packet(struct packet_struct *orig_packet,
                           int rcode, enum netbios_reply_type_code rcv_code, int opcode,
                           int ttl, char *data,int len)
 {
-  struct packet_struct packet;
-  struct nmb_packet *nmb = NULL;
-  struct res_rec answers;
-  struct nmb_packet *orig_nmb = &orig_packet->packet.nmb;
-  BOOL loopback_this_packet = False;
-  const char *packet_type = "unknown";
+       struct packet_struct packet;
+       struct nmb_packet *nmb = NULL;
+       struct res_rec answers;
+       struct nmb_packet *orig_nmb = &orig_packet->packet.nmb;
+       BOOL loopback_this_packet = False;
+       const char *packet_type = "unknown";
   
-  /* Check if we are sending to or from ourselves. */
-  if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port))
-    loopback_this_packet = True;
+       /* Check if we are sending to or from ourselves. */
+       if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port))
+               loopback_this_packet = True;
   
-  nmb = &packet.packet.nmb;
-
-  /* Do a partial copy of the packet. We clear the locked flag and
-     the resource record pointers. */
-  packet = *orig_packet;   /* Full structure copy. */
-  packet.locked = False;
-  nmb->answers = NULL;
-  nmb->nsrecs = NULL;
-  nmb->additional = NULL;
-
-  switch (rcv_code)
-  {
-    case NMB_STATUS:
-    {
-      packet_type = "nmb_status";
-      nmb->header.nm_flags.recursion_desired = False;
-      nmb->header.nm_flags.recursion_available = False;
-      break;
-    }
-    case NMB_QUERY:
-    {
-      packet_type = "nmb_query";
-      nmb->header.nm_flags.recursion_desired = True;
-      nmb->header.nm_flags.recursion_available = True;
-      break;
-    }
-    case NMB_REG:
-    case NMB_REG_REFRESH:
-    {
-      packet_type = "nmb_reg";
-      nmb->header.nm_flags.recursion_desired = True;
-      nmb->header.nm_flags.recursion_available = True;
-      break;
-    }
-    case NMB_REL:
-    {
-      packet_type = "nmb_rel";
-      nmb->header.nm_flags.recursion_desired = False;
-      nmb->header.nm_flags.recursion_available = False;
-      break;
-    }
-    case NMB_WAIT_ACK:
-    {
-      packet_type = "nmb_wack";
-      nmb->header.nm_flags.recursion_desired = False;
-      nmb->header.nm_flags.recursion_available = False;
-      break;
-    }
-    case WINS_REG:
-    {
-      packet_type = "wins_reg";
-      nmb->header.nm_flags.recursion_desired = True;
-      nmb->header.nm_flags.recursion_available = True;
-      break;
-    }
-    case WINS_QUERY:
-    {
-      packet_type = "wins_query";
-      nmb->header.nm_flags.recursion_desired = True;
-      nmb->header.nm_flags.recursion_available = True;
-      break;
-    }
-
-    default:
-    {
-      DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n",
-                   packet_type, nmb_namestr(&orig_nmb->question.question_name),
-                    inet_ntoa(packet.ip)));
-
-      return;
-    }
-  }
-
-  DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \
-for id %hu\n",
-          packet_type, nmb_namestr(&orig_nmb->question.question_name),
-           inet_ntoa(packet.ip), orig_nmb->header.name_trn_id));
-
-  nmb->header.name_trn_id = orig_nmb->header.name_trn_id;
-  nmb->header.opcode = opcode;
-  nmb->header.response = True;
-  nmb->header.nm_flags.bcast = False;
-  nmb->header.nm_flags.trunc = False;
-  nmb->header.nm_flags.authoritative = True;
+       nmb = &packet.packet.nmb;
+
+       /* Do a partial copy of the packet. We clear the locked flag and
+                       the resource record pointers. */
+       packet = *orig_packet;   /* Full structure copy. */
+       packet.locked = False;
+       nmb->answers = NULL;
+       nmb->nsrecs = NULL;
+       nmb->additional = NULL;
+
+       switch (rcv_code) {
+               case NMB_STATUS:
+                       packet_type = "nmb_status";
+                       nmb->header.nm_flags.recursion_desired = False;
+                       nmb->header.nm_flags.recursion_available = False;
+                       break;
+               case NMB_QUERY:
+                       packet_type = "nmb_query";
+                       nmb->header.nm_flags.recursion_desired = True;
+                       nmb->header.nm_flags.recursion_available = True;
+                       break;
+               case NMB_REG:
+               case NMB_REG_REFRESH:
+                       packet_type = "nmb_reg";
+                       nmb->header.nm_flags.recursion_desired = True;
+                       nmb->header.nm_flags.recursion_available = True;
+                       break;
+               case NMB_REL:
+                       packet_type = "nmb_rel";
+                       nmb->header.nm_flags.recursion_desired = False;
+                       nmb->header.nm_flags.recursion_available = False;
+                       break;
+               case NMB_WAIT_ACK:
+                       packet_type = "nmb_wack";
+                       nmb->header.nm_flags.recursion_desired = False;
+                       nmb->header.nm_flags.recursion_available = False;
+                       break;
+               case WINS_REG:
+                       packet_type = "wins_reg";
+                       nmb->header.nm_flags.recursion_desired = True;
+                       nmb->header.nm_flags.recursion_available = True;
+                       break;
+               case WINS_QUERY:
+                       packet_type = "wins_query";
+                       nmb->header.nm_flags.recursion_desired = True;
+                       nmb->header.nm_flags.recursion_available = True;
+                       break;
+               default:
+                       DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n",
+                               packet_type, nmb_namestr(&orig_nmb->question.question_name),
+                               inet_ntoa(packet.ip)));
+                       return;
+       }
+
+       DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \
+for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name),
+                       inet_ntoa(packet.ip), orig_nmb->header.name_trn_id));
+
+       nmb->header.name_trn_id = orig_nmb->header.name_trn_id;
+       nmb->header.opcode = opcode;
+       nmb->header.response = True;
+       nmb->header.nm_flags.bcast = False;
+       nmb->header.nm_flags.trunc = False;
+       nmb->header.nm_flags.authoritative = True;
   
-  nmb->header.rcode = rcode;
-  nmb->header.qdcount = 0;
-  nmb->header.ancount = 1;
-  nmb->header.nscount = 0;
-  nmb->header.arcount = 0;
+       nmb->header.rcode = rcode;
+       nmb->header.qdcount = 0;
+       nmb->header.ancount = 1;
+       nmb->header.nscount = 0;
+       nmb->header.arcount = 0;
   
-  memset((char*)&nmb->question,'\0',sizeof(nmb->question));
+       memset((char*)&nmb->question,'\0',sizeof(nmb->question));
   
-  nmb->answers = &answers;
-  memset((char*)nmb->answers,'\0',sizeof(*nmb->answers));
+       nmb->answers = &answers;
+       memset((char*)nmb->answers,'\0',sizeof(*nmb->answers));
   
-  nmb->answers->rr_name  = orig_nmb->question.question_name;
-  nmb->answers->rr_type  = orig_nmb->question.question_type;
-  nmb->answers->rr_class = orig_nmb->question.question_class;
-  nmb->answers->ttl      = ttl;
+       nmb->answers->rr_name  = orig_nmb->question.question_name;
+       nmb->answers->rr_type  = orig_nmb->question.question_type;
+       nmb->answers->rr_class = orig_nmb->question.question_class;
+       nmb->answers->ttl      = ttl;
   
-  if (data && len)
-  {
-    nmb->answers->rdlength = len;
-    memcpy(nmb->answers->rdata, data, len);
-  }
+       if (data && len) {
+               nmb->answers->rdlength = len;
+               memcpy(nmb->answers->rdata, data, len);
+       }
   
-  packet.packet_type = NMB_PACKET;
-  /* Ensure we send out on the same fd that the original
-     packet came in on to give the correct source IP address. */
-  packet.fd = orig_packet->fd;
-  packet.timestamp = time(NULL);
+       packet.packet_type = NMB_PACKET;
+       /* Ensure we send out on the same fd that the original
+               packet came in on to give the correct source IP address. */
+       packet.fd = orig_packet->fd;
+       packet.timestamp = time(NULL);
 
-  debug_nmb_packet(&packet);
+       debug_nmb_packet(&packet);
   
-  if(loopback_this_packet)
-  {
-    struct packet_struct *lo_packet;
-    DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n"));
-    if((lo_packet = copy_packet(&packet)) == NULL)
-      return;
-    queue_packet(lo_packet);
-  }
-  else if (!send_packet(&packet)) 
-  {
-    DEBUG(0,("reply_netbios_packet: send_packet to IP %s port %d failed\n",
-                 inet_ntoa(packet.ip),packet.port));
-  }
+       if(loopback_this_packet) {
+               struct packet_struct *lo_packet;
+               DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n"));
+               if((lo_packet = copy_packet(&packet)) == NULL)
+                       return;
+               queue_packet(lo_packet);
+       } else if (!send_packet(&packet)) {
+               DEBUG(0,("reply_netbios_packet: send_packet to IP %s port %d failed\n",
+                       inet_ntoa(packet.ip),packet.port));
+       }
 }
 
 /*******************************************************************
   Queue a packet into a packet queue
 ******************************************************************/
+
 static void queue_packet(struct packet_struct *packet)
 {
-  struct packet_struct *p;
-
-  if (!packet_queue) 
-  {
-    packet->prev = NULL;
-    packet->next = NULL;
-    packet_queue = packet;
-    return;
-  }
+       struct packet_struct *p;
+
+       if (!packet_queue) {
+               packet->prev = NULL;
+               packet->next = NULL;
+               packet_queue = packet;
+               return;
+       }
   
-  /* find the bottom */
-  for (p=packet_queue;p->next;p=p->next) 
-    ;
+       /* find the bottom */
+       for (p=packet_queue;p->next;p=p->next) 
+               ;
 
-  p->next = packet;
-  packet->next = NULL;
-  packet->prev = p;
+       p->next = packet;
+       packet->next = NULL;
+       packet->prev = p;
 }
 
 /****************************************************************************
@@ -1053,184 +1006,153 @@ static void queue_packet(struct packet_struct *packet)
 
 static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_struct *p)
 {
-  struct subnet_record *subrec;
-
-  /* Go through all the broadcast subnets and see if the mask matches. */
-  for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
-      return subrec;
-  }
-
-  /* If the subnet record is the remote announce broadcast subnet,
-     hack it here to be the first subnet. This is really gross and
-     is needed due to people turning on port 137/138 broadcast
-     forwarding on their routers. May fire and brimstone rain
-     down upon them...
-   */
-
-  return FIRST_SUBNET;
+       struct subnet_record *subrec;
+
+       /* Go through all the broadcast subnets and see if the mask matches. */
+       for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+                       return subrec;
+       }
+
+       /* If the subnet record is the remote announce broadcast subnet,
+               hack it here to be the first subnet. This is really gross and
+               is needed due to people turning on port 137/138 broadcast
+               forwarding on their routers. May fire and brimstone rain
+               down upon them...
+       */
+
+       return FIRST_SUBNET;
 }
 
 /****************************************************************************
 Dispatch a browse frame from port 138 to the correct processing function.
 ****************************************************************************/
+
 static void process_browse_packet(struct packet_struct *p, char *buf,int len)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int command = CVAL(buf,0);
-  struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p);
-
-  /* Drop the packet if it's a different NetBIOS scope, or
-     the source is from one of our names. */
-
-  if (!strequal(dgram->dest_name.scope, global_scope()))
-  {
-    DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \
-mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope()));
-    return;
-  }
-
-  if (is_myname(dgram->source_name.name))
-  {
-    DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int command = CVAL(buf,0);
+       struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p);
+       char scope[64];
+       nstring src_name;
+
+       /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */
+       pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE);
+       if (!strequal(scope, global_scope())) {
+               DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \
+mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope()));
+               return;
+       }
+
+       pull_ascii_nstring(src_name, dgram->source_name.name);
+       if (is_myname(src_name)) {
+               DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \
 %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name)));
-    return;
-  }
-
-  switch (command)
-  {
-    case ANN_HostAnnouncement:
-    {
-      debug_browse_data(buf, len);
-      process_host_announce(subrec, p, buf+1);
-      break;
-    }
-    case ANN_DomainAnnouncement:
-    {
-      debug_browse_data(buf, len);
-      process_workgroup_announce(subrec, p, buf+1);
-      break;
-    }
-    case ANN_LocalMasterAnnouncement:
-    {
-      debug_browse_data(buf, len);
-      process_local_master_announce(subrec, p, buf+1);
-      break;
-    }
-    case ANN_AnnouncementRequest:
-    {
-      debug_browse_data(buf, len);
-      process_announce_request(subrec, p, buf+1);
-      break;
-    }
-    case ANN_Election:
-    {
-      debug_browse_data(buf, len);
-      process_election(subrec, p, buf+1);
-      break;
-    }
-    case ANN_GetBackupListReq:
-    {
-      debug_browse_data(buf, len);
-      process_get_backup_list_request(subrec, p, buf+1);
-      break;
-    }
-    case ANN_GetBackupListResp:
-    {
-      debug_browse_data(buf, len);
-      /* We never send ANN_GetBackupListReq so we
-         should never get these. */
-      DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \
+               return;
+       }
+
+       switch (command) {
+               case ANN_HostAnnouncement:
+                       debug_browse_data(buf, len);
+                       process_host_announce(subrec, p, buf+1);
+                       break;
+               case ANN_DomainAnnouncement:
+                       debug_browse_data(buf, len);
+                       process_workgroup_announce(subrec, p, buf+1);
+                       break;
+               case ANN_LocalMasterAnnouncement:
+                       debug_browse_data(buf, len);
+                       process_local_master_announce(subrec, p, buf+1);
+                       break;
+               case ANN_AnnouncementRequest:
+                       debug_browse_data(buf, len);
+                       process_announce_request(subrec, p, buf+1);
+                       break;
+               case ANN_Election:
+                       debug_browse_data(buf, len);
+                       process_election(subrec, p, buf+1);
+                       break;
+               case ANN_GetBackupListReq:
+                       debug_browse_data(buf, len);
+                       process_get_backup_list_request(subrec, p, buf+1);
+                       break;
+               case ANN_GetBackupListResp:
+                       debug_browse_data(buf, len);
+                       /* We never send ANN_GetBackupListReq so we should never get these. */
+                       DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \
 packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip)));
-      break;
-    }
-    case ANN_ResetBrowserState:
-    {
-      debug_browse_data(buf, len);
-      process_reset_browser(subrec, p, buf+1);
-      break;
-    }
-    case ANN_MasterAnnouncement:
-    {
-      /* Master browser datagrams must be processed
-         on the unicast subnet. */
-      subrec = unicast_subnet;
-
-      debug_browse_data(buf, len);
-      process_master_browser_announce(subrec, p, buf+1);
-      break;
-    }
-    case ANN_BecomeBackup:
-    {
-      /* 
-       * We don't currently implement this. Log it just in case.
-       */
-      debug_browse_data(buf, len);
-      DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \
-command ANN_BecomeBackup from %s IP %s to %s\n",
-            subrec->subnet_name, nmb_namestr(&dgram->source_name),
-            inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
-      break;
-    }
-    default:
-    {
-      debug_browse_data(buf, len);
-      DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \
-command code %d from %s IP %s to %s\n", 
-            subrec->subnet_name, command, nmb_namestr(&dgram->source_name),
-            inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
-    }
-  } 
+                       break;
+               case ANN_ResetBrowserState:
+                       debug_browse_data(buf, len);
+                       process_reset_browser(subrec, p, buf+1);
+                       break;
+               case ANN_MasterAnnouncement:
+                       /* Master browser datagrams must be processed on the unicast subnet. */
+                       subrec = unicast_subnet;
+
+                       debug_browse_data(buf, len);
+                       process_master_browser_announce(subrec, p, buf+1);
+                       break;
+               case ANN_BecomeBackup:
+                       /* 
+                        * We don't currently implement this. Log it just in case.
+                        */
+                       debug_browse_data(buf, len);
+                       DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \
+command ANN_BecomeBackup from %s IP %s to %s\n", subrec->subnet_name, nmb_namestr(&dgram->source_name),
+                                       inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
+                       break;
+               default:
+                       debug_browse_data(buf, len);
+                       DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \
+command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name),
+                               inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
+                       break;
+       } 
 }
 
 /****************************************************************************
  Dispatch a LanMan browse frame from port 138 to the correct processing function.
 ****************************************************************************/
+
 static void process_lanman_packet(struct packet_struct *p, char *buf,int len)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  int command = SVAL(buf,0);
-  struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p);
-
-  /* Drop the packet if it's a different NetBIOS scope, or
-     the source is from one of our names. */
-
-  if (!strequal(dgram->dest_name.scope, global_scope()))
-  {
-    DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \
-mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope()));
-    return;
-  }
-
-  if (is_myname(dgram->source_name.name))
-  {
-    DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       int command = SVAL(buf,0);
+       struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p);
+       char scope[64];
+       nstring src_name;
+
+       /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */
+
+       pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE);
+       if (!strequal(scope, global_scope())) {
+               DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \
+mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope()));
+               return;
+       }
+
+       pull_ascii_nstring(src_name, dgram->source_name.name);
+       if (is_myname(src_name)) {
+               DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \
 %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name)));
-    return;
-  }
-
-  switch (command)
-  {
-    case ANN_HostAnnouncement:
-    {
-      debug_browse_data(buf, len);
-      process_lm_host_announce(subrec, p, buf+1);
-      break;
-    }
-    case ANN_AnnouncementRequest:
-    {
-      process_lm_announce_request(subrec, p, buf+1);
-      break;
-    }
-    default:
-    {
-      DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \
-command code %d from %s IP %s to %s\n",
-            subrec->subnet_name, command, nmb_namestr(&dgram->source_name),
-            inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
-    }
-  }
+               return;
+       }
+
+       switch (command) {
+               case ANN_HostAnnouncement:
+                       debug_browse_data(buf, len);
+                       process_lm_host_announce(subrec, p, buf+1);
+                       break;
+               case ANN_AnnouncementRequest:
+                       process_lm_announce_request(subrec, p, buf+1);
+                       break;
+               default:
+                       DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \
+command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name),
+                               inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name)));
+                       break;
+       }
 }
 
 /****************************************************************************
@@ -1241,104 +1163,94 @@ command code %d from %s IP %s to %s\n",
 
 static BOOL listening(struct packet_struct *p,struct nmb_name *nbname)
 {
-  struct subnet_record *subrec = NULL;
+       struct subnet_record *subrec = NULL;
 
-  for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
-      break;
-  }
+       for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+                       break;
+       }
 
-  if(subrec == NULL)
-    subrec = unicast_subnet;
+       if(subrec == NULL)
+               subrec = unicast_subnet;
 
-  return (find_name_on_subnet(subrec, nbname, FIND_SELF_NAME) != NULL);
+       return (find_name_on_subnet(subrec, nbname, FIND_SELF_NAME) != NULL);
 }
 
 /****************************************************************************
   Process udp 138 datagrams
 ****************************************************************************/
+
 static void process_dgram(struct packet_struct *p)
 {
-  char *buf;
-  char *buf2;
-  int len;
-  struct dgram_packet *dgram = &p->packet.dgram;
-
-  /* If we aren't listening to the destination name then ignore the packet */
-  if (!listening(p,&dgram->dest_name))
-  {
-         unexpected_packet(p);
-         DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n",
-                  nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip)));
-         return;
-  }
-
-  if (dgram->header.msg_type != 0x10 &&
-      dgram->header.msg_type != 0x11 &&
-      dgram->header.msg_type != 0x12) 
-  {
-         unexpected_packet(p);
-         /* Don't process error packets etc yet */
-         DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \
-an error packet of type %x\n",
-                  nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type));
-         return;
-  }
-
-  buf = &dgram->data[0];
-  buf -= 4; /* XXXX for the pseudo tcp length - 
-              someday I need to get rid of this */
-
-  if (CVAL(buf,smb_com) != SMBtrans)
-    return;
-
-  len = SVAL(buf,smb_vwv11);
-  buf2 = smb_base(buf) + SVAL(buf,smb_vwv12);
-
-  if (len <= 0)
-    return;
-
-  if (buf2 + len > buf + sizeof(dgram->data)) {
-    DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n",
+       char *buf;
+       char *buf2;
+       int len;
+       struct dgram_packet *dgram = &p->packet.dgram;
+
+       /* If we aren't listening to the destination name then ignore the packet */
+       if (!listening(p,&dgram->dest_name)) {
+                       unexpected_packet(p);
+                       DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n",
+                               nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip)));
+                       return;
+       }
+
+       if (dgram->header.msg_type != 0x10 && dgram->header.msg_type != 0x11 && dgram->header.msg_type != 0x12) {
+               unexpected_packet(p);
+               /* Don't process error packets etc yet */
+               DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \
+an error packet of type %x\n", nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type));
+               return;
+       }
+
+       buf = &dgram->data[0];
+       buf -= 4; /* XXXX for the pseudo tcp length - someday I need to get rid of this */
+
+       if (CVAL(buf,smb_com) != SMBtrans)
+               return;
+
+       len = SVAL(buf,smb_vwv11);
+       buf2 = smb_base(buf) + SVAL(buf,smb_vwv12);
+
+       if (len <= 0)
+               return;
+
+       if (buf2 + len > buf + sizeof(dgram->data)) {
+               DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n",
+                       nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name),
+                       inet_ntoa(p->ip), smb_buf(buf),len));
+               len = (buf + sizeof(dgram->data)) - buf;
+       }
+
+       DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n",
                nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name),
-               inet_ntoa(p->ip), smb_buf(buf),len));
-       len = (buf + sizeof(dgram->data)) - buf;
-  }
+               inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len));
 
-  DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n",
-          nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name),
-          inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len));
+       /* Datagram packet received for the browser mailslot */
+       if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) {
+               process_browse_packet(p,buf2,len);
+               return;
+       }
 
-  /* Datagram packet received for the browser mailslot */
-  if (strequal(smb_buf(buf),BROWSE_MAILSLOT))
-  {
-    process_browse_packet(p,buf2,len);
-    return;
-  }
-
-  /* Datagram packet received for the LAN Manager mailslot */
-  if (strequal(smb_buf(buf),LANMAN_MAILSLOT)) {
-    process_lanman_packet(p,buf2,len);
-    return;
-  }
-
-  /* Datagram packet received for the domain logon mailslot */
-  if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT))
-  {
-    process_logon_packet(p,buf2,len,NET_LOGON_MAILSLOT);
-    return;
-  }
-
-  /* Datagram packet received for the NT domain logon mailslot */
-  if (strequal(smb_buf(buf),NT_LOGON_MAILSLOT))
-  {
-    process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT);
-    return;
-  }
-
-  unexpected_packet(p);
+       /* Datagram packet received for the LAN Manager mailslot */
+       if (strequal(smb_buf(buf),LANMAN_MAILSLOT)) {
+               process_lanman_packet(p,buf2,len);
+               return;
+       }
+
+       /* Datagram packet received for the domain logon mailslot */
+       if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT)) {
+               process_logon_packet(p,buf2,len,NET_LOGON_MAILSLOT);
+               return;
+       }
+
+       /* Datagram packet received for the NT domain logon mailslot */
+       if (strequal(smb_buf(buf),NT_LOGON_MAILSLOT)) {
+               process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT);
+               return;
+       }
+
+       unexpected_packet(p);
 }
 
 /****************************************************************************
@@ -1347,52 +1259,49 @@ an error packet of type %x\n",
 
 static BOOL validate_nmb_response_packet( struct nmb_packet *nmb )
 {
-  BOOL ignore = False;
-
-  switch (nmb->header.opcode) 
-  {
-    case NMB_NAME_REG_OPCODE:
-    case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
-    case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
-      if (nmb->header.ancount == 0)
-      {
-        DEBUG(0,("validate_nmb_response_packet: Bad REG/REFRESH Packet. "));
-        ignore = True;
-      }
-      break;
-
-    case NMB_NAME_QUERY_OPCODE:
-      if ((nmb->header.ancount != 0) && (nmb->header.ancount != 1))
-      {
-        DEBUG(0,("validate_nmb_response_packet: Bad QUERY Packet. "));
-        ignore = True;
-      }
-      break;
-    case NMB_NAME_RELEASE_OPCODE:
-      if (nmb->header.ancount == 0)
-      {
-        DEBUG(0,("validate_nmb_response_packet: Bad RELEASE Packet. "));
-        ignore = True;
-      }
-      break;
-    case NMB_WACK_OPCODE:
-      /* Check WACK response here. */
-      if (nmb->header.ancount != 1)
-      {
-        DEBUG(0,("validate_nmb_response_packet: Bad WACK Packet. "));
-        ignore = True;
-      }
-      break;
-    default:
-      DEBUG(0,("validate_nmb_response_packet: Ignoring packet with unknown opcode %d.\n",
-        nmb->header.opcode));
-      return True;
-  }
-
-  if(ignore)
-    DEBUG(0,("Ignoring response packet with opcode %d.\n", nmb->header.opcode));
-
-  return ignore;
+       BOOL ignore = False;
+
+       switch (nmb->header.opcode) {
+               case NMB_NAME_REG_OPCODE:
+               case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
+               case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
+                       if (nmb->header.ancount == 0) {
+                               DEBUG(0,("validate_nmb_response_packet: Bad REG/REFRESH Packet. "));
+                               ignore = True;
+                       }
+                       break;
+
+               case NMB_NAME_QUERY_OPCODE:
+                       if ((nmb->header.ancount != 0) && (nmb->header.ancount != 1)) {
+                               DEBUG(0,("validate_nmb_response_packet: Bad QUERY Packet. "));
+                               ignore = True;
+                       }
+                       break;
+
+               case NMB_NAME_RELEASE_OPCODE:
+                       if (nmb->header.ancount == 0) {
+                               DEBUG(0,("validate_nmb_response_packet: Bad RELEASE Packet. "));
+                               ignore = True;
+                       }
+                       break;
+
+               case NMB_WACK_OPCODE:
+                       /* Check WACK response here. */
+                       if (nmb->header.ancount != 1) {
+                               DEBUG(0,("validate_nmb_response_packet: Bad WACK Packet. "));
+                               ignore = True;
+                       }
+                       break;
+               default:
+                       DEBUG(0,("validate_nmb_response_packet: Ignoring packet with unknown opcode %d.\n",
+                                       nmb->header.opcode));
+                       return True;
+       }
+
+       if(ignore)
+               DEBUG(0,("Ignoring response packet with opcode %d.\n", nmb->header.opcode));
+
+       return ignore;
 }
  
 /****************************************************************************
@@ -1401,48 +1310,43 @@ static BOOL validate_nmb_response_packet( struct nmb_packet *nmb )
 
 static BOOL validate_nmb_packet( struct nmb_packet *nmb )
 {
-  BOOL ignore = False;
-
-  switch (nmb->header.opcode) 
-  {
-    case NMB_NAME_REG_OPCODE:
-    case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
-    case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
-    case NMB_NAME_MULTIHOMED_REG_OPCODE:
-      if (nmb->header.qdcount==0 || nmb->header.arcount==0)
-      {
-        DEBUG(0,("validate_nmb_packet: Bad REG/REFRESH Packet. "));
-        ignore = True;
-      }
-      break;
-
-    case NMB_NAME_QUERY_OPCODE:
-      if ((nmb->header.qdcount == 0) || 
-         ((nmb->question.question_type != QUESTION_TYPE_NB_QUERY) &&
-         (nmb->question.question_type != QUESTION_TYPE_NB_STATUS)))
-      {
-        DEBUG(0,("validate_nmb_packet: Bad QUERY Packet. "));
-        ignore = True;
-      }
-      break;
-
-    case NMB_NAME_RELEASE_OPCODE:
-      if (nmb->header.qdcount==0 || nmb->header.arcount==0)
-      {
-        DEBUG(0,("validate_nmb_packet: Bad RELEASE Packet. "));
-        ignore = True;
-      }
-      break;
-    default:
-      DEBUG(0,("validate_nmb_packet: Ignoring packet with unknown opcode %d.\n",
-        nmb->header.opcode));
-      return True;
-  }
-
-  if(ignore)
-    DEBUG(0,("validate_nmb_packet: Ignoring request packet with opcode %d.\n", nmb->header.opcode));
-
-  return ignore;
+       BOOL ignore = False;
+
+       switch (nmb->header.opcode) {
+               case NMB_NAME_REG_OPCODE:
+               case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
+               case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
+               case NMB_NAME_MULTIHOMED_REG_OPCODE:
+                       if (nmb->header.qdcount==0 || nmb->header.arcount==0) {
+                               DEBUG(0,("validate_nmb_packet: Bad REG/REFRESH Packet. "));
+                               ignore = True;
+                       }
+                       break;
+
+               case NMB_NAME_QUERY_OPCODE:
+                       if ((nmb->header.qdcount == 0) || ((nmb->question.question_type != QUESTION_TYPE_NB_QUERY) &&
+                                       (nmb->question.question_type != QUESTION_TYPE_NB_STATUS))) {
+                               DEBUG(0,("validate_nmb_packet: Bad QUERY Packet. "));
+                               ignore = True;
+                       }
+                       break;
+
+               case NMB_NAME_RELEASE_OPCODE:
+                       if (nmb->header.qdcount==0 || nmb->header.arcount==0) {
+                               DEBUG(0,("validate_nmb_packet: Bad RELEASE Packet. "));
+                               ignore = True;
+                       }
+                       break;
+               default:
+                       DEBUG(0,("validate_nmb_packet: Ignoring packet with unknown opcode %d.\n",
+                               nmb->header.opcode));
+                       return True;
+       }
+
+       if(ignore)
+               DEBUG(0,("validate_nmb_packet: Ignoring request packet with opcode %d.\n", nmb->header.opcode));
+
+       return ignore;
 }
 
 /****************************************************************************
@@ -1452,58 +1356,53 @@ static BOOL validate_nmb_packet( struct nmb_packet *nmb )
 static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p,
                                                          struct response_record **pprrec)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct response_record *rrec = NULL;
-  struct subnet_record *subrec = NULL;
-
-  if(pprrec != NULL)
-    *pprrec = NULL;
-
-  if(nmb->header.response)
-  {
-    /* It's a response packet. Find a record for it or it's an error. */
-
-    rrec = find_response_record( &subrec, nmb->header.name_trn_id);
-    if(rrec == NULL)
-    {
-      DEBUG(3,("find_subnet_for_nmb_packet: response record not found for response id %hu\n",
-               nmb->header.name_trn_id));
-      unexpected_packet(p);
-      return NULL;
-    }
-
-    if(subrec == NULL)
-    {
-      DEBUG(0,("find_subnet_for_nmb_packet: subnet record not found for response id %hu\n",
-               nmb->header.name_trn_id));
-      return NULL;
-    }
-
-    if(pprrec != NULL)
-      *pprrec = rrec;
-    return subrec;
-  }
-
-  /* Try and see what subnet this packet belongs to. */
-
-  /* WINS server ? */
-  if(packet_is_for_wins_server(p))
-    return wins_server_subnet;
-
-  /* If it wasn't a broadcast packet then send to the UNICAST subnet. */
-  if(nmb->header.nm_flags.bcast == False)
-    return unicast_subnet;
-
-  /* Go through all the broadcast subnets and see if the mask matches. */
-  for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
-      return subrec;
-  }
-
-  /* If none match it must have been a directed broadcast - assign
-     the remote_broadcast_subnet. */
-  return remote_broadcast_subnet;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct response_record *rrec = NULL;
+       struct subnet_record *subrec = NULL;
+
+       if(pprrec != NULL)
+               *pprrec = NULL;
+
+       if(nmb->header.response) {
+               /* It's a response packet. Find a record for it or it's an error. */
+
+               rrec = find_response_record( &subrec, nmb->header.name_trn_id);
+               if(rrec == NULL) {
+                       DEBUG(3,("find_subnet_for_nmb_packet: response record not found for response id %hu\n",
+                               nmb->header.name_trn_id));
+                       unexpected_packet(p);
+                       return NULL;
+               }
+
+               if(subrec == NULL) {
+                       DEBUG(0,("find_subnet_for_nmb_packet: subnet record not found for response id %hu\n",
+                               nmb->header.name_trn_id));
+                       return NULL;
+               }
+
+               if(pprrec != NULL)
+                       *pprrec = rrec;
+               return subrec;
+       }
+
+       /* Try and see what subnet this packet belongs to. */
+
+       /* WINS server ? */
+       if(packet_is_for_wins_server(p))
+               return wins_server_subnet;
+
+       /* If it wasn't a broadcast packet then send to the UNICAST subnet. */
+       if(nmb->header.nm_flags.bcast == False)
+               return unicast_subnet;
+
+       /* Go through all the broadcast subnets and see if the mask matches. */
+       for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+                       return subrec;
+       }
+
+       /* If none match it must have been a directed broadcast - assign the remote_broadcast_subnet. */
+       return remote_broadcast_subnet;
 }
 
 /****************************************************************************
@@ -1512,79 +1411,71 @@ static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p
 
 static void process_nmb_request(struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct subnet_record *subrec = NULL;
-
-  debug_nmb_packet(p);
-
-  /* Ensure we have a good packet. */
-  if(validate_nmb_packet(nmb))
-    return;
-
-  /* Allocate a subnet to this packet - if we cannot - fail. */
-  if((subrec = find_subnet_for_nmb_packet(p, NULL))==NULL)
-    return;
-
-  switch (nmb->header.opcode) 
-  {
-    case NMB_NAME_REG_OPCODE:
-      if(subrec == wins_server_subnet)
-        wins_process_name_registration_request(subrec, p);
-      else
-        process_name_registration_request(subrec, p);
-      break;
-
-    case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
-    case NMB_NAME_REFRESH_OPCODE_9:
-      if(subrec == wins_server_subnet)
-        wins_process_name_refresh_request(subrec, p);
-      else
-        process_name_refresh_request(subrec, p);
-      break;
-
-    case NMB_NAME_MULTIHOMED_REG_OPCODE:
-      if(subrec == wins_server_subnet)
-        wins_process_multihomed_name_registration_request(subrec, p);
-      else
-      {
-        DEBUG(0,("process_nmb_request: Multihomed registration request must be \
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct subnet_record *subrec = NULL;
+
+       debug_nmb_packet(p);
+
+       /* Ensure we have a good packet. */
+       if(validate_nmb_packet(nmb))
+               return;
+
+       /* Allocate a subnet to this packet - if we cannot - fail. */
+       if((subrec = find_subnet_for_nmb_packet(p, NULL))==NULL)
+               return;
+
+       switch (nmb->header.opcode) {
+               case NMB_NAME_REG_OPCODE:
+                       if(subrec == wins_server_subnet)
+                               wins_process_name_registration_request(subrec, p);
+                       else
+                               process_name_registration_request(subrec, p);
+                       break;
+
+               case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
+               case NMB_NAME_REFRESH_OPCODE_9:
+                       if(subrec == wins_server_subnet)
+                               wins_process_name_refresh_request(subrec, p);
+                       else
+                               process_name_refresh_request(subrec, p);
+                       break;
+
+               case NMB_NAME_MULTIHOMED_REG_OPCODE:
+                       if(subrec == wins_server_subnet) {
+                               wins_process_multihomed_name_registration_request(subrec, p);
+                       } else {
+                               DEBUG(0,("process_nmb_request: Multihomed registration request must be \
 directed at a WINS server.\n"));
-      }
-      break;
-
-    case NMB_NAME_QUERY_OPCODE:
-      switch (nmb->question.question_type)
-      {
-        case QUESTION_TYPE_NB_QUERY:
-        {
-          if(subrec == wins_server_subnet)
-            wins_process_name_query_request(subrec, p);
-          else
-            process_name_query_request(subrec, p);
-          break;
-        }
-        case QUESTION_TYPE_NB_STATUS:
-        {
-          if(subrec == wins_server_subnet)
-          {
-            DEBUG(0,("process_nmb_request: NB_STATUS request directed at WINS server is \
+                       }
+                       break;
+
+               case NMB_NAME_QUERY_OPCODE:
+                       switch (nmb->question.question_type) {
+                               case QUESTION_TYPE_NB_QUERY:
+                                       if(subrec == wins_server_subnet)
+                                               wins_process_name_query_request(subrec, p);
+                                       else
+                                               process_name_query_request(subrec, p);
+                                       break;
+                               case QUESTION_TYPE_NB_STATUS:
+                                       if(subrec == wins_server_subnet) {
+                                               DEBUG(0,("process_nmb_request: NB_STATUS request directed at WINS server is \
 not allowed.\n"));
-            break;
-          }
-          else
-            process_node_status_request(subrec, p);
-          break;
-        }
-      }
-      break;
+                                               break;
+                                       } else {
+                                               process_node_status_request(subrec, p);
+                                       }
+                                       break;
+                       }
+                       break;
       
-    case NMB_NAME_RELEASE_OPCODE:
-      if(subrec == wins_server_subnet)
-        wins_process_name_release_request(subrec, p);
-      else
-        process_name_release_request(subrec, p);
-      break;
-  }
+               case NMB_NAME_RELEASE_OPCODE:
+                       if(subrec == wins_server_subnet)
+                               wins_process_name_release_request(subrec, p);
+                       else
+                               process_name_release_request(subrec, p);
+                       break;
+       }
 }
 
 /****************************************************************************
@@ -1594,65 +1485,61 @@ not allowed.\n"));
 
 static void process_nmb_response(struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct subnet_record *subrec = NULL;
-  struct response_record *rrec = NULL;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct subnet_record *subrec = NULL;
+       struct response_record *rrec = NULL;
 
-  debug_nmb_packet(p);
+       debug_nmb_packet(p);
 
-  if(validate_nmb_response_packet(nmb))
-    return;
+       if(validate_nmb_response_packet(nmb))
+               return;
 
-  if((subrec = find_subnet_for_nmb_packet(p, &rrec))==NULL)
-    return;
+       if((subrec = find_subnet_for_nmb_packet(p, &rrec))==NULL)
+               return;
 
-  if(rrec == NULL)
-  {
-    DEBUG(0,("process_nmb_response: response packet received but no response record \
+       if(rrec == NULL) {
+               DEBUG(0,("process_nmb_response: response packet received but no response record \
 found for id = %hu. Ignoring packet.\n", nmb->header.name_trn_id));
-    return;
-  }
+               return;
+       }
 
-  /* Increment the number of responses received for this record. */
-  rrec->num_msgs++;
-  /* Ensure we don't re-send the request. */
-  rrec->repeat_count = 0;
+       /* Increment the number of responses received for this record. */
+       rrec->num_msgs++;
+       /* Ensure we don't re-send the request. */
+       rrec->repeat_count = 0;
   
-  /* Call the response received function for this packet. */
-  (*rrec->resp_fn)(subrec, rrec, p);
+       /* Call the response received function for this packet. */
+       (*rrec->resp_fn)(subrec, rrec, p);
 }
 
-
 /*******************************************************************
   Run elements off the packet queue till its empty
 ******************************************************************/
 
 void run_packet_queue(void)
 {
-  struct packet_struct *p;
-
-  while ((p = packet_queue))
-  {
-    packet_queue = p->next;
-    if (packet_queue)
-      packet_queue->prev = NULL;
-    p->next = p->prev = NULL;
-
-    switch (p->packet_type)
-    {
-      case NMB_PACKET:
-        if(p->packet.nmb.header.response)
-          process_nmb_response(p);
-        else
-          process_nmb_request(p);
-        break;
-
-      case DGRAM_PACKET:
-        process_dgram(p);
-        break;
-    }
-    free_packet(p);
-  }
+       struct packet_struct *p;
+
+       while ((p = packet_queue)) {
+               packet_queue = p->next;
+               if (packet_queue)
+                       packet_queue->prev = NULL;
+               p->next = p->prev = NULL;
+
+               switch (p->packet_type) {
+                       case NMB_PACKET:
+                               if(p->packet.nmb.header.response)
+                                       process_nmb_response(p);
+                               else
+                                       process_nmb_request(p);
+                               break;
+
+                       case DGRAM_PACKET:
+                               process_dgram(p);
+                               break;
+               }
+               free_packet(p);
+       }
 } 
 
 /*******************************************************************
@@ -1665,66 +1552,54 @@ void run_packet_queue(void)
 
 void retransmit_or_expire_response_records(time_t t)
 {
-  struct subnet_record *subrec;
+       struct subnet_record *subrec;
 
-  for (subrec = FIRST_SUBNET; subrec; 
-               subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec))
-  {
-    struct response_record *rrec, *nextrrec;
+       for (subrec = FIRST_SUBNET; subrec; subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec)) {
+               struct response_record *rrec, *nextrrec;
 
-    for (rrec = subrec->responselist; rrec; rrec = nextrrec)
-    {
-      nextrrec = rrec->next;
+               for (rrec = subrec->responselist; rrec; rrec = nextrrec) {
+                       nextrrec = rrec->next;
    
-      if (rrec->repeat_time <= t) 
-      {
-        if (rrec->repeat_count > 0)
-        {
-          /* Resend while we have a non-zero repeat_count. */
-          if(!send_packet(rrec->packet))
-          {
-            DEBUG(0,("retransmit_or_expire_response_records: Failed to resend packet id %hu \
-to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), 
-                          subrec->subnet_name));
-          }
-          rrec->repeat_time = t + rrec->repeat_interval;
-          rrec->repeat_count--;
-        }
-        else
-        {
-          DEBUG(4,("retransmit_or_expire_response_records: timeout for packet id %hu to IP %s \
-on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), 
-                 subrec->subnet_name));
-
-          /*
-           * Check the flag in this record to prevent recursion if we end
-           * up in this function again via the timeout function call.
-           */
-
-          if(!rrec->in_expiration_processing)
-          {
-
-            /*
-             * Set the recursion protection flag in this record.
-             */
-
-            rrec->in_expiration_processing = True;
-
-            /* Call the timeout function. This will deal with removing the
-               timed out packet. */
-            if(rrec->timeout_fn)
-              (*rrec->timeout_fn)(subrec, rrec);
-            else
-            {
-              /* We must remove the record ourself if there is
-                 no timeout function. */
-              remove_response_record(subrec, rrec);
-            }
-          } /* !rrec->in_expitation_processing */
-        } /* rrec->repeat_count > 0 */
-      } /* rrec->repeat_time <= t */
-    } /* end for rrec */
-  } /* end for subnet */
+                       if (rrec->repeat_time <= t) {
+                               if (rrec->repeat_count > 0) {
+                                       /* Resend while we have a non-zero repeat_count. */
+                                       if(!send_packet(rrec->packet)) {
+                                               DEBUG(0,("retransmit_or_expire_response_records: Failed to resend packet id %hu \
+to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name));
+                                       }
+                                       rrec->repeat_time = t + rrec->repeat_interval;
+                                       rrec->repeat_count--;
+                               } else {
+                                       DEBUG(4,("retransmit_or_expire_response_records: timeout for packet id %hu to IP %s \
+on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name));
+
+                                       /*
+                                        * Check the flag in this record to prevent recursion if we end
+                                        * up in this function again via the timeout function call.
+                                        */
+
+                                       if(!rrec->in_expiration_processing) {
+
+                                               /*
+                                                * Set the recursion protection flag in this record.
+                                                */
+
+                                               rrec->in_expiration_processing = True;
+
+                                               /* Call the timeout function. This will deal with removing the
+                                                               timed out packet. */
+                                               if(rrec->timeout_fn) {
+                                                       (*rrec->timeout_fn)(subrec, rrec);
+                                               } else {
+                                                       /* We must remove the record ourself if there is
+                                                                       no timeout function. */
+                                                       remove_response_record(subrec, rrec);
+                                               }
+                                       } /* !rrec->in_expitation_processing */
+                               } /* rrec->repeat_count > 0 */
+                       } /* rrec->repeat_time <= t */
+               } /* end for rrec */
+       } /* end for subnet */
 }
 
 /****************************************************************************
@@ -1734,68 +1609,63 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip),
 
 static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number)
 {
-  int *sock_array = NULL;
-  struct subnet_record *subrec = NULL;
-  int count = 0;
-  int num = 0;
-  fd_set *pset = (fd_set *)malloc(sizeof(fd_set));
-
-  if(pset == NULL)
-  {
-    DEBUG(0,("create_listen_fdset: malloc fail !\n"));
-    return True;
-  }
-
-  /* Check that we can add all the fd's we need. */
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    count++;
-
-  if((count*2) + 2 > FD_SETSIZE)
-  {
-    DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \
+       int *sock_array = NULL;
+       struct subnet_record *subrec = NULL;
+       int count = 0;
+       int num = 0;
+       fd_set *pset = (fd_set *)malloc(sizeof(fd_set));
+
+       if(pset == NULL) {
+               DEBUG(0,("create_listen_fdset: malloc fail !\n"));
+               return True;
+       }
+
+       /* Check that we can add all the fd's we need. */
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
+               count++;
+
+       if((count*2) + 2 > FD_SETSIZE) {
+               DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \
 only use %d.\n", (count*2) + 2, FD_SETSIZE));
-    return True;
-  }
-
-  if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL)
-  {
-    DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
-    return True;
-  }
-
-  FD_ZERO(pset);
-
-  /* Add in the broadcast socket on 137. */
-  FD_SET(ClientNMB,pset);
-  sock_array[num++] = ClientNMB;
-
-  /* Add in the 137 sockets on all the interfaces. */
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    FD_SET(subrec->nmb_sock,pset);
-    sock_array[num++] = subrec->nmb_sock;
-  }
-
-  /* Add in the broadcast socket on 138. */
-  FD_SET(ClientDGRAM,pset);
-  sock_array[num++] = ClientDGRAM;
-
-  /* Add in the 138 sockets on all the interfaces. */
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    FD_SET(subrec->dgram_sock,pset);
-    sock_array[num++] = subrec->dgram_sock;
-  }
-
-  *listen_number = (count*2) + 2;
-
-  SAFE_FREE(*ppset);
-  SAFE_FREE(*psock_array);
-
-  *ppset = pset;
-  *psock_array = sock_array;
+               return True;
+       }
+
+       if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) {
+               DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
+               return True;
+       }
+
+       FD_ZERO(pset);
+
+       /* Add in the broadcast socket on 137. */
+       FD_SET(ClientNMB,pset);
+       sock_array[num++] = ClientNMB;
+
+       /* Add in the 137 sockets on all the interfaces. */
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               FD_SET(subrec->nmb_sock,pset);
+               sock_array[num++] = subrec->nmb_sock;
+       }
+
+       /* Add in the broadcast socket on 138. */
+       FD_SET(ClientDGRAM,pset);
+       sock_array[num++] = ClientDGRAM;
+
+       /* Add in the 138 sockets on all the interfaces. */
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               FD_SET(subrec->dgram_sock,pset);
+               sock_array[num++] = subrec->dgram_sock;
+       }
+
+       *listen_number = (count*2) + 2;
+
+       SAFE_FREE(*ppset);
+       SAFE_FREE(*psock_array);
+
+       *ppset = pset;
+       *psock_array = sock_array;
  
-  return False;
+       return False;
 }
 
 /****************************************************************************
@@ -1805,214 +1675,211 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE));
 
 BOOL listen_for_packets(BOOL run_election)
 {
-  static fd_set *listen_set = NULL;
-  static int listen_number = 0;
-  static int *sock_array = NULL;
-  int i;
-
-  fd_set fds;
-  int selrtn;
-  struct timeval timeout;
+       static fd_set *listen_set = NULL;
+       static int listen_number = 0;
+       static int *sock_array = NULL;
+       int i;
+
+       fd_set fds;
+       int selrtn;
+       struct timeval timeout;
 #ifndef SYNC_DNS
-  int dns_fd;
+       int dns_fd;
 #endif
 
-  if(listen_set == NULL || rescan_listen_set)
-  {
-    if(create_listen_fdset(&listen_set, &sock_array, &listen_number))
-    {
-      DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n"));
-      return True;
-    }
-    rescan_listen_set = False;
-  }
+       if(listen_set == NULL || rescan_listen_set) {
+               if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) {
+                       DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n"));
+                       return True;
+               }
+               rescan_listen_set = False;
+       }
 
-  memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set));
+       memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set));
 
 #ifndef SYNC_DNS
-  dns_fd = asyncdns_fd();
-  if (dns_fd != -1) {
-         FD_SET(dns_fd, &fds);
-  }
+       dns_fd = asyncdns_fd();
+       if (dns_fd != -1) {
+               FD_SET(dns_fd, &fds);
+       }
 #endif
 
+       /* 
+        * During elections and when expecting a netbios response packet we
+        * need to send election packets at tighter intervals.
+        * Ideally it needs to be the interval (in ms) between time now and
+        * the time we are expecting the next netbios packet.
+        */
 
-  /* 
-   * During elections and when expecting a netbios response packet we
-   * need to send election packets at tighter intervals.
-   * Ideally it needs to be the interval (in ms) between time now and
-   * the time we are expecting the next netbios packet.
-   */
-
-  timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP;
-  timeout.tv_usec = 0;
+       timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP;
+       timeout.tv_usec = 0;
 
-  /* Prepare for the select - allow certain signals. */
+       /* Prepare for the select - allow certain signals. */
 
-  BlockSignals(False, SIGTERM);
+       BlockSignals(False, SIGTERM);
 
-  selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout);
+       selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout);
 
-  /* We can only take signals when we are in the select - block them again here. */
+       /* We can only take signals when we are in the select - block them again here. */
 
-  BlockSignals(True, SIGTERM);
+       BlockSignals(True, SIGTERM);
 
-  if(selrtn == -1) {
-         return False;
-  }
+       if(selrtn == -1) {
+               return False;
+       }
 
 #ifndef SYNC_DNS
-  if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) {
-         run_dns_queue();
-  }
+       if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) {
+               run_dns_queue();
+       }
 #endif
 
-  for(i = 0; i < listen_number; i++) {
-         if (i < (listen_number/2)) {
-                 /* Processing a 137 socket. */
-                 if (FD_ISSET(sock_array[i],&fds)) {
-                         struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET);
-                         if (packet) {
-                                 /*
-                                  * If we got a packet on the broadcast socket and interfaces
-                                  * only is set then check it came from one of our local nets. 
-                                  */
-                                 if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && 
-                                    (!is_local_net(packet->ip))) {
-                                         DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n",
-                                                  inet_ntoa(packet->ip),packet->port));          
-                                         free_packet(packet);
-                                 } else if ((ip_equal(loopback_ip, packet->ip) || 
-                                             ismyip(packet->ip)) && packet->port == global_nmb_port &&
-                                            packet->packet.nmb.header.nm_flags.bcast) {
-                                         DEBUG(7,("discarding own bcast packet from %s:%d\n",
-                                                  inet_ntoa(packet->ip),packet->port));          
-                                         free_packet(packet);
-                                 } else {
-                                         /* Save the file descriptor this packet came in on. */
-                                         packet->fd = sock_array[i];
-                                         queue_packet(packet);
-                                 }
-                         }
-                 }
-         } else {
-                 /* Processing a 138 socket. */
-                 if (FD_ISSET(sock_array[i],&fds)) {
-                         struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET);
-                         if (packet) {
-                                 /*
-                                  * If we got a packet on the broadcast socket and interfaces
-                                  * only is set then check it came from one of our local nets. 
-                                  */
-                                 if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && 
-                                    (!is_local_net(packet->ip))) {
-                                         DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n",
-                                                  inet_ntoa(packet->ip),packet->port));          
-                                         free_packet(packet);
-                                 } else if ((ip_equal(loopback_ip, packet->ip) || 
-                                             ismyip(packet->ip)) && packet->port == DGRAM_PORT) {
-                                         DEBUG(7,("discarding own dgram packet from %s:%d\n",
-                                                  inet_ntoa(packet->ip),packet->port));          
-                                         free_packet(packet);
-                                 } else {
-                                         /* Save the file descriptor this packet came in on. */
-                                         packet->fd = sock_array[i];
-                                         queue_packet(packet);
-                                 }
-                         }
-                 }
-         } /* end processing 138 socket. */
-  } /* end for */
-  return False;
+       for(i = 0; i < listen_number; i++) {
+               if (i < (listen_number/2)) {
+                       /* Processing a 137 socket. */
+                       if (FD_ISSET(sock_array[i],&fds)) {
+                               struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET);
+                               if (packet) {
+                                       /*
+                                        * If we got a packet on the broadcast socket and interfaces
+                                        * only is set then check it came from one of our local nets. 
+                                        */
+                                       if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && 
+                                                               (!is_local_net(packet->ip))) {
+                                               DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n",
+                                                       inet_ntoa(packet->ip),packet->port));     
+                                               free_packet(packet);
+                                       } else if ((ip_equal(loopback_ip, packet->ip) || 
+                                                               ismyip(packet->ip)) && packet->port == global_nmb_port &&
+                                                               packet->packet.nmb.header.nm_flags.bcast) {
+                                               DEBUG(7,("discarding own bcast packet from %s:%d\n",
+                                                       inet_ntoa(packet->ip),packet->port));     
+                                               free_packet(packet);
+                                       } else {
+                                               /* Save the file descriptor this packet came in on. */
+                                               packet->fd = sock_array[i];
+                                               queue_packet(packet);
+                                       }
+                               }
+                       }
+               } else {
+                       /* Processing a 138 socket. */
+                               if (FD_ISSET(sock_array[i],&fds)) {
+                               struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET);
+                               if (packet) {
+                                       /*
+                                        * If we got a packet on the broadcast socket and interfaces
+                                        * only is set then check it came from one of our local nets. 
+                                        */
+                                       if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && 
+                                                               (!is_local_net(packet->ip))) {
+                                               DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n",
+                                               inet_ntoa(packet->ip),packet->port));     
+                                               free_packet(packet);
+                                       } else if ((ip_equal(loopback_ip, packet->ip) || 
+                                                       ismyip(packet->ip)) && packet->port == DGRAM_PORT) {
+                                               DEBUG(7,("discarding own dgram packet from %s:%d\n",
+                                                       inet_ntoa(packet->ip),packet->port));     
+                                               free_packet(packet);
+                                       } else {
+                                               /* Save the file descriptor this packet came in on. */
+                                               packet->fd = sock_array[i];
+                                               queue_packet(packet);
+                                       }
+                               }
+                       }
+               } /* end processing 138 socket. */
+       } /* end for */
+       return False;
 }
 
 /****************************************************************************
   Construct and send a netbios DGRAM.
 **************************************************************************/
+
 BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len,
                    const char *srcname, int src_type,
                    const char *dstname, int dest_type,
                    struct in_addr dest_ip,struct in_addr src_ip,
                   int dest_port)
 {
-  BOOL loopback_this_packet = False;
-  struct packet_struct p;
-  struct dgram_packet *dgram = &p.packet.dgram;
-  char *ptr,*p2;
-  char tmp[4];
-
-  memset((char *)&p,'\0',sizeof(p));
-
-  if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */
-    loopback_this_packet = True;
-
-  /* generate_name_trn_id(); */ /* Not used, so gone, RJS */
-
-  /* DIRECT GROUP or UNIQUE datagram. */
-  dgram->header.msg_type = unique ? 0x10 : 0x11; 
-  dgram->header.flags.node_type = M_NODE;
-  dgram->header.flags.first = True;
-  dgram->header.flags.more = False;
-  dgram->header.dgm_id = generate_name_trn_id();
-  dgram->header.source_ip = src_ip;
-  dgram->header.source_port = DGRAM_PORT;
-  dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */
-  dgram->header.packet_offset = 0;
+       BOOL loopback_this_packet = False;
+       struct packet_struct p;
+       struct dgram_packet *dgram = &p.packet.dgram;
+       char *ptr,*p2;
+       char tmp[4];
+
+       memset((char *)&p,'\0',sizeof(p));
+
+       if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */
+               loopback_this_packet = True;
+
+       /* generate_name_trn_id(); */ /* Not used, so gone, RJS */
+
+       /* DIRECT GROUP or UNIQUE datagram. */
+       dgram->header.msg_type = unique ? 0x10 : 0x11; 
+       dgram->header.flags.node_type = M_NODE;
+       dgram->header.flags.first = True;
+       dgram->header.flags.more = False;
+       dgram->header.dgm_id = generate_name_trn_id();
+       dgram->header.source_ip = src_ip;
+       dgram->header.source_port = DGRAM_PORT;
+       dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */
+       dgram->header.packet_offset = 0;
   
-  make_nmb_name(&dgram->source_name,srcname,src_type);
-  make_nmb_name(&dgram->dest_name,dstname,dest_type);
-
-  ptr = &dgram->data[0];
-
-  /* Setup the smb part. */
-  ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */
-  memcpy(tmp,ptr,4);
-  set_message(ptr,17,23 + len,True);
-  memcpy(ptr,tmp,4);
-
-  SCVAL(ptr,smb_com,SMBtrans);
-  SSVAL(ptr,smb_vwv1,len);
-  SSVAL(ptr,smb_vwv11,len);
-  SSVAL(ptr,smb_vwv12,70 + strlen(mailslot));
-  SSVAL(ptr,smb_vwv13,3);
-  SSVAL(ptr,smb_vwv14,1);
-  SSVAL(ptr,smb_vwv15,1);
-  SSVAL(ptr,smb_vwv16,2);
-  p2 = smb_buf(ptr);
-  safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data));
-  p2 = skip_string(p2,1);
+       make_nmb_name(&dgram->source_name,srcname,src_type);
+       make_nmb_name(&dgram->dest_name,dstname,dest_type);
+
+       ptr = &dgram->data[0];
+
+       /* Setup the smb part. */
+       ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */
+       memcpy(tmp,ptr,4);
+       set_message(ptr,17,23 + len,True);
+       memcpy(ptr,tmp,4);
+
+       SCVAL(ptr,smb_com,SMBtrans);
+       SSVAL(ptr,smb_vwv1,len);
+       SSVAL(ptr,smb_vwv11,len);
+       SSVAL(ptr,smb_vwv12,70 + strlen(mailslot));
+       SSVAL(ptr,smb_vwv13,3);
+       SSVAL(ptr,smb_vwv14,1);
+       SSVAL(ptr,smb_vwv15,1);
+       SSVAL(ptr,smb_vwv16,2);
+       p2 = smb_buf(ptr);
+       safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data));
+       p2 = skip_string(p2,1);
   
-  if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) {
-         DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n"));
-         return False;
-  } else {
-         memcpy(p2,buf,len);
-         p2 += len;
-  }
-
-  dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */
-
-  p.ip = dest_ip;
-  p.port = dest_port;
-  p.fd = find_subnet_mailslot_fd_for_address( src_ip );
-  p.timestamp = time(NULL);
-  p.packet_type = DGRAM_PACKET;
-
-  DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot,
-                    nmb_namestr(&dgram->source_name), inet_ntoa(src_ip)));
-  DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip)));
-
-  debug_browse_data(buf, len);
-
-  if(loopback_this_packet)
-  {
-    struct packet_struct *lo_packet = NULL;
-    DEBUG(5,("send_mailslot: sending packet to ourselves.\n"));
-    if((lo_packet = copy_packet(&p)) == NULL)
-      return False;
-    queue_packet(lo_packet);
-    return True;
-  }
-  else
-    return(send_packet(&p));
+       if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) {
+               DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n"));
+               return False;
+       } else {
+               memcpy(p2,buf,len);
+               p2 += len;
+       }
+
+       dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */
+
+       p.ip = dest_ip;
+       p.port = dest_port;
+       p.fd = find_subnet_mailslot_fd_for_address( src_ip );
+       p.timestamp = time(NULL);
+       p.packet_type = DGRAM_PACKET;
+
+       DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot,
+                       nmb_namestr(&dgram->source_name), inet_ntoa(src_ip)));
+       DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip)));
+
+       debug_browse_data(buf, len);
+
+       if(loopback_this_packet) {
+               struct packet_struct *lo_packet = NULL;
+               DEBUG(5,("send_mailslot: sending packet to ourselves.\n"));
+               if((lo_packet = copy_packet(&p)) == NULL)
+                       return False;
+               queue_packet(lo_packet);
+               return True;
+       } else {
+               return(send_packet(&p));
+       }
 }
index bc3540af70e1b2bb735aee7c9f81532e0d957bb0..2a6a6b66d1f511499d117dbd6cfdb190c713b455 100644 (file)
@@ -3,7 +3,7 @@
    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
    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
    
    This program is free software; you can redistribute it and/or modify
@@ -35,6 +35,7 @@ struct sam_database_info {
 /****************************************************************************
 Send a message to smbd to do a sam delta sync
 **************************************************************************/
+
 static void send_repl_message(uint32 low_serial)
 {
         TDB_CONTEXT *tdb;
@@ -64,432 +65,452 @@ Process a domain logon packet
 void process_logon_packet(struct packet_struct *p, char *buf,int len, 
                           const char *mailslot)
 {
-  struct dgram_packet *dgram = &p->packet.dgram;
-  pstring my_name;
-  fstring reply_name;
-  pstring outbuf;
-  int code;
-  uint16 token = 0;
-  uint32 ntversion = 0;
-  uint16 lmnttoken = 0;
-  uint16 lm20token = 0;
-  uint32 domainsidsize;
-  BOOL short_request = False;
-  char *getdc;
-  char *uniuser; /* Unicode user name. */
-  pstring ascuser;
-  char *unicomp; /* Unicode computer name. */
-
-  memset(outbuf, 0, sizeof(outbuf));
-
-  if (!lp_domain_logons())
-  {
-    DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \
+       struct dgram_packet *dgram = &p->packet.dgram;
+       pstring my_name;
+       fstring reply_name;
+       pstring outbuf;
+       int code;
+       uint16 token = 0;
+       uint32 ntversion = 0;
+       uint16 lmnttoken = 0;
+       uint16 lm20token = 0;
+       uint32 domainsidsize;
+       BOOL short_request = False;
+       char *getdc;
+       char *uniuser; /* Unicode user name. */
+       pstring ascuser;
+       char *unicomp; /* Unicode computer name. */
+
+       memset(outbuf, 0, sizeof(outbuf));
+
+       if (!lp_domain_logons()) {
+               DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \
 logons are not enabled.\n", inet_ntoa(p->ip) ));
-    return;
-  }
-
-  pstrcpy(my_name, global_myname());
-
-  code = SVAL(buf,0);
-  DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code));
-
-  switch (code)
-  {
-    case 0:    
-    {
-      char *q = buf + 2;
-      char *machine = q;
-      char *user = skip_string(machine,1);
-
-      getdc = skip_string(user,1);
-      q = skip_string(getdc,1);
-      token = SVAL(q,3);
-
-      fstrcpy(reply_name,my_name); 
-
-      DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
-             machine,inet_ntoa(p->ip),user,token));
-
-      q = outbuf;
-      SSVAL(q, 0, 6);
-      q += 2;
-
-      fstrcpy(reply_name, "\\\\");
-      fstrcat(reply_name, my_name);
-      fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
-
-      SSVAL(q, 0, token);
-      q += 2;
-
-      dump_data(4, outbuf, PTR_DIFF(q, outbuf));
-
-      send_mailslot(True, getdc, 
-                    outbuf,PTR_DIFF(q,outbuf),
-                   global_myname(), 0x0,
-                                       machine,
-                    dgram->source_name.name_type,
-                    p->ip, *iface_ip(p->ip), p->port);  
-      break;
-    }
-
-    case QUERYFORPDC:
-    {
-      char *q = buf + 2;
-      char *machine = q;
-
-      if (!lp_domain_master())
-      {  
-         /* We're not Primary Domain Controller -- ignore this */
-         return;
-      }
-
-      getdc = skip_string(machine,1);
-      q = skip_string(getdc,1);
-      q = ALIGN2(q, buf);
-
-      /* at this point we can work out if this is a W9X or NT style
-         request. Experiments show that the difference is wether the
-         packet ends here. For a W9X request we now end with a pair of
-         bytes (usually 0xFE 0xFF) whereas with NT we have two further
-         strings - the following is a simple way of detecting this */
-      if (len - PTR_DIFF(q, buf) <= 3) {
-             short_request = True;
-      } else {
-             unicomp = q;
-
-             /* A full length (NT style) request */
-             q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp));
-
-             if (len - PTR_DIFF(q, buf) > 8) {
+               return;
+       }
+
+       pstrcpy(my_name, global_myname());
+
+       code = SVAL(buf,0);
+       DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code));
+
+       switch (code) {
+               case 0:    
+                       {
+                               fstring mach_str, user_str, getdc_str;
+                               char *q = buf + 2;
+                               char *machine = q;
+                               char *user = skip_string(machine,1);
+
+                               getdc = skip_string(user,1);
+                               q = skip_string(getdc,1);
+                               token = SVAL(q,3);
+
+                               fstrcpy(reply_name,my_name); 
+
+                               pull_ascii_fstring(mach_str, machine);
+                               pull_ascii_fstring(user_str, user);
+                               pull_ascii_fstring(getdc_str, getdc);
+
+                               DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
+                                       mach_str,inet_ntoa(p->ip),user_str,token));
+
+                               q = outbuf;
+                               SSVAL(q, 0, 6);
+                               q += 2;
+
+                               fstrcpy(reply_name, "\\\\");
+                               fstrcat(reply_name, my_name);
+                               push_ascii_fstring(q, reply_name);
+                               q = skip_string(q, 1); /* PDC name */
+
+                               SSVAL(q, 0, token);
+                               q += 2;
+
+                               dump_data(4, outbuf, PTR_DIFF(q, outbuf));
+
+                               send_mailslot(True, getdc_str, 
+                                               outbuf,PTR_DIFF(q,outbuf),
+                                               global_myname(), 0x0,
+                                               mach_str,
+                                               dgram->source_name.name_type,
+                                               p->ip, *iface_ip(p->ip), p->port);  
+                               break;
+                       }
+
+               case QUERYFORPDC:
+                       {
+                               fstring mach_str, getdc_str;
+                               nstring source_name;
+                               char *q = buf + 2;
+                               char *machine = q;
+
+                               if (!lp_domain_master()) {  
+                                       /* We're not Primary Domain Controller -- ignore this */
+                                       return;
+                               }
+
+                               getdc = skip_string(machine,1);
+                               q = skip_string(getdc,1);
+                               q = ALIGN2(q, buf);
+
+                               /* At this point we can work out if this is a W9X or NT style
+                                  request. Experiments show that the difference is wether the
+                                  packet ends here. For a W9X request we now end with a pair of
+                                  bytes (usually 0xFE 0xFF) whereas with NT we have two further
+                                  strings - the following is a simple way of detecting this */
+
+                               if (len - PTR_DIFF(q, buf) <= 3) {
+                                       short_request = True;
+                               } else {
+                                       unicomp = q;
+
+                                       /* A full length (NT style) request */
+                                       q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp));
+
+                                       if (len - PTR_DIFF(q, buf) > 8) {
+                                               /* with NT5 clients we can sometimes
+                                                       get additional data - a length specificed string
+                                                       containing the domain name, then 16 bytes of
+                                                       data (no idea what it is) */
+                                               int dom_len = CVAL(q, 0);
+                                               q++;
+                                               if (dom_len != 0) {
+                                                       q += dom_len + 1;
+                                               }
+                                               q += 16;
+                                       }
+                                       ntversion = IVAL(q, 0);
+                                       lmnttoken = SVAL(q, 4);
+                                       lm20token = SVAL(q, 6);
+                               }
+
+                               /* Construct reply. */
+                               q = outbuf;
+                               SSVAL(q, 0, QUERYFORPDC_R);
+                               q += 2;
+
+                               fstrcpy(reply_name,my_name);
+                               push_ascii_fstring(q, reply_name);
+                               q = skip_string(q, 1); /* PDC name */
+
+                               /* PDC and domain name */
+                               if (!short_request) {
+                                       /* Make a full reply */
+                                       q = ALIGN2(q, outbuf);
+
+                                       q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */
+                                       q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/
+                                       SIVAL(q, 0, 1); /* our nt version */
+                                       SSVAL(q, 4, 0xffff); /* our lmnttoken */
+                                       SSVAL(q, 6, 0xffff); /* our lm20token */
+                                       q += 8;
+                               }
+
+                               /* RJS, 21-Feb-2000, we send a short reply if the request was short */
+
+                               pull_ascii_fstring(mach_str, machine);
+
+                               DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \
+reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
+                                       mach_str,inet_ntoa(p->ip), reply_name, lp_workgroup(),
+                                       QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
+                                       (uint32)lm20token ));
+
+                               dump_data(4, outbuf, PTR_DIFF(q, outbuf));
+
+                               pull_ascii_fstring(getdc_str, getdc);
+                               pull_ascii_nstring(source_name, dgram->source_name.name);
+
+                               send_mailslot(True, getdc_str,
+                                       outbuf,PTR_DIFF(q,outbuf),
+                                       global_myname(), 0x0,
+                                       source_name,
+                                       dgram->source_name.name_type,
+                                       p->ip, *iface_ip(p->ip), p->port);  
+                               return;
+                       }
+
+               case SAMLOGON:
+
+                       {
+                               fstring getdc_str;
+                               nstring source_name;
+                               char *q = buf + 2;
+                               fstring asccomp;
+
+                               q += 2;
+                               unicomp = q;
+                               uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp));
+                               getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser));
+                               q = skip_string(getdc,1);
+                               q += 4; /* Account Control Bits - indicating username type */
+                               domainsidsize = IVAL(q, 0);
+                               q += 4;
+
+                               DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len));
+
+                               if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) {
+                                       q += domainsidsize;
+                                       q = ALIGN4(q, buf);
+                               }
+
+                               DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) ));
+
+                               if (len - PTR_DIFF(q, buf) > 8) {
                                        /* with NT5 clients we can sometimes
-                                          get additional data - a length specificed string
-                                          containing the domain name, then 16 bytes of
-                                          data (no idea what it is) */
+                                               get additional data - a length specificed string
+                                               containing the domain name, then 16 bytes of
+                                               data (no idea what it is) */
                                        int dom_len = CVAL(q, 0);
                                        q++;
-                                       if (dom_len != 0) {
+                                       if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) {
                                                q += dom_len + 1;
                                        }
                                        q += 16;
-             }
-             ntversion = IVAL(q, 0);
-             lmnttoken = SVAL(q, 4);
-             lm20token = SVAL(q, 6);
-      }
-
-      /* Construct reply. */
-      q = outbuf;
-      SSVAL(q, 0, QUERYFORPDC_R);
-      q += 2;
-
-      fstrcpy(reply_name,my_name);
-      fstrcpy(q, reply_name);
-      q = skip_string(q, 1); /* PDC name */
-
-      /* PDC and domain name */
-      if (!short_request)  /* Make a full reply */
-      {
-        q = ALIGN2(q, outbuf);
-
-        q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */
-        q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/
-        SIVAL(q, 0, 1); /* our nt version */
-        SSVAL(q, 4, 0xffff); /* our lmnttoken */
-        SSVAL(q, 6, 0xffff); /* our lm20token */
-        q += 8;
-      }
-
-      /* RJS, 21-Feb-2000, we send a short reply if the request was short */
-
-      DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \
-reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
-            machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
-            QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
-            (uint32)lm20token ));
-
-      dump_data(4, outbuf, PTR_DIFF(q, outbuf));
-
-      send_mailslot(True, getdc,
-                  outbuf,PTR_DIFF(q,outbuf),
-                   global_myname(), 0x0,
-                  dgram->source_name.name,
-                  dgram->source_name.name_type,
-                  p->ip, *iface_ip(p->ip), p->port);  
-      return;
-    }
-
-    case SAMLOGON:
-    {
-      char *q = buf + 2;
-      fstring asccomp;
-
-      q += 2;
-      unicomp = q;
-      uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp));
-      getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser));
-      q = skip_string(getdc,1);
-      q += 4; /* Account Control Bits - indicating username type */
-      domainsidsize = IVAL(q, 0);
-      q += 4;
-
-      DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len));
-
-      if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) {
-             q += domainsidsize;
-             q = ALIGN4(q, buf);
-      }
-
-      DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) ));
-
-      if (len - PTR_DIFF(q, buf) > 8) {
-             /* with NT5 clients we can sometimes
-                get additional data - a length specificed string
-                containing the domain name, then 16 bytes of
-                data (no idea what it is) */
-             int dom_len = CVAL(q, 0);
-             q++;
-             if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) {
-                     q += dom_len + 1;
-             }
-             q += 16;
-      }
-
-      ntversion = IVAL(q, 0);
-      lmnttoken = SVAL(q, 4);
-      lm20token = SVAL(q, 6);
-      q += 8;
-
-      DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
-
-      /*
-       * we respond regadless of whether the machine is in our password 
-       * database. If it isn't then we let smbd send an appropriate error.
-       * Let's ignore the SID.
-       */
-      pull_ucs2_pstring(ascuser, uniuser);
-      pull_ucs2_fstring(asccomp, unicomp);
-      DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser));
-
-      fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */
-      fstrcat(reply_name, my_name);
-
-      DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
-              asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(),
-              SAMLOGON_R ,lmnttoken));
-
-      /* Construct reply. */
-
-      q = outbuf;
-      /* we want the simple version unless we are an ADS PDC..which means  */
-      /* never, at least for now */
-      if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) {
-       if (SVAL(uniuser, 0) == 0) {
-         SSVAL(q, 0, SAMLOGON_UNK_R);  /* user unknown */
-       } else {
-         SSVAL(q, 0, SAMLOGON_R);
-       }
+                               }
+
+                               ntversion = IVAL(q, 0);
+                               lmnttoken = SVAL(q, 4);
+                               lm20token = SVAL(q, 6);
+                               q += 8;
+
+                               DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
+
+                               /*
+                                * we respond regadless of whether the machine is in our password 
+                                * database. If it isn't then we let smbd send an appropriate error.
+                                * Let's ignore the SID.
+                                */
+                               pull_ucs2_pstring(ascuser, uniuser);
+                               pull_ucs2_fstring(asccomp, unicomp);
+                               DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser));
+
+                               fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */
+                               fstrcat(reply_name, my_name);
+
+                               DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
+                                       asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(),
+                               SAMLOGON_R ,lmnttoken));
+
+                               /* Construct reply. */
+
+                               q = outbuf;
+                               /* we want the simple version unless we are an ADS PDC..which means  */
+                               /* never, at least for now */
+                               if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) {
+                                       if (SVAL(uniuser, 0) == 0) {
+                                               SSVAL(q, 0, SAMLOGON_UNK_R);    /* user unknown */
+                                       } else {
+                                               SSVAL(q, 0, SAMLOGON_R);
+                                       }
 
-       q += 2;
+                                       q += 2;
 
-       q += dos_PutUniCode(q, reply_name,sizeof(pstring), True);
-       q += dos_PutUniCode(q, ascuser, sizeof(pstring), True);
-       q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True);
-      } 
+                                       q += dos_PutUniCode(q, reply_name,sizeof(pstring), True);
+                                       q += dos_PutUniCode(q, ascuser, sizeof(pstring), True);
+                                       q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True);
+                               }
 #ifdef HAVE_ADS
-      else {
-       GUID domain_guid;
-       pstring domain;
-       pstring hostname;
-       char *component, *dc, *q1;
-       uint8 size;
-       char *q_orig = q;
-       int str_offset;
-
-       get_mydomname(domain);
-       get_myname(hostname);
+                               else {
+                                       GUID domain_guid;
+                                       pstring domain;
+                                       pstring hostname;
+                                       char *component, *dc, *q1;
+                                       uint8 size;
+                                       char *q_orig = q;
+                                       int str_offset;
+
+                                       get_mydomname(domain);
+                                       get_myname(hostname);
        
-       if (SVAL(uniuser, 0) == 0) {
-         SIVAL(q, 0, SAMLOGON_AD_UNK_R);       /* user unknown */
-       } else {
-         SIVAL(q, 0, SAMLOGON_AD_R);
-       }
-       q += 4;
+                                       if (SVAL(uniuser, 0) == 0) {
+                                               SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */
+                                       } else {
+                                               SIVAL(q, 0, SAMLOGON_AD_R);
+                                       }
+                                       q += 4;
 
-       SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS|
-                   ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE);
-       q += 4;
+                                       SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS|
+                                               ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE);
+                                       q += 4;
 
-       /* Push Domain GUID */
-       if (False == secrets_fetch_domain_guid(domain, &domain_guid)) {
-         DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain));
-         return;
-       }
-       memcpy(q, &domain_guid, sizeof(domain_guid));
-       q += sizeof(domain_guid);
-
-       /* Forest */
-       str_offset = q - q_orig;
-       dc = domain;
-       q1 = q;
-       while ((component = strtok(dc, "."))) {
-         dc = NULL;
-         size = push_ascii(&q[1], component, -1, 0);
-         SCVAL(q, 0, size);
-         q += (size + 1);
-       }
+                                       /* Push Domain GUID */
+                                       if (False == secrets_fetch_domain_guid(domain, &domain_guid)) {
+                                               DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain));
+                                               return;
+                                       }
+                                       memcpy(q, &domain_guid, sizeof(domain_guid));
+                                       q += sizeof(domain_guid);
+
+                                       /* Forest */
+                                       str_offset = q - q_orig;
+                                       dc = domain;
+                                       q1 = q;
+                                       while ((component = strtok(dc, "."))) {
+                                               dc = NULL;
+                                               size = push_ascii(&q[1], component, -1, 0);
+                                               SCVAL(q, 0, size);
+                                               q += (size + 1);
+                                       }
 
-       /* Unk0 */
-       SCVAL(q, 0, 0); q++;
-
-       /* Domain */
-       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
-       SCVAL(q, 1, str_offset & 0xFF);
-       q += 2;
-
-       /* Hostname */
-       size = push_ascii(&q[1], hostname, -1, 0);
-       SCVAL(q, 0, size);
-       q += (size + 1);
-       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
-       SCVAL(q, 1, str_offset & 0xFF);
-       q += 2;
-
-       /* NETBIOS of domain */
-       size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER);
-       SCVAL(q, 0, size);
-       q += (size + 1);
-
-       /* Unk1 */
-       SCVAL(q, 0, 0); q++;
-
-       /* NETBIOS of hostname */
-       size = push_ascii(&q[1], my_name, -1, 0);
-       SCVAL(q, 0, size);
-       q += (size + 1);
-
-       /* Unk2 */
-       SCVAL(q, 0, 0); q++;
-
-       /* User name */
-       if (SVAL(uniuser, 0) != 0) {
-               size = push_ascii(&q[1], ascuser, -1, 0);
-               SCVAL(q, 0, size);
-               q += (size + 1);
-       }
+                                       /* Unk0 */
+                                       SCVAL(q, 0, 0);
+                                       q++;
 
-       q_orig = q;
-       /* Site name */
-       size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0);
-       SCVAL(q, 0, size);
-       q += (size + 1);
-
-       /* Site name (2) */
-       str_offset = q - q_orig;
-       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
-       SCVAL(q, 1, str_offset & 0xFF);
-       q += 2;
-
-       SCVAL(q, 0, PTR_DIFF(q,q1));
-       SCVAL(q, 1, 0x10); /* unknown */
-
-       SIVAL(q, 0, 0x00000002); q += 4; /* unknown */
-       SIVAL(q, 0, (iface_ip(p->ip))->s_addr); q += 4;
-       SIVAL(q, 0, 0x00000000); q += 4; /* unknown */
-       SIVAL(q, 0, 0x00000000); q += 4; /* unknown */
-      }        
+                                       /* Domain */
+                                       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
+                                       SCVAL(q, 1, str_offset & 0xFF);
+                                       q += 2;
+
+                                       /* Hostname */
+                                       size = push_ascii(&q[1], hostname, -1, 0);
+                                       SCVAL(q, 0, size);
+                                       q += (size + 1);
+                                       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
+                                       SCVAL(q, 1, str_offset & 0xFF);
+                                       q += 2;
+
+                                       /* NETBIOS of domain */
+                                       size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER);
+                                       SCVAL(q, 0, size);
+                                       q += (size + 1);
+
+                                       /* Unk1 */
+                                       SCVAL(q, 0, 0);
+                                       q++;
+
+                                       /* NETBIOS of hostname */
+                                       size = push_ascii(&q[1], my_name, -1, 0);
+                                       SCVAL(q, 0, size);
+                                       q += (size + 1);
+
+                                       /* Unk2 */
+                                       SCVAL(q, 0, 0);
+                                       q++;
+
+                                       /* User name */
+                                       if (SVAL(uniuser, 0) != 0) {
+                                               size = push_ascii(&q[1], ascuser, -1, 0);
+                                               SCVAL(q, 0, size);
+                                               q += (size + 1);
+                                       }
+
+                                       q_orig = q;
+                                       /* Site name */
+                                       size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0);
+                                       SCVAL(q, 0, size);
+                                       q += (size + 1);
+
+                                       /* Site name (2) */
+                                       str_offset = q - q_orig;
+                                       SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
+                                       SCVAL(q, 1, str_offset & 0xFF);
+                                       q += 2;
+
+                                       SCVAL(q, 0, PTR_DIFF(q,q1));
+                                       SCVAL(q, 1, 0x10); /* unknown */
+
+                                       SIVAL(q, 0, 0x00000002);
+                                       q += 4; /* unknown */
+                                       SIVAL(q, 0, (iface_ip(p->ip))->s_addr);
+                                       q += 4;
+                                       SIVAL(q, 0, 0x00000000);
+                                       q += 4; /* unknown */
+                                       SIVAL(q, 0, 0x00000000);
+                                       q += 4; /* unknown */
+                               }       
 #endif
 
-      /* tell the client what version we are */
-      SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); 
-      /* our ntversion */
-      SSVAL(q, 4, 0xffff); /* our lmnttoken */ 
-      SSVAL(q, 6, 0xffff); /* our lm20token */
-      q += 8;
-
-      dump_data(4, outbuf, PTR_DIFF(q, outbuf));
-
-      send_mailslot(True, getdc,
-                   outbuf,PTR_DIFF(q,outbuf),
-                   global_myname(), 0x0,
-                   dgram->source_name.name,
-                   dgram->source_name.name_type,
-                   p->ip, *iface_ip(p->ip), p->port);  
-      break;
-    }
-
-    /* Announce change to UAS or SAM.  Send by the domain controller when a
-       replication event is required. */
-
-  case SAM_UAS_CHANGE: {
-          struct sam_database_info *db_info;
-          char *q = buf + 2;
-          int i, db_count;
-          uint32 low_serial;
+                               /* tell the client what version we are */
+                               SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); 
+                               /* our ntversion */
+                               SSVAL(q, 4, 0xffff); /* our lmnttoken */ 
+                               SSVAL(q, 6, 0xffff); /* our lm20token */
+                               q += 8;
+
+                               dump_data(4, outbuf, PTR_DIFF(q, outbuf));
+
+                               pull_ascii_fstring(getdc_str, getdc);
+                               pull_ascii_nstring(source_name, dgram->source_name.name);
+
+                               send_mailslot(True, getdc,
+                                       outbuf,PTR_DIFF(q,outbuf),
+                                       global_myname(), 0x0,
+                                       dgram->source_name.name,
+                                       dgram->source_name.name_type,
+                                       p->ip, *iface_ip(p->ip), p->port);  
+                               break;
+                       }
+
+               /* Announce change to UAS or SAM.  Send by the domain controller when a
+               replication event is required. */
+
+               case SAM_UAS_CHANGE:
+                       {
+                               struct sam_database_info *db_info;
+                               char *q = buf + 2;
+                               int i, db_count;
+                               uint32 low_serial;
           
-          /* Header */
+                               /* Header */
           
-          low_serial = IVAL(q, 0); q += 4;     /* Low serial number */
+                               low_serial = IVAL(q, 0); q += 4;     /* Low serial number */
 
-          q += 4;                   /* Date/time */
-          q += 4;                   /* Pulse */
-          q += 4;                   /* Random */
+                               q += 4;                   /* Date/time */
+                               q += 4;                   /* Pulse */
+                               q += 4;                   /* Random */
           
-          /* Domain info */
+                               /* Domain info */
           
-          q = skip_string(q, 1);    /* PDC name */
-          q = skip_string(q, 1);    /* Domain name */
-          q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */
-          q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */
+                               q = skip_string(q, 1);    /* PDC name */
+                               q = skip_string(q, 1);    /* Domain name */
+                               q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */
+                               q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */
           
-          /* Database info */
+                               /* Database info */
           
-          db_count = SVAL(q, 0); q += 2;
+                               db_count = SVAL(q, 0); q += 2;
           
-          db_info = (struct sam_database_info *)
-                  malloc(sizeof(struct sam_database_info) * db_count);
-
-          if (db_info == NULL) {
-                  DEBUG(3, ("out of memory allocating info for %d databases\n",
-                            db_count));
-                  return;
-          }
+                               db_info = (struct sam_database_info *)
+                                               malloc(sizeof(struct sam_database_info) * db_count);
+
+                               if (db_info == NULL) {
+                                       DEBUG(3, ("out of memory allocating info for %d databases\n", db_count));
+                                       return;
+                               }
           
-          for (i = 0; i < db_count; i++) {
-                  db_info[i].index = IVAL(q, 0);
-                  db_info[i].serial_lo = IVAL(q, 4);
-                  db_info[i].serial_hi = IVAL(q, 8);
-                  db_info[i].date_lo = IVAL(q, 12);
-                  db_info[i].date_hi = IVAL(q, 16);
-                  q += 20;
-          }
-
-          /* Domain SID */
-
-          q += IVAL(q, 0) + 4;  /* 4 byte length plus data */
+                               for (i = 0; i < db_count; i++) {
+                                       db_info[i].index = IVAL(q, 0);
+                                       db_info[i].serial_lo = IVAL(q, 4);
+                                       db_info[i].serial_hi = IVAL(q, 8);
+                                       db_info[i].date_lo = IVAL(q, 12);
+                                       db_info[i].date_hi = IVAL(q, 16);
+                                       q += 20;
+                               }
+
+                               /* Domain SID */
+
+                               q += IVAL(q, 0) + 4;  /* 4 byte length plus data */
           
-          q += 2;               /* Alignment? */
-
-          /* Misc other info */
+                               q += 2;               /* Alignment? */
 
-          q += 4;               /* NT version (0x1) */
-          q += 2;               /* LMNT token (0xff) */
-          q += 2;               /* LM20 token (0xff) */
+                               /* Misc other info */
 
-          SAFE_FREE(db_info);        /* Not sure whether we need to do anything
-                                   useful with these */
+                               q += 4;               /* NT version (0x1) */
+                               q += 2;               /* LMNT token (0xff) */
+                               q += 2;               /* LM20 token (0xff) */
 
-          /* Send message to smbd */
+                               SAFE_FREE(db_info);        /* Not sure whether we need to do anything useful with these */
 
-          send_repl_message(low_serial);
+                               /* Send message to smbd */
 
-          break;
-  }
+                               send_repl_message(low_serial);
+                               break;
+                       }
 
-    default:
-    {
-      DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));
-      return;
-    }
-  }
+               default:
+                       DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));
+                       return;
+       }
 }
index 7e8c8025aeb4e865fc37f2fb34aee1155044dc1d..30c0c129508da9ef5b4a7d2026c979496905f3a8 100644 (file)
@@ -34,27 +34,26 @@ int num_response_packets = 0;
 static void add_response_record(struct subnet_record *subrec,
                                struct response_record *rrec)
 {
-  struct response_record *rrec2;
+       struct response_record *rrec2;
 
-  num_response_packets++; /* count of total number of packets still around */
+       num_response_packets++; /* count of total number of packets still around */
 
-  DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n",
-            rrec->response_id, subrec->subnet_name, num_response_packets));
+       DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n",
+               rrec->response_id, subrec->subnet_name, num_response_packets));
 
-  if (!subrec->responselist)
-  {
-    subrec->responselist = rrec;
-    rrec->prev = NULL;
-    rrec->next = NULL;
-    return;
-  }
+       if (!subrec->responselist) {
+               subrec->responselist = rrec;
+               rrec->prev = NULL;
+               rrec->next = NULL;
+               return;
+       }
   
-  for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) 
-    ;
+       for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) 
+               ;
   
-  rrec2->next = rrec;
-  rrec->next = NULL;
-  rrec->prev = rrec2;
+       rrec2->next = rrec;
+       rrec->next = NULL;
+       rrec->prev = rrec2;
 }
 
 /***************************************************************************
@@ -64,32 +63,31 @@ static void add_response_record(struct subnet_record *subrec,
 void remove_response_record(struct subnet_record *subrec,
                                struct response_record *rrec)
 {
-  if (rrec->prev)
-    rrec->prev->next = rrec->next;
-  if (rrec->next)
-    rrec->next->prev = rrec->prev;
-
-  if (subrec->responselist == rrec) 
-    subrec->responselist = rrec->next; 
-
-  if(rrec->userdata)
-  {
-         if(rrec->userdata->free_fn) {
-                 (*rrec->userdata->free_fn)(rrec->userdata);
-         } else {
-                 ZERO_STRUCTP(rrec->userdata);
-                 SAFE_FREE(rrec->userdata);
-         }
-  }
-
-  /* Ensure we can delete. */
-  rrec->packet->locked = False;
-  free_packet(rrec->packet);
-
-  ZERO_STRUCTP(rrec);
-  SAFE_FREE(rrec);
-
-  num_response_packets--; /* count of total number of packets still around */
+       if (rrec->prev)
+               rrec->prev->next = rrec->next;
+       if (rrec->next)
+               rrec->next->prev = rrec->prev;
+
+       if (subrec->responselist == rrec) 
+               subrec->responselist = rrec->next; 
+
+       if(rrec->userdata) {
+               if(rrec->userdata->free_fn) {
+                       (*rrec->userdata->free_fn)(rrec->userdata);
+               } else {
+                       ZERO_STRUCTP(rrec->userdata);
+                       SAFE_FREE(rrec->userdata);
+               }
+       }
+
+       /* Ensure we can delete. */
+       rrec->packet->locked = False;
+       free_packet(rrec->packet);
+
+       ZERO_STRUCTP(rrec);
+       SAFE_FREE(rrec);
+
+       num_response_packets--; /* count of total number of packets still around */
 }
 
 /****************************************************************************
@@ -104,77 +102,70 @@ struct response_record *make_response_record( struct subnet_record *subrec,
                                              fail_function fail_fn,
                                              struct userdata_struct *userdata)
 {
-  struct response_record *rrec;
-  struct nmb_packet *nmb = &p->packet.nmb;
-
-  if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) 
-  {
-    DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
-    return NULL;
-  }
-
-  memset((char *)rrec, '\0', sizeof(*rrec));
-
-  rrec->response_id = nmb->header.name_trn_id;
-
-  rrec->resp_fn = resp_fn;
-  rrec->timeout_fn = timeout_fn;
-  rrec->success_fn = success_fn;
-  rrec->fail_fn = fail_fn;
-
-  rrec->packet = p;
-
-  if(userdata)
-  {
-    /* Intelligent userdata. */
-    if(userdata->copy_fn)
-    {
-      if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL)
-      {
-        DEBUG(0,("make_response_queue_record: copy fail for userdata.\n"));
-       ZERO_STRUCTP(rrec);
-        SAFE_FREE(rrec);
-        return NULL;
-      }
-    }
-    else
-    {
-      /* Primitive userdata, do a memcpy. */
-      if((rrec->userdata = (struct userdata_struct *)
-           malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL)
-      {
-        DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
-       ZERO_STRUCTP(rrec);
-        SAFE_FREE(rrec);
-        return NULL;
-      }
-      rrec->userdata->copy_fn = userdata->copy_fn;
-      rrec->userdata->free_fn = userdata->free_fn;
-      rrec->userdata->userdata_len = userdata->userdata_len;
-      memcpy(rrec->userdata->data, userdata->data, userdata->userdata_len);
-    }
-  }
-  else
-    rrec->userdata = NULL;
-
-  rrec->num_msgs = 0;
-
-  if(!nmb->header.nm_flags.bcast)
-    rrec->repeat_interval = 5; /* 5 seconds for unicast packets. */
-  else
-    rrec->repeat_interval = 1; /* XXXX should be in ms */
-  rrec->repeat_count = 3; /* 3 retries */
-  rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */
-
-  /* This packet is not being processed. */
-  rrec->in_expiration_processing = False;
-
-  /* Lock the packet so we won't lose it while it's on the list. */
-  p->locked = True;
-
-  add_response_record(subrec, rrec);
-
-  return rrec;
+       struct response_record *rrec;
+       struct nmb_packet *nmb = &p->packet.nmb;
+
+       if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) {
+               DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
+               return NULL;
+       }
+
+       memset((char *)rrec, '\0', sizeof(*rrec));
+
+       rrec->response_id = nmb->header.name_trn_id;
+
+       rrec->resp_fn = resp_fn;
+       rrec->timeout_fn = timeout_fn;
+       rrec->success_fn = success_fn;
+       rrec->fail_fn = fail_fn;
+
+       rrec->packet = p;
+
+       if(userdata) {
+               /* Intelligent userdata. */
+               if(userdata->copy_fn) {
+                       if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL) {
+                               DEBUG(0,("make_response_queue_record: copy fail for userdata.\n"));
+                               ZERO_STRUCTP(rrec);
+                               SAFE_FREE(rrec);
+                               return NULL;
+                       }
+               } else {
+                       /* Primitive userdata, do a memcpy. */
+                       if((rrec->userdata = (struct userdata_struct *)
+                                       malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) {
+                               DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
+                               ZERO_STRUCTP(rrec);
+                               SAFE_FREE(rrec);
+                               return NULL;
+                       }
+                       rrec->userdata->copy_fn = userdata->copy_fn;
+                       rrec->userdata->free_fn = userdata->free_fn;
+                       rrec->userdata->userdata_len = userdata->userdata_len;
+                       memcpy(rrec->userdata->data, userdata->data, userdata->userdata_len);
+               }
+       } else {
+               rrec->userdata = NULL;
+       }
+
+       rrec->num_msgs = 0;
+
+       if(!nmb->header.nm_flags.bcast)
+               rrec->repeat_interval = 5; /* 5 seconds for unicast packets. */
+       else
+               rrec->repeat_interval = 1; /* XXXX should be in ms */
+       rrec->repeat_count = 3; /* 3 retries */
+       rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */
+
+       /* This packet is not being processed. */
+       rrec->in_expiration_processing = False;
+
+       /* Lock the packet so we won't lose it while it's on the list. */
+       p->locked = True;
+
+       add_response_record(subrec, rrec);
+
+       return rrec;
 }
 
 /****************************************************************************
@@ -184,18 +175,16 @@ struct response_record *make_response_record( struct subnet_record *subrec,
 static struct response_record *find_response_record_on_subnet(
                                 struct subnet_record *subrec, uint16 id)
 {  
-  struct response_record *rrec = NULL;
-
-  for (rrec = subrec->responselist; rrec; rrec = rrec->next)
-  {
-    if (rrec->response_id == id) 
-    {
-      DEBUG(4, ("find_response_record: found response record id = %hu on subnet %s\n",
-               id, subrec->subnet_name));
-      break;
-    }
-  }
-  return rrec;
+       struct response_record *rrec = NULL;
+
+       for (rrec = subrec->responselist; rrec; rrec = rrec->next) {
+               if (rrec->response_id == id) {
+                       DEBUG(4, ("find_response_record: found response record id = %hu on subnet %s\n",
+                               id, subrec->subnet_name));
+                       break;
+               }
+       }
+       return rrec;
 }
 
 /****************************************************************************
@@ -205,37 +194,34 @@ static struct response_record *find_response_record_on_subnet(
 struct response_record *find_response_record(struct subnet_record **ppsubrec,
                                uint16 id)
 {  
-  struct response_record *rrec = NULL;
-
-  for ((*ppsubrec) = FIRST_SUBNET; (*ppsubrec); 
-                  (*ppsubrec) = NEXT_SUBNET_INCLUDING_UNICAST(*ppsubrec))
-  {
-    if((rrec = find_response_record_on_subnet(*ppsubrec, id)) != NULL)
-      return rrec;
-  }
-
-  /* There should never be response records on the remote_broadcast subnet.
-     Sanity check to ensure this is so. */
-  if(remote_broadcast_subnet->responselist != NULL)
-  {
-    DEBUG(0,("find_response_record: response record found on subnet %s. This should \
+       struct response_record *rrec = NULL;
+
+       for ((*ppsubrec) = FIRST_SUBNET; (*ppsubrec); 
+                               (*ppsubrec) = NEXT_SUBNET_INCLUDING_UNICAST(*ppsubrec)) {
+               if((rrec = find_response_record_on_subnet(*ppsubrec, id)) != NULL)
+                       return rrec;
+       }
+
+       /* There should never be response records on the remote_broadcast subnet.
+                       Sanity check to ensure this is so. */
+       if(remote_broadcast_subnet->responselist != NULL) {
+               DEBUG(0,("find_response_record: response record found on subnet %s. This should \
 never happen !\n", remote_broadcast_subnet->subnet_name));
-  }
+       }
 
-  /* Now check the WINS server subnet if it exists. */
-  if(wins_server_subnet != NULL)
-  {
-    *ppsubrec = wins_server_subnet;
-    if((rrec = find_response_record_on_subnet(*ppsubrec, id))!= NULL)
-      return rrec;
-  }
+       /* Now check the WINS server subnet if it exists. */
+       if(wins_server_subnet != NULL) {
+               *ppsubrec = wins_server_subnet;
+               if((rrec = find_response_record_on_subnet(*ppsubrec, id))!= NULL)
+                       return rrec;
+       }
 
-  DEBUG(0,("find_response_record: response packet id %hu received with no \
+       DEBUG(0,("find_response_record: response packet id %hu received with no \
 matching record.\n", id));
  
-  *ppsubrec = NULL;
+       *ppsubrec = NULL;
 
-  return NULL;
+       return NULL;
 }
 
 /****************************************************************************
@@ -244,21 +230,19 @@ matching record.\n", id));
    
 BOOL is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec)
 {  
-  struct response_record *rrec = NULL;
+       struct response_record *rrec = NULL;
    
-  for (rrec = subrec->responselist; rrec; rrec = rrec->next)
-  {
-    struct packet_struct *p = rrec->packet;
-    struct nmb_packet *nmb = &p->packet.nmb;
-
-    if((nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) ||
-       (nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9))
-    {
-      /* Yes it's a queued refresh - check if the name is correct. */
-      if(nmb_name_equal(&nmb->question.question_name, &namerec->name))
-        return True;
-    }
-  }
-
-  return False;
-} 
+       for (rrec = subrec->responselist; rrec; rrec = rrec->next) {
+               struct packet_struct *p = rrec->packet;
+               struct nmb_packet *nmb = &p->packet.nmb;
+
+               if((nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) ||
+                               (nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9)) {
+                       /* Yes it's a queued refresh - check if the name is correct. */
+                       if(nmb_name_equal(&nmb->question.question_name, &namerec->name))
+                       return True;
+               }
+       }
+
+       return False;
+}
index 353717ee623f14f0c6bb660b348b5cd860c64cf3..87908e352cf87eef1b9e58ead7b49933673fcb6c 100644 (file)
@@ -35,21 +35,21 @@ extern BOOL found_lm_clients;
 
 void send_browser_reset(int reset_type, const char *to_name, int to_type, struct in_addr to_ip)
 {
-  pstring outbuf;
-  char *p;
+       pstring outbuf;
+       char *p;
 
-  DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n",
-       reset_type, to_name, to_type, inet_ntoa(to_ip) ));
+       DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n",
+               reset_type, to_name, to_type, inet_ntoa(to_ip) ));
 
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf;
-  SCVAL(p,0,ANN_ResetBrowserState);
-  p++;
-  SCVAL(p,0,reset_type);
-  p++;
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf;
+       SCVAL(p,0,ANN_ResetBrowserState);
+       p++;
+       SCVAL(p,0,reset_type);
+       p++;
 
-  send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
-                global_myname(), 0x0, to_name, to_type, to_ip, 
+       send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
+               global_myname(), 0x0, to_name, to_type, to_ip, 
                FIRST_SUBNET->myip, DGRAM_PORT);
 }
 
@@ -60,25 +60,25 @@ void send_browser_reset(int reset_type, const char *to_name, int to_type, struct
 
 void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work)
 {
-  pstring outbuf;
-  char *p;
+       pstring outbuf;
+       char *p;
 
-  work->needannounce = True;
+       work->needannounce = True;
 
-  DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \
+       DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \
 to subnet %s\n", work->work_group, subrec->subnet_name));
 
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf;
-  SCVAL(p,0,ANN_AnnouncementRequest);
-  p++;
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf;
+       SCVAL(p,0,ANN_AnnouncementRequest);
+       p++;
 
-  SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */
-  p++;
-  p +=  push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
+       SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */
+       p++;
+       p +=  push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
   
-  send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
-                global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip, 
+       send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
+               global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip, 
                subrec->myip, DGRAM_PORT);
 }
 
@@ -91,33 +91,33 @@ static void send_announcement(struct subnet_record *subrec, int announce_type,
                               time_t announce_interval,
                               const char *server_name, int server_type, const char *server_comment)
 {
-  pstring outbuf;
-  char *p;
+       pstring outbuf;
+       char *p;
 
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf+1;
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf+1;
 
-  SCVAL(outbuf,0,announce_type);
+       SCVAL(outbuf,0,announce_type);
 
-  /* Announcement parameters. */
-  SCVAL(p,0,updatecount);
-  SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */
+       /* Announcement parameters. */
+       SCVAL(p,0,updatecount);
+       SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */
 
-  push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
+       push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
 
-  SCVAL(p,21,lp_major_announce_version()); /* Major version. */
-  SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */
+       SCVAL(p,21,lp_major_announce_version()); /* Major version. */
+       SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */
 
-  SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
-  /* Browse version: got from NT/AS 4.00  - Value defined in smb.h (JHT). */
-  SSVAL(p,27,BROWSER_ELECTION_VERSION);
-  SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */
+       SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
+       /* Browse version: got from NT/AS 4.00  - Value defined in smb.h (JHT). */
+       SSVAL(p,27,BROWSER_ELECTION_VERSION);
+       SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */
 
-  p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE);
+       p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE);
 
-  send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
-                from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
-               DGRAM_PORT);
+       send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
+                       from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
+                       DGRAM_PORT);
 }
 
 /****************************************************************************
@@ -129,28 +129,23 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type
                               time_t announce_interval,
                               char *server_name, int server_type, char *server_comment)
 {
-  pstring outbuf;
-  char *p=outbuf;
-
-  memset(outbuf,'\0',sizeof(outbuf));
-
-  SSVAL(p,0,announce_type);
-  SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
-  SCVAL(p,6,lp_major_announce_version()); /* Major version. */
-  SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */
-  SSVAL(p,8,announce_interval);            /* In seconds - according to spec. */
-
-  p += 10;
-  /*StrnCpy(p,server_name,15);
-  strupper_m(p);
-  p = skip_string(p,1);
-  pstrcpy(p,server_comment);
-  p = skip_string(p,1);*/
-  p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
-  p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE);
-
-  send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
-                from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
+       pstring outbuf;
+       char *p=outbuf;
+
+       memset(outbuf,'\0',sizeof(outbuf));
+
+       SSVAL(p,0,announce_type);
+       SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY);
+       SCVAL(p,6,lp_major_announce_version()); /* Major version. */
+       SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */
+       SSVAL(p,8,announce_interval);            /* In seconds - according to spec. */
+
+       p += 10;
+       p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE);
+       p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE);
+
+       send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
+               from_name, 0x0, to_name, to_type, to_ip, subrec->myip,
                DGRAM_PORT);
 }
 
@@ -161,20 +156,20 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type
 static void send_local_master_announcement(struct subnet_record *subrec, struct work_record *work,
                                            struct server_record *servrec)
 {
-  /* Ensure we don't have the prohibited bit set. */
-  uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
-
-  DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
-            type, global_myname(), subrec->subnet_name, work->work_group));
-
-  send_announcement(subrec, ANN_LocalMasterAnnouncement,
-                    global_myname(),                 /* From nbt name. */
-                    work->work_group, 0x1e,          /* To nbt name. */
-                    subrec->bcast_ip,                /* To ip. */
-                    work->announce_interval,         /* Time until next announce. */
-                    global_myname(),                 /* Name to announce. */
-                    type,                            /* Type field. */
-                    servrec->serv.comment);
+       /* Ensure we don't have the prohibited bit set. */
+       uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
+
+       DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
+               type, global_myname(), subrec->subnet_name, work->work_group));
+
+       send_announcement(subrec, ANN_LocalMasterAnnouncement,
+                       global_myname(),                 /* From nbt name. */
+                       work->work_group, 0x1e,          /* To nbt name. */
+                       subrec->bcast_ip,                /* To ip. */
+                       work->announce_interval,         /* Time until next announce. */
+                       global_myname(),                 /* Name to announce. */
+                       type,                            /* Type field. */
+                       servrec->serv.comment);
 }
 
 /****************************************************************************
@@ -183,17 +178,17 @@ static void send_local_master_announcement(struct subnet_record *subrec, struct
 
 static void send_workgroup_announcement(struct subnet_record *subrec, struct work_record *work)
 {
-  DEBUG(3,("send_workgroup_announcement: on subnet %s for workgroup %s\n",
-            subrec->subnet_name, work->work_group));
-
-  send_announcement(subrec, ANN_DomainAnnouncement,
-                    global_myname(),                 /* From nbt name. */
-                    MSBROWSE, 0x1,                   /* To nbt name. */
-                    subrec->bcast_ip,                /* To ip. */
-                    work->announce_interval,         /* Time until next announce. */
-                    work->work_group,                /* Name to announce. */
-                    SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT,  /* workgroup announce flags. */
-                    global_myname());                /* From name as comment. */
+       DEBUG(3,("send_workgroup_announcement: on subnet %s for workgroup %s\n",
+               subrec->subnet_name, work->work_group));
+
+       send_announcement(subrec, ANN_DomainAnnouncement,
+                       global_myname(),                 /* From nbt name. */
+                       MSBROWSE, 0x1,                   /* To nbt name. */
+                       subrec->bcast_ip,                /* To ip. */
+                       work->announce_interval,         /* Time until next announce. */
+                       work->work_group,                /* Name to announce. */
+                       SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT,  /* workgroup announce flags. */
+                       global_myname());                /* From name as comment. */
 }
 
 /****************************************************************************
@@ -203,20 +198,20 @@ static void send_workgroup_announcement(struct subnet_record *subrec, struct wor
 static void send_host_announcement(struct subnet_record *subrec, struct work_record *work,
                                    struct server_record *servrec)
 {
-  /* Ensure we don't have the prohibited bits set. */
-  uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
-
-  DEBUG(3,("send_host_announcement: type %x for host %s on subnet %s for workgroup %s\n",
-            type, servrec->serv.name, subrec->subnet_name, work->work_group));
-
-  send_announcement(subrec, ANN_HostAnnouncement,
-                    servrec->serv.name,              /* From nbt name. */
-                    work->work_group, 0x1d,          /* To nbt name. */
-                    subrec->bcast_ip,                /* To ip. */
-                    work->announce_interval,         /* Time until next announce. */
-                    servrec->serv.name,              /* Name to announce. */
-                    type,                            /* Type field. */
-                    servrec->serv.comment);
+       /* Ensure we don't have the prohibited bits set. */
+       uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
+
+       DEBUG(3,("send_host_announcement: type %x for host %s on subnet %s for workgroup %s\n",
+               type, servrec->serv.name, subrec->subnet_name, work->work_group));
+
+       send_announcement(subrec, ANN_HostAnnouncement,
+                       servrec->serv.name,              /* From nbt name. */
+                       work->work_group, 0x1d,          /* To nbt name. */
+                       subrec->bcast_ip,                /* To ip. */
+                       work->announce_interval,         /* Time until next announce. */
+                       servrec->serv.name,              /* Name to announce. */
+                       type,                            /* Type field. */
+                       servrec->serv.comment);
 }
 
 /****************************************************************************
@@ -226,20 +221,20 @@ static void send_host_announcement(struct subnet_record *subrec, struct work_rec
 static void send_lm_host_announcement(struct subnet_record *subrec, struct work_record *work,
                                    struct server_record *servrec, int lm_interval)
 {
-  /* Ensure we don't have the prohibited bits set. */
-  uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
-
-  DEBUG(3,("send_lm_host_announcement: type %x for host %s on subnet %s for workgroup %s, ttl: %d\n",
-            type, servrec->serv.name, subrec->subnet_name, work->work_group, lm_interval));
-
-  send_lm_announcement(subrec, ANN_HostAnnouncement,
-                    servrec->serv.name,              /* From nbt name. */
-                    work->work_group, 0x00,          /* To nbt name. */
-                    subrec->bcast_ip,                /* To ip. */
-                    lm_interval,                     /* Time until next announce. */
-                    servrec->serv.name,              /* Name to announce. */
-                    type,                            /* Type field. */
-                    servrec->serv.comment);
+       /* Ensure we don't have the prohibited bits set. */
+       uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY;
+
+       DEBUG(3,("send_lm_host_announcement: type %x for host %s on subnet %s for workgroup %s, ttl: %d\n",
+               type, servrec->serv.name, subrec->subnet_name, work->work_group, lm_interval));
+
+       send_lm_announcement(subrec, ANN_HostAnnouncement,
+                       servrec->serv.name,              /* From nbt name. */
+                       work->work_group, 0x00,          /* To nbt name. */
+                       subrec->bcast_ip,                /* To ip. */
+                       lm_interval,                     /* Time until next announce. */
+                       servrec->serv.name,              /* Name to announce (fstring not netbios name struct). */
+                       type,                            /* Type field. */
+                       servrec->serv.comment);
 }
 
 /****************************************************************************
@@ -249,18 +244,15 @@ static void send_lm_host_announcement(struct subnet_record *subrec, struct work_
 static void announce_server(struct subnet_record *subrec, struct work_record *work,
                      struct server_record *servrec)
 {
-  /* Only do domain announcements if we are a master and it's
-     our primary name we're being asked to announce. */
-
-  if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname(),servrec->serv.name))
-  {
-    send_local_master_announcement(subrec, work, servrec);
-    send_workgroup_announcement(subrec, work);
-  }
-  else
-  {
-    send_host_announcement(subrec, work, servrec);
-  }
+       /* Only do domain announcements if we are a master and it's
+               our primary name we're being asked to announce. */
+
+       if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname(),servrec->serv.name)) {
+               send_local_master_announcement(subrec, work, servrec);
+               send_workgroup_announcement(subrec, work);
+       } else {
+               send_host_announcement(subrec, work, servrec);
+       }
 }
 
 /****************************************************************************
@@ -270,43 +262,39 @@ static void announce_server(struct subnet_record *subrec, struct work_record *wo
 
 void announce_my_server_names(time_t t)
 {
-  struct subnet_record *subrec;
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
-
-    if(work)
-    {
-      struct server_record *servrec;
-
-      if (work->needannounce)
-      {
-        /* Drop back to a max 3 minute announce. This is to prevent a
-           single lost packet from breaking things for too long. */
-
-        work->announce_interval = MIN(work->announce_interval,
-                                    CHECK_TIME_MIN_HOST_ANNCE*60);
-        work->lastannounce_time = t - (work->announce_interval+1);
-        work->needannounce = False;
-      }
-
-      /* Announce every minute at first then progress to every 12 mins */
-      if ((t - work->lastannounce_time) < work->announce_interval)
-        continue;
-
-      if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60))
-        work->announce_interval += 60;
-
-      work->lastannounce_time = t;
-
-      for (servrec = work->serverlist; servrec; servrec = servrec->next)
-      {
-        if (is_myname(servrec->serv.name))
-          announce_server(subrec, work, servrec);
-      }
-    } /* if work */
-  } /* for subrec */
+       struct subnet_record *subrec;
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
+
+               if(work) {
+                       struct server_record *servrec;
+
+                       if (work->needannounce) {
+                               /* Drop back to a max 3 minute announce. This is to prevent a
+                                       single lost packet from breaking things for too long. */
+
+                               work->announce_interval = MIN(work->announce_interval,
+                                                       CHECK_TIME_MIN_HOST_ANNCE*60);
+                               work->lastannounce_time = t - (work->announce_interval+1);
+                               work->needannounce = False;
+                       }
+
+                       /* Announce every minute at first then progress to every 12 mins */
+                       if ((t - work->lastannounce_time) < work->announce_interval)
+                               continue;
+
+                       if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60))
+                               work->announce_interval += 60;
+
+                       work->lastannounce_time = t;
+
+                       for (servrec = work->serverlist; servrec; servrec = servrec->next) {
+                               if (is_myname(servrec->serv.name))
+                                       announce_server(subrec, work, servrec);
+                       }
+               } /* if work */
+       } /* for subrec */
 }
 
 /****************************************************************************
@@ -316,47 +304,42 @@ void announce_my_server_names(time_t t)
 
 void announce_my_lm_server_names(time_t t)
 {
-  struct subnet_record *subrec;
-  static time_t last_lm_announce_time=0;
-  int announce_interval = lp_lm_interval();
-  int lm_announce = lp_lm_announce();
-
-  if ((announce_interval <= 0) || (lm_announce <= 0))
-  {
-    /* user absolutely does not want LM announcements to be sent. */
-    return;
-  }
-
-  if ((lm_announce >= 2) && (!found_lm_clients))
-  {
-    /* has been set to 2 (Auto) but no LM clients detected (yet). */
-    return;
-  }
-
-  /* Otherwise: must have been set to 1 (Yes), or LM clients *have*
-     been detected. */
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
-
-    if(work)
-    {
-      struct server_record *servrec;
-
-      if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval ))
-        continue;
-
-      last_lm_announce_time = t;
-
-      for (servrec = work->serverlist; servrec; servrec = servrec->next)
-      {
-        if (is_myname(servrec->serv.name))
-          /* skipping equivalent of announce_server() */
-          send_lm_host_announcement(subrec, work, servrec, announce_interval);
-      }
-    } /* if work */
-  } /* for subrec */
+       struct subnet_record *subrec;
+       static time_t last_lm_announce_time=0;
+       int announce_interval = lp_lm_interval();
+       int lm_announce = lp_lm_announce();
+
+       if ((announce_interval <= 0) || (lm_announce <= 0)) {
+               /* user absolutely does not want LM announcements to be sent. */
+               return;
+       }
+
+       if ((lm_announce >= 2) && (!found_lm_clients)) {
+               /* has been set to 2 (Auto) but no LM clients detected (yet). */
+               return;
+       }
+
+       /* Otherwise: must have been set to 1 (Yes), or LM clients *have*
+               been detected. */
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
+
+               if(work) {
+                       struct server_record *servrec;
+
+                       if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval ))
+                               continue;
+
+                       last_lm_announce_time = t;
+
+                       for (servrec = work->serverlist; servrec; servrec = servrec->next) {
+                               if (is_myname(servrec->serv.name))
+                                       /* skipping equivalent of announce_server() */
+                                       send_lm_host_announcement(subrec, work, servrec, announce_interval);
+                       }
+               } /* if work */
+       } /* for subrec */
 }
 
 /* Announce timer. Moved into global static so it can be reset
@@ -370,7 +353,7 @@ static time_t announce_timer_last=0;
 
 void reset_announce_timer(void)
 {
-  announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60);
+       announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60);
 }
 
 /****************************************************************************
@@ -379,45 +362,40 @@ void reset_announce_timer(void)
 
 void announce_myself_to_domain_master_browser(time_t t)
 {
-  struct subnet_record *subrec;
-  struct work_record *work;
-
-  if(!we_are_a_wins_client())
-  {
-    DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n"));
-    return;
-  }
-
-  if (!announce_timer_last)
-    announce_timer_last = t;
-
-  if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60))
-  {
-    DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n",
-             (int)t, (int)announce_timer_last, 
-             CHECK_TIME_MST_ANNOUNCE * 60 ));
-    return;
-  }
-
-  announce_timer_last = t;
-
-  /* Look over all our broadcast subnets to see if any of them
-     has the state set as local master browser. */
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    for (work = subrec->workgrouplist; work; work = work->next)
-    {
-      if (AM_LOCAL_MASTER_BROWSER(work))
-      {
-        DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \
+       struct subnet_record *subrec;
+       struct work_record *work;
+
+       if(!we_are_a_wins_client()) {
+               DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n"));
+               return;
+       }
+
+       if (!announce_timer_last)
+               announce_timer_last = t;
+
+       if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) {
+               DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n",
+                       (int)t, (int)announce_timer_last, 
+                       CHECK_TIME_MST_ANNOUNCE * 60 ));
+               return;
+       }
+
+       announce_timer_last = t;
+
+       /* Look over all our broadcast subnets to see if any of them
+               has the state set as local master browser. */
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               for (work = subrec->workgrouplist; work; work = work->next) {
+                       if (AM_LOCAL_MASTER_BROWSER(work)) {
+                               DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \
 workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
 
-        /* Look in nmbd_browsersync.c for the rest of this code. */
-        announce_and_sync_with_domain_master_browser(subrec, work);
-      }
-    }
-  }
+                               /* Look in nmbd_browsersync.c for the rest of this code. */
+                               announce_and_sync_with_domain_master_browser(subrec, work);
+                       }
+               }
+       }
 }
 
 /****************************************************************************
@@ -427,49 +405,43 @@ This must *only* be called on shutdown.
 
 void announce_my_servers_removed(void)
 {
-  int announce_interval = lp_lm_interval();
-  int lm_announce = lp_lm_announce();
-  struct subnet_record *subrec; 
-
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work;
-    for (work = subrec->workgrouplist; work; work = work->next)
-    {
-      struct server_record *servrec;
-
-      work->announce_interval = 0;
-      for (servrec = work->serverlist; servrec; servrec = servrec->next)
-      {
-        if (!is_myname(servrec->serv.name))
-          continue;
-        servrec->serv.type = 0;
-        if(AM_LOCAL_MASTER_BROWSER(work))
-          send_local_master_announcement(subrec, work, servrec);
-        send_host_announcement(subrec, work, servrec);
-
-
-        if ((announce_interval <= 0) || (lm_announce <= 0))
-        {
-          /* user absolutely does not want LM announcements to be sent. */
-          continue;
-        }
-
-        if ((lm_announce >= 2) && (!found_lm_clients))
-        {
-          /* has been set to 2 (Auto) but no LM clients detected (yet). */
-          continue;
-        }
-
-        /* 
-         * lm announce was set or we have seen lm announcements, so do
-         * a lm announcement of host removed.
-         */
-
-        send_lm_host_announcement(subrec, work, servrec, 0);
-      }
-    }
-  }
+       int announce_interval = lp_lm_interval();
+       int lm_announce = lp_lm_announce();
+       struct subnet_record *subrec; 
+
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+               struct work_record *work;
+               for (work = subrec->workgrouplist; work; work = work->next) {
+                       struct server_record *servrec;
+
+                       work->announce_interval = 0;
+                       for (servrec = work->serverlist; servrec; servrec = servrec->next) {
+                               if (!is_myname(servrec->serv.name))
+                                       continue;
+                               servrec->serv.type = 0;
+                               if(AM_LOCAL_MASTER_BROWSER(work))
+                                       send_local_master_announcement(subrec, work, servrec);
+                               send_host_announcement(subrec, work, servrec);
+
+                               if ((announce_interval <= 0) || (lm_announce <= 0)) {
+                                       /* user absolutely does not want LM announcements to be sent. */
+                                       continue;
+                               }
+
+                               if ((lm_announce >= 2) && (!found_lm_clients)) {
+                                       /* has been set to 2 (Auto) but no LM clients detected (yet). */
+                                       continue;
+                               }
+
+                               /* 
+                                * lm announce was set or we have seen lm announcements, so do
+                                * a lm announcement of host removed.
+                                */
+
+                               send_lm_host_announcement(subrec, work, servrec, 0);
+                       }
+               }
+       }
 }
 
 /****************************************************************************
@@ -480,132 +452,127 @@ void announce_my_servers_removed(void)
 
 void announce_remote(time_t t)
 {
-  char *s;
-  const char *ptr;
-  static time_t last_time = 0;
-  pstring s2;
-  struct in_addr addr;
-  char *comment;
-  int stype = lp_default_server_announce();
-
-  if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
-    return;
-
-  last_time = t;
-
-  s = lp_remote_announce();
-  if (!*s)
-    return;
-
-  comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH);
-
-  for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) 
-  {
-    /* The entries are of the form a.b.c.d/WORKGROUP with 
-       WORKGROUP being optional */
-    const char *wgroup;
-    char *pwgroup;
-    int i;
-
-    pwgroup = strchr_m(s2,'/');
-    if (pwgroup)
-      *pwgroup++ = 0;
-    if (!pwgroup || !*pwgroup)
-      wgroup = lp_workgroup();
-    else
-      wgroup = pwgroup;
-
-    addr = *interpret_addr2(s2);
+       char *s;
+       const char *ptr;
+       static time_t last_time = 0;
+       pstring s2;
+       struct in_addr addr;
+       char *comment;
+       int stype = lp_default_server_announce();
+
+       if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
+               return;
+
+       last_time = t;
+
+       s = lp_remote_announce();
+       if (!*s)
+               return;
+
+       comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH);
+
+       for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
+               /* The entries are of the form a.b.c.d/WORKGROUP with 
+                               WORKGROUP being optional */
+               const char *wgroup;
+               char *pwgroup;
+               int i;
+
+               pwgroup = strchr_m(s2,'/');
+               if (pwgroup)
+                       *pwgroup++ = 0;
+               if (!pwgroup || !*pwgroup)
+                       wgroup = lp_workgroup();
+               else
+                       wgroup = pwgroup;
+
+               addr = *interpret_addr2(s2);
     
-    /* Announce all our names including aliases */
-    /* Give the ip address as the address of our first
-       broadcast subnet. */
-
-    for(i=0; my_netbios_names(i); i++) 
-    {
-      const char *name = my_netbios_names(i);
-
-      DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n",
-                 name, inet_ntoa(addr) ));
-
-      send_announcement(FIRST_SUBNET, ANN_HostAnnouncement,
-                    name,                      /* From nbt name. */
-                    wgroup, 0x1d,              /* To nbt name. */
-                    addr,                      /* To ip. */
-                    REMOTE_ANNOUNCE_INTERVAL,  /* Time until next announce. */
-                    name,                      /* Name to announce. */
-                    stype,                     /* Type field. */
-                    comment);
-    }
-  }
+               /* Announce all our names including aliases */
+               /* Give the ip address as the address of our first
+                               broadcast subnet. */
+
+               for(i=0; my_netbios_names(i); i++) {
+                       const char *name = my_netbios_names(i);
+
+                       DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n",
+                               name, inet_ntoa(addr) ));
+
+                       send_announcement(FIRST_SUBNET, ANN_HostAnnouncement,
+                                               name,                      /* From nbt name. */
+                                               wgroup, 0x1d,              /* To nbt name. */
+                                               addr,                      /* To ip. */
+                                               REMOTE_ANNOUNCE_INTERVAL,  /* Time until next announce. */
+                                               name,                      /* Name to announce. */
+                                               stype,                     /* Type field. */
+                                               comment);
+               }
+       }
 }
 
 /****************************************************************************
   Implement the 'remote browse sync' feature Andrew added.
   These are used to put our browse lists into remote browse lists.
-  **************************************************************************/
+**************************************************************************/
 
 void browse_sync_remote(time_t t)
 {  
-  char *s;
-  const char *ptr;
-  static time_t last_time = 0; 
-  pstring s2;
-  struct in_addr addr;
-  struct work_record *work;
-  pstring outbuf;
-  char *p;
-  fstring myname;
+       char *s;
+       const char *ptr;
+       static time_t last_time = 0; 
+       pstring s2;
+       struct in_addr addr;
+       struct work_record *work;
+       pstring outbuf;
+       char *p;
+       fstring myname;
  
-  if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
-    return;
+       if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
+               return;
    
-  last_time = t;
-
-  s = lp_remote_browse_sync();
-  if (!*s)
-    return;
-
-  /*
-   * We only do this if we are the local master browser
-   * for our workgroup on the firsst subnet.
-   */
-
-  if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL)
-  {   
-    DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n",
-           lp_workgroup(), FIRST_SUBNET->subnet_name ));
-    return;
-  }   
+       last_time = t;
+
+       s = lp_remote_browse_sync();
+       if (!*s)
+               return;
+
+       /*
+        * We only do this if we are the local master browser
+        * for our workgroup on the firsst subnet.
+        */
+
+       if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) {   
+               DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n",
+                       lp_workgroup(), FIRST_SUBNET->subnet_name ));
+               return;
+       }
          
-  if(!AM_LOCAL_MASTER_BROWSER(work))
-  {
-    DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \
+       if(!AM_LOCAL_MASTER_BROWSER(work)) {
+               DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \
 for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
-    return;
-  } 
+               return;
+       
 
-  memset(outbuf,'\0',sizeof(outbuf));
-  p = outbuf;
-  SCVAL(p,0,ANN_MasterAnnouncement);
-  p++;
+       memset(outbuf,'\0',sizeof(outbuf));
+       p = outbuf;
+       SCVAL(p,0,ANN_MasterAnnouncement);
+       p++;
 
-  fstrcpy(myname, global_myname());
-  strupper_m(myname);
-  myname[15]='\0';
-  push_pstring_base(p, myname, outbuf);
+       fstrcpy(myname, global_myname());
+       strupper_m(myname);
+       myname[15]='\0';
+       push_pstring_base(p, myname, outbuf);
 
-  p = skip_string(p,1);
+       p = skip_string(p,1);
 
-  for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) 
-  {
-    /* The entries are of the form a.b.c.d */
-    addr = *interpret_addr2(s2);
+       for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
+               /* The entries are of the form a.b.c.d */
+               addr = *interpret_addr2(s2);
 
-    DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n",
-                 global_myname(), inet_ntoa(addr) ));
+               DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n",
+                       global_myname(), inet_ntoa(addr) ));
 
-    send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
-          global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT);
-  }
+               send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
+                       global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT);
+       }
 }
index 2484a7f830b630b21b4509251e43ed9258a2ff51..cdb1089a54faa57ede1d80c56cd70b07b34e75ea 100644 (file)
@@ -33,28 +33,26 @@ int updatecount = 0;
 
 void remove_all_servers(struct work_record *work)
 {
-  struct server_record *servrec;
-  struct server_record *nexts;
+       struct server_record *servrec;
+       struct server_record *nexts;
 
-  for (servrec = work->serverlist; servrec; servrec = nexts)
-  {
-    DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name));
-    nexts = servrec->next;
+       for (servrec = work->serverlist; servrec; servrec = nexts) {
+               DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name));
+               nexts = servrec->next;
 
-    if (servrec->prev)
-      servrec->prev->next = servrec->next;
-    if (servrec->next)
-      servrec->next->prev = servrec->prev;
+               if (servrec->prev)
+                       servrec->prev->next = servrec->next;
+               if (servrec->next)
+                       servrec->next->prev = servrec->prev;
 
-    if (work->serverlist == servrec)
-      work->serverlist = servrec->next;
+               if (work->serverlist == servrec)
+                       work->serverlist = servrec->next;
 
-    ZERO_STRUCTP(servrec);
-    SAFE_FREE(servrec);
+               ZERO_STRUCTP(servrec);
+               SAFE_FREE(servrec);
+       }
 
-  }
-
-  work->subnet->work_changed = True;
+       work->subnet->work_changed = True;
 }
 
 /***************************************************************************
@@ -64,23 +62,22 @@ void remove_all_servers(struct work_record *work)
 static void add_server_to_workgroup(struct work_record *work,
                              struct server_record *servrec)
 {
-  struct server_record *servrec2;
-
-  if (!work->serverlist)
-  {
-    work->serverlist = servrec;
-    servrec->prev = NULL;
-    servrec->next = NULL;
-    return;
-  }
-
-  for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next)
-    ;
-
-  servrec2->next = servrec;
-  servrec->next = NULL;
-  servrec->prev = servrec2;
-  work->subnet->work_changed = True;
+       struct server_record *servrec2;
+
+       if (!work->serverlist) {
+               work->serverlist = servrec;
+               servrec->prev = NULL;
+               servrec->next = NULL;
+               return;
+       }
+
+       for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next)
+               ;
+
+       servrec2->next = servrec;
+       servrec->next = NULL;
+       servrec->prev = servrec2;
+       work->subnet->work_changed = True;
 }
 
 /****************************************************************************
@@ -89,14 +86,13 @@ static void add_server_to_workgroup(struct work_record *work,
 
 struct server_record *find_server_in_workgroup(struct work_record *work, const char *name)
 {
-  struct server_record *ret;
+       struct server_record *ret;
   
-  for (ret = work->serverlist; ret; ret = ret->next)
-  {
-    if (strequal(ret->serv.name,name))
-      return ret;
-  }
-  return NULL;
+       for (ret = work->serverlist; ret; ret = ret->next) {
+               if (strequal(ret->serv.name,name))
+                       return ret;
+       }
+       return NULL;
 }
 
 
@@ -106,17 +102,17 @@ struct server_record *find_server_in_workgroup(struct work_record *work, const c
 
 void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec)
 {
-  if (servrec->prev)
-    servrec->prev->next = servrec->next;
-  if (servrec->next)
-    servrec->next->prev = servrec->prev;
+       if (servrec->prev)
+               servrec->prev->next = servrec->next;
+       if (servrec->next)
+               servrec->next->prev = servrec->prev;
 
-  if (work->serverlist == servrec) 
-    work->serverlist = servrec->next; 
+       if (work->serverlist == servrec) 
+               work->serverlist = servrec->next; 
 
-  ZERO_STRUCTP(servrec);
-  SAFE_FREE(servrec);
-  work->subnet->work_changed = True;
+       ZERO_STRUCTP(servrec);
+       SAFE_FREE(servrec);
+       work->subnet->work_changed = True;
 }
 
 /****************************************************************************
@@ -127,47 +123,44 @@ struct server_record *create_server_on_workgroup(struct work_record *work,
                                                  const char *name,int servertype, 
                                                  int ttl, const char *comment)
 {
-  struct server_record *servrec;
+       struct server_record *servrec;
   
-  if (name[0] == '*')
-  {
-      DEBUG(7,("create_server_on_workgroup: not adding name starting with '*' (%s)\n",
-             name));
-      return (NULL);
-  }
+       if (name[0] == '*') {
+               DEBUG(7,("create_server_on_workgroup: not adding name starting with '*' (%s)\n",
+                       name));
+               return (NULL);
+       }
   
-  if((servrec = find_server_in_workgroup(work, name)) != NULL)
-  {
-    DEBUG(0,("create_server_on_workgroup: Server %s already exists on \
+       if((servrec = find_server_in_workgroup(work, name)) != NULL) {
+               DEBUG(0,("create_server_on_workgroup: Server %s already exists on \
 workgroup %s. This is a bug.\n", name, work->work_group));
-    return NULL;
-  }
+               return NULL;
+       }
   
-  if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL)
-  {
-    DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
-    return NULL;
-  }
+       if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) {
+               DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
+               return NULL;
+       }
 
-  memset((char *)servrec,'\0',sizeof(*servrec));
+       memset((char *)servrec,'\0',sizeof(*servrec));
  
-  servrec->subnet = work->subnet;
+       servrec->subnet = work->subnet;
  
-  fstrcpy(servrec->serv.name,name);
-  fstrcpy(servrec->serv.comment,comment);
-  strupper_m(servrec->serv.name);
-  servrec->serv.type  = servertype;
+       fstrcpy(servrec->serv.name,name);
+       fstrcpy(servrec->serv.comment,comment);
+       strupper_m(servrec->serv.name);
+       servrec->serv.type  = servertype;
 
-  update_server_ttl(servrec, ttl);
+       update_server_ttl(servrec, ttl);
   
-  add_server_to_workgroup(work, servrec);
+       add_server_to_workgroup(work, servrec);
       
-  DEBUG(3,("create_server_on_workgroup: Created server entry %s of type %x (%s) on \
+       DEBUG(3,("create_server_on_workgroup: Created server entry %s of type %x (%s) on \
 workgroup %s.\n", name,servertype,comment, work->work_group));
  
-  work->subnet->work_changed = True;
+       work->subnet->work_changed = True;
  
-  return(servrec);
+       return(servrec);
 }
 
 /*******************************************************************
@@ -176,15 +169,15 @@ workgroup %s.\n", name,servertype,comment, work->work_group));
 
 void update_server_ttl(struct server_record *servrec, int ttl)
 {
-  if(ttl > lp_max_ttl())
-    ttl = lp_max_ttl();
+       if(ttl > lp_max_ttl())
+               ttl = lp_max_ttl();
 
-  if(is_myname(servrec->serv.name))
-    servrec->death_time = PERMANENT_TTL;
-  else
-    servrec->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL;
+       if(is_myname(servrec->serv.name))
+               servrec->death_time = PERMANENT_TTL;
+       else
+               servrec->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL;
 
-  servrec->subnet->work_changed = True;
+       servrec->subnet->work_changed = True;
 }
 
 /*******************************************************************
@@ -195,20 +188,18 @@ void update_server_ttl(struct server_record *servrec, int ttl)
 
 void expire_servers(struct work_record *work, time_t t)
 {
-  struct server_record *servrec;
-  struct server_record *nexts;
+       struct server_record *servrec;
+       struct server_record *nexts;
   
-  for (servrec = work->serverlist; servrec; servrec = nexts)
-  {
-    nexts = servrec->next;
-
-    if ((servrec->death_time != PERMANENT_TTL) && ((t == -1) || (servrec->death_time < t)))
-    {
-      DEBUG(3,("expire_old_servers: Removing timed out server %s\n",servrec->serv.name));
-      remove_server_from_workgroup(work, servrec);
-      work->subnet->work_changed = True;
-    }
-  }
+       for (servrec = work->serverlist; servrec; servrec = nexts) {
+               nexts = servrec->next;
+
+               if ((servrec->death_time != PERMANENT_TTL) && ((t == -1) || (servrec->death_time < t))) {
+                       DEBUG(3,("expire_old_servers: Removing timed out server %s\n",servrec->serv.name));
+                       remove_server_from_workgroup(work, servrec);
+                       work->subnet->work_changed = True;
+               }
+       }
 }
 
 /*******************************************************************
@@ -221,33 +212,30 @@ static uint32 write_this_server_name( struct subnet_record *subrec,
                                       struct work_record *work,
                                       struct server_record *servrec)
 {
-  struct subnet_record *ssub;
-  struct work_record *iwork;
-
-  /* Go through all the subnets we have already seen. */
-  for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) 
-  {
-    for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next)
-    {
-      if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL)
-      {
-        /*
-         * We have already written out this server record, don't
-         * do it again. This gives precedence to servers we have seen
-         * on the broadcast subnets over servers that may have been
-         * added via a sync on the unicast_subet.
-         *
-         * The correct way to do this is to have a serverlist file
-         * per subnet - this means changes to smbd as well. I may
-         * add this at a later date (JRA).
-         */
-
-        return 0;
-      }
-    }
-  }
-
-  return servrec->serv.type;
+       struct subnet_record *ssub;
+       struct work_record *iwork;
+
+       /* Go through all the subnets we have already seen. */
+       for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) {
+               for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) {
+                       if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) {
+                               /*
+                                * We have already written out this server record, don't
+                                * do it again. This gives precedence to servers we have seen
+                                * on the broadcast subnets over servers that may have been
+                                * added via a sync on the unicast_subet.
+                                *
+                                * The correct way to do this is to have a serverlist file
+                                * per subnet - this means changes to smbd as well. I may
+                                * add this at a later date (JRA).
+                                */
+
+                               return 0;
+                       }
+               }
+       }
+
+       return servrec->serv.type;
 }
 
 /*******************************************************************
@@ -261,30 +249,29 @@ static uint32 write_this_server_name( struct subnet_record *subrec,
 static uint32 write_this_workgroup_name( struct subnet_record *subrec, 
                                          struct work_record *work)
 {
-  struct subnet_record *ssub;
+       struct subnet_record *ssub;
 
-  if(strequal(lp_workgroup(), work->work_group))
-    return 0;
+       if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring)-1))
+               return 0;
 
-  /* This is a workgroup we have seen on a broadcast subnet. All
-     these have the same type. */
+       /* This is a workgroup we have seen on a broadcast subnet. All
+               these have the same type. */
 
-  if(subrec != unicast_subnet)
-    return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY);
+       if(subrec != unicast_subnet)
+               return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY);
 
-  for(ssub = FIRST_SUBNET; ssub;  ssub = NEXT_SUBNET_EXCLUDING_UNICAST(ssub))
-  {
-    /* This is the unicast subnet so check if we've already written out
-       this subnet when we passed over the broadcast subnets. */
+       for(ssub = FIRST_SUBNET; ssub;  ssub = NEXT_SUBNET_EXCLUDING_UNICAST(ssub)) {
+               /* This is the unicast subnet so check if we've already written out
+                       this subnet when we passed over the broadcast subnets. */
 
-    if(find_workgroup_on_subnet( ssub, work->work_group) != NULL)
-      return 0;
-  }
+               if(find_workgroup_on_subnet( ssub, work->work_group) != NULL)
+                       return 0;
+       }
 
-  /* All workgroups on the unicast subnet (except our own, which we
-     have already written out) cannot be local. */
+       /* All workgroups on the unicast subnet (except our own, which we
+               have already written out) cannot be local. */
 
-  return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT);
+       return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT);
 }
 
 /*******************************************************************
@@ -306,143 +293,130 @@ void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type,
 
 void write_browse_list(time_t t, BOOL force_write)
 {   
-  struct subnet_record *subrec;
-  struct work_record *work;
-  struct server_record *servrec;
-  pstring fname,fnamenew;
-  uint32 stype;
-  int i;
-  XFILE *fp;
-  BOOL list_changed = force_write;
-  static time_t lasttime = 0;
+       struct subnet_record *subrec;
+       struct work_record *work;
+       struct server_record *servrec;
+       pstring fname,fnamenew;
+       uint32 stype;
+       int i;
+       XFILE *fp;
+       BOOL list_changed = force_write;
+       static time_t lasttime = 0;
     
-  /* Always dump if we're being told to by a signal. */
-  if(force_write == False)
-  {
-    if (!lasttime)
-      lasttime = t;
-    if (t - lasttime < 5)
-      return;
-  }
-
-  lasttime = t;
-
-  dump_workgroups(force_write);
+       /* Always dump if we're being told to by a signal. */
+       if(force_write == False) {
+               if (!lasttime)
+                       lasttime = t;
+               if (t - lasttime < 5)
+                       return;
+       }
+
+       lasttime = t;
+
+       dump_workgroups(force_write);
  
-  for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-    if(subrec->work_changed)
-    {
-      list_changed = True;
-      break;
-    }
-  }
-
-  if(!list_changed)
-    return;
-
-  updatecount++;
+       for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               if(subrec->work_changed) {
+                       list_changed = True;
+                       break;
+               }
+       }
+
+       if(!list_changed)
+               return;
+
+       updatecount++;
     
-  pstrcpy(fname,lp_lockdir());
-  trim_string(fname,NULL,"/");
-  pstrcat(fname,"/");
-  pstrcat(fname,SERVER_LIST);
-  pstrcpy(fnamenew,fname);
-  pstrcat(fnamenew,".");
+       pstrcpy(fname,lp_lockdir());
+       trim_char(fname,'\0' ,'/');
+       pstrcat(fname,"/");
+       pstrcat(fname,SERVER_LIST);
+       pstrcpy(fnamenew,fname);
+       pstrcat(fnamenew,".");
  
-  fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
+       fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
  
-  if (!fp)
-  {
-    DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n",
-              fnamenew,strerror(errno)));
-    return;
-  } 
+       if (!fp) {
+               DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n",
+                       fnamenew,strerror(errno)));
+               return;
+       } 
   
-  /*
-   * Write out a record for our workgroup. Use the record from the first
-   * subnet.
-   */
-
-  if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL)
-  { 
-    DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n",
-             lp_workgroup()));
-    x_fclose(fp);
-    return;
-  }
-
-  write_browse_list_entry(fp, work->work_group,
-     SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY,
-     work->local_master_browser_name, work->work_group);
-
-  /* 
-   * We need to do something special for our own names.
-   * This is due to the fact that we may be a local master browser on
-   * one of our broadcast subnets, and a domain master on the unicast
-   * subnet. We iterate over the subnets and only write out the name
-   * once.
-   */
-
-  for (i=0; my_netbios_names(i); i++)
-  {
-    stype = 0;
-    for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-    {
-      if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL)
-        continue;
-      if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL)
-        continue;
-
-      stype |= servrec->serv.type;
-    }
-
-    /* Output server details, plus what workgroup they're in. */
-    write_browse_list_entry(fp, my_netbios_names(i), stype,
-        string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup());
-  }
+       /*
+        * Write out a record for our workgroup. Use the record from the first
+        * subnet.
+        */
+
+       if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { 
+               DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n",
+                       lp_workgroup()));
+               x_fclose(fp);
+               return;
+       }
+
+       write_browse_list_entry(fp, work->work_group,
+               SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY,
+               work->local_master_browser_name, work->work_group);
+
+       /* 
+        * We need to do something special for our own names.
+        * This is due to the fact that we may be a local master browser on
+        * one of our broadcast subnets, and a domain master on the unicast
+        * subnet. We iterate over the subnets and only write out the name
+        * once.
+        */
+
+       for (i=0; my_netbios_names(i); i++) {
+               stype = 0;
+               for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+                       if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL)
+                               continue;
+                       if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL)
+                               continue;
+
+                       stype |= servrec->serv.type;
+               }
+
+               /* Output server details, plus what workgroup they're in. */
+               write_browse_list_entry(fp, my_netbios_names(i), stype,
+                       string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup());
+       }
       
-  for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) 
-  { 
-    subrec->work_changed = False;
-
-    for (work = subrec->workgrouplist; work ; work = work->next)
-    {
-      /* Write out a workgroup record for a workgroup. */
-      uint32 wg_type = write_this_workgroup_name( subrec, work);
-
-      if(wg_type)
-      {
-        write_browse_list_entry(fp, work->work_group, wg_type,
-                                work->local_master_browser_name,
-                                work->work_group);
-      }
-
-      /* Now write out any server records a workgroup may have. */
-
-      for (servrec = work->serverlist; servrec ; servrec = servrec->next)
-      {
-        uint32 serv_type;
-
-        /* We have already written our names here. */
-        if(is_myname(servrec->serv.name))
-          continue; 
-
-        serv_type = write_this_server_name(subrec, work, servrec);
-
-        if(serv_type)
-        {
-          /* Output server details, plus what workgroup they're in. */
-          write_browse_list_entry(fp, servrec->serv.name, serv_type,
-                                 servrec->serv.comment, work->work_group);
-        }
-      }
-    }
-  } 
+       for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { 
+               subrec->work_changed = False;
+
+               for (work = subrec->workgrouplist; work ; work = work->next) {
+                       /* Write out a workgroup record for a workgroup. */
+                       uint32 wg_type = write_this_workgroup_name( subrec, work);
+
+                       if(wg_type) {
+                               write_browse_list_entry(fp, work->work_group, wg_type,
+                                               work->local_master_browser_name,
+                                               work->work_group);
+                       }
+
+                       /* Now write out any server records a workgroup may have. */
+
+                       for (servrec = work->serverlist; servrec ; servrec = servrec->next) {
+                               uint32 serv_type;
+
+                               /* We have already written our names here. */
+                               if(is_myname(servrec->serv.name))
+                                       continue; 
+
+                               serv_type = write_this_server_name(subrec, work, servrec);
+                               if(serv_type) {
+                                       /* Output server details, plus what workgroup they're in. */
+                                       write_browse_list_entry(fp, servrec->serv.name, serv_type,
+                                               servrec->serv.comment, work->work_group);
+                               }
+                       }
+               }
+       } 
   
-  x_fclose(fp);
-  unlink(fname);
-  chmod(fnamenew,0644);
-  rename(fnamenew,fname);
-  DEBUG(3,("write_browse_list: Wrote browse list into file %s\n",fname));
+       x_fclose(fp);
+       unlink(fname);
+       chmod(fnamenew,0644);
+       rename(fnamenew,fname);
+       DEBUG(3,("write_browse_list: Wrote browse list into file %s\n",fname));
 }
index 62968264259d9a70b7512a51dc0d168dac95a4e5..02a91f27606026434d1a0087d3299c30d9600041 100644 (file)
@@ -63,28 +63,27 @@ static void add_subnet(struct subnet_record *subrec)
  * ************************************************************************** **
  */
 static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node )
-  {
-  struct name_record *NR = (struct name_record *)Node;
-
-  if( DEBUGLVL( 10 ) )
-    {
-    struct nmb_name *Iname = (struct nmb_name *)Item;
+{
+       struct name_record *NR = (struct name_record *)Node;
 
-    Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" );
-    Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n",
-            memcmp( Item, &(NR->name), sizeof(struct nmb_name) ),
-            nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) );
-    }
+       if( DEBUGLVL( 10 ) ) {
+               struct nmb_name *Iname = (struct nmb_name *)Item;
 
-  return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); 
-  } /* namelist_entry_compare */
+               Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" );
+               Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n",
+                       memcmp( Item, &(NR->name), sizeof(struct nmb_name) ),
+                       nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) );
+       }
 
+       return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); 
+}
 
 /****************************************************************************
 stop listening on a subnet
 we don't free the record as we don't have proper reference counting for it
 yet and it may be in use by a response record
   ****************************************************************************/
+
 void close_subnet(struct subnet_record *subrec)
 {
        DLIST_REMOVE(subnetlist, subrec);
@@ -99,8 +98,6 @@ void close_subnet(struct subnet_record *subrec)
        }
 }
 
-
-
 /****************************************************************************
   Create a subnet entry.
   ****************************************************************************/
@@ -109,102 +106,90 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type
                                         struct in_addr myip, struct in_addr bcast_ip, 
                                         struct in_addr mask_ip)
 {
-  struct subnet_record *subrec = NULL;
-  int nmb_sock, dgram_sock;
-
-  /* Check if we are creating a non broadcast subnet - if so don't create
-     sockets.
-   */
-
-  if(type != NORMAL_SUBNET)
-  {
-    nmb_sock = -1;
-    dgram_sock = -1;
-  }
-  else
-  {
-    /*
-     * Attempt to open the sockets on port 137/138 for this interface
-     * and bind them.
-     * Fail the subnet creation if this fails.
-     */
-
-    if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1)
-    {
-      if( DEBUGLVL( 0 ) )
-      {
-        Debug1( "nmbd_subnetdb:make_subnet()\n" );
-        Debug1( "  Failed to open nmb socket on interface %s ", inet_ntoa(myip) );
-        Debug1( "for port %d.  ", global_nmb_port );
-        Debug1( "Error was %s\n", strerror(errno) );
-      }
-      return NULL;
-    }
-
-    if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1)
-    {
-      if( DEBUGLVL( 0 ) )
-      {
-        Debug1( "nmbd_subnetdb:make_subnet()\n" );
-        Debug1( "  Failed to open dgram socket on interface %s ", inet_ntoa(myip) );
-        Debug1( "for port %d.  ", DGRAM_PORT );
-        Debug1( "Error was %s\n", strerror(errno) );
-      }
-      return NULL;
-    }
-
-    /* Make sure we can broadcast from these sockets. */
-    set_socket_options(nmb_sock,"SO_BROADCAST");
-    set_socket_options(dgram_sock,"SO_BROADCAST");
-
-  }
-
-  subrec = (struct subnet_record *)malloc(sizeof(*subrec));
-  
-  if (!subrec) 
-  {
-    DEBUG(0,("make_subnet: malloc fail !\n"));
-    close(nmb_sock);
-    close(dgram_sock);
-    return(NULL);
-  }
+       struct subnet_record *subrec = NULL;
+       int nmb_sock, dgram_sock;
+
+       /* Check if we are creating a non broadcast subnet - if so don't create
+               sockets.  */
+
+       if(type != NORMAL_SUBNET) {
+               nmb_sock = -1;
+               dgram_sock = -1;
+       } else {
+               /*
+                * Attempt to open the sockets on port 137/138 for this interface
+                * and bind them.
+                * Fail the subnet creation if this fails.
+                */
+
+               if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) {
+                       if( DEBUGLVL( 0 ) ) {
+                               Debug1( "nmbd_subnetdb:make_subnet()\n" );
+                               Debug1( "  Failed to open nmb socket on interface %s ", inet_ntoa(myip) );
+                               Debug1( "for port %d.  ", global_nmb_port );
+                               Debug1( "Error was %s\n", strerror(errno) );
+                       }
+                       return NULL;
+               }
+
+               if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) {
+                       if( DEBUGLVL( 0 ) ) {
+                               Debug1( "nmbd_subnetdb:make_subnet()\n" );
+                               Debug1( "  Failed to open dgram socket on interface %s ", inet_ntoa(myip) );
+                               Debug1( "for port %d.  ", DGRAM_PORT );
+                               Debug1( "Error was %s\n", strerror(errno) );
+                       }
+                       return NULL;
+               }
+
+               /* Make sure we can broadcast from these sockets. */
+               set_socket_options(nmb_sock,"SO_BROADCAST");
+               set_socket_options(dgram_sock,"SO_BROADCAST");
+       }
+
+       subrec = (struct subnet_record *)malloc(sizeof(*subrec));
+       if (!subrec) {
+               DEBUG(0,("make_subnet: malloc fail !\n"));
+               close(nmb_sock);
+               close(dgram_sock);
+               return(NULL);
+       }
   
-  memset( (char *)subrec, '\0', sizeof(*subrec) );
-  (void)ubi_trInitTree( subrec->namelist,
-                        namelist_entry_compare,
-                        ubi_trOVERWRITE );
-
-  if((subrec->subnet_name = strdup(name)) == NULL)
-  {
-    DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
-    close(nmb_sock);
-    close(dgram_sock);
-    ZERO_STRUCTP(subrec);
-    SAFE_FREE(subrec);
-    return(NULL);
-  }
-
-  DEBUG(2, ("making subnet name:%s ", name ));
-  DEBUG(2, ("Broadcast address:%s ", inet_ntoa(bcast_ip)));
-  DEBUG(2, ("Subnet mask:%s\n", inet_ntoa(mask_ip)));
+       memset( (char *)subrec, '\0', sizeof(*subrec) );
+       (void)ubi_trInitTree( subrec->namelist,
+                       namelist_entry_compare,
+                       ubi_trOVERWRITE );
+
+       if((subrec->subnet_name = strdup(name)) == NULL) {
+               DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
+               close(nmb_sock);
+               close(dgram_sock);
+               ZERO_STRUCTP(subrec);
+               SAFE_FREE(subrec);
+               return(NULL);
+       }
+
+       DEBUG(2, ("making subnet name:%s ", name ));
+       DEBUG(2, ("Broadcast address:%s ", inet_ntoa(bcast_ip)));
+       DEBUG(2, ("Subnet mask:%s\n", inet_ntoa(mask_ip)));
  
-  subrec->namelist_changed = False;
-  subrec->work_changed = False;
+       subrec->namelist_changed = False;
+       subrec->work_changed = False;
  
-  subrec->bcast_ip = bcast_ip;
-  subrec->mask_ip  = mask_ip;
-  subrec->myip = myip;
-  subrec->type = type;
-  subrec->nmb_sock = nmb_sock;
-  subrec->dgram_sock = dgram_sock;
+       subrec->bcast_ip = bcast_ip;
+       subrec->mask_ip  = mask_ip;
+       subrec->myip = myip;
+       subrec->type = type;
+       subrec->nmb_sock = nmb_sock;
+       subrec->dgram_sock = dgram_sock;
   
-  return subrec;
+       return subrec;
 }
 
-
 /****************************************************************************
   Create a normal subnet
 **************************************************************************/
+
 struct subnet_record *make_normal_subnet(struct interface *iface)
 {
        struct subnet_record *subrec;
@@ -217,100 +202,99 @@ struct subnet_record *make_normal_subnet(struct interface *iface)
        return subrec;
 }
 
-
 /****************************************************************************
   Create subnet entries.
 **************************************************************************/
 
 BOOL create_subnets(void)
 {    
-  int num_interfaces = iface_count();
-  int i;
-  struct in_addr unicast_ip, ipzero;
-  extern struct in_addr loopback_ip;
-
-  if(num_interfaces == 0) {
-         DEBUG(0,("create_subnets: No local interfaces !\n"));
-         DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n"));
-         while (iface_count() == 0) {
-                 sleep(5);
-                 load_interfaces();
-         }
-  }
-
-  num_interfaces = iface_count();
-
-  /* 
-   * Create subnets from all the local interfaces and thread them onto
-   * the linked list. 
-   */
-
-  for (i = 0 ; i < num_interfaces; i++)
-  {
-    struct interface *iface = get_interface(i);
-
-    /*
-     * We don't want to add a loopback interface, in case
-     * someone has added 127.0.0.1 for smbd, nmbd needs to
-     * ignore it here. JRA.
-     */
-
-    if (ip_equal(iface->ip, loopback_ip)) {
-      DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
-      continue;
-    }
-
-    if (!make_normal_subnet(iface)) return False;
-  }
-
-  if (lp_we_are_a_wins_server()) {
-         /* Pick the first interface ip address as the WINS server ip. */
-         unicast_ip = *iface_n_ip(0);
-  } else {
-         /* note that we do not set the wins server IP here. We just
-            set it at zero and let the wins registration code cope
-            with getting the IPs right for each packet */
-         zero_ip(&unicast_ip);
-  }
-
-  /*
-   * Create the unicast and remote broadcast subnets.
-   * Don't put these onto the linked list.
-   * The ip address of the unicast subnet is set to be
-   * the WINS server address, if it exists, or ipzero if not.
-   */
-
-  unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, 
-                                 unicast_ip, unicast_ip, unicast_ip);
-
-  zero_ip(&ipzero);
-
-  remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
-                                         REMOTE_BROADCAST_SUBNET,
-                                         ipzero, ipzero, ipzero);
-
-  if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL))
-    return False;
-
-  /* 
-   * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on
-   * the linked list.
-   */
-
-  if (lp_we_are_a_wins_server())
-  {
-    if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET",
-                                           WINS_SERVER_SUBNET, 
-                                           ipzero, ipzero, ipzero )) == NULL )
-      return False;
-  }
-
-  return True;
+       int num_interfaces = iface_count();
+       int i;
+       struct in_addr unicast_ip, ipzero;
+       extern struct in_addr loopback_ip;
+
+       if(num_interfaces == 0) {
+               DEBUG(0,("create_subnets: No local interfaces !\n"));
+               DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n"));
+               while (iface_count() == 0) {
+                       sleep(5);
+                       load_interfaces();
+               }
+       }
+
+       num_interfaces = iface_count();
+
+       /* 
+        * Create subnets from all the local interfaces and thread them onto
+        * the linked list. 
+        */
+
+       for (i = 0 ; i < num_interfaces; i++) {
+               struct interface *iface = get_interface(i);
+
+               /*
+                * We don't want to add a loopback interface, in case
+                * someone has added 127.0.0.1 for smbd, nmbd needs to
+                * ignore it here. JRA.
+                */
+
+               if (ip_equal(iface->ip, loopback_ip)) {
+                       DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
+                       continue;
+               }
+
+               if (!make_normal_subnet(iface))
+                       return False;
+       }
+
+       if (lp_we_are_a_wins_server()) {
+               /* Pick the first interface ip address as the WINS server ip. */
+               unicast_ip = *iface_n_ip(0);
+       } else {
+               /* note that we do not set the wins server IP here. We just
+                       set it at zero and let the wins registration code cope
+                       with getting the IPs right for each packet */
+               zero_ip(&unicast_ip);
+       }
+
+       /*
+        * Create the unicast and remote broadcast subnets.
+        * Don't put these onto the linked list.
+        * The ip address of the unicast subnet is set to be
+        * the WINS server address, if it exists, or ipzero if not.
+        */
+
+       unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, 
+                               unicast_ip, unicast_ip, unicast_ip);
+
+       zero_ip(&ipzero);
+
+       remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
+                               REMOTE_BROADCAST_SUBNET,
+                               ipzero, ipzero, ipzero);
+
+       if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL))
+               return False;
+
+       /* 
+        * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on
+        * the linked list.
+        */
+
+       if (lp_we_are_a_wins_server()) {
+               if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET",
+                                               WINS_SERVER_SUBNET, 
+                                               ipzero, ipzero, ipzero )) == NULL )
+                       return False;
+       }
+
+       return True;
 }
 
 /*******************************************************************
 Function to tell us if we can use the unicast subnet.
 ******************************************************************/
+
 BOOL we_are_a_wins_client(void)
 {
        if (wins_srv_count() > 0) {
@@ -326,12 +310,12 @@ Access function used by NEXT_SUBNET_INCLUDING_UNICAST
 
 struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec)
 {
-  if(subrec == unicast_subnet)
-    return NULL;
-  else if((subrec->next == NULL) && we_are_a_wins_client())
-    return unicast_subnet;
-  else
-    return subrec->next;
+       if(subrec == unicast_subnet)
+               return NULL;
+       else if((subrec->next == NULL) && we_are_a_wins_client())
+               return unicast_subnet;
+       else
+               return subrec->next;
 }
 
 /*******************************************************************
@@ -343,19 +327,18 @@ struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec
 
 struct subnet_record *get_next_subnet_maybe_unicast_or_wins_server(struct subnet_record *subrec)
 {
-  if(subrec == unicast_subnet)
-  {
-    if(wins_server_subnet)
-      return wins_server_subnet;
-    else
-      return NULL;
-  }
-
-  if(wins_server_subnet && subrec == wins_server_subnet)
-    return NULL;
-
-  if((subrec->next == NULL) && we_are_a_wins_client())
-    return unicast_subnet;
-  else
-    return subrec->next;
+       if(subrec == unicast_subnet) {
+               if(wins_server_subnet)
+                       return wins_server_subnet;
+               else
+                       return NULL;
+       }
+
+       if(wins_server_subnet && subrec == wins_server_subnet)
+               return NULL;
+
+       if((subrec->next == NULL) && we_are_a_wins_client())
+               return unicast_subnet;
+       else
+               return subrec->next;
 }
index b9952fb446ca63a183499109683909acf0d5f3b9..6a0576a5a439291fba2fb072eaadb9c8b1314381 100644 (file)
@@ -31,8 +31,8 @@
 
 struct sync_record {
        struct sync_record *next, *prev;
-       fstring workgroup;
-       fstring server;
+       nstring workgroup;
+       nstring server;
        pstring fname;
        struct in_addr ip;
        pid_t pid;
@@ -47,6 +47,7 @@ static XFILE *fp;
   This is the NetServerEnum callback.
   Note sname and comment are in UNIX codepage format.
   ******************************************************************/
+
 static void callback(const char *sname, uint32 stype, 
                      const char *comment, void *state)
 {
@@ -58,6 +59,7 @@ static void callback(const char *sname, uint32 stype,
   Log in on the remote server's SMB port to their IPC$ service,
   do a NetServerEnum and record the results in fname
 ******************************************************************/
+
 static void sync_child(char *name, int nm_type, 
                       char *workgroup,
                       struct in_addr ip, BOOL local, BOOL servers,
@@ -78,10 +80,9 @@ static void sync_child(char *name, int nm_type,
        }
 
        make_nmb_name(&calling, local_machine, 0x0);
-       make_nmb_name(&called , name         , nm_type);
+       make_nmb_name(&called , name, nm_type);
 
-       if (!cli_session_request(&cli, &calling, &called))
-       {
+       if (!cli_session_request(&cli, &calling, &called)) {
                cli_shutdown(&cli);
                return;
        }
@@ -120,12 +121,12 @@ static void sync_child(char *name, int nm_type,
        cli_shutdown(&cli);
 }
 
-
 /*******************************************************************
   initialise a browse sync with another browse server.  Log in on the
   remote server's SMB port to their IPC$ service, do a NetServerEnum
   and record the results
 ******************************************************************/
+
 void sync_browse_lists(struct work_record *work,
                       char *name, int nm_type, 
                       struct in_addr ip, BOOL local, BOOL servers)
@@ -147,8 +148,8 @@ done:
 
        ZERO_STRUCTP(s);
        
-       fstrcpy(s->workgroup, work->work_group);
-       fstrcpy(s->server, name);
+       nstrcpy(s->workgroup, work->work_group);
+       nstrcpy(s->server, name);
        s->ip = ip;
 
        slprintf(s->fname, sizeof(pstring)-1,
@@ -182,8 +183,9 @@ done:
 }
 
 /**********************************************************************
-handle one line from a completed sync file
+ Handle one line from a completed sync file.
  **********************************************************************/
+
 static void complete_one(struct sync_record *s, 
                         char *sname, uint32 stype, char *comment)
 {
@@ -204,8 +206,7 @@ static void complete_one(struct sync_record *s,
                                                          sname, lp_max_ttl());
                        if (work) {
                                /* remember who the master is */
-                               fstrcpy(work->local_master_browser_name, 
-                                       comment);
+                               nstrcpy(work->local_master_browser_name, comment);
                        }
                }
                return;
@@ -235,10 +236,10 @@ static void complete_one(struct sync_record *s,
        create_server_on_workgroup(work, sname,stype, lp_max_ttl(), comment);
 }
                
-
 /**********************************************************************
-read the completed sync info
- **********************************************************************/
+ Read the completed sync info.
+**********************************************************************/
+
 static void complete_sync(struct sync_record *s)
 {
        XFILE *f;
@@ -251,11 +252,13 @@ static void complete_sync(struct sync_record *s)
 
        f = x_fopen(s->fname,O_RDONLY, 0);
 
-       if (!f) return;
+       if (!f)
+               return;
        
        while (!x_feof(f)) {
                
-               if (!fgets_slash(line,sizeof(pstring),f)) continue;
+               if (!fgets_slash(line,sizeof(pstring),f))
+                       continue;
                
                ptr = line;
 
@@ -281,8 +284,9 @@ static void complete_sync(struct sync_record *s)
 }
 
 /**********************************************************************
-check for completion of any of the child processes
- **********************************************************************/
+ Check for completion of any of the child processes.
+**********************************************************************/
+
 void sync_check_completion(void)
 {
        struct sync_record *s, *next;
index 2e65ebb612d19f1c5f9b461301e65d42692dfa6f..bace112752f7071261be7f9f82d27daa68c66f1d 100644 (file)
@@ -30,92 +30,85 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec,
                         struct userdata_struct *userdata,
                         struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec)
 {
-  struct packet_struct *original_packet;
-  struct subnet_record *orig_broadcast_subnet;
-  struct name_record *namerec;
-  uint16 nb_flags;
-  int num_ips;
-  int i;
-  int ttl = 3600; /* By default one hour in the cache. */
-  struct in_addr *iplist;
-
-  /* Extract the original packet and the original broadcast subnet from
-     the userdata. */
-
-  memcpy( (char *)&orig_broadcast_subnet, userdata->data, sizeof(struct subnet_record *) );
-  memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)],
-          sizeof(struct packet_struct *) );
-
-  nb_flags = get_nb_flags( rrec->rdata );
-
-  num_ips = rrec->rdlength / 6;
-  if(num_ips == 0)
-  {
-    DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \
+       nstring name;
+       struct packet_struct *original_packet;
+       struct subnet_record *orig_broadcast_subnet;
+       struct name_record *namerec;
+       uint16 nb_flags;
+       int num_ips;
+       int i;
+       int ttl = 3600; /* By default one hour in the cache. */
+       struct in_addr *iplist;
+
+       /* Extract the original packet and the original broadcast subnet from
+                       the userdata. */
+
+       memcpy( (char *)&orig_broadcast_subnet, userdata->data, sizeof(struct subnet_record *) );
+       memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)],
+                       sizeof(struct packet_struct *) );
+
+       nb_flags = get_nb_flags( rrec->rdata );
+
+       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) ));
-    return;
-  }
-
-  if(num_ips == 1)
-    iplist = &ip;
-  else
-  {
-    if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL)
-    {
-      DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
-      return;
-    }
-
-    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)
-    ttl = lp_max_ttl();
-
-  namerec = add_name_to_subnet( orig_broadcast_subnet, nmbname->name,
-                                nmbname->name_type, nb_flags, ttl,
-                                WINS_PROXY_NAME, num_ips, iplist );
-
-  if(iplist != &ip)
-    SAFE_FREE(iplist);
-
-  /*
-   * Check that none of the IP addresses we are returning is on the
-   * same broadcast subnet as the original requesting packet. If it
-   * is then don't reply (although we still need to add the name
-   * to the cache) as the actual machine will be replying also
-   * and we don't want two replies to a broadcast query.
-   */
-
-  if(namerec && original_packet->packet.nmb.header.nm_flags.bcast)
-  {
-    for( i = 0; i < namerec->data.num_ips; i++)
-    {
-      if( same_net( namerec->data.ip[i],
-                    orig_broadcast_subnet->myip,
-                    orig_broadcast_subnet->mask_ip ) )
-      {
-        DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \
+               return;
+       }
+
+       if(num_ips == 1) {
+               iplist = &ip;
+       } else {
+               if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) {
+                       DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
+                       return;
+               }
+
+               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)
+               ttl = lp_max_ttl();
+
+       pull_ascii_nstring(name, nmbname->name);
+       namerec = add_name_to_subnet( orig_broadcast_subnet, name,
+                                       nmbname->name_type, nb_flags, ttl,
+                                       WINS_PROXY_NAME, num_ips, iplist );
+
+       if(iplist != &ip)
+               SAFE_FREE(iplist);
+
+       /*
+        * Check that none of the IP addresses we are returning is on the
+        * same broadcast subnet as the original requesting packet. If it
+        * is then don't reply (although we still need to add the name
+        * to the cache) as the actual machine will be replying also
+        * and we don't want two replies to a broadcast query.
+        */
+
+       if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) {
+               for( i = 0; i < namerec->data.num_ips; i++) {
+                       if( same_net( namerec->data.ip[i], orig_broadcast_subnet->myip,
+                                       orig_broadcast_subnet->mask_ip ) ) {
+                               DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \
 proxy name and is also on the same subnet (%s) as the requestor. \
-Not replying.\n",
-                    nmb_namestr(&namerec->name),
-                    orig_broadcast_subnet->subnet_name ) );
-        return;
-      }
-    }
-  }
-
-  /* Finally reply to the original name query. */
-  reply_netbios_packet(original_packet,                /* Packet to reply to. */
-                       0,                              /* Result code. */
-                       NMB_QUERY,                      /* nmbd type code. */
-                       NMB_NAME_QUERY_OPCODE,          /* opcode. */
-                       ttl,                            /* ttl. */
-                       rrec->rdata,                    /* data to send. */
-                       rrec->rdlength);                /* data length. */
+Not replying.\n", nmb_namestr(&namerec->name), orig_broadcast_subnet->subnet_name ) );
+                               return;
+                       }
+               }
+       }
+
+       /* Finally reply to the original name query. */
+       reply_netbios_packet(original_packet,                /* Packet to reply to. */
+                               0,                              /* Result code. */
+                               NMB_QUERY,                      /* nmbd type code. */
+                               NMB_NAME_QUERY_OPCODE,          /* opcode. */
+                               ttl,                            /* ttl. */
+                               rrec->rdata,                    /* data to send. */
+                               rrec->rdlength);                /* data length. */
 }
 
 /****************************************************************************
@@ -126,7 +119,7 @@ static void wins_proxy_name_query_request_fail(struct subnet_record *subrec,
                                     struct response_record *rrec,
                                     struct nmb_name *question_name, int fail_code)
 {
-  DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \
+       DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \
 of name %s.\n", fail_code, nmb_namestr(question_name) ));
 }
 
@@ -137,38 +130,35 @@ proxy query returns.
 
 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 packet_struct *p, *copy_of_p;
+       struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len );
 
-  if(new_userdata == NULL)
-    return NULL;
+       if(new_userdata == NULL)
+               return NULL;
 
-  new_userdata->copy_fn = userdata->copy_fn;
-  new_userdata->free_fn = userdata->free_fn;
-  new_userdata->userdata_len = userdata->userdata_len;
+       new_userdata->copy_fn = userdata->copy_fn;
+       new_userdata->free_fn = userdata->free_fn;
+       new_userdata->userdata_len = userdata->userdata_len;
 
-  /* Copy the subnet_record pointer. */
-  memcpy( new_userdata->data, userdata->data, sizeof(struct subnet_record *) );
+       /* Copy the subnet_record pointer. */
+       memcpy( new_userdata->data, userdata->data, sizeof(struct subnet_record *) );
 
-  /* Extract the pointer to the packet struct */
-  memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)],
-         sizeof(struct packet_struct *) );
+       /* Extract the pointer to the packet struct */
+       memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], sizeof(struct packet_struct *) );
 
-  /* Do a deep copy of the packet. */
-  if((copy_of_p = copy_packet(p)) == NULL)
-  {
-    SAFE_FREE(new_userdata);
-    return NULL;
-  }
+       /* Do a deep copy of the packet. */
+       if((copy_of_p = copy_packet(p)) == NULL) {
+               SAFE_FREE(new_userdata);
+               return NULL;
+       }
 
-  /* Lock the copy. */
-  copy_of_p->locked = True;
+       /* Lock the copy. */
+       copy_of_p->locked = True;
 
-  memcpy( &new_userdata->data[sizeof(struct subnet_record *)], (char *)&copy_of_p,
-          sizeof(struct packet_struct *) );
+       memcpy( &new_userdata->data[sizeof(struct subnet_record *)], (char *)&copy_of_p,
+               sizeof(struct packet_struct *) );
 
-  return new_userdata;
+       return new_userdata;
 }
 
 /****************************************************************************
@@ -178,18 +168,18 @@ proxy query returned.
 
 static void wins_proxy_userdata_free_fn(struct userdata_struct *userdata)
 {
-  struct packet_struct *p;
+       struct packet_struct *p;
 
-  /* Extract the pointer to the packet struct */
-  memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)],
-         sizeof(struct packet_struct *));
+       /* Extract the pointer to the packet struct */
+       memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)],
+               sizeof(struct packet_struct *));
 
-  /* Unlock the packet. */
-  p->locked = False;
+       /* Unlock the packet. */
+       p->locked = False;
 
-  free_packet(p);
-  ZERO_STRUCTP(userdata);
-  SAFE_FREE(userdata);
+       free_packet(p);
+       ZERO_STRUCTP(userdata);
+       SAFE_FREE(userdata);
 }
 
 /****************************************************************************
@@ -200,22 +190,24 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec,
                                          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;
+       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));
+       memset(ud, '\0', sizeof(ud));
  
-  userdata->copy_fn = wins_proxy_userdata_copy_fn;
-  userdata->free_fn = wins_proxy_userdata_free_fn;
-  userdata->userdata_len = sizeof(ud);
-  memcpy( userdata->data, (char *)&subrec, sizeof(struct subnet_record *));
-  memcpy( &userdata->data[sizeof(struct subnet_record *)], (char *)&incoming_packet,
-          sizeof(struct packet_struct *));
-
-  /* Now use the unicast subnet to query the name with the WINS server. */
-  query_name( unicast_subnet, question_name->name, question_name->name_type,
-              wins_proxy_name_query_request_success,
-              wins_proxy_name_query_request_fail,
-              userdata);
+       userdata->copy_fn = wins_proxy_userdata_copy_fn;
+       userdata->free_fn = wins_proxy_userdata_free_fn;
+       userdata->userdata_len = sizeof(ud);
+       memcpy( userdata->data, (char *)&subrec, sizeof(struct subnet_record *));
+       memcpy( &userdata->data[sizeof(struct subnet_record *)], (char *)&incoming_packet,
+                       sizeof(struct packet_struct *));
+
+       /* Now use the unicast subnet to query the name with the WINS server. */
+       pull_ascii_nstring(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,
+               userdata);
 }
index eafff03b767730e2a4424fb89a3635d62deb8659..484588c6626be24364af9a0fcfd3e9f828f71255 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/CIFS implementation.
    NBT netbios routines and daemon - version 2
 
-   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
@@ -26,8 +26,9 @@
 #define WINS_VERSION 1
 
 /****************************************************************************
-change the wins owner address in the record.
+ Change the wins owner address in the record.
 *****************************************************************************/
+
 static void update_wins_owner(struct name_record *namerec, struct in_addr wins_ip)
 {
        if (namerec==NULL)
@@ -36,8 +37,9 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_i
 }
 
 /****************************************************************************
-create the wins flags based on the nb flags and the input value.
+ Create the wins flags based on the nb flags and the input value.
 *****************************************************************************/
+
 static void update_wins_flag(struct name_record *namerec, int flags)
 {
        if (namerec==NULL)
@@ -74,12 +76,12 @@ static void update_wins_flag(struct name_record *namerec, int flags)
 
        DEBUG(8,("update_wins_flag: nbflags: 0x%x, ttl: 0x%d, flags: 0x%x, winsflags: 0x%x\n", 
                 namerec->data.nb_flags, (int)namerec->data.death_time, flags, namerec->data.wins_flags));
-
 }
 
 /****************************************************************************
-return the general ID value and increase it if requested
+ Return the general ID value and increase it if requested.
 *****************************************************************************/
+
 static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update)
 {
        /*
@@ -98,8 +100,9 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update)
 }
 
 /****************************************************************************
-possibly call the WINS hook external program when a WINS change is made
+ Possibly call the WINS hook external program when a WINS change is made.
 *****************************************************************************/
+
 static void wins_hook(const char *operation, struct name_record *namerec, int ttl)
 {
        pstring command;
@@ -120,7 +123,7 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt
        p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", 
                      cmd,
                      operation, 
-                     namerec->name.name,
+                     nmb_namestr(&namerec->name),
                      namerec->name.name_type,
                      ttl);
 
@@ -139,63 +142,58 @@ Determine if this packet should be allocated to the WINS server.
 
 BOOL packet_is_for_wins_server(struct packet_struct *packet)
 {
-  struct nmb_packet *nmb = &packet->packet.nmb;
-
-  /* Only unicast packets go to a WINS server. */
-  if((wins_server_subnet == NULL) || (nmb->header.nm_flags.bcast == True))
-  {
-    DEBUG(10, ("packet_is_for_wins_server: failing WINS test #1.\n"));
-    return False;
-  }
-
-  /* Check for node status requests. */
-  if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY)
-    return False;
-
-  switch(nmb->header.opcode)
-  { 
-    /*
-     * A WINS server issues WACKS, not receives them.
-     */
-    case NMB_WACK_OPCODE:
-      DEBUG(10, ("packet_is_for_wins_server: failing WINS test #2 (WACK).\n"));
-      return False;
-    /*
-     * A WINS server only processes registration and
-     * release requests, not responses.
-     */
-    case NMB_NAME_REG_OPCODE:
-    case NMB_NAME_MULTIHOMED_REG_OPCODE:
-    case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
-    case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
-      if(nmb->header.response)
-      {
-        DEBUG(10, ("packet_is_for_wins_server: failing WINS test #3 (response = 1).\n"));
-        return False;
-      }
-      break;
-
-    case NMB_NAME_RELEASE_OPCODE:
-      if(nmb->header.response)
-      {
-        DEBUG(10, ("packet_is_for_wins_server: failing WINS test #4 (response = 1).\n"));
-        return False;
-      }
-      break;
-
-    /*
-     * Only process unicast name queries with rd = 1.
-     */
-    case NMB_NAME_QUERY_OPCODE:
-      if(!nmb->header.response && !nmb->header.nm_flags.recursion_desired)
-      {
-        DEBUG(10, ("packet_is_for_wins_server: failing WINS test #5 (response = 1).\n"));
-        return False;
-      }
-      break;
-  }
-
-  return True;
+       struct nmb_packet *nmb = &packet->packet.nmb;
+
+       /* Only unicast packets go to a WINS server. */
+       if((wins_server_subnet == NULL) || (nmb->header.nm_flags.bcast == True)) {
+               DEBUG(10, ("packet_is_for_wins_server: failing WINS test #1.\n"));
+               return False;
+       }
+
+       /* Check for node status requests. */
+       if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY)
+               return False;
+
+       switch(nmb->header.opcode) { 
+               /*
+                * A WINS server issues WACKS, not receives them.
+                */
+               case NMB_WACK_OPCODE:
+                       DEBUG(10, ("packet_is_for_wins_server: failing WINS test #2 (WACK).\n"));
+                       return False;
+               /*
+                * A WINS server only processes registration and
+                * release requests, not responses.
+                */
+               case NMB_NAME_REG_OPCODE:
+               case NMB_NAME_MULTIHOMED_REG_OPCODE:
+               case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */
+               case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */
+                       if(nmb->header.response) {
+                               DEBUG(10, ("packet_is_for_wins_server: failing WINS test #3 (response = 1).\n"));
+                               return False;
+                       }
+                       break;
+
+               case NMB_NAME_RELEASE_OPCODE:
+                       if(nmb->header.response) {
+                               DEBUG(10, ("packet_is_for_wins_server: failing WINS test #4 (response = 1).\n"));
+                               return False;
+                       }
+                       break;
+
+               /*
+                * Only process unicast name queries with rd = 1.
+                */
+               case NMB_NAME_QUERY_OPCODE:
+                       if(!nmb->header.response && !nmb->header.nm_flags.recursion_desired) {
+                               DEBUG(10, ("packet_is_for_wins_server: failing WINS test #5 (response = 1).\n"));
+                               return False;
+                       }
+                       break;
+       }
+
+       return True;
 }
 
 /****************************************************************************
@@ -204,15 +202,15 @@ Utility function to decide what ttl to give a register/refresh request.
 
 static int get_ttl_from_packet(struct nmb_packet *nmb)
 {
-  int ttl = nmb->additional->ttl;
+       int ttl = nmb->additional->ttl;
 
-  if(ttl < lp_min_wins_ttl() )
-    ttl = lp_min_wins_ttl();
+       if(ttl < lp_min_wins_ttl() )
+               ttl = lp_min_wins_ttl();
 
-  if(ttl > lp_max_wins_ttl() )
-    ttl = lp_max_wins_ttl();
+       if(ttl > lp_max_wins_ttl() )
+               ttl = lp_max_wins_ttl();
 
-  return ttl;
+       return ttl;
 }
 
 /****************************************************************************
@@ -221,177 +219,160 @@ Load or create the WINS database.
 
 BOOL initialise_wins(void)
 {
-  time_t time_now = time(NULL);
-  XFILE *fp;
-  pstring line;
-
-  if(!lp_we_are_a_wins_server())
-    return True;
-
-  add_samba_names_to_subnet(wins_server_subnet);
-
-  if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL)
-  {
-    DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
-           WINS_LIST, strerror(errno) ));
-    return True;
-  }
-
-  while (!x_feof(fp))
-  {
-    pstring name_str, ip_str, ttl_str, nb_flags_str;
-    unsigned int num_ips;
-    pstring name;
-    struct in_addr *ip_list;
-    int type = 0;
-    int nb_flags;
-    int ttl;
-    const char *ptr;
-    char *p;
-    BOOL got_token;
-    BOOL was_ip;
-    int i;
-    unsigned hash;
-    int version;
-
-    /* Read a line from the wins.dat file. Strips whitespace
-       from the beginning and end of the line.
-     */
-    if (!fgets_slash(line,sizeof(pstring),fp))
-      continue;
+       time_t time_now = time(NULL);
+       XFILE *fp;
+       pstring line;
+
+       if(!lp_we_are_a_wins_server())
+               return True;
+
+       add_samba_names_to_subnet(wins_server_subnet);
+
+       if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) {
+               DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
+                       WINS_LIST, strerror(errno) ));
+               return True;
+       }
+
+       while (!x_feof(fp)) {
+               pstring name_str, ip_str, ttl_str, nb_flags_str;
+               unsigned int num_ips;
+               pstring name;
+               struct in_addr *ip_list;
+               int type = 0;
+               int nb_flags;
+               int ttl;
+               const char *ptr;
+               char *p;
+               BOOL got_token;
+               BOOL was_ip;
+               int i;
+               unsigned int hash;
+               int version;
+
+               /* Read a line from the wins.dat file. Strips whitespace
+                       from the beginning and end of the line.  */
+               if (!fgets_slash(line,sizeof(pstring),fp))
+                       continue;
       
-    if (*line == '#')
-      continue;
-
-    if (strncmp(line,"VERSION ", 8) == 0) {
-           if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
-               version != WINS_VERSION) {
-                   DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line));
-                   x_fclose(fp);
-                   return True;
-           }
-           continue;
-    }
-
-    ptr = line;
-
-    /* 
-     * Now we handle multiple IP addresses per name we need
-     * to iterate over the line twice. The first time to
-     * determine how many IP addresses there are, the second
-     * time to actually parse them into the ip_list array.
-     */
-
-    if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) 
-    {
-      DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line ));
-      continue;
-    }
-
-    if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)))
-    {
-      DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line ));
-      continue;
-    }
-
-    /*
-     * Determine the number of IP addresses per line.
-     */
-    num_ips = 0;
-    do
-    {
-      got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str));
-      was_ip = False;
-
-      if(got_token && strchr(ip_str, '.'))
-      {
-        num_ips++;
-        was_ip = True;
-      }
-    } while( got_token && was_ip);
-
-    if(num_ips == 0)
-    {
-      DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line ));
-      continue;
-    }
-
-    if(!got_token)
-    {
-      DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line ));
-      continue;
-    }
-
-    /* Allocate the space for the ip_list. */
-    if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL)
-    {
-      DEBUG(0,("initialise_wins: Malloc fail !\n"));
-      return False;
-    }
+               if (*line == '#')
+                       continue;
+
+               if (strncmp(line,"VERSION ", 8) == 0) {
+                       if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
+                                               version != WINS_VERSION) {
+                               DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line));
+                               x_fclose(fp);
+                               return True;
+                       }
+                       continue;
+               }
+
+               ptr = line;
+
+               /* 
+                * Now we handle multiple IP addresses per name we need
+                * to iterate over the line twice. The first time to
+                * determine how many IP addresses there are, the second
+                * time to actually parse them into the ip_list array.
+                */
+
+               if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) {
+                       DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line ));
+                       continue;
+               }
+
+               if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) {
+                       DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line ));
+                       continue;
+               }
+
+               /*
+                * Determine the number of IP addresses per line.
+                */
+               num_ips = 0;
+               do {
+                       got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str));
+                       was_ip = False;
+
+                       if(got_token && strchr(ip_str, '.')) {
+                               num_ips++;
+                               was_ip = True;
+                       }
+               } while( got_token && was_ip);
+
+               if(num_ips == 0) {
+                       DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line ));
+                       continue;
+               }
+
+               if(!got_token) {
+                       DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line ));
+                       continue;
+               }
+
+               /* Allocate the space for the ip_list. */
+               if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) {
+                       DEBUG(0,("initialise_wins: Malloc fail !\n"));
+                       return False;
+               }
  
-    /* Reset and re-parse the line. */
-    ptr = line;
-    next_token(&ptr,name_str,NULL,sizeof(name_str)); 
-    next_token(&ptr,ttl_str,NULL,sizeof(ttl_str));
-    for(i = 0; i < num_ips; i++)
-    {
-      next_token(&ptr, ip_str, NULL, sizeof(ip_str));
-      ip_list[i] = *interpret_addr2(ip_str);
-    }
-    next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str));
-
-    /* 
-     * Deal with SELF or REGISTER name encoding. Default is REGISTER
-     * for compatibility with old nmbds.
-     */
-
-    if(nb_flags_str[strlen(nb_flags_str)-1] == 'S')
-    {
-      DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line));
-      SAFE_FREE(ip_list);
-      continue;
-    }
+               /* Reset and re-parse the line. */
+               ptr = line;
+               next_token(&ptr,name_str,NULL,sizeof(name_str)); 
+               next_token(&ptr,ttl_str,NULL,sizeof(ttl_str));
+               for(i = 0; i < num_ips; i++) {
+                       next_token(&ptr, ip_str, NULL, sizeof(ip_str));
+                       ip_list[i] = *interpret_addr2(ip_str);
+               }
+               next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str));
+
+               /* 
+                * Deal with SELF or REGISTER name encoding. Default is REGISTER
+                * for compatibility with old nmbds.
+                */
+
+               if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') {
+                       DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line));
+                       SAFE_FREE(ip_list);
+                       continue;
+               }
       
-    if(nb_flags_str[strlen(nb_flags_str)-1] == 'R')
-      nb_flags_str[strlen(nb_flags_str)-1] = '\0';
+               if(nb_flags_str[strlen(nb_flags_str)-1] == 'R')
+                       nb_flags_str[strlen(nb_flags_str)-1] = '\0';
       
-    /* Netbios name. # divides the name from the type (hex): netbios#xx */
-    pstrcpy(name,name_str);
+               /* Netbios name. # divides the name from the type (hex): netbios#xx */
+               pstrcpy(name,name_str);
       
-    if((p = strchr(name,'#')) != NULL)
-    {
-      *p = 0;
-      sscanf(p+1,"%x",&type);
-    }
+               if((p = strchr(name,'#')) != NULL) {
+                       *p = 0;
+                       sscanf(p+1,"%x",&type);
+               }
       
-    /* Decode the netbios flags (hex) and the time-to-live (in seconds). */
-    sscanf(nb_flags_str,"%x",&nb_flags);
-    sscanf(ttl_str,"%d",&ttl);
-
-    /* add all entries that have 60 seconds or more to live */
-    if ((ttl - 60) > time_now || ttl == PERMANENT_TTL)
-    {
-      if(ttl != PERMANENT_TTL)
-        ttl -= time_now;
+               /* Decode the netbios flags (hex) and the time-to-live (in seconds). */
+               sscanf(nb_flags_str,"%x",&nb_flags);
+               sscanf(ttl_str,"%d",&ttl);
+
+               /* add all entries that have 60 seconds or more to live */
+               if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) {
+                       if(ttl != PERMANENT_TTL)
+                               ttl -= time_now;
     
-      DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n",
-           name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
-
-      (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, 
-                                    ttl, REGISTER_NAME, num_ips, ip_list );
-
-    }
-    else
-    {
-      DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n",
-             name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
-    }
+                       DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n",
+                               name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
+
+                       (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, 
+                                       ttl, REGISTER_NAME, num_ips, ip_list );
+               } else {
+                       DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n",
+                               name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
+               }
 
-    SAFE_FREE(ip_list);
-  } 
+               SAFE_FREE(ip_list);
+       
     
-  x_fclose(fp);
-  return True;
+       x_fclose(fp);
+       return True;
 }
 
 /****************************************************************************
@@ -400,30 +381,33 @@ Send a WINS WACK (Wait ACKnowledgement) response.
 
 static void send_wins_wack_response(int ttl, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  unsigned char rdata[2];
-
-  rdata[0] = rdata[1] = 0;
-
-  /* Taken from nmblib.c - we need to send back almost
-     identical bytes from the requesting packet header. */
-
-  rdata[0] = (nmb->header.opcode & 0xF) << 3;
-  if (nmb->header.nm_flags.authoritative &&
-      nmb->header.response) rdata[0] |= 0x4;
-  if (nmb->header.nm_flags.trunc) rdata[0] |= 0x2;
-  if (nmb->header.nm_flags.recursion_desired) rdata[0] |= 0x1;
-  if (nmb->header.nm_flags.recursion_available &&
-      nmb->header.response) rdata[1] |= 0x80;
-  if (nmb->header.nm_flags.bcast) rdata[1] |= 0x10;
-
-  reply_netbios_packet(p,                             /* Packet to reply to. */
-                       0,                             /* Result code. */
-                       NMB_WAIT_ACK,                  /* nmbd type code. */
-                       NMB_WACK_OPCODE,               /* opcode. */
-                       ttl,                           /* ttl. */
-                       (char *)rdata,                 /* data to send. */
-                       2);                            /* data length. */
+       struct nmb_packet *nmb = &p->packet.nmb;
+       unsigned char rdata[2];
+
+       rdata[0] = rdata[1] = 0;
+
+       /* Taken from nmblib.c - we need to send back almost
+               identical bytes from the requesting packet header. */
+
+       rdata[0] = (nmb->header.opcode & 0xF) << 3;
+       if (nmb->header.nm_flags.authoritative && nmb->header.response)
+               rdata[0] |= 0x4;
+       if (nmb->header.nm_flags.trunc)
+               rdata[0] |= 0x2;
+       if (nmb->header.nm_flags.recursion_desired)
+               rdata[0] |= 0x1;
+       if (nmb->header.nm_flags.recursion_available && nmb->header.response)
+               rdata[1] |= 0x80;
+       if (nmb->header.nm_flags.bcast)
+               rdata[1] |= 0x10;
+
+       reply_netbios_packet(p,                                /* Packet to reply to. */
+                               0,                             /* Result code. */
+                               NMB_WAIT_ACK,                  /* nmbd type code. */
+                               NMB_WACK_OPCODE,               /* opcode. */
+                               ttl,                           /* ttl. */
+                               (char *)rdata,                 /* data to send. */
+                               2);                            /* data length. */
 }
 
 /****************************************************************************
@@ -432,18 +416,18 @@ Send a WINS name registration response.
 
 static void send_wins_name_registration_response(int rcode, int ttl, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  char rdata[6];
-
-  memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
-
-  reply_netbios_packet(p,                             /* Packet to reply to. */
-                       rcode,                         /* Result code. */
-                       WINS_REG,                      /* nmbd type code. */
-                       NMB_NAME_REG_OPCODE,           /* opcode. */
-                       ttl,                           /* ttl. */
-                       rdata,                         /* data to send. */
-                       6);                            /* data length. */
+       struct nmb_packet *nmb = &p->packet.nmb;
+       char rdata[6];
+
+       memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
+
+       reply_netbios_packet(p,                                /* Packet to reply to. */
+                               rcode,                         /* Result code. */
+                               WINS_REG,                      /* nmbd type code. */
+                               NMB_NAME_REG_OPCODE,           /* opcode. */
+                               ttl,                           /* ttl. */
+                               rdata,                         /* data to send. */
+                               6);                            /* data length. */
 }
 
 /***********************************************************************
@@ -453,139 +437,128 @@ static void send_wins_name_registration_response(int rcode, int ttl, struct pack
 void wins_process_name_refresh_request(struct subnet_record *subrec,
                                             struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  BOOL group = (nb_flags & NB_GROUP) ? True : False;
-  struct name_record *namerec = NULL;
-  int ttl = get_ttl_from_packet(nmb);
-  struct in_addr from_ip;
-  struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
-
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-
-  if(bcast)
-  {
-    /*
-     * We should only get unicast name refresh packets here.
-     * Anyone trying to refresh broadcast should not be going to a WINS
-     * server. Log an error here.
-     */
-
-    DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       struct name_record *namerec = NULL;
+       int ttl = get_ttl_from_packet(nmb);
+       struct in_addr from_ip;
+       struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+
+       if(bcast) {
+               /*
+                * We should only get unicast name refresh packets here.
+                * Anyone trying to refresh broadcast should not be going to a WINS
+                * server. Log an error here.
+                */
+
+               DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \
 received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               return;
+       }
 
-  DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \
+       DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \
 IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) ));
 
-  /* 
-   * See if the name already exists.
-   */
+       /* 
+        * See if the name already exists.
+        */
 
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
 
-  /*
-   * If this is a refresh request and the name doesn't exist then
-   * treat it like a registration request. This allows us to recover 
-   * from errors (tridge)
-   */
+       /*
+        * If this is a refresh request and the name doesn't exist then
+        * treat it like a registration request. This allows us to recover 
+        * from errors (tridge)
+        */
 
-  if(namerec == NULL)
-  {
-    DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \
+       if(namerec == NULL) {
+               DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \
 the name does not exist. Treating as registration.\n", nmb_namestr(question) ));
-    wins_process_name_registration_request(subrec,p);
-    return;
-  }
-
-  /*
-   * if the name is present but not active,
-   * simply remove it and treat the request
-   * as a registration
-   */
-  if (namerec != NULL && !WINS_STATE_ACTIVE(namerec))
-  {
-    DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \
+               wins_process_name_registration_request(subrec,p);
+               return;
+       }
+
+       /*
+        * if the name is present but not active,
+        * simply remove it and treat the request
+        * as a registration
+        */
+       if (namerec != NULL && !WINS_STATE_ACTIVE(namerec)) {
+               DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \
 not active - removing it.\n", nmb_namestr(question) ));
-    remove_name_from_namelist( subrec, namerec );
-    namerec = NULL;
-    wins_process_name_registration_request(subrec,p);
-    return;
-  }
-
-  /*
-   * Check that the group bits for the refreshing name and the
-   * name in our database match.
-   */
-
-  if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) )
-  {
-    DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \
+               remove_name_from_namelist( subrec, namerec );
+               namerec = NULL;
+               wins_process_name_registration_request(subrec,p);
+               return;
+       }
+
+       /*
+        * Check that the group bits for the refreshing name and the
+        * name in our database match.
+        */
+
+       if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) {
+               DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \
 does not match group bit in WINS for this name.\n", nmb_namestr(question), group ? "True" : "False" ));
-    send_wins_name_registration_response(RFS_ERR, 0, p);
-    return;
-  }
-
-  /*
-   * For a unique name check that the person refreshing the name is one of the registered IP
-   * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c.
-   * Just return success for unique 0x1d refreshes. For normal group names update the ttl
-   * and return success.
-   */
-
-  if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip ))
-  {
-    /*
-     * Update the ttl.
-     */
-    update_name_ttl(namerec, ttl);
-
-    /*
-     * if the record is a replica:
-     * we take ownership and update the version ID.
-     */
-    if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
-       update_wins_owner(namerec, our_fake_ip);
-       get_global_id_and_update(&namerec->data.id, True);
-    }
-
-    send_wins_name_registration_response(0, ttl, p);
-    wins_hook("refresh", namerec, ttl);
-    return;
-  }
-  else if(group)
-  {
-    /* 
-     * Normal groups are all registered with an IP address of 255.255.255.255 
-     * so we can't search for the IP address.
-     */
-    update_name_ttl(namerec, ttl);
-    send_wins_name_registration_response(0, ttl, p);
-    return;
-  }
-  else if(!group && (question->name_type == 0x1d))
-  {
-    /*
-     * Special name type - just pretend the refresh succeeded.
-     */
-    send_wins_name_registration_response(0, ttl, p);
-    return;
-  }
-  else
-  {
-    /*
-     * Fail the refresh.
-     */
-
-    DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \
+               send_wins_name_registration_response(RFS_ERR, 0, p);
+               return;
+       }
+
+       /*
+        * For a unique name check that the person refreshing the name is one of the registered IP
+        * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c.
+        * Just return success for unique 0x1d refreshes. For normal group names update the ttl
+        * and return success.
+        */
+
+       if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip )) {
+               /*
+                * Update the ttl.
+                */
+               update_name_ttl(namerec, ttl);
+
+               /*
+                * if the record is a replica:
+                * we take ownership and update the version ID.
+                */
+               if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
+                       update_wins_owner(namerec, our_fake_ip);
+                       get_global_id_and_update(&namerec->data.id, True);
+               }
+
+               send_wins_name_registration_response(0, ttl, p);
+               wins_hook("refresh", namerec, ttl);
+               return;
+       } else if(group) {
+               /* 
+                * Normal groups are all registered with an IP address of 255.255.255.255 
+                * so we can't search for the IP address.
+                */
+               update_name_ttl(namerec, ttl);
+               send_wins_name_registration_response(0, ttl, p);
+               return;
+       } else if(!group && (question->name_type == 0x1d)) {
+               /*
+                * Special name type - just pretend the refresh succeeded.
+                */
+               send_wins_name_registration_response(0, ttl, p);
+               return;
+       } else {
+               /*
+                * Fail the refresh.
+                */
+
+               DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \
 is IP is not known to the name.\n", nmb_namestr(question), inet_ntoa(from_ip) ));
-    send_wins_name_registration_response(RFS_ERR, 0, p);
-    return;
-  }
+               send_wins_name_registration_response(RFS_ERR, 0, p);
+               return;
+       }
 }
 
 /***********************************************************************
@@ -604,17 +577,17 @@ static void wins_register_query_success(struct subnet_record *subrec,
                                              struct in_addr ip,
                                              struct res_rec *answers)
 {
-  struct packet_struct *orig_reg_packet;
+       struct packet_struct *orig_reg_packet;
 
-  memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
+       memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
 
-  DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \
+       DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \
 name %s. Rejecting registration request.\n", inet_ntoa(ip), nmb_namestr(question_name) ));
 
-  send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
+       send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
 
-  orig_reg_packet->locked = False;
-  free_packet(orig_reg_packet);
+       orig_reg_packet->locked = False;
+       free_packet(orig_reg_packet);
 }
 
 /***********************************************************************
@@ -632,40 +605,37 @@ static void wins_register_query_fail(struct subnet_record *subrec,
                                           struct nmb_name *question_name,
                                           int rcode)
 {
-  struct userdata_struct *userdata = rrec->userdata;
-  struct packet_struct *orig_reg_packet;
-  struct name_record *namerec = NULL;
-
-  memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
-
-  /*
-   * We want to just add the name, as we now know the original owner
-   * didn't want it. But we can't just do that as an arbitary
-   * amount of time may have taken place between the name query
-   * request and this timeout/error response. So we check that
-   * the name still exists and is in the same state - if so
-   * we remove it and call wins_process_name_registration_request()
-   * as we know it will do the right thing now.
-   */
-
-  namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME);
-
-  if( (namerec != NULL)
-   && (namerec->data.source == REGISTER_NAME)
-   && ip_equal(rrec->packet->ip, *namerec->data.ip) )
-  {
-    remove_name_from_namelist( subrec, namerec);
-    namerec = NULL;
-  }
-
-  if(namerec == NULL)
-    wins_process_name_registration_request(subrec, orig_reg_packet);
-  else
-    DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \
+       struct userdata_struct *userdata = rrec->userdata;
+       struct packet_struct *orig_reg_packet;
+       struct name_record *namerec = NULL;
+
+       memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
+
+       /*
+        * We want to just add the name, as we now know the original owner
+        * didn't want it. But we can't just do that as an arbitary
+        * amount of time may have taken place between the name query
+        * request and this timeout/error response. So we check that
+        * the name still exists and is in the same state - if so
+        * we remove it and call wins_process_name_registration_request()
+        * as we know it will do the right thing now.
+        */
+
+       namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME);
+
+       if( (namerec != NULL) && (namerec->data.source == REGISTER_NAME) && ip_equal(rrec->packet->ip, *namerec->data.ip) ) {
+               remove_name_from_namelist( subrec, namerec);
+               namerec = NULL;
+       }
+
+       if(namerec == NULL)
+               wins_process_name_registration_request(subrec, orig_reg_packet);
+       else
+               DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \
 querying for name %s in order to replace it and this reply.\n", nmb_namestr(question_name) ));
 
-  orig_reg_packet->locked = False;
-  free_packet(orig_reg_packet);
+       orig_reg_packet->locked = False;
+       free_packet(orig_reg_packet);
 }
 
 /***********************************************************************
@@ -728,279 +698,271 @@ querying for name %s in order to replace it and this reply.\n", nmb_namestr(ques
 void wins_process_name_registration_request(struct subnet_record *subrec,
                                             struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  int ttl = get_ttl_from_packet(nmb);
-  struct name_record *namerec = NULL;
-  struct in_addr from_ip;
-  BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;
-  struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
-
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-
-  if(bcast)
-  {
-    /*
-     * We should only get unicast name registration packets here.
-     * Anyone trying to register broadcast should not be going to a WINS
-     * server. Log an error here.
-     */
-
-    DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \
+       nstring name;
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       int ttl = get_ttl_from_packet(nmb);
+       struct name_record *namerec = NULL;
+       struct in_addr from_ip;
+       BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;
+       struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+
+       if(bcast) {
+               /*
+                * We should only get unicast name registration packets here.
+                * Anyone trying to register broadcast should not be going to a WINS
+                * server. Log an error here.
+                */
+
+               DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \
 received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               return;
+       }
 
-  DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \
+       DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \
 IP %s\n", registering_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) ));
 
-  /*
-   * See if the name already exists.
-   */
+       /*
+        * See if the name already exists.
+        */
 
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
 
-  /*
-   * if the record exists but NOT in active state,
-   * consider it dead.
-   */
-  if ( (namerec != NULL) && !WINS_STATE_ACTIVE(namerec))
-  {
-    DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \
+       /*
+        * if the record exists but NOT in active state,
+        * consider it dead.
+        */
+       if ( (namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) {
+               DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \
 not active - removing it.\n", nmb_namestr(question) ));
-    remove_name_from_namelist( subrec, namerec );
-    namerec = NULL;
-  }
-
-  /*
-   * Deal with the case where the name found was a dns entry.
-   * Remove it as we now have a NetBIOS client registering the
-   * name.
-   */
-
-  if( (namerec != NULL)
-   && ( (namerec->data.source == DNS_NAME)
-     || (namerec->data.source == DNSFAIL_NAME) ) )
-  {
-    DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \
+               remove_name_from_namelist( subrec, namerec );
+               namerec = NULL;
+       }
+
+       /*
+        * Deal with the case where the name found was a dns entry.
+        * Remove it as we now have a NetBIOS client registering the
+        * name.
+        */
+
+       if( (namerec != NULL) && ( (namerec->data.source == DNS_NAME) || (namerec->data.source == DNSFAIL_NAME) ) ) {
+               DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \
 a dns lookup - removing it.\n", nmb_namestr(question) ));
-    remove_name_from_namelist( subrec, namerec );
-    namerec = NULL;
-  }
-
-  /*
-   * Reject if the name exists and is not a REGISTER_NAME.
-   * (ie. Don't allow any static names to be overwritten.
-   */
-
-  if((namerec != NULL) && (namerec->data.source != REGISTER_NAME))
-  {
-    DEBUG( 3, ( "wins_process_name_registration_request: Attempt \
+               remove_name_from_namelist( subrec, namerec );
+               namerec = NULL;
+       }
+
+       /*
+        * Reject if the name exists and is not a REGISTER_NAME.
+        * (ie. Don't allow any static names to be overwritten.
+        */
+
+       if((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) {
+               DEBUG( 3, ( "wins_process_name_registration_request: Attempt \
 to register name %s. Name already exists in WINS with source type %d.\n",
-                nmb_namestr(question), namerec->data.source ));
-    send_wins_name_registration_response(RFS_ERR, 0, p);
-    return;
-  }
-
-  /*
-   * Special policy decisions based on MS documentation.
-   * 1). All group names (except names ending in 0x1c) are added as 255.255.255.255.
-   * 2). All unique names ending in 0x1d are ignored, although a positive response is sent.
-   */
-
-  /*
-   * A group name is always added as the local broadcast address, except
-   * for group names ending in 0x1c.
-   * Group names with type 0x1c are registered with individual IP addresses.
-   */
-
-  if(registering_group_name && (question->name_type != 0x1c))
-    from_ip = *interpret_addr2("255.255.255.255");
-
-  /*
-   * Ignore all attempts to register a unique 0x1d name, although return success.
-   */
-
-  if(!registering_group_name && (question->name_type == 0x1d))
-  {
-    DEBUG(3,("wins_process_name_registration_request: Ignoring request \
+                       nmb_namestr(question), namerec->data.source ));
+               send_wins_name_registration_response(RFS_ERR, 0, p);
+               return;
+       }
+
+       /*
+        * Special policy decisions based on MS documentation.
+        * 1). All group names (except names ending in 0x1c) are added as 255.255.255.255.
+        * 2). All unique names ending in 0x1d are ignored, although a positive response is sent.
+        */
+
+       /*
+        * A group name is always added as the local broadcast address, except
+        * for group names ending in 0x1c.
+        * Group names with type 0x1c are registered with individual IP addresses.
+        */
+
+       if(registering_group_name && (question->name_type != 0x1c))
+               from_ip = *interpret_addr2("255.255.255.255");
+
+       /*
+        * Ignore all attempts to register a unique 0x1d name, although return success.
+        */
+
+       if(!registering_group_name && (question->name_type == 0x1d)) {
+               DEBUG(3,("wins_process_name_registration_request: Ignoring request \
 to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) ));
-    send_wins_name_registration_response(0, ttl, p);
-    return;
-  }
-
-  /*
-   * Next two cases are the 'if statement' mentioned above.
-   */
-
-  if((namerec != NULL) && NAME_GROUP(namerec))
-  {
-    if(registering_group_name)
-    {
-      /*
-       * If we are adding a group name, the name exists and is also a group entry just add this
-       * IP address to it and update the ttl.
-       */
-
-      DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n",
-            inet_ntoa(from_ip), nmb_namestr(question) ));
-      /* 
-       * Check the ip address is not already in the group.
-       */
-      if(!find_ip_in_name_record(namerec, from_ip)) {
-        add_ip_to_name_record(namerec, from_ip);
-       /* we need to update the record for replication */
-        get_global_id_and_update(&namerec->data.id, True);
+               send_wins_name_registration_response(0, ttl, p);
+               return;
+       }
 
        /*
-        * if the record is a replica, we must change
-        * the wins owner to us to make the replication updates
-        * it on the other wins servers.
-        * And when the partner will receive this record,
-        * it will update its own record.
+        * Next two cases are the 'if statement' mentioned above.
         */
 
-       update_wins_owner(namerec, our_fake_ip);
+       if((namerec != NULL) && NAME_GROUP(namerec)) {
+               if(registering_group_name) {
+                       /*
+                        * If we are adding a group name, the name exists and is also a group entry just add this
+                        * IP address to it and update the ttl.
+                        */
+
+                       DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n",
+                               inet_ntoa(from_ip), nmb_namestr(question) ));
+
+                       /* 
+                        * Check the ip address is not already in the group.
+                        */
+
+                       if(!find_ip_in_name_record(namerec, from_ip)) {
+                               add_ip_to_name_record(namerec, from_ip);
+                               /* we need to update the record for replication */
+                               get_global_id_and_update(&namerec->data.id, True);
+
+                               /*
+                                * if the record is a replica, we must change
+                                * the wins owner to us to make the replication updates
+                                * it on the other wins servers.
+                                * And when the partner will receive this record,
+                                * it will update its own record.
+                                */
+
+                               update_wins_owner(namerec, our_fake_ip);
+                       }
+                       update_name_ttl(namerec, ttl);
+                       send_wins_name_registration_response(0, ttl, p);
+                       return;
+               } else {
 
-      }
-      update_name_ttl(namerec, ttl);
-      send_wins_name_registration_response(0, ttl, p);
-      return;
-    }
-    else
-    {
-      /*
-       * If we are adding a unique name, the name exists in the WINS db 
-       * and is a group name then reject the registration.
-       *
-       * explanation: groups have a higher priority than unique names.
-       */
-
-      DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
+                       /*
+                        * If we are adding a unique name, the name exists in the WINS db 
+                        * and is a group name then reject the registration.
+                        *
+                        * explanation: groups have a higher priority than unique names.
+                        */
+
+                       DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
 already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
-      send_wins_name_registration_response(RFS_ERR, 0, p);
-      return;
-    } 
-  }
-
-  /*
-   * From here on down we know that if the name exists in the WINS db it is
-   * a unique name, not a group name.
-   */
-
-  /* 
-   * If the name exists and is one of our names then check the
-   * registering IP address. If it's not one of ours then automatically
-   * reject without doing the query - we know we will reject it.
-   */
-
-  if((namerec != NULL) && (is_myname(namerec->name.name)) )
-  {
-    if(!ismyip(from_ip))
-    {
-      DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
+                       send_wins_name_registration_response(RFS_ERR, 0, p);
+                       return;
+               } 
+       }
+
+       /*
+        * From here on down we know that if the name exists in the WINS db it is
+        * a unique name, not a group name.
+        */
+
+       /* 
+        * If the name exists and is one of our names then check the
+        * registering IP address. If it's not one of ours then automatically
+        * reject without doing the query - we know we will reject it.
+        */
+
+       if ( namerec != NULL )
+               pull_ascii_nstring(name, namerec->name.name);
+               
+       if( is_myname(name) ) {
+               if(!ismyip(from_ip)) {
+                       DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
 is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
-      send_wins_name_registration_response(RFS_ERR, 0, p);
-      return;
-    }
-    else
-    {
-      /*
-       * It's one of our names and one of our IP's - update the ttl.
-       */
-      update_name_ttl(namerec, ttl);
-      send_wins_name_registration_response(0, ttl, p);
-      wins_hook("refresh", namerec, ttl);
-      return;
-    }
-  }
-
-  /*
-   * If the name exists and it is a unique registration and the registering IP 
-   * is the same as the (single) already registered IP then just update the ttl.
-   *
-   * But not if the record is an active replica. IF it's a replica, it means it can be
-   * the same client which has moved and not yet expired. So we don't update
-   * the ttl in this case and go beyond to do a WACK and query the old client
-   */
-
-  if( !registering_group_name
-   && (namerec != NULL)
-   && (namerec->data.num_ips == 1)
-   && ip_equal( namerec->data.ip[0], from_ip )
-   && ip_equal(namerec->data.wins_ip, our_fake_ip) )
-  {
-    update_name_ttl( namerec, ttl );
-    send_wins_name_registration_response( 0, ttl, p );
-    wins_hook("refresh", namerec, ttl);
-    return;
-  }
-
-  /*
-   * Finally if the name exists do a query to the registering machine 
-   * to see if they still claim to have the name.
-   */
-
-  if( namerec != NULL )
-  {
-    long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1];
-    struct userdata_struct *userdata = (struct userdata_struct *)ud;
-
-    /*
-     * First send a WACK to the registering machine.
-     */
-
-    send_wins_wack_response(60, p);
-
-    /*
-     * When the reply comes back we need the original packet.
-     * Lock this so it won't be freed and then put it into
-     * the userdata structure.
-     */
-
-    p->locked = True;
-
-    userdata = (struct userdata_struct *)ud;
-
-    userdata->copy_fn = NULL;
-    userdata->free_fn = NULL;
-    userdata->userdata_len = sizeof(struct packet_struct *);
-    memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) );
-
-    /*
-     * Use the new call to send a query directly to an IP address.
-     * This sends the query directly to the IP address, and ensures
-     * the recursion desired flag is not set (you were right Luke :-).
-     * This function should *only* be called from the WINS server
-     * code. JRA.
-     */
-
-    query_name_from_wins_server( *namerec->data.ip,
-                                  question->name,
-                                  question->name_type, 
-                                  wins_register_query_success,
-                                  wins_register_query_fail,
-                                  userdata );
-    return;
-  }
-
-  /*
-   * Name did not exist - add it.
-   */
-
-  (void)add_name_to_subnet( subrec, question->name, question->name_type,
-                            nb_flags, ttl, REGISTER_NAME, 1, &from_ip);
-  if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) {
-       get_global_id_and_update(&namerec->data.id, True);
-       update_wins_owner(namerec, our_fake_ip);
-       update_wins_flag(namerec, WINS_ACTIVE);
-       wins_hook("add", namerec, ttl);
-  }
+                       send_wins_name_registration_response(RFS_ERR, 0, p);
+                       return;
+               } else {
+                       /*
+                        * It's one of our names and one of our IP's - update the ttl.
+                        */
+                       update_name_ttl(namerec, ttl);
+                       send_wins_name_registration_response(0, ttl, p);
+                       wins_hook("refresh", namerec, ttl);
+                       return;
+               }
+       }
+
+       /*
+        * If the name exists and it is a unique registration and the registering IP 
+        * is the same as the (single) already registered IP then just update the ttl.
+        *
+        * But not if the record is an active replica. IF it's a replica, it means it can be
+        * the same client which has moved and not yet expired. So we don't update
+        * the ttl in this case and go beyond to do a WACK and query the old client
+        */
 
-  send_wins_name_registration_response(0, ttl, p);
+       if( !registering_group_name
+                       && (namerec != NULL)
+                       && (namerec->data.num_ips == 1)
+                       && ip_equal( namerec->data.ip[0], from_ip )
+                       && ip_equal(namerec->data.wins_ip, our_fake_ip) ) {
+               update_name_ttl( namerec, ttl );
+               send_wins_name_registration_response( 0, ttl, p );
+               wins_hook("refresh", namerec, ttl);
+               return;
+       }
+
+       /*
+        * Finally if the name exists do a query to the registering machine 
+        * to see if they still claim to have the name.
+        */
+
+       if( namerec != NULL ) {
+               long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1];
+               struct userdata_struct *userdata = (struct userdata_struct *)ud;
+
+               /*
+                * First send a WACK to the registering machine.
+                */
+
+               send_wins_wack_response(60, p);
+
+               /*
+                * When the reply comes back we need the original packet.
+                * Lock this so it won't be freed and then put it into
+                * the userdata structure.
+                */
+
+               p->locked = True;
+
+               userdata = (struct userdata_struct *)ud;
+
+               userdata->copy_fn = NULL;
+               userdata->free_fn = NULL;
+               userdata->userdata_len = sizeof(struct packet_struct *);
+               memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) );
+
+               /*
+                * Use the new call to send a query directly to an IP address.
+                * This sends the query directly to the IP address, and ensures
+                * the recursion desired flag is not set (you were right Luke :-).
+                * This function should *only* be called from the WINS server
+                * code. JRA.
+                */
+
+               pull_ascii_nstring(name, question->name);
+               query_name_from_wins_server( *namerec->data.ip,
+                               name,
+                               question->name_type, 
+                               wins_register_query_success,
+                               wins_register_query_fail,
+                               userdata );
+               return;
+       }
+
+       /*
+        * Name did not exist - add it.
+        */
+
+       pull_ascii_nstring(name, question->name);
+       add_name_to_subnet( subrec, name, question->name_type,
+                       nb_flags, ttl, REGISTER_NAME, 1, &from_ip);
+
+       if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) {
+               get_global_id_and_update(&namerec->data.id, True);
+               update_wins_owner(namerec, our_fake_ip);
+               update_wins_flag(namerec, WINS_ACTIVE);
+               wins_hook("add", namerec, ttl);
+       }
+
+       send_wins_name_registration_response(0, ttl, p);
 }
 
 /***********************************************************************
@@ -1017,55 +979,54 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec,
                                              struct in_addr ip,
                                              struct res_rec *answers)
 {
-  struct packet_struct *orig_reg_packet;
-  struct nmb_packet *nmb;
-  struct name_record *namerec = NULL;
-  struct in_addr from_ip;
-  int ttl;
-  struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
-
-  memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
-
-  nmb = &orig_reg_packet->packet.nmb;
-
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-  ttl = get_ttl_from_packet(nmb);
-
-  /*
-   * We want to just add the new IP, as we now know the requesting
-   * machine claims to own it. But we can't just do that as an arbitary
-   * amount of time may have taken place between the name query
-   * request and this response. So we check that
-   * the name still exists and is in the same state - if so
-   * we just add the extra IP and update the ttl.
-   */
-
-  namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME);
-
-  if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) )
-  {
-    DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \
+       struct packet_struct *orig_reg_packet;
+       struct nmb_packet *nmb;
+       struct name_record *namerec = NULL;
+       struct in_addr from_ip;
+       int ttl;
+       struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+
+       memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
+
+       nmb = &orig_reg_packet->packet.nmb;
+
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+       ttl = get_ttl_from_packet(nmb);
+
+       /*
+        * We want to just add the new IP, as we now know the requesting
+        * machine claims to own it. But we can't just do that as an arbitary
+        * amount of time may have taken place between the name query
+        * request and this response. So we check that
+        * the name still exists and is in the same state - if so
+        * we just add the extra IP and update the ttl.
+        */
+
+       namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME);
+
+       if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) ) {
+               DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \
 a subsequent IP address.\n", nmb_namestr(question_name) ));
-    send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
+               send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
 
-    orig_reg_packet->locked = False;
-    free_packet(orig_reg_packet);
+               orig_reg_packet->locked = False;
+               free_packet(orig_reg_packet);
 
-    return;
-  }
+               return;
+       }
 
-  if(!find_ip_in_name_record(namerec, from_ip))
-    add_ip_to_name_record(namerec, from_ip);
+       if(!find_ip_in_name_record(namerec, from_ip))
+               add_ip_to_name_record(namerec, from_ip);
 
-  get_global_id_and_update(&namerec->data.id, True);
-  update_wins_owner(namerec, our_fake_ip);
-  update_wins_flag(namerec, WINS_ACTIVE);
-  update_name_ttl(namerec, ttl);
-  send_wins_name_registration_response(0, ttl, orig_reg_packet);
-  wins_hook("add", namerec, ttl);
+       get_global_id_and_update(&namerec->data.id, True);
+       update_wins_owner(namerec, our_fake_ip);
+       update_wins_flag(namerec, WINS_ACTIVE);
+       update_name_ttl(namerec, ttl);
+       send_wins_name_registration_response(0, ttl, orig_reg_packet);
+       wins_hook("add", namerec, ttl);
 
-  orig_reg_packet->locked = False;
-  free_packet(orig_reg_packet);
+       orig_reg_packet->locked = False;
+       free_packet(orig_reg_packet);
 }
 
 /***********************************************************************
@@ -1081,18 +1042,18 @@ static void wins_multihomed_register_query_fail(struct subnet_record *subrec,
                                           struct nmb_name *question_name,
                                           int rcode)
 {
-  struct userdata_struct *userdata = rrec->userdata;
-  struct packet_struct *orig_reg_packet;
+       struct userdata_struct *userdata = rrec->userdata;
+       struct packet_struct *orig_reg_packet;
 
-  memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
+       memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
 
-  DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \
+       DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \
 query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), nmb_namestr(question_name) ));
-  send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
+       send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
 
-  orig_reg_packet->locked = False;
-  free_packet(orig_reg_packet);
-  return;
+       orig_reg_packet->locked = False;
+       free_packet(orig_reg_packet);
+       return;
 }
 
 /***********************************************************************
@@ -1103,250 +1064,241 @@ query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), nmb_namestr(
 void wins_process_multihomed_name_registration_request( struct subnet_record *subrec,
                                                         struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  int ttl = get_ttl_from_packet(nmb);
-  struct name_record *namerec = NULL;
-  struct in_addr from_ip;
-  BOOL group = (nb_flags & NB_GROUP) ? True : False;
-  struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
-
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-
-  if(bcast)
-  {
-    /*
-     * We should only get unicast name registration packets here.
-     * Anyone trying to register broadcast should not be going to a WINS
-     * server. Log an error here.
-     */
-
-    DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       int ttl = get_ttl_from_packet(nmb);
+       struct name_record *namerec = NULL;
+       struct in_addr from_ip;
+       BOOL group = (nb_flags & NB_GROUP) ? True : False;
+       struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+       nstring qname;
+
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+
+       if(bcast) {
+               /*
+                * We should only get unicast name registration packets here.
+                * Anyone trying to register broadcast should not be going to a WINS
+                * server. Log an error here.
+                */
+
+               DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \
 received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               return;
+       }
 
-  /*
-   * Only unique names should be registered multihomed.
-   */
+       /*
+        * Only unique names should be registered multihomed.
+        */
 
-  if(group)
-  {
-    DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \
+       if(group) {
+               DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \
 received for name %s from IP %s on subnet %s. Errror - group names should not be multihomed.\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               return;
+       }
 
-  DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \
+       DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \
 IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) ));
 
-  /*
-   * Deal with policy regarding 0x1d names.
-   */
+       /*
+        * Deal with policy regarding 0x1d names.
+        */
 
-  if(question->name_type == 0x1d)
-  {
-    DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \
+       if(question->name_type == 0x1d) {
+               DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \
 to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) ));
-    send_wins_name_registration_response(0, ttl, p);  
-    return;
-  }
-
-  /*
-   * See if the name already exists.
-   */
-
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
-
-  /*
-   * if the record exists but NOT in active state,
-   * consider it dead.
-   */
-  if ((namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) {
-         DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was not active - removing it.\n", nmb_namestr(question)));
-         remove_name_from_namelist(subrec, namerec);
-         namerec = NULL;
-  }
+               send_wins_name_registration_response(0, ttl, p);  
+               return;
+       }
+
+       /*
+        * See if the name already exists.
+        */
+
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+
+       /*
+        * if the record exists but NOT in active state,
+        * consider it dead.
+        */
+
+       if ((namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) {
+               DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was not active - removing it.\n", nmb_namestr(question)));
+               remove_name_from_namelist(subrec, namerec);
+               namerec = NULL;
+       }
   
-  /*
-   * Deal with the case where the name found was a dns entry.
-   * Remove it as we now have a NetBIOS client registering the
-   * name.
-   */
-
-  if( (namerec != NULL)
-   && ( (namerec->data.source == DNS_NAME)
-     || (namerec->data.source == DNSFAIL_NAME) ) )
-  {
-    DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \
+       /*
+        * Deal with the case where the name found was a dns entry.
+        * Remove it as we now have a NetBIOS client registering the
+        * name.
+        */
+
+       if( (namerec != NULL) && ( (namerec->data.source == DNS_NAME) || (namerec->data.source == DNSFAIL_NAME) ) ) {
+               DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \
 - removing it.\n", nmb_namestr(question) ));
-    remove_name_from_namelist( subrec, namerec);
-    namerec = NULL;
-  }
-
-  /*
-   * Reject if the name exists and is not a REGISTER_NAME.
-   * (ie. Don't allow any static names to be overwritten.
-   */
-
-  if( (namerec != NULL) && (namerec->data.source != REGISTER_NAME) )
-  {
-    DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \
+               remove_name_from_namelist( subrec, namerec);
+               namerec = NULL;
+       }
+
+       /*
+        * Reject if the name exists and is not a REGISTER_NAME.
+        * (ie. Don't allow any static names to be overwritten.
+        */
+
+       if( (namerec != NULL) && (namerec->data.source != REGISTER_NAME) ) {
+               DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \
 to register name %s. Name already exists in WINS with source type %d.\n",
-    nmb_namestr(question), namerec->data.source ));
-    send_wins_name_registration_response(RFS_ERR, 0, p);
-    return;
-  }
-
-  /*
-   * Reject if the name exists and is a GROUP name and is active.
-   */
-
-  if((namerec != NULL) && NAME_GROUP(namerec) && WINS_STATE_ACTIVE(namerec))
-  {
-    DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
+                       nmb_namestr(question), namerec->data.source ));
+               send_wins_name_registration_response(RFS_ERR, 0, p);
+               return;
+       }
+
+       /*
+        * Reject if the name exists and is a GROUP name and is active.
+        */
+
+       if((namerec != NULL) && NAME_GROUP(namerec) && WINS_STATE_ACTIVE(namerec)) {
+               DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
 already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
-    send_wins_name_registration_response(RFS_ERR, 0, p);
-    return;
-  } 
-
-  /*
-   * From here on down we know that if the name exists in the WINS db it is
-   * a unique name, not a group name.
-   */
-
-  /*
-   * If the name exists and is one of our names then check the
-   * registering IP address. If it's not one of ours then automatically
-   * reject without doing the query - we know we will reject it.
-   */
-
-  if((namerec != NULL) && (is_myname(namerec->name.name)) )
-  {
-    if(!ismyip(from_ip))
-    {
-      DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
+               send_wins_name_registration_response(RFS_ERR, 0, p);
+               return;
+       } 
+
+       /*
+        * From here on down we know that if the name exists in the WINS db it is
+        * a unique name, not a group name.
+        */
+
+       /*
+        * If the name exists and is one of our names then check the
+        * registering IP address. If it's not one of ours then automatically
+        * reject without doing the query - we know we will reject it.
+        */
+
+       if((namerec != NULL) && (is_myname(namerec->name.name)) ) {
+               if(!ismyip(from_ip)) {
+                       DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
 is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
-      send_wins_name_registration_response(RFS_ERR, 0, p);
-      return;
-    }
-    else
-    {
-      /*
-       * It's one of our names and one of our IP's. Ensure the IP is in the record and
-       *  update the ttl. Update the version ID to force replication.
-       */
-           if(!find_ip_in_name_record(namerec, from_ip)) {
-                   get_global_id_and_update(&namerec->data.id, True);
-                   update_wins_owner(namerec, our_fake_ip);
-                   update_wins_flag(namerec, WINS_ACTIVE);
-
-                   add_ip_to_name_record(namerec, from_ip);
-                   wins_hook("add", namerec, ttl);
-           } else {
-                   wins_hook("refresh", namerec, ttl);
-           }
-
-           update_name_ttl(namerec, ttl);
-           send_wins_name_registration_response(0, ttl, p);
-           return;
-    }
-  }
-
-  /*
-   * If the name exists and is active, check if the IP address is already registered
-   * to that name. If so then update the ttl and reply success.
-   */
-
-  if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip) && WINS_STATE_ACTIVE(namerec))
-  {
-    update_name_ttl(namerec, ttl);
-    /*
-     * If it's a replica, we need to become the wins owner
-     * to force the replication
-     */
-    if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
-      get_global_id_and_update(&namerec->data.id, True);
-      update_wins_owner(namerec, our_fake_ip);
-      update_wins_flag(namerec, WINS_ACTIVE);
-    }
+                       send_wins_name_registration_response(RFS_ERR, 0, p);
+                       return;
+               } else {
+                       /*
+                        * It's one of our names and one of our IP's. Ensure the IP is in the record and
+                        *  update the ttl. Update the version ID to force replication.
+                        */
+                       if(!find_ip_in_name_record(namerec, from_ip)) {
+                               get_global_id_and_update(&namerec->data.id, True);
+                               update_wins_owner(namerec, our_fake_ip);
+                               update_wins_flag(namerec, WINS_ACTIVE);
+
+                               add_ip_to_name_record(namerec, from_ip);
+                               wins_hook("add", namerec, ttl);
+                       } else {
+                               wins_hook("refresh", namerec, ttl);
+                       }
+
+                       update_name_ttl(namerec, ttl);
+                       send_wins_name_registration_response(0, ttl, p);
+                       return;
+               }
+       }
+
+       /*
+        * If the name exists and is active, check if the IP address is already registered
+        * to that name. If so then update the ttl and reply success.
+        */
+
+       if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip) && WINS_STATE_ACTIVE(namerec)) {
+               update_name_ttl(namerec, ttl);
+
+               /*
+                * If it's a replica, we need to become the wins owner
+                * to force the replication
+                */
+               if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
+                       get_global_id_and_update(&namerec->data.id, True);
+                       update_wins_owner(namerec, our_fake_ip);
+                       update_wins_flag(namerec, WINS_ACTIVE);
+               }
     
-    send_wins_name_registration_response(0, ttl, p);
-    wins_hook("refresh", namerec, ttl);
-    return;
-  }
-
-  /*
-   * If the name exists do a query to the owner
-   * to see if they still want the name.
-   */
-
-  if(namerec != NULL)
-  {
-    long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1];
-    struct userdata_struct *userdata = (struct userdata_struct *)ud;
-
-    /*
-     * First send a WACK to the registering machine.
-     */
-
-    send_wins_wack_response(60, p);
-
-    /*
-     * When the reply comes back we need the original packet.
-     * Lock this so it won't be freed and then put it into
-     * the userdata structure.
-     */
-
-    p->locked = True;
-
-    userdata = (struct userdata_struct *)ud;
-
-    userdata->copy_fn = NULL;
-    userdata->free_fn = NULL;
-    userdata->userdata_len = sizeof(struct packet_struct *);
-    memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) );
-
-    /* 
-     * Use the new call to send a query directly to an IP address.
-     * This sends the query directly to the IP address, and ensures
-     * the recursion desired flag is not set (you were right Luke :-).
-     * This function should *only* be called from the WINS server
-     * code. JRA.
-     *
-     * Note that this packet is sent to the current owner of the name,
-     * not the person who sent the packet 
-     */
-
-    query_name_from_wins_server( namerec->data.ip[0],
-                                 question->name,
-                                 question->name_type, 
-                                 wins_multihomed_register_query_success,
-                                 wins_multihomed_register_query_fail,
-                                 userdata );
-
-    return;
-  }
-
-  /*
-   * Name did not exist - add it.
-   */
-
-  (void)add_name_to_subnet( subrec, question->name, question->name_type,
-                            nb_flags, ttl, REGISTER_NAME, 1, &from_ip);
-
-  if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) {
-         get_global_id_and_update(&namerec->data.id, True);
-         update_wins_owner(namerec, our_fake_ip);
-         update_wins_flag(namerec, WINS_ACTIVE);
-         wins_hook("add", namerec, ttl);
-  }
-
-  send_wins_name_registration_response(0, ttl, p);
+               send_wins_name_registration_response(0, ttl, p);
+               wins_hook("refresh", namerec, ttl);
+               return;
+       }
+
+       /*
+        * If the name exists do a query to the owner
+        * to see if they still want the name.
+        */
+
+       if(namerec != NULL) {
+               long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1];
+               struct userdata_struct *userdata = (struct userdata_struct *)ud;
+
+               /*
+                * First send a WACK to the registering machine.
+                */
+
+               send_wins_wack_response(60, p);
+
+               /*
+                * When the reply comes back we need the original packet.
+                * Lock this so it won't be freed and then put it into
+                * the userdata structure.
+                */
+
+               p->locked = True;
+
+               userdata = (struct userdata_struct *)ud;
+
+               userdata->copy_fn = NULL;
+               userdata->free_fn = NULL;
+               userdata->userdata_len = sizeof(struct packet_struct *);
+               memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) );
+
+               /* 
+                * Use the new call to send a query directly to an IP address.
+                * This sends the query directly to the IP address, and ensures
+                * the recursion desired flag is not set (you were right Luke :-).
+                * This function should *only* be called from the WINS server
+                * code. JRA.
+                *
+                * Note that this packet is sent to the current owner of the name,
+                * not the person who sent the packet 
+                */
+
+               pull_ascii_nstring( qname, question->name);
+               query_name_from_wins_server( namerec->data.ip[0],
+                               qname,
+                               question->name_type, 
+                               wins_multihomed_register_query_success,
+                               wins_multihomed_register_query_fail,
+                               userdata );
+
+               return;
+       }
+
+       /*
+        * Name did not exist - add it.
+        */
+
+       pull_ascii_nstring( qname, question->name);
+       add_name_to_subnet( subrec, qname, question->name_type,
+                       nb_flags, ttl, REGISTER_NAME, 1, &from_ip);
+
+       if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) {
+               get_global_id_and_update(&namerec->data.id, True);
+               update_wins_owner(namerec, our_fake_ip);
+               update_wins_flag(namerec, WINS_ACTIVE);
+               wins_hook("add", namerec, ttl);
+       }
+
+       send_wins_name_registration_response(0, ttl, p);
 }
 
 /***********************************************************************
@@ -1356,76 +1308,68 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio
 static void process_wins_dmb_query_request(struct subnet_record *subrec,  
                                            struct packet_struct *p)
 {  
-  struct name_record *namerec = NULL;
-  char *prdata;
-  int num_ips;
-
-  /*
-   * Go through all the ACTIVE names in the WINS db looking for those
-   * ending in <1b>. Use this to calculate the number of IP
-   * addresses we need to return.
-   */
-
-  num_ips = 0;
-  for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-       namerec;
-       namerec = (struct name_record *)ubi_trNext( namerec ) )
-  {
-    if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b )
-      num_ips += namerec->data.num_ips;
-  }
-
-  if(num_ips == 0)
-  {
-    /*
-     * There are no 0x1b names registered. Return name query fail.
-     */
-    send_wins_name_query_response(NAM_ERR, p, NULL);
-    return;
-  }
-
-  if((prdata = (char *)malloc( num_ips * 6 )) == NULL)
-  {
-    DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
-    return;
-  }
-
-  /*
-   * Go through all the names again in the WINS db looking for those
-   * ending in <1b>. Add their IP addresses into the list we will
-   * return.
-   */ 
-
-  num_ips = 0;
-  for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
-       namerec;
-       namerec = (struct name_record *)ubi_trNext( namerec ) )
-  {
-    if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b)
-    {
-      int i;
-      for(i = 0; i < namerec->data.num_ips; i++)
-      {
-        set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags);
-        putip((char *)&prdata[(num_ips * 6) + 2], &namerec->data.ip[i]);
-        num_ips++;
-      }
-    }
-  }
-
-  /*
-   * Send back the reply containing the IP list.
-   */
-
-  reply_netbios_packet(p,                             /* Packet to reply to. */
-                       0,                             /* Result code. */
-                       WINS_QUERY,                    /* nmbd type code. */
-                       NMB_NAME_QUERY_OPCODE,         /* opcode. */
-                       lp_min_wins_ttl(),             /* ttl. */
-                       prdata,                        /* data to send. */
-                       num_ips*6);                    /* data length. */
-
-  SAFE_FREE(prdata);
+       struct name_record *namerec = NULL;
+       char *prdata;
+       int num_ips;
+
+       /*
+        * Go through all the ACTIVE names in the WINS db looking for those
+        * ending in <1b>. Use this to calculate the number of IP
+        * addresses we need to return.
+        */
+
+       num_ips = 0;
+       for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
+                       namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) {
+               if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b )
+                       num_ips += namerec->data.num_ips;
+       }
+
+       if(num_ips == 0) {
+               /*
+                * There are no 0x1b names registered. Return name query fail.
+                */
+               send_wins_name_query_response(NAM_ERR, p, NULL);
+               return;
+       }
+
+       if((prdata = (char *)malloc( num_ips * 6 )) == NULL) {
+               DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
+               return;
+       }
+
+       /*
+        * Go through all the names again in the WINS db looking for those
+        * ending in <1b>. Add their IP addresses into the list we will
+        * return.
+        */ 
+
+       num_ips = 0;
+       for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
+                       namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) {
+               if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) {
+                       int i;
+                       for(i = 0; i < namerec->data.num_ips; i++) {
+                               set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags);
+                               putip((char *)&prdata[(num_ips * 6) + 2], &namerec->data.ip[i]);
+                               num_ips++;
+                       }
+               }
+       }
+
+       /*
+        * Send back the reply containing the IP list.
+        */
+
+       reply_netbios_packet(p,                                /* Packet to reply to. */
+                               0,                             /* Result code. */
+                               WINS_QUERY,                    /* nmbd type code. */
+                               NMB_NAME_QUERY_OPCODE,         /* opcode. */
+                               lp_min_wins_ttl(),             /* ttl. */
+                               prdata,                        /* data to send. */
+                               num_ips*6);                    /* data length. */
+
+       SAFE_FREE(prdata);
 }
 
 /****************************************************************************
@@ -1435,55 +1379,48 @@ Send a WINS name query response.
 void send_wins_name_query_response(int rcode, struct packet_struct *p, 
                                           struct name_record *namerec)
 {
-  char rdata[6];
-  char *prdata = rdata;
-  int reply_data_len = 0;
-  int ttl = 0;
-  int i;
-
-  memset(rdata,'\0',6);
-
-  if(rcode == 0)
-  {
-    ttl = (namerec->data.death_time != PERMANENT_TTL) ?
-             namerec->data.death_time - p->timestamp : lp_max_wins_ttl();
-
-    /* Copy all known ip addresses into the return data. */
-    /* Optimise for the common case of one IP address so
-       we don't need a malloc. */
-
-    if( namerec->data.num_ips == 1 )
-      prdata = rdata;
-    else
-    {
-      if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL)
-      {
-        DEBUG(0,("send_wins_name_query_response: malloc fail !\n"));
-        return;
-      }
-    }
-
-    for(i = 0; i < namerec->data.num_ips; i++)
-    {
-      set_nb_flags(&prdata[i*6],namerec->data.nb_flags);
-      putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]);
-    }
-
-    sort_query_replies(prdata, i, p->ip);
-
-    reply_data_len = namerec->data.num_ips * 6;
-  }
-
-  reply_netbios_packet(p,                             /* Packet to reply to. */
-                       rcode,                         /* Result code. */
-                       WINS_QUERY,                    /* nmbd type code. */
-                       NMB_NAME_QUERY_OPCODE,         /* opcode. */
-                       ttl,                           /* ttl. */
-                       prdata,                        /* data to send. */
-                       reply_data_len);               /* data length. */
-
-  if(prdata != rdata)
-    SAFE_FREE(prdata);
+       char rdata[6];
+       char *prdata = rdata;
+       int reply_data_len = 0;
+       int ttl = 0;
+       int i;
+
+       memset(rdata,'\0',6);
+
+       if(rcode == 0) {
+               ttl = (namerec->data.death_time != PERMANENT_TTL) ?  namerec->data.death_time - p->timestamp : lp_max_wins_ttl();
+
+               /* Copy all known ip addresses into the return data. */
+               /* Optimise for the common case of one IP address so we don't need a malloc. */
+
+               if( namerec->data.num_ips == 1 ) {
+                       prdata = rdata;
+               } else {
+                       if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) {
+                               DEBUG(0,("send_wins_name_query_response: malloc fail !\n"));
+                               return;
+                       }
+               }
+
+               for(i = 0; i < namerec->data.num_ips; i++) {
+                       set_nb_flags(&prdata[i*6],namerec->data.nb_flags);
+                       putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]);
+               }
+
+               sort_query_replies(prdata, i, p->ip);
+               reply_data_len = namerec->data.num_ips * 6;
+       }
+
+       reply_netbios_packet(p,                                /* Packet to reply to. */
+                               rcode,                         /* Result code. */
+                               WINS_QUERY,                    /* nmbd type code. */
+                               NMB_NAME_QUERY_OPCODE,         /* opcode. */
+                               ttl,                           /* ttl. */
+                               prdata,                        /* data to send. */
+                               reply_data_len);               /* data length. */
+
+       if(prdata != rdata)
+               SAFE_FREE(prdata);
 }
 
 /***********************************************************************
@@ -1493,93 +1430,87 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p,
 void wins_process_name_query_request(struct subnet_record *subrec, 
                                      struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  struct name_record *namerec = NULL;
-
-  DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", 
-            nmb_namestr(question), inet_ntoa(p->ip) ));
-
-  /*
-   * Special name code. If the queried name is *<1b> then search
-   * the entire WINS database and return a list of all the IP addresses
-   * registered to any <1b> name. This is to allow domain master browsers
-   * to discover other domains that may not have a presence on their subnet.
-   */
-
-  if(strequal( question->name, "*") && (question->name_type == 0x1b))
-  {
-    process_wins_dmb_query_request( subrec, p);
-    return;
-  }
-
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
-
-  if(namerec != NULL)
-  {
-    /*
-     * If the name is not anymore in active state then reply not found.
-     * it's fair even if we keep it in the cache for days.
-     */
-    if (!WINS_STATE_ACTIVE(namerec))
-    {
-      DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n",
-             nmb_namestr(question) ));
-      send_wins_name_query_response(NAM_ERR, p, namerec);
-      return;
-    }
-    /* 
-     * If it's a DNSFAIL_NAME then reply name not found.
-     */
-
-    if( namerec->data.source == DNSFAIL_NAME )
-    {
-      DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n",
-             nmb_namestr(question) ));
-      send_wins_name_query_response(NAM_ERR, p, namerec);
-      return;
-    }
-
-    /*
-     * If the name has expired then reply name not found.
-     */
-
-    if( (namerec->data.death_time != PERMANENT_TTL)
-     && (namerec->data.death_time < p->timestamp) )
-    {
-      DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n",
-                nmb_namestr(question) ));
-      send_wins_name_query_response(NAM_ERR, p, namerec);
-      return;
-    }
-
-    DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n",
-           nmb_namestr(question), inet_ntoa(namerec->data.ip[0]) ));
-
-    send_wins_name_query_response(0, p, namerec);
-    return;
-  }
-
-  /* 
-   * Name not found in WINS - try a dns query if it's a 0x20 name.
-   */
-
-  if(lp_dns_proxy() && 
-     ((question->name_type == 0x20) || question->name_type == 0))
-  {
-
-    DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n",
-              nmb_namestr(question) ));
-
-    queue_dns_query(p, question, &namerec);
-    return;
-  }
-
-  /*
-   * Name not found - return error.
-   */
-
-  send_wins_name_query_response(NAM_ERR, p, NULL);
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       struct name_record *namerec = NULL;
+       nstring qname;
+
+       DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", 
+               nmb_namestr(question), inet_ntoa(p->ip) ));
+
+       /*
+        * Special name code. If the queried name is *<1b> then search
+        * the entire WINS database and return a list of all the IP addresses
+        * registered to any <1b> name. This is to allow domain master browsers
+        * to discover other domains that may not have a presence on their subnet.
+        */
+
+       pull_ascii_nstring(qname, question->name);
+       if(strequal( qname, "*") && (question->name_type == 0x1b)) {
+               process_wins_dmb_query_request( subrec, p);
+               return;
+       }
+
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+
+       if(namerec != NULL) {
+               /*
+                * If the name is not anymore in active state then reply not found.
+                * it's fair even if we keep it in the cache for days.
+                */
+               if (!WINS_STATE_ACTIVE(namerec)) {
+                       DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n",
+                               nmb_namestr(question) ));
+                       send_wins_name_query_response(NAM_ERR, p, namerec);
+                       return;
+               }
+
+               /* 
+                * If it's a DNSFAIL_NAME then reply name not found.
+                */
+
+               if( namerec->data.source == DNSFAIL_NAME ) {
+                       DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n",
+                               nmb_namestr(question) ));
+                       send_wins_name_query_response(NAM_ERR, p, namerec);
+                       return;
+               }
+
+               /*
+                * If the name has expired then reply name not found.
+                */
+
+               if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < p->timestamp) ) {
+                       DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n",
+                                       nmb_namestr(question) ));
+                       send_wins_name_query_response(NAM_ERR, p, namerec);
+                       return;
+               }
+
+               DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n",
+                               nmb_namestr(question), inet_ntoa(namerec->data.ip[0]) ));
+
+               send_wins_name_query_response(0, p, namerec);
+               return;
+       }
+
+       /* 
+        * Name not found in WINS - try a dns query if it's a 0x20 name.
+        */
+
+       if(lp_dns_proxy() && ((question->name_type == 0x20) || question->name_type == 0)) {
+               DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n",
+                               nmb_namestr(question) ));
+
+               queue_dns_query(p, question, &namerec);
+               return;
+       }
+
+       /*
+        * Name not found - return error.
+        */
+
+       send_wins_name_query_response(NAM_ERR, p, NULL);
 }
 
 /****************************************************************************
@@ -1588,18 +1519,18 @@ Send a WINS name release response.
 
 static void send_wins_name_release_response(int rcode, struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  char rdata[6];
-
-  memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
-
-  reply_netbios_packet(p,                            /* Packet to reply to. */
-                       rcode,                        /* Result code. */
-                       NMB_REL,                      /* nmbd type code. */
-                       NMB_NAME_RELEASE_OPCODE,      /* opcode. */
-                       0,                            /* ttl. */
-                       rdata,                        /* data to send. */
-                       6);                           /* data length. */
+       struct nmb_packet *nmb = &p->packet.nmb;
+       char rdata[6];
+
+       memcpy(&rdata[0], &nmb->additional->rdata[0], 6);
+
+       reply_netbios_packet(p,                               /* Packet to reply to. */
+                               rcode,                        /* Result code. */
+                               NMB_REL,                      /* nmbd type code. */
+                               NMB_NAME_RELEASE_OPCODE,      /* opcode. */
+                               0,                            /* ttl. */
+                               rdata,                        /* data to send. */
+                               6);                           /* data length. */
 }
 
 /***********************************************************************
@@ -1609,123 +1540,115 @@ static void send_wins_name_release_response(int rcode, struct packet_struct *p)
 void wins_process_name_release_request(struct subnet_record *subrec,
                                        struct packet_struct *p)
 {
-  struct nmb_packet *nmb = &p->packet.nmb;
-  struct nmb_name *question = &nmb->question.question_name;
-  BOOL bcast = nmb->header.nm_flags.bcast;
-  uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
-  struct name_record *namerec = NULL;
-  struct in_addr from_ip;
-  BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
-
-  putip((char *)&from_ip,&nmb->additional->rdata[2]);
-
-  if(bcast)
-  {
-    /*
-     * We should only get unicast name registration packets here.
-     * Anyone trying to register broadcast should not be going to a WINS
-     * server. Log an error here.
-     */
-
-    DEBUG(0,("wins_process_name_release_request: broadcast name registration request \
+       struct nmb_packet *nmb = &p->packet.nmb;
+       struct nmb_name *question = &nmb->question.question_name;
+       BOOL bcast = nmb->header.nm_flags.bcast;
+       uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
+       struct name_record *namerec = NULL;
+       struct in_addr from_ip;
+       BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
+
+       putip((char *)&from_ip,&nmb->additional->rdata[2]);
+
+       if(bcast) {
+               /*
+                * We should only get unicast name registration packets here.
+                * Anyone trying to register broadcast should not be going to a WINS
+                * server. Log an error here.
+                */
+
+               DEBUG(0,("wins_process_name_release_request: broadcast name registration request \
 received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n",
-          nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
-    return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name));
+               return;
+       }
   
-  DEBUG(3,("wins_process_name_release_request: %s name release for name %s \
+       DEBUG(3,("wins_process_name_release_request: %s name release for name %s \
 IP %s\n", releasing_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) ));
     
-  /*
-   * Deal with policy regarding 0x1d names.
-   */
+       /*
+        * Deal with policy regarding 0x1d names.
+        */
 
-  if(!releasing_group_name && (question->name_type == 0x1d))
-  {
-    DEBUG(3,("wins_process_name_release_request: Ignoring request \
+       if(!releasing_group_name && (question->name_type == 0x1d)) {
+               DEBUG(3,("wins_process_name_release_request: Ignoring request \
 to release name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) ));
-    send_wins_name_release_response(0, p);
-    return;
-  }
+               send_wins_name_release_response(0, p);
+               return;
+       }
 
-  /*
-   * See if the name already exists.
-   */
+       /*
+        * See if the name already exists.
+        */
     
-  namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
-
-  if( (namerec == NULL)
-   || ((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) )
-  {
-    send_wins_name_release_response(NAM_ERR, p);
-    return;
-  }
-
-  /* 
-   * Check that the sending machine has permission to release this name.
-   * If it's a group name not ending in 0x1c then just say yes and let
-   * the group time out.
-   */
-
-  if(releasing_group_name && (question->name_type != 0x1c))
-  {
-    send_wins_name_release_response(0, p);
-    return;
-  }
-
-  /* 
-   * Check that the releasing node is on the list of IP addresses
-   * for this name. Disallow the release if not.
-   */
-
-  if(!find_ip_in_name_record(namerec, from_ip))
-  {
-    DEBUG(3,("wins_process_name_release_request: Refusing request to \
+       namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME);
+
+       if( (namerec == NULL) || ((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) ) {
+               send_wins_name_release_response(NAM_ERR, p);
+               return;
+       }
+
+       /* 
+        * Check that the sending machine has permission to release this name.
+        * If it's a group name not ending in 0x1c then just say yes and let
+        * the group time out.
+        */
+
+       if(releasing_group_name && (question->name_type != 0x1c)) {
+               send_wins_name_release_response(0, p);
+               return;
+       }
+
+       /* 
+        * Check that the releasing node is on the list of IP addresses
+        * for this name. Disallow the release if not.
+        */
+
+       if(!find_ip_in_name_record(namerec, from_ip)) {
+               DEBUG(3,("wins_process_name_release_request: Refusing request to \
 release name %s as IP %s is not one of the known IP's for this name.\n",
-           nmb_namestr(question), inet_ntoa(from_ip) ));
-    send_wins_name_release_response(NAM_ERR, p);
-    return;
-  }    
-
-  /*
-   * Check if the record is active. IF it's already released
-   * or tombstoned, refuse the release.
-   */
-  if (!WINS_STATE_ACTIVE(namerec)) {
-    DEBUG(3,("wins_process_name_release_request: Refusing request to \
-release name %s as this record is not anymore active.\n",
-           nmb_namestr(question) ));
-    send_wins_name_release_response(NAM_ERR, p);
-    return;
-  }    
-
-  /*
-   * Check if the record is a 0x1c group
-   * and has more then one ip
-   * remove only this address.
-   */
-
-  if(releasing_group_name &&
-               (question->name_type == 0x1c) &&
-               (namerec->data.num_ips > 1)) {
-       remove_ip_from_name_record(namerec, from_ip);
-       DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n",
-                       inet_ntoa(from_ip),nmb_namestr(question)));
-       send_wins_name_release_response(0, p);
-       return;
-  }
+                       nmb_namestr(question), inet_ntoa(from_ip) ));
+               send_wins_name_release_response(NAM_ERR, p);
+               return;
+       }
+
+       /*
+        * Check if the record is active. IF it's already released
+        * or tombstoned, refuse the release.
+        */
 
-  /* 
-   * Send a release response.
-   * Flag the name as released and update the ttl
-   */
+       if (!WINS_STATE_ACTIVE(namerec)) {
+               DEBUG(3,("wins_process_name_release_request: Refusing request to \
+release name %s as this record is not active anymore.\n", nmb_namestr(question) ));
+               send_wins_name_release_response(NAM_ERR, p);
+               return;
+       }    
+
+       /*
+        * Check if the record is a 0x1c group
+        * and has more then one ip
+        * remove only this address.
+        */
+
+       if(releasing_group_name && (question->name_type == 0x1c) && (namerec->data.num_ips > 1)) {
+               remove_ip_from_name_record(namerec, from_ip);
+               DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n",
+                               inet_ntoa(from_ip),nmb_namestr(question)));
+               send_wins_name_release_response(0, p);
+               return;
+       }
+
+       /* 
+        * Send a release response.
+        * Flag the name as released and update the ttl
+        */
 
-  send_wins_name_release_response(0, p);
+       send_wins_name_release_response(0, p);
   
-  namerec->data.wins_flags |= WINS_RELEASED;
-  update_name_ttl(namerec, EXTINCTION_INTERVAL);
+       namerec->data.wins_flags |= WINS_RELEASED;
+       update_name_ttl(namerec, EXTINCTION_INTERVAL);
 
-  wins_hook("delete", namerec, 0);
+       wins_hook("delete", namerec, 0);
 }
 
 /*******************************************************************
@@ -1817,94 +1740,89 @@ we are not the wins owner !\n", nmb_namestr(&namerec->name)));
 /*******************************************************************
  Write out the current WINS database.
 ******************************************************************/
+
 void wins_write_database(BOOL background)
 {
-  struct name_record *namerec;
-  pstring fname, fnamenew;
+       struct name_record *namerec;
+       pstring fname, fnamenew;
 
-  XFILE *fp;
+       XFILE *fp;
    
-  if(!lp_we_are_a_wins_server())
-    return;
-
-  /* we will do the writing in a child process to ensure that the parent
-     doesn't block while this is done */
-  if (background) {
-         CatchChild();
-         if (sys_fork()) {
-                 return;
-         }
-  }
-
-  slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST);
-  all_string_sub(fname,"//", "/", 0);
-  slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid());
-
-  if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL)
-  {
-    DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno)));
-    if (background) {
-           _exit(0);
-    }
-    return;
-  }
-
-  DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
-
-  x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0);
+       if(!lp_we_are_a_wins_server())
+               return;
+
+       /* We will do the writing in a child process to ensure that the parent doesn't block while this is done */
+       if (background) {
+               CatchChild();
+               if (sys_fork()) {
+                       return;
+               }
+       }
+
+       slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST);
+       all_string_sub(fname,"//", "/", 0);
+       slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid());
+
+       if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) {
+               DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno)));
+               if (background) {
+                       _exit(0);
+               }
+               return;
+       }
+
+       DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
+
+       x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0);
  
-  for( namerec 
-           = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist );
-       namerec;
-       namerec = (struct name_record *)ubi_trNext( namerec ) )
-  {
-    int i;
-    struct tm *tm;
-
-    DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) ));
-
-    if( namerec->data.death_time != PERMANENT_TTL )
-    {
-      char *ts, *nl;
-
-      tm = LocalTime(&namerec->data.death_time);
-      ts = asctime(tm);
-      nl = strrchr( ts, '\n' );
-      if( NULL != nl )
-        *nl = '\0';
-      DEBUGADD(4,("TTL = %s  ", ts ));
-    }
-    else
-      DEBUGADD(4,("TTL = PERMANENT                 "));
-
-    for (i = 0; i < namerec->data.num_ips; i++)
-      DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) ));
-    DEBUGADD(4,("%2x\n", namerec->data.nb_flags ));
-
-    if( namerec->data.source == REGISTER_NAME )
-    {
-      x_fprintf(fp, "\"%s#%02x\" %d ",
-               namerec->name.name,namerec->name.name_type, /* Ignore scope. */
-               (int)namerec->data.death_time);
-
-      for (i = 0; i < namerec->data.num_ips; i++)
-        x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) );
-      x_fprintf( fp, "%2xR\n", namerec->data.nb_flags );
-    }
-  }
+       for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) {
+               int i;
+               struct tm *tm;
+
+               DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) ));
+
+               if( namerec->data.death_time != PERMANENT_TTL ) {
+                       char *ts, *nl;
+
+                       tm = LocalTime(&namerec->data.death_time);
+                       ts = asctime(tm);
+                       nl = strrchr( ts, '\n' );
+                       if( NULL != nl )
+                               *nl = '\0';
+                       DEBUGADD(4,("TTL = %s  ", ts ));
+               } else {
+                       DEBUGADD(4,("TTL = PERMANENT                 "));
+               }
+
+               for (i = 0; i < namerec->data.num_ips; i++)
+                       DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) ));
+               DEBUGADD(4,("%2x\n", namerec->data.nb_flags ));
+
+               if( namerec->data.source == REGISTER_NAME ) {
+                       nstring name;
+                       pull_ascii_nstring(name, namerec->name.name);
+                       x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */
+                               (int)namerec->data.death_time);
+
+                       for (i = 0; i < namerec->data.num_ips; i++)
+                               x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) );
+                       x_fprintf( fp, "%2xR\n", namerec->data.nb_flags );
+               }
+       }
   
-  x_fclose(fp);
-  chmod(fnamenew,0644);
-  unlink(fname);
-  rename(fnamenew,fname);
-  if (background) {
-         _exit(0);
-  }
+       x_fclose(fp);
+       chmod(fnamenew,0644);
+       unlink(fname);
+       rename(fnamenew,fname);
+       if (background) {
+               _exit(0);
+       }
 }
 
 /****************************************************************************
-process a internal Samba message receiving a wins record
+ Process a internal Samba message receiving a wins record.
 ***************************************************************************/
+
 void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len)
 {
        WINS_RECORD *record;
@@ -1918,11 +1836,10 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len)
        if (buf==NULL)
                return;
        
+       /* Record should use UNIX codepage. Ensure this is so in the wrepld code. JRA. */
        record=(WINS_RECORD *)buf;
        
-       ZERO_STRUCT(question);
-       memcpy(question.name, record->name, 16);
-       question.name_type=record->type;
+       make_nmb_name(&question, record->name, record->type);
 
        namerec = find_name_on_subnet(wins_server_subnet, &question, FIND_ANY_NAME);
 
@@ -1994,9 +1911,9 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len)
                                for (i=0; i<record->num_ips; i++)
                                        if(!find_ip_in_name_record(namerec, record->ip[i]))
                                                add_ip_to_name_record(namerec, record->ip[i]);
-                       }
-                       else
+                       } else {
                                overwrite=True;
+                       }
                }
                
                /* the replica is a multihomed host */
@@ -2050,11 +1967,3 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len)
 
        }
 }
-
-
-
-
-
-
-
-
index 2357fd637b572e6449544fcdd60e4282818747db..b9fab4b278c12508cfc2273bc9b7b6ec5cdee5a3 100644 (file)
@@ -31,7 +31,7 @@ int workgroup_count = 0; /* unique index key: one for each workgroup */
 
 /****************************************************************************
   Add a workgroup into the list.
-  **************************************************************************/
+**************************************************************************/
 
 static void add_workgroup(struct subnet_record *subrec, struct work_record *work)
 {
@@ -42,164 +42,160 @@ static void add_workgroup(struct subnet_record *subrec, struct work_record *work
 
 /****************************************************************************
   Create an empty workgroup.
-  **************************************************************************/
+**************************************************************************/
 
 static struct work_record *create_workgroup(const char *name, int ttl)
 {
-  struct work_record *work;
-  struct subnet_record *subrec;
-  int t = -1;
+       struct work_record *work;
+       struct subnet_record *subrec;
+       int t = -1;
   
-  if((work = (struct work_record *)malloc(sizeof(*work))) == NULL)
-  {
-    DEBUG(0,("create_workgroup: malloc fail !\n"));
-    return NULL;
-  }
-  memset((char *)work, '\0', sizeof(*work));
+       if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) {
+               DEBUG(0,("create_workgroup: malloc fail !\n"));
+               return NULL;
+       }
+       memset((char *)work, '\0', sizeof(*work));
  
-  fstrcpy(work->work_group,name);
-  work->serverlist = NULL;
+       if (strlen(name)+1 > sizeof(nstring)) {
+               memcpy(work->work_group,name,sizeof(nstring)-1);
+               work->work_group[sizeof(nstring)-1] = '\0';
+               DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n",
+                               name, work->work_group ));
+       } else {
+               nstrcpy(work->work_group,name);
+       }
+       work->serverlist = NULL;
   
-  work->RunningElection = False;
-  work->ElectionCount = 0;
-  work->announce_interval = 0;
-  work->needelection = False;
-  work->needannounce = True;
-  work->lastannounce_time = time(NULL);
-  work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
-  work->dom_state = DOMAIN_NONE;
-  work->log_state = LOGON_NONE;
+       work->RunningElection = False;
+       work->ElectionCount = 0;
+       work->announce_interval = 0;
+       work->needelection = False;
+       work->needannounce = True;
+       work->lastannounce_time = time(NULL);
+       work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+       work->dom_state = DOMAIN_NONE;
+       work->log_state = LOGON_NONE;
   
-  work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL;
+       work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL;
 
-  /* Make sure all token representations of workgroups are unique. */
+       /* Make sure all token representations of workgroups are unique. */
   
-  for (subrec = FIRST_SUBNET; subrec && (t == -1); 
-           subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-    struct work_record *w;
-    for (w = subrec->workgrouplist; w && t == -1; w = w->next)
-    {
-      if (strequal(w->work_group, work->work_group))
-        t = w->token;
-    }
-  }
+       for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               struct work_record *w;
+               for (w = subrec->workgrouplist; w && t == -1; w = w->next) {
+                       if (strnequal(w->work_group, work->work_group, sizeof(nstring)-1))
+                               t = w->token;
+               }
+       }
   
-  if (t == -1)
-    work->token = ++workgroup_count;
-  else
-    work->token = t;
+       if (t == -1)
+               work->token = ++workgroup_count;
+       else
+               work->token = t;
   
-  /* No known local master browser as yet. */
-  *work->local_master_browser_name = '\0';
-
-  /* No known domain master browser as yet. */
-  *work->dmb_name.name = '\0';
-  zero_ip(&work->dmb_addr);
-
-  /* WfWg  uses 01040b01 */
-  /* Win95 uses 01041501 */
-  /* NTAS  uses ???????? */
-  work->ElectionCriterion  = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); 
-  work->ElectionCriterion |= (lp_os_level() << 24);
-  if (lp_domain_master())
-    work->ElectionCriterion |= 0x80;
+       /* No known local master browser as yet. */
+       *work->local_master_browser_name = '\0';
+
+       /* No known domain master browser as yet. */
+       *work->dmb_name.name = '\0';
+       zero_ip(&work->dmb_addr);
+
+       /* WfWg  uses 01040b01 */
+       /* Win95 uses 01041501 */
+       /* NTAS  uses ???????? */
+       work->ElectionCriterion  = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); 
+       work->ElectionCriterion |= (lp_os_level() << 24);
+       if (lp_domain_master())
+               work->ElectionCriterion |= 0x80;
   
-  return work;
+       return work;
 }
 
 /*******************************************************************
   Remove a workgroup.
-  ******************************************************************/
+******************************************************************/
 
 static struct work_record *remove_workgroup_from_subnet(struct subnet_record *subrec, 
                                      struct work_record *work)
 {
-  struct work_record *ret_work = NULL;
+       struct work_record *ret_work = NULL;
   
-  DEBUG(3,("remove_workgroup: Removing workgroup %s\n", work->work_group));
+       DEBUG(3,("remove_workgroup: Removing workgroup %s\n", work->work_group));
   
-  ret_work = work->next;
+       ret_work = work->next;
 
-  remove_all_servers(work);
+       remove_all_servers(work);
   
-  if (!work->serverlist)
-  {
-    if (work->prev)
-      work->prev->next = work->next;
-    if (work->next)
-      work->next->prev = work->prev;
+       if (!work->serverlist) {
+               if (work->prev)
+                       work->prev->next = work->next;
+               if (work->next)
+                       work->next->prev = work->prev;
   
-    if (subrec->workgrouplist == work)
-      subrec->workgrouplist = work->next; 
+               if (subrec->workgrouplist == work)
+                       subrec->workgrouplist = work->next; 
   
-    ZERO_STRUCTP(work);
-    SAFE_FREE(work);
-  }
+               ZERO_STRUCTP(work);
+               SAFE_FREE(work);
+       }
   
-  subrec->work_changed = True;
+       subrec->work_changed = True;
 
-  return ret_work;
+       return ret_work;
 }
 
-
 /****************************************************************************
   Find a workgroup in the workgroup list of a subnet.
-  **************************************************************************/
+**************************************************************************/
 
 struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, 
                                              const char *name)
 {
-  struct work_record *ret;
+       struct work_record *ret;
   
-  DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ",
-            name, subrec->subnet_name));
+       DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ",
+               name, subrec->subnet_name));
   
-  for (ret = subrec->workgrouplist; ret; ret = ret->next)
-  {
-    if (!strcmp(ret->work_group,name))
-    {
-      DEBUGADD(4, ("found.\n"));
-      return(ret);
-    }
-  }
-  DEBUGADD(4, ("not found.\n"));
-  return NULL;
+       for (ret = subrec->workgrouplist; ret; ret = ret->next) {
+               if (strnequal(ret->work_group,name,sizeof(nstring)-1)) {
+                       DEBUGADD(4, ("found.\n"));
+                       return(ret);
+               }
+       }
+       DEBUGADD(4, ("not found.\n"));
+       return NULL;
 }
 
 /****************************************************************************
   Create a workgroup in the workgroup list of the subnet.
-  **************************************************************************/
+**************************************************************************/
 
 struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec,
                                                const char *name, int ttl)
 {
-  struct work_record *work = NULL;
+       struct work_record *work = NULL;
 
-  DEBUG(4,("create_workgroup_on_subnet: creating group %s on subnet %s\n",
-           name, subrec->subnet_name));
+       DEBUG(4,("create_workgroup_on_subnet: creating group %s on subnet %s\n",
+               name, subrec->subnet_name));
   
-  if ((work = create_workgroup(name, ttl)))
-  {
-    add_workgroup(subrec, work);
-
-    subrec->work_changed = True;
+       if ((work = create_workgroup(name, ttl))) {
+               add_workgroup(subrec, work);
+               subrec->work_changed = True;
+               return(work);
+       }
 
-    return(work);
-  }
-
-  return NULL;
+       return NULL;
 }
 
 /****************************************************************************
   Update a workgroup ttl.
-  **************************************************************************/
+**************************************************************************/
 
 void update_workgroup_ttl(struct work_record *work, int ttl)
 {
-  if(work->death_time != PERMANENT_TTL)
-    work->death_time = time(NULL)+(ttl*3);
-  work->subnet->work_changed = True;
+       if(work->death_time != PERMANENT_TTL)
+               work->death_time = time(NULL)+(ttl*3);
+       work->subnet->work_changed = True;
 }
 
 /****************************************************************************
@@ -210,8 +206,8 @@ void update_workgroup_ttl(struct work_record *work, int ttl)
 static void fail_register(struct subnet_record *subrec, struct response_record *rrec,
                           struct nmb_name *nmbname)
 {  
-  DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n",
-            nmb_namestr(nmbname), subrec->subnet_name));
+       DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n",
+               nmb_namestr(nmbname), subrec->subnet_name));
 }  
 
 /****************************************************************************
@@ -220,50 +216,38 @@ static void fail_register(struct subnet_record *subrec, struct response_record *
 
 void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_record *work)
 {
-  int i;
+       int i;
 
-  if(!strequal(lp_workgroup(), work->work_group))
-    return;
+       if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring)-1))
+               return;
 
-  /* If this is a broadcast subnet then start elections on it
-     if we are so configured. */
+       /* If this is a broadcast subnet then start elections on it if we are so configured. */
 
-  if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) &&
-      (subrec != wins_server_subnet) && lp_preferred_master() &&
-      lp_local_master())
-  {
-    DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \
+       if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) &&
+                       (subrec != wins_server_subnet) && lp_preferred_master() && lp_local_master()) {
+               DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \
 workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
-    work->needelection = True;
-    work->ElectionCriterion |= (1<<3);
-  }  
+               work->needelection = True;
+               work->ElectionCriterion |= (1<<3);
+       }
   
-  /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */
+       /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */
 
-  register_name(subrec,lp_workgroup(),0x0,samba_nb_type|NB_GROUP,
-                NULL,
-                fail_register,NULL);
-     
-  register_name(subrec,lp_workgroup(),0x1e,samba_nb_type|NB_GROUP,
-                NULL,
-                fail_register,NULL);
-     
-  for( i = 0; my_netbios_names(i); i++)
-  {
-    const char *name = my_netbios_names(i);
-    int stype = lp_default_server_announce() | (lp_local_master() ?
-                        SV_TYPE_POTENTIAL_BROWSER : 0 );
+       register_name(subrec,lp_workgroup(),0x0,samba_nb_type|NB_GROUP, NULL, fail_register,NULL);
+       register_name(subrec,lp_workgroup(),0x1e,samba_nb_type|NB_GROUP, NULL, fail_register,NULL);
+
+       for( i = 0; my_netbios_names(i); i++) {
+               const char *name = my_netbios_names(i);
+               int stype = lp_default_server_announce() | (lp_local_master() ?  SV_TYPE_POTENTIAL_BROWSER : 0 );
    
-    if(!strequal(global_myname(), name))
-        stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER|
-                   SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER);
+               if(!strequal(global_myname(), name))
+                       stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER|SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER);
    
-    create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY,
-                              PERMANENT_TTL, 
-                              string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
-    DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \
+               create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, PERMANENT_TTL, 
+                               string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
+               DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \
 on subnet %s\n", name, subrec->subnet_name));
-  }
+       }
 } 
 
 /****************************************************************************
@@ -272,43 +256,34 @@ on subnet %s\n", name, subrec->subnet_name));
 
 void dump_workgroups(BOOL force_write)
 {
-  struct subnet_record *subrec;
-  int debuglevel = force_write ? 0 : 4;
+       struct subnet_record *subrec;
+       int debuglevel = force_write ? 0 : 4;
  
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-    if (subrec->workgrouplist)
-    {
-      struct work_record *work;
-
-      if( DEBUGLVL( debuglevel ) )
-      {
-        dbgtext( "dump_workgroups()\n " );
-        dbgtext( "dump workgroup on subnet %15s: ", subrec->subnet_name );
-        dbgtext( "netmask=%15s:\n", inet_ntoa(subrec->mask_ip) );
-      }
-         
-      for (work = subrec->workgrouplist; work; work = work->next)
-      {
-        DEBUGADD( debuglevel, ( "\t%s(%d) current master browser = %s\n",
-                                work->work_group,
-                                work->token, 
-                               *work->local_master_browser_name
-                              ? work->local_master_browser_name : "UNKNOWN" ) );
-        if (work->serverlist)
-        {
-          struct server_record *servrec;                 
-          for (servrec = work->serverlist; servrec; servrec = servrec->next)
-          {
-            DEBUGADD( debuglevel, ( "\t\t%s %8x (%s)\n",
-                                    servrec->serv.name,
-                                    servrec->serv.type,
-                                    servrec->serv.comment ) );
-          }
-        }
-      }
-    }
-  }
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               if (subrec->workgrouplist) {
+                       struct work_record *work;
+
+                       if( DEBUGLVL( debuglevel ) ) {
+                               dbgtext( "dump_workgroups()\n " );
+                               dbgtext( "dump workgroup on subnet %15s: ", subrec->subnet_name );
+                               dbgtext( "netmask=%15s:\n", inet_ntoa(subrec->mask_ip) );
+                       }
+
+                       for (work = subrec->workgrouplist; work; work = work->next) {
+                               DEBUGADD( debuglevel, ( "\t%s(%d) current master browser = %s\n", work->work_group,
+                                       work->token, *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" ) );
+                               if (work->serverlist) {
+                                       struct server_record *servrec;            
+                                       for (servrec = work->serverlist; servrec; servrec = servrec->next) {
+                                               DEBUGADD( debuglevel, ( "\t\t%s %8x (%s)\n",
+                                                       servrec->serv.name,
+                                                       servrec->serv.type,
+                                                       servrec->serv.comment ) );
+                                       }
+                               }
+                       }
+               }
+       }
 }
 
 /****************************************************************************
@@ -318,25 +293,22 @@ void dump_workgroups(BOOL force_write)
 
 void expire_workgroups_and_servers(time_t t)
 {
-  struct subnet_record *subrec;
+       struct subnet_record *subrec;
    
-  for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
-  {
-    struct work_record *work;
-    struct work_record *nextwork;
-
-    for (work = subrec->workgrouplist; work; work = nextwork)
-    {
-      nextwork = work->next;
-      expire_servers(work, t);
-
-      if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && 
-                     ((t == -1) || (work->death_time < t)))
-      {
-        DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n",
-                  work->work_group));
-        remove_workgroup_from_subnet(subrec, work);
-      }
-    }
-  }
+       for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
+               struct work_record *work;
+               struct work_record *nextwork;
+
+               for (work = subrec->workgrouplist; work; work = nextwork) {
+                       nextwork = work->next;
+                       expire_servers(work, t);
+
+                       if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && 
+                                       ((t == -1) || (work->death_time < t))) {
+                               DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n",
+                                               work->work_group));
+                               remove_workgroup_from_subnet(subrec, work);
+                       }
+               }
+       }
 }
index fae635d8067fde692d967a415c1db1d4056cf08a..0afcceb6aa2e8d01bd8572e78ee179ea9ed97e1a 100644 (file)
 #define PAM_SM_ACCOUNT
 #define PAM_SM_PASSWORD
 
-#if defined(SUNOS5) || defined(SUNOS4) || defined(HPUX)
+#if defined(SUNOS5) || defined(SUNOS4) || defined(HPUX) || defined(FREEBSD)
 
 /* Solaris always uses dynamic pam modules */
 #define PAM_EXTERN extern
 #include <security/pam_appl.h> 
 
+#ifndef PAM_AUTHTOK_RECOVER_ERR
 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
 #endif
 
+#endif
+
 #ifdef HAVE_SECURITY_PAM_MODULES_H
 #include <security/pam_modules.h>
 #endif
index 7c5a8dd0546e1637814e1994a860c7d2f628c71c..0c6644e9d0055dc26e326678e1ca0ff9f34c5fa1 100644 (file)
@@ -264,6 +264,80 @@ static int wb_getgroups(const char *user, gid_t **groups)
        return -1;
 }
 
+/* Call winbindd to initialise group membership.  This is necessary for
+   some systems (i.e RH5.2) that do not have an initgroups function as part
+   of the nss extension.  In RH5.2 this is implemented using getgrent()
+   which can be amazingly inefficient as well as having problems with
+   username case. */
+
+int winbind_initgroups(char *user, gid_t gid)
+{
+       gid_t *tgr, *groups = NULL;
+       int result;
+
+       /* Call normal initgroups if we are a local user */
+
+       if (!strchr(user, *lp_winbind_separator())) {
+               return initgroups(user, gid);
+       }
+
+       result = wb_getgroups(user, &groups);
+
+       DEBUG(10,("winbind_getgroups: %s: result = %s\n", user, 
+                 result == -1 ? "FAIL" : "SUCCESS"));
+
+       if (result != -1) {
+               int ngroups = result, i;
+               BOOL is_member = False;
+
+               /* Check to see if the passed gid is already in the list */
+
+               for (i = 0; i < ngroups; i++) {
+                       if (groups[i] == gid) {
+                               is_member = True;
+                       }
+               }
+
+               /* Add group to list if necessary */
+
+               if (!is_member) {
+                       tgr = (gid_t *)Realloc(groups, sizeof(gid_t) * ngroups + 1);
+                       
+                       if (!tgr) {
+                               errno = ENOMEM;
+                               result = -1;
+                               goto done;
+                       }
+                       else groups = tgr;
+
+                       groups[ngroups] = gid;
+                       ngroups++;
+               }
+
+               /* Set the groups */
+
+               if (sys_setgroups(ngroups, groups) == -1) {
+                       errno = EPERM;
+                       result = -1;
+                       goto done;
+               }
+
+       } else {
+               
+               /* The call failed.  Set errno to something so we don't get
+                  a bogus value from the last failed system call. */
+
+               errno = EIO;
+       }
+
+       /* Free response data if necessary */
+
+ done:
+       SAFE_FREE(groups);
+
+       return result;
+}
+
 /* Return a list of groups the user is a member of.  This function is
    useful for large systems where inverting the group database would be too
    time consuming.  If size is zero, list is not modified and the total
index fcd7d2d50817524719233885d66c81629ac76880..0018e99f60f83e017f227d12eaa8dd45cc7d8910 100644 (file)
@@ -3,7 +3,7 @@
 
    Winbind status program.
 
-   Copyright (C) Tim Potter      2000-2002
+   Copyright (C) Tim Potter      2000-2003
    Copyright (C) Andrew Bartlett 2002
    
    This program is free software; you can redistribute it and/or modify
@@ -219,15 +219,20 @@ static BOOL wbinfo_list_domains(void)
 
 
 /* show sequence numbers */
-static BOOL wbinfo_show_sequence(void)
+static BOOL wbinfo_show_sequence(const char *domain)
 {
+       struct winbindd_request  request;
        struct winbindd_response response;
 
        ZERO_STRUCT(response);
+       ZERO_STRUCT(request);
+
+       if ( domain )
+               fstrcpy( request.domain_name, domain );
 
        /* Send request */
 
-       if (winbindd_request(WINBINDD_SHOW_SEQUENCE, NULL, &response) !=
+       if (winbindd_request(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
            NSS_STATUS_SUCCESS)
                return False;
 
@@ -481,9 +486,18 @@ static BOOL wbinfo_auth_crap(char *username)
                
        parse_wbinfo_domain_user(username, name_domain, name_user);
 
-       fstrcpy(request.data.auth_crap.user, name_user);
+       if (push_utf8_fstring(request.data.auth_crap.user, name_user) == -1) {
+               d_printf("unable to create utf8 string for '%s'\n",
+                        name_user);
+               return False;
+       }
 
-       fstrcpy(request.data.auth_crap.domain, name_domain);
+       if (push_utf8_fstring(request.data.auth_crap.domain, 
+                             name_domain) == -1) {
+               d_printf("unable to create utf8 string for '%s'\n",
+                        name_domain);
+               return False;
+       }
 
        generate_random_buffer(request.data.auth_crap.chal, 8, False);
         
@@ -682,17 +696,27 @@ static BOOL wbinfo_remove_user_from_group(char *string)
 
 /* Print domain users */
 
-static BOOL print_domain_users(void)
+static BOOL print_domain_users(const char *domain)
 {
+       struct winbindd_request request;
        struct winbindd_response response;
        const char *extra_data;
        fstring name;
 
        /* Send request to winbind daemon */
 
+       ZERO_STRUCT(request);
        ZERO_STRUCT(response);
+       
+       if (domain) {
+               /* '.' is the special sign for our own domwin */
+               if ( strequal(domain, ".") )
+                       fstrcpy( request.domain_name, lp_workgroup() );
+               else
+                       fstrcpy( request.domain_name, domain );
+       }
 
-       if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) !=
+       if (winbindd_request(WINBINDD_LIST_USERS, &request, &response) !=
            NSS_STATUS_SUCCESS)
                return False;
 
@@ -713,15 +737,24 @@ static BOOL print_domain_users(void)
 
 /* Print domain groups */
 
-static BOOL print_domain_groups(void)
+static BOOL print_domain_groups(const char *domain)
 {
+       struct winbindd_request  request;
        struct winbindd_response response;
        const char *extra_data;
        fstring name;
 
+       ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) !=
+       if (domain) {
+               if ( strequal(domain, ".") )
+                       fstrcpy( request.domain_name, lp_workgroup() );
+               else
+                       fstrcpy( request.domain_name, domain );
+       }
+
+       if (winbindd_request(WINBINDD_LIST_GROUPS, &request, &response) !=
            NSS_STATUS_SUCCESS)
                return False;
 
@@ -845,6 +878,7 @@ static BOOL wbinfo_ping(void)
 enum {
        OPT_SET_AUTH_USER = 1000,
        OPT_GET_AUTH_USER,
+       OPT_DOMAIN_NAME,
        OPT_SEQUENCE
 };
 
@@ -854,8 +888,8 @@ int main(int argc, char **argv)
 
        poptContext pc;
        static char *string_arg;
+       static char *opt_domain_name;
        static int int_arg;
-       BOOL got_command = False;
        int result = 1;
 
        struct poptOption long_options[] = {
@@ -864,8 +898,8 @@ int main(int argc, char **argv)
                /* longName, shortName, argInfo, argPtr, value, descrip, 
                   argDesc */
 
-               { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users"},
-               { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups" },
+               { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
+               { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
                { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
                { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
                { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
@@ -888,6 +922,7 @@ int main(int argc, char **argv)
                { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
                { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
                { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
+               { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operatio", "domain" },
                POPT_COMMON_VERSION
                POPT_TABLEEND
        };
@@ -917,11 +952,7 @@ int main(int argc, char **argv)
        }
 
        while((opt = poptGetNextOpt(pc)) != -1) {
-               if (got_command) {
-                       d_fprintf(stderr, "No more than one command may be specified at once.\n");
-                       exit(1);
-               }
-               got_command = True;
+               /* get the generic configuration parameters like --domain */
        }
 
        poptFreeContext(pc);
@@ -932,13 +963,13 @@ int main(int argc, char **argv)
        while((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case 'u':
-                       if (!print_domain_users()) {
+                       if (!print_domain_users(opt_domain_name)) {
                                d_printf("Error looking up domain users\n");
                                goto done;
                        }
                        break;
                case 'g':
-                       if (!print_domain_groups()) {
+                       if (!print_domain_groups(opt_domain_name)) {
                                d_printf("Error looking up domain groups\n");
                                goto done;
                        }
@@ -1007,7 +1038,7 @@ int main(int argc, char **argv)
                        }
                        break;
                case OPT_SEQUENCE:
-                       if (!wbinfo_show_sequence()) {
+                       if (!wbinfo_show_sequence(opt_domain_name)) {
                                d_printf("Could not show sequence numbers\n");
                                goto done;
                        }
@@ -1086,6 +1117,9 @@ int main(int argc, char **argv)
                case OPT_GET_AUTH_USER:
                        wbinfo_get_auth_user();
                        break;
+               /* generic configuration options */
+               case OPT_DOMAIN_NAME:
+                       break;
                default:
                        d_fprintf(stderr, "Invalid option\n");
                        poptPrintHelp(pc, stderr, 0);
index 8345fa11d0c33afa710c856f28b61df577e2deb0..6a0056f917e1ad98e5ce31ede932a0ca3aeb8eed 100644 (file)
@@ -570,9 +570,9 @@ static void process_loop(void)
 
                message_dispatch();
 
-               /* rescan the trusted domains list. This must be done
-                  regularly to cope with transitive trusts */
-               rescan_trusted_domains(False);
+               /* refresh the trusted domain cache */
+                  
+               rescan_trusted_domains();
 
                /* Free up temporary memory */
 
@@ -829,7 +829,7 @@ int main(int argc, char **argv)
        setup_logging("winbindd", log_stdout);
        reopen_logs();
 
-       DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
+       DEBUG(1, ("winbindd version %s started.\n", SAMBA_VERSION_STRING) );
        DEBUGADD( 1, ( "Copyright The Samba Team 2000-2003\n" ) );
 
        if (!reload_services_file(False)) {
index 8abfd17110804a3ac024747227df214f4037669d..0c06df7fdd4670a434ec835c939a2bbdea08554f 100644 (file)
@@ -70,18 +70,13 @@ static BOOL winbindd_accountdb_init(void)
        
        if ( account_tdb )
                return True;
-               
-       /* Nope.  Try to open it */
 
-       if (!(account_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, 
-               TDB_DEFAULT, O_RDWR | O_CREAT, 0600))) 
-       {
-               /* last chance -- maybe idmap has already opened it */
-               if ( !(account_tdb = idmap_tdb_handle()) ) {
+       /* winbindd_idmap.tdb should always be opened by the idmap_init()
+          code first */
 
-                       DEBUG(0, ("winbindd_idmap_init: Unable to open idmap database\n"));
-                       return False;
-               }
+       if ( !(account_tdb = idmap_tdb_handle()) ) {
+               DEBUG(0, ("winbindd_accountdb_init: Unable to retreive handle for database\n"));
+               return False;
        }
        
        /* yeah! */
index 7140dc35a0dd95db41d70cc289c8b4612e8362e5..c64359a2241d37817179656e2918efc7b2baa592 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
 
-/* the realm of our primary LDAP server */
-static char *primary_realm;
-
-
 /*
   return our ads connections structure for a domain. We keep the connection
   open to make things faster
@@ -58,10 +54,8 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain)
        SAFE_FREE(ads->auth.password);
        ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
 
-       if (primary_realm) {
-               SAFE_FREE(ads->auth.realm);
-               ads->auth.realm = strdup(primary_realm);
-       }
+       SAFE_FREE(ads->auth.realm);
+       ads->auth.realm = strdup(lp_realm());
 
        status = ads_connect(ads);
        if (!ADS_ERR_OK(status) || !ads->config.realm) {
@@ -84,11 +78,6 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain)
                return NULL;
        }
 
-       /* remember our primary realm for trusted domain support */
-       if (!primary_realm) {
-               primary_realm = strdup(ads->config.realm);
-       }
-
        domain->private = (void *)ads;
        return ads;
 }
@@ -123,7 +112,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
        }
 
        rc = ads_search_retry(ads, &res, "(objectCategory=user)", attrs);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !res) {
                DEBUG(1,("query_user_list ads_search: %s\n", ads_errstr(rc)));
                goto done;
        }
@@ -190,7 +179,8 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
        DEBUG(3,("ads query_user_list gave %d entries\n", (*num_entries)));
 
 done:
-       if (res) ads_msgfree(ads, res);
+       if (res) 
+               ads_msgfree(ads, res);
 
        return status;
 }
@@ -224,7 +214,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
        }
 
        rc = ads_search_retry(ads, &res, "(objectCategory=group)", attrs);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !res) {
                DEBUG(1,("enum_dom_groups ads_search: %s\n", ads_errstr(rc)));
                goto done;
        }
@@ -283,7 +273,8 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
        DEBUG(3,("ads enum_dom_groups gave %d entries\n", (*num_entries)));
 
 done:
-       if (res) ads_msgfree(ads, res);
+       if (res) 
+               ads_msgfree(ads, res);
 
        return status;
 }
@@ -378,7 +369,7 @@ static BOOL dn_lookup(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx,
        SAFE_FREE(ldap_exp);
        SAFE_FREE(escaped_dn);
 
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !res) {
                goto failed;
        }
 
@@ -393,11 +384,15 @@ static BOOL dn_lookup(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx,
                goto failed;
        }
 
-       if (res) ads_msgfree(ads, res);
+       if (res) 
+               ads_msgfree(ads, res);
+
        return True;
 
 failed:
-       if (res) ads_msgfree(ads, res);
+       if (res) 
+               ads_msgfree(ads, res);
+
        return False;
 }
 
@@ -436,7 +431,7 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
        rc = ads_search_retry(ads, &msg, ldap_exp, attrs);
        free(ldap_exp);
        free(sidstr);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !msg) {
                DEBUG(1,("query_user(sid=%s) ads_search: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc)));
                goto done;
        }
@@ -470,7 +465,8 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
 
        DEBUG(3,("ads query_user gave %s\n", info->acct_name));
 done:
-       if (msg) ads_msgfree(ads, msg);
+       if (msg) 
+               ads_msgfree(ads, msg);
 
        return status;
 }
@@ -511,7 +507,7 @@ static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain,
        rc = ads_search_retry(ads, &res, ldap_exp, group_attrs);
        free(ldap_exp);
        
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !res) {
                DEBUG(1,("lookup_usergroups ads_search member=%s: %s\n", user_dn, ads_errstr(rc)));
                return ads_ntstatus(rc);
        }
@@ -555,8 +551,10 @@ static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain,
 
        DEBUG(3,("ads lookup_usergroups (alt) for dn=%s\n", user_dn));
 done:
-       if (res) ads_msgfree(ads, res);
-       if (msg) ads_msgfree(ads, msg);
+       if (res) 
+               ads_msgfree(ads, res);
+       if (msg) 
+               ads_msgfree(ads, msg);
 
        return status;
 }
@@ -609,7 +607,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
        free(ldap_exp);
        free(sidstr);
 
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !msg) {
                DEBUG(1,("lookup_usergroups(sid=%s) ads_search: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc)));
                goto done;
        }
@@ -617,14 +615,16 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
        user_dn = ads_pull_string(ads, mem_ctx, msg, "distinguishedName");
        if (!user_dn) {
                DEBUG(1,("lookup_usergroups(sid=%s) ads_search did not return a a distinguishedName!\n", sid_to_string(sid_string, sid)));
-               if (msg) ads_msgfree(ads, msg);
+               if (msg) 
+                       ads_msgfree(ads, msg);
                goto done;
        }
 
-       if (msg) ads_msgfree(ads, msg);
+       if (msg) 
+               ads_msgfree(ads, msg);
 
        rc = ads_search_retry_dn(ads, &msg, user_dn, attrs2);
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !msg) {
                DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc)));
                goto done;
        }
@@ -638,7 +638,8 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
 
        count = ads_pull_sids(ads, mem_ctx, msg, "tokenGroups", &sids);
 
-       if (msg) ads_msgfree(ads, msg);
+       if (msg) 
+               ads_msgfree(ads, msg);
 
        /* there must always be at least one group in the token, 
           unless we are talking to a buggy Win2k server */
@@ -712,7 +713,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
        free(ldap_exp);
        free(sidstr);
 
-       if (!ADS_ERR_OK(rc)) {
+       if (!ADS_ERR_OK(rc) || !res) {
                DEBUG(1,("query_user_list ads_search: %s\n", ads_errstr(rc)));
                goto done;
        }
@@ -761,7 +762,8 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
        status = NT_STATUS_OK;
        DEBUG(3,("ads lookup_groupmem for sid=%s\n", sid_to_string(sid_string, group_sid)));
 done:
-       if (res) ads_msgfree(ads, res);
+       if (res) 
+               ads_msgfree(ads, res);
 
        return status;
 }
@@ -808,6 +810,7 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
        struct cli_state        *cli = NULL;
                                /* i think we only need our forest and downlevel trusted domains */
        uint32                  flags = DS_DOMAIN_IN_FOREST | DS_DOMAIN_DIRECT_OUTBOUND;
+       char                    *contact_domain_name;
 
        DEBUG(3,("ads: trusted_domains\n"));
 
@@ -816,14 +819,15 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain,
        *names       = NULL;
        *dom_sids    = NULL;
                
-       if ( !NT_STATUS_IS_OK(result = cm_fresh_connection(domain->name, PI_NETLOGON, &cli)) ) {
+       contact_domain_name = *domain->alt_name ? domain->alt_name : domain->name;
+       if ( !NT_STATUS_IS_OK(result = cm_fresh_connection(contact_domain_name, PI_NETLOGON, &cli)) ) {
                DEBUG(5, ("trusted_domains: Could not open a connection to %s for PIPE_NETLOGON (%s)\n", 
-                         domain->name, nt_errstr(result)));
+                         contact_domain_name, nt_errstr(result)));
                return NT_STATUS_UNSUCCESSFUL;
        }
        
        if ( NT_STATUS_IS_OK(result) )
-               result = cli_ds_enum_domain_trusts( cli, mem_ctx, cli->desthost, flags, &domains, &count );
+               result = cli_ds_enum_domain_trusts( cli, mem_ctx, cli->desthost, flags, &domains, (unsigned int *)&count );
        
        if ( NT_STATUS_IS_OK(result) && count) {
        
index 2891a4fa683a8cbfa81eb3d52d4f09bb70af17c5..bc6967dee1cd13d720ac6b0d34f19105daaece7c 100644 (file)
@@ -432,7 +432,7 @@ static struct cache_entry *wcache_fetch(struct winbind_cache *cache,
        }
 
        centry = smb_xmalloc(sizeof(*centry));
-       centry->data = data.dptr;
+       centry->data = (unsigned char *)data.dptr;
        centry->len = data.dsize;
        centry->ofs = 0;
 
@@ -576,7 +576,7 @@ static void centry_end(struct cache_entry *centry, const char *format, ...)
 
        key.dptr = kstr;
        key.dsize = strlen(kstr);
-       data.dptr = centry->data;
+       data.dptr = (char *)centry->data;
        data.dsize = centry->ofs;
 
        tdb_store(wcache->tdb, key, data, TDB_REPLACE);
@@ -924,7 +924,7 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
        centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname);
        if (!centry)
                goto do_query;
-       *type = centry_uint32(centry);
+       *type = (enum SID_NAME_USE)centry_uint32(centry);
        sid2 = centry_sid(centry, mem_ctx);
        if (!sid2) {
                ZERO_STRUCTP(sid);
@@ -988,7 +988,7 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
        if (!centry)
                goto do_query;
        if (NT_STATUS_IS_OK(centry->status)) {
-               *type = centry_uint32(centry);
+               *type = (enum SID_NAME_USE)centry_uint32(centry);
                *name = centry_string(centry, mem_ctx);
        }
        status = centry->status;
index f07117b5ab8680b9a38ce7d044f0d564f569aafc..8513a46f8f2ebb2514a43f7181c98440c2e55193 100644 (file)
@@ -116,7 +116,8 @@ static NTSTATUS cm_open_connection(const char *domain, const int pipe_index,
                               struct winbindd_cm_conn *new_conn)
 {
        NTSTATUS result;
-       char *ipc_username, *ipc_domain, *ipc_password;
+       char *machine_password; 
+       char *machine_krb5_principal, *ipc_username, *ipc_domain, *ipc_password;
        struct in_addr dc_ip;
        int i;
        BOOL retry = True;
@@ -137,10 +138,15 @@ static NTSTATUS cm_open_connection(const char *domain, const int pipe_index,
                
        /* Initialise SMB connection */
 
-       cm_get_ipc_userpass(&ipc_username, &ipc_domain, &ipc_password);
+       /* grab stored passwords */
+       machine_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
+       
+       if (asprintf(&machine_krb5_principal, "%s$@%s", global_myname(), lp_realm()) == -1) {
+               SAFE_FREE(machine_password);
+               return NT_STATUS_NO_MEMORY;
+       }
 
-       DEBUG(5, ("connecting to %s from %s with username [%s]\\[%s]\n", 
-             new_conn->controller, global_myname(), ipc_domain, ipc_username));
+       cm_get_ipc_userpass(&ipc_username, &ipc_domain, &ipc_password);
 
        for (i = 0; retry && (i < 3); i++) {
                BOOL got_mutex;
@@ -150,12 +156,99 @@ static NTSTATUS cm_open_connection(const char *domain, const int pipe_index,
                        continue;
                }
                
-               result = cli_full_connection(&new_conn->cli, global_myname(), new_conn->controller, 
-                                            &dc_ip, 0, "IPC$", "IPC", ipc_username, ipc_domain, 
-                                            ipc_password, CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK, 
-                                            Undefined, &retry);
-               
-               secrets_named_mutex_release(new_conn->controller);
+               new_conn->cli = NULL;
+               result = cli_start_connection(&new_conn->cli, global_myname(), 
+                                             new_conn->controller, 
+                                             &dc_ip, 0, Undefined, 
+                                             CLI_FULL_CONNECTION_USE_KERBEROS, 
+                                             &retry);
+
+               if (NT_STATUS_IS_OK(result)) {
+
+                       /* reset the error code */
+                       result = NT_STATUS_UNSUCCESSFUL; 
+
+                       /* Krb5 session */
+                       
+                       if ((lp_security() == SEC_ADS) 
+                               && (new_conn->cli->protocol >= PROTOCOL_NT1 && new_conn->cli->capabilities & CAP_EXTENDED_SECURITY)) {
+                               new_conn->cli->use_kerberos = True;
+                               DEBUG(5, ("connecting to %s from %s with kerberos principal [%s]\n", 
+                                         new_conn->controller, global_myname(), machine_krb5_principal));
+
+                               result = NT_STATUS_OK;
+
+                               if (!cli_session_setup_spnego(new_conn->cli, machine_krb5_principal, 
+                                                             machine_password, 
+                                                             domain)) {
+                                       result = cli_nt_error(new_conn->cli);
+                                       DEBUG(4,("failed kerberos session setup with %s\n", nt_errstr(result)));
+                                       if (NT_STATUS_IS_OK(result)) 
+                                               result = NT_STATUS_UNSUCCESSFUL;
+                               }
+                       }
+                       new_conn->cli->use_kerberos = False;
+                       
+                       /* only do this is we have a username/password for thr IPC$ connection */
+                       
+                       if ( !NT_STATUS_IS_OK(result) 
+                               && new_conn->cli->sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE
+                               && strlen(ipc_username) )
+                       {       
+                               DEBUG(5, ("connecting to %s from %s with username [%s]\\[%s]\n", 
+                                         new_conn->controller, global_myname(), ipc_domain, ipc_username));
+
+                               result = NT_STATUS_OK;
+
+                               if (!cli_session_setup(new_conn->cli, ipc_username, 
+                                                      ipc_password, strlen(ipc_password)+1, 
+                                                      ipc_password, strlen(ipc_password)+1, 
+                                                      domain)) {
+                                       result = cli_nt_error(new_conn->cli);
+                                       DEBUG(4,("failed authenticated session setup with %s\n", nt_errstr(result)));
+                                       if (NT_STATUS_IS_OK(result)) 
+                                               result = NT_STATUS_UNSUCCESSFUL;
+                               }
+                       }
+                       
+                       /* anonymous is all that is left if we get to here */
+                       
+                       if (!NT_STATUS_IS_OK(result)) { 
+                       
+                               DEBUG(5, ("anonymous connection attempt to %s from %s\n", 
+                                         new_conn->controller, global_myname()));
+                                         
+                               result = NT_STATUS_OK;
+
+                               if (!cli_session_setup(new_conn->cli, "", NULL, 0, NULL, 0, "")) 
+                               {
+                                       result = cli_nt_error(new_conn->cli);
+                                       DEBUG(4,("failed anonymous session setup with %s\n", nt_errstr(result)));
+                                       if (NT_STATUS_IS_OK(result)) 
+                                               result = NT_STATUS_UNSUCCESSFUL;
+                               } 
+                               
+                       }
+
+                       if (NT_STATUS_IS_OK(result) && !cli_send_tconX(new_conn->cli, "IPC$", "IPC",
+                                                                      "", 0)) {
+                               result = cli_nt_error(new_conn->cli);
+                               DEBUG(1,("failed tcon_X with %s\n", nt_errstr(result)));
+                               cli_shutdown(new_conn->cli);
+                               if (NT_STATUS_IS_OK(result)) {
+                                       result = NT_STATUS_UNSUCCESSFUL;
+                               }
+                       }
+               }
+
+               if (NT_STATUS_IS_OK(result)) {
+                       struct ntuser_creds creds;
+                       init_creds(&creds, ipc_username, ipc_domain, ipc_password);
+                       cli_init_creds(new_conn->cli, &creds);
+               }
+
+               if (got_mutex)
+                       secrets_named_mutex_release(new_conn->controller);
 
                if (NT_STATUS_IS_OK(result))
                        break;
@@ -164,6 +257,7 @@ static NTSTATUS cm_open_connection(const char *domain, const int pipe_index,
        SAFE_FREE(ipc_username);
        SAFE_FREE(ipc_domain);
        SAFE_FREE(ipc_password);
+       SAFE_FREE(machine_password);
 
        if (!NT_STATUS_IS_OK(result)) {
                add_failed_connection_entry(domain, new_conn->controller, result);
@@ -479,6 +573,7 @@ NTSTATUS cm_get_netlogon_cli(const char *domain,
        struct winbindd_cm_conn *conn;
        fstring lock_name;
        BOOL got_mutex;
+       struct winbindd_domain *wb_domain = NULL;
 
        if (!cli)
                return NT_STATUS_INVALID_PARAMETER;
@@ -520,6 +615,17 @@ NTSTATUS cm_get_netlogon_cli(const char *domain,
        if ( sec_channel_type == SEC_CHAN_DOMAIN )
                fstr_sprintf(conn->cli->mach_acct, "%s$", lp_workgroup());
                        
+       /* we need the short form of the domain name for the schanel
+          rpc bind.  What if we fail?  I don't think we should ever get 
+          a request for a domain name not in our list but I'm not bailing 
+          out if we do since I'm not 10% certain about this   --jerry */
+          
+       if ( (wb_domain = find_domain_from_name( domain )) != NULL ) {
+               DEBUG(5,("cm_get_netlogon_cli: Using short for of domain name [%s] for netlogon rpc bind\n",
+                       wb_domain->name));
+               fstrcpy( conn->cli->domain, wb_domain->name);
+       }
+       
        result = cli_nt_establish_netlogon(conn->cli, sec_channel_type, trust_passwd);
        
        if (got_mutex)
index 96c121685a15609e8613cb4932b0dbea34894931..fba427536c8dd833c24fb156fb4e1cbbb1e60967 100644 (file)
@@ -821,17 +821,29 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
 {
        uint32 total_entries = 0;
        struct winbindd_domain *domain;
+       const char *which_domain;
        char *extra_data = NULL;
        char *ted = NULL;
        unsigned int extra_data_len = 0, i;
 
        DEBUG(3, ("[%5lu]: list groups\n", (unsigned long)state->pid));
 
+       /* Ensure null termination */
+       state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';  
+       which_domain = state->request.domain_name;
+       
        /* Enumerate over trusted domains */
 
        for (domain = domain_list(); domain; domain = domain->next) {
                struct getent_state groups;
 
+               /* if we have a domain name restricting the request and this
+                  one in the list doesn't match, then just bypass the remainder
+                  of the loop */
+                  
+               if ( *which_domain && !strequal(which_domain, domain->name) )
+                       continue;
+                       
                ZERO_STRUCT(groups);
 
                /* Get list of sam groups */
index 740b760b930f827ea14ad5aea8200aff7e702e92..88fbb5ee0065d088e4216944d9345ae4390ddc6f 100644 (file)
@@ -35,6 +35,8 @@ enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *stat
         int num_retries = 0;
         struct cli_state *cli;
        uint32 sec_channel_type;
+       const char *contact_domain_name = NULL;
+       
        DEBUG(3, ("[%5lu]: check machine account\n", (unsigned long)state->pid));
 
        /* Get trust account password */
@@ -46,11 +48,21 @@ enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *stat
                goto done;
        }
 
+
+       /* use the realm name if appropriate and possible */
+       
+       if ( lp_security() == SEC_ADS )
+               contact_domain_name = lp_realm();
+       
+       if ( !contact_domain_name || !*contact_domain_name )
+               contact_domain_name = lp_workgroup();
+               
         /* This call does a cli_nt_setup_creds() which implicitly checks
            the trust account password. */
-
        /* Don't shut this down - it belongs to the connection cache code */
-        result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, sec_channel_type, True, &cli);
+       
+        result = cm_get_netlogon_cli(contact_domain_name,
+               trust_passwd, sec_channel_type, True, &cli);
 
         if (!NT_STATUS_IS_OK(result)) {
                 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
@@ -148,9 +160,14 @@ enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
 {
        struct winbindd_domain *domain;
        char *extra_data = NULL;
+       const char *which_domain;
 
        DEBUG(3, ("[%5lu]: show sequence\n", (unsigned long)state->pid));
 
+       /* Ensure null termination */
+       state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';  
+       which_domain = state->request.domain_name;
+
        extra_data = strdup("");
 
        /* this makes for a very simple data format, and is easily parsable as well
@@ -158,6 +175,13 @@ enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state)
        for (domain = domain_list(); domain; domain = domain->next) {
                char *s;
 
+               /* if we have a domain name restricting the request and this
+                  one in the list doesn't match, then just bypass the remainder
+                  of the loop */
+
+               if ( *which_domain && !strequal(which_domain, domain->name) )
+                       continue;
+
                domain->methods->sequence_number(domain, &domain->sequence_number);
                
                if (DOM_SEQUENCE_NONE == (unsigned)domain->sequence_number) {
@@ -194,7 +218,7 @@ enum winbindd_result winbindd_info(struct winbindd_cli_state *state)
        DEBUG(3, ("[%5lu]: request misc info\n", (unsigned long)state->pid));
 
        state->response.data.info.winbind_separator = *lp_winbind_separator();
-       fstrcpy(state->response.data.info.samba_version, VERSION);
+       fstrcpy(state->response.data.info.samba_version, SAMBA_VERSION_STRING);
 
        return WINBINDD_OK;
 }
index c4407bbe31c9062302676cc5aad5a0fdbbef999a..41fecd2816cf8d6d715e1fb73beed2be77ab96ff 100644 (file)
@@ -157,6 +157,7 @@ struct winbindd_request {
        enum winbindd_cmd cmd;   /* Winbindd command to execute */
        pid_t pid;               /* pid of calling process */
        uint32 flags;            /* flags relavant to a given request */
+       fstring domain_name;    /* name of domain for which the request applies */
 
        union {
                fstring winsreq;     /* WINS request */
index a8908487c1b566d93914ea66cf28ea3f9c01dc5b..21ae6478def825b8c3610a9c1420b439fbf40e74 100644 (file)
@@ -65,7 +65,7 @@ enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
        time_t last_change_time;
        uint32 sec_channel_type;
         NET_USER_INFO_3 info3;
-        struct cli_state *cli = NULL;
+        struct cli_state *cli;
        uchar chal[8];
        TALLOC_CTX *mem_ctx = NULL;
        DATA_BLOB lm_resp;
@@ -75,6 +75,7 @@ enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
        unsigned char local_lm_response[24];
        unsigned char local_nt_response[24];
        const char *contact_domain;
+       BOOL retry;
 
        /* Ensure null termination */
        state->request.data.auth.user[sizeof(state->request.data.auth.user)-1]='\0';
@@ -127,6 +128,8 @@ enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
        do {
                ZERO_STRUCT(info3);
                ZERO_STRUCT(ret_creds);
+               cli = NULL;
+               retry = False;
        
                /* Don't shut this down - it belongs to the connection cache code */
                result = cm_get_netlogon_cli(contact_domain, trust_passwd, 
@@ -154,15 +157,14 @@ enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
                                "password was changed and we didn't know it.  Killing connections to domain %s\n",
                                name_domain));
                        winbindd_cm_flush();
-                       cli->fd = -1;
+                       retry = True;
                } 
                
                /* We have to try a second time as cm_get_netlogon_cli
                   might not yet have noticed that the DC has killed
                   our connection. */
 
-       } while ( (attempts < 2) && (cli->fd == -1) );
-
+       } while ( (attempts < 2) && retry );
         
        clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
        
@@ -170,10 +172,8 @@ enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
                netsamlogon_cache_store( cli->mem_ctx, &info3 );
                wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3);
        }
-       
-        
+   
 done:
-       
        /* give us a more useful (more correct?) error code */
        if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) || (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
                result = NT_STATUS_NO_LOGON_SERVERS;
@@ -206,7 +206,7 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
        time_t last_change_time;
        uint32 sec_channel_type;
         NET_USER_INFO_3 info3;
-        struct cli_state *cli = NULL;
+        struct cli_state *cli;
        TALLOC_CTX *mem_ctx = NULL;
        char *user = NULL;
        const char *domain = NULL;
@@ -214,6 +214,7 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
        const char *contact_domain;
        DOM_CRED ret_creds;
        int attempts = 0;
+       BOOL retry;
 
        DATA_BLOB lm_resp, nt_resp;
 
@@ -226,10 +227,8 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
        }
 
        /* Ensure null termination */
-       state->request.data.auth_crap.user[sizeof(state->request.data.auth_crap.user)-1]='\0';
-
-       /* Ensure null termination */
-       state->request.data.auth_crap.domain[sizeof(state->request.data.auth_crap.domain)-1]='\0';
+       state->request.data.auth_crap.user[sizeof(state->request.data.auth_crap.user)-1]=0;
+       state->request.data.auth_crap.domain[sizeof(state->request.data.auth_crap.domain)-1]=0;
 
        if (!(mem_ctx = talloc_init("winbind pam auth crap for (utf8) %s", state->request.data.auth_crap.user))) {
                DEBUG(0, ("winbindd_pam_auth_crap: could not talloc_init()!\n"));
@@ -239,12 +238,16 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
 
         if (pull_utf8_talloc(mem_ctx, &user, state->request.data.auth_crap.user) == (size_t)-1) {
                DEBUG(0, ("winbindd_pam_auth_crap: pull_utf8_talloc failed!\n"));
+               result = NT_STATUS_UNSUCCESSFUL;
+               goto done;
        }
 
        if (*state->request.data.auth_crap.domain) {
                char *dom = NULL;
                if (pull_utf8_talloc(mem_ctx, &dom, state->request.data.auth_crap.domain) == (size_t)-1) {
                        DEBUG(0, ("winbindd_pam_auth_crap: pull_utf8_talloc failed!\n"));
+                       result = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
                }
                domain = dom;
        } else if (lp_winbind_use_default_domain()) {
@@ -268,6 +271,8 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
                char *wrk = NULL;
                if (pull_utf8_talloc(mem_ctx, &wrk, state->request.data.auth_crap.workstation) == (size_t)-1) {
                        DEBUG(0, ("winbindd_pam_auth_crap: pull_utf8_talloc failed!\n"));
+                       result = NT_STATUS_UNSUCCESSFUL;
+                       goto done;
                }
                workstation = wrk;
        } else {
@@ -296,6 +301,8 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
        do {
                ZERO_STRUCT(info3);
                ZERO_STRUCT(ret_creds);
+               cli = NULL;
+               retry = False;
 
                /* Don't shut this down - it belongs to the connection cache code */
                result = cm_get_netlogon_cli(contact_domain, trust_passwd, sec_channel_type, False, &cli);
@@ -325,14 +332,14 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
                                "password was changed and we didn't know it.  Killing connections to domain %s\n",
                                domain));
                        winbindd_cm_flush();
-                       cli->fd = -1;
+                       retry = True;
                } 
                
                /* We have to try a second time as cm_get_netlogon_cli
                   might not yet have noticed that the DC has killed
                   our connection. */
 
-       } while ( (attempts < 2) && (cli->fd == -1) );
+       } while ( (attempts < 2) && retry );
 
        clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
         
@@ -353,7 +360,6 @@ enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
        }
 
 done:
-
        /* give us a more useful (more correct?) error code */
        if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) || (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
                result = NT_STATUS_NO_LOGON_SERVERS;
index 33339d7ca03be6309aa7b3b0f557054abfb9ac9a..8bd2c66511341ab50a278523ac66adfcec8f81d4 100644 (file)
@@ -295,7 +295,7 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
 
        if (NT_STATUS_IS_OK(result)) {
                sid_copy(sid, &sids[0]);
-               *type = types[0];
+               *type = (enum SID_NAME_USE)types[0];
        }
 
        return result;
@@ -331,7 +331,7 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
                        hnd && hnd->cli && hnd->cli->fd == -1);
 
        if (NT_STATUS_IS_OK(result)) {
-               *type = types[0];
+               *type = (enum SID_NAME_USE)types[0];
                *name = names[0];
                DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains[0], *name));
 
index 98a6fce24baabffdec4d3f745ace985adbb41f16..ac1ee1155546b364e453a69e4da2ee8a7ae47e05 100644 (file)
@@ -185,12 +185,17 @@ enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
 {
        DOM_SID sid;
 
-       /* Bug out if the uid isn't in the winbind range */
-
+#if 0  /* JERRY */
+       /* we cannot do this check this anymore since a domain member of 
+          a Samba domain may share unix accounts via NIS or LDAP.  In this 
+          case the uid/gid will be out of winbindd's range but still might
+          be resolved to a SID via an ldap idmap backend */
+          
        if ((state->request.data.uid < server_state.uid_low ) ||
            (state->request.data.uid > server_state.uid_high)) {
                return WINBINDD_ERROR;
        }
+#endif
 
        DEBUG(3, ("[%5lu]: uid to sid %lu\n", (unsigned long)state->pid, 
                  (unsigned long)state->request.data.uid));
@@ -214,12 +219,17 @@ enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state)
 {
        DOM_SID sid;
 
-       /* Bug out if the gid isn't in the winbind range */
-
+#if 0  /* JERRY */
+       /* we cannot do this check this anymore since a domain member of 
+          a Samba domain may share unix accounts via NIS or LDAP.  In this 
+          case the uid/gid will be out of winbindd's range but still might
+          be resolved to a SID via an ldap idmap backend */
+          
        if ((state->request.data.gid < server_state.gid_low) ||
            (state->request.data.gid > server_state.gid_high)) {
                return WINBINDD_ERROR;
        }
+#endif
 
        DEBUG(3, ("[%5lu]: gid to sid %lu\n", (unsigned long)state->pid,
                  (unsigned long)state->request.data.gid));
index c0b0d94167e8f71a60ed1dbf5a1b576ace863320..eab88c842eac75aa3a436c956a91ff12303b7b54 100644 (file)
@@ -575,6 +575,7 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
 {
        struct winbindd_domain *domain;
        WINBIND_USERINFO *info;
+       const char *which_domain;
        uint32 num_entries = 0, total_entries = 0;
        char *ted, *extra_data = NULL;
        int extra_data_len = 0;
@@ -586,13 +587,24 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
        if (!(mem_ctx = talloc_init("winbindd_list_users")))
                return WINBINDD_ERROR;
 
+       /* Ensure null termination */
+       state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';  
+       which_domain = state->request.domain_name;
+       
        /* Enumerate over trusted domains */
 
        for (domain = domain_list(); domain; domain = domain->next) {
                NTSTATUS status;
                struct winbindd_methods *methods;
                unsigned int i;
-
+               
+               /* if we have a domain name restricting the request and this
+                  one in the list doesn't match, then just bypass the remainder
+                  of the loop */
+                  
+               if ( *which_domain && !strequal(which_domain, domain->name) )
+                       continue;
+                       
                methods = domain->methods;
 
                /* Query display info */
index a810e503a00adbafc0181114e292d76d03c6cbf6..25de4eff716bb1f382a762af370a6a7a93da570b 100644 (file)
@@ -80,6 +80,14 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
                                                  DOM_SID *sid)
 {
        struct winbindd_domain *domain;
+       char *contact_name;
+       const char *alternative_name = NULL;
+       
+       /* ignore alt_name if we are not in an AD domain */
+       
+       if ( (lp_security() == SEC_ADS) && alt_name && *alt_name) {
+               alternative_name = alt_name;
+       }
         
        /* We can't call domain_list() as this function is called from
           init_domain_list() and we'll get stuck in a loop. */
@@ -88,9 +96,9 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
                    strcasecmp(domain_name, domain->alt_name) == 0) {
                        return domain;
                }
-               if (alt_name && *alt_name) {
-                       if (strcasecmp(alt_name, domain->name) == 0 ||
-                           strcasecmp(alt_name, domain->alt_name) == 0) {
+               if (alternative_name && *alternative_name) {
+                       if (strcasecmp(alternative_name, domain->name) == 0 ||
+                           strcasecmp(alternative_name, domain->alt_name) == 0) {
                                return domain;
                        }
                }
@@ -107,13 +115,13 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
        ZERO_STRUCTP(domain);
 
        /* prioritise the short name */
-       if (strchr_m(domain_name, '.') && alt_name && *alt_name) {
-               fstrcpy(domain->name, alt_name);
+       if (strchr_m(domain_name, '.') && alternative_name && *alternative_name) {
+               fstrcpy(domain->name, alternative_name);
                fstrcpy(domain->alt_name, domain_name);
        } else {
                fstrcpy(domain->name, domain_name);
-               if (alt_name) {
-                       fstrcpy(domain->alt_name, alt_name);
+               if (alternative_name) {
+                       fstrcpy(domain->alt_name, alternative_name);
                }
        }
 
@@ -125,10 +133,12 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
                sid_copy(&domain->sid, sid);
        }
        
-       /* see if this is a native mode win2k domain */
+       /* see if this is a native mode win2k domain (use realm name if possible) */
           
-       domain->native_mode = cm_check_for_native_mode_win2k( domain_name );
-       DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", domain_name,
+       contact_name = *domain->alt_name ? domain->alt_name : domain->name;
+       domain->native_mode = cm_check_for_native_mode_win2k( contact_name );
+       
+       DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", contact_name,
                domain->native_mode ? "native" : "mixed (or NT4)" ));
 
        /* Link to domain list */
@@ -141,57 +151,80 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
        return domain;
 }
 
+/********************************************************************
+ Periodically we need to refresh the trusted domain cache for smbd 
+********************************************************************/
 
-/*
+void rescan_trusted_domains( void )
+{
+       static time_t last_scan;
+       time_t now = time(NULL);
+       struct winbindd_domain *mydomain = NULL;
+       
+       /* see if the time has come... */
+       
+       if ( (now > last_scan) && ((now-last_scan) < WINBINDD_RESCAN_FREQ) )
+               return;
+               
+       /* get the handle for our domain */
+       
+       if ( (mydomain = find_domain_from_name(lp_workgroup())) == NULL ) {
+               DEBUG(0,("rescan_trusted_domains: Can't find my own domain!\n"));
+               return;
+       }
+       
+       /* this will only add new domains we didn't already know about */
+       
+       add_trusted_domains( mydomain );
+
+       last_scan = now;
+       
+       return; 
+}
+
+/********************************************************************
   rescan our domains looking for new trusted domains
- */
-void rescan_trusted_domains(BOOL force)
+********************************************************************/
+
+void add_trusted_domains( struct winbindd_domain *domain )
 {
-       struct winbindd_domain *domain;
        TALLOC_CTX *mem_ctx;
-       static time_t last_scan;
-       time_t t = time(NULL);
+       NTSTATUS result;
+       time_t t;
+       char **names;
+       char **alt_names;
+       int num_domains = 0;
+       DOM_SID *dom_sids, null_sid;
+       int i;
+       struct winbindd_domain *new_domain;
 
        /* trusted domains might be disabled */
        if (!lp_allow_trusted_domains()) {
                return;
        }
 
-       /* Only rescan every few minutes but force if necessary */
-
-       if (((unsigned)(t - last_scan) < WINBINDD_RESCAN_FREQ) && !force)
-               return;
-
-       last_scan = t;
-
        DEBUG(1, ("scanning trusted domain list\n"));
 
        if (!(mem_ctx = talloc_init("init_domain_list")))
                return;
+          
+       ZERO_STRUCTP(&null_sid);
 
-       for (domain = _domain_list; domain; domain = domain->next) {
-               NTSTATUS result;
-               char **names;
-               char **alt_names;
-               int num_domains = 0;
-               DOM_SID *dom_sids, null_sid;
-               int i;
-               struct winbindd_domain *new_domain;
+       t = time(NULL);
+       
+       /* ask the DC what domains it trusts */
+       
+       result = domain->methods->trusted_domains(domain, mem_ctx, (unsigned int *)&num_domains,
+               &names, &alt_names, &dom_sids);
                
-               ZERO_STRUCTP(&null_sid);
-
-               result = domain->methods->trusted_domains(domain, mem_ctx, &num_domains,
-                                                         &names, &alt_names, &dom_sids);
-               if (!NT_STATUS_IS_OK(result)) {
-                       continue;
-               }
+       if ( NT_STATUS_IS_OK(result) ) {
 
                /* Add each domain to the trusted domain list */
                
                for(i = 0; i < num_domains; i++) {
                        DEBUG(10,("Found domain %s\n", names[i]));
                        add_trusted_domain(names[i], alt_names?alt_names[i]:NULL,
-                                          domain->methods, &dom_sids[i]);
+                               domain->methods, &dom_sids[i]);
                                           
                        /* if the SID was empty, we better set it now */
                        
@@ -212,7 +245,7 @@ void rescan_trusted_domains(BOOL force)
                                result = domain->methods->domain_sid( new_domain, &new_domain->sid );
                                 
                                if ( NT_STATUS_IS_OK(result) )
-                                       sid_copy( &dom_sids[i], &domain->sid );
+                                       sid_copy( &dom_sids[i], &new_domain->sid );
                        }
                        
                        /* store trusted domain in the cache */
@@ -234,18 +267,26 @@ BOOL init_domain_list(void)
        free_domain_list();
 
        /* Add ourselves as the first entry */
-       domain = add_trusted_domain( lp_workgroup(), NULL, &cache_methods, NULL);
+       
+       domain = add_trusted_domain( lp_workgroup(), lp_realm(), &cache_methods, NULL);
+       
+       /* get any alternate name for the primary domain */
+       
+       cache_methods.alternate_name(domain);
+       
+       /* now we have the correct netbios (short) domain name */
+       
+       if ( *domain->name )
+               set_global_myworkgroup( domain->name );
+               
        if (!secrets_fetch_domain_sid(domain->name, &domain->sid)) {
                DEBUG(1, ("Could not fetch sid for our domain %s\n",
                          domain->name));
                return False;
        }
 
-       /* get any alternate name for the primary domain */
-       cache_methods.alternate_name(domain);
-
        /* do an initial scan for trusted domains */
-       rescan_trusted_domains(True);
+       add_trusted_domains(domain);
 
        return True;
 }
index 87dac60192e2b756417861c81046c51ecfbe9882..0fc4e46cdb7959a696797e7b625aabb523e3cd30 100644 (file)
@@ -260,54 +260,105 @@ int lookup(nsd_file_t *rq)
 }
 
 #else
+
+/* Allocate some space from the nss static buffer.  The buffer and buflen
+   are the pointers passed in by the C library to the _nss_*_*
+   functions. */
+
+static char *get_static(char **buffer, int *buflen, int len)
+{
+       char *result;
+
+       /* Error check.  We return false if things aren't set up right, or
+          there isn't enough buffer space left. */
+       
+       if ((buffer == NULL) || (buflen == NULL) || (*buflen < len)) {
+               return NULL;
+       }
+
+       /* Return an index into the static buffer */
+
+       result = *buffer;
+       *buffer += len;
+       *buflen -= len;
+
+       return result;
+}
+
 /****************************************************************************
 gethostbyname() - we ignore any domain portion of the name and only
 handle names that are at most 15 characters long
   **************************************************************************/
 NSS_STATUS
-_nss_wins_gethostbyname_r(const char *name, struct hostent *he,
-                         char *buffer, size_t buflen, int *errnop,
-                         int *h_errnop)
+_nss_wins_gethostbyname_r(const char *hostname, struct hostent *he,
+                         char *buffer, size_t buflen, int *h_errnop)
 {
-       char **host_addresses;
        struct in_addr *ip_list;
        int i, count;
-       size_t namelen = strlen(name) + 1;
+       fstring name;
+       size_t namelen;
                
        memset(he, '\0', sizeof(*he));
+       fstrcpy(name, hostname);
+
+       /* Do lookup */
 
        ip_list = lookup_byname_backend(name, &count);
-       if (!ip_list) {
-               return NSS_STATUS_NOTFOUND;
-       }
 
-       if (buflen < namelen + (2*count+1)*INADDRSZ) {
-               /* no ENOMEM error type?! */
+       if (!ip_list)
                return NSS_STATUS_NOTFOUND;
-       }
 
+       /* Copy h_name */
 
-       host_addresses = (char **)buffer;
-       he->h_addr_list = host_addresses;
-       host_addresses[count] = NULL;
-       buffer += (count + 1) * INADDRSZ;
-       buflen += (count + 1) * INADDRSZ;
-       he->h_addrtype = AF_INET;
-       he->h_length = INADDRSZ;
+       namelen = strlen(name) + 1;
+
+       if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL)
+               return NSS_STATUS_TRYAGAIN;
+
+       memcpy(he->h_name, name, namelen);
+
+       /* Copy h_addr_list, align to pointer boundary first */
 
-       for (i=0;i<count;i++) {
-               memcpy(buffer, &ip_list[i].s_addr, INADDRSZ);
-               *host_addresses = buffer;
-               buffer += INADDRSZ;
-               buflen -= INADDRSZ;
-               host_addresses++;
+       if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0)
+               i = sizeof(char*) - i;
+
+       if (get_static(&buffer, &buflen, i) == NULL)
+               return NSS_STATUS_TRYAGAIN;
+
+       if ((he->h_addr_list = (char **)get_static(
+                    &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL)
+               return NSS_STATUS_TRYAGAIN;
+
+       for (i = 0; i < count; i++) {
+               if ((he->h_addr_list[i] = get_static(&buffer, &buflen,
+                                                    INADDRSZ)) == NULL)
+                       return NSS_STATUS_TRYAGAIN;
+               memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ);
        }
 
+       he->h_addr_list[count] = NULL;
+
        if (ip_list)
                free(ip_list);
 
-       memcpy(buffer, name, namelen);
-       he->h_name = buffer;
+       /* Set h_addr_type and h_length */
+
+       he->h_addrtype = AF_INET;
+       he->h_length = INADDRSZ;
+
+       /* Set h_aliases */
+
+       if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0)
+               i = sizeof(char*) - i;
+
+       if (get_static(&buffer, &buflen, i) == NULL)
+               return NSS_STATUS_TRYAGAIN;
+
+       if ((he->h_aliases = (char **)get_static(
+                    &buffer, &buflen, sizeof(char *))) == NULL)
+               return NSS_STATUS_TRYAGAIN;
+
+       he->h_aliases[0] = NULL;
 
        return NSS_STATUS_SUCCESS;
 }
@@ -315,15 +366,14 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he,
 
 NSS_STATUS
 _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he,
-                               char *buffer, size_t buflen, int *errnop,
-                               int *h_errnop)
+                          char *buffer, size_t buflen, int *h_errnop)
 {
        if(af!=AF_INET) {
                *h_errnop = NO_DATA;
-               *errnop = EAFNOSUPPORT;
                return NSS_STATUS_UNAVAIL;
        }
 
-       return _nss_wins_gethostbyname_r(name,he,buffer,buflen,errnop,h_errnop);
+       return _nss_wins_gethostbyname_r(
+               name, he, buffer, buflen, h_errnop);
 }
 #endif
index 8bd50f35de0146223017fbe4e83964df77954903..41b32cef1096ef254ef5fd45a507d3600f986ccc 100644 (file)
@@ -231,7 +231,6 @@ typedef struct
        char *szLdapSuffix;
        char *szLdapFilter;
        char *szLdapAdminDn;
-       BOOL ldap_trust_ids;
        char *szAclCompat;
        int ldap_passwd_sync; 
        BOOL ldap_delete_dn;
@@ -563,6 +562,7 @@ static BOOL handle_debug_list( const char *pszParmValue, char **ptr );
 static BOOL handle_workgroup( const char *pszParmValue, char **ptr );
 static BOOL handle_netbios_aliases( const char *pszParmValue, char **ptr );
 static BOOL handle_netbios_scope( const char *pszParmValue, char **ptr );
+static BOOL handle_charset( const char *pszParmValue, char **ptr );
 
 static BOOL handle_ldap_suffix ( const char *pszParmValue, char **ptr );
 static BOOL handle_ldap_sub_suffix ( const char *pszParmValue, char **ptr );
@@ -700,6 +700,7 @@ static const struct enum_list enum_smb_signing_vals[] = {
        {True, "1"},
        {True, "On"},
        {True, "enabled"},
+       {Auto, "auto"},
        {Required, "required"},
        {Required, "mandatory"},
        {Required, "force"},
@@ -752,9 +753,9 @@ static const struct enum_list enum_map_to_guest[] = {
 static struct parm_struct parm_table[] = {
        {"Base Options", P_SEP, P_SEPARATOR}, 
 
-       {"dos charset", P_STRING, P_GLOBAL, &Globals.dos_charset, NULL, NULL, FLAG_ADVANCED}, 
-       {"unix charset", P_STRING, P_GLOBAL, &Globals.unix_charset, NULL, NULL, FLAG_ADVANCED}, 
-       {"display charset", P_STRING, P_GLOBAL, &Globals.display_charset, NULL, NULL, FLAG_ADVANCED}, 
+       {"dos charset", P_STRING, P_GLOBAL, &Globals.dos_charset, handle_charset, NULL, FLAG_ADVANCED}, 
+       {"unix charset", P_STRING, P_GLOBAL, &Globals.unix_charset, handle_charset, NULL, FLAG_ADVANCED}, 
+       {"display charset", P_STRING, P_GLOBAL, &Globals.display_charset, handle_charset, NULL, FLAG_ADVANCED}, 
        {"comment", P_STRING, P_LOCAL, &sDefault.comment, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT}, 
        {"path", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT}, 
        {"directory", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_HIDE}, 
@@ -1071,7 +1072,6 @@ static struct parm_struct parm_table[] = {
        {"ldap admin dn", P_STRING, P_GLOBAL, &Globals.szLdapAdminDn, NULL, NULL, FLAG_ADVANCED}, 
        {"ldap ssl", P_ENUM, P_GLOBAL, &Globals.ldap_ssl, NULL, enum_ldap_ssl, FLAG_ADVANCED}, 
        {"ldap passwd sync", P_ENUM, P_GLOBAL, &Globals.ldap_passwd_sync, NULL, enum_ldap_passwd_sync, FLAG_ADVANCED}, 
-       {"ldap trust ids", P_BOOL, P_GLOBAL, &Globals.ldap_trust_ids, NULL, NULL, FLAG_ADVANCED}, 
        {"ldap delete dn", P_BOOL, P_GLOBAL, &Globals.ldap_delete_dn, NULL, NULL, FLAG_ADVANCED}, 
 
        {"Miscellaneous Options", P_SEP, P_SEPARATOR}, 
@@ -1309,18 +1309,18 @@ static void init_globals(void)
        string_set(&Globals.szGuestaccount, GUEST_ACCOUNT);
 
        /* using UTF8 by default allows us to support all chars */
-       string_set(&Globals.unix_charset, "UTF8");
+       string_set(&Globals.unix_charset, DEFAULT_UNIX_CHARSET);
 
 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
        /* If the system supports nl_langinfo(), try to grab the value
           from the user's locale */
        string_set(&Globals.display_charset, "LOCALE");
 #else
-       string_set(&Globals.display_charset, "ASCII");
+       string_set(&Globals.display_charset, DEFAULT_DISPLAY_CHARSET);
 #endif
 
        /* Use codepage 850 as a default for the dos character set */
-       string_set(&Globals.dos_charset, "CP850");
+       string_set(&Globals.dos_charset, DEFAULT_DOS_CHARSET);
 
        /*
         * Allow the default PASSWD_CHAT to be overridden in local.h.
@@ -1339,7 +1339,7 @@ static void init_globals(void)
        string_set(&Globals.szLockDir, dyn_LOCKDIR);
        string_set(&Globals.szSocketAddress, "0.0.0.0");
        pstrcpy(s, "Samba ");
-       pstrcat(s, VERSION);
+       pstrcat(s, SAMBA_VERSION_STRING);
        string_set(&Globals.szServerString, s);
        slprintf(s, sizeof(s) - 1, "%d.%d", DEFAULT_MAJOR_VERSION,
                 DEFAULT_MINOR_VERSION);
@@ -1427,19 +1427,21 @@ static void init_globals(void)
        Globals.bClientPlaintextAuth = True;    /* Do use a plaintext password if is requested by the server */
        Globals.bLanmanAuth = True;     /* Do use the LanMan hash if it is available */
        Globals.bNTLMAuth = True;       /* Do use NTLMv1 if it is available (otherwise NTLMv2) */
-       
+       Globals.bClientNTLMv2Auth = False; /* Client should not use NTLMv2, as we can't tell that the server supports it. */
+       /* Note, that we will use NTLM2 session security (which is different), if it is available */
+
        Globals.map_to_guest = 0;       /* By Default, "Never" */
        Globals.min_passwd_length = MINPASSWDLENGTH;    /* By Default, 5. */
        Globals.oplock_break_wait_time = 0;     /* By Default, 0 msecs. */
        Globals.enhanced_browsing = True; 
-       Globals.iLockSpinCount = 3; /* Try 2 times. */
+       Globals.iLockSpinCount = 3; /* Try 3 times. */
        Globals.iLockSpinTime = 10; /* usec. */
 #ifdef MMAP_BLACKLIST
        Globals.bUseMmap = False;
 #else
        Globals.bUseMmap = True;
 #endif
-       Globals.bUnixExtensions = False;
+       Globals.bUnixExtensions = True;
 
        /* hostname lookups can be very expensive and are broken on
           a large number of sites (tridge) */
@@ -1514,6 +1516,9 @@ static void init_globals(void)
        Globals.bUseSpnego = True;
        Globals.bClientUseSpnego = True;
 
+       Globals.client_signing = Auto;
+       Globals.server_signing = False;
+
        string_set(&Globals.smb_ports, SMB_PORTS);
 }
 
@@ -1554,8 +1559,8 @@ static char *lp_string(const char *s)
                lp_talloc = talloc_init("lp_talloc");
 
        tmpstr = alloc_sub_basic(current_user_info.smb_name, s);
-       if (trim_string(tmpstr, "\"", "\"")) {
-               if (strchr(tmpstr,'"') != NULL) {
+       if (trim_char(tmpstr, '\"', '\"')) {
+               if (strchr(tmpstr,'\"') != NULL) {
                        SAFE_FREE(tmpstr);
                        tmpstr = alloc_sub_basic(current_user_info.smb_name,s);
                }
@@ -1692,7 +1697,6 @@ FN_GLOBAL_STRING(lp_ldap_filter, &Globals.szLdapFilter)
 FN_GLOBAL_STRING(lp_ldap_admin_dn, &Globals.szLdapAdminDn)
 FN_GLOBAL_INTEGER(lp_ldap_ssl, &Globals.ldap_ssl)
 FN_GLOBAL_INTEGER(lp_ldap_passwd_sync, &Globals.ldap_passwd_sync)
-FN_GLOBAL_BOOL(lp_ldap_trust_ids, &Globals.ldap_trust_ids)
 FN_GLOBAL_BOOL(lp_ldap_delete_dn, &Globals.ldap_delete_dn)
 FN_GLOBAL_STRING(lp_add_share_cmd, &Globals.szAddShareCommand)
 FN_GLOBAL_STRING(lp_change_share_cmd, &Globals.szChangeShareCommand)
@@ -2293,13 +2297,8 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
        if (!(*(ServicePtrs[iDefaultService]->szPath))
            || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(GLOBAL_SECTION_SNUM))) {
                pstrcpy(newHomedir, pszHomedir);
-       } else {
-               pstrcpy(newHomedir, lp_pathname(iDefaultService));
-               string_sub(newHomedir,"%H", pszHomedir, sizeof(newHomedir)); 
-               string_sub(newHomedir,"%S", pszHomename, sizeof(newHomedir)); 
-       }
-
-       string_set(&ServicePtrs[i]->szPath, newHomedir);
+               string_set(&ServicePtrs[i]->szPath, newHomedir);
+       } 
 
        if (!(*(ServicePtrs[i]->comment))) {
                pstring comment;
@@ -2307,7 +2306,9 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
                         "Home directory of %s", user);
                string_set(&ServicePtrs[i]->comment, comment);
        }
-       ServicePtrs[i]->bAvailable = sDefault.bAvailable;
+
+       /* set the browseable flag from the gloabl default */
+
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
 
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename, 
@@ -2377,7 +2378,10 @@ BOOL lp_add_printer(const char *pszPrintername, int iDefaultService)
        /* the printer name is set to the service name. */
        string_set(&ServicePtrs[i]->szPrintername, pszPrintername);
        string_set(&ServicePtrs[i]->comment, comment);
+
+       /* set the browseable flag from the gloabl default */
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+
        /* Printers cannot be read_only. */
        ServicePtrs[i]->bRead_only = False;
        /* No share modes on printer services. */
@@ -2698,7 +2702,6 @@ static BOOL handle_netbios_name(const char *pszParmValue, char **ptr)
 
        standard_sub_basic(current_user_info.smb_name, netbios_name,sizeof(netbios_name));
 
-
        ret = set_global_myname(netbios_name);
        string_set(&Globals.szNetbiosName,global_myname());
        
@@ -2708,6 +2711,15 @@ static BOOL handle_netbios_name(const char *pszParmValue, char **ptr)
        return ret;
 }
 
+static BOOL handle_charset(const char *pszParmValue, char **ptr)
+{
+       if (strcmp(*ptr, pszParmValue) != 0) {
+               string_set(ptr, pszParmValue);
+               init_iconv();
+       }
+       return True;
+}
+
 static BOOL handle_workgroup(const char *pszParmValue, char **ptr)
 {
        BOOL ret;
@@ -3101,7 +3113,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        pstr_sprintf(param_key, "%s:", pszParmName);
                        slen = strlen(param_key);
                        pstrcat(param_key, sep+1);
-                       trim_string(param_key+slen, " ", " ");
+                       trim_char(param_key+slen, ' ', ' ');
                        not_added = True;
                        data = (snum < 0) ? Globals.param_opt : 
                                ServicePtrs[snum]->param_opt;
@@ -4158,12 +4170,11 @@ void lp_remove_service(int snum)
 
 void lp_copy_service(int snum, const char *new_name)
 {
-       char *oldname = lp_servicename(snum);
        do_section(new_name);
        if (snum >= 0) {
                snum = lp_servicenumber(new_name);
                if (snum >= 0)
-                       lp_do_parameter(snum, "copy", oldname);
+                       lp_do_parameter(snum, "copy", lp_servicename(snum));
        }
 }
 
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
new file mode 100644 (file)
index 0000000..f84ff28
--- /dev/null
@@ -0,0 +1,488 @@
+/* 
+   Unix SMB/CIFS implementation.
+   uid/user handling
+   Copyright (C) Andrew Tridgell         1992-1998
+   Copyright (C) Gerald (Jerry) Carter   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
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#include "includes.h"
+
+/*****************************************************************
+ *THE CANONICAL* convert name to SID function.
+ Tries local lookup first - for local domains - then uses winbind.
+*****************************************************************/  
+
+BOOL lookup_name(const char *domain, const char *name, DOM_SID *psid, enum SID_NAME_USE *name_type)
+{
+       fstring sid;
+       BOOL local_lookup = False;
+       
+       *name_type = SID_NAME_UNKNOWN;
+
+       /* If we are looking up a domain user, make sure it is
+          for the local machine only */
+       
+       if (strequal(global_myname(), domain)) {
+               local_lookup = True;
+       } else if (lp_server_role() == ROLE_DOMAIN_PDC || 
+                  lp_server_role() == ROLE_DOMAIN_BDC) {
+               if (strequal(domain, lp_workgroup())) {
+                       local_lookup = True;
+               }
+       }
+               
+       if (local_lookup) {
+               if (local_lookup_name(name, psid, name_type)) {
+                       DEBUG(10,
+                             ("lookup_name: (local) [%s]\\[%s] -> SID %s (type %s: %u)\n",
+                              domain, name, sid_to_string(sid,psid),
+                              sid_type_lookup(*name_type), (unsigned int)*name_type));
+                       return True;
+               }
+       } else {
+               /* Remote */
+               if (winbind_lookup_name(domain, name, psid, name_type)) {
+                       
+                       DEBUG(10,("lookup_name (winbindd): [%s]\\[%s] -> SID %s (type %u)\n",
+                                 domain, name, sid_to_string(sid, psid), 
+                                 (unsigned int)*name_type));
+                       return True;
+               }
+       }
+       
+       DEBUG(10, ("lookup_name: %s lookup for [%s]\\[%s] failed\n", 
+                  local_lookup ? "local" : "winbind", domain, name));
+
+       return False;
+}
+
+/*****************************************************************
+ *THE CANONICAL* convert SID to name function.
+ Tries local lookup first - for local sids, then tries winbind.
+*****************************************************************/  
+
+BOOL lookup_sid(DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAME_USE *name_type)
+{
+       if (!name_type)
+               return False;
+
+       *name_type = SID_NAME_UNKNOWN;
+
+       /* Check if this is our own sid.  This should perhaps be done by
+          winbind?  For the moment handle it here. */
+
+       if (sid->num_auths == 5) {
+               DOM_SID tmp_sid;
+               uint32 rid;
+
+               sid_copy(&tmp_sid, sid);
+               sid_split_rid(&tmp_sid, &rid);
+
+               if (sid_equal(get_global_sam_sid(), &tmp_sid)) {
+
+                       return map_domain_sid_to_name(&tmp_sid, dom_name) &&
+                               local_lookup_sid(sid, name, name_type);
+               }
+       }
+
+       if (!winbind_lookup_sid(sid, dom_name, name, name_type)) {
+               fstring sid_str;
+               DOM_SID tmp_sid;
+               uint32 rid;
+
+               DEBUG(10,("lookup_sid: winbind lookup for SID %s failed - trying local.\n", sid_to_string(sid_str, sid) ));
+
+               sid_copy(&tmp_sid, sid);
+               sid_split_rid(&tmp_sid, &rid);
+               return map_domain_sid_to_name(&tmp_sid, dom_name) &&
+                       lookup_known_rid(&tmp_sid, rid, name, name_type);
+       }
+       return True;
+}
+
+
+/*****************************************************************
+ Id mapping cache.  This is to avoid Winbind mappings already
+ seen by smbd to be queried too frequently, keeping winbindd
+ busy, and blocking smbd while winbindd is busy with other
+ stuff. Written by Michael Steffens <michael.steffens@hp.com>,
+ modified to use linked lists by jra.
+*****************************************************************/  
+
+#define MAX_UID_SID_CACHE_SIZE 100
+#define TURNOVER_UID_SID_CACHE_SIZE 10
+#define MAX_GID_SID_CACHE_SIZE 100
+#define TURNOVER_GID_SID_CACHE_SIZE 10
+
+static size_t n_uid_sid_cache = 0;
+static size_t n_gid_sid_cache = 0;
+
+static struct uid_sid_cache {
+       struct uid_sid_cache *next, *prev;
+       uid_t uid;
+       DOM_SID sid;
+       enum SID_NAME_USE sidtype;
+} *uid_sid_cache_head;
+
+static struct gid_sid_cache {
+       struct gid_sid_cache *next, *prev;
+       gid_t gid;
+       DOM_SID sid;
+       enum SID_NAME_USE sidtype;
+} *gid_sid_cache_head;
+
+/*****************************************************************
+  Find a SID given a uid.
+*****************************************************************/  
+
+static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid)
+{
+       struct uid_sid_cache *pc;
+
+       for (pc = uid_sid_cache_head; pc; pc = pc->next) {
+               if (pc->uid == uid) {
+                       fstring sid;
+                       *psid = pc->sid;
+                       DEBUG(3,("fetch sid from uid cache %u -> %s\n",
+                               (unsigned int)uid, sid_to_string(sid, psid)));
+                       DLIST_PROMOTE(uid_sid_cache_head, pc);
+                       return True;
+               }
+       }
+       return False;
+}
+
+/*****************************************************************
+  Find a uid given a SID.
+*****************************************************************/  
+
+static BOOL fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid )
+{
+       struct uid_sid_cache *pc;
+
+       for (pc = uid_sid_cache_head; pc; pc = pc->next) {
+               if (sid_compare(&pc->sid, psid) == 0) {
+                       fstring sid;
+                       *puid = pc->uid;
+                       DEBUG(3,("fetch uid from cache %u -> %s\n",
+                               (unsigned int)*puid, sid_to_string(sid, psid)));
+                       DLIST_PROMOTE(uid_sid_cache_head, pc);
+                       return True;
+               }
+       }
+       return False;
+}
+
+/*****************************************************************
+ Store uid to SID mapping in cache.
+*****************************************************************/  
+
+static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
+{
+       struct uid_sid_cache *pc;
+
+       if (n_uid_sid_cache >= MAX_UID_SID_CACHE_SIZE && n_uid_sid_cache > TURNOVER_UID_SID_CACHE_SIZE) {
+               /* Delete the last TURNOVER_UID_SID_CACHE_SIZE entries. */
+               struct uid_sid_cache *pc_next;
+               size_t i;
+
+               for (i = 0, pc = uid_sid_cache_head; i < (n_uid_sid_cache - TURNOVER_UID_SID_CACHE_SIZE); i++, pc = pc->next)
+                       ;
+               for(; pc; pc = pc_next) {
+                       pc_next = pc->next;
+                       DLIST_REMOVE(uid_sid_cache_head,pc);
+                       SAFE_FREE(pc);
+                       n_uid_sid_cache--;
+               }
+       }
+
+       pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache));
+       if (!pc)
+               return;
+       pc->uid = uid;
+       sid_copy(&pc->sid, psid);
+       DLIST_ADD(uid_sid_cache_head, pc);
+       n_uid_sid_cache++;
+}
+
+/*****************************************************************
+  Find a SID given a gid.
+*****************************************************************/  
+
+static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid)
+{
+       struct gid_sid_cache *pc;
+
+       for (pc = gid_sid_cache_head; pc; pc = pc->next) {
+               if (pc->gid == gid) {
+                       fstring sid;
+                       *psid = pc->sid;
+                       DEBUG(3,("fetch sid from gid cache %u -> %s\n",
+                               (unsigned int)gid, sid_to_string(sid, psid)));
+                       DLIST_PROMOTE(gid_sid_cache_head, pc);
+                       return True;
+               }
+       }
+       return False;
+}
+
+/*****************************************************************
+  Find a gid given a SID.
+*****************************************************************/  
+
+static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid)
+{
+       struct gid_sid_cache *pc;
+
+       for (pc = gid_sid_cache_head; pc; pc = pc->next) {
+               if (sid_compare(&pc->sid, psid) == 0) {
+                       fstring sid;
+                       *pgid = pc->gid;
+                       DEBUG(3,("fetch uid from cache %u -> %s\n",
+                               (unsigned int)*pgid, sid_to_string(sid, psid)));
+                       DLIST_PROMOTE(gid_sid_cache_head, pc);
+                       return True;
+               }
+       }
+       return False;
+}
+
+/*****************************************************************
+ Store gid to SID mapping in cache.
+*****************************************************************/  
+
+static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
+{
+       struct gid_sid_cache *pc;
+
+       if (n_gid_sid_cache >= MAX_GID_SID_CACHE_SIZE && n_gid_sid_cache > TURNOVER_GID_SID_CACHE_SIZE) {
+               /* Delete the last TURNOVER_GID_SID_CACHE_SIZE entries. */
+               struct gid_sid_cache *pc_next;
+               size_t i;
+
+               for (i = 0, pc = gid_sid_cache_head; i < (n_gid_sid_cache - TURNOVER_GID_SID_CACHE_SIZE); i++, pc = pc->next)
+                       ;
+               for(; pc; pc = pc_next) {
+                       pc_next = pc->next;
+                       DLIST_REMOVE(gid_sid_cache_head,pc);
+                       SAFE_FREE(pc);
+                       n_gid_sid_cache--;
+               }
+       }
+
+       pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache));
+       if (!pc)
+               return;
+       pc->gid = gid;
+       sid_copy(&pc->sid, psid);
+       DLIST_ADD(gid_sid_cache_head, pc);
+       n_gid_sid_cache++;
+}
+
+/*****************************************************************
+ *THE CANONICAL* convert uid_t to SID function.
+*****************************************************************/  
+
+NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid)
+{
+       uid_t low, high;
+       fstring sid;
+
+       ZERO_STRUCTP(psid);
+
+       if (fetch_sid_from_uid_cache(psid, uid))
+               return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
+
+       if (lp_idmap_uid(&low, &high) && uid >= low && uid <= high) {
+               if (winbind_uid_to_sid(psid, uid)) {
+
+                       DEBUG(10,("uid_to_sid: winbindd %u -> %s\n",
+                               (unsigned int)uid, sid_to_string(sid, psid)));
+
+                       if (psid)
+                               store_uid_sid_cache(psid, uid);
+                       return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
+               }
+       }
+
+       if (!local_uid_to_sid(psid, uid)) {
+               DEBUG(10,("uid_to_sid: local %u failed to map to sid\n", (unsigned int)uid ));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+        
+       DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid, sid_to_string(sid, psid)));
+
+       store_uid_sid_cache(psid, uid);
+       return NT_STATUS_OK;
+}
+
+/*****************************************************************
+ *THE CANONICAL* convert gid_t to SID function.
+*****************************************************************/  
+
+NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid)
+{
+       gid_t low, high;
+       fstring sid;
+
+       ZERO_STRUCTP(psid);
+
+       if (fetch_sid_from_gid_cache(psid, gid))
+               return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
+
+       if (lp_idmap_gid(&low, &high) && gid >= low && gid <= high) {
+               if (winbind_gid_to_sid(psid, gid)) {
+
+                       DEBUG(10,("gid_to_sid: winbindd %u -> %s\n",
+                               (unsigned int)gid, sid_to_string(sid, psid)));
+                        
+                       if (psid)
+                               store_gid_sid_cache(psid, gid);
+                       return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
+               }
+       }
+
+       if (!local_gid_to_sid(psid, gid)) {
+               DEBUG(10,("gid_to_sid: local %u failed to map to sid\n", (unsigned int)gid ));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+        
+       DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid, sid_to_string(sid, psid)));
+
+       store_gid_sid_cache(psid, gid);
+       return NT_STATUS_OK;
+}
+
+/*****************************************************************
+ *THE CANONICAL* convert SID to uid function.
+*****************************************************************/  
+
+NTSTATUS sid_to_uid(const DOM_SID *psid, uid_t *puid)
+{
+       fstring dom_name, name, sid_str;
+       enum SID_NAME_USE name_type;
+
+       if (fetch_uid_from_cache(puid, psid))
+               return NT_STATUS_OK;
+
+       /* if this is our SID then go straight to a local lookup */
+       
+       if ( sid_compare_domain(get_global_sam_sid(), psid) == 0 ) {
+               DEBUG(10,("sid_to_uid: my domain (%s) - trying local.\n",
+                       sid_string_static(psid) ));
+               
+               if ( local_sid_to_uid(puid, psid, &name_type) )
+                       goto success;
+                       
+               DEBUG(10,("sid_to_uid: local lookup failed\n"));
+               
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+       
+       /* If it is not our local domain, only hope is winbindd */
+
+       if ( !winbind_lookup_sid(psid, dom_name, name, &name_type) ) {
+               DEBUG(10,("sid_to_uid: winbind lookup for non-local sid %s failed\n",
+                       sid_string_static(psid) ));
+                       
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       /* If winbindd does know the SID, ensure this is a user */
+
+       if (name_type != SID_NAME_USER) {
+               DEBUG(10,("sid_to_uid: winbind lookup succeeded but SID is not a user (%u)\n",
+                       (unsigned int)name_type ));
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* get the uid.  Has to work or else we are dead in the water */
+
+       if ( !winbind_sid_to_uid(puid, psid) ) {
+               DEBUG(10,("sid_to_uid: winbind failed to allocate a new uid for sid %s\n",
+                       sid_to_string(sid_str, psid) ));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+success:
+       DEBUG(10,("sid_to_uid: %s -> %u\n", sid_to_string(sid_str, psid),
+               (unsigned int)*puid ));
+
+       store_uid_sid_cache(psid, *puid);
+       
+       return NT_STATUS_OK;
+}
+/*****************************************************************
+ *THE CANONICAL* convert SID to gid function.
+ Group mapping is used for gids that maps to Wellknown SIDs
+*****************************************************************/  
+
+NTSTATUS sid_to_gid(const DOM_SID *psid, gid_t *pgid)
+{
+       fstring dom_name, name, sid_str;
+       enum SID_NAME_USE name_type;
+
+       if (fetch_gid_from_cache(pgid, psid))
+               return NT_STATUS_OK;
+
+       /*
+        * First we must look up the name and decide if this is a group sid.
+        * Group mapping can deal with foreign SIDs
+        */
+
+       if (!winbind_lookup_sid(psid, dom_name, name, &name_type)) {
+               DEBUG(10,("sid_to_gid: winbind lookup for sid %s failed - trying local.\n",
+                       sid_to_string(sid_str, psid) ));
+
+               if ( local_sid_to_gid(pgid, psid, &name_type) )
+                       goto success;
+                       
+               DEBUG(10,("sid_to_gid: no one knows this SID\n"));
+               
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       /* winbindd knows it; Ensure this is a group sid */
+
+       if ((name_type != SID_NAME_DOM_GRP) && (name_type != SID_NAME_ALIAS) && (name_type != SID_NAME_WKN_GRP)) {
+               DEBUG(10,("sid_to_gid: winbind lookup succeeded but SID is not a known group (%u)\n",
+                       (unsigned int)name_type ));
+
+               /* winbindd is running and knows about this SID.  Just the wrong type.
+                  Don't fallback to a local lookup here */
+                  
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+       
+       /* winbindd knows it and it is a type of group; sid_to_gid must succeed
+          or we are dead in the water */
+
+       if ( !winbind_sid_to_gid(pgid, psid) ) {
+               DEBUG(10,("sid_to_uid: winbind failed to allocate a new gid for sid %s\n",
+                       sid_to_string(sid_str, psid) ));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+success:
+       DEBUG(10,("sid_to_gid: %s -> %u\n", sid_to_string(sid_str, psid),
+               (unsigned int)*pgid ));
+
+       store_gid_sid_cache(psid, *pgid);
+       
+       return NT_STATUS_OK;
+}
+
index e440e064ef8a2afcdc2dc9c1375a8a546622577d..76745be3f010ec4d6e42242f246b93ec97407d84 100644 (file)
@@ -758,13 +758,27 @@ BOOL local_lookup_sid(DOM_SID *sid, char *name, enum SID_NAME_USE *psid_name_use
 
        if (fallback_pdb_rid_is_user(rid)) {
                uid_t uid;
+               struct passwd *pw = NULL;
 
                DEBUG(5, ("assuming RID %u is a user\n", (unsigned)rid));
 
                        uid = fallback_pdb_user_rid_to_uid(rid);
-               slprintf(name, sizeof(fstring)-1, "unix_user.%u", (unsigned int)uid);   
-
-               return False;  /* Indicates that this user was 'not mapped' */
+               pw = sys_getpwuid( uid );
+               
+               DEBUG(5,("local_lookup_sid: looking up uid %u %s\n", (unsigned int)uid,
+                        pw ? "succeeded" : "failed" ));
+                        
+               if ( !pw )
+                       fstr_sprintf(name, "unix_user.%u", (unsigned int)uid);  
+               else 
+                       fstrcpy( name, pw->pw_name );
+                       
+               DEBUG(5,("local_lookup_sid: found user %s for rid %u\n", name,
+                        (unsigned int)rid ));
+                        
+               *psid_name_use = SID_NAME_USER;
+               
+               return ( pw != NULL );
        } else {
                gid_t gid;
                struct group *gr; 
@@ -779,16 +793,19 @@ BOOL local_lookup_sid(DOM_SID *sid, char *name, enum SID_NAME_USE *psid_name_use
                DEBUG(5,("local_lookup_sid: looking up gid %u %s\n", (unsigned int)gid,
                         gr ? "succeeded" : "failed" ));
                        
-               if(!gr) {
-                       slprintf(name, sizeof(fstring)-1, "unix_group.%u", (unsigned int)gid);
-                       return False; /* Indicates that this group was 'not mapped' */
-               }
-                       
-               fstrcpy( name, gr->gr_name);
+               if( !gr )
+                       fstr_sprintf(name, "unix_group.%u", (unsigned int)gid);
+               else
+                       fstrcpy( name, gr->gr_name);
                        
                DEBUG(5,("local_lookup_sid: found group %s for rid %u\n", name,
                         (unsigned int)rid ));
-               return True;   
+               
+               /* assume fallback groups aer domain global groups */
+               
+               *psid_name_use = SID_NAME_DOM_GRP;
+               
+               return ( gr != NULL );
        }
 }
 
@@ -1156,11 +1173,18 @@ BOOL local_sid_to_uid(uid_t *puid, const DOM_SID *psid, enum SID_NAME_USE *name_
 DOM_SID *local_gid_to_sid(DOM_SID *psid, gid_t gid)
 {
        GROUP_MAP group;
+       BOOL ret;
        
        /* we don't need to disable winbindd since the gid is stored in 
           the GROUP_MAP object */
+          
+       /* done as root since ldap backend requires root to open a connection */
 
-       if ( !pdb_getgrgid( &group, gid ) ) {
+       become_root();
+       ret = pdb_getgrgid( &group, gid );
+       unbecome_root();
+       
+       if ( !ret ) {
 
                /* fallback to rid mapping if enabled */
 
@@ -1289,6 +1313,7 @@ BOOL init_sam_from_buffer(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
        BOOL ret = True;
        uid_t uid = -1;
        gid_t gid = -1;
+       struct passwd *pw = NULL;
        
        if(sampass == NULL || buf == NULL) {
                DEBUG(0, ("init_sam_from_buffer: NULL parameters found!\n"));
@@ -1296,7 +1321,7 @@ BOOL init_sam_from_buffer(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
        }
                                                                        
        /* unpack the buffer into variables */
-       len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING,
+       len = tdb_unpack ((char *)buf, buflen, TDB_FORMAT_STRING,
                &logon_time,
                &logoff_time,
                &kickoff_time,
@@ -1344,6 +1369,12 @@ BOOL init_sam_from_buffer(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
        pdb_set_nt_username(sampass, nt_username, PDB_SET);
        pdb_set_fullname(sampass, fullname, PDB_SET);
 
+
+       if ( (pw=Get_Pwnam(username)) != NULL ) {
+               uid = pw->pw_uid;
+               gid = pw->pw_gid;
+       }
+
        if (homedir) {
                pdb_set_homedir(sampass, homedir, PDB_SET);
        }
@@ -1633,7 +1664,7 @@ uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL size_
        }
        
        /* now for the real call to tdb_pack() */
-       buflen = tdb_pack(*buf, len,  TDB_FORMAT_STRING,
+       buflen = tdb_pack((char *)*buf, len,  TDB_FORMAT_STRING,
                logon_time,
                logoff_time,
                kickoff_time,
@@ -1676,3 +1707,51 @@ uint32 init_buffer_from_sam (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL size_
 
        return (buflen);
 }
+
+
+/**********************************************************************
+**********************************************************************/
+
+static BOOL get_free_ugid_range(uint32 *low, uint32 *high)
+{
+       uid_t u_low, u_high;
+       gid_t g_low, g_high;
+
+       if (!lp_idmap_uid(&u_low, &u_high) || !lp_idmap_gid(&g_low, &g_high)) {
+               return False;
+       }
+       
+       *low  = (u_low < g_low)   ? u_low  : g_low;
+       *high = (u_high < g_high) ? u_high : g_high;
+       
+       return True;
+}
+
+/******************************************************************
+ Get the the non-algorithmic RID range if idmap range are defined
+******************************************************************/
+
+BOOL get_free_rid_range(uint32 *low, uint32 *high)
+{
+       uint32 id_low, id_high;
+
+       if (!lp_enable_rid_algorithm()) {
+               *low = BASE_RID;
+               *high = (uint32)-1;
+       }
+
+       if (!get_free_ugid_range(&id_low, &id_high)) {
+               return False;
+       }
+
+       *low = fallback_pdb_uid_to_user_rid(id_low);
+       if (fallback_pdb_user_rid_to_uid((uint32)-1) < id_high) {
+               *high = (uint32)-1;
+       } else {
+               *high = fallback_pdb_uid_to_user_rid(id_high);
+       }
+
+       return True;
+}
+
+
index 5ebc14030f06cf9e2fed55f5526ae53d654780f3..d548081e78b71af1ed6291886cd7f9909db6a6cc 100644 (file)
@@ -422,10 +422,10 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c
        if (p) {
                *p = 0;
                module_location = p+1;
-               trim_string(module_location, " ", " ");
+               trim_char(module_location, ' ', ' ');
        }
 
-       trim_string(module_name, " ", " ");
+       trim_char(module_name, ' ', ' ');
 
 
        DEBUG(5,("Attempting to find an passdb backend to match %s (%s)\n", selected, module_name));
index aee6495759308a362026277c5ef6794c9bd6b3e4..009425c5f6c86e1c9d069113ea23738306cb17f5 100644 (file)
@@ -333,6 +333,8 @@ static NTSTATUS ldapsam_delete_entry(struct ldapsam_privates *ldap_state,
 
 /* New Interface is being implemented here */
 
+#if 0  /* JERRY - not uesed anymore */
+
 /**********************************************************************
 Initialize SAM_ACCOUNT from an LDAP query (unix attributes only)
 *********************************************************************/
@@ -385,6 +387,7 @@ static BOOL get_unix_attributes (struct ldapsam_privates *ldap_state,
        return True;
 }
 
+#endif
 
 /**********************************************************************
 Initialize SAM_ACCOUNT from an LDAP query
@@ -419,8 +422,9 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
        uint32 hours_len;
        uint8           hours[MAX_HOURS_LEN];
        pstring temp;
+       struct passwd   *pw = NULL;
        uid_t           uid = -1;
-       gid_t           gid = getegid();
+       gid_t           gid = -1;
 
        /*
         * do a little initialization
@@ -455,6 +459,14 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
 
        DEBUG(2, ("Entry found for user: %s\n", username));
 
+       /* I'm not going to fail here, since there are checks 
+          higher up the cal stack to do this   --jerry */
+
+       if ( (pw=Get_Pwnam(username)) != NULL ) {
+               uid = pw->pw_uid;
+               gid = pw->pw_gid;
+       }
+
        pstrcpy(nt_username, username);
 
        pstrcpy(domain, ldap_state->domain_name);
@@ -523,6 +535,7 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
        }
 
 
+#if 0  /* JERRY -- not used anymore */
        /* 
         * If so configured, try and get the values from LDAP 
         */
@@ -541,6 +554,7 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
                        }
                }
        }
+#endif
 
        if (!smbldap_get_single_attribute(ldap_state->smbldap_state->ldap_struct, entry, 
                get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_LAST_SET), temp)) 
@@ -1685,7 +1699,7 @@ static BOOL init_group_from_ldap(struct ldapsam_privates *ldap_state,
                        get_attr_key2string( groupmap_attr_list, LDAP_ATTR_GROUP_TYPE)));
                return False;
        }
-       map->sid_name_use = (uint32)atol(temp);
+       map->sid_name_use = (enum SID_NAME_USE)atol(temp);
 
        if ((map->sid_name_use < SID_NAME_USER) ||
            (map->sid_name_use > SID_NAME_UNKNOWN)) {
@@ -2128,7 +2142,6 @@ static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods,
        GROUP_MAP map;
        GROUP_MAP *mapt;
        int entries = 0;
-       NTSTATUS nt_status;
 
        *num_entries = 0;
        *rmap = NULL;
@@ -2138,7 +2151,7 @@ static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods,
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       while (NT_STATUS_IS_OK(nt_status = ldapsam_getsamgrent(methods, &map))) {
+       while (NT_STATUS_IS_OK(ldapsam_getsamgrent(methods, &map))) {
                if (sid_name_use != SID_NAME_UNKNOWN &&
                    sid_name_use != map.sid_name_use) {
                        DEBUG(11,("enum_group_mapping: group %s is not of the requested type\n", map.nt_name));
index d3eb7cb975e42dc2c5413f18c38ef252c344264d..6c200be5045b9439a6f2d17ed0944f61a0278432 100644 (file)
@@ -240,9 +240,9 @@ static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u)
        pdb_set_unknown_str(u, row[16], PDB_SET);
        pdb_set_munged_dial(u, row[17], PDB_SET);
 
-       string_to_sid(&sid, row[18]);
+       if(row[18])string_to_sid(&sid, row[18]);
        pdb_set_user_sid(u, &sid, PDB_SET);
-       string_to_sid(&sid, row[19]);
+       if(row[19])string_to_sid(&sid, row[19]);
        pdb_set_group_sid(u, &sid, PDB_SET);
 
        if (pdb_gethexpwd(row[20], temp), PDB_SET)
index ea67da23a552a04de4a76a6dab9dc7bc69991e04..027cd0b5d3353fa44f64f8d6562ece8aa3ea74c1 100644 (file)
@@ -41,9 +41,11 @@ NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con
        if (p) {
                *p = 0;
                plugin_location = p+1;
-               trim_string(plugin_location, " ", " ");
-       } else plugin_location = NULL;
-       trim_string(plugin_name, " ", " ");
+               trim_char(plugin_location, ' ', ' ');
+       } else {
+               plugin_location = NULL;
+       }
+       trim_char(plugin_name, ' ', ' ');
 
        DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name));
        dl_handle = sys_dlopen(plugin_name, RTLD_NOW );
index 7c2156455aa713a953a878232ed3e0fa4eff395f..c9a84f3242c2e06a69031101ca604c66d025e846 100644 (file)
@@ -133,7 +133,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *
        }
   
        /* unpack the buffer */
-       if (!init_sam_from_buffer(user, data.dptr, data.dsize)) {
+       if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) {
                DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
                SAFE_FREE(data.dptr);
                return nt_status;
@@ -213,7 +213,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods, SAM_ACCOUNT
        }
   
        /* unpack the buffer */
-       if (!init_sam_from_buffer(user, data.dptr, data.dsize)) {
+       if (!init_sam_from_buffer(user, (unsigned char *)data.dptr, data.dsize)) {
                DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n"));
                SAFE_FREE(data.dptr);
                tdb_close(pwd_tdb);
@@ -390,7 +390,7 @@ static BOOL tdb_update_sam(struct pdb_methods *my_methods, SAM_ACCOUNT* newpwd,
                ret = False;
                goto done;
        }
-       data.dptr = buf;
+       data.dptr = (char *)buf;
 
        fstrcpy(name, pdb_get_username(newpwd));
        strlower_m(name);
index 23413e4026c45601b0c656e309adfb9113935aad..8a146f0d6887fd606d47a59b0e115577acf4573b 100644 (file)
@@ -58,7 +58,7 @@ void *secrets_fetch(const char *key, size_t *size)
        secrets_init();
        if (!tdb)
                return NULL;
-       kbuf.dptr = key;
+       kbuf.dptr = (char *)key;
        kbuf.dsize = strlen(key);
        dbuf = tdb_fetch(tdb, kbuf);
        if (size)
@@ -74,9 +74,9 @@ BOOL secrets_store(const char *key, const void *data, size_t size)
        secrets_init();
        if (!tdb)
                return False;
-       kbuf.dptr = key;
+       kbuf.dptr = (char *)key;
        kbuf.dsize = strlen(key);
-       dbuf.dptr = data;
+       dbuf.dptr = (char *)data;
        dbuf.dsize = size;
        return tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) == 0;
 }
@@ -90,7 +90,7 @@ BOOL secrets_delete(const char *key)
        secrets_init();
        if (!tdb)
                return False;
-       kbuf.dptr = key;
+       kbuf.dptr = (char *)key;
        kbuf.dsize = strlen(key);
        return tdb_delete(tdb, kbuf) == 0;
 }
@@ -738,3 +738,56 @@ BOOL must_use_pdc( const char *domain )
 
 }
 
+/*******************************************************************************
+ Store a complete AFS keyfile into secrets.tdb.
+*******************************************************************************/
+
+BOOL secrets_store_afs_keyfile(const char *cell, const struct afs_keyfile *keyfile)
+{
+       fstring key;
+
+       if ((cell == NULL) || (keyfile == NULL))
+               return False;
+
+       if (ntohl(keyfile->nkeys) > SECRETS_AFS_MAXKEYS)
+               return False;
+
+       slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_AFS_KEYFILE, cell);
+       return secrets_store(key, keyfile, sizeof(struct afs_keyfile));
+}
+
+/*******************************************************************************
+ Fetch the current (highest) AFS key from secrets.tdb
+*******************************************************************************/
+BOOL secrets_fetch_afs_key(const char *cell, struct afs_key *result)
+{
+       fstring key;
+       struct afs_keyfile *keyfile;
+       size_t size;
+       uint32 i;
+
+       slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_AFS_KEYFILE, cell);
+
+       keyfile = (struct afs_keyfile *)secrets_fetch(key, &size);
+
+       if (keyfile == NULL)
+               return False;
+
+       if (size != sizeof(struct afs_keyfile)) {
+               SAFE_FREE(keyfile);
+               return False;
+       }
+
+       i = ntohl(keyfile->nkeys);
+
+       if (i > SECRETS_AFS_MAXKEYS) {
+               SAFE_FREE(keyfile);
+               return False;
+       }
+
+       *result = keyfile->entry[i-1];
+
+       result->kvno = ntohl(result->kvno);
+
+       return True;
+}
index 0acca67b7044aa470a2ec32b1b0c82db65313f20..111617e3aed5ced8ddf870fc458a6e8987bf9be1 100644 (file)
@@ -766,14 +766,14 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
 
   /* Make sure the status is valid */
   parse_line.space2 = '\0';
-  trim_string(parse_line.status, NULL, " ");
+  trim_char(parse_line.status, '\0', ' ');
   if (!strequal(parse_line.status, LPRNT_PRINTING) &&
       !strequal(parse_line.status, LPRNT_PAUSED) &&
       !strequal(parse_line.status, LPRNT_WAITING))
     return(False);
   
   parse_line.space3 = '\0';
-  trim_string(parse_line.jobname, NULL, " ");
+  trim_char(parse_line.jobname, '\0', ' ');
 
   buf->job = atoi(parse_line.jobid);
   buf->priority = 0;
@@ -837,7 +837,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
 
   /* Get the job name */
   parse_line.space2[0] = '\0';
-  trim_string(parse_line.jobname, NULL, " ");
+  trim_char(parse_line.jobname, '\0', ' ');
   fstrcpy(buf->fs_file, parse_line.jobname);
 
   buf->priority = 0;
@@ -850,7 +850,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
 
   /* Make sure we have a valid status */
   parse_line.space4[0] = '\0';
-  trim_string(parse_line.status, NULL, " ");
+  trim_char(parse_line.status, '\0', ' ');
   if (!strequal(parse_line.status, LPROS2_PRINTING) &&
       !strequal(parse_line.status, LPROS2_PAUSED) &&
       !strequal(parse_line.status, LPROS2_WAITING))
index 5e6e95ff7e21a31afc8b2067be0cd83faee02534..4859d785be68deb0967505f07b10234d6d0eab51 100644 (file)
@@ -204,13 +204,19 @@ struct table_node {
        int     version;
 };
  
+#define SPL_ARCH_WIN40         "WIN40"
+#define SPL_ARCH_W32X86                "W32X86"
+#define SPL_ARCH_W32MIPS       "W32MIPS"
+#define SPL_ARCH_W32ALPHA      "W32ALPHA"
+#define SPL_ARCH_W32PPC                "W32PPC"
+
 static const struct table_node archi_table[]= {
 
-       {"Windows 4.0",          "WIN40",       0 },
-       {"Windows NT x86",       "W32X86",      2 },
-       {"Windows NT R4000",     "W32MIPS",     2 },
-       {"Windows NT Alpha_AXP", "W32ALPHA",    2 },
-       {"Windows NT PowerPC",   "W32PPC",      2 },
+       {"Windows 4.0",          SPL_ARCH_WIN40,        0 },
+       {"Windows NT x86",       SPL_ARCH_W32X86,       2 },
+       {"Windows NT R4000",     SPL_ARCH_W32MIPS,      2 },
+       {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA,     2 },
+       {"Windows NT PowerPC",   SPL_ARCH_W32PPC,       2 },
        {NULL,                   "",            -1 }
 };
 
@@ -1755,6 +1761,11 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
        ZERO_STRUCT(driver);
 
        architecture = get_short_archi(arch);
+       
+       /* Windows 4.0 (i.e. win9x) should always use a version of 0 */
+       
+       if ( strcmp( architecture, SPL_ARCH_WIN40 ) == 0 )
+               version = 0;
 
        DEBUG(8,("get_a_printer_driver_3: [%s%s/%d/%s]\n", DRIVERS_PREFIX, architecture, version, drivername));
 
@@ -2015,7 +2026,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info)
 
        if (info->servername[0]!='\0') {
                trim_string(info->printername, info->servername, NULL);
-               trim_string(info->printername, "\\", NULL);
+               trim_char(info->printername, '\\', '\0');
                info->servername[0]='\0';
        }
 
@@ -2245,7 +2256,7 @@ int unpack_devicemode(NT_DEVICEMODE **nt_devmode, char *buf, int buflen)
        int len = 0;
        int extra_len = 0;
        NT_DEVICEMODE devmode;
-
+       
        ZERO_STRUCT(devmode);
 
        len += tdb_unpack(buf+len, buflen-len, "p", nt_devmode);
@@ -2886,6 +2897,11 @@ WERROR delete_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key, const
        key_index = lookup_printerkey( &p2->data, key );
        if ( key_index == -1 )
                return WERR_OK;
+       
+       /* make sure the value exists so we can return the correct error code */
+       
+       if ( !regval_ctr_getvalue( &p2->data.keys[key_index].values, value ) )
+               return WERR_BADFILE;
                
        regval_ctr_delvalue( &p2->data.keys[key_index].values, value );
        
@@ -2919,7 +2935,7 @@ WERROR add_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key, const cha
                return WERR_NOMEM;
        
        regval_ctr_addvalue( &p2->data.keys[key_index].values, value,
-               type, data, real_len );
+               type, (const char *)data, real_len );
        
        DEBUG(8,("add_printer_data: Added key => [%s], value => [%s], type=> [%d], size => [%d]\n",
                key, value, type, real_len  ));
@@ -3012,7 +3028,7 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen)
                
                /* add the new value */
                
-               regval_ctr_addvalue( &printer_data->keys[key_index].values, valuename, type, data_p, size );
+               regval_ctr_addvalue( &printer_data->keys[key_index].values, valuename, type, (const char *)data_p, size );
 
                SAFE_FREE(data_p); /* 'B' option to tdbpack does a malloc() */
 
@@ -3195,6 +3211,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sh
        int             len = 0;
        TDB_DATA kbuf, dbuf;
        fstring printername;
+       char adevice[MAXDEVICENAME];
                
        ZERO_STRUCT(info);
 
@@ -3255,6 +3272,10 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sh
                        printername));
                info.devmode = construct_nt_devicemode(printername);
        }
+       
+       safe_strcpy(adevice, info.printername, sizeof(adevice)-1);
+       fstrcpy(info.devmode->devicename, adevice);     
+
 
        len += unpack_values( &info.data, dbuf.dptr+len, dbuf.dsize-len );
 
index 4204f43f7b9dbe0c9d31f4ca8b3cb69fab98d53a..07191be86822e47b1a75bf6ba85841970c95886d 100644 (file)
@@ -104,8 +104,7 @@ done:
                if (cli)
                        cli_shutdown(cli);
 
-               if (mem_ctx)
-                       talloc_destroy(mem_ctx);
+               talloc_destroy(mem_ctx);
        }
 
        return result;
@@ -141,12 +140,13 @@ static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw)
 
 static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 {
-       PyObject *py_names, *result;
+       PyObject *py_names, *result = NULL;
        NTSTATUS ntstatus;
        lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self;
        int num_names, i;
        const char **names;
        DOM_SID *sids;
+       TALLOC_CTX *mem_ctx = NULL;
        uint32 *name_types;
 
        if (!PyArg_ParseTuple(args, "O", &py_names))
@@ -157,18 +157,22 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
                return NULL;
        }
 
+       if (!(mem_ctx = talloc_init("lsa_lookup_names"))) {
+               PyErr_SetString(lsa_error, "unable to init talloc context\n");
+               goto done;
+       }
+
        if (PyList_Check(py_names)) {
 
                /* Convert list to char ** array */
 
                num_names = PyList_Size(py_names);
-               names = (const char **)talloc(
-                       hnd->mem_ctx, num_names * sizeof(char *));
+               names = (const char **)talloc(mem_ctx, num_names * sizeof(char *));
                
                for (i = 0; i < num_names; i++) {
                        PyObject *obj = PyList_GetItem(py_names, i);
                        
-                       names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj));
+                       names[i] = talloc_strdup(mem_ctx, PyString_AsString(obj));
                }
 
        } else {
@@ -176,17 +180,17 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
                /* Just a single element */
 
                num_names = 1;
-               names = (const char **)talloc(hnd->mem_ctx, sizeof(char *));
+               names = (const char **)talloc(mem_ctx, sizeof(char *));
 
                names[0] = PyString_AsString(py_names);
        }
 
-       ntstatus = cli_lsa_lookup_names(hnd->cli, hnd->mem_ctx, &hnd->pol,
+       ntstatus = cli_lsa_lookup_names(hnd->cli, mem_ctx, &hnd->pol,
                                        num_names, names, &sids, &name_types);
 
        if (!NT_STATUS_IS_OK(ntstatus) && NT_STATUS_V(ntstatus) != 0x107) {
                PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus));
-               return NULL;
+               goto done;
        }
 
        result = PyList_New(num_names);
@@ -196,10 +200,13 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 
                py_from_SID(&sid_obj, &sids[i]);
 
-               obj = Py_BuildValue("(Oi)", sid_obj, name_types[i]);
+               obj = Py_BuildValue("(Ni)", sid_obj, name_types[i]);
 
                PyList_SetItem(result, i, obj);
        }
+
+ done:
+       talloc_destroy(mem_ctx);
        
        return result;
 }
@@ -207,7 +214,7 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, 
                                 PyObject *kw) 
 {
-       PyObject *py_sids, *result;
+       PyObject *py_sids, *result = NULL;
        NTSTATUS ntstatus;
        int num_sids, i;
        char **domains, **names;
@@ -224,7 +231,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                return NULL;
        }
 
-       if (!(mem_ctx = talloc_init("lsa_open_policy"))) {
+       if (!(mem_ctx = talloc_init("lsa_lookup_sids"))) {
                PyErr_SetString(lsa_error, "unable to init talloc context\n");
                goto done;
        }
@@ -243,7 +250,6 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                        
                        if (!string_to_sid(&sids[i], PyString_AsString(obj))) {
                                PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
-                               result = NULL;
                                goto done;
                        }
                }
@@ -257,7 +263,6 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
 
                if (!string_to_sid(&sids[0], PyString_AsString(py_sids))) {
                        PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
-                       result = NULL;
                        goto done;
                }
        }
@@ -268,7 +273,6 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
 
        if (!NT_STATUS_IS_OK(ntstatus)) {
                PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus));
-               result = NULL;
                goto done;
        }
 
@@ -285,8 +289,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
        }
 
  done:
-       if (mem_ctx)
-               talloc_destroy(mem_ctx);
+       talloc_destroy(mem_ctx);
 
        return result;
 }
@@ -404,7 +407,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.setup_logging(interactive = 1)" },
+">>> lsa.setup_logging(interactive = 1)" },
 
        { "get_debuglevel", (PyCFunction)get_debuglevel, 
          METH_VARARGS, 
@@ -412,7 +415,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.get_debuglevel()\n"
+">>> lsa.get_debuglevel()\n"
 "0" },
 
        { "set_debuglevel", (PyCFunction)set_debuglevel, 
@@ -421,7 +424,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.set_debuglevel(10)" },
+">>> lsa.set_debuglevel(10)" },
 
        { NULL }
 };
index bb84a337c93214f84add2cd96f2cbaa162047196..e5e65061965f9a5395b30018ceb73423b65efd1e 100644 (file)
@@ -221,10 +221,10 @@ static PyObject *py_smb_query_secdesc(PyObject *self, PyObject *args,
 {
        cli_state_object *cli = (cli_state_object *)self;
        static char *kwlist[] = { "fnum", NULL };
-       PyObject *result;
+       PyObject *result = NULL;
        SEC_DESC *secdesc = NULL;
        int fnum;
-       TALLOC_CTX *mem_ctx;
+       TALLOC_CTX *mem_ctx = NULL;
 
        /* Parse parameters */
 
@@ -238,7 +238,6 @@ static PyObject *py_smb_query_secdesc(PyObject *self, PyObject *args,
 
        if (cli_is_error(cli->cli)) {
                PyErr_SetString(PyExc_RuntimeError, "query_secdesc failed");
-               result = NULL;
                goto done;
        }
 
@@ -252,7 +251,6 @@ static PyObject *py_smb_query_secdesc(PyObject *self, PyObject *args,
                PyErr_SetString(
                        PyExc_TypeError,
                        "Invalid security descriptor returned");
-               result = NULL;
                goto done;
        }
 
@@ -268,11 +266,12 @@ static PyObject *py_smb_set_secdesc(PyObject *self, PyObject *args,
 {
        cli_state_object *cli = (cli_state_object *)self;
        static char *kwlist[] = { "fnum", "security_descriptor", NULL };
+       PyObject *result = NULL;
        PyObject *py_secdesc;
        SEC_DESC *secdesc;
-       TALLOC_CTX *mem_ctx = talloc_init("py_smb_set_secdesc");
+       TALLOC_CTX *mem_ctx = NULL;
        int fnum;
-       BOOL result;
+       BOOL err;
 
        /* Parse parameters */
 
@@ -280,20 +279,26 @@ static PyObject *py_smb_set_secdesc(PyObject *self, PyObject *args,
                    args, kw, "iO", kwlist, &fnum, &py_secdesc))
                return NULL;
 
+       mem_ctx = talloc_init("py_smb_set_secdesc");
+
        if (!py_to_SECDESC(&secdesc, py_secdesc, mem_ctx)) {
                PyErr_SetString(PyExc_TypeError, 
                                "Invalid security descriptor");
-               return NULL;
+               goto done;
        }
 
-       result = cli_set_secdesc(cli->cli, fnum, secdesc);
+       err = cli_set_secdesc(cli->cli, fnum, secdesc);
 
        if (cli_is_error(cli->cli)) {
                PyErr_SetString(PyExc_RuntimeError, "set_secdesc failed");
-               return NULL;
+               goto done;
        }
 
-       return PyInt_FromLong(result);
+       result =  PyInt_FromLong(err);
+ done:
+       talloc_destroy(mem_ctx);
+
+       return result;
 }
 
 static PyMethodDef smb_hnd_methods[] = {
index a072ac0d5c0afc94edfe3903dca45e07e7e53c7a..12190519ecc84d60ef3b8ad1ebfbc231696b4dcf 100644 (file)
@@ -177,6 +177,7 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
        int level = 1;
        uint32 needed;
        char *arch = "Windows NT x86";
+       int version = 2;
        static char *kwlist[] = {"level", "arch", NULL};
 
        /* Parse parameters */
@@ -189,12 +190,12 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
 
        werror = cli_spoolss_getprinterdriver(
                hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
-               arch, &ctr);
+               version, arch, &ctr);
 
        if (W_ERROR_V(werror) == ERRinsufficientbuffer)
                werror = cli_spoolss_getprinterdriver(
                        hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
-                       level, arch, &ctr);
+                       level, version, arch, &ctr);
 
        if (!W_ERROR_IS_OK(werror)) {
                PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
index ebceb95d718f579067cc51b037dfab53143c3c21..130f78d7e126e424330232f0177f10f1017b4a2a 100644 (file)
@@ -427,7 +427,10 @@ static PyObject *py_auth_crap(PyObject *self, PyObject *args, PyObject *kw)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       fstrcpy(request.data.auth_crap.user, username);
+       if (push_utf8_fstring(request.data.auth_crap.user, username) == -1) {
+               PyErr_SetString(winbind_error, "unable to create utf8 string");
+               return NULL;
+       }
 
        generate_random_buffer(request.data.auth_crap.chal, 8, False);
         
@@ -473,7 +476,10 @@ static PyObject *py_auth_smbd(PyObject *self, PyObject *args, PyObject *kw)
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
-       fstrcpy(request.data.smbd_auth_crap.user, username);
+       if (push_utf8_fstring(request.data.auth_crap.user, username) == -1) {
+               PyErr_SetString("unable to create utf8 string");
+               return NULL;
+       }
 
        generate_random_buffer(request.data.smbd_auth_crap.chal, 8, False);
         
index 7b8cd19174d0440d4d199a1f7331a4423d71a745..97bc4c65b76c68985580c0709bbc859242f9d9d9 100644 (file)
@@ -514,7 +514,7 @@ NTSTATUS cli_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx,
                               0, /* param_ctrl */
                               0xdead, 0xbeef, /* LUID? */
                               username, cli->clnt_name_slash,
-                              cli->sess_key, lm_owf_user_pwd,
+                              (const char *)cli->sess_key, lm_owf_user_pwd,
                               nt_owf_user_pwd);
 
                 break;
@@ -685,31 +685,20 @@ NTSTATUS cli_net_srv_pwset(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        NET_Q_SRV_PWSET q_s;
        uint16 sec_chan_type = 2;
        NTSTATUS nt_status;
-       char *mach_acct;
 
        gen_next_creds( cli, &new_clnt_cred);
        
        prs_init(&qbuf , 1024, mem_ctx, MARSHALL);
        prs_init(&rbuf, 0,    mem_ctx, UNMARSHALL);
        
-       /* create and send a MSRPC command with api NET_SRV_PWSET */
-       
-       mach_acct = talloc_asprintf(mem_ctx, "%s$", machine_name);
-       
-       if (!mach_acct) {
-               DEBUG(0,("talloc_asprintf failed!\n"));
-               nt_status = NT_STATUS_NO_MEMORY;
-               goto done;
-       }
-
        DEBUG(4,("cli_net_srv_pwset: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
-                cli->srv_name_slash, mach_acct, sec_chan_type, machine_name,
+                cli->srv_name_slash, cli->mach_acct, sec_chan_type, machine_name,
                 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
        
         /* store the parameters */
-       init_q_srv_pwset(&q_s, cli->srv_name_slash, cli->sess_key,
-                        mach_acct, sec_chan_type, machine_name, 
-                        &new_clnt_cred, (char *)hashed_mach_pwd);
+       init_q_srv_pwset(&q_s, cli->srv_name_slash, (const char *)cli->sess_key,
+                        cli->mach_acct, sec_chan_type, machine_name, 
+                        &new_clnt_cred, hashed_mach_pwd);
        
        /* turn parameters into data stream */
        if(!net_io_q_srv_pwset("", &q_s,  &qbuf, 0)) {
index ebe54c2c06f7918fe08f768f2952ea956a5c37fb..dedbf017a93a04caae8bc4f9055e36cea4fc5f5b 100644 (file)
@@ -264,7 +264,7 @@ static BOOL rpc_auth_pipe(struct cli_state *cli, prs_struct *rdata,
                        DATA_BLOB ntlmssp_verf = data_blob(NULL, auth_len);
                        
                        /* save the reply away, for use a little later */
-                       prs_copy_data_out(ntlmssp_verf.data, &auth_verf, auth_len);
+                       prs_copy_data_out((char *)ntlmssp_verf.data, &auth_verf, auth_len);
 
 
                        return (NT_STATUS_IS_OK(ntlmssp_client_store_response(cli->ntlmssp_pipe_state, 
@@ -287,7 +287,7 @@ static BOOL rpc_auth_pipe(struct cli_state *cli, prs_struct *rdata,
                                return False;
                        }
                        sig = data_blob(NULL, auth_len);
-                       prs_copy_data_out(sig.data, &auth_verf, auth_len);
+                       prs_copy_data_out((char *)sig.data, &auth_verf, auth_len);
                }
        
                /*
@@ -306,12 +306,12 @@ static BOOL rpc_auth_pipe(struct cli_state *cli, prs_struct *rdata,
                                return False;
                        }
                        nt_status = ntlmssp_client_unseal_packet(cli->ntlmssp_pipe_state, 
-                                                                reply_data, data_len,
+                                                                (unsigned char *)reply_data, data_len,
                                                                 &sig);
                } 
                else if (cli->pipe_auth_flags & AUTH_PIPE_SIGN) {
                        nt_status = ntlmssp_client_check_packet(cli->ntlmssp_pipe_state, 
-                                                               reply_data, data_len,
+                                                               (const unsigned char *)reply_data, data_len,
                                                                &sig);
                }
 
@@ -684,10 +684,10 @@ static NTSTATUS create_rpc_bind_req(struct cli_state *cli, prs_struct *rpc_out,
 
                /* Auth len in the rpc header doesn't include auth_header. */
                auth_len = request.length;
-               prs_copy_data_in(&auth_info, request.data, request.length);
+               prs_copy_data_in(&auth_info, (char *)request.data, request.length);
 
                DEBUG(5, ("NTLMSSP Negotiate:\n"));
-               dump_data(5, request.data, request.length);
+               dump_data(5, (const char *)request.data, request.length);
 
                data_blob_free(&request);
 
@@ -751,6 +751,7 @@ static NTSTATUS create_rpc_bind_req(struct cli_state *cli, prs_struct *rpc_out,
                        return NT_STATUS_NO_MEMORY;
                }
        }
+       prs_mem_free(&auth_info);
        return NT_STATUS_OK;
 }
 
@@ -810,7 +811,7 @@ static NTSTATUS create_rpc_bind_resp(struct cli_state *cli,
         * Append the auth data to the outgoing buffer.
         */
 
-       if(!prs_copy_data_in(rpc_out, ntlmssp_reply.data, ntlmssp_reply.length)) {
+       if(!prs_copy_data_in(rpc_out, (char *)ntlmssp_reply.data, ntlmssp_reply.length)) {
                DEBUG(0,("create_rpc_bind_req: failed to grow parse struct to add auth.\n"));
                data_blob_free(&ntlmssp_reply);
                return NT_STATUS_NO_MEMORY;
@@ -1016,7 +1017,7 @@ BOOL rpc_api_pipe_req(struct cli_state *cli, uint8 op_num,
                                /* write auth footer onto the packet */
                                real_auth_len = sign_blob.length;
                                
-                               prs_copy_data_in(&sec_blob, sign_blob.data, sign_blob.length);
+                               prs_copy_data_in(&sec_blob, (char *)sign_blob.data, sign_blob.length);
                                data_blob_free(&sign_blob);
 
                        }
@@ -1492,7 +1493,9 @@ NTSTATUS cli_nt_establish_netlogon(struct cli_state *cli, int sec_chan,
                                   const uchar trust_password[16])
 {
        NTSTATUS result;        
-       uint32 neg_flags = 0x000001ff;
+       /* The 7 here seems to be required to get Win2k not to downgrade us
+          to NT4.  Actually, anything other than 1ff would seem to do... */
+       uint32 neg_flags = 0x000701ff;
        int fnum;
 
        cli_nt_netlogon_netsec_session_close(cli);
@@ -1585,7 +1588,9 @@ NTSTATUS cli_nt_setup_netsec(struct cli_state *cli, int sec_chan,
                             const uchar trust_password[16])
 {
        NTSTATUS result;        
-       uint32 neg_flags = 0x000001ff;
+       /* The 7 here seems to be required to get Win2k not to downgrade us
+          to NT4.  Actually, anything other than 1ff would seem to do... */
+       uint32 neg_flags = 0x000701ff;
        cli->pipe_auth_flags = 0;
 
        if (lp_client_schannel() == False) {
index 63926204978d8af19b788172de4d1d16e26c7dcc..8f5f2413deec38d4daa829568fc433970912ddd7 100644 (file)
@@ -720,7 +720,7 @@ WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
                                    TALLOC_CTX *mem_ctx, 
                                    uint32 offered, uint32 *needed,
                                    POLICY_HND *pol, uint32 level, 
-                                   const char *env, PRINTER_DRIVER_CTR *ctr)
+                                   const char *env, int version, PRINTER_DRIVER_CTR *ctr)
 {
        prs_struct qbuf, rbuf;
        SPOOL_Q_GETPRINTERDRIVER2 q;
@@ -742,7 +742,7 @@ WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
        prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
        prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
 
-       make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2,
+       make_spoolss_q_getprinterdriver2(&q, pol, env, level, version, 2,
                                         &buffer, offered);
 
        /* Marshall data and send request */
@@ -2027,7 +2027,7 @@ WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        /* Initialise input parameters */
 
         make_spoolss_q_setprinterdata(
-               &q, hnd, value->valuename, value->type, value->data_p, value->size);
+               &q, hnd, value->valuename, value->type, (char *)value->data_p, value->size);
 
        /* Marshall data and send request */
 
@@ -2072,7 +2072,7 @@ WERROR cli_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        /* Initialise input parameters */
 
         make_spoolss_q_setprinterdataex(
-               &q, hnd, keyname, value->valuename, value->type, value->data_p, 
+               &q, hnd, keyname, value->valuename, value->type, (char *)value->data_p, 
                value->size);
 
        /* Marshall data and send request */
@@ -2215,7 +2215,7 @@ WERROR cli_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
 
                rpcstr_pull(name, v->valuename.buffer, sizeof(name), -1, 
                            STR_TERMINATE);
-               regval_ctr_addvalue(ctr, name, v->type, v->data, v->data_len);
+               regval_ctr_addvalue(ctr, name, v->type, (const char *)v->data, v->data_len);
        }
 
  done:
index 67f9ad772eec7091a079354170bbe3de6c0bfa73..4b1ff1f4d545d35811dca7645fdebc02c95a0160 100644 (file)
@@ -73,7 +73,7 @@ BOOL echo_io_q_echo_data(const char *desc, ECHO_Q_ECHO_DATA *q_d,
                        return False;
        }
 
-       if (!prs_uint8s(False, "data", ps, depth, q_d->data, q_d->size))
+       if (!prs_uint8s(False, "data", ps, depth, (unsigned char *)q_d->data, q_d->size))
                return False;
 
        return True;
@@ -92,7 +92,7 @@ BOOL echo_io_r_echo_data(const char *desc, ECHO_R_ECHO_DATA *q_d,
                        return False;
        }
 
-       if (!prs_uint8s(False, "data", ps, depth, q_d->data, q_d->size))
+       if (!prs_uint8s(False, "data", ps, depth, (unsigned char *)q_d->data, q_d->size))
                return False;
 
        return True;
@@ -120,7 +120,7 @@ BOOL echo_io_q_sink_data(const char *desc, ECHO_Q_SINK_DATA *q_d,
                        return False;
        }
 
-       if (!prs_uint8s(False, "data", ps, depth, q_d->data, q_d->size))
+       if (!prs_uint8s(False, "data", ps, depth, (unsigned char *)q_d->data, q_d->size))
                return False;
 
        return True;
@@ -159,7 +159,7 @@ BOOL echo_io_r_source_data(const char *desc, ECHO_R_SOURCE_DATA *q_d,
                        return False;
        }
 
-       if (!prs_uint8s(False, "data", ps, depth, q_d->data, q_d->size))
+       if (!prs_uint8s(False, "data", ps, depth, (unsigned char *)q_d->data, q_d->size))
                return False;
 
        return True;
index 804da707dedc4f01dd422091656860670de5e8c6..dd319df5a0fcfe8fb72414055c4611d43df992f8 100644 (file)
@@ -801,7 +801,7 @@ void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s,
        DEBUG(5,("init_q_srv_pwset\n"));
        
        /* Process the new password. */
-       cred_hash3( nt_cypher, hashed_mach_pwd, sess_key, 1);
+       cred_hash3( nt_cypher, hashed_mach_pwd, (const unsigned char *)sess_key, 1);
 
        init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
 
@@ -2447,6 +2447,10 @@ static BOOL net_io_sam_policy_info(const char *desc, SAM_DELTA_POLICY *info,
        return True;
 }
 
+#if 0
+
+/* This function is pretty broken - see bug #334 */
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -2495,6 +2499,12 @@ static BOOL net_io_sam_trustdoms_info(const char *desc, SAM_DELTA_TRUSTDOMS *inf
        return True;
 }
 
+#endif
+
+#if 0
+
+/* This function doesn't work - see bug #334 */
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -2582,6 +2592,8 @@ static BOOL net_io_sam_secret_info(const char *desc, SAM_DELTA_SECRET *info,
        return True;
 }
 
+#endif
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
@@ -2726,14 +2738,10 @@ static BOOL net_io_sam_delta_ctr(const char *desc, uint8 sess_key[16],
                                 return False;
                        break;
 
-               case SAM_DELTA_TRUST_DOMS:
-                       if (!net_io_sam_trustdoms_info("", &delta->trustdoms_info, ps, depth))
-                                return False;
-                       break;
+                       /* These guys are implemented but broken */
 
+               case SAM_DELTA_TRUST_DOMS:
                case SAM_DELTA_SECRET_INFO:
-                       if (!net_io_sam_secret_info("", &delta->secret_info, ps, depth))
-                                return False;
                        break;
 
                        /* These guys are not implemented yet */
index 11d8658b15d7c40a9debe39f4f15b4c842b29c1b..81a95730778595da0226ce2416ae3a5038683ccc 100644 (file)
@@ -1402,7 +1402,7 @@ static void netsec_digest(struct netsec_auth_struct *a,
        if (auth_flags & AUTH_PIPE_SEAL) {
                MD5Update(&ctx3, verf->data8, sizeof(verf->data8));
        }
-       MD5Update(&ctx3, data, data_len);
+       MD5Update(&ctx3, (const unsigned char *)data, data_len);
        MD5Final(whole_packet_digest, &ctx3);
        dump_data_pw("whole_packet_digest:\n", whole_packet_digest, sizeof(whole_packet_digest));
        
@@ -1429,7 +1429,7 @@ static void netsec_get_sealing_key(struct netsec_auth_struct *a,
        
        dump_data_pw("sess_kf0:\n", sess_kf0, sizeof(sess_kf0));
        
-       /* MD5 of sess_kf0 and the high bytes of the sequence number */
+       /* MD5 of sess_kf0 and 4 zero bytes */
        hmac_md5(sess_kf0, zeros, 0x4, digest2);
        dump_data_pw("digest2:\n", digest2, sizeof(digest2));
        
@@ -1506,9 +1506,9 @@ void netsec_encode(struct netsec_auth_struct *a, int auth_flags,
                dump_data_pw("verf->data8_enc:\n", verf->data8, sizeof(verf->data8));
                
                /* encode the packet payload */
-               dump_data_pw("data:\n", data, data_len);
-               netsechash(sealing_key, data, data_len);
-               dump_data_pw("data_enc:\n", data, data_len);
+               dump_data_pw("data:\n", (const unsigned char *)data, data_len);
+               netsechash(sealing_key, (unsigned char *)data, data_len);
+               dump_data_pw("data_enc:\n", (const unsigned char *)data, data_len);
        }
 
        /* encode the sequence number (key based on packet digest) */
@@ -1578,9 +1578,9 @@ BOOL netsec_decode(struct netsec_auth_struct *a, int auth_flags,
                             sizeof(verf->data8));
                
                /* extract the packet payload */
-               dump_data_pw("data   :\n", data, data_len);
-               netsechash(sealing_key, data, data_len);
-               dump_data_pw("datadec:\n", data, data_len);     
+               dump_data_pw("data   :\n", (const unsigned char *)data, data_len);
+               netsechash(sealing_key, (unsigned char *)data, data_len);
+               dump_data_pw("datadec:\n", (const unsigned char *)data, data_len);      
        }
 
        /* digest includes 'data' after unsealing */
index b4d20bf2baa32b66d4e6ffd96fce217ef388f254..bbf6e6a8e3de9cd5c9e20278951f19ffea0f70e9 100644 (file)
@@ -40,7 +40,7 @@ static uint32 reg_init_buffer2( BUFFER2 *buf2, REGISTRY_VALUE *val )
                return 0;
                
        real_size = regval_size(val);
-       init_buffer2( buf2, (char*)regval_data_p(val), real_size );
+       init_buffer2( buf2, (unsigned char*)regval_data_p(val), real_size );
 
        return real_size;
 }
index fce31952256e4366b479250240f23efe3b9fd5c3..1fe9b3231fcc656db8ee0aca2b7985cf872143b6 100644 (file)
@@ -183,9 +183,9 @@ BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
 reads or writes a structure.
 ********************************************************************/
 
-void init_samr_q_unknown_2d(SAMR_Q_UNKNOWN_2D * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
+void init_samr_q_remove_user_foreign_domain(SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
 {
-       DEBUG(5, ("samr_init_samr_q_unknown_2d\n"));
+       DEBUG(5, ("samr_init_samr_q_remove_user_foreign_domain\n"));
 
        q_u->dom_pol = *dom_pol;
        init_dom_sid2(&q_u->sid, sid);
@@ -195,13 +195,13 @@ void init_samr_q_unknown_2d(SAMR_Q_UNKNOWN_2D * q_u, POLICY_HND *dom_pol, DOM_SI
 reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_unknown_2d(const char *desc, SAMR_Q_UNKNOWN_2D * q_u,
+BOOL samr_io_q_remove_user_foreign_domain(const char *desc, SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN * q_u,
                          prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_unknown_2d");
+       prs_debug(ps, depth, desc, "samr_io_q_remove_user_foreign_domain");
        depth++;
 
        if(!prs_align(ps))
@@ -223,13 +223,13 @@ BOOL samr_io_q_unknown_2d(const char *desc, SAMR_Q_UNKNOWN_2D * q_u,
 reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_unknown_2d(const char *desc, SAMR_R_UNKNOWN_2D * r_u,
+BOOL samr_io_r_remove_user_foreign_domain(const char *desc, SAMR_R_REMOVE_USER_FOREIGN_DOMAIN * r_u,
                          prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_2d");
+       prs_debug(ps, depth, desc, "samr_io_r_remove_user_foreign_domain");
        depth++;
 
        if(!prs_align(ps))
index 1a380c64d556502c9f48cc4be0caa5ebf93169f1..7ca9bccab461625e583936dd6fca2bd3dfecf13c 100644 (file)
@@ -1368,7 +1368,7 @@ BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u,
                return False;
        
        if (UNMARSHALLING(ps) && r_u->size) {
-               r_u->data = prs_alloc_mem(ps, r_u->size);
+               r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
                if(!r_u->data)
                        return False;
        }
@@ -6178,7 +6178,7 @@ BOOL make_spoolss_q_setprinterdata(SPOOL_Q_SETPRINTERDATA *q_u, const POLICY_HND
        init_unistr2(&q_u->value, value, strlen(value)+1);
 
        q_u->max_len = q_u->real_len = data_size;
-       q_u->data = data;
+       q_u->data = (unsigned char *)data;
        
        return True;
 }
@@ -6195,7 +6195,7 @@ BOOL make_spoolss_q_setprinterdataex(SPOOL_Q_SETPRINTERDATAEX *q_u, const POLICY
        init_unistr2(&q_u->key, key, strlen(key)+1);
 
        q_u->max_len = q_u->real_len = data_size;
-       q_u->data = data;
+       q_u->data = (unsigned char *)data;
        
        return True;
 }
@@ -6990,7 +6990,7 @@ BOOL spoolss_io_r_getprinterdataex(const char *desc, SPOOL_R_GETPRINTERDATAEX *r
                return False;
        
        if (UNMARSHALLING(ps) && r_u->size) {
-               r_u->data = prs_alloc_mem(ps, r_u->size);
+               r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
                if(!r_u->data)
                        return False;
        }
@@ -7689,7 +7689,7 @@ BOOL make_spoolss_q_writeprinter(SPOOL_Q_WRITEPRINTER *q_u,
 {
         memcpy(&q_u->handle, handle, sizeof(POLICY_HND));
        q_u->buffer_size = q_u->buffer_size2 = data_size;
-       q_u->buffer = data;
+       q_u->buffer = (unsigned char *)data;
        return True;
 }
 
index 27bb0732b47bc294011e2ff3a44f5c6eb14df8dd..6c35917e618cd5a1f4b5a25295b64b2799cc82f5 100644 (file)
@@ -157,17 +157,23 @@ static BOOL api_dfs_enum(pipes_struct *p)
 /*******************************************************************
 \pipe\netdfs commands
 ********************************************************************/
-
-NTSTATUS rpc_dfs_init(void)
+static struct api_struct api_netdfs_cmds[] =
 {
-  struct api_struct api_netdfs_cmds[] =
-    {
       {"DFS_EXIST",        DFS_EXIST,               api_dfs_exist    },
       {"DFS_ADD",          DFS_ADD,                 api_dfs_add      },
       {"DFS_REMOVE",       DFS_REMOVE,              api_dfs_remove   },
       {"DFS_GET_INFO",     DFS_GET_INFO,            api_dfs_get_info },
       {"DFS_ENUM",         DFS_ENUM,                api_dfs_enum     }
-    };
+};
+
+void netdfs_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_netdfs_cmds;
+       *n_fns = sizeof(api_netdfs_cmds) / sizeof(struct api_struct);
+}
+
+NTSTATUS rpc_dfs_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "netdfs", "netdfs", api_netdfs_cmds,
                                    sizeof(api_netdfs_cmds) / sizeof(struct api_struct));
 }
index eba4eaec756f9bc4761ef8bb43189c456fe7b4bd..3470ad99b458d51829375f704ef9019e9899a312 100644 (file)
@@ -159,7 +159,7 @@ WERROR _dfs_remove(pipes_struct *p, DFS_Q_DFS_REMOVE *q_u,
        {
          pstring refpath;
          pstrcpy(refpath,jn.referral_list[i].alternate_path);
-         trim_string(refpath, "\\", "\\");
+         trim_char(refpath, '\\', '\\');
          DEBUG(10,("_dfs_remove:  refpath: .%s.\n", refpath));
          if(strequal(refpath, altpath))
            {
@@ -257,7 +257,7 @@ static BOOL init_reply_dfs_info_3(TALLOC_CTX *ctx, struct junction_map* j, DFS_I
          struct referral* ref = &(j[i].referral_list[ii]);
          
          pstrcpy(path, ref->alternate_path);
-         trim_string(path,"\\","");
+         trim_char(path,'\\','\0');
          p = strrchr_m(path,'\\');
          if(p==NULL)
            {
index 166b6e939d2dea07468058ce1f2b1e17ce8eeb01..c6cfde07c15e678b23070352ec8cdd19fe1aea48 100644 (file)
@@ -120,18 +120,31 @@ static BOOL api_sink_data(pipes_struct *p)
 \pipe\rpcecho commands
 ********************************************************************/
 
-NTSTATUS rpc_echo_init(void)
+struct api_struct api_echo_cmds[] = {
+       {"ADD_ONE",       ECHO_ADD_ONE,     api_add_one },
+       {"ECHO_DATA",     ECHO_DATA,        api_echo_data },
+       {"SOURCE_DATA",   ECHO_SOURCE_DATA, api_source_data },
+       {"SINK_DATA",     ECHO_SINK_DATA,   api_sink_data },
+};
+
+
+void echo_get_pipe_fns( struct api_struct **fns, int *n_fns )
 {
-       struct api_struct api_echo_cmds[] = {
-               {"ADD_ONE",       ECHO_ADD_ONE,     api_add_one },
-               {"ECHO_DATA",     ECHO_DATA,        api_echo_data },
-               {"SOURCE_DATA",   ECHO_SOURCE_DATA, api_source_data },
-               {"SINK_DATA",     ECHO_SINK_DATA,   api_sink_data },
-       };
+       *fns = api_echo_cmds;
+       *n_fns = sizeof(api_echo_cmds) / sizeof(struct api_struct);
+}
 
+NTSTATUS rpc_echo_init(void)
+{
        return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION,
                "rpcecho", "rpcecho", api_echo_cmds,
                sizeof(api_echo_cmds) / sizeof(struct api_struct));
 }
 
+#else /* DEVELOPER */
+
+NTSTATUS rpc_echo_init(void)
+{
+       return NT_STATUS_OK;
+}
 #endif /* DEVELOPER */
index 34812b15d982c4828a8d5742fa28c8fb8b8f76c0..138fb1d7ef9adddf725c323f70257654e937bfb9 100644 (file)
@@ -644,9 +644,8 @@ static BOOL api_lsa_query_info2(pipes_struct *p)
 /***************************************************************************
  \PIPE\ntlsa commands
  ***************************************************************************/
-NTSTATUS rpc_lsa_init(void)
-{
-static const struct api_struct api_lsa_cmds[] =
+static struct api_struct api_lsa_cmds[] =
 {
        { "LSA_OPENPOLICY2"     , LSA_OPENPOLICY2     , api_lsa_open_policy2     },
        { "LSA_OPENPOLICY"      , LSA_OPENPOLICY      , api_lsa_open_policy      },
@@ -671,17 +670,33 @@ static const struct api_struct api_lsa_cmds[] =
           ADS DC capabilities                                               */
        { "LSA_QUERYINFO2"      , LSA_QUERYINFO2      , api_lsa_query_info2      }
 };
-/*
- * NOTE: Certain calls can not be enabled if we aren't an ADS DC.  Make sure
- * these calls are always last and that you decrement by the amount of calls
- * to disable.
- */
-  int funcs = sizeof(api_lsa_cmds) / sizeof(struct api_struct);
 
-  if (!(SEC_ADS == lp_security() && ROLE_DOMAIN_PDC == lp_server_role())) {
-         funcs -= 1;
-  }
+static int count_fns(void)
+{
+       int funcs = sizeof(api_lsa_cmds) / sizeof(struct api_struct);
+       
+       /*
+        * NOTE: Certain calls can not be enabled if we aren't an ADS DC.  Make sure
+        * these calls are always last and that you decrement by the amount of calls
+        * to disable.
+        */
+       if (!(SEC_ADS == lp_security() && ROLE_DOMAIN_PDC == lp_server_role())) {
+               funcs -= 1;
+       }
+
+       return funcs;
+}
+void lsa_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_lsa_cmds;
+       *n_fns = count_fns();
+}
+
+
+NTSTATUS rpc_lsa_init(void)
+{
+       int funcs = count_fns();
 
-  return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "lsarpc", "lsass", api_lsa_cmds, 
-                                   funcs);
+       return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "lsarpc", "lsass", api_lsa_cmds, 
+               funcs);
 }
diff --git a/source3/rpc_server/srv_lsa_ds.c b/source3/rpc_server/srv_lsa_ds.c
new file mode 100644 (file)
index 0000000..1e75175
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  RPC Pipe client / server routines
+ *  Copyright (C) Gerald Carter                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
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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.
+ */
+
+/* This is the interface for the registry functions. */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_SRV
+
+#if 0  /* disabled */
+/*******************************************************************
+ api_reg_open_entry
+ ********************************************************************/
+
+static BOOL api_dsrole_get_primary_dominfo(pipes_struct *p)
+{
+       DS_Q_GETPRIMDOMINFO q_u;
+       DS_R_GETPRIMDOMINFO r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
+
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       /* grab the request */
+       if ( !ds_io_q_getprimdominfo("", data, 0, &q_u) )
+               return False;
+
+       /* construct reply. */
+       r_u.status = _dsrole_get_primary_dominfo( p, &q_u, &r_u );
+
+       if ( !ds_io_r_getprimdominfo("", rdata, 0, &r_u) )
+               return False;
+
+       return True;
+}
+#endif
+
+/*******************************************************************
+ stub functions for unimplemented RPC
+*******************************************************************/
+
+static BOOL api_dsrole_stub( pipes_struct *p )
+{
+       DEBUG(0,("api_dsrole_stub:  Hmmm....didn't know this RPC existed...\n"));
+
+       return False;
+}
+
+
+/*******************************************************************
+ array of \PIPE\lsass (new windows 2000 UUID)  operations
+********************************************************************/
+static struct api_struct api_lsa_ds_cmds[] = {
+       { "DS_NOP",                     DS_NOP,                 api_dsrole_stub }
+
+#if 0  /* disabled due to breakage with viewing domain users and groups 
+          on a Samba PDC from win2k clients  --jerry CIFS 2003 */
+       { "DS_GETPRIMDOMINFO",          DS_GETPRIMDOMINFO,      api_dsrole_get_primary_dominfo  }
+#endif
+
+};
+
+void lsa_ds_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_lsa_ds_cmds;
+       *n_fns = sizeof(api_lsa_ds_cmds) / sizeof(struct api_struct);
+}
+
+
+NTSTATUS rpc_lsa_ds_init(void)
+{
+       return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "lsa_ds", "lsa_ds", api_lsa_ds_cmds,
+               sizeof(api_lsa_ds_cmds) / sizeof(struct api_struct));
+}
diff --git a/source3/rpc_server/srv_lsa_ds_nt.c b/source3/rpc_server/srv_lsa_ds_nt.c
new file mode 100644 (file)
index 0000000..37540a9
--- /dev/null
@@ -0,0 +1,127 @@
+/* 
+ *  Unix SMB/CIFS implementation.
+ *  RPC Pipe client / server routines
+ *  Copyright (C) Andrew Tridgell               1992-1997.
+ *  Copyright (C) Luke Kenneth Casson Leighton  1996-1997.
+ *  Copyright (C) Paul Ashton                        1997.
+ *  Copyright (C) Jeremy Allison                     2001.
+ *  Copyright (C) Gerald Carter                      2002.
+ *
+ *  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
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  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.
+ */
+
+/* Implementation of registry functions. */
+
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_SRV
+
+/********************************************************************
+ Fill in a DS_DOMINFO_CTR structure
+ ********************************************************************/
+
+static NTSTATUS fill_dsrole_dominfo_basic(TALLOC_CTX *ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **info) 
+{
+       DSROLE_PRIMARY_DOMAIN_INFO_BASIC *basic;
+       const char *netbios_domain;
+       fstring dnsdomain;
+
+       DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
+
+       if ( !(basic = talloc_zero(ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC))) ) {
+               DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error!  talloc_xero() failed\n"));
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       switch ( lp_server_role() ) {
+               case ROLE_STANDALONE:
+                       basic->machine_role = DSROLE_STANDALONE_SRV;
+                       break;
+               case ROLE_DOMAIN_MEMBER:
+                       basic->machine_role = DSROLE_DOMAIN_MEMBER_SRV;
+                       break;
+               case ROLE_DOMAIN_BDC:
+                       basic->machine_role = DSROLE_BDC;
+                       basic->flags = DSROLE_PRIMARY_DS_RUNNING|DSROLE_PRIMARY_DS_MIXED_MODE;
+                       if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
+                               basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
+                       get_mydomname(dnsdomain);
+                       strlower_m(dnsdomain);
+                       break;
+               case ROLE_DOMAIN_PDC:
+                       basic->machine_role = DSROLE_PDC;
+                       basic->flags = DSROLE_PRIMARY_DS_RUNNING|DSROLE_PRIMARY_DS_MIXED_MODE;
+                       if ( secrets_fetch_domain_guid( lp_workgroup(), &basic->domain_guid ) )
+                               basic->flags |= DSROLE_PRIMARY_DOMAIN_GUID_PRESENT;
+                       get_mydomname(dnsdomain);
+                       strlower_m(dnsdomain);
+                       break;
+       }
+
+       basic->unknown = 0x6173;                /* seen on the wire; maybe padding */
+
+       /* always set netbios name */
+
+       basic->netbios_ptr = 1;
+       netbios_domain = get_global_sam_name();
+       init_unistr2( &basic->netbios_domain, netbios_domain, strlen(netbios_domain) );
+
+       basic->dnsname_ptr = 1;
+       init_unistr2( &basic->dns_domain, dnsdomain, strlen(dnsdomain) );
+       basic->forestname_ptr = 1;
+       init_unistr2( &basic->forest_domain, dnsdomain, strlen(dnsdomain) );
+       
+
+       /* fill in some additional fields if we are a member of an AD domain */
+
+       if ( lp_security() == SEC_ADS ) {       
+               /* TODO */
+               ;;
+       }
+
+       *info = basic;
+
+       return NT_STATUS_OK;
+}
+
+/********************************************************************
+ Implement the DsroleGetPrimaryDomainInfo() call
+ ********************************************************************/
+
+NTSTATUS _dsrole_get_primary_dominfo(pipes_struct *p, DS_Q_GETPRIMDOMINFO *q_u, DS_R_GETPRIMDOMINFO *r_u)
+{
+       NTSTATUS result = NT_STATUS_OK;
+       uint32 level = q_u->level;
+
+       switch ( level ) {
+
+               case DsRolePrimaryDomainInfoBasic:
+                       r_u->level = DsRolePrimaryDomainInfoBasic;
+                       r_u->ptr = 1;
+                       result = fill_dsrole_dominfo_basic( p->mem_ctx, &r_u->info.basic );
+                       break;
+
+               default:
+                       DEBUG(0,("_dsrole_get_primary_dominfo: Unsupported info level [%d]!\n",
+                               level));
+                       result = NT_STATUS_INVALID_LEVEL;
+       }
+
+       return result;
+}
+
+
+
index 9eafcb8dc356c8192f035053888ce2f61dfa5af1..330dd727efd4492839cae3211c690a9b66ca2b5d 100644 (file)
@@ -502,7 +502,7 @@ NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_E
        if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
                return NT_STATUS_ACCESS_DENIED;
 
-       nt_status = secrets_get_trusted_domains(p->mem_ctx, &enum_context, max_num_domains, &num_domains, &trust_doms);
+       nt_status = secrets_get_trusted_domains(p->mem_ctx, (int *)&enum_context, max_num_domains, (int *)&num_domains, &trust_doms);
 
        if (!NT_STATUS_IS_OK(nt_status) &&
            !NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES) &&
index d1be2f3723a827608d043f602c89c6c9fd98f204..9c10d86379dff4f3f75d225292ea82440725da34 100644 (file)
@@ -320,10 +320,7 @@ static BOOL api_net_logon_ctrl(pipes_struct *p)
 /*******************************************************************
  array of \PIPE\NETLOGON operations
  ********************************************************************/
-
-NTSTATUS rpc_net_init(void)
-{
-  static struct api_struct api_net_cmds [] =
+static struct api_struct api_net_cmds [] =
     {
       { "NET_REQCHAL"       , NET_REQCHAL       , api_net_req_chal       }, 
       { "NET_AUTH"          , NET_AUTH          , api_net_auth           }, 
@@ -336,6 +333,14 @@ NTSTATUS rpc_net_init(void)
       { "NET_LOGON_CTRL"    , NET_LOGON_CTRL    , api_net_logon_ctrl     }
     };
 
+void netlog_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_net_cmds;
+       *n_fns = sizeof(api_net_cmds) / sizeof(struct api_struct);
+}
+
+NTSTATUS rpc_net_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "NETLOGON", "lsass", api_net_cmds,
                                    sizeof(api_net_cmds) / sizeof(struct api_struct));
 }
index 594cb3a9ae41b8411f4a7db181dcc3ed03115d51..d1fb587d748a4368067a37ae5ff3ff28e92f977b 100644 (file)
@@ -713,26 +713,19 @@ BOOL setup_fault_pdu(pipes_struct *p, NTSTATUS status)
  Used to reject unknown binds from Win2k.
 *******************************************************************/
 
-BOOL check_bind_req(char* pipe_name, RPC_IFACE* abstract,
-                                       RPC_IFACE* transfer)
+BOOL check_bind_req(struct pipes_struct *p, RPC_IFACE* abstract,
+                    RPC_IFACE* transfer, uint32 context_id)
 {
        extern struct pipe_id_info pipe_names[];
+       char *pipe_name = p->name;
        int i=0;
        fstring pname;
+       
        fstrcpy(pname,"\\PIPE\\");
        fstrcat(pname,pipe_name);
 
        DEBUG(3,("check_bind_req for %s\n", pname));
 
-#ifndef SUPPORT_NEW_LSARPC_UUID
-
-       /* check for the first pipe matching the name */
-       
-       for ( i=0; pipe_names[i].client_pipe; i++ ) {
-               if ( strequal(pipe_names[i].client_pipe, pname) )
-                       break;
-       }
-#else
        /* we have to check all now since win2k introduced a new UUID on the lsaprpc pipe */
                
        for ( i=0; pipe_names[i].client_pipe; i++ ) 
@@ -743,29 +736,34 @@ BOOL check_bind_req(char* pipe_name, RPC_IFACE* abstract,
                        && (transfer->version == pipe_names[i].trans_syntax.version)
                        && (memcmp(&transfer->uuid, &pipe_names[i].trans_syntax.uuid, sizeof(RPC_UUID)) == 0) )
                {
+                       struct api_struct       *fns = NULL;
+                       int                     n_fns = 0;
+                       PIPE_RPC_FNS            *context_fns;
+                       
+                       if ( !(context_fns = malloc(sizeof(PIPE_RPC_FNS))) ) {
+                               DEBUG(0,("check_bind_req: malloc() failed!\n"));
+                               return False;
+                       }
+                       
+                       /* save the RPC function table associated with this bind */
+                       
+                       get_pipe_fns(i, &fns, &n_fns);
+                       
+                       context_fns->cmds = fns;
+                       context_fns->n_cmds = n_fns;
+                       context_fns->context_id = context_id;
+                       
+                       /* add to the list of open contexts */
+                       
+                       DLIST_ADD( p->contexts, context_fns );
+                       
                        break;
                }
        }
-#endif
 
        if(pipe_names[i].client_pipe == NULL)
                return False;
 
-#ifndef SUPPORT_NEW_LSARPC_UUID
-       /* check the abstract interface */
-       if ( (abstract->version != pipe_names[i].abstr_syntax.version) 
-               || (memcmp(&abstract->uuid, &pipe_names[i].abstr_syntax.uuid, sizeof(RPC_UUID)) != 0) )
-       {
-               return False;
-       }
-
-       /* check the transfer interface */
-       if ( (transfer->version != pipe_names[i].trans_syntax.version) 
-               || (memcmp(&transfer->uuid, &pipe_names[i].trans_syntax.uuid, sizeof(RPC_UUID)) != 0) )
-       {
-               return False;
-       }
-#endif
        return True;
 }
 
@@ -861,7 +859,7 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p)
        }
 
        if (i == rpc_lookup_size) {
-                               if (NT_STATUS_IS_ERR(smb_probe_module("rpc", p->name))) {
+               if (NT_STATUS_IS_ERR(smb_probe_module("rpc", p->name))) {
                        DEBUG(3,("api_pipe_bind_req: Unknown pipe name %s in bind request.\n",
                                 p->name ));
                        if(!setup_bind_nak(p))
@@ -878,10 +876,10 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p)
                        }
                 }
 
-                               if (i == rpc_lookup_size) {
-                                       DEBUG(0, ("module %s doesn't provide functions for pipe %s!\n", p->name, p->name));
-                                       return False;
-                               }
+               if (i == rpc_lookup_size) {
+                       DEBUG(0, ("module %s doesn't provide functions for pipe %s!\n", p->name, p->name));
+                       return False;
+               }
        }
 
        /* decode the bind request */
@@ -1028,7 +1026,8 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p)
                unknown to NT4)
                Needed when adding entries to a DACL from NT5 - SK */
 
-       if(check_bind_req(p->name, &hdr_rb.abstract, &hdr_rb.transfer)) {
+       if(check_bind_req(p, &hdr_rb.abstract, &hdr_rb.transfer, hdr_rb.context_id )) 
+       {
                init_rpc_hdr_ba(&hdr_ba,
                        MAX_PDU_FRAG_LEN,
                        MAX_PDU_FRAG_LEN,
@@ -1227,10 +1226,10 @@ BOOL api_pipe_auth_process(pipes_struct *p, prs_struct *rpc_in)
                             sizeof(p->ntlmssp_hash));
 
                dump_data_pw("Incoming RPC PDU (NTLMSSP sealed)\n", 
-                            data, data_len);
+                            (const unsigned char *)data, data_len);
                NTLMSSPcalc_p(p, (uchar*)data, data_len);
                dump_data_pw("Incoming RPC PDU (NTLMSSP unsealed)\n", 
-                            data, data_len);
+                            (const unsigned char *)data, data_len);
                crc32 = crc32_calc_buffer(data, data_len);
        }
 
@@ -1391,6 +1390,48 @@ struct current_user *get_current_user(struct current_user *user, pipes_struct *p
        return user;
 }
 
+/****************************************************************************
+ Find the set of RPC functions associated with this context_id
+****************************************************************************/
+
+static PIPE_RPC_FNS* find_pipe_fns_by_context( PIPE_RPC_FNS *list, uint32 context_id )
+{
+       PIPE_RPC_FNS *fns = NULL;
+       PIPE_RPC_FNS *tmp = NULL;
+       
+       if ( !list ) {
+               DEBUG(0,("find_pipe_fns_by_context: ERROR!  No context list for pipe!\n"));
+               return NULL;
+       }
+       
+       for (tmp=list; tmp; tmp=tmp->next ) {
+               if ( tmp->context_id == context_id )
+                       break;
+       }
+       
+       fns = tmp;
+       
+       return fns;
+}
+
+/****************************************************************************
+ memory cleanup
+****************************************************************************/
+
+void free_pipe_rpc_context( PIPE_RPC_FNS *list )
+{
+       PIPE_RPC_FNS *tmp = list;
+       PIPE_RPC_FNS *tmp2;
+               
+       while (tmp) {
+               tmp2 = tmp->next;
+               SAFE_FREE(tmp);
+               tmp = tmp2;
+       }
+
+       return; 
+}
+
 /****************************************************************************
  Find the correct RPC function to call for this request.
  If the pipe is authenticated then become the correct UNIX user
@@ -1399,9 +1440,9 @@ struct current_user *get_current_user(struct current_user *user, pipes_struct *p
 
 BOOL api_pipe_request(pipes_struct *p)
 {
-       int i = 0;
        BOOL ret = False;
-
+       PIPE_RPC_FNS *pipe_fns;
+       
        if (p->ntlmssp_auth_validated) {
 
                if(!become_authenticated_pipe_user(p)) {
@@ -1411,36 +1452,19 @@ BOOL api_pipe_request(pipes_struct *p)
        }
 
        DEBUG(5, ("Requested \\PIPE\\%s\n", p->name));
-
-       for (i = 0; i < rpc_lookup_size; i++) {
-               if (strequal(rpc_lookup[i].pipe.clnt, p->name)) {
-                        DEBUG(3,("Doing \\PIPE\\%s\n", 
-                                 rpc_lookup[i].pipe.clnt));
-                        set_current_rpc_talloc(p->mem_ctx);
-                        ret = api_rpcTNP(p, rpc_lookup[i].pipe.clnt,
-                                         rpc_lookup[i].cmds,
-                                         rpc_lookup[i].n_cmds);
-                        set_current_rpc_talloc(NULL);
-                        break;
-                }
+       
+       /* get the set of RPC functions for this context */
+       
+       pipe_fns = find_pipe_fns_by_context(p->contexts, p->hdr_req.context_id);
+       
+       if ( pipe_fns ) {
+               set_current_rpc_talloc(p->mem_ctx);
+               ret = api_rpcTNP(p, p->name, pipe_fns->cmds, pipe_fns->n_cmds);
+               set_current_rpc_talloc(NULL);   
        }
-
-
-       if (i == rpc_lookup_size) {
-               smb_probe_module("rpc", p->name);
-
-                for (i = 0; i < rpc_lookup_size; i++) {
-                        if (strequal(rpc_lookup[i].pipe.clnt, p->name)) {
-                                DEBUG(3,("Doing \\PIPE\\%s\n",
-                                         rpc_lookup[i].pipe.clnt));
-                                set_current_rpc_talloc(p->mem_ctx);
-                                ret = api_rpcTNP(p, rpc_lookup[i].pipe.clnt,
-                                                 rpc_lookup[i].cmds,
-                                                 rpc_lookup[i].n_cmds);
-                                set_current_rpc_talloc(NULL);
-                                break;
-                        }
-                }
+       else {
+               DEBUG(0,("api_pipe_request: No rpc function table associated with context [%d] on pipe [%s]\n",
+                       p->hdr_req.context_id, p->name));
        }
 
        if(p->ntlmssp_auth_validated)
@@ -1529,3 +1553,56 @@ BOOL api_rpcTNP(pipes_struct *p, const char *rpc_name,
 
        return True;
 }
+
+/*******************************************************************
+*******************************************************************/
+
+void get_pipe_fns( int idx, struct api_struct **fns, int *n_fns )
+{
+       struct api_struct *cmds = NULL;
+       int               n_cmds = 0;
+
+       switch ( idx ) {
+               case PI_LSARPC:
+                       lsa_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_LSARPC_DS:
+                       lsa_ds_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_SAMR:
+                       samr_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_NETLOGON:
+                       netlog_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_SRVSVC:
+                       srvsvc_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_WKSSVC:
+                       wkssvc_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_WINREG:
+                       reg_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_SPOOLSS:
+                       spoolss_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+               case PI_NETDFS:
+                       netdfs_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+#ifdef DEVELOPER
+               case PI_ECHO:
+                       echo_get_pipe_fns( &cmds, &n_cmds );
+                       break;
+#endif
+               default:
+                       DEBUG(0,("get_pipe_fns: Unknown pipe index! [%d]\n", idx));
+       }
+
+       *fns = cmds;
+       *n_fns = n_cmds;
+
+       return;
+}
+
+
index 125f6037710b88dd8f59c50eb2f61e74deb69cfe..55def9767324ce9307dbef017d37d2a83e149d20 100644 (file)
@@ -1106,6 +1106,8 @@ static BOOL close_internal_rpc_pipe_hnd(void *np_conn)
 
        if (p->mem_ctx)
                talloc_destroy(p->mem_ctx);
+               
+       free_pipe_rpc_context( p->contexts );
 
        /* Free the handles database. */
        close_policy_by_pipe(p);
index e1a02103f77d0ef1d13f24ac5bb7a348fa186af3..b780be0aff3c16677989128ed5bfd23539fb9f2d 100644 (file)
@@ -367,16 +367,12 @@ static BOOL api_reg_save_key(pipes_struct *p)
        return True;
 }
 
-
-
 /*******************************************************************
  array of \PIPE\reg operations
  ********************************************************************/
 
-NTSTATUS rpc_reg_init(void)
+static struct api_struct api_reg_cmds[] =
 {
-  static struct api_struct api_reg_cmds[] =
-    {
       { "REG_CLOSE"              , REG_CLOSE              , api_reg_close            },
       { "REG_OPEN_ENTRY"         , REG_OPEN_ENTRY         , api_reg_open_entry       },
       { "REG_OPEN_HKCR"          , REG_OPEN_HKCR          , api_reg_open_hkcr        },
@@ -390,7 +386,17 @@ NTSTATUS rpc_reg_init(void)
       { "REG_ABORT_SHUTDOWN"     , REG_ABORT_SHUTDOWN     , api_reg_abort_shutdown   },
       { "REG_UNKNOWN_1A"         , REG_UNKNOWN_1A         , api_reg_unknown_1a       },
       { "REG_SAVE_KEY"           , REG_SAVE_KEY           , api_reg_save_key         }
-    };
+};
+
+void reg_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_reg_cmds;
+       *n_fns = sizeof(api_reg_cmds) / sizeof(struct api_struct);
+}
+    
+NTSTATUS rpc_reg_init(void)
+{
+
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "winreg", "winreg", api_reg_cmds,
                                    sizeof(api_reg_cmds) / sizeof(struct api_struct));
 }
index 86ff039683310472ee49ef228726c90878e974ab..a0f62c20fcaac8d7698f27c7fa9c4ff6c307050d 100644 (file)
@@ -386,7 +386,7 @@ static BOOL api_samr_chgpasswd_user(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* unknown 38 command */
+       /* change password request */
        if (!samr_io_q_chgpasswd_user("", &q_u, data, 0)) {
                DEBUG(0,("api_samr_chgpasswd_user: Failed to unmarshall SAMR_Q_CHGPASSWD_USER.\n"));
                return False;
@@ -448,13 +448,12 @@ static BOOL api_samr_open_user(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 22 */
        if(!samr_io_q_open_user("", &q_u, data, 0)) {
                DEBUG(0,("api_samr_open_user: unable to unmarshall SAMR_Q_OPEN_USER.\n"));
                return False;
        }
 
-       r_u.status = _api_samr_open_user(p, &q_u, &r_u);
+       r_u.status = _samr_open_user(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
        if(!samr_io_r_open_user("", &r_u, rdata, 0)) {
@@ -479,7 +478,6 @@ static BOOL api_samr_query_userinfo(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 24 */
        if(!samr_io_q_query_userinfo("", &q_u, data, 0)){
                DEBUG(0,("api_samr_query_userinfo: unable to unmarshall SAMR_Q_QUERY_USERINFO.\n"));
                return False;
@@ -510,7 +508,6 @@ static BOOL api_samr_query_usergroups(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 32 */
        if(!samr_io_q_query_usergroups("", &q_u, data, 0)) {
                DEBUG(0,("api_samr_query_usergroups: unable to unmarshall SAMR_Q_QUERY_USERGROUPS.\n"));
                return False;
@@ -541,7 +538,6 @@ static BOOL api_samr_query_dom_info(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 8 command */
        if(!samr_io_q_query_dom_info("", &q_u, data, 0)) {
                DEBUG(0,("api_samr_query_dom_info: unable to unmarshall SAMR_Q_QUERY_DOMAIN_INFO.\n"));
                return False;
@@ -579,7 +575,7 @@ static BOOL api_samr_create_user(pipes_struct *p)
                return False;
        }
 
-       r_u.status=_api_samr_create_user(p, &q_u, &r_u);
+       r_u.status=_samr_create_user(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
        if(!samr_io_r_create_user("", &r_u, rdata, 0)) {
@@ -761,7 +757,7 @@ static BOOL api_samr_open_alias(pipes_struct *p)
                return False;
        }
 
-       r_u.status=_api_samr_open_alias(p, &q_u, &r_u);
+       r_u.status=_samr_open_alias(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
        if(!samr_io_r_open_alias("", &r_u, rdata, 0)) {
@@ -1347,13 +1343,13 @@ static BOOL api_samr_open_group(pipes_struct *p)
 }
 
 /*******************************************************************
- api_samr_unknown_2d
+ api_samr_remove_user_foreign_domain
  ********************************************************************/
 
-static BOOL api_samr_unknown_2d(pipes_struct *p)
+static BOOL api_samr_remove_user_foreign_domain(pipes_struct *p)
 {
-       SAMR_Q_UNKNOWN_2D q_u;
-       SAMR_R_UNKNOWN_2D r_u;
+       SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN q_u;
+       SAMR_R_REMOVE_USER_FOREIGN_DOMAIN r_u;
 
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
@@ -1361,15 +1357,15 @@ static BOOL api_samr_unknown_2d(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if (!samr_io_q_unknown_2d("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_unknown_2d: unable to unmarshall SAMR_Q_UNKNOWN_2D.\n"));
+       if (!samr_io_q_remove_user_foreign_domain("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_remove_user_foreign_domain: unable to unmarshall SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN.\n"));
                return False;
        }
 
-       r_u.status = _samr_unknown_2d(p, &q_u, &r_u);
+       r_u.status = _samr_remove_user_foreign_domain(p, &q_u, &r_u);
 
-       if (!samr_io_r_unknown_2d("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_unknown_2d: unable to marshall SAMR_R_UNKNOWN_2D.\n"));
+       if (!samr_io_r_remove_user_foreign_domain("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_remove_user_foreign_domain: unable to marshall SAMR_R_REMOVE_USER_FOREIGN_DOMAIN.\n"));
                return False;
        }
 
@@ -1421,7 +1417,6 @@ static BOOL api_samr_set_dom_info(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 8 command */
        if(!samr_io_q_set_domain_info("", &q_u, data, 0)) {
                DEBUG(0,("api_samr_set_dom_info: unable to unmarshall SAMR_Q_SET_DOMAIN_INFO.\n"));
                return False;
@@ -1442,10 +1437,8 @@ static BOOL api_samr_set_dom_info(pipes_struct *p)
  array of \PIPE\samr operations
  ********************************************************************/
 
-NTSTATUS rpc_samr_init(void)
+static struct api_struct api_samr_cmds [] =
 {
-  static struct api_struct api_samr_cmds [] =
-    {
       {"SAMR_CLOSE_HND"         , SAMR_CLOSE_HND        , api_samr_close_hnd        },
       {"SAMR_CONNECT"           , SAMR_CONNECT          , api_samr_connect          },
       {"SAMR_CONNECT_ANON"      , SAMR_CONNECT_ANON     , api_samr_connect_anon     },
@@ -1490,7 +1483,7 @@ NTSTATUS rpc_samr_init(void)
       {"SAMR_OPEN_ALIAS"        , SAMR_OPEN_ALIAS       , api_samr_open_alias       },
       {"SAMR_OPEN_GROUP"        , SAMR_OPEN_GROUP       , api_samr_open_group       },
       {"SAMR_OPEN_DOMAIN"       , SAMR_OPEN_DOMAIN      , api_samr_open_domain      },
-      {"SAMR_UNKNOWN_2D"        , SAMR_UNKNOWN_2D       , api_samr_unknown_2d       },
+      {"SAMR_REMOVE_USER_FOREIGN_DOMAIN"       , SAMR_REMOVE_USER_FOREIGN_DOMAIN      , api_samr_remove_user_foreign_domain      },
       {"SAMR_LOOKUP_DOMAIN"     , SAMR_LOOKUP_DOMAIN    , api_samr_lookup_domain    },
       
       {"SAMR_QUERY_SEC_OBJECT"  , SAMR_QUERY_SEC_OBJECT , api_samr_query_sec_obj    },
@@ -1499,7 +1492,17 @@ NTSTATUS rpc_samr_init(void)
       {"SAMR_UNKNOWN_2E"        , SAMR_UNKNOWN_2E       , api_samr_unknown_2e       },
       {"SAMR_SET_DOMAIN_INFO"   , SAMR_SET_DOMAIN_INFO  , api_samr_set_dom_info     },
       {"SAMR_CONNECT4"          , SAMR_CONNECT4         , api_samr_connect4         }
-    };
+};
+
+void samr_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_samr_cmds;
+       *n_fns = sizeof(api_samr_cmds) / sizeof(struct api_struct);
+}
+
+
+NTSTATUS rpc_samr_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "samr", "lsass", api_samr_cmds,
                                    sizeof(api_samr_cmds) / sizeof(struct api_struct));
 }
index 14aad5d6f8c1d6249592c2f547a9a0fcfc30fb51..7f7b5e8d5e4ead371d9250771869ee3db7006bea 100644 (file)
@@ -8,6 +8,7 @@
  *  Copyright (C) Jeremy Allison               2001-2002,
  *  Copyright (C) Jean François Micouleau      1998-2001,
  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002.
+ *  Copyright (C) Gerald (Jerry) Carter             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
@@ -913,7 +914,6 @@ static NTSTATUS get_group_alias_entries(TALLOC_CTX *ctx, DOMAIN_GRP **d_grp, DOM
        } else if (sid_equal(sid, get_global_sam_sid()) && !lp_hide_local_users()) {
                struct sys_grent *glist;
                struct sys_grent *grp;
-               struct passwd *pw;
                gid_t winbind_gid_low, winbind_gid_high;
                BOOL winbind_groups_exist = lp_idmap_gid(&winbind_gid_low, &winbind_gid_high);
 
@@ -952,7 +952,7 @@ static NTSTATUS get_group_alias_entries(TALLOC_CTX *ctx, DOMAIN_GRP **d_grp, DOM
 
                        /* Don't return user private groups... */
 
-                       if ((pw = Get_Pwnam(smap.nt_name)) != 0) {
+                       if (Get_Pwnam(smap.nt_name) != 0) {
                                DEBUG(10,("get_group_alias_entries: not returing %s, clashes with user.\n", smap.nt_name ));
                                continue;                       
                        }
@@ -1013,8 +1013,13 @@ static NTSTATUS get_group_domain_entries(TALLOC_CTX *ctx, DOMAIN_GRP **d_grp, DO
 
        *p_num_entries = 0;
 
+       /* access checks for the users were performed higher up.  become/unbecome_root()
+          needed for some passdb backends to enumerate groups */
+          
+       become_root();
        pdb_enum_group_mapping(SID_NAME_DOM_GRP, &map, (int *)&group_entries, ENUM_ONLY_MAPPED);
-
+       unbecome_root();
+       
        num_entries=group_entries-start_idx;
 
        /* limit the number of entries */
@@ -1659,10 +1664,10 @@ NTSTATUS _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOK
 }
 
 /*******************************************************************
- _api_samr_open_user. Safe - gives out no passwd info.
+ _samr_open_user. Safe - gives out no passwd info.
  ********************************************************************/
 
-NTSTATUS _api_samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USER *r_u)
+NTSTATUS _samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USER *r_u)
 {
        SAM_ACCOUNT *sampass=NULL;
        DOM_SID sid;
@@ -2140,7 +2145,7 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA
                                       num_users, num_groups, num_aliases);
                        break;
                case 0x03:
-                       account_policy_get(AP_TIME_TO_LOGOUT, (int *)&u_logout);
+                       account_policy_get(AP_TIME_TO_LOGOUT, (unsigned int *)&u_logout);
                        unix_to_nt_time_abs(&nt_logout, u_logout);
                        
                        init_unk_info3(&ctr->info.inf3, nt_logout);
@@ -2181,12 +2186,12 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA
 }
 
 /*******************************************************************
- _api_samr_create_user
+ _samr_create_user
  Create an account, can be either a normal user or a machine.
  This funcion will need to be updated for bdc/domain trusts.
  ********************************************************************/
 
-NTSTATUS _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREATE_USER *r_u)
+NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREATE_USER *r_u)
 {
        SAM_ACCOUNT *sam_pass=NULL;
        fstring account;
@@ -2300,12 +2305,12 @@ NTSTATUS _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_
                        int add_ret;
                        all_string_sub(add_script, "%u", account, sizeof(account));
                        add_ret = smbrun(add_script,NULL);
-                       DEBUG(3,("_api_samr_create_user: Running the command `%s' gave %d\n", add_script, add_ret));
+                       DEBUG(3,("_samr_create_user: Running the command `%s' gave %d\n", add_script, add_ret));
                }
                else    /* no add user script -- ask winbindd to do it */
                {
                        if ( !winbind_create_user( account, &new_rid ) ) {
-                               DEBUG(3,("_api_samr_create_user: winbind_create_user(%s) failed\n", 
+                               DEBUG(3,("_samr_create_user: winbind_create_user(%s) failed\n", 
                                        account));
                        }
                }
@@ -2369,6 +2374,7 @@ NTSTATUS _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_
 NTSTATUS _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CONNECT_ANON *r_u)
 {
        struct samr_info *info = NULL;
+       uint32    des_access = q_u->access_mask;
 
        /* Access check */
 
@@ -2386,6 +2392,13 @@ NTSTATUS _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CO
        if ((info = get_samr_info_by_sid(NULL)) == NULL)
                return NT_STATUS_NO_MEMORY;
 
+       /* don't give away the farm but this is probably ok.  The SA_RIGHT_SAM_ENUM_DOMAINS
+          was observed from a win98 client trying to enumerate users (when configured  
+          user level access control on shares)   --jerry */
+          
+       se_map_generic( &des_access, &sam_generic_mapping );
+       info->acc_granted = des_access & (SA_RIGHT_SAM_ENUM_DOMAINS|SA_RIGHT_SAM_OPEN_DOMAIN);
+       
        info->status = q_u->unknown_0;
 
        /* get a (unique) handle.  open a policy on it. */
@@ -2510,7 +2523,9 @@ NTSTATUS _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_
        if (!find_policy_by_hnd(p, &q_u->connect_pol, (void**)&info))
                return NT_STATUS_INVALID_HANDLE;
 
-       if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted, SA_RIGHT_SAM_OPEN_DOMAIN, "_samr_lookup_domain"))) {
+       if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted, 
+               SA_RIGHT_SAM_ENUM_DOMAINS, "_samr_lookup_domain"))) 
+       {
                return r_u->status;
        }
 
@@ -2605,7 +2620,7 @@ NTSTATUS _samr_enum_domains(pipes_struct *p, SAMR_Q_ENUM_DOMAINS *q_u, SAMR_R_EN
  api_samr_open_alias
  ********************************************************************/
 
-NTSTATUS _api_samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_ALIAS *r_u)
+NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_ALIAS *r_u)
 {
        DOM_SID sid;
        POLICY_HND domain_pol = q_u->dom_pol;
@@ -3773,7 +3788,8 @@ NTSTATUS _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAM
        /* check if the user exists before trying to delete */
        pdb_init_sam(&sam_pass);
        if(!pdb_getsampwsid(sam_pass, &user_sid)) {
-               DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n", pdb_get_username(sam_pass)));
+               DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n", 
+                       sid_string_static(&user_sid)));
                pdb_free_sam(&sam_pass);
                return NT_STATUS_NO_SUCH_USER;
        }
@@ -4269,13 +4285,75 @@ NTSTATUS _samr_open_group(pipes_struct *p, SAMR_Q_OPEN_GROUP *q_u, SAMR_R_OPEN_G
 }
 
 /*********************************************************************
- _samr_unknown_2d
+ _samr_remove_user_foreign_domain
 *********************************************************************/
 
-NTSTATUS _samr_unknown_2d(pipes_struct *p, SAMR_Q_UNKNOWN_2D *q_u, SAMR_R_UNKNOWN_2D *r_u)
+NTSTATUS _samr_remove_user_foreign_domain(pipes_struct *p, 
+                                          SAMR_Q_REMOVE_USER_FOREIGN_DOMAIN *q_u, 
+                                          SAMR_R_REMOVE_USER_FOREIGN_DOMAIN *r_u)
 {
-       DEBUG(0,("_samr_unknown_2d: Not yet implemented.\n"));
-       return NT_STATUS_NOT_IMPLEMENTED;
+       DOM_SID                 user_sid, dom_sid;
+       SAM_ACCOUNT             *sam_pass=NULL;
+       uint32                  acc_granted;
+       
+       sid_copy( &user_sid, &q_u->sid.sid );
+       
+       DEBUG(5,("_samr_remove_user_foreign_domain: removing user [%s]\n",
+               sid_string_static(&user_sid)));
+               
+       /* Find the policy handle. Open a policy on it. */
+       
+       if (!get_lsa_policy_samr_sid(p, &q_u->dom_pol, &dom_sid, &acc_granted)) 
+               return NT_STATUS_INVALID_HANDLE;
+               
+       if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, 
+               STD_RIGHT_DELETE_ACCESS, "_samr_remove_user_foreign_domain"))) 
+       {
+               return r_u->status;
+       }
+               
+       if ( !sid_check_is_in_our_domain(&user_sid) ) {
+               DEBUG(5,("_samr_remove_user_foreign_domain: user not is our domain!\n"));
+               return NT_STATUS_NO_SUCH_USER;
+       }
+
+       /* check if the user exists before trying to delete */
+       
+       pdb_init_sam(&sam_pass);
+       
+       if ( !pdb_getsampwsid(sam_pass, &user_sid) ) {
+       
+               DEBUG(5,("_samr_remove_user_foreign_domain:User %s doesn't exist.\n", 
+                       sid_string_static(&user_sid)));
+                       
+               pdb_free_sam(&sam_pass);
+               
+               return NT_STATUS_NO_SUCH_USER;
+       }
+
+       /*
+        * delete the unix side
+        * 
+        * note: we don't check if the delete really happened
+        * as the script is not necessary present
+        * and maybe the sysadmin doesn't want to delete the unix side
+        */
+        
+       smb_delete_user(pdb_get_username(sam_pass));
+
+       /* and delete the samba side */
+       
+       if ( !pdb_delete_sam_account(sam_pass) ) {
+       
+               DEBUG(5,("_samr_delete_dom_user:Failed to delete entry for user %s.\n", pdb_get_username(sam_pass)));
+               pdb_free_sam(&sam_pass);
+               
+               return NT_STATUS_CANNOT_DELETE;
+       }
+       
+       pdb_free_sam(&sam_pass);
+
+       return NT_STATUS_OK;
 }
 
 /*******************************************************************
index fa0ca8478c6304c5d18be936fbefe95b94f5422f..f846813a40b86be85dc653b428e60ae4f316fc47 100755 (executable)
@@ -141,7 +141,7 @@ static BOOL api_spoolss_deleteprinterdata(pipes_struct *p)
                return False;
        }
        
-       r_u.status = _spoolss_deleteprinterdata( p, &q_u, &r_u);
+       r_u.status = _spoolss_deleteprinterdata( p, &q_u, &r_u );
 
        if (!spoolss_io_r_deleteprinterdata("", &r_u, rdata, 0)) {
                DEBUG(0,("spoolss_io_r_deleteprinterdata: unable to marshall SPOOL_R_DELETEPRINTERDATA.\n"));
@@ -1580,8 +1580,6 @@ static BOOL api_spoolss_replycloseprinter(pipes_struct *p)
 \pipe\spoolss commands
 ********************************************************************/
 
-NTSTATUS rpc_spoolss_init(void)
-{
   struct api_struct api_spoolss_cmds[] = 
     {
  {"SPOOLSS_OPENPRINTER",               SPOOLSS_OPENPRINTER,               api_spoolss_open_printer              },
@@ -1640,6 +1638,15 @@ NTSTATUS rpc_spoolss_init(void)
  {"SPOOLSS_REPLYCLOSEPRINTER",         SPOOLSS_REPLYCLOSEPRINTER,         api_spoolss_replycloseprinter         }
 #endif
     };
+
+void spoolss_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_spoolss_cmds;
+       *n_fns = sizeof(api_spoolss_cmds) / sizeof(struct api_struct);
+}
+
+NTSTATUS rpc_spoolss_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "spoolss", "spoolss", api_spoolss_cmds,
                                    sizeof(api_spoolss_cmds) / sizeof(struct api_struct));
 }
index 8237298ebb7ad92b3e26fa8550951c2ff12867ad..7159527a7d8d3ead86460427c71711adf6083d87 100644 (file)
@@ -387,7 +387,6 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
                char *cmd = lp_deleteprinter_cmd();
                pstring command;
                int ret;
-               int i;
 
                /* Printer->dev.handlename equals portname equals sharename */
                slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd,
@@ -406,7 +405,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
                /* go ahead and re-read the services immediately */
                reload_services( False );
 
-               if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) < 0 )
+               if ( lp_servicenumber( Printer->dev.handlename )  < 0 )
                        return WERR_ACCESS_DENIED;
        }
 
@@ -957,7 +956,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
                SPOOL_NOTIFY_INFO_DATA *data;
                uint32  data_len = 0;
                uint32  id;
-               int     i, event_index;
+               int     i;
 
                /* Is there notification on this handle? */
 
@@ -980,8 +979,6 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
                data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) );
                ZERO_STRUCTP(data);
                
-               event_index = 0;
-               
                /* build the array of change notifications */
                
                sending_msg_count = 0;
@@ -2671,6 +2668,8 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer,
 
                fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
 
+               ZERO_STRUCT(notify_cli);
+
                if(!spoolss_connect_to_client(&notify_cli, client_ip, unix_printer))
                        return False;
                        
@@ -3753,7 +3752,6 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
        Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
        int n_services=lp_numservices();
        int i;
-       uint32 id;
        SPOOL_NOTIFY_OPTION *option;
        SPOOL_NOTIFY_OPTION_TYPE *option_type;
 
@@ -3763,7 +3761,6 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
                return WERR_BADFID;
 
        option=Printer->notify.option;
-       id=1;
        info->version=2;
        info->data=NULL;
        info->count=0;
@@ -6192,12 +6189,9 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle,
        SPOOL_PRINTER_INFO_LEVEL_7 *info7 = info->info_7;
        int snum;
        Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
-       WERROR result;
 
        DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
 
-       result = WERR_OK;
-
        if (!Printer)
                return WERR_BADFID;
 
@@ -7100,7 +7094,6 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name)
        init_unistr(&port->port_name, name);
        init_unistr(&port->monitor_name, "Local Monitor");
        init_unistr(&port->description, "Local Port");
-#define PORT_TYPE_WRITE 1
        port->port_type=PORT_TYPE_WRITE;
        port->reserved=0x0;     
 }
@@ -7723,7 +7716,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
 
        NT_PRINTER_INFO_LEVEL *printer = NULL;
        
-       uint32          param_index;
        uint32          biggest_valuesize;
        uint32          biggest_datasize;
        uint32          data_len;
@@ -7772,7 +7764,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
        {
                DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
 
-               param_index       = 0;
                biggest_valuesize = 0;
                biggest_datasize  = 0;
                                
@@ -8032,6 +8023,9 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_
        unistr2_to_ascii( valuename, value, sizeof(valuename)-1 );
 
        status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename );
+       
+       if ( W_ERROR_IS_OK(status) )
+               mod_a_printer( *printer, 2 );
 
        free_a_printer(&printer, 2);
 
@@ -8895,6 +8889,9 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX
 
        status = delete_printer_dataex( printer, keyname, valuename );
 
+       if ( W_ERROR_IS_OK(status) )
+               mod_a_printer( *printer, 2 );
+               
        free_a_printer(&printer, 2);
 
        return status;
@@ -9186,12 +9183,11 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name,
 {
        pstring path;
        pstring long_archi;
-        const char *short_archi;
        PRINTPROCESSOR_DIRECTORY_1 *info=NULL;
 
        unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1);
 
-       if (!(short_archi = get_short_archi(long_archi)))
+       if (!get_short_archi(long_archi))
                return WERR_INVALID_ENVIRONMENT;
 
        if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL)
index 0da3cf70dd8b99c11d30f19a90487328c597cbce..9d85088e568beff3a1a6eecac2a0fb5d44b5007a 100644 (file)
@@ -526,10 +526,8 @@ static BOOL api_srv_net_file_set_secdesc(pipes_struct *p)
 \PIPE\srvsvc commands
 ********************************************************************/
 
-NTSTATUS rpc_srv_init(void)
+static struct api_struct api_srv_cmds[] =
 {
-  static const struct api_struct api_srv_cmds[] =
-    {
       { "SRV_NET_CONN_ENUM"         , SRV_NET_CONN_ENUM         , api_srv_net_conn_enum          },
       { "SRV_NET_SESS_ENUM"         , SRV_NET_SESS_ENUM         , api_srv_net_sess_enum          },
       { "SRV_NET_SHARE_ENUM_ALL"    , SRV_NET_SHARE_ENUM_ALL    , api_srv_net_share_enum_all     },
@@ -547,7 +545,17 @@ NTSTATUS rpc_srv_init(void)
       { "SRV_NET_NAME_VALIDATE"     , SRV_NET_NAME_VALIDATE     , api_srv_net_name_validate      },
       { "SRV_NET_FILE_QUERY_SECDESC", SRV_NET_FILE_QUERY_SECDESC, api_srv_net_file_query_secdesc },
       { "SRV_NET_FILE_SET_SECDESC"  , SRV_NET_FILE_SET_SECDESC  , api_srv_net_file_set_secdesc   }
-    };
+};
+
+void srvsvc_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_srv_cmds;
+       *n_fns = sizeof(api_srv_cmds) / sizeof(struct api_struct);
+}
+
+
+NTSTATUS rpc_srv_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "srvsvc", "ntsvcs", api_srv_cmds,
                                    sizeof(api_srv_cmds) / sizeof(struct api_struct));
 }
index 03e53118a89afe18bc4c912caf0f84dabb26e8c2..632d381503ee3317a58271d2a3be70179b5ab11a 100644 (file)
@@ -307,8 +307,17 @@ BOOL get_domain_user_groups(TALLOC_CTX *ctx, int *numgroups, DOM_GID **pgids, SA
         */
        gids = (DOM_GID *)talloc(ctx, sizeof(DOM_GID) *  num_entries);  
 
-       /* for each group, check if the user is a member of*/
+       /* for each group, check if the user is a member of.  Only include groups 
+          from this domain */
+       
        for(i=0; i<num_entries; i++) {
+       
+               if ( !sid_check_is_in_our_domain(&map[i].sid) ) {
+                       DEBUG(10,("get_domain_user_groups: skipping check of %s since it is not in our domain\n",
+                               map[i].nt_name));
+                       continue;
+               }
+                       
                if ((grp=getgrgid(map[i].gid)) == NULL) {
                        /* very weird !!! */
                        DEBUG(5,("get_domain_user_groups: gid %d doesn't exist anymore !\n", (int)map[i].gid));
index 856f451779e4c368f2e5783ca3f1aa1cc0eeac36..b5c1af34d9dfe76d66a3b8f867303805ee4f6278 100644 (file)
@@ -60,12 +60,19 @@ static BOOL api_wks_query_info(pipes_struct *p)
  \PIPE\wkssvc commands
  ********************************************************************/
 
-NTSTATUS rpc_wks_init(void)
+static struct api_struct api_wks_cmds[] =
 {
-  static struct api_struct api_wks_cmds[] =
-    {
       { "WKS_Q_QUERY_INFO", WKS_QUERY_INFO, api_wks_query_info }
-    };
+};
+
+void wkssvc_get_pipe_fns( struct api_struct **fns, int *n_fns )
+{
+       *fns = api_wks_cmds;
+       *n_fns = sizeof(api_wks_cmds) / sizeof(struct api_struct);
+}
+
+NTSTATUS rpc_wks_init(void)
+{
   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "wkssvc", "ntsvcs", api_wks_cmds,
                                    sizeof(api_wks_cmds) / sizeof(struct api_struct));
 }
index 721bd59ba0ccf15dfd3906b3ac08e39b99ae751a..b01236d9a58921de51f30def97b5345bc6deee39 100644 (file)
@@ -54,7 +54,7 @@ static NTSTATUS cmd_ds_enum_domain_trusts(struct cli_state *cli,
        NTSTATUS                result;
        uint32                  flags = 0x1;
        DS_DOMAIN_TRUSTS         *trusts = NULL;
-       int                     num_domains = 0;
+       unsigned int                    num_domains = 0;
        
        result = cli_ds_enum_domain_trusts( cli, mem_ctx, cli->desthost, flags, 
                &trusts, &num_domains );
index 0ec78a067342fb28920045171cff76f96726719b..a48b59bf6a38ec31b4a49dd77aec08c5b53dfa5c 100644 (file)
@@ -146,13 +146,10 @@ static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
                                       const char **argv)
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-        unsigned char trust_passwd[16];
         uint32 database_id = 0, num_deltas;
         SAM_DELTA_HDR *hdr_deltas;
         SAM_DELTA_CTR *deltas;
        DOM_CRED ret_creds;
-       uint32 neg_flags = 0x000001ff;
-       uint32 sec_channel_type = 0;
 
         if (argc > 2) {
                 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
@@ -162,26 +159,6 @@ static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
         if (argc == 2)
                 database_id = atoi(argv[1]);
 
-        if (!secrets_init()) {
-                fprintf(stderr, "Unable to initialise secrets database\n");
-                return result;
-        }
-
-        /* Initialise session credentials */
-
-       if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
-                                                  NULL, &sec_channel_type)) {
-               fprintf(stderr, "could not fetch trust account password\n");
-               goto done;
-       }        
-
-        result = cli_nt_setup_creds(cli, sec_channel_type, trust_passwd, &neg_flags, 2);
-
-        if (!NT_STATUS_IS_OK(result)) {
-                fprintf(stderr, "Error initialising session creds\n");
-                goto done;
-        }
-
        /* on first call the returnAuthenticator is empty */
        memset(&ret_creds, 0, sizeof(ret_creds));
  
@@ -208,13 +185,10 @@ static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
                                         const char **argv)
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-        unsigned char trust_passwd[16];
         uint32 database_id, num_deltas, tmp;
         SAM_DELTA_HDR *hdr_deltas;
         SAM_DELTA_CTR *deltas;
         UINT64_S seqnum;
-       uint32 neg_flags = 0x000001ff;
-       uint32 sec_channel_type = 0;
 
         if (argc != 3) {
                 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
@@ -227,28 +201,6 @@ static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
         seqnum.low = tmp & 0xffff;
         seqnum.high = 0;
 
-        if (!secrets_init()) {
-                fprintf(stderr, "Unable to initialise secrets database\n");
-                goto done;
-        }
-
-        /* Initialise session credentials */
-
-       if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
-                                                  NULL, &sec_channel_type)) {
-               fprintf(stderr, "could not fetch trust account password\n");
-               goto done;
-       }        
-
-        result = cli_nt_setup_creds(cli, sec_channel_type, trust_passwd, &neg_flags, 2);
-
-        if (!NT_STATUS_IS_OK(result)) {
-                fprintf(stderr, "Error initialising session creds\n");
-                goto done;
-        }
-
-        /* Synchronise sam database */
-
        result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
                                         seqnum, &num_deltas, 
                                         &hdr_deltas, &deltas);
@@ -308,6 +260,8 @@ static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
        
         result = cli_netlogon_sam_logon(cli, mem_ctx, &ret_creds, username, password, logon_type);
 
+       clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
+
        if (!NT_STATUS_IS_OK(result))
                goto done;
 
@@ -315,6 +269,39 @@ static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
         return result;
 }
 
+/* Change the trust account password */
+
+static NTSTATUS cmd_netlogon_change_trust_pw(struct cli_state *cli, 
+                                            TALLOC_CTX *mem_ctx, int argc,
+                                            const char **argv)
+{
+        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+       DOM_CRED ret_creds;
+
+        /* Check arguments */
+
+        if (argc > 1) {
+                fprintf(stderr, "Usage: change_trust_pw");
+                return NT_STATUS_OK;
+        }
+
+        /* Perform the sam logon */
+
+       ZERO_STRUCT(ret_creds);
+
+       result = trust_pw_find_change_and_store_it(cli, mem_ctx,
+                                                  lp_workgroup());
+
+       clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+ done:
+        return result;
+}
+
+
 /* List of commands exported by this module */
 
 struct cmd_set netlogon_commands[] = {
@@ -325,7 +312,8 @@ struct cmd_set netlogon_commands[] = {
        { "logonctrl",  RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl,  NULL, PI_NETLOGON, "Logon Control",       "" },
        { "samsync",    RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync,    NULL, PI_NETLOGON, "Sam Synchronisation", "" },
        { "samdeltas",  RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas,  NULL, PI_NETLOGON, "Query Sam Deltas",    "" },
-     { "samlogon",   RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon,   NULL, PI_NETLOGON, "Sam Logon",           "" },
+       { "samlogon",   RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon,   NULL, PI_NETLOGON, "Sam Logon",           "" },
+       { "samlogon",   RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw,   NULL, PI_NETLOGON, "Change Trust Account Password",           "" },
 
        { NULL }
 };
index b2fa802e9a38796d3f664c619e12c3811efc1169..61e100c03bb7a12b7650573212120d7294b131cb 100644 (file)
@@ -35,6 +35,7 @@ static const struct table_node archi_table[]= {
 
        {"Windows 4.0",          "WIN40",       0 },
        {"Windows NT x86",       "W32X86",      2 },
+       {"Windows NT x86",       "W32X86",      3 },
        {"Windows NT R4000",     "W32MIPS",     2 },
        {"Windows NT Alpha_AXP", "W32ALPHA",    2 },
        {"Windows NT PowerPC",   "W32PPC",      2 },
@@ -395,7 +396,31 @@ static void display_port_info_2(PORT_INFO_2 *i2)
        rpcstr_pull(buffer, i2->description.buffer, sizeof(buffer), -1, STR_TERMINATE);
 
        printf("\tDescription:\t[%s]\n", buffer);
-       printf("\tPort Type:\t[%d]\n", i2->port_type);
+       printf("\tPort Type:\t" );
+       if ( i2->port_type ) {
+               int comma = 0; /* hack */
+               printf( "[" );
+               if ( i2->port_type & PORT_TYPE_READ ) {
+                       printf( "Read" );
+                       comma = 1;
+               }
+               if ( i2->port_type & PORT_TYPE_WRITE ) {
+                       printf( "%sWrite", comma ? ", " : "" );
+                       comma = 1;
+               }
+               /* These two have slightly different interpretations
+                on 95/98/ME but I'm disregarding that for now */
+               if ( i2->port_type & PORT_TYPE_REDIRECTED ) {
+                       printf( "%sRedirected", comma ? ", " : "" );
+                       comma = 1;
+               }
+               if ( i2->port_type & PORT_TYPE_NET_ATTACHED ) {
+                       printf( "%sNet-Attached", comma ? ", " : "" );
+               }
+               printf( "]\n" );
+       } else {
+               printf( "[Unset]\n" );
+       }
        printf("\tReserved:\t[%d]\n", i2->reserved);
        printf("\n");
 }
@@ -912,6 +937,7 @@ static WERROR cmd_spoolss_getdriver(struct cli_state *cli,
                        servername, 
                        user;
        uint32          i;
+       BOOL            success = False;
 
        if ((argc == 1) || (argc > 3)) 
        {
@@ -947,15 +973,22 @@ static WERROR cmd_spoolss_getdriver(struct cli_state *cli,
 
                werror = cli_spoolss_getprinterdriver(
                        cli, mem_ctx, 0, &needed, &pol, info_level, 
-                       archi_table[i].long_archi, &ctr);
+                       archi_table[i].long_archi, archi_table[i].version,
+                       &ctr);
 
-               if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+               if (W_ERROR_V(werror) == ERRinsufficientbuffer) {
                        werror = cli_spoolss_getprinterdriver(
                                cli, mem_ctx, needed, NULL, &pol, info_level, 
-                               archi_table[i].long_archi, &ctr);
+                               archi_table[i].long_archi, archi_table[i].version, 
+                               &ctr);
+               }
 
                if (!W_ERROR_IS_OK(werror))
                        continue;
+               
+               /* need at least one success */
+               
+               success = True;
                        
                printf ("\n[%s]\n", archi_table[i].long_archi);
 
@@ -980,6 +1013,9 @@ static WERROR cmd_spoolss_getdriver(struct cli_state *cli,
        if (opened_hnd)
                cli_spoolss_close_printer (cli, mem_ctx, &pol);
        
+       if ( success )
+               werror = WERR_OK;
+               
        return werror;
 }
 
index 831d2beaa41f296e213d2f61030fae6a562bdfe7..515489292bc2b0c6a9ff704454830166e52d218e 100644 (file)
@@ -40,7 +40,7 @@ static struct cmd_list {
 /****************************************************************************
 handle completion of commands for readline
 ****************************************************************************/
-static char **completion_fn(char *text, int start, int end)
+static char **completion_fn(const char *text, int start, int end)
 {
 #define MAX_COMPLETIONS 100
        char **matches;
@@ -361,7 +361,7 @@ static NTSTATUS cmd_schannel(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        static uchar zeros[16];
 
        if (argc == 2) {
-               strhex_to_str(cli->auth_info.sess_key,
+               strhex_to_str((char *)cli->auth_info.sess_key,
                              strlen(argv[1]), 
                              argv[1]);
                memcpy(cli->sess_key, cli->auth_info.sess_key, sizeof(cli->sess_key));
@@ -522,6 +522,8 @@ static NTSTATUS do_cmd(struct cli_state *cli,
        /* some of the DsXXX commands use the netlogon pipe */
 
        if (lp_client_schannel() && (cmd_entry->pipe_idx == PI_NETLOGON) && !(cli->pipe_auth_flags & AUTH_PIPE_NETSEC)) {
+               /* The 7 here seems to be required to get Win2k not to downgrade us
+                  to NT4.  Actually, anything other than 1ff would seem to do... */
                uint32 neg_flags = 0x000001ff;
                uint32 sec_channel_type;
        
@@ -725,8 +727,10 @@ out_free:
        nt_status = cli_full_connection(&cli, global_myname(), server, 
                                        opt_ipaddr ? &server_ip : NULL, 0,
                                        "IPC$", "IPC",  
-                                       cmdline_auth_info.username, lp_workgroup(),
-                                       cmdline_auth_info.password, 0,
+                                       cmdline_auth_info.username, 
+                                       lp_workgroup(),
+                                       cmdline_auth_info.password, 
+                                       cmdline_auth_info.use_kerberos ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
                                        cmdline_auth_info.signing_state,NULL);
        
        if (!NT_STATUS_IS_OK(nt_status)) {
index 9a1ee039d0c8f876551992483f6c82b3325d07b8..6122641718666dfe346ea6a027c0aac55e019f73 100644 (file)
@@ -4,7 +4,7 @@
    idmap LDAP backend
 
    Copyright (C) Tim Potter            2000
-   Copyright (C) Anthony Liguori       2003
+   Copyright (C) Jim McDonough <jmcd@us.ibm.com>       2003
    Copyright (C) Simo Sorce            2003
    Copyright (C) Gerald Carter                 2003
    
 struct ldap_idmap_state {
        struct smbldap_state *smbldap_state;
        TALLOC_CTX *mem_ctx;
-
-       uint32 low_allocated_user_rid;
-       uint32 high_allocated_user_rid;
-       uint32 low_allocated_group_rid;
-       uint32 high_allocated_group_rid;
-
 };
 
 #define LDAP_MAX_ALLOC_ID 128              /* number tries while allocating
@@ -203,11 +197,7 @@ static NTSTATUS ldap_next_rid(struct ldap_idmap_state *state, uint32 *rid,
                                                         get_attr_key2string(dominfo_attr_list, LDAP_ATTR_NEXT_USERRID),
                                                         old_rid_string)) 
                                {
-                                       
-                                       *rid = (uint32)atol(old_rid_string);
-                                       
-                               } else {
-                                       *rid = state->low_allocated_user_rid;
+                                       *rid = (uint32)atol(old_rid_string);                                    
                                }
                                break;
                        case GROUP_RID_TYPE:
@@ -216,8 +206,6 @@ static NTSTATUS ldap_next_rid(struct ldap_idmap_state *state, uint32 *rid,
                                                         old_rid_string)) 
                                {
                                        *rid = (uint32)atol(old_rid_string);
-                               } else {
-                                       *rid = state->low_allocated_group_rid;
                                }
                                break;
                        }
@@ -231,10 +219,6 @@ static NTSTATUS ldap_next_rid(struct ldap_idmap_state *state, uint32 *rid,
                        
                        switch (rid_type) {
                        case USER_RID_TYPE:
-                               if (next_rid > state->high_allocated_user_rid) {
-                                       return NT_STATUS_UNSUCCESSFUL;
-                               }
-                               
                                /* Try to make the modification atomically by enforcing the
                                   old value in the delete mod. */
                                smbldap_make_mod(state->smbldap_state->ldap_struct, entry, &mods, 
@@ -243,10 +227,6 @@ static NTSTATUS ldap_next_rid(struct ldap_idmap_state *state, uint32 *rid,
                                break;
                                
                        case GROUP_RID_TYPE:
-                               if (next_rid > state->high_allocated_group_rid) {
-                                       return NT_STATUS_UNSUCCESSFUL;
-                               }
-                               
                                /* Try to make the modification atomically by enforcing the
                                   old value in the delete mod. */
                                smbldap_make_mod(state->smbldap_state->ldap_struct, entry, &mods,
@@ -361,7 +341,7 @@ static NTSTATUS ldap_allocate_id(unid_t *id, int id_type)
                get_attr_key2string( idpool_attr_list, LDAP_ATTR_UIDNUMBER ) : 
                get_attr_key2string( idpool_attr_list, LDAP_ATTR_GIDNUMBER );
 
-       snprintf(filter, sizeof(filter)-1, "(objectClass=%s)", LDAP_OBJ_IDPOOL);
+       pstr_sprintf(filter, "(objectClass=%s)", LDAP_OBJ_IDPOOL);
 
        attr_list = get_attr_list( idpool_attr_list );
        
@@ -400,20 +380,23 @@ static NTSTATUS ldap_allocate_id(unid_t *id, int id_type)
        if (id_type & ID_USERID) {
                id->uid = strtoul(id_str, NULL, 10);
                if (id->uid > huid ) {
-                       DEBUG(0,("ldap_allocate_id: Cannot allocate uid above %d!\n", huid));
+                       DEBUG(0,("ldap_allocate_id: Cannot allocate uid above %lu!\n", 
+                                (unsigned long)huid));
                        goto out;
                }
        }
        else { 
                id->gid = strtoul(id_str, NULL, 10);
                if (id->gid > hgid ) {
-                       DEBUG(0,("ldap_allocate_id: Cannot allocate gid above %d!\n", hgid));
+                       DEBUG(0,("ldap_allocate_id: Cannot allocate gid above %lu!\n", 
+                                (unsigned long)hgid));
                        goto out;
                }
        }
        
-       snprintf(new_id_str, sizeof(new_id_str), "%u", 
-                ((id_type & ID_USERID) ? id->uid : id->gid) + 1);
+       pstr_sprintf(new_id_str, "%lu", 
+                ((id_type & ID_USERID) ? (unsigned long)id->uid : 
+                 (unsigned long)id->gid) + 1);
                 
        smbldap_set_mod( &mods, LDAP_MOD_DELETE, type, id_str );                 
        smbldap_set_mod( &mods, LDAP_MOD_ADD, type, new_id_str );
@@ -458,27 +441,38 @@ static NTSTATUS ldap_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type)
        if ( id_type & ID_USERID ) {
                type = get_attr_key2string( idpool_attr_list, LDAP_ATTR_UIDNUMBER );
                obj_class = LDAP_OBJ_SAMBASAMACCOUNT;
-               snprintf(id_str, sizeof(id_str), "%u", id.uid );        
+               fstr_sprintf(id_str, "%lu", (unsigned long)id.uid );    
                pstrcpy( suffix, lp_ldap_suffix());
        }
        else {
                type = get_attr_key2string( idpool_attr_list, LDAP_ATTR_GIDNUMBER );
                obj_class = LDAP_OBJ_GROUPMAP;
-               snprintf(id_str, sizeof(id_str), "%u", id.gid );        
+               fstr_sprintf(id_str, "%lu", (unsigned long)id.gid );    
                pstrcpy( suffix, lp_ldap_group_suffix() );
        }
+
+       DEBUG(5,("ldap_get_sid_from_id: Searching \"%s\"\n", filter ));
                 
        attr_list = get_attr_list( sidmap_attr_list );
-       snprintf(filter, sizeof(filter), "(&(|(objectClass=%s)(objectClass=%s))(%s=%s))", 
+       pstr_sprintf(filter, "(&(|(objectClass=%s)(objectClass=%s))(%s=%s))", 
                 LDAP_OBJ_IDMAP_ENTRY, obj_class, type, id_str);
 
        rc = smbldap_search(ldap_state.smbldap_state, suffix, LDAP_SCOPE_SUBTREE, 
                            filter, attr_list, 0, &result);
        
-       if (rc != LDAP_SUCCESS) 
+       if (rc != LDAP_SUCCESS) {
+               DEBUG(3,("ldap_get_isd_from_id: Failure looking up entry (%s)\n",
+                       ldap_err2string(rc) ));
                goto out;
-          
+       }
+
        count = ldap_count_entries(ldap_state.smbldap_state->ldap_struct, result);
+       
+       if (count > 1) {
+               DEBUG(0,("ldap_get_sid_from_id: mapping returned [%d] entries!\n",
+                       count));
+               goto out;
+       }
 
        /* fall back to looking up an idmap entry if we didn't find and 
           actual user or group */
@@ -487,24 +481,30 @@ static NTSTATUS ldap_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type)
                ldap_msgfree(result);
                result = NULL;
                
-               snprintf(filter, sizeof(filter), "(&(objectClass=%s)(%s=%u))",
-                       LDAP_OBJ_IDMAP_ENTRY, type,  ((id_type & ID_USERID) ? id.uid : id.gid));
+               pstr_sprintf(filter, "(&(objectClass=%s)(%s=%lu))",
+                       LDAP_OBJ_IDMAP_ENTRY, type,  
+                        ((id_type & ID_USERID) ? (unsigned long)id.uid : 
+                         (unsigned long)id.gid));
 
                pstrcpy( suffix, lp_ldap_idmap_suffix() );
 
                rc = smbldap_search(ldap_state.smbldap_state, suffix, LDAP_SCOPE_SUBTREE, 
                        filter, attr_list, 0, &result);
 
-               if (rc != LDAP_SUCCESS)
-                          goto out;
+               if (rc != LDAP_SUCCESS) {
+                       DEBUG(3,("ldap_get_isd_from_id: Failure looking up entry (%s)\n",
+                               ldap_err2string(rc) ));
+                       goto out;
+               }
                           
                count = ldap_count_entries(ldap_state.smbldap_state->ldap_struct, result);
-       }
-       
-       if (count != 1) {
-               DEBUG(0,("ldap_get_sid_from_id: mapping not found for %s: %u\n", 
-                       type, ((id_type & ID_USERID) ? id.uid : id.gid)));
-               goto out;
+
+               if (count != 1) {
+                       DEBUG(0,("ldap_get_sid_from_id: mapping not found for %s: %lu\n", 
+                               type, ((id_type & ID_USERID) ? (unsigned long)id.uid : 
+                                      (unsigned long)id.gid)));
+                       goto out;
+               }
        }
        
        entry = ldap_first_entry(ldap_state.smbldap_state->ldap_struct, result);
@@ -538,117 +538,146 @@ static NTSTATUS ldap_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *si
        pstring id_str;
        const char *suffix;     
        const char *type;
-       const char *obj_class;
-       const char *posix_obj_class;
        int rc;
        int count;
        char **attr_list;
        char *dn = NULL;
        NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
 
-       /* first try getting the mapping from a samba user or group */
-       
        sid_to_string(sid_str, sid);
-       if ( *id_type & ID_USERID ) {
-               type = get_attr_key2string( sidmap_attr_list, LDAP_ATTR_UIDNUMBER );
-               obj_class = LDAP_OBJ_SAMBASAMACCOUNT;
-               posix_obj_class = LDAP_OBJ_POSIXACCOUNT;
-               suffix = lp_ldap_suffix();
-               snprintf(filter, sizeof(filter), 
-                        "(&(|(&(objectClass=%s)(objectClass=%s))(objectClass=%s))(%s=%s))", 
-                        obj_class, posix_obj_class, LDAP_OBJ_IDMAP_ENTRY, 
-                        get_attr_key2string( sidmap_attr_list, LDAP_ATTR_SID ), 
-                        sid_str);
-       }
-       else {
+
+       DEBUG(8,("ldap_get_id_from_sid: %s (%s)\n", sid_str,
+               (*id_type & ID_GROUPID ? "group" : "user") ));
+
+       /* ahhh....  ok.  We have to check users and groups in places other
+          than idmap (hint: we're a domain member of a Samba domain) */
+
+       if ( *id_type & ID_GROUPID ) {
+
                type = get_attr_key2string( sidmap_attr_list, LDAP_ATTR_GIDNUMBER );
-               obj_class = LDAP_OBJ_GROUPMAP;
-               posix_obj_class = LDAP_OBJ_POSIXGROUP;
                suffix = lp_ldap_group_suffix();
-               snprintf(filter, sizeof(filter), 
-                        "(&(|(objectClass=%s)(objectClass=%s))(%s=%s))", 
-                        obj_class, LDAP_OBJ_IDMAP_ENTRY, 
+               pstr_sprintf(filter, "(&(|(objectClass=%s)(objectClass=%s))(%s=%s))", 
+                       LDAP_OBJ_GROUPMAP, LDAP_OBJ_IDMAP_ENTRY, 
+                       get_attr_key2string( sidmap_attr_list, LDAP_ATTR_SID ), 
+                       sid_str);
+
+       }
+       else {
+
+               type = get_attr_key2string( sidmap_attr_list, LDAP_ATTR_UIDNUMBER );
+               suffix = lp_ldap_suffix();
+               pstr_sprintf(filter, "(&(|(&(objectClass=%s)(objectClass=%s))(objectClass=%s))(%s=%s))", 
+                        LDAP_OBJ_SAMBASAMACCOUNT, LDAP_OBJ_POSIXACCOUNT, LDAP_OBJ_IDMAP_ENTRY, 
                         get_attr_key2string( sidmap_attr_list, LDAP_ATTR_SID ), 
                         sid_str);
+
        }
-          
+
+       DEBUG(10,("ldap_get_id_from_sid: Searching for \"%s\"\n", filter));
+
+       /* do the search and check for errors */
+
        attr_list = get_attr_list( sidmap_attr_list );
        rc = smbldap_search(ldap_state.smbldap_state, suffix, LDAP_SCOPE_SUBTREE, 
-               filter, attr_list, 0, &result);
-               
-       if (rc != LDAP_SUCCESS)
+               filter, attr_list, 0, &result); 
+
+       if ( rc != LDAP_SUCCESS ) {
+               DEBUG(3,("ldap_get_id_from_sid: Failure looking up group mapping (%s)\n",
+                       ldap_err2string(rc) ));
                goto out;
+       }
 
        count = ldap_count_entries(ldap_state.smbldap_state->ldap_struct, result);
-       
-       /* fall back to looking up an idmap entry if we didn't find anything under the idmap
-          user or group suffix */
 
-       if (count == 0) {
-               ldap_msgfree(result);
-               
-               snprintf(filter, sizeof(filter), "(&(objectClass=%s)(%s=%s))", 
-                       LDAP_OBJ_IDMAP_ENTRY, LDAP_ATTRIBUTE_SID, sid_str);
+       if ( count > 1 ) {
+               DEBUG(3,("ldap_get_id_from_sid: search \"%s\" returned [%d] entries.  Bailing...\n",
+                       filter, count));
+               goto out;
+       }
+
+       /* see if we need to do a search here */
+
+       if ( count == 0 ) {
+
+               if ( result ) {
+                       ldap_msgfree(result);
+                       result = NULL;
+               }
+
+               /* look in idmap suffix */
 
                suffix = lp_ldap_idmap_suffix();
+               pstr_sprintf(filter, "(&(objectClass=%s)(%s=%s))", 
+                       LDAP_OBJ_IDMAP_ENTRY, LDAP_ATTRIBUTE_SID, sid_str);
 
                rc = smbldap_search(ldap_state.smbldap_state, suffix, LDAP_SCOPE_SUBTREE, 
                        filter, attr_list, 0, &result);
                        
-               if (rc != LDAP_SUCCESS)
+               if (rc != LDAP_SUCCESS) {
+                       DEBUG(3,("ldap_get_id_from_sid: Failure looking up idmap entry (%s)\n",
+                               ldap_err2string(rc) ));
                        goto out;
+               }
                        
+               /* check for the number of entries returned */
+
                count = ldap_count_entries(ldap_state.smbldap_state->ldap_struct, result);
-       }
           
-       if ( count > 1 ) {
-               DEBUG(0, ("ldap_get_id_from_sid: search %s returned more than on entry!\n",
-                       filter));
-               goto out;
-       }
-
-       /* we might have an existing entry to work with so pull out the requested information */
-       
-       if ( count ) {
-               entry = ldap_first_entry(ldap_state.smbldap_state->ldap_struct, result);
-       
-               dn = ldap_get_dn(ldap_state.smbldap_state->ldap_struct, result);
-               DEBUG(10, ("Found mapping entry at dn=%s, looking for %s\n", dn, type));
-               
-               if ( smbldap_get_single_attribute(ldap_state.smbldap_state->ldap_struct, entry, type, id_str) ) 
-               {
-                       if ( (*id_type & ID_USERID) )
-                               id->uid = strtoul(id_str, NULL, 10);
-                       else
-                               id->gid = strtoul(id_str, NULL, 10);
-                       
-                       ret = NT_STATUS_OK;
+               if ( count > 1 ) {
+                       DEBUG(0, ("ldap_get_id_from_sid: (2nd) search %s returned [%d] entries!\n",
+                               filter, count));
                        goto out;
                }
-       }
        
-       if (!(*id_type & ID_QUERY_ONLY)) {
-               /* if entry == NULL, and we are asked to - allocate a new id */
-               int i;
+
+               /* try to allocate a new id if we still haven't found one */
+
+               if ( (count==0) && !(*id_type & ID_QUERY_ONLY) ) {
+                       int i;
+
+                       DEBUG(8,("ldap_get_id_from_sid: Allocating new id\n"));
                
-               for (i = 0; i < LDAP_MAX_ALLOC_ID; i++) 
-               {
-                       ret = ldap_allocate_id(id, *id_type);
-                       if ( NT_STATUS_IS_OK(ret) )
-                               break;
-               }
+                       for (i = 0; i < LDAP_MAX_ALLOC_ID; i++) {
+                               ret = ldap_allocate_id(id, *id_type);
+                               if ( NT_STATUS_IS_OK(ret) )
+                                       break;
+                       }
                
-               if ( !NT_STATUS_IS_OK(ret) ) {
-                       DEBUG(0,("ldap_allocate_id: cannot acquire id lock!\n"));
+                       if ( !NT_STATUS_IS_OK(ret) ) {
+                               DEBUG(0,("ldap_allocate_id: cannot acquire id lock!\n"));
+                               goto out;
+                       }
+
+                       DEBUG(10,("ldap_get_id_from_sid: Allocated new %cid [%ul]\n",
+                               (*id_type & ID_GROUPID ? 'g' : 'u'), (uint32)id->uid ));
+       
+                       ret = ldap_set_mapping(sid, *id, *id_type);
+
+                       /* all done */
+
                        goto out;
                }
-               
-               ret = ldap_set_mapping(sid, *id, *id_type);
-       } else {
-               /* no match, and not adding one */
-               ret = NT_STATUS_UNSUCCESSFUL;
        }
 
+       DEBUG(10,("ldap_get_id_from_sid: success\n"));
+
+       entry = ldap_first_entry(ldap_state.smbldap_state->ldap_struct, result);
+       
+       dn = ldap_get_dn(ldap_state.smbldap_state->ldap_struct, result);
+
+       DEBUG(10, ("Found mapping entry at dn=%s, looking for %s\n", dn, type));
+               
+       if ( smbldap_get_single_attribute(ldap_state.smbldap_state->ldap_struct, entry, type, id_str) ) 
+       {
+               if ( (*id_type & ID_USERID) )
+                       id->uid = strtoul(id_str, NULL, 10);
+               else
+                       id->gid = strtoul(id_str, NULL, 10);
+               
+               ret = NT_STATUS_OK;
+               goto out;
+       }
+       
 out:
        free_attr_list( attr_list );
        if (result)
@@ -670,7 +699,7 @@ static NTSTATUS ldap_set_mapping_internals(const DOM_SID *sid, unid_t id,
                                           int id_type, const char *ldap_dn, 
                                           LDAPMessage *entry)
 {
-       char *dn = NULL;
+       pstring dn; 
        pstring id_str;
        fstring type;
        LDAPMod **mods = NULL;
@@ -685,24 +714,20 @@ static NTSTATUS ldap_set_mapping_internals(const DOM_SID *sid, unid_t id,
        if (ldap_dn) {
                DEBUG(10, ("Adding new IDMAP mapping on DN: %s", ldap_dn));
                ldap_op = LDAP_MOD_REPLACE;
-               dn = strdup(ldap_dn);
+               pstrcpy( dn, ldap_dn );
        } else {
                ldap_op = LDAP_MOD_ADD;
-               asprintf(&dn, "%s=%s,%s", get_attr_key2string( sidmap_attr_list, LDAP_ATTR_SID), 
+               pstr_sprintf(dn, "%s=%s,%s", get_attr_key2string( sidmap_attr_list, LDAP_ATTR_SID), 
                         sid_string, lp_ldap_idmap_suffix());
        }
        
-       if (!dn) {
-               DEBUG(0, ("ldap_set_mapping_internals: out of memory allocating DN!\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
        if ( id_type & ID_USERID ) 
                fstrcpy( type, get_attr_key2string( sidmap_attr_list, LDAP_ATTR_UIDNUMBER ) );
        else
                fstrcpy( type, get_attr_key2string( sidmap_attr_list, LDAP_ATTR_GIDNUMBER ) );
 
-       snprintf(id_str, sizeof(id_str), "%u", ((id_type & ID_USERID) ? id.uid : id.gid));      
+       pstr_sprintf(id_str, "%lu", ((id_type & ID_USERID) ? (unsigned long)id.uid : 
+                                                (unsigned long)id.gid));       
        
        if (entry) 
                values = ldap_get_values(ldap_state.smbldap_state->ldap_struct, entry, "objectClass");
@@ -754,15 +779,16 @@ static NTSTATUS ldap_set_mapping_internals(const DOM_SID *sid, unid_t id,
                char *ld_error = NULL;
                ldap_get_option(ldap_state.smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,
                                &ld_error);
-               DEBUG(0,("ldap_set_mapping_internals: Failed to %s mapping from %s to %u [%s]\n",
+               DEBUG(0,("ldap_set_mapping_internals: Failed to %s mapping from %s to %lu [%s]\n",
                         (ldap_op == LDAP_MOD_ADD) ? "add" : "replace",
-                        sid_string, (unsigned int)((id_type & ID_USERID) ? id.uid : id.gid), type));
+                        sid_string, (unsigned long)((id_type & ID_USERID) ? id.uid : id.gid), type));
                DEBUG(0, ("ldap_set_mapping_internals: Error was: %s (%s)\n", ld_error ? ld_error : "(NULL)", ldap_err2string (rc)));
                return NT_STATUS_UNSUCCESSFUL;
        }
                
-       DEBUG(10,("ldap_set_mapping: Successfully created mapping from %s to %d [%s]\n",
-               sid_string, ((id_type & ID_USERID) ? id.uid : id.gid), type));
+       DEBUG(10,("ldap_set_mapping: Successfully created mapping from %s to %lu [%s]\n",
+               sid_string, ((id_type & ID_USERID) ? (unsigned long)id.uid : 
+                            (unsigned long)id.gid), type));
 
        return NT_STATUS_OK;
 }
@@ -794,18 +820,18 @@ static NTSTATUS ldap_set_mapping(const DOM_SID *sid, unid_t id, int id_type)
                suffix = lp_ldap_suffix();
                type = get_attr_key2string( idpool_attr_list, LDAP_ATTR_UIDNUMBER );
                posix_obj_class = LDAP_OBJ_POSIXACCOUNT;
-               snprintf(id_str, sizeof(id_str), "%u", id.uid );        
+               fstr_sprintf(id_str, "%lu", (unsigned long)id.uid );    
        }
        else {
                obj_class = LDAP_OBJ_GROUPMAP;
                suffix = lp_ldap_group_suffix();
                type = get_attr_key2string( idpool_attr_list, LDAP_ATTR_GIDNUMBER );
                posix_obj_class = LDAP_OBJ_POSIXGROUP;
-               snprintf(id_str, sizeof(id_str), "%u", id.gid );        
+               fstr_sprintf(id_str, "%lu", (unsigned long)id.gid );    
        }
        
        sid_to_string(sid_str, sid);
-       snprintf(filter, sizeof(filter)
+       pstr_sprintf(filter
                 "(|"
                 "(&(|(objectClass=%s)(|(objectClass=%s)(objectClass=%s)))(%s=%s))"
                 "(&(objectClass=%s)(%s=%s))"
@@ -859,10 +885,13 @@ out:
        
        return ret;
 }
-/*****************************************************************************
- Initialise idmap database. 
-*****************************************************************************/
-static NTSTATUS ldap_idmap_init( char *params )
+
+
+/**********************************************************************
+ Verify the sambaUnixIdPool entry in the directiry.  
+**********************************************************************/
+
+static NTSTATUS verify_idpool( void )
 {
        fstring filter;
        int rc;
@@ -870,24 +899,8 @@ static NTSTATUS ldap_idmap_init( char *params )
        LDAPMessage *result = NULL;
        LDAPMod **mods = NULL;
        int count;
-       NTSTATUS nt_status;
-
-       ldap_state.mem_ctx = talloc_init("idmap_ldap");
-       if (!ldap_state.mem_ctx) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       /* assume location is the only parameter */
-       if (!NT_STATUS_IS_OK(nt_status = 
-                            smbldap_init(ldap_state.mem_ctx, params, 
-                                         &ldap_state.smbldap_state))) {
-               talloc_destroy(ldap_state.mem_ctx);
-               return nt_status;
-       }
-
-       /* see if the idmap suffix and sub entries exists */
        
-       snprintf( filter, sizeof(filter), "(objectclass=%s)", LDAP_OBJ_IDPOOL );
+       fstr_sprintf( filter, "(objectclass=%s)", LDAP_OBJ_IDPOOL );
        
        attr_list = get_attr_list( idpool_attr_list );
        rc = smbldap_search(ldap_state.smbldap_state, lp_ldap_idmap_suffix(), 
@@ -914,8 +927,8 @@ static NTSTATUS ldap_idmap_init( char *params )
                        return NT_STATUS_UNSUCCESSFUL;
                }
                
-               snprintf( uid_str, sizeof(uid_str), "%d", luid );
-               snprintf( gid_str, sizeof(gid_str), "%d", lgid );
+               fstr_sprintf( uid_str, "%lu", (unsigned long)luid );
+               fstr_sprintf( gid_str, "%lu", (unsigned long)lgid );
 
                smbldap_set_mod( &mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_IDPOOL );
                smbldap_set_mod( &mods, LDAP_MOD_ADD, 
@@ -925,7 +938,36 @@ static NTSTATUS ldap_idmap_init( char *params )
                
                rc = smbldap_modify(ldap_state.smbldap_state, lp_ldap_idmap_suffix(), mods);
        }
+
+       return ( rc==LDAP_SUCCESS ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
+}
+
+/*****************************************************************************
+ Initialise idmap database. 
+*****************************************************************************/
+static NTSTATUS ldap_idmap_init( char *params )
+{
+       NTSTATUS nt_status;
+
+       ldap_state.mem_ctx = talloc_init("idmap_ldap");
+       if (!ldap_state.mem_ctx) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       /* assume location is the only parameter */
+       if (!NT_STATUS_IS_OK(nt_status = 
+                            smbldap_init(ldap_state.mem_ctx, params, 
+                                         &ldap_state.smbldap_state))) {
+               talloc_destroy(ldap_state.mem_ctx);
+               return nt_status;
+       }
+
+       /* see if the idmap suffix and sub entries exists */
        
+       nt_status = verify_idpool();    
+       if ( !NT_STATUS_IS_OK(nt_status) )
+               return nt_status;
+               
        return NT_STATUS_OK;
 }
 
index 20551038986c9d388a30958fbc1f5d1c51f65a57..8ab8ec8477073958462bc0670d87caf3a5c13aa4 100644 (file)
@@ -45,20 +45,6 @@ static struct idmap_state {
        gid_t gid_low, gid_high;               /* Range of gids to allocate */
 } idmap_state;
 
-/**********************************************************************
- Return the TDB_CONTEXT* for winbindd_idmap.  I **really** feel
- dirty doing this, but not so dirty that I want to create another 
- tdb
-***********************************************************************/
-
-TDB_CONTEXT *idmap_tdb_handle( void )
-{
-       if ( idmap_tdb )
-               return idmap_tdb;
-       
-       return NULL;
-}
-
 /**********************************************************************
  allocate a new RID; We don't care if is a user or group
 **********************************************************************/
@@ -75,7 +61,7 @@ static NTSTATUS db_allocate_rid(uint32 *rid, int rid_type)
        
        /* cannot fail since idmap is only called winbindd */
        
-       idmap_get_free_rid_range( &lowrid, &highrid );
+       get_free_rid_range( &lowrid, &highrid );
        
        tmp_rid = lowrid;
        
@@ -122,7 +108,7 @@ static NTSTATUS db_allocate_id(unid_t *id, int id_type)
                        }
 
                        /* fetch a new id and increment it */
-                       ret = tdb_change_uint32_atomic(idmap_tdb, HWM_USER, &hwm, 1);
+                       ret = tdb_change_uint32_atomic(idmap_tdb, HWM_USER, (unsigned int *)&hwm, 1);
                        if (!ret) {
                                DEBUG(0, ("idmap_tdb: Fatal error while fetching a new id\n!"));
                                return NT_STATUS_UNSUCCESSFUL;
@@ -152,7 +138,7 @@ static NTSTATUS db_allocate_id(unid_t *id, int id_type)
                        }
 
                        /* fetch a new id and increment it */
-                       ret = tdb_change_uint32_atomic(idmap_tdb, HWM_GROUP, &hwm, 1);
+                       ret = tdb_change_uint32_atomic(idmap_tdb, HWM_GROUP, (unsigned int *)&hwm, 1);
 
                        if (!ret) {
                                DEBUG(0, ("idmap_tdb: Fatal error while fetching a new id\n!"));
@@ -650,6 +636,27 @@ static void db_idmap_status(void)
        /* Display complete mapping of users and groups to rids */
 }
 
+/**********************************************************************
+ Return the TDB_CONTEXT* for winbindd_idmap.  I **really** feel
+ dirty doing this, but not so dirty that I want to create another 
+ tdb
+***********************************************************************/
+
+TDB_CONTEXT *idmap_tdb_handle( void )
+{
+       if ( idmap_tdb )
+               return idmap_tdb;
+               
+       /* go ahead an open it;  db_idmap_init() doesn't use any params 
+          right now */
+          
+       db_idmap_init( NULL );
+       if ( idmap_tdb )
+               return idmap_tdb;
+               
+       return NULL;
+}
+
 static struct idmap_methods db_methods = {
 
        db_idmap_init,
index f794ea5173d9e464a44c8196700593d78051978a..f28e11cde745a9b04a4a723b11580ed7b7aca809 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
 
-/**********************************************************************
-**********************************************************************/
-
-BOOL idmap_get_free_ugid_range(uint32 *low, uint32 *high)
-{
-       uid_t u_low, u_high;
-       gid_t g_low, g_high;
-
-       if (!lp_idmap_uid(&u_low, &u_high) || !lp_idmap_gid(&g_low, &g_high)) {
-               return False;
-       }
-       
-       *low  = (u_low < g_low)   ? u_low  : g_low;
-       *high = (u_high < g_high) ? u_high : g_high;
-       
-       return True;
-}
-
-/******************************************************************
- Get the the non-algorithmic RID range if idmap range are defined
-******************************************************************/
-
-BOOL idmap_get_free_rid_range(uint32 *low, uint32 *high)
-{
-       uint32 id_low, id_high;
-
-       if (!lp_enable_rid_algorithm()) {
-               *low = BASE_RID;
-               *high = (uint32)-1;
-       }
-
-       if (!idmap_get_free_ugid_range(&id_low, &id_high)) {
-               return False;
-       }
-
-       *low = fallback_pdb_uid_to_user_rid(id_low);
-       if (fallback_pdb_user_rid_to_uid((uint32)-1) < id_high) {
-               *high = (uint32)-1;
-       } else {
-               *high = fallback_pdb_uid_to_user_rid(id_high);
-       }
-
-       return True;
-}
+#if 0  /* NOT USED */
 
 /**********************************************************************
  Get the free RID base if idmap is configured, otherwise return 0
@@ -137,6 +94,8 @@ BOOL idmap_check_sid_is_in_free_range(const DOM_SID *sid)
        return True;
 }
 
+#endif /* NOT USED */
+
 /*****************************************************************
  Returns SID pointer.
 *****************************************************************/  
@@ -192,7 +151,7 @@ NTSTATUS idmap_sid_to_uid(const DOM_SID *sid, uid_t *uid, uint32 flags)
 
        flags |= ID_USERID;
 
-       ret = idmap_get_id_from_sid(&id, &flags, sid);
+       ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
        
        if ( NT_STATUS_IS_OK(ret) ) {
                DEBUG(10,("idmap_sid_to_uid: uid = [%lu]\n", (unsigned long)id.uid));
@@ -221,7 +180,7 @@ NTSTATUS idmap_sid_to_gid(const DOM_SID *sid, gid_t *gid, uint32 flags)
 
        flags |= ID_GROUPID;
 
-       ret = idmap_get_id_from_sid(&id, &flags, sid);
+       ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
        
        if ( NT_STATUS_IS_OK(ret) ) 
        {
index 7a8114ecd73942c7d16348b6bbca42705c4e9b91..0464ca23351366dea1e1339fe051eadbbbf4626c 100644 (file)
@@ -1 +1,2 @@
 findsmb
+gen-8bit-gap.sh
diff --git a/source3/script/find_missing_doc.pl b/source3/script/find_missing_doc.pl
deleted file mode 100755 (executable)
index b27a405..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/perl
-
-my $doc_file = "/docs/docbook/manpages/smb.conf.5.sgml";
-my $source_file = "/source/param/loadparm.c";
-
-my %link,%doc,%param;
-
-# This one shouldn't be documented at all
-$doc{-valid} = "FOUND";
-
-$topdir = (shift @ARGV) or $topdir = ".";
-
-##################################################
-# Reading links from manpage
-
-open(IN,$topdir.$doc_file);
-
-while(<IN>) {
-       if( /<listitem><para><link linkend="([^"]*)"><parameter>([^<]*)<\/parameter><\/link><\/para><\/listitem>/g ){
-               $link{$2} = $1;
-               $ref{$1} = $2;
-       }
-}
-
-close(IN);
-
-##################################################
-# Reading documentation from manpage
-
-open(IN,$topdir.$doc_file) || die("Can't open $topdir$doc_file");
-
-while(<IN>) {
-       if( /<term><anchor id="([^"]*)"\/>([^<]*?)([ ]*)\(.\)([ ]*)<\/term>/g ) {
-               $key = $1;
-               $value = $2;
-               $doc{$value} = $key;
-
-               # There is a reference to this entry
-               if($ref{$key} eq $value){
-                       $ref{$key} = "FOUND";
-               } else {
-                       if($ref{$key}) {
-                               print "$key should refer to $value, but refers to " . $ref{$key} . "\n";
-                       } else {
-                               print "$key should refer to $value, but has no reference!\n";
-                       }
-                       $ref{$key} = $value;
-               }
-       }
-}
-
-close(IN);
-
-#################################################
-# Reading entries from source code
-
-open(SOURCE,$topdir.$source_file) || die("Can't open $topdir$source_file");
-
-while ($ln = <SOURCE>) {
-  last if $ln =~ m/^static\ struct\ parm_struct\ parm_table.*/;
-} #burn through the preceding lines
-
-while ($ln = <SOURCE>) {
-  last if $ln =~ m/^\s*\}\;\s*$/;
-  #pull in the param names only
-  next if $ln =~ m/.*P_SEPARATOR.*/;
-  next unless $ln =~ /.*\"(.*)\".*/;
-  
-  if($doc{lc($1)}) {
-       $doc{lc($1)} = "FOUND";
-  } else {
-       print "$1 is not documented!\n";
-  }
-}
-close SOURCE;
-
-##################################################
-# Trying to find missing references
-
-foreach (keys %ref) {
-       if($ref{$_} cmp "FOUND") {
-               print "$_ references to " . $ref{$_} . ", but " . $ref{$_} . " isn't an anchor!\n";
-       }
-}
-
-foreach (keys %doc) {
-       if($doc{$_} cmp "FOUND") {
-               print "$_ is documented but is not a configuration option!\n";
-       }
-}
index 6276bd3f3921bed6a45e75cdb324b166330a8f0a..fb06018fe5c47bb1836809cad95dab8272bcd8d5 100755 (executable)
 $SAMBABIN = "@prefix@/bin";
 
 for ($i = 0; $i < 2; $i++) {   # test for -d and -r options
-  $_ = shift;
-  if (m/-d|-D/) {
-    $DEBUG = 1;
-  } elsif (m/-r/) {
-    $R_OPTION = "-r";
-  }
+       $_ = shift;
+       if (m/-d|-D/) {
+               $DEBUG = 1;
+       } elsif (m/-r/) {
+               $R_OPTION = "-r";
+       }
 }
 
 if ($_) {                      # set broadcast address if it was specified
-      $BCAST = "-B $_";
+       $BCAST = "-B $_";
 }
 
-sub ipsort                     # do numeric sort on last field of IP address
+
+######################################################################
+# do numeric sort on last field of IP address
+sub ipsort                     
 {
-  @t1 = split(/\./,$a);
-  @t2 = split(/\./,$b);
-  @t1[3] <=> @t2[3];
+       @t1 = split(/\./,$a);
+       @t2 = split(/\./,$b);
+       @t1[3] <=> @t2[3];
 }
+######################################################################
 
 # look for all machines that respond to a name lookup
 
-open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*'|") || 
-  die("Can't run nmblookup '*'.\n");
+open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*' --debuglevel=0|") || 
+       die("Can't run nmblookup '*'.\n");
 
 # get rid of all lines that are not a response IP address,
 # strip everything but IP address and sort by last field in address
@@ -59,94 +63,98 @@ print "---------------------------------------------------------------------\n";
 
 foreach $ip (@ipaddrs)         # loop through each IP address found
 {
-  $ip =~ s/\n//;               # strip newline from IP address
-
-# find the netbios names registered by each machine
-
-  open(NMBLOOKUP,"$SAMBABIN/nmblookup $R_OPTION -A $ip|") || 
-       die("Can't get nmb name list.\n");
-  @nmblookup = <NMBLOOKUP>;
-  close NMBLOOKUP;
-
-# get the first <00> name
-
-  @name = grep(/<00>/,@nmblookup);
-  $_ = @name[0];
-  if ($_) {                     # we have a netbios name
-    if (/GROUP/) {             # is it a group name
-       ($name, $aliases, $type, $length, @addresses) = 
-       gethostbyaddr(pack('C4',split('\.',$ip)),2);
-       if (! $name) {                  # could not get name
-           $name = "unknown nis name";
+       $ip =~ s/\n//;          # strip newline from IP address
+
+       # find the netbios names registered by each machine
+
+       open(NMBLOOKUP,"$SAMBABIN/nmblookup $R_OPTION -A $ip --debuglevel=0|") || 
+               die("Can't get nmb name list.\n");
+       @nmblookup = <NMBLOOKUP>;
+       close NMBLOOKUP;
+
+       # get the first <00> name
+
+       @name = grep(/<00>/,@nmblookup);
+       $_ = @name[0];
+
+       if ($_) {                       # we have a netbios name
+               if (/GROUP/) {          # is it a group name
+                       ($name, $aliases, $type, $length, @addresses) = 
+                       gethostbyaddr(pack('C4',split('\.',$ip)),2);
+                       if (! $name) {                  # could not get name
+                               $name = "unknown nis name";
+                       }
+               } else {
+                       # The Netbios name can contain lot of characters also '<' '>'
+                       # and spaces. The follwing cure inside name space but not
+                       # names starting or ending with spaces
+                       /(.{1,15})\s+<00>\s+/;
+                       $name = $1;
+                       $name =~ s/^\s+//g;
+               }
+
+               # do an smbclient command on the netbios name.
+
+               if ( "$name" ) {
+                       open(SMB,"$SAMBABIN/smbclient -L $name -I $ip -N --debuglevel=1 2>&1 |") ||
+                               die("Can't do smbclient command.\n");
+                       @smb = <SMB>;
+                       close SMB;
+
+                       if ($DEBUG) {           # if -d flag print results of nmblookup and smbclient
+                               print "===============================================================\n";
+                               print @nmblookup;
+                               print @smb;
+                       }
+
+                       # look for the OS= string
+
+                       @info = grep(/OS=/,@smb);
+                       $_ = @info[0];
+                       if ($_) {                               # we found response
+                               s/Domain=|OS=|Server=|\n//g;    # strip out descriptions to make line shorter
+
+                       } else {                                # no OS= string in response (WIN95 client)
+
+                               # for WIN95 clients get workgroup name from nmblookup response
+                               @name = grep(/<00> - <GROUP>/,@nmblookup);
+                               $_ = @name[0];
+                               if ($_) {
+                                       # Same as before for space and characters
+                                       /(.{1,15})\s+<00>\s+/;
+                                       $_ = "[$1]";
+                               } else {
+                                       $_ = "Unknown Workgroup";
+                               }
+                       }
+               }
+
+               # see if machine registered a local master browser name
+               if (grep(/<1d>/,@nmblookup)) {
+                       $master = '+';                  # indicate local master browser
+                       if (grep(/<1b>/,@nmblookup)) {  # how about domain master browser?
+                               $master = '*';                  # indicate domain master browser
+                       }
+               } else {
+                       $master = ' ';                  # not a browse master
+               }
+
+               # line up info in 3 columns
+
+               print "$ip".' 'x(16-length($ip))."$name".' 'x(14-length($name))."$master"."$_\n";
+
+       } else {                                # no netbios name found
+               # try getting the host name
+               ($name, $aliases, $type, $length, @addresses) = 
+               gethostbyaddr(pack('C4',split('\.',$ip)),2);
+               if (! $name) {                  # could not get name
+                       $name = "unknown nis name";
+               }
+               if ($DEBUG) {                   # if -d flag print results of nmblookup
+                       print "===============================================================\n";
+                       print @nmblookup;
+               }
+               print "$ip".' 'x(16-length($ip))."$name\n";
        }
-    } else {
-# The Netbios name can contain lot of characters also '<' '>'
-# and spaces. The follwing cure inside name space but not
-# names starting or ending with spaces
-       /(.{1,15})\s+<00>\s+/;
-       $name = $1;
-    }
-
-# do an smbclient command on the netbios name.
-
-    open(SMB,"$SAMBABIN/smbclient -N -L $name -I $ip -U% |") ||
-       die("Can't do smbclient command.\n");
-    @smb = <SMB>;
-    close SMB;
-
-    if ($DEBUG) {              # if -d flag print results of nmblookup and smbclient
-      print "===============================================================\n";
-      print @nmblookup;
-      print @smb;
-    }
-
-# look for the OS= string
-
-    @info = grep(/OS=/,@smb);
-    $_ = @info[0];
-    if ($_) {                          # we found response
-      s/Domain=|OS=|Server=|\n//g;     # strip out descriptions to make line shorter
-
-    } else {                           # no OS= string in response (WIN95 client)
-
-# for WIN95 clients get workgroup name from nmblookup response
-      @name = grep(/<00> - <GROUP>/,@nmblookup);
-      $_ = @name[0];
-      if ($_) {
-# Same as before for space and characters
-        /(.{1,15})\s+<00>\s+/;
-        $_ = "[$1]";
-      } else {
-       $_ = "Unknown Workgroup";
-      }
-    }
-
-# see if machine registered a local master browser name
-    if (grep(/<1d>/,@nmblookup)) {
-      $master = '+';                   # indicate local master browser
-      if (grep(/<1b>/,@nmblookup)) {   # how about domain master browser?
-        $master = '*';                 # indicate domain master browser
-      }
-    } else {
-      $master = ' ';                   # not a browse master
-    }
-
-# line up info in 3 columns
-
-    print "$ip".' 'x(16-length($ip))."$name".' 'x(14-length($name))."$master"."$_\n";
-
-  } else {                             # no netbios name found
-# try getting the host name
-    ($name, $aliases, $type, $length, @addresses) = 
-      gethostbyaddr(pack('C4',split('\.',$ip)),2);
-    if (! $name) {                     # could not get name
-      $name = "unknown nis name";
-    }
-    if ($DEBUG) {                      # if -d flag print results of nmblookup
-      print "===============================================================\n";
-      print @nmblookup;
-    }
-    print "$ip".' 'x(16-length($ip))."$name\n";
-  }
 } 
 
diff --git a/source3/script/gap.awk b/source3/script/gap.awk
new file mode 100644 (file)
index 0000000..11680d1
--- /dev/null
@@ -0,0 +1,39 @@
+BEGIN { hv["0"] =  0; hv["1"] =  1; hv["2"] =  2; hv["3"] =  3;
+       hv["4"] =  4; hv["5"] =  5; hv["6"] =  6; hv["7"] =  7;
+       hv["8"] =  8; hv["9"] =  9; hv["A"] = 10; hv["B"] = 11;
+       hv["C"] = 12; hv["D"] = 13; hv["E"] = 14; hv["F"] = 15;
+       hv["a"] = 10; hv["b"] = 11; hv["c"] = 12; hv["d"] = 13;
+       hv["e"] = 14; hv["f"] = 15;
+
+       first = 0; last = 0; idx = 0;
+}
+
+function tonum(str)
+{
+  num=0;
+  cnt=1;
+  while (cnt <= length(str)) {
+    num *= 16;
+    num += hv[substr(str,cnt,1)];
+    ++cnt;
+  }
+  return num;
+}
+
+{
+  u = tonum($1);
+  if (u - last > 6)
+    {
+      if (last)
+       {
+         printf ("  { 0x%04x, 0x%04x, %5d },\n",
+                 first, last, idx);
+         idx -= u - last - 1;
+       }
+      first = u;
+    }
+  last = u;
+}
+
+END { printf ("  { 0x%04x, 0x%04x, %5d },\n",
+             first, last, idx); }
diff --git a/source3/script/gaptab.awk b/source3/script/gaptab.awk
new file mode 100644 (file)
index 0000000..f9d1526
--- /dev/null
@@ -0,0 +1,48 @@
+BEGIN { hv["0"] =  0; hv["1"] =  1; hv["2"] =  2; hv["3"] =  3;
+       hv["4"] =  4; hv["5"] =  5; hv["6"] =  6; hv["7"] =  7;
+       hv["8"] =  8; hv["9"] =  9; hv["A"] = 10; hv["B"] = 11;
+       hv["C"] = 12; hv["D"] = 13; hv["E"] = 14; hv["F"] = 15;
+       hv["a"] = 10; hv["b"] = 11; hv["c"] = 12; hv["d"] = 13;
+       hv["e"] = 14; hv["f"] = 15;
+
+       first = 0; last = 0; idx = 0; f = 0;
+}
+
+function tonum(str)
+{
+  num=0;
+  cnt=1;
+  while (cnt <= length(str)) {
+    num *= 16;
+    num += hv[substr(str,cnt,1)];
+    ++cnt;
+  }
+  return num;
+}
+
+function fmt(val)
+{
+  if (f++ % 8 == 0)
+    { printf ("\n  '\\x%02x',", val); }
+  else
+    { printf (" '\\x%02x',", val); }
+}
+
+{
+  u = tonum($1); c = tonum($2);
+
+  if (u - last > 6)
+    {
+      if (last) { idx += last - first + 1; }
+      first = u;
+    }
+  else
+    {
+      for (m = last+1; m < u; m++) { fmt(0); }
+    }
+
+  fmt(c);
+  last = u;
+}
+
+END { print "" }
diff --git a/source3/script/gen-8bit-gap.awk b/source3/script/gen-8bit-gap.awk
new file mode 100644 (file)
index 0000000..59a1a23
--- /dev/null
@@ -0,0 +1,18 @@
+BEGIN {
+       for (i=0; i<256; i++) {
+               tbl[sprintf("%02x",i)] = "0x0000";
+       }
+}
+
+/^<U([[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]])>[[:space:]]*.x([[:xdigit:]][[:xdigit:]])[:space:]*.*$/ {
+       tbl[substr($2,3,2)]=sprintf("0x%s",substr($1,3,4));
+}
+
+END {
+       for(i=0; i<32; i++) {
+               for(j=0; j<8; j++) {
+                       printf(" %s,", tbl[sprintf("%02x",i*8+j)]);
+               }
+               printf "\n"
+       }
+}
\ No newline at end of file
diff --git a/source3/script/gen-8bit-gap.sh.in b/source3/script/gen-8bit-gap.sh.in
new file mode 100755 (executable)
index 0000000..bcf64a4
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+if test $# -ne 2 ; then
+       echo "Usage: $0 <charmap file> <CHARSET NAME>"
+       exit 1
+fi
+
+CHARMAP=$1
+CHARSETNAME=$2
+
+echo "/* "
+echo " * Conversion table for $CHARSETNAME charset "
+echo " * "
+echo " * Conversion tables are generated using $CHARMAP table "
+echo " * and source/script/gen-8bit-gap.sh script "
+echo " * "
+echo " * This program is free software; you can redistribute it and/or modify "
+echo " * it under the terms of the GNU General Public License as published by "
+echo " * the Free Software Foundation; either version 2 of the License, or "
+echo " * (at your option) any later version. "
+echo " *  "
+echo " * This program is distributed in the hope that it will be useful,"
+echo " * but WITHOUT ANY WARRANTY; without even the implied warranty of "
+echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
+echo " * GNU General Public License for more details. "
+echo " *  "
+echo " * You should have received a copy of the GNU General Public License "
+echo " * along with this program; if not, write to the Free Software "
+echo " * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. "
+echo " */"
+
+echo '#include "includes.h"'
+echo
+echo "static const uint16 to_ucs2[256] = {"
+cat "$CHARMAP" | @AWK@ -f @srcdir@/script/gen-8bit-gap.awk
+echo "};"
+echo
+echo "static const struct charset_gap_table from_idx[] = {"
+sed -ne 's/^<U\(....\).*/\1/p' \
+    "$CHARMAP" | sort -u | @AWK@ -f @srcdir@/script/gap.awk
+echo "  { 0xffff, 0xffff, 0 }"
+echo "};"
+echo
+echo "static const unsigned char from_ucs2[] = {"
+sed -ne 's/^<U\(....\)>[[:space:]]*.x\(..\).*/\1 \2/p' \
+    "$CHARMAP" | sort -u | @AWK@ -f @srcdir@/script/gaptab.awk
+echo "};"
+echo 
+echo "SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP($CHARSETNAME)"
+echo
index ec5691992dd1e8614fcda50b7fdddf6f9f952a0c..c80da763688fdad5e705ed2b019dab3eea5f8752 100755 (executable)
@@ -24,13 +24,4 @@ for p in $*; do
  chmod $INSTALLPERMS $LIBDIR/$p2
 done
 
-
-cat << EOF
-======================================================================
-The modules are installed.  You may uninstall the modules using the 
-command "make uninstallmodules" or "make uninstall" to uninstall
-binaries, man pages, shell scripts and modules.
-======================================================================
-EOF
-
 exit 0
index d1f8ea191d93603cce7ba88594d4f76e2b9bda18..bd2f8da2348f941d70a509a1fa18b3c4015a06d5 100755 (executable)
@@ -71,13 +71,13 @@ done
 
 done
 
-# Install Using Samba book
+# Install Using Samba book (but only if it is there)
 
-if [ "x$BOOKDIR" != "x" ]; then
+if [ "x$BOOKDIR" != "x" -a -f $SRCDIR../docs/htmldocs/using_samba/toc.html ]; then
 
     # Create directories
 
-    for d in $BOOKDIR $BOOKDIR/figs $BOOKDIR/gifs; do
+    for d in $BOOKDIR $BOOKDIR/figs ; do
         if [ ! -d $d ]; then
             mkdir $d
             if [ ! -d $d ]; then
@@ -96,19 +96,17 @@ if [ "x$BOOKDIR" != "x" ]; then
         chmod 0644 $FNAME
     done
 
-    # Figures
-
-    for f in $SRCDIR../docs/htmldocs/using_samba/figs/*.gif; do
-        FNAME=$BOOKDIR/figs/`basename $f`
+    for f in $SRCDIR../docs/htmldocs/using_samba/*.gif; do
+        FNAME=$BOOKDIR/`basename $f`
         echo $FNAME
         cp $f $FNAME || echo Cannot install $FNAME. Does $USER have privileges?
         chmod 0644 $FNAME
     done
 
-    # Gifs
+    # Figures
 
-    for f in $SRCDIR../docs/htmldocs/using_samba/gifs/*.gif; do
-        FNAME=$BOOKDIR/gifs/`basename $f`
+    for f in $SRCDIR../docs/htmldocs/using_samba/figs/*.gif; do
+        FNAME=$BOOKDIR/figs/`basename $f`
         echo $FNAME
         cp $f $FNAME || echo Cannot install $FNAME. Does $USER have privileges?
         chmod 0644 $FNAME
diff --git a/source3/script/linkmodules.sh b/source3/script/linkmodules.sh
new file mode 100755 (executable)
index 0000000..16a04cc
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+cd "$1"
+test -f "$2" || exit 0
+
+for I in $3 $4 $5 $6 $7 $8
+do 
+       echo "Linking $I to $2"
+       ln -s $2 $I
+done
+
+exit 0
index 6a45a70cc30307e51a317a72adba166c44e8a13b..b6e911699eb3547fe7431289d7561880093dac65 100644 (file)
@@ -41,20 +41,6 @@ END {
   }
 }
 
-# special handling for code merge of TNG to head
-/^#define OLD_NTDOMAIN 1/ {
-  printf "#if OLD_NTDOMAIN\n"
-}
-/^#undef OLD_NTDOMAIN/ {
-  printf "#endif\n"
-}
-/^#define NEW_NTDOMAIN 1/ {
-  printf "#if NEW_NTDOMAIN\n"
-}
-/^#undef NEW_NTDOMAIN/ {
-  printf "#endif\n"
-}
-
 # we handle the loadparm.c fns separately
 
 /^FN_LOCAL_BOOL/ {
index 2bf96c9b41de714e761b13851a6e15aa09f03263..62041c7e331b2e51a478ac47bba2e90569ecbf53 100755 (executable)
@@ -25,7 +25,7 @@ header="$1"
 shift
 headertmp="$header.$$.tmp~"
 
-proto_src="`echo $@ | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort | uniq | egrep -v 'ubiqx/|wrapped'`"
+proto_src="`echo $@ | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort | uniq | egrep -v 'ubiqx/|wrapped|modules/getdate'`"
 
 echo creating $header
 
diff --git a/source3/script/mkversion.sh b/source3/script/mkversion.sh
new file mode 100755 (executable)
index 0000000..ca39297
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+
+VERSION_FILE=$1
+OUTPUT_FILE=$2
+
+if test -z "$VERSION_FILE";then
+       VERSION_FILE="VERSION"
+fi
+
+if test -z "$OUTPUT_FILE";then
+       OUTPUT_FILE="include/version.h"
+fi
+
+SOURCE_DIR=$3
+
+SAMBA_VERSION_MAJOR=`sed -n 's/^SAMBA_VERSION_MAJOR=//p' $SOURCE_DIR$VERSION_FILE`
+SAMBA_VERSION_MINOR=`sed -n 's/^SAMBA_VERSION_MINOR=//p' $SOURCE_DIR$VERSION_FILE`
+SAMBA_VERSION_RELEASE=`sed -n 's/^SAMBA_VERSION_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_REVISION=`sed -n 's/^SAMBA_VERSION_REVISION=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_PRE_RELEASE=`sed -n 's/^SAMBA_VERSION_PRE_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_RC_RELEASE=`sed -n 's/^SAMBA_VERSION_RC_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_BETA_RELEASE=`sed -n 's/^SAMBA_VERSION_BETA_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_ALPHA_RELEASE=`sed -n 's/^SAMBA_VERSION_ALPHA_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_TEST_RELEASE=`sed -n 's/^SAMBA_VERSION_TEST_RELEASE=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_IS_CVS_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_CVS_SNAPSHOT=//p' $SOURCE_DIR$VERSION_FILE`
+
+SAMBA_VERSION_VENDOR_SUFFIX=`sed -n 's/^SAMBA_VERSION_VENDOR_SUFFIX=//p' $SOURCE_DIR$VERSION_FILE`
+
+echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE
+
+echo "#define SAMBA_VERSION_MAJOR ${SAMBA_VERSION_MAJOR}" >> $OUTPUT_FILE
+echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE
+echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE
+
+
+SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}"
+
+
+if test -n "${SAMBA_VERSION_REVISION}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}"
+    echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE
+elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}"
+    echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE
+elif test -n "${SAMBA_VERSION_RC_RELEASE}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}rc${SAMBA_VERSION_RC_RELEASE}"
+    echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE
+elif test -n "${SAMBA_VERSION_BETA_RELEASE}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}beta${SAMBA_VERSION_BETA_RELEASE}"
+    echo "#define SAMBA_VERSION_BETA_RELEASE ${SAMBA_VERSION_BETA_RELEASE}" >> $OUTPUT_FILE
+elif test -n "${SAMBA_VERSION_ALPHA_RELEASE}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}alpha${SAMBA_VERSION_ALPHA_RELEASE}"
+    echo "#define SAMBA_VERSION_ALPHA_RELEASE ${SAMBA_VERSION_ALPHA_RELEASE}" >> $OUTPUT_FILE
+elif test -n "${SAMBA_VERSION_TEST_RELEASE}";then
+    SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}test${SAMBA_VERSION_TEST_RELEASE}"
+    echo "#define SAMBA_VERSION_TEST_RELEASE ${SAMBA_VERSION_TEST_RELEASE}" >> $OUTPUT_FILE
+fi
+
+
+if test x"${SAMBA_VERSION_IS_CVS_SNAPSHOT}" = x"yes";then
+    SAMBA_VERSION_STRING="CVS ${SAMBA_VERSION_STRING}"
+    echo "#define SAMBA_VERSION_IS_CVS_SNAPSHOT 1" >> $OUTPUT_FILE
+fi
+
+if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
+    echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE
+fi
+
+echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE
+
+echo "#define SAMBA_VERSION_STRING samba_version_string()" >> $OUTPUT_FILE
+
+echo "$0: 'include/version.h' created for Samba(\"${SAMBA_VERSION_STRING}\")"
+
+if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then
+    echo "$0: with VENDOR_SUFFIX = ${SAMBA_VERSION_VENDOR_SUFFIX}"
+fi
+
+exit 0
index 9837413aeb5ac0613d07953f4db2afc630483c1a..35f6dbab141168dbef25671e70f492800a43edcd 100755 (executable)
@@ -2,13 +2,19 @@
 #
 # smbadduser - Written by Mike Zakharoff
 #
+
+prefix=/usr/local/samba
+exec_prefix=${prefix}
+LIBDIR=${exec_prefix}/lib
+PRIVATEDIR=${prefix}/private
+CONFIGDIR=${LIBDIR}
+
 unalias *
 set path = ($path /usr/local/samba/bin)
 
-set smbpasswd = /usr/local/samba/private/smbpasswd
-#set smbpasswd = /etc/samba/smbpasswd
-set user_map  = /usr/local/samba/lib/users.map
-#set user_map  = /etc/samba/smbusers
+set smbpasswd = $PRIVATEDIR/smbpasswd
+set user_map  = $CONFIGDIR/users.map
+
 #
 # Set to site specific passwd command
 #
diff --git a/source3/smbadduser.in b/source3/smbadduser.in
new file mode 100644 (file)
index 0000000..05da7de
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/csh
+#
+# smbadduser - Written by Mike Zakharoff
+#
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+LIBDIR=@libdir@
+PRIVATEDIR=@privatedir@
+CONFIGDIR=@configdir@
+
+unalias *
+set path = ($path /usr/local/samba/bin)
+
+set smbpasswd = $PRIVATEDIR/smbpasswd
+set user_map  = $CONFIGDIR/users.map
+
+#
+# Set to site specific passwd command
+#
+set passwd    = "cat /etc/passwd"
+#set passwd    = "niscat passwd.org_dir"
+#set passwd    = "ypcat passwd"
+
+set line = "----------------------------------------------------------"
+if ($#argv == 0) then
+       echo $line
+       echo "Written: Mike Zakharoff email: michael.j.zakharoff@boeing.com"
+       echo ""
+       echo "   1) Updates $smbpasswd"
+       echo "   2) Updates $user_map"
+       echo "   3) Executes smbpasswd for each new user"
+       echo ""
+       echo "smbadduser unixid:ntid unixid:ntid ..."
+       echo ""
+       echo "Example: smbadduser zak:zakharoffm johns:smithj"
+       echo $line
+       exit 1
+endif
+
+touch $smbpasswd $user_map
+set new  = ()
+foreach one ($argv)
+       echo $one | grep ':' >& /dev/null
+       if ($status != 0) then
+               echo "ERROR: Must use unixid:ntid like -> zak:zakharoffm"
+               continue
+       endif
+       set unix = `echo $one | awk -F: '{print $1}'`
+       set ntid = `echo $one | awk -F: '{print $2}'`
+
+       set usr = `eval $passwd | awk -F: '$1==USR {print $1}' USR=$unix`
+       if ($#usr != 1) then
+               echo "ERROR: $unix Not in passwd database SKIPPING..."
+               continue
+       endif
+        set tmp = `cat $smbpasswd | awk -F: '$1==USR {print $1}' USR=$unix`
+       if ($#tmp != 0) then
+               echo "ERROR: $unix is already in $smbpasswd SKIPPING..."
+               continue
+       endif
+
+       echo "Adding: $unix to $smbpasswd"
+       /usr/bin/smbpasswd -a -n $unix
+       if ($unix != $ntid) then
+               echo "Adding: {$unix = $ntid} to $user_map"
+               echo "$unix = $ntid" >> $user_map
+       endif
+       set new = ($new $unix)
+end
+
+#
+# Enter password for new users
+#
+foreach one ($new)
+       echo $line
+       echo "ENTER password for $one"
+       smbpasswd $one
+end
index fed3a51b8859f0eccfaa679e4cd751ab557db820..8fa2a6494e3cd2ce8022be02f77c13822ac10e21 100644 (file)
@@ -148,7 +148,7 @@ for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout,
                blr->fsp->fnum, blr->fsp->fsp_name ));
 
        /* Push the MID of this packet on the signing queue. */
-       srv_defer_sign_response(SVAL(inbuf,smb_mid));
+       srv_defer_sign_response(SVAL(inbuf,smb_mid), True);
 
        return True;
 }
index 2eff77b1f708ca1be6cf6c695a945a84ea667e45..80c9fcb258c36e08abffef6e9074d4a4fb423e6a 100644 (file)
@@ -35,6 +35,9 @@ NTSTATUS change_trust_account_password( const char *domain, const char *remote_m
        fstring dc_name;
        struct cli_state *cli;
 
+       DEBUG(5,("change_trust_account_password: Attempting to change trust account password in domain %s....\n",
+               domain));
+
        if (remote_machine == NULL || !strcmp(remote_machine, "*")) {
                /* Use the PDC *only* for this */
        
@@ -92,6 +95,8 @@ failed:
                DEBUG(0,("%s : change_trust_account_password: Failed to change password for domain %s.\n", 
                        timestring(False), domain));
        }
+       else
+               DEBUG(5,("change_trust_account_password: sucess!\n"));
   
        return nt_status;
 }
index 6bc8626d8105d2c1d797d3b4d84d0881d4e75273..d99570ff7c0125acbdf5b3c26f3018f4300a2b59 100644 (file)
@@ -259,7 +259,7 @@ static int expect(int master, char *issue, char *expected)
                                /* Eat leading/trailing whitespace before match. */
                                pstring str;
                                pstrcpy( str, buffer);
-                               trim_string( str, " ", " ");
+                               trim_char( str, ' ', ' ');
 
                                if ((match = (unix_wild_match(expected, str) == 0)))
                                        timeout = 200;
@@ -333,19 +333,14 @@ static BOOL chat_with_program(char *passwordprogram, struct passwd *pass,
        int wstat;
        BOOL chstat = False;
 
-       if (pass == NULL)
-       {
-               DEBUG(0,
-                     ("chat_with_program: user doesn't exist in the UNIX password database.\n"));
+       if (pass == NULL) {
+               DEBUG(0, ("chat_with_program: user doesn't exist in the UNIX password database.\n"));
                return False;
        }
 
        /* allocate a pseudo-terminal device */
-       if ((master = findpty(&slavedev)) < 0)
-       {
-               DEBUG(3,
-                     ("Cannot Allocate pty for password change: %s\n",
-                      pass->pw_name));
+       if ((master = findpty(&slavedev)) < 0) {
+               DEBUG(3, ("Cannot Allocate pty for password change: %s\n", pass->pw_name));
                return (False);
        }
 
@@ -356,39 +351,29 @@ static BOOL chat_with_program(char *passwordprogram, struct passwd *pass,
 
        CatchChildLeaveStatus();
 
-       if ((pid = sys_fork()) < 0)
-       {
-               DEBUG(3,
-                     ("Cannot fork() child for password change: %s\n",
-                      pass->pw_name));
+       if ((pid = sys_fork()) < 0) {
+               DEBUG(3, ("Cannot fork() child for password change: %s\n", pass->pw_name));
                close(master);
                CatchChild();
                return (False);
        }
 
        /* we now have a pty */
-       if (pid > 0)
-       {                       /* This is the parent process */
-               if ((chstat = talktochild(master, chatsequence)) == False)
-               {
-                       DEBUG(3,
-                             ("Child failed to change password: %s\n",
-                              pass->pw_name));
+       if (pid > 0) {                  /* This is the parent process */
+               if ((chstat = talktochild(master, chatsequence)) == False) {
+                       DEBUG(3, ("Child failed to change password: %s\n", pass->pw_name));
                        kill(pid, SIGKILL);     /* be sure to end this process */
                }
 
-               while ((wpid = sys_waitpid(pid, &wstat, 0)) < 0)
-               {
-                       if (errno == EINTR)
-                       {
+               while ((wpid = sys_waitpid(pid, &wstat, 0)) < 0) {
+                       if (errno == EINTR) {
                                errno = 0;
                                continue;
                        }
                        break;
                }
 
-               if (wpid < 0)
-               {
+               if (wpid < 0) {
                        DEBUG(3, ("The process is no longer waiting!\n\n"));
                        close(master);
                        CatchChild();
@@ -402,29 +387,21 @@ static BOOL chat_with_program(char *passwordprogram, struct passwd *pass,
 
                close(master);
 
-               if (pid != wpid)
-               {
-                       DEBUG(3,
-                             ("We were waiting for the wrong process ID\n"));
+               if (pid != wpid) {
+                       DEBUG(3, ("We were waiting for the wrong process ID\n"));
                        return (False);
                }
-               if (WIFEXITED(wstat) == 0)
-               {
-                       DEBUG(3,
-                             ("The process exited while we were waiting\n"));
+               if (WIFEXITED(wstat) == 0) {
+                       DEBUG(3, ("The process exited while we were waiting\n"));
                        return (False);
                }
-               if (WEXITSTATUS(wstat) != 0)
-               {
-                       DEBUG(3,
-                             ("The status of the process exiting was %d\n",
+               if (WEXITSTATUS(wstat) != 0) {
+                       DEBUG(3, ("The status of the process exiting was %d\n",
                               wstat));
                        return (False);
                }
 
-       }
-       else
-       {
+       } else {
                /* CHILD */
 
                /*
@@ -438,12 +415,9 @@ static BOOL chat_with_program(char *passwordprogram, struct passwd *pass,
                if (as_root)
                        become_root();
 
-               DEBUG(3,
-                     ("Dochild for user %s (uid=%d,gid=%d)\n", pass->pw_name,
-                      (int)getuid(), (int)getgid()));
-               chstat =
-                       dochild(master, slavedev, pass, passwordprogram,
-                               as_root);
+               DEBUG(3, ("Dochild for user %s (uid=%d,gid=%d) (as_root = %s)\n", pass->pw_name,
+                      (int)getuid(), (int)getgid(), BOOLSTR(as_root) ));
+               chstat = dochild(master, slavedev, pass, passwordprogram, as_root);
 
                if (as_root)
                        unbecome_root();
@@ -452,20 +426,16 @@ static BOOL chat_with_program(char *passwordprogram, struct passwd *pass,
                 * The child should never return from dochild() ....
                 */
 
-               DEBUG(0,
-                     ("chat_with_program: Error: dochild() returned %d\n",
-                      chstat));
+               DEBUG(0, ("chat_with_program: Error: dochild() returned %d\n", chstat));
                exit(1);
        }
 
        if (chstat)
-               DEBUG(3,
-                     ("Password change %ssuccessful for user %s\n",
+               DEBUG(3, ("Password change %ssuccessful for user %s\n",
                       (chstat ? "" : "un"), pass->pw_name));
        return (chstat);
 }
 
-
 BOOL chgpasswd(const char *name, const char *oldpass, const char *newpass, BOOL as_root)
 {
        pstring passwordprogram;
@@ -489,7 +459,7 @@ BOOL chgpasswd(const char *name, const char *oldpass, const char *newpass, BOOL
                oldpass = "";
        }
 
-       DEBUG(3, ("Password change for user: %s\n", name));
+       DEBUG(3, ("Password change (as_root=%s) for user: %s\n", BOOLSTR(as_root), name));
 
 #if DEBUG_PASSWORD
        DEBUG(100, ("Passwords: old=%s new=%s\n", oldpass, newpass));
@@ -519,8 +489,7 @@ BOOL chgpasswd(const char *name, const char *oldpass, const char *newpass, BOOL
        len = strlen(oldpass);
        for (i = 0; i < len; i++) {
                if (iscntrl((int)oldpass[i])) {
-                       DEBUG(0,
-                             ("chat_with_program: oldpass contains control characters (disallowed).\n"));
+                       DEBUG(0, ("chat_with_program: oldpass contains control characters (disallowed).\n"));
                        return False;
                }
        }
@@ -528,8 +497,7 @@ BOOL chgpasswd(const char *name, const char *oldpass, const char *newpass, BOOL
        len = strlen(newpass);
        for (i = 0; i < len; i++) {
                if (iscntrl((int)newpass[i])) {
-                       DEBUG(0,
-                             ("chat_with_program: newpass contains control characters (disallowed).\n"));
+                       DEBUG(0, ("chat_with_program: newpass contains control characters (disallowed).\n"));
                        return False;
                }
        }
@@ -556,11 +524,8 @@ BOOL chgpasswd(const char *name, const char *oldpass, const char *newpass, BOOL
 
        /* A non-PAM password change just doen't make sense without a valid local user */
 
-       if (pass == NULL)
-       {
-               DEBUG(0,
-                     ("chgpasswd: user %s doesn't exist in the UNIX password database.\n",
-                      name));
+       if (pass == NULL) {
+               DEBUG(0, ("chgpasswd: user %s doesn't exist in the UNIX password database.\n", name));
                return False;
        }
 
@@ -746,7 +711,6 @@ NTSTATUS pass_oem_change(char *user,
                         uchar * ntdata, uchar * nthash)
 {
        fstring new_passwd;
-       const char *unix_user;
        SAM_ACCOUNT *sampass = NULL;
        NTSTATUS nt_status = check_oem_password(user, lmdata, lmhash, ntdata, nthash,
                                     &sampass, new_passwd, sizeof(new_passwd));
@@ -754,20 +718,9 @@ NTSTATUS pass_oem_change(char *user,
        if (!NT_STATUS_IS_OK(nt_status))
                return nt_status;
 
-       /* 
-        * At this point we have the new case-sensitive plaintext
-        * password in the fstring new_passwd. If we wanted to synchronise
-        * with UNIX passwords we would call a UNIX password changing 
-        * function here. However it would have to be done as root
-        * as the plaintext of the old users password is not 
-        * available. JRA.
-        */
-
-       unix_user = pdb_get_username(sampass);
-
        /* We've already checked the old password here.... */
        become_root();
-       nt_status = change_oem_password(sampass, NULL, new_passwd);
+       nt_status = change_oem_password(sampass, NULL, new_passwd, True);
        unbecome_root();
 
        memset(new_passwd, 0, sizeof(new_passwd));
@@ -949,7 +902,7 @@ static NTSTATUS check_oem_password(const char *user,
  is correct before calling. JRA.
 ************************************************************/
 
-NTSTATUS change_oem_password(SAM_ACCOUNT *hnd, char *old_passwd, char *new_passwd)
+NTSTATUS change_oem_password(SAM_ACCOUNT *hnd, char *old_passwd, char *new_passwd, BOOL as_root)
 {
        BOOL ret;
        uint32 min_len;
@@ -993,7 +946,7 @@ NTSTATUS change_oem_password(SAM_ACCOUNT *hnd, char *old_passwd, char *new_passw
         */
        
        if(lp_unix_password_sync() &&
-               !chgpasswd(pdb_get_username(hnd), old_passwd, new_passwd, False)) {
+               !chgpasswd(pdb_get_username(hnd), old_passwd, new_passwd, as_root)) {
                return NT_STATUS_ACCESS_DENIED;
        }
 
index 6be5f6af7d001b2200864bf32cfe6474dd5074aa..6cf701484636359a6ac7ff16985d6bb4537c3a62 100644 (file)
@@ -87,8 +87,11 @@ ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
         * Serve from write cache if we can.
         */
 
-       if(read_from_write_cache(fsp, data, pos, n))
+       if(read_from_write_cache(fsp, data, pos, n)) {
+               fsp->pos = pos + n;
+               fsp->position_information = fsp->pos;
                return n;
+       }
 
        flush_write_cache(fsp, READ_FLUSH);
 
@@ -123,6 +126,9 @@ tryagain:
        DEBUG(10,("read_file (%s): pos = %.0f, size = %lu, returned %lu\n",
                fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
 
+       fsp->pos += ret;
+       fsp->position_information = fsp->pos;
+
        return(ret);
 }
 
@@ -145,6 +151,16 @@ static ssize_t real_write_file(files_struct *fsp,char *data,SMB_OFF_T pos, size_
        DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
                fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
 
+       if (ret != -1) {
+               fsp->pos += ret;
+
+/* Yes - this is correct - writes don't update this. JRA. */
+/* Found by Samba4 tests. */
+#if 0
+               fsp->position_information = fsp->pos;
+#endif
+       }
+
        return ret;
 }
 
@@ -244,7 +260,7 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
        if(!wcp) {
                DO_PROFILE_INC(writecache_direct_writes);
                total_written = real_write_file(fsp, data, pos, n);
-               if ((total_written != -1) && (pos + total_written > (SMB_OFF_T)fsp->size))
+               if ((total_written != -1) && (pos + total_written > (SMB_OFF_T)fsp->size)) 
                        fsp->size = (SMB_BIG_UINT)(pos + total_written);
                return total_written;
        }
@@ -252,6 +268,8 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
        DEBUG(9,("write_file (%s)(fd=%d pos=%.0f size=%u) wcp->offset=%.0f wcp->data_size=%u\n",
                fsp->fsp_name, fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size));
 
+       fsp->pos = pos + n;
+
        /* 
         * If we have active cache and it isn't contiguous then we flush.
         * NOTE: There is a small problem with running out of disk ....
index ad107f9c3e13b814c7cde4f38819819a4cd6d346..643e315c0694f2890c8cbe86dfc354ce494f027d 100644 (file)
@@ -125,7 +125,7 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen
         * also trim trailing /'s.
         */
 
-       trim_string(name,"/","/");
+       trim_char(name,'/','/');
 
        /*
         * If we trimmed down to a single '\0' character
@@ -164,7 +164,7 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen
                return(True);
 
        start = name;
-       while (strncmp(start,"./",2) == 0)
+       while (start[0] == '.' && start[1] == '/')
                start += 2;
 
        pstrcpy(orig_path, name);
index f0fd6b7a736e781cee587e6b3d2e1f4f8f1dcd72..1fe6f250e526b3803429fcc00aede6b07f6feaad 100644 (file)
@@ -142,6 +142,22 @@ void file_close_conn(connection_struct *conn)
        }
 }
 
+/****************************************************************************
+ Close all open files for a pid.
+****************************************************************************/
+
+void file_close_pid(uint16 smbpid)
+{
+       files_struct *fsp, *next;
+       
+       for (fsp=Files;fsp;fsp=next) {
+               next = fsp->next;
+               if (fsp->file_pid == smbpid) {
+                       close_file(fsp,False); 
+               }
+       }
+}
+
 /****************************************************************************
  Initialise file structures.
 ****************************************************************************/
@@ -200,6 +216,18 @@ void file_close_user(int vuid)
        }
 }
 
+void file_dump_open_table(void)
+{
+       int count=0;
+       files_struct *fsp;
+
+       for (fsp=Files;fsp;fsp=fsp->next,count++) {
+               DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, fileid = %lu, dev = %x, inode = %.0f\n",
+                       count, fsp->fnum, fsp->fsp_name, fsp->fd, (unsigned long)fsp->file_id,
+                       (unsigned int)fsp->dev, (double)fsp->inode ));
+       }
+}
+
 /****************************************************************************
  Find a fsp given a file descriptor.
 ****************************************************************************/
index a5f7a7b2ea9ff8f91a501848a8e6067df880e416..b27ccc23ef7b03481ac2a0c129c98e3a2d7db080 100644 (file)
@@ -1706,13 +1706,24 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para
        int uLevel = SVAL(p,0);
        const char *level_string;
        int count=0;
+       SAM_ACCOUNT *sampw = NULL;
+       BOOL ret = False;
+        DOM_GID *gids = NULL;
+        int num_groups = 0;
+       int i;
+       fstring grp_domain;
+       fstring grp_name;
+       enum SID_NAME_USE grp_type;
+       DOM_SID sid, dom_sid;
 
        *rparam_len = 8;
        *rparam = REALLOC(*rparam,*rparam_len);
   
        /* check it's a supported varient */
-       if (!strcmp(str1,"zWrLeh"))
+       
+       if ( strcmp(str1,"zWrLeh") != 0 )
                return False;
+               
        switch( uLevel ) {
                case 0:
                        level_string = "B21";
@@ -1732,18 +1743,59 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para
 
        p = *rdata;
 
-       /* XXXX we need a real SAM database some day */
-       pstrcpy(p,"Users"); p += 21; count++;
-       pstrcpy(p,"Domain Users"); p += 21; count++;
-       pstrcpy(p,"Guests"); p += 21; count++;
-       pstrcpy(p,"Domain Guests"); p += 21; count++;
+       /* Lookup the user information; This should only be one of 
+          our accounts (not remote domains) */
+          
+       pdb_init_sam( &sampw );
+       
+       become_root();                                  /* ROOT BLOCK */
+
+       if ( !pdb_getsampwnam(sampw, UserName) )
+               goto out;
+
+       /* this next set of code is horribly inefficient, but since 
+          it is rarely called, I'm going to leave it like this since 
+          it easier to follow      --jerry                          */
+          
+       /* get the list of group SIDs */
+       
+       if ( !get_domain_user_groups(conn->mem_ctx, &num_groups, &gids, sampw) ) {
+               DEBUG(1,("api_NetUserGetGroups: get_domain_user_groups() failed!\n"));
+               goto out;
+        }
 
+       /* convert to names (we don't support universal groups so the domain
+          can only be ours) */
+       
+       sid_copy( &dom_sid, get_global_sam_sid() );
+       for (i=0; i<num_groups; i++) {
+       
+               /* make the DOM_GID into a DOM_SID and then lookup 
+                  the name */
+               
+               sid_copy( &sid, &dom_sid );
+               sid_append_rid( &sid, gids[i].g_rid );
+               
+               if ( lookup_sid(&sid, grp_domain, grp_name, &grp_type) ) {
+                       pstrcpy(p, grp_name); 
+                       p += 21; 
+                       count++;
+               }
+       }
+       
        *rdata_len = PTR_DIFF(p,*rdata);
 
        SSVAL(*rparam,4,count); /* is this right?? */
        SSVAL(*rparam,6,count); /* is this right?? */
 
-       return(True);
+       ret = True;
+
+out:
+       unbecome_root();                                /* END ROOT BLOCK */
+
+       pdb_free_sam( &sampw );
+
+       return ret;
 }
 
 /*******************************************************************
@@ -1932,7 +1984,7 @@ static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param
                if (NT_STATUS_IS_OK(check_plaintext_password(user,password,&server_info))) {
 
                        become_root();
-                       if (NT_STATUS_IS_OK(change_oem_password(server_info->sam_account, pass1, pass2))) {
+                       if (NT_STATUS_IS_OK(change_oem_password(server_info->sam_account, pass1, pass2, False))) {
                                SSVAL(*rparam,0,NERR_Success);
                        }
                        unbecome_root();
@@ -1957,7 +2009,7 @@ static BOOL api_SetUserPassword(connection_struct *conn,uint16 vuid, char *param
 
                if (check_lanman_password(user,(unsigned char *)pass1,(unsigned char *)pass2, &hnd)) {
                        become_root();
-                       if (change_lanman_password(hnd,pass2)) {
+                       if (change_lanman_password(hnd,(uchar *)pass2)) {
                                SSVAL(*rparam,0,NERR_Success);
                        }
                        unbecome_root();
@@ -1980,47 +2032,46 @@ static BOOL api_SamOEMChangePassword(connection_struct *conn,uint16 vuid, char *
                                char **rdata,char **rparam,
                                int *rdata_len,int *rparam_len)
 {
-  fstring user;
-  char *p = param + 2;
-  *rparam_len = 2;
-  *rparam = REALLOC(*rparam,*rparam_len);
+       fstring user;
+       char *p = param + 2;
+       *rparam_len = 2;
+       *rparam = REALLOC(*rparam,*rparam_len);
 
-  *rdata_len = 0;
+       *rdata_len = 0;
 
-  SSVAL(*rparam,0,NERR_badpass);
+       SSVAL(*rparam,0,NERR_badpass);
 
-  /*
-   * Check the parameter definition is correct.
-   */
-  if(!strequal(param + 2, "zsT")) {
-    DEBUG(0,("api_SamOEMChangePassword: Invalid parameter string %s\n", param + 2));
-    return False;
-  }
-  p = skip_string(p, 1);
+       /*
+        * Check the parameter definition is correct.
+        */
 
-  if(!strequal(p, "B516B16")) {
-    DEBUG(0,("api_SamOEMChangePassword: Invalid data parameter string %s\n", p));
-    return False;
-  }
-  p = skip_string(p,1);
+       if(!strequal(param + 2, "zsT")) {
+               DEBUG(0,("api_SamOEMChangePassword: Invalid parameter string %s\n", param + 2));
+               return False;
+       }
+       p = skip_string(p, 1);
 
-  p += pull_ascii_fstring(user,p);
+       if(!strequal(p, "B516B16")) {
+               DEBUG(0,("api_SamOEMChangePassword: Invalid data parameter string %s\n", p));
+               return False;
+       }
+       p = skip_string(p,1);
+       p += pull_ascii_fstring(user,p);
 
-  DEBUG(3,("api_SamOEMChangePassword: Change password for <%s>\n",user));
+       DEBUG(3,("api_SamOEMChangePassword: Change password for <%s>\n",user));
 
-  /*
-   * Pass the user through the NT -> unix user mapping
-   * function.
-   */
+       /*
+        * Pass the user through the NT -> unix user mapping
+        * function.
+        */
 
-  (void)map_username(user);
+       (void)map_username(user);
 
-  if (NT_STATUS_IS_OK(pass_oem_change(user, (uchar*) data, (uchar *)&data[516], NULL, NULL)))
-  {
-    SSVAL(*rparam,0,NERR_Success);
-  }
+       if (NT_STATUS_IS_OK(pass_oem_change(user, (uchar*) data, (uchar *)&data[516], NULL, NULL))) {
+               SSVAL(*rparam,0,NERR_Success);
+       }
 
-  return(True);
+       return(True);
 }
 
 /****************************************************************************
index cdce28e1bd858d9cf03cd77f1d02e1ab71f42f48..9cd0438d5134425bc7db64cc0656a0ec5f264c3c 100644 (file)
@@ -201,22 +201,24 @@ static const char *cache_lookup(u32 hash)
    In this algorithm, mangled names use only pure ascii characters (no
    multi-byte) so we can avoid doing a UCS2 conversion 
  */
-static BOOL is_mangled_component(const char *name)
+static BOOL is_mangled_component(const char *name, size_t len)
 {
-       unsigned int len, i;
+       unsigned int i;
 
-       M_DEBUG(10,("is_mangled_component %s ?\n", name));
+       M_DEBUG(10,("is_mangled_component %s (len %u) ?\n", name, (unsigned int)len));
 
        /* check the length */
-       len = strlen(name);
-       if (len > 12 || len < 8) return False;
+       if (len > 12 || len < 8)
+               return False;
 
        /* the best distinguishing characteristic is the ~ */
-       if (name[6] != '~') return False;
+       if (name[6] != '~')
+               return False;
 
        /* check extension */
        if (len > 8) {
-               if (name[8] != '.') return False;
+               if (name[8] != '.')
+                       return False;
                for (i=9; name[i]; i++) {
                        if (! FLAG_CHECK(name[i], FLAG_ASCII)) {
                                return False;
@@ -241,7 +243,7 @@ static BOOL is_mangled_component(const char *name)
                }
        }
 
-       M_DEBUG(10,("is_mangled %s -> yes\n", name));
+       M_DEBUG(10,("is_mangled_component %s (len %u) -> yes\n", name, (unsigned int)len));
 
        return True;
 }
@@ -267,16 +269,13 @@ static BOOL is_mangled(const char *name)
        M_DEBUG(10,("is_mangled %s ?\n", name));
 
        for (s=name; (p=strchr(s, '/')); s=p+1) {
-               char *component = strndup(s, PTR_DIFF(p, s));
-               if (is_mangled_component(component)) {
-                       free(component);
+               if (is_mangled_component(s, PTR_DIFF(p, s))) {
                        return True;
                }
-               free(component);
        }
        
        /* and the last part ... */
-       return is_mangled_component(s);
+       return is_mangled_component(s,strlen(s));
 }
 
 
@@ -305,7 +304,8 @@ static BOOL is_8_3(const char *name, BOOL check_case, BOOL allow_wildcards)
         the result we need in this case. Using strlen_m would not
         only be slower, it would be incorrect */
        len = strlen(name);
-       if (len > 12) return False;
+       if (len > 12)
+               return False;
 
        /* find the '.'. Note that once again we use the non-multibyte
            function */
@@ -449,6 +449,27 @@ static BOOL is_legal_name(const char *name)
        size_t numdots = 0;
 
        while (*name) {
+               if (((unsigned int)name[0]) > 128 && (name[1] != 0)) {
+                       /* Possible start of mb character. */
+                       char mbc[2];
+                       /*
+                        * We know the following will return 2 bytes. What
+                        * we need to know was if errno was set.
+                        * Note that if CH_UNIX is utf8 a string may be 3
+                        * bytes, but this is ok as mb utf8 characters don't
+                        * contain embedded ascii bytes. We are really checking
+                        * for mb UNIX asian characters like Japanese (SJIS) here.
+                        * JRA.
+                        */
+                       errno = 0;
+                       convert_string(CH_UNIX, CH_UCS2, name, 2, mbc, 2);
+                       if (!errno) {
+                               /* Was a good mb string. */
+                               name += 2;
+                               continue;
+                       }
+               }
+
                if (FLAG_CHECK(name[0], FLAG_ILLEGAL)) {
                        return False;
                }
index 233848d2d610d0ad3b181d2e2c9da0210047158d..88f833e468617c2d40bffc0a497ff85edc79585a 100644 (file)
@@ -64,7 +64,7 @@ static void msg_deliver(void)
    * Incoming message is in DOS codepage format. Convert to UNIX.
    */
   
-  if ((len = convert_string_allocate(CH_DOS, CH_UNIX, msgbuf, msgpos, (void **) &msg)) < 0 || !msg) {
+  if ((len = convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **) &msg)) < 0 || !msg) {
     DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
     for (i = 0; i < msgpos;) {
       if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') {
index 9adf827c794d79d43fda49c8ea957d2febfec2d5..ca6f2b783f2567c4c3eb80906eefde3c526c2fe6 100644 (file)
@@ -199,7 +199,7 @@ BOOL change_notify_set(char *inbuf, files_struct *fsp, connection_struct *conn,
        DLIST_ADD(change_notify_list, cnbp);
 
        /* Push the MID of this packet on the signing queue. */
-       srv_defer_sign_response(SVAL(inbuf,smb_mid));
+       srv_defer_sign_response(SVAL(inbuf,smb_mid), True);
 
        return True;
 }
index 3ffa6efa77a693a0f4829d3aa8ad6878c244b750..f8bd3ae15f1b12c3b4011f38accb3544c77b9a36 100644 (file)
@@ -762,9 +762,8 @@ create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attrib
                restore_case_semantics(file_attributes);
 
                if(!fsp) {
-                       set_bad_path_error(errno, bad_path);
                        END_PROFILE(SMBntcreateX);
-                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                }
        } else {
                /*
@@ -838,16 +837,14 @@ create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attrib
                                
                                if(!fsp) {
                                        restore_case_semantics(file_attributes);
-                                       set_bad_path_error(errno, bad_path);
                                        END_PROFILE(SMBntcreateX);
-                                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                                }
                        } else {
 
                                restore_case_semantics(file_attributes);
-                               set_bad_path_error(errno, bad_path);
                                END_PROFILE(SMBntcreateX);
-                               return(UNIXERROR(ERRDOS,ERRnoaccess));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                        }
                } 
        }
@@ -1279,8 +1276,7 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
 
                if(!fsp) {
                        restore_case_semantics(file_attributes);
-                       set_bad_path_error(errno, bad_path);
-                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                }
 
        } else {
@@ -1312,13 +1308,11 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o
                                
                                if(!fsp) {
                                        restore_case_semantics(file_attributes);
-                                       set_bad_path_error(errno, bad_path);
-                                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                                }
                        } else {
                                restore_case_semantics(file_attributes);
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRnoaccess));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
                        }
                } 
   
@@ -1724,7 +1718,11 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                                  char **ppparams, uint32 parameter_count,
                                  char **ppdata, uint32 data_count)
 {
-       unsigned fnum, control;
+       uint32 function;
+       uint16 fidnum;
+       files_struct *fsp;
+       uint8 isFSctl;
+       uint8 compfilter;
        static BOOL logged_message;
        char *pdata = *ppdata;
 
@@ -1733,19 +1731,26 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
        }
 
-       fnum = SVAL(*ppsetup, 4);
-       control = IVAL(*ppsetup, 0);
+       function = IVAL(*ppsetup, 0);
+       fidnum = SVAL(*ppsetup, 4);
+       isFSctl = CVAL(*ppsetup, 6);
+       compfilter = CVAL(*ppsetup, 7);
+
+       DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n", 
+                function, fidnum, isFSctl, compfilter));
 
-       DEBUG(10,("call_nt_transact_ioctl: fnum=%d control=0x%08x\n", 
-                fnum, control));
+       fsp=file_fsp(*ppsetup, 4);
+       /* this check is done in each implemented function case for now
+          because I don't want to break anything... --metze
+       FSP_BELONGS_CONN(fsp,conn);*/
 
-       switch (control) {
+       switch (function) {
        case FSCTL_SET_SPARSE:
                /* pretend this succeeded - tho strictly we should
                   mark the file sparse (if the local fs supports it)
                   so we can know if we need to pre-allocate or not */
 
-               DEBUG(10,("FSCTL_SET_SPARSE: fnum=%d control=0x%08x\n",fnum,control));
+               DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
                send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
                return -1;
        
@@ -1754,7 +1759,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                   but works ok like this --metze
                 */
 
-               DEBUG(10,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
+               DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
                send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
                return -1;
 
@@ -1763,7 +1768,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                 * --metze
                 */
 
-               DEBUG(10,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
+               DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
                send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
                return -1;
 
@@ -1772,10 +1777,125 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                 * --metze
                 */
 
-               DEBUG(10,("FSCTL_SET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum,control));
+               DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
                send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
                return -1;
                        
+       case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
+       {
+               /*
+                * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
+                * and return their volume names.  If max_data_count is 16, then it is just
+                * asking for the number of volumes and length of the combined names.
+                *
+                * pdata is the data allocated by our caller, but that uses
+                * total_data_count (which is 0 in our case) rather than max_data_count.
+                * Allocate the correct amount and return the pointer to let
+                * it be deallocated when we return.
+                */
+               uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
+               SHADOW_COPY_DATA *shadow_data = NULL;
+               TALLOC_CTX *shadow_mem_ctx = NULL;
+               BOOL labels = False;
+               uint32 labels_data_count = 0;
+               uint32 i;
+               char *cur_pdata;
+
+               FSP_BELONGS_CONN(fsp,conn);
+
+               if (max_data_count < 16) {
+                       DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
+                               max_data_count));
+                       return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+               }
+
+               if (max_data_count > 16) {
+                       labels = True;
+               }
+
+               shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
+               if (shadow_mem_ctx == NULL) {
+                       DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
+                       return ERROR_NT(NT_STATUS_NO_MEMORY);
+               }
+
+               shadow_data = (SHADOW_COPY_DATA *)talloc_zero(shadow_mem_ctx,sizeof(SHADOW_COPY_DATA));
+               if (shadow_data == NULL) {
+                       DEBUG(0,("talloc_zero() failed!\n"));
+                       return ERROR_NT(NT_STATUS_NO_MEMORY);
+               }
+               
+               shadow_data->mem_ctx = shadow_mem_ctx;
+               
+               /*
+                * Call the VFS routine to actually do the work.
+                */
+               if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
+                       talloc_destroy(shadow_data->mem_ctx);
+                       if (errno == ENOSYS) {
+                               DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n", 
+                                       conn->connectpath));
+                               return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
+                       } else {
+                               DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n", 
+                                       conn->connectpath));
+                               return ERROR_NT(NT_STATUS_UNSUCCESSFUL);                        
+                       }
+               }
+
+               labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
+
+               if (!labels) {
+                       data_count = 16;
+               } else {
+                       data_count = 12+labels_data_count+4;
+               }
+
+               if (max_data_count<data_count) {
+                       DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
+                               max_data_count,data_count));
+                       talloc_destroy(shadow_data->mem_ctx);
+                       return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
+               }
+
+               pdata = nttrans_realloc(ppdata, data_count);
+               if (pdata == NULL) {
+                       talloc_destroy(shadow_data->mem_ctx);
+                       return ERROR_NT(NT_STATUS_NO_MEMORY);
+               }               
+
+               cur_pdata = pdata;
+
+               /* num_volumes 4 bytes */
+               SIVAL(pdata,0,shadow_data->num_volumes);
+
+               if (labels) {
+                       /* num_labels 4 bytes */
+                       SIVAL(pdata,4,shadow_data->num_volumes);
+               }
+
+               /* needed_data_count 4 bytes */
+               SIVAL(pdata,8,labels_data_count);
+
+               cur_pdata+=12;
+
+               DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
+                       shadow_data->num_volumes,fsp->fsp_name));
+               if (labels && shadow_data->labels) {
+                       for (i=0;i<shadow_data->num_volumes;i++) {
+                               srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
+                               cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
+                               DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
+                       }
+               }
+
+               talloc_destroy(shadow_data->mem_ctx);
+
+               send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
+
+               return -1;
+        }
+        
        case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
        {
                /* pretend this succeeded - 
@@ -1783,24 +1903,24 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                 * we have to send back a list with all files owned by this SID
                 *
                 * but I have to check that --metze
-                */ 
-                  
+                */
                DOM_SID sid;
                uid_t uid;
-               size_t sid_len=SID_MAX_SIZE;
-               
-               DEBUG(10,("FSCTL_FIND_FILES_BY_SID: fnum=%d control=0x%08x\n",fnum,control));
+               size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
                
-               /* this is not the length of the sid :-( so unknown 4 bytes */
-               /*sid_len = IVAL(pdata,0);      
-               DEBUGADD(0,("sid_len: (%u)\n",sid_len));*/
+               DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
+
+               FSP_BELONGS_CONN(fsp,conn);
+
+               /* unknown 4 bytes: this is not the length of the sid :-(  */
+               /*unknown = IVAL(pdata,0);*/
                
                sid_parse(pdata+4,sid_len,&sid);
-               DEBUGADD(10,("SID: %s\n",sid_string_static(&sid)));
+               DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
 
                if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
-                       DEBUG(0,("sid_to_uid: failed, sid[%s]\n",
-                               sid_string_static(&sid)));
+                       DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%u]\n",
+                               sid_string_static(&sid),sid_len));
                        uid = (-1);
                }
                
@@ -1813,6 +1933,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                 * for each file
                 *
                 * but I don't know how to deal with the paged results
+                * (maybe we can hang the result anywhere in the fsp struct)
                 *
                 * we don't send all files at once
                 * and at the next we should *not* start from the beginning, 
@@ -1829,7 +1950,7 @@ static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *ou
                if (!logged_message) {
                        logged_message = True; /* Only print this once... */
                        DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
-                                control));
+                                function));
                }
        }
 
index 5f49640aa496e306986ba57f4bf944e9b47a97b3..71af23aaf928b5b99ff85a6dc6b1faa4b3f6469e 100644 (file)
@@ -23,6 +23,7 @@
 
 extern userdom_struct current_user_info;
 extern uint16 global_oplock_port;
+extern uint16 global_smbpid;
 extern BOOL global_client_failed_oplock_break;
 
 /****************************************************************************
@@ -226,8 +227,8 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
        fsp->inode = psbuf->st_ino;
        fsp->dev = psbuf->st_dev;
        fsp->vuid = current_user.vuid;
+       fsp->file_pid = global_smbpid;
        fsp->size = psbuf->st_size;
-       fsp->pos = -1;
        fsp->can_lock = True;
        fsp->can_read = ((flags & O_WRONLY)==0);
        fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
@@ -626,6 +627,12 @@ static int open_mode_check(connection_struct *conn, const char *fname, SMB_DEV_T
                                DEBUG(5,("open_mode_check: oplock_request = %d, breaking oplock (%x) on file %s, \
 dev = %x, inode = %.0f\n", *p_oplock_request, share_entry->op_type, fname, (unsigned int)dev, (double)inode));
                                
+                               /* Ensure the reply for the open uses the correct sequence number. */
+                               /* This isn't a real deferred packet as it's response will also increment
+                                * the sequence.
+                                */
+                               srv_defer_sign_response(get_current_mid(), False);
+
                                /* Oplock break - unlock to request it. */
                                unlock_share_entry(conn, dev, inode);
                                
@@ -1356,7 +1363,7 @@ files_struct *open_directory(connection_struct *conn, char *fname, SMB_STRUCT_ST
        fsp->dev = psbuf->st_dev;
        fsp->size = psbuf->st_size;
        fsp->vuid = current_user.vuid;
-       fsp->pos = -1;
+       fsp->file_pid = global_smbpid;
        fsp->can_lock = True;
        fsp->can_read = False;
        fsp->can_write = False;
@@ -1419,7 +1426,7 @@ files_struct *open_file_stat(connection_struct *conn, char *fname, SMB_STRUCT_ST
        fsp->dev = (SMB_DEV_T)0;
        fsp->size = psbuf->st_size;
        fsp->vuid = current_user.vuid;
-       fsp->pos = -1;
+       fsp->file_pid = global_smbpid;
        fsp->can_lock = False;
        fsp->can_read = False;
        fsp->can_write = False;
index b988f2ec745768b17bbac604dd9c0df9d31d1ce6..32c24b3d67991ad360e26f0ef3caea8aa0413a1b 100644 (file)
@@ -28,6 +28,9 @@ static user_struct *validated_users;
 static int next_vuid = VUID_OFFSET;
 static int num_validated_vuids;
 
+extern userdom_struct current_user_info;
+
+
 /****************************************************************************
  Check if a uid has been validated, and return an pointer to the user_struct
  if it has. NULL if not. vuid is biased by an offset. This allows us to
@@ -296,7 +299,7 @@ BOOL user_ok(const char *user,int snum, gid_t *groups, size_t n_groups)
 
        if (ret && lp_valid_users(snum)) {
                str_list_copy(&valid, lp_valid_users(snum));
-               if (valid && str_list_substitute(valid, "%S", lp_servicename(snum))) {
+               if ( valid && str_list_sub_basic(valid, current_user_info.smb_name) ) {
                        ret = user_in_list(user, (const char **)valid, groups, n_groups);
                }
        }
index dce1c4bc03b51d35e759e53630521c2f8095a4c3..3c15cd18333711702431815cc7de279adb9c4231 100644 (file)
@@ -47,6 +47,15 @@ SIG_ATOMIC_T got_sig_term = 0;
 BOOL global_machine_password_needs_changing = False;
 extern int max_send;
 
+/****************************************************************************
+ Function to return the current request mid from Inbuffer.
+****************************************************************************/
+
+uint16 get_current_mid(void)
+{
+       return SVAL(InBuffer,smb_mid);
+}
+
 /****************************************************************************
  structure to hold a linked list of queued messages.
  for processing.
@@ -88,7 +97,7 @@ static BOOL push_message(ubi_slList *list_head, char *buf, int msg_len)
        ubi_slAddTail( list_head, msg);
 
        /* Push the MID of this packet on the signing queue. */
-       srv_defer_sign_response(SVAL(buf,smb_mid));
+       srv_defer_sign_response(SVAL(buf,smb_mid), True);
 
        return True;
 }
@@ -710,7 +719,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
                        if(session_tag != UID_FIELD_INVALID)
                                vuser = get_valid_user_struct(session_tag);           
                        if(vuser != NULL)
-                               current_user_info = vuser->user;
+                               set_current_user_info(&vuser->user);
                }
 
                /* does this protocol need to be run as root? */
@@ -1256,8 +1265,10 @@ void smbd_process(void)
        if ((InBuffer == NULL) || (OutBuffer == NULL)) 
                return;
 
+#if defined(DEVELOPER)
        clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
        clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
+#endif
 
        max_recv = MIN(lp_maxxmit(),BUFFER_SIZE);
 
@@ -1286,7 +1297,9 @@ void smbd_process(void)
                        num_smbs = 0; /* Reset smb counter. */
                }
 
+#if defined(DEVELOPER)
                clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
+#endif
 
                while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) {
                        if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time))
index 71312295f4f51b5b02e72b93f51c56db7f982603..6ac4cffddb4eaf3a542e007a33c9bb02585d15f3 100644 (file)
@@ -38,6 +38,21 @@ unsigned int smb_echo_count = 0;
 
 extern BOOL global_encrypted_passwords_negotiated;
 
+/****************************************************************************
+ Ensure we check the path in the same way as W2K.
+****************************************************************************/
+
+static NTSTATUS check_path_syntax(const char *name)
+{
+       while (*name == '\\')
+               name++;
+       if (strequal(name, "."))
+               return NT_STATUS_OBJECT_NAME_INVALID;
+       else if (strequal(name, ".."))
+               return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
+       return NT_STATUS_OK;
+}
+
 /****************************************************************************
  Reply to a special message.
 ****************************************************************************/
@@ -333,7 +348,6 @@ int reply_ioctl(connection_struct *conn,
        uint32 ioctl_code = (device << 16) + function;
        int replysize, outsize;
        char *p;
-       files_struct *fsp = file_fsp(inbuf,smb_vwv0);
        START_PROFILE(SMBioctl);
 
        DEBUG(4, ("Received IOCTL (code 0x%x)\n", ioctl_code));
@@ -356,6 +370,11 @@ int reply_ioctl(connection_struct *conn,
        switch (ioctl_code) {
                case IOCTL_QUERY_JOB_INFO:                  
                {
+                       files_struct *fsp = file_fsp(inbuf,smb_vwv0);
+                       if (!fsp) {
+                               END_PROFILE(SMBioctl);
+                               return(UNIXERROR(ERRDOS,ERRbadfid));
+                       }
                        SSVAL(p,0,fsp->rap_print_jobid);             /* Job number */
                        srvstr_push(outbuf, p+2, global_myname(), 15, STR_TERMINATE|STR_ASCII);
                        srvstr_push(outbuf, p+18, lp_servicename(SNUM(conn)), 13, STR_TERMINATE|STR_ASCII);
@@ -379,10 +398,16 @@ int reply_chkpth(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        BOOL ok = False;
        BOOL bad_path = False;
        SMB_STRUCT_STAT sbuf;
+       NTSTATUS status;
+
        START_PROFILE(SMBchkpth);
 
        srvstr_pull_buf(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), STR_TERMINATE);
 
+       status = check_path_syntax(name);
+       if (!NT_STATUS_IS_OK(status))
+               return ERROR_NT(status);
+
        RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
 
        unix_convert(name,conn,0,&bad_path,&sbuf);
@@ -401,8 +426,21 @@ int reply_chkpth(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
                        one at a time - if a component fails it expects
                        ERRbadpath, not ERRbadfile.
                */
-               if(errno == ENOENT)
-                       return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+               if(errno == ENOENT) {
+                       /*
+                        * Windows returns different error codes if
+                        * the parent directory is valid but not the
+                        * last component - it returns NT_STATUS_OBJECT_NAME_NOT_FOUND
+                        * for that case and NT_STATUS_OBJECT_PATH_NOT_FOUND
+                        * if the path is invalid.
+                        */
+                       if (bad_path) {
+                               return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+                       } else {
+                               return ERROR_NT(NT_STATUS_OBJECT_NAME_NOT_FOUND);
+                       }
+               } else if (errno == ENOTDIR)
+                       return ERROR_NT(NT_STATUS_NOT_A_DIRECTORY);
 
                return(UNIXERROR(ERRDOS,ERRbadpath));
        }
@@ -463,9 +501,8 @@ int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        }
   
        if (!ok) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBgetatr);
-               return(UNIXERROR(ERRDOS,ERRbadfile));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadfile);
        }
  
        outsize = set_message(outbuf,10,0,True);
@@ -510,20 +547,24 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        mode = SVAL(inbuf,smb_vwv0);
        mtime = make_unix_date3(inbuf+smb_vwv1);
   
-       if (VALID_STAT_OF_DIR(sbuf))
-               mode |= aDIR;
-       else
-               mode &= ~aDIR;
+       if (mode != FILE_ATTRIBUTE_NORMAL) {
+               if (VALID_STAT_OF_DIR(sbuf))
+                       mode |= aDIR;
+               else
+                       mode &= ~aDIR;
+
+               if (check_name(fname,conn))
+                       ok =  (file_chmod(conn,fname,mode,NULL) == 0);
+       } else {
+               ok = True;
+       }
 
-       if (check_name(fname,conn))
-               ok =  (file_chmod(conn,fname,mode,NULL) == 0);
        if (ok)
                ok = set_filetime(conn,fname,mtime);
   
        if (!ok) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBsetatr);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnoaccess);
        }
  
        outsize = set_message(outbuf,0,0,True);
@@ -684,9 +725,8 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
                        dptr_num = dptr_create(conn,directory,True,expect_close,SVAL(inbuf,smb_pid));
                        if (dptr_num < 0) {
                                if(dptr_num == -2) {
-                                       set_bad_path_error(errno, bad_path);
                                        END_PROFILE(SMBsearch);
-                                       return (UNIXERROR(ERRDOS,ERRnofids));
+                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnofids);
                                }
                                END_PROFILE(SMBsearch);
                                return ERROR_DOS(ERRDOS,ERRnofids);
@@ -732,21 +772,23 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
 
   SearchEmpty:
 
-       if (numentries == 0 || !ok) {
-               SCVAL(outbuf,smb_rcls,ERRDOS);
-               SSVAL(outbuf,smb_err,ERRnofiles);
-               dptr_close(&dptr_num);
-       }
-
        /* If we were called as SMBffirst with smb_search_id == NULL
                and no entries were found then return error and close dirptr 
                (X/Open spec) */
 
        if(ok && expect_close && numentries == 0 && status_len == 0) {
-               SCVAL(outbuf,smb_rcls,ERRDOS);
-               SSVAL(outbuf,smb_err,ERRnofiles);
+               if (Protocol < PROTOCOL_NT1) {
+                       SCVAL(outbuf,smb_rcls,ERRDOS);
+                       SSVAL(outbuf,smb_err,ERRnofiles);
+               }
                /* Also close the dptr - we know it's gone */
                dptr_close(&dptr_num);
+       } else if (numentries == 0 || !ok) {
+               if (Protocol < PROTOCOL_NT1) {
+                       SCVAL(outbuf,smb_rcls,ERRDOS);
+                       SSVAL(outbuf,smb_err,ERRnofiles);
+               }
+               dptr_close(&dptr_num);
        }
 
        /* If we were called as SMBfunique, then we can close the dirptr now ! */
@@ -851,9 +893,8 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
                        unixmode, oplock_request,&rmode,NULL);
 
        if (!fsp) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBopen);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnoaccess);
        }
 
        size = sbuf.st_size;
@@ -939,9 +980,8 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
                        oplock_request, &rmode,&smb_action);
       
        if (!fsp) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBopenX);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnoaccess);
        }
 
        size = sbuf.st_size;
@@ -1063,9 +1103,8 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
                        ofun, unixmode, oplock_request, NULL, NULL);
   
        if (!fsp) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBcreate);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnoaccess);
        }
  
        outsize = set_message(outbuf,1,0,True);
@@ -1132,9 +1171,8 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
        close(tmpfd);
 
        if (!fsp) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBctemp);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRnoaccess);
        }
 
        outsize = set_message(outbuf,1,0,True);
@@ -1215,6 +1253,9 @@ static NTSTATUS can_delete(char *fname,connection_struct *conn, int dirtype)
        int access_mode;
        files_struct *fsp;
 
+       DEBUG(10,("can_delete: %s, dirtype = %d\n",
+               fname, dirtype ));
+
        if (!CAN_WRITE(conn))
                return NT_STATUS_MEDIA_WRITE_PROTECTED;
 
@@ -1222,14 +1263,21 @@ static NTSTATUS can_delete(char *fname,connection_struct *conn, int dirtype)
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 
        fmode = dos_mode(conn,fname,&sbuf);
+
+       /* Can't delete a directory. */
        if (fmode & aDIR)
                return NT_STATUS_FILE_IS_A_DIRECTORY;
+#if 0 /* JRATEST */
+       else if (dirtype & aDIR) /* Asked for a directory and it isn't. */
+               return NT_STATUS_OBJECT_NAME_INVALID;
+#endif /* JRATEST */
+
        if (!lp_delete_readonly(SNUM(conn))) {
                if (fmode & aRONLY)
                        return NT_STATUS_CANNOT_DELETE;
        }
        if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM))
-               return NT_STATUS_CANNOT_DELETE;
+               return NT_STATUS_NO_SUCH_FILE;
 
        /* We need a better way to return NT status codes from open... */
        unix_ERR_class = 0;
@@ -1329,7 +1377,7 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name)
                */
                
                if (dirptr) {
-                       error = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+                       error = NT_STATUS_NO_SUCH_FILE;
                        
                        if (strequal(mask,"????????.???"))
                                pstrcpy(mask,"*");
@@ -1377,6 +1425,10 @@ int reply_unlink(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        
        srvstr_pull_buf(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), STR_TERMINATE);
        
+       status = check_path_syntax(name);
+       if (!NT_STATUS_IS_OK(status))
+               return ERROR_NT(status);
+
        RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
        
        DEBUG(3,("reply_unlink : %s\n",name));
@@ -2262,39 +2314,25 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
        switch (mode) {
                case 0:
                        umode = SEEK_SET;
+                       res = startpos;
                        break;
                case 1:
                        umode = SEEK_CUR;
+                       res = fsp->pos + startpos;
                        break;
                case 2:
                        umode = SEEK_END;
                        break;
                default:
                        umode = SEEK_SET;
+                       res = startpos;
                        break;
        }
 
-       if((res = SMB_VFS_LSEEK(fsp,fsp->fd,startpos,umode)) == -1) {
-               /*
-                * Check for the special case where a seek before the start
-                * of the file sets the offset to zero. Added in the CIFS spec,
-                * section 4.2.7.
-                */
-
-               if(errno == EINVAL) {
-                       SMB_OFF_T current_pos = startpos;
-
-                       if(umode == SEEK_CUR) {
-
-                               if((current_pos = SMB_VFS_LSEEK(fsp,fsp->fd,0,SEEK_CUR)) == -1) {
-                                       END_PROFILE(SMBlseek);
-                                       return(UNIXERROR(ERRDOS,ERRnoaccess));
-                               }
-
-                               current_pos += startpos;
-
-                       } else if (umode == SEEK_END) {
-
+       if (umode == SEEK_END) {
+               if((res = SMB_VFS_LSEEK(fsp,fsp->fd,startpos,umode)) == -1) {
+                       if(errno == EINVAL) {
+                               SMB_OFF_T current_pos = startpos;
                                SMB_STRUCT_STAT sbuf;
 
                                if(SMB_VFS_FSTAT(fsp,fsp->fd, &sbuf) == -1) {
@@ -2303,10 +2341,9 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
                                }
 
                                current_pos += sbuf.st_size;
+                               if(current_pos < 0)
+                                       res = SMB_VFS_LSEEK(fsp,fsp->fd,0,SEEK_SET);
                        }
-                       if(current_pos < 0)
-                               res = SMB_VFS_LSEEK(fsp,fsp->fd,0,SEEK_SET);
                }
 
                if(res == -1) {
@@ -2334,10 +2371,12 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
 int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int size, int dum_buffsize)
 {
        int outsize = set_message(outbuf,0,0,True);
+       uint16 fnum = SVAL(inbuf,smb_vwv0);
        files_struct *fsp = file_fsp(inbuf,smb_vwv0);
        START_PROFILE(SMBflush);
 
-       CHECK_FSP(fsp,conn);
+       if (fnum != 0xFFFF)
+               CHECK_FSP(fsp,conn);
        
        if (!fsp) {
                file_sync_all(conn);
@@ -2359,6 +2398,9 @@ int reply_exit(connection_struct *conn,
 {
        int outsize;
        START_PROFILE(SMBexit);
+
+       file_close_pid(SVAL(inbuf,smb_pid));
+
        outsize = set_message(outbuf,0,0,True);
 
        DEBUG(3,("exit\n"));
@@ -2704,7 +2746,7 @@ int reply_printclose(connection_struct *conn,
 
        if (!CAN_PRINT(conn)) {
                END_PROFILE(SMBsplclose);
-               return ERROR_DOS(ERRDOS,ERRnoaccess);
+               return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
        }
   
        DEBUG(3,("printclose fd=%d fnum=%d\n",
@@ -2849,7 +2891,17 @@ NTSTATUS mkdir_internal(connection_struct *conn, pstring directory)
                ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory));
        
        if (ret == -1) {
-               NTSTATUS nterr = set_bad_path_error(errno, bad_path);
+               NTSTATUS nterr = NT_STATUS_OK;
+               if(errno == ENOENT) {
+                       unix_ERR_class = ERRDOS;
+                       if (bad_path) {
+                               unix_ERR_code = ERRbadpath;
+                               nterr = NT_STATUS_OBJECT_PATH_NOT_FOUND;
+                       } else {
+                               unix_ERR_code = ERRbadfile;
+                               nterr = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+                       }
+               }
                if (!NT_STATUS_IS_OK(nterr))
                        return nterr;
                return map_nt_error_from_unix(errno);
@@ -3044,9 +3096,8 @@ int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
        }
   
        if (!ok) {
-               set_bad_path_error(errno, bad_path);
                END_PROFILE(SMBrmdir);
-               return(UNIXERROR(ERRDOS,ERRbadpath));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS, ERRbadpath);
        }
  
        outsize = set_message(outbuf,0,0,True);
@@ -3129,6 +3180,130 @@ static BOOL resolve_wildcards(const char *name1, char *name2)
        return(True);
 }
 
+/****************************************************************************
+ Ensure open files have their names updates.
+****************************************************************************/
+
+static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T inode, char *newname)
+{
+       files_struct *fsp;
+       BOOL did_rename = False;
+
+       for(fsp = file_find_di_first(dev, inode); fsp; fsp = file_find_di_next(fsp)) {
+               DEBUG(10,("rename_open_files: renaming file fnum %d (dev = %x, inode = %.0f) from %s -> %s\n",
+                       fsp->fnum, (unsigned int)fsp->dev, (double)fsp->inode,
+                       fsp->fsp_name, newname ));
+               string_set(&fsp->fsp_name, newname);
+               did_rename = True;
+       }
+
+       if (!did_rename)
+               DEBUG(10,("rename_open_files: no open files on dev %x, inode %.0f for %s\n",
+                       (unsigned int)dev, (double)inode, newname ));
+}
+
+/****************************************************************************
+ Rename an open file - given an fsp.
+****************************************************************************/
+
+NTSTATUS rename_internals_fsp(connection_struct *conn, files_struct *fsp, char *newname, BOOL replace_if_exists)
+{
+       SMB_STRUCT_STAT sbuf;
+       BOOL bad_path = False;
+       pstring newname_last_component;
+       NTSTATUS error = NT_STATUS_OK;
+       BOOL dest_exists;
+
+       ZERO_STRUCT(sbuf);
+       unix_convert(newname,conn,newname_last_component,&bad_path,&sbuf);
+
+       /* Ensure newname contains a '/' */
+       if(strrchr_m(newname,'/') == 0) {
+               pstring tmpstr;
+               
+               pstrcpy(tmpstr, "./");
+               pstrcat(tmpstr, newname);
+               pstrcpy(newname, tmpstr);
+       }
+
+       /*
+        * Check for special case with case preserving and not
+        * case sensitive. If the old last component differs from the original
+        * last component only by case, then we should allow
+        * the rename (user is trying to change the case of the
+        * filename).
+        */
+
+       if((case_sensitive == False) && (case_preserve == True) &&
+                       strequal(newname, fsp->fsp_name)) {
+               char *p;
+               pstring newname_modified_last_component;
+
+               /*
+                * Get the last component of the modified name.
+                * Note that we guarantee that newname contains a '/'
+                * character above.
+                */
+               p = strrchr_m(newname,'/');
+               pstrcpy(newname_modified_last_component,p+1);
+                       
+               if(strcsequal(newname_modified_last_component, 
+                             newname_last_component) == False) {
+                       /*
+                        * Replace the modified last component with
+                        * the original.
+                        */
+                       pstrcpy(p+1, newname_last_component);
+               }
+       }
+
+       /*
+        * If the src and dest names are identical - including case,
+        * don't do the rename, just return success.
+        */
+
+       if (strcsequal(fsp->fsp_name, newname)) {
+               DEBUG(3,("rename_internals_fsp: identical names in rename %s - returning success\n",
+                       newname));
+               return NT_STATUS_OK;
+       }
+
+       dest_exists = vfs_object_exist(conn,newname,NULL);
+
+       if(!replace_if_exists && dest_exists) {
+               DEBUG(3,("rename_internals_fsp: dest exists doing rename %s -> %s\n",
+                       fsp->fsp_name,newname));
+               return NT_STATUS_OBJECT_NAME_COLLISION;
+       }
+
+       error = can_rename(newname,conn,&sbuf);
+
+       if (dest_exists && !NT_STATUS_IS_OK(error)) {
+               DEBUG(3,("rename_internals: Error %s rename %s -> %s\n",
+                       nt_errstr(error), fsp->fsp_name,newname));
+               if (NT_STATUS_EQUAL(error,NT_STATUS_SHARING_VIOLATION))
+                       error = NT_STATUS_ACCESS_DENIED;
+               return error;
+       }
+
+       if(SMB_VFS_RENAME(conn,fsp->fsp_name, newname) == 0) {
+               DEBUG(3,("rename_internals_fsp: succeeded doing rename on %s -> %s\n",
+                       fsp->fsp_name,newname));
+               rename_open_files(conn, fsp->dev, fsp->inode, newname);
+               return NT_STATUS_OK;    
+       }
+
+       if (errno == ENOTDIR || errno == EISDIR)
+               error = NT_STATUS_OBJECT_NAME_COLLISION;
+       else
+               error = map_nt_error_from_unix(errno);
+               
+       DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n",
+               nt_errstr(error), fsp->fsp_name,newname));
+
+       return error;
+}
+
 /****************************************************************************
  The guts of the rename command, split out so it may be called by the NT SMB
  code. 
@@ -3150,6 +3325,8 @@ NTSTATUS rename_internals(connection_struct *conn, char *name, char *newname, BO
 
        *directory = *mask = 0;
 
+       ZERO_STRUCT(sbuf1);
+       ZERO_STRUCT(sbuf2);
        rc = unix_convert(name,conn,0,&bad_path1,&sbuf1);
        unix_convert(newname,conn,newname_last_component,&bad_path2,&sbuf2);
 
@@ -3290,6 +3467,7 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                 */
 
                if (strcsequal(directory, newname)) {
+                       rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname);
                        DEBUG(3,("rename_internals: identical names in rename %s - returning success\n", directory));
                        return NT_STATUS_OK;
                }
@@ -3303,6 +3481,7 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                if(SMB_VFS_RENAME(conn,directory, newname) == 0) {
                        DEBUG(3,("rename_internals: succeeded doing rename on %s -> %s\n",
                                directory,newname));
+                       rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname);
                        return NT_STATUS_OK;    
                }
 
@@ -3367,8 +3546,10 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                                        continue;
                                }
                                
-                               if (!SMB_VFS_RENAME(conn,fname,destname))
+                               if (!SMB_VFS_RENAME(conn,fname,destname)) {
+                                       rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname);
                                        count++;
+                               }
                                DEBUG(3,("rename_internals: doing rename on %s -> %s\n",fname,destname));
                        }
                        CloseDir(dirptr);
index 411ece52495c5f80b615147ad7fba289c0a1829b..8a85792ead55d4f70e24d3a3ec455eaa5ee90588 100644 (file)
@@ -199,7 +199,7 @@ BOOL initialise_groups(char *user, uid_t uid, gid_t gid)
 
        /* Call initgroups() to get user groups */
 
-       if (initgroups(user,gid) == -1) {
+       if (winbind_initgroups(user,gid) == -1) {
                DEBUG(0,("Unable to initgroups. Error was %s\n", strerror(errno) ));
                if (getuid() == 0) {
                        if (gid < 0 || gid > 32767 || uid < 0 || uid > 32767) {
index 453ff54e4ba88c8af2dfb2dfe54e3a69f6923a33..8b890549ea34595b122e727fdedcd1f88f1f83e3 100644 (file)
@@ -744,7 +744,7 @@ void build_options(BOOL screen);
 
        reopen_logs();
 
-       DEBUG(0,( "smbd version %s started.\n", VERSION));
+       DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
        DEBUGADD(0,( "Copyright Andrew Tridgell and the Samba Team 1992-2003\n"));
 
        DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
index c2855487a553a563965e60c4d3f899282537b713..70126b9e7fc9eed9f32fde4e39fb555906d49541 100644 (file)
@@ -273,7 +273,7 @@ static void set_read_only(connection_struct *conn, gid_t *groups, size_t n_group
 
        str_list_copy(&list, lp_readlist(conn->service));
        if (list) {
-               if (!str_list_substitute(list, "%S", service)) {
+               if ( !str_list_sub_basic(list, current_user_info.smb_name) ) {
                        DEBUG(0, ("ERROR: read list substitution failed\n"));
                }
                if (user_in_list(conn->user, (const char **)list, groups, n_groups))
@@ -283,7 +283,7 @@ static void set_read_only(connection_struct *conn, gid_t *groups, size_t n_group
        
        str_list_copy(&list, lp_writelist(conn->service));
        if (list) {
-               if (!str_list_substitute(list, "%S", service)) {
+               if ( !str_list_sub_basic(list, current_user_info.smb_name) ) {
                        DEBUG(0, ("ERROR: write list substitution failed\n"));
                }
                if (user_in_list(conn->user, (const char **)list, groups, n_groups))
@@ -642,6 +642,10 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        return NULL;
                }
        }
+
+#ifdef WITH_FAKE_KASERVER
+       afs_login(user);
+#endif
        
 #if CHECK_PATH_ON_TCONX
        /* win2000 does not check the permissions on the directory
@@ -691,6 +695,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
 
        if( DEBUGLVL( IS_IPC(conn) ? 3 : 1 ) ) {
                dbgtext( "%s (%s) ", get_remote_machine_name(), conn->client_address );
+               dbgtext( "%s", srv_is_signing_active() ? "signed " : "");
                dbgtext( "connect to service %s ", lp_servicename(SNUM(conn)) );
                dbgtext( "initially as user %s ", user );
                dbgtext( "(uid=%d, gid=%d) ", (int)geteuid(), (int)getegid() );
index 88b442215d66f78a4244e9be6122a2dfb9535de7..427caa3ba11d407aef348c7c753477956792f204 100644 (file)
@@ -62,7 +62,7 @@ static int add_signature(char *outbuf, char *p)
        char *start = p;
        fstring lanman;
 
-       fstr_sprintf( lanman, "Samba %s", VERSION );
+       fstr_sprintf( lanman, "Samba %s", SAMBA_VERSION_STRING);
 
        p += srvstr_push(outbuf, p, "Unix", -1, STR_TERMINATE);
        p += srvstr_push(outbuf, p, lanman, -1, STR_TERMINATE);
@@ -149,7 +149,6 @@ static int reply_spnego_kerberos(connection_struct *conn,
        DATA_BLOB auth_data;
        DATA_BLOB ap_rep, ap_rep_wrapped, response;
        auth_serversupplied_info *server_info = NULL;
-       ADS_STRUCT *ads;
        uint8 session_key[16];
        uint8 tok_id[2];
        BOOL foreign = False;
@@ -165,18 +164,12 @@ static int reply_spnego_kerberos(connection_struct *conn,
                return ERROR_NT(NT_STATUS_LOGON_FAILURE);
        }
 
-       ads = ads_init_simple();
+       ret = ads_verify_ticket(lp_realm(), &ticket, &client, &auth_data, &ap_rep, session_key);
 
-       if (!ads) {
-               return ERROR_NT(NT_STATUS_LOGON_FAILURE);
-       }
+       data_blob_free(&ticket);
 
-       ads->auth.realm = strdup(lp_realm());
-
-       ret = ads_verify_ticket(ads, &ticket, &client, &auth_data, &ap_rep, session_key);
        if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(1,("Failed to verify incoming ticket!\n"));       
-               ads_destroy(&ads);
                return ERROR_NT(NT_STATUS_LOGON_FAILURE);
        }
 
@@ -187,16 +180,17 @@ static int reply_spnego_kerberos(connection_struct *conn,
        p = strchr_m(client, '@');
        if (!p) {
                DEBUG(3,("Doesn't look like a valid principal\n"));
-               ads_destroy(&ads);
                data_blob_free(&ap_rep);
+               SAFE_FREE(client);
                return ERROR_NT(NT_STATUS_LOGON_FAILURE);
        }
 
        *p = 0;
-       if (strcasecmp(p+1, ads->auth.realm) != 0) {
+       if (strcasecmp(p+1, lp_realm()) != 0) {
                DEBUG(3,("Ticket for foreign realm %s@%s\n", client, p+1));
                if (!lp_allow_trusted_domains()) {
                        data_blob_free(&ap_rep);
+                       SAFE_FREE(client);
                        return ERROR_NT(NT_STATUS_LOGON_FAILURE);
                }
                foreign = True;
@@ -213,7 +207,7 @@ static int reply_spnego_kerberos(connection_struct *conn,
                user = smb_xstrdup(client);
        }
 
-       ads_destroy(&ads);
+       SAFE_FREE(client);
 
        /* setup the string used by %U */
        sub_set_smb_name(user);
@@ -223,7 +217,7 @@ static int reply_spnego_kerberos(connection_struct *conn,
        if (!pw) {
                DEBUG(1,("Username %s is invalid on this system\n",user));
                data_blob_free(&ap_rep);
-               return ERROR_NT(NT_STATUS_NO_SUCH_USER);
+               return ERROR_NT(NT_STATUS_LOGON_FAILURE);
        }
 
        if (!NT_STATUS_IS_OK(ret = make_server_info_pw(&server_info,pw))) {
index fbebdb240f4b2eef659acf38acfd1c3b91622ada..948173687d9ebcb9516a738ab1a4210bb04ea164 100644 (file)
@@ -66,11 +66,12 @@ void stat_cache_add( const char *full_orig_name, const char *orig_translated_pat
                return;
 
        /*
-        * Don't cache trivial valid directory entries.
+        * Don't cache trivial valid directory entries such as . and ..
         */
 
-       if((*full_orig_name == '\0') || (strcmp(full_orig_name, ".") == 0) ||
-                       (strcmp(full_orig_name, "..") == 0))
+       if((*full_orig_name == '\0') || (full_orig_name[0] == '.' && 
+                               ((full_orig_name[1] == '\0') ||
+                                (full_orig_name[1] == '.' && full_orig_name[1] == '\0'))))
                return;
 
        /*
@@ -216,10 +217,10 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath,
        /*
         * Don't lookup trivial valid directory entries.
         */
-       if((*name == '\0') || (strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
-               DO_PROFILE_INC(statcache_misses);
+       if((*name == '\0') || (name[0] == '.' && 
+                               ((name[1] == '\0') ||
+                                (name[1] == '.' && name[1] == '\0'))))
                return False;
-       }
 
        if (case_sensitive) {
                chk_name = strdup(name);
@@ -247,6 +248,7 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath,
        while (1) {
                hash_elem = hash_lookup(&stat_cache, chk_name);
                if(hash_elem == NULL) {
+                       DEBUG(10,("stat_cache_lookup: lookup failed for name [%s]\n", chk_name ));
                        /*
                         * Didn't find it - remove last component for next try.
                         */
@@ -276,6 +278,7 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath,
                        }
                } else {
                        scp = (stat_cache_entry *)(hash_elem->value);
+                       DEBUG(10,("stat_cache_lookup: lookup succeeded for name [%s] -> [%s]\n", chk_name, scp->translated_path ));
                        DO_PROFILE_INC(statcache_hits);
                        if(SMB_VFS_STAT(conn,scp->translated_path, pst) != 0) {
                                /* Discard this entry - it doesn't exist in the filesystem.  */
index 86906fa5be0c0827b1e0c41ccee16101dbd530c6..033e76a33e1dcb9a664bbc6961c1d5852f11e6a4 100644 (file)
@@ -1,7 +1,7 @@
 /* 
    Unix SMB/CIFS implementation.
    SMB transaction2 handling
-   Copyright (C) Jeremy Allison                        1994-2001
+   Copyright (C) Jeremy Allison                        1994-2003
    Copyright (C) Stefan (metze) Metzmacher     2003
 
    Extensively modified by Andrew Tridgell, 1995
@@ -261,8 +261,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
        unix_convert(fname,conn,0,&bad_path,&sbuf);
     
        if (!check_name(fname,conn)) {
-               set_bad_path_error(errno, bad_path);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
        unixmode = unix_mode(conn,open_attr | aARCH, fname);
@@ -271,8 +270,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
                oplock_request, &rmode,&smb_action);
       
        if (!fsp) {
-               set_bad_path_error(errno, bad_path);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
        size = get_file_size(sbuf);
@@ -441,9 +439,9 @@ static mode_t unix_perms_from_wire( connection_struct *conn, SMB_STRUCT_STAT *ps
 }
 
 /****************************************************************************
-checks for SMB_TIME_NO_CHANGE and if not found
-calls interpret_long_date
+ Checks for SMB_TIME_NO_CHANGE and if not found calls interpret_long_date.
 ****************************************************************************/
+
 time_t interpret_long_unix_date(char *p)
 {
        DEBUG(1,("interpret_long_unix_date\n"));
@@ -763,6 +761,70 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
                        p = pdata + len;
                        break;
 
+               case SMB_FIND_FILE_LEVEL_261:
+                       p += 4;
+                       SIVAL(p,0,reskey); p += 4;
+                       put_long_date(p,cdate); p += 8;
+                       put_long_date(p,adate); p += 8;
+                       put_long_date(p,mdate); p += 8;
+                       put_long_date(p,mdate); p += 8;
+                       SOFF_T(p,0,file_size); 
+                       SOFF_T(p,8,allocation_size);
+                       p += 16;
+                       SIVAL(p,0,nt_extmode);
+                       p += 4;
+                       len = srvstr_push(outbuf, p + 20, fname, -1, STR_TERMINATE_ASCII);
+                       SIVAL(p, 0, len);
+                       memset(p+4,'\0',16); /* EA size. Unknown 0 1 2 */
+                       p += 20 + len; /* Strlen, EA size. Unknown 0 1 2, string itself */
+                       len = PTR_DIFF(p, pdata);
+                       len = (len + 3) & ~3;
+                       SIVAL(pdata,0,len);
+                       p = pdata + len;
+                       break;
+
+               case SMB_FIND_FILE_LEVEL_262:
+                       was_8_3 = mangle_is_8_3(fname, True);
+                       p += 4;
+                       SIVAL(p,0,reskey); p += 4;
+                       put_long_date(p,cdate); p += 8;
+                       put_long_date(p,adate); p += 8;
+                       put_long_date(p,mdate); p += 8;
+                       put_long_date(p,mdate); p += 8;
+                       SOFF_T(p,0,file_size);
+                       SOFF_T(p,8,allocation_size);
+                       p += 16;
+                       SIVAL(p,0,nt_extmode); p += 4;
+                       q = p; p += 4;
+                       SIVAL(p,0,0); p += 4;
+                       /* Clear the short name buffer. This is
+                        * IMPORTANT as not doing so will trigger
+                        * a Win2k client bug. JRA.
+                        */
+                       memset(p,'\0',26);
+                       if (!was_8_3) {
+                               pstring mangled_name;
+                               pstrcpy(mangled_name, fname);
+                               mangle_map(mangled_name,True,True,SNUM(conn));
+                               mangled_name[12] = 0;
+                               len = srvstr_push(outbuf, p+2, mangled_name, 24, STR_UPPER|STR_UNICODE);
+                               SSVAL(p, 0, len);
+                       } else {
+                               SSVAL(p,0,0);
+                               *(p+2) = 0;
+                       }
+                       p += 2 + 24;
+                       memset(p, '\0', 10); /* 2 4 byte unknowns plus a zero reserved. */
+                       p += 10;
+                       len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
+                       SIVAL(q,0,len);
+                       p += len;
+                       len = PTR_DIFF(p, pdata);
+                       len = (len + 3) & ~3;
+                       SIVAL(pdata,0,len);
+                       p = pdata + len;
+                       break;
+
                /* CIFS UNIX Extension. */
 
                case SMB_FIND_FILE_UNIX:
@@ -895,6 +957,8 @@ close_if_end = %d requires_resume_key = %d level = %d, max_data_bytes = %d\n",
                case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
                case SMB_FIND_FILE_NAMES_INFO:
                case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
+               case SMB_FIND_FILE_LEVEL_261:
+               case SMB_FIND_FILE_LEVEL_262:
                        break;
                case SMB_FIND_FILE_UNIX:
                        if (!lp_unix_extensions())
@@ -910,8 +974,7 @@ close_if_end = %d requires_resume_key = %d level = %d, max_data_bytes = %d\n",
 
        unix_convert(directory,conn,0,&bad_path,&sbuf);
        if(!check_name(directory,conn)) {
-               set_bad_path_error(errno, bad_path);
-               return(UNIXERROR(ERRDOS,ERRbadpath));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
        }
 
        p = strrchr_m(directory,'/');
@@ -1365,7 +1428,7 @@ static int call_trans2qfsinfo(connection_struct *conn, char *inbuf, char *outbuf
                         * the called hostname and the service name.
                         */
                        SIVAL(pdata,0,str_checksum(lp_servicename(snum)) ^ (str_checksum(local_machine)<<16) );
-                       len = srvstr_push(outbuf, pdata+l2_vol_szVolLabel, vname, -1, 0);
+                       len = srvstr_push(outbuf, pdata+l2_vol_szVolLabel, vname, -1, STR_NOALIGN);
                        SCVAL(pdata,l2_vol_cch,len);
                        data_len = l2_vol_szVolLabel + len;
                        DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",
@@ -1716,14 +1779,22 @@ static int call_trans2setfsinfo(connection_struct *conn,
  *  Utility function to set bad path error.
  ****************************************************************************/
 
-NTSTATUS set_bad_path_error(int err, BOOL bad_path)
+int set_bad_path_error(int err, BOOL bad_path, char *outbuf, int def_class, uint32 def_code)
 {
-       if((err == ENOENT) && bad_path) {
+       DEBUG(10,("set_bad_path_error: err = %d bad_path = %d\n",
+                       err, (int)bad_path ));
+
+       if(err == ENOENT) {
                unix_ERR_class = ERRDOS;
-               unix_ERR_code = ERRbadpath;
-               return NT_STATUS_OBJECT_PATH_NOT_FOUND;
+               if (bad_path) {
+                       unix_ERR_code = ERRbadpath;
+                       return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+               } else {
+                       unix_ERR_code = ERRbadfile;
+                       return ERROR_NT(NT_STATUS_OBJECT_NAME_NOT_FOUND);
+               }
        }
-       return NT_STATUS_OK;
+       return UNIXERROR(def_class,def_code);
 }
 
 /****************************************************************************
@@ -1778,8 +1849,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                        unix_convert(fname,conn,0,&bad_path,&sbuf);
                        if (!check_name(fname,conn)) {
                                DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed for fake_file(%s)\n",fname,strerror(errno)));
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
                        
                } else if(fsp && (fsp->is_directory || fsp->fd == -1)) {
@@ -1792,21 +1862,18 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                        unix_convert(fname,conn,0,&bad_path,&sbuf);
                        if (!check_name(fname,conn)) {
                                DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
                  
                        if (INFO_LEVEL_IS_UNIX(info_level)) {
                                /* Always do lstat for UNIX calls. */
                                if (SMB_VFS_LSTAT(conn,fname,&sbuf)) {
                                        DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",fname,strerror(errno)));
-                                       set_bad_path_error(errno, bad_path);
-                                       return(UNIXERROR(ERRDOS,ERRbadpath));
+                                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                                }
                        } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,fname,&sbuf)) {
                                DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
 
                        delete_pending = fsp->directory_delete_on_close;
@@ -1821,9 +1888,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                                DEBUG(3,("fstat of fnum %d failed (%s)\n", fsp->fnum, strerror(errno)));
                                return(UNIXERROR(ERRDOS,ERRbadfid));
                        }
-                       if((pos = SMB_VFS_LSEEK(fsp,fsp->fd,0,SEEK_CUR)) == -1)
-                               return(UNIXERROR(ERRDOS,ERRnoaccess));
-
+                       pos = fsp->position_information;
                        delete_pending = fsp->delete_on_close;
                }
        } else {
@@ -1842,29 +1907,26 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                unix_convert(fname,conn,0,&bad_path,&sbuf);
                if (!check_name(fname,conn)) {
                        DEBUG(3,("call_trans2qfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
-                       set_bad_path_error(errno, bad_path);
-                       return(UNIXERROR(ERRDOS,ERRbadpath));
+                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                }
 
                if (INFO_LEVEL_IS_UNIX(info_level)) {
                        /* Always do lstat for UNIX calls. */
                        if (SMB_VFS_LSTAT(conn,fname,&sbuf)) {
                                DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_LSTAT of %s failed (%s)\n",fname,strerror(errno)));
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
                } else if (!VALID_STAT(sbuf) && SMB_VFS_STAT(conn,fname,&sbuf)) {
                        DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
-                       set_bad_path_error(errno, bad_path);
-                       return(UNIXERROR(ERRDOS,ERRbadpath));
+                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                }
        }
 
        if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions())
                return ERROR_DOS(ERRDOS,ERRunknownlevel);
 
-       DEBUG(3,("call_trans2qfilepathinfo %s level=%d call=%d total_data=%d\n",
-               fname,info_level,tran_call,total_data));
+       DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
+               fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
 
        p = strrchr_m(fname,'/'); 
        if (!p)
@@ -1873,6 +1935,9 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                base_name = p+1;
 
        mode = dos_mode(conn,fname,&sbuf);
+       if (!mode)
+               mode = FILE_ATTRIBUTE_NORMAL;
+
        fullpathname = fname;
        file_size = get_file_size(sbuf);
        allocation_size = get_allocation_size(fsp,&sbuf);
@@ -1985,7 +2050,10 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                        data_size = 24;
                        SOFF_T(pdata,0,allocation_size);
                        SOFF_T(pdata,8,file_size);
-                       SIVAL(pdata,16,sbuf.st_nlink);
+                       if (delete_pending & sbuf.st_nlink)
+                               SIVAL(pdata,16,sbuf.st_nlink - 1);
+                       else
+                               SIVAL(pdata,16,sbuf.st_nlink);
                        SCVAL(pdata,20,0);
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
                        break;
@@ -2043,7 +2111,10 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
                        pdata += 40;
                        SOFF_T(pdata,0,allocation_size);
                        SOFF_T(pdata,8,file_size);
-                       SIVAL(pdata,16,sbuf.st_nlink);
+                       if (delete_pending && sbuf.st_nlink)
+                               SIVAL(pdata,16,sbuf.st_nlink - 1);
+                       else
+                               SIVAL(pdata,16,sbuf.st_nlink);
                        SCVAL(pdata,20,delete_pending);
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
                        pdata += 24;
@@ -2415,8 +2486,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
                        unix_convert(fname,conn,0,&bad_path,&sbuf);
                        if (!check_name(fname,conn) || (!VALID_STAT(sbuf))) {
                                DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
-                               set_bad_path_error(errno, bad_path);
-                               return(UNIXERROR(ERRDOS,ERRbadpath));
+                               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                        }
                } else if (fsp && fsp->print_file) {
                        /*
@@ -2455,8 +2525,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
                srvstr_pull(inbuf, fname, &params[6], sizeof(fname), -1, STR_TERMINATE);
                unix_convert(fname,conn,0,&bad_path,&sbuf);
                if(!check_name(fname, conn)) {
-                       set_bad_path_error(errno, bad_path);
-                       return(UNIXERROR(ERRDOS,ERRbadpath));
+                       return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
                }
 
                /*
@@ -2465,8 +2534,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
 
                if(!VALID_STAT(sbuf) && !INFO_LEVEL_IS_UNIX(info_level)) {
                        DEBUG(3,("call_trans2setfilepathinfo: stat of %s failed (%s)\n", fname, strerror(errno)));
-                       set_bad_path_error(errno, bad_path);
-                       return(UNIXERROR(ERRDOS,ERRbadpath));
+                       return ERROR_NT(NT_STATUS_OBJECT_NAME_NOT_FOUND);
                }    
        }
 
@@ -2479,8 +2547,8 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
        if (VALID_STAT(sbuf))
                unixmode = sbuf.st_mode;
 
-       DEBUG(3,("call_trans2setfilepathinfo(%d) %s info_level=%d totdata=%d\n",
-               tran_call,fname,info_level,total_data));
+       DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d totdata=%d\n",
+               tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
 
        /* Realloc the parameter and data sizes */
        params = Realloc(*pparams,2);
@@ -2507,18 +2575,13 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
        switch (info_level) {
                case SMB_INFO_STANDARD:
                {
-                       if (total_data < l1_cbFile+4)
+                       if (total_data < 12)
                                return(ERROR_DOS(ERRDOS,ERRinvalidparam));
 
                        /* access time */
                        tvs.actime = make_unix_date2(pdata+l1_fdateLastAccess);
-
                        /* write time */
                        tvs.modtime = make_unix_date2(pdata+l1_fdateLastWrite);
-
-                       dosmode = SVAL(pdata,l1_attrFile);
-                       size = IVAL(pdata,l1_cbFile);
-
                        break;
                }
 
@@ -2677,14 +2740,17 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
                case SMB_FILE_DISPOSITION_INFORMATION:
                case SMB_SET_FILE_DISPOSITION_INFO: /* Set delete on close for open file. */
                {
-                       BOOL delete_on_close = (CVAL(pdata,0) ? True : False);
+                       BOOL delete_on_close;
                        NTSTATUS status;
 
                        if (total_data < 1)
                                return(ERROR_DOS(ERRDOS,ERRinvalidparam));
 
+                       delete_on_close = (CVAL(pdata,0) ? True : False);
+
+                       /* Just ignore this set on a path. */
                        if (tran_call != TRANSACT2_SETFILEINFO)
-                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+                               break;
 
                        if (fsp == NULL)
                                return(UNIXERROR(ERRDOS,ERRbadfid));
@@ -2702,6 +2768,27 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
                        break;
                }
 
+               case SMB_FILE_POSITION_INFORMATION:
+               {
+                       SMB_BIG_UINT position_information;
+
+                       if (total_data < 8)
+                               return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+
+                       position_information = (SMB_BIG_UINT)IVAL(pdata,0);
+#ifdef LARGE_SMB_OFF_T
+                       position_information |= (((SMB_BIG_UINT)IVAL(pdata,4)) << 32);
+#else /* LARGE_SMB_OFF_T */
+                       if (IVAL(pdata,4) != 0) /* more than 32 bits? */
+                               return ERROR_DOS(ERRDOS,ERRunknownlevel);
+#endif /* LARGE_SMB_OFF_T */
+                       DEBUG(10,("call_trans2setfilepathinfo: Set file position information for file %s to %.0f\n",
+                                       fname, (double)position_information ));
+                       if (fsp)
+                               fsp->position_information = position_information;
+                       break;
+               }
+
                /*
                 * CIFS UNIX extensions.
                 */
@@ -2881,6 +2968,55 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
                        return(-1);
                }
 
+               case SMB_FILE_RENAME_INFORMATION:
+               {
+                       BOOL overwrite;
+                       uint32 root_fid;
+                       uint32 len;
+                       pstring newname;
+                       pstring base_name;
+                       char *p;
+                       NTSTATUS status;
+
+                       if (total_data < 12)
+                               return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+
+                       overwrite = (CVAL(pdata,0) ? True : False);
+                       root_fid = IVAL(pdata,4);
+                       len = IVAL(pdata,8);
+                       srvstr_pull(inbuf, newname, &pdata[12], sizeof(newname), len, 0);
+
+                       /* Check the new name has no '\' characters. */
+                       if (strchr_m(newname, '\\') || strchr_m(newname, '/'))
+                               return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
+
+                       RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
+
+                       /* Create the base directory. */
+                       pstrcpy(base_name, fname);
+                       p = strrchr_m(base_name, '/');
+                       if (p)
+                               *p = '\0';
+                       /* Append the new name. */
+                       pstrcat(base_name, "/");
+                       pstrcat(base_name, newname);
+
+                       if (fsp) {
+                               DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
+                                       fsp->fnum, fsp->fsp_name, base_name ));
+                               status = rename_internals_fsp(conn, fsp, base_name, overwrite);
+                       } else {
+                               DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
+                                       fname, newname ));
+                               status = rename_internals(conn, fname, base_name, overwrite);
+                       }
+                       if (!NT_STATUS_IS_OK(status))
+                               return ERROR_NT(status);
+                       process_pending_change_notify_queue((time_t)0);
+                       SSVAL(params,0,0);
+                       send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+                       return(-1);
+               }
                default:
                        return ERROR_DOS(ERRDOS,ERRunknownlevel);
        }
@@ -2896,10 +3032,12 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
        DEBUG(6,("modtime: %s ", ctime(&tvs.modtime)));
        DEBUG(6,("size: %.0f ", (double)size));
 
-       if (S_ISDIR(sbuf.st_mode))
-               dosmode |= aDIR;
-       else
-               dosmode &= ~aDIR;
+       if (dosmode) {
+               if (S_ISDIR(sbuf.st_mode))
+                       dosmode |= aDIR;
+               else
+                       dosmode &= ~aDIR;
+       }
 
        DEBUG(6,("dosmode: %x\n"  , dosmode));
 
@@ -3030,8 +3168,7 @@ static int call_trans2mkdir(connection_struct *conn,
   
        if(ret < 0) {
                DEBUG(5,("call_trans2mkdir error (%s)\n", strerror(errno)));
-               set_bad_path_error(errno, bad_path);
-               return(UNIXERROR(ERRDOS,ERRnoaccess));
+               return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
        }
 
        /* Realloc the parameter and data sizes */
index 8d3e7cd9be774b0c3bc4513a8198bd6289d57945..7979ffe85406b8c8673b549ccae3922ab22e88f8 100644 (file)
@@ -370,7 +370,7 @@ BOOL unbecome_user(void)
 }
 
 /*****************************************************************
- Convert the suplimentary SIDs returned in a netlogon into UNIX
+ Convert the supplementary SIDs returned in a netlogon into UNIX
  group gid_t's. Add to the total group array.
 *****************************************************************/
  
@@ -437,467 +437,4 @@ void add_supplementary_nt_login_groups(int *n_groups, gid_t **pp_groups, NT_USER
        *pptok = new_tok;
 }
 
-/*****************************************************************
- *THE CANONICAL* convert name to SID function.
- Tries local lookup first - for local domains - then uses winbind.
-*****************************************************************/  
-
-BOOL lookup_name(const char *domain, const char *name, DOM_SID *psid, enum SID_NAME_USE *name_type)
-{
-       fstring sid;
-       BOOL local_lookup = False;
-       
-       *name_type = SID_NAME_UNKNOWN;
-
-       /* If we are looking up a domain user, make sure it is
-          for the local machine only */
-       
-       if (strequal(global_myname(), domain)) {
-               local_lookup = True;
-       } else if (lp_server_role() == ROLE_DOMAIN_PDC || 
-                  lp_server_role() == ROLE_DOMAIN_BDC) {
-               if (strequal(domain, lp_workgroup())) {
-                       local_lookup = True;
-               }
-       }
-               
-       if (local_lookup) {
-               if (local_lookup_name(name, psid, name_type)) {
-                       DEBUG(10,
-                             ("lookup_name: (local) [%s]\\[%s] -> SID %s (type %s: %u)\n",
-                              domain, name, sid_to_string(sid,psid),
-                              sid_type_lookup(*name_type), (unsigned int)*name_type));
-                       return True;
-               }
-       } else {
-               /* Remote */
-               if (winbind_lookup_name(domain, name, psid, name_type)) {
-                       
-                       DEBUG(10,("lookup_name (winbindd): [%s]\\[%s] -> SID %s (type %u)\n",
-                                 domain, name, sid_to_string(sid, psid), 
-                                 (unsigned int)*name_type));
-                       return True;
-               }
-       }
-       
-       DEBUG(10, ("lookup_name: %s lookup for [%s]\\[%s] failed\n", 
-                  local_lookup ? "local" : "winbind", domain, name));
-
-       return False;
-}
-
-/*****************************************************************
- *THE CANONICAL* convert SID to name function.
- Tries local lookup first - for local sids, then tries winbind.
-*****************************************************************/  
-
-BOOL lookup_sid(DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAME_USE *name_type)
-{
-       if (!name_type)
-               return False;
-
-       *name_type = SID_NAME_UNKNOWN;
-
-       /* Check if this is our own sid.  This should perhaps be done by
-          winbind?  For the moment handle it here. */
-
-       if (sid->num_auths == 5) {
-               DOM_SID tmp_sid;
-               uint32 rid;
-
-               sid_copy(&tmp_sid, sid);
-               sid_split_rid(&tmp_sid, &rid);
-
-               if (sid_equal(get_global_sam_sid(), &tmp_sid)) {
-
-                       return map_domain_sid_to_name(&tmp_sid, dom_name) &&
-                               local_lookup_sid(sid, name, name_type);
-               }
-       }
-
-       if (!winbind_lookup_sid(sid, dom_name, name, name_type)) {
-               fstring sid_str;
-               DOM_SID tmp_sid;
-               uint32 rid;
-
-               DEBUG(10,("lookup_sid: winbind lookup for SID %s failed - trying local.\n", sid_to_string(sid_str, sid) ));
-
-               sid_copy(&tmp_sid, sid);
-               sid_split_rid(&tmp_sid, &rid);
-               return map_domain_sid_to_name(&tmp_sid, dom_name) &&
-                       lookup_known_rid(&tmp_sid, rid, name, name_type);
-       }
-       return True;
-}
-
-
-/*****************************************************************
- Id mapping cache.  This is to avoid Winbind mappings already
- seen by smbd to be queried too frequently, keeping winbindd
- busy, and blocking smbd while winbindd is busy with other
- stuff. Written by Michael Steffens <michael.steffens@hp.com>,
- modified to use linked lists by jra.
-*****************************************************************/  
-
-#define MAX_UID_SID_CACHE_SIZE 100
-#define TURNOVER_UID_SID_CACHE_SIZE 10
-#define MAX_GID_SID_CACHE_SIZE 100
-#define TURNOVER_GID_SID_CACHE_SIZE 10
-
-static size_t n_uid_sid_cache = 0;
-static size_t n_gid_sid_cache = 0;
-
-static struct uid_sid_cache {
-       struct uid_sid_cache *next, *prev;
-       uid_t uid;
-       DOM_SID sid;
-       enum SID_NAME_USE sidtype;
-} *uid_sid_cache_head;
-
-static struct gid_sid_cache {
-       struct gid_sid_cache *next, *prev;
-       gid_t gid;
-       DOM_SID sid;
-       enum SID_NAME_USE sidtype;
-} *gid_sid_cache_head;
-
-/*****************************************************************
-  Find a SID given a uid.
-*****************************************************************/  
-
-static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid)
-{
-       struct uid_sid_cache *pc;
-
-       for (pc = uid_sid_cache_head; pc; pc = pc->next) {
-               if (pc->uid == uid) {
-                       fstring sid;
-                       *psid = pc->sid;
-                       DEBUG(3,("fetch sid from uid cache %u -> %s\n",
-                               (unsigned int)uid, sid_to_string(sid, psid)));
-                       DLIST_PROMOTE(uid_sid_cache_head, pc);
-                       return True;
-               }
-       }
-       return False;
-}
-
-/*****************************************************************
-  Find a uid given a SID.
-*****************************************************************/  
-
-static BOOL fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid )
-{
-       struct uid_sid_cache *pc;
-
-       for (pc = uid_sid_cache_head; pc; pc = pc->next) {
-               if (sid_compare(&pc->sid, psid) == 0) {
-                       fstring sid;
-                       *puid = pc->uid;
-                       DEBUG(3,("fetch uid from cache %u -> %s\n",
-                               (unsigned int)*puid, sid_to_string(sid, psid)));
-                       DLIST_PROMOTE(uid_sid_cache_head, pc);
-                       return True;
-               }
-       }
-       return False;
-}
-
-/*****************************************************************
- Store uid to SID mapping in cache.
-*****************************************************************/  
-
-static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
-{
-       struct uid_sid_cache *pc;
-
-       if (n_uid_sid_cache >= MAX_UID_SID_CACHE_SIZE && n_uid_sid_cache > TURNOVER_UID_SID_CACHE_SIZE) {
-               /* Delete the last TURNOVER_UID_SID_CACHE_SIZE entries. */
-               struct uid_sid_cache *pc_next;
-               size_t i;
-
-               for (i = 0, pc = uid_sid_cache_head; i < (n_uid_sid_cache - TURNOVER_UID_SID_CACHE_SIZE); i++, pc = pc->next)
-                       ;
-               for(; pc; pc = pc_next) {
-                       pc_next = pc->next;
-                       DLIST_REMOVE(uid_sid_cache_head,pc);
-                       SAFE_FREE(pc);
-                       n_uid_sid_cache--;
-               }
-       }
-
-       pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache));
-       if (!pc)
-               return;
-       pc->uid = uid;
-       sid_copy(&pc->sid, psid);
-       DLIST_ADD(uid_sid_cache_head, pc);
-       n_uid_sid_cache++;
-}
-
-/*****************************************************************
-  Find a SID given a gid.
-*****************************************************************/  
-
-static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid)
-{
-       struct gid_sid_cache *pc;
-
-       for (pc = gid_sid_cache_head; pc; pc = pc->next) {
-               if (pc->gid == gid) {
-                       fstring sid;
-                       *psid = pc->sid;
-                       DEBUG(3,("fetch sid from gid cache %u -> %s\n",
-                               (unsigned int)gid, sid_to_string(sid, psid)));
-                       DLIST_PROMOTE(gid_sid_cache_head, pc);
-                       return True;
-               }
-       }
-       return False;
-}
-
-/*****************************************************************
-  Find a gid given a SID.
-*****************************************************************/  
-
-static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid)
-{
-       struct gid_sid_cache *pc;
-
-       for (pc = gid_sid_cache_head; pc; pc = pc->next) {
-               if (sid_compare(&pc->sid, psid) == 0) {
-                       fstring sid;
-                       *pgid = pc->gid;
-                       DEBUG(3,("fetch uid from cache %u -> %s\n",
-                               (unsigned int)*pgid, sid_to_string(sid, psid)));
-                       DLIST_PROMOTE(gid_sid_cache_head, pc);
-                       return True;
-               }
-       }
-       return False;
-}
-
-/*****************************************************************
- Store gid to SID mapping in cache.
-*****************************************************************/  
 
-static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
-{
-       struct gid_sid_cache *pc;
-
-       if (n_gid_sid_cache >= MAX_GID_SID_CACHE_SIZE && n_gid_sid_cache > TURNOVER_GID_SID_CACHE_SIZE) {
-               /* Delete the last TURNOVER_GID_SID_CACHE_SIZE entries. */
-               struct gid_sid_cache *pc_next;
-               size_t i;
-
-               for (i = 0, pc = gid_sid_cache_head; i < (n_gid_sid_cache - TURNOVER_GID_SID_CACHE_SIZE); i++, pc = pc->next)
-                       ;
-               for(; pc; pc = pc_next) {
-                       pc_next = pc->next;
-                       DLIST_REMOVE(gid_sid_cache_head,pc);
-                       SAFE_FREE(pc);
-                       n_gid_sid_cache--;
-               }
-       }
-
-       pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache));
-       if (!pc)
-               return;
-       pc->gid = gid;
-       sid_copy(&pc->sid, psid);
-       DLIST_ADD(gid_sid_cache_head, pc);
-       n_gid_sid_cache++;
-}
-
-/*****************************************************************
- *THE CANONICAL* convert uid_t to SID function.
-*****************************************************************/  
-
-NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid)
-{
-       uid_t low, high;
-       fstring sid;
-
-       ZERO_STRUCTP(psid);
-
-       if (fetch_sid_from_uid_cache(psid, uid))
-               return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
-
-       if (lp_idmap_uid(&low, &high) && uid >= low && uid <= high) {
-               if (winbind_uid_to_sid(psid, uid)) {
-
-                       DEBUG(10,("uid_to_sid: winbindd %u -> %s\n",
-                               (unsigned int)uid, sid_to_string(sid, psid)));
-
-                       if (psid)
-                               store_uid_sid_cache(psid, uid);
-                       return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
-               }
-       }
-
-       if (!local_uid_to_sid(psid, uid)) {
-               DEBUG(10,("uid_to_sid: local %u failed to map to sid\n", (unsigned int)uid ));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-        
-       DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid, sid_to_string(sid, psid)));
-
-       store_uid_sid_cache(psid, uid);
-       return NT_STATUS_OK;
-}
-
-/*****************************************************************
- *THE CANONICAL* convert gid_t to SID function.
-*****************************************************************/  
-
-NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid)
-{
-       gid_t low, high;
-       fstring sid;
-
-       ZERO_STRUCTP(psid);
-
-       if (fetch_sid_from_gid_cache(psid, gid))
-               return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
-
-       if (lp_idmap_gid(&low, &high) && gid >= low && gid <= high) {
-               if (winbind_gid_to_sid(psid, gid)) {
-
-                       DEBUG(10,("gid_to_sid: winbindd %u -> %s\n",
-                               (unsigned int)gid, sid_to_string(sid, psid)));
-                        
-                       if (psid)
-                               store_gid_sid_cache(psid, gid);
-                       return ( psid ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL );
-               }
-       }
-
-       if (!local_gid_to_sid(psid, gid)) {
-               DEBUG(10,("gid_to_sid: local %u failed to map to sid\n", (unsigned int)gid ));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-        
-       DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid, sid_to_string(sid, psid)));
-
-       store_gid_sid_cache(psid, gid);
-       return NT_STATUS_OK;
-}
-
-/*****************************************************************
- *THE CANONICAL* convert SID to uid function.
-*****************************************************************/  
-
-NTSTATUS sid_to_uid(const DOM_SID *psid, uid_t *puid)
-{
-       fstring dom_name, name, sid_str;
-       enum SID_NAME_USE name_type;
-
-       if (fetch_uid_from_cache(puid, psid))
-               return NT_STATUS_OK;
-
-       /* if this is our SID then go straight to a local lookup */
-       
-       if ( sid_compare_domain(get_global_sam_sid(), psid) == 0 ) {
-               DEBUG(10,("sid_to_uid: my domain (%s) - trying local.\n",
-                       sid_string_static(psid) ));
-               
-               if ( local_sid_to_uid(puid, psid, &name_type) )
-                       goto success;
-                       
-               DEBUG(10,("sid_to_uid: local lookup failed\n"));
-               
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-       
-       /* If it is not our local domain, only hope is winbindd */
-
-       if ( !winbind_lookup_sid(psid, dom_name, name, &name_type) ) {
-               DEBUG(10,("sid_to_uid: winbind lookup for non-local sid %s failed\n",
-                       sid_string_static(psid) ));
-                       
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       /* If winbindd does know the SID, ensure this is a user */
-
-       if (name_type != SID_NAME_USER) {
-               DEBUG(10,("sid_to_uid: winbind lookup succeeded but SID is not a user (%u)\n",
-                       (unsigned int)name_type ));
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       /* get the uid.  Has to work or else we are dead in the water */
-
-       if ( !winbind_sid_to_uid(puid, psid) ) {
-               DEBUG(10,("sid_to_uid: winbind failed to allocate a new uid for sid %s\n",
-                       sid_to_string(sid_str, psid) ));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-success:
-       DEBUG(10,("sid_to_uid: %s -> %u\n", sid_to_string(sid_str, psid),
-               (unsigned int)*puid ));
-
-       store_uid_sid_cache(psid, *puid);
-       
-       return NT_STATUS_OK;
-}
-/*****************************************************************
- *THE CANONICAL* convert SID to gid function.
- Group mapping is used for gids that maps to Wellknown SIDs
-*****************************************************************/  
-
-NTSTATUS sid_to_gid(const DOM_SID *psid, gid_t *pgid)
-{
-       fstring dom_name, name, sid_str;
-       enum SID_NAME_USE name_type;
-
-       if (fetch_gid_from_cache(pgid, psid))
-               return NT_STATUS_OK;
-
-       /*
-        * First we must look up the name and decide if this is a group sid.
-        * Group mapping can deal with foreign SIDs
-        */
-
-       if (!winbind_lookup_sid(psid, dom_name, name, &name_type)) {
-               DEBUG(10,("sid_to_gid: winbind lookup for sid %s failed - trying local.\n",
-                       sid_to_string(sid_str, psid) ));
-
-               if ( local_sid_to_gid(pgid, psid, &name_type) )
-                       goto success;
-                       
-               DEBUG(10,("sid_to_gid: no one knows this SID\n"));
-               
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       /* winbindd knows it; Ensure this is a group sid */
-
-       if ((name_type != SID_NAME_DOM_GRP) && (name_type != SID_NAME_ALIAS) && (name_type != SID_NAME_WKN_GRP)) {
-               DEBUG(10,("sid_to_gid: winbind lookup succeeded but SID is not a known group (%u)\n",
-                       (unsigned int)name_type ));
-
-               /* winbindd is running and knows about this SID.  Just the wrong type.
-                  Don't fallback to a local lookup here */
-                  
-               return NT_STATUS_INVALID_PARAMETER;
-       }
-       
-       /* winbindd knows it and it is a type of group; sid_to_gid must succeed
-          or we are dead in the water */
-
-       if ( !winbind_sid_to_gid(pgid, psid) ) {
-               DEBUG(10,("sid_to_uid: winbind failed to allocate a new gid for sid %s\n",
-                       sid_to_string(sid_str, psid) ));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-success:
-       DEBUG(10,("sid_to_gid: %s -> %u\n", sid_to_string(sid_str, psid),
-               (unsigned int)*pgid ));
-
-       store_gid_sid_cache(psid, *pgid);
-       
-       return NT_STATUS_OK;
-}
index 6ff2f586bae46feff795a987b858173300004da6..a521d0113d469501d3fbe11c2efa763e35dbbbb7 100644 (file)
@@ -217,13 +217,13 @@ static void uw_pathname(pstring fname, const char *uw_name, const char *uw_defau
        /* For w-files, first look for explicit "wtmp dir" */
        if (uw_name[0] == 'w') {
                pstrcpy(dirname,lp_wtmpdir());
-               trim_string(dirname,"","/");
+               trim_char(dirname,'\0','/');
        }
 
        /* For u-files and non-explicit w-dir, look for "utmp dir" */
        if (dirname == 0 || strlen(dirname) == 0) {
                pstrcpy(dirname,lp_utmpdir());
-               trim_string(dirname,"","/");
+               trim_char(dirname,'\0','/');
        }
 
        /* If explicit directory above, use it */
@@ -283,8 +283,12 @@ static void updwtmp_my(pstring wname, struct utmp *u, BOOL claim)
                 *      man page appears not to specify (hints non-NULL)
                 *      A correspondent suggest at least ut_name should be NULL
                 */
+#if defined(HAVE_UT_UT_NAME)
                memset((char *)&u->ut_name, '\0', sizeof(u->ut_name));
+#endif
+#if defined(HAVE_UT_UT_HOST)
                memset((char *)&u->ut_host, '\0', sizeof(u->ut_host));
+#endif
        }
        /* Stolen from logwtmp function in libutil.
         * May be more locking/blocking is needed?
@@ -406,7 +410,9 @@ static void sys_utmp_update(struct utmp *u, const char *hostname, BOOL claim)
        else
                ux.ut_syslen = 0;
 #endif
+#if defined(HAVE_UT_UT_HOST)
        utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
+#endif
 
        uw_pathname(uname, "utmpx", ux_pathname);
        uw_pathname(wname, "wtmpx", wx_pathname);
index 8d44a1a0fa12ac44a45af07152986f89caa7d7f5..a76a7a6abdcd22413a4e20755bfed64da4d3f0ea 100644 (file)
@@ -49,6 +49,42 @@ SMB_BIG_UINT vfswrap_disk_free(vfs_handle_struct *handle, connection_struct *con
     result = sys_disk_free(path, small_query, bsize, dfree, dsize);
     return result;
 }
+
+int vfswrap_get_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+{
+#ifdef HAVE_SYS_QUOTAS
+       int result;
+
+       START_PROFILE(syscall_get_quota);
+       result = sys_get_quota(conn->connectpath, qtype, id, qt);
+       END_PROFILE(syscall_get_quota);
+       return result;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif 
+}
+
+int vfswrap_set_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+{
+#ifdef HAVE_SYS_QUOTAS
+       int result;
+
+       START_PROFILE(syscall_set_quota);
+       result = sys_set_quota(conn->connectpath, qtype, id, qt);
+       END_PROFILE(syscall_set_quota);
+       return result;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif 
+}
+
+int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels)
+{
+       errno = ENOSYS;
+       return -1;  /* Not implemented. */
+}
     
 /* Directory operations */
 
@@ -756,36 +792,6 @@ int vfswrap_sys_acl_free_qualifier(vfs_handle_struct *handle, connection_struct
        return sys_acl_free_qualifier(qualifier, tagtype);
 }
 
-int vfswrap_get_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
-{
-#ifdef HAVE_SYS_QUOTAS
-       int result;
-
-       START_PROFILE(syscall_get_quota);
-       result = sys_get_quota(conn->connectpath, qtype, id, qt);
-       END_PROFILE(syscall_get_quota);
-       return result;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif 
-}
-
-int vfswrap_set_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
-{
-#ifdef HAVE_SYS_QUOTAS
-       int result;
-
-       START_PROFILE(syscall_set_quota);
-       result = sys_set_quota(conn->connectpath, qtype, id, qt);
-       END_PROFILE(syscall_set_quota);
-       return result;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif 
-}
-
 /****************************************************************
  Extended attribute operations.
 *****************************************************************/
index 5f3abe7efea5b43dbda54b462cd9fcd6d4e36787..753db4cece385e28ec9647c080fdde3ee968ee9f 100644 (file)
@@ -56,6 +56,7 @@ static struct vfs_ops default_vfs = {
                vfswrap_disk_free,
                vfswrap_get_quota,
                vfswrap_set_quota,
+               vfswrap_get_shadow_copy_data,
        
                /* Directory operations */
        
@@ -140,7 +141,6 @@ static struct vfs_ops default_vfs = {
                vfswrap_setxattr,
                vfswrap_lsetxattr,
                vfswrap_fsetxattr
-
        }
 };
 
@@ -233,10 +233,10 @@ BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object)
        if (p) {
                *p = 0;
                module_param = p+1;
-               trim_string(module_param, " ", " ");
+               trim_char(module_param, ' ', ' ');
        }
 
-       trim_string(module_name, " ", " ");
+       trim_char(module_name, ' ', ' ');
 
        /* First, try to load the module with the new module system */
        if((entry = vfs_find_backend_entry(module_name)) || 
index 34681ea78f28fea90617ad1699fae9e37abd7eef..f5809ef63ad3d3ad9de4037ee69aca4a3d41bb2d 100644 (file)
@@ -1015,12 +1015,11 @@ static int tdb_keylocked(TDB_CONTEXT *tdb, u32 hash)
 }
 
 /* As tdb_find, but if you succeed, keep the lock */
-static tdb_off tdb_find_lock(TDB_CONTEXT *tdb, TDB_DATA key, int locktype,
+static tdb_off tdb_find_lock_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash, int locktype,
                             struct list_struct *rec)
 {
-       u32 hash, rec_ptr;
+       u32 rec_ptr;
 
-       hash = tdb_hash(&key);
        if (!tdb_keylocked(tdb, hash))
                return 0;
        if (tdb_lock(tdb, BUCKET(hash), locktype) == -1)
@@ -1061,13 +1060,13 @@ const char *tdb_errorstr(TDB_CONTEXT *tdb)
    on failure return -1.
 */
 
-static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
+static int tdb_update_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash, TDB_DATA dbuf)
 {
        struct list_struct rec;
        tdb_off rec_ptr;
 
        /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, tdb_hash(&key), &rec)))
+       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec)))
                return -1;
 
        /* must be long enough key, data and tailer */
@@ -1101,9 +1100,11 @@ TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
        tdb_off rec_ptr;
        struct list_struct rec;
        TDB_DATA ret;
+       u32 hash;
 
        /* find which hash bucket it is in */
-       if (!(rec_ptr = tdb_find_lock(tdb,key,F_RDLCK,&rec)))
+       hash = tdb_hash(&key);
+       if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec)))
                return tdb_null;
 
        if (rec.data_len)
@@ -1122,16 +1123,22 @@ TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
    this doesn't match the conventions in the rest of this module, but is
    compatible with gdbm
 */
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
+static int tdb_exists_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash)
 {
        struct list_struct rec;
        
-       if (tdb_find_lock(tdb, key, F_RDLCK, &rec) == 0)
+       if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0)
                return 0;
        tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK);
        return 1;
 }
 
+int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
+{
+       u32 hash = tdb_hash(&key);
+       return tdb_exists_hash(tdb, key, hash);
+}
+
 /* record lock stops delete underneath */
 static int lock_record(TDB_CONTEXT *tdb, tdb_off off)
 {
@@ -1388,7 +1395,7 @@ TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA oldkey)
 
        if (!tdb->travlocks.off) {
                /* No previous element: do normal find, and lock record */
-               tdb->travlocks.off = tdb_find_lock(tdb, oldkey, F_WRLCK, &rec);
+               tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb_hash(&oldkey), F_WRLCK, &rec);
                if (!tdb->travlocks.off)
                        return tdb_null;
                tdb->travlocks.hash = BUCKET(rec.full_hash);
@@ -1416,13 +1423,13 @@ TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA oldkey)
 }
 
 /* delete an entry in the database given a key */
-int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
+static int tdb_delete_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash)
 {
        tdb_off rec_ptr;
        struct list_struct rec;
        int ret;
 
-       if (!(rec_ptr = tdb_find_lock(tdb, key, F_WRLCK, &rec)))
+       if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK, &rec)))
                return -1;
        ret = do_delete(tdb, rec_ptr, &rec);
        if (tdb_unlock(tdb, BUCKET(rec.full_hash), F_WRLCK) != 0)
@@ -1430,6 +1437,12 @@ int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
        return ret;
 }
 
+int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
+{
+       u32 hash = tdb_hash(&key);
+       return tdb_delete_hash(tdb, key, hash);
+}
+
 /* store an element in the database, replacing any existing element
    with the same key 
 
@@ -1452,13 +1465,13 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
 
        /* check for it existing, on insert. */
        if (flag == TDB_INSERT) {
-               if (tdb_exists(tdb, key)) {
+               if (tdb_exists_hash(tdb, key, hash)) {
                        tdb->ecode = TDB_ERR_EXISTS;
                        goto fail;
                }
        } else {
                /* first try in-place update, on modify or replace. */
-               if (tdb_update(tdb, key, dbuf) == 0)
+               if (tdb_update_hash(tdb, key, hash, dbuf) == 0)
                        goto out;
                if (flag == TDB_MODIFY && tdb->ecode == TDB_ERR_NOEXIST)
                        goto fail;
@@ -1470,7 +1483,7 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
            care.  Doing this first reduces fragmentation, and avoids
            coalescing with `allocated' block before it's updated. */
        if (flag != TDB_INSERT)
-               tdb_delete(tdb, key);
+               tdb_delete_hash(tdb, key, hash);
 
        /* Copy key+value *before* allocating free space in case malloc
           fails and we are left with a dead spot in the tdb. */
@@ -1519,13 +1532,13 @@ fail:
    is <= the old data size and the key exists.
    on failure return -1. Record must be locked before calling.
 */
-static int tdb_append_inplace(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
+static int tdb_append_inplace(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash, TDB_DATA new_dbuf)
 {
        struct list_struct rec;
        tdb_off rec_ptr;
 
        /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, tdb_hash(&key), &rec)))
+       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec)))
                return -1;
 
        /* Append of 0 is always ok. */
@@ -1567,7 +1580,7 @@ int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
                return -1;
 
        /* first try in-place. */
-       if (tdb_append_inplace(tdb, key, new_dbuf) == 0)
+       if (tdb_append_inplace(tdb, key, hash, new_dbuf) == 0)
                goto out;
 
        /* reset the error code potentially set by the tdb_append_inplace() */
@@ -1610,7 +1623,7 @@ int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
            care.  Doing this first reduces fragmentation, and avoids
            coalescing with `allocated' block before it's updated. */
 
-       tdb_delete(tdb, key);
+       tdb_delete_hash(tdb, key, hash);
 
        if (!(rec_ptr = tdb_allocate(tdb, key.dsize + new_data_size, &rec)))
                goto fail;
index d91dbf50e022d6462a729debda9dd59ae47c1e4a..8317a57a20dbecb7df42cc502537e225d32c10d0 100644 (file)
@@ -490,8 +490,8 @@ static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        int ret;
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -533,6 +533,7 @@ static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
+
        SAFE_FREE(pwd);
        SAFE_FREE(grp);
        return NT_STATUS_OK;
@@ -544,8 +545,8 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        int fd;
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -596,6 +597,7 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
+
        SAFE_FREE(pwd);
        SAFE_FREE(grp);
        return NT_STATUS_OK;
@@ -606,8 +608,8 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 {
        const char *user;
        const char *group;
-       struct passwd *pwd;
-       struct group *grp;
+       struct passwd *pwd = NULL;
+       struct group *grp = NULL;
        SMB_STRUCT_STAT st;
 
        if (argc != 2) {
@@ -647,6 +649,7 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        printf("  Access: %s", ctime(&(st.st_atime)));
        printf("  Modify: %s", ctime(&(st.st_mtime)));
        printf("  Change: %s", ctime(&(st.st_ctime)));
+       
        SAFE_FREE(pwd);
        SAFE_FREE(grp);
        return NT_STATUS_OK;
index fa901e3d63d4067ea54f410cbf89f9f0dd8c9a8f..8c44f35f958ea4f81ad922c7a54086384f7064c8 100644 (file)
@@ -140,7 +140,7 @@ static BOOL reg_match_one(struct cli_state *cli, const char *pattern, const char
 
        if (strcmp(file,"..") == 0) file = ".";
 
-       return ms_fnmatch(pattern, file, cli->protocol)==0;
+       return ms_fnmatch(pattern, file, cli->protocol, False /* not case sensitive */)==0;
 }
 
 static char *reg_test(struct cli_state *cli, char *pattern, char *long_name, char *short_name)
index 8dfaebd64fae68eee83667509352b6250edd5eb8..d95c0cee0fe98d41e8a61dd988e19f2bf2e9b392 100644 (file)
@@ -193,7 +193,7 @@ static void usage(char *pname)
   fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
           pname);
 
-  fprintf(out_hnd, "\nVersion %s\n",VERSION);
+  fprintf(out_hnd, "\nVersion %s\n",SAMBA_VERSION_STRING);
   fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
   fprintf(out_hnd, "\t-l log basename.      Basename for log/debug files\n");
   fprintf(out_hnd, "\t-n netbios name.      Use this name as my netbios name\n");
@@ -489,7 +489,7 @@ enum client_action
        strupper_m(global_myname);
        fstrcpy(cli_info.myhostname, global_myname);
 
-       DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION));
+       DEBUG(3,("%s client started (version %s)\n",timestring(False),SAMBA_VERSION_STRING));
 
        if (*smb_cli->domain == 0)
        {
index 3524136fb1e786c99f9732f70e88ed133d13e100..1dd168b0bb0047f002b4af50fa92fa9db971dca3 100644 (file)
@@ -24,7 +24,7 @@
 #include "includes.h"
 
 static int
-process_block (smb_iconv_t cd, char *addr, size_t len, FILE *output)
+process_block (smb_iconv_t cd, const char *addr, size_t len, FILE *output)
 {
 #define OUTBUF_SIZE    32768
   const char *start = addr;
@@ -37,7 +37,7 @@ process_block (smb_iconv_t cd, char *addr, size_t len, FILE *output)
     {
       outptr = outbuf;
       outlen = OUTBUF_SIZE;
-      n = smb_iconv (cd, &addr, &len, &outptr, &outlen);
+      n = smb_iconv (cd,  &addr, &len, &outptr, &outlen);
 
       if (outptr != outbuf)
        {
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
        char *from = "";
        char *to = "";
        char *output = NULL;
-       char *preload = NULL;
+       const char *preload_modules[] = {NULL, NULL};
        FILE *out = stdout;
        int fd;
        smb_iconv_t cd;
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
                { "from-code", 'f', POPT_ARG_STRING, &from, 0, "Encoding of original text" },
                { "to-code", 't', POPT_ARG_STRING, &to, 0, "Encoding for output" },
                { "output", 'o', POPT_ARG_STRING, &output, 0, "Write output to this file" },
-               { "preload-modules", 'p', POPT_ARG_STRING, &preload, 0, "Modules to load" },
+               { "preload-modules", 'p', POPT_ARG_STRING, &preload_modules[0], 0, "Modules to load" },
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
@@ -202,12 +202,12 @@ int main(int argc, char *argv[])
           facilities.  See lib/debug.c */
        setup_logging("smbiconv", True);
 
-       if(preload)smb_load_modules(str_list_make(preload, NULL));
+       if (preload_modules[0]) smb_load_modules(preload_modules);
 
        if(output) {
-               output = fopen(output, "w");
+               out = fopen(output, "w");
 
-               if(!output) {
+               if(!out) {
                        DEBUG(0, ("Can't open output file '%s': %s, exiting...\n", output, strerror(errno)));
                        return 1;
                }
@@ -231,7 +231,7 @@ int main(int argc, char *argv[])
                }
 
                /* Loop thru all arguments */
-               process_fd(cd, fd, stdout);
+               process_fd(cd, fd, out);
 
                close(fd);
        }
diff --git a/source3/utils/log2pcaphex.c b/source3/utils/log2pcaphex.c
new file mode 100644 (file)
index 0000000..4804b99
--- /dev/null
@@ -0,0 +1,294 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Utility to extract pcap files from samba (log level 10) log files
+
+   Copyright (C) Jelmer Vernooij 2003
+   Thanks to Tim Potter for the genial idea
+
+   Portions (from capconvert.c) (C) Andrew Tridgell 1997
+   Portions (from text2pcap.c) (C) Ashok Narayanan 2001
+
+   Example use with -h parameter: 
+       log2pcaphex < samba-log-file | text2pcap -T 139,139 - foo.pcap
+
+   TODO: Have correct IP and TCP checksums.
+
+   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
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.
+*/
+
+#include "includes.h"
+#include <assert.h>
+
+int quiet = 0;
+int hexformat = 0;
+
+#define itoa(a) ((a) < 0xa?'0'+(a):'A' + (a-0xa))
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#define TCPDUMP_MAGIC 0xa1b2c3d4
+
+/* tcpdump file format */
+struct tcpdump_file_header {
+       uint32 magic;
+       uint16 major;
+       uint16 minor;
+       int32 zone;
+       uint32 sigfigs;
+       uint32 snaplen;
+       uint32 linktype;
+};
+
+struct tcpdump_packet {
+       struct timeval ts;
+       uint32 caplen;
+       uint32 len;
+};
+
+typedef struct {
+    uint8  ver_hdrlen;
+    uint8  dscp;
+    uint16 packet_length;
+    uint16 identification;
+    uint8  flags;
+    uint8  fragment;
+    uint8  ttl;
+    uint8  protocol;
+    uint16 hdr_checksum;
+    uint32 src_addr;
+    uint32 dest_addr;
+} hdr_ip_t;
+
+static hdr_ip_t HDR_IP = {0x45, 0, 0, 0x3412, 0, 0, 0xff, 6, 0, 0x01010101, 0x02020202};
+
+typedef struct {
+    uint16 source_port;
+    uint16 dest_port;
+    uint32 seq_num;
+    uint32 ack_num;
+    uint8  hdr_length;
+    uint8  flags;
+    uint16 window;
+    uint16 checksum;
+    uint16 urg;
+} hdr_tcp_t;
+
+static hdr_tcp_t HDR_TCP = {139, 139, 0, 0, 0x50, 0, 0, 0, 0};
+
+void print_pcap_header(FILE *out)
+{
+       struct tcpdump_file_header h;
+       h.magic = TCPDUMP_MAGIC;
+       h.major = 2;
+       h.minor = 4;
+       h.zone = 0;
+       h.sigfigs = 0;
+       h.snaplen = 102400; /* As long packets as possible */
+       h.linktype = 101; /* Raw IP */
+       fwrite(&h, sizeof(struct tcpdump_file_header), 1, out);
+}
+
+void print_pcap_packet(FILE *out, unsigned char *data, long length, long caplen)
+{
+       static int i = 0;
+       struct tcpdump_packet p;
+       i++;
+       p.ts.tv_usec = 0;
+       p.ts.tv_sec = 0;
+       p.caplen = caplen;
+       p.len = length;
+       fwrite(&p, sizeof(struct tcpdump_packet), 1, out);
+       fwrite(data, sizeof(unsigned char), caplen, out);
+}
+
+void print_hex_packet(FILE *out, unsigned char *data, long length)
+{
+       long i,cur = 0;
+       while(cur < length) {
+               fprintf(out, "%06lX ", cur);
+               for(i = cur; i < length && i < cur + 16; i++) {
+                       fprintf(out, "%02x ", data[i]);
+               }
+       
+               cur = i;
+               fprintf(out, "\n");
+       }
+}
+
+void print_netbios_packet(FILE *out, unsigned char *data, long length, long actual_length)
+{      
+       unsigned char *newdata; long offset = 0;
+       long newlen;
+       
+       newlen = length+sizeof(HDR_IP)+sizeof(HDR_TCP);
+       newdata = malloc(newlen);
+
+       HDR_IP.packet_length = htons(newlen);
+       HDR_TCP.window = htons(0x2000);
+       HDR_TCP.source_port = HDR_TCP.dest_port = htons(139);
+
+       memcpy(newdata+offset, &HDR_IP, sizeof(HDR_IP));offset+=sizeof(HDR_IP);
+       memcpy(newdata+offset, &HDR_TCP, sizeof(HDR_TCP));offset+=sizeof(HDR_TCP);
+       memcpy(newdata+offset,data,length);
+       
+       print_pcap_packet(out, newdata, newlen, actual_length+offset);
+       free(newdata);
+}
+
+unsigned char *curpacket = NULL;
+long curpacket_len = 0;
+
+void read_log_msg(FILE *in, unsigned char **_buffer, long *buffersize, long *data_offset, long *data_length)
+{
+       unsigned char *buffer;
+       int tmp; long i;
+       assert(fscanf(in, " size=%ld\n", buffersize));
+       *buffersize+=4; /* for netbios */
+       buffer = malloc(*buffersize);
+       memset(buffer, 0, *buffersize);
+       /* NetBIOS */
+       buffer[0] = 0x00;
+       buffer[1] = 0x00;
+       memcpy(buffer+2, &buffersize, 2);
+       buffer[4] = 0xFF;
+       buffer[5] = 'S';
+       buffer[6] = 'M';
+       buffer[7] = 'B';
+       assert(fscanf(in, "  smb_com=0x%x\n", &tmp)); buffer[smb_com] = tmp;
+       assert(fscanf(in, "  smb_rcls=%d\n", &tmp)); buffer[smb_rcls] = tmp;
+       assert(fscanf(in, "  smb_reh=%d\n", &tmp)); buffer[smb_reh] = tmp;
+       assert(fscanf(in, "  smb_err=%d\n", &tmp)); memcpy(buffer+smb_err, &tmp, 2);
+       assert(fscanf(in, "  smb_flg=%d\n", &tmp)); buffer[smb_flg] = tmp;
+       assert(fscanf(in, "  smb_flg2=%d\n", &tmp)); memcpy(buffer+smb_flg2, &tmp, 2);
+       assert(fscanf(in, "  smb_tid=%d\n", &tmp)); memcpy(buffer+smb_tid, &tmp, 2);
+       assert(fscanf(in, "  smb_pid=%d\n", &tmp)); memcpy(buffer+smb_pid, &tmp, 2);
+       assert(fscanf(in, "  smb_uid=%d\n", &tmp)); memcpy(buffer+smb_uid, &tmp, 2);
+       assert(fscanf(in, "  smb_mid=%d\n", &tmp)); memcpy(buffer+smb_mid, &tmp, 2);
+       assert(fscanf(in, "  smt_wct=%d\n", &tmp)); buffer[smb_wct] = tmp;
+       for(i = 0; i < buffer[smb_wct]; i++) {
+               assert(fscanf(in, "  smb_vwv[%*2d]=%*5d (0x%X)\n", &tmp));
+               memcpy(buffer+smb_vwv+i*2, &tmp, 2);
+       }
+
+       *data_offset = smb_vwv+buffer[smb_wct]*2;
+       assert(fscanf(in, "  smb_bcc=%ld\n", data_length)); buffer[(*data_offset)] = *data_length;
+       (*data_offset)+=2;
+       *_buffer = buffer;
+}
+
+long read_log_data(FILE *in, unsigned char *buffer, long data_length)
+{
+       long i, addr; char real[2][16]; int ret;
+       unsigned char tmp;
+       for(i = 0; i < data_length; i++) {
+               if(i % 16 == 0){
+                       if(i != 0) { /* Read data after each line */
+                               assert(fscanf(in, "%8s %8s", real[0], real[1]) == 2);
+                       }
+                       ret = fscanf(in, "  [%03lX]", &addr);
+                       if(!ret) {
+                               if(!quiet)fprintf(stderr, "Only first %ld bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i);
+                               return i-1;
+                       }
+                       assert(addr == i);
+               }
+               if(!fscanf(in, "%02lX", &tmp)) {
+                       if(!quiet)fprintf(stderr, "Only first %ld bytes are logged, packet trace will be incomplete\nTry a higher log level\n", i-1);
+                       return i-1;
+               }
+               buffer[i] = tmp;
+       }
+       return data_length;
+}
+
+int main (int argc, char **argv)
+{
+       const char *infile, *outfile;
+       FILE *out, *in;
+       int opt;
+       poptContext pc;
+       char buffer[4096];
+       long data_offset, data_length;
+       long data_bytes_read;
+       int in_packet = 0;
+       struct poptOption long_options[] = {
+               POPT_AUTOHELP
+               { "quiet", 'q', POPT_ARG_NONE, &quiet, 0, "Be quiet, don't output warnings" },
+               { "hex", 'h', POPT_ARG_NONE, &hexformat, 0, "Output format readable by text2pcap" },
+               POPT_TABLEEND
+       };
+       
+       pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
+                           POPT_CONTEXT_KEEP_FIRST);
+       poptSetOtherOptionHelp(pc, "[<infile> [<outfile>]]");
+       
+       
+       while((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               }
+       }
+
+       poptGetArg(pc); /* Drop argv[0], the program name */
+
+       infile = poptGetArg(pc);
+
+       if(infile) {
+               in  = fopen(infile, "r");
+               if(!in) {
+                       perror("fopen");
+                       return 1;
+               }
+       } else in = stdin;
+       
+       outfile = poptGetArg(pc);
+
+       if(outfile) {
+               out = fopen(outfile, "w+");
+               if(!out) { 
+                       perror("fopen"); 
+                       fprintf(stderr, "Can't find %s, using stdout...\n", outfile);
+               }
+       }
+
+       if(!outfile) out = stdout;
+
+       if(!hexformat)print_pcap_header(out);
+
+       while(!feof(in)) {
+               fgets(buffer, sizeof(buffer), in);
+               if(buffer[0] == '[') { /* Header */
+                       if(strstr(buffer, "show_msg")) {
+                               in_packet++;
+                               if(in_packet == 1)continue;
+                               read_log_msg(in, &curpacket, &curpacket_len, &data_offset, &data_length);
+                       } else if(in_packet && strstr(buffer, "dump_data")) {
+                               data_bytes_read = read_log_data(in, curpacket+data_offset, data_length);
+                       }  else { 
+                               if(in_packet){ 
+                                       if(hexformat) print_hex_packet(out, curpacket, curpacket_len); 
+                                       else print_netbios_packet(out, curpacket, curpacket_len, data_bytes_read+data_offset);
+                                       free(curpacket); 
+                               }
+                               in_packet = 0;
+                       }
+               } 
+       }
+
+       return 0;
+}
index 8f6b09a3fa4f7f2329f092e4d3334ae44410a7a9..e5c078da29f1b71f62f7695f5360f55e9b76bdec 100644 (file)
@@ -181,6 +181,27 @@ NTSTATUS connect_to_ipc_anonymous(struct cli_state **c,
        }
 }
 
+/****************************************************************************
+ Use the local machine's password for this session
+****************************************************************************/
+int net_use_machine_password(void) 
+{
+       char *user_name = NULL;
+
+       if (!secrets_init()) {
+               d_printf("ERROR: Unable to open secrets database\n");
+               exit(1);
+       }
+
+       user_name = NULL;
+       opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
+       if (asprintf(&user_name, "%s$@%s", global_myname(), lp_realm()) == -1) {
+               return -1;
+       }
+       opt_user_name = user_name;
+       return 0;
+}
+
 BOOL net_find_server(unsigned flags, struct in_addr *server_ip, char **server_name)
 {
 
@@ -321,7 +342,7 @@ static int net_join(int argc, const char **argv)
                if (net_ads_join(argc, argv) == 0)
                        return 0;
                else
-                       d_printf("ADS join did not work, trying RPC...\n");
+                       d_printf("ADS join did not work, falling back to RPC...\n");
        }
        return net_rpc_join(argc, argv);
 }
@@ -334,6 +355,31 @@ static int net_changetrustpw(int argc, const char **argv)
        return net_rpc_changetrustpw(argc, argv);
 }
 
+static int net_changesecretpw(int argc, const char **argv)
+{
+        char *trust_pw;
+        uint32 sec_channel_type = SEC_CHAN_WKSTA;
+
+       if(opt_force) {
+               trust_pw = getpass("Enter machine password: ");
+
+               if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) {
+                           d_printf("Unable to write the machine account password in the secrets database");
+                           return 1;
+               }
+               else {
+                   d_printf("Modified trust account password in secrets database\n");
+               }
+       }
+       else {
+               d_printf("Machine account password change requires the -f flag.\n");
+               d_printf("Do NOT use this function unless you know what it does!\n");
+               d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n");
+       }
+
+        return 0;
+}
+
 static int net_share(int argc, const char **argv)
 {
        if (net_rpc_check(0))
@@ -416,6 +462,50 @@ static int net_getdomainsid(int argc, const char **argv)
        return 0;
 }
 
+#ifdef WITH_FAKE_KASERVER
+
+int net_afskey_usage(int argc, const char **argv)
+{
+       d_printf("  net afskey filename\n"
+                "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
+       return -1;
+}
+
+static int net_afskey(int argc, const char **argv)
+{
+       int fd;
+       struct afs_keyfile keyfile;
+
+       if (argc != 1) {
+               d_printf("usage: 'net afskey <keyfile>'\n");
+               return -1;
+       }
+
+       if (!secrets_init()) {
+               d_printf("Could not open secrets.tdb\n");
+               return -1;
+       }
+
+       if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
+               d_printf("Could not open %s\n", argv[0]);
+               return -1;
+       }
+
+       if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
+               d_printf("Could not read keyfile\n");
+               return -1;
+       }
+
+       if (!secrets_store_afs_keyfile(afs_cell(), &keyfile)) {
+               d_printf("Could not write keyfile to secrets.tdb\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+#endif /* WITH_FAKE_KASERVER */
+
 static uint32 get_maxrid(void)
 {
        SAM_ACCOUNT *pwd = NULL;
@@ -516,6 +606,7 @@ static struct functable net_func[] = {
        {"SERVICE", net_rap_service},   
        {"PASSWORD", net_rap_password},
        {"CHANGETRUSTPW", net_changetrustpw},
+       {"CHANGESECRETPW", net_changesecretpw},
        {"TIME", net_time},
        {"LOOKUP", net_lookup},
        {"JOIN", net_join},
@@ -525,6 +616,9 @@ static struct functable net_func[] = {
        {"GETDOMAINSID", net_getdomainsid},
        {"MAXRID", net_maxrid},
        {"IDMAP", net_idmap},
+#ifdef WITH_FAKE_KASERVER
+       {"AFSKEY", net_afskey},
+#endif
 
        {"HELP", net_help},
        {NULL, NULL}
@@ -649,23 +743,10 @@ static struct functable net_func[] = {
        sec_init();
 
        if (opt_machine_pass) {
-               char *user = NULL;
                /* it is very useful to be able to make ads queries as the
                   machine account for testing purposes and for domain leave */
 
-               if (!secrets_init()) {
-                       d_printf("ERROR: Unable to open secrets database\n");
-                       exit(1);
-               }
-
-               opt_password = secrets_fetch_machine_password(opt_workgroup, NULL, NULL);
-
-               asprintf(&user,"%s$", global_myname());
-               opt_user_name = user;
-               if (!opt_password) {
-                       d_printf("ERROR: Unable to fetch machine password\n");
-                       exit(1);
-               }
+               net_use_machine_password();
        }
 
        if (!opt_password) {
index 631e235127559a6d06c035e5f8ab05da413eab8a..3b955742d845e7102378177f28e7c4294b316d51 100644 (file)
@@ -127,9 +127,14 @@ static ADS_STRUCT *ads_startup(void)
        ADS_STATUS status;
        BOOL need_password = False;
        BOOL second_time = False;
-       char *cp;
+       char *cp;
        
-       ads = ads_init(NULL, opt_target_workgroup, opt_host);
+       /* lp_realm() should be handled by a command line param, 
+          However, the join requires that realm be set in smb.conf
+          and compares our realm with the remote server's so this is
+          ok until someone needs more flexibility */
+          
+       ads = ads_init(lp_realm(), opt_target_workgroup, opt_host);
 
        if (!opt_user_name) {
                opt_user_name = "administrator";
@@ -579,10 +584,7 @@ static int net_ads_leave(int argc, const char **argv)
        }
 
        if (!opt_password) {
-               char *user_name;
-               asprintf(&user_name, "%s$", global_myname());
-               opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
-               opt_user_name = user_name;
+               net_use_machine_password();
        }
 
        if (!(ads = ads_startup())) {
@@ -603,7 +605,6 @@ static int net_ads_leave(int argc, const char **argv)
 
 static int net_ads_join_ok(void)
 {
-       char *user_name;
        ADS_STRUCT *ads = NULL;
 
        if (!secrets_init()) {
@@ -611,9 +612,7 @@ static int net_ads_join_ok(void)
                return -1;
        }
 
-       asprintf(&user_name, "%s$", global_myname());
-       opt_user_name = user_name;
-       opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
+       net_use_machine_password();
 
        if (!(ads = ads_startup())) {
                return -1;
@@ -648,6 +647,7 @@ int net_ads_join(int argc, const char **argv)
        ADS_STRUCT *ads;
        ADS_STATUS rc;
        char *password;
+       char *machine_account = NULL;
        char *tmp_password;
        const char *org_unit = "Computers";
        char *dn;
@@ -656,6 +656,8 @@ int net_ads_join(int argc, const char **argv)
        char *ou_str;
        uint32 sec_channel_type = SEC_CHAN_WKSTA;
        uint32 account_type = UF_WORKSTATION_TRUST_ACCOUNT;
+       char *short_domain_name = NULL;
+       TALLOC_CTX *ctx = NULL;
 
        if (argc > 0) org_unit = argv[0];
 
@@ -669,6 +671,16 @@ int net_ads_join(int argc, const char **argv)
 
        if (!(ads = ads_startup())) return -1;
 
+       if (!*lp_realm()) {
+               d_printf("realm must be set in in smb.conf for ADS join to succeed.\n");
+               return -1;
+       }
+
+       if (strcmp(ads->config.realm, lp_realm()) != 0) {
+               d_printf("realm of remote server (%s) and realm in smb.conf (%s) DO NOT match.  Aborting join\n", ads->config.realm, lp_realm());
+               return -1;
+       }
+
        ou_str = ads_ou_string(org_unit);
        asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path);
        free(ou_str);
@@ -696,16 +708,47 @@ int net_ads_join(int argc, const char **argv)
 
        rc = ads_domain_sid(ads, &dom_sid);
        if (!ADS_ERR_OK(rc)) {
-               d_printf("ads_domain_sid: %s\n", ads_errstr(rc));
+               d_printf("ads_domain_sid: %s\n", ads_errstr(rc));       
+       return -1;
+       }
+
+       if (asprintf(&machine_account, "%s$", global_myname()) == -1) {
+               d_printf("asprintf failed\n");
                return -1;
        }
 
-       rc = ads_set_machine_password(ads, global_myname(), password);
+       rc = ads_set_machine_password(ads, machine_account, password);
        if (!ADS_ERR_OK(rc)) {
                d_printf("ads_set_machine_password: %s\n", ads_errstr(rc));
                return -1;
        }
-
+       
+       /* make sure we get the right workgroup */
+       
+       if ( !(ctx = talloc_init("net ads join")) ) {
+               d_printf("talloc_init() failed!\n");
+               return -1;
+       }
+       
+       rc = ads_workgroup_name(ads, ctx, &short_domain_name);
+       if ( ADS_ERR_OK(rc) ) {
+               if ( !strequal(lp_workgroup(), short_domain_name) ) {
+                       d_printf("The workgroup in smb.conf does not match the short\n");
+                       d_printf("domain name obtained from the server.\n");
+                       d_printf("Using the name [%s] from the server.\n", short_domain_name);
+                       d_printf("You should set \"workgroup = %s\" in smb.conf.\n", short_domain_name);
+               }
+       }
+       else
+               short_domain_name = lp_workgroup();
+       
+       d_printf("Using short domain name -- %s\n", short_domain_name);
+       
+       /*  HACK ALRET!  Store the sid and password under bother the lp_workgroup() 
+           value from smb.conf and the string returned from the server.  The former is
+           neede to bootstrap winbindd's first connection to the DC to get the real 
+           short domain name   --jerry */
+           
        if (!secrets_store_domain_sid(lp_workgroup(), &dom_sid)) {
                DEBUG(1,("Failed to save domain sid\n"));
                return -1;
@@ -716,10 +759,22 @@ int net_ads_join(int argc, const char **argv)
                return -1;
        }
 
-       d_printf("Joined '%s' to realm '%s'\n", global_myname(), ads->config.realm);
+       if (!secrets_store_domain_sid(short_domain_name, &dom_sid)) {
+               DEBUG(1,("Failed to save domain sid\n"));
+               return -1;
+       }
 
-       free(password);
+       if (!secrets_store_machine_password(password, short_domain_name, sec_channel_type)) {
+               DEBUG(1,("Failed to save machine password\n"));
+               return -1;
+       }
+       
+       d_printf("Joined '%s' to realm '%s'\n", global_myname(), ads->config.realm);
 
+       SAFE_FREE(password);
+       SAFE_FREE(machine_account);
+       if ( ctx )
+               talloc_destroy(ctx);
        return 0;
 }
 
@@ -1020,17 +1075,13 @@ int net_ads_changetrustpw(int argc, const char **argv)
     char *host_principal;
     char *hostname;
     ADS_STATUS ret;
-    char *user_name;
 
     if (!secrets_init()) {
            DEBUG(1,("Failed to initialise secrets database\n"));
            return -1;
     }
 
-    asprintf(&user_name, "%s$", global_myname());
-    opt_user_name = user_name;
-
-    opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
+    net_use_machine_password();
 
     use_in_memory_ccache();
 
index e74e4b5a4cf14c68426d2d5afd8e52f7a7749c9d..595e6e943473f8fb660ecde8e41f51323f90167a 100644 (file)
@@ -240,7 +240,7 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
                return -1;
        }
 
-       p = os3.data;
+       p = (char *)os3.data;
 
        reply->type = IVAL(p, 0); p += 4;
        reply->flags = IVAL(p, 0); p += 4;
@@ -248,25 +248,25 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
        memcpy(&reply->guid.info, p, GUID_SIZE);
        p += GUID_SIZE;
 
-       p += pull_netlogon_string(reply->forest, p, os3.data);
-       p += pull_netlogon_string(reply->unk0, p, os3.data);
-       p += pull_netlogon_string(reply->domain, p, os3.data);
-       p += pull_netlogon_string(reply->hostname, p, os3.data);
-       p += pull_netlogon_string(reply->netbios_domain, p, os3.data);
-       p += pull_netlogon_string(reply->unk1, p, os3.data);
-       p += pull_netlogon_string(reply->netbios_hostname, p, os3.data);
-       p += pull_netlogon_string(reply->unk2, p, os3.data);
+       p += pull_netlogon_string(reply->forest, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->unk0, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->domain, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->hostname, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->netbios_domain, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->unk1, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->netbios_hostname, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->unk2, p, (const char *)os3.data);
 
        if (reply->type == SAMLOGON_AD_R) {
-               p += pull_netlogon_string(reply->user_name, p, os3.data);
+               p += pull_netlogon_string(reply->user_name, p, (const char *)os3.data);
        } else {
                *reply->user_name = 0;
        }
 
-       p += pull_netlogon_string(reply->unk3, p, os3.data);
-       p += pull_netlogon_string(reply->site_name, p, os3.data);
-       p += pull_netlogon_string(reply->unk4, p, os3.data);
-       p += pull_netlogon_string(reply->site_name_2, p, os3.data);
+       p += pull_netlogon_string(reply->unk3, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->site_name, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->unk4, p, (const char *)os3.data);
+       p += pull_netlogon_string(reply->site_name_2, p, (const char *)os3.data);
 
        reply->version = IVAL(p, 0);
        reply->lmnt_token = SVAL(p, 4);
index 8831839e4eb979935e36403486e4a16f20a3d862..99371452307edd5dbc6dde3a73d05166e81d5e00 100644 (file)
@@ -252,11 +252,21 @@ static int net_groupmap_add(int argc, const char **argv)
                }
        }
 
-       if ( !unixgrp[0] || (!rid && !string_sid[0]) ) {
+       if ( !unixgrp[0] ) {
                d_printf("Usage: net groupmap add {rid=<int>|sid=<string>} unixgroup=<string> [type=<domain|local|builtin>] [ntgroup=<string>] [comment=<string>]\n");
                return -1;
        }
        
+       if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) {
+               d_printf("Can't lookup UNIX group %s\n", ntgroup);
+               return -1;
+       }
+       
+       if ( (rid == 0) && (string_sid[0] == '\0') ) {
+               d_printf("No rid or sid specified, choosing algorithmic mapping\n");
+               rid = pdb_gid_to_group_rid(gid);
+       }
+
        /* append the rid to our own domain/machine SID if we don't have a full SID */
        if ( !string_sid[0] ) {
                sid_copy(&sid, get_global_sam_sid());
@@ -267,11 +277,6 @@ static int net_groupmap_add(int argc, const char **argv)
        if (ntcomment[0])
                fstrcpy(ntcomment, "Local Unix group");
                
-       if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) {
-               d_printf("Can't lookup UNIX group %s\n", ntgroup);
-               return -1;
-       }
-       
        if ( !ntgroup[0] )
                fstrcpy( ntgroup, unixgrp );
                
index 1f3afb1690e5637c00b83fa72c2cf0cae74e4380..95116a4d2a8a7599e9e1e4f4b45e7a49c7678f15 100644 (file)
@@ -47,7 +47,7 @@ int net_common_flags_usage(int argc, const char **argv)
        d_printf("\t-U or --user=<name>\t\tuser name\n");
        d_printf("\t-s or --configfile=<path>\t\tpathname of smb.conf file\n");
        d_printf("\t-l or --long\t\t\tDisplay full information\n");
-       d_printf("\t-V or --version\t\tPrint samba version information\n");
+       d_printf("\t-V or --version\t\t\tPrint samba version information\n");
        d_printf("\t-P or --machine-pass\t\tAuthenticate as machine account\n");
        return -1;
 }
@@ -60,7 +60,8 @@ static int help_usage(int argc, const char **argv)
 "\n"\
 "Valid functions are:\n"\
 "  RPC RAP ADS FILE SHARE SESSION SERVER DOMAIN PRINTQ USER GROUP VALIDATE\n"\
-"  GROUPMEMBER ADMIN SERVICE PASSWORD TIME LOOKUP GETLOCALSID SETLOCALSID\n");
+"  GROUPMEMBER ADMIN SERVICE PASSWORD TIME LOOKUP GETLOCALSID SETLOCALSID\n"\
+"  CHANGESCRETPW\n");
        return -1;
 }
 
@@ -156,6 +157,8 @@ static int net_usage(int argc, const char **argv)
                 "  net cache\t\tto operate on cache tdb file\n"\
                 "  net getlocalsid [NAME]\tto get the SID for local name\n"\
                 "  net setlocalsid SID\tto set the local domain SID\n"\
+                "  net changesecretpw\tto change the machine password in the local secrets database only\n"\
+                "                    \tthis requires the -f flag as a safety barrier\n"\
                 "\n"\
                 "  net ads <command>\tto run ADS commands\n"\
                 "  net rap <command>\tto run RAP (pre-RPC) commands\n"\
@@ -193,6 +196,9 @@ int net_help(int argc, const char **argv)
                {"PASSWORD", net_rap_password_usage},
                {"TIME", net_time_usage},
                {"LOOKUP", net_lookup_usage},
+#ifdef WITH_FAKE_KASERVER
+               {"AFSKEY", net_afskey_usage},
+#endif
 
                {"HELP", help_usage},
                {NULL, NULL}};
index 8456da4e0cb93cf5777eaf32c1f7932ab482582d..cef0ea5fbed62f430dc40285430f5626253d1783 100644 (file)
@@ -23,7 +23,7 @@
 int net_lookup_usage(int argc, const char **argv)
 {
        d_printf(
-"  net lookup host HOSTNAME <type>\n\tgives IP for a hostname\n\n"
+"  net lookup [host] HOSTNAME[#<type>]\n\tgives IP for a hostname\n\n"
 "  net lookup ldap [domain]\n\tgives IP of domain's ldap server\n\n"
 "  net lookup kdc [realm]\n\tgives IP of realm's kerberos KDC\n\n"
 "  net lookup dc [domain]\n\tgives IP of domains Domain Controllers\n\n"
@@ -37,14 +37,22 @@ static int net_lookup_host(int argc, const char **argv)
 {
        struct in_addr ip;
        int name_type = 0x20;
+       const char *name = argv[0];
+       char *p;
 
-       if (argc == 0) return net_lookup_usage(argc, argv);
-       if (argc > 1) name_type = strtol(argv[1], NULL, 0);
+       if (argc == 0) 
+               return net_lookup_usage(argc, argv);
 
-       if (!resolve_name(argv[0], &ip, name_type)) {
+       p = strchr_m(name,'#');
+       if (p) {
+               *p = '\0';
+               sscanf(++p,"%x",&name_type);
+       }
+       
+       if (!resolve_name(name, &ip, name_type)) {
                /* we deliberately use DEBUG() here to send it to stderr 
                   so scripts aren't mucked up */
-               DEBUG(0,("Didn't find %s#%02x\n", argv[0], name_type));
+               DEBUG(0,("Didn't find %s#%02x\n", name, name_type));
                return -1;
        }
 
@@ -221,7 +229,9 @@ static int net_lookup_kdc(int argc, const char **argv)
 /* lookup hosts or IP addresses using internal samba lookup fns */
 int net_lookup(int argc, const char **argv)
 {
-       struct functable func[] = {
+       int i;
+
+       struct functable table[] = {
                {"HOST", net_lookup_host},
                {"LDAP", net_lookup_ldap},
                {"DC", net_lookup_dc},
@@ -230,5 +240,19 @@ int net_lookup(int argc, const char **argv)
                {NULL, NULL}
        };
 
-       return net_run_function(argc, argv, func, net_lookup_usage);
+       if (argc < 1) {
+               d_printf("\nUsage: \n");
+               return net_lookup_usage(argc, argv);
+       }
+       for (i=0; table[i].funcname; i++) {
+               if (StrCaseCmp(argv[0], table[i].funcname) == 0)
+                       return table[i].fn(argc-1, argv+1);
+       }
+
+       /* Default to lookup a hostname so 'net lookup foo#1b' can be 
+          used instead of 'net lookup host foo#1b'.  The host syntax
+          is a bit confusing as non #00 names can't really be 
+          considered hosts as such. */
+
+       return net_lookup_host(argc, argv);
 }
index 890d4a012b131a07000dd97df05fe6d40ccab806..fefc5af3653d93e2efc9067020d3b8ed15e4ab76 100644 (file)
@@ -84,7 +84,14 @@ static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli)
        result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class, 
                                           domain_name, domain_sid);
        if (!NT_STATUS_IS_OK(result)) {
-               goto error;
+ error:
+               fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
+
+               if (!NT_STATUS_IS_OK(result)) {
+                       fprintf(stderr, "error: %s\n", nt_errstr(result));
+               }
+
+               exit(1);
        }
 
        cli_lsa_close(cli, mem_ctx, &pol);
@@ -92,15 +99,6 @@ static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli)
        talloc_destroy(mem_ctx);
 
        return domain_sid;
-
- error:
-       fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
-
-       if (!NT_STATUS_IS_OK(result)) {
-               fprintf(stderr, "error: %s\n", nt_errstr(result));
-       }
-
-       exit(1);
 }
 
 /**
@@ -1709,8 +1707,13 @@ static NTSTATUS rpc_trustdom_add_internals(const DOM_SID *domain_sid, struct cli
 
 static int rpc_trustdom_add(int argc, const char **argv)
 {
-       return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
-                              argc, argv);
+       if (argc > 0) {
+               return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
+                                      argc, argv);
+       } else {
+               d_printf("Usage: net rpc trustdom add <domain>\n");
+               return -1;
+       }
 }
 
 
@@ -1726,6 +1729,7 @@ static int rpc_trustdom_add(int argc, const char **argv)
 static int rpc_trustdom_del(int argc, const char **argv)
 {
        d_printf("Sorry, not yet implemented.\n");
+       d_printf("Use 'smbpasswd -x -i' instead.\n");
        return -1;
 }
 
@@ -1782,7 +1786,7 @@ static int rpc_trustdom_establish(int argc, const char **argv)
 
        /* find the domain controller */
        if (!net_find_pdc(&server_ip, pdc_name, domain_name)) {
-               DEBUG(0, ("Coulnd find domain controller for domain %s\n", domain_name));
+               DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
                return -1;
        }
 
@@ -1988,8 +1992,8 @@ static int rpc_trustdom_list(int argc, const char **argv)
        POLICY_HND connect_hnd;
        
        /* trusted domains listing variables */
-       int enum_ctx = 0;
-       int num_domains, i, pad_len, col_len = 20;
+       unsigned int num_domains, enum_ctx = 0;
+       int i, pad_len, col_len = 20;
        DOM_SID *domain_sids;
        char **trusted_dom_names;
        fstring pdc_name, dummy;
index 9eadbbbade6c7b7d269280503bdd415335f4451a..ed69f8a326b15850fdc67df1f1f18d707cabbde9 100644 (file)
@@ -550,7 +550,11 @@ fetch_group_info(uint32 rid, SAM_GROUP_INFO *delta)
        map.sid = group_sid;
        map.sid_name_use = SID_NAME_DOM_GRP;
        fstrcpy(map.nt_name, name);
-       fstrcpy(map.comment, comment);
+       if (delta->hdr_grp_desc.buffer) {
+               fstrcpy(map.comment, comment);
+       } else {
+               fstrcpy(map.comment, "");
+       }
 
        if (insert)
                pdb_add_group_mapping_entry(&map);
@@ -911,9 +915,40 @@ fetch_sam_entry(SAM_DELTA_HDR *hdr_delta, SAM_DELTA_CTR *delta,
                fetch_alias_mem(hdr_delta->target_rid,
                                &delta->als_mem_info, dom_sid);
                break;
+       /* The following types are recognised but not handled */
        case SAM_DELTA_DOMAIN_INFO:
                d_printf("SAM_DELTA_DOMAIN_INFO not handled\n");
                break;
+       case SAM_DELTA_RENAME_GROUP:
+               d_printf("SAM_DELTA_RENAME_GROUP not handled\n");
+               break;
+       case SAM_DELTA_RENAME_USER:
+               d_printf("SAM_DELTA_RENAME_USER not handled\n");
+               break;
+       case SAM_DELTA_RENAME_ALIAS:
+               d_printf("SAM_DELTA_RENAME_ALIAS not handled\n");
+               break;
+       case SAM_DELTA_POLICY_INFO:
+               d_printf("SAM_DELTA_POLICY_INFO not handled\n");
+               break;
+       case SAM_DELTA_TRUST_DOMS:
+               d_printf("SAM_DELTA_TRUST_DOMS not handled\n");
+               break;
+       case SAM_DELTA_PRIVS_INFO:
+               d_printf("SAM_DELTA_PRIVS_INFO not handled\n");
+               break;
+       case SAM_DELTA_SECRET_INFO:
+               d_printf("SAM_DELTA_SECRET_INFO not handled\n");
+               break;
+       case SAM_DELTA_DELETE_GROUP:
+               d_printf("SAM_DELTA_DELETE_GROUP not handled\n");
+               break;
+       case SAM_DELTA_DELETE_USER:
+               d_printf("SAM_DELTA_DELETE_USER not handled\n");
+               break;
+       case SAM_DELTA_MODIFIED_COUNT:
+               d_printf("SAM_DELTA_MODIFIED_COUNT not handled\n");
+               break;
        default:
                d_printf("Unknown delta record type %d\n", hdr_delta->type);
                break;
index d2c5cbc00ed41579c9ad01c7ef3dbc0df6a2c5c8..3c5a22841eacda18f5bbc2e4dd6118d34d38d108 100644 (file)
@@ -109,7 +109,7 @@ static void do_node_status(int fd, const char *name, int type, struct in_addr ip
        status = node_status_query(fd,&nname,ip, &count);
        if (status) {
                for (i=0;i<count;i++) {
-                       fstrcpy(cleanname, status[i].name);
+                       pull_ascii_fstring(cleanname, status[i].name);
                        for (j=0;cleanname[j];j++) {
                                if (!isprint((int)cleanname[j])) cleanname[j] = '.';
                        }
index 1d36a7ce521eb3dec759082e62fdaa2a2759ee05..7cd7e0b0875fce4133a7d63b16f3fac244fb54d6 100644 (file)
@@ -200,10 +200,24 @@ static NTSTATUS contact_winbind_auth_crap(const char *username,
 
        request.flags = flags;
 
-       fstrcpy(request.data.auth_crap.user, username);
+       if (push_utf8_fstring(request.data.auth_crap.user, username) == -1) {
+               *error_string = smb_xstrdup(
+                       "unable to create utf8 string for username");
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       if (push_utf8_fstring(request.data.auth_crap.domain, domain) == -1) {
+               *error_string = smb_xstrdup(
+                       "unable to create utf8 string for domain");
+               return NT_STATUS_UNSUCCESSFUL;
+       }
 
-       fstrcpy(request.data.auth_crap.domain, domain);
-       fstrcpy(request.data.auth_crap.workstation, workstation);
+       if (push_utf8_fstring(request.data.auth_crap.workstation, 
+                             workstation) == -1) {
+               *error_string = smb_xstrdup(
+                       "unable to create utf8 string for workstation");
+               return NT_STATUS_UNSUCCESSFUL;
+       }
 
        memcpy(request.data.auth_crap.chal, challenge->data, MIN(challenge->length, 8));
 
@@ -296,7 +310,7 @@ static void manage_squid_ntlmssp_request(enum squid_mode squid_mode,
        }
 
        DEBUG(10, ("got NTLMSSP packet:\n"));
-       dump_data(10, request.data, request.length);
+       dump_data(10, (const char *)request.data, request.length);
 
        nt_status = ntlmssp_server_update(ntlmssp_state, request, &reply);
        
@@ -347,27 +361,35 @@ static void manage_squid_basic_request(enum squid_mode squid_mode,
 static void offer_gss_spnego_mechs(void) {
 
        DATA_BLOB token;
-       ASN1_DATA asn1;
        SPNEGO_DATA spnego;
        ssize_t len;
        char *reply_base64;
 
+       pstring principal;
+       pstring myname_lower;
+
        ZERO_STRUCT(spnego);
 
+       pstrcpy(myname_lower, global_myname());
+       strlower_m(myname_lower);
+
+       pstr_sprintf(principal, "%s$@%s", myname_lower, lp_realm());
+
        /* Server negTokenInit (mech offerings) */
        spnego.type = SPNEGO_NEG_TOKEN_INIT;
-       spnego.negTokenInit.mechTypes = smb_xmalloc(sizeof(char *) * 2);
+       spnego.negTokenInit.mechTypes = smb_xmalloc(sizeof(char *) * 3);
+#ifdef HAVE_KRB5
+       spnego.negTokenInit.mechTypes[0] = smb_xstrdup(OID_KERBEROS5_OLD);
+       spnego.negTokenInit.mechTypes[1] = smb_xstrdup(OID_NTLMSSP);
+       spnego.negTokenInit.mechTypes[2] = NULL;
+#else
        spnego.negTokenInit.mechTypes[0] = smb_xstrdup(OID_NTLMSSP);
        spnego.negTokenInit.mechTypes[1] = NULL;
+#endif
+
 
-       ZERO_STRUCT(asn1);
-       asn1_push_tag(&asn1, ASN1_SEQUENCE(0));
-       asn1_push_tag(&asn1, ASN1_CONTEXT(0));
-       asn1_write_GeneralString(&asn1, "NONE");
-       asn1_pop_tag(&asn1);
-       asn1_pop_tag(&asn1);
-       spnego.negTokenInit.mechListMIC = data_blob(asn1.data, asn1.length);
-       asn1_free(&asn1);
+       spnego.negTokenInit.mechListMIC = data_blob(principal,
+                                                   strlen(principal));
 
        len = write_spnego_data(&token, &spnego);
        free_spnego_data(&spnego);
@@ -391,11 +413,14 @@ static void manage_gss_spnego_request(enum squid_mode squid_mode,
                                      char *buf, int length) 
 {
        static NTLMSSP_STATE *ntlmssp_state = NULL;
-       SPNEGO_DATA spnego;
-       DATA_BLOB request, token;
+       SPNEGO_DATA request, response;
+       DATA_BLOB token;
        NTSTATUS status;
        ssize_t len;
 
+       char *user = NULL;
+       char *domain = NULL;
+
        const char *reply_code;
        char       *reply_base64;
        pstring     reply_argument;
@@ -432,9 +457,9 @@ static void manage_gss_spnego_request(enum squid_mode squid_mode,
                return;
        }
 
-       request = base64_decode_data_blob(buf + 3);
-       len = read_spnego_data(request, &spnego);
-       data_blob_free(&request);
+       token = base64_decode_data_blob(buf + 3);
+       len = read_spnego_data(token, &request);
+       data_blob_free(&token);
 
        if (len == -1) {
                DEBUG(1, ("GSS-SPNEGO query [%s] invalid", buf));
@@ -442,100 +467,159 @@ static void manage_gss_spnego_request(enum squid_mode squid_mode,
                return;
        }
 
-       if (spnego.type == SPNEGO_NEG_TOKEN_INIT) {
+       if (request.type == SPNEGO_NEG_TOKEN_INIT) {
 
                /* Second request from Client. This is where the
                   client offers its mechanism to use. We currently
                   only support NTLMSSP, the decision for Kerberos
                   would be taken here. */
 
-               if ( (spnego.negTokenInit.mechTypes == NULL) ||
-                    (spnego.negTokenInit.mechTypes[0] == NULL) ) {
+               if ( (request.negTokenInit.mechTypes == NULL) ||
+                    (request.negTokenInit.mechTypes[0] == NULL) ) {
                        DEBUG(1, ("Client did not offer any mechanism"));
                        x_fprintf(x_stdout, "BH\n");
                        return;
                }
 
-               if ( strcmp(spnego.negTokenInit.mechTypes[0], OID_NTLMSSP) != 0 ) {
-                       DEBUG(1, ("Client did not choose NTLMSSP but %s\n",
-                                 spnego.negTokenInit.mechTypes[0]));
-                       x_fprintf(x_stdout, "BH\n");
-                       return;
-               }
+               if (strcmp(request.negTokenInit.mechTypes[0], OID_NTLMSSP) == 0) {
 
-               if ( spnego.negTokenInit.mechToken.data == NULL ) {
-                       DEBUG(1, ("Client did not provide  NTLMSSP data\n"));
-                       x_fprintf(x_stdout, "BH\n");
-                       return;
-               }
+                       if ( request.negTokenInit.mechToken.data == NULL ) {
+                               DEBUG(1, ("Client did not provide  NTLMSSP data\n"));
+                               x_fprintf(x_stdout, "BH\n");
+                               return;
+                       }
 
-               if ( ntlmssp_state != NULL ) {
-                       DEBUG(1, ("Client wants a new NTLMSSP challenge, but "
-                                 "already got one\n"));
-                       x_fprintf(x_stdout, "BH\n");
-                       ntlmssp_server_end(&ntlmssp_state);
-                       return;
+                       if ( ntlmssp_state != NULL ) {
+                               DEBUG(1, ("Client wants a new NTLMSSP challenge, but "
+                                         "already got one\n"));
+                               x_fprintf(x_stdout, "BH\n");
+                               ntlmssp_server_end(&ntlmssp_state);
+                               return;
+                       }
+
+                       ntlmssp_server_start(&ntlmssp_state);
+                       ntlmssp_state->check_password = winbind_pw_check;
+                       ntlmssp_state->get_domain = get_winbind_domain;
+                       ntlmssp_state->get_global_myname = get_winbind_netbios_name;
+
+                       DEBUG(10, ("got NTLMSSP packet:\n"));
+                       dump_data(10, (const char *)request.negTokenInit.mechToken.data,
+                                 request.negTokenInit.mechToken.length);
+
+                       response.type = SPNEGO_NEG_TOKEN_TARG;
+                       response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+                       response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
+
+                       status = ntlmssp_server_update(ntlmssp_state,
+                                                      request.negTokenInit.mechToken,
+                                                      &response.negTokenTarg.responseToken);
                }
 
-               ntlmssp_server_start(&ntlmssp_state);
-               ntlmssp_state->check_password = winbind_pw_check;
-               ntlmssp_state->get_domain = get_winbind_domain;
-               ntlmssp_state->get_global_myname = get_winbind_netbios_name;
+#ifdef HAVE_KRB5
+               if (strcmp(request.negTokenInit.mechTypes[0], OID_KERBEROS5_OLD) == 0) {
 
-               DEBUG(10, ("got NTLMSSP packet:\n"));
-               dump_data(10, spnego.negTokenInit.mechToken.data,
-                         spnego.negTokenInit.mechToken.length);
+                       char *principal;
+                       DATA_BLOB auth_data;
+                       DATA_BLOB ap_rep;
+                       uint8 session_key[16];
 
-               free_spnego_data(&spnego);
+                       if ( request.negTokenInit.mechToken.data == NULL ) {
+                               DEBUG(1, ("Client did not provide Kerberos data\n"));
+                               x_fprintf(x_stdout, "BH\n");
+                               return;
+                       }
 
-               spnego.type = SPNEGO_NEG_TOKEN_TARG;
-               spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
-               spnego.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+                       response.type = SPNEGO_NEG_TOKEN_TARG;
+                       response.negTokenTarg.supportedMech = strdup(OID_KERBEROS5_OLD);
+                       response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
+                       response.negTokenTarg.responseToken = data_blob(NULL, 0);
 
-               status = ntlmssp_server_update(ntlmssp_state,
-                                              spnego.negTokenInit.mechToken,
-                                              &spnego.negTokenTarg.responseToken);
+                       status = ads_verify_ticket(lp_realm(),
+                                                  &request.negTokenInit.mechToken,
+                                                  &principal, &auth_data, &ap_rep,
+                                                  session_key);
 
-       } else {
+                       /* Now in "principal" we have the name we are
+                           authenticated as. */
+
+                       if (NT_STATUS_IS_OK(status)) {
+
+                               domain = strchr(principal, '@');
 
-               /* spnego.type == SPNEGO_NEG_TOKEN_TARG */
+                               if (domain == NULL) {
+                                       DEBUG(1, ("Did not get a valid principal "
+                                                 "from ads_verify_ticket\n"));
+                                       x_fprintf(x_stdout, "BH\n");
+                                       return;
+                               }
 
-               DATA_BLOB response;
+                               *domain++ = '\0';
+                               domain = strdup(domain);
+                               user = strdup(principal);
 
-               if (spnego.negTokenTarg.responseToken.data == NULL) {
-                       DEBUG(1, ("Got a negTokenArg without a responseToken!\n"));
+                               data_blob_free(&ap_rep);
+                               data_blob_free(&auth_data);
+
+                               SAFE_FREE(principal);
+                       }
+               }
+#endif
+
+       } else {
+
+               if ( (request.negTokenTarg.supportedMech == NULL) ||
+                    ( strcmp(request.negTokenTarg.supportedMech, OID_NTLMSSP) != 0 ) ) {
+                       /* Kerberos should never send a negTokenTarg, OID_NTLMSSP
+                          is the only one we support that sends this stuff */
+                       DEBUG(1, ("Got a negTokenTarg for something non-NTLMSSP: %s\n",
+                                 request.negTokenTarg.supportedMech));
                        x_fprintf(x_stdout, "BH\n");
                        return;
                }
 
-               status = ntlmssp_server_update(ntlmssp_state,
-                                              spnego.negTokenTarg.responseToken,
-                                              &response);
+               if (request.negTokenTarg.responseToken.data == NULL) {
+                       DEBUG(1, ("Got a negTokenTarg without a responseToken!\n"));
+                       x_fprintf(x_stdout, "BH\n");
+                       return;
+               }
 
-               data_blob_free(&spnego.negTokenTarg.responseToken);
+               status = ntlmssp_server_update(ntlmssp_state,
+                                              request.negTokenTarg.responseToken,
+                                              &response.negTokenTarg.responseToken);
 
-               spnego.negTokenTarg.responseToken = response;
+               response.type = SPNEGO_NEG_TOKEN_TARG;
+               response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+               response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
 
+               if (NT_STATUS_IS_OK(status)) {
+                       user = strdup(ntlmssp_state->user);
+                       domain = strdup(ntlmssp_state->domain);
+                       ntlmssp_server_end(&ntlmssp_state);
+               }
        }
 
+       free_spnego_data(&request);
+
        if (NT_STATUS_IS_OK(status)) {
-               spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
+               response.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
                reply_code = "AF";
-               pstr_sprintf(reply_argument, "%s\\%s",
-                            ntlmssp_state->domain, ntlmssp_state->user);
+               pstr_sprintf(reply_argument, "%s\\%s", domain, user);
        } else if (NT_STATUS_EQUAL(status,
                                   NT_STATUS_MORE_PROCESSING_REQUIRED)) {
-               spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
+               response.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
                reply_code = "TT";
                pstr_sprintf(reply_argument, "*");
        } else {
-               spnego.negTokenTarg.negResult = SPNEGO_REJECT;
+               response.negTokenTarg.negResult = SPNEGO_REJECT;
                reply_code = "NA";
                pstrcpy(reply_argument, nt_errstr(status));
        }
 
-       len = write_spnego_data(&token, &spnego);
-       free_spnego_data(&spnego);
+       SAFE_FREE(user);
+       SAFE_FREE(domain);
+
+       len = write_spnego_data(&token, &response);
+       free_spnego_data(&response);
 
        if (len == -1) {
                DEBUG(1, ("Could not write SPNEGO data blob\n"));
@@ -551,16 +635,12 @@ static void manage_gss_spnego_request(enum squid_mode squid_mode,
        SAFE_FREE(reply_base64);
        data_blob_free(&token);
 
-       if (NT_STATUS_IS_OK(status)) {
-               ntlmssp_server_end(&ntlmssp_state);
-       }
-
        return;
 }
 
 static NTLMSSP_CLIENT_STATE *client_ntlmssp_state = NULL;
 
-static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
+static BOOL manage_client_ntlmssp_init(SPNEGO_DATA spnego)
 {
        NTSTATUS status;
        DATA_BLOB null_blob = data_blob(NULL, 0);
@@ -573,14 +653,12 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (client_ntlmssp_state != NULL) {
                DEBUG(1, ("Request for initial SPNEGO request where "
                          "we already have a state\n"));
-               x_fprintf(x_stdout, "BH\n");
-               return;
+               return False;
        }
 
        if ( (opt_username == NULL) || (opt_domain == NULL) ) {
                DEBUG(1, ("Need username and domain for NTLMSSP\n"));
-               x_fprintf(x_stdout, "BH\n");
-               return;
+               return False;
        }
 
        if (opt_password == NULL) {
@@ -591,7 +669,7 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
 
                DEBUG(10, ("Requesting password\n"));
                x_fprintf(x_stdout, "PW\n");
-               return;
+               return True;
        }
 
        status = ntlmssp_client_start(&client_ntlmssp_state);
@@ -599,9 +677,8 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Could not start NTLMSSP client: %s\n",
                          nt_errstr(status)));
-               x_fprintf(x_stdout, "BH\n");
                ntlmssp_client_end(&client_ntlmssp_state);
-               return;
+               return False;
        }
 
        status = ntlmssp_set_username(client_ntlmssp_state, opt_username);
@@ -609,9 +686,8 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Could not set username: %s\n",
                          nt_errstr(status)));
-               x_fprintf(x_stdout, "BH\n");
                ntlmssp_client_end(&client_ntlmssp_state);
-               return;
+               return False;
        }
 
        status = ntlmssp_set_domain(client_ntlmssp_state, opt_domain);
@@ -619,9 +695,8 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Could not set domain: %s\n",
                          nt_errstr(status)));
-               x_fprintf(x_stdout, "BH\n");
                ntlmssp_client_end(&client_ntlmssp_state);
-               return;
+               return False;
        }
 
        status = ntlmssp_set_password(client_ntlmssp_state, opt_password);
@@ -629,9 +704,8 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Could not set password: %s\n",
                          nt_errstr(status)));
-               x_fprintf(x_stdout, "BH\n");
                ntlmssp_client_end(&client_ntlmssp_state);
-               return;
+               return False;
        }
 
        spnego.type = SPNEGO_NEG_TOKEN_INIT;
@@ -645,9 +719,8 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                DEBUG(1, ("Expected MORE_PROCESSING_REQUIRED, got: %s\n",
                          nt_errstr(status)));
-               x_fprintf(x_stdout, "BH\n");
                ntlmssp_client_end(&client_ntlmssp_state);
-               return;
+               return False;
        }
 
        write_spnego_data(&to_server, &spnego);
@@ -657,7 +730,7 @@ static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        data_blob_free(&to_server);
        x_fprintf(x_stdout, "KK %s\n", to_server_base64);
        SAFE_FREE(to_server_base64);
-       return;
+       return True;
 }
 
 static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
@@ -719,21 +792,110 @@ static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
        return;
 }
 
-static void manage_client_krb5_init(SPNEGO_DATA spnego)
+#ifdef HAVE_KRB5
+
+static BOOL manage_client_krb5_init(SPNEGO_DATA spnego)
 {
-       DEBUG(1, ("to be done ... \n"));
-       x_fprintf(x_stdout, "BH\n");
-       return;
+       char *principal;
+       DATA_BLOB tkt, to_server;
+       unsigned char session_key_krb5[16];
+       SPNEGO_DATA reply;
+       char *reply_base64;
+       
+       const char *my_mechs[] = {OID_KERBEROS5_OLD, NULL};
+       ssize_t len;
+
+       if ( (spnego.negTokenInit.mechListMIC.data == NULL) ||
+            (spnego.negTokenInit.mechListMIC.length == 0) ) {
+               DEBUG(1, ("Did not get a principal for krb5\n"));
+               return False;
+       }
+
+       principal = malloc(spnego.negTokenInit.mechListMIC.length+1);
+
+       if (principal == NULL) {
+               DEBUG(1, ("Could not malloc principal\n"));
+               return False;
+       }
+
+       memcpy(principal, spnego.negTokenInit.mechListMIC.data,
+              spnego.negTokenInit.mechListMIC.length);
+       principal[spnego.negTokenInit.mechListMIC.length] = '\0';
+
+       tkt = cli_krb5_get_ticket(principal, 0, session_key_krb5);
+
+       if (tkt.data == NULL) {
+
+               pstring user;
+
+               /* Let's try to first get the TGT, for that we need a
+                   password. */
+
+               if (opt_password == NULL) {
+                       DEBUG(10, ("Requesting password\n"));
+                       x_fprintf(x_stdout, "PW\n");
+                       return True;
+               }
+
+               pstr_sprintf(user, "%s@%s", opt_username, opt_domain);
+
+               if (kerberos_kinit_password(user, opt_password, 0) != 0) {
+                       DEBUG(10, ("Requesting TGT failed\n"));
+                       x_fprintf(x_stdout, "NA\n");
+                       return True;
+               }
+
+               tkt = cli_krb5_get_ticket(principal, 0, session_key_krb5);
+       }
+
+       ZERO_STRUCT(reply);
+
+       reply.type = SPNEGO_NEG_TOKEN_INIT;
+       reply.negTokenInit.mechTypes = my_mechs;
+       reply.negTokenInit.reqFlags = 0;
+       reply.negTokenInit.mechToken = tkt;
+       reply.negTokenInit.mechListMIC = data_blob(NULL, 0);
+
+       len = write_spnego_data(&to_server, &reply);
+       data_blob_free(&tkt);
+
+       if (len == -1) {
+               DEBUG(1, ("Could not write SPNEGO data blob\n"));
+               return False;
+       }
+
+       reply_base64 = base64_encode_data_blob(to_server);
+       x_fprintf(x_stdout, "KK %s *\n", reply_base64);
+
+       SAFE_FREE(reply_base64);
+       data_blob_free(&to_server);
+       DEBUG(10, ("sent GSS-SPNEGO KERBEROS5 negTokenInit\n"));
+       return True;
 }
 
 static void manage_client_krb5_targ(SPNEGO_DATA spnego)
 {
-       DEBUG(1, ("Got a negTokenTarg with a Kerberos token. This should not "
-                 "happen!\n"));
-       x_fprintf(x_stdout, "BH\n");
-       return;
+       switch (spnego.negTokenTarg.negResult) {
+       case SPNEGO_ACCEPT_INCOMPLETE:
+               DEBUG(1, ("Got a Kerberos negTokenTarg with ACCEPT_INCOMPLETE\n"));
+               x_fprintf(x_stdout, "BH\n");
+               break;
+       case SPNEGO_ACCEPT_COMPLETED:
+               DEBUG(10, ("Accept completed\n"));
+               x_fprintf(x_stdout, "AF\n");
+               break;
+       case SPNEGO_REJECT:
+               DEBUG(10, ("Rejected\n"));
+               x_fprintf(x_stdout, "NA\n");
+               break;
+       default:
+               DEBUG(1, ("Got an invalid negTokenTarg\n"));
+               x_fprintf(x_stdout, "AF\n");
+       }
 }
 
+#endif
+
 static void manage_gss_spnego_client_request(enum squid_mode squid_mode,
                                             char *buf, int length) 
 {
@@ -753,7 +915,7 @@ static void manage_gss_spnego_client_request(enum squid_mode squid_mode,
 
                /* We asked for a password and obviously got it :-) */
 
-               opt_password = strndup(request.data, request.length);
+               opt_password = strndup((const char *)request.data, request.length);
 
                if (opt_password == NULL) {
                        DEBUG(1, ("Out of memory\n"));
@@ -796,14 +958,17 @@ static void manage_gss_spnego_client_request(enum squid_mode squid_mode,
 
                while (*mechType != NULL) {
 
-                       if (strcmp(*mechType, OID_NTLMSSP) == 0) {
-                               manage_client_ntlmssp_init(spnego);
-                               goto out;
+#ifdef HAVE_KRB5
+                       if ( (strcmp(*mechType, OID_KERBEROS5_OLD) == 0) ||
+                            (strcmp(*mechType, OID_KERBEROS5) == 0) ) {
+                               if (manage_client_krb5_init(spnego))
+                                       goto out;
                        }
+#endif
 
-                       if (strcmp(*mechType, OID_KERBEROS5_OLD) == 0) {
-                               manage_client_krb5_init(spnego);
-                               goto out;
+                       if (strcmp(*mechType, OID_NTLMSSP) == 0) {
+                               if (manage_client_ntlmssp_init(spnego))
+                                       goto out;
                        }
 
                        mechType++;
@@ -816,17 +981,42 @@ static void manage_gss_spnego_client_request(enum squid_mode squid_mode,
 
        if (spnego.type == SPNEGO_NEG_TOKEN_TARG) {
 
+               if (spnego.negTokenTarg.supportedMech == NULL) {
+                       /* On accept/reject Windows does not send the
+                           mechanism anymore. Handle that here and
+                           shut down the mechanisms. */
+
+                       switch (spnego.negTokenTarg.negResult) {
+                       case SPNEGO_ACCEPT_COMPLETED:
+                               x_fprintf(x_stdout, "AF\n");
+                               break;
+                       case SPNEGO_REJECT:
+                               x_fprintf(x_stdout, "NA\n");
+                               break;
+                       default:
+                               DEBUG(1, ("Got a negTokenTarg with no mech and an "
+                                         "unknown negResult: %d\n",
+                                         spnego.negTokenTarg.negResult));
+                               x_fprintf(x_stdout, "BH\n");
+                       }
+
+                       ntlmssp_client_end(&client_ntlmssp_state);
+                       goto out;
+               }
+
                if (strcmp(spnego.negTokenTarg.supportedMech,
                           OID_NTLMSSP) == 0) {
                        manage_client_ntlmssp_targ(spnego);
                        goto out;
                }
 
+#if HAVE_KRB5
                if (strcmp(spnego.negTokenTarg.supportedMech,
                           OID_KERBEROS5_OLD) == 0) {
                        manage_client_krb5_targ(spnego);
                        goto out;
                }
+#endif
 
        }
 
@@ -925,8 +1115,8 @@ static BOOL check_auth_crap(void)
                                              &opt_lm_response, 
                                              &opt_nt_response, 
                                              flags,
-                                             lm_key, 
-                                             nt_key, 
+                                             (unsigned char *)lm_key, 
+                                             (unsigned char *)nt_key, 
                                              &error_string);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
@@ -940,7 +1130,7 @@ static BOOL check_auth_crap(void)
        if (request_lm_key 
            && (memcmp(zeros, lm_key, 
                       sizeof(lm_key)) != 0)) {
-               hex_encode(lm_key,
+               hex_encode((const unsigned char *)lm_key,
                           sizeof(lm_key),
                           &hex_lm_key);
                x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key);
@@ -949,7 +1139,7 @@ static BOOL check_auth_crap(void)
        if (request_nt_key 
            && (memcmp(zeros, nt_key, 
                       sizeof(nt_key)) != 0)) {
-               hex_encode(nt_key, 
+               hex_encode((const unsigned char *)nt_key, 
                           sizeof(nt_key), 
                           &hex_nt_key);
                x_fprintf(x_stdout, "NT_KEY: %s\n", hex_nt_key);
@@ -1023,16 +1213,16 @@ static BOOL test_lm(void)
                   sizeof(lm_key)) != 0) {
                DEBUG(1, ("LM Key does not match expectations!\n"));
                DEBUG(1, ("lm_key:\n"));
-               dump_data(1, lm_key, 8);
+               dump_data(1, (const char *)lm_key, 8);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
        }
        if (memcmp(lm_hash, nt_key, 8) != 0) {
                DEBUG(1, ("Session Key (first 8, lm hash) does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 8);
+               dump_data(1, (const char *)nt_key, 8);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
        }
         return True;
 }
@@ -1095,18 +1285,18 @@ static BOOL test_lm_ntlm(void)
                   sizeof(lm_key)) != 0) {
                DEBUG(1, ("LM Key does not match expectations!\n"));
                DEBUG(1, ("lm_key:\n"));
-               dump_data(1, lm_key, 8);
+               dump_data(1, (const char *)lm_key, 8);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
                pass = False;
        }
        if (memcmp(session_key.data, nt_key, 
                   sizeof(nt_key)) != 0) {
                DEBUG(1, ("NT Session Key does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 16);
+               dump_data(1, (const char *)nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, session_key.data, session_key.length);
+               dump_data(1, (const char *)session_key.data, session_key.length);
                pass = False;
        }
         return pass;
@@ -1138,10 +1328,10 @@ static BOOL test_ntlm(void)
        flags |= WBFLAG_PAM_NTKEY;
 
        SMBNTencrypt(opt_password,chall.data,nt_response.data);
-       E_md4hash(opt_password, nt_hash);
-       SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
+       E_md4hash(opt_password, (unsigned char *)nt_hash);
+       SMBsesskeygen_ntv1((const unsigned char *)nt_hash, NULL, session_key.data);
 
-       E_deshash(opt_password, lm_hash); 
+       E_deshash(opt_password, (unsigned char *)lm_hash); 
 
        nt_status = contact_winbind_auth_crap(opt_username, opt_domain, 
                                              opt_workstation,
@@ -1149,8 +1339,8 @@ static BOOL test_ntlm(void)
                                              NULL,
                                              &nt_response,
                                              flags,
-                                             lm_key,
-                                             nt_key,
+                                             (unsigned char *)lm_key,
+                                             (unsigned char *)nt_key,
                                              &error_string);
        
        data_blob_free(&nt_response);
@@ -1178,7 +1368,7 @@ static BOOL test_ntlm(void)
                DEBUG(1, ("nt_key:\n"));
                dump_data(1, nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, session_key.data, session_key.length);
+               dump_data(1, (const char *)session_key.data, session_key.length);
                pass = False;
        }
         return pass;
@@ -1234,17 +1424,17 @@ static BOOL test_ntlm_in_lm(void)
                   sizeof(lm_key)) != 0) {
                DEBUG(1, ("LM Key does not match expectations!\n"));
                DEBUG(1, ("lm_key:\n"));
-               dump_data(1, lm_key, 8);
+               dump_data(1, (const char *)lm_key, 8);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
                pass = False;
        }
        if (memcmp(lm_hash, nt_key, 8) != 0) {
                DEBUG(1, ("Session Key (first 8 lm hash) does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 16);
+               dump_data(1, (const char *)nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
                pass = False;
        }
         return pass;
@@ -1276,10 +1466,10 @@ static BOOL test_ntlm_in_both(void)
        flags |= WBFLAG_PAM_NTKEY;
 
        SMBNTencrypt(opt_password,chall.data,nt_response.data);
-       E_md4hash(opt_password, nt_hash);
-       SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
+       E_md4hash(opt_password, (unsigned char *)nt_hash);
+       SMBsesskeygen_ntv1((const unsigned char *)nt_hash, NULL, session_key.data);
 
-       E_deshash(opt_password, lm_hash); 
+       E_deshash(opt_password, (unsigned char *)lm_hash); 
 
        nt_status = contact_winbind_auth_crap(opt_username, opt_domain, 
                                              opt_workstation,
@@ -1287,8 +1477,8 @@ static BOOL test_ntlm_in_both(void)
                                              &nt_response,
                                              &nt_response,
                                              flags,
-                                             lm_key,
-                                             nt_key,
+                                             (unsigned char *)lm_key,
+                                             (unsigned char *)nt_key,
                                              &error_string);
        
        data_blob_free(&nt_response);
@@ -1316,7 +1506,7 @@ static BOOL test_ntlm_in_both(void)
                DEBUG(1, ("nt_key:\n"));
                dump_data(1, nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, session_key.data, session_key.length);
+               dump_data(1, (const char *)session_key.data, session_key.length);
                pass = False;
        }
 
@@ -1378,9 +1568,9 @@ static BOOL test_ntlmv2(void)
                   sizeof(nt_key)) != 0) {
                DEBUG(1, ("NT Session Key does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 16);
+               dump_data(1, (const char *)nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, nt_session_key.data, nt_session_key.length);
+               dump_data(1, (const char *)nt_session_key.data, nt_session_key.length);
                pass = False;
        }
         return pass;
@@ -1442,9 +1632,9 @@ static BOOL test_lmv2_ntlmv2(void)
                   sizeof(nt_key)) != 0) {
                DEBUG(1, ("NT Session Key does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 16);
+               dump_data(1, (const char *)nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, nt_session_key.data, nt_session_key.length);
+               dump_data(1, (const char *)nt_session_key.data, nt_session_key.length);
                pass = False;
        }
         return pass;
@@ -1557,18 +1747,18 @@ static BOOL test_ntlm_broken(BOOL break_lm)
                   sizeof(lm_key)) != 0) {
                DEBUG(1, ("LM Key does not match expectations!\n"));
                DEBUG(1, ("lm_key:\n"));
-               dump_data(1, lm_key, 8);
+               dump_data(1, (const char *)lm_key, 8);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, lm_hash, 8);
+               dump_data(1, (const char *)lm_hash, 8);
                pass = False;
        }
        if (memcmp(session_key.data, nt_key, 
                   sizeof(nt_key)) != 0) {
                DEBUG(1, ("NT Session Key does not match expectations!\n"));
                DEBUG(1, ("nt_key:\n"));
-               dump_data(1, nt_key, 16);
+               dump_data(1, (const char *)nt_key, 16);
                DEBUG(1, ("expected:\n"));
-               dump_data(1, session_key.data, session_key.length);
+               dump_data(1, (const char *)session_key.data, session_key.length);
                pass = False;
        }
         return pass;
index 23df26d15022b5045e40d8cf480a81bfb061627e..3230eb21fc88fb44555f180743d38f19968dd4f6 100644 (file)
@@ -448,7 +448,7 @@ static int get_sid(DOM_SID *sid, const unsigned char *sid_str)
 
     SIVAL(&sid->sub_auths[i], 0, auth);
     i++;
-    lstr = strchr(lstr + 1, '-'); 
+    lstr = (const unsigned char *)strchr(lstr + 1, '-'); 
   }
 
   return 1;
index c90c042106e531c76a6a228bcffd3efc32dd27f2..58ee57b5dd2ad0d4d62d10c8150bc2c7cb99004e 100644 (file)
@@ -751,7 +751,7 @@ static struct cli_state *connect_one(const char *share)
                POPT_AUTOHELP
                { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" },
                { "modify", 'M', POPT_ARG_STRING, NULL, 'M', "Modify an acl", "ACL" },
-               { "add", 'A', POPT_ARG_STRING, NULL, 'A', "Add an acl", "ACL" },
+               { "add", 'a', POPT_ARG_STRING, NULL, 'a', "Add an acl", "ACL" },
                { "set", 'S', POPT_ARG_STRING, NULL, 'S', "Set acls", "ACLS" },
                { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
                { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" },
@@ -796,7 +796,7 @@ static struct cli_state *connect_one(const char *share)
                        mode = SMB_ACL_MODIFY;
                        break;
 
-               case 'A':
+               case 'a':
                        the_acl = smb_xstrdup(poptGetOptArg(pc));
                        mode = SMB_ACL_ADD;
                        break;
diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c
deleted file mode 100644 (file)
index 0faa051..0000000
+++ /dev/null
@@ -1,405 +0,0 @@
-/* 
- *  Unix SMB/CIFS implementation.
- *  RPC Pipe client / server routines
- *  Copyright (C) Andrew Tridgell              1992-2000,
- *  Copyright (C) Jean François Micouleau      1998-2001.
- *  
- *  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
- *  (at your option) any later version.
- *  
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  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.
- */
-
-#include "includes.h"
-
-/*
- * Next two lines needed for SunOS and don't
- * hurt anything else...
- */
-extern char *optarg;
-extern int optind;
-
-/*********************************************************
- Print command usage on stderr and die.
-**********************************************************/
-static void usage(void)
-{
-       if (getuid() == 0) {
-               printf("smbgroupedit options\n");
-       } else {
-               printf("You need to be root to use this tool!\n");
-       }
-       printf("options:\n");
-       printf("  -a group             create new group\n");
-       printf("    -n group           NT group name\n");
-       printf("    -p privilege       only local\n");
-       printf("    -d description     group description\n");
-       printf("  -v                   list groups\n");
-       printf("    -l                 long list (include details)\n");
-       printf("    -s                 short list (default)\n");
-       printf("  -c SID               change group\n");
-       printf("     -u unix group\n");
-       printf("     -d description    group description\n");
-       printf("  -r rid               RID of new group\n");
-       printf("  -x group             delete this group\n");
-       printf("\n");
-       printf("    -t[b|d|l]          type: builtin, domain, local \n");
-       exit(1);
-}
-
-/*********************************************************
- Figure out if the input was an NT group or a SID string.  
- Return the SID.
-**********************************************************/
-static BOOL get_sid_from_input(DOM_SID *sid, char *input) 
-{
-       GROUP_MAP map;
-       
-       if (StrnCaseCmp( input, "S-", 2)) {
-               /* Perhaps its the NT group name? */
-               if (!pdb_getgrnam(&map, input, MAPPING_WITHOUT_PRIV)) {
-                       printf("NT Group %s doesn't exist in mapping DB\n", input);
-                       return False;
-               } else {
-                       *sid = map.sid;
-               }
-       } else {
-               if (!string_to_sid(sid, input)) {
-                       printf("converting sid %s from a string failed!\n", input);
-                       return False;
-               }
-       }
-       return True;
-}
-
-/*********************************************************
- add a group.
-**********************************************************/
-static int addgroup(gid_t gid, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcomment, char *privilege, uint32 rid)
-{
-       PRIVILEGE_SET se_priv;
-       DOM_SID sid;
-       fstring string_sid;
-       fstring comment;
-
-       sid_copy(&sid, get_global_sam_sid());
-       sid_append_rid(&sid, rid);
-       
-       sid_to_string(string_sid, &sid);
-       
-       if (ntcomment==NULL)
-               fstrcpy(comment, "Local Unix group");
-       else
-               fstrcpy(comment, ntcomment);
-
-       init_privilege(&se_priv);
-       if (privilege!=NULL)
-               convert_priv_from_text(&se_priv, privilege);
-
-       if(!add_initial_entry(gid, string_sid, sid_type, ntgroup,
-                             comment, se_priv, PR_ACCESS_FROM_NETWORK)) {
-               printf("adding entry for group %s failed!\n", ntgroup);
-               free_privilege(&se_priv);
-               return -1;
-       }
-
-       free_privilege(&se_priv);
-       return 0;
-}
-
-/*********************************************************
- Change a group.
-**********************************************************/
-static int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *groupdesc, char *privilege)
-{
-       DOM_SID sid;
-       GROUP_MAP map;
-       gid_t gid;
-
-       if (!get_sid_from_input(&sid, sid_string)) {
-               return -1;
-       }
-
-       /* Get the current mapping from the database */
-       if(!pdb_getgrsid(&map, sid, MAPPING_WITH_PRIV)) {
-               printf("This SID does not exist in the database\n");
-               return -1;
-       }
-
-       /* If a new Unix group is specified, check and change */
-       if (group!=NULL) {
-               gid=nametogid(group);
-               if (gid==-1) {
-                       printf("The UNIX group does not exist\n");
-                       return -1;
-               } else
-                       map.gid=gid;
-       }
-       
-       /*
-        * Allow changing of group type only between domain and local
-        * We disallow changing Builtin groups !!! (SID problem)
-        */ 
-       if (sid_type==SID_NAME_ALIAS 
-           || sid_type==SID_NAME_DOM_GRP 
-           || sid_type==SID_NAME_UNKNOWN) {
-               if (map.sid_name_use==SID_NAME_ALIAS 
-                   || map.sid_name_use==SID_NAME_DOM_GRP
-                   || map.sid_name_use==SID_NAME_UNKNOWN) {
-                       map.sid_name_use=sid_type;
-               } else {
-                       printf("cannot change group type to builtin\n");
-               };
-       } else {
-               printf("cannot change group type from builtin\n");
-       }
-
-       if (ntgroup!=NULL)
-               fstrcpy(map.nt_name, ntgroup);
-
-       /* Change comment if new one */
-       if (groupdesc!=NULL)
-               fstrcpy(map.comment, groupdesc);
-
-       /* Change the privilege if new one */
-       if (privilege!=NULL)
-               convert_priv_from_text(&map.priv_set, privilege);
-
-       if (!pdb_update_group_mapping_entry(&map)) {
-               printf("Could not update group database\n");
-               free_privilege(&map.priv_set);
-               return -1;
-       }
-       
-       free_privilege(&map.priv_set);
-       return 0;
-}
-
-/*********************************************************
- Delete the group.
-**********************************************************/
-static int deletegroup(char *group)
-{
-       DOM_SID sid;
-
-       if (!get_sid_from_input(&sid, group)) {
-               return -1;
-       }
-
-       if(!pdb_delete_group_mapping_entry(sid)) {
-               printf("removing group %s from the mapping db failed!\n", group);
-               return -1;
-       }
-
-       return 0;
-}
-
-/*********************************************************
- List the groups.
-**********************************************************/
-static int listgroup(enum SID_NAME_USE sid_type, BOOL long_list)
-{
-       int entries,i;
-       GROUP_MAP *map=NULL;
-       fstring string_sid;
-       fstring group_type;
-       fstring priv_text;
-
-       if (!long_list)
-               printf("NT group (SID) -> Unix group\n");
-               
-       if (!pdb_enum_group_mapping(sid_type, &map, &entries, ENUM_ALL_MAPPED, MAPPING_WITH_PRIV))
-               return -1;
-       
-       for (i=0; i<entries; i++) {
-               decode_sid_name_use(group_type, (map[i]).sid_name_use);
-               sid_to_string(string_sid, &map[i].sid);
-               convert_priv_to_text(&(map[i].priv_set), priv_text);
-               free_privilege(&(map[i].priv_set));
-               
-               if (!long_list)
-                       printf("%s (%s) -> %s\n", map[i].nt_name, string_sid, gidtoname(map[i].gid));
-               else {
-                       printf("%s\n", map[i].nt_name);
-                       printf("\tSID       : %s\n", string_sid);
-                       printf("\tUnix group: %s\n", gidtoname(map[i].gid));
-                       printf("\tGroup type: %s\n", group_type);
-                       printf("\tComment   : %s\n", map[i].comment);
-                       printf("\tPrivilege : %s\n\n", priv_text);
-               }
-       }
-
-       return 0;
-}
-
-/*********************************************************
- Start here.
-**********************************************************/
-int main (int argc, char **argv)
-{
-       int ch;
-       BOOL add_group = False;
-       BOOL view_group = False;
-       BOOL change_group = False;
-       BOOL delete_group = False;
-       BOOL nt_group = False;
-       BOOL priv = False;
-       BOOL group_type = False;
-       BOOL long_list = False;
-
-       char *group = NULL;
-       char *sid = NULL;
-       char *ntgroup = NULL;
-       char *privilege = NULL;
-       char *groupt = NULL;
-       char *group_desc = NULL;
-
-       enum SID_NAME_USE sid_type;
-       uint32 rid = -1;
-
-       setup_logging("groupedit", True);
-
-       if (argc < 2) {
-               usage();
-               return 0;
-       }
-       
-       if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
-               fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
-                       dyn_CONFIGFILE);
-               exit(1);
-       }
-
-       if (!init_names())
-               exit(1);
-       
-       if(!initialize_password_db(True)) {
-               fprintf(stderr, "Can't setup password database vectors.\n");
-               exit(1);
-       }
-       
-       if(get_global_sam_sid()==False) {
-               fprintf(stderr, "Can not read machine SID\n");
-               return 0;
-       }
-
-       while ((ch = getopt(argc, argv, "a:c:d:ln:p:r:st:u:vx:")) != EOF) {
-               switch(ch) {
-               case 'a':
-                       add_group = True;
-                       group=optarg;
-                       break;
-               case 'c':
-                       change_group = True;
-                       sid=optarg;
-                       break;
-               case 'd':
-                       group_desc=optarg;
-                       break;
-               case 'l':
-                       long_list = True;
-                       break;
-               case 'n':
-                       nt_group = True;
-                       ntgroup=optarg;
-                       break;
-               case 'p':
-                       priv = True;
-                       privilege=optarg;
-                       break;
-               case 'r':
-                       rid = atoi(optarg);
-                       break;
-               case 's':
-                       long_list = False;
-                       break;
-               case 't':
-                       group_type = True;
-                       groupt=optarg;
-                       break;
-               case 'u':
-                       group=optarg;
-                       break;
-               case 'v':
-                       view_group = True;
-                       break;
-               case 'x':
-                       delete_group = True;
-                       group=optarg;
-                       break;
-               /*default:
-                       usage();*/
-               }
-       }
-       
-       
-       if (((add_group?1:0) + (view_group?1:0) + (change_group?1:0) + (delete_group?1:0)) > 1) {
-               fprintf (stderr, "Incompatible options on command line!\n");
-               usage();
-               exit(1);
-       }
-
-       /* no option on command line -> list groups */  
-       if (((add_group?1:0) + (view_group?1:0) + (change_group?1:0) + (delete_group?1:0)) == 0)
-               view_group = True;
-
-       
-       if (group_type==False)
-               sid_type=SID_NAME_UNKNOWN;
-       else {
-               switch (groupt[0]) {
-                       case 'l':
-                       case 'L':
-                               sid_type=SID_NAME_ALIAS;
-                               break;
-                       case 'd':
-                       case 'D':
-                               sid_type=SID_NAME_DOM_GRP;
-                               break;
-                       case 'b':
-                       case 'B':
-                               sid_type=SID_NAME_WKN_GRP;
-                               break;
-                       default:
-                               sid_type=SID_NAME_UNKNOWN;
-                               break;
-               }
-       }
-
-       if (add_group) {
-               gid_t gid=nametogid(group);
-               if (gid==-1) {
-                       printf("unix group %s doesn't exist!\n", group);
-                       return -1;
-               }
-
-               if (rid == -1) {
-                       rid = pdb_gid_to_group_rid(gid);
-               }
-               return addgroup(gid, sid_type, ntgroup?ntgroup:group,
-                               group_desc, privilege, rid);
-       }
-
-       if (view_group)
-               return listgroup(sid_type, long_list);
-
-       if (delete_group)
-               return deletegroup(group);
-       
-       if (change_group) {             
-               return changegroup(sid, group, sid_type, ntgroup, group_desc, privilege);
-       }
-       
-       usage();
-
-       return 0;
-}
index 8bf67fc4d634b6578181841d0b9afedf02cbf7f5..c17e080b6bf384afc47174d12d062f97f0a4792b 100644 (file)
@@ -597,7 +597,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
        } else {
                if (locks_only) goto locks;
 
-               d_printf("\nSamba version %s\n",VERSION);
+               d_printf("\nSamba version %s\n",SAMBA_VERSION_STRING);
                d_printf("PID     Username      Group         Machine                        \n");
                d_printf("-------------------------------------------------------------------\n");
 
index 16918ecd4ae41a2cd24717391e0e34a19e1a43b2..0a87b4bc1eacd86c2a96d7114fa1ca87c9475abc 100644 (file)
@@ -287,6 +287,27 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
                                           Level II oplocks can only be set if oplocks are also set.\n",
                                           lp_servicename(s) );
                        }
+
+                       if (lp_map_hidden(s) && !(lp_create_mask(s) & S_IXOTH)) {
+                               printf("Invalid combination of parameters for service %s. \
+                                          Map hidden can only work if create mask includes octal 01 (S_IXOTH).\n",
+                                          lp_servicename(s) );
+                       }
+                       if (lp_map_hidden(s) && (lp_force_create_mode(s) & S_IXOTH)) {
+                               printf("Invalid combination of parameters for service %s. \
+                                          Map hidden can only work if force create mode excludes octal 01 (S_IXOTH).\n",
+                                          lp_servicename(s) );
+                       }
+                       if (lp_map_system(s) && !(lp_create_mask(s) & S_IXGRP)) {
+                               printf("Invalid combination of parameters for service %s. \
+                                          Map system can only work if create mask includes octal 010 (S_IXGRP).\n",
+                                          lp_servicename(s) );
+                       }
+                       if (lp_map_system(s) && (lp_force_create_mode(s) & S_IXGRP)) {
+                               printf("Invalid combination of parameters for service %s. \
+                                          Map system can only work if force create mode excludes octal 010 (S_IXGRP).\n",
+                                          lp_servicename(s) );
+                       }
                }
        }
 
index c579e8f1123e1eca13c2b4519b72290574090eb6..21d7e4573893fe4c50c266775cf1ce061388cc7c 100644 (file)
@@ -327,7 +327,7 @@ void status_page(void)
 
        d_printf("<table>\n");
 
-       d_printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), VERSION);
+       d_printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING);
 
        fflush(stdout);
        d_printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
index a1c132a08854b3bda39d45af14c3a9d5e3cc6540..1c892559dd97f5b4971de3796d53985f91f1aa8d 100644 (file)
@@ -737,7 +737,16 @@ static void wizard_page(void)
        d_printf("<td><input type=radio name=\"WINSType\" value=0 %s> Not Used&nbsp;</td>", (winstype == 0) ? "checked" : "");
        d_printf("<td><input type=radio name=\"WINSType\" value=1 %s> Server for client use&nbsp;</td>", (winstype == 1) ? "checked" : "");
        d_printf("<td><input type=radio name=\"WINSType\" value=2 %s> Client of another WINS server&nbsp;</td>", (winstype == 2) ? "checked" : "");
-       d_printf("<tr><td></td><td></td><td></td><td>Remote WINS Server&nbsp;<input type=text size=\"16\" name=\"WINSAddr\" value=\"%s\"></td></tr>",lp_wins_server_list());
+       d_printf("<tr><td></td><td></td><td></td><td>Remote WINS Server&nbsp;<input type=text size=\"16\" name=\"WINSAddr\" value=\"");
+       
+       /* Print out the list of wins servers */
+       if(lp_wins_server_list()) {
+               int i;
+               const char **wins_servers = lp_wins_server_list();
+               for(i = 0; wins_servers[i]; i++) d_printf("%s ", wins_servers[i]);
+       }
+       
+       d_printf("\"></td></tr>");
        if (winstype == 3) {
                d_printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">Error: WINS Server Mode and WINS Support both set in smb.conf</font></td></tr>");
                d_printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">Please Select desired WINS mode above.</font></td></tr>");
index 504818b8d5277d80e8e3f5d7660f14b3b960aae4..25de680982ce8722775c0feeeb70b68a53ca8dfb 100644 (file)
@@ -586,7 +586,7 @@ static void process(void)
 
        reopen_logs();
 
-       DEBUG(1,( "wrepld version %s started.\n", VERSION));
+       DEBUG(1,( "wrepld version %s started.\n", SAMBA_VERSION_STRING));
        DEBUGADD(1,( "Copyright Andrew Tridgell and the Samba Team 1992-2002\n"));
 
        DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",