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

#31: Support multiple devices per user #177

Merged
merged 57 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
13cb6fc
Update changelog
mcdope Aug 23, 2022
119ff4f
Update AUTHORS
mcdope Aug 23, 2022
daeaadc
Update version numbers
mcdope Aug 23, 2022
92e5de2
Update fedora changelog
mcdope Aug 23, 2022
5a84cc5
Update debian changelog
mcdope Aug 23, 2022
a9d08e5
Fix debian changelog
mcdope Aug 23, 2022
50e44a4
Update debian/source/option
mcdope Aug 23, 2022
940f19a
Use same name in fedora changes then for debian / realname everywhere
mcdope Aug 23, 2022
5515521
Update README.md
mcdope Aug 23, 2022
50cdf61
[Docs] Update non-manpage "doc/" files
Aug 24, 2022
7c5e976
[Packaging] [Debian] Fix config script picking up device serials as n…
mcdope Aug 24, 2022
61b90c5
#165: Update ChangeLog and debian/changelog
mcdope Aug 24, 2022
b69db4a
Merge remote-tracking branch 'origin/master' into prepare-083
mcdope Aug 25, 2022
dc41184
Update changelogs
mcdope Aug 25, 2022
20be5fd
[local.c] Fix tiny memleak
mcdope Aug 26, 2022
5a6d8b8
#31: Prepare conf.c/xpath.c for multiple devices per user
mcdope Aug 27, 2022
6ea5419
#31: [device.c] pusb_device_connected() -> loop device_list and assig…
mcdope Aug 27, 2022
a4a4b0d
#31: Prepare dist/doc config for multi-device
mcdope Aug 27, 2022
d4d9709
#31: [pamusb-agent] add todo
mcdope Aug 27, 2022
f0a6fd0
#31 CI, plz?
mcdope Aug 27, 2022
5538ec6
#31: Fix errors
mcdope Aug 28, 2022
d2be4dd
#31: Don't iterate empty devices, fix 'nodevice' output
mcdope Aug 29, 2022
f1f5c9c
#31: Revert ae51375dda71ce44882b15b14c171b6f538d21a0, add support for…
mcdope Aug 29, 2022
7571f19
#31: Adjust tests for multi-device support
mcdope Aug 29, 2022
d71b610
#31: We cant load the mod 2x, so adjust tests accordingly
mcdope Aug 29, 2022
3ab2250
#31: Rename add-device back, since it only adds a single device
mcdope Aug 29, 2022
78ef7d4
#31: Fix detects-device testcase
mcdope Aug 29, 2022
b1947cd
#31: More test fixes
mcdope Aug 29, 2022
50d86f4
#31: Moremore test fixes
mcdope Aug 29, 2022
9615cb0
#31: Moar test fixes
mcdope Aug 29, 2022
7d3da0b
#31: Moarmoar test fixes
mcdope Aug 29, 2022
68504d7
#31: Get some debug output
mcdope Aug 29, 2022
869a101
#31: Manually mount alternate stick
mcdope Aug 29, 2022
ba01aa5
Merge branch 'master' into issue-31-experimental-multidevice-support
mcdope Sep 1, 2022
87410ca
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Sep 3, 2022
eac01e1
Merge branch 'master' into issue-31-experimental-multidevice-support
mcdope Mar 12, 2023
744024e
Merge branch 'master' into issue-31-experimental-multidevice-support
mcdope Mar 18, 2023
173234c
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Mar 20, 2023
054ce36
Merge remote-tracking branch 'origin/issue-31-experimental-multidevic…
mcdope Mar 20, 2023
0f32e33
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Jan 3, 2024
e198f0e
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Jan 7, 2024
6a30c3d
ä31: Misc
mcdope Jan 7, 2024
35fbd34
#31: Misc
mcdope Jan 8, 2024
c4aa26d
#31: Update todos
mcdope Mar 31, 2024
538d50d
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Jul 12, 2024
1aca921
#31: Fix merge derp, make it actually work again
mcdope Jul 14, 2024
914896b
#31: Start to adjust agent
mcdope Jul 14, 2024
4e2d5b0
Merge remote-tracking branch 'origin/master' into issue-31-experiment…
mcdope Jul 14, 2024
d2af4a4
#31: Continue work on agent [WIP/Broken]
mcdope Jul 14, 2024
256c630
#31: [agent] Start a thread for each device
mcdope Jul 14, 2024
0b2d52b
#31: [agent] Only react to event if no other device is connected for …
mcdope Jul 16, 2024
97037bd
#31: [Tests] Give more time for unlock event
mcdope Jul 16, 2024
5dc323c
#31: Run deepseek-coder-v2 over changed C files
mcdope Jul 16, 2024
f016b10
#31: Remove debug output
mcdope Jul 18, 2024
c68d079
#31: Remove even more debug output
mcdope Jul 18, 2024
cd95c82
#31: Remove even more debug output
mcdope Jul 18, 2024
1e69695
#31: Remove even more debug output
mcdope Jul 18, 2024
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
8 changes: 8 additions & 0 deletions doc/pam_usb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ See https://github.com/mcdope/pam_usb/wiki/Configuration
<volume_uuid>6F6B-42FC</volume_uuid>
<option name="probe_timeout">10</option>
</device>
<device id="MySecondDevice">
<vendor>Commodore</vendor>
<model>REU</model>
<serial>CMDKXXXXXXXXXXXXXXXX</serial>
<volume_uuid>6F6B-00FF</volume_uuid>
<option name="probe_timeout">10</option>
</device>
-->
</devices>

