tholm@uvicctr.UUCP (Terrence W. Holm) (08/26/88)
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 <stdio.h>
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 <user_name>. It will be '\0' terminated. If <user_name> is
X NULL then local static storage is used, otherwise <user_name>
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 <user_name> 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 <stdio.h>
X#include <pwd.h>
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 <stdio.h>
X#include <pwd.h>
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