1999-09-14 09:32:05 -04:00
|
|
|
/* Scheme48/scsh Unix system interface.
|
|
|
|
** User and group db access routines
|
|
|
|
** Copyright (c) 1993, 1994 by Olin Shivers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The code in this file is separated out from the code in syscalls1.c
|
|
|
|
** because we must compile them with different compiler flags (non-posix)
|
|
|
|
** to get around a NeXTSTEP bug. Once they get their act together, we can
|
|
|
|
** stick it back into syscalls1.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
|
|
|
|
/* Make sure our exports match up w/the implementation: */
|
|
|
|
#include "userinfo1.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
1999-11-16 11:37:28 -05:00
|
|
|
#include "scheme48.h"
|
2000-05-16 05:24:54 -04:00
|
|
|
#include "cstuff.h"
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
/* User db access routines
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Return a user name for ourself.
|
|
|
|
** Uses our *real* uid, not our effective one.
|
|
|
|
*/
|
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
s48_value my_username(void)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
|
|
|
char *s = getlogin();
|
1999-11-16 11:37:28 -05:00
|
|
|
if( s ) return s48_enter_string (s);
|
1999-09-14 09:32:05 -04:00
|
|
|
else {
|
|
|
|
struct passwd *pwd = getpwuid(getuid());
|
1999-11-16 11:37:28 -05:00
|
|
|
return pwd ? s48_enter_string(pwd->pw_name) : S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
s48_value user_info_uid(s48_value scheme_uid, s48_value user_info_record)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
1999-11-16 11:37:28 -05:00
|
|
|
struct passwd *pwd = getpwuid(s48_extract_fixnum(scheme_uid));
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
|
|
|
S48_GC_PROTECT_1(user_info_record);
|
|
|
|
|
1999-09-14 09:32:05 -04:00
|
|
|
if( !pwd ) {
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_RECORD_SET(user_info_record, 0, s48_enter_string (pwd->pw_name));
|
|
|
|
S48_RECORD_SET(user_info_record, 2, s48_enter_fixnum (pwd->pw_gid));
|
|
|
|
S48_RECORD_SET(user_info_record, 3, s48_enter_string (pwd->pw_dir));
|
|
|
|
S48_RECORD_SET(user_info_record, 4, s48_enter_string (pwd->pw_shell));
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
s48_value user_info_name(s48_value scheme_name, s48_value user_info_record)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
1999-11-16 11:37:28 -05:00
|
|
|
struct passwd *pwd = getpwnam(s48_extract_string (scheme_name));
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
|
|
|
S48_GC_PROTECT_1(user_info_record);
|
|
|
|
|
1999-09-14 09:32:05 -04:00
|
|
|
if( !pwd ) {
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_RECORD_SET(user_info_record, 1, s48_enter_fixnum (pwd->pw_uid));
|
|
|
|
S48_RECORD_SET(user_info_record, 2, s48_enter_fixnum (pwd->pw_gid));
|
|
|
|
S48_RECORD_SET(user_info_record, 3, s48_enter_string (pwd->pw_dir));
|
|
|
|
S48_RECORD_SET(user_info_record, 4, s48_enter_string (pwd->pw_shell));
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-14 09:32:05 -04:00
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
s48_value group_info_gid (s48_value scheme_gid, s48_value group_info_record)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
1999-11-16 11:37:28 -05:00
|
|
|
struct group *grp = getgrgid(s48_extract_fixnum(scheme_gid));
|
|
|
|
s48_value member_list;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
|
|
|
S48_GC_PROTECT_1(group_info_record);
|
|
|
|
|
1999-09-14 09:32:05 -04:00
|
|
|
if( !grp ) {
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
|
|
|
}
|
|
|
|
S48_RECORD_SET(group_info_record, 0, s48_enter_string (grp->gr_name));
|
|
|
|
|
|
|
|
member_list = char_pp_2_string_list (grp->gr_mem);
|
|
|
|
if( !member_list ) {
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_RECORD_SET(group_info_record, 2, member_list);
|
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_TRUE;
|
|
|
|
}
|
1999-09-14 09:32:05 -04:00
|
|
|
|
1999-11-16 11:37:28 -05:00
|
|
|
s48_value group_info_name (s48_value scheme_name, s48_value group_info_record)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
1999-11-16 11:37:28 -05:00
|
|
|
struct group *grp = getgrnam(s48_extract_string(scheme_name));
|
|
|
|
s48_value member_list;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
|
|
|
S48_GC_PROTECT_1(group_info_record);
|
|
|
|
|
1999-09-14 09:32:05 -04:00
|
|
|
if( !grp ) {
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
|
|
|
}
|
|
|
|
S48_RECORD_SET(group_info_record, 1, s48_enter_fixnum (grp->gr_gid));
|
|
|
|
|
|
|
|
member_list = char_pp_2_string_list (grp->gr_mem);
|
|
|
|
if( !member_list ) {
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_FALSE;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_RECORD_SET(group_info_record, 2, member_list);
|
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return S48_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-01 12:21:35 -05:00
|
|
|
void s48_init_userinfo(void){
|
1999-11-16 11:37:28 -05:00
|
|
|
S48_EXPORT_FUNCTION(user_info_uid);
|
|
|
|
S48_EXPORT_FUNCTION(user_info_name);
|
|
|
|
S48_EXPORT_FUNCTION(my_username);
|
|
|
|
S48_EXPORT_FUNCTION(group_info_gid);
|
|
|
|
S48_EXPORT_FUNCTION(group_info_name);
|
|
|
|
}
|