Browse Source

* Don't share out userfile entries to bots that shouldn't get them (nodename/os/uname/config)

svn: 2124
Bryan Drewery 21 years ago
parent
commit
c9a48f4aa1
3 changed files with 51 additions and 10 deletions
  1. 25 0
      src/mod/share.mod/share.c
  2. 3 0
      src/mod/share.mod/share.h
  3. 23 10
      src/userent.c

+ 25 - 0
src/mod/share.mod/share.c

@@ -1044,6 +1044,31 @@ shareout(const char *format, ...)
   q_resync(s);
 }
 
+void
+shareout_prot(struct userrec *u, const char *format, ...)
+{
+  char s[601] = "";
+  int l;
+  va_list va;
+
+  va_start(va, format);
+
+  strcpy(s, "s ");
+  if ((l = egg_vsnprintf(s + 2, 509, format, va)) < 0)
+    s[2 + (l = 509)] = 0;
+  va_end(va);
+
+  for (int i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && (dcc[i].type->flags & DCT_BOT) && 
+       (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING)) &&
+       /* only send to hubs and to the same user */
+       (dcc[i].hub || dcc[i].user == u)) {
+      tputs(dcc[i].sock, s, l + 2);
+    }
+  }
+  q_resync(s);
+}
+
 static void
 shareout_but(int x, const char *format, ...)
 {

+ 3 - 0
src/mod/share.mod/share.h

@@ -10,8 +10,11 @@
 #define UFF_INVITE	BIT1	/* Send invites in user file	    */
 #define UFF_EXEMPT	BIT2	/* Send exempts in user file	    */
 
+#include "src/users.h"
+
 void sharein(int, char *);
 void shareout(const char *, ...) __attribute__((format(printf, 1, 2)));
+void shareout_prot(struct userrec *, const char *, ...) __attribute__((format(printf, 2, 3)));
 void finish_share(int);
 void dump_resync(int);
 void share_report(int, int);

+ 23 - 10
src/userent.c

@@ -69,7 +69,7 @@ bool def_kill(struct user_entry *e)
   return 1;
 }
 
-bool write_userfile_noleaf(FILE * f, struct userrec *u, struct user_entry *e, int idx)
+bool write_userfile_protected(FILE * f, struct userrec *u, struct user_entry *e, int idx)
 {
   /* only write if saving local, or if sending to hub, or if sending to same user as entry */
   if (idx == -1 || dcc[idx].hub || dcc[idx].user == u) {
@@ -91,7 +91,7 @@ void *def_get(struct userrec *u, struct user_entry *e)
   return e->u.string;
 }
 
-bool def_set(struct userrec *u, struct user_entry *e, void *buf)
+bool def_set_real(struct userrec *u, struct user_entry *e, void *buf, bool protect)
 {
   char *string = (char *) buf;
 
@@ -122,11 +122,24 @@ bool def_set(struct userrec *u, struct user_entry *e, void *buf)
     e->u.string = NULL;
   }
   if (!noshare) {
-    shareout("c %s %s %s\n", e->type->name, u->handle, e->u.string ? e->u.string : "");
+    if (protect)
+      shareout_prot(u, "c %s %s %s\n", e->type->name, u->handle, e->u.string ? e->u.string : "");
+    else
+      shareout("c %s %s %s\n", e->type->name, u->handle, e->u.string ? e->u.string : "");
   }
   return 1;
 }
 
+bool def_set(struct userrec *u, struct user_entry *e, void *buf)
+{
+  return (def_set_real(u, e, buf, 0));
+}
+
+bool set_protected(struct userrec *u, struct user_entry *e, void *buf)
+{
+  return (def_set_real(u, e, buf, 1));
+}
+
 bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx)
 {
   if (conf.bot->hub)
@@ -227,7 +240,7 @@ static bool config_set(struct userrec *u, struct user_entry *e, void *buf)
   /* we will possibly free new below, so let's send the information
    * to the botnet now */
   if (!noshare && !cfg_noshare)
-    shareout("c CONFIG %s %s %s\n", u->handle, mynew->key, mynew->data ? mynew->data : "");
+    shareout_prot(u, "c CONFIG %s %s %s\n", u->handle, mynew->key, mynew->data ? mynew->data : "");
   if ((old && old != mynew) || !mynew->data || !mynew->data[0]) {
     list_delete((struct list_type **) (&e->u.extra), (struct list_type *) old);
 
@@ -384,10 +397,10 @@ struct user_entry_type USERENTRY_USERNAME = {
  0,
  def_gotshare,
  def_unpack,
- write_userfile_noleaf,
+ write_userfile_protected,
  def_kill,
  def_get,
- def_set,
+ set_protected,
  botmisc_display,
  "USERNAME"
 };
@@ -396,10 +409,10 @@ struct user_entry_type USERENTRY_NODENAME = {
  0,
  def_gotshare,
  def_unpack,
- write_userfile_noleaf,
+ write_userfile_protected,
  def_kill,
  def_get,
- def_set,
+ set_protected,
  botmisc_display,
  "NODENAME"
 };
@@ -408,10 +421,10 @@ struct user_entry_type USERENTRY_OS = {
  0,
  def_gotshare,
  def_unpack,
- write_userfile_noleaf,
+ write_userfile_protected,
  def_kill,
  def_get,
- def_set,
+ set_protected,
  botmisc_display,
  "OS"
 };