mirror of https://github.com/fairyglade/ly.git
Fix xauth command for some shells and fix building in ReleaseSafe
This commit is contained in:
parent
5aa03df2bf
commit
ebb8fe3a84
10
build.zig
10
build.zig
|
@ -40,6 +40,16 @@ pub fn build(b: *std.Build) !void {
|
||||||
exe.linkSystemLibrary("xcb");
|
exe.linkSystemLibrary("xcb");
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
|
|
||||||
|
// Only fails with ReleaseSafe, so we'll override it.
|
||||||
|
const translate_c = b.addTranslateC(.{
|
||||||
|
.root_source_file = .{ .path = "include/termbox2.h" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = if (optimize == .ReleaseSafe) .ReleaseFast else optimize,
|
||||||
|
});
|
||||||
|
translate_c.defineCMacroRaw("TB_IMPL");
|
||||||
|
const termbox2 = translate_c.addModule("termbox2");
|
||||||
|
exe.root_module.addImport("termbox2", termbox2);
|
||||||
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
|
35
src/auth.zig
35
src/auth.zig
|
@ -327,7 +327,36 @@ fn createXauthFile(pwd: [:0]const u8) ![:0]const u8 {
|
||||||
return xauthority;
|
return xauthority;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xauth(display_name: [:0]u8, shell: [*:0]const u8, pw_dir: [*:0]const u8, xauth_cmd: []const u8, mcookie_cmd: []const u8) !void {
|
pub fn mcookie(cmd: [:0]const u8) ![32]u8 {
|
||||||
|
const pipe = try std.posix.pipe();
|
||||||
|
defer std.posix.close(pipe[1]);
|
||||||
|
|
||||||
|
const output = std.fs.File{ .handle = pipe[0] };
|
||||||
|
defer output.close();
|
||||||
|
|
||||||
|
const pid = try std.posix.fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
std.posix.close(pipe[0]);
|
||||||
|
|
||||||
|
std.posix.dup2(pipe[1], std.posix.STDOUT_FILENO) catch std.process.exit(1);
|
||||||
|
std.posix.close(pipe[1]);
|
||||||
|
|
||||||
|
const args = [_:null]?[*:0]u8{};
|
||||||
|
std.posix.execveZ(cmd.ptr, &args, std.c.environ) catch {};
|
||||||
|
std.process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = std.posix.waitpid(pid, 0);
|
||||||
|
|
||||||
|
if (result.status != 0) return error.CommandFailed;
|
||||||
|
|
||||||
|
var buf: [32]u8 = undefined;
|
||||||
|
const len = try output.read(&buf);
|
||||||
|
if (len != 32) return error.UnexpectedLength;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xauth(display_name: [:0]u8, shell: [*:0]const u8, pw_dir: [*:0]const u8, xauth_cmd: []const u8, mcookie_cmd: [:0]const u8) !void {
|
||||||
var pwd_buf: [100]u8 = undefined;
|
var pwd_buf: [100]u8 = undefined;
|
||||||
const pwd = try std.fmt.bufPrintZ(&pwd_buf, "{s}", .{pw_dir});
|
const pwd = try std.fmt.bufPrintZ(&pwd_buf, "{s}", .{pw_dir});
|
||||||
|
|
||||||
|
@ -335,10 +364,12 @@ fn xauth(display_name: [:0]u8, shell: [*:0]const u8, pw_dir: [*:0]const u8, xaut
|
||||||
_ = interop.setenv("XAUTHORITY", xauthority, 1);
|
_ = interop.setenv("XAUTHORITY", xauthority, 1);
|
||||||
_ = interop.setenv("DISPLAY", display_name, 1);
|
_ = interop.setenv("DISPLAY", display_name, 1);
|
||||||
|
|
||||||
|
const mcookie_output = try mcookie(mcookie_cmd);
|
||||||
|
|
||||||
const pid = try std.posix.fork();
|
const pid = try std.posix.fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
var cmd_buffer: [1024]u8 = undefined;
|
var cmd_buffer: [1024]u8 = undefined;
|
||||||
const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} add {s} . $({s})", .{ xauth_cmd, display_name, mcookie_cmd }) catch std.process.exit(1);
|
const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} add {s} . {s}", .{ xauth_cmd, display_name, mcookie_output }) catch std.process.exit(1);
|
||||||
const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str };
|
const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str };
|
||||||
std.posix.execveZ(shell, &args, std.c.environ) catch {};
|
std.posix.execveZ(shell, &args, std.c.environ) catch {};
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
|
|
|
@ -27,7 +27,7 @@ margin_box_v: u8 = 1,
|
||||||
max_desktop_len: u8 = 100,
|
max_desktop_len: u8 = 100,
|
||||||
max_login_len: u8 = 255,
|
max_login_len: u8 = 255,
|
||||||
max_password_len: u8 = 255,
|
max_password_len: u8 = 255,
|
||||||
mcookie_cmd: []const u8 = "/usr/bin/mcookie",
|
mcookie_cmd: [:0]const u8 = "/usr/bin/mcookie",
|
||||||
min_refresh_delta: u16 = 5,
|
min_refresh_delta: u16 = 5,
|
||||||
numlock: bool = false,
|
numlock: bool = false,
|
||||||
path: ?[:0]const u8 = "/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin",
|
path: ?[:0]const u8 = "/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin",
|
||||||
|
|
|
@ -2,10 +2,7 @@ const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
pub const termbox = @cImport({
|
pub const termbox = @import("termbox2");
|
||||||
@cDefine("TB_IMPL", {});
|
|
||||||
@cInclude("termbox2.h");
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const pam = @cImport({
|
pub const pam = @cImport({
|
||||||
@cInclude("security/pam_appl.h");
|
@cInclude("security/pam_appl.h");
|
||||||
|
|
Loading…
Reference in New Issue