diff options
62 files changed, 1314 insertions, 742 deletions
diff --git a/source4/Makefile.in b/source4/Makefile.in index fdc87934d0..ea75d26ab9 100644 --- a/source4/Makefile.in +++ b/source4/Makefile.in @@ -54,7 +54,7 @@ LOCKDIR = @lockdir@ # the directory where pid files go PIDDIR = @piddir@ -FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include $(CPPFLAGS) -I. -I$(srcdir) +FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include $(CPPFLAGS) -I. -I$(srcdir) -Ilib FLAGS32 = PASSWD_FLAGS = -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\" @@ -79,6 +79,8 @@ TORTURE_PROGS = bin/smbtorture@EXEEXT@ \ bin/masktest@EXEEXT@ \ bin/ndrdump@EXEEXT@ +LDB_PROGS = bin/ldbadd bin/ldbdel bin/ldbmodify bin/ldbedit bin/ldbsearch + CHARSET_MODULES = @CHARSET_MODULES@ CHARSET_LIBDIR = $(LIBDIR)/charset DCERPC_MODULES = @DCERPC_MODULES@ @@ -144,6 +146,23 @@ REG_OBJS = @REG_OBJS@ REG_LIBS = @REG_LIBS@ GTK_LIBS = @GTK_LIBS@ +LIBLDB_OBJS = @LIBLDB_OBJS@ + +LDBADD_OBJS = @LDBADD_OBJS@ +LDBADD_LIBS = $(CONFIG_LIBS) $(LIBSMB_LIBS) $(LIBBASIC_LIBS) + +LDBDEL_OBJS = @LDBDEL_OBJS@ +LDBDEL_LIBS = $(CONFIG_LIBS) $(LIBSMB_LIBS) $(LIBBASIC_LIBS) + +LDBMODIFY_OBJS = @LDBMODIFY_OBJS@ +LDBMODIFY_LIBS = $(CONFIG_LIBS) $(LIBSMB_LIBS) $(LIBBASIC_LIBS) + +LDBSEARCH_OBJS = @LDBSEARCH_OBJS@ +LDBSEARCH_LIBS = $(CONFIG_LIBS) $(LIBSMB_LIBS) $(LIBBASIC_LIBS) + +LDBEDIT_OBJS = @LDBEDIT_OBJS@ +LDBEDIT_LIBS = $(CONFIG_LIBS) $(LIBSMB_LIBS) $(LIBBASIC_LIBS) + TORTURE_RAW_OBJS = @TORTURE_RAW_OBJS@ TORTURE_RPC_OBJS = @TORTURE_RPC_OBJS@ @@ -210,7 +229,7 @@ PROTO_OBJ = $(SERVER_OBJS) $(PROCESS_MODEL_OBJS) $(CLIENT_OBJS) $(TORTURE_OBJS) ###################################################################### # now the rules... ###################################################################### -all: SHOWFLAGS $(SBIN_PROGS) $(BIN_PROGS) $(TORTURE_PROGS) $(MODULES) +all: SHOWFLAGS $(SBIN_PROGS) $(BIN_PROGS) $(TORTURE_PROGS) $(LDB_PROGS) $(MODULES) torture : SHOWFLAGS $(TORTURE_PROGS) @@ -332,6 +351,26 @@ bin/smbtorture@EXEEXT@: $(SMBTORTURE_OBJS) bin/.dummy @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(SMBTORTURE_OBJS) $(LDFLAGS) $(SMBTORTURE_LIBS) +bin/ldbadd@EXEEXT@: $(LDBADD_OBJS) bin/.dummy + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LDBADD_OBJS) $(LDFLAGS) $(LDBADD_LIBS) + +bin/ldbdel@EXEEXT@: $(LDBDEL_OBJS) bin/.dummy + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LDBDEL_OBJS) $(LDFLAGS) $(LDBADD_LIBS) + +bin/ldbmodify@EXEEXT@: $(LDBMODIFY_OBJS) bin/.dummy + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LDBMODIFY_OBJS) $(LDFLAGS) $(LDBADD_LIBS) + +bin/ldbsearch@EXEEXT@: $(LDBSEARCH_OBJS) bin/.dummy + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LDBSEARCH_OBJS) $(LDFLAGS) $(LDBADD_LIBS) + +bin/ldbedit@EXEEXT@: $(LDBEDIT_OBJS) bin/.dummy + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(LDBEDIT_OBJS) $(LDFLAGS) $(LDBADD_LIBS) + bin/ndrdump@EXEEXT@: $(NDRDUMP_OBJS) bin/.dummy @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(NDRDUMP_OBJS) $(LDFLAGS) $(NDRDUMP_LIBS) @@ -433,7 +472,7 @@ uninstallmodules: TOPFILES=dynconfig.o dynconfig.po clean: delheaders - -rm -f core */*~ *~ */*.o */*/*.o */*/*.po */*/*.po32 */*.po */*.po32 */*.@SHLIBEXT@ \ + -rm -f core */*~ *~ */*.o */*/*.o */*/*/*.o */*/*.po */*/*.po32 */*.po */*.po32 */*.@SHLIBEXT@ \ $(TOPFILES) $(BIN_PROGS) $(SBIN_PROGS) $(MODULES) $(TORTURE_PROGS) \ .headers.stamp -rm -rf librpc/gen_* diff --git a/source4/auth/auth_sam.c b/source4/auth/auth_sam.c index f25a5e4691..35635ea474 100644 --- a/source4/auth/auth_sam.c +++ b/source4/auth/auth_sam.c @@ -348,7 +348,7 @@ static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx, /* 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(mem_ctx, must_change_time), (long)must_change_time)); + DEBUG(1,("Password expired at '%s' (%ld) unix time.\n", timestring(mem_ctx, must_change_time), (long)must_change_time)); return NT_STATUS_PASSWORD_EXPIRED; } } diff --git a/source4/client/client.c b/source4/client/client.c index 0430689865..d783ec3991 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -393,7 +393,7 @@ static void display_finfo(file_info *finfo) finfo->name, attrib_string(finfo->mode), (double)finfo->size, - asctime(LocalTime(&t))); + asctime(localtime(&t))); dir_total += finfo->size; } } @@ -2025,7 +2025,7 @@ static int cmd_newer(void) if (ok && (sys_stat(buf,&sbuf) == 0)) { newer_than = sbuf.st_mtime; DEBUG(1,("Getting files newer than %s", - asctime(LocalTime(&newer_than)))); + asctime(localtime(&newer_than)))); } else { newer_than = 0; } diff --git a/source4/client/clitar.c b/source4/client/clitar.c index 356709b915..cd3c9f2310 100644 --- a/source4/client/clitar.c +++ b/source4/client/clitar.c @@ -1683,7 +1683,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) if (sys_stat(argv[Optind], &stbuf) == 0) { newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", - asctime(LocalTime(&newer_than)))); + asctime(localtime(&newer_than)))); Optind++; } else { DEBUG(0,("Error setting newer-than time\n")); diff --git a/source4/include/context.h b/source4/include/context.h index 5c7d117050..17664c50f8 100644 --- a/source4/include/context.h +++ b/source4/include/context.h @@ -278,6 +278,9 @@ struct negotiate_context { /* client capabilities */ uint32 client_caps; + + /* the timezone we sent to the client */ + int zone_offset; }; /* this is the context for a SMB socket associated with the socket itself */ diff --git a/source4/include/includes.h b/source4/include/includes.h index 79fca5f7b4..b611974e29 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -680,6 +680,7 @@ extern int errno; #include "xfile.h" #include "dlinklist.h" #include "lib/ldb/include/ldb.h" +#include "lib/ldb/include/ldb_parse.h" #include "lib/tdb/tdb.h" #include "lib/tdb/spinlock.h" #include "lib/tdb/tdbutil.h" @@ -749,8 +750,6 @@ struct functable { typedef int (*comparison_fn_t)(const void *, const void *); #endif -#include "lib/ldb/include/ldb_parse.h" - #include "nsswitch/nss.h" /***** automatically generated prototypes *****/ diff --git a/source4/include/talloc.h b/source4/include/talloc.h index 60a2822f38..204dd406b9 100644 --- a/source4/include/talloc.h +++ b/source4/include/talloc.h @@ -51,6 +51,10 @@ char *talloc_asprintf_append(TALLOC_CTX *t, char *, const char *, ...) #define talloc_array_p(ctx, type, count) (type *)talloc_realloc_array(ctx, NULL, sizeof(type), count) #define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count) +#define malloc_p(type) (type *)malloc(sizeof(type)) +#define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) +#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) + /** @} */ #endif /* ndef _TALLOC_H_ */ diff --git a/source4/lib/ldb/Makefile.ldb b/source4/lib/ldb/Makefile.ldb index 0610ccf19b..2a41629852 100644 --- a/source4/lib/ldb/Makefile.ldb +++ b/source4/lib/ldb/Makefile.ldb @@ -12,13 +12,14 @@ LDB_TDB_OBJ=ldb_tdb/ldb_match.o ldb_tdb/ldb_tdb.o \ LDB_LDAP_OBJ=ldb_ldap/ldb_ldap.o -COMMON_OBJ=common/ldb.o common/ldb_ldif.o common/util.o common/ldb_parse.o +COMMON_OBJ=common/ldb.o common/ldb_ldif.o common/util.o \ + common/ldb_parse.o common/ldb_msg.o OBJS = $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(LDB_LDAP_OBJ) LDB_LIB = lib/libldb.a -BINS = bin/ldbadd bin/ldbsearch bin/ldbdel bin/ldbmodify +BINS = bin/ldbadd bin/ldbsearch bin/ldbdel bin/ldbmodify bin/ldbedit LIBS = $(LDB_LIB)($(OBJS)) @@ -46,6 +47,9 @@ bin/ldbdel: tools/ldbdel.o $(LIBS) bin/ldbmodify: tools/ldbmodify.o $(LIBS) $(CC) -o bin/ldbmodify tools/ldbmodify.o $(LIB_FLAGS) +bin/ldbedit: tools/ldbedit.o $(LIBS) + $(CC) -o bin/ldbedit tools/ldbedit.o $(LIB_FLAGS) + clean: rm -f */*.o *~ */*~ $(BINS) $(LDB_LIB) diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 3ba4434e07..146745043f 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -80,7 +80,7 @@ int ldb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - const char *attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { return ldb->ops->search(ldb, base, scope, expression, attrs, res); } diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index b4c27c3369..5f2fccfebc 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -90,7 +90,7 @@ char *ldb_base64_encode(const char *buf, int len) { const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int bit_offset, byte_offset, idx, i; - unsigned char *d = (unsigned char *)buf; + const unsigned char *d = (const unsigned char *)buf; int bytes = (len*8 + 5)/6; char *out; @@ -222,6 +222,23 @@ int ldif_write(int (*fprintf_fn)(void *, const char *, ...), } for (i=0;i<msg->num_elements;i++) { + if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { + switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + fprintf_fn(private, "add: %s\n", + msg->elements[i].name); + break; + case LDB_FLAG_MOD_DELETE: + fprintf_fn(private, "delete: %s\n", + msg->elements[i].name); + break; + case LDB_FLAG_MOD_REPLACE: + fprintf_fn(private, "replace: %s\n", + msg->elements[i].name); + break; + } + } + for (j=0;j<msg->elements[i].num_values;j++) { if (ldb_should_b64_encode(&msg->elements[i].values[j])) { ret = fprintf_fn(private, "%s:: ", @@ -246,6 +263,9 @@ int ldif_write(int (*fprintf_fn)(void *, const char *, ...), CHECK_RET; } } + if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { + fprintf_fn(private, "-\n"); + } } ret = fprintf_fn(private,"\n"); CHECK_RET; diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c new file mode 100644 index 0000000000..633cc91f2c --- /dev/null +++ b/source4/lib/ldb/common/ldb_msg.c @@ -0,0 +1,133 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2004 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Name: ldb + * + * Component: ldb message component utility functions + * + * Description: functions for manipulating ldb_message structures + * + * Author: Andrew Tridgell + */ + +#include "includes.h" + + +/* + find an element in a message by attribute name +*/ +struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, + const char *attr_name) +{ + int i; + for (i=0;i<msg->num_elements;i++) { + if (strcmp(msg->elements[i].name, attr_name) == 0) { + return &msg->elements[i]; + } + } + return NULL; +} + + +/* + find a value in an element +*/ +struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, + struct ldb_val *val) +{ + int i; + for (i=0;i<el->num_values;i++) { + if (ldb_val_equal(val, &el->values[i])) { + return &el->values[i]; + } + } + return NULL; +} + + +/* + add an empty element to a message +*/ +int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags) +{ + struct ldb_message_element *els; + + els = realloc_p(msg->elements, struct ldb_message_element, msg->num_elements+1); + if (!els) { + errno = ENOMEM; + return -1; + } + + els[msg->num_elements].values = NULL; + els[msg->num_elements].num_values = 0; + els[msg->num_elements].flags = flags; + els[msg->num_elements].name = strdup(attr_name); + if (!els[msg->num_elements].name) { + return -1; + } + + msg->elements = els; + msg->num_elements++; + + return 0; +} + +/* + add an empty element to a message +*/ +int ldb_msg_add(struct ldb_message *msg, + const struct ldb_message_element *el, + int flags) +{ + if (ldb_msg_add_empty(msg, el->name, flags) != 0) { + return -1; + } + + msg->elements[msg->num_elements-1] = *el; + msg->elements[msg->num_elements-1].flags = flags; + + return 0; +} + +/* + compare two ldb_message_element structures +*/ +int ldb_msg_element_compare(struct ldb_message_element *el1, + struct ldb_message_element *el2) +{ + int i; + + if (el1->num_values != el2->num_values) { + return el1->num_values - el2->num_values; + } + + for (i=0;i<el1->num_values;i++) { + if (!ldb_msg_find_val(el2, &el1->values[i])) { + return -1; + } + } + + return 0; +} diff --git a/source4/lib/ldb/common/util.c b/source4/lib/ldb/common/util.c index d198a1ad92..e1a7ada1c6 100644 --- a/source4/lib/ldb/common/util.c +++ b/source4/lib/ldb/common/util.c @@ -77,11 +77,11 @@ int list_find(const void *needle, int r; test_i = (min_i + max_i) / 2; - r = comp_fn(needle, *(void **)(base_p + (size * test_i))); + r = comp_fn(needle, *(void * const *)(base_p + (size * test_i))); if (r == 0) { /* scan back for first element */ while (test_t > 0 && - comp_fn(needle, *(void **)(base_p + (size * (test_i-1)))) == 0) { + comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) { test_i--; } return test_i; @@ -94,7 +94,7 @@ int list_find(const void *needle, } } - if (comp_fn(needle, *(void **)(base_p + (size * min_i))) == 0) { + if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) { return min_i; } diff --git a/source4/lib/ldb/config.m4 b/source4/lib/ldb/config.m4 index 6fdfcf526a..7c4749ab02 100644 --- a/source4/lib/ldb/config.m4 +++ b/source4/lib/ldb/config.m4 @@ -1,17 +1,37 @@ - -SMB_MODULE(libldb_tdb,LIBLDB,STATIC, - [lib/ldb/ldb_tdb/ldb_tdb.o \ - lib/ldb/ldb_tdb/ldb_pack.o \ +SMB_SUBSYSTEM(LIBLDB,[lib/ldb/common/ldb.o], + [lib/ldb/common/ldb_ldif.o \ + lib/ldb/common/ldb_parse.o \ + lib/ldb/common/ldb_msg.o \ + lib/ldb/common/util.o \ lib/ldb/ldb_tdb/ldb_search.o \ + lib/ldb/ldb_tdb/ldb_tdb.o \ + lib/ldb/ldb_tdb/ldb_pack.o \ lib/ldb/ldb_tdb/ldb_index.o \ - lib/ldb/ldb_tdb/ldb_match.o]) + lib/ldb/ldb_tdb/ldb_match.o \ + lib/ldb/ldb_ldap/ldb_ldap.o], + lib/ldb/include/ldb.h) -if test x"$with_ldap_support" = x"yes"; then - SMB_MODULE_DEFAULT(libldb_ldap,STATIC) -fi -SMB_MODULE(libldb_ldap,LIBLDB,NOT,[lib/ldb/ldb_ldap/ldb_ldap.o]) +SMB_SUBSYSTEM(LDBADD,[], + [lib/ldb/tools/ldbadd.o \ + \$(LIBBASIC_OBJS) \$(LIBSMB_OBJS) \$(CONFIG_OBJS) \$(LIBLDB_OBJS)], + lib/ldb/include/proto.h) -SMB_SUBSYSTEM(LIBLDB,[lib/ldb/common/ldb.o], - [lib/ldb/common/ldb_ldif.o \ - lib/ldb/common/ldb_parse.o \ - lib/ldb/common/util.o]) +SMB_SUBSYSTEM(LDBDEL,[], + [lib/ldb/tools/ldbdel.o \ + \$(LIBBASIC_OBJS) \$(LIBSMB_OBJS) \$(CONFIG_OBJS) \$(LIBLDB_OBJS)], + lib/ldb/include/proto.h) + +SMB_SUBSYSTEM(LDBMODIFY,[], + [lib/ldb/tools/ldbmodify.o \ + \$(LIBBASIC_OBJS) \$(LIBSMB_OBJS) \$(CONFIG_OBJS) \$(LIBLDB_OBJS)], + lib/ldb/include/proto.h) + +SMB_SUBSYSTEM(LDBSEARCH,[], + [lib/ldb/tools/ldbsearch.o \ + \$(LIBBASIC_OBJS) \$(LIBSMB_OBJS) \$(CONFIG_OBJS) \$(LIBLDB_OBJS)], + lib/ldb/include/proto.h) + +SMB_SUBSYSTEM(LDBEDIT,[], + [lib/ldb/tools/ldbedit.o \ + \$(LIBBASIC_OBJS) \$(LIBSMB_OBJS) \$(CONFIG_OBJS) \$(LIBLDB_OBJS)], + lib/ldb/include/proto.h) diff --git a/source4/lib/ldb/include/includes.h b/source4/lib/ldb/include/includes.h index ea8540d330..70ad1f3588 100644 --- a/source4/lib/ldb/include/includes.h +++ b/source4/lib/ldb/include/includes.h @@ -2,7 +2,9 @@ a temporary includes file until I work on the ldb build system */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -11,6 +13,7 @@ #include <fcntl.h> #include <stdarg.h> #include <signal.h> +#include <unistd.h> #include "ldb.h" #include "ldb_parse.h" diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 12064bbf75..dc1b1d7732 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -174,7 +174,7 @@ int ldb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - const char *attrs[], struct ldb_message ***res); + char * const attrs[], struct ldb_message ***res); /* free a set of messages returned by ldb_search diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 25dad914da..25af43c569 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -33,8 +33,7 @@ */ #include "includes.h" -#if HAVE_LDAP -#include "ldb_ldap.h" +#include "ldb/ldb_ldap/ldb_ldap.h" #if 0 /* @@ -519,4 +518,4 @@ failed: if (ldb) free(ldb); return NULL; } -#endif /*HAVE_LDAP*/ + diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c index 5964e0751d..1196e561a2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb.h" +#include "ldb/ldb_tdb/ldb_tdb.h" /* change this if the data format ever changes */ #define LTDB_PACKING_FORMAT 0x26011966 diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5905231b32..9cb5853c94 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb.h" +#include "ldb/ldb_tdb/ldb_tdb.h" /* free a message that has all parts separately allocated @@ -56,22 +56,6 @@ static void msg_free_all_parts(struct ldb_message *msg) /* - TODO: this should take advantage of the sorted nature of the message - - return index of the attribute, or -1 if not found -*/ -int ldb_msg_find_attr(const struct ldb_message *msg, const char *attr) -{ - int i; - for (i=0;i<msg->num_elements;i++) { - if (strcmp(msg->elements[i].name, attr) == 0) { - return i; - } - } - return -1; -} - -/* duplicate a ldb_val structure */ struct ldb_val ldb_val_dup(const struct ldb_val *v) @@ -193,7 +177,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, } for (i=0;attrs[i];i++) { - int j; + struct ldb_message_element *el; if (strcmp(attrs[i], "*") == 0) { if (msg_add_all_elements(ret, msg) != 0) { @@ -202,17 +186,15 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, } continue; } - j = ldb_msg_find_attr(msg, attrs[i]); - if (j == -1) { + + el = ldb_msg_find_element(msg, attrs[i]); + if (!el) { continue; } - do { - if (msg_add_element(ret, &msg->elements[j]) != 0) { - msg_free_all_parts(ret); - return NULL; - } - } while (++j < msg->num_elements && - strcmp(attrs[i], msg->elements[j].name) == 0); + if (msg_add_element(ret, el) != 0) { + msg_free_all_parts(ret); + return NULL; + } } return ret; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index ec90eec03f..b28d73cbea 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb.h" +#include "ldb/ldb_tdb/ldb_tdb.h" /* form a TDB_DATA for a record key diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 30afe223ea..efb0af1c9c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -5,7 +5,9 @@ struct ltdb_private { unsigned int connect_flags; }; -#ifdef STANDALONE +#ifndef IVAL #define IVAL(p, ofs) (((unsigned *)((char *)(p) + (ofs)))[0]) +#endif +#ifndef SIVAL #define SIVAL(p, ofs, v) do { IVAL(p, ofs) = (v); } while (0) #endif diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index 92ed29e6b8..446c0d80f9 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -34,28 +34,28 @@ #include "includes.h" - int main(void) -{ - static struct ldb_context *ldb; - struct ldb_ldif *ldif; - int ret; - int count=0, failures=0; - const char *ldb_url; - - ldb_url = getenv("LDB_URL"); - if (!ldb_url) { - ldb_url = "tdb://test.ldb"; - } +static int failures; - ldb = ldb_connect(ldb_url, 0, NULL); +static void usage(void) +{ + printf("Usage: ldbadd <options> <ldif...>\n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf("\n"); + printf("Adds records to a ldb, reading ldif the specified list of files\n\n"); + exit(1); +} - if (!ldb) { - perror("ldb_connect"); - exit(1); - } - while ((ldif = ldif_read_file(stdin))) { +/* + add records from an opened file +*/ +static int process_file(struct ldb_context *ldb, FILE *f) +{ + struct ldb_ldif *ldif; + int ret, count=0; + while ((ldif = ldif_read_file(f))) { if (ldif->changetype != LDB_CHANGETYPE_ADD && ldif->changetype != LDB_CHANGETYPE_NONE) { fprintf(stderr, "Only CHANGETYPE_ADD records allowed\n"); @@ -73,6 +73,69 @@ ldif_read_free(ldif); } + return count; +} + + + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; + int count=0; + const char *ldb_url; + int opt, i; + + ldb_url = getenv("LDB_URL"); + + while ((opt = getopt(argc, argv, "hH:")) != EOF) { + switch (opt) { + case 'H': + ldb_url = optarg; + break; + + case 'h': + default: + usage(); + break; + } + } + + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + if (argc == 0) { + usage(); + } + + for (i=0;i<argc;i++) { + FILE *f; + if (strcmp(argv[i],"-") == 0) { + f = stdin; + } else { + f = fopen(argv[i], "r"); + } + if (!f) { + perror(argv[i]); + exit(1); + } + count += process_file(ldb, f); + if (f != stdin) { + fclose(f); + } + } + ldb_close(ldb); printf("Added %d records with %d failures\n", count, failures); diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index 177279d47a..0e50a68532 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -34,20 +34,48 @@ #include "includes.h" - int main(int argc, const char *argv[]) +static void usage(void) { - static struct ldb_context *ldb; + printf("Usage: ldbdel <options> <DN...>\n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf("\n"); + printf("Deletes records from a ldb\n\n"); + exit(1); +} + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; int ret, i; const char *ldb_url; + int opt; ldb_url = getenv("LDB_URL"); + + while ((opt = getopt(argc, argv, "hH:")) != EOF) { + switch (opt) { + case 'H': + ldb_url = optarg; + break; + + case 'h': + default: + usage(); + break; + } + } + if (!ldb_url) { - ldb_url = "tdb://test.ldb"; + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); } + argc -= optind; + argv += optind; - if (argc < 2) { - printf("Usage: ldbdel <dn...>\n"); + if (argc < 1) { + usage(); exit(1); } @@ -57,7 +85,7 @@ exit(1); } - for (i=1;i<argc;i++) { + for (i=0;i<argc;i++) { ret = ldb_delete(ldb, argv[i]); if (ret != 0) { printf("delete of '%s' failed\n", argv[i]); @@ -65,5 +93,6 @@ } ldb_close(ldb); + return 0; } diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c new file mode 100644 index 0000000000..c5eb1349dd --- /dev/null +++ b/source4/lib/ldb/tools/ldbedit.c @@ -0,0 +1,365 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2004 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Name: ldb + * + * Component: ldbedit + * + * Description: utility for ldb editing + * + * Author: Andrew Tridgell + */ + +#include "includes.h" + +/* + modify a database record so msg1 becomes msg2 +*/ +static int modify_record(struct ldb_context *ldb, + struct ldb_message *msg1, + struct ldb_message *msg2) +{ + struct ldb_message mod; + struct ldb_message_element *el; + int i; + + mod.dn = msg1->dn; + mod.num_elements = 0; + mod.elements = NULL; + + /* look in msg2 to find elements that need to be added + or modified */ + for (i=0;i<msg2->num_elements;i++) { + el = ldb_msg_find_element(msg1, msg2->elements[i].name); + + if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) { + continue; + } + + if (ldb_msg_add(&mod, + &msg2->elements[i], + el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { + return -1; + } + } + + /* look in msg1 to find elements that need to be deleted */ + for (i=0;i<msg1->num_elements;i++) { + el = ldb_msg_find_element(msg2, msg1->elements[i].name); + if (!el) { + if (ldb_msg_add_empty(&mod, + msg1->elements[i].name, + LDB_FLAG_MOD_DELETE) != 0) { + return -1; + } + } + } + + if (mod.num_elements == 0) { + return 0; + } + + if (ldb_modify(ldb, &mod) != 0) { + fprintf(stderr, "failed to modify %s\n", msg1->dn); + return -1; + } + + return 0; +} + +/* + find dn in msgs[] +*/ +static struct ldb_message *msg_find(struct ldb_message **msgs, int count, + const char *dn) +{ + int i; + for (i=0;i<count;i++) { + if (strcmp(dn, msgs[i]->dn) == 0) { + return msgs[i]; + } + } + return NULL; +} + +/* + merge the changes in msgs2 into the messages from msgs1 +*/ +static int merge_edits(struct ldb_context *ldb, + struct ldb_message **msgs1, int count1, + struct ldb_message **msgs2, int count2) +{ + int i; + struct ldb_message *msg; + int ret = 0; + + /* do the adds and modifies */ + for (i=0;i<count2;i++) { + msg = msg_find(msgs1, count1, msgs2[i]->dn); + if (!msg) { + if (ldb_add(ldb, msgs2[i]) != 0) { + fprintf(stderr, "failed to add %s\n", + msgs2[i]->dn); + return -1; + } + } else { + modify_record(ldb, msg, msgs2[i]); + } + } + + /* do the deletes */ + for (i=0;i<count1;i++) { + msg = msg_find(msgs2, count2, msgs1[i]->dn); + if (!msg) { + if (ldb_delete(ldb, msgs1[i]->dn) != 0) { + fprintf(stderr, "failed to delete %s\n", + msgs1[i]->dn); + return -1; + } + } + } + + return ret; +} + +/* + save a set of messages as ldif to a file +*/ +static int save_ldif(FILE *f, struct ldb_message **msgs, int count) +{ + int i; + + fprintf(f, "# returned %d records\n", count); + + for (i=0;i<count;i++) { + struct ldb_ldif ldif; + fprintf(f, "# record %d\n", i+1); + + ldif.changetype = LDB_CHANGETYPE_NONE; + ldif.msg = *msgs[i]; + + ldif_write_file(f, &ldif); + } + + return 0; +} + + +/* + edit the ldb search results in msgs using the user selected editor +*/ +static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int count1, + const char *editor) +{ + int fd, ret; + FILE *f; + char template[] = "/tmp/ldbedit.XXXXXX"; + char *cmd; + struct ldb_ldif *ldif; + struct ldb_message **msgs2 = NULL; + int count2 = 0; + + /* write out the original set of messages to a temporary + file */ + fd = mkstemp(template); + + if (fd == -1) { + perror(template); + return -1; + } + + f = fdopen(fd, "r+"); + + if (!f) { + perror("fopen"); + close(fd); + unlink(template); + return -1; + } + + if (save_ldif(f, msgs1, count1) != 0) { + return -1; + } + + fclose(f); + + asprintf(&cmd, "%s %s", editor, template); + + if (!cmd) { + unlink(template); + fprintf(stderr, "out of memory\n"); + return -1; + } + + /* run the editor */ + ret = system(cmd); + free(cmd); + + if (ret != 0) { + unlink(template); + fprintf(stderr, "edit with %s failed\n", editor); + return -1; + } + + /* read the resulting ldif into msgs2 */ + f = fopen(template, "r"); + if (!f) { + perror(template); + return -1; + } + + while ((ldif = ldif_read_file(f))) { + msgs2 = realloc_p(msgs2, struct ldb_message *, count2+1); + if (!msgs2) { + fprintf(stderr, "out of memory"); + return -1; + } + msgs2[count2++] = &ldif->msg; + } + + fclose(f); + unlink(template); + + return merge_edits(ldb, msgs1, count1, msgs2, count2); +} + +static void usage(void) +{ + printf("Usage: ldbedit <options> <expression>\n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf(" -s base|sub|one choose search scope\n"); + printf(" -b basedn choose baseDN\n"); + printf(" -a edit all records (expression 'dn=*')\n"); + printf(" -e editor choose editor (or $VISUAL or $EDITOR)\n"); + exit(1); +} + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; + struct ldb_message **msgs; + int ret; + const char *expression = NULL; + const char *ldb_url; + const char *basedn = NULL; + int opt; + enum ldb_scope scope = LDB_SCOPE_SUBTREE; + const char *editor; + + ldb_url = getenv("LDB_URL"); + + /* build the editor command to run - + use the same editor priorities as vipw */ + editor = getenv("VISUAL"); + if (!editor) { + editor = getenv("EDITOR"); + } + if (!editor) { + editor = "vi"; + } + + while ((opt = getopt(argc, argv, "ab:e:H:s:")) != EOF) { + switch (opt) { + case 'b': + basedn = optarg; + break; + + case 'H': + ldb_url = optarg; + break; + + case 's': + if (strcmp(optarg, "base") == 0) { + scope = LDB_SCOPE_BASE; + } else if (strcmp(optarg, "sub") == 0) { + scope = LDB_SCOPE_SUBTREE; + } else if (strcmp(optarg, "one") == 0) { + scope = LDB_SCOPE_ONELEVEL; + } + break; + + case 'e': + editor = optarg; + break; + + case 'a': + expression = "dn=*"; + break; + + case 'h': + default: + usage(); + break; + } + } + + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + if (!expression) { + if (argc == 0) { + usage(); + } + expression = argv[0]; + } + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + ret = ldb_search(ldb, basedn, scope, expression, NULL, &msgs); + + if (ret == -1) { + printf("search failed - %s\n", ldb_errstring(ldb)); + exit(1); + } + + if (ret == 0) { + printf("no matching records - cannot edit\n"); + return 0; + } + + do_edit(ldb, msgs, ret, editor); + + if (ret > 0) { + ret = ldb_search_free(ldb, msgs); + if (ret == -1) { + fprintf(stderr, "search_free failed\n"); + exit(1); + } + } + + ldb_close(ldb); + return 0; +} diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index e1cff655db..a93c710a7a 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -34,27 +34,27 @@ #include "includes.h" - int main(void) -{ - static struct ldb_context *ldb; - struct ldb_ldif *ldif; - int ret; - int count=0, failures=0; - const char *ldb_url; - - ldb_url = getenv("LDB_URL"); - if (!ldb_url) { - ldb_url = "tdb://test.ldb"; - } +static int failures; - ldb = ldb_connect(ldb_url, 0, NULL); - - if (!ldb) { - perror("ldb_connect"); - exit(1); - } +static void usage(void) +{ + printf("Usage: ldbmodify <options> <ldif...>\n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf("\n"); + printf("Modifies a ldb based upon ldif change records\n\n"); + exit(1); +} - while ((ldif = ldif_read_file(stdin))) { +/* + process modifies for one file +*/ +static int process_file(struct ldb_context *ldb, FILE *f) +{ + struct ldb_ldif *ldif; + int ret, count = 0; + + while ((ldif = ldif_read_file(f))) { switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: @@ -77,6 +77,68 @@ ldif_read_free(ldif); } + return count; +} + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; + int count=0; + const char *ldb_url; + int opt, i; + + ldb_url = getenv("LDB_URL"); + + while ((opt = getopt(argc, argv, "hH:")) != EOF) { + switch (opt) { + case 'H': + ldb_url = optarg; + break; + + case 'h': + default: + usage(); + break; + } + } + + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + if (argc == 0) { + usage(); + exit(1); + } + + for (i=0;i<argc;i++) { + FILE *f; + if (strcmp(argv[i],"-") == 0) { + f = stdin; + } else { + f = fopen(argv[i], "r"); + } + if (!f) { + perror(argv[i]); + exit(1); + } + count += process_file(ldb, f); + if (f != stdin) { + fclose(f); + } + } + ldb_close(ldb); printf("Modified %d records with %d failures\n", count, failures); diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f4eb8f00db..327feb28ef 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -33,26 +33,32 @@ */ #include "includes.h" -#include <getopt.h> + +static void usage(void) +{ + printf("Usage: ldbsearch <options> <expression> <attrs...>\n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf(" -s base|sub|one choose search scope\n"); + printf(" -b basedn choose baseDN\n"); + exit(1); +} int main(int argc, char * const argv[]) { - static struct ldb_context *ldb; + struct ldb_context *ldb; struct ldb_message **msgs; int ret, i; const char *expression; - const char * const *attrs = NULL; + char * const *attrs = NULL; const char *ldb_url; const char *basedn = NULL; int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; ldb_url = getenv("LDB_URL"); - if (!ldb_url) { - ldb_url = "tdb://test.ldb"; - } - while ((opt = getopt(argc, argv, "b:H:s:")) != EOF) { + while ((opt = getopt(argc, argv, "b:H:s:h")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -71,14 +77,24 @@ scope = LDB_SCOPE_ONELEVEL; } break; + + case 'h': + default: + usage(); + break; } } + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + argc -= optind; argv += optind; if (argc < 1) { - printf("Usage: ldbsearch <expression> [attrs...]\n"); + usage(); exit(1); } diff --git a/source4/lib/replace.c b/source4/lib/replace.c index a4f3da1a66..cde9ce7a1b 100644 --- a/source4/lib/replace.c +++ b/source4/lib/replace.c @@ -445,7 +445,7 @@ char *rep_inet_ntoa(struct in_addr ip) tm2 = *tm; tm2.tm_isdst = tm3.tm_isdst; t = mktime(&tm2); - t -= TimeDiff(t); + t -= TimeDiff(); return t; } diff --git a/source4/lib/time.c b/source4/lib/time.c index 2844da004d..d6c6396996 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -1,8 +1,10 @@ /* Unix SMB/CIFS implementation. time handling functions - Copyright (C) Andrew Tridgell 1992-1998 + + Copyright (C) Andrew Tridgell 1992-2004 Copyright (C) Stefan (metze) Metzmacher 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 @@ -20,36 +22,17 @@ #include "includes.h" -/* - This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com> - in May 1996 - */ - - -int extra_time_offset = 0; - -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif - #ifndef TIME_T_MIN #define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ - : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) + : ~ (time_t) 0 << (sizeof (time_t) * 8 - 1)) #endif #ifndef TIME_T_MAX #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif -void get_nttime_max(NTTIME *t) -{ - /* FIXME: This is incorrect */ - unix_to_nt_time(t, get_time_t_max()); -} - /******************************************************************* External access to time_t_min and time_t_max. ********************************************************************/ - time_t get_time_t_max(void) { return TIME_T_MAX; @@ -67,225 +50,38 @@ void GetTimeOfDay(struct timeval *tval) #endif } -#define TM_YEAR_BASE 1900 - /******************************************************************* yield the difference between *A and *B, in seconds, ignoring leap seconds ********************************************************************/ static int tm_diff(struct tm *a, struct tm *b) { - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = - (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - - return seconds; + int ay = a->tm_year + (1900 - 1); + int by = b->tm_year + (1900 - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + + return seconds; } /******************************************************************* return the UTC offset in seconds west of UTC, or 0 if it cannot be determined ******************************************************************/ -static int TimeZone(time_t t) -{ - struct tm *tm = gmtime(&t); - struct tm tm_utc; - if (!tm) - return 0; - tm_utc = *tm; - tm = localtime(&t); - if (!tm) - return 0; - return tm_diff(&tm_utc,tm); - -} - -static BOOL done_serverzone_init; - -/* Return the smb serverzone value */ - -static int get_serverzone(void) -{ - static int serverzone; - - if (!done_serverzone_init) { - serverzone = TimeZone(time(NULL)); - - if ((serverzone % 60) != 0) { - DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); - } - - DEBUG(4,("Serverzone is %d\n",serverzone)); - - done_serverzone_init = True; - } - - return serverzone; -} - -/* Re-read the smb serverzone value */ - -static struct timeval start_time_hires; - -void TimeInit(void) -{ - done_serverzone_init = False; - get_serverzone(); - /* Save the start time of this process. */ - if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) - GetTimeOfDay(&start_time_hires); -} - -/********************************************************************** - Return a timeval struct of the uptime of this process. As TimeInit is - done before a daemon fork then this is the start time from the parent - daemon start. JRA. -***********************************************************************/ - -void get_process_uptime(struct timeval *ret_time) -{ - struct timeval time_now_hires; - - GetTimeOfDay(&time_now_hires); - ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec; - ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; - if (time_now_hires.tv_usec < start_time_hires.tv_usec) { - ret_time->tv_sec -= 1; - ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); - } else - ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; -} - -/******************************************************************* -return the same value as TimeZone, but it should be more efficient. - -We keep a table of DST offsets to prevent calling localtime() on each -call of this function. This saves a LOT of time on many unixes. - -Updated by Paul Eggert <eggert@twinsun.com> -********************************************************************/ -static int TimeZoneFaster(time_t t) +int get_time_zone(time_t t) { - static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; - static int table_size = 0; - int i; - int zone = 0; - - if (t == 0) t = time(NULL); - - /* Tunis has a 8 day DST region, we need to be careful ... */ -#define MAX_DST_WIDTH (365*24*60*60) -#define MAX_DST_SKIP (7*24*60*60) - - for (i=0;i<table_size;i++) - if (t >= dst_table[i].start && t <= dst_table[i].end) break; - - if (i<table_size) { - zone = dst_table[i].zone; - } else { - time_t low,high; - - zone = TimeZone(t); - tdt = (struct dst_table *)Realloc(dst_table, - sizeof(dst_table[0])*(i+1)); - if (!tdt) { - DEBUG(0,("TimeZoneFaster: out of memory!\n")); - SAFE_FREE(dst_table); - table_size = 0; - } else { - dst_table = tdt; - table_size++; - - dst_table[i].zone = zone; - dst_table[i].start = dst_table[i].end = t; - - /* no entry will cover more than 6 months */ - low = t - MAX_DST_WIDTH/2; - if (t < low) - low = TIME_T_MIN; - - high = t + MAX_DST_WIDTH/2; - if (high < t) - high = TIME_T_MAX; - - /* widen the new entry using two bisection searches */ - while (low+60*60 < dst_table[i].start) { - if (dst_table[i].start - low > MAX_DST_SKIP*2) - t = dst_table[i].start - MAX_DST_SKIP; - else - t = low + (dst_table[i].start-low)/2; - if (TimeZone(t) == zone) - dst_table[i].start = t; - else - low = t; - } - - while (high-60*60 > dst_table[i].end) { - if (high - dst_table[i].end > MAX_DST_SKIP*2) - t = dst_table[i].end + MAX_DST_SKIP; - else - t = high - (high-dst_table[i].end)/2; - if (TimeZone(t) == zone) - dst_table[i].end = t; - else - high = t; - } -#if 0 - DEBUG(1,("Added DST entry from %s ", - asctime(localtime(&dst_table[i].start)))); - DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)), - dst_table[i].zone)); -#endif - } - } - return zone; -} - -/**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time offset - **************************************************************************/ -int TimeDiff(time_t t) -{ - return TimeZoneFaster(t) + 60 * lp_time_offset(); -} - - -/**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time - offset, for a local time value. If ut = lt + LocTimeDiff(lt), then - lt = ut - TimeDiff(ut), but the converse does not necessarily hold near - daylight savings transitions because some local times are ambiguous. - LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. - +**************************************************************************/ -static int LocTimeDiff(time_t lte) -{ - time_t lt = lte - 60 * lp_time_offset(); - int d = TimeZoneFaster(lt); - time_t t = lt + d; - - /* if overflow occurred, ignore all the adjustments so far */ - if (((lte < lt) ^ (lp_time_offset() < 0)) | ((t < lt) ^ (d < 0))) - t = lte; - - /* now t should be close enough to the true UTC to yield the right answer */ - return TimeDiff(t); -} - - -/**************************************************************************** -try to optimise the localtime call, it can be quite expensive on some machines -****************************************************************************/ -struct tm *LocalTime(time_t *t) -{ - time_t t2 = *t; - - t2 -= TimeDiff(t2); - - return(gmtime(&t2)); + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); } #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) @@ -293,86 +89,36 @@ struct tm *LocalTime(time_t *t) /**************************************************************************** interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" - -It appears to be kludge-GMT (at least for file listings). This means -its the GMT you get by taking a localtime and adding the -serverzone. This is NOT the same as GMT in some cases. This routine -converts this to real GMT. ****************************************************************************/ time_t nt_time_to_unix(const NTTIME *nt) { - double d; - time_t ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; - - if (nt->high == 0) return(0); - - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); - d *= 1.0e-7; - - /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT; - - if (!(l_time_min <= d && d <= l_time_max)) - return(0); - - ret = (time_t)(d+0.5); - - /* this takes us from kludge-GMT to real GMT */ - ret -= get_serverzone(); - ret += LocTimeDiff(ret); - - return(ret); -} - -/**************************************************************************** - Convert a NTTIME structure to a time_t. - It's originally in "100ns units". - - This is an absolute version of the one above. - By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 - if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM -****************************************************************************/ - -time_t nt_time_to_unix_abs(NTTIME *nt) -{ double d; time_t ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; - if (nt->high == 0) - return(0); - - if (nt->high==0x80000000 && nt->low==0) - return -1; - - /* reverse the time */ - /* it's a negative value, turn it to positive */ - nt->high=~nt->high; - nt->low=~nt->low; + if (nt->high == 0) { + return 0; + } d = ((double)nt->high)*4.0*(double)(1<<30); d += (nt->low&0xFFF00000); d *= 1.0e-7; - - if (!(l_time_min <= d && d <= l_time_max)) - return(0); + + /* now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT; + + if (TIME_T_MIN >= d || d >= TIME_T_MAX) { + return 0; + } ret = (time_t)(d+0.5); - return(ret); + return ret; } + /**************************************************************************** put a 8 byte filetime from a time_t -This takes real GMT as input and converts to kludge-GMT +This takes GMT as input ****************************************************************************/ void unix_to_nt_time(NTTIME *nt, time_t t) { @@ -394,9 +140,6 @@ void unix_to_nt_time(NTTIME *nt, time_t t) return; } - /* this converts GMT to kludge-GMT */ - t -= TimeDiff(t) - get_serverzone(); - d = (double)(t); d += TIME_FIXUP_CONSTANT; d *= 1.0e7; @@ -405,69 +148,15 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } -/**************************************************************************** - Convert a time_t to a NTTIME structure - - This is an absolute version of the one above. - By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 - If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM -****************************************************************************/ - -void unix_to_nt_time_abs(NTTIME *nt, time_t t) -{ - double d; - - if (t==0) { - nt->low = 0; - nt->high = 0; - return; - } - - if (t == TIME_T_MAX) { - nt->low = 0xffffffff; - nt->high = 0x7fffffff; - return; - } - - if (t == -1) { - /* that's what NT uses for infinite */ - nt->low = 0x0; - nt->high = 0x80000000; - return; - } - - d = (double)(t); - d *= 1.0e7; - - nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); - nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); - - /* convert to a negative value */ - nt->high=~nt->high; - nt->low=~nt->low; -} - - -/**************************************************************************** -take an NTTIME structure, containing high / low time. convert to unix time. -lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... -****************************************************************************/ -void put_long_date(char *p,time_t t) -{ - NTTIME nt; - unix_to_nt_time(&nt, t); - SIVAL(p, 0, nt.low); - SIVAL(p, 4, nt.high); -} /**************************************************************************** check if it's a null mtime ****************************************************************************/ BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) - return True; - return False; + return mtime == 0 || + mtime == (time_t)0xFFFFFFFF || + mtime == (time_t)-1; } /******************************************************************* @@ -496,7 +185,7 @@ static uint16 make_dos_time1(struct tm *t) create a 32 bit dos packed date/time from some parameters This takes a GMT time and returns a packed localtime structure ********************************************************************/ -static uint32 make_dos_date(time_t unixdate) +static uint32 make_dos_date(time_t unixdate, int zone_offset) { struct tm *t; uint32 ret=0; @@ -505,7 +194,9 @@ static uint32 make_dos_date(time_t unixdate) return 0; } - t = LocalTime(&unixdate); + unixdate -= zone_offset; + + t = gmtime(&unixdate); if (!t) { return 0xFFFFFFFF; } @@ -520,9 +211,9 @@ static uint32 make_dos_date(time_t unixdate) put a dos date into a buffer (time/date format) This takes GMT time and puts local time in the buffer ********************************************************************/ -void put_dos_date(char *buf,int offset,time_t unixdate) +void push_dos_date(char *buf, int offset, time_t unixdate, int zone_offset) { - uint32 x = make_dos_date(unixdate); + uint32 x = make_dos_date(unixdate, zone_offset); SIVAL(buf,offset,x); } @@ -530,10 +221,10 @@ void put_dos_date(char *buf,int offset,time_t unixdate) put a dos date into a buffer (date/time format) This takes GMT time and puts local time in the buffer ********************************************************************/ -void put_dos_date2(char *buf,int offset,time_t unixdate) +void push_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset) { uint32 x; - x = make_dos_date(unixdate); + x = make_dos_date(unixdate, zone_offset); x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(buf,offset,x); } @@ -543,10 +234,11 @@ put a dos 32 bit "unix like" date into a buffer. This routine takes GMT and converts it to LOCAL time before putting it (most SMBs assume localtime for this sort of date) ********************************************************************/ -void put_dos_date3(char *buf,int offset,time_t unixdate) +void push_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset) { - if (!null_mtime(unixdate)) - unixdate -= TimeDiff(unixdate); + if (!null_mtime(unixdate)) { + unixdate -= zone_offset; + } SIVAL(buf,offset,unixdate); } @@ -555,24 +247,24 @@ void put_dos_date3(char *buf,int offset,time_t unixdate) ********************************************************************/ static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) { - uint32 p0,p1,p2,p3; + uint32 p0,p1,p2,p3; - p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; - p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; - *second = 2*(p0 & 0x1F); - *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); - *hour = (p1>>3)&0xFF; - *day = (p2&0x1F); - *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; - *year = ((p3>>1)&0xFF) + 80; + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; } /******************************************************************* create a unix date (int GMT) from a dos date (which is actually in localtime) ********************************************************************/ -time_t make_unix_date(void *date_ptr) +time_t pull_dos_date(const uint8 *date_ptr, int zone_offset) { uint32 dos_date=0; struct tm t; @@ -586,16 +278,17 @@ time_t make_unix_date(void *date_ptr) &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); t.tm_isdst = -1; - /* mktime() also does the local to GMT time conversion for us */ - ret = mktime(&t); + ret = timegm(&t); - return(ret); + ret += zone_offset; + + return ret; } /******************************************************************* like make_unix_date() but the words are reversed ********************************************************************/ -time_t make_unix_date2(void *date_ptr) +time_t pull_dos_date2(const uint8 *date_ptr, int zone_offset) { uint32 x,x2; @@ -603,18 +296,19 @@ time_t make_unix_date2(void *date_ptr) x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return make_unix_date((void *)&x); + return pull_dos_date((void *)&x, zone_offset); } /******************************************************************* create a unix GMT date from a dos date in 32 bit "unix like" format these generally arrive as localtimes, with corresponding DST ******************************************************************/ -time_t make_unix_date3(void *date_ptr) +time_t pull_dos_date3(const uint8 *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); - if (!null_mtime(t)) - t += LocTimeDiff(t); + if (!null_mtime(t)) { + t += zone_offset; + } return t; } @@ -624,22 +318,25 @@ return a HTTP/1.0 time string ***************************************************************************/ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) { - char *buf; - fstring tempTime; - struct tm *tm = LocalTime(&t); + char *buf; + char tempTime[60]; + struct tm *tm = localtime(&t); + + if (!tm) { + return talloc_asprintf(mem_ctx,"%ld seconds since the Epoch",(long)t); + } - if (!tm) - buf = talloc_asprintf(mem_ctx,"%ld seconds since the Epoch",(long)t); - else #ifndef HAVE_STRFTIME - buf = talloc_strdup(mem_ctx, asctime(tm)); - if(buf[strlen(buf)-1] == '\n') - buf[strlen(buf)-1] = 0; -#else /* !HAVE_STRFTIME */ + buf = talloc_strdup(mem_ctx, asctime(tm)); + if (buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = 0; + } +#else strftime(tempTime, sizeof(tempTime)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); - buf = talloc_strdup(mem_ctx, tempTime); + buf = talloc_strdup(mem_ctx, tempTime); #endif /* !HAVE_STRFTIME */ - return buf; + + return buf; } @@ -647,90 +344,27 @@ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) /**************************************************************************** Return the date and time as a string ****************************************************************************/ - -char *timestring(TALLOC_CTX *mem_ctx, BOOL hires) +char *timestring(TALLOC_CTX *mem_ctx, time_t t) { char *TimeBuf; - fstring tempTime; - struct timeval tp; - time_t t; + char tempTime[80]; struct tm *tm; - if (hires) { - GetTimeOfDay(&tp); - t = (time_t)tp.tv_sec; - } else { - t = time(NULL); - } - tm = LocalTime(&t); + tm = localtime(&t); if (!tm) { - if (hires) { - TimeBuf = talloc_asprintf(mem_ctx, - "%ld.%06ld seconds since the Epoch", - (long)tp.tv_sec, - (long)tp.tv_usec); - } else { - TimeBuf = talloc_asprintf(mem_ctx, - "%ld seconds since the Epoch", - (long)t); - } - } else { + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); + } + #ifdef HAVE_STRFTIME - if (hires) { - strftime(tempTime,sizeof(tempTime)-1,"%Y/%m/%d %H:%M:%S",tm); - TimeBuf = talloc_asprintf(mem_ctx, "%s.%06ld", - tempTime, (long)tp.tv_usec); - } else { - strftime(tempTime,100,"%Y/%m/%d %H:%M:%S",tm); - TimeBuf = talloc_strdup(mem_ctx, tempTime); - } + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); #else - if (hires) { - TimeBuf = talloc_asprintf(mem_ctx, - "%s.%06ld", - asctime(tm), - (long)tp.tv_usec); - } else { - TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); - } + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); #endif - } - return(TimeBuf); -} - -/**************************************************************************** - return the best approximation to a 'create time' under UNIX from a stat - structure. -****************************************************************************/ - -time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) -{ - time_t ret, ret1; - - if(S_ISDIR(st->st_mode) && fake_dirs) - return (time_t)315493200L; /* 1/1/1980 */ - - ret = MIN(st->st_ctime, st->st_mtime); - ret1 = MIN(ret, st->st_atime); - - if(ret1 != (time_t)0) - return ret1; - - /* - * One of ctime, mtime or atime was zero (probably atime). - * Just return MIN(ctime, mtime). - */ - return ret; -} - -/**************************************************************************** -initialise an NTTIME to -1, which means "unknown" or "don't expire" -****************************************************************************/ -void init_nt_time(NTTIME *nt) -{ - nt->high = 0x7FFFFFFF; - nt->low = 0xFFFFFFFF; + return TimeBuf; } /**************************************************************************** @@ -738,9 +372,7 @@ check if NTTIME is 0 ****************************************************************************/ BOOL nt_time_is_zero(NTTIME *nt) { - if(nt->high==0) - return True; - return False; + return (nt->high==0); } /* @@ -749,6 +381,27 @@ BOOL nt_time_is_zero(NTTIME *nt) const char *nt_time_string(TALLOC_CTX *mem_ctx, const NTTIME *nt) { time_t t = nt_time_to_unix(nt); - return talloc_strdup(mem_ctx, http_timestring(mem_ctx, t)); + return talloc_strdup(mem_ctx, timestring(mem_ctx, t)); +} + + +/* + put a NTTIME into a packet +*/ +void push_nttime(void *base, uint16 offset, NTTIME *t) +{ + SIVAL(base, offset, t->low); + SIVAL(base, offset+4, t->high); +} + +/* + pull a NTTIME from a packet +*/ +NTTIME pull_nttime(void *base, uint16 offset) +{ + NTTIME ret; + ret.low = IVAL(base, offset); + ret.high = IVAL(base, offset+4); + return ret; } diff --git a/source4/libcli/config.m4 b/source4/libcli/config.m4 index ac8e7cbabb..b5273b9bb2 100644 --- a/source4/libcli/config.m4 +++ b/source4/libcli/config.m4 @@ -10,7 +10,8 @@ SMB_SUBSYSTEM(LIBCLI_RAW,[], libcli/raw/rawtrans.o libcli/raw/clioplock.o \ libcli/raw/rawnegotiate.o libcli/raw/rawfsinfo.o \ libcli/raw/rawfileinfo.o libcli/raw/rawnotify.o \ - libcli/raw/rawioctl.o libcli/raw/rawacl.o], + libcli/raw/rawioctl.o libcli/raw/rawacl.o \ + libcli/raw/rawdate.o ], libcli/raw/libcli_raw_public_proto.h) SMB_SUBSYSTEM(LIBCLI_UTILS,[], diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c new file mode 100644 index 0000000000..e80c376bf7 --- /dev/null +++ b/source4/libcli/raw/rawdate.c @@ -0,0 +1,81 @@ +/* + Unix SMB/CIFS implementation. + + raw date handling functions + + Copyright (C) Andrew Tridgell 2004 + + 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" + +/******************************************************************* +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time for zone_offset in the buffer +********************************************************************/ +void raw_push_dos_date(struct cli_transport *transport, + uint8 *buf, int offset, time_t unixdate) +{ + push_dos_date(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void raw_push_dos_date2(struct cli_transport *transport, + char *buf, int offset, time_t unixdate) +{ + push_dos_date2(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +put a dos 32 bit "unix like" date into a buffer. This routine takes +GMT and converts it to LOCAL time in zone_offset before putting it +********************************************************************/ +void raw_push_dos_date3(struct cli_transport *transport, + char *buf, int offset, time_t unixdate) +{ + push_dos_date3(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +convert a dos date +********************************************************************/ +time_t raw_pull_dos_date(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date(date_ptr, transport->negotiate.server_zone); +} + +/******************************************************************* +like raw_pull_dos_date() but the words are reversed +********************************************************************/ +time_t raw_pull_dos_date2(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date2(date_ptr, transport->negotiate.server_zone); +} + +/******************************************************************* + create a unix GMT date from a dos date in 32 bit "unix like" format + these arrive in server zone, with corresponding DST + ******************************************************************/ +time_t raw_pull_dos_date3(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date3(date_ptr, transport->negotiate.server_zone); +} diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 0dc2a15c11..d1a665ab14 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -240,7 +240,8 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, SSVAL(t2.in.params.data, VWV(1), parms->t2open.in.open_mode); SSVAL(t2.in.params.data, VWV(2), 0); /* reserved */ SSVAL(t2.in.params.data, VWV(3), parms->t2open.in.file_attrs); - put_dos_date(t2.in.params.data, VWV(4), parms->t2open.in.write_time); + raw_push_dos_date(tree->session->transport, + t2.in.params.data, VWV(4), parms->t2open.in.write_time); SSVAL(t2.in.params.data, VWV(6), parms->t2open.in.open_func); SIVAL(t2.in.params.data, VWV(7), parms->t2open.in.size); SIVAL(t2.in.params.data, VWV(9), parms->t2open.in.timeout); @@ -278,7 +279,8 @@ static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx parms->t2open.out.fnum = SVAL(t2.out.params.data, VWV(0)); parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); - parms->t2open.out.write_time = make_unix_date3(t2.out.params.data + VWV(2)); + parms->t2open.out.write_time = raw_pull_dos_date3(req->transport, + t2.out.params.data + VWV(2)); parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); parms->t2open.out.access = SVAL(t2.out.params.data, VWV(6)); parms->t2open.out.ftype = SVAL(t2.out.params.data, VWV(7)); @@ -316,7 +318,8 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SSVAL(req->out.vwv, VWV(3), parms->openx.in.open_mode); SSVAL(req->out.vwv, VWV(4), parms->openx.in.search_attrs); SSVAL(req->out.vwv, VWV(5), parms->openx.in.file_attrs); - put_dos_date3(req->out.vwv, VWV(6), parms->openx.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(6), parms->openx.in.write_time); SSVAL(req->out.vwv, VWV(8), parms->openx.in.open_func); SIVAL(req->out.vwv, VWV(9), parms->openx.in.size); SIVAL(req->out.vwv, VWV(11),parms->openx.in.timeout); @@ -327,21 +330,24 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par case RAW_OPEN_MKNEW: SETUP_REQUEST(SMBmknew, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->mknew.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->mknew.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->mknew.in.write_time); cli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); break; case RAW_OPEN_CREATE: SETUP_REQUEST(SMBcreate, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->create.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->create.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->create.in.write_time); cli_req_append_ascii4(req, parms->create.in.fname, STR_TERMINATE); break; case RAW_OPEN_CTEMP: SETUP_REQUEST(SMBctemp, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->ctemp.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->ctemp.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->ctemp.in.write_time); cli_req_append_ascii4(req, parms->ctemp.in.directory, STR_TERMINATE); break; @@ -398,7 +404,8 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s CLI_CHECK_WCT(req, 7); parms->open.out.fnum = SVAL(req->in.vwv, VWV(0)); parms->open.out.attrib = SVAL(req->in.vwv, VWV(1)); - parms->open.out.write_time = make_unix_date3(req->in.vwv + VWV(2)); + parms->open.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(2)); parms->open.out.size = IVAL(req->in.vwv, VWV(4)); parms->open.out.rmode = SVAL(req->in.vwv, VWV(6)); break; @@ -407,7 +414,8 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s CLI_CHECK_MIN_WCT(req, 15); parms->openx.out.fnum = SVAL(req->in.vwv, VWV(2)); parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); - parms->openx.out.write_time = make_unix_date3(req->in.vwv + VWV(4)); + parms->openx.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(4)); parms->openx.out.size = IVAL(req->in.vwv, VWV(6)); parms->openx.out.access = SVAL(req->in.vwv, VWV(8)); parms->openx.out.ftype = SVAL(req->in.vwv, VWV(9)); @@ -491,7 +499,8 @@ struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *p case RAW_CLOSE_CLOSE: SETUP_REQUEST(SMBclose, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->close.in.fnum); - put_dos_date3(req->out.vwv, VWV(1), parms->close.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->close.in.write_time); break; case RAW_CLOSE_SPLCLOSE: diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index fd66080057..9d715e6104 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -52,9 +52,12 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_STANDARD: FINFO_CHECK_SIZE(22); - parms->standard.out.create_time = make_unix_date2(blob->data + 0); - parms->standard.out.access_time = make_unix_date2(blob->data + 4); - parms->standard.out.write_time = make_unix_date2(blob->data + 8); + parms->standard.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->standard.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->standard.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); parms->standard.out.size = IVAL(blob->data, 12); parms->standard.out.alloc_size = IVAL(blob->data, 16); parms->standard.out.attrib = SVAL(blob->data, 20); @@ -62,9 +65,12 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_EA_SIZE: FINFO_CHECK_SIZE(26); - parms->ea_size.out.create_time = make_unix_date2(blob->data + 0); - parms->ea_size.out.access_time = make_unix_date2(blob->data + 4); - parms->ea_size.out.write_time = make_unix_date2(blob->data + 8); + parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->ea_size.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); parms->ea_size.out.size = IVAL(blob->data, 12); parms->ea_size.out.alloc_size = IVAL(blob->data, 16); parms->ea_size.out.attrib = SVAL(blob->data, 20); @@ -376,7 +382,8 @@ static NTSTATUS smb_raw_getattr_recv(struct cli_request *req, CLI_CHECK_WCT(req, 10); parms->getattr.out.attrib = SVAL(req->in.vwv, VWV(0)); - parms->getattr.out.write_time = make_unix_date3(req->in.vwv + VWV(1)); + parms->getattr.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(1)); parms->getattr.out.size = IVAL(req->in.vwv, VWV(3)); failed: @@ -416,9 +423,12 @@ static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, } CLI_CHECK_WCT(req, 11); - parms->getattre.out.create_time = make_unix_date2(req->in.vwv + VWV(0)); - parms->getattre.out.access_time = make_unix_date2(req->in.vwv + VWV(2)); - parms->getattre.out.write_time = make_unix_date2(req->in.vwv + VWV(4)); + parms->getattre.out.create_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(0)); + parms->getattre.out.access_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(2)); + parms->getattre.out.write_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(4)); parms->getattre.out.size = IVAL(req->in.vwv, VWV(6)); parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8)); parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 04941f6118..587050bef8 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -129,8 +129,9 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(6)); transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(10)) * 60; - /* this time is converted to GMT by make_unix_date */ - transport->negotiate.server_time = make_unix_date(req->in.vwv+VWV(8)); + /* this time is converted to GMT by raw_pull_dos_date */ + transport->negotiate.server_time = raw_pull_dos_date(transport, + req->in.vwv+VWV(8)); if ((SVAL(req->in.vwv,VWV(5)) & 0x1)) { transport->negotiate.readbraw_supported = 1; } @@ -144,7 +145,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.sec_mode = 0; transport->negotiate.server_time = time(NULL); transport->negotiate.max_xmit = ~0; - transport->negotiate.server_zone = TimeDiff(time(NULL)); + transport->negotiate.server_zone = get_time_zone(transport->negotiate.server_time); } /* a way to force ascii SMB */ diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 3aa95c35aa..3e3b29d252 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -223,7 +223,8 @@ struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *p SSVAL(req->out.vwv, VWV(0), parms->writeclose.in.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeclose.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeclose.in.offset); - put_dos_date3(req->out.vwv, VWV(4), parms->writeclose.in.mtime); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(4), parms->writeclose.in.mtime); SCVAL(req->out.data, 0, 0); if (parms->writeclose.in.count > 0) { memcpy(req->out.data+1, parms->writeclose.in.data, diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 4c7da6ec4d..a4236d2dbe 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -44,7 +44,8 @@ static void smb_raw_search_backend(struct cli_request *req, for (i=0; i < count; i++) { search_data.search.search_id = cli_req_pull_blob(req, mem_ctx, p, 21); search_data.search.attrib = CVAL(p, 21); - search_data.search.write_time = make_unix_date(p + 22); + search_data.search.write_time = raw_pull_dos_date(req->transport, + p + 22); search_data.search.size = IVAL(p, 26); cli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); if (!callback(private, &search_data)) { @@ -255,9 +256,12 @@ static int parse_trans2_search(struct cli_tree *tree, blob->length -= 4; } if (blob->length < 24) return -1; - data->standard.create_time = make_unix_date2(blob->data + 0); - data->standard.access_time = make_unix_date2(blob->data + 4); - data->standard.write_time = make_unix_date2(blob->data + 8); + data->standard.create_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 0); + data->standard.access_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 4); + data->standard.write_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 8); data->standard.size = IVAL(blob->data, 12); data->standard.alloc_size = IVAL(blob->data, 16); data->standard.attrib = SVAL(blob->data, 20); @@ -274,9 +278,12 @@ static int parse_trans2_search(struct cli_tree *tree, blob->length -= 4; } if (blob->length < 28) return -1; - data->ea_size.create_time = make_unix_date2(blob->data + 0); - data->ea_size.access_time = make_unix_date2(blob->data + 4); - data->ea_size.write_time = make_unix_date2(blob->data + 8); + data->ea_size.create_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 0); + data->ea_size.access_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 4); + data->ea_size.write_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 8); data->ea_size.size = IVAL(blob->data, 12); data->ea_size.alloc_size = IVAL(blob->data, 16); data->ea_size.attrib = SVAL(blob->data, 20); diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index b82c20176b..9da94f161c 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -45,9 +45,12 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, case RAW_SFILEINFO_STANDARD: NEED_BLOB(12); - put_dos_date2(blob->data, 0, parms->standard.in.create_time); - put_dos_date2(blob->data, 4, parms->standard.in.access_time); - put_dos_date2(blob->data, 8, parms->standard.in.write_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 0, parms->standard.in.create_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 4, parms->standard.in.access_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 8, parms->standard.in.write_time); return True; case RAW_SFILEINFO_EA_SET: @@ -204,7 +207,8 @@ static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree, if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->setattr.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->setattr.in.write_time); memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ cli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); cli_req_append_ascii4(req, "", STR_TERMINATE); @@ -229,9 +233,12 @@ static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum); - put_dos_date2(req->out.vwv, VWV(1), parms->setattre.in.create_time); - put_dos_date2(req->out.vwv, VWV(3), parms->setattre.in.access_time); - put_dos_date2(req->out.vwv, VWV(5), parms->setattre.in.write_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(1), parms->setattre.in.create_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(3), parms->setattre.in.access_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(5), parms->setattre.in.write_time); if (!cli_request_send(req)) { cli_request_destroy(req); diff --git a/source4/libcli/util/smbencrypt.c b/source4/libcli/util/smbencrypt.c index 39f3803ade..fc3449d767 100644 --- a/source4/libcli/util/smbencrypt.c +++ b/source4/libcli/util/smbencrypt.c @@ -342,10 +342,13 @@ static DATA_BLOB NTLMv2_generate_client_data(const DATA_BLOB *names_blob) uchar client_chal[8]; DATA_BLOB response = data_blob(NULL, 0); char long_date[8]; + NTTIME nttime; + + unix_to_nt_time(&nttime, time(NULL)); generate_random_buffer(client_chal, sizeof(client_chal), False); - put_long_date(long_date, time(NULL)); + push_nttime(long_date, 0, &nttime); /* See http://www.ubiqx.org/cifs/SMB.html#SMB.8.5 */ diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c index 0c63faf347..570f7719a4 100644 --- a/source4/librpc/ndr/ndr_basic.c +++ b/source4/librpc/ndr/ndr_basic.c @@ -678,7 +678,7 @@ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t) if (t == (time_t)-1 || t == 0) { ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t); } else { - ndr->print(ndr, "%-25s: %s", name, http_timestring(ndr->mem_ctx, t)); + ndr->print(ndr, "%-25s: %s", name, timestring(ndr->mem_ctx, t)); } } diff --git a/source4/librpc/rpc/dcerpc_lsa.c b/source4/librpc/rpc/dcerpc_lsa.c index 482853c0ab..9c00ce34f3 100644 --- a/source4/librpc/rpc/dcerpc_lsa.c +++ b/source4/librpc/rpc/dcerpc_lsa.c @@ -27,7 +27,6 @@ NTSTATUS lsa_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct lsa_ObjectAttribute attr; struct lsa_QosInfo qos; struct lsa_OpenPolicy r; - NTSTATUS status; uint16 system_name = '\\'; qos.len = 0; diff --git a/source4/nmbd/nmbd_namelistdb.c b/source4/nmbd/nmbd_namelistdb.c index 932d926a91..6653cdd24b 100644 --- a/source4/nmbd/nmbd_namelistdb.c +++ b/source4/nmbd/nmbd_namelistdb.c @@ -566,7 +566,7 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) if(namerec->data.death_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->data.death_time); + tm = localtime(&namerec->data.death_time); x_fprintf(fp, "death_time = %s\t", asctime(tm)); } else @@ -574,7 +574,7 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) if(namerec->data.refresh_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->data.refresh_time); + tm = localtime(&namerec->data.refresh_time); x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); } else diff --git a/source4/nmbd/nmbd_winsserver.c b/source4/nmbd/nmbd_winsserver.c index 4ef476f814..6d1f654e84 100644 --- a/source4/nmbd/nmbd_winsserver.c +++ b/source4/nmbd/nmbd_winsserver.c @@ -1814,7 +1814,7 @@ void wins_write_database(BOOL background) if( namerec->data.death_time != PERMANENT_TTL ) { char *ts, *nl; - tm = LocalTime(&namerec->data.death_time); + tm = localtime(&namerec->data.death_time); ts = asctime(tm); nl = strrchr_m( ts, '\n' ); if( NULL != nl ) diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 966a670677..2a87d59a06 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -145,14 +145,15 @@ static NTSTATUS cvfs_connect(struct request_context *req, const char *sharename) private->map_calls = talloc_strdup(conn->mem_ctx, map_calls); } - /* if we are mapping trans2, then we need to not give a trans2 + /* if we are mapping trans2, then we need to give a trans2 pointer in the operations structure */ if (private->map_calls && in_list("trans2", private->map_calls, True)) { struct ntvfs_ops *ops = talloc_memdup(conn->mem_ctx,conn->ntvfs_ops,sizeof(*ops)); + static NTSTATUS cvfs_trans2(struct request_context *,struct smb_trans2 *); if (!ops) { return NT_STATUS_NO_MEMORY; } - ops->trans2 = NULL; + ops->trans2 = cvfs_trans2; conn->ntvfs_ops = ops; } @@ -725,10 +726,10 @@ NTSTATUS ntvfs_cifs_init(void) ops.trans = cvfs_trans; /* only define this one for trans2 testing */ - ops.trans2 = cvfs_trans2; - - /* register ourselves with the NTVFS subsystem. We register under the name 'cifs'. */ + ops.trans2 = NULL; + /* register ourselves with the NTVFS subsystem. We register + under the name 'cifs'. */ ret = register_backend("ntvfs", &ops); if (!NT_STATUS_IS_OK(ret)) { diff --git a/source4/printing/print_generic.c b/source4/printing/print_generic.c index 4d77b827bf..aae2844ded 100644 --- a/source4/printing/print_generic.c +++ b/source4/printing/print_generic.c @@ -99,7 +99,7 @@ static int generic_job_delete(int snum, struct printjob *pjob) snum, lp_lprmcommand(snum), NULL, "%j", jobstr, - "%T", http_timestring(pjob->starttime), + "%T", timestring(pjob->starttime), NULL); } diff --git a/source4/smb_server/config.m4 b/source4/smb_server/config.m4 index 4ce688850c..e49f610317 100644 --- a/source4/smb_server/config.m4 +++ b/source4/smb_server/config.m4 @@ -1,16 +1,17 @@ dnl # SMB server subsystem SMB_SUBSYSTEM(SMB,smb_server/smb_server.o, - [smb_server/conn.o ]\ - [smb_server/connection.o]\ - [smb_server/negprot.o]\ - [smb_server/nttrans.o]\ - [smb_server/password.o]\ - [smb_server/reply.o]\ - [smb_server/request.o]\ - [smb_server/search.o]\ - [smb_server/service.o]\ - [smb_server/session.o]\ - [smb_server/sesssetup.o]\ - [smb_server/trans2.o], + [smb_server/conn.o \ + smb_server/connection.o \ + smb_server/negprot.o \ + smb_server/nttrans.o \ + smb_server/password.o \ + smb_server/reply.o \ + smb_server/request.o \ + smb_server/search.o \ + smb_server/service.o \ + smb_server/session.o \ + smb_server/sesssetup.o \ + smb_server/srvtime.o \ + smb_server/trans2.o],\ smb_server/smb_server_public_proto.h) diff --git a/source4/smb_server/negprot.c b/source4/smb_server/negprot.c index caf3ce33b9..92ce5675ad 100644 --- a/source4/smb_server/negprot.c +++ b/source4/smb_server/negprot.c @@ -119,8 +119,8 @@ static void reply_lanman1(struct request_context *req, uint16 choice) SSVAL(req->out.vwv, VWV(4), 1); SSVAL(req->out.vwv, VWV(5), raw); SIVAL(req->out.vwv, VWV(6), req->smb->pid); - put_dos_date(req->out.vwv, VWV(8), t); - SSVAL(req->out.vwv, VWV(10), TimeDiff(t)/60); + srv_push_dos_date(req->smb, req->out.vwv, VWV(8), t); + SSVAL(req->out.vwv, VWV(10), req->smb->negotiate.zone_offset/60); /* Create a token value and add it to the outgoing packet. */ if (req->smb->negotiate.encrypted_passwords) { @@ -159,8 +159,8 @@ static void reply_lanman2(struct request_context *req, uint16 choice) SSVAL(req->out.vwv, VWV(4), 1); SSVAL(req->out.vwv, VWV(5), raw); SIVAL(req->out.vwv, VWV(6), req->smb->pid); - put_dos_date(req->out.vwv, VWV(8), t); - SSVAL(req->out.vwv, VWV(10), TimeDiff(t)/60); + srv_push_dos_date(req->smb, req->out.vwv, VWV(8), t); + SSVAL(req->out.vwv, VWV(10), req->smb->negotiate.zone_offset/60); /* Create a token value and add it to the outgoing packet. */ if (req->smb->negotiate.encrypted_passwords) { @@ -229,8 +229,11 @@ static void reply_nt1(struct request_context *req, uint16 choice) int capabilities; int secword=0; time_t t = req->request_time.tv_sec; + NTTIME nttime; BOOL negotiate_spnego = False; + unix_to_nt_time(&nttime, t); + capabilities = CAP_NT_FIND | CAP_LOCK_AND_READ | CAP_LEVEL_II_OPLOCKS | CAP_NT_SMBS | CAP_RPC_REMOTE_APIS; @@ -303,8 +306,8 @@ static void reply_nt1(struct request_context *req, uint16 choice) SIVAL(req->out.vwv+1, VWV(5), 0x10000); /* raw size. full 64k */ SIVAL(req->out.vwv+1, VWV(7), req->smb->pid); /* session key */ SIVAL(req->out.vwv+1, VWV(9), capabilities); - put_long_date(req->out.vwv + VWV(11) + 1, t); - SSVALS(req->out.vwv+1,VWV(15), TimeDiff(t)/60); + push_nttime(req->out.vwv+1, VWV(11), &nttime); + SSVALS(req->out.vwv+1,VWV(15), req->smb->negotiate.zone_offset/60); if (!negotiate_spnego) { /* Create a token value and add it to the outgoing packet. */ diff --git a/source4/smb_server/reply.c b/source4/smb_server/reply.c index 298b2443d3..8b9bb4fb5e 100644 --- a/source4/smb_server/reply.c +++ b/source4/smb_server/reply.c @@ -62,27 +62,6 @@ /* zero out some reserved fields in a reply */ #define REQ_VWV_RESERVED(start, count) memset(req->out.vwv + VWV(start), 0, (count)*2) -/* - put a NTTIME into a packet -*/ -void push_nttime(void *base, uint16 offset, NTTIME *t) -{ - SIVAL(base, offset, t->low); - SIVAL(base, offset+4, t->high); -} - -/* - pull a NTTIME from a packet -*/ -NTTIME pull_nttime(void *base, uint16 offset) -{ - NTTIME ret; - ret.low = IVAL(base, offset); - ret.high = IVAL(base, offset+4); - return ret; -} - - /**************************************************************************** Reply to a simple request (async send) ****************************************************************************/ @@ -298,7 +277,7 @@ static void reply_getatr_send(struct request_context *req) req_setup_reply(req, 10, 0); SSVAL(req->out.vwv, VWV(0), st->getattr.out.attrib); - put_dos_date3(req->out.vwv, VWV(1), st->getattr.out.write_time); + srv_push_dos_date3(req->smb, req->out.vwv, VWV(1), st->getattr.out.write_time); SIVAL(req->out.vwv, VWV(3), st->getattr.out.size); REQ_VWV_RESERVED(5, 5); @@ -348,7 +327,7 @@ void reply_setatr(struct request_context *req) st->setattr.level = RAW_SFILEINFO_SETATTR; st->setattr.in.attrib = SVAL(req->in.vwv, VWV(0)); - st->setattr.in.write_time = make_unix_date3(req->in.vwv + VWV(1)); + st->setattr.in.write_time = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(1)); req_pull_ascii4(req, &st->setattr.file.fname, req->in.data, STR_TERMINATE); @@ -425,7 +404,7 @@ static void reply_open_send(struct request_context *req) SSVAL(req->out.vwv, VWV(0), oi->open.out.fnum); SSVAL(req->out.vwv, VWV(1), oi->open.out.attrib); - put_dos_date3(req->out.vwv, VWV(2), oi->open.out.write_time); + srv_push_dos_date3(req->smb, req->out.vwv, VWV(2), oi->open.out.write_time); SIVAL(req->out.vwv, VWV(4), oi->open.out.size); SSVAL(req->out.vwv, VWV(6), oi->open.out.rmode); @@ -484,7 +463,7 @@ static void reply_open_and_X_send(struct request_context *req) SSVAL(req->out.vwv, VWV(1), 0); SSVAL(req->out.vwv, VWV(2), oi->openx.out.fnum); SSVAL(req->out.vwv, VWV(3), oi->openx.out.attrib); - put_dos_date3(req->out.vwv, VWV(4), oi->openx.out.write_time); + srv_push_dos_date3(req->smb, req->out.vwv, VWV(4), oi->openx.out.write_time); SIVAL(req->out.vwv, VWV(6), oi->openx.out.size); SSVAL(req->out.vwv, VWV(8), oi->openx.out.access); SSVAL(req->out.vwv, VWV(9), oi->openx.out.ftype); @@ -517,7 +496,7 @@ void reply_open_and_X(struct request_context *req) oi->openx.in.open_mode = SVAL(req->in.vwv, VWV(3)); oi->openx.in.search_attrs = SVAL(req->in.vwv, VWV(4)); oi->openx.in.file_attrs = SVAL(req->in.vwv, VWV(5)); - oi->openx.in.write_time = make_unix_date3(req->in.vwv + VWV(6)); + oi->openx.in.write_time = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(6)); oi->openx.in.open_func = SVAL(req->in.vwv, VWV(8)); oi->openx.in.size = IVAL(req->in.vwv, VWV(9)); oi->openx.in.timeout = IVAL(req->in.vwv, VWV(11)); @@ -570,7 +549,7 @@ void reply_mknew(struct request_context *req) oi->mknew.level = RAW_OPEN_MKNEW; oi->mknew.in.attrib = SVAL(req->in.vwv, VWV(0)); - oi->mknew.in.write_time = make_unix_date3(req->in.vwv + VWV(1)); + oi->mknew.in.write_time = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(1)); req_pull_ascii4(req, &oi->mknew.in.fname, req->in.data, STR_TERMINATE); @@ -621,7 +600,7 @@ void reply_ctemp(struct request_context *req) oi->ctemp.level = RAW_OPEN_CTEMP; oi->ctemp.in.attrib = SVAL(req->in.vwv, VWV(0)); - oi->ctemp.in.write_time = make_unix_date3(req->in.vwv + VWV(1)); + oi->ctemp.in.write_time = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(1)); /* the filename is actually a directory name, the server provides a filename in that directory */ @@ -1224,7 +1203,7 @@ void reply_close(struct request_context *req) io->close.level = RAW_CLOSE_CLOSE; io->close.in.fnum = req_fnum(req, req->in.vwv, VWV(0)); - io->close.in.write_time = make_unix_date3(req->in.vwv + VWV(1)); + io->close.in.write_time = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(1)); req->async.send_fn = reply_simple_send; @@ -1271,7 +1250,7 @@ void reply_writeclose(struct request_context *req) io->writeclose.in.fnum = req_fnum(req, req->in.vwv, VWV(0)); io->writeclose.in.count = SVAL(req->in.vwv, VWV(1)); io->writeclose.in.offset = IVAL(req->in.vwv, VWV(2)); - io->writeclose.in.mtime = make_unix_date3(req->in.vwv + VWV(4)); + io->writeclose.in.mtime = srv_pull_dos_date3(req->smb, req->in.vwv + VWV(4)); io->writeclose.in.data = req->in.data + 1; /* make sure they gave us the data they promised */ @@ -1486,7 +1465,7 @@ void reply_printqueue_send(struct request_context *req) req->out.ptr = req->out.data + 3; for (i=0;i<lpq->retq.out.count;i++) { - put_dos_date2(req->out.ptr, 0 , lpq->retq.out.queue[i].time); + srv_push_dos_date2(req->smb, req->out.ptr, 0 , lpq->retq.out.queue[i].time); SCVAL(req->out.ptr, 4, lpq->retq.out.queue[i].status); SSVAL(req->out.ptr, 5, lpq->retq.out.queue[i].job); SIVAL(req->out.ptr, 7, lpq->retq.out.queue[i].size); @@ -1851,9 +1830,9 @@ void reply_setattrE(struct request_context *req) info->setattre.level = RAW_SFILEINFO_SETATTRE; info->setattre.file.fnum = req_fnum(req, req->in.vwv, VWV(0)); - info->setattre.in.create_time = make_unix_date2(req->in.vwv + VWV(1)); - info->setattre.in.access_time = make_unix_date2(req->in.vwv + VWV(3)); - info->setattre.in.write_time = make_unix_date2(req->in.vwv + VWV(5)); + info->setattre.in.create_time = srv_pull_dos_date2(req->smb, req->in.vwv + VWV(1)); + info->setattre.in.access_time = srv_pull_dos_date2(req->smb, req->in.vwv + VWV(3)); + info->setattre.in.write_time = srv_pull_dos_date2(req->smb, req->in.vwv + VWV(5)); req->async.send_fn = reply_simple_send; @@ -1897,9 +1876,9 @@ static void reply_getattrE_send(struct request_context *req) /* setup reply */ req_setup_reply(req, 11, 0); - put_dos_date2(req->out.vwv, VWV(0), info->getattre.out.create_time); - put_dos_date2(req->out.vwv, VWV(2), info->getattre.out.access_time); - put_dos_date2(req->out.vwv, VWV(4), info->getattre.out.write_time); + srv_push_dos_date2(req->smb, req->out.vwv, VWV(0), info->getattre.out.create_time); + srv_push_dos_date2(req->smb, req->out.vwv, VWV(2), info->getattre.out.access_time); + srv_push_dos_date2(req->smb, req->out.vwv, VWV(4), info->getattre.out.write_time); SIVAL(req->out.vwv, VWV(6), info->getattre.out.size); SIVAL(req->out.vwv, VWV(8), info->getattre.out.alloc_size); SSVAL(req->out.vwv, VWV(10), info->getattre.out.attrib); diff --git a/source4/smb_server/search.c b/source4/smb_server/search.c index 9d01a0e98f..0a6aaa6c25 100644 --- a/source4/smb_server/search.c +++ b/source4/smb_server/search.c @@ -78,7 +78,7 @@ static void find_fill_info(struct request_context *req, p += req_append_bytes(req, file->search.search_id.data, 21); p += req_append_bytes(req, (char*)&file->search.attrib, 1); - put_dos_date((char*)&dos_date, 0, file->search.write_time); + srv_push_dos_date3(req->smb, (uint8 *)&dos_date, 0, file->search.write_time); p += req_append_bytes(req, (char*)&dos_date, 4); p += req_append_bytes(req, (char*)&file->search.size, 4); memset(&search_name[0], ' ', 13); diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index f798accc3f..84209d8670 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -749,6 +749,8 @@ void init_smbsession(struct event_context *ev, struct model_ops *model_ops, int good performance */ smb->negotiate.max_recv = lp_max_xmit(); + smb->negotiate.zone_offset = get_time_zone(time(NULL)); + smb->users.next_vuid = VUID_OFFSET; smb->events = ev; diff --git a/source4/smb_server/srvtime.c b/source4/smb_server/srvtime.c new file mode 100644 index 0000000000..c6a0606e89 --- /dev/null +++ b/source4/smb_server/srvtime.c @@ -0,0 +1,81 @@ +/* + Unix SMB/CIFS implementation. + + server side time handling + + Copyright (C) Andrew Tridgell 2004 + + 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" + +/******************************************************************* +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time for zone_offset in the buffer +********************************************************************/ +void srv_push_dos_date(struct server_context *smb_server, + uint8 *buf, int offset, time_t unixdate) +{ + push_dos_date(buf, offset, unixdate, smb_server->negotiate.zone_offset); +} + +/******************************************************************* +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void srv_push_dos_date2(struct server_context *smb_server, + char *buf, int offset, time_t unixdate) +{ + push_dos_date2(buf, offset, unixdate, smb_server->negotiate.zone_offset); +} + +/******************************************************************* +put a dos 32 bit "unix like" date into a buffer. This routine takes +GMT and converts it to LOCAL time in zone_offset before putting it +********************************************************************/ +void srv_push_dos_date3(struct server_context *smb_server, + char *buf, int offset, time_t unixdate) +{ + push_dos_date3(buf, offset, unixdate, smb_server->negotiate.zone_offset); +} + +/******************************************************************* +convert a dos date +********************************************************************/ +time_t srv_pull_dos_date(struct server_context *smb_server, + const uint8 *date_ptr) +{ + return pull_dos_date(date_ptr, smb_server->negotiate.zone_offset); +} + +/******************************************************************* +like srv_pull_dos_date() but the words are reversed +********************************************************************/ +time_t srv_pull_dos_date2(struct server_context *smb_server, + const uint8 *date_ptr) +{ + return pull_dos_date2(date_ptr, smb_server->negotiate.zone_offset); +} + +/******************************************************************* + create a unix GMT date from a dos date in 32 bit "unix like" format + these arrive in server zone, with corresponding DST + ******************************************************************/ +time_t srv_pull_dos_date3(struct server_context *smb_server, + const uint8 *date_ptr) +{ + return pull_dos_date3(date_ptr, smb_server->negotiate.zone_offset); +} diff --git a/source4/smb_server/trans2.c b/source4/smb_server/trans2.c index bc51191aa6..a412d9df3a 100644 --- a/source4/smb_server/trans2.c +++ b/source4/smb_server/trans2.c @@ -420,9 +420,9 @@ static NTSTATUS trans2_fileinfo_fill(struct request_context *req, struct smb_tra trans2_setup_reply(req, trans, 2, 22, 0); SSVAL(trans->out.params.data, 0, 0); - put_dos_date2(trans->out.data.data, 0, st->standard.out.create_time); - put_dos_date2(trans->out.data.data, 4, st->standard.out.access_time); - put_dos_date2(trans->out.data.data, 8, st->standard.out.write_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 0, st->standard.out.create_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 4, st->standard.out.access_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 8, st->standard.out.write_time); SIVAL(trans->out.data.data, 12, st->standard.out.size); SIVAL(trans->out.data.data, 16, st->standard.out.alloc_size); SSVAL(trans->out.data.data, 20, st->standard.out.attrib); @@ -432,9 +432,9 @@ static NTSTATUS trans2_fileinfo_fill(struct request_context *req, struct smb_tra trans2_setup_reply(req, trans, 2, 26, 0); SSVAL(trans->out.params.data, 0, 0); - put_dos_date2(trans->out.data.data, 0, st->ea_size.out.create_time); - put_dos_date2(trans->out.data.data, 4, st->ea_size.out.access_time); - put_dos_date2(trans->out.data.data, 8, st->ea_size.out.write_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 0, st->ea_size.out.create_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 4, st->ea_size.out.access_time); + srv_push_dos_date2(req->smb, trans->out.data.data, 8, st->ea_size.out.write_time); SIVAL(trans->out.data.data, 12, st->ea_size.out.size); SIVAL(trans->out.data.data, 16, st->ea_size.out.alloc_size); SSVAL(trans->out.data.data, 20, st->ea_size.out.attrib); @@ -705,9 +705,9 @@ static NTSTATUS trans2_parse_sfileinfo(struct request_context *req, case RAW_SFILEINFO_STANDARD: CHECK_MIN_BLOB_SIZE(blob, 12); - st->standard.in.create_time = make_unix_date2(blob->data + 0); - st->standard.in.access_time = make_unix_date2(blob->data + 4); - st->standard.in.write_time = make_unix_date2(blob->data + 8); + st->standard.in.create_time = pull_dos_date2(req->smb, blob->data + 0); + st->standard.in.access_time = pull_dos_date2(req->smb, blob->data + 4); + st->standard.in.write_time = pull_dos_date2(req->smb, blob->data + 8); return NT_STATUS_OK; case RAW_SFILEINFO_EA_SET: @@ -896,9 +896,9 @@ static void find_fill_info(struct request_context *req, trans2_grow_data(req, trans, ofs + 23); } data = trans->out.data.data + ofs; - put_dos_date2(data, 0, file->standard.create_time); - put_dos_date2(data, 4, file->standard.access_time); - put_dos_date2(data, 8, file->standard.write_time); + srv_push_dos_date2(req->smb, data, 0, file->standard.create_time); + srv_push_dos_date2(req->smb, data, 4, file->standard.access_time); + srv_push_dos_date2(req->smb, data, 8, file->standard.write_time); SIVAL(data, 12, file->standard.size); SIVAL(data, 16, file->standard.alloc_size); SSVAL(data, 20, file->standard.attrib); @@ -915,9 +915,9 @@ static void find_fill_info(struct request_context *req, trans2_grow_data(req, trans, ofs + 27); } data = trans->out.data.data + ofs; - put_dos_date2(data, 0, file->ea_size.create_time); - put_dos_date2(data, 4, file->ea_size.access_time); - put_dos_date2(data, 8, file->ea_size.write_time); + srv_push_dos_date2(req->smb, data, 0, file->ea_size.create_time); + srv_push_dos_date2(req->smb, data, 4, file->ea_size.access_time); + srv_push_dos_date2(req->smb, data, 8, file->ea_size.write_time); SIVAL(data, 12, file->ea_size.size); SIVAL(data, 16, file->ea_size.alloc_size); SSVAL(data, 20, file->ea_size.attrib); diff --git a/source4/smbd/process.c b/source4/smbd/process.c index 592a0efc99..183f0655da 100644 --- a/source4/smbd/process.c +++ b/source4/smbd/process.c @@ -88,9 +88,6 @@ void smbd_process_init(void) if (!dcesrv_init()) exit(1); - /* re-initialise the timezone */ - TimeInit(); - talloc_destroy(mem_ctx); } diff --git a/source4/torture/raw/close.c b/source4/torture/raw/close.c index 909c8f6c95..0180f43dd2 100644 --- a/source4/torture/raw/close.c +++ b/source4/torture/raw/close.c @@ -79,7 +79,7 @@ BOOL torture_raw_close(int dummy) if (basetime != nt_time_to_unix(&finfo.all_info.out.write_time)) { printf("Incorrect write time on file - %s - %s\n", - time_string(mem_ctx, basetime), + timestring(mem_ctx, basetime), nt_time_string(mem_ctx, &finfo.all_info.out.write_time)); dump_all_info(mem_ctx, &finfo); ret = False; diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c index d2055536a1..7c575fbe9a 100644 --- a/source4/torture/raw/open.c +++ b/source4/torture/raw/open.c @@ -88,8 +88,8 @@ static const char *rdwr_string(enum rdwr_mode m) if (ABS(t1-t2) > 2) { \ printf("(%d) wrong time for field %s %s - %s\n", \ __LINE__, #field, \ - time_string(mem_ctx, t1), \ - time_string(mem_ctx, t2)); \ + timestring(mem_ctx, t1), \ + timestring(mem_ctx, t2)); \ dump_all_info(mem_ctx, &finfo); \ ret = False; \ }} while (0) diff --git a/source4/torture/raw/qfileinfo.c b/source4/torture/raw/qfileinfo.c index 15e358673d..9c1c3a9e5c 100644 --- a/source4/torture/raw/qfileinfo.c +++ b/source4/torture/raw/qfileinfo.c @@ -336,14 +336,14 @@ BOOL torture_raw_qfileinfo(int dummy) s1 = fnum_find(sname); \ if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ - time_string(mem_ctx, s1->stype.out.tfield), \ + timestring(mem_ctx, s1->stype.out.tfield), \ nt_time_string(mem_ctx, &correct_time)); \ ret = False; \ } \ s1 = fname_find(sname); \ if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ - time_string(mem_ctx, s1->stype.out.tfield), \ + timestring(mem_ctx, s1->stype.out.tfield), \ nt_time_string(mem_ctx, &correct_time)); \ ret = False; \ }} while (0) @@ -352,14 +352,14 @@ BOOL torture_raw_qfileinfo(int dummy) s1 = fnum_find(sname); \ if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ - time_string(mem_ctx, s1->stype.out.tfield), \ + timestring(mem_ctx, s1->stype.out.tfield), \ nt_time_string(mem_ctx, &correct_time)); \ ret = False; \ } \ s1 = fname_find(sname); \ if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, &correct_time) != 0) { \ printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield, \ - time_string(mem_ctx, s1->stype.out.tfield), \ + timestring(mem_ctx, s1->stype.out.tfield), \ nt_time_string(mem_ctx, &correct_time)); \ ret = False; \ }} while (0) diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c index 9881a45cb1..1753d3dd37 100644 --- a/source4/torture/raw/search.c +++ b/source4/torture/raw/search.c @@ -198,7 +198,7 @@ static BOOL test_one_file(struct cli_state *cli, TALLOC_CTX *mem_ctx) if (s->sname1.field1 != (~1 & nt_time_to_unix(&v.sname2.out.field2))) { \ printf("(%d) %s/%s [%s] != %s/%s [%s]\n", \ __LINE__, \ - #sname1, #field1, time_string(mem_ctx, s->sname1.field1), \ + #sname1, #field1, timestring(mem_ctx, s->sname1.field1), \ #sname2, #field2, nt_time_string(mem_ctx, &v.sname2.out.field2)); \ ret = False; \ } \ diff --git a/source4/torture/raw/setfileinfo.c b/source4/torture/raw/setfileinfo.c index fa286ae4da..247e54a4b0 100644 --- a/source4/torture/raw/setfileinfo.c +++ b/source4/torture/raw/setfileinfo.c @@ -157,7 +157,7 @@ BOOL torture_raw_sfileinfo(int dummy) call_name, #stype, #field, \ (uint_t)value, \ (uint_t)nt_time_to_unix(&finfo2.stype.out.field)); \ - printf("\t%s", http_timestring(mem_ctx, value)); \ + printf("\t%s", timestring(mem_ctx, value)); \ printf("\t%s\n", nt_time_string(mem_ctx, &finfo2.stype.out.field)); \ dump_all_info(mem_ctx, &finfo1); \ }} while (0) diff --git a/source4/torture/torture_util.c b/source4/torture/torture_util.c index 57add86602..96579999c3 100644 --- a/source4/torture/torture_util.c +++ b/source4/torture/torture_util.c @@ -114,13 +114,14 @@ int create_complex_file(struct cli_state *cli, TALLOC_CTX *mem_ctx, const char * printf("Failed to setup EAs\n"); } - /* make sure all the timestamps aren't the same */ + /* make sure all the timestamps aren't the same, and are also + in different DST zones*/ setfile.generic.level = RAW_SFILEINFO_SETATTRE; setfile.generic.file.fnum = fnum; - setfile.setattre.in.create_time = t + 60; - setfile.setattre.in.access_time = t + 120; - setfile.setattre.in.write_time = t + 180; + setfile.setattre.in.create_time = t + 9*30*24*60*60; + setfile.setattre.in.access_time = t + 6*30*24*60*60; + setfile.setattre.in.write_time = t + 3*30*24*60*60; status = smb_raw_setfileinfo(cli->tree, &setfile); if (!NT_STATUS_IS_OK(status)) { @@ -212,14 +213,6 @@ BOOL wire_bad_flags(WIRE_STRING *str, int flags) } /* - return a talloced string representing a time_t for human consumption -*/ -const char *time_string(TALLOC_CTX *mem_ctx, time_t t) -{ - return talloc_strdup(mem_ctx, http_timestring(mem_ctx, t)); -} - -/* check if 2 NTTIMEs are equal */ BOOL nt_time_equal(NTTIME *t1, NTTIME *t2) diff --git a/source4/utils/ndrdump.c b/source4/utils/ndrdump.c index 7916ccec34..d02d993604 100644 --- a/source4/utils/ndrdump.c +++ b/source4/utils/ndrdump.c @@ -20,7 +20,7 @@ #include "includes.h" -static struct dcerpc_interface_table *find_pipe(const char *pipe_name) +static const struct dcerpc_interface_table *find_pipe(const char *pipe_name) { int i; for (i=0;dcerpc_pipes[i];i++) { diff --git a/source4/utils/net_ads.c b/source4/utils/net_ads.c index 6fb6394764..9febb694a9 100644 --- a/source4/utils/net_ads.c +++ b/source4/utils/net_ads.c @@ -107,7 +107,7 @@ static int net_ads_info(int argc, const char **argv) d_printf("Realm: %s\n", ads->config.realm); d_printf("Bind Path: %s\n", ads->config.bind_path); d_printf("LDAP port: %d\n", ads->ldap_port); - d_printf("Server time: %s\n", http_timestring(ads->config.current_time)); + d_printf("Server time: %s\n", timestring(ads->config.current_time)); return 0; } diff --git a/source4/utils/pdbedit.c b/source4/utils/pdbedit.c index 15e0b50fa9..8038900c28 100644 --- a/source4/utils/pdbedit.c +++ b/source4/utils/pdbedit.c @@ -119,22 +119,22 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst printf ("Munged dial: %s\n", pdb_get_munged_dial(sam_pwent)); tmp = pdb_get_logon_time(sam_pwent); - printf ("Logon time: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Logon time: %s\n", tmp ? timestring(tmp) : "0"); tmp = pdb_get_logoff_time(sam_pwent); - printf ("Logoff time: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Logoff time: %s\n", tmp ? timestring(tmp) : "0"); tmp = pdb_get_kickoff_time(sam_pwent); - printf ("Kickoff time: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Kickoff time: %s\n", tmp ? timestring(tmp) : "0"); tmp = pdb_get_pass_last_set_time(sam_pwent); - printf ("Password last set: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Password last set: %s\n", tmp ? timestring(tmp) : "0"); tmp = pdb_get_pass_can_change_time(sam_pwent); - printf ("Password can change: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Password can change: %s\n", tmp ? timestring(tmp) : "0"); tmp = pdb_get_pass_must_change_time(sam_pwent); - printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0"); + printf ("Password must change: %s\n", tmp ? timestring(tmp) : "0"); } else if (smbpwdstyle) { if (IS_SAM_UNIX_USER(sam_pwent)) { diff --git a/source4/utils/status.c b/source4/utils/status.c index c28b0a41fd..71a5f78db8 100644 --- a/source4/utils/status.c +++ b/source4/utils/status.c @@ -114,7 +114,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) d_printf("NONE "); d_printf(" %s %s",fname, - asctime(LocalTime((time_t *)&e->time.tv_sec))); + asctime(localtime((time_t *)&e->time.tv_sec))); } } @@ -511,7 +511,7 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st d_printf("%-10.10s %5d %-12s %s", crec.name,(int)crec.pid, crec.machine, - asctime(LocalTime(&crec.start))); + asctime(localtime(&crec.start))); return 0; } diff --git a/source4/web/statuspage.c b/source4/web/statuspage.c index 33bf63ae62..c83d0af021 100644 --- a/source4/web/statuspage.c +++ b/source4/web/statuspage.c @@ -96,7 +96,7 @@ static char *mapPid2Machine (pid_t pid) static char *tstring(time_t t) { static pstring buf; - pstrcpy(buf, asctime(LocalTime(&t))); + pstrcpy(buf, asctime(localtime(&t))); all_string_sub(buf," "," ",sizeof(buf)); return buf; } diff --git a/source4/web/swat.c b/source4/web/swat.c index 1e01910061..ec646f5848 100644 --- a/source4/web/swat.c +++ b/source4/web/swat.c @@ -381,7 +381,7 @@ static void write_config(FILE *f, BOOL show_defaults) { fprintf(f, "# Samba config file created using SWAT\n"); fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr()); - fprintf(f, "# Date: %s\n\n", timestring(False)); + fprintf(f, "# Date: %s\n\n", timestring(time(NULL))); lp_dump(f, show_defaults, iNumNonAutoPrintServices); } |