static VALUE rb_shadow_sgetspent(VALUE self, VALUE str) { struct spwd *entry; VALUE result; if( TYPE(str) != T_STRING ) rb_raise(rb_eException,"argument must be a string."); entry = sgetspent(StringValuePtr(str)); if( entry == NULL ) return Qnil; result = rb_struct_new(rb_sPasswdEntry, rb_tainted_str_new2(entry->sp_namp), rb_tainted_str_new2(entry->sp_pwdp), INT2FIX(entry->sp_lstchg), INT2FIX(entry->sp_min), INT2FIX(entry->sp_max), INT2FIX(entry->sp_warn), INT2FIX(entry->sp_inact), INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), 0); free(entry); return result; };
void testValues() { f = 2; struct spwd * result = sgetspent(anystring()); //@ assert result != \null ==> \valid_read(result->sp_namp); //@ assert f == 2; //@ assert vacuous: \false; }
/* fgetspent - get an entry from an /etc/shadow formatted stream */ struct spwd *fgetspent(FILE *fp) { char buf[BUFSIZ]; char *cp; if (!fp) /* return (0); */ return NULL; if (fgets(buf, sizeof buf, fp) != (char *) 0) { if ((cp = strchr(buf, '\n'))) *cp = '\0'; return (sgetspent(buf)); } /* return 0; */ return NULL; }
static VALUE rb_shadow_sgetspent(VALUE self, VALUE str) { struct spwd *entry; VALUE result; if( TYPE(str) != T_STRING ) rb_raise(rb_eException,"argument must be a string."); entry = sgetspent(StringValuePtr(str)); if( entry == NULL ) return Qnil; result = convert_pw_struct( entry ); free(entry); return result; };
static void * shadow_parse(const char *line) { return (void *) sgetspent(line); }
void runFailure() { sgetspent(NULL); }
void runSuccess() { sgetspent(anystring()); }