Browse Source

The device directory is now automatically created if it didn't exist.

master
Andrea Luzzardi 18 years ago
parent
commit
6d38f27c7e
2 changed files with 26 additions and 24 deletions
  1. +7
    -2
      pam_usb/src/conf.h
  2. +19
    -22
      pam_usb/src/pad.c

+ 7
- 2
pam_usb/src/conf.h View File

@ -22,6 +22,11 @@
# define CONF_USER_XPATH "//configuration/users/user[@id='%s']/%s" # define CONF_USER_XPATH "//configuration/users/user[@id='%s']/%s"
# define CONF_SERVICE_XPATH "//configuration/services/service[@id='%s']/%s" # define CONF_SERVICE_XPATH "//configuration/services/service[@id='%s']/%s"
# define CONF_USER_MAXLEN 32 # define CONF_USER_MAXLEN 32
# include <limits.h>
# include <linux/limits.h>
# ifndef PATH_MAX
# define PATH_MAX 4096
# endif
typedef struct pusb_device typedef struct pusb_device
{ {
@ -41,8 +46,8 @@ typedef struct pusb_options
int color_log; int color_log;
int one_time_pad; int one_time_pad;
char hostname[32]; char hostname[32];
char system_pad_directory[128];
char device_pad_directory[32];
char system_pad_directory[PATH_MAX];
char device_pad_directory[PATH_MAX];
t_pusb_device device; t_pusb_device device;
} t_pusb_options; } t_pusb_options;


+ 19
- 22
pam_usb/src/pad.c View File

@ -36,25 +36,31 @@ static FILE *pusb_pad_open_device(t_pusb_options *opts,
const char *mode) const char *mode)
{ {
FILE *f; FILE *f;
char *path;
size_t path_size;
char path[PATH_MAX];
const char *mnt_point; const char *mnt_point;
mnt_point = (char *)libhal_volume_get_mount_point(volume); mnt_point = (char *)libhal_volume_get_mount_point(volume);
if (!mnt_point) if (!mnt_point)
return (NULL); return (NULL);
path_size = strlen(mnt_point) + 1 + strlen(opts->device_pad_directory) +
1 + strlen(user) + 1 + strlen(opts->hostname) + strlen(".pad") + 1;
if (!(path = malloc(path_size)))
memset(path, 0x00, PATH_MAX);
if (strchr(mode, 'w'))
{ {
log_error("malloc error!\n");
return (NULL);
snprintf(path, PATH_MAX, "%s/%s", mnt_point, opts->device_pad_directory);
if (access(path, F_OK) != 0)
{
log_debug("Directory %s does not exist, creating one.\n", path);
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
{
log_debug("Unable to create directory %s: %s\n", path,
strerror(errno));
return (NULL);
}
}
memset(path, 0x00, PATH_MAX);
} }
memset(path, 0x00, path_size);
snprintf(path, path_size, "%s/%s/%s.%s.pad", mnt_point,
snprintf(path, PATH_MAX, "%s/%s/%s.%s.pad", mnt_point,
opts->device_pad_directory, user, opts->hostname); opts->device_pad_directory, user, opts->hostname);
f = fopen(path, mode); f = fopen(path, mode);
free(path);
if (!f) if (!f)
{ {
log_debug("Cannot open device file: %s\n", strerror(errno)); log_debug("Cannot open device file: %s\n", strerror(errno));
@ -94,21 +100,12 @@ static FILE *pusb_pad_open_system(t_pusb_options *opts,
const char *mode) const char *mode)
{ {
FILE *f; FILE *f;
char *path;
size_t path_size;
char path[PATH_MAX];
path_size = strlen(opts->system_pad_directory) + 1 +
strlen(user) + 1 + strlen(opts->device.name) + strlen(".pad") + 1;
if (!(path = malloc(path_size)))
{
log_error("malloc error\n");
return (NULL);
}
memset(path, 0x00, path_size);
snprintf(path, path_size, "%s/%s.%s.pad", opts->system_pad_directory,
memset(path, 0x00, PATH_MAX);
snprintf(path, PATH_MAX, "%s/%s.%s.pad", opts->system_pad_directory,
user, opts->device.name); user, opts->device.name);
f = fopen(path, mode); f = fopen(path, mode);
free(path);
if (!f) if (!f)
{ {
log_debug("Cannot open system file: %s\n", strerror(errno)); log_debug("Cannot open system file: %s\n", strerror(errno));


Loading…
Cancel
Save