xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/username.c (revision 41fbaed053f8fbfdf9d2a4ee0a7386a3c83f8505)
1*41fbaed0Stron /*	$NetBSD: username.c,v 1.1.1.1 2009/06/23 10:09:01 tron Exp $	*/
2*41fbaed0Stron 
3*41fbaed0Stron /*++
4*41fbaed0Stron /* NAME
5*41fbaed0Stron /*	username 3
6*41fbaed0Stron /* SUMMARY
7*41fbaed0Stron /*	lookup name of real user
8*41fbaed0Stron /* SYNOPSIS
9*41fbaed0Stron /*	#include <username.h>
10*41fbaed0Stron /*
11*41fbaed0Stron /*	const char *username()
12*41fbaed0Stron /* DESCRIPTION
13*41fbaed0Stron /*	username() jumps whatever system-specific hoops it takes to
14*41fbaed0Stron /*	get the name of the user who started the process. The result
15*41fbaed0Stron /*	is volatile. Make a copy if it is to be used for an appreciable
16*41fbaed0Stron /*	amount of time.
17*41fbaed0Stron /* LICENSE
18*41fbaed0Stron /* .ad
19*41fbaed0Stron /* .fi
20*41fbaed0Stron /*	The Secure Mailer license must be distributed with this software.
21*41fbaed0Stron /* AUTHOR(S)
22*41fbaed0Stron /*	Wietse Venema
23*41fbaed0Stron /*	IBM T.J. Watson Research
24*41fbaed0Stron /*	P.O. Box 704
25*41fbaed0Stron /*	Yorktown Heights, NY 10598, USA
26*41fbaed0Stron /*--*/
27*41fbaed0Stron 
28*41fbaed0Stron /* System library. */
29*41fbaed0Stron 
30*41fbaed0Stron #include <sys_defs.h>
31*41fbaed0Stron #include <unistd.h>
32*41fbaed0Stron #include <pwd.h>
33*41fbaed0Stron 
34*41fbaed0Stron /* Utility library. */
35*41fbaed0Stron 
36*41fbaed0Stron #include "username.h"
37*41fbaed0Stron 
38*41fbaed0Stron /* username - get name of user */
39*41fbaed0Stron 
username(void)40*41fbaed0Stron const char *username(void)
41*41fbaed0Stron {
42*41fbaed0Stron     uid_t   uid;
43*41fbaed0Stron     struct passwd *pwd;
44*41fbaed0Stron 
45*41fbaed0Stron     uid = getuid();
46*41fbaed0Stron     if ((pwd = getpwuid(uid)) == 0)
47*41fbaed0Stron 	return (0);
48*41fbaed0Stron     return (pwd->pw_name);
49*41fbaed0Stron }
50