Expand All @@ -38,6 +45,7 @@ See https://github.com/mcdope/pam_usb/wiki/Configuration
removal:
<user id="scox">
<device>MyDevice</device>
<device>MySecondDevice</device>
<option name="quiet">true</option>
<agent event="lock">
<cmd>gnome-screensaver-command -\-lock</cmd>
Expand Down
63 changes: 51 additions & 12 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,40 +88,43 @@ static int pusb_conf_device_get_property(
xmlDoc *doc,
const char *property,
char *store,
size_t size
size_t size,
char *deviceId
)
{
char *xpath = NULL;
size_t xpath_len;
int retval;

xpath_len = strlen(CONF_DEVICE_XPATH) + strlen(opts->device.name) + strlen(property) + 1;
xpath_len = strlen(CONF_DEVICE_XPATH) + strlen(deviceId) + strlen(property) + 1;
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check notice

Code scanning / devskim

If a string is missing a null terminator, strlen will read past the end of the buffer Note

Problematic C function detected (strlen)

Check notice

Code scanning / devskim

If a string is missing a null terminator, strlen will read past the end of the buffer Note

Problematic C function detected (strlen)

Check notice

Code scanning / devskim

If a string is missing a null terminator, strlen will read past the end of the buffer Note

Problematic C function detected (strlen)
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
xpath = xmalloc(xpath_len);
if (xpath == NULL) {
log_error("Memory allocation failed\n");
return 0;
}
memset(xpath, 0x00, xpath_len);
snprintf(xpath, xpath_len, CONF_DEVICE_XPATH, opts->device.name, property);
snprintf(xpath, xpath_len, CONF_DEVICE_XPATH, deviceId, property);
retval = pusb_xpath_get_string(doc, xpath, store, size);
xfree(xpath);
return retval;
}

static int pusb_conf_parse_device(
t_pusb_options *opts,
xmlDoc *doc
xmlDoc *doc,
int deviceIndex,
char *deviceId
)
{
pusb_conf_device_get_property(opts, doc, "vendor", opts->device.vendor, sizeof(opts->device.vendor));
pusb_conf_device_get_property(opts, doc, "model", opts->device.model, sizeof(opts->device.model));
pusb_conf_device_get_property(opts, doc, "vendor", opts->device_list[deviceIndex].vendor, sizeof(opts->device_list[deviceIndex].vendor), deviceId);
pusb_conf_device_get_property(opts, doc, "model", opts->device_list[deviceIndex].model, sizeof(opts->device_list[deviceIndex].model), deviceId);

if (!pusb_conf_device_get_property(opts, doc, "serial", opts->device.serial, sizeof(opts->device.serial)))
if (!pusb_conf_device_get_property(opts, doc, "serial", opts->device_list[deviceIndex].serial, sizeof(opts->device_list[deviceIndex].serial), deviceId))
{
return 0;
}

pusb_conf_device_get_property(opts, doc, "volume_uuid", opts->device.volume_uuid, sizeof(opts->device.volume_uuid));
pusb_conf_device_get_property(opts, doc, "volume_uuid", opts->device_list[deviceIndex].volume_uuid, sizeof(opts->device_list[deviceIndex].volume_uuid), deviceId);
return 1;
}

Expand Down Expand Up @@ -177,26 +180,62 @@ int pusb_conf_parse(
return 0;
}
snprintf(device_xpath, sizeof(device_xpath), CONF_USER_XPATH, user, "device");
retval = pusb_xpath_get_string(

char *device_list[10] = {
xmalloc(128), xmalloc(128), xmalloc(128), xmalloc(128), xmalloc(128),
xmalloc(128), xmalloc(128), xmalloc(128), xmalloc(128), xmalloc(128)
};
for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
memset(device_list[currentDevice], 0x0, 128);
}
retval = pusb_xpath_get_string_list(
doc,
device_xpath,
opts->device.name,
device_list,
sizeof(opts->device.name)
);
if (!retval || !pusb_conf_parse_device(opts, doc))
if (!retval)
{
log_error("No authentication device configured for user \"%s\".\n", user);
log_error("No authentication device(s) configured for user \"%s\".\n", user);
xmlFreeDoc(doc);
xmlCleanupParser();

for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
xfree(device_list[currentDevice]);
}
return 0;
}

