Example #1
0
int main(int argc, char* argv[]){
	char cmd[512];
	
	print_menu();
	fgets(cmd,512,stdin);

	printf("%s\n\n\n",cmd);

	while(!strcmp(cmd,"exit")){
		
		
		int pid=fork();
		if(pid==-1){
			printf("fork error\n");
		}
		else if(pid==0){
			printf("this is child with pid: %d\n",getpid());
			printf("parent pid is: %d\n",getppid());
			printf("////////////////////////////////////////////\n");
			startcmd(cmd);
			exit(1);	
		}
		else {
			printf("this is parent with pid: %d\n",getpid());
			printf("waiting\n");
			printf("///////////////////////////////////////////\n");
			wait();
			printf("returned to parent with pid: %d\n",getpid());
			printf("///////////////////////////////////////////\n");
		}
		print_menu();
		//cmd=NULL;
		//getline(scmd,512);
		fgets(cmd,512,stdin);
	}
	printf("exiting program\n");
}
Example #2
0
void
data(void)
{
	int status, nbytes;
	char *cp, *ep;
	char errx[ERRMAX];
	Link *l;
	String *cmd, *err;

	if(rejectcheck())
		return;
	if(senders.last == 0){
		reply("503 2.5.2 Data without MAIL FROM:\r\n");
		rejectcount++;
		return;
	}
	if(rcvers.last == 0){
		reply("503 2.5.2 Data without RCPT TO:\r\n");
		rejectcount++;
		return;
	}
	if(!trusted && sendermxcheck()){
		rerrstr(errx, sizeof errx);
		if(strncmp(errx, "rejected:", 9) == 0)
			reply("554 5.7.1 %s\r\n", errx);
		else
			reply("450 4.7.0 %s\r\n", errx);
		for(l=rcvers.first; l; l=l->next)
			syslog(0, "smtpd", "[%s/%s] %s -> %s sendercheck: %s",
				him, nci->rsys, s_to_c(senders.first->p),
				s_to_c(l->p), errx);
		rejectcount++;
		return;
	}

	cmd = startcmd();
	if(cmd == 0)
		return;

	reply("354 Input message; end with <CRLF>.<CRLF>\r\n");
	if(debug){
		seek(2, 0, 2);
		stamp();
		fprint(2, "# sent 354; accepting DATA %s\n", thedate());
	}


	/*
	 *  allow 145 more minutes to move the data
	 */
	alarm(145*60*1000);

	status = pipemsg(&nbytes);

	/*
	 *  read any error messages
	 */
	err = s_new();
	if (debug) {
		stamp();
		fprint(2, "waiting for upas/send to close stderr\n");
	}
	while(s_read_line(pp->std[2]->fp, err))
		;

	alarm(0);
	atnotify(catchalarm, 0);

	if (debug) {
		stamp();
		fprint(2, "waiting for upas/send to exit\n");
	}
	status |= proc_wait(pp);
	if(debug){
		seek(2, 0, 2);
		stamp();
		fprint(2, "# %d upas/send status %#ux at %s\n",
			getpid(), status, thedate());
		if(*s_to_c(err))
			fprint(2, "# %d error %s\n", getpid(), s_to_c(err));
	}

	/*
	 *  if process terminated abnormally, send back error message
	 */
	if(status){
		int code;
		char *ecode;

		if(strstr(s_to_c(err), "mail refused")){
			syslog(0, "smtpd", "++[%s/%s] %s %s refused: %s",
				him, nci->rsys, s_to_c(senders.first->p),
				s_to_c(cmd), firstline(s_to_c(err)));
			code = 554;
			ecode = "5.0.0";
		} else {
			syslog(0, "smtpd", "++[%s/%s] %s %s %s%s%sreturned %#q %s",
				him, nci->rsys,
				s_to_c(senders.first->p), s_to_c(cmd),
				piperror? "error during pipemsg: ": "",
				piperror? piperror: "",
				piperror? "; ": "",
				pp->waitmsg->msg, firstline(s_to_c(err)));
			code = 450;
			ecode = "4.0.0";
		}
		for(cp = s_to_c(err); ep = strchr(cp, '\n'); cp = ep){
			*ep++ = 0;
			reply("%d-%s %s\r\n", code, ecode, cp);
		}
		reply("%d %s mail process terminated abnormally\r\n",
			code, ecode);
	} else {
		/*
		 * if a message appeared on stderr, despite good status,
		 * log it.  this can happen if rewrite.in contains a bad
		 * r.e., for example.
		 */
		if(*s_to_c(err))
			syslog(0, "smtpd",
				"%s returned good status, but said: %s",
				s_to_c(mailer), s_to_c(err));

		if(filterstate == BLOCKED)
			reply("554 5.7.1 we believe this is spam.  "
				"we don't accept it.\r\n");
		else if(filterstate == DELAY)
			reply("450 4.3.0 There will be a delay in delivery "
				"of this message.\r\n");
		else {
			reply("250 2.5.0 sent\r\n");
			logcall(nbytes);
			if(debug){
				seek(2, 0, 2);
				stamp();
				fprint(2, "# %d sent 250 reply %s\n",
					getpid(), thedate());
			}
		}
	}
	proc_free(pp);
	pp = 0;
	s_free(cmd);
	s_free(err);

	listfree(&senders);
	listfree(&rcvers);
}
Example #3
0
void
fromnet(Conn *c)
{
	int infd, kidpid, n;
	char *cmd;
	Msg *m;

	infd = kidpid = -1;
	for(;;){
		m = recvmsg(c, -1);
		if(m == nil)
			exits(nil);
		switch(m->type){
		default:
			//badmsg(m, 0);
			sendmsg(allocmsg(c, SSH_SMSG_FAILURE, 0));
			break;

		case SSH_MSG_DISCONNECT:
			sysfatal("client disconnected");

		case SSH_CMSG_REQUEST_PTY:
			sendmsg(allocmsg(c, SSH_SMSG_SUCCESS, 0));
			break;

		case SSH_CMSG_X11_REQUEST_FORWARDING:
			sendmsg(allocmsg(c, SSH_SMSG_FAILURE, 0));
			break;

		case SSH_CMSG_MAX_PACKET_SIZE:
			maxmsg = getlong(m);
			sendmsg(allocmsg(c, SSH_SMSG_SUCCESS, 0));
			break;

		case SSH_CMSG_REQUEST_COMPRESSION:
			sendmsg(allocmsg(c, SSH_SMSG_FAILURE, 0));
			break;

		case SSH_CMSG_EXEC_SHELL:
			startcmd(c, nil, &kidpid, &infd);
			goto InteractiveMode;

		case SSH_CMSG_EXEC_CMD:
			cmd = getstring(m);
			startcmd(c, cmd, &kidpid, &infd);
			goto InteractiveMode;
		}
		free(m);
	}

InteractiveMode:
	for(;;){
		free(m);
		m = recvmsg(c, -1);
		if(m == nil)
			exits(nil);
		switch(m->type){
		default:
			badmsg(m, 0);

		case SSH_MSG_DISCONNECT:
			postnote(PNGROUP, kidpid, "hangup");
			sysfatal("client disconnected");

		case SSH_CMSG_STDIN_DATA:
			if(infd != 0){
				n = getlong(m);
				write(infd, getbytes(m, n), n);
			}
			break;

		case SSH_CMSG_EOF:
			close(infd);
			infd = -1;
			break;

		case SSH_CMSG_EXIT_CONFIRMATION:
			/* sent by some clients as dying breath */
			exits(nil);
	
		case SSH_CMSG_WINDOW_SIZE:
			/* we don't care */
			break;
		}
	}
}
Example #4
0
File: main.c Project: npe9/harvey
void
threadmain(int argc, char *argv[])
{
	int i, j;
	char *dir, *tag, *name;
	char buf[1024], **av;

	quotefmtinstall();
	rfork(RFNAMEG);
	ARGBEGIN{
	case 'd':
		debug = 1;
		chatty9p++;
		break;
	case 'e':
		eraseinput = 1;
		break;
	case 'D':
{extern int _threaddebuglevel;
		_threaddebuglevel = 1<<20;
}
	}ARGEND

	if(argc == 0){
		av = emalloc(3*sizeof(char*));
		av[0] = "rc";
		av[1] = "-i";
		name = getenv("sysname");
	}else{
		av = argv;
		name = utfrrune(av[0], '/');
		if(name)
			name++;
		else
			name = av[0];
	}

	if(getwd(buf, sizeof buf) == 0)
		dir = "/";
	else
		dir = buf;
	dir = estrdup(dir);
	tag = estrdup(dir);
	tag = eappend(estrdup(tag), "/-", name);
	win = newwindow();
	snprint(buf, sizeof buf, "%d", win->id);
	putenv("winid", buf);
	winname(win, tag);
	wintagwrite(win, "Send Noscroll", 5+8);
	threadcreate(mainctl, win, STACK);
	mountcons();
	threadcreate(fsloop, nil, STACK);
	startpipe();
	startcmd(av, &notepg);

	strcpy(buf, "win");
	j = 3;
	for(i=0; i<argc && j+1+strlen(argv[i])+1<sizeof buf; i++){
		strcpy(buf+j, " ");
		strcpy(buf+j+1, argv[i]);
		j += 1+strlen(argv[i]);
	}

	ctlprint(win->ctl, "scroll");
	winsetdump(win, dir, buf);
}