Skip to content

Commit

Permalink
Allow users to have any shell defined in /etc/shells
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Jan 11, 2024
1 parent 854a345 commit 092586f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions sync-accounts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,27 @@ def read_permissions(config_file_or_url)
permissions
end

def shells
return $shells if defined?($shells)
$shells = File.read('/etc/shells').lines.map{|l|l.strip}.select { |l| !l.empty? && !l.start_with?('#') }
$shells
end

def system_users
users = `cat /etc/passwd | grep -v root | grep '/bin/bash'`.split("\n").map do |u|
u =~ /([^\s]+):.*:.*:.*:.*:([^\s]+):\/bin\/bash$/
{:name => $1, :home => $2}
users = `cat /etc/passwd | grep -v root`.split("\n").map do |u|
u =~ /([^\s]+):.*:.*:.*:.*:([^\s]+):([^:]+)$/
{name: $1, home: $2, shell: $3}
end
users = users.select{|u| u[:home] && u[:name] }
users = users.select{|u| u[:home] && u[:name] && shells.include?(u[:shell]) }
users.select{|u| u[:home].index('/home') == 0 }
end

def system_apps
users = `cat /etc/passwd | grep -v root | grep '/bin/bash'`.split("\n").map do |u|
u =~ /([^\s]+):.*:.*:.*:.*:([^\s]+):\/bin\/bash$/
{:name => $1, :home => $2}
users = `cat /etc/passwd | grep -v root`.split("\n").map do |u|
u =~ /([^\s]+):.*:.*:.*:.*:([^\s]+):([^:]+)$/
{name: $1, home: $2, shell: $3}
end
users = users.select{|u| u[:home] && u[:name] }
users = users.select{|u| u[:home] && u[:name] && shells.include?(u[:shell]) }
users.select{|u| u[:home].index('/srv') == 0 }
end

Expand Down

0 comments on commit 092586f

Please sign in to comment.