Пример #1
0
BOOL NEWS_MONITOR(char *server, int port, CStringList &lstGroups, char *uid, char *pwd, 
				  int timeout, char *connaddr, char *custpath, char *szReturn)
{
	DWORD dwBeginTime = 0, dwEndTime = 0;

	dwBeginTime = ::GetTickCount();

	CNNTPConnection nntp(timeout);

	if(!nntp.Connect(server, uid, pwd, port))
	{
		sprintf(szReturn, "error=%s", nntp.m_strErrorMsg);
		return FALSE;
	}

	int nArticles = 0;
	POSITION pos = lstGroups.FindIndex(0);
	while(pos)
	{
		int n = 0;
		CString strGroup = lstGroups.GetNext(pos);
		if(!nntp.Group((LPCTSTR)strGroup, n))
		{
			sprintf(szReturn, "error=%s", nntp.m_strErrorMsg);
			return FALSE;
		}

		nArticles += n;
	}

	nntp.Disconnect();

	dwEndTime = ::GetTickCount();

	sprintf(szReturn, "Articles=%d$roundTripTime=%ld$", 
				nArticles, dwEndTime - dwBeginTime);

	return TRUE;
}
Пример #2
0
int main(int argc, char *argv[])
{
    struct passwd   *pw;
    int		    i, rc; 
    socklen_t	    addrlen = sizeof(struct sockaddr_in6);
    char	    str[INET6_ADDRSTRLEN];
#ifdef  HAVE_GEOIP_H
    GeoIP   *gi;
#endif

    /*
     * The next trick is to supply a fake environment variable
     * FTND_ROOT because this program is started from inetd.
     * This will setup the variable so InitConfig() will work.
     * The /etc/passwd must point to the correct homedirectory.
     */
    pw = getpwuid(geteuid());
    if (getenv("FTND_ROOT") == NULL) {
	envptr = xstrcpy((char *)"FTND_ROOT=");
	envptr = xstrcat(envptr, pw->pw_dir);
	putenv(envptr);
    }
    mypid = getpid();

    /*
     * Read the global configuration data, registrate connection
     */
    InitConfig();
    InitMsgs();
    InitUser();
    InitFidonet();
    InitNode();
    umask(002);
    memset(&usrconfig, 0, sizeof(usrconfig));

    t_start = time(NULL);
    InitClient(pw->pw_name, (char *)"ftnnntp", CFG.location, CFG.logfile, 
	    CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
    Syslog(' ', "FTNNNTP v%s", VERSION);
    IsDoing("Loging in");

#ifdef	USE_NEWSGATE
    WriteError("FTNd is compiled for full newsgate, you cannot use ftnnntp!");
#endif

    /*
     * Catch all the signals we can, and ignore the rest.
     */
    for(i = 0; i < NSIG; i++) {

	if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT))
	    signal(i, (void (*))die);
	else if (i == SIGCHLD)
	    signal(i, SIG_DFL);
	else if ((i != SIGKILL) && (i != SIGSTOP))
	    signal(i, SIG_IGN);
    }

    if ((rc = rawport()) != 0)
	WriteError("Unable to set raw mode");
    else {
	if (getpeername(0,(struct sockaddr*)&peeraddr6,&addrlen) == 0) {
	    /*
	     * Copy IPv4 part into the IPv6 structure. There has to be a better way
	     * to deal with mixed incoming sockets ???
	     */
	    memcpy(&peeraddr4, &peeraddr6, sizeof(struct sockaddr_in));
	    if ((peeraddr6.sin6_family == AF_INET6) && (inet_ntop(AF_INET6, &peeraddr6.sin6_addr, str, sizeof(str)))) {
		Syslog('+', "Incoming IPv6 connection from %s", str);
	    } else if ((peeraddr4.sin_family == AF_INET) && (inet_ntop(AF_INET, &peeraddr4.sin_addr, str, sizeof(str)))) {
		Syslog('+', "Incoming IPv4 connection from %s", str);
	    }

#ifdef  HAVE_GEOIP_H
	    _GeoIP_setup_dbfilename();
	    if (peeraddr6.sin6_family == AF_INET6) {
	    	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
		    if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD)) != NULL) {
		    	geoiplookup(gi, str, GEOIP_COUNTRY_EDITION_V6);
		    }
		    GeoIP_delete(gi);
	    	}
	    } else if (peeraddr6.sin6_family == AF_INET) {
		if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
		    if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
			geoiplookup(gi, str, GEOIP_COUNTRY_EDITION);
		    }
		    GeoIP_delete(gi);
		}
	    }
#endif
#ifdef	USE_NEWSGATE
	    send_nntp("400 Server closed");
#else
	    if (! check_free()) {
		send_nntp("400 Server closed");
	    } else {
		send_nntp("200 FTNNNTP v%s server ready -- posting allowed", VERSION);
		nntp();
	    }
#endif
	}
    }

    cookedport();

    die(0);
    return 0;
}
Пример #3
0
int main(int argc, char * argv[]) {
  if (argc != 2) {
    std::cerr << "usage: " << argv[0] << " config.ini" << std::endl;
    return 1;
  }

  nntpchan::Mainloop loop;
  
  nntpchan::NNTPServer nntp(loop);
  
  std::string fname(argv[1]);

  std::ifstream i(fname);

  if(i.is_open()) {
    INI::Parser conf(i);
    
    std::vector<std::string> requiredSections = {"nntp", "storage"};
    
    auto & level = conf.top();
    
    for ( const auto & section : requiredSections ) {
      if(level.sections.find(section) == level.sections.end()) {
        std::cerr << "config file " << fname << " does not have required section: ";
        std::cerr << section << std::endl;
        return 1;
      }
    }

    auto & storeconf = level.sections["storage"].values;

    if (storeconf.find("path") == storeconf.end()) {
      std::cerr << "storage section does not have 'path' value" << std::endl;
      return 1;
    }

    nntp.SetStoragePath(storeconf["path"]);
    
    auto & nntpconf = level.sections["nntp"].values;

    if (nntpconf.find("bind") == nntpconf.end()) {
      std::cerr << "nntp section does not have 'bind' value" << std::endl;
      return 1;
    }

    if (nntpconf.find("authdb") != nntpconf.end()) {
      nntp.SetLoginDB(nntpconf["authdb"]);
    }

    if ( level.sections.find("frontend") != level.sections.end()) {
      // frontend enabled
      auto & frontconf = level.sections["frontend"].values;
      if (frontconf.find("type") == frontconf.end()) {
        std::cerr << "frontend section provided but 'type' value not provided" << std::endl;
        return 1;
      }
      auto ftype = frontconf["type"];
      if (ftype == "exec") {
        if (frontconf.find("exec") == frontconf.end()) {
          std::cerr << "exec frontend specified but no 'exec' value provided" << std::endl;
          return 1;
        }
        nntp.SetFrontend(new nntpchan::ExecFrontend(frontconf["exec"]));
      } else {
        std::cerr << "unknown frontend type '" << ftype << "'" << std::endl;
      }
          
    }
    
    auto & a = nntpconf["bind"];

    try {
      nntp.Bind(a);  
    } catch ( std::exception & ex ) {
      std::cerr << "failed to bind: " << ex.what() << std::endl;
      return 1;
    }
    try {
      std::cerr << "run mainloop" << std::endl;
      loop.Run();
    } catch ( std::exception & ex ) {
      std::cerr << "exception in mainloop: " << ex.what() << std::endl;
      return 2;
    }
    
  } else {
    std::cerr << "failed to open " << fname << std::endl;
    return 1;
  }
    
  
}