From owner-freebsd-isp Sat Sep 5 22:53:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id WAA01757 for freebsd-isp-outgoing; Sat, 5 Sep 1998 22:53:42 -0700 (PDT) (envelope-from owner-freebsd-isp@FreeBSD.ORG) Received: from obie.softweyr.com ([204.68.178.33]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA01739; Sat, 5 Sep 1998 22:53:36 -0700 (PDT) (envelope-from wes@softweyr.com) Received: from softweyr.com (wes@zaphod.softweyr.com [204.68.178.35]) by obie.softweyr.com (8.8.8/8.8.8) with ESMTP id AAA01170; Sun, 6 Sep 1998 00:04:23 -0600 (MDT) (envelope-from wes@softweyr.com) Message-ID: <35F2248F.87CE70FC@softweyr.com> Date: Sat, 05 Sep 1998 23:58:39 -0600 From: Wes Peters Organization: Softweyr llc X-Mailer: Mozilla 4.05 [en] (X11; I; FreeBSD 2.2.6-RELEASE i386) MIME-Version: 1.0 To: Joao Carlos Mendes Luis CC: lva@dds.nl, freebsd-isp@FreeBSD.ORG, freebsd-security@FreeBSD.ORG Subject: Re: small LDA c program requested References: <199809050426.BAA20989@roma.coe.ufrj.br> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-isp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Joao Carlos Mendes Luis wrote: > > #define quoting(Wes Peters) > // /* > // * Create the file and prepare to write. > // */ > // snprintf(mailbox, PATH_MAX, "/var/mail/%s/%s", domain, user); > // if ((fd = open(mailbox, O_WRONLY | O_APPEND | O_CREAT, 0600)) < 0) > // { > // abort("Cannot open user mailbox \"%s\" for appending.\n", mailbox); > // } > // > // /* > // * OK, copy stdin until exhausted. > // */ > // while ((nbytes = read(STDIN_FILENO, buffer, BUFSIZ)) > 0) > // { > // if (write(fd, buffer, nbytes) != nbytes) > // { > // abort("Error writing mailbox \"%s\".\n", mailbox); > // } > // } > // > // close(fd); > // return 0; > > Shouldn't you lock the file ? O_APPEND is only good for atomic > writes, IIRC. You're right. A quick fix would be to open the file with O_EXLOCK and puke if the filesystem doesn't support locking; this would rule out NFS-mounted mailboxes. It would be better, IMHO, to collect the entire input and write it in a single call, but this might get expensive in terms of memory allocation. You could do it by allocating a number of large, fixed-size buffers and using writev for output, but what about some bonehead who mails a 40 Meg "Word" document? -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC http://www.softweyr.com/~softweyr wes@softweyr.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-isp" in the body of the message