diff options
author | Joursoir <chat@joursoir.net> | 2021-03-03 20:21:20 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-03-03 20:21:20 +0000 |
commit | 1c5f7fd29fce3008218d781ab148a6974e898cac (patch) | |
tree | 54e1da521c476ca510e5db6cb830c0e58049b665 | |
parent | 8a48afccb97462b0dc261e8c99c0825295ebc019 (diff) | |
download | lock-password-1c5f7fd29fce3008218d781ab148a6974e898cac.tar.gz lock-password-1c5f7fd29fce3008218d781ab148a6974e898cac.tar.bz2 lock-password-1c5f7fd29fce3008218d781ab148a6974e898cac.zip |
some chore and delete useless thing
-rw-r--r-- | src/easydir.c | 3 | ||||
-rw-r--r-- | src/implementation.c | 13 | ||||
-rw-r--r-- | src/implementation.h | 2 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/r-x11.c | 2 | ||||
-rw-r--r-- | src/xstd.c | 28 | ||||
-rw-r--r-- | src/xstd.h | 3 |
7 files changed, 14 insertions, 46 deletions
diff --git a/src/easydir.c b/src/easydir.c index cf10110..acf1104 100644 --- a/src/easydir.c +++ b/src/easydir.c @@ -19,13 +19,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <sys/wait.h> #include <errno.h> #include <dirent.h> #include "easydir.h" -#include "xstd.h" int file_exist(const char *path) { diff --git a/src/implementation.c b/src/implementation.c index af9f79d..5fcd17e 100644 --- a/src/implementation.c +++ b/src/implementation.c @@ -28,7 +28,6 @@ #include "implementation.h" #include "constants.h" -#include "xstd.h" #include "easydir.h" #include "r-gpgme.h" #if defined(DISPLAY) @@ -174,19 +173,19 @@ char *get_input(int minlen, int maxlen) return pass; } -void gen_password(char *dest, int amount) +char *gen_password(int length) { int i, min = 33, max = 126; - char password[amount]; + char *password = malloc(sizeof(char) * (length + 1)); srand(time(NULL)); - for(i = 0; i < amount; i++) + for(i = 0; i < length; i++) password[i] = min + rand() % (max-min); - strcpy(dest, password); + return password; } -static void clearStdinBuff() +static void clear_stdin() { int garbage; while( (garbage = fgetc(stdin)) != '\n' && garbage != EOF ) @@ -199,7 +198,7 @@ int overwrite_answer(const char *path) printf("Password for \"%s\" exists. Overwrite? (Y/N)\n", path); while((answer = fgetc(stdin))) { - clearStdinBuff(); + clear_stdin(); switch(answer) { case 'Y': diff --git a/src/implementation.h b/src/implementation.h index dc905ef..467da6f 100644 --- a/src/implementation.h +++ b/src/implementation.h @@ -28,7 +28,7 @@ char *get_password(const char *path); void visible_enter(int status); int insert_pass(const char *path, const char *password); char *get_input(int minlen, int maxlen); -void gen_password(char *dest, int amount); +char *gen_password(int length); int overwrite_answer(const char *path); #endif
\ No newline at end of file @@ -290,18 +290,21 @@ int cmd_generate(int argc, char *argv[]) errprint(1, "You can't generate password for directory\n"); // generate password - char g_pass[pass_length]; - gen_password(g_pass, pass_length); + char *g_pass; + g_pass = gen_password(pass_length); result = insert_pass(path, g_pass); - if(result) + if(result) { + free(g_pass); errprint(1, "Can't add password to LockPassword"); + } if(flag_copy) copy_outside(g_pass); else printf("Generated password: %s\n", g_pass); printf("Password added successfully for %s\n", path); + free(g_pass); return 0; } diff --git a/src/r-x11.c b/src/r-x11.c index 3a4b240..b42c852 100644 --- a/src/r-x11.c +++ b/src/r-x11.c @@ -50,7 +50,7 @@ static void send_data(Display *dpy, XSelectionRequestEvent *sev, if(target == X_utf8) { an = XGetAtomName(dpy, sev->property); if(an) { - dbgprint("Sending data, property '%s'\n", sev->requestor, an); + dbgprint("Sending data, property '%s'\n", an); XFree(an); } @@ -16,36 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ***/ -#include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <sys/wait.h> - -void callError(int num) -{ - fprintf(stderr, "lpass: Sorry, there was an error in the program [#%d]\n", num); - exit(3); -} - -void printError(const char *text) -{ - fprintf(stderr, "%s", text); - exit(4); -} - -void easyFork(char *name, char *arguments[]) -{ - int pid; - pid = fork(); - if(pid == -1) callError(100); - if(pid == 0) { /* new process */ - execvp(name, arguments); - perror(name); - exit(4); - } - wait(&pid); -} char *xstrcat(const char *first, const char *second, const char *delimiter) @@ -19,9 +19,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. ***/ -void easyFork(char *name, char *arguments[]); -void callError(int num); -void printError(const char *text); char *xstrcat(const char *first, const char *second, const char *delimiter); |