r23005: If we're running on a system where time_t is 8 bytes
authorJeremy Allison <jra@samba.org>
Fri, 18 May 2007 23:38:56 +0000 (23:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:22:13 +0000 (12:22 -0500)
we have to take care to preserve the "special" values
for Windows of 0x80000000 and 0x7FFFFFFF when casting
between time_t and uint32. Add conversion functions
(and use them).
Jeremy.
(This used to be commit 4e1a0b2549f7c11326deed2801de19564af0f16a)

source3/configure.in
source3/lib/time.c
source3/passdb/passdb.c
source3/utils/pdbedit.c

index c940c8c3d9e8aa081700fba310178564e4325dcd..31907c54e12c2a08b313ba8d9765698523832ec1 100644 (file)
@@ -2079,6 +2079,14 @@ if test x"$samba_cv_compiler_supports_ll" = x"yes"; then
 fi
 
 
+AC_CACHE_CHECK([for 64 bit time_t],samba_cv_SIZEOF_TIME_T,[
+AC_TRY_RUN([#include <time.h>
+main() { exit((sizeof(time_t) == 8) ? 0 : 1); }],
+samba_cv_SIZEOF_TIME_T=yes,samba_cv_SIZEOF_TIME_T=no,samba_cv_SIZEOF_TIME_T=cross)])
+if test x"$samba_cv_SIZEOF_TIME_T" = x"yes"; then
+    AC_DEFINE(SIZEOF_TIME_T,8,[The size of the 'time_t' type])
+fi
+
 AC_CACHE_CHECK([for 64 bit off_t],samba_cv_SIZEOF_OFF_T,[
 AC_TRY_RUN([#include <stdio.h>
 #include <sys/stat.h>
index e98f8232abc58fa2beb3c552f40ccf21843cb7cb..ba158fe1ae9773ec7841f3299b475457ff041890 100644 (file)
@@ -554,6 +554,37 @@ NTTIME timeval_to_nttime(const struct timeval *tv)
                  ((TIME_FIXUP_CONSTANT_INT + (uint64_t)tv->tv_sec) * 1000000));
 }
 
+/**************************************************************
+ Handle conversions between time_t and uint32, taking care to
+ preserve the "special" values.
+**************************************************************/
+
+uint32 convert_time_t_to_uint32(time_t t)
+{
+#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
+       /* time_t is 64-bit. */
+       if (t == 0x8000000000000000LL) {
+               return 0x80000000;
+       } else if (t == 0x7FFFFFFFFFFFFFFFLL) {
+               return 0x7FFFFFFF;
+       }
+#endif
+       return (uint32)t;
+}
+
+time_t convert_uint32_to_time_t(uint32 u)
+{
+#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8))
+       /* time_t is 64-bit. */
+       if (u == 0x80000000) {
+               return (time_t)0x8000000000000000LL;
+       } else if (u == 0x7FFFFFFF) {
+               return (time_t)0x7FFFFFFFFFFFFFFFLL) {
+       }
+#endif
+       return (time_t)u;
+}
+
 /*******************************************************************
  Yield the difference between *A and *B, in seconds, ignoring leap seconds.
 ********************************************************************/
index 0ad5e21c780cb0701b898f4bcf37db464cebae8b..aebcbaaacfc6b62f8d06a0fe7b9c03d2f89691c1 100644 (file)
@@ -930,13 +930,13 @@ BOOL init_sam_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
                goto done;
        }
 
-       pdb_set_logon_time(sampass, logon_time, PDB_SET);
-       pdb_set_logoff_time(sampass, logoff_time, PDB_SET);
-       pdb_set_kickoff_time(sampass, kickoff_time, PDB_SET);
-       pdb_set_bad_password_time(sampass, bad_password_time, PDB_SET);
-       pdb_set_pass_can_change_time(sampass, pass_can_change_time, PDB_SET);
-       pdb_set_pass_must_change_time(sampass, pass_must_change_time, PDB_SET);
-       pdb_set_pass_last_set_time(sampass, pass_last_set_time, PDB_SET);
+       pdb_set_logon_time(sampass, convert_uint32_to_time_t(logon_time), PDB_SET);
+       pdb_set_logoff_time(sampass, convert_uint32_to_time_t(logoff_time), PDB_SET);
+       pdb_set_kickoff_time(sampass, convert_uint32_to_time_t(kickoff_time), PDB_SET);
+       pdb_set_bad_password_time(sampass, convert_uint32_to_time_t(bad_password_time), PDB_SET);
+       pdb_set_pass_can_change_time(sampass, convert_uint32_to_time_t(pass_can_change_time), PDB_SET);
+       pdb_set_pass_must_change_time(sampass, convert_uint32_to_time_t(pass_must_change_time), PDB_SET);
+       pdb_set_pass_last_set_time(sampass, convert_uint32_to_time_t(pass_last_set_time), PDB_SET);
 
        pdb_set_username(sampass, username, PDB_SET); 
        pdb_set_domain(sampass, domain, PDB_SET);
@@ -1118,13 +1118,13 @@ uint32 init_buffer_from_sam_v3 (uint8 **buf, struct samu *sampass, BOOL size_onl
        *buf = NULL;
        buflen = 0;
 
-       logon_time = (uint32)pdb_get_logon_time(sampass);
-       logoff_time = (uint32)pdb_get_logoff_time(sampass);
-       kickoff_time = (uint32)pdb_get_kickoff_time(sampass);
-       bad_password_time = (uint32)pdb_get_bad_password_time(sampass);
-       pass_can_change_time = (uint32)pdb_get_pass_can_change_time_noncalc(sampass);
-       pass_must_change_time = (uint32)pdb_get_pass_must_change_time(sampass);
-       pass_last_set_time = (uint32)pdb_get_pass_last_set_time(sampass);
+       logon_time = convert_time_t_to_uint32(pdb_get_logon_time(sampass));
+       logoff_time = convert_time_t_to_uint32(pdb_get_logoff_time(sampass));
+       kickoff_time = convert_time_t_to_uint32(pdb_get_kickoff_time(sampass));
+       bad_password_time = convert_time_t_to_uint32(pdb_get_bad_password_time(sampass));
+       pass_can_change_time = convert_time_t_to_uint32(pdb_get_pass_can_change_time_noncalc(sampass));
+       pass_must_change_time = convert_time_t_to_uint32(pdb_get_pass_must_change_time(sampass));
+       pass_last_set_time = convert_time_t_to_uint32(pdb_get_pass_last_set_time(sampass));
 
        user_rid = pdb_get_user_rid(sampass);
        group_rid = pdb_get_group_rid(sampass);
@@ -1408,7 +1408,7 @@ BOOL pdb_update_bad_password_count(struct samu *sampass, BOOL *updated)
        LastBadPassword = pdb_get_bad_password_time(sampass);
        DEBUG(7, ("LastBadPassword=%d, resettime=%d, current time=%d.\n", 
                   (uint32) LastBadPassword, resettime, (uint32)time(NULL)));
-       if (time(NULL) > (LastBadPassword + (time_t)resettime*60)){
+       if (time(NULL) > (LastBadPassword + convert_uint32_to_time_t(resettime)*60)){
                pdb_set_bad_password_count(sampass, 0, PDB_CHANGED);
                pdb_set_bad_password_time(sampass, 0, PDB_CHANGED);
                if (updated) {
@@ -1462,7 +1462,7 @@ BOOL pdb_update_autolock_flag(struct samu *sampass, BOOL *updated)
                return True;
        }
 
-       if ((time(NULL) > (LastBadPassword + (time_t) duration * 60))) {
+       if ((time(NULL) > (LastBadPassword + convert_uint32_to_time_t(duration) * 60))) {
                pdb_set_acct_ctrl(sampass,
                                  pdb_get_acct_ctrl(sampass) & ~ACB_AUTOLOCK,
                                  PDB_CHANGED);
index 722c650b852a2e7f4e7e664d476e7264a7c3c695..a598828d927602c6a2048a6e455eaf525d2f01c8 100644 (file)
@@ -285,14 +285,14 @@ static int print_sam_info (struct samu *sam_pwent, BOOL verbosity, BOOL smbpwdst
                       lm_passwd,
                       nt_passwd,
                       pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
-                      (uint32)pdb_get_pass_last_set_time(sam_pwent));
+                      (uint32)convert_time_t_to_uint32(pdb_get_pass_last_set_time(sam_pwent)));
        } else {
                uid = nametouid(pdb_get_username(sam_pwent));
                printf ("%s:%lu:%s\n", pdb_get_username(sam_pwent), (unsigned long)uid, 
                        pdb_get_fullname(sam_pwent));
        }
 
-       return 0;       
+       return 0;
 }
 
 /*********************************************************