13 #include <sys/types.h>
33 #ifndef CSIDL_COMMON_APPDATA
34 #define CSIDL_COMMON_APPDATA 35
65 if (!login) login =
getenv(
"USER");
75 #if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
77 safe_setup_str(
const char *str)
79 if (str == 0) str =
"";
84 safe_setup_locale_str(
const char *str)
86 if (str == 0) str =
"";
91 safe_setup_filesystem_str(
const char *str)
93 if (str == 0) str =
"";
100 setup_passwd(
struct passwd *pwd)
104 safe_setup_locale_str(pwd->pw_name),
105 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
106 safe_setup_str(pwd->pw_passwd),
110 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
111 safe_setup_locale_str(pwd->pw_gecos),
113 safe_setup_filesystem_str(pwd->pw_dir),
114 safe_setup_filesystem_str(pwd->pw_shell),
115 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
118 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
121 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
122 PW_AGE2VAL(pwd->pw_age),
124 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
125 safe_setup_locale_str(pwd->pw_class),
127 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
128 safe_setup_locale_str(pwd->pw_comment),
130 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
158 #if defined(HAVE_GETPWENT)
171 return setup_passwd(pwd);
201 return setup_passwd(pwd);
208 static int passwd_blocking = 0;
213 passwd_blocking = (int)
Qfalse;
223 while (pw = getpwent()) {
232 if (passwd_blocking) {
235 passwd_blocking = (int)
Qtrue;
236 rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
269 else if (pw = getpwent()) {
270 return setup_passwd(pw);
351 if (pw = getpwent()) {
352 return setup_passwd(pw);
360 setup_group(
struct group *grp)
372 safe_setup_locale_str(grp->gr_name),
373 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
374 safe_setup_str(grp->gr_passwd),
413 return setup_group(grp);
444 return setup_group(grp);
451 static int group_blocking = 0;
456 group_blocking = (int)
Qfalse;
467 while (pw = getgrent()) {
476 if (group_blocking) {
479 group_blocking = (int)
Qtrue;
480 rb_ensure(group_iterate, 0, group_ensure, 0);
509 else if (grp = getgrent()) {
510 return setup_group(grp);
540 etc_each_group(
VALUE obj)
588 if (gr = getgrent()) {
589 return setup_group(gr);
595 #define numberof(array) (sizeof(array) / sizeof(*(array)))
628 WCHAR path[_MAX_PATH];
630 if (!len)
return Qnil;
691 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
696 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
701 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
704 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
707 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
710 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
713 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
716 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
768 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
static VALUE etc_getpwnam(VALUE obj, VALUE nam)
static VALUE etc_endgrent(VALUE obj)
static VALUE etc_group(VALUE obj)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE etc_setpwent(VALUE obj)
static VALUE etc_getpwent(VALUE obj)
static VALUE etc_setgrent(VALUE obj)
VALUE rb_struct_new(VALUE,...)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE etc_getgrnam(VALUE obj, VALUE nam)
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE etc_systmpdir(void)
#define CSIDL_COMMON_APPDATA
static VALUE etc_getpwuid(int argc, VALUE *argv, VALUE obj)
VALUE rb_struct_define_under(VALUE, const char *,...)
static VALUE etc_passwd(VALUE obj)
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
int rb_block_given_p(void)
static VALUE etc_getgrgid(int argc, VALUE *argv, VALUE obj)
void rb_define_const(VALUE, const char *, VALUE)
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len)
VALUE rb_locale_str_new_cstr(const char *)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
static VALUE etc_getlogin(VALUE obj)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_extend_object(VALUE obj, VALUE module)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
#define rb_tainted_str_new2
void rb_sys_fail(const char *mesg)
static VALUE etc_each_passwd(VALUE obj)
RUBY_EXTERN VALUE rb_cStruct
VALUE rb_w32_special_folder(int type)
static VALUE etc_endpwent(VALUE obj)
rb_encoding * rb_filesystem_encoding(void)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define SafeStringValue(v)
VALUE rb_filesystem_str_new_cstr(const char *)
VALUE rb_define_module(const char *name)
static VALUE etc_sysconfdir(VALUE obj)
static VALUE etc_getgrent(VALUE obj)