[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed May 4 03:01:03 UTC 2016


The branch, master has been updated
       via  f85b30a s3:smbd remove todo comments
       via  c519cc8 selftest: test for case insensitivity over SMB2/SMB3
       via  a9ccd50 s3:smbd/filename remove smelly code
       via  3242776 s3:smbd/service apply some code formatting
       via  bb9f5ce s3:smbd/service disable case-sensitivity for SMB2/3 connections
       via  87fa3c3 lib: Avoid includes.h in base64.c
       via  93b982f lib: Give base64.c its own .h
       via  9ec3332 lib: Remove SMB_ASSERT from base64_encode_data_blob
       via  cf5a810 lib: Make callers of base64_encode_data_blob check for success
       via  f457535 lib: =0 and |= is equivalent to =
       via  a5fd779 lib: The base64 chars are by definition single-byte :-)
       via  a2c59d3 smbd: use remote arch caching
       via  719e422 s3/lib: add remote arch caching
       via  44c236a s3/lib: add get_remote_arch_from_str()
       via  6b5b004 s3/lib: rework get_remote_arch_str() to use an array
      from  5359031 ldb-samba: Use ndr_pull_struct_blob_all_noalloc

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f85b30ae78c90b7b1ae9bdce099d37728c77c9d4
Author: Christian Ambach <ambi at samba.org>
Date:   Tue Apr 5 14:30:47 2016 +0200

    s3:smbd remove todo comments
    
    as the service is set to be case insensitive for SMB2 now,
    there is no need to set FLAG_CASELESS_PATHNAMES as flag
    
    Signed-off-by: Christian Ambach <ambi at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed May  4 05:00:36 CEST 2016 on sn-devel-144

commit c519cc8b98e05a17698790ebad7dec04531c22d8
Author: Christian Ambach <ambi at samba.org>
Date:   Mon Apr 4 19:28:05 2016 +0200

    selftest: test for case insensitivity over SMB2/SMB3
    
    Signed-off-by: Christian Ambach <ambi at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a9ccd50b63421187c18bfb04001d225d212cdc2a
Author: Christian Ambach <ambi at samba.org>
Date:   Tue Apr 5 02:58:48 2016 +0200

    s3:smbd/filename remove smelly code
    
    not sure how this chunk ended up there, but I agree with
    the statement in the comment that behavior should not depend
    on developer mode
    
    make test does not seem to depend on it anymore.
    
    This piece had some bad influence on the tests I wrote
    for case insensitivite behavior of SMB2/3, so let us
    remove this technical debt.
    
    Signed-off-by: Christian Ambach <ambi at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 32427768610cbe2e5dfe199ab7865b061ea57919
Author: Christian Ambach <ambi at samba.org>
Date:   Sun Apr 3 05:16:45 2016 +0200

    s3:smbd/service apply some code formatting
    
    reduce indentation in switch statement, obey 80 char line limit, use C99 bool
    
    Signed-off-by: Christian Ambach <ambi at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit bb9f5ceeb37df2485f2a9d18fb441e64b168378c
