From 101dd376b32c2cd12640e81b93c2f30975baac7f Mon Sep 17 00:00:00 2001 From: Joursoir Date: Mon, 26 Oct 2020 19:11:16 +0000 Subject: feature: edit command --- implementation.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'implementation.c') diff --git a/implementation.c b/implementation.c index 0a011ce..04af102 100644 --- a/implementation.c +++ b/implementation.c @@ -8,9 +8,10 @@ #include "handerror.h" #include "easydir.h" +#include "implementation.h" -#define GPG_OUTPUT_FILE ".gap" -#define GPG_PUBLICKEY_MAXLENGTH 1025 // +1 for '\0' +/* define in implementation.h */ +// GPG_PUBLICKEY_MAXLENGTH 1025 // == global var == extern char *gPath_rootdir; // /home/[username]/.lockpassword/ @@ -28,7 +29,7 @@ void checkForbiddenPaths(char *path) // check two dot in path } } -static char *getGPGKey(char *dest, size_t size) +char *getGPGKey(char *dest, size_t size) { FILE *fileGPG = fopen(".gpg-key", "r"); if(fileGPG == NULL) { @@ -44,16 +45,16 @@ static char *getGPGKey(char *dest, size_t size) return dest; } -char* getPassword(char *path_pass, char *password, size_t size) // path_pass is not used +char* getPassword(char *path_pass, char *password, size_t size) { int size_gpgkey = sizeof(char) * GPG_PUBLICKEY_MAXLENGTH; char *secret_gpgkey = (char *) malloc(size_gpgkey); getGPGKey(secret_gpgkey, size_gpgkey); - char *arguments[] = {"gpg", "-d", "--quiet", "-r", secret_gpgkey, "-o", GPG_OUTPUT_FILE, gPath_pass, NULL}; + char *arguments[] = {"gpg", "-d", "--quiet", "-r", secret_gpgkey, "-o", path_pass, gPath_pass, NULL}; easyFork("gpg", arguments); - FILE *filePass = fopen(GPG_OUTPUT_FILE, "r"); + FILE *filePass = fopen(path_pass, "r"); if(filePass == NULL) callError(127); if(!fgets(password, size, filePass)) { @@ -61,8 +62,8 @@ char* getPassword(char *path_pass, char *password, size_t size) // path_pass is } fclose(filePass); + remove(path_pass); free(secret_gpgkey); - remove(GPG_OUTPUT_FILE); return password; } @@ -218,7 +219,7 @@ int getOverwriteAnswer(char *path) snprintf(text, buffSize, "Password for '%s' exists. Overwrite? (Y/N)", path); printf("%s ", text); - char answer; + int answer; while((answer = fgetc(stdin))) { clearStdinBuff(); -- cgit v1.2.3-18-g5258