Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created May 2, 2011 18:55
Show Gist options
  • Save weissjeffm/952131 to your computer and use it in GitHub Desktop.
Save weissjeffm/952131 to your computer and use it in GitHub Desktop.
How to test ruby-shadow
[root@host ~]# irb
irb(main):001:0> require "/usr/lib64/ruby/site_ruby/1.8/powerpc64-linux/shadow.so" #varies by platform - check 'rpm -ql ruby-shadow' for real location.
=> true
irb(main):004:0> Shadow::Passwd.getspent()
=> #<struct Struct::PasswdEntry sp_namp="root", sp_pwdp="$1$s9SM/aIM$ATv5Gcjkd2b/G/rkddVTq0", sp_lstchg=15095, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1>
(execute getspent() repeatedly, should give a new user entry each time.
irb(main):009:0> Shadow::Passwd.setspent()
=> nil
irb(main):010:0> Shadow::Passwd.getspent()
=> #<struct Struct::PasswdEntry sp_namp="root", sp_pwdp="$1$redhat$9yxjZID8FYVlQzHGhasqW/", sp_lstchg=15097, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1>
(running setspent should reset back to the first entry, which you can get again with getspent)
irb(main):005:0> Shadow::Passwd.getspnam("root")
=> #<struct Struct::PasswdEntry sp_namp="root", sp_pwdp="$1$s9SM/aIM$ATv5Gcjkd2b/G/rkddVTq0", sp_lstchg=15095, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, s
(gives you a particular user entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment