v7.local.c (18726) | v7.local.c (74769) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35#if 0 |
|
35static char sccsid[] = "@(#)v7.local.c 8.1 (Berkeley) 6/6/93"; | 36static char sccsid[] = "@(#)v7.local.c 8.1 (Berkeley) 6/6/93"; |
37#endif 38static const char rcsid[] = 39 "$FreeBSD: head/usr.bin/mail/v7.local.c 74769 2001-03-25 04:57:05Z mikeh $"; |
|
36#endif /* not lint */ 37 38/* 39 * Mail -- a mail program 40 * 41 * Version 7 42 * 43 * Local routines that are installation dependent. 44 */ 45 46#include "rcv.h" 47#include <fcntl.h> 48#include "extern.h" 49 50/* 51 * Locate the user's mailbox file (ie, the place where new, unread 52 * mail is queued). 53 */ 54void | 40#endif /* not lint */ 41 42/* 43 * Mail -- a mail program 44 * 45 * Version 7 46 * 47 * Local routines that are installation dependent. 48 */ 49 50#include "rcv.h" 51#include <fcntl.h> 52#include "extern.h" 53 54/* 55 * Locate the user's mailbox file (ie, the place where new, unread 56 * mail is queued). 57 */ 58void |
55findmail(user, buf) | 59findmail(user, buf, buflen) |
56 char *user, *buf; | 60 char *user, *buf; |
61 int buflen; |
|
57{ 58 char *tmp = getenv("MAIL"); 59 60 if (tmp == NULL) | 62{ 63 char *tmp = getenv("MAIL"); 64 65 if (tmp == NULL) |
61 (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, user); | 66 (void)snprintf(buf, buflen, "%s/%s", _PATH_MAILDIR, user); |
62 else | 67 else |
63 (void)strcpy(buf, tmp); | 68 (void)strlcpy(buf, tmp, buflen); |
64} 65 66/* 67 * Get rid of the queued mail. 68 */ 69void 70demail() 71{ 72 73 if (value("keep") != NOSTR || rm(mailname) < 0) | 69} 70 71/* 72 * Get rid of the queued mail. 73 */ 74void 75demail() 76{ 77 78 if (value("keep") != NOSTR || rm(mailname) < 0) |
74 close(creat(mailname, 0600)); | 79 close(open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600)); |
75} 76 77/* 78 * Discover user login name. 79 */ 80char * 81username() 82{ 83 char *np; | 80} 81 82/* 83 * Discover user login name. 84 */ 85char * 86username() 87{ 88 char *np; |
89 uid_t uid; |
|
84 85 if ((np = getenv("USER")) != NOSTR) 86 return np; | 90 91 if ((np = getenv("USER")) != NOSTR) 92 return np; |
87 return getname(getuid()); | 93 if ((np = getenv("LOGNAME")) != NOSTR) 94 return np; 95 if ((np = getname(uid = getuid())) != NOSTR) 96 return np; 97 printf("Cannot associate a name with uid %u\n", (unsigned)uid); 98 return NOSTR; |
88} | 99} |