summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.build.yml5
-rw-r--r--meson.build44
-rw-r--r--meson_options.txt7
-rw-r--r--pam.c56
4 files changed, 74 insertions, 38 deletions
diff --git a/.build.yml b/.build.yml
index a4b8747..1c1bc12 100644
--- a/.build.yml
+++ b/.build.yml
@@ -18,4 +18,7 @@ tasks:
- build: |
cd swaylock
ninja -C build
-
+ - build-no-pam: |
+ cd swaylock
+ meson configure build -Dpam=disabled
+ ninja -C build
diff --git a/meson.build b/meson.build
index 281abfa..7c8ec56 100644
--- a/meson.build
+++ b/meson.build
@@ -39,7 +39,7 @@ cairo = dependency('cairo')
pango = dependency('pango')
pangocairo = dependency('pangocairo')
gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: false)
-libpam = cc.find_library('pam', required: false)
+libpam = cc.find_library('pam', required: get_option('pam') == 'enabled')
crypt = cc.find_library('crypt', required: false)
math = cc.find_library('m')
@@ -114,14 +114,14 @@ conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found())
subdir('include')
dependencies = [
- cairo,
- client_protos,
- gdk_pixbuf,
- math,
- pango,
- pangocairo,
- xkbcommon,
- wayland_client,
+ cairo,
+ client_protos,
+ gdk_pixbuf,
+ math,
+ pango,
+ pangocairo,
+ xkbcommon,
+ wayland_client,
]
sources = [
@@ -138,22 +138,22 @@ sources = [
'unicode.c',
]
-if libpam.found()
- sources += ['pam.c']
- dependencies += [libpam]
+if libpam.found() and get_option('pam') != 'disabled'
+ sources += ['pam.c']
+ dependencies += [libpam]
else
- warning('The swaylock binary must be setuid when compiled without libpam')
- warning('You must do this manually post-install: chmod a+s /path/to/swaylock')
- sources += ['shadow.c']
- if crypt.found()
- dependencies += [crypt]
- endif
+ warning('The swaylock binary must be setuid when compiled without libpam')
+ warning('You must do this manually post-install: chmod a+s /path/to/swaylock')
+ sources += ['shadow.c']
+ if crypt.found()
+ dependencies += [crypt]
+ endif
endif
swaylock_inc = include_directories('include')
executable('swaylock',
- sources,
+ sources,
include_directories: [swaylock_inc],
dependencies: dependencies,
install: true
@@ -199,7 +199,7 @@ endif
datadir = get_option('datadir')
-if (get_option('zsh-completions'))
+if get_option('zsh-completions')
zsh_files = files(
'completions/zsh/_swaylock',
)
@@ -208,7 +208,7 @@ if (get_option('zsh-completions'))
install_data(zsh_files, install_dir: zsh_install_dir)
endif
-if (get_option('bash-completions'))
+if get_option('bash-completions')
bash_files = files(
'completions/bash/swaylock',
)
@@ -217,7 +217,7 @@ if (get_option('bash-completions'))
install_data(bash_files, install_dir: bash_install_dir)
endif
-if (get_option('fish-completions'))
+if get_option('fish-completions')
fish_files = files(
'completions/fish/swaylock.fish',
)
diff --git a/meson_options.txt b/meson_options.txt
index 1d9fd5b..9533fba 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,4 +1,11 @@
option('sway-version', type : 'string', description: 'The version string reported in `sway --version`.')
+option(
+ 'pam',
+ type: 'combo',
+ choices: ['auto', 'enabled', 'disabled'],
+ value: 'auto',
+ description: 'Use PAM instead of shadow.',
+)
option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.')
option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.')
option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.')
diff --git a/pam.c b/pam.c
index 805817a..4ae8276 100644
--- a/pam.c
+++ b/pam.c
@@ -33,30 +33,56 @@ static int function_conversation(int num_msg, const struct pam_message **msg,
return PAM_SUCCESS;
}
+static const char *get_pam_auth_error(int pam_status) {
+ switch (pam_status) {
+ case PAM_AUTH_ERR:
+ return "invalid credentials";
+ case PAM_CRED_INSUFFICIENT:
+ return "swaylock cannot authenticate users; check /etc/pam.d/swaylock "
+ "has been installed properly";
+ case PAM_AUTHINFO_UNAVAIL:
+ return "authentication information unavailable";
+ case PAM_MAXTRIES:
+ return "maximum number of authentication tries exceeded";
+ default:;
+ static char msg[64];
+ snprintf(msg, sizeof(msg), "unknown error (%d)", pam_status);
+ return msg;
+ }
+}
+
bool attempt_password(struct swaylock_password *pw) {
struct passwd *passwd = getpwuid(getuid());
char *username = passwd->pw_name;
+
+ bool success = false;
+
const struct pam_conv local_conversation = {
- function_conversation, pw
+ .conv = function_conversation,
+ .appdata_ptr = pw,
};
pam_handle_t *local_auth_handle = NULL;
- int pam_err;
- if ((pam_err = pam_start("swaylock", username,
- &local_conversation, &local_auth_handle)) != PAM_SUCCESS) {
- swaylock_log(LOG_ERROR, "PAM returned error %d", pam_err);
+ if (pam_start("swaylock", username, &local_conversation, &local_auth_handle)
+ != PAM_SUCCESS) {
+ swaylock_log(LOG_ERROR, "pam_start failed");
+ goto out;
}
- if ((pam_err = pam_authenticate(local_auth_handle, 0)) != PAM_SUCCESS) {
- swaylock_log(LOG_ERROR, "pam_authenticate failed");
- goto fail;
+
+ int pam_status = pam_authenticate(local_auth_handle, 0);
+ if (pam_status == PAM_SUCCESS) {
+ swaylock_log(LOG_DEBUG, "pam_authenticate succeeded");
+ success = true;
+ } else {
+ swaylock_log(LOG_ERROR, "pam_authenticate failed: %s",
+ get_pam_auth_error(pam_status));
}
- // TODO: only call pam_end once we succeed at authing. refresh tokens beforehand
- if ((pam_err = pam_end(local_auth_handle, pam_err)) != PAM_SUCCESS) {
+
+ if (pam_end(local_auth_handle, pam_status) != PAM_SUCCESS) {
swaylock_log(LOG_ERROR, "pam_end failed");
- goto fail;
+ success = false;
}
+
+out:
clear_password_buffer(pw);
- return true;
-fail:
- clear_password_buffer(pw);
- return false;
+ return success;
}