xref: /titanic_51/usr/src/ucbcmd/whoami/whoami.c (revision f22acdfff536d452df49dd85c5ecd42092b8fcad)
178b6ed60Scraigm /*
2*f22acdffSgbrunett  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
378b6ed60Scraigm  * Use is subject to license terms.
478b6ed60Scraigm  */
578b6ed60Scraigm 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
1578b6ed60Scraigm #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include <unistd.h>
187c478bd9Sstevel@tonic-gate #include <sys/types.h>
197c478bd9Sstevel@tonic-gate #include <pwd.h>
207c478bd9Sstevel@tonic-gate #include <locale.h>
217c478bd9Sstevel@tonic-gate #include <stdlib.h>
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate #define	MSG	"whoami: no login associated with uid %u.\n"
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * whoami
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
2978b6ed60Scraigm int
3078b6ed60Scraigm main(int argc, char *argv[])
31*f22acdffSgbrunett /*ARGSUSED*/
327c478bd9Sstevel@tonic-gate {
3378b6ed60Scraigm 	struct passwd *pp;
347c478bd9Sstevel@tonic-gate 	uid_t	euid;
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
377c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
387c478bd9Sstevel@tonic-gate #if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
397c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"  /* Use this only if it wasn't */
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 	euid = geteuid();
447c478bd9Sstevel@tonic-gate 	pp = getpwuid(euid);
457c478bd9Sstevel@tonic-gate 	if (pp == 0) {
467c478bd9Sstevel@tonic-gate 		(void) printf(gettext(MSG), euid);
477c478bd9Sstevel@tonic-gate 		exit(1);
487c478bd9Sstevel@tonic-gate 	}
49*f22acdffSgbrunett 	(void) printf("%s\n", pp->pw_name);
5078b6ed60Scraigm 	return (0);
517c478bd9Sstevel@tonic-gate }
52