| ... | ... | @@ -593,8 +593,10 @@ pub fn getUserInfo(name: []const u8) !UserInfo { |
| 593 | 593 | /// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else |
| 594 | 594 | /// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`. |
| 595 | 595 | pub fn posixGetUserInfo(name: []const u8) !UserInfo { |
| 596 | | var reader = try io.Reader.open("/etc/passwd", null); |
| 597 | | defer reader.close(); |
| 596 | const file = try std.fs.openFileAbsolute("/etc/passwd", .{}); |
| 597 | defer file.close(); |
| 598 | |
| 599 | const reader = file.reader(); |
| 598 | 600 | |
| 599 | 601 | const State = enum { |
| 600 | 602 | Start, |
| ... | ... | @@ -650,8 +652,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo { |
| 650 | 652 | '0'...'9' => byte - '0', |
| 651 | 653 | else => return error.CorruptPasswordFile, |
| 652 | 654 | }; |
| 653 | | if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile; |
| 654 | | if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile; |
| 655 | if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile; |
| 656 | if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile; |
| 655 | 657 | }, |
| 656 | 658 | }, |
| 657 | 659 | .ReadGroupId => switch (byte) { |
| ... | ... | @@ -666,8 +668,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo { |
| 666 | 668 | '0'...'9' => byte - '0', |
| 667 | 669 | else => return error.CorruptPasswordFile, |
| 668 | 670 | }; |
| 669 | | if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile; |
| 670 | | if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile; |
| 671 | if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile; |
| 672 | if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile; |
| 671 | 673 | }, |
| 672 | 674 | }, |
| 673 | 675 | } |