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