Exemplo n.º 1
0
subroutine sendemails(io emaillog) {

	var errormsg;

	if (not toemails) {
		return;
	}

	ccemails.trimmerf(";");

	call sendmail(toemails, ccemails, subject, body, "", "", errormsg);

	if (errormsg and errormsg ne "OK") {
		emaillog ^= VM ^ errormsg;
	}else{
		nsent += 1;
	}

	emaillog ^= VM;

	toemails = "";
	ccemails = "";

	return;

}
Exemplo n.º 2
0
int main(int n, char *cmd[]) {
        if(n<4) {
                printf("usage: sendmail -f mail-from mail-reciever.\r\n");
                exit(0);
        }
        sendmail(cmd[2], cmd[3]);
}
Exemplo n.º 3
0
int 
Sendm(char *str)
{
	if (value("flipm") != NOSTR)
		return(sendmail(str));
	else return(Sendmail(str));
}
Exemplo n.º 4
0
bool
wxEmail::Send(wxMailMessage& message,
              const wxString& profileName,
              const wxString& sendMail)
{
    wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ;


    // The 'from' field is optionally supplied by the app; it's not needed
    // by MAPI, and on Unix, will be guessed if not supplied.
    wxString from = message.m_from;
    if ( from.empty() )
    {
        from = wxGetEmailAddress();
    }

    wxString msg;
    msg << wxT("To: ");

    const size_t rcptCount = message.m_to.GetCount();
    for (size_t rcpt = 0; rcpt < rcptCount; rcpt++)
    {
        if ( rcpt )
            msg << wxT(", ");
        msg << message.m_to[rcpt];
    }

    msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject;
    msg << wxT("\n\n") << message.m_body;

    wxString filename;
    filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
        (long) rand());

    {
        wxFileOutputStream stream(filename);
        if (stream.Ok())
        {
            stream.Write(msg, msg.Length());
        }
        else
        {
            return FALSE ;
        }
    }

    // TODO search for a suitable sendmail if sendMail is empty
    wxString sendmail(sendMail);

    wxString cmd;
    cmd << sendmail << wxT(" < ") << filename;

    // TODO: check return code
    wxSystem(cmd.c_str());

    wxRemoveFile(filename);

    return TRUE;
}
Exemplo n.º 5
0
/**
 * loop over all files in the current directory and execute them
 */
