Beispiel #1
0
static int init(void)
{
  const char* tmp;

  if ((tmp = getprotoenv("LOCALHOST")) == 0) tmp = UNKNOWN;
  str_copys(&domain_name, tmp);

  if ((tmp = getenv("SMTPGREETING")) != 0)
    str_copys(&str_welcome, tmp);
  else {
    str_copy(&str_welcome, &domain_name);
    str_cats(&str_welcome, " mailfront");
  }
  str_cats(&str_welcome, " ESMTP");

  if ((tmp = getenv("MAXNOTIMPL")) != 0)
    maxnotimpl = strtoul(tmp, 0, 10);

  if (!str_cats(&init_capabilities, "8BITMIME\nENHANCEDSTATUSCODES\nPIPELINING")) {
    respond(&resp_oom);
    return 1;
  }

  return 0;
}
static int str_catfromby(str* s, const char* helo_domain,
			 const char* host, const char* ip)
{
  int c;

  if (helo_domain == 0)
    helo_domain = (host != 0 && *host != 0) ? host : (ip != 0) ? ip : UNKNOWN;
  while((c = *helo_domain++) != 0) {
    if(!str_catc(s, (isalnum(c) || (c == '.') || (c == '-'))? c:'_')) return 0;
  }
  /* if (!str_cats(s, helo_domain)) return 0; */
  if (host != 0 || ip != 0) {
    if (!str_cats(s, " (")) return 0;
    if (host != 0) {
      if (!str_cats(s, host)) return 0;
      if (ip != 0)
	if (!str_catc(s, ' ')) return 0;
    }
    if (ip != 0) {
      if (!str_catc(s, '[')) return 0;
      if(strchr(ip, ':') && !str_cats(s, "IPV6:")) return 0;
      if( !str_cats(s, ip) ||
	  !str_catc(s, ']'))
	return 0;
    }
    if (!str_catc(s, ')')) return 0;
  }
  return 1;
}
Beispiel #3
0
static const response* check_fqdn(str* s)
{
  int at;
  int dot;
  const char* name;

  if ((at = str_findlast(s, '@')) <= 0) {
    if ((name = session_getenv("DEFAULTHOST")) != 0) {
      at = s->len;
      if (!str_catc(s, '@')
	  || !str_cats(s, name))
	return &resp_oom;
    }
    else
      return &resp_nodomain;
  }
  if ((dot = str_findlast(s, '.')) < at) {
    if ((name = session_getenv("DEFAULTDOMAIN")) != 0) {
      if (!str_catc(s, '.')
	  || !str_cats(s, name))
	return &resp_oom;
    }
    else
      return &resp_nofqdn;
  }
  return 0;
}
Beispiel #4
0
static void failsys(const char* id, const char* msg)
{
  wrap_str(str_copyb(&tmp, id, strlen(id) + 1));
  wrap_str(str_cats(&tmp, msg));
  wrap_str(str_cats(&tmp, ": "));
  wrap_str(str_cats(&tmp, strerror(errno)));
  if (!sendpacket(1, &tmp))
    exit(111);
}
static void addflag(const char *var, const char* flag, int reset)
{
  if(!session_getnum(var, 0)) return;

  if(reset) session_delnum(var);

  if(mflags.len) str_cats(&mflags, ",");
  str_cats(&mflags, flag);

}
/* actually do the log entry */
static void dosqlog(void)
{
  str sql;
  str mq, mr, md;
  unsigned int i, ni;

  if(!sqlseq) return;		/* nothing happened */

  str_init(&sql);
  str_init(&mq);
  str_init(&mr);
  str_init(&mflags);
  addflag("greylist", "greylist", 1);
  addflag("sump", "sump", 0);
  addflag("dblhelo", "dblhelo", 0);
  addflag("dblfrom", "dblfrom", 1);
  addflag("badrcpt", "badrcpt", 1);
  addflag("badbatv", "badbatv", 1);
  addflag("rcptrule", "badabuse", 1);

  str_copys(&sql, "update mail set flags='");
  str_cat(&sql, &mflags);
  sqlquote(&qsender, &mq);
  str_cats(&sql, "',mailfrom='");
  str_cat(&sql, &mq);
  /* envelope domain */
  i = str_findfirst(&qsender, '@');
  if(i < qsender.len) {
    str_init(&md);
    str_copyb(&md, qsender.s+i+1, qsender.len-i-1);
    sqlquote(&md, &mq);
    str_cats(&sql, "',envdomain='");
    str_cat(&sql, &mq);
  }
  str_cats(&sql, "' where serial=");
  str_cat(&sql, &sqlseqstr);
  sqlquery(&sql, 0);

  /* now add the recipients */
  for(i = 0; i < qrecips.len ; i = ni+1) {
    ni = str_findnext(&qrecips, 0, i);

    str_copyb(&mr, qrecips.s+i, ni-i);
    sqlquote(&mr, &mq);
    str_copys(&sql,"insert into mailrcpt(serial,rcptto) values(");
    str_cat(&sql, &sqlseqstr);
    str_cats(&sql, ",'");
    str_cat(&sql, &mq);
    str_cats(&sql, "')");
    sqlquery(&sql, 0);
  }
}
Beispiel #7
0
static const response* helo(str* hostname, str* capabilities)
{
  if (tls_available)
    if (!str_cats(capabilities, "STARTTLS\n")) return &resp_oom;
  return 0;
  (void)hostname;
}
Beispiel #8
0
static int doit(str *work,const char *rule)
{
  char ch;
  unsigned int colon;
  unsigned int prefixlen;
  const char *p;

  ch = *rule++;
  if ((ch != '?') && (ch != '=') && (ch != '*') && (ch != '-')) return 1;
  p = strchr(rule,':');
  if (!p) return 1;
  colon = p - rule;

  if (work->len < colon) return 1;
  prefixlen = work->len - colon;
  if ((ch == '=') && prefixlen) return 1;
  if (strncasecmp(rule,work->s + prefixlen,colon)) return 1;
  if (ch == '?') {
    if (memchr(work->s,':',prefixlen)) return 1;
    if (memchr(work->s,'.',prefixlen)) return 1;
    if (memchr(work->s,'[',prefixlen)) return 1;
    if (memchr(work->s,']',prefixlen)) return 1;
  }

  work->len = prefixlen;
  if (ch == '-') work->len = 0;
  return str_cats(work,rule + colon + 1);
}
Beispiel #9
0
static void report(const char* id, const char* msg)
{
  wrap_str(str_copyb(&tmp, id, strlen(id) + 1));
  wrap_str(str_cats(&tmp, msg));
  if (!sendpacket(1, &tmp))
    exit(111);
}
static int build_received(str* s, str *seqno)
{
  if (!str_cats(s, "Received: from ")) return 0;
  if (!str_catfromby(s, session_getstr("helo_domain"),
		     remote_host, remote_ip))
    return 0;
  if (!str_cats(s, "\n  by ")) return 0;
  if (!str_catfromby(s, local_host, 0, local_ip)) return 0;
  if (!str_cat4s(s, "\n  with ", session_protocol(),
		 " via ", linkproto))
    return 0;
  if (!str_cat4s(s, " port ", remote_port, "/", local_port)) return 0;
  if (!str_cat2s(s, " id ", seqno->s)) return 0;
  if (!str_cat3s(s, "; ", date_string(), "\n")) return 0;
  return 1;
}
Beispiel #11
0
static const response* message_end(int fd)
{
  struct stat st;
  char buf[1024];
  long rd;
  char* lf;
  char* ptr;

  if (fd >= 0) {
    /* Log the first two lines of the message, usually a Received: header */
    lseek(fd, 0, SEEK_SET);
    rd = read(fd, buf, sizeof buf - 1);
    buf[rd] = 0;
    if ((lf = strchr(buf, LF)) != 0) {
      str_copyb(&tmp, buf, lf-buf);
      ptr = lf + 1;
      if ((lf = strchr(ptr, LF)) != 0)
	str_catb(&tmp, ptr, lf-ptr);
      msg1(tmp.s);
    }

    fstat(fd, &st);
    databytes = st.st_size;
  }

  str_copys(&tmp, "Received ");
  str_catu(&tmp, databytes);
  str_cats(&tmp, " bytes.");
  resp.message = tmp.s;
  return &resp;
  (void)fd;
}
Beispiel #12
0
void determine_paths (char *argv0)
{
    char   buffer[8192], buffer2[MAX_PATH], *p;

    if (!fl_opt.has_driveletters)
    {
        // 1. User directory
        p = getenv ("HOME");
        if (p == NULL) fly_error ("HOME variable is not set, aborting\n\n");
        str_scopy (buffer, p);
        str_cats (buffer, ".nftp2");
        if (access (buffer, X_OK) < 0)
            if (mkdir1 (buffer, 0700) < 0)
                fly_error ("\nCannot create directory `%s'\n\n", buffer);
        paths.user_libpath = strdup (buffer);
        chmod (buffer, 0700);

        // 2. System directory
        strcpy (buffer, USR_PATH"/nftp2");
        if (access (buffer, X_OK) == 0)
        {
            paths.system_libpath = strdup (buffer);
        }
        else
        {
            strcpy (buffer, USR_LOCAL_PATH"/nftp2");
            if (access (buffer, X_OK) == 0)
               paths.system_libpath = strdup (buffer);
            else
               paths.system_libpath = paths.user_libpath;
        }
    }
    else
    {
        // 1. System directory
        strcpy (buffer, argv0);
        str_translate (buffer, '\\', '/');
        p = strrchr (buffer, '/');
        if (p == NULL) p = buffer;
        *p = '\0';

        // bare filename
        if (p == buffer)
        {
            buffer[0] = query_drive () + 'a';
            buffer[1] = ':';
            getcwd (buffer2, sizeof(buffer2));
            str_translate (buffer2, '\\', '/');
            if (buffer2[1] == ':')
                strcpy (buffer+2, buffer2+2);
            else
                strcpy (buffer+2, buffer2);
        }
        paths.system_libpath = strdup (buffer);

        // 2. User directory
        paths.user_libpath = paths.system_libpath;
    }

}
Beispiel #13
0
void write_config (void)
{
    char    cfgfile[MAX_PATH], *p;
    int     rc, x0, y0, i;

    rc = video_get_window_pos (&x0, &y0);
    if (rc == 0)
    {
        cfg_set_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0", x0);
        cfg_set_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0", y0);
    }

    cfg_set_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows", video_vsize());
    cfg_set_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols", video_hsize());

    for (i=0; i<sizeof(runtime_flags)/sizeof(runtime_flags[0]); i++)
    {
        if (runtime_flags[i].name != NULL)
            cfg_set_boolean (CONFIG_NFTP, NULL, runtime_flags[i].name, *(runtime_flags[i].value));
    }

    p = fly_get_font ();
    cfg_set_string (CONFIG_NFTP, fl_opt.platform_nick, "font", p);
    free (p);

    cfg_set_string (CONFIG_NFTP, "", "local-directory-left", local[V_LEFT].dir.name);
    cfg_set_string (CONFIG_NFTP, "", "local-directory-right", local[V_RIGHT].dir.name);

    strcpy (cfgfile, paths.user_libpath);
    str_cats (cfgfile, "nftp.cfg");
    cfg_write (CONFIG_NFTP, cfgfile);
}
Beispiel #14
0
static const response* sender(str* s, str* params)
{
  str_copys(&tmp, "Sender='");
  str_cat(&tmp, s);
  str_cats(&tmp, "'.");
  str_cat_params(&tmp, params);
  resp.message = tmp.s;
  return &resp;
}
Beispiel #15
0
void report_io_bytes(void)
{
  static str tmp;
  if (str_copys(&tmp, "bytes in: ") &&
      str_catu(&tmp, inbuf.io.offset) &&
      str_cats(&tmp, " bytes out: ") &&
      str_catu(&tmp, outbuf.io.offset))
    msg1(tmp.s);
}
Beispiel #16
0
static const response* recipient(str* r, str* params)
{
  str_copys(&tmp, "Recipient='");
  str_cat(&tmp, r);
  str_cats(&tmp, "'.");
  str_cat_params(&tmp, params);
  resp.message = tmp.s;
  return &resp;
}
Beispiel #17
0
void make_username(const char* start, ssize_t len, const char* msgprefix)
{
  str_copyb(&username, start, len);
  if (local_name && str_findfirst(&username, AT) < 0) {
    str_catc(&username, AT);
    str_cats(&username, local_name);
  }
  str_copy2s(&msgstr, msgprefix, username.s);
  log_line(msgstr.s, msgstr.len);
}
Beispiel #18
0
int open_file(const char* prefix, const char* filename)
{
  static str fullname;
  if (!str_truncate(&fullname, 0)) oom();
  if (prefix != 0) {
    if (!str_copys(&fullname, prefix)) oom();
    if (!str_catc(&fullname, '/')) oom();
  }
  if (!str_cats(&fullname, filename)) oom();
  return open(fullname.s, O_RDONLY);
}
Beispiel #19
0
/* ------------------------------------------------------------------------- */
const char* format_connection(const struct connections_entry* c)
{
  static str s;
  if (!str_copys(&s, ipv4_format(&c->key.ip))) return 0;
  if (!str_catc(&s, '/')) return 0;
  if (!str_catu(&s, c->key.port)) return 0;
  if (!str_catc(&s, '/')) return 0;
  if (!str_cat(&s, &c->data.service->key.sender)) return 0;
  if (!str_catc(&s, '/')) return 0;
  if (!str_cat(&s, &c->data.service->key.service)) return 0;
  if (!str_cats(&s, ": ")) return 0;
  return s.s;
}
Beispiel #20
0
/** Put an assignment, in \c NAME=value format, into the environment
 * string.
 * \note Unlike putenv, a copy of the assignment is made instead of
 * keeping a copy of the given pointer. */
