aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-23 17:32:33 +0000
committerJoursoir <chat@joursoir.net>2021-03-23 17:32:33 +0000
commite06f9fcb689878878469e2396617786ed525ca87 (patch)
tree1efd4748996de665c01595464cb7f40ab9a7618a
parentf14b09b10db42962a4f7f0a4d7f9cf2ea8feef4f (diff)
downloadlock-password-e06f9fcb689878878469e2396617786ed525ca87.tar.gz
lock-password-e06f9fcb689878878469e2396617786ed525ca87.tar.bz2
lock-password-e06f9fcb689878878469e2396617786ed525ca87.zip
refactor; set correct headers guard
-rw-r--r--src/constants.h2
-rw-r--r--src/easydir.h6
-rw-r--r--src/exec-cmd.c2
-rw-r--r--src/r-gpgme.c11
-rw-r--r--src/routines.c (renamed from src/implementation.c)28
-rw-r--r--src/routines.h (renamed from src/implementation.h)6
-rw-r--r--src/xstd.h2
7 files changed, 25 insertions, 32 deletions
diff --git a/src/constants.h b/src/constants.h
index cc15a86..0843b5b 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -51,7 +51,7 @@
#endif
enum {
- maxlen_texteditor = 16,
+ maxlen_fingerprint = 256,
minlen_pass = 1,
maxlen_pass = 128,
stdlen_pass = 14
diff --git a/src/easydir.h b/src/easydir.h
index 292002e..c9cab57 100644
--- a/src/easydir.h
+++ b/src/easydir.h
@@ -1,5 +1,5 @@
-#ifndef EASYDIR_H
-#define EASYDIR_H
+#ifndef LPASS_EASYDIR_H
+#define LPASS_EASYDIR_H
/***
This file is part of LockPassword
@@ -28,4 +28,4 @@ enum status_file {
int file_exist(const char *path);
int count_dir_entries(const char *path);
-#endif \ No newline at end of file
+#endif /* LPASS_EASYDIR_H */ \ No newline at end of file
diff --git a/src/exec-cmd.c b/src/exec-cmd.c
index 6aced93..4ec1c10 100644
--- a/src/exec-cmd.c
+++ b/src/exec-cmd.c
@@ -29,7 +29,7 @@
#include "exec-cmd.h"
#include "constants.h"
#include "easydir.h"
-#include "implementation.h"
+#include "routines.h"
#include "exec-cmd.h"
#include "tree.h"
diff --git a/src/r-gpgme.c b/src/r-gpgme.c
index a13a62a..586bd55 100644
--- a/src/r-gpgme.c
+++ b/src/r-gpgme.c
@@ -23,10 +23,9 @@
#include <errno.h>
#include <gpgme.h>
+#include "constants.h"
#include "r-gpgme.h"
-#define BUF_SIZE 128
-
#ifdef DEBUG
#define ret_if_err(ret, err) \
do { \
@@ -79,7 +78,7 @@ static int init_ctx(gpgme_ctx_t ctx, gpgme_protocol_t protocol)
static int loop_read(const char *path, gpgme_data_t dh)
{
- char buf[BUF_SIZE];
+ char buf[maxlen_pass];
int ret;
FILE *f = fopen(path, "w");
@@ -91,7 +90,7 @@ static int loop_read(const char *path, gpgme_data_t dh)
fclose(f);
ret_if_err(1, gpgme_err_code_from_errno(errno));
}
- while((ret = gpgme_data_read(dh, buf, BUF_SIZE)) > 0)
+ while((ret = gpgme_data_read(dh, buf, maxlen_pass)) > 0)
fwrite(buf, ret, 1, f);
if(ret < 0) {
fclose(f);
@@ -165,8 +164,8 @@ char *decrypt_data(const char *path)
if(ret)
ret_if_err(NULL, gpgme_err_code_from_errno(errno));
- char *data = malloc(sizeof(char) * (BUF_SIZE + 1));
- gpgme_data_read(plain, data, BUF_SIZE);
+ char *data = malloc(sizeof(char) * (maxlen_pass + 1));
+ gpgme_data_read(plain, data, maxlen_pass);
gpgme_data_release(plain);
gpgme_data_release(cipher);
diff --git a/src/implementation.c b/src/routines.c
index af59b21..f6b6bcc 100644
--- a/src/implementation.c
+++ b/src/routines.c
@@ -26,7 +26,7 @@
#include <errno.h>
#include <sys/stat.h>
-#include "implementation.h"
+#include "routines.h"
#include "constants.h"
#include "easydir.h"
#include "r-gpgme.h"
@@ -34,9 +34,6 @@
#include "r-x11.h"
#endif
-/* define in implementation.h */
-// GPG_PUBLICKEY_MAXLENGTH NNNN
-
int copy_outside(char *password)
{
#if defined(DISPLAY)
@@ -81,24 +78,22 @@ int check_sneaky_paths(const char *path)
char *get_pubkey()
{
- int size_key = sizeof(char) * GPG_PUBLICKEY_MAXLENGTH;
- char *pubkey = malloc(size_key + sizeof(char));
+ char *pubkey;
FILE *fileGPG = fopen(".gpg-key", "r");
if(fileGPG == NULL) {
- free(pubkey);
if(errno == ENOENT)
- errprint_r(NULL, "No GPG key exists. Use \"lpass init\".");
- perror(".gpg-key");
- return NULL;
+ errprint_r(NULL, "No GPG key exists. Use \"lpass init\"\n");
+ errprint_r(NULL, "%s\n", strerror(errno));
}
- if(!fgets(pubkey, size_key, fileGPG)) {
+ pubkey = malloc(sizeof(char) * (maxlen_fingerprint + 1));
+ if(fgets(pubkey, maxlen_fingerprint + 1, fileGPG) == NULL) {
free(pubkey);
- pubkey = NULL;
+ errprint_ptr(&pubkey, NULL, "%s\n", strerror(errno));
}
- fclose(fileGPG);
+ fclose(fileGPG);
return pubkey;
}
@@ -152,13 +147,12 @@ int insert_pass(const char *path, const char *password)
char *get_input(int minlen, int maxlen)
{
- size_t size = sizeof(char) * maxlen;
- char *pass = malloc(size + sizeof(char)); // +1 for '\0'
+ char *pass = malloc(sizeof(char) * (maxlen + 1));
int len;
- if(fgets(pass, size, stdin) == NULL) {
+ if(fgets(pass, maxlen + 1, stdin) == NULL) {
free(pass);
- return NULL;
+ errprint_ptr(&pass, NULL, "%s\n", strerror(errno));
}
len = strlen(pass);
diff --git a/src/implementation.h b/src/routines.h
index 467da6f..90d6fb3 100644
--- a/src/implementation.h
+++ b/src/routines.h
@@ -1,5 +1,5 @@
-#ifndef IMPLEMENTATION_H
-#define IMPLEMENTATION_H
+#ifndef LPASS_ROUTINES_H
+#define LPASS_ROUTINES_H
/***
This file is part of LockPassword
@@ -31,4 +31,4 @@ char *get_input(int minlen, int maxlen);
char *gen_password(int length);
int overwrite_answer(const char *path);
-#endif \ No newline at end of file
+#endif /* LPASS_ROUTINES_H */ \ No newline at end of file
diff --git a/src/xstd.h b/src/xstd.h
index 351069d..4683c3b 100644
--- a/src/xstd.h
+++ b/src/xstd.h
@@ -22,4 +22,4 @@
char *xstrcat(const char *first, const char *second,
const char *delimiter);
-#endif \ No newline at end of file
+#endif /* LPASS_XSTD_H */