Skip to content

port to udisks2 #31

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ LIBDIR ?= lib
# 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 Down
77 changes: 49 additions & 28 deletions src/device.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t; -*- */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luka-n, could you remove those? They are editor specific and I don't think they belong in the source file.


/*
* Copyright (c) 2016 Luka Novsak <[email protected]>
* Copyright (c) 2003-2007 Andrea Luzzardi <[email protected]>
*
* This file is part of the pam_usb project. pam_usb is free software;
Expand All @@ -18,63 +21,81 @@
#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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No extra space between function name and (

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);
}
1 change: 1 addition & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifndef PUSB_DEVICE_H_
# define PUSB_DEVICE_H_
# include "conf.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required here? Shouldn't it be in device.c?


int pusb_device_check(t_pusb_options *opts, const char *user);

Expand Down
Loading