Created
June 29, 2009 15:39
-
-
Save mattrose/137657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p1 = open("passwd").read.split("\n") | |
s1 = open("shadow").read.split("\n") | |
s1.delete_if { |ent| ent.split(":")[1] !~ /^\$1\$/ } | |
shash = Hash[*s1.collect { |e| [e.split(":",2)[0],e.split(":",2)[1]]}.flatten] | |
phash = Hash[*p1.collect { |e| [e.split(":",2)[0],e.split(":",2)[1]]}.flatten] | |
newpasswd = open("/tmp/passwd").read | |
phash.each { |k,v| | |
unless newpasswd.split("\n").include?(k + ":" + v) | |
if shash.has_key?(k) | |
newpasswd << k + ":" + v + "\n" | |
end | |
end | |
} | |
newshadow = open("/tmp/shadow").read.split("\n") | |
s1.each { |e| | |
unless newshadow.include?(e) | |
newshadow << e | |
end | |
} | |
puts newshadow.join("\n") | |
open("/tmp/shadow",'a') {|f| f.write(newshadow.join("\n")) ; f.write("\n")} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment