[eggheads-patches] PATCH1.5: filesys_remote_ln_1.5.patch

Fabian Knittel fknittel at gmx.de
Thu Oct 26 10:30:01 CST 2000


[ filesys_remote_ln_1.5.patch ]

This patch fixes a whole family of problems related to the `ln'
command in filesys.mod. During the rewrite of the module's
DB engine, I totally forgot about linked files and therefore
forgot to implement it in part. To be specific, the data headers
of each file element in the DB contains fields for the link data,
but they were never accessed and there was no code present that
included the link data in the internal calculations.

Anyway, as the actual header hasn't changed, the DB format hasn't
changed and I here-with simply declare the old code as broken for
remote links. :)  In other words: Don't downgrade to older
1.5.x filesys versions once you've started using remote links, as
you'll mess up your data in various aspects (partly because of
other bugs in the old code).

The attached patch should fix all the problems mentioned. And this
time I've even _tested_ the `ln' code. Now aint that great.

BTW: How come noone noticed yet? Doesn't seem to be a very actively
used feature, hehe.

Fabian

--
Fabian Knittel <fknittel at gmx.de> -- http://www.esc-web.de/fabian/
Signed or encrypted mail preferred.    PGP DSA key ID: 0x838B4D20
-------------- next part --------------
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/doc/UPDATES1.5 eggdrop1.5/doc/UPDATES1.5
--- eggdrop1.5~/doc/UPDATES1.5	Mon Oct 23 23:55:05 2000
+++ eggdrop1.5/doc/UPDATES1.5	Thu Oct 26 17:27:24 2000
@@ -4,6 +4,9 @@
 
 1.5.5
 Found by  Fixed by  What...
+fabulous  Fabian    The filesys module did not support remotely linked files.
+                    Instead, the bot crashed in various places and didn't even
+                    attempt to save/load the link information.
           Fabian    Minor cleanup of protocol in back-ground code.
           Fabian    Avoid data lossage during the start of connections, while
                     the receiving dcc functions aren't listening yet. So now
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/filesys.mod/dbcompat.c eggdrop1.5/src/mod/filesys.mod/dbcompat.c
--- eggdrop1.5~/src/mod/filesys.mod/dbcompat.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/filesys.mod/dbcompat.c	Thu Oct 26 17:23:32 2000
@@ -244,7 +244,7 @@
   Context;
   filedb_readtop(*fdb_s, &fdbt);
   /* Old DB version? */