Author: Christian Ambach <ambi at samba.org>
Date:   Sun Apr 3 05:06:05 2016 +0200

    s3:smbd/service disable case-sensitivity for SMB2/3 connections
    
    in SMB2, there is no flag to let us know if the client wants to have case-sensitive behavior,
    so in Auto mode, disable case-sensitivity
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=11438
    Signed-off-by: Christian Ambach <ambi at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 87fa3c36f3bc7848a3fbd06a0dcd7bb49666da74
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 3 16:12:23 2016 +0200

    lib: Avoid includes.h in base64.c
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 93b982faada860b6be178e0dcd4650bf7ca498aa
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 3 16:12:10 2016 +0200

    lib: Give base64.c its own .h
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9ec33323499cae77dba1ea3ff659d3cf59e9e2d4
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 3 15:56:37 2016 +0200

    lib: Remove SMB_ASSERT from base64_encode_data_blob
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit cf5a81013d2dbc62cacaa0141c9ee6b53e13cb39
Author: Volker Lendecke <vl at samba.org>
Date:   Tue May 3 15:54:07 2016 +0200

    lib: Make callers of base64_encode_data_blob check for success
    
    Quite a few callers already did check for !=NULL. With the current code this is
    pointless due to a SMB_ASSERT in base64_encode_data_blob() itself. Make the
    callers consistently check, so that we can remove SMB_ASSERT from base64.c.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f457535e33a35754c069232cb7a27556569b970c
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 25 21:43:57 2016 +0100

    lib: =0 and |= is equivalent to =
    
    Just a small simplication I thought might be nice
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a5fd779aa1393bf83e5dd693293a85b06d8c33c1
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 25 21:43:20 2016 +0100

    lib: The base64 chars are by definition single-byte :-)
    
    Remove a dependency on charcnv
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a2c59d3e45e71b44d9135b35c1cf5522e04dec0e
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Apr 13 17:44:26 2016 +0200

    smbd: use remote arch caching
    
    We're using the client guid as gencache db key, so this can only be used
    with SMB 2_10 or higher.
    
    The idea is that whenever we get a direct SMB2 negprot, we can then try
    to see if a value is cached for the client's guid.
    
    When a user logs off the cache entry is deleted.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 719e42294d33f9e40d6f21c85a59296921b4b297
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Apr 13 17:42:55 2016 +0200

    s3/lib: add remote arch caching
    
    This allows caching the remote arch string in gencache. A subsequent
    commit will use this in SMB2 negprot.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 44c236ac7f586fc5d2d2e7e92eafd9550ecb35f6
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Apr 13 17:55:11 2016 +0200

    s3/lib: add get_remote_arch_from_str()
    
    This will be used when fetching remote arch from gencache.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6b5b00491811758e36ec846432e195d186305ab2
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Apr 13 17:39:26 2016 +0200

    s3/lib: rework get_remote_arch_str() to use an array
    
    By using C99 designated array initializers we can simplify the code and
    remove the dependency on initializers appearing in a particular order.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 auth/gensec/gensec_start.c                         |   1 +
 auth/gensec/spnego.c                               |   1 +
 lib/util/base64.c                                  |  12 +-
 lib/util/base64.h                                  |  52 +++++
 lib/util/charset/tests/convert_string.c            |   1 +
 lib/util/samba_util.h                              |  21 --
 source3/include/proto.h                            |   3 +
 source3/include/smb.h                              |   2 +-
 source3/lib/tldap_util.c                           |   1 +
 source3/lib/util.c                                 | 232 +++++++++++++++++----
 source3/libnet/libnet_dssync_passdb.c              |  11 +-
 source3/libnet/libnet_samsync_ldif.c               |   1 +
 source3/libnet/libnet_samsync_passdb.c             |  10 +-
 source3/passdb/pdb_ipa.c                           |   1 +
 source3/passdb/pdb_samba_dsdb.c                    |   1 +
 source3/rpc_server/samr/srv_samr_nt.c              |   1 +
 source3/rpc_server/samr/srv_samr_util.c            |  23 +-
 .../script/tests/test_smb2_not_casesensitive.sh    |  82 ++++++++
 source3/selftest/tests.py                          |   1 +
 source3/smbd/filename.c                            |  28 ---
 source3/smbd/service.c                             |  50 +++--
 source3/smbd/smb2_negprot.c                        |  13 +-
 source3/smbd/smb2_server.c                         |   1 -
 source3/smbd/smb2_sesssetup.c                      |  11 +
 source3/smbd/smb2_setinfo.c                        |   1 -
 source3/torture/torture.c                          |   1 +
 source3/utils/ntlm_auth.c                          |   3 +
 source4/lib/http/gensec/basic.c                    |   1 +
 source4/lib/http/gensec/ntlm.c                     |   1 +
 source4/ntvfs/posix/python/pyxattr_native.c        |   1 +
 source4/torture/ndr/drsblobs.c                     |   1 +
 source4/utils/ntlm_auth.c                          |   3 +
 32 files changed, 434 insertions(+), 138 deletions(-)
 create mode 100644 lib/util/base64.h
 create mode 100755 source3/script/tests/test_smb2_not_casesensitive.sh


