Skip to content

Commit

Permalink
New feature, create directory in the user home.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAtYubico committed Nov 14, 2012
1 parent ad27af3 commit 1eff1ad
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions ykpamcfg.c
Expand Up @@ -37,6 +37,8 @@
#include <pwd.h> #include <pwd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>


#include <ykpers.h> #include <ykpers.h>


Expand Down Expand Up @@ -136,12 +138,41 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, i
*exit_code = 1; *exit_code = 1;


p = getpwuid (getuid ()); p = getpwuid (getuid ());

if (! p) { if (! p) {
fprintf (stderr, "Who am I???"); fprintf (stderr, "Who am I???");
goto out; 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)) { if (! get_user_challenge_file(yk, output_dir, p->pw_name, &fn)) {
fprintf (stderr, "Failed getting chalresp state filename\n"); fprintf (stderr, "Failed getting chalresp state filename\n");
goto out; goto out;
Expand Down Expand Up @@ -242,7 +273,7 @@ main(int argc, char **argv)
goto err; goto err;


if (! check_firmware_version(yk, verbose, false)) if (! check_firmware_version(yk, verbose, false))
goto err; goto err;


if (! do_add_hmac_chalresp (yk, slot, verbose, output_dir, &exit_code)) if (! do_add_hmac_chalresp (yk, slot, verbose, output_dir, &exit_code))
goto err; goto err;
Expand Down

0 comments on commit 1eff1ad

Please sign in to comment.