mirror of
https://github.com/Yubico/yubico-pam.git
synced 2025-01-31 16:52:19 +01:00
New feature, create directory in the user home.
This commit is contained in:
parent
ad27af3518
commit
1eff1ad71b
35
ykpamcfg.c
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user