-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinceUsers.lua
More file actions
90 lines (74 loc) · 2.08 KB
/
princeUsers.lua
File metadata and controls
90 lines (74 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/env lua
local princeUsers = { }
local princeUtils = require "princeUtils"
local princeStakeholders = require "princeStakeholders"
local slurm_log = princeUtils.slurm_log
local user_log = princeUtils.user_log
local users = { }
users["0"] = "root"
users["1015"] = "wang"
users["1032"] = "stratos"
users["1041"] = "deng"
-- users["1042"] = "peskin"
users["1044"] = "teague"
-- users["1045"] = "polunina"
users["1048"] = "dedits"
users["50202"] = "gencore"
users["51202"] = "cbi"
users["51207"] = "lgs"
users["51203"] = "smappx"
users["15000"] = "hpcadmin"
local blocked_netids = princeStakeholders.blocked_netids
local netid = nil
local function create_users_from_etc_passwd()
slurm_log("setup users from /etc/passwd")
local passwd_file = "/etc/passwd"
local fin = io.open(passwd_file, "r")
if fin == nil then return end
local netid, uid
local n = 0
while true do
local line = fin:read("*l")
if line == nil then break end
_, _, netid, uid = string.find(line, "^(%a+%d+):x:(%d+):")
if netid ~= nil and uid ~= nil then
users[uid] = netid
n = n + 1
end
end
fin:close()
slurm_log("%d netids in users", n)
end
local function uid_to_netid(uid)
local uid = string.format("%d", uid)
netid = users[uid]
if netid == nil then
create_users_from_etc_passwd()
netid = users[uid]
end
end
local function uid_is_valid(uid)
uid_to_netid(uid)
if netid == nil then
user_log("uid %d is not valid to run jobs", uid)
return false
end
return true
end
local function netid_is_blocked(uid)
if not uid_is_valid(uid) then return true end
if #blocked_netids > 0 and princeUtils.in_table(blocked_netids, netid) then
slurm_log("user %s is blocked to submit jobs", netid)
user_log("Sorry, you are not allowed to submit jobs now, please contact hpc@nyu.edu for help")
return true
end
return false
end
local function nyu_netid()
return netid
end
-- functions
princeUsers.nyu_netid = nyu_netid
princeUsers.netid_is_blocked = netid_is_blocked
slurm_log("To load princeUsers.lua")
return princeUsers