Beispiel #1
0
static int try_mail_dotlock(const char *dotlock, char *idbuf)
{
	char timebuf[NUMBUFSIZE];
	char pidbuf[NUMBUFSIZE];
	char *tmpname;
	int rc;

	libmail_str_time_t(time(NULL), timebuf);
	libmail_str_pid_t(getpid(), pidbuf);

	tmpname=malloc(strlen(dotlock) + strlen(timebuf) + strlen(pidbuf) +
		       strlen(idbuf) + 10);

	if (!tmpname)
		return -1;

	strcpy(tmpname, dotlock);
	strcat(tmpname, ".");
	strcat(tmpname, timebuf);
	strcat(tmpname, ".");
	strcat(tmpname, pidbuf);
	strcat(tmpname, ".");
	strcat(tmpname, strchr(idbuf, ':')+1);

	rc=try_dotlock(tmpname, dotlock, idbuf);
	free(tmpname);
	return (rc);
}
Beispiel #2
0
static void acctout(const char *disc)
{
	static const char msg2[]=", user="******", ip=[";
	static const char msgport[]="], port=[";
	static const char msg4[]="], top=";
	static const char msg5[]=", retr=";
	static const char msg6[]=", time=";
	static const char msg7[]=", stls=1";
	static const char msgAR[]=", rcvd=";
	static const char msgAS[]=", sent=";

	char num1[NUMBUFSIZE];
	char num2[NUMBUFSIZE];
	char num3[NUMBUFSIZE];
	char numAR[NUMBUFSIZE];
	char numAS[NUMBUFSIZE];

	char *p;
	const char *q;

	libmail_str_size_t(top_count, num1);
	libmail_str_size_t(retr_count, num2);
	libmail_str_time_t(time(NULL)-start_time, num3);
	libmail_str_size_t(bytes_received_count, numAR);
	libmail_str_size_t(bytes_sent_count, numAS);

	p=malloc(strlen(authaddr)+strlen(remoteip)+strlen(remoteport)+strlen(disc)+
		 strlen(num1)+strlen(num2)+strlen(num3)+
		 strlen(numAR)+strlen(numAS)+200);	/* Should be enough */

	strcpy(p, disc);
	strcat(p, msg2);
	strcat(p, authaddr);
	strcat(p, msg3);
	strcat(p, remoteip);
	strcat(p, msgport);
	strcat(p, remoteport);
	strcat(p, msg4);
	strcat(p, num1);
	strcat(p, msg5);
	strcat(p, num2);
	strcat(p, msgAR);
	strcat(p, numAR);
	strcat(p, msgAS);
	strcat(p, numAS);
	strcat(p, msg6);
	strcat(p, num3);

	if ((q=getenv("POP3_TLS")) && atoi(q))
		strcat(p, msg7);

	strcat(p, "\n");
	if (write(2, p, strlen(p)) < 0)
		; /* make gcc shut up */
	free(p);
}
Beispiel #3
0
static char *make_track_filename(const char *trackdir,
				 time_t offset)
{
	char *namebuf;
	char buf2[NUMBUFSIZE];

	libmail_str_time_t(offset, buf2);

	namebuf=malloc(strlen(trackdir)+strlen(buf2)+2);

	if (!namebuf)
		return NULL;

	strcat(strcat(strcpy(namebuf, trackdir), "/"), buf2);

	return namebuf;
}
Beispiel #4
0
char *rfc2045_mk_boundary(struct rfc2045 *s, int fd)
{
char	hostnamebuf[256];
pid_t	mypid;
char	pidbuf[NUMBUFSIZE];
time_t	mytime;
char	timebuf[NUMBUFSIZE];
static size_t	cnt=0;
char	cntbuf[NUMBUFSIZE];
char	*p;
int	rc;

	hostnamebuf[sizeof(hostnamebuf)-1]=0;
	if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
		hostnamebuf[0]=0;
	mypid=getpid();
	time(&mytime);
	libmail_str_pid_t(mypid, pidbuf);
	libmail_str_time_t(mytime, timebuf);
	for (;;)
	{
		char tempbuf[NUMBUFSIZE];

		libmail_str_size_t(++cnt, tempbuf);
		sprintf(cntbuf, "%4s", tempbuf);
		for (p=cntbuf; *p == ' '; *p++ = '0')
			;
		p=malloc(strlen(hostnamebuf)+strlen(pidbuf)
			 +strlen(timebuf)+strlen(cntbuf)+11);
		if (!p)
		{
			rfc2045_enomem();
			return (NULL);
		}

		sprintf(p, "=_%s-%s-%s-%s", hostnamebuf,
			pidbuf, timebuf, cntbuf);
		if ((rc=rfc2045_try_boundary(s, fd, p)) == 0)
			break;
		free(p);
		if (rc < 0)
			return (NULL);
	}
	return (p);
}
Beispiel #5
0
static void track_save_record(const char *trackdir,
			      const char *address, int status,
			      char *(*ulower)(const char *),
			      int autopurge)
{
	char buf2[NUMBUFSIZE];
	FILE *fp;
	time_t curTime=time(NULL);
	time_t t=curTime / 3600;
	char *addrbuf=ulower(address);
	struct stat stat_buf;
	char *namebuf;

	namebuf=make_track_filename(trackdir, t);

	if (namebuf)
	{
		if (autopurge && stat(namebuf, &stat_buf))
		{
			dopurge(trackdir);
		}

		if (stat(trackdir, &stat_buf) == 0 &&
		    stat_buf.st_uid == geteuid())
			/*
			** Sanity check: avoid creating root-owner files, if
			** verifysmtp is executed by root.
			*/
		{
			fp=fopen(namebuf, "a");

			libmail_str_time_t(curTime, buf2);

			if (fp)
			{
				fprintf(fp, "%s %c%s\n", buf2, (char)status,
					addrbuf);
				fclose(fp);
			}
		}
		free(namebuf);
	}
	free(addrbuf);
}
Beispiel #6
0
void bye_msg(const char *type)
{
	const char *a=getenv("AUTHENTICATED");
	char buf[NUMBUFSIZE];
	const char *tls=getenv("IMAP_TLS");

	libmail_str_time_t(time(NULL)-start_time, buf);

	if (tls && atoi(tls))
		tls=", starttls=1";
	else
		tls="";

	if (a && *a)
		fprintf(stderr, "%s, user=%s, "
			"ip=[%s], headers=%lu, body=%lu, rcvd=%lu, sent=%lu, time=%s%s\n",
			type,
			a, getenv("TCPREMOTEIP"), header_count, body_count, bytes_received_count, bytes_sent_count,
			buf, tls);
	else
		fprintf(stderr, "DEBUG: Disconnected, ip=[%s], time=%s%s\n",
			getenv("TCPREMOTEIP"),
			buf, tls);
}
static int maildir_tmpcreate_fd_do(struct maildir_tmpcreate_info *info)
{
	const char *maildir=info->maildir;
	const char *uniq=info->uniq;
	const char *hostname=info->hostname;

	char hostname_buf[256];
	char time_buf[NUMBUFSIZE];
	char usec_buf[NUMBUFSIZE];
	char pid_buf[NUMBUFSIZE];
	char len_buf[NUMBUFSIZE+3];
	char dev_buf[NUMBUFSIZE];
	char ino_buf[NUMBUFSIZE];
	struct timeval tv;

	struct stat stat_buf;
	int fd;

	if (!maildir)
		maildir=".";
	if (!uniq)
		uniq="";

	if (!hostname || !*hostname)
	{
		hostname_buf[sizeof(hostname_buf)-1]=0;
		if (gethostname(hostname_buf, sizeof(hostname_buf)-1) < 0)
			strcpy(hostname_buf, "localhost");
		hostname=hostname_buf;
	}

	gettimeofday(&tv, NULL);

	libmail_str_time_t(tv.tv_sec, time_buf);
	libmail_str_time_t(tv.tv_usec, usec_buf);
	libmail_str_pid_t(getpid(), pid_buf);
	len_buf[0]=0;
	if (info->msgsize > 0)
	{
		strcpy(len_buf, ",S=");
		libmail_str_size_t(info->msgsize, len_buf+3);
	}

	if (info->tmpname)
		free(info->tmpname);

	info->tmpname=malloc(strlen(maildir)+strlen(uniq)+
			     strlen(hostname)+strlen(time_buf)+
			     strlen(usec_buf)+
			     strlen(pid_buf)+strlen(len_buf)+100);

	if (!info->tmpname)
	{
		maildir_tmpcreate_free(info);
		return -1;
	}

	strcpy(info->tmpname, maildir);
	strcat(info->tmpname, "/tmp/");
	strcat(info->tmpname, time_buf);
	strcat(info->tmpname, ".M");
	strcat(info->tmpname, usec_buf);
	strcat(info->tmpname, "P");
	strcat(info->tmpname, pid_buf);

	if (*uniq)
		strcat(strcat(info->tmpname, "_"), uniq);
	strcat(info->tmpname, ".");
	strcat(info->tmpname, hostname);
	strcat(info->tmpname, len_buf);

	if (stat( info->tmpname, &stat_buf) == 0)
	{
		maildir_tmpcreate_free(info);
		errno=EAGAIN;
		return -1;
	}

	if (errno != ENOENT)
	{
		maildir_tmpcreate_free(info);
		if (errno == EAGAIN)
			errno=EIO;
		return -1;
	}

	if ((fd=maildir_safeopen_stat(info->tmpname, O_CREAT|O_RDWR|O_TRUNC,
				      info->openmode, &stat_buf)) < 0)
	{
		maildir_tmpcreate_free(info);
		return -1;
	}

	libmail_strh_dev_t(stat_buf.st_dev, dev_buf);
	libmail_strh_ino_t(stat_buf.st_ino, ino_buf);

	if (info->newname)
		free(info->newname);
	info->newname=NULL;

	if (info->curname)
		free(info->curname);
	info->curname=NULL;

	info->newname=malloc(strlen(info->tmpname)+strlen(ino_buf)+
			     strlen(dev_buf)+3);

	if (info->newname)
	{
		info->curname=malloc(strlen(info->tmpname)+strlen(ino_buf)+
				     strlen(dev_buf)+3);
		if (!info->curname)
		{
			free(info->newname);
			info->newname=NULL;
		}
	}

	if (!info->newname)
	{
		maildir_tmpcreate_free(info);
		unlink(info->tmpname);
		close(fd);
		if (errno == EAGAIN)
			errno=EIO;
		return -1;
	}

	strcpy(info->newname, maildir);
	strcat(info->newname, "/new/");
	strcat(info->newname, time_buf);
	strcat(info->newname, ".M");
	strcat(info->newname, usec_buf);
	strcat(info->newname, "P");
	strcat(info->newname, pid_buf);
	strcat(info->newname, "V");
	strcat(info->newname, dev_buf);
	strcat(info->newname, "I");
	strcat(info->newname, ino_buf);
	if (*uniq)
		strcat(strcat(info->newname, "_"), uniq);
	strcat(info->newname, ".");
	strcat(info->newname, hostname);
	strcat(info->newname, len_buf);

	strcpy(info->curname, info->newname);
	memcpy(info->curname + strlen(maildir)+1, "cur", 3);

	return fd;
}