aboutsummaryrefslogtreecommitdiff
path: root/src/utils.nim
diff options
context:
space:
mode:
authorshirleyquirk2020-08-04 23:53:21 +0000
committerGitHub2020-08-04 23:53:21 +0000
commit731f8d7692bfe08f5fd5890a98797f9b1b8d065d (patch)
tree512a18c53d4e7e6878ea134a2a307e3caec2278d /src/utils.nim
parent29e12415d4bae7a08fa9f3024d809b5a3be76ba1 (diff)
parentb2321b0ded6f4a9803daf9dbcbd88d56321a9305 (diff)
Merge branch 'lc_useVersion' into collect
Diffstat (limited to 'src/utils.nim')
-rw-r--r--src/utils.nim29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/utils.nim b/src/utils.nim
index e46a8e0..da9618b 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -211,26 +211,23 @@ proc forkWaitRedirect*(call: () -> int): tuple[output: seq[string], code: int] =
proc getgrouplist*(user: cstring, group: Gid, groups: ptr cint, ngroups: var cint): cint
{.importc, header: "<grp.h>".}
+
proc setgroups*(size: csize_t, 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)