v7.local.c revision 99112
1153577Sjhb/*
2153577Sjhb * Copyright (c) 1980, 1993
3153577Sjhb *	The Regents of the University of California.  All rights reserved.
4153577Sjhb *
5153577Sjhb * Redistribution and use in source and binary forms, with or without
6153577Sjhb * modification, are permitted provided that the following conditions
7153577Sjhb * are met:
8153577Sjhb * 1. Redistributions of source code must retain the above copyright
9153577Sjhb *    notice, this list of conditions and the following disclaimer.
10153577Sjhb * 2. Redistributions in binary form must reproduce the above copyright
11153577Sjhb *    notice, this list of conditions and the following disclaimer in the
12153577Sjhb *    documentation and/or other materials provided with the distribution.
13153577Sjhb * 3. All advertising materials mentioning features or use of this software
14153577Sjhb *    must display the following acknowledgement:
15153577Sjhb *	This product includes software developed by the University of
16153577Sjhb *	California, Berkeley and its contributors.
17153577Sjhb * 4. Neither the name of the University nor the names of its contributors
18153577Sjhb *    may be used to endorse or promote products derived from this software
19153577Sjhb *    without specific prior written permission.
20153577Sjhb *
21153577Sjhb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22153577Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23153577Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24153577Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25153577Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26153577Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27153577Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28153577Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29153577Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30153577Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31153577Sjhb * SUCH DAMAGE.
32153577Sjhb */
33153577Sjhb
34153577Sjhb#ifndef lint
35153577Sjhb#if 0
36153577Sjhbstatic char sccsid[] = "@(#)v7.local.c	8.1 (Berkeley) 6/6/93";
37153577Sjhb#endif
38153577Sjhb#endif /* not lint */
39153577Sjhb#include <sys/cdefs.h>
40153577Sjhb__FBSDID("$FreeBSD: head/usr.bin/mail/v7.local.c 99112 2002-06-30 05:25:07Z obrien $");
41153577Sjhb
42189373Sjhb/*
43198251Sjkim * Mail -- a mail program
44189373Sjhb *
45153577Sjhb * Version 7
46268351Smarcel *
47254882Sdumbbell * Local routines that are installation dependent.
48254882Sdumbbell */
49254882Sdumbbell
50254882Sdumbbell#include "rcv.h"
51153577Sjhb#include <fcntl.h>
52153577Sjhb#include "extern.h"
53153577Sjhb
54279487Sdumbbell/*
55279487Sdumbbell * Locate the user's mailbox file (ie, the place where new, unread
56189373Sjhb * mail is queued).
57189373Sjhb */
58189373Sjhbvoid
59189373Sjhbfindmail(user, buf, buflen)
60189373Sjhb	char *user, *buf;
61183095Sjhb	int buflen;
62183095Sjhb{
63249315Sjhb	char *tmp = getenv("MAIL");
64249315Sjhb
65183095Sjhb	if (tmp == NULL)
66183095Sjhb		(void)snprintf(buf, buflen, "%s/%s", _PATH_MAILDIR, user);
67198251Sjkim	else
68198251Sjkim		(void)strlcpy(buf, tmp, buflen);
69255571Sdumbbell}
70255571Sdumbbell
71294883Sjhibbits/*
72294883Sjhibbits * Get rid of the queued mail.
73255571Sdumbbell */
74255571Sdumbbellvoid
75255571Sdumbbelldemail()
76198251Sjkim{
77198964Sjkim
78198251Sjkim	if (value("keep") != NULL || rm(mailname) < 0)
79198251Sjkim		(void)close(open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600));
80254882Sdumbbell}
81254882Sdumbbell
82254882Sdumbbell/*
83259679Sdumbbell * Discover user login name.
84259679Sdumbbell */
85259679Sdumbbellchar *
86254882Sdumbbellusername()
87259679Sdumbbell{
88259679Sdumbbell	char *np;
89259679Sdumbbell	uid_t uid;
90259679Sdumbbell
91259679Sdumbbell	if ((np = getenv("USER")) != NULL)
92259679Sdumbbell		return (np);
93259679Sdumbbell	if ((np = getenv("LOGNAME")) != NULL)
94259679Sdumbbell		return (np);
95259679Sdumbbell	if ((np = getname(uid = getuid())) != NULL)
96259679Sdumbbell		return (np);
97259679Sdumbbell	printf("Cannot associate a name with uid %u\n", (unsigned)uid);
98259679Sdumbbell	return (NULL);
99259679Sdumbbell}
100259679Sdumbbell