getname.c revision 99112
12786Ssos/*
22786Ssos * Copyright (c) 1980, 1993
32786Ssos *	The Regents of the University of California.  All rights reserved.
42786Ssos *
52786Ssos * Redistribution and use in source and binary forms, with or without
62786Ssos * modification, are permitted provided that the following conditions
72786Ssos * are met:
82786Ssos * 1. Redistributions of source code must retain the above copyright
92786Ssos *    notice, this list of conditions and the following disclaimer.
102786Ssos * 2. Redistributions in binary form must reproduce the above copyright
112786Ssos *    notice, this list of conditions and the following disclaimer in the
122786Ssos *    documentation and/or other materials provided with the distribution.
132786Ssos * 3. All advertising materials mentioning features or use of this software
142786Ssos *    must display the following acknowledgement:
152786Ssos *	This product includes software developed by the University of
162786Ssos *	California, Berkeley and its contributors.
172786Ssos * 4. Neither the name of the University nor the names of its contributors
182786Ssos *    may be used to endorse or promote products derived from this software
192786Ssos *    without specific prior written permission.
202786Ssos *
212786Ssos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222786Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
232786Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242786Ssos * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
252786Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
262786Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
272786Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
282786Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
292786Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
302786Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
312786Ssos * SUCH DAMAGE.
322786Ssos */
332786Ssos
342786Ssos#ifndef lint
352786Ssos#if 0
362786Ssosstatic char sccsid[] = "@(#)getname.c	8.1 (Berkeley) 6/6/93";
372786Ssos#endif
382786Ssos#endif /* not lint */
392786Ssos#include <sys/cdefs.h>
402786Ssos__FBSDID("$FreeBSD: head/usr.bin/mail/getname.c 99112 2002-06-30 05:25:07Z obrien $");
412786Ssos
422786Ssos#include "rcv.h"
432786Ssos#include <pwd.h>
442786Ssos#include "extern.h"
452786Ssos
462786Ssos/* Getname / getuserid for those with hashed passwd data base). */
472786Ssos
482786Ssos/*
492786Ssos * Search the passwd file for a uid. Return name on success, NULL on failure.
502786Ssos */
512786Ssoschar *
522786Ssosgetname(uid)
532786Ssos	int uid;
542786Ssos{
552786Ssos	struct passwd *pw;
562786Ssos
572786Ssos	if ((pw = getpwuid(uid)) == NULL)
582786Ssos		return (NULL);
592786Ssos	return (pw->pw_name);
602786Ssos}
612786Ssos
622786Ssos/*
632786Ssos * Convert the passed name to a user id and return it.  Return -1
642786Ssos * on error.
652786Ssos */
662786Ssosint
672786Ssosgetuserid(name)
682786Ssos	char name[];
692786Ssos{
702786Ssos	struct passwd *pw;
712786Ssos
722786Ssos	if ((pw = getpwnam(name)) == NULL)
732786Ssos		return (-1);
742786Ssos	return (pw->pw_uid);
752786Ssos}
762786Ssos