int envstr_put(struct str* env, const char* asgn, int overwrite)
{
  long varlen;
  const char* found;
  found = strchr(asgn, '=');
  varlen = (found == 0) ? (long)strlen(asgn) : found - asgn;
  if ((found = envstr_find(env, asgn, varlen)) != 0) {
    if (!overwrite)
      return 1;
    str_spliceb(env, found - env->s, strlen(found) + 1, 0, 0);
  }
  return str_cats(env, asgn)
    && str_catc(env, 0);
}
Beispiel #21
0
static void make_prq(void)
{
  brandom_fill(nonce, sizeof nonce);
  pkt_start(&packet, PRQ1);
  pkt_add_b(&packet, nonce, sizeof nonce);
  pkt_add_s1c(&packet, AUTHENTICATOR_NAME);
  wrap_str(str_copys(&keyex_name, nistp224_cb.name));
  if (keylist_get(&shared_secrets, &curve25519_cb) != 0) {
    wrap_str(str_catc(&keyex_name, 0));
    wrap_str(str_cats(&keyex_name, curve25519_cb.name));
  }
  pkt_add_s1(&packet, &keyex_name);
  pkt_add_s1c(&packet, KEYHASH_NAME);
  pkt_add_s1c(&packet, ENCRYPTOR_NAME);
  pkt_add_s1c(&packet, "null");
}
Beispiel #22
0
/* Mark a maildir filename with the named flag */
static int add_flag(str* fn, char flag)
{
  int c;
  /* If the filename has no flags, append them */
  if ((c = str_findfirst(fn, ':')) == -1) {
    if (!str_cats(fn, ":2,")) return 0;
  }
  else {
    /* If it has a colon (start of flags), see if they are a type we
     * recognize, and bail out if they aren't */
    if (fn->s[c+1] != '2' || fn->s[c+2] != ',') return 1;
    /* Scan through the flag characters and return success
     * if the message is already marked with the flag */
    if (strchr(fn->s+c+3, flag) != 0) return 1;
  }
  return str_catc(fn, flag);
}
static int dblchk(str *domain, str *dbltxt)
{
	str dblstr;
	char *dbl = getenv("DBLLOOKUP");
	int l, i;
	unsigned char ansbuf[512];
	
	if(!dbl || domain->len == 0) return 0;
	if(session_getnum("sump",0)) return 0; /* no point */


	str_init(&dblstr);
	str_copy(&dblstr, domain);
	str_catc(&dblstr, '.');
	str_cats(&dblstr, dbl);
			
	l = res_query(dblstr.s, C_IN, T_TXT, ansbuf, sizeof(ansbuf));
	if(l > 0 && ((HEADER *)ansbuf)->ancount != 0) {  /* something in the answer */
		unsigned char *recbuf = ansbuf+NS_HFIXEDSZ;
		
		/* skip over questions, why am I still writing stuff
		 * like this? */
		for(i = ns_get16(ansbuf+4); i != 0; --i)
			recbuf += dn_skipname(recbuf, ansbuf+l)+4;

		for(i = ns_get16(ansbuf+6); i != 0; --i) {
			recbuf += dn_skipname(recbuf, ansbuf+l);

			if(ns_get16(recbuf) != T_TXT) { /* CNAME or something */
				recbuf += 10 + ns_get16(recbuf+8);
				continue;
			}
			/* it's a TXT record, wow */
			str_init(dbltxt);
			str_copyb(dbltxt, (char*)recbuf+11, recbuf[10]);
			str_free(&dblstr);
			return 1;
		}
	} /* didn't find anything */
	str_free(&dblstr);
	return 0;
	}