int process() {
	struct dirent *dp; /* dir pointer */
	DIR *d = opendir(".");

	if (d == NULL) {
		LOG("opendir(): %s\n", strerror(errno));
		return 1;
	}

	/* loop over the dirent */
	int i = 0;
	int ret = 0;
	while ((dp = readdir(d)) != NULL) {
		/* skip hidden files */
		if (dp->d_name[0] == '.') continue;

		DEBUG("executing %s\n", dp->d_name);

		/* run the plugin */
		char *output = NULL;
		ret = execute(dp->d_name, &output);
		if (options.debug && output != NULL)
			printf("%s", output);

		/* something went wrong, ignore it */
		if (ret == -1) {
			LOG("error executing %s, moving on\n", dp->d_name);
			if (output != NULL) free(output);
			continue;
		}
		ret = WEXITSTATUS(ret);

		switch (ret) {
			case 0: /* success */
				DEBUG("%s executed succesfully\n",
				    dp->d_name);
				break;
			default: /* health check failed */
				LOG("%s failed (exit code %d)\n",
				    dp->d_name, ret);

				if (options.mail_to != NULL) {
					LOG("sending email to %s\n",
					    options.mail_to);
					sendmail(dp->d_name, output);
				}
				if (output != NULL) free(output);
				closedir(d);
				return ret;
		}
		if (output != NULL) free(output);
		i++;
	}
	closedir(d);

	DEBUG("%d scripts executed\n", i);

	return 0;
}
Exemplo n.º 6
0
/**
 * this is the function that takes over from main().  
 * It will call all functions nessicary to finish off the 
 * rest of the program and then return properly. 
**/
void
createMail(void)
{
	dstrbuf *msg=NULL, *full_msg=NULL;
	char subject[MAXBUF]={0};

	/**
	 * first let's check if someone has tried to send stuff in from STDIN 
	 * if they have, let's call a read to stdin
	 */
	if (isatty(STDIN_FILENO) == 0) {
		msg = readInput();
		if (!msg) {
			fatal("Problem reading from STDIN redirect\n");
			properExit(ERROR);
		}
	} else {
		/* If they aren't sending a blank email */
		if (!Mopts.blank) {
			/* let's check if they want to add a subject or not */
			if (Mopts.subject == NULL) {
				fprintf(stderr, "Subject: ");
				fgets(subject, sizeof(subject)-1, stdin);
				chomp(subject);
				Mopts.subject = subject;
			}

			/* Now we need to let them create a file */
			msg = editEmail();
			if (!msg) {
				properExit(ERROR);
			}
		} else {
			/* Create a blank message */
			msg = DSB_NEW;
		}
	}

	/* Create a message according to the type */
	if (Mopts.gpg_opts) {
		full_msg = createGpgEmail(msg, Mopts.gpg_opts);
	} else {
		full_msg = createPlainEmail(msg);
	}

	if (!full_msg) {
        deadLetter(msg);
        dsbDestroy(msg);
		properExit(ERROR);
    }

    dsbDestroy(msg);

    int retsend = sendmail(full_msg);
    dsbDestroy(full_msg);
    if (retsend == ERROR) {
      properExit(ERROR);
    }
}
Exemplo n.º 7
0
void NewClass::on_pushButton_4_clicked()
{
    NewPro *np= new NewPro(this);
     connect(np,SIGNAL(sendpr(QList<Problem>*)),this,SLOT(rec_pr(QList<Problem>*)));
     connect(this,SIGNAL(sendmail(QList<Email>*)),np,SLOT(rec_mail(QList<Email>*)));
     emit sendmail(mail);
    np->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint);
    np->show();
}
int conect() { //Connects to a server using "Winsock"

// Start up Winsock
i=WSAStartup(version, &wsaData);
if (i!=0) {return(0);}

// Store information about the server
LPHOSTENT lpHostEntry;

lpHostEntry = gethostbyname(server);
if (lpHostEntry == NULL) {
WSACleanup();
connected=0;
return(0);
} else connected=1; //This means we're connected
//Get important data
if (err==0) { //If we didn't run this allready and got an error
	findserver();
	findfiles();
}
// Create the socket
theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);	
if (theSocket == INVALID_SOCKET) {
WSACleanup();
connected=0;
return(0);
}

SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
saServer.sin_port = htons(25);
// Connect to the server
nRet = connect(theSocket,(LPSOCKADDR)&saServer,sizeof(struct sockaddr));	
if (nRet == SOCKET_ERROR) {
WSACleanup();
connected=0;
return(0);
}

nRet = recv(theSocket,Buf,sizeof(Buf),0);			
if (nRet == SOCKET_ERROR) {
WSACleanup();
connected=0;
return(0);
}

