2 This file is part of pam_dbus.
4 pam_dbus is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 pam_dbus is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with pam_dbus; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include <security/pam_modules.h>
25 #include <dbus/dbus.h>
26 #include <dbus/dbus-glib.h>
28 PAM_EXTERN int pam_sm_authenticate(pam_handle_t *ph, int flags, int argc, const char **argv) {
29 DBusGConnection *connection;
38 connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
39 if (connection == NULL) {
41 return PAM_AUTHINFO_UNAVAIL;
44 /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
46 proxy = dbus_g_proxy_new_for_name (connection,
47 "de.nomeata.pam_dbus",
48 "/de/nomeata/pam_dbus",
49 "de.nomeata.pam_dbus");
51 char *service, *user, *rhost, *ruser;
52 pam_get_item(ph, PAM_SERVICE, (const void **)&service);
53 pam_get_item(ph, PAM_USER, (const void **)&user);
54 pam_get_item(ph, PAM_RHOST, (const void **)&rhost);
55 pam_get_item(ph, PAM_RUSER, (const void **)&ruser);
57 /* Call ListNames method, wait for reply */
59 if (!dbus_g_proxy_call_with_timeout (proxy, "MayLogin", 5*60*1000, &error,
60 G_TYPE_STRING, service,
65 G_TYPE_BOOLEAN, &login_ok,
68 /* Just do demonstrate remote exceptions versus regular GError */
70 g_object_unref (proxy);
71 return PAM_AUTHINFO_UNAVAIL;
74 /* Print the results */
77 g_object_unref (proxy);
79 return login_ok ? PAM_SUCCESS : PAM_AUTH_ERR;