[SCM] Samba Shared Repository - branch master updated - c4d3dc849f48a75653d1b16031e9c0657df4d098

Jelmer Vernooij jelmer at samba.org
Sun Oct 12 00:28:22 GMT 2008


The branch, master has been updated
       via  c4d3dc849f48a75653d1b16031e9c0657df4d098 (commit)
       via  d7371dae24a8ec341713d004c2ac9444ec4b14de (commit)
       via  771e25b63b8435b2e9ae201017516ea700890190 (commit)
       via  348be5f1e44c0b17ff87a8964a36e83b291a6518 (commit)
       via  218f482fbfe96b2cddec8c05f6b8f174481d2e27 (commit)
       via  cb78d4593b5ac4eaa0cbead6f86027d040a9e88a (commit)
       via  75a36a9a5491b86aaa3b0983d5a2bd5d024f783a (commit)
      from  bb33097fb79021c1a47bb4bc45c132020c47d6e4 (commit)

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


- Log -----------------------------------------------------------------
commit c4d3dc849f48a75653d1b16031e9c0657df4d098
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Oct 12 02:27:38 2008 +0200

    Add extra const.

commit d7371dae24a8ec341713d004c2ac9444ec4b14de
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Oct 12 01:56:11 2008 +0200

    Add one-test testsuite for datablob.

commit 771e25b63b8435b2e9ae201017516ea700890190
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Oct 12 01:48:22 2008 +0200

    Avoid problems with paranoid malloc checker.

commit 348be5f1e44c0b17ff87a8964a36e83b291a6518
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Oct 12 01:46:15 2008 +0200

    Share data_blob implementation.

commit 218f482fbfe96b2cddec8c05f6b8f174481d2e27
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Oct 12 00:56:56 2008 +0200

    Use common strlist implementation in Samba 3 and Samba 4.

commit cb78d4593b5ac4eaa0cbead6f86027d040a9e88a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 11 23:57:44 2008 +0200

    Cope with changed signature of http_timestring().

commit 75a36a9a5491b86aaa3b0983d5a2bd5d024f783a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 11 23:25:35 2008 +0200

    Add some simple tests for lib/util/time.c

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

Summary of changes:
 lib/util/data_blob.c                      |    2 +
 lib/util/data_blob.h                      |    2 +
 lib/util/tests/data_blob.c                |   44 +++
 lib/util/tests/strlist.c                  |    6 +-
 lib/util/tests/time.c                     |   75 ++++
 lib/util/time.c                           |  128 ++++++-
 lib/util/time.h                           |    5 +
 lib/util/util.h                           |    9 +-
 lib/util/util_strlist.c                   |   20 +-
 lib/util/xfile.c                          |    4 +-
 libcli/nbt/namerefresh.c                  |    4 +-
 libcli/nbt/nameregister.c                 |    4 +-
 source3/Makefile.in                       |    7 +-
 source3/auth/auth.c                       |    4 +-
 source3/auth/auth_sam.c                   |    2 +-
 source3/include/includes.h                |    3 +
 source3/include/messages.h                |    7 +-
 source3/include/packet.h                  |    4 +-
 source3/include/proto.h                   |   18 +-
 source3/include/smb.h                     |   12 -
 source3/lib/data_blob.c                   |  180 ---------
 source3/lib/events.c                      |    2 +-
 source3/lib/packet.c                      |   12 +-
 source3/lib/time.c                        |  558 -----------------------------
 source3/lib/util_str.c                    |  107 ------
 source3/libads/authdata.c                 |    4 +-
 source3/libads/ldap.c                     |    4 +-
 source3/libsmb/clikrb5.c                  |    4 +-
 source3/param/loadparm.c                  |    7 +-
 source3/printing/print_generic.c          |    2 +-
 source3/rpc_server/srv_svcctl_nt.c        |    2 +-
 source3/rpcclient/cmd_samr.c              |   16 +-
 source3/smbd/chgpasswd.c                  |    2 +-
 source3/smbd/password.c                   |    4 +-
 source3/utils/net_ads.c                   |    3 +-
 source3/utils/net_registry_util.c         |    2 +-
 source3/utils/pdbedit.c                   |   23 +-
 source3/web/cgi.c                         |    5 +-
 source3/winbindd/winbindd_dual.c          |    2 +-
 source4/auth/sam.c                        |    2 +-
 source4/client/client.c                   |    2 +-
 source4/dsdb/common/util.c                |    2 +-
 source4/libcli/resolve/wins.c             |    2 +-
 source4/libnet/libnet_lookup.c            |    2 +-
 source4/nbt_server/wins/winsclient.c      |    2 +-
 source4/param/generic.c                   |    2 +-
 source4/param/loadparm.c                  |    6 +-
 source4/rpc_server/remote/dcesrv_remote.c |    2 +-
 source4/torture/local/config.mk           |    2 +
 source4/torture/local/local.c             |    2 +
 source4/torture/nbt/wins.c                |    8 +-
 source4/winbind/wb_samba3_cmd.c           |    2 +-
 52 files changed, 347 insertions(+), 988 deletions(-)
 create mode 100644 lib/util/tests/data_blob.c
 create mode 100644 lib/util/tests/time.c
 delete mode 100644 source3/lib/data_blob.c


