]> git.pond.sub.org Git - empserver/commitdiff
Fix files utility not to set timestamps
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 May 2008 17:35:22 +0000 (19:35 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 17 May 2008 17:35:22 +0000 (19:35 +0200)
Commit f33b96b1 (v4.3.12) made files again set timestamps.  That was
intentionally suppressed in commit 990eb46b (v4.3.10), because it
facilitates attacks against the PRNG.  Commit 8f98e53a (v4.3.0) had
added it as a feature.

Fix by making files's main() pass new flag EFF_NOTIME to ef_open().
Implement the flag in do_write().

include/file.h
src/lib/common/file.c
src/util/files.c

index b14d0bc6bc1a0e7bd9a29da3c8e0f1e97e1f543a..c086fe22dd6b630a7ee03decbe3d19da606d95e9 100644 (file)
@@ -98,9 +98,11 @@ struct emptypedstr {
 #define EFF_PRIVATE    bit(9)
 /* Table is customized (configuration tables only) */
 #define EFF_CUSTOM     bit(10)
+/* Don't update timestamps */
+#define EFF_NOTIME     bit(11)
 /* Transient flags, only occur in argument of ef_open() */
 /* Create table file, clobbering any existing file */
-#define EFF_CREATE     bit(11)
+#define EFF_CREATE     bit(16)
 
 /*
  * Empire `file types'
index b1ebfb13d873d592dbd8db46d6263ed91965049d..d20f7e02fde5c8a1e1342c49703be898b1acba96 100644 (file)
@@ -369,7 +369,7 @@ do_write(struct empfile *ep, void *buf, int id, int count)
        return -1;
 
     if (ep->flags & EFF_TYPED) {
-       now = time(NULL);
+       now = ep->flags & EFF_NOTIME ? (time_t)-1 : time(NULL);
        for (i = 0; i < count; i++) {
            /*
             * TODO Oopses here could be due to bad data corruption.
@@ -380,7 +380,8 @@ do_write(struct empfile *ep, void *buf, int id, int count)
                elt->ef_type = ep->uid;
            if (CANT_HAPPEN(elt->uid != id + i))
                elt->uid = id + i;
-           elt->timestamp = now;
+           if (now != (time_t)-1)
+               elt->timestamp = now;
        }
     }
 
index 4151e20d3cff0f7a9faddf24f4e9c58aae0cf9ca..5ef6161820df90e178801b976da9a70f9fc19237 100644 (file)
@@ -131,7 +131,7 @@ main(int argc, char *argv[])
     for (i = 0; i < EF_MAX; i++) {
        if (!EF_IS_GAME_STATE(i))
            continue;
-       if (!ef_open(i, EFF_CREATE, -1)) {
+       if (!ef_open(i, EFF_CREATE | EFF_NOTIME, -1)) {
            perror("ef_open");
            exit(1);
        }