Method: Cfruby::Users::FreeBSDUserManager#users

Defined in:
lib/libcfruby/osmodules/freebsd.rb

#usersObject

returns a list of all the users on the system



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/libcfruby/osmodules/freebsd.rb', line 227

def users()
  userlist = UserList.new()

  File.open('/etc/passwd', File::RDONLY) { |fp|
    regex = /^([a-zA-Z0-9-]+):[^:]+:([0-9]+):([0-9]+):([^:]*):([^:]*):([^:]*)$/
    fp.each_line() { |line|
      match = regex.match(line)
      if(match != nil)
        user = UserInfo.new()
        user.username = match[1]
        user.uid = match[2].to_i()
        user.gid = match[3].to_i()
        user.fullname = match[4]
        user.homedir = match[5]
        user.shell = match[6]
        userlist[user.username] = user
      end
    }
  }

  return(userlist)
end