v7.local.c revision 216370
1327Sjkh/*
28857Srgrimes * Copyright (c) 1980, 1993
3327Sjkh *	The Regents of the University of California.  All rights reserved.
4327Sjkh *
5327Sjkh * Redistribution and use in source and binary forms, with or without
6327Sjkh * modification, are permitted provided that the following conditions
7327Sjkh * are met:
8327Sjkh * 1. Redistributions of source code must retain the above copyright
9327Sjkh *    notice, this list of conditions and the following disclaimer.
10327Sjkh * 2. Redistributions in binary form must reproduce the above copyright
11327Sjkh *    notice, this list of conditions and the following disclaimer in the
12327Sjkh *    documentation and/or other materials provided with the distribution.
13327Sjkh * 4. Neither the name of the University nor the names of its contributors
14327Sjkh *    may be used to endorse or promote products derived from this software
15327Sjkh *    without specific prior written permission.
16327Sjkh *
17327Sjkh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18327Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19327Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20327Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21327Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22327Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23327Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24327Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25327Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26327Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27327Sjkh * SUCH DAMAGE.
28327Sjkh */
294996Sjkh
30327Sjkh#ifndef lint
31327Sjkh#if 0
32327Sjkhstatic char sccsid[] = "@(#)v7.local.c	8.1 (Berkeley) 6/6/93";
33411Sjkh#endif
34379Sjkh#endif /* not lint */
35383Sjkh#include <sys/cdefs.h>
36392Sjkh__FBSDID("$FreeBSD: head/usr.bin/mail/v7.local.c 216370 2010-12-11 08:32:16Z joel $");
37327Sjkh
38327Sjkh/*
39327Sjkh * Mail -- a mail program
40327Sjkh *
41327Sjkh * Version 7
42327Sjkh *
43327Sjkh * Local routines that are installation dependent.
44327Sjkh */
45327Sjkh
46327Sjkh#include "rcv.h"
47327Sjkh#include <fcntl.h>
48327Sjkh#include "extern.h"
49327Sjkh
50327Sjkh/*
51327Sjkh * Locate the user's mailbox file (ie, the place where new, unread
52327Sjkh * mail is queued).
53327Sjkh */
54327Sjkhvoid
55327Sjkhfindmail(user, buf, buflen)
564996Sjkh	char *user, *buf;
57327Sjkh	int buflen;
58327Sjkh{
59327Sjkh	char *tmp = getenv("MAIL");
60327Sjkh
61327Sjkh	if (tmp == NULL)
62327Sjkh		(void)snprintf(buf, buflen, "%s/%s", _PATH_MAILDIR, user);
63327Sjkh	else
64327Sjkh		(void)strlcpy(buf, tmp, buflen);
65327Sjkh}
66327Sjkh
67327Sjkh/*
68327Sjkh * Get rid of the queued mail.
69327Sjkh */
70327Sjkhvoid
71327Sjkhdemail()
72327Sjkh{
73327Sjkh
74327Sjkh	if (value("keep") != NULL || rm(mailname) < 0)
754996Sjkh		(void)close(open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600));
764996Sjkh}
774996Sjkh
784996Sjkh/*
79327Sjkh * Discover user login name.
80327Sjkh */
81327Sjkhchar *
82327Sjkhusername()
83327Sjkh{
84327Sjkh	char *np;
85327Sjkh	uid_t uid;
86327Sjkh
87327Sjkh	if ((np = getenv("USER")) != NULL)
88327Sjkh		return (np);
89327Sjkh	if ((np = getenv("LOGNAME")) != NULL)
90327Sjkh		return (np);
91327Sjkh	if ((np = getname(uid = getuid())) != NULL)
92327Sjkh		return (np);
93327Sjkh	printf("Cannot associate a name with uid %u\n", (unsigned)uid);
94327Sjkh	return (NULL);
954996Sjkh}
964996Sjkh