Changeset truncated at 500 lines:

diff --git a/lib/util/data_blob.c b/lib/util/data_blob.c
index 57b34b7..1b2f055 100644
--- a/lib/util/data_blob.c
+++ b/lib/util/data_blob.c
@@ -20,6 +20,8 @@
 
 #include "includes.h"
 
+const DATA_BLOB data_blob_null = { NULL, 0 };
+
 /**
  * @file
  * @brief Manipulation of arbitrary data blobs
diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h
index e9dca67..58c1117 100644
--- a/lib/util/data_blob.h
+++ b/lib/util/data_blob.h
@@ -120,4 +120,6 @@ _PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t len
 _PUBLIC_ bool data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob,
 				   const void *p, size_t length);
 
+extern const DATA_BLOB data_blob_null;
+
 #endif /* _SAMBA_DATABLOB_H_ */
diff --git a/lib/util/tests/data_blob.c b/lib/util/tests/data_blob.c
new file mode 100644
index 0000000..5dd1adc
--- /dev/null
+++ b/lib/util/tests/data_blob.c
@@ -0,0 +1,44 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   data blob testing
+
+   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
+   
+   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/>.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+
+static bool test_string(struct torture_context *tctx)
+{
+	DATA_BLOB blob = data_blob_string_const("bla");	
+
+	torture_assert_int_equal(tctx, blob.length, 3, "blob length");
+	torture_assert_str_equal(tctx, blob.data, "bla", "blob data");
+
+	data_blob_free(&blob);
+
+	return true;
+}
+
+struct torture_suite *torture_local_util_data_blob(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite = torture_suite_create(mem_ctx, "DATABLOB");
+
+	torture_suite_add_simple_test(suite, "string", test_string);
+
+	return suite;
+}
diff --git a/lib/util/tests/strlist.c b/lib/util/tests/strlist.c
index 9af26f9..8605102 100644
--- a/lib/util/tests/strlist.c
+++ b/lib/util/tests/strlist.c
@@ -71,17 +71,17 @@ static bool test_list_copy(struct torture_context *tctx)
 	const char *empty_list[] = { NULL };
 	const char **null_list = NULL;
 
-	result = str_list_copy(tctx, list);
+	result = (const char **)str_list_copy(tctx, list);
 	torture_assert_int_equal(tctx, str_list_length(result), 2, "list length");
 	torture_assert_str_equal(tctx, result[0], "foo", "element 0");
 	torture_assert_str_equal(tctx, result[1], "bar", "element 1");
 	torture_assert_str_equal(tctx, result[2], NULL, "element 2");
 
-	result = str_list_copy(tctx, empty_list);
+	result = (const char **)str_list_copy(tctx, empty_list);
 	torture_assert_int_equal(tctx, str_list_length(result), 0, "list length");
 	torture_assert_str_equal(tctx, result[0], NULL, "element 0");
 
