xref: /titanic_44/usr/src/cmd/mail/islocal.c (revision b7f45089ccbe01bab3d7c7377b49d80d2ae18a69)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 #pragma ident	"%Z%%M%	%I%	%E% SMI"
26 
27 #include <sys/param.h>
28 #include "mail.h"
29 
30 /*
31  * islocal (char *user, uid_t *puid) - see if user exists on this system
32  */
33 islocal(user, puid)
34 char *user;
35 uid_t *puid;
36 {
37 	char	fname[MAXPATHLEN];
38 	struct stat statb;
39 	struct passwd *pwd_ptr;
40 
41 	/* Check for existing mailfile first */
42 	(void) snprintf(fname, sizeof (fname), "%s%s", maildir, user);
43 	if (stat(fname, &statb) == 0) {
44 		*puid = statb.st_uid;
45 		return (TRUE);
46 	}
47 
48 	/* If no existing mailfile, check passwd file */
49 	setpwent();
50 	if ((pwd_ptr = getpwnam(user)) == NULL) {
51 		return (FALSE);
52 	}
53 	*puid = pwd_ptr->pw_uid;
54 	return (TRUE);
55 }
56