for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
if (device_list[currentDevice] == NULL || strlen(device_list[currentDevice]) == 0)
Dismissed Show dismissed Hide dismissed
{
continue;
}

strcpy(opts->device_list[currentDevice].name, device_list[currentDevice]);
Dismissed Show dismissed Hide dismissed
pusb_conf_parse_device(opts, doc, currentDevice, device_list[currentDevice]);
}

if (!pusb_conf_parse_options(opts, doc, user, service))
{
xmlFreeDoc(doc);
xmlCleanupParser();

for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
xfree(device_list[currentDevice]);
}
return (0);
}
xmlFreeDoc(doc);
xmlCleanupParser();

for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
xfree(device_list[currentDevice]);
}
return (1);
}
1 change: 1 addition & 0 deletions src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct pusb_options
char system_pad_directory[PATH_MAX];
char device_pad_directory[PATH_MAX];
t_pusb_device device;
t_pusb_device device_list[10];
} t_pusb_options;

struct s_opt_list
Expand Down
56 changes: 35 additions & 21 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,47 @@ static int pusb_device_connected(t_pusb_options *opts, UDisksClient *udisks)
GDBusObjectManager *manager = udisks_client_get_object_manager(udisks);
GList *objects = g_dbus_object_manager_get_objects(manager);
int retval = 0;
int i;
int i;
UDisksObject *object = NULL;
UDisksDrive *drive = NULL;

log_debug("Searching for \"%s\" in the hardware database...\n", opts->device.name);

for (i = 0; i < g_list_length(objects); ++i)
for (int currentDevice = 0; currentDevice < 10; currentDevice++)
{
object = UDISKS_OBJECT(g_list_nth(objects, i)->data);
if (udisks_object_peek_drive(object))
if (strcmp(opts->device_list[currentDevice].name, "") == 0)
{
drive = udisks_object_get_drive(object);
retval = strcmp(udisks_drive_get_serial(drive), opts->device.serial) == 0;
continue;
}

if (strcmp(opts->device.vendor, "Generic") != 0)
{
retval = retval && strcmp(udisks_drive_get_vendor(drive), opts->device.vendor) == 0;
}
log_error("Searching for \"%s\" in the hardware database...\n", opts->device_list[currentDevice].name);

if (strcmp(opts->device.model, "Generic") != 0)
for (i = 0; i < g_list_length(objects); ++i)
{
object = UDISKS_OBJECT(g_list_nth(objects, i)->data);
if (udisks_object_peek_drive(object))
{
retval = retval && strcmp(udisks_drive_get_model(drive), opts->device.model) == 0;
}

g_object_unref(drive);
if (retval) {
break;
drive = udisks_object_get_drive(object);
retval = strcmp(udisks_drive_get_serial(drive), opts->device_list[currentDevice].serial) == 0;

if (strcmp(opts->device_list[currentDevice].vendor, "Generic") != 0)
{
retval = retval && strcmp(udisks_drive_get_vendor(drive), opts->device_list[currentDevice].vendor) == 0;
}

if (strcmp(opts->device_list[currentDevice].model, "Generic") != 0)
{
retval = retval && strcmp(udisks_drive_get_model(drive), opts->device_list[currentDevice].model) == 0;
}

g_object_unref(drive);
if (retval) {
strncpy(opts->device.name, opts->device_list[currentDevice].name, sizeof(opts->device.name) - 1);
Dismissed Show dismissed Hide dismissed
strncpy(opts->device.vendor, opts->device_list[currentDevice].vendor, sizeof(opts->device.vendor) - 1);
Dismissed Show dismissed Hide dismissed
strncpy(opts->device.model, opts->device_list[currentDevice].model, sizeof(opts->device.model) - 1);
Dismissed Show dismissed Hide dismissed
strncpy(opts->device.serial, opts->device_list[currentDevice].serial, sizeof(opts->device.serial) - 1);
Dismissed Show dismissed Hide dismissed
strncpy(opts->device.volume_uuid, opts->device_list[currentDevice].volume_uuid, sizeof(opts->device.volume_uuid) - 1);
Dismissed Show dismissed Hide dismissed
currentDevice = 10;
break;
}
}
}
}
Expand All @@ -68,7 +82,7 @@ static int pusb_device_connected(t_pusb_options *opts, UDisksClient *udisks)
}
else
{
log_error("Authentication device \"%s\" is not connected.\n", opts->device.name);
log_error("None of the configured authentication devices is connected.\n");
}

for (i = 0; i < g_list_length(objects); ++i)
Expand All @@ -90,7 +104,7 @@ int pusb_device_check(t_pusb_options *opts, const char *user)
if (udisks_client_error != NULL)
{
log_error("Unable to check for device, could not get UDisksClient! Error was: %s\n", udisks_client_error->message);
g_error_free (udisks_client_error);
g_error_free(udisks_client_error);
return (0);
}

Expand Down
Loading
Loading