Explorar el Código

* Begin working on cmd_conf

svn: 957
Bryan Drewery hace 22 años
padre
commit
8d887406af
Se han modificado 4 ficheros con 74 adiciones y 31 borrados
  1. 44 2
      src/cmds.c
  2. 27 28
      src/conf.c
  3. 2 1
      src/conf.h
  4. 1 0
      src/main.c

+ 44 - 2
src/cmds.c

@@ -7,6 +7,7 @@
 
 #include "common.h"
 #include "cmds.h"
+#include "conf.h"
 #include "color.h"
 #include "settings.h"
 #include "salt.h"
@@ -1843,6 +1844,45 @@ static void cmd_sha1(struct userrec *u, int idx, char *par)
   dprintf(idx, "SHA1(%s) = %s\n", par, SHA1(par));
 }
 
+static void cmd_conf(struct userrec *u, int idx, char *par)
+{
+  char *cmd = NULL;
+
+  if (!localhub) {
+    dprintf(idx, "Please use '%s%s%s' for this login/shell.\n", RED(idx), conf.localhub, COLOR_END(idx));
+    return;
+  }
+
+  if (par[0])
+    cmd = newsplit(&par);
+
+  /* del/change should restart the specified bot ;) */
+
+  if (!cmd) {
+    dprintf(idx, "Usage: conf <add|del|list|change|set> [options]\n");
+    return;
+  }
+  
+  putlog(LOG_CMDS, "*", "#%s# conf %s %s", dcc[idx].nick, cmd, par[0] ? par : "");
+
+  if (!egg_strcasecmp(cmd, "list")) {
+    conf_bot *bot = NULL;
+    unsigned int i = 0;
+
+    for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+      i++;
+      dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
+                    bot->nick,
+                    bot->ip ? bot->ip : "",
+                    bot->host ? bot->host : "",
+                    bot->ip6 ? bot->ip6 : "",
+                    bot->host6 ? bot->host6 : "",
+                    bot->pid);
+    }
+  }
+  /* showconf(idx); */
+}
+
 static void cmd_encrypt(struct userrec *u, int idx, char *par)
 {
   char *key = NULL, *buf = NULL;
@@ -2312,7 +2352,8 @@ static void cmd_chattr(struct userrec *u, int idx, char *par)
 		     user = {0, 0, 0, 0},
 		     ouser = {0, 0, 0, 0};
   /*int fl = -1, of = 0, ocf = 0;*/
-  flag_t fl = -1, of = 0, ocf = 0;
+/* FIXME: fl WAS -1 */
+  flag_t of = 0, ocf = 0;
 
   if (!par[0]) {
     dprintf(idx, "Usage: chattr <handle> [changes] [channel]\n");
@@ -2393,7 +2434,7 @@ static void cmd_chattr(struct userrec *u, int idx, char *par)
       return;
     }
 /* FIXME: POSSIBLY WRONG BECAUSE OF SIGNNES CHANGE OF fl */
-  user.match &= fl;
+  user.match &= -1;
 
   if (chg) {
     pls.match = user.match;
@@ -4213,6 +4254,7 @@ cmd_t C_dcc[] =
   {"randstring", 	"", 	(Function) cmd_randstring, 	NULL},
   {"md5",		"",	(Function) cmd_md5,		NULL},
   {"sha1",		"",	(Function) cmd_sha1,		NULL},
+  {"conf",		"",	(Function) cmd_conf,		NULL},
   {"encrypt",		"",	(Function) cmd_encrypt,		NULL},
   {"decrypt",		"",	(Function) cmd_decrypt,		NULL},
 #ifdef HUB

+ 27 - 28
src/conf.c

@@ -321,6 +321,7 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
 #ifdef LEAF
   if (bot == conffile.bots) {
     bot->localhub = 1;          /* first bot */
+    conffile.localhub = strdup(nick ? nick : origbotname);
     /* perhaps they did -B localhub-bot ? */
     if (origbotname[0] && !strcmp(origbotname, bot->nick))
       localhub = 1;
@@ -350,34 +351,31 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
 
 
 void
-showconf()
+showconf(int idx)
 {
   conf_bot *bot = NULL;
 
-  sdprintf("---------------------------CONF START---------------------------");
 #ifndef CYGWIN_HACKS
-  sdprintf("uid      : %d", conffile.uid);
-  sdprintf("uname    : %s", conffile.uname);
-  sdprintf("username : %s", conffile.username);
-  sdprintf("homedir  : %s", conffile.homedir);
-  sdprintf("binpath  : %s", conffile.binpath);
-  sdprintf("binname  : %s", conffile.binname);
-  sdprintf("portmin  : %d", conffile.portmin);
-  sdprintf("portmax  : %d", conffile.portmax);
-  sdprintf("pscloak  : %d", conffile.pscloak);
-  sdprintf("autocron : %d", conffile.autocron);
-  sdprintf("autouname: %d", conffile.autouname);
+  dprintf(idx, "uid      : %d\n", conffile.uid);
+  dprintf(idx, "uname    : %s\n", conffile.uname);
+  dprintf(idx, "username : %s\n", conffile.username);
+  dprintf(idx, "homedir  : %s\n", conffile.homedir);
+  dprintf(idx, "binpath  : %s\n", conffile.binpath);
+  dprintf(idx, "binname  : %s\n", conffile.binname);
+  dprintf(idx, "portmin  : %d\n", conffile.portmin);
+  dprintf(idx, "portmax  : %d\n", conffile.portmax);
+  dprintf(idx, "pscloak  : %d\n", conffile.pscloak);
+  dprintf(idx, "autocron : %d\n", conffile.autocron);
+  dprintf(idx, "autouname: %d\n", conffile.autouname);
 #endif /* !CYGWIN_HACKS */
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next)
-    sdprintf("%s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d PID_FILE: %s LOCALHUB %d", bot->nick, bot->ip, bot->host,
-             bot->ip6, bot->host6, bot->pid, bot->pid_file,
-#ifdef LEAF
-             bot->localhub
-#else
-             0
-#endif /* LEAF */
-      );
-  sdprintf("----------------------------CONF END----------------------------");
+    dprintf(idx, "%s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n",
+             bot->nick, 
+             bot->ip ? bot->ip : "",
+             bot->host ? bot->host : "",
+             bot->ip6 ? bot->ip6 : "", 
+             bot->host6 ? bot->host6 : "", 
+             bot->pid);
 }
 
 void
@@ -413,6 +411,12 @@ parseconf()
   if (!conffile.bots->nick && !conffile.bots->next)     /* no bots ! */
     werr(ERR_NOBOTS);
 
+  if (conffile.username) {
+    str_redup(&conffile.username, my_username());
+  } else {
+    conffile.username = strdup(my_username());
+  }
+
 #ifndef CYGWIN_HACKS
   if (conffile.uid && conffile.uid != myuid) {
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
@@ -430,12 +434,6 @@ parseconf()
     conffile.uname = strdup(my_uname());
   }
 
-  if (conffile.username) {
-    str_redup(&conffile.username, my_username());
-  } else {
-    conffile.username = strdup(my_username());
-  }
-
   if (conffile.homedir) {
     str_redup(&conffile.homedir, homedir());
   } else {
@@ -741,6 +739,7 @@ fillconf(conf_t * inconf)
   free(mynick);
   inconf->bot = (conf_bot *) calloc(1, sizeof(conf_bot));
   conf_bot_dup(inconf->bot, bot);
+  inconf->localhub = conffile.localhub ? strdup(conffile.localhub) : NULL;
   inconf->binpath = conffile.binpath ? strdup(conffile.binpath) : NULL;
   inconf->binname = conffile.binname ? strdup(conffile.binname) : NULL;
   inconf->uname = conffile.uname ? strdup(conffile.uname) : NULL;

+ 2 - 1
src/conf.h

@@ -24,6 +24,7 @@ typedef struct conf_bot_b {
 typedef struct conf_b {
   conf_bot *bots;       /* the list of bots */
   conf_bot *bot;        /* single bot (me) */
+  char *localhub;	/* my localhub */
   uid_t uid;
   char *uname;
   char *username;       /* shell username */
@@ -54,7 +55,7 @@ int killbot(char *);
 void confedit(char *);
 #endif /* S_CONFEDIT */
 pid_t checkpid(char *, conf_bot *);
-void showconf();
+void showconf(int);
 void init_conf();
 void free_conf();
 int readconf(char *, int);

+ 1 - 0
src/main.c

@@ -711,6 +711,7 @@ int main(int argc, char **argv)
 #endif /* CYGWIN_HACKS */
   clear_tmp();		/* clear out the tmp dir, no matter if we are localhub or not */
   /* just load everything now, won't matter if it's loaded if the bot has to suicide on startup */
+  init_flags();
   init_settings();
   binds_init();
   core_binds_init();