mirror of https://github.com/fairyglade/ly.git
Don't dupeZ() in main
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
f9553655a3
commit
0a9ceca822
12
src/auth.zig
12
src/auth.zig
|
@ -32,7 +32,7 @@ pub fn sessionSignalHandler(i: c_int) callconv(.c) void {
|
|||
if (child_pid > 0) _ = std.c.kill(child_pid, i);
|
||||
}
|
||||
|
||||
pub fn authenticate(allocator: std.mem.Allocator, log_writer: *std.Io.Writer, options: AuthOptions, current_environment: Environment, login: [:0]const u8, password: [:0]const u8) !void {
|
||||
pub fn authenticate(allocator: std.mem.Allocator, log_writer: *std.Io.Writer, options: AuthOptions, current_environment: Environment, login: []const u8, password: []const u8) !void {
|
||||
var tty_buffer: [3]u8 = undefined;
|
||||
const tty_str = try std.fmt.bufPrint(&tty_buffer, "{d}", .{options.tty});
|
||||
|
||||
|
@ -43,7 +43,13 @@ pub fn authenticate(allocator: std.mem.Allocator, log_writer: *std.Io.Writer, op
|
|||
try setXdgEnv(allocator, tty_str, current_environment);
|
||||
|
||||
// Open the PAM session
|
||||
var credentials = [_:null]?[*:0]const u8{ login, password };
|
||||
const login_z = try allocator.dupeZ(u8, login);
|
||||
defer allocator.free(login_z);
|
||||
|
||||
const password_z = try allocator.dupeZ(u8, password);
|
||||
defer allocator.free(password_z);
|
||||
|
||||
var credentials = [_:null]?[*:0]const u8{ login_z, password_z };
|
||||
|
||||
const conv = interop.pam.pam_conv{
|
||||
.conv = loginConv,
|
||||
|
@ -79,7 +85,7 @@ pub fn authenticate(allocator: std.mem.Allocator, log_writer: *std.Io.Writer, op
|
|||
defer interop.closePasswordDatabase();
|
||||
|
||||
// Get password structure from username
|
||||
user_entry = interop.getUsernameEntry(login) orelse return error.GetPasswordNameFailed;
|
||||
user_entry = interop.getUsernameEntry(login_z) orelse return error.GetPasswordNameFailed;
|
||||
}
|
||||
|
||||
// Set user shell if it hasn't already been set
|
||||
|
|
|
@ -839,11 +839,6 @@ pub fn main() !void {
|
|||
defer shared_err.deinit();
|
||||
|
||||
{
|
||||
const login_text = try allocator.dupeZ(u8, login.getCurrentUser());
|
||||
defer allocator.free(login_text);
|
||||
const password_text = try allocator.dupeZ(u8, password.text.items);
|
||||
defer allocator.free(password_text);
|
||||
|
||||
session_pid = try std.posix.fork();
|
||||
if (session_pid == 0) {
|
||||
const current_environment = session.label.list.items[session.label.current];
|
||||
|
@ -867,7 +862,7 @@ pub fn main() !void {
|
|||
};
|
||||
std.posix.sigaction(std.posix.SIG.CHLD, &tty_control_transfer_act, null);
|
||||
|
||||
auth.authenticate(allocator, log_writer, auth_options, current_environment, login_text, password_text) catch |err| {
|
||||
auth.authenticate(allocator, log_writer, auth_options, current_environment, login.getCurrentUser(), password.text.items) catch |err| {
|
||||
shared_err.writeError(err);
|
||||
std.process.exit(1);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue