Rev 5366: merge from upstream in http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

Michael Adam ma at sernet.de
Tue Apr 17 20:33:21 GMT 2007


At http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

------------------------------------------------------------
revno: 5366
revision-id: ma at sernet.de-20070417203314-fd8138bdafee1c09
parent: ma at sernet.de-20070416232634-c01bd4ddb6932dd1
parent: metze at samba.org-20070417170717-d21x3e2w4vg57tcd
committer: Michael Adam <ma at sernet.de>
branch nick: SAMBA_3_0-registry.bzr
timestamp: Tue 2007-04-17 22:33:14 +0200
message:
  merge from upstream
removed:
  source/lib/tdb/common/tdbback.c tdbback.c-20070416111147-cebijg5x16vcb45j-23
  source/lib/tdb/include/tdbback.h tdbback.h-20070416111147-cebijg5x16vcb45j-29
modified:
  REVISION                       REVISION-20060530022625-68239662668b41c3
  source/Makefile.in             Makefile.in-20060530022626-b16dac2328ebe703
  source/configure.in            configure.in-20060530022626-07e74bc1e326c82d
  source/include/includes.h      includes.h-20060530022627-d1a059a99c05e8be
  source/include/smb_macros.h    smb_macros.h-20060530022627-412e2056512de943
  source/lib/replace/README      readme-20060919015053-50coyc2ouwpsm77j-17
  source/lib/replace/replace.h   replace.h-20060919015053-50coyc2ouwpsm77j-19
  source/lib/tdb/tools/tdbbackup.c tdbbackup.c-20070416111147-cebijg5x16vcb45j-33
  source/lib/tdb/tools/tdbdump.c tdbdump.c-20070416111147-cebijg5x16vcb45j-34
  source/nsswitch/idmap_tdb.c    idmap_tdb.c-20061212152807-vd9wgefsa63jj0is-1
  source/nsswitch/winbind_nss_config.h winbind_nss_config.h-20060530022627-1477f6076c79e493
  source/smbd/reply.c            reply.c-20060530022627-92de20342694c043
    ------------------------------------------------------------
    merged: metze at samba.org-20070417170717-d21x3e2w4vg57tcd
    parent: metze at samba.org-20070417170545-4nt0iwz2dq4x7ecu
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 12:07:17 -0500
    message:
      metze at samba.org (r22315)  2007-04-17 11:53:06 -0500 (Tue, 17 Apr 2007)
          
          move tdbback.c content into tdbbackup.c
          and make the functions static.
          
          also use libreplace headers in tdbbackup.c
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417170545-4nt0iwz2dq4x7ecu
    parent: metze at samba.org-20070417170323-w29nfl4cd1aure5q
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 12:05:45 -0500
    message:
      metze at samba.org (r22314)  2007-04-17 11:36:24 -0500 (Tue, 17 Apr 2007)
          
          use libreplace headers
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417170323-w29nfl4cd1aure5q
    parent: metze at samba.org-20070417170142-r1z391jp128hcvjw
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 12:03:23 -0500
    message:
      metze at samba.org (r22313)  2007-04-17 11:06:20 -0500 (Tue, 17 Apr 2007)
          
          as discussed with simo:
          
          remove the only usage of backup_tdb() in samba3.
          As backup_tdb() will go completely soon.
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417170142-r1z391jp128hcvjw
    parent: metze at samba.org-20070417110332-vfs9ymzdf32ils5u
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 12:01:42 -0500
    message:
      metze at samba.org (r22304)  2007-04-17 07:21:47 -0500 (Tue, 17 Apr 2007)
          
          remove unused stuff completely to fix the build, sorry
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417110332-vfs9ymzdf32ils5u
    parent: metze at samba.org-20070417110205-c4dqe7bh3hs0xq6l
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 06:03:32 -0500
    message:
      metze at samba.org (r22302)  2007-04-17 05:07:12 -0500 (Tue, 17 Apr 2007)
          
          fix the build when no shared-library support is detected
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417110205-c4dqe7bh3hs0xq6l
    parent: metze at samba.org-20070417110110-b9exui7wmhukqz7g
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 06:02:05 -0500
    message:
      metze at samba.org (r22301)  2007-04-17 05:05:43 -0500 (Tue, 17 Apr 2007)
          
          remove unused vars
          
          metze
    ------------------------------------------------------------
    merged: metze at samba.org-20070417110110-b9exui7wmhukqz7g
    parent: jra at samba.org-20070417050051-y96qb142g3w64nw3
    committer: metze at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 06:01:10 -0500
    message:
      metze at samba.org (r22298)  2007-04-17 03:03:29 -0500 (Tue, 17 Apr 2007)
          
          move ZERO_*, ARRAY_SIZE and PTR_DIFF macros into libreplace
          
          metze
    ------------------------------------------------------------
    merged: jra at samba.org-20070417050051-y96qb142g3w64nw3
    parent: jra at samba.org-20070416230319-bj51pdyg19el7zr6
    committer: jra at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Tue 2007-04-17 00:00:51 -0500
    message:
      jra at samba.org (r22291)  2007-04-16 21:14:28 -0500 (Mon, 16 Apr 2007)
          
          Fix off-by-one in tconX parsing.
          Jeremy.
          
=== removed file 'source/lib/tdb/common/tdbback.c'
--- a/source/lib/tdb/common/tdbback.c	2007-04-16 11:11:51 +0000
+++ b/source/lib/tdb/common/tdbback.c	1970-01-01 00:00:00 +0000
@@ -1,227 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   low level tdb backup and restore utility
-   Copyright (C) Andrew Tridgell              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.
-*/
-
-#ifdef STANDALONE
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/mman.h>
-
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <ctype.h>
-#include <signal.h>
-
-#else
-#include "includes.h"
-
-#ifdef malloc
-#undef malloc
-#endif
-                                                                                                                 
-#ifdef realloc
-#undef realloc
-#endif
-                                                                                                                 
-#ifdef calloc
-#undef calloc
-#endif
-
-#endif
-
-#include "tdb.h"
-
-static int failed;
-
-char *add_suffix(const char *name, const char *suffix)
-{
-	char *ret;
-	int len = strlen(name) + strlen(suffix) + 1;
-	ret = (char *)malloc(len);
-	if (!ret) {
-		fprintf(stderr,"Out of memory!\n");
-		exit(1);
-	}
-	snprintf(ret, len, "%s%s", name, suffix);
-	return ret;
-}
-
-static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
-{
-	TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state;
-
-	if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) {
-		fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb));
-		failed = 1;
-		return 1;
-	}
-	return 0;
-}
-
-
-static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
-{
-	return 0;
-}
-
-/*
-  carefully backup a tdb, validating the contents and
-  only doing the backup if its OK
-  this function is also used for restore
-*/
-int backup_tdb(const char *old_name, const char *new_name, int hash_size)
-{
-	TDB_CONTEXT *tdb;
-	TDB_CONTEXT *tdb_new;
-	char *tmp_name;
-	struct stat st;
-	int count1, count2;
-
-	tmp_name = add_suffix(new_name, ".tmp");
-
-	/* stat the old tdb to find its permissions */
-	if (stat(old_name, &st) != 0) {
-		perror(old_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	/* open the old tdb */
-	tdb = tdb_open(old_name, 0, 0, O_RDWR, 0);
-	if (!tdb) {
-		printf("Failed to open %s\n", old_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	/* create the new tdb */
-	unlink(tmp_name);
-	tdb_new = tdb_open(tmp_name,
-			   hash_size ? hash_size : tdb_hash_size(tdb),
-			   TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, 
-			   st.st_mode & 0777);
-	if (!tdb_new) {
-		perror(tmp_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	/* lock the old tdb */
-	if (tdb_lockall(tdb) != 0) {
-		fprintf(stderr,"Failed to lock %s\n", old_name);
-		tdb_close(tdb);
-		tdb_close(tdb_new);
-		unlink(tmp_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	failed = 0;
-
-	/* traverse and copy */
-	count1 = tdb_traverse(tdb, copy_fn, (void *)tdb_new);
-	if (count1 < 0 || failed) {
-		fprintf(stderr,"failed to copy %s\n", old_name);
-		tdb_close(tdb);
-		tdb_close(tdb_new);
-		unlink(tmp_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	/* close the old tdb */
-	tdb_close(tdb);
-
-	/* close the new tdb and re-open read-only */
-	tdb_close(tdb_new);
-	tdb_new = tdb_open(tmp_name, 0, TDB_DEFAULT, O_RDONLY, 0);
-	if (!tdb_new) {
-		fprintf(stderr,"failed to reopen %s\n", tmp_name);
-		unlink(tmp_name);
-		perror(tmp_name);
-		free(tmp_name);
-		return 1;
-	}
-	
-	/* traverse the new tdb to confirm */
-	count2 = tdb_traverse(tdb_new, test_fn, 0);
-	if (count2 != count1) {
-		fprintf(stderr,"failed to copy %s\n", old_name);
-		tdb_close(tdb_new);
-		unlink(tmp_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	/* make sure the new tdb has reached stable storage */
-	fsync(tdb_fd(tdb_new));
-
-	/* close the new tdb and rename it to .bak */
-	tdb_close(tdb_new);
-	unlink(new_name);
-	if (rename(tmp_name, new_name) != 0) {
-		perror(new_name);
-		free(tmp_name);
-		return 1;
-	}
-
-	free(tmp_name);
-
-	return 0;
-}
-
-
-
-/*
-  verify a tdb and if it is corrupt then restore from *.bak
-*/
-int verify_tdb(const char *fname, const char *bak_name)
-{
-	TDB_CONTEXT *tdb;
-	int count = -1;
-
-	/* open the tdb */
-	tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
-
-	/* traverse the tdb, then close it */
-	if (tdb) {
-		count = tdb_traverse(tdb, test_fn, NULL);
-		tdb_close(tdb);
-	}
-
-	/* count is < 0 means an error */
-	if (count < 0) {
-		printf("restoring %s\n", fname);
-		return backup_tdb(bak_name, fname, 0);
-	}
-
-	printf("%s : %d records\n", fname, count);
-
-	return 0;
-}

=== removed file 'source/lib/tdb/include/tdbback.h'
--- a/source/lib/tdb/include/tdbback.h	2007-04-16 11:11:51 +0000
+++ b/source/lib/tdb/include/tdbback.h	1970-01-01 00:00:00 +0000
@@ -1,23 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   low level tdb backup and restore utility
-   Copyright (C) Andrew Tridgell              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.
-*/
-
-char *add_suffix(const char *name, const char *suffix);
-int backup_tdb(const char *old_name, const char *new_name, int hash_size);
-int verify_tdb(const char *fname, const char *bak_name);

=== modified file 'REVISION'
--- a/REVISION	2007-04-16 23:03:19 +0000
+++ b/REVISION	2007-04-17 17:07:17 +0000
@@ -2,9 +2,9 @@
 URL: svn+ssh://svn.samba.org/home/svn/samba/branches/SAMBA_3_0
 Repository Root: svn+ssh://svn.samba.org/home/svn/samba
 Repository UUID: 0c0555d6-39d7-0310-84fc-f1cc0bd64818
-Revision: 22285
+Revision: 22315
 Node Kind: directory
-Last Changed Author: jra
-Last Changed Rev: 22285
-Last Changed Date: 2007-04-16 17:42:45 -0500 (Mon, 16 Apr 2007)
+Last Changed Author: metze
+Last Changed Rev: 22315
+Last Changed Date: 2007-04-17 11:53:06 -0500 (Tue, 17 Apr 2007)
 

=== modified file 'source/Makefile.in'
--- a/source/Makefile.in	2007-04-16 23:26:34 +0000
+++ b/source/Makefile.in	2007-04-17 20:33:14 +0000
@@ -126,7 +126,7 @@
 LIBADDNS_MAJOR=0
 LIBADDNS_MINOR=1
 
-FLAGS1 = $(CFLAGS) @FLAGS1@ @SAMBA_CPPFLAGS@ @SMBWRAP_INC@ $(CPPFLAGS)
+FLAGS1 = $(CFLAGS) @FLAGS1@ @SAMBA_CPPFLAGS@ $(CPPFLAGS)
 FLAGS2 =
 FLAGS3 =
 FLAGS4 =
@@ -176,7 +176,7 @@
 
 PAM_MODULES = @PAM_MODULES@
 
-NSS_MODULES = @WINBIND_WINS_NSS@ @WINBIND_NSS@
+NSS_MODULES = @NSS_MODULES@
 
 SCRIPTS = $(srcdir)/script/smbtar $(builddir)/script/findsmb
 
@@ -200,7 +200,7 @@
 	lib/tdb/common/open.o lib/tdb/common/transaction.o \
 	lib/tdb/common/traverse.o
 
-TDB_OBJ = $(TDBBASE_OBJ) lib/util_tdb.o lib/tdb/common/tdbback.o
+TDB_OBJ = $(TDBBASE_OBJ) lib/util_tdb.o
 
 SMBLDAP_OBJ = @SMBLDAP@ @SMBLDAPUTIL@
 
@@ -848,7 +848,7 @@
 PROTO_OBJ = $(SMBD_OBJ_MAIN) $(LIBNDR_OBJ) $(RPCCLIENT_NDR_OBJ) \
 			$(LIBNDR_GEN_OBJ) $(SMBD_OBJ_SRV) $(NMBD_OBJ1) $(LIBSMB_OBJ) \
 	    $(SMBTORTURE_OBJ1) $(RPCCLIENT_OBJ1) \
-	    $(LIBMSRPC_OBJ) @SMBWRAP_OBJS@ \
+	    $(LIBMSRPC_OBJ) \
 	    $(LIB_WITH_PROTO_OBJ) \
 	    $(RPC_PIPE_OBJ) $(RPC_PARSE_OBJ) $(KRBCLIENT_OBJ) \
 	    $(AUTH_OBJ) $(PARAM_OBJ) $(LOCKING_OBJ) $(SECRETS_OBJ) \
@@ -961,7 +961,7 @@
 INIPARSER_OBJ = iniparser/src/iniparser.o iniparser/src/dictionary.o \
 		iniparser/src/strlib.o
 
-TDBBACKUP_OBJ = lib/tdb/tools/tdbbackup.o lib/tdb/common/tdbback.o $(LIBREPLACE_OBJ) \
+TDBBACKUP_OBJ = lib/tdb/tools/tdbbackup.o $(LIBREPLACE_OBJ) \
 	$(TDBBASE_OBJ) $(SOCKET_WRAPPER_OBJ)
 
 TDBTOOL_OBJ = lib/tdb/tools/tdbtool.o $(TDBBASE_OBJ) $(LIBREPLACE_OBJ) \

=== modified file 'source/configure.in'
--- a/source/configure.in	2007-04-16 11:11:51 +0000
+++ b/source/configure.in	2007-04-17 11:03:32 +0000
@@ -297,9 +297,7 @@
 AC_SUBST(PAM_MODULES)
 AC_SUBST(INSTALL_PAM_MODULES)
 AC_SUBST(UNINSTALL_PAM_MODULES)
-AC_SUBST(SMBWRAPPER)
-AC_SUBST(SMBWRAP_OBJS)
-AC_SUBST(SMBWRAP_INC)
+AC_SUBST(NSS_MODULES)
 AC_SUBST(EXTRA_BIN_PROGS)
 AC_SUBST(SMBMOUNT_PROGS)
 AC_SUBST(CIFSMOUNT_PROGS)
@@ -5787,6 +5785,10 @@
 AC_SUBST(WINBIND_NSS_EXTRA_LIBS)
 AC_SUBST(NSSSONAMEVERSIONSUFFIX)
 
+if test $BLDSHARED = true -a x"$HAVE_WINBIND" = x"yes"; then
+	NSS_MODULES="${WINBIND_NSS} ${WINBIND_WINS_NSS}"
+fi
+
 AC_SUBST(SMB_KRB5_LOCATOR)
 
 # Check the setting of --with-winbind

=== modified file 'source/include/includes.h'
--- a/source/include/includes.h	2007-04-06 23:10:10 +0000
+++ b/source/include/includes.h	2007-04-17 17:07:17 +0000
@@ -635,7 +635,6 @@
 #include "dlinklist.h"
 #include "tdb.h"
 #include "util_tdb.h"
-#include "tdbback.h"
 
 #include "lib/talloc/talloc.h"
 /* And a little extension. Abort on type mismatch */

=== modified file 'source/include/smb_macros.h'
--- a/source/include/smb_macros.h	2007-04-16 23:01:29 +0000
+++ b/source/include/smb_macros.h	2007-04-17 11:01:10 +0000
@@ -46,25 +46,6 @@
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
 #endif
 
-/* zero a structure */
-#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
-
-/* zero a structure given a pointer to the structure */
-#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
-
-/* zero a structure given a pointer to the structure - no zero check */
-#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
-
-/* zero an array - note that sizeof(array) must work - ie. it must not be a 
-   pointer */
-#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
-
-/* pointer difference macro */
-#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
-
-/* work out how many elements there are in a static array */
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
-
 /* assert macros */
 #ifdef DEVELOPER
 #define SMB_ASSERT(b) ( (b) ? (void)0 : \

=== modified file 'source/lib/replace/README'
--- a/source/lib/replace/README	2007-04-16 23:01:02 +0000
+++ b/source/lib/replace/README	2007-04-17 11:01:10 +0000
@@ -86,6 +86,12 @@
 MIN
 MAX
 QSORT_CAST
+ZERO_STRUCT
+ZERO_STRUCTP
+ZERO_STRUCTPN
+ZERO_ARRAY
+ARRAY_SIZE
+PTR_DIFF
 
 Headers:
 stdint.h

=== modified file 'source/lib/replace/replace.h'
--- a/source/lib/replace/replace.h	2007-04-16 23:01:02 +0000
+++ b/source/lib/replace/replace.h	2007-04-17 11:01:10 +0000
@@ -451,6 +451,35 @@
 #define __location__ __FILE__ ":" __LINESTR__
 #endif
 
+/** 
+ * zero a structure 
+ */
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+/** 
+ * zero a structure given a pointer to the structure 
+ */
+#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
+
+/** 
+ * zero a structure given a pointer to the structure - no zero check 
+ */
+#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
+
+/* zero an array - note that sizeof(array) must work - ie. it must not be a
+   pointer */
+#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
+
+/**
+ * work out how many elements there are in a static array 
+ */
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+/** 
+ * pointer difference macro 
+ */
+#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
+
 #if MMAP_BLACKLIST
 #undef HAVE_MMAP
 #endif

=== modified file 'source/lib/tdb/tools/tdbbackup.c'
--- a/source/lib/tdb/tools/tdbbackup.c	2007-04-16 11:11:51 +0000
+++ b/source/lib/tdb/tools/tdbbackup.c	2007-04-17 17:07:17 +0000
@@ -41,36 +41,182 @@
 
  */
 
-#ifdef STANDALONE
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <ctype.h>
-#include <signal.h>
-
-#else
-
-#include "includes.h"
-
-#endif
-
+#include "replace.h"
+#include "system/locale.h"
+#include "system/time.h"
+#include "system/filesys.h"
 #include "tdb.h"
-#include "tdbback.h"
-
-extern int optind;
-extern char *optarg;
+
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+static int failed;
+
+static char *add_suffix(const char *name, const char *suffix)
+{
+	char *ret;
+	int len = strlen(name) + strlen(suffix) + 1;
+	ret = (char *)malloc(len);
+	if (!ret) {
+		fprintf(stderr,"Out of memory!\n");
+		exit(1);
+	}
+	snprintf(ret, len, "%s%s", name, suffix);
+	return ret;
+}
+
+static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
+{
+	TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state;
+
+	if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) {
+		fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb));
+		failed = 1;
+		return 1;
+	}
+	return 0;
+}
+
+
+static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
+{
+	return 0;
+}
+
+/*
+  carefully backup a tdb, validating the contents and
+  only doing the backup if its OK
+  this function is also used for restore
+*/
+static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
+{
+	TDB_CONTEXT *tdb;
+	TDB_CONTEXT *tdb_new;
+	char *tmp_name;
+	struct stat st;
+	int count1, count2;
+
+	tmp_name = add_suffix(new_name, ".tmp");
+
+	/* stat the old tdb to find its permissions */
+	if (stat(old_name, &st) != 0) {
+		perror(old_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	/* open the old tdb */
+	tdb = tdb_open(old_name, 0, 0, O_RDWR, 0);
+	if (!tdb) {
+		printf("Failed to open %s\n", old_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	/* create the new tdb */
+	unlink(tmp_name);
+	tdb_new = tdb_open(tmp_name,
+			   hash_size ? hash_size : tdb_hash_size(tdb),
+			   TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, 
+			   st.st_mode & 0777);
+	if (!tdb_new) {
+		perror(tmp_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	/* lock the old tdb */
+	if (tdb_lockall(tdb) != 0) {
+		fprintf(stderr,"Failed to lock %s\n", old_name);
+		tdb_close(tdb);
+		tdb_close(tdb_new);
+		unlink(tmp_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	failed = 0;
+
+	/* traverse and copy */
+	count1 = tdb_traverse(tdb, copy_fn, (void *)tdb_new);
+	if (count1 < 0 || failed) {
+		fprintf(stderr,"failed to copy %s\n", old_name);
+		tdb_close(tdb);
+		tdb_close(tdb_new);
+		unlink(tmp_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	/* close the old tdb */
+	tdb_close(tdb);
+
+	/* close the new tdb and re-open read-only */
+	tdb_close(tdb_new);
+	tdb_new = tdb_open(tmp_name, 0, TDB_DEFAULT, O_RDONLY, 0);
+	if (!tdb_new) {
+		fprintf(stderr,"failed to reopen %s\n", tmp_name);
+		unlink(tmp_name);
+		perror(tmp_name);
+		free(tmp_name);
+		return 1;
+	}
+	
+	/* traverse the new tdb to confirm */
+	count2 = tdb_traverse(tdb_new, test_fn, 0);
+	if (count2 != count1) {
+		fprintf(stderr,"failed to copy %s\n", old_name);
+		tdb_close(tdb_new);
+		unlink(tmp_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	/* make sure the new tdb has reached stable storage */
+	fsync(tdb_fd(tdb_new));
+
+	/* close the new tdb and rename it to .bak */
+	tdb_close(tdb_new);
+	unlink(new_name);
+	if (rename(tmp_name, new_name) != 0) {
+		perror(new_name);
+		free(tmp_name);
+		return 1;
+	}
+
+	free(tmp_name);
+
+	return 0;
+}
+
+/*
+  verify a tdb and if it is corrupt then restore from *.bak
+*/
+static int verify_tdb(const char *fname, const char *bak_name)
+{
+	TDB_CONTEXT *tdb;
+	int count = -1;
+
+	/* open the tdb */
+	tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
+
+	/* traverse the tdb, then close it */
+	if (tdb) {
+		count = tdb_traverse(tdb, test_fn, NULL);
+		tdb_close(tdb);
+	}
+
+	/* count is < 0 means an error */
+	if (count < 0) {
+		printf("restoring %s\n", fname);
+		return backup_tdb(bak_name, fname, 0);
+	}
+
+	printf("%s : %d records\n", fname, count);
+
+	return 0;
+}
 
 /*
   see if one file is newer than another

=== modified file 'source/lib/tdb/tools/tdbdump.c'
--- a/source/lib/tdb/tools/tdbdump.c	2007-04-16 11:11:51 +0000
+++ b/source/lib/tdb/tools/tdbdump.c	2007-04-17 17:05:45 +0000
@@ -18,18 +18,10 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <ctype.h>
-#include <signal.h>
+#include "replace.h"
+#include "system/locale.h"
+#include "system/time.h"
+#include "system/filesys.h"
 #include "tdb.h"
 
 static void print_data(TDB_DATA d)

=== modified file 'source/nsswitch/idmap_tdb.c'
--- a/source/nsswitch/idmap_tdb.c	2007-03-30 15:43:31 +0000
+++ b/source/nsswitch/idmap_tdb.c	2007-04-17 17:03:23 +0000
@@ -115,13 +115,15 @@
  Convert the idmap database from an older version.
 *****************************************************************************/
 
-static BOOL idmap_tdb_convert(const char *idmap_name)
+static BOOL idmap_tdb_upgrade(const char *idmap_name)
 {
 	int32 vers;
 	BOOL bigendianheader;
 	BOOL failed = False;
 	TDB_CONTEXT *idmap_tdb;
 
+	DEBUG(0, ("Upgrading winbindd_idmap.tdb from an old version\n"));
+
 	if (!(idmap_tdb = tdb_open_log(idmap_name, 0,
 					TDB_DEFAULT, O_RDWR,
 					0600))) {
@@ -189,32 +191,6 @@
 	return True;
 }
 
-/*****************************************************************************
- Convert the idmap database from an older version if necessary
-*****************************************************************************/
-
-BOOL idmap_tdb_upgrade(TALLOC_CTX *ctx, const char *tdbfile)
-{
-	char *backup_name;
-
-	DEBUG(0, ("Upgrading winbindd_idmap.tdb from an old version\n"));
-
-	backup_name = talloc_asprintf(ctx, "%s.bak", tdbfile);
-	if ( ! backup_name) {
-		DEBUG(0, ("Out of memory!\n"));
-		return False;
-	}
-
-	if (backup_tdb(tdbfile, backup_name, 0) != 0) {
-		DEBUG(0, ("Could not backup idmap database\n"));
-		talloc_free(backup_name);
-		return False;
-	}
-
-	talloc_free(backup_name);
-	return idmap_tdb_convert(tdbfile);
-}
-
 /* WARNING: We can't open a tdb twice inthe same process, for that reason
  * I'm going to use a hack with open ref counts to open the winbindd_idmap.tdb
  * only once. We will later decide whether to split the db in multiple files
@@ -282,7 +258,7 @@
 		/* backup_tdb expects the tdb not to be open */
 		tdb_close(idmap_tdb_common_ctx);
 
-		if ( ! idmap_tdb_upgrade(ctx, tdbfile)) {
+		if ( ! idmap_tdb_upgrade(tdbfile)) {
 		
 			DEBUG(0, ("Unable to open idmap database, it's in an old formati, and upgrade failed!\n"));
 			ret = NT_STATUS_INTERNAL_DB_ERROR;

=== modified file 'source/nsswitch/winbind_nss_config.h'
--- a/source/nsswitch/winbind_nss_config.h	2006-09-27 16:06:12 +0000
+++ b/source/nsswitch/winbind_nss_config.h	2007-04-17 11:01:10 +0000
@@ -103,18 +103,6 @@
 #endif  /* don't lie.  If we don't have it, then don't use it */
 #endif
 
-
-
-/* zero a structure */
-#ifndef ZERO_STRUCT
-#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
-#endif
-
-/* zero a structure given a pointer to the structure */
-#ifndef ZERO_STRUCTP
-#define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
-#endif
-
 /* Some systems (SCO) treat UNIX domain sockets as FIFOs */
 
 #ifndef S_IFSOCK

=== modified file 'source/smbd/reply.c'
--- a/source/smbd/reply.c	2007-04-09 23:02:01 +0000
+++ b/source/smbd/reply.c	2007-04-17 05:00:51 +0000
@@ -469,13 +469,22 @@
  
 	if (global_encrypted_passwords_negotiated) {
 		password = data_blob(smb_buf(inbuf),passlen);
+		if (lp_security() == SEC_SHARE) {
+			/*
+			 * Security = share always has a pad byte
+			 * after the password.
+			 */
+			p = smb_buf(inbuf) + passlen + 1;
+		} else {
+			p = smb_buf(inbuf) + passlen;
+		}
 	} else {
 		password = data_blob(smb_buf(inbuf),passlen+1);
 		/* Ensure correct termination */
-		password.data[passlen]=0;    
+		password.data[passlen]=0;
+		p = smb_buf(inbuf) + passlen + 1;
 	}
 
-	p = smb_buf(inbuf) + passlen;
 	p += srvstr_pull_buf(inbuf, path, p, sizeof(path), STR_TERMINATE);
 
 	/*



More information about the samba-cvs mailing list