Преглед на файлове

* Added core components for readconf()

svn: 665
Bryan Drewery преди 22 години
родител
ревизия
1dbe2fccbf
променени са 2 файла, в които са добавени 95 реда и са изтрити 0 реда
  1. 68 0
      src/shell.c
  2. 27 0
      src/shell.h

+ 68 - 0
src/shell.c

@@ -50,6 +50,74 @@ extern char		tempdir[], origbotname[], botnetnick[], *binname, owneremail[],
 extern time_t		now;
 extern time_t		now;
 extern struct userrec       *userlist;
 extern struct userrec       *userlist;
 
 
+conf_t conf;
+
+void init_conf() {
+  conf.bots = (conf_bot *) calloc(1, sizeof(conf_bot));
+  conf.bots->nick = NULL;
+  conf.bots->next = NULL;
+}
+
+/* 
+ * Return the PID of a bot if it is running, otherwise return 0
+ */
+
+static int checkpid(char *nick) {
+  FILE *f;
+  int xx;
+  char buf[DIRMAX], s[11];
+
+  egg_snprintf(buf, sizeof buf, "%s.pid.%s", tempdir, nick);
+  if ((f = fopen(buf, "r"))) {
+    fgets(s, 10, f);
+    fclose(f);
+    xx = atoi(s);
+    kill(xx, SIGCHLD);
+    if (errno != ESRCH) /* PID is !running */
+      return xx;
+  }
+  return 0;
+}
+
+static void conf_addbot(char *nick, char *ip, char *host, char *ip6, char *host6) {
+  conf_bot *bot;
+
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next);
+  bot->next = (conf_bot *) calloc(1, sizeof(conf_bot));
+  bot->next->next = NULL;
+  bot->nick = strdup(nick);
+  if (bot == conf.bots) bot->localhub = 1;          /* first bot */
+  if (ip)    bot->ip = strdup(ip);
+  if (host)  bot->host = strdup(host);
+  if (ip6)   bot->ip6 = strdup(ip6);
+  if (host6) bot->host = strdup(host);
+  bot->pid = checkpid(nick);
+}
+
+void free_conf() {
+  conf_bot *bot, *bot_n;
+
+  for (bot = conf.bots; bot; bot = bot_n) {
+    bot_n = bot->next;
+    free(bot->nick);
+    if (bot->ip)    free(bot->ip);
+    if (bot->host)  free(bot->host);
+    if (bot->ip6)   free(bot->ip6);
+    if (bot->host6) free(bot->host6);
+    /* must also free() anything malloc`d in addbot() */
+    free(bot);
+  }
+  free(conf.uname);
+}
+
+int readconf() 
+{
+//  conf.uid = READ;
+//  conf.uname = strdup(READ);
+  return 0;
+}
+
+
 #ifdef S_LASTCHECK
 #ifdef S_LASTCHECK
 char last_buf[128]="";
 char last_buf[128]="";
 #endif /* S_LASTCHECK */
 #endif /* S_LASTCHECK */

+ 27 - 0
src/shell.h

@@ -1,6 +1,30 @@
 #ifndef _SHELL_H
 #ifndef _SHELL_H
 #define _SHELL_H
 #define _SHELL_H
 
 
+typedef struct conf_bot_b {
+  char *nick;
+  char *host;
+  char *host6;
+  char *ip;
+  char *ip6;
+  int pid;              /* contains the PID for the bot (read for the pidfile) */
+  int localhub;         /* bot is localhub */
+  struct conf_bot_b *next;
+} conf_bot;
+
+typedef struct conf_b {
+  uid_t uid;
+  char *uname;
+  int pscloak;          /* should the bots bother trying to cloak `ps`? */
+#ifdef HUB
+  int portrange;        /* for hubs, the reserved port range for incoming connections */
+#endif /* HUB */
+  char *binpath;        /* path to binary, ie: ~/ */
+  char *binname;        /* binary name, ie: .sshrc */
+  conf_bot *bots;       /* the list of bots */
+} conf_t;
+
+
 #define ERR_BINSTAT     1
 #define ERR_BINSTAT     1
 #define ERR_BINMOD      2
 #define ERR_BINMOD      2
 #define ERR_PASSWD      3
 #define ERR_PASSWD      3
@@ -35,6 +59,9 @@
 
 
 
 
 #ifndef MAKING_MODS
 #ifndef MAKING_MODS
+void init_conf();
+void free_conf();
+int readconf();
 char *homedir();
 char *homedir();
 char *my_uname();
 char *my_uname();
 char *confdir();
 char *confdir();