-
Notifications
You must be signed in to change notification settings - Fork 85
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
luka-n
wants to merge
1
commit into
aluzzardi:master
Choose a base branch
from
luka-n:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
port to udisks2 #31
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t; -*- */ | ||
|
||
/* | ||
* 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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
#ifndef PUSB_DEVICE_H_ | ||
# define PUSB_DEVICE_H_ | ||
# include "conf.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required here? Shouldn't it be in |
||
|
||
int pusb_device_check(t_pusb_options *opts, const char *user); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.