Changeset truncated at 500 lines:

diff --git a/auth/gensec/gensec_start.c b/auth/gensec/gensec_start.c
index 4c43519..1e61627 100644
--- a/auth/gensec/gensec_start.c
+++ b/auth/gensec/gensec_start.c
@@ -31,6 +31,7 @@
 #include "lib/param/param.h"
 #include "lib/util/tsort.h"
 #include "lib/util/samba_modules.h"
+#include "lib/util/base64.h"
 
 /* the list of currently registered GENSEC backends */
 static const struct gensec_security_ops **generic_security_ops;
diff --git a/auth/gensec/spnego.c b/auth/gensec/spnego.c
index 3962d72..ef30ab7 100644
--- a/auth/gensec/spnego.c
+++ b/auth/gensec/spnego.c
@@ -30,6 +30,7 @@
 #include "auth/gensec/gensec_internal.h"
 #include "param/param.h"
 #include "lib/util/asn1.h"
+#include "lib/util/base64.h"
 
 #undef strcasecmp
 
diff --git a/lib/util/base64.c b/lib/util/base64.c
index bc78404..e9906f1 100644
--- a/lib/util/base64.c
+++ b/lib/util/base64.c
@@ -22,7 +22,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
+#include "replace.h"
+#include "lib/util/base64.h"
 
 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
@@ -38,7 +39,7 @@ _PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const cha
 
 	n=i=0;
 
-	while (*s && (p=strchr_m(b64,*s))) {
+	while (*s && (p=strchr(b64,*s))) {
 		idx = (int)(p - b64);
 		byte_offset = (i*6)/8;
 		bit_offset = (i*6)%8;
@@ -48,8 +49,7 @@ _PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const cha
 			n = byte_offset+1;
 		} else {
 			d[byte_offset] |= (idx >> (bit_offset-2));
-			d[byte_offset+1] = 0;
-			d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
+			d[byte_offset+1] = (idx << (8-(bit_offset-2))) & 0xFF;
 			n = byte_offset+2;
 		}
 		s++; i++;
@@ -115,7 +115,9 @@ _PUBLIC_ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
 					   * random but should be enough for
 					   * the = and \0 */
 	result = talloc_array(mem_ctx, char, output_len); /* get us plenty of space */
-	SMB_ASSERT(result != NULL);
+	if (result == NULL) {
+		return NULL;
+	}
 
 	while (len--) {
 		int c = (unsigned char) *(data.data++);
diff --git a/lib/util/base64.h b/lib/util/base64.h
new file mode 100644
index 0000000..4763804
--- /dev/null
+++ b/lib/util/base64.h
@@ -0,0 +1,52 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba utility functions
+ *
+ * Copyright (C) Andrew Tridgell 1992-2001
+ * Copyright (C) Simo Sorce      2001-2002
+ * Copyright (C) Martin Pool     2003
+ * Copyright (C) James Peach	 2006
+ * Copyright (C) Jeremy Allison  1992-2007
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIB_UTIL_BASE64_H__
+#define __LIB_UTIL_BASE64_H__
+
+#include "replace.h"
+#include "lib/util/data_blob.h"
+
+/**
+ Base64 decode a string, place into a data blob.  Caller to
+ data_blob_free() the result.
+**/
+DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const char *s);
+
+/**
+ Base64 decode a string, place into a data blob on NULL context.
+ Caller to data_blob_free() the result.
+**/
+DATA_BLOB base64_decode_data_blob(const char *s);
+
+/**
+ Base64 decode a string, inplace
+**/
+void base64_decode_inplace(char *s);
+/**
+ Base64 encode a binary data blob into a string
+**/
+char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data);
+
+#endif
diff --git a/lib/util/charset/tests/convert_string.c b/lib/util/charset/tests/convert_string.c
index 92de702..e63fca6 100644
--- a/lib/util/charset/tests/convert_string.c
+++ b/lib/util/charset/tests/convert_string.c
@@ -22,6 +22,7 @@
 #include "torture/torture.h"
 #include "lib/util/charset/charset.h"
 #include "param/param.h"
