Exemplo n.º 1
0
void chanprog()
{
  struct utsname un;


  sdprintf("I am: %s", conf.bot->nick);

  /* Add the 'default' virtual channel.
     The flags will be overwritten when the userfile is loaded,
     but if there is no userfile yet, or no 'default' channel,
     then it will take on the properties of 'def_chanset',
     and then later save this to the userfile.
   */
  channel_add(NULL, "default", def_chanset, 1);

  if (conf.bot->hub) {
    simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
    loading = 1;
    checkchans(0);
    readuserfile(userfile, &userlist);
    checkchans(1);
    var_parse_my_botset();
    loading = 0;
  }

  load_internal_users();

  add_myself_to_userlist();

  if (conf.bot->localhub)
    add_child_bots();
  else if (!conf.bot->hub)
    add_localhub();

  rehash_ip();

  /* set our shell info */
  uname(&un);
  set_user(&USERENTRY_OS, conf.bot->u, un.sysname);
  set_user(&USERENTRY_USERNAME, conf.bot->u, conf.username);
  set_user(&USERENTRY_NODENAME, conf.bot->u, un.nodename);
  set_user(&USERENTRY_ARCH, conf.bot->u, un.machine);
  set_user(&USERENTRY_OSVER, conf.bot->u, un.release);

  var_parse_my_botset();

  /* We should be safe now */

  reaffirm_owners();
}
Exemplo n.º 2
0
/* Reload the user file from disk
 */
void reload()
{
  if (!file_readable(userfile)) {
    putlog(LOG_MISC, "*", MISC_CANTRELOADUSER);
    return;
  }

  noshare = 1;
  clear_userlist(userlist);
  noshare = 0;
  userlist = NULL;
  if (!readuserfile(userfile, &userlist))
    fatal(MISC_MISSINGUSERF, 0);
  reaffirm_owners();
  check_tcl_event("userfile-loaded");
  call_hook(HOOK_READ_USERFILE);
}
Exemplo n.º 3
0
/* Reload the user file from disk
 */
void reload()
{
  FILE *f = fopen(userfile, "r");

  if (f == NULL) {
    putlog(LOG_MISC, "*", "Can't reload user file!");
    return;
  }
  fclose(f);
  noshare = 1;
  clear_userlist(userlist);
  noshare = 0;
  userlist = NULL;
  loading = 1;
  checkchans(0);
  if (!readuserfile(userfile, &userlist))
    fatal("User file is missing!", 0);

  /* ensure we did not lose our internal users */
  load_internal_users();
  /* make sure I am added and conf.bot->u is set */
  add_myself_to_userlist();

  if (conf.bot->localhub)
    add_child_bots();
  else if (!conf.bot->hub)
    add_localhub();

  /* Make sure no removed users/bots are still connected. */
  check_stale_dcc_users();

  for (tand_t* bot = tandbot; bot; bot = bot->next)
    bot->u = get_user_by_handle(userlist, bot->bot);

  /* I don't think these will ever be called anyway. */
  if (!conf.bot->hub) {
    Auth::FillUsers();
    check_hostmask();
  }

  checkchans(1);
  loading = 0;
  var_parse_my_botset();
  reaffirm_owners();
  hook_read_userfile();
}
Exemplo n.º 4
0
void chanprog()
{
  int i;
  FILE *f;
  char s[161], rands[8];

  admin[0]   = 0;
  helpdir[0] = 0;
  tempdir[0] = 0;
  conmask    = 0;

  for (i = 0; i < max_logs; i++)
    logs[i].flags |= LF_EXPIRING;

  /* Turn off read-only variables (make them write-able) for rehash */
  protect_readonly = 0;

  /* Now read it */
  if (!readtclprog(configfile))
    fatal(MISC_NOCONFIGFILE, 0);

  for (i = 0; i < max_logs; i++) {
    if (logs[i].flags & LF_EXPIRING) {
      if (logs[i].filename != NULL) {
        nfree(logs[i].filename);
        logs[i].filename = NULL;
      }
      if (logs[i].chname != NULL) {
        nfree(logs[i].chname);
        logs[i].chname = NULL;
      }
      if (logs[i].f != NULL) {
        fclose(logs[i].f);
        logs[i].f = NULL;
      }
      logs[i].mask = 0;
      logs[i].flags = 0;
    }
  }

  /* We should be safe now */
  call_hook(HOOK_REHASH);
  protect_readonly = 1;

  if (!botnetnick[0])
    strncpyz(botnetnick, origbotname, HANDLEN + 1);

  if (!botnetnick[0])
    fatal("I don't have a botnet nick!!\n", 0);

  if (!userfile[0])
    fatal(MISC_NOUSERFILE2, 0);

  if (!readuserfile(userfile, &userlist)) {
    if (!make_userfile) {
      char tmp[178];

      egg_snprintf(tmp, sizeof tmp, MISC_NOUSERFILE, configfile);
      fatal(tmp, 0);
    }
    printf("\n\n%s\n", MISC_NOUSERFILE2);
    if (module_find("server", 0, 0))
      printf(MISC_USERFCREATE1, origbotname);
    printf("%s\n\n", MISC_USERFCREATE2);
  } else if (make_userfile) {
    make_userfile = 0;
    printf("%s\n", MISC_USERFEXISTS);
  }

  if (helpdir[0])
    if (helpdir[strlen(helpdir) - 1] != '/')
      strcat(helpdir, "/");

  if (tempdir[0])
    if (tempdir[strlen(tempdir) - 1] != '/')
      strcat(tempdir, "/");

  /* Test tempdir: it's vital. */

  /* Possible file race condition solved by using a random string
   * and the process id in the filename.
   * FIXME: This race is only partitially fixed. We could still be
   *        overwriting an existing file / following a malicious
   *        link.
   */
  make_rand_str(rands, 7); /* create random string */
  sprintf(s, "%s.test-%u-%s", tempdir, getpid(), rands);
  f = fopen(s, "w");
  if (f == NULL)
    fatal(MISC_CANTWRITETEMP, 0);
  fclose(f);
  unlink(s);
  reaffirm_owners();
  check_tcl_event("userfile-loaded");
}