Przeglądaj źródła

* Ported [2727] to 1.2.10 (tempdir, update fixes)

svn: 2728
Bryan Drewery 20 lat temu
rodzic
commit
7f88901fa4

+ 4 - 2
src/binary.c

@@ -29,8 +29,8 @@ settings_t settings = {
   ""
 };
 
-#define PACK_ENC 1
-#define PACK_DEC 2
+int settings_crypt = PACK_ENC;
+
 static void edpack(settings_t *, const char *, int);
 
 int checked_bin_buf = 0;
@@ -297,6 +297,8 @@ static void edpack(settings_t *incfg, const char *in_hash, int what)
   unsigned char *(*enc_dec_string)(const char *, unsigned char *, size_t *);
   size_t len = 0;
 
+  settings_crypt = what;
+
   if (what == PACK_ENC)
     enc_dec_string = encrypt_binary;
   else

+ 5 - 1
src/binary.h

@@ -3,7 +3,11 @@
 
 #include "conf.h"
 
-extern int checked_bin_buf;
+extern int checked_bin_buf, settings_crypt;
+
+#define PACK_ENC 1
+#define PACK_DEC 2
+
 
 #  define GET_CHECKSUM		BIT0
 #  define WRITE_CHECKSUM 	BIT1

+ 0 - 1
src/dcc.h

@@ -108,7 +108,6 @@ struct xfer_info {
   char *origname;
   unsigned char sofar;          /* how much of the byte count received     */
   unsigned short ack_type;      /* type of ack                             */
-  char dir[DIRLEN];             /* used when uploads go to the current dir */
   char from[NICKLEN];           /* [GET] user who offered the file         */
   char buf[4];                  /* you only need 5 bytes!                  */
 };

+ 2 - 0
src/main.c

@@ -711,6 +711,8 @@ printf("out: %s\n", out);
   if (!checked_bin_buf)
     exit(1);
 
+  /* The tempdir might use the packname, let's attempt anyway.. */
+  Tempfile::FindDir();
 
 #ifdef STOP_UAC
   {

+ 22 - 10
src/misc_file.c

@@ -14,6 +14,7 @@
 #include "misc_file.h"
 #include "main.h"
 #include "shell.h"
+#include "binary.h"
 
 /* Copy a file from one place to another (possibly erasing old copy).
  *
@@ -210,14 +211,10 @@ Tempfile::~Tempfile()
 
 static bool check_tempdir(bool do_mod)
 {
-  if (!can_stat(tempdir)) {
-    if (mkdir(tempdir,  S_IRUSR | S_IWUSR | S_IXUSR)) {
-      unlink(tempdir);
-      if (!can_stat(tempdir))
-        if (mkdir(tempdir, S_IRUSR | S_IWUSR | S_IXUSR))
-          return 0;
-    }
-  }
+  mkdir_p(tempdir);
+
+  if (!can_stat(tempdir))
+    return 0;
 
   if (do_mod && fixmod(tempdir))
     return 0;
@@ -249,8 +246,13 @@ void Tempfile::FindDir()
 #else
 
   /* If this is a hub, use, "./tmp/" */
-  if (conf.bots && conf.bots->nick && conf.bots->hub)
+  if (conf.bots && conf.bots->nick && conf.bots->hub) {
     simple_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
+    if (check_tempdir(0))
+      return;
+  }
+  
+/* WHY
   else if (conf.homedir && conf.homedir[0]) {
     //need to create ~/.ssh/  
     simple_snprintf(tempdir, DIRMAX, "%s/.ssh/", conf.homedir);
@@ -259,6 +261,7 @@ void Tempfile::FindDir()
     clear_tmpdir = 1;
     simple_snprintf(tempdir, DIRMAX, "%s/.ssh/.../", conf.homedir);
   }
+*/
 
   /* The dirs we WANT to use aren't accessible, try a random one instead to get the job done. */
 
@@ -273,9 +276,18 @@ void Tempfile::FindDir()
   };
   int i = 0;
   bool found = 0;
