From 5f70d320a0d3d1fef0bc6b7b77ef2a7c2923b990 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 28 Mar 2017 20:31:42 +0200 Subject: Implement OpenBSD authentication using bsd_auth(3). OpenBSD does not have nor use pam(8) for password authentication but instead uses bsd_auth(3): add a bsd_auth authentication scheme to make locking possible. This has been a part of gnome-screensaver already but was probably removed at one point. This is mostly identical to that code, with some minor modifications. --- src/gs-auth-bsdauth.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/gs-auth-bsdauth.c (limited to 'src/gs-auth-bsdauth.c') diff --git a/src/gs-auth-bsdauth.c b/src/gs-auth-bsdauth.c new file mode 100644 index 0000000..3463974 --- /dev/null +++ b/src/gs-auth-bsdauth.c @@ -0,0 +1,103 @@ +/* + * gs-auth-bsdauth.c --- verifying typed passwords with bsd_auth(3) + * + * Copyright (c) 1993-1998 Jamie Zawinski + * Copyright (C) 2006 William Jon McCann + * Copyright (c) 2009 Antoine Jacoutot + * Copyright (c) 2017 Robert Nagy + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "config.h" + +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#include + +#include +#include + +#include "gs-auth.h" +#include "subprocs.h" + +static gboolean verbose_enabled = FALSE; + +GQuark +gs_auth_error_quark (void) +{ + static GQuark quark = 0; + if (! quark) { + quark = g_quark_from_static_string ("gs_auth_error"); + } + + return quark; +} + +void +gs_auth_set_verbose (gboolean enabled) +{ + verbose_enabled = enabled; +} + +gboolean +gs_auth_get_verbose (void) +{ + return verbose_enabled; +} + +gboolean +gs_auth_verify_user (const char *username, + const char *display, + GSAuthMessageFunc func, + gpointer data, + GError **error) +{ + int res; + char *password; + + /* ask for the password for user */ + if (func != NULL) { + func (GS_AUTH_MESSAGE_PROMPT_ECHO_OFF, + "Password: ", + &password, + data); + } + + if (password == NULL) { + return FALSE; + } + + /* authenticate */ + res = auth_userokay((char *)username, NULL, "auth-mate-screensaver", password); + + return res; +} + +gboolean +gs_auth_init (void) +{ + return TRUE; +} + +gboolean +gs_auth_priv_init (void) +{ + return TRUE; +} -- cgit v1.2.1