133965Sjdp/* 233965Sjdp * Copyright (c) 1980, 1993 333965Sjdp * The Regents of the University of California. All rights reserved. 4218822Sdim * 533965Sjdp * Redistribution and use in source and binary forms, with or without 6218822Sdim * modification, are permitted provided that the following conditions 733965Sjdp * are met: 8218822Sdim * 1. Redistributions of source code must retain the above copyright 933965Sjdp * notice, this list of conditions and the following disclaimer. 10218822Sdim * 2. Redistributions in binary form must reproduce the above copyright 11218822Sdim * notice, this list of conditions and the following disclaimer in the 12218822Sdim * documentation and/or other materials provided with the distribution. 13218822Sdim * 4. Neither the name of the University nor the names of its contributors 1433965Sjdp * may be used to endorse or promote products derived from this software 15218822Sdim * without specific prior written permission. 16218822Sdim * 17218822Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1933965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2033965Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21218822Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22218822Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23218822Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2433965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2533965Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2633965Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2733965Sjdp * SUCH DAMAGE. 2833965Sjdp */ 2933965Sjdp 3033965Sjdp#ifndef lint 3133965Sjdp#if 0 3233965Sjdpstatic char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93"; 3333965Sjdp#endif 3433965Sjdp#endif /* not lint */ 3533965Sjdp#include <sys/cdefs.h> 3633965Sjdp__FBSDID("$FreeBSD: releng/11.0/usr.bin/mail/temp.c 216564 2010-12-19 16:25:23Z charnier $"); 3733965Sjdp 3833965Sjdp#include "rcv.h" 3933965Sjdp#include "extern.h" 4033965Sjdp 4133965Sjdp/* 4233965Sjdp * Mail -- a mail program 4333965Sjdp * 4433965Sjdp * Give names to all the temporary files that we will need. 4533965Sjdp */ 4633965Sjdp 4733965Sjdpchar *tmpdir; 4833965Sjdp 4933965Sjdpvoid 5033965Sjdptinit(void) 5133965Sjdp{ 5233965Sjdp char *cp; 5333965Sjdp 5433965Sjdp if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') 5533965Sjdp tmpdir = _PATH_TMP; 5633965Sjdp if ((tmpdir = strdup(tmpdir)) == NULL) 5733965Sjdp errx(1, "Out of memory"); 5833965Sjdp /* Strip trailing '/' if necessary */ 5933965Sjdp cp = tmpdir + strlen(tmpdir) - 1; 6033965Sjdp while (cp > tmpdir && *cp == '/') { 6133965Sjdp *cp = '\0'; 6233965Sjdp cp--; 6333965Sjdp } 6433965Sjdp 6533965Sjdp /* 6633965Sjdp * It's okay to call savestr in here because main will 6733965Sjdp * do a spreserve() after us. 6833965Sjdp */ 6933965Sjdp if (myname != NULL) { 7033965Sjdp if (getuserid(myname) < 0) 7133965Sjdp errx(1, "\"%s\" is not a user of this system", myname); 7233965Sjdp } else { 7333965Sjdp if ((cp = username()) == NULL) { 7433965Sjdp myname = "ubluit"; 7533965Sjdp if (rcvmode) 7633965Sjdp errx(1, "Who are you!?"); 7733965Sjdp } else 7833965Sjdp myname = savestr(cp); 7933965Sjdp } 8033965Sjdp if ((cp = getenv("HOME")) == NULL || *cp == '\0' || 8133965Sjdp strlen(cp) >= PATHSIZE) 8233965Sjdp homedir = NULL; 8333965Sjdp else 8433965Sjdp homedir = savestr(cp); 8533965Sjdp if (debug) 8633965Sjdp printf("user = %s, homedir = %s\n", myname, 8733965Sjdp homedir ? homedir : "NONE"); 8833965Sjdp} 8933965Sjdp