getname.c revision 216370
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:
86851Ssos * 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 * 4. Neither the name of the University nor the names of its contributors
142786Ssos *    may be used to endorse or promote products derived from this software
1528375Ssos *    without specific prior written permission.
162786Ssos *
172786Ssos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182786Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
197420Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202786Ssos * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212786Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222786Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232786Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242786Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252786Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262786Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272786Ssos * SUCH DAMAGE.
282786Ssos */
292786Ssos
302786Ssos#ifndef lint
312786Ssos#if 0
322786Ssosstatic char sccsid[] = "@(#)getname.c	8.1 (Berkeley) 6/6/93";
332786Ssos#endif
342786Ssos#endif /* not lint */
352786Ssos#include <sys/cdefs.h>
362786Ssos__FBSDID("$FreeBSD: head/usr.bin/mail/getname.c 216370 2010-12-11 08:32:16Z joel $");
372786Ssos
382786Ssos#include "rcv.h"
392786Ssos#include <pwd.h>
402786Ssos#include "extern.h"
412786Ssos
422786Ssos/* Getname / getuserid for those with hashed passwd data base). */
432786Ssos
442786Ssos/*
452786Ssos * Search the passwd file for a uid. Return name on success, NULL on failure.
462786Ssos */
472786Ssoschar *
482786Ssosgetname(uid)
492786Ssos	int uid;
502786Ssos{
512786Ssos	struct passwd *pw;
522786Ssos
532786Ssos	if ((pw = getpwuid(uid)) == NULL)
542786Ssos		return (NULL);
552786Ssos	return (pw->pw_name);
562786Ssos}
572786Ssos
582786Ssos/*
592786Ssos * Convert the passed name to a user id and return it.  Return -1
602786Ssos * on error.
612786Ssos */
626851Ssosint
632786Ssosgetuserid(name)
642786Ssos	char name[];
652786Ssos{
662786Ssos	struct passwd *pw;
672786Ssos
682786Ssos	if ((pw = getpwnam(name)) == NULL)
692786Ssos		return (-1);
702786Ssos	return (pw->pw_uid);
712786Ssos}
722786Ssos