aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzqqw2020-05-28 03:30:19 +0000
committerGitHub2020-05-28 03:30:19 +0000
commitd2030e0bf79d8a2252ae4750dbb0086bd06b72cb (patch)
tree40f5e739bcee3b27ac8103d5bda06adcc7639bbf
parent36e59748983034d5d39293e5d2415e92c14e2a22 (diff)
parent38a6904a948661802d2c744e0c2b9759e11fbd70 (diff)
Merge pull request #2 from bernimoses/master
Support remote passwd providers like SSSD.
-rw-r--r--src/utils.nim28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/utils.nim b/src/utils.nim
index 8ca68d4..c329b68 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -215,22 +215,18 @@ proc setgroups*(size: csize, groups: ptr cint): cint
{.importc, header: "<grp.h>".}
proc getUser(uid: int): User =
- while true:
- var pw = getpwent()
- if pw == nil:
- endpwent()
- raise newException(CatchableError, "")
- if pw.pw_uid.int == uid:
- var groups: array[100, cint]
- var ngroups: cint = 100
- if getgrouplist(pw.pw_name, pw.pw_gid, addr(groups[0]), ngroups) < 0:
- raise newException(CatchableError, "")
- else:
- let groupsSeq = groups[0 .. ngroups - 1].map(x => x.int)
- let res = ($pw.pw_name, pw.pw_uid.int, pw.pw_gid.int, groupsSeq,
- $pw.pw_dir, $pw.pw_shell)
- endpwent()
- return res
+ var pw = getpwuid(Uid(uid))
+ if pw == nil:
+ raise newException(CatchableError, "")
+ var groups: array[100, cint]
+ var ngroups: cint = 100
+ if getgrouplist(pw.pw_name, pw.pw_gid, addr(groups[0]), ngroups) < 0:
+ raise newException(CatchableError, "")
+ else:
+ let groupsSeq = groups[0 .. ngroups - 1].map(x => x.int)
+ let res = ($pw.pw_name, pw.pw_uid.int, pw.pw_gid.int, groupsSeq,
+ $pw.pw_dir, $pw.pw_shell)
+ return res
let currentUser* = getUser(getuid().int)