Beispiel #24
0
static void cmd_quit(void)
{
  long i;
  for (i = 0; i < msg_count; i++) {
    const char* fn = msgs[i].filename;
    if (msgs[i].deleted)
      unlink(fn);
    /* Logic: 
     * 1. move all messages into "cur"
     * 2. tag all read messages without flags with a read flag (:2,S)
     * Note: no real opportunity to report errors,
     * so just continue when we hit one.
     */
    else {
      if (!str_copys(&tmp, "cur/")) continue;
      if (!str_cats(&tmp, fn+4)) continue;
      if (msgs[i].read && !add_flag(&tmp, 'S')) continue;
      rename(fn, tmp.s);
    }
  }
  respond(ok);
  exit(0);
}
Beispiel #25
0
static long scan_dir(const char* subdir, str* list, long* countptr, long max)
{
  DIR* dir;
  direntry* entry;
  long count;
  
  if ((dir = opendir(subdir)) == 0) return 0;
  count = 0;
  while (!(max_count > 0 && msg_count >= max_count) &&
	 !(max > 0 && count >= max) &&
	 (entry = readdir(dir)) != 0) {
    if (entry->d_name[0] == '.') continue;
    if (!str_copys(&tmp, subdir)) return 0;
    if (!str_catc(&tmp, '/')) return 0;
    if (!str_cats(&tmp, entry->d_name)) return 0;
    if (!str_cat(list, &tmp)) return 0;
    if (!str_catc(list, 0)) return 0;
    ++count;
    ++msg_count;
  }
  closedir(dir);
  *countptr = count;
  return 1;
}
Beispiel #26
0
static int setup_env(void)
{
  const char* s;
  const char* colon;
  struct stat st;

  if (cvm_fact_mailbox != 0
      && (s = getenv("SETUP_ENV")) != 0
      && strcmp(s, "dovecot") == 0) {
    /* This tells Dovecot that its environment has already been set up. */
    if (putenv("DOVECONF_ENV=1") != 0)
      return 0;
    /* Use the file type to set the prefix to mbox: or maildir:
     * Assume missing files are mboxes. */
    s = (stat(cvm_fact_mailbox, &st) == 0
	 && S_ISDIR(st.st_mode))
      ? "maildir:"
      : "mbox:";
    /* Use cmd for temporary storage of the substituted mailbox name */
    if (!str_copys(&cmd, s))
      return 0;
    s = cvm_fact_mailbox;
    while ((colon = strchr(s, ':')) != 0) {
      if (!str_catb(&cmd, s, colon-s)
	  || !str_catb(&cmd, "::", 2))
	return 0;
      s = colon + 1;
    }
    if (!str_cats(&cmd, s))
      return 0;
    cvm_fact_mailbox = cmd.s;
  }
  return cvm_setenv()
    && setenv("IMAPLOGINTAG", tag.s, 1) == 0
    && setenv("AUTHENTICATED", cvm_fact_username, 1) == 0;
}
Beispiel #27
0
void init_config (void)
{
    char    inifile[MAX_PATH], ifile[MAX_PATH];
    char    cfgfile[MAX_PATH];
    int     i;

    // set defaults
    cfg_set_string (CONFIG_NFTP, fl_opt.platform_nick, "language", "english");

    // read stored customizations
    strcpy (cfgfile, paths.user_libpath);
    str_cats (cfgfile, "nftp.cfg");
    if (fl_opt.has_console && !fl_opt.initialized)
        fly_ask_ok (0, "loading %s......\n", cfgfile);
    cfg_read (CONFIG_NFTP, cfgfile);

    if (cmdline.language != NULL)
    {
        cfg_set_string (CONFIG_NFTP, fl_opt.platform_nick, "language", cmdline.language);
    }

    // load nftp.ini
    strcpy (inifile, paths.user_libpath);
    str_cats (inifile, "nftp.ini");
    if (fl_opt.has_console && !fl_opt.initialized)
        fly_ask_ok (0, "loading %s......\n", inifile);

    if (access (inifile, F_OK) != 0)
    {
        // looking for nftp.i file in user dir, then in system dir
        strcpy (ifile, paths.user_libpath);
        str_cats (ifile, "nftp.i");
        if (access (ifile, R_OK) != 0)
        {
            strcpy (ifile, paths.system_libpath);
            str_cats (ifile, "nftp.i");
            if (access (ifile, R_OK) != 0)
                fly_error ("Cannot find nftp.i neither in %s nor in %s",
                           paths.user_libpath, paths.system_libpath);
        }
        if (copy_file (ifile, inifile))
            fly_error ("Error copying %s to %s", ifile, inifile);
    }

    if (access (inifile, R_OK) != 0)
    {
        fly_error ("Cannot read %s", inifile);
    }

    GetProfileOptions (inifile);

    if (cmdline.slowlink) options.slowlink = TRUE;
    if (options.slowlink) fl_opt.use_ceol = TRUE;

    for (i=0; i<sizeof(runtime_flags)/sizeof(runtime_flags[0]); i++)
    {
        *(runtime_flags[i].value) = runtime_flags[i].def;
        if (runtime_flags[i].name != NULL &&
            cfg_check_boolean (CONFIG_NFTP, NULL, runtime_flags[i].name))
            *(runtime_flags[i].value) = cfg_get_boolean (CONFIG_NFTP, NULL, runtime_flags[i].name);
    }

    for (i=0; i<MAX_SITE; i++)
    {
        status.resolve_symlinks[i] = TRUE;
        status.use_flags[i] = TRUE;
        status.use_proxy[i] = FALSE;
        status.passive_mode[i] = FALSE;
    }
}
Beispiel #28
0
void load_menu (void)
{
    char    menu_filename[1024], *language;

    // find out what language user wants
    if (options.english_menu || cmdline.english)
    {
        language = "english";
    }
    else
    {
        language = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "language");
        str_strip (language, " ");
    }

