13 #include <sys/types.h>
33 #ifndef CSIDL_COMMON_APPDATA
34 #define CSIDL_COMMON_APPDATA 35
65 if (!login) login =
getenv(
"USER");
82 #if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
84 safe_setup_str(
const char *
str)
86 if (str == 0) str =
"";
91 safe_setup_locale_str(
const char *str)
93 if (str == 0) str =
"";
98 safe_setup_filesystem_str(
const char *str)
100 if (str == 0) str =
"";
107 setup_passwd(
struct passwd *pwd)
111 safe_setup_locale_str(pwd->pw_name),
112 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
113 safe_setup_str(pwd->pw_passwd),
117 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
118 safe_setup_locale_str(pwd->pw_gecos),
120 safe_setup_filesystem_str(pwd->pw_dir),
121 safe_setup_filesystem_str(pwd->pw_shell),
122 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
125 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
128 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
129 PW_AGE2VAL(pwd->pw_age),
131 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
132 safe_setup_locale_str(pwd->pw_class),
134 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
135 safe_setup_locale_str(pwd->pw_comment),
137 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
165 #if defined(HAVE_GETPWENT)
178 return setup_passwd(pwd);
208 return setup_passwd(pwd);
215 static int passwd_blocking = 0;
230 while (pw = getpwent()) {
239 if (passwd_blocking) {
243 rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
276 else if (pw = getpwent()) {
277 return setup_passwd(pw);
358 if (pw = getpwent()) {
359 return setup_passwd(pw);
367 setup_group(
struct group *grp)
379 safe_setup_locale_str(grp->gr_name),
380 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
381 safe_setup_str(grp->gr_passwd),
420 return setup_group(grp);
451 return setup_group(grp);
458 static int group_blocking = 0;
474 while (pw = getgrent()) {
483 if (group_blocking) {
487 rb_ensure(group_iterate, 0, group_ensure, 0);
516 else if (grp = getgrent()) {
517 return setup_group(grp);
595 if (gr = getgrent()) {
596 return setup_group(gr);
602 #define numberof(array) (sizeof(array) / sizeof(*(array)))
635 WCHAR
path[_MAX_PATH];
637 if (!len)
return Qnil;
698 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
703 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
708 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
711 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
714 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
717 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
720 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
723 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
775 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
static VALUE etc_getpwnam(VALUE obj, VALUE nam)
static VALUE etc_endgrent(VALUE obj)
size_t strlen(const char *)
static VALUE etc_group(VALUE obj)
#define rb_tainted_str_new2
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_ary_push(VALUE ary, VALUE item)
static VALUE etc_getgrnam(VALUE obj, VALUE nam)
VALUE rb_struct_new(VALUE,...)
void rb_raise(VALUE exc, const char *fmt,...)
static VALUE etc_systmpdir(void)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define CSIDL_COMMON_APPDATA
#define SafeStringValue(v)
static VALUE etc_getpwuid(int argc, VALUE *argv, VALUE obj)
rb_encoding * rb_utf8_encoding(void)
static VALUE etc_passwd(VALUE obj)
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
int rb_block_given_p(void)
VALUE rb_locale_str_new_cstr(const char *)
void rb_define_const(VALUE, const char *, VALUE)
static VALUE etc_getgrgid(int argc, VALUE *argv, VALUE obj)
VALUE rb_struct_define_under(VALUE, const char *,...)
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len)
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,...)
rb_encoding * rb_locale_encoding(void)
void rb_extend_object(VALUE obj, VALUE module)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
void rb_sys_fail(const char *mesg)
static VALUE etc_each_passwd(VALUE obj)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
VALUE rb_w32_special_folder(int type)
static VALUE etc_endpwent(VALUE obj)
rb_encoding * rb_filesystem_encoding(void)
VALUE rb_define_module(const char *name)
VALUE rb_filesystem_str_new_cstr(const char *)
static VALUE etc_sysconfdir(VALUE obj)
static VALUE etc_getgrent(VALUE obj)
RUBY_EXTERN VALUE rb_cStruct