+#include "lib/util/base64.h"
 
 struct torture_suite *torture_local_convert_string_handle(TALLOC_CTX *mem_ctx);
 struct torture_suite *torture_local_string_case_handle(TALLOC_CTX *mem_ctx);
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 387e957..c339161 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -303,27 +303,6 @@ _PUBLIC_ int strwicmp(const char *psz1, const char *psz2);
 _PUBLIC_ void string_replace(char *s, char oldc, char newc);
 
 /**
- Base64 decode a string, place into a data blob.  Caller to data_blob_free() the result.
-**/
-_PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const char *s);
-
-/**
- Base64 decode a string, place into a data blob on NULL context.
- Caller to data_blob_free() the result.
-**/
-_PUBLIC_ DATA_BLOB base64_decode_data_blob(const char *s);
-
-
-/**
- Base64 decode a string, inplace
-**/
-_PUBLIC_ void base64_decode_inplace(char *s);
-/**
- Base64 encode a binary data blob into a string
-**/
-_PUBLIC_ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data);
-
-/**
  * Compare 2 strings.
  *
  * @note The comparison is case-insensitive.
diff --git a/source3/include/proto.h b/source3/include/proto.h
index afbbff0..c032b9e 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -389,8 +389,11 @@ bool fcntl_getlock(int fd, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppi
 bool is_myname(const char *s);
 void ra_lanman_string( const char *native_lanman );
 const char *get_remote_arch_str(void);
+enum remote_arch_types get_remote_arch_from_str(const char *remote_arch_string);
 void set_remote_arch(enum remote_arch_types type);
 enum remote_arch_types get_remote_arch(void);
+bool remote_arch_cache_update(const struct GUID *client_guid);
+bool remote_arch_cache_delete(const struct GUID *client_guid);
 const char *tab_depth(int level, int depth);
 int str_checksum(const char *s);
 void zero_free(void *p, size_t size);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 7eeef88..dec3189 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -529,7 +529,7 @@ http://msdn.microsoft.com/en-us/library/cc246334(PROT.13).aspx
 #define NO_SUBSTREAMS		0x2
 #define NO_REPARSETAG		0x4
 
-/* Remote architectures we know about. */
+/* Remote architectures we know about, keep in sync with remote_arch_strings */
 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT,
 			RA_WIN2K, RA_WINXP, RA_WIN2K3, RA_VISTA,
 			RA_SAMBA, RA_CIFSFS, RA_WINXP64, RA_OSX};
diff --git a/source3/lib/tldap_util.c b/source3/lib/tldap_util.c
index b7233f6..89f812b 100644
--- a/source3/lib/tldap_util.c
+++ b/source3/lib/tldap_util.c
@@ -23,6 +23,7 @@
 #include "../libcli/security/security.h"
 #include "../lib/util/asn1.h"
 #include "../librpc/ndr/libndr.h"
+#include "lib/util/base64.h"
 
 bool tldap_entry_values(struct tldap_message *msg, const char *attribute,
 			DATA_BLOB **values, int *num_values)
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 2895c14..f64f6b5 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1230,14 +1230,46 @@ void ra_lanman_string( const char *native_lanman )
 		set_remote_arch( RA_WIN2K3 );
 }
 