Rescan:

    // Try $user_libpath directory
    strcpy (menu_filename, paths.user_libpath);
    str_cats (menu_filename, language);
    strcat (menu_filename, ".mnu");
    if (access (menu_filename, R_OK) == 0) goto Found;

    // Try $user_libpath/nls directory
    strcpy (menu_filename, paths.user_libpath);
    str_cats (menu_filename, "nls");
    str_cats (menu_filename, language);
    strcat (menu_filename, ".mnu");
    if (access (menu_filename, R_OK) == 0) goto Found;

    // Try $system_libpath directory
    strcpy (menu_filename, paths.system_libpath);
    str_cats (menu_filename, language);
    strcat (menu_filename, ".mnu");
    if (access (menu_filename, R_OK) == 0) goto Found;

    // Try $system_libpath/nls directory
    strcpy (menu_filename, paths.system_libpath);
    str_cats (menu_filename, "nls");
    str_cats (menu_filename, language);
    strcat (menu_filename, ".mnu");
    if (access (menu_filename, R_OK) == 0) goto Found;

    // Try ../nls
    strcpy (menu_filename, "../nls");
    str_cats (menu_filename, language);
    strcat (menu_filename, ".mnu");
    if (access (menu_filename, R_OK) == 0) goto Found;

    if (strcmp (language, "english") != 0)
    {
        if (fl_opt.has_console && !fl_opt.initialized)
            fly_ask_ok (0, "Failed to load \"%s.mnu\", trying English.\n", language);
        language = "english";
        goto Rescan;
    }
    else
        fly_error ("Failed to load \"%s.mnu\".", language);

