From 1eff1ad71bd56ac1e7fae1d590aae17b920fd730 Mon Sep 17 00:00:00 2001 From: Tommaso Galassi De Orchi Date: Wed, 14 Nov 2012 14:14:06 +0100 Subject: [PATCH] New feature, create directory in the user home. --- ykpamcfg.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/ykpamcfg.c b/ykpamcfg.c index 979983ad..27e73b93 100644 --- a/ykpamcfg.c +++ b/ykpamcfg.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include @@ -136,12 +138,41 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, i *exit_code = 1; p = getpwuid (getuid ()); - + if (! p) { fprintf (stderr, "Who am I???"); goto out; } + /* + * Create default output directory for the user + */ + + if (!output_dir){ + const char *pathname = p->pw_dir; + char fullpath[256]; + snprintf(fullpath, 256,"%s/.yubico",p->pw_dir); + struct stat st; + + //check if directory exists + if (stat(fullpath,&st)!=0 ){ + if(mkdir(fullpath, S_IRWXU)==-1){ + fprintf(stderr, "Failed creating directory '%s' :%s\n", + fullpath, strerror(errno)); + } + if(verbose){ + printf("Directory %s created successfully.\n", fullpath); + } + } + else{ + if(!S_ISDIR(st.st_mode)){ + fprintf(stderr, "Destination %s already exist and is not a directory.\n", + fullpath); + goto out; + } + } + } + if (! get_user_challenge_file(yk, output_dir, p->pw_name, &fn)) { fprintf (stderr, "Failed getting chalresp state filename\n"); goto out; @@ -242,7 +273,7 @@ main(int argc, char **argv) goto err; if (! check_firmware_version(yk, verbose, false)) - goto err; + goto err; if (! do_add_hmac_chalresp (yk, slot, verbose, output_dir, &exit_code)) goto err;