Re: can www execute sendmail -t?
On Mon, 11 Sep 2006, Bryan Irvine wrote: > > if(pclose(mail)) > > err(2, NULL); > > that did it. I don't understand why though. Got a cluestick handy? Not really. That's just a common idiom for making a system call and aborting if there is an error. Something else "did" it. We diverge off-topic here. Dave -- Experience runs an expensive school, but fools will learn in no other. -- Benjamin Franklin
Re: can www execute sendmail -t?
Easy enough to write one's own with a call to pipe(2) and some sleight-of-handle with dup2 and friends, depending on need. Stevens' "Adv. Prog. in the Unix Env." has the canonical examples. Offhand, though, I can't think of an existing library routine. The OP is not so hot on C programming, he says. (I refer him to the book just mentioned, which is truly "how to write real Unix programs", should he like to improve his skills at the feet of a master.) I actually *just* received that book a couple days ago from amazon. I've barely made it through the preface, but I can already tell that this book will enable me to be mediocre :-) --Bryan
Re: can www execute sendmail -t?
if(pclose(mail)) err(2, NULL); that did it. I don't understand why though. Got a cluestick handy? --Bryan
Re: can www execute sendmail -t?
On Sat, 9 Sep 2006, Matthew R. Dempsky wrote: > On Sat, Sep 09, 2006 at 09:50:16AM -0400, Woodchuck wrote: > > > FILE *mail; > > > char sendmail[512]; > > > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); > > > > use snprintf here, this is exactly the sort of code that some joker > > will try to do a buffer overflow on. > > Assuming RECPIENT is actually something that will be user > controllable, doesn't he need to worry about quoting RECIPIENT and > making sure it doesn't start with a dash? Sounds reasonable. I was assuming that RECIPIENT would eventually be user input. I suggest not having it in the popen() call, but let sendmail scan the recipients from a To: header or even a Bcc: if that's needed. > Does OpenBSD have a popen(3) replacement but with an exec(3)-like > interface instead of a system(3)-like one? Easy enough to write one's own with a call to pipe(2) and some sleight-of-handle with dup2 and friends, depending on need. Stevens' "Adv. Prog. in the Unix Env." has the canonical examples. Offhand, though, I can't think of an existing library routine. The OP is not so hot on C programming, he says. (I refer him to the book just mentioned, which is truly "how to write real Unix programs", should he like to improve his skills at the feet of a master.) Dave -- Experience runs an expensive school, but fools will learn in no other. -- Benjamin Franklin
Re: can www execute sendmail -t?
On Sat, Sep 09, 2006 at 10:23:05PM +0200, Joachim Schipper wrote: > On Sat, Sep 09, 2006 at 12:30:27PM -0500, Matthew R. Dempsky wrote: > > Does OpenBSD have a popen(3) replacement but with an exec(3)-like > > interface instead of a system(3)-like one? > > Not really, IIRC; using pipe() and exec() is the way to go... That's what I suspected. I could image it worth while, however, to have a popen_execl (or whatever) function to let you avoid dealing with shell quoting. (On the other hand, I'm pretty comfortable using pipe/fork/exec, so I don't know how big of an issue this is in practice.)
Re: can www execute sendmail -t?
On Sat, Sep 09, 2006 at 12:30:27PM -0500, Matthew R. Dempsky wrote: > On Sat, Sep 09, 2006 at 09:50:16AM -0400, Woodchuck wrote: > > > FILE *mail; > > > char sendmail[512]; > > > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); > > > > use snprintf here, this is exactly the sort of code that some joker > > will try to do a buffer overflow on. > > Assuming RECPIENT is actually something that will be user > controllable, doesn't he need to worry about quoting RECIPIENT and > making sure it doesn't start with a dash? > > Does OpenBSD have a popen(3) replacement but with an exec(3)-like > interface instead of a system(3)-like one? Not really, IIRC; using pipe() and exec() is the way to go... Joachim
Re: can www execute sendmail -t?
On 9/9/06, Matthew R. Dempsky <[EMAIL PROTECTED]> wrote: On Sat, Sep 09, 2006 at 09:50:16AM -0400, Woodchuck wrote: > > FILE *mail; > > char sendmail[512]; > > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); > > use snprintf here, this is exactly the sort of code that some joker > will try to do a buffer overflow on. Assuming RECPIENT is actually something that will be user controllable, doesn't he need to worry about quoting RECIPIENT and making sure it doesn't start with a dash? Does OpenBSD have a popen(3) replacement but with an exec(3)-like interface instead of a system(3)-like one? -- Stefan
Re: can www execute sendmail -t?
On Sat, Sep 09, 2006 at 09:50:16AM -0400, Woodchuck wrote: > > FILE *mail; > > char sendmail[512]; > > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); > > use snprintf here, this is exactly the sort of code that some joker > will try to do a buffer overflow on. Assuming RECPIENT is actually something that will be user controllable, doesn't he need to worry about quoting RECIPIENT and making sure it doesn't start with a dash? Does OpenBSD have a popen(3) replacement but with an exec(3)-like interface instead of a system(3)-like one?
Re: can www execute sendmail -t?
On Fri, 8 Sep 2006, Bryan Irvine wrote: > i have a peice of code that doesn't seem to work. It compiles and > even executes fine but the email never goes anywhere. > > maillog doesn't even show anything trying. Apache is not running chrooted. > > #define SENDMAIL_PATH "/usr/sbin/sendmail -t" > #define RECIPIENT "[EMAIL PROTECTED]" > #define SENDER "[EMAIL PROTECTED]" Note subtle changes made from your original. > FILE *mail; > char sendmail[512]; > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); use snprintf here, this is exactly the sort of code that some joker will try to do a buffer overflow on. > mail = popen(sendmail, "w"); Check return from popen. Abort if NULL. As in: if(!(mail=popen(sendmail, "w"))) err(1, NULL); /* man 3 err */ You might want to add fflush(stdin); /* man 3 popen, under "BUGS" */ and fprintf(mail, "To: %s\n", RECIPIENT); here. Sendmail -t does not generate this header, and without it aggressive spam blockers might can the message. >From man 8 sendmail: -t Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission. You may not need the recipient in the invocation of sendmail. (You don't). > fprintf(mail, "From: %s\n", SENDER); > fprintf(mail, "Subject: test email.\n"); > fprintf(mail, "\n"); > fprintf(mail, "blah\n"); > pclose(mail); if(pclose(mail)) err(2, NULL); > > also worth noting that i'm a terrible C programmer. It's possible > that elsewhere I have a bug, but I just want to eliminate whether www > can even execute sendmail. > > --Bryan If apache is not chrooted, it should run this. Login as www (or however apache runs) and try it from the command line, then from a standalone small program. You will have to make www a log-in-able user with vipw first. -- Experience runs an expensive school, but fools will learn in no other. -- Benjamin Franklin
Re: can www execute sendmail -t?
On Fri, Sep 08, 2006 at 11:52:47AM -0700, Bryan Irvine wrote: > i have a peice of code that doesn't seem to work. It compiles and > even executes fine but the email never goes anywhere. > > maillog doesn't even show anything trying. Apache is not running > chrooted. > > #define SENDMAIL_PATH "/usr/sbin/sendmail -t" > #define RECIPIENT "[EMAIL PROTECTED]" > #define SENDER "From: [EMAIL PROTECTED]" > FILE *mail; > char sendmail[512]; > > sprintf(sendmail, "%s %s", SENDMAIL_PATH, RECIPIENT); > > mail = popen(sendmail, "w"); > > fprintf(mail, "From: [EMAIL PROTECTED]"); > fprintf(mail, "Subject: test email.\n"); > fprintf(mail, "\n"); > fprintf(mail, "blah\n"); > > pclose(mail); > > > also worth noting that i'm a terrible C programmer. It's possible > that elsewhere I have a bug, but I just want to eliminate whether > www can even execute sendmail. If I am correct in assuming that you run this under Apache, you forgot to take care of the chroot environment. Install the chroot flavour of mini_sendmail. Checking the return values from popen() and pclose() would almost certainly have caught this, BTW. Finally, could I point you to the fcgi package? It might be very useful if you're trying to do CGIish stuff from C. Notably, it allows you to be even faster. ;-) Joachim