Found:

    if (main_menu != NULL)
    {
        menu_unload (main_menu);
    }

    if (fl_opt.has_console && !fl_opt.initialized)
        fly_ask_ok (0, "loading %s......\n", menu_filename);
    main_menu = menu_load (menu_filename, options.keytable,
                           sizeof(options.keytable)/sizeof(options.keytable[0]));
}
Beispiel #29
0
void initialize (int *argc, char **argv[], char ***envp)
{
    char    buf[512], *p;
    char    inifile[MAX_PATH], ifile[MAX_PATH];
    time_t     t1;
    struct tm  tm1;
#ifdef __MINGW32__
    WSADATA wsa;
#endif

    //putenv ("TZ=GMT0");
    //tzset ();

    // first we need to initialize FLY variables
    fly_initialize ();
    fl_opt.appname = "nftp";

    if (fl_opt.has_console)
        fprintf (stderr, "\nNFTP - Version%sof %s, %s"
                 "\nCopyright (C) Sergey Ayukov 1994--2000.\n\n",
                 NFTP_VERSION, __DATE__, __TIME__);

    fly_process_args (argc, argv, envp);

    // checking command-line arguments
    check_args (*argc, *argv);

    // find where our config files are
    determine_paths ((*argv)[0]);

    // delete old temporary files
    clear_tmp ();

    // loading configuration files
    init_config ();

    // initilialize debug subsystem if specified
    if (options.debug)
    {
        sprintf (buf, /*sizeof(buf),*/ "%s/debug", paths.user_libpath);
        mkdir1 (buf, 0700);
        sprintf (buf, /*sizeof(buf),*/ "%s/debug/nftp.dbg.%u", paths.user_libpath, (int)getpid ());
        dbfile = fopen (buf, "w");
        tools_debug = dbfile;
    }

    if (options.log_cc)
    {
        sprintf (buf, /*sizeof(buf),*/ "%s/CC", paths.user_libpath);
        mkdir1 (buf, 0700);
        t1 = time (NULL);
        tm1 = *localtime (&t1);
        sprintf (buf, "CC/%04d-%02d-%02d.%02d:%02d:%02d.log",
                 tm1.tm_year+1900, tm1.tm_mon, tm1.tm_mday,
                 tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
        p = str_sjoin (paths.user_libpath, buf);
        cc_log = fopen (p, "w");
        if (cc_log == NULL) options.log_cc = FALSE;
        free (p);
    }

    // load language-specific things
    nls_init (paths.system_libpath, paths.user_libpath);
    load_menu ();

    // check for correct NFTP.INI version
    strcpy (buf, NFTP_VERSION);
    str_strip2 (buf, " ");
    //if (str_numchars (buf, '.') > 1)  *(strrchr (buf, '.')) = '\0';
    if (strcmp (options.version, buf) != 0)
    {
        // looking for nftp.i file in user dir, then in system dir
        strcpy (ifile, paths.user_libpath);
        str_cats (ifile, "nftp.i");
        if (access (ifile, R_OK) != 0)
        {
            strcpy (ifile, paths.system_libpath);
            str_cats (ifile, "nftp.i");
            if (access (ifile, R_OK) != 0)
                fly_error (MSG(M_INI_CANT_FIND_NFTP_I),
                        paths.user_libpath, paths.system_libpath);
        }
        strcpy (inifile, paths.user_libpath);
        str_cats (inifile, "nftp.ini");
        update_inifile (inifile, ifile);
        GetProfileOptions (inifile);
    }

    config_fly ();

#ifdef __MINGW32__
    WSAStartup (MAKEWORD(1,1), &wsa);
#endif
}
Beispiel #30
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode, i;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADARGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
    }

    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    display.view[V_LEFT] = -1;
    display.view[V_RIGHT] = -1;
    display.cursor = V_LEFT;
    display.parsed = TRUE;

    for (i=0; i<MAX_SITE; i++)
    {
        site[i].set_up = FALSE;
        site[i].CC.na = 0;
        site[i].CC.n = 0;
    }

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    lcache.lda = 0;
    lcache.ld  = 0;
    lcache.L   = NULL;

    local[V_LEFT].dir.name = NULL;
    local[V_LEFT].dir.files = NULL;
    local[V_LEFT].dir.nfiles = 0;
    local[V_LEFT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_LEFT].sortdirection = 1;
    else
        local[V_LEFT].sortdirection = -1;
    l_chdir (V_LEFT, NULL);

    local[V_RIGHT].dir.name = NULL;
    local[V_RIGHT].dir.files = NULL;
    local[V_RIGHT].dir.nfiles = 0;
    local[V_RIGHT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_RIGHT].sortdirection = 1;
    else
        local[V_RIGHT].sortdirection = -1;
    l_chdir (V_RIGHT, NULL);


    PutLineIntoResp (RT_COMM, 0, "NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp (RT_RESP, 0, "Copyright (C) 1994--2000 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp (RT_RESP, 0, "Portions Copyright (C) Eric Young <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp (RT_RESP, 0, MSG(M_RESP_F9_FOR_MENU));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, MSG(M_PROXY_ISNT_SPECIFIED));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_LOOKING_UP), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_CANNOT_RESOLVE), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp (RT_COMM,0, MSG(M_RESP_FOUND), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();

    // analyze arguments
    switch (action)
    {
    case ACTION_NONE:
        if (options.download_path != NULL)
        {
            l_chdir (V_RIGHT, options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-left");
            if (p[0] != '\0')
            {
                l_chdir (V_LEFT, p);
            }
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-right");
            if (p[0] != '\0')
            {
                l_chdir (V_RIGHT, p);
            }
        }
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;

    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = status.batch_mode;
        status.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode) fly_ask_ok (0, MSG(M_TRANSFER_FAILED), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff (0);
            terminate ();
            exit (0);
        }
        status.batch_mode = oldmode;
        return 0;

    //case ACTION_CMDLIST:
    //    rc = runscript (optarg1);
    //    return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (-1, &u, V_LEFT);
        if (rc) return 0;
        if ((action == ACTION_NICK_BOOK && MAX_SITE > 1 && optarg2 != NULL &&
             bookmark_nickname (optarg2, &u) == 1) ||
            (action == ACTION_NICK_HIST && MAX_SITE > 1 && optarg2 != NULL &&
             history_nickname (optarg2, &u) == 1))
        {
            rc = Login (-1, &u, V_RIGHT);
        }
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;

    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
        {
            l_chdir (V_LEFT, options.download_path);
            l_chdir (V_RIGHT, options.download_path);
        }
        dmsg ("optarg1 is [%s]\n", optarg1);
        parse_url (optarg1, &u);
        rc = Login (-1, &u, V_LEFT);
        if (MAX_SITE > 1 && optarg2 != NULL)
        {
            parse_url (optarg2, &u);
            rc = Login (-1, &u, V_RIGHT);
        }
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}