-static const char *remote_arch_str;
+static const char *remote_arch_strings[] = {
+	[RA_UNKNOWN] =	"UNKNOWN",
+	[RA_WFWG] =	"WfWg",
+	[RA_OS2] =	"OS2",
+	[RA_WIN95] =	"Win95",
+	[RA_WINNT] =	"WinNT",
+	[RA_WIN2K] =	"Win2K",
+	[RA_WINXP] =	"WinXP",
+	[RA_WIN2K3] =	"Win2K3",
+	[RA_VISTA] =	"Vista",
+	[RA_SAMBA] =	"Samba",
+	[RA_CIFSFS] =	"CIFSFS",
+	[RA_WINXP64] =	"WinXP64",
+	[RA_OSX] =	"OSX",
+};
 
 const char *get_remote_arch_str(void)
 {
-	if (!remote_arch_str) {
-		return "UNKNOWN";
+	if (ra_type >= ARRAY_SIZE(remote_arch_strings)) {
+		/*
+		 * set_remote_arch() already checks this so ra_type
+		 * should be in the allowed range, but anyway, let's
+		 * do another bound check here.
+		 */
+		DBG_ERR("Remote arch info out of sync [%d] missing\n", ra_type);
+		ra_type = RA_UNKNOWN;
+	}
+	return remote_arch_strings[ra_type];
+}
+
+enum remote_arch_types get_remote_arch_from_str(const char *remote_arch_string)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(remote_arch_strings); i++) {
+		if (strcmp(remote_arch_string, remote_arch_strings[i]) == 0) {
+			return i;
+		}
 	}
-	return remote_arch_str;
+	return RA_UNKNOWN;
 }
 
 /*******************************************************************
@@ -1246,52 +1278,20 @@ const char *get_remote_arch_str(void)
 
 void set_remote_arch(enum remote_arch_types type)
 {
-	ra_type = type;
-	switch( type ) {
-	case RA_WFWG:
-		remote_arch_str = "WfWg";
-		break;
-	case RA_OS2:
-		remote_arch_str = "OS2";
-		break;
-	case RA_WIN95:
-		remote_arch_str = "Win95";
-		break;
-	case RA_WINNT:
-		remote_arch_str = "WinNT";
-		break;
-	case RA_WIN2K:
-		remote_arch_str = "Win2K";
-		break;
-	case RA_WINXP:
-		remote_arch_str = "WinXP";
-		break;
-	case RA_WINXP64:
-		remote_arch_str = "WinXP64";
-		break;
-	case RA_WIN2K3:
-		remote_arch_str = "Win2K3";
-		break;
-	case RA_VISTA:
-		remote_arch_str = "Vista";
-		break;
-	case RA_SAMBA:
-		remote_arch_str = "Samba";
-		break;
-	case RA_CIFSFS:
-		remote_arch_str = "CIFSFS";
-		break;
-	case RA_OSX:
-		remote_arch_str = "OSX";
-		break;
-	default:
+	if (ra_type >= ARRAY_SIZE(remote_arch_strings)) {
+		/*
+		 * This protects against someone adding values to enum
+		 * remote_arch_types without updating
+		 * remote_arch_strings array.
+		 */
+		DBG_ERR("Remote arch info out of sync [%d] missing\n", ra_type);
 		ra_type = RA_UNKNOWN;
-		remote_arch_str = "UNKNOWN";
-		break;
+		return;
 	}
 
