getname.c revision 1590
155071Sache/* 229726Swosch * Copyright (c) 1980, 1993 386796Sache * The Regents of the University of California. All rights reserved. 486796Sache * 586796Sache * Redistribution and use in source and binary forms, with or without 686796Sache * modification, are permitted provided that the following conditions 786796Sache * are met: 886796Sache * 1. Redistributions of source code must retain the above copyright 986796Sache * notice, this list of conditions and the following disclaimer. 1086796Sache * 2. Redistributions in binary form must reproduce the above copyright 1186796Sache * notice, this list of conditions and the following disclaimer in the 1286796Sache * documentation and/or other materials provided with the distribution. 1355071Sache * 3. All advertising materials mentioning features or use of this software 1455071Sache * must display the following acknowledgement: 1555071Sache * This product includes software developed by the University of 1655071Sache * California, Berkeley and its contributors. 1755071Sache * 4. Neither the name of the University nor the names of its contributors 1855071Sache * may be used to endorse or promote products derived from this software 1955071Sache * without specific prior written permission. 2055071Sache * 2155071Sache * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2255071Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2355071Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2455071Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2555071Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2655071Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2755071Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2855071Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2955071Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3055071Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3155071Sache * SUCH DAMAGE. 3255071Sache */ 3355071Sache 3455071Sache#ifndef lint 3555071Sachestatic char sccsid[] = "@(#)getname.c 8.1 (Berkeley) 6/6/93"; 3655071Sache#endif /* not lint */ 3755071Sache 3855071Sache#include "rcv.h" 3955071Sache#include <pwd.h> 4055071Sache#include "extern.h" 4155071Sache 4286796Sache/* Getname / getuserid for those with hashed passwd data base). */ 4386796Sache 4486796Sache/* 4586796Sache * Search the passwd file for a uid. Return name through ref parameter 4686796Sache * if found, indicating success with 0 return. Return -1 on error. 4786796Sache */ 4886796Sachechar * 4986796Sachegetname(uid) 5086796Sache int uid; 5186796Sache{ 5286796Sache struct passwd *pw; 5355071Sache 5455071Sache if ((pw = getpwuid(uid)) == NULL) 5555071Sache return NOSTR; 5655071Sache return pw->pw_name; 5755071Sache} 5855071Sache 5955071Sache/* 6055071Sache * Convert the passed name to a user id and return it. Return -1 6155071Sache * on error. 6255071Sache */ 6355071Sacheint 6455071Sachegetuserid(name) 6555071Sache char name[]; 6655071Sache{ 6755071Sache struct passwd *pw; 6855071Sache 6955071Sache if ((pw = getpwnam(name)) == NULL) 7055071Sache return -1; 7155071Sache return pw->pw_uid; 7255071Sache} 7355071Sache