diff --git a/src/group.zig b/src/group.zig index c8c22c6..dadb092 100644 --- a/src/group.zig +++ b/src/group.zig @@ -153,12 +153,12 @@ test "construct PackedGroups" { defer buf.deinit(); const groups = [_]GroupStored{ - .{ + GroupStored{ .gid = 1000, .name = "sudo", .members_offset = 1, }, - .{ + GroupStored{ .gid = std.math.maxInt(u32), .name = "Name" ** 8, // 32 .members_offset = std.math.maxInt(u64), diff --git a/src/sections.zig b/src/sections.zig index 9bff7db..fa18182 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -15,15 +15,17 @@ const BufSet = std.BufSet; const pad = @import("padding.zig"); const compress = @import("compress.zig"); -const shellImport = @import("shell.zig"); -const userImport = @import("user.zig"); -const groupImport = @import("group.zig"); +const PackedUser = @import("user.zig").PackedUser; +const User = @import("user.zig").User; +const Group = @import("group.zig").Group; +const GroupStored = @import("group.zig").GroupStored; +const PackedGroup = @import("group.zig").PackedGroup; +const ShellSections = @import("shell.zig").ShellWriter.ShellSections; +const ShellReader = @import("shell.zig").ShellReader; +const ShellWriter = @import("shell.zig").ShellWriter; +const max_shells = @import("shell.zig").max_shells; const cmph = @import("cmph.zig"); const bdz = @import("bdz.zig"); -const User = userImport.User; -const Group = groupImport.Group; -const ShellSections = shellImport.ShellWriter.ShellSections; -const ShellReader = shellImport.ShellReader; const Corpus = struct { arena: std.heap.ArenaAllocator, @@ -137,10 +139,10 @@ pub fn shellSections( allocator: Allocator, corpus: *const Corpus, ) error{ OutOfMemory, Overflow }!ShellSections { - var popcon = shellImport.ShellWriter.init(allocator); + var popcon = ShellWriter.init(allocator); for (corpus.users.items(.shell)) |shell| try popcon.put(shell); - return popcon.toOwnedSections(shellImport.max_shells); + return popcon.toOwnedSections(max_shells); } pub const UserGids = struct { @@ -230,13 +232,13 @@ pub fn usersSection( const user_offset = try math.cast(u35, blob.items.len); assert(user_offset & 7 == 0); idx2offset[i] = @truncate(u32, user_offset >> 3); - try userImport.PackedUser.packTo( + try PackedUser.packTo( &blob, user, gids.idx2offset[i], shells.shell2idx, ); - try pad.arrayList(&blob, userImport.PackedUser.alignment_bits); + try pad.arrayList(&blob, PackedUser.alignment_bits); } return UsersSection{ .idx2offset = idx2offset, @@ -327,13 +329,13 @@ pub fn groupsSection( const group_offset = try math.cast(u32, blob.items.len); assert(group_offset & 7 == 0); idx2offset[i] = @truncate(u32, group_offset >> 3); - const group_stored = groupImport.GroupStored{ + const group_stored = GroupStored{ .gid = group.gid, .name = group.name, .members_offset = members_offset[i], }; - try groupImport.PackedGroup.packTo(&blob, group_stored); - try pad.arrayList(&blob, groupImport.PackedGroup.alignment_bits); + try PackedGroup.packTo(&blob, group_stored); + try pad.arrayList(&blob, PackedGroup.alignment_bits); } return GroupsSection{ @@ -459,7 +461,7 @@ pub const AllSections = struct { .bdz_uid = bdz_uid, .bdz_username = bdz_username, .shell_sections = shell_sections, - .shell_reader = shellImport.ShellReader.init( + .shell_reader = ShellReader.init( mem.sliceAsBytes(shell_sections.index.constSlice()), mem.sliceAsBytes(shell_sections.blob.constSlice()), ), @@ -493,6 +495,7 @@ pub const AllSections = struct { }; const testing = std.testing; +const someMembers = @import("group.zig").someMembers; fn testCorpus(allocator: Allocator) !Corpus { const users = [_]User{ User{ @@ -525,19 +528,19 @@ fn testCorpus(allocator: Allocator) !Corpus { .shell = "/usr/sbin/nologin", } }; - var members1 = try groupImport.someMembers( + var members1 = try someMembers( allocator, &[_][]const u8{"vidmantas"}, ); defer members1.deinit(); - var members2 = try groupImport.someMembers( + var members2 = try someMembers( allocator, &[_][]const u8{ "svc-bar", "vidmantas" }, ); defer members2.deinit(); - var members3 = try groupImport.someMembers( + var members3 = try someMembers( allocator, &[_][]const u8{ "svc-bar", "Name" ** 8, "vidmantas" }, ); @@ -614,10 +617,7 @@ test "test groups, group members and users" { try testing.expectEqual(it.next(), null); } - var it = userImport.PackedUser.iterator( - sections.users.blob, - sections.shell_reader, - ); + var it = PackedUser.iterator(sections.users.blob, sections.shell_reader); i = 0; while (i < corpus.users.len) : (i += 1) { const got = (try it.next()).?;