getname.c revision 99112
1116576Smurray/*
2116576Smurray * Copyright (c) 1980, 1993
3116576Smurray *	The Regents of the University of California.  All rights reserved.
4116576Smurray *
5116576Smurray * Redistribution and use in source and binary forms, with or without
6116576Smurray * modification, are permitted provided that the following conditions
7116576Smurray * are met:
8116576Smurray * 1. Redistributions of source code must retain the above copyright
9116576Smurray *    notice, this list of conditions and the following disclaimer.
10116576Smurray * 2. Redistributions in binary form must reproduce the above copyright
11116576Smurray *    notice, this list of conditions and the following disclaimer in the
12116576Smurray *    documentation and/or other materials provided with the distribution.
13116576Smurray * 3. All advertising materials mentioning features or use of this software
14116576Smurray *    must display the following acknowledgement:
15116576Smurray *	This product includes software developed by the University of
16116576Smurray *	California, Berkeley and its contributors.
17116576Smurray * 4. Neither the name of the University nor the names of its contributors
18116576Smurray *    may be used to endorse or promote products derived from this software
19116576Smurray *    without specific prior written permission.
20116576Smurray *
21116576Smurray * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22116576Smurray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23116576Smurray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24116576Smurray * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25116576Smurray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26116576Smurray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27116576Smurray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28116576Smurray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29116576Smurray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30116576Smurray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31116576Smurray * SUCH DAMAGE.
32116576Smurray */
33116576Smurray
34116576Smurray#ifndef lint
35116576Smurray#if 0
36116576Smurraystatic char sccsid[] = "@(#)getname.c	8.1 (Berkeley) 6/6/93";
37116576Smurray#endif
38116576Smurray#endif /* not lint */
39116576Smurray#include <sys/cdefs.h>
40116576Smurray__FBSDID("$FreeBSD: head/usr.bin/mail/getname.c 99112 2002-06-30 05:25:07Z obrien $");
41116576Smurray
42116576Smurray#include "rcv.h"
43116576Smurray#include <pwd.h>
44116576Smurray#include "extern.h"
45116576Smurray
46116576Smurray/* Getname / getuserid for those with hashed passwd data base). */
47116576Smurray
48116576Smurray/*
49116576Smurray * Search the passwd file for a uid. Return name on success, NULL on failure.
50116576Smurray */
51116576Smurraychar *
52116576Smurraygetname(uid)
53116576Smurray	int uid;
54116576Smurray{
55116576Smurray	struct passwd *pw;
56116576Smurray
57116576Smurray	if ((pw = getpwuid(uid)) == NULL)
58116576Smurray		return (NULL);
59116576Smurray	return (pw->pw_name);
60116576Smurray}
61116576Smurray
62116576Smurray/*
63116576Smurray * Convert the passed name to a user id and return it.  Return -1
64116576Smurray * on error.
65116576Smurray */
66116576Smurrayint
67116576Smurraygetuserid(name)
68116576Smurray	char name[];
69116576Smurray{
70116576Smurray	struct passwd *pw;
71116576Smurray
72116576Smurray	if ((pw = getpwnam(name)) == NULL)
73116576Smurray		return (-1);
74116576Smurray	return (pw->pw_uid);
75116576Smurray}
76116576Smurray