aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-01 21:10:28 +0000
committerJoursoir <chat@joursoir.net>2021-03-01 21:10:28 +0000
commitce7c8411d7af66904da5e852f01fd95426ccf5c0 (patch)
tree29a0e1545cf2aa38d128e9031c9495f26582fa18
parent10b676a2fee216cc00d2ca090a93a23d8b47241f (diff)
downloadlock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.tar.gz
lock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.tar.bz2
lock-password-ce7c8411d7af66904da5e852f01fd95426ccf5c0.zip
use xlib for copy password
-rwxr-xr-xMakefile6
-rw-r--r--src/implementation.c51
-rw-r--r--src/implementation.h2
-rw-r--r--src/r-x11.c2
-rw-r--r--src/r-x11.h2
5 files changed, 33 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index b425c33..4aa7e94 100755
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,10 @@
PREFIX = /usr/local/bin
CC = gcc
-CFLAGS = -Wall -g $(shell gpgme-config --cflags --libs) # -DDEBUG
+CFLAGS = -Wall -g \
+ $(shell gpgme-config --cflags --libs) #-DDEBUG
+ifdef DISPLAY
+ CFLAGS += -lX11 -DDISPLAY
+endif
MAN_PATH = /usr/share/man/man1
SOURCES = src/*.c
OBJECTS = *.o
diff --git a/src/implementation.c b/src/implementation.c
index fb279fc..af9f79d 100644
--- a/src/implementation.c
+++ b/src/implementation.c
@@ -31,42 +31,41 @@
#include "xstd.h"
#include "easydir.h"
#include "r-gpgme.h"
+#if defined(DISPLAY)
+ #include "r-x11.h"
+#endif
/* define in implementation.h */
// GPG_PUBLICKEY_MAXLENGTH NNNN
-
-void copy_outside(char *password)
+int copy_outside(char *password)
{
- char *simple_path = malloc(sizeof(char) * (5 + 1));
- strcpy(simple_path, ".pass");
+ #if defined(DISPLAY)
+ int pid;
+ pid = fork();
+ if(pid == -1)
+ errprint(1, "X11 fork() failed\n");
+ if(pid == 0) /* new process */
+ exit(run_clipboard(password));
+ return 0;
+ #endif
- if(getenv("DISPLAY") != NULL)
- {
- FILE *f_pass;
- f_pass = fopen(simple_path, "w");
- if(f_pass == NULL) {
- callError(130);
+ if(getenv("WAYLAND_DISPLAY") != NULL) {
+ char * const wl_copy[] = {"wl-copy", password, NULL};
+ int pid;
+ pid = fork();
+ if(pid == -1)
+ errprint(1, "Wayland fork() failed\n");
+ if(pid == 0) { /* new process */
+ execvp("wl-copy", wl_copy);
+ perror("wl-copy");
+ exit(1);
}
- fputs(password, f_pass);
- fclose(f_pass);
-
- char *xclip[] = {"xclip", "-selection", "clipboard", "-i", simple_path, NULL};
- easyFork("xclip", xclip);
- remove(simple_path);
- free(simple_path);
+ return 0;
}
- 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
+ errprint(1, "You didn't have x11 or wayland when app builded\n");
}
/* check two dot in path */
diff --git a/src/implementation.h b/src/implementation.h
index 1dcd884..dc905ef 100644
--- a/src/implementation.h
+++ b/src/implementation.h
@@ -21,7 +21,7 @@
#define GPG_PUBLICKEY_MAXLENGTH 1024
-void copy_outside(char *password);
+int copy_outside(char *password);
int check_sneaky_paths(const char *path);
char *get_pubkey();
char *get_password(const char *path);
diff --git a/src/r-x11.c b/src/r-x11.c
index 0e68225..3a4b240 100644
--- a/src/r-x11.c
+++ b/src/r-x11.c
@@ -65,7 +65,7 @@ static void send_data(Display *dpy, XSelectionRequestEvent *sev,
XSendEvent(dpy, sev->requestor, True, NoEventMask, (XEvent *)&ssev);
}
-int run_clipboard(char *data)
+int run_clipboard(const char *data)
{
Display *dpy;
Window owner, root;
diff --git a/src/r-x11.h b/src/r-x11.h
index b331bb4..2c9be04 100644
--- a/src/r-x11.h
+++ b/src/r-x11.h
@@ -19,6 +19,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
***/
-int run_clipboard(char *data);
+int run_clipboard(const char *data);
#endif /* LPASS_RX11_H */