-  if ((fdbt.version > 0) && (fdbt.version < FILEDB_VERSION3)) {
+  if (fdbt.version > 0 && fdbt.version < FILEDB_VERSION3) {
     char *tempdb;
 
     Context;
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/filesys.mod/filedb3.c eggdrop1.5/src/mod/filesys.mod/filedb3.c
--- eggdrop1.5~/src/mod/filesys.mod/filedb3.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/filesys.mod/filedb3.c	Thu Oct 26 17:31:38 2000
@@ -39,8 +39,6 @@
  *  | filename      |      |                     |
  *  |- - - - - - - -|      |                     |
  *  | description   |      |                     |
- *  |- - - - - - - -|      |                     |
- *  | share link    |      |                     |
  *  |- - - - - - - -|      |  Dynamic length     |  Complete entry
  *  | channel name  |      |                     |
  *  |- - - - - - - -|      |                     |
@@ -48,6 +46,8 @@
  *  |- - - - - - - -|      |                     |
  *  | flags_req     |      |                     |
  *  |- - - - - - - -|      |                     |
+ *  | share link    |      |                     |
+ *  |- - - - - - - -|      |                     |
  *  | buffer        |     _|                    _|
  *  |---------------|
  *  | ...           |
@@ -310,6 +310,8 @@
     fdh.uploader_len = strlen(fdbe->uploader) + 1;
   if (fdbe->flags_req)
     fdh.flags_req_len = strlen(fdbe->flags_req) + 1;
+  if (fdbe->sharelink)
+    fdh.sharelink_len = strlen(fdbe->sharelink) + 1;
 
   odyntot = fdbe->dyn_len;		/* Old length of dynamic data	*/
   obuftot = fdbe->buf_len;		/* Old length of spare space	*/
@@ -393,6 +395,8 @@
       fwrite(fdbe->uploader, 1, fdh.uploader_len, fdb);
     if (fdbe->flags_req)
       fwrite(fdbe->flags_req, 1, fdh.flags_req_len, fdb);
+    if (fdbe->sharelink)
+      fwrite(fdbe->sharelink, 1, fdh.sharelink_len, fdb);
   } else
     fseek(fdb, ndyntot, SEEK_CUR);	/* Skip over dynamic data */
   fseek(fdb, nbuftot, SEEK_CUR);	/* Skip over buffer	  */
@@ -464,19 +468,27 @@
   fdbe->pos = pos;			/* Save position		*/
   fdbe->_type = TYPE_EXIST;		/* Entry exists in DB		*/
 
+  /* This is useful for cases where we don't read the rest of the
+   * data, but need to know whether the file is a link.
+   */
+  if (fdh.sharelink_len > 0)
+    fdbe->stat |= FILE_ISLINK;
+  else
+    fdbe->stat &= ~FILE_ISLINK;
+
   /* Read additional data from db */
   if (get >= GET_FILENAME) {
     filedb_read(fdb, fdbe->filename, fdh.filename_len);
   } else
     fseek(fdb, fdh.filename_len, SEEK_CUR);
-  if ((get < GET_FULL) || (fdh.stat & FILE_UNUSED))
-    fseek(fdb, fdh.desc_len + fdh.chan_len + fdh.uploader_len
-	  + fdh.flags_req_len, SEEK_CUR);
+  if (get < GET_FULL || (fdh.stat & FILE_UNUSED))
+    fseek(fdb, filedb_tot_dynspace(fdh) - fdh.filename_len, SEEK_CUR);
   else if (get == GET_FULL) {
     filedb_read(fdb, fdbe->desc, fdh.desc_len);
     filedb_read(fdb, fdbe->chan, fdh.chan_len);
     filedb_read(fdb, fdbe->uploader, fdh.uploader_len);
     filedb_read(fdb, fdbe->flags_req, fdh.flags_req_len);
+    filedb_read(fdb, fdbe->sharelink, fdh.sharelink_len);
   }
   fseek(fdb, fdh.buffer_len, SEEK_CUR);	/* Skip buffer			*/
   Context;
@@ -633,7 +645,7 @@
 {
   filedb_top fdbt;
 
-  fdbt.version = FILEDB_VERSION3;
+  fdbt.version = FILEDB_NEWEST_VER;
   fdbt.timestamp = now;
   filedb_writetop(fdb, &fdbt);
 }
@@ -712,8 +724,9 @@
   fdbe = filedb_getfile(fdb, ftell(fdb), GET_FILENAME);
   while (fdbe) {
     where = ftell(fdb);
-    if (!(fdbe->stat & FILE_UNUSED) && !(fdbe->sharelink) && fdbe->filename) {
-      s = nmalloc(strlen(path) + strlen(fdbe->filename) + 2);
+    if (!(fdbe->stat & FILE_UNUSED) && !(fdbe->stat & FILE_ISLINK) &&
+	fdbe->filename) {
+      s = nmalloc(strlen(path) + 1 + strlen(fdbe->filename) + 1);
       sprintf(s, "%s/%s", path, fdbe->filename);
       if (stat(s, &st) != 0)
 	/* gone file */
@@ -810,7 +823,7 @@
 	return NULL;
       }
       lockfile(fdb);
-      fdbt.version = FILEDB_VERSION3;
+      fdbt.version = FILEDB_NEWEST_VER;
       fdbt.timestamp = now;
       filedb_writetop(fdb, &fdbt);
       filedb_update(npath, fdb, sort);
@@ -824,7 +837,7 @@
   
   lockfile(fdb);			/* Lock it from other bots */
   filedb_readtop(fdb, &fdbt);
-  if (fdbt.version < FILEDB_VERSION3) {
+  if (fdbt.version < FILEDB_NEWEST_VER) {
     if (!convert_old_db(&fdb, s)) {
       /* Conversion failed. Unlock file again and error out.
        * (convert_old_db() could have modified fdb, so check
@@ -1084,7 +1097,6 @@
     if (!fdbe) {
       reject = FILES_FILEDNE;
     } else {
-      free_fdbe(&fdbe);
       if ((!(fdbe->stat & FILE_SHARE)) ||
 	  (fdbe->stat & (FILE_HIDDEN | FILE_DIR)))
 	reject = FILES_NOSHARE;
@@ -1107,6 +1119,7 @@
 	  my_free(s);
 	my_free(s1);
       }
+      free_fdbe(&fdbe);
     }
   }
   s1 = nmalloc(strlen(botnetnick) + strlen(dir) + strlen(what) + 3);
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/filesys.mod/filedb3.h eggdrop1.5/src/mod/filesys.mod/filedb3.h
--- eggdrop1.5~/src/mod/filesys.mod/filedb3.h	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/filesys.mod/filedb3.h	Thu Oct 26 17:21:05 2000
@@ -61,7 +61,8 @@
   unsigned short int _type;		/* Type of entry (private)	*/
 
   /* NOTE: These three are only valid during one db open/close. Entry
-   *       movements often invalidate them too.
+   *       movements often invalidate them too, so make sure you know
+   *       what you're doing before using/relying on them.
    */
   long pos;				/* Last position in the filedb	*/
   unsigned short int dyn_len;		/* Length of dynamic data in DB	*/
@@ -69,7 +70,8 @@
 
   char *filename;			/* Filename			*/
   char *desc;				/* Description			*/
-  char *sharelink;			/* Share link			*/
+  char *sharelink;			/* Share link. Points to remote
+		 			   file on linked bot.		*/
   char *chan;				/* Channel name			*/
   char *uploader;			/* Uploader			*/
   char *flags_req;			/* Required flags		*/
@@ -99,15 +101,18 @@
     my_free(target);							\
 } while (0)
 
+/* Macro to calculate the total length of dynamic data. */
 #define filedb_tot_dynspace(fdh) ((fdh).filename_len + (fdh).desc_len +	\
-	(fdh).chan_len + (fdh).uploader_len + (fdh).flags_req_len)
+	(fdh).chan_len + (fdh).uploader_len + (fdh).flags_req_len + \
+	(fdh).sharelink_len)
 
 #define filedb_zero_dynspace(fdh) {					\
-	(fdh).filename_len  = 0;					\
-	(fdh).desc_len	    = 0;					\
-	(fdh).chan_len	    = 0;					\
-	(fdh).uploader_len  = 0;					\
-	(fdh).flags_req_len = 0;					\
+	(fdh).filename_len	= 0;					\
+	(fdh).desc_len		= 0;					\
+	(fdh).chan_len		= 0;					\
+	(fdh).uploader_len	= 0;					\
+	(fdh).flags_req_len	= 0;					\
+	(fdh).sharelink_len	= 0;					\
 }
 
 /* Memory debugging makros */
@@ -124,16 +129,18 @@
  */
 
 #define FILEDB_VERSION1	0x0001
-#define FILEDB_VERSION2	0x0002
-#define FILEDB_VERSION3	0x0003	/* Newest DB version			*/
+#define FILEDB_VERSION2	0x0002	/* DB version used for 1.3, 1.4		*/
+#define FILEDB_VERSION3	0x0003
+#define FILEDB_NEWEST_VER FILEDB_VERSION3	/* Newest DB version	*/
 
 #define POS_NEW		0	/* Position which indicates that the
-				 * entry wants to be repositioned.	*/
+				   entry wants to be repositioned.	*/
 
-#define FILE_UNUSED	0x0001	/* Deleted entry */
-#define FILE_DIR	0x0002	/* It's actually a directory */
-#define FILE_SHARE	0x0004	/* Can be shared on the botnet */
-#define FILE_HIDDEN	0x0008	/* Hidden file */
+#define FILE_UNUSED	0x0001	/* Deleted entry.			*/
+#define FILE_DIR	0x0002	/* It's actually a directory.		*/
+#define FILE_SHARE	0x0004	/* Can be shared on the botnet.		*/
+#define FILE_HIDDEN	0x0008	/* Hidden file.				*/
+#define FILE_ISLINK	0x0010	/* The file is a link to another bot.	*/
 
 #define FILEDB_ESTDYN	50	/* Estimated dynamic length of an entry	*/
 
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/filesys.mod/files.c eggdrop1.5/src/mod/filesys.mod/files.c
--- eggdrop1.5~/src/mod/filesys.mod/files.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/filesys.mod/files.c	Wed Oct 25 15:56:00 2000
@@ -436,7 +436,8 @@
       nicklen = (int) me->funcs[SERVER_NICKLEN];
   }
   if (!par[0]) {
-    dprintf(idx, "%s: %sget <file(s)> [nickname]\n", MISC_USAGE, resend ? "re" : "");
+    dprintf(idx, "%s: %sget <file(s)> [nickname]\n", MISC_USAGE,
+	    resend ? "re" : "");
     return;
   }
   what = newsplit(&par);
@@ -723,7 +724,7 @@
  */
 static void cmd_ln(int idx, char *par)
 {
-  char *share, *newpath, *newfn = NULL, *p;
+  char *share, *newpath = NULL, *newfn = NULL, *p;
   FILE *fdb;
   filedb_entry *fdbe;
 




More information about the Patches mailing list