diff --git a/pam_usb/src/Makefile b/pam_usb/src/Makefile
index 9d6545e..0ce71c8 100644
--- a/pam_usb/src/Makefile
+++ b/pam_usb/src/Makefile
@@ -4,7 +4,7 @@ SRC = test.c \
xpath.c \
hal.c \
otp.c \
- device.c drive.c
+ device.c
OBJ = $(SRC:.c=.o)
NAME = test
CC = gcc
diff --git a/pam_usb/src/conf.c b/pam_usb/src/conf.c
index c8e28fa..32ce147 100644
--- a/pam_usb/src/conf.c
+++ b/pam_usb/src/conf.c
@@ -28,6 +28,10 @@ static void pusb_conf_options_get_from(t_pusb_options *opts,
{
pusb_xpath_get_string_from(doc, from, "option[@name='hostname']",
opts->hostname, sizeof(opts->hostname));
+ pusb_xpath_get_string_from(doc, from, "option[@name='system_otp_directory']",
+ opts->system_otp_directory, sizeof(opts->system_otp_directory));
+ pusb_xpath_get_string_from(doc, from, "option[@name='device_otp_directory']",
+ opts->device_otp_directory, sizeof(opts->device_otp_directory));
pusb_xpath_get_bool_from(doc, from, "option[@name='debug']",
&(opts->debug));
pusb_xpath_get_bool_from(doc, from, "option[@name='enable']",
@@ -36,6 +40,8 @@ static void pusb_conf_options_get_from(t_pusb_options *opts,
&(opts->try_otp));
pusb_xpath_get_bool_from(doc, from, "option[@name='enforce_otp']",
&(opts->enforce_otp));
+ pusb_xpath_get_int_from(doc, from, "option[@name='probe_timeout']",
+ &(opts->probe_timeout));
}
static int pusb_conf_parse_options(t_pusb_options *opts,
@@ -118,6 +124,9 @@ int pusb_conf_init(t_pusb_options *opts)
log_error("gethostname: %s\n", strerror(errno));
return (0);
}
+ strcpy(opts->system_otp_directory, "./");
+ strcpy(opts->device_otp_directory, ".auth");
+ opts->probe_timeout = 10;
opts->enable = 1;
opts->try_otp = 1;
opts->enforce_otp = 0;
diff --git a/pam_usb/src/conf.h b/pam_usb/src/conf.h
index 3bfc254..0345a18 100644
--- a/pam_usb/src/conf.h
+++ b/pam_usb/src/conf.h
@@ -32,11 +32,14 @@ typedef struct pusb_device
typedef struct pusb_options
{
+ int probe_timeout;
int enable;
int try_otp;
int enforce_otp;
int debug;
char hostname[32];
+ char system_otp_directory[128];
+ char device_otp_directory[32];
t_pusb_device device;
} t_pusb_options;
diff --git a/pam_usb/src/conf.xml b/pam_usb/src/conf.xml
index 4fc9e92..836dea7 100644
--- a/pam_usb/src/conf.xml
+++ b/pam_usb/src/conf.xml
@@ -4,23 +4,35 @@
+
+
+ SanDisk
+ Cruzer Titanium
+ SanDisk_Cruzer_Titanium_SNDKB882652FC4A03701
+
+
+
+
+
SanDisk Corp.
Cruzer Titanium
SNDKB882652FC4A03701
+
foobar
- foobar
+ foobar2
diff --git a/pam_usb/src/device.c b/pam_usb/src/device.c
index 02f2101..b0702b6 100644
--- a/pam_usb/src/device.c
+++ b/pam_usb/src/device.c
@@ -15,6 +15,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include
+#include
#include
#include "conf.h"
#include "hal.h"
@@ -34,12 +36,8 @@ LibHalDrive *pusb_device_get_storage(t_pusb_options *opts, LibHalContext *ctx,
"info.parent", udi,
"info.bus", "usb",
NULL)))
- {
- printf("loop\n");
- usleep(250000);
- }
- printf("phydev: %s\n", phy_udi);
- maxloop = (10000000 / 250000);
+ usleep(250000);
+ maxloop = ((opts->probe_timeout * 1000000) / 250000);
while (maxloop > 0 &&
(!(storage_udi = pusb_hal_find_item(ctx,
"storage.physical_device", phy_udi,
@@ -48,17 +46,13 @@ LibHalDrive *pusb_device_get_storage(t_pusb_options *opts, LibHalContext *ctx,
{
if (storage_udi)
libhal_free_string(storage_udi);
- printf("loop\n");
- printf("maxloop: %d\n", maxloop);
--maxloop;
usleep(250000);
}
- printf("blockdev: %s\n", storage_udi);
libhal_free_string(phy_udi);
if (storage_udi)
{
drive = libhal_drive_from_udi(ctx, storage_udi);
- printf("%s\n", storage_udi);
libhal_free_string(storage_udi);
}
return (drive);
diff --git a/pam_usb/src/otp.c b/pam_usb/src/otp.c
index cbed26e..14d9b5c 100644
--- a/pam_usb/src/otp.c
+++ b/pam_usb/src/otp.c
@@ -66,7 +66,7 @@ static LibHalVolume *pusb_otp_find_volume(t_pusb_options *opts, LibHalContext *c
}
static FILE *pusb_otp_open_device(t_pusb_options *opts, LibHalVolume *volume,
- const char *mode)
+ const char *mode)
{
FILE *f;
char *path;
@@ -76,7 +76,7 @@ static FILE *pusb_otp_open_device(t_pusb_options *opts, LibHalVolume *volume,
mnt_point = (char *)libhal_volume_get_mount_point(volume);
if (!mnt_point)
return (NULL);
- path_size = strlen(mnt_point) + 1 + strlen(".auth") + 1 + \
+ path_size = strlen(mnt_point) + 1 + strlen(opts->device_otp_directory) + 1 + \
strlen(opts->hostname) + strlen(".otp") + 1;
if (!(path = malloc(path_size)))
{
@@ -84,8 +84,8 @@ static FILE *pusb_otp_open_device(t_pusb_options *opts, LibHalVolume *volume,
return (NULL);
}
memset(path, 0x00, path_size);
- snprintf(path, path_size, "%s/.auth/%s.otp", mnt_point,
- opts->hostname);
+ snprintf(path, path_size, "%s/%s/%s.otp", mnt_point,
+ opts->device_otp_directory, opts->hostname);
f = fopen(path, mode);
free(path);
if (!f)
@@ -102,14 +102,16 @@ static FILE *pusb_otp_open_system(t_pusb_options *opts, const char *mode)
char *path;
size_t path_size;
- path_size = strlen(".") + 1 + strlen(opts->device.serial) + strlen(".otp") + 1;
+ path_size = strlen(opts->system_otp_directory) + 1 +
+ strlen(opts->device.serial) + strlen(".otp") + 1;
if (!(path = malloc(path_size)))
{
log_error("malloc error\n");
return (NULL);
}
memset(path, 0x00, path_size);
- snprintf(path, path_size, "%s/%s.otp", ".", opts->device.serial);
+ snprintf(path, path_size, "%s/%s.otp", opts->system_otp_directory,
+ opts->device.serial);
f = fopen(path, mode);
free(path);
if (!f)
@@ -181,10 +183,10 @@ int pusb_otp_check(t_pusb_options *opts, LibHalContext *ctx,
int maxtries;
int i;
- maxtries = (10000000 / 250000);
+ maxtries = ((opts->probe_timeout * 1000000) / 250000);
for (i = 0; i < maxtries; ++i)
{
- printf("Waiting for volumes...\n");
+ log_debug("Waiting volumes...\n");
volume = pusb_otp_find_volume(opts, ctx, drive);
if (volume)
break;
diff --git a/pam_usb/src/test.c b/pam_usb/src/test.c
index c59bedd..426fe13 100644
--- a/pam_usb/src/test.c
+++ b/pam_usb/src/test.c
@@ -22,11 +22,14 @@
static void pusb_dump_conf(t_pusb_options *opts)
{
printf("\nConfiguration dump:\n");
- printf("enable:\t\t%d\n", opts->enable);
- printf("try_otp:\t%d\n", opts->try_otp);
- printf("enforce_otp:\t%d\n", opts->enforce_otp);
- printf("debug:\t\t%d\n", opts->debug);
- printf("hostname:\t%s\n", opts->hostname);
+ printf("enable:\t\t\t%d\n", opts->enable);
+ printf("probe_timeout:\t\t%d\n", opts->probe_timeout);
+ printf("try_otp:\t\t%d\n", opts->try_otp);
+ printf("enforce_otp:\t\t%d\n", opts->enforce_otp);
+ printf("debug:\t\t\t%d\n", opts->debug);
+ printf("hostname:\t\t%s\n", opts->hostname);
+ printf("system_otp_directory:\t%s\n", opts->system_otp_directory);
+ printf("device_otp_directory:\t%s\n", opts->device_otp_directory);
}
int main(int argc, char **argv)
diff --git a/pam_usb/src/xpath.c b/pam_usb/src/xpath.c
index d5d5746..ffc95e2 100644
--- a/pam_usb/src/xpath.c
+++ b/pam_usb/src/xpath.c
@@ -150,3 +150,37 @@ int pusb_xpath_get_bool_from(xmlDocPtr doc,
log_debug("%s%s -> %s\n", base, path, *value ? "true" : "false");
return (retval);
}
+
+int pusb_xpath_get_int(xmlDocPtr doc, const char *path, int *value)
+{
+ char ret[64]; /* strlen("false") + 1 */
+
+ if (!pusb_xpath_get_string(doc, path, ret, sizeof(ret)))
+ return (0);
+ *value = atoi(ret);
+ return (1);
+}
+
+int pusb_xpath_get_int_from(xmlDocPtr doc,
+ const char *base,
+ const char *path,
+ int *value)
+{
+ char *xpath = NULL;
+ size_t xpath_size;
+ int retval;
+
+ xpath_size = strlen(base) + strlen(path) + 1;
+ if (!(xpath = malloc(xpath_size)))
+ {
+ log_error("malloc error!\n");
+ return (0);
+ }
+ memset(xpath, 0x00, xpath_size);
+ snprintf(xpath, xpath_size, "%s%s", base, path);
+ retval = pusb_xpath_get_int(doc, xpath, value);
+ free(xpath);
+ if (retval)
+ log_debug("%s%s -> %d\n", base, path, *value);
+ return (retval);
+}
diff --git a/pam_usb/src/xpath.h b/pam_usb/src/xpath.h
index 3c316f2..f7f5761 100644
--- a/pam_usb/src/xpath.h
+++ b/pam_usb/src/xpath.h
@@ -26,4 +26,10 @@ int pusb_xpath_get_string_from(xmlDocPtr doc, const char *base,
const char *path, char *value, size_t size);
int pusb_xpath_get_bool_from(xmlDocPtr doc, const char *base, const char *path,
int *value);
+int pusb_xpath_get_int(xmlDocPtr doc, const char *path, int *value);
+int pusb_xpath_get_int_from(xmlDocPtr doc,
+ const char *base,
+ const char *path,
+ int *value);
+
#endif /* !PUSB_XPATH_H_ */