diff options
-rwxr-xr-x | Makefile | 6 | ||||
-rw-r--r-- | src/implementation.c | 51 | ||||
-rw-r--r-- | src/implementation.h | 2 | ||||
-rw-r--r-- | src/r-x11.c | 2 | ||||
-rw-r--r-- | src/r-x11.h | 2 |
5 files changed, 33 insertions, 30 deletions
@@ -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 */ |