Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New feature, create directory in the user home.

  • Loading branch information...
commit 1eff1ad71bd56ac1e7fae1d590aae17b920fd730 1 parent ad27af3
@TomAtYubico TomAtYubico authored
Showing with 33 additions and 2 deletions.
  1. +33 −2 ykpamcfg.c
View
35 ykpamcfg.c
@@ -37,6 +37,8 @@
#include <pwd.h>
#include <string.h>
#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <ykpers.h>
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.