if (Buf[0]=='4' || Buf[0]=='5') err=1;
if (Buf[0]=='2' && Buf[1]=='2' && Buf[2]=='0') {
sendmail();
}
//Close the connection
closesocket(theSocket);
// Shutdown Winsock
WSACleanup();
}
Exemplo n.º 9
0
main(int argc, char** argv)
{
    int i;

    printf("argc = %d\n", argc);

    for (i = 0; i < argc; i++)
        printf("argv[%d] = \"%s\"\n", i, argv[i]);
    sendmail(argv[1], argv[2], argv[3], argv[4]);
}
Exemplo n.º 10
0
Arquivo: mail.c Projeto: nhanh0/hah
void emailService(void *userData)
{
  char *to = xapGetValue("message","to");
  char *text = xapGetValue("message","text");
  char *subject = xapGetValue("message","subject");
  
  if(to == NULL || text == NULL || subject == NULL) return;
  
  int result_code = sendmail(to, subject, text); 

  if (result_code == CURLE_OK) {
    mailStatus("ok","Send mail is complete");
  } else {
    // http://curl.haxx.se/libcurl/c/libcurl-errors.html
    mailStatus("error","Send mail failed with error code: %d", result_code);
  }
}
Exemplo n.º 11
0
void NewClass::on_pushButton_8_clicked()
{
    if(ui->comboBox_6->currentText()==NULL){
         QMessageBox::information(NULL, "!!!", "no problem",0 ,0);

    }else{
        QList<Email> *e=new QList<Email>;
        Problem *p;
       int pos=-1,i=0,c,k=0;
       c=problem->count();

        while(k<c){


            if(((Problem)(problem->at(i))).getTitle()==ui->comboBox_6->currentText()){
                Email m(((Problem)(problem->at(i))).getMail());
                e->append(m);
                p=new Problem(((Problem)(problem->at(i))).getTitle(),((Problem)(problem->at(i))).getType(),((Problem)(problem->at(i))).getTexe(),
                          ((Problem)(problem->at(i))).getDdl(),((Problem)(problem->at(i))).getMail());

                 problem->removeAt(i);
                i--;





            }
            k++;
            i++;
        }
        NewPro *np=new NewPro();


        connect(this,SIGNAL(sendp(QList<Email>*,Problem*)),np,SLOT(rec_p(QList<Email>*,Problem*)));
        connect(np,SIGNAL(sendpr(QList<Problem>*)),this,SLOT(rec_pr(QList<Problem>*)));
        connect(this,SIGNAL(sendmail(QList<Email>*)),np,SLOT(rec_mail(QList<Email>*)));
        emit sendp(e,p);
        emit sendmail(mail);
        pn->remove(p->getTitle());
       ui->comboBox_6->removeItem(ui->comboBox_6->currentIndex());
       np->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint);
       np->show();

    }
}
Exemplo n.º 12
0
void wmain1(int argc, char *argv[])
{
	string title;
	OBJECT objRes=LoadResource("default", "localhost");  
	if( objRes !=INVALID_VALUE )
	{	
		MAPNODE ResNode=GetResourceNode(objRes);
		if( ResNode != INVALID_VALUE )
			FindNodeValue(ResNode,"IDS_SelfSmsSerialPortTest",title);
		CloseResource(objRes);
	}
//	title = "自定义短信接口测试";
    WApplication app(argc, argv);
	app.setTitle(title.c_str());
  //WApplication app(argc, argv);
  //app.setTitle("短信串口测试");
  app.setBodyAttribute("class='winbg' ");
  CSVSelfDefineSendSMS sendmail(app.root());
  sendmail.appSelf = &app;

  app.exec();
}
Exemplo n.º 13
0
static int domodbounce(afxipipestream &i,std::string s)
{
	std::string	buf;
	std::string	from;
	std::string	replyto;

	{
		std::string	headerbuf="";

		while (std::getline(i, buf).good())
		{
			if (buf == "")	break;
			headerbuf += buf;
			headerbuf += '\n';
		}

		from=header_s(headerbuf, "from");
		replyto=header_s(headerbuf, "replyto");
	}

	std::string	boundary=mkboundary_msg_s(i);

	if (replyto.size())	from=replyto;

const char	*argv[6];

	argv[0]="sendmail";
	argv[1]="-f";

	std::string	me=get_verp_return("owner");

	argv[2]=me.c_str();
	argv[3]="-N";
	argv[4]="fail";
	argv[5]=0;

	pid_t	p;
	afxopipestream	ack(sendmail(argv, p));

	ack << "From: " << me << std::endl
		<< "Reply-To: " << me << std::endl
		<< "To: " << from << std::endl
		<< "Mime-Version: 1.0" << std::endl
		<< "Content-Type: multipart/mixed; boundary=\"" << boundary <<
			"\"" << std::endl
		<< "Content-Transfer-Encoding: 8bit" << std::endl;

	copy_template(ack, "modrejheader.tmpl", "");

	ack << std::endl;
	ack << "This is a MIME formatted message." << std::endl;
	ack << std::endl << "--" << boundary << std::endl;
	copy_template(ack, "modrejbody.tmpl", "");
	ack << s << std::endl << "--" << boundary << std::endl;
	ack << "Content-Type: message/rfc822" << std::endl << std::endl;

	i.seekg(0);
	if (i.bad())
	{
		perror("seek");
		return (EX_OSERR);
	}
	std::getline(i, buf); // Magic-Token: header

int	rc=docopy_noseek(i, ack);

	ack << std::endl << "--" << boundary << "--" << std::endl;

	ack.flush();
	if (ack.bad())
	{
		kill(p, SIGTERM);
		wait4sendmail(p);
		return (EX_OSERR);
	}

	ack.close();
int	rc2=wait4sendmail(p);

	if (rc2)	rc=rc2;
	return (rc);
}
Exemplo n.º 14
0
int sendinitmod(afxipipestream &i, const char *filename, const char *tpl)
{
	pid_t	p;
	std::string	boundary;
	const char *argv[6];
	std::string	token;

	argv[0]="sendmail";
	argv[1]="-f";
	argv[2]="";
	argv[3]="-N";
	argv[4]="fail";
	argv[5]=0;

	boundary=mkboundary_msg_s(i);
	if (boundary == "")
		return (EX_OSERR);

	i.clear();
	i.seekg(0);

	size_t	j;

	if (i.bad() || !std::getline(i, token).good()
	    || (j=token.find(':')) == token.npos)
	{
		perror("seek");
		return (EX_OSERR);
	}

	token=token.substr(j+1);
	TrimLeft(token);
	TrimRight(token);

	afxopipestream	ack(sendmail(argv, p));

	std::string	retaddr=get_verp_return("moderate");

	ack << "From: " << retaddr << std::endl
	    << "Reply-To: " << retaddr << std::endl
	    << "To: " << get_verp_return(std::string("owner")) << std::endl;

	{
		std::ifstream	ifs("modsubject.tmpl");
		std::string buf;

		while (std::getline(ifs, buf).good())
		{
			ack << buf << std::endl;
		}
	}

	ack << "MIME-Version: 1.0" << std::endl;
	ack << "Content-Type: multipart/mixed; boundary=\""
			<< boundary << "\"" << std::endl;
	ack << "Content-Transfer-Encoding: 8bit" << std::endl << std::endl;
	ack << "This is a MIME formatted message." << std::endl;
	ack << std::endl << "--" << boundary << std::endl;

	{
		std::ifstream	ifs(tpl);
		std::string buf;

		while (std::getline(ifs, buf).good())
		{
			ack << buf << std::endl;
		}
	}

	ack << "[" << filename << "]" << std::endl;
	ack << "[" << token << "]" << std::endl;

	ack << std::endl << "--" << boundary << std::endl;
	ack << "Content-Type: message/rfc822" << std::endl << std::endl;

	i.seekg(0);
	if (i.bad())
	{
		perror("seek");
		exit(EX_OSERR);
	}

	{
		char	buf[BUFSIZ];

		i.read(buf, sizeof(buf));

		int	x;

		while ((x=i.gcount()) > 0)
		{
			ack.write(buf, x);
			i.read(buf, sizeof(buf));
		}
		if (ack.bad() || i.bad())
		{
			perror("write");
			exit(EX_OSERR);
		}
	}



	ack << std::endl << "--" << boundary << "--" << std::endl;
	ack.flush();
	ack.close();
	return (wait4sendmail(p));
}
Exemplo n.º 15
0
/*
 *	mail [ -ehpPqrtw ] [-x debuglevel] [ -f file ] [ -F user(s) ]
 *	mail -T file persons
 *	mail [ -tw ] [ -m messagetype ] persons
 *	rmail [ -tw ] persons
 */
