Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to udisks2 from fork IGP/pam_usb + minor fixes #34

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ce05427
Makefile paths for 32/64 bits systems, configuration and documentatio…
frantsao Mar 16, 2016
fb1d08a
Updated Free Software Foundation address in license notes
frantsao Mar 16, 2016
1ccae66
port to udisks2
luka-n Feb 7, 2016
00f26b9
Merge remote-tracking branch 'upstream/master'
frantsao May 14, 2016
d50d2bd
Merge pull request #2 from frantsao/master
iamsivil Oct 6, 2016
9c55f04
Update Makefile - disable DEBUG
iamsivil Oct 6, 2016
fe2c595
Delete hal.c in prep for udisks2 merge
iamsivil Oct 6, 2016
5c67b75
Delete hal.h in prep for udisks2 merge
iamsivil Oct 6, 2016
19db31a
Merge pull request #1 from luka-n/master
iamsivil Oct 6, 2016
0ac18e3
Cleanup device.c
iamsivil Oct 6, 2016
3ec7098
Cleanup pad.c
iamsivil Oct 6, 2016
d946be5
Cleanup volume.c
iamsivil Oct 6, 2016
3f3e503
Update volume.c - more iters with less sleeping
iamsivil Oct 6, 2016
1053d92
Cleaning pad.c
iamsivil Oct 6, 2016
a2fe52a
Update conf.h
iamsivil Oct 6, 2016
088252e
Update Makefile
iamsivil Oct 7, 2016
d37d222
Rename pamusb.conf to pam_usb.conf
iamsivil Oct 7, 2016
52b610b
Update pamusb-agent
iamsivil Oct 7, 2016
7d1bc15
Update pamusb-conf
iamsivil Oct 7, 2016
15e3054
Update pam_usb.conf
iamsivil Oct 7, 2016
15f358b
Update CONFIGURATION.md
iamsivil Oct 7, 2016
d23bce6
Update conf.h
iamsivil Oct 7, 2016
0fe1ddb
Update volume.h
iamsivil Oct 7, 2016
3999288
Update pad.h
iamsivil Oct 7, 2016
c2b7294
Update device.h
iamsivil Oct 7, 2016
0c7b1b2
Rename doc/pam_usb.conf to doc/examples/pam_usb.conf
iamsivil Oct 7, 2016
06b7432
Create pam_usb.conf
iamsivil Oct 7, 2016
5433482
Update Makefile
iamsivil Oct 7, 2016
fea00c8
Removed extra spaces between function name and '(' in 4 places
drmfinlay Feb 26, 2017
afae3eb
Created AUTHORS file
drmfinlay Feb 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Andrea Luzzardi <[email protected]>
Luka Novsak <[email protected]>
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
DEBUG := no

PREFIX ?= /usr
LIBDIR ?= lib
ARCH := $(shell getconf LONG_BIT)
ifeq ($(ARCH),64)
LIBDIR := lib64
else
LIBDIR := lib
endif

# compiler/linker options
CC := gcc
CFLAGS := $(CFLAGS) -Wall -fPIC `pkg-config --cflags libxml-2.0` \
`pkg-config --cflags dbus-1`
`pkg-config --cflags udisks2`
LIBS := `pkg-config --libs libxml-2.0` \
`pkg-config --libs dbus-1`
`pkg-config --libs udisks2`

# common source files
SRCS := src/conf.c \
src/mem.c \
src/log.c \
src/xpath.c \
src/hal.c \
src/pad.c \
src/volume.c \
src/local.c \
Expand All @@ -37,17 +41,17 @@ PAMUSB_CHECK := pamusb-check

# Tools
PAMUSB_CONF := pamusb-conf
PAMUSB_AGENT := pamusb-agent
PAMUSB_AGENT := pamusb-agent
TOOLS_DEST := $(DESTDIR)$(PREFIX)/bin
TOOLS_SRC := tools

# Conf
CONFS := doc/pamusb.conf
CONFS_DEST := $(DESTDIR)/etc
CONFS := doc/pam_usb.conf
CONFS_DEST := $(DESTDIR)/etc/security

# Doc
DOCS := doc/CONFIGURATION.md
DOCS_DEST := $(DESTDIR)$(PREFIX)/share/doc/pamusb
DOCS_DEST := $(DESTDIR)$(PREFIX)/share/doc/pam_usb

# Man
MANS := doc/pamusb-conf.1.gz doc/pamusb-agent.1.gz doc/pamusb-check.1.gz
Expand Down Expand Up @@ -88,4 +92,4 @@ deinstall :
$(RM) -f $(PAM_USB_DEST)/$(PAM_USB)
$(RM) -f $(TOOLS_DEST)/$(PAMUSB_CHECK) $(TOOLS_DEST)/$(PAMUSB_CONF) $(TOOLS_DEST)/$(PAMUSB_AGENT)
$(RM) -rf $(DOCS_DEST)
$(RM) -f $(MANS_DEST)/pusb_*
$(RM) -f $(MANS_DEST)/pamusb-*\.1\.gz
2 changes: 1 addition & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Example:
Location of the configuration file
----------------------------------

