Пример #1
0
static void remote_filereq(int idx, char *from, char *file)
{
  char *p, what[256], dir[256], s[256], s1[256], *reject;
  FILE *f;
  filedb fdb;
  long i = 0;

  strcpy(what, file);
  p = strrchr(what, '/');
  if (p == NULL)
    dir[0] = 0;
  else {
    *p = 0;
    strcpy(dir, what);
    strcpy(what, p + 1);
  }
  f = filedb_open(dir, 0);
  reject = NULL;
  if (f == NULL) {
    reject = FILES_DIRDNE;
  } else {
    if (!findmatch(f, what, &i, &fdb)) {
      reject = FILES_FILEDNE;
      filedb_close(f);
    } else {
      if ((!(fdb.stat & FILE_SHARE)) ||
	  (fdb.stat & (FILE_HIDDEN | FILE_DIR))) {
	reject = FILES_NOSHARE;
	filedb_close(f);
      } else {
	filedb_close(f);
	/* copy to /tmp if needed */
	sprintf(s1, "%s%s%s%s", dccdir, dir, dir[0] ? "/" : "", what);
	if (copy_to_tmp) {
	  sprintf(s, "%s%s", tempdir, what);
	  copyfile(s1, s);
	} else
	  strcpy(s, s1);
	i = raw_dcc_send(s, "*remote", FILES_REMOTE, s);
	if (i > 0) {
	  wipe_tmp_filename(s, -1);
	  reject = FILES_SENDERR;
	}
      }
    }
  }
  simple_sprintf(s1, "%s:%s/%s", botnetnick, dir, what);
  if (reject) {
    botnet_send_filereject(idx, s1, from, reject);
    return;
  }
  /* grab info from dcc struct and bounce real request across net */
  i = dcc_total - 1;
  simple_sprintf(s, "%d %u %d", iptolong(getmyip()), dcc[i].port,
		dcc[i].u.xfer->length);
  botnet_send_filesend(idx, s1, from, s);
  putlog(LOG_FILES, "*", FILES_REMOTEREQ, dir, dir[0] ? "/" : "", what);
}
Пример #2
0
static int _dcc_send(int idx, char *filename, char *nick, char *dir)
{
  int x;
  char *nfn, *buf = NULL;

  Context;
  if (strlen(nick) > HANDLEN)
    nick[HANDLEN] = 0;
  x = raw_dcc_send(filename, nick, dcc[idx].nick, dir);
  if (x == DCCSEND_FULL) {
    dprintf(idx, "Sorry, too many DCC connections.  (try again later)\n");
    putlog(LOG_FILES, "*", "DCC connections full: GET %s [%s]", filename,
	   dcc[idx].nick);
    return 0;
  }
  if (x == DCCSEND_NOSOCK) {
    if (reserved_port) {
      dprintf(idx, "My DCC SEND port is in use.  Try later.\n");
      putlog(LOG_FILES, "*", "DCC port in use (can't open): GET %s [%s]",
	     filename, dcc[idx].nick);
    } else {
      dprintf(idx, "Unable to listen at a socket.\n");
      putlog(LOG_FILES, "*", "DCC socket error: GET %s [%s]", filename,
	     dcc[idx].nick);
    }
    return 0;
  }
  if (x == DCCSEND_BADFN) {
    dprintf(idx, "File not found (???)\n");
    putlog(LOG_FILES, "*", "DCC file not found: GET %s [%s]", filename,
	   dcc[idx].nick);
    return 0;
  }
  nfn = strrchr(filename, '/');
  if (nfn == NULL)
    nfn = filename;
  else
    nfn++;
  if (strchr(nfn, ' ')) {
    char *p;

    buf = nmalloc(strlen(nfn) + 1);
    strcpy(buf, nfn);
    p = nfn = buf;
    while ((p = strchr(p, ' ')) != NULL)
      *p = '_';
  }
  if (strcasecmp(nick, dcc[idx].nick))
    dprintf(DP_HELP, "NOTICE %s :Here is a file from %s ...\n", nick, dcc[idx].nick);
  dprintf(idx, "Type '/DCC GET %s %s' to receive.\n", botname, nfn);
  dprintf(idx, "Sending: %s to %s\n", nfn, nick);
  if (buf)
    nfree(buf);
  return 1;
}
Пример #3
0
static void remote_filereq(int idx, char *from, char *file)
{
    char *p = NULL, *what = NULL, *dir = NULL,
          *s1 = NULL, *reject = NULL, *s = NULL;
    FILE *fdb = NULL;
    int i = 0;
    filedb_entry *fdbe = NULL;

    malloc_strcpy(what, file);
    p = strrchr(what, '/');
    if (p) {
        *p = 0;
        malloc_strcpy(dir, what);
        strcpy(what, p + 1);
    } else {
        malloc_strcpy(dir, "");
    }
    fdb = filedb_open(dir, 0);
    if (!fdb) {
        reject = FILES_DIRDNE;
    } else {
        filedb_readtop(fdb, NULL);
        fdbe = filedb_matchfile(fdb, ftell(fdb), what);
        filedb_close(fdb);
        if (!fdbe) {
            reject = FILES_FILEDNE;
        } else {
            if ((!(fdbe->stat & FILE_SHARE)) ||
                    (fdbe->stat & (FILE_HIDDEN | FILE_DIR)))
                reject = FILES_NOSHARE;
            else {
                s1 = nmalloc(strlen(dccdir) + strlen(dir) + strlen(what) + 2);
                /* Copy to /tmp if needed */
                sprintf(s1, "%s%s%s%s", dccdir, dir, dir[0] ? "/" : "", what);
                if (copy_to_tmp) {
                    s = nmalloc(strlen(tempdir) + strlen(what) + 1);
                    sprintf(s, "%s%s", tempdir, what);
                    copyfile(s1, s);
                } else
                    s = s1;
                i = raw_dcc_send(s, "*remote", FILES_REMOTE, s);
                if (i > 0) {
                    wipe_tmp_filename(s, -1);
                    reject = FILES_SENDERR;
                }
                if (s1 != s)
                    my_free(s);
                my_free(s1);
            }
            free_fdbe(&fdbe);
        }
    }
    s1 = nmalloc(strlen(botnetnick) + strlen(dir) + strlen(what) + 3);
    simple_sprintf(s1, "%s:%s/%s", botnetnick, dir, what);
    if (reject) {
        botnet_send_filereject(idx, s1, from, reject);
        my_free(s1);
        my_free(what);
        my_free(dir);
        return;
    }
    /* Grab info from dcc struct and bounce real request across net */
    i = dcc_total - 1;
    s = nmalloc(40);              /* Enough? */
    simple_sprintf(s, "%d %u %d", iptolong(getmyip()), dcc[i].port,
                   dcc[i].u.xfer->length);
    botnet_send_filesend(idx, s1, from, s);
    putlog(LOG_FILES, "*", FILES_REMOTEREQ, dir, dir[0] ? "/" : "", what);
    my_free(s1);
    my_free(s);
    my_free(what);
    my_free(dir);
}
Пример #4
0
static int _dcc_send(int idx, char *filename, char *nick, char *dir,
                     int resend)
{
  int x;
  char *nfn, *buf = NULL;

  if (strlen(nick) > NICKMAX)
    nick[NICKMAX] = 0;
  if (resend)
    x = raw_dcc_resend(filename, nick, dcc[idx].nick, dir);
  else
    x = raw_dcc_send(filename, nick, dcc[idx].nick, dir);
  if (x == DCCSEND_FULL) {
    dprintf(idx, "Sorry, too many DCC connections.  (try again later)\n");
    putlog(LOG_FILES, "*", "DCC connections full: %sGET %s [%s]", filename,
           resend ? "RE" : "", dcc[idx].nick);
    return 0;
  }
  if (x == DCCSEND_NOSOCK) {
    if (reserved_port_min) {
      dprintf(idx, "All my DCC SEND ports are in use.  Try later.\n");
      putlog(LOG_FILES, "*", "DCC port in use (can't open): %sGET %s [%s]",
             resend ? "RE" : "", filename, dcc[idx].nick);
    } else {
      dprintf(idx, "Unable to listen at a socket.\n");
      putlog(LOG_FILES, "*", "DCC socket error: %sGET %s [%s]", filename,
             resend ? "RE" : "", dcc[idx].nick);
    }
    return 0;
  }
  if (x == DCCSEND_BADFN) {
    dprintf(idx, "File not found ?\n");
    putlog(LOG_FILES, "*", "DCC file not found: %sGET %s [%s]", filename,
           resend ? "RE" : "", dcc[idx].nick);
    return 0;
  }
  if (x == DCCSEND_FEMPTY) {
    dprintf(idx, "The file is empty.  Aborted transfer.\n");
    putlog(LOG_FILES, "*", "DCC file is empty: %s [%s]", filename,
           dcc[idx].nick);
    return 0;
  }
  nfn = strrchr(dir, '/');
  if (nfn == NULL)
    nfn = dir;
  else
    nfn++;

  /* Eliminate any spaces in the filename. */
  if (strchr(nfn, ' ')) {
    char *p;

    malloc_strcpy(buf, nfn);
    p = nfn = buf;
    while ((p = strchr(p, ' ')) != NULL)
      *p = '_';
  }

  if (egg_strcasecmp(nick, dcc[idx].nick))
    dprintf(DP_HELP, "NOTICE %s :Here is %s file from %s %s...\n", nick,
            resend ? "the" : "a", dcc[idx].nick, resend ? "again " : "");
  dprintf(idx, "%sending: %s to %s\n", resend ? "Res" : "S", nfn, nick);
  my_free(buf);
  return 1;
}