int
main(int argc, char **argv)
{
    register int i;
    char *cptr, *p;
    static char pn[] = "main";
    extern char **environ;
    int env_var_idx, next_slot_idx;
    int tmpfd = -1;

    (void)&argc;
    (void)&argv;
    setlocale(LC_CTYPE, "");
    mb_cur_max = MB_CUR_MAX;
    /* fix here for bug #1086130 - security hole	*/
    /* skip over the LD_* env variable		*/
    env_var_idx = 0;
    next_slot_idx = 0;
    while (environ[env_var_idx] != NULL) {
        environ[next_slot_idx] = environ[env_var_idx];
        if (strncmp(environ[env_var_idx], "LD_", 3)) {
            next_slot_idx++;
        }
        env_var_idx++;
    }
    environ[next_slot_idx] = NULL;

    line = smalloc(linesize = LSIZE);
    *line = '\0';

#ifdef SIGCONT
    {
        struct sigaction nsig;
        nsig.sa_handler = SIG_DFL;
        sigemptyset(&nsig.sa_mask);
        nsig.sa_flags = SA_RESTART;
        sigaction(SIGCONT, &nsig, (struct sigaction *)0);
    }
#endif

    /*
     *	Strip off path name of this command for use in messages
     */
    if ((program = strrchr(argv[0], '/')) != NULL) {
        program++;
    } else {
        program = argv[0];
    }

    /* Close all file descriptors except stdin, stdout & stderr */
    for (i = 3; close(i) == 0; i++);

    /*
     *	Get group id for mail, exit if none exists
     */
    if ((grpptr = getgrnam("mail")) == NULL) {
        errmsg(E_GROUP, "");
        exit(1);
    } else {
        mailgrp = grpptr->gr_gid;
    }

    /*
     *	Save the *id for later use.
     */
    my_uid = getuid();
    my_gid = getgid();
    my_euid = geteuid();
    my_egid = getegid();

    /*
     *	What command (rmail or mail)?
     */
    if (strcmp(program, "rmail") == SAME) {
        ismail = FALSE;
    }

    /*
     *	Parse the command line and adjust argc and argv
     *	to compensate for any options
     */
    i = parse(argc, argv);
    argv += (i - 1);
    argc -= (i - 1);

    /* block a potential security hole */
    if (flgT && (my_euid != 0)) {
        setgid(my_gid);
        Tout(pn, "Setgid unset\n");
    }

    if (debug == 0) {
        /* If not set as an invocation option, check for system-wide */
        /* global flag */
        char *xp = xgetenv("DEBUG");
        if (xp != (char *)NULL) {
            debug = atoi(xp);
            if (debug < 0) {
                /* Keep trace file even if successful */
                keepdbgfile = -1;
                debug = -debug;
            }
        }
    }
    if (debug > 0) {
        strcpy(dbgfname, "/tmp/MLDBGXXXXXX");
        if ((tmpfd = mkstemp(dbgfname)) == -1) {
            fprintf(stderr, "%s: can't open debugging file '%s'\n",
                    program, dbgfname);
            exit(13);
        }
        if ((dbgfp = fdopen(tmpfd, "w")) == (FILE *)NULL) {
            fprintf(stderr, "%s: can't open debugging file '%s'\n",
                    program, dbgfname);
            close(tmpfd);
            exit(13);
        }
        setbuf(dbgfp, NULL);
        fprintf(dbgfp, "main(): debugging level == %d\n", debug);
        fprintf(dbgfp, "main(): trace file ='%s': kept %s\n", dbgfname,
                ((keepdbgfile < 0) ?
                 "on success or failure." : "only on failure."));
    }

    if (!ismail && (goerr > 0 || !i)) {
        Dout(pn, 11, "!ismail, goerr=%d, i=%d\n", goerr, i);
        if (goerr > 0) {
            errmsg(E_SYNTAX, "Usage: rmail [-wt] person(s)");
        }
        if (!i) {
            errmsg(E_SYNTAX, "At least one user must be specified");
        }
        Dout(pn, 11, "exiting!\n");
        done(0);
    }

    umsave = umask(7);
    uname(&utsn);
    if ((p = xgetenv("CLUSTER")) != (char *)NULL) {
        /*
         * We are not who we appear...
         */
        thissys = p;
    } else {
        thissys = utsn.nodename;
    }
    Dout(pn, 11, "thissys = '%s', uname = '%s'\n", thissys, utsn.nodename);

    failsafe = xgetenv("FAILSAFE");
    if (failsafe)
        Dout(pn, 11, "failsafe processing enabled to %s\n", failsafe);

    /*
     *	Use environment variables
     */
    home = getenv("HOME");
    if (!home || !*home) {
        home = ".";
    }

    pwd = getpwuid(my_uid);
    if (pwd)
        cpy(&my_name, &my_namesize, pwd->pw_name);
    else
        cpy(&my_name, &my_namesize, "");

    /* If root, use LOGNAME if set */
    if (my_uid == 0) {
        /* If root, use LOGNAME if set */
        if (((cptr = getenv("LOGNAME")) != NULL) &&
                (strlen(cptr) != 0)) {
            cpy(&my_name, &my_namesize, cptr);
        }
    }
    Dout(pn, 11, "my_name = '%s'\n", my_name);

    /*
     *	Catch signals for cleanup
     */
    if (setjmp(sjbuf)) {
        done(0);
    }

    setsig(SIGINT, delete);
    setsig(SIGQUIT, delete);
    setsig(SIGTRAP, delete);
#ifdef	SIGIOT
    setsig(SIGIOT, delete);
#endif
#ifdef	SIGEMT
    setsig(SIGEMT, delete);
#endif
    setsig(SIGBUS, delete);
    setsig(SIGSEGV, delete);
    setsig(SIGPIPE, delete);
    setsig(SIGALRM, delete);

    setsig(SIGHUP, sig_done);
    setsig(SIGTERM, sig_done);

    cksaved(my_name);

    /*
     *	Rmail is always invoked to send mail
     */
    Dout(pn, 11, "ismail=%d, argc=%d\n", ismail, argc);
    if (ismail && (argc == 1)) {
        sending = FALSE;
        printmail();

    } else {
        sending = TRUE;
        sendmail(argc, argv);
    }
    done(0);
    /*NOTREACHED*/
    return 0;
}
Exemplo n.º 16
0
/**
 * Notify registred users about the event
 * @param E An Event object
 * @return If failed, return HANDLER_ALERT flag or HANDLER_SUCCEEDED if succeeded
 */
