aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-01-14 19:26:56 +0000
committerJoursoir <chat@joursoir.net>2021-01-14 19:30:18 +0000
commit3165436ed14cb353843abf01e9208c088583bc40 (patch)
tree0cc5d967c94198a90402a732ca6e8842665b58fc /src
parentca3fc712cd9038c587cc897426dbadedcee0cfd0 (diff)
downloadlock-password-3165436ed14cb353843abf01e9208c088583bc40.tar.gz
lock-password-3165436ed14cb353843abf01e9208c088583bc40.tar.bz2
lock-password-3165436ed14cb353843abf01e9208c088583bc40.zip
rewrite shell script 'copy' to c language
Diffstat (limited to 'src')
-rw-r--r--src/implementation.c33
-rw-r--r--src/main.c5
2 files changed, 30 insertions, 8 deletions
diff --git a/src/implementation.c b/src/implementation.c
index 3ba2be7..7d19282 100644
--- a/src/implementation.c
+++ b/src/implementation.c
@@ -22,13 +22,36 @@ extern char *gPath_pass; // example: programming/github.com/joursoir.gpg
static void copyText(char *password)
{
- size_t size = (strlen(password) + strlen(BASH_EXEC_COPY) + 1) * sizeof(char);
- char *command = malloc(size);
+ size_t size = (strlen(gPath_rootdir) + 5 + 1) * sizeof(char);
+ char *simple_path = malloc(size);
+ snprintf(simple_path, size, "%s%s", gPath_rootdir, ".pass");
- snprintf(command, size, "%s %s", BASH_EXEC_COPY, password);
- system(command);
+ if(getenv("DISPLAY") != NULL)
+ {
+ FILE *f_pass;
+ f_pass = fopen(simple_path, "w");
+ if(f_pass == NULL) {
+ callError(130);
+ }
+ fputs(password, f_pass);
+ fclose(f_pass);
+
+ char *xclip[] = {"xclip", "-selection", "clipboard", "-i", simple_path, NULL};
+ easyFork("xclip", xclip);
- free(command);
+ remove(simple_path);
+ free(simple_path);
+ }
+ else if(getenv("WAYLAND_DISPLAY") != NULL)
+ {
+ char *wl_copy[] = {"wl-copy", password, NULL};
+ easyFork("wl-copy", wl_copy);
+ }
+ else printError("Error: No X11 or Wayland");
+
+ #if defined(DEBUG)
+ printf("Password copied to clipboard\n");
+ #endif
}
void checkForbiddenPaths(char *path) // check two dot in path
diff --git a/src/main.c b/src/main.c
index edcc517..fd1345b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,9 +18,8 @@
#include "handerror.h"
#include "implementation.h"
-#define VERSION "1.0b"
-#define DATE_RELEASE "6 January, 2021"
-#define DEBUG
+#define VERSION "1.0c"
+#define DATE_RELEASE "14 January, 2021"
#define STANDARD_TEXTEDITOR "vim"
#define MAXLEN_TEXTEDITOR 16
#define MINLEN_PASSWORD 1