Skip to content

Commit

Permalink
feat(hostinfo/passwd): Added a hostinfo check to get passwd stati
Browse files Browse the repository at this point in the history
added passwd hostinfo check to all

fix(hostinfo/passwd): Fix funky spawn error
  • Loading branch information
kaustavha committed Jul 28, 2015
1 parent c4c2721 commit 1d9d627
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions hostinfo/all.lua
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
--]]
return {
require('./passwd'),
require('./pam'),
require('./cron'),
require('./kernel_modules'),
Expand Down
82 changes: 82 additions & 0 deletions hostinfo/passwd.lua
@@ -0,0 +1,82 @@
--[[
Copyright 2015 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]
local HostInfo = require('./base').HostInfo
local fs = require('fs')
local los = require('los')
local table = require('table')
local asyncSpawn = require('./misc').asyncSpawn
--[[ Passwordstatus Variables ]]--
local Info = HostInfo:extend()
function Info:initialize()
HostInfo.initialize(self)
end
function Info:run(callback)
if los.type() ~= 'linux' then
self._error = 'Unsupported OS for passwdstatus'
return callback()
end
fs.readFile('/etc/passwd', function (err, data)
if err then
self._error = "Couldn't read /etc/passwd"
return callback()
end
local users = {}
for line in data:gmatch("[^\r\n]+") do
local name = line:match("[^:]*")
table.insert(users, name)
end
local function spawnFunc(datum)
return 'passwd', {'-S', datum}
end
local function successFunc(data, obj, datum)
data = data:gsub('[\n|"]','')
local iter = data:gmatch("%S+")
obj[iter()] = {
status = iter(),
last_changed = iter(),
minimum_age = iter(),
warning_period = iter(),
inactivity_period = iter()
}
end
local function finalCb(obj, errData)
if obj ~= nil then
table.insert(self._params, obj)
return callback()
else
table.insert(self._err, errdata)
return callback()
end
end
return asyncSpawn(users, spawnFunc, successFunc, finalCb)
end)
end
function Info:getType()
return 'PASSWD'
end
return Info

0 comments on commit 1d9d627

Please sign in to comment.