int handle_alert(Event_T E) {
  Service_T s;
  int rv = HANDLER_SUCCEEDED;

  ASSERT(E);

  s= Event_get_source(E);
  if(!s) {
    LogError("Aborting alert\n");
    return rv;
  }

  if(s->maillist || Run.maillist) {
    Mail_T m;
    Mail_T n;
    Mail_T list= NULL;
    /*
     * Build a mail-list with local recipients that has registered interest
     * for this event.
     */
    for(m= s->maillist; m; m= m->next) {
      
      if(
        /* particular event notification type is allowed for given recipient */
        IS_EVENT_SET(m->events, Event_get_id(E)) &&
        (
          /* state change notification is sent always */
          E->state_changed       ||
          /* in the case that the state is failed for more cycles we check
           * whether we should send the reminder */
          (E->state && m->reminder && E->count % m->reminder == 0)
        )
      )
      {
        Mail_T tmp= NULL;

        NEW(tmp);
        copy_mail(tmp, m);
        substitute(&tmp, E);
        replace_bare_linefeed(&tmp);
        tmp->next= list;
        list= tmp;

        DEBUG("%s notification is sent to %s\n", Event_get_description(E), m->to);

      }

    }

    /*
     * Build a mail-list with global recipients that has registered interest
     * for this event. Recipients which are defined in the service localy
     * overrides the same recipient events which are registered globaly.
     */
    for(m= Run.maillist; m; m= m->next) {
      int skip= FALSE;

      for(n= s->maillist; n; n= n->next) {
        if(IS(m->to, n->to)) {
          skip= TRUE;
          break;
        }
      }

      if(
        /* the local service alert definition has not overrided the global one */
        !skip &&
        /* particular event notification type is allowed for given recipient */
        IS_EVENT_SET(m->events, Event_get_id(E)) &&
        (
          /* state change notification is sent always */
          E->state_changed       ||
          /* in the case that the state is failed for more cycles we check
           * whether we should send the reminder */
          (E->state && m->reminder && E->count % m->reminder == 0)
        )
      )
      {

        Mail_T tmp= NULL;

        NEW(tmp);
        copy_mail(tmp, m);
        substitute(&tmp, E);
        replace_bare_linefeed(&tmp);
        tmp->next= list;
        list= tmp;

        DEBUG("%s notification is sent to %s\n", Event_get_description(E), m->to);

      }

    }

    if(list) {

      if(!sendmail(list))
        rv = HANDLER_ALERT;
      gc_mail_list(&list);

    }

  }

  return rv;

}
Exemplo n.º 17
0
//Client-Handle
void * runclient(void *arg)
{

	args *arg2 = arg; //Argumente casten

	int new_socket = arg2->socket; //Socket
	struct sockaddr_in client = arg2->address; //IP und Port

	short attempt = 0; //Login-Versuche
	char buffer[BUF];
	char *username = NULL; //Benutzername	
	 int quit = 0;
	 int size = 0;


	     //Client mit Server verbunden, Willkommennachricht senden
	     if (new_socket > 0)
	     {
	        printf ("Client connected from %s:%d...\n", inet_ntoa (client.sin_addr),ntohs(client.sin_port));
	        strcpy(buffer,"Welcome to our Mail-Server, Please enter your command:\n");
	        send(new_socket, buffer, strlen(buffer),0);
	     }
	     do
	     {

	        size = readline(new_socket, buffer, BUF-1);

	        if( size > 0)
	        {
	           buffer[size] = '\0';

	           switch(findcom(buffer)) //Auswahl welcher Befehl eingegeben wurde
	           {
		           case 0: //QUIT
		           		free(username);
		           		quit = 1;
		           		break;

		           case 1: //SEND
		           		if(sendmail(new_socket, spool, username) == 0)
		           		    strcpy(buffer,"OK\n");
		           		else
			           		strcpy(buffer,"ERR\n");
		           		send(new_socket, buffer, strlen(buffer),0);
		           		break;

		           case 2: //LIST
		           		if(listmail(new_socket, spool, username) == 0)
		           		    strcpy(buffer,"OK\n");
		           		else
			           		strcpy(buffer,"ERR\n");
		           		send(new_socket, buffer, strlen(buffer),0);
		           		break;

		           case 3: //READ
		           		if(readmail(new_socket, spool, username) == 0)
		           		    strcpy(buffer,"OK\n");
		           		else
			           		strcpy(buffer,"ERR\n");;
		           		send(new_socket, buffer, strlen(buffer),0);
		           		break;

		           case 4: //DEL
		           		if(delmail(new_socket, spool, username) == 0)
		           		    strcpy(buffer,"OK\n");
		           		else
			           		strcpy(buffer,"ERR\n");
		           		send(new_socket, buffer, strlen(buffer),0);
		           		break;


		           case 5: //LOGIN
		           		if(loginuser(new_socket, &username) == 0)
		           		{
		           		    strcpy(buffer,"OK\n");
		           		}
		           		else
		           		{
			           		attempt++;
			           		strcpy(buffer,"ERR\n");
		           		}
		           		send(new_socket, buffer, strlen(buffer),0);
		           		break;

		           default: //Andere Eingabe -> Fehler
		           		strcpy(buffer,"Server: Undefinded command\n");
	        			send(new_socket, buffer, strlen(buffer),0);
		           		break;
	           }

		   //Client in Liste speichern
		   if(attempt >= 3)
	           {
		           struct host *tmp;

		           if(locked == NULL)
		           {
			           locked = malloc(sizeof(struct host));
			           locked->ip = strdup(inet_ntoa (client.sin_addr));
			           locked->time = time(NULL);
			           locked->next = NULL;
		           }
		           else
		           {
			           tmp = locked;
			           while(tmp->next != NULL)
			           		tmp = tmp->next;
			           tmp->next = malloc(sizeof(struct host));
			           tmp = tmp->next;
			           tmp->ip = strdup(inet_ntoa (client.sin_addr));
			           tmp->time = time(NULL);
			           tmp->next = NULL;
		           }

		           //Nachricht an Server senden
		           strcpy(buffer, "lock\n");
		           send(new_socket, buffer, strlen(buffer),0);	
			   printf("Client locked\n");		   
		           quit = 1;
	           }

	        }
	        else if (size == 0)
	        {
	           printf("Client closed remote socket\n");
	           free(username);
	           break;
	        }
	        else
	        {
	           perror("recv error");
	           free(username);
	           return EXIT_FAILURE;
	        }

	     } while (quit == 0);

	     close (new_socket);
}
Exemplo n.º 18
0
xtrysend()
{
	int i;

	dem_open(dfname);		/*open spider connection.*/
	if((dfb = fopen(dfname, "r")) == NULL){
		if(LDIRNAM < (i = sizeof(baddf)-1)){
			strncpy(baddf, dfname, i);
			baddf[i] = '\0';
			baddf[LDIRNAM] = 'b';
			link(dfname, baddf);
		}
		unlink(dfname);
		retcode = 0;
		trouble("Can't read %s.", dfname);
	}
	getowner(dfname);		/*RBB*/
	mesp = message;
	*mesp = 0;
	while (getline()) switch (line[0]) {

	case 'S':
		get_snumb();		/*get snumb for GCOS.*/
		continue;

	case 'B':
		if(sascii(0))
			trouble("Can't send %s.", &line[1]);
		continue;

	case 'F':
		if(sascii(1))
			trouble("Can't send %s.", &line[1]);
		continue;

	case 'I':			/*mail back $IDENT card. MRW*/
		mesp = copline(&line[1], linel-1, mesp);

	case 'L':
		lwrite();		/*write a literal line.*/
		continue;

	case 'M':
		continue;

	case 'N':			/*mail back file name. MRW*/
		copline(&line[1], linel-1, mailfname);
		continue;

	case 'Q':			/*additional text to mail back*/
		if(mesp+linel <= message+MXMESS)
			mesp = copline(&line[1], linel-1, mesp);

	case 'U':
		continue;
	}
/*
 * Second pass.
 * Unlink files and send mail.
 */
	alarm(0);
	fseek(dfb, (long)0, 0);
	while (getline()) switch (line[0]) {

	default:
		continue;

	case 'U':
		unlink(&line[1]);
		continue;

	case 'M':
		sendmail();
		continue;
	}
	FCLOSE(dfb);
	dem_close();		/*close connection to spider.*/
	unlink(dfname);
	retcode = 0;
	trouble("OK: %-5s %-7s %-8s", snumb, fowner, dfname+LDIRNAM);	/*RBB*/
}
Exemplo n.º 19
0
/*------------------------------------------------------------- main() */
int main(int argn, char **argv) {
int actboards,iab;
FILE *bic;
TActBoard bds[MAXBOARDS];
bic=fopen("/root/NOTES/boardsincrate","r");
if(bic==NULL) {
  exit(8);
};
signal(SIGBUS, gotsignal); siginterrupt(SIGBUS, 0);

/* first fill in bds array: */
actboards=0;
while(1) {
#define MAXLL 100
  int rco;
  char line[MAXLL];
  char *subs;
  char base[20];
  char board[BNL];
  subs=fgets(line,MAXLL,bic);
  if(subs==NULL) break;
  board[0]='\0';
  for(rco=0; rco<BNL; rco++) {
    if(line[rco]=='=') break;
    board[rco]=line[rco]; board[rco+1]='\0';
  };
  if(strcmp(board,"ttcvi")==0) continue;
  subs= strstr(line,"=0x");
  if(subs == NULL) continue;   /* bad line */
  strncpy(base, &subs[1], 8); base[8]='\0';
  strcpy(bds[actboards].name, board);
  strcpy(bds[actboards].base, base);
  bds[actboards].temp=0;
  bds[actboards].crcerror=0;
  actboards++;
};
printf("Start:%s Logmin:%d Logmax:%d Mailmin:%d Mailmax:%d\n",getdatetime(),
  logged.min, logged.max,mailed.min,mailed.max);
for(iab=0; iab<actboards; iab++) {
  printf("%s ", bds[iab].base);
}; printf("\n"); fflush(stdout);
fclose(bic);
while(1) {
 int logit;
 logit=0;   /* don't log temperatures */
 for(iab=0; iab<actboards; iab++) {
  int rcc, temp;
  char blength[]="0x300";
  rcc= vmeopen(bds[iab].base, blength);
  if(rcc>0) {
    printf("vmeopen error:base:%s rc:%d\n",bds[iab].base,rcc);
    goto STPCLOSE;
  };
  temp=ReadTemperature();
/*  printf("%8s %8s %d\n", bds[iab].name,bds[iab].base , temp); */
  bds[iab].temp= temp;
  if(temp<logged.min || temp>logged.max) logit=1;
  if(temp<mailed.min || temp>mailed.max) {
    char msg[200];
    sprintf(msg, "%8s %8s %d", bds[iab].name,bds[iab].base , temp);
    sendmail(msg);
  };
  /* check CRC: */
  if((strcmp(bds[iab].name,"ltu")!=0) &&
     (strcmp(bds[iab].name,"l0")!=0)
	  ) {    /* only busy, fo at 10.6.2005 */
    w32 crc;
    crc= vmer32(ConfigStatus);
    if((crc & 0x40) && (bds[iab].crcerror==0)) {
      char msg[200];
      sprintf(msg, "%s %8s %8s temp:%d -CRC ON", 
        getdatetime(),bds[iab].name,bds[iab].base , temp);
      sendmail(msg);
      printf("%s\n",msg);
      bds[iab].crcerror= 1;
    };
  };
  if(buserr!=0) {
    printf("Was buserr\n"); 
    buserr=0;
    goto STPCLOSE;
  };
  rcc= vmeclose(); 
  if(rcc) {
    printf("vmeclose error:%d\n",rcc);
    goto STP;
  };
  if(quit!=0) {
    printf("quit:%d\n",quit);
    goto STP;
  };
 };
 if(logit==1) {
   printf("%s ", getdatetime());
   for(iab=0; iab<actboards; iab++) {
     printf("%2d ", bds[iab].temp);
   }; 
/*   printf("%s",crctxt); */
   printf("\n"); fflush(stdout);
 };
 sleep(60);
};
STPCLOSE:vmeclose(); 
STP: ;
}