+  char *pack_hash = NULL;
+
+  if (settings_crypt == PACK_DEC) {
+    pack_hash = MD5(settings.packname);
+    pack_hash[5] = 0;
+  }
 
   for (i = 0; dirs[i]; i++) {
-    simple_snprintf(tempdir, DIRMAX, dirs[i]);
+    if (pack_hash)
+      simple_snprintf(tempdir, DIRMAX, "%s.%s/", dirs[i], pack_hash);
+    else
+      strlcpy(tempdir, dirs[i], DIRMAX);
     if (check_tempdir(0)) {
       found = 1;
       break;

+ 2 - 1
src/mod/share.mod/share.c

@@ -1353,7 +1353,8 @@ start_sending_users(int idx)
   }
 */
 
-  if ((i = raw_dcc_send(share_file, "*users", "(users)", share_file, &j)) > 0) {
+  if ((i = raw_dcc_send(share_file, "*users", "(users)", &j)) > 0) {
+    /* FIXME: the bot should be unlinked at this point */
     unlink(share_file);
     dprintf(idx, "s e %s\n", "Can't send userfile to you (internal error)");
     putlog(LOG_BOTS, "*", "%s -- can't send userfile",

+ 9 - 33
src/mod/transfer.mod/transfer.c

@@ -47,19 +47,6 @@ static void dcc_get_pending(int, char *, int);
 /*
  *   Misc functions
  */
-/* Replaces all spaces with underscores (' ' -> '_').  The returned buffer
- * needs to be freed after use.
- */
-static char *replace_spaces(char *fn)
-{
-  register char *ret = NULL, *p = NULL;
-
-  p = ret = strdup(fn);
-  while ((p = strchr(p, ' ')) != NULL)
-    *p = '_';
-  return ret;
-}
-
 
 /*
  *    DCC routines
@@ -779,12 +766,12 @@ static void dcc_get_pending(int idx, char *buf, int len)
  * Use raw_dcc_resend() and raw_dcc_send() instead of this function.
  */
 
-static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir, int resend, int *idx)
+static int raw_dcc_resend_send(char *filename, char *nick, char *from, int resend, int *idx)
 {
   int zz = -1;
   int i;
   port_t port;
-  char *nfn = NULL, *buf = NULL;
+  char *buf = NULL;
   long dccfilesize;
   FILE *f = NULL, *dccfile = NULL;
  
@@ -820,11 +807,7 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir
 
   if (zz == (-1))
     return DCCSEND_NOSOCK;
-  nfn = strrchr(dir, '/');
-  if (nfn == NULL)
-    nfn = dir;
-  else
-    nfn++;
+  
   f = fopen(filename, "rb");
   if (!f)
     return DCCSEND_BADFN;
@@ -837,22 +820,15 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir
   strcpy(dcc[i].host, "irc");
   dcc[i].u.xfer->filename = (char *) my_calloc(1, strlen(filename) + 1);
   strcpy(dcc[i].u.xfer->filename, filename);
-  if (strchr(nfn, ' '))
-    nfn = buf = replace_spaces(nfn);
-  dcc[i].u.xfer->origname = (char *) my_calloc(1, strlen(nfn) + 1);
-  strcpy(dcc[i].u.xfer->origname, nfn);
+
+  dcc[i].u.xfer->origname = (char *) my_calloc(1, strlen(filename) + 1);
+  strcpy(dcc[i].u.xfer->origname, filename);
   strlcpy(dcc[i].u.xfer->from, from, NICKLEN);
-  strlcpy(dcc[i].u.xfer->dir, dir, DIRLEN);
   dcc[i].u.xfer->length = dccfilesize;
   dcc[i].timeval = now;
   dcc[i].u.xfer->f = f;
   dcc[i].u.xfer->type = resend ? XFER_RESEND_PEND : XFER_SEND;
-  if (nick[0] != '*') {
-    dprintf(DP_HELP, "PRIVMSG %s :\001DCC %sSEND %s %lu %d %lu\001\n", nick,
-	    resend ? "RE" :  "", nfn, iptolong(getmyip()), port, dccfilesize);
-    putlog(LOG_FILES, "*",TRANSFER_BEGIN_DCC, resend ? TRANSFER_RE :  "",
-	   nfn, nick);
-  }
+
   if (buf)
     free(buf);
 
@@ -872,9 +848,9 @@ static int raw_dcc_resend(char *filename, char *nick, char *from, char *dir)
 
 /* Starts a DCC_SEND connection.
  */
-int raw_dcc_send(char *filename, char *nick, char *from, char *dir, int *idx)
+int raw_dcc_send(char *filename, char *nick, char *from, int *idx)
 {
-  return raw_dcc_resend_send(filename, nick, from, dir, 0, idx);
+  return raw_dcc_resend_send(filename, nick, from, 0, idx);
 }
 
 /*

+ 1 - 1
src/mod/transfer.mod/transfer.h

@@ -30,7 +30,7 @@ enum {
         XFER_ACK_WITHOUT_OFFSET /* Skipped data is NOT counted in ack.  */
 };
 
-int raw_dcc_send(char *, char *, char *, char *, int *);
+int raw_dcc_send(char *, char *, char *, int *);
 
 #ifdef MAKING_TRANSFER
 #define TRANSFER_REGET_PACKETID 0xfeab

+ 8 - 3
src/mod/update.mod/update.c

@@ -258,7 +258,7 @@ void finish_update(int idx)
 static void start_sending_binary(int idx)
 {
   /* module_entry *me; */
-  char update_file[51] = "", update_fpath[DIRMAX] = "", tmpFile[1024] = "", *sysname = NULL;
+  char update_file[51] = "", update_fpath[DIRMAX] = "", *sysname = NULL;
   int i = 1, j = -1;
 
   dcc[idx].status &= ~(STAT_OFFEREDU | STAT_SENDINGU);
@@ -278,7 +278,10 @@ static void start_sending_binary(int idx)
   }
 
   simple_snprintf(update_file, sizeof update_file, "wraith.%s-%s", sysname, egg_version);
-  simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", conf.binpath, update_file);
+
+  simple_snprintf(update_fpath, sizeof update_fpath, "%s/bins/%s", conf.binpath, update_file);
+  if (!can_stat(update_fpath))
+    simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", conf.binpath, update_file);
 
   if (!can_stat(update_fpath)) {
     putlog(LOG_MISC, "*", "Need to update \002%s\002 with %s but there was an error: %s", dcc[idx].nick, update_fpath,
@@ -288,10 +291,12 @@ static void start_sending_binary(int idx)
     return;
   }
 
+#ifdef old
   /* copy the binary to our tempdir and send that one. */
   sprintf(tmpFile, "%s.%s", tempdir, update_file);
   unlink(tmpFile);
   copyfile(update_fpath, tmpFile);
+#endif
 
 /* NO
   ic = 0;
@@ -313,7 +318,7 @@ static void start_sending_binary(int idx)
   end:;
 */
 
-  if ((i = raw_dcc_send(tmpFile, "*binary", "(binary)", tmpFile, &j)) > 0) {
+  if ((i = raw_dcc_send(update_file, "*binary", "(binary)", &j)) > 0) {
     putlog(LOG_BOTS, "*", "%s -- can't send new binary",
 	   i == DCCSEND_FULL   ? "NO MORE DCC CONNECTIONS" :
 	   i == DCCSEND_NOSOCK ? "CAN'T OPEN A LISTENING SOCKET" :