From 55ef58ad7e87489fd488eb13c60a5200eb13a5f2 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Sun, 31 Dec 2023 16:44:30 +0100 Subject: [PATCH] Try to fix some more bugs Signed-off-by: AnErrupTion --- src/auth.zig | 26 ++++++++++++++++++-------- src/main.zig | 5 +---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/auth.zig b/src/auth.zig index 4401d29..9d3941c 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -35,14 +35,27 @@ pub fn authenticate( try setXdgEnv(allocator, tty_str, uid_str, current_environment.xdg_name); // Open the PAM session - var credentials = [_][]const u8{ login.text.items, password.text.items }; + const login_text_z = try allocator.dupeZ(u8, login.text.items); + defer allocator.free(login_text_z); + + const password_text_z = try allocator.dupeZ(u8, password.text.items); + defer allocator.free(password_text_z); + + var credentials: [*c][*c]const u8 = undefined; + credentials[0] = login_text_z.ptr; + credentials[1] = password_text_z.ptr; + credentials[2] = 0; + const conv = interop.pam.pam_conv{ .conv = loginConv, .appdata_ptr = @ptrCast(&credentials), }; var handle: ?*interop.pam.pam_handle = undefined; - var status = interop.pam.pam_start(service_name.ptr, null, &conv, &handle); + const service_name_z = try allocator.dupeZ(u8, service_name); + defer allocator.free(service_name_z); + + var status = interop.pam.pam_start(service_name_z.ptr, null, &conv, &handle); defer status = interop.pam.pam_end(handle, status); if (status != interop.pam.PAM_SUCCESS) return pamDiagnose(status); @@ -64,9 +77,6 @@ pub fn authenticate( password.clear(); // Get password structure from username - const login_text_z = try allocator.dupeZ(u8, login.text.items); - defer allocator.free(login_text_z); - const maybe_pwd = interop.getpwnam(login_text_z.ptr); interop.endpwent(); @@ -198,12 +208,12 @@ fn setXdgEnv(allocator: Allocator, tty_str: [:0]u8, uid_str: [:0]u8, desktop_nam const desktop_name_z = try allocator.dupeZ(u8, desktop_name); defer allocator.free(desktop_name_z); - _ = interop.setenv("XDG_RUNTIME_DIR", uid_str, 0); + _ = interop.setenv("XDG_RUNTIME_DIR", uid_str.ptr, 0); _ = interop.setenv("XDG_SESSION_CLASS", "user", 0); _ = interop.setenv("XDG_SESSION_ID", "1", 0); - _ = interop.setenv("XDG_SESSION_DESKTOP", desktop_name_z, 0); + _ = interop.setenv("XDG_SESSION_DESKTOP", desktop_name_z.ptr, 0); _ = interop.setenv("XDG_SEAT", "seat0", 0); - _ = interop.setenv("XDG_VTNR", tty_str, 0); + _ = interop.setenv("XDG_VTNR", tty_str.ptr, 0); } fn loginConv( diff --git a/src/main.zig b/src/main.zig index 960f41e..b649449 100644 --- a/src/main.zig +++ b/src/main.zig @@ -138,16 +138,13 @@ pub fn main() !void { const reader = file.reader(); const username_length = try reader.readIntLittle(u64); - const username_buffer = try reader.readAllAlloc(allocator, username_length); + const username_buffer = try allocator.alloc(u8, username_length); defer allocator.free(username_buffer); _ = try reader.read(username_buffer); const current_desktop = try reader.readIntLittle(u64); - const load_buffer = try reader.readAllAlloc(allocator, config.ly.max_login_len + 5); - defer allocator.free(load_buffer); - if (username_buffer.len > 0) { try login.text.appendSlice(username_buffer); login.end = username_buffer.len;