Exemplo n.º 1
0
void
starttls(void)
{
	int certlen, fd;
	uchar *cert;
	TLSconn *conn;

	if (tlscert == nil) {
		reply("500 5.5.1 illegal command or bad syntax\r\n");
		return;
	}
	conn = mallocz(sizeof *conn, 1);
	cert = readcert(tlscert, &certlen);
	if (conn == nil || cert == nil) {
		if (conn != nil)
			free(conn);
		reply("454 4.7.5 TLS not available\r\n");
		return;
	}
	reply("220 2.0.0 Go ahead make my day\r\n");
	conn->cert = cert;
	conn->certlen = certlen;
	fd = tlsServer(Bfildes(&bin), conn);
	if (fd < 0) {
		free(cert);
		free(conn);
		syslog(0, "smtpd", "TLS start-up failed with %s", him);

		/* force the client to hang up */
		close(Bfildes(&bin));		/* probably fd 0 */
		close(1);
		exits("tls failed");
	}
	Bterm(&bin);
	Binit(&bin, fd, OREAD);
	if (dup(fd, 1) < 0)
		fprint(2, "dup of %d failed: %r\n", fd);
	passwordinclear = 1;
	syslog(0, "smtpd", "started TLS with %s", him);
}
Exemplo n.º 2
0
void fsd::configure()
{
   clientport=6809, serverport=3011, systemport=3012;
   configentry *entry;
   configgroup *sysgroup=configman->getgroup("system");
   /* Configure */
   if (sysgroup)
   {
      if ((entry=sysgroup->getentry("clientport"))!=NULL)
         clientport=entry->getint();
      if ((entry=sysgroup->getentry("serverport"))!=NULL)
         serverport=entry->getint();
      if ((entry=sysgroup->getentry("systemport"))!=NULL)
         systemport=entry->getint();
      if ((entry=sysgroup->getentry("certificates"))!=NULL)
         certfile=strdup(entry->getdata());
      if ((entry=sysgroup->getentry("whazzup"))!=NULL)
		 whazzupfile=strdup(entry->getdata());
   }
   configmyserver();
   readcert();
}
Exemplo n.º 3
0
Arquivo: pop3.c Projeto: npe9/harvey
void
main(int argc, char **argv)
{
	int fd;
	char *arg, cmdbuf[1024];
	Cmd *c;

	rfork(RFNAMEG);
	Binit(&in, 0, OREAD);
	Binit(&out, 1, OWRITE);

	ARGBEGIN{
	case 'a':
		loggedin = 1;
		if(readmbox(EARGF(usage())) < 0)
			exits(nil);
		break;
	case 'd':
		debug++;
		if((fd = create(EARGF(usage()), OWRITE, 0666)) >= 0 && fd != 2){
			dup(fd, 2);
			close(fd);
		}
		break;
	case 'p':
		passwordinclear = 1;
		break;
	case 'r':
		strecpy(tmpaddr, tmpaddr+sizeof tmpaddr, EARGF(usage()));
		if(arg = strchr(tmpaddr, '!'))
			*arg = '\0';
		peeraddr = tmpaddr;
		break;
	case 't':
		tlscert = readcert(EARGF(usage()), &ntlscert);
		if(tlscert == nil){
			senderr("cannot read TLS certificate: %r");
			exits(nil);
		}
		break;
	}ARGEND

	/* do before TLS */
	if(peeraddr == nil)
		peeraddr = remoteaddr(0,0);

	hello();

	while(Bflush(&out), getcrnl(cmdbuf, sizeof cmdbuf) > 0){
		arg = nextarg(cmdbuf);
		for(c=cmdtab; c->name; c++)
			if(cistrcmp(c->name, cmdbuf) == 0)
				break;
		if(c->name == 0){
			senderr("unknown command %s", cmdbuf);
			continue;
		}
		if(c->needauth && !loggedin){
			senderr("%s requires authentication", cmdbuf);
			continue;
		}
		(*c->f)(arg);
	}
	exits(nil);
}
Exemplo n.º 4
0
/* Here we do timeout checks. This function is triggered every second to
   reduce the load on the server */
