Kaynağa Gözat

* Fixed hubs not searching for binaries in same dir for update
* Improvements to nodename/username/os|sysname


svn: 1051

Bryan Drewery 22 yıl önce
ebeveyn
işleme
d47d7385d5
8 değiştirilmiş dosya ile 50 ekleme ve 72 silme
  1. 1 0
      doc/UPDATES
  2. 17 36
      src/botcmd.c
  3. 2 4
      src/dcc.c
  4. 0 1
      src/dcc.h
  5. 0 6
      src/mod/transfer.mod/transfer.c
  6. 27 23
      src/mod/update.mod/update.c
  7. 1 1
      src/userent.c
  8. 2 1
      src/users.c

+ 1 - 0
doc/UPDATES

@@ -28,6 +28,7 @@ This is a summary of ChangeLog basically.
 24.Recoded some of the AES core, fixed several outstanding bugs.
 25.Now dumping the stack on SIGSEGV.
 26.FreeBSD packages now have release # again, ie: FreeBSD4.
+27.Fixed hub not searching for update bins in it's own dir.
 
 1.1.7
 

+ 17 - 36
src/botcmd.c

@@ -434,40 +434,31 @@ static void remote_tell_who(int idx, char *nick, int chan)
   }
 }
 
-static void bot_sysname(int idx, char *par)
+static void bot_shellinfo(int idx, char *par)
 {
+  char *username = NULL, *sysname = NULL, *nodename = NULL;
+  
+  username = newsplit(&par);
+  sysname = newsplit(&par);
+  nodename = newsplit(&par);
+
   dcc[idx].u.bot->sysname[0] = 0;
-  strcpy(dcc[idx].u.bot->sysname, par);
-}
+  set_user(&USERENTRY_USERNAME, dcc[idx].user, username);
 
-static void bot_username(int idx, char *par)
-{
-  if (par && par[0]) {
-    set_user(&USERENTRY_USERNAME, dcc[idx].user, par);
-  }
-}
+  set_user(&USERENTRY_OS, dcc[idx].user, par);
+  strcpy(dcc[idx].u.bot->sysname, sysname); 
 
-static void bot_nodename(int idx, char *par)
-{
-  if (par && par[0]) {
-    set_user(&USERENTRY_NODENAME, dcc[idx].user, par);
-  }
+  set_user(&USERENTRY_NODENAME, dcc[idx].user, nodename);
 }
 
-static void bot_os(int idx, char *par)
+
+/* FIXME: remove after 1.1.8 */
+static void bot_sysname(int idx, char *par)
 {
-  if (par && par[0]) {
-    set_user(&USERENTRY_OS, dcc[idx].user, par);
-  }
+  dcc[idx].u.bot->sysname[0] = 0;
+  strcpy(dcc[idx].u.bot->sysname, par);
 }
 
-
-//  dprintf(idx, "username %s\n", conf.username ? conf.username : "");  /* username */
-//  dprintf(idx, "nodename %s\n", un.nodename ? un.nodename : "");      /* nodename */
-//  dprintf(idx, "os %s\n", un.sysname ? un.sysname : "");        /* os */
-
-
-
 /* who <from@bot> <tobot> <chan#>
  */
 static void bot_who(int idx, char *par)
@@ -785,12 +776,6 @@ static void bot_traced(int idx, char *par)
   }
 }
 
