aboutsummaryrefslogtreecommitdiffstats
path: root/implementation.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-10-19 15:54:40 +0000
committerJoursoir <chat@joursoir.net>2020-10-19 15:54:40 +0000
commit8af0737920cceb1d29bbd4ac6cf7b692c1ad1416 (patch)
tree2939d0e832649126b349e5a0d957712b29820877 /implementation.c
parent742fe01bf8712b37a0f6cdfe379c1966bcd11c90 (diff)
downloadlock-password-8af0737920cceb1d29bbd4ac6cf7b692c1ad1416.tar.gz
lock-password-8af0737920cceb1d29bbd4ac6cf7b692c1ad1416.tar.bz2
lock-password-8af0737920cceb1d29bbd4ac6cf7b692c1ad1416.zip
feature: gpg encryption, remove pass
Diffstat (limited to 'implementation.c')
-rw-r--r--implementation.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/implementation.c b/implementation.c
index 0ef17c1..f695b01 100644
--- a/implementation.c
+++ b/implementation.c
@@ -12,17 +12,22 @@
// == global var ==
extern char *gPath_rootdir;
+extern char *gSecret_gpgkey;
char* getPassword(char *path, char *password, int maxlen)
{
- FILE *filePass;
- filePass = fopen(path, "r");
- if(filePass == NULL) {
- if(errno == ENOENT) { // file doesn't exist
- printError("lpass: No such file exists\n");
- }
- callError(110);
+ // gpg
+ int pid = fork();
+ if(pid == 1) callError(126);
+ if(pid == 0) {
+ execlp("gpg", "-d", "--quiet", "-r", gSecret_gpgkey, "-o", "gap", path, NULL);
+ perror("gpg");
+ exit(4);
}
+ wait(&pid);
+
+ FILE *filePass = fopen("gap", "r");
+ if(filePass == NULL) callError(127);
char sign[maxlen];
if(!fgets(sign, sizeof(sign), filePass)) {
@@ -31,6 +36,8 @@ char* getPassword(char *path, char *password, int maxlen)
strcpy(password, sign);
fclose(filePass);
+
+ remove("gap");
return password;
}
@@ -91,6 +98,17 @@ void insertPass(char *add_path, char *password)
fputs(password, filePass);
fclose(filePass);
+ // gpg
+ int pid = fork();
+ if(pid == 1) callError(225);
+ if(pid == 0) {
+ execlp("gpg", "-a", "-r", gSecret_gpgkey, "-e", file_path, NULL);
+ perror("gpg");
+ exit(4);
+ }
+ wait(&pid);
+ remove(file_path);
+
free(main_path);
free(file_path);
}