-	result = str_list_copy(tctx, null_list);
+	result = (const char **)str_list_copy(tctx, null_list);
 	torture_assert(tctx, result == NULL, "result NULL");
 	
 	return true;
diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c
new file mode 100644
index 0000000..4a31566
--- /dev/null
+++ b/lib/util/tests/time.c
@@ -0,0 +1,75 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   util time testing
+
+   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
+   
+   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/>.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+
+static bool test_null_time(struct torture_context *tctx)
+{
+	torture_assert(tctx, null_time(0), "0");
+	torture_assert(tctx, null_time(0xFFFFFFFF), "0xFFFFFFFF");
+	torture_assert(tctx, null_time(-1), "-1");
+	torture_assert(tctx, !null_time(42), "42");
+	return true;
+}
+
+static bool test_null_nttime(struct torture_context *tctx)
+{
+	torture_assert(tctx, null_nttime(-1), "-1");
+	torture_assert(tctx, null_nttime(-1), "-1");
+	torture_assert(tctx, !null_nttime(42), "42");
+	return true;
+}
+
+
+static bool test_http_timestring(struct torture_context *tctx)
+{
+	const char *start = "Thu, 01 Jan 1970";
+	torture_assert(tctx, !strncmp(start, http_timestring(tctx, 42), 
+										 strlen(start)), "42");
+	torture_assert_str_equal(tctx, "never", 
+							 http_timestring(tctx, get_time_t_max()), "42");
+	return true;
+}
+
+static bool test_timestring(struct torture_context *tctx)
+{
+	const char *start = "Thu Jan  1";
+	torture_assert(tctx, !strncmp(start, timestring(tctx, 42), strlen(start)),
+				   "42");
+	return true;
+}
+
+
+
+struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite = torture_suite_create(mem_ctx, "TIME");
+
+	torture_suite_add_simple_test(suite, "null_time", test_null_time);
+	torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime);
+	torture_suite_add_simple_test(suite, "http_timestring", 
+								  test_http_timestring);
+	torture_suite_add_simple_test(suite, "timestring", 
+								  test_timestring);
+
+	return suite;
+}
diff --git a/lib/util/time.c b/lib/util/time.c
index 978d73c..a001e5f 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -32,6 +32,14 @@
 #define TIME_T_MIN 0
 #endif
 
+#if (SIZEOF_LONG == 8)
+#define TIME_FIXUP_CONSTANT_INT 11644473600L
+#elif (SIZEOF_LONG_LONG == 8)
+#define TIME_FIXUP_CONSTANT_INT 11644473600LL
+#endif
+
+
+
 /*
  * we use the INT32_MAX here as on 64 bit systems,
  * gmtime() fails with INT64_MAX
@@ -64,27 +72,40 @@ _PUBLIC_ void GetTimeOfDay(struct timeval *tval)
 
 #define TIME_FIXUP_CONSTANT 11644473600LL
 
-/**
-interpret an 8 byte "filetime" structure to a time_t
-It's originally in "100ns units since jan 1st 1601"
-**/
-_PUBLIC_ time_t nt_time_to_unix(NTTIME nt)
+time_t convert_timespec_to_time_t(struct timespec ts)
 {
-	if (nt == 0) {
-		return 0;
-	}
-	if (nt == -1LL) {
-		return (time_t)-1;
+	/* 1 ns == 1,000,000,000 - one thousand millionths of a second.
+	   increment if it's greater than 500 millionth of a second. */
+	if (ts.tv_nsec > 500000000) {
+		return ts.tv_sec + 1;
 	}
-	nt += 1000*1000*10/2;
-	nt /= 1000*1000*10;
-	nt -= TIME_FIXUP_CONSTANT;
+	return ts.tv_sec;
+}
 
-	if (TIME_T_MIN > nt || nt > TIME_T_MAX) {
-		return 0;
-	}
+struct timespec convert_time_t_to_timespec(time_t t)
+{
+	struct timespec ts;
+	ts.tv_sec = t;
+	ts.tv_nsec = 0;
+	return ts;
+}
 
-	return (time_t)nt;
+
+
+/**
+ Interpret an 8 byte "filetime" structure to a time_t
+ It's originally in "100ns units since jan 1st 1601"
+
+ An 8 byte value of 0xffffffffffffffff will be returned as a timespec of
+
+	tv_sec = 0
+	tv_nsec = 0;
+
+ Returns GMT.
+**/
+time_t nt_time_to_unix(NTTIME nt)
+{
+	return convert_timespec_to_time_t(nt_time_to_unix_timespec(&nt));
 }
 
 
@@ -99,14 +120,20 @@ _PUBLIC_ void unix_to_nt_time(NTTIME *nt, time_t t)
 	if (t == (time_t)-1) {
 		*nt = (NTTIME)-1LL;
 		return;
-	}		
+	}	
+
+	if (t == TIME_T_MAX) {
+		*nt = 0x7fffffffffffffffLL;
+		return;
+	}
+
 	if (t == 0) {
 		*nt = 0;
 		return;
 	}		
 
 	t2 = t;