-static void bot_buildts(int idx, char *par)
-{
-  if (par && par[0])
-    dcc[idx].u.bot->bts = atoi(par);
-}
-
 static void bot_timesync(int idx, char *par)
 {
   putlog(LOG_DEBUG, "@", "Got timesync from %s: %s (%li - %li)", dcc[idx].nick, par, atol(par), now);
@@ -1188,8 +1173,6 @@ botcmd_t C_bot[] =
 {
   {"a",			(Function) bot_actchan},
   {"aw",		(Function) bot_away},
-  {"away",		(Function) bot_away},
-  {"bts",		(Function) bot_buildts},
   {"bye",		(Function) bot_bye},
   {"c",			(Function) bot_chan2},
   {"cg",                (Function) bot_config},
@@ -1205,8 +1188,6 @@ botcmd_t C_bot[] =
   {"l",			(Function) bot_link},
   {"n",			(Function) bot_nlinked},
   {"nc",		(Function) bot_nickchange},
-  {"nodename",		(Function) bot_nodename},
-  {"os",		(Function) bot_os},
   {"p",			(Function) bot_priv},
   {"pi",		(Function) bot_ping},
   {"po",		(Function) bot_pong},
@@ -1216,6 +1197,7 @@ botcmd_t C_bot[] =
   {"rr", 		(Function) bot_remotereply},
   {"s",			(Function) bot_share},
   {"sb",		(Function) bot_shareupdate},
+  {"si",		(Function) bot_shellinfo},
   {"t",			(Function) bot_trace},
   {"tb",		(Function) bot_thisbot},
   {"td",		(Function) bot_traced},
@@ -1223,7 +1205,6 @@ botcmd_t C_bot[] =
   {"u",			(Function) bot_update},
   {"ul",		(Function) bot_unlink},
   {"un",		(Function) bot_unlinked},
-  {"username",		(Function) bot_username},
   {"v",			(Function) bot_versions},
   {"vs",		(Function) bot_sysname},
   {"w",			(Function) bot_who},

+ 2 - 4
src/dcc.c

@@ -218,7 +218,6 @@ static void greet_new_bot(int idx)
 
   dcc[idx].timeval = now;
   dcc[idx].u.bot->version[0] = 0;
-  dcc[idx].u.bot->bts = 0;
   dcc[idx].u.bot->sysname[0] = 0;
   dcc[idx].u.bot->numver = 0;
 #ifdef HUB
@@ -244,10 +243,9 @@ static void greet_new_bot(int idx)
   dprintf(idx, "v 1001500 %d %s <%s> %d %li %s\n", HANDLEN, ver, "-", localhub, buildts, egg_version);
 /* FIXME: remove after 1.1.8 */
   dprintf(idx, "vs %s\n", sysname);
-  dprintf(idx, "username %s\n", conf.username ? conf.username : "");	/* username */
-  dprintf(idx, "nodename %s\n", un.nodename ? un.nodename : "");	/* nodename */
-  dprintf(idx, "os %s\n", un.sysname ? un.sysname : "");		/* os */
   dprintf(idx, "bts %lu\n", buildts);
+
+  dprintf(idx, "si %s %s %s", conf.username ? conf.username : "*", un.sysname ? un.sysname : "*", un.nodename ? un.nodename : "*");
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_FORK_BOT) {
       killsock(dcc[i].sock);

+ 0 - 1
src/dcc.h

@@ -103,7 +103,6 @@ struct xfer_info {
 };
 
 struct bot_info {
-  time_t bts;                   /* build timestamp */
   int  numver;
   int  uff_flags;               /* user file feature flags              */
   port_t port;		        /* base port                            */

+ 0 - 6
src/mod/transfer.mod/transfer.c

@@ -322,8 +322,6 @@ void eof_dcc_fork_send(int idx)
   lostdcc(idx);
 }
 
-long tlen = 0;
-
 static void eof_dcc_send(int idx)
 {
   int ok, j;
@@ -339,7 +337,6 @@ static void eof_dcc_send(int idx)
 
     /* Success */
     ok = 0;
-    putlog(LOG_DEBUG, "*", "tlen: %li length: %li status: %li", tlen, dcc[idx].u.xfer->length, dcc[idx].status);
     if (!strcmp(dcc[idx].nick, "*users")) {
       finish_share(idx);
       killsock(dcc[idx].sock);
@@ -741,8 +738,6 @@ void dcc_send(int idx, char *buf, int len)
   fflush(dcc[idx].u.xfer->f);
   fsync(fileno(dcc[idx].u.xfer->f));
 
-  tlen += len;
-
   dcc[idx].status += len;
   /* Put in network byte order */
   sent = dcc[idx].status;
@@ -991,7 +986,6 @@ void dcc_fork_send(int idx, char *x, int y)
   egg_snprintf(s1, sizeof s1, "%s!%s", dcc[idx].nick, dcc[idx].host);
   if (strcmp(dcc[idx].nick, "*users") && strcmp(dcc[idx].nick, "*binary"))
     putlog(LOG_MISC, "*", TRANSFER_DCC_CONN, dcc[idx].u.xfer->origname, s1);
-  tlen = 0;
 }
 
 #ifdef HUB

+ 27 - 23
src/mod/update.mod/update.c

@@ -18,10 +18,7 @@
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <sys/stat.h>
-
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 
 
@@ -139,15 +136,18 @@ static void update_version(int idx, char *par)
 return;
   /* Cleanup any share flags */
 #ifdef HUB
+  tand_t *bot = NULL;
+
   if (bupdating) return;
 
   dcc[idx].status &= ~(STAT_GETTINGU | STAT_SENDINGU | STAT_OFFEREDU);
-  if ((dcc[idx].u.bot->bts < buildts) && (isupdatehub())) {
+  bot = findbot(dcc[idx].nick);
+  if (bot && (bot->buildts < buildts) && (isupdatehub())) {
     putlog(LOG_DEBUG, "@", "Asking %s to accept update from me", dcc[idx].nick);
     dprintf(idx, "sb u?\n");
     dcc[idx].status |= STAT_OFFEREDU;
   }
-#endif
+#endif /* HUB */
 }
 
 /* Note: these MUST be sorted. */
@@ -283,8 +283,7 @@ static void start_sending_binary(int idx)
 {
   /* module_entry *me; */
 #ifdef HUB
-  char update_file[1024] = "", buf2[1024] = "", buf3[1024] = "";
-  struct stat sb;
+  char update_file[DIRMAX] = "", tmpFile[1024] = "", *sysname = NULL;
   int i = 1;
 
   dcc[idx].status &= ~(STAT_OFFEREDU | STAT_SENDINGU);
@@ -295,25 +294,28 @@ static void start_sending_binary(int idx)
   dcc[idx].status |= STAT_SENDINGU;
 
   putlog(LOG_BOTS, "*", "Sending binary send request to %s", dcc[idx].nick);
-  if (!strcmp("*", dcc[idx].u.bot->sysname)) {
+  sysname = get_user(&USERENTRY_OS, dcc[idx].user);
+/* FIXME: remove after 1.1.8 */
+  if (!sysname || !sysname[0] || !sysname[1] || !sysname[2] || !strcmp(sysname, ""))
+    sysname = dcc[idx].u.bot->sysname;
+  if (!sysname || !sysname[0] || !strcmp("*", sysname)) {
     putlog(LOG_MISC, "*", "Cannot update \002%s\002 automatically, uname not returning os name.", dcc[idx].nick);
     return;
   }
-  if (bot_hublevel(dcc[idx].user) == 999) { /* send them the leaf binary.. */
-    sprintf(buf2, "leaf");
-  } else {
-    sprintf(buf2, "hub");
-  }
-  sprintf(update_file, "%s.%s-%s", buf2,dcc[idx].u.bot->sysname, egg_version);
 
-  if (stat(update_file, &sb)) {
+  sprintf(update_file, "%s%s.%s-%s", dirname(binname), (bot_hublevel(dcc[idx].user) == 999) ? "leaf" : "hub", 
+                                     sysname, egg_version);
+
+  if (!can_stat(update_file)) {
     putlog(LOG_MISC, "*", "Need to update \002%s\002 with %s, but it cannot be accessed", dcc[idx].nick, update_file);
     bupdating = 0;
     return;
-  } 
-  sprintf(buf3, "%s.%s", tempdir, update_file);
-  unlink(buf3);
-  copyfile(update_file, buf3);
+  }
+
+  /* copy the binary to our tempdir and send that one. */
+  sprintf(tmpFile, "%s.%s", tempdir, update_file);
+  unlink(tmpFile);
+  copyfile(update_file, tmpFile);
 
 /* NO
   ic = 0;
@@ -324,7 +326,7 @@ static void start_sending_binary(int idx)
     goto end;
   }
   result = 0;
-  result = is_compressedfile(buf3);
+  result = is_compressedfile(tmpFile);
   if (result == COMPF_UNCOMPRESSED) {
     compress_file(buf3, 9);
     usleep(1000 * 500);
@@ -335,7 +337,7 @@ static void start_sending_binary(int idx)
   end:;
 */
 
-  if ((i = raw_dcc_send(buf3, "*binary", "(binary)", buf3)) > 0) {
+  if ((i = raw_dcc_send(tmpFile, "*binary", "(binary)", tmpFile)) > 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" :
@@ -360,6 +362,7 @@ static void check_updates()
   if (isupdatehub()) {
     int i;
     char buf[1024] = "";
+    tand_t *bot = NULL;
 
     cnt++;
     if ((cnt > 5) && bupdating)  bupdating = 0; /* 2 minutes should be plenty. */
@@ -370,11 +373,12 @@ static void check_updates()
       if (dcc[i].type->flags & DCT_BOT && (dcc[i].status & STAT_SHARE) &&
           !(dcc[i].status & STAT_SENDINGU) && !(dcc[i].status & STAT_OFFEREDU) &&
           !(dcc[i].status & STAT_UPDATED)) { /* only offer binary to bots that are sharing */
+        bot = findbot(dcc[i].nick);
 
         dcc[i].status &= ~(STAT_GETTINGU | STAT_SENDINGU | STAT_OFFEREDU);
 
-        if ((dcc[i].u.bot->bts < buildts) && (isupdatehub())) {
-          putlog(LOG_DEBUG, "@", "Bot: %s has build %lu, offering them %lu", dcc[i].nick, dcc[i].u.bot->bts, buildts);
+        if (bot && (bot->buildts < buildts) && (isupdatehub())) {
+          putlog(LOG_DEBUG, "@", "Bot: %s has build %lu, offering them %lu", dcc[i].nick, bot->buildts, buildts);
           dprintf(i, "sb u?\n");
           dcc[i].status |= STAT_OFFEREDU;
         }

+ 1 - 1
src/userent.c

@@ -1045,7 +1045,7 @@ void *get_user(struct user_entry_type *et, struct userrec *u)
 
   if (u && (e = find_user_entry(et, u)))
     return et->get(u, e);
-  return 0;
+  return NULL;
 }
 
 int set_user(struct user_entry_type *et, struct userrec *u, void *d)

+ 2 - 1
src/users.c

@@ -1074,6 +1074,7 @@ void autolink_cycle(char *start)
 {
   char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
   struct userrec *u = NULL;
+  tand_t *bot = NULL;
   int i;
 
   link_pref_val(conf.bot->u, myval);
@@ -1087,7 +1088,7 @@ void autolink_cycle(char *start)
       if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
         continue; /* lets let the binary have it's peace. */
 
-      if (dcc[i].u.bot->bts != buildts)
+      if ((bot = findbot(dcc[i].nick)) && bot->buildts != buildts)
         continue; /* same thing. */
 
       if (dcc[i].status & (STAT_SHARE | STAT_OFFERED | STAT_SENDING | STAT_GETTING)) {