+	ra_type = type;
 	DEBUG(10,("set_remote_arch: Client arch is \'%s\'\n",
-				remote_arch_str));
+		  get_remote_arch_str()));
 }
 
 /*******************************************************************
@@ -1303,6 +1303,146 @@ enum remote_arch_types get_remote_arch(void)
 	return ra_type;
 }
 
+#define RA_CACHE_TTL 7*24*3600
+
+static bool remote_arch_cache_key(const struct GUID *client_guid,
+				  fstring key)
+{
+	struct GUID_txt_buf guid_buf;
+	const char *guid_string = NULL;
+
+	guid_string = GUID_buf_string(client_guid, &guid_buf);
+	if (guid_string == NULL) {
+		return false;
+	}
+
+	fstr_sprintf(key, "RA/%s", guid_string);
+	return true;
+}
+
+struct ra_parser_state {
+	bool found;
+	enum remote_arch_types ra;
+};
+
+static void ra_parser(time_t timeout, DATA_BLOB blob, void *priv_data)
+{
+	struct ra_parser_state *state = (struct ra_parser_state *)priv_data;
+	const char *ra_str = NULL;
+
+	if (timeout <= time(NULL)) {
+		return;
+	}
+
+	if ((blob.length == 0) || (blob.data[blob.length-1] != '\0')) {
+		DBG_ERR("Remote arch cache key not a string\n");
+		return;
+	}
+
+	ra_str = (const char *)blob.data;
+	DBG_INFO("Got remote arch [%s] from cache\n", ra_str);
+
+	state->ra = get_remote_arch_from_str(ra_str);
+	state->found = true;
+	return;
+}
+
+static bool remote_arch_cache_get(const struct GUID *client_guid)
+{
+	bool ok;
+	fstring ra_key;
+	struct ra_parser_state state = (struct ra_parser_state) {
+		.found = false,
+		.ra = RA_UNKNOWN,
+	};
+
+	ok = remote_arch_cache_key(client_guid, ra_key);
+	if (!ok) {
+		return false;
+	}
+
+	ok = gencache_parse(ra_key, ra_parser, &state);
+	if (!ok || !state.found) {
+		return true;
+	}
+
+	if (state.ra == RA_UNKNOWN) {
+		return true;
+	}
+
+	set_remote_arch(state.ra);
+	return true;
+}
+
+static bool remote_arch_cache_set(const struct GUID *client_guid)
+{
+	bool ok;
+	fstring ra_key;
+	const char *ra_str = NULL;
+
+	if (get_remote_arch() == RA_UNKNOWN) {
+		return true;
+	}
+
+	ok = remote_arch_cache_key(client_guid, ra_key);
+	if (!ok) {
+		return false;
+	}
+
+	ra_str = get_remote_arch_str();
+	if (ra_str == NULL) {
+		return false;
+	}
+
+	ok = gencache_set(ra_key, ra_str, time(NULL) + RA_CACHE_TTL);
+	if (!ok) {
+		return false;
+	}
+
+	return true;
+}
+
+bool remote_arch_cache_update(const struct GUID *client_guid)
+{
+	bool ok;
+
+	if (get_remote_arch() == RA_UNKNOWN) {
+
+		become_root();
+		ok = remote_arch_cache_get(client_guid);
+		unbecome_root();
+
+		return ok;
+	}
+
+	become_root();
+	ok = remote_arch_cache_set(client_guid);
+	unbecome_root();
+
+	return ok;
+}
+
+bool remote_arch_cache_delete(const struct GUID *client_guid)
+{
+	bool ok;
+	fstring ra_key;
+
+	ok = remote_arch_cache_key(client_guid, ra_key);
+	if (!ok) {
+		return false;
+	}
+
+	become_root();
+	ok = gencache_del(ra_key);
+	unbecome_root();
+
+	if (!ok) {
+		return false;
+	}
+
+	return true;
+}
+
 const char *tab_depth(int level, int depth)
 {
 	if( CHECK_DEBUGLVL(level) ) {
diff --git a/source3/libnet/libnet_dssync_passdb.c b/source3/libnet/libnet_dssync_passdb.c
index 5617776..b80bece 100644
--- a/source3/libnet/libnet_dssync_passdb.c
+++ b/source3/libnet/libnet_dssync_passdb.c
@@ -28,6 +28,7 @@
 #include "dbwrap/dbwrap_rbt.h"
 #include "../libds/common/flag_mapping.h"
 #include "passdb.h"
+#include "lib/util/base64.h"
 
 /****************************************************************
 ****************************************************************/
@@ -1240,10 +1241,14 @@ static NTSTATUS sam_account_from_object(struct samu *account,
 	}
 
 	if (userParameters.data) {
-		char *newstr;
+		char *newstr = NULL;
 		old_string = pdb_get_munged_dial(account);
-		newstr = (userParameters.length == 0) ? NULL :
-			base64_encode_data_blob(talloc_tos(), userParameters);
+
+		if (userParameters.length != 0) {
+			newstr = base64_encode_data_blob(talloc_tos(),


-- 
Samba Shared Repository



More information about the samba-cvs mailing list