void fsd::dochecks()
{
   time_t now=mtime();
   if ((now-prevnotify)>NOTIFYCHECK)
   {
      configgroup *sgroup=configman->getgroup("system");
      if (sgroup&&sgroup->changed)
         configmyserver();
      serverinterface->sendservernotify("*", myserver, NULL);
      prevnotify=now;
   }
   if ((now-prevlagcheck)>LAGCHECK)
   { 
      char data[80];
      sprintf(data,"-1 %lu", mtime());
      serverinterface->sendping("*", data);
      prevlagcheck=now;
   }
   if ((now-prevcertcheck)>CERTFILECHECK)
   {
      configentry *entry;
      configgroup *sysgroup=configman->getgroup("system");
      if (sysgroup) if ((entry=sysgroup->getentry("certificates"))!=NULL)
      {
         if (certfile) free(certfile);
         certfile=strdup(entry->getdata());
         struct stat buf;
         prevcertcheck=now;
         if (!stat(certfile, &buf)) if (buf.st_mtime!=certfilestat)
         {
            certfilestat=buf.st_mtime;
            readcert();
         }
      }
   }
// WhazzUp Start
   if ((now-prevwhazzup)>=WHAZZUPCHECK)
   {
      configentry *entry;
      configgroup *sysgroup=configman->getgroup("system");
      if (sysgroup) if ((entry=sysgroup->getentry("whazzup"))!=NULL)
      {
         if (whazzupfile) free(whazzupfile);
         whazzupfile=strdup(entry->getdata());
         char whazzuptemp[100];
         sprintf(whazzuptemp,"%s%s", whazzupfile, ".tmp");
         prevwhazzup=now;
         if (fileopen==0)
         {
            FILE *wzfile=fopen(whazzuptemp, "w");
            if (wzfile)
            {
               //Ready to write data
               fileopen = 1;
               char s[32];
			   fprintf(wzfile,"%s%s\n","![DateStamp]",sprintgmtdate(now,s));
               fprintf(wzfile,"%s\n","!GENERAL");
               fprintf(wzfile,"%s = %d\n", "VERSION", 1);
               fprintf(wzfile,"%s = %d\n", "RELOAD", 1);
               fprintf(wzfile,"%s = %s\n", "UPDATE", sprintgmt(now, s));
               client *tempclient;
               flightplan *tempflightplan;
               server *tempserver;
               int clients=0;
               for (tempclient=rootclient;tempclient;tempclient=tempclient->next)
                  clients++;
               fprintf(wzfile,"%s = %d\n", "CONNECTED CLIENTS", clients);
               int servers=0;
               for (tempserver=rootserver;tempserver;tempserver=tempserver->next)
                  servers++;
               fprintf(wzfile,"%s = %d\n", "CONNECTED SERVERS", servers);
               fprintf(wzfile,"%s\n","!CLIENTS");
               char dataseg1[150]; char dataseg2[150]; char dataseg3[150]; char dataseg4[150]; char dataseg5[150]; char dataseg6[2000]; char dataseg7[50];
               for (tempclient=rootclient;tempclient;tempclient=tempclient->next)
               {
                  sprintf(dataseg1,"%s:%s:%s:%s", tempclient->callsign, tempclient->cid, tempclient->realname, tempclient->type==CLIENT_ATC?"ATC":"PILOT");
                  if (tempclient->frequency!=0 && tempclient->frequency<100000 && tempclient)
                     sprintf(dataseg2,"1%02d.%03d", tempclient->frequency/1000, tempclient->frequency%1000);
                  else
                     sprintf(dataseg2,"%s","");
                  tempflightplan=tempclient->plan;
                  if (tempclient->lat!=0 && tempclient->altitude < 100000 && tempclient->lon != 0)
                     sprintf(dataseg3,"%f:%f:%d:%d", tempclient->lat, tempclient->lon, tempclient->altitude, tempclient->groundspeed);
                  else
                     sprintf(dataseg3,"%s",":::");
                  if (tempflightplan)
                     sprintf(dataseg4,"%s:%d:%s:%s:%s", tempflightplan->aircraft, tempflightplan->tascruise, tempflightplan->depairport, tempflightplan->alt, tempflightplan->destairport);
                  else
                     sprintf(dataseg4,"%s","::::");
                  sprintf(dataseg5,"%s:%s:%d:%d:%d:%d", tempclient->location->ident, tempclient->protocol, tempclient->rating, tempclient->transponder, tempclient->facilitytype, tempclient->visualrange);
                  if (tempflightplan)
                     sprintf(dataseg6,"%d:%c:%d:%d:%d:%d:%d:%d:%s:%s:%s", tempflightplan->revision, tempflightplan->type, tempflightplan->deptime, tempflightplan->actdeptime, tempflightplan->hrsenroute, tempflightplan->minenroute, tempflightplan->hrsfuel, tempflightplan->minfuel, tempflightplan->altairport, tempflightplan->remarks, tempflightplan->route);
                  else
                     sprintf(dataseg6,"%s","::::::::::");
                  sprintf(dataseg7,"::::::%s", sprintgmt(tempclient->starttime,s));
                  fprintf(wzfile,"%s:%s:%s:%s:%s:%s:%s\n", dataseg1, dataseg2, dataseg3, dataseg4, dataseg5, dataseg6, dataseg7);
               }
               char dataline[150]; 
               fprintf(wzfile,"%s\n","!SERVERS");
               for (tempserver=rootserver;tempserver;tempserver=tempserver->next)
                  if (strcmp(tempserver->hostname,"n/a") != 0)
                  {
                     sprintf(dataline,"%s:%s:%s:%s:%d", tempserver->ident, tempserver->hostname, tempserver->location, tempserver->name, tempserver->flags&SERVER_SILENT?0:1);
                     fprintf(wzfile,"%s\n",dataline);
                  }; 
               fclose(wzfile);
			   remove(whazzupfile);
               rename(whazzuptemp, whazzupfile);
               fileopen=0;
            }
            else
               fileopen=0;
         }
      }
   }
// WhazzUp End
   server *tempserver=rootserver;
   while (tempserver)
   {
      server *next=tempserver->next;
      if ((now-tempserver->alive)>SERVERTIMEOUT&&(tempserver!=myserver))
         delete tempserver;
      tempserver=next;
   }
   client *tempclient=rootclient;

   /* Check for client timeouts. We should not drop clients if we are in
      silent mode; If we are in silent mode, we won't receive updates, so
      every client would timeout. When we are a silent server, the limit
      will be SILENTCLIENTTIMEOUT, which is about 10 hours  */
   int limit=(myserver->flags&SERVER_SILENT)?SILENTCLIENTTIMEOUT:CLIENTTIMEOUT;
   while (tempclient)
   {
      client *next=tempclient->next;
      if (tempclient->location!=myserver)
      if ((now-tempclient->alive)>limit)
         delete tempclient;
      tempclient=next;
   }
}