mirror of https://github.com/fairyglade/ly.git
Conditionally import login_cap.h with pwd.h
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
2c428f5537
commit
5e85618730
12
src/auth.zig
12
src/auth.zig
|
@ -66,12 +66,12 @@ pub fn authenticate(config: Config, current_environment: Session.Environment, lo
|
|||
if (status != interop.pam.PAM_SUCCESS) return pamDiagnose(status);
|
||||
defer status = interop.pam.pam_close_session(handle, 0);
|
||||
|
||||
var pwd: *interop.passwd = undefined;
|
||||
var pwd: *interop.pwd.passwd = undefined;
|
||||
{
|
||||
defer interop.endpwent();
|
||||
defer interop.pwd.endpwent();
|
||||
|
||||
// Get password structure from username
|
||||
pwd = interop.getpwnam(login) orelse return error.GetPasswordNameFailed;
|
||||
pwd = interop.pwd.getpwnam(login) orelse return error.GetPasswordNameFailed;
|
||||
}
|
||||
|
||||
// Set user shell if it hasn't already been set
|
||||
|
@ -122,7 +122,7 @@ pub fn authenticate(config: Config, current_environment: Session.Environment, lo
|
|||
|
||||
fn startSession(
|
||||
config: Config,
|
||||
pwd: *interop.passwd,
|
||||
pwd: *interop.pwd.passwd,
|
||||
handle: ?*interop.pam.pam_handle,
|
||||
current_environment: Session.Environment,
|
||||
) !void {
|
||||
|
@ -132,7 +132,7 @@ fn startSession(
|
|||
if (status != 0) return error.GroupInitializationFailed;
|
||||
|
||||
// FreeBSD sets the GID and UID with setusercontext()
|
||||
const result = interop.logincap.setusercontext(null, pwd, pwd.pw_uid, interop.logincap.LOGIN_SETALL);
|
||||
const result = interop.pwd.setusercontext(null, pwd, pwd.pw_uid, interop.pwd.LOGIN_SETALL);
|
||||
if (result != 0) return error.SetUserUidFailed;
|
||||
} else {
|
||||
const status = interop.grp.initgroups(pwd.pw_name, pwd.pw_gid);
|
||||
|
@ -166,7 +166,7 @@ fn startSession(
|
|||
}
|
||||
}
|
||||
|
||||
fn initEnv(pwd: *interop.passwd, path_env: ?[:0]const u8) !void {
|
||||
fn initEnv(pwd: *interop.pwd.passwd, path_env: ?[:0]const u8) !void {
|
||||
_ = interop.stdlib.setenv("HOME", pwd.pw_dir, 1);
|
||||
_ = interop.stdlib.setenv("PWD", pwd.pw_dir, 1);
|
||||
_ = interop.stdlib.setenv("SHELL", pwd.pw_shell, 1);
|
||||
|
|
|
@ -35,18 +35,15 @@ pub const stdlib = @cImport({
|
|||
|
||||
pub const pwd = @cImport({
|
||||
@cInclude("pwd.h");
|
||||
// We include a FreeBSD-specific header here since login_cap.h references
|
||||
// the passwd struct directly, so we can't import it separately'
|
||||
if (builtin.os.tag == .freebsd) @cInclude("login_cap.h");
|
||||
});
|
||||
|
||||
pub const grp = @cImport({
|
||||
@cInclude("grp.h");
|
||||
});
|
||||
|
||||
// FreeBSD-specific headers (except for pwd.h)
|
||||
pub const logincap = @cImport({
|
||||
@cInclude("pwd.h");
|
||||
@cInclude("login_cap.h");
|
||||
});
|
||||
|
||||
// BSD-specific headers
|
||||
pub const kbio = @cImport({
|
||||
@cInclude("sys/kbio.h");
|
||||
|
@ -61,11 +58,6 @@ pub const vt = @cImport({
|
|||
@cInclude("sys/vt.h");
|
||||
});
|
||||
|
||||
// On FreeBSD, login_cap.h references the passwd struct directly, so we must use logincap.passwd instead
|
||||
pub const passwd = if (builtin.os.tag == .freebsd) logincap.passwd else pwd.passwd;
|
||||
pub const endpwent = if (builtin.os.tag == .freebsd) logincap.endpwent else pwd.endpwent;
|
||||
pub const getpwnam = if (builtin.os.tag == .freebsd) logincap.getpwnam else pwd.getpwnam;
|
||||
|
||||
// Used for getting & setting the lock state
|
||||
const LedState = if (builtin.os.tag.isBSD()) c_int else c_char;
|
||||
const get_led_state = if (builtin.os.tag.isBSD()) kbio.KDGETLED else kd.KDGKBLED;
|
||||
|
|
Loading…
Reference in New Issue