-	t2 += TIME_FIXUP_CONSTANT;
+	t2 += TIME_FIXUP_CONSTANT_INT;
 	t2 *= 1000*1000*10;
 
 	*nt = t2;
@@ -218,7 +245,7 @@ _PUBLIC_ void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_o
 /*******************************************************************
   interpret a 32 bit dos packed date/time to some parameters
 ********************************************************************/
-static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second)
+void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second)
 {
 	uint32_t p0,p1,p2,p3;
 
@@ -295,6 +322,10 @@ _PUBLIC_ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t)
 	char tempTime[60];
 	struct tm *tm = localtime(&t);
 
+	if (t == TIME_T_MAX) {
+		return talloc_strdup(mem_ctx, "never");
+	}
+
 	if (!tm) {
 		return talloc_asprintf(mem_ctx,"%ld seconds since the Epoch",(long)t);
 	}
@@ -613,6 +644,50 @@ _PUBLIC_ int get_time_zone(time_t t)
 	return tm_diff(&tm_utc,tm);
 }
 
+struct timespec nt_time_to_unix_timespec(NTTIME *nt)
+{
+	int64_t d;
+	struct timespec ret;
+
+	if (*nt == 0 || *nt == (int64_t)-1) {
+		ret.tv_sec = 0;
+		ret.tv_nsec = 0;
+		return ret;
+	}
+
+	d = (int64_t)*nt;
+	/* d is now in 100ns units, since jan 1st 1601".
+	   Save off the ns fraction. */
+
+	/*
+	 * Take the last seven decimal digits and multiply by 100.
+	 * to convert from 100ns units to 1ns units.
+	 */
+        ret.tv_nsec = (long) ((d % (1000 * 1000 * 10)) * 100);
+
+	/* Convert to seconds */
+	d /= 1000*1000*10;
+
+	/* Now adjust by 369 years to make the secs since 1970 */
+	d -= TIME_FIXUP_CONSTANT_INT;
+
+	if (d <= (int64_t)TIME_T_MIN) {
+		ret.tv_sec = TIME_T_MIN;
+		ret.tv_nsec = 0;
+		return ret;
+	}
+
+	if (d >= (int64_t)TIME_T_MAX) {
+		ret.tv_sec = TIME_T_MAX;
+		ret.tv_nsec = 0;
+		return ret;
+	}
+
+	ret.tv_sec = (time_t)d;
+	return ret;
+}
+
+
 /**
   check if 2 NTTIMEs are equal.
 */
@@ -620,3 +695,16 @@ bool nt_time_equal(NTTIME *t1, NTTIME *t2)
 {
 	return *t1 == *t2;
 }
+
+/**
+ Check if it's a null timespec.
+**/
+
+bool null_timespec(struct timespec ts)
+{
+	return ts.tv_sec == 0 || 
+		ts.tv_sec == (time_t)0xFFFFFFFF || 
+		ts.tv_sec == (time_t)-1;
+}
+
+
diff --git a/lib/util/time.h b/lib/util/time.h
index e4008c5..1a1fcc9 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -229,4 +229,9 @@ _PUBLIC_ int get_time_zone(time_t t);
 */
 bool nt_time_equal(NTTIME *t1, NTTIME *t2);
 
+void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second);
+
+
+struct timespec nt_time_to_unix_timespec(NTTIME *nt);
+
 #endif /* _SAMBA_TIME_H_ */
diff --git a/lib/util/util.h b/lib/util/util.h
index 861b6af..5cecad7 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -21,10 +21,9 @@
 #ifndef _SAMBA_UTIL_H_
 #define _SAMBA_UTIL_H_
 
+#include "lib/charset/charset.h"
 #include "../lib/util/attr.h"
 
-#include "charset/charset.h"
-
 /* for TALLOC_CTX */
 #include <talloc.h>
 
@@ -452,7 +451,7 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2);
   separator list. The separator list must contain characters less than
   or equal to 0x2f for this to work correctly on multi-byte strings
 */
-_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
+_PUBLIC_ char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
 
 /**
  * build a null terminated list of strings from an argv-like input string 
@@ -473,12 +472,12 @@ _PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char
 /**
   return the number of elements in a string list
 */
-_PUBLIC_ size_t str_list_length(const char **list);
+_PUBLIC_ size_t str_list_length(const char * const *list);
 
 /**
   copy a string list
 */
-_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
+_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
 
 /**
    Return true if all the elements of the list match exactly.
diff --git a/lib/util/util_strlist.c b/lib/util/util_strlist.c
index 30de4b9..b069a11 100644
--- a/lib/util/util_strlist.c
+++ b/lib/util/util_strlist.c
@@ -21,6 +21,8 @@
 #include "includes.h"
 #include "system/locale.h"
 
+#undef strcasecmp
+
 /**
  * @file
  * @brief String list manipulation
@@ -31,30 +33,30 @@
   separator list. The separator list must contain characters less than
   or equal to 0x2f for this to work correctly on multi-byte strings
 */
-_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
+_PUBLIC_ char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
 {
 	int num_elements = 0;
-	const char **ret = NULL;
+	char **ret = NULL;
 
 	if (sep == NULL) {
 		sep = LIST_SEP;
 	}
 
-	ret = talloc_array(mem_ctx, const char *, 1);
+	ret = talloc_array(mem_ctx, char *, 1);
 	if (ret == NULL) {
 		return NULL;
 	}
 
 	while (string && *string) {
 		size_t len = strcspn(string, sep);
-		const char **ret2;
+		char **ret2;
 		
 		if (len == 0) {
 			string += strspn(string, sep);
 			continue;
 		}
 
-		ret2 = talloc_realloc(mem_ctx, ret, const char *, num_elements+2);
+		ret2 = talloc_realloc(mem_ctx, ret, char *, num_elements+2);
 		if (ret2 == NULL) {
 			talloc_free(ret);
 			return NULL;
@@ -185,7 +187,7 @@ _PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char
 /**
   return the number of elements in a string list
 */
-_PUBLIC_ size_t str_list_length(const char **list)
+_PUBLIC_ size_t str_list_length(const char * const*list)
 {
 	size_t ret;
 	for (ret=0;list && list[ret];ret++) /* noop */ ;
@@ -196,15 +198,15 @@ _PUBLIC_ size_t str_list_length(const char **list)
 /**
   copy a string list
 */
-_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
+_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
 {
 	int i;
-	const char **ret;
+	char **ret;
 
 	if (list == NULL)
 		return NULL;
 	
-	ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1);
+	ret = talloc_array(mem_ctx, char *, str_list_length(list)+1);
 	if (ret == NULL) 
 		return NULL;
 
diff --git a/lib/util/xfile.c b/lib/util/xfile.c


-- 
Samba Shared Repository


More information about the samba-cvs mailing list