From 6cdbc756b060644efa05665a884e13a38e595871 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sun, 22 Oct 2006 01:12:20 +0000 Subject: [PATCH] system pad directory is now relative to the user's home folder --- pam_usb/src/conf.c | 4 +-- pam_usb/src/pad.c | 77 +++++++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/pam_usb/src/conf.c b/pam_usb/src/conf.c index b6933ac..72fcf7b 100644 --- a/pam_usb/src/conf.c +++ b/pam_usb/src/conf.c @@ -130,8 +130,8 @@ int pusb_conf_init(t_pusb_options *opts) log_error("gethostname: %s\n", strerror(errno)); return (0); } - strcpy(opts->system_pad_directory, "./"); - strcpy(opts->device_pad_directory, ".auth"); + strcpy(opts->system_pad_directory, ".pusb"); + strcpy(opts->device_pad_directory, ".pusb"); opts->probe_timeout = 10; opts->enable = 1; opts->debug = 0; diff --git a/pam_usb/src/pad.c b/pam_usb/src/pad.c index 129f051..636b6b5 100644 --- a/pam_usb/src/pad.c +++ b/pam_usb/src/pad.c @@ -43,18 +43,15 @@ static FILE *pusb_pad_open_device(t_pusb_options *opts, if (!mnt_point) return (NULL); memset(path, 0x00, PATH_MAX); - if (strchr(mode, 'w')) + snprintf(path, PATH_MAX, "%s/%s", mnt_point, opts->device_pad_directory); + if (access(path, F_OK) != 0) { - 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("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); - } + log_debug("Unable to create directory %s: %s\n", path, + strerror(errno)); + return (NULL); } memset(path, 0x00, PATH_MAX); } @@ -69,6 +66,47 @@ static FILE *pusb_pad_open_device(t_pusb_options *opts, return (f); } +static FILE *pusb_pad_open_system(t_pusb_options *opts, + const char *user, + const char *mode) +{ + FILE *f; + char path[PATH_MAX]; + struct passwd *user_ent = NULL; + + if (!(user_ent = getpwnam(user)) || !(user_ent->pw_dir)) + { + log_error("Unable to retrieve informations for user \"%s\": %s\n", + strerror(errno)); + return (0); + } + memset(path, 0x00, PATH_MAX); + snprintf(path, PATH_MAX, "%s/%s", user_ent->pw_dir, + opts->system_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); + } + chown(path, user_ent->pw_uid, user_ent->pw_gid); + chmod(path, S_IRUSR | S_IWUSR | S_IXUSR); + } + memset(path, 0x00, PATH_MAX); + snprintf(path, PATH_MAX, "%s/%s/%s.pad", user_ent->pw_dir, + opts->system_pad_directory, opts->device.name); + f = fopen(path, mode); + if (!f) + { + log_debug("Cannot open system file: %s\n", strerror(errno)); + return (NULL); + } + return (f); +} + static int pusb_pad_protect(const char *user, int fd) { struct passwd *user_ent = NULL; @@ -95,25 +133,6 @@ static int pusb_pad_protect(const char *user, int fd) return (1); } -static FILE *pusb_pad_open_system(t_pusb_options *opts, - const char *user, - const char *mode) -{ - FILE *f; - char path[PATH_MAX]; - - memset(path, 0x00, PATH_MAX); - snprintf(path, PATH_MAX, "%s/%s.%s.pad", opts->system_pad_directory, - user, opts->device.name); - f = fopen(path, mode); - if (!f) - { - log_debug("Cannot open system file: %s\n", strerror(errno)); - return (NULL); - } - return (f); -} - static void pusb_pad_update(t_pusb_options *opts, LibHalVolume *volume, const char *user)