By default, pam_usb.so and its tools will look for the configuration file at `/etc/pamusb.conf`.
By default, pam_usb.so and its tools will look for the configuration file at `/etc/security/pam_usb.conf`.

If you want to use a different location, you will have to use the `-c` flag.

Expand Down
2 changes: 1 addition & 1 deletion doc/pamusb.conf → doc/examples/pam_usb.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
pamusb.conf: Configuration file for pam_usb.
pam_usb.conf: Configuration file for pam_usb.

See http://www.pamusb.org/doc/configuring
-->
Expand Down
17 changes: 17 additions & 0 deletions doc/pam_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configuration>
<defaults>

</defaults>

<devices>

</devices>

<users>

</users>

<services>

</services>
</configuration>
4 changes: 2 additions & 2 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <sys/utsname.h>
Expand Down
6 changes: 3 additions & 3 deletions src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef PUSB_CONF_H_
# define PUSB_CONF_H_
# define PUSB_CONF_FILE "/etc/pamusb.conf"
# define PUSB_CONF_FILE "/etc/security/pam_usb.conf"
# define CONF_DEVICE_XPATH "//configuration/devices/device[@id='%s']/%s"
# define CONF_USER_XPATH "//configuration/users/user[@id='%s']/%s"
# define CONF_SERVICE_XPATH "//configuration/services/service[@id='%s']/%s"
Expand Down
78 changes: 48 additions & 30 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,88 @@
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <dbus/dbus.h>
#include "mem.h"

#include <udisks/udisks.h>

#include "conf.h"
#include "hal.h"
#include "log.h"
#include "pad.h"
#include "device.h"

static int pusb_device_connected(t_pusb_options *opts, DBusConnection *dbus)
static int pusb_device_connected(t_pusb_options *opts, UDisksClient *udisks)
{
char *udi = NULL;
GDBusObjectManager *manager = udisks_client_get_object_manager(udisks);
GList *objects = g_dbus_object_manager_get_objects(manager);
int retval = 0;
int i;
UDisksObject *object = NULL;
UDisksDrive *drive = NULL;

manager = udisks_client_get_object_manager(udisks);
objects = g_dbus_object_manager_get_objects(manager);

log_debug("Searching for \"%s\" in the hardware database...\n",
opts->device.name);
udi = pusb_hal_find_item(dbus,
"DriveSerial", opts->device.serial,
"DriveVendor", opts->device.vendor,
"DriveModel", opts->device.model,
NULL);
if (!udi)

for (i = 0; i < g_list_length(objects); ++i)
{
log_error("Device \"%s\" is not connected.\n",
opts->device.name);
return (0);
object = UDISKS_OBJECT(g_list_nth(objects, i)->data);
if (udisks_object_peek_drive(object))
{
drive = udisks_object_get_drive(object);
retval = strcmp(udisks_drive_get_serial(drive), opts->device.serial) == 0 &&
strcmp(udisks_drive_get_vendor(drive), opts->device.vendor) == 0 &&
strcmp(udisks_drive_get_model(drive), opts->device.model) == 0;
g_object_unref(drive);
if (retval)
break;
}
}
xfree(udi);
log_info("Device \"%s\" is connected (good).\n", opts->device.name);
return (1);

if (retval)
log_info("Device \"%s\" is connected (good).\n",
opts->device.name);
else
log_error("Device \"%s\" is not connected (bad).\n",
opts->device.name);

g_list_foreach(objects, (GFunc) g_object_unref, NULL);
g_list_free(objects);

return (retval);
}

int pusb_device_check(t_pusb_options *opts,
const char *user)
int pusb_device_check(t_pusb_options *opts, const char *user)
{
DBusConnection *dbus = NULL;
int retval = 0;
UDisksClient *udisks = NULL;
int retval = 0;

log_debug("Connecting to HAL...\n");
if (!(dbus = pusb_hal_dbus_connect()))
return (0);
udisks = udisks_client_new_sync(NULL, NULL);

if (!pusb_device_connected(opts, dbus))
if (!pusb_device_connected(opts, udisks))
{
pusb_hal_dbus_disconnect(dbus);
g_object_unref(udisks);
return (0);
}

if (opts->one_time_pad)
{
log_info("Performing one time pad verification...\n");
retval = pusb_pad_check(opts, dbus, user);
retval = pusb_pad_check(opts, udisks, user);
}
else
{
log_debug("One time pad is disabled, no more verifications to do.\n");
retval = 1;
}

pusb_hal_dbus_disconnect(dbus);
g_object_unref(udisks);
return (retval);
}
4 changes: 2 additions & 2 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef PUSB_DEVICE_H_
Expand Down
Loading