Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: getlogin(3) Message-ID: <483@uvicctr.UUCP> Date: 26 Aug 88 00:15:53 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 139 EFTH MINIX report #39 - August 1988 - getlogin(3) There follows an implementation of getlogin(3) for Minix. ---------------------------------------------------------- echo x - getlogin.3 gres '^X' '' > getlogin.3 << '/' XSUBROUTINES X getlogin(3) - get the current login name X XINVOCATION X char *get_login() X XEXPLANATION X The real user's name (as opposed to the effective user name) X is copied to local static storage. X XRESULTS X o/w : A pointer to the real user's name. X NULL : Error. X XREFERENCES X who(1), cuserid(3) X XPROBLEMS X Getlogin(3) should check /usr/adm/wtmp, in the same manner X as the command "who am i". For efficiency this is not done. X Therefore, getlogin(3) is incorrect after a su(1), or if X multiple users share a user ID. / echo x - cuserid.3 gres '^X' '' > cuserid.3 << '/' XSUBROUTINES X cuserid(3) - get the current effective user name X XINVOCATION X #include X X char *cuserid( user_name ) X char *user_name; X XEXPLANATION X The current effective user name is copied to the storage pointed X to by . It will be '\0' terminated. If is X NULL then local static storage is used, otherwise X must point to storage of at least L_cuserid characters. X XRESULTS X o/w : A pointer to the effective user's name. X NULL : Error. If was not NULL then it now points X to "\0". X XFILES X /etc/passwd user login names X XREFERENCES X whoami(1), getlogin(3) / echo x - getlogin.c gres '^X' '' > getlogin.c << '/' X/* getlogin(3) X * X * Author: Terrence W. Holm Aug. 1988 X */ X X#include X#include X X#ifndef L_cuserid X#define L_cuserid 9 X#endif X Xextern struct passwd *getpwuid(); X X Xchar *getlogin() X { X static char userid[ L_cuserid ]; X struct passwd *pw_entry; X X pw_entry = getpwuid( getuid() ); X X if ( pw_entry == NULL ) X return( NULL ); X X strcpy( userid, pw_entry->pw_name ); X X return( userid ); X } / echo x - cuserid.c gres '^X' '' > cuserid.c << '/' X/* cuserid(3) X * X * Author: Terrence W. Holm Sept. 1987 X */ X X#include X#include X X#ifndef L_cuserid X#define L_cuserid 9 X#endif X Xextern struct passwd *getpwuid(); X X Xchar *cuserid( user_name ) X char *user_name; X X { X static char userid[ L_cuserid ]; X struct passwd *pw_entry; X X if ( user_name == NULL ) X user_name = userid; X X pw_entry = getpwuid( geteuid() ); X X if ( pw_entry == NULL ) X { X *user_name = '\0'; X return( NULL ); X } X X strcpy( user_name, pw_entry->pw_name ); X X return( user_name ); X } / ---------------------------------------------------------- Edwin L. Froese uw-beaver!ubc-cs!mprg!handel!froese Terrence W. Holm uw-beaver!uvicctr!tholm