* Better tempfilename generation for receive_spool()
authorArt Cancro <ajc@citadel.org>
Fri, 21 May 2010 16:32:48 +0000 (16:32 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 21 May 2010 16:32:48 +0000 (16:32 +0000)
citadel/modules/network/serv_network.c

index c8269f05a00128ef900e24e787079947f0251264..8b0df4ec175b0e24ba055233409e437a1a290ff0 100644 (file)
@@ -1843,17 +1843,28 @@ void receive_spool(int *sock, char *remote_nodename) {
        char buf[SIZ];
        static char pbuf[IGNET_PACKET_SIZE];
        char tempfilename[PATH_MAX];
-       char filename[PATH_MAX];
+       char permfilename[PATH_MAX];
        long plen;
        FILE *fp;
 
        snprintf(tempfilename, 
-                sizeof tempfilename, 
-                "%s/%s.%ld",
-                ctdl_nettmp_dir,
-                remote_nodename, 
-                (long) getpid()
+               sizeof tempfilename, 
+               "%s/%s.%lx%x",
+               ctdl_nettmp_dir,
+               remote_nodename, 
+               time(NULL),
+               rand()
+       );
+
+       snprintf(permfilename, 
+               sizeof permfilename, 
+               "%s/%s.%lx%x",
+               ctdl_netin_dir,
+               remote_nodename, 
+               time(NULL),
+               rand()
        );
+
        if (sock_puts(sock, "NDOP") < 0) return;
        if (sock_getln(sock, buf, sizeof buf) < 0) return;
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
@@ -1935,17 +1946,9 @@ void receive_spool(int *sock, char *remote_nodename) {
        
        /* Now move the temp file to its permanent location.
         */
-       snprintf(filename, 
-                sizeof filename, 
-                "%s/%s.%ld",
-                ctdl_netin_dir,
-                remote_nodename, 
-                (long) getpid()
-       );
-
-       if (link(tempfilename, filename) != 0) {
+       if (link(tempfilename, permfilename) != 0) {
                CtdlLogPrintf(CTDL_ALERT, "Could not link %s to %s: %s\n",
-                       tempfilename, filename, strerror(errno)
+                       tempfilename, permfilename, strerror(errno)
                );
        }
        unlink(tempfilename);