aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-10-08 17:56:11 +0300
committerJoursoir <chat@joursoir.net>2020-10-08 17:56:11 +0300
commitae832e7ec00a30bf23609fcf35e7d1ffcf63e19b (patch)
tree8b8c2ab2e4d40b36a1bd9fecc38620d906370765
parent84180756da688591de8324733d344bd14d15ddef (diff)
downloadlock-password-ae832e7ec00a30bf23609fcf35e7d1ffcf63e19b.tar.gz
lock-password-ae832e7ec00a30bf23609fcf35e7d1ffcf63e19b.tar.bz2
lock-password-ae832e7ec00a30bf23609fcf35e7d1ffcf63e19b.zip
add docs and change style
-rw-r--r--.gitignore4
-rwxr-xr-xMakefile31
-rw-r--r--README.md23
-rwxr-xr-xcompulation4
-rw-r--r--main.c78
5 files changed, 78 insertions, 62 deletions
diff --git a/.gitignore b/.gitignore
index d28ca88..9a8e40d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-documentation/
+architecture
*.o
-lpass \ No newline at end of file
+lpass
diff --git a/Makefile b/Makefile
new file mode 100755
index 0000000..4301985
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,31 @@
+VERSION = 1.01
+PREFIX = /usr/local/bin
+CC = gcc
+CFLAGS = -Wall -g
+SOURCES = easydir.c handerror.c main.c
+OBJECTS = $(SOURCES:.c=.o)
+EXECUTABLE = lpass
+
+.PHONY: all clean install uninstall
+
+all: $(EXECUTABLE)
+
+clean:
+ @rm -rf $(EXECUTABLE) $(OBJECTS)
+
+$(OBJECTS):
+ @$(CC) -c $(CFLAGS) $(SOURCES)
+
+$(EXECUTABLE): $(OBJECTS)
+ @$(CC) $(CFLAGS) -o $(EXECUTABLE) $(OBJECTS)
+
+install: all
+ @echo installing file to $(PREFIX)
+ #@mkdir -p $(PREFIX)
+ #@cp -f $(EXECUTABLE) $(PREFIX)
+ @install $(EXECUTABLE) $(PREFIX)
+ @chmod 755 $(PREFIX)/$(EXECUTABLE)
+
+uninstall:
+ @echo removing file from $(PREFIX)
+ @rm -rf $(PREFIX)/$(EXECUTABLE) \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ac13ed6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,23 @@
+# LockPassword - a simple terminal password manager
+## Synopsis
+### lpass [command]
+
+## Commands
+### --init
+Initialize password bank. Before use a LockPassword you must be run this command.
+### -c
+In developing...
+### -e name
+Edit a existing password in 'name'.
+### -g [number-of-symbols] name
+Generate a new password using length [number-of-symbols] and insert in name. Without [number-of-symbols] default generate 10 chars.
+### -i name
+Create 'name' store and insert your password there.
+### -R name
+Remove 'name' store from the password bank.
+
+## How are passwords stored?
+For now, passwords are kept in clear еtext. We will add password encryption in the next update
+
+## Guide
+Coming soon...
diff --git a/compulation b/compulation
deleted file mode 100755
index 614c238..0000000
--- a/compulation
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-gcc -c -Wall -g *.c
-gcc -Wall -g -o lpass *.o \ No newline at end of file
diff --git a/main.c b/main.c
index 20dee39..853e686 100644
--- a/main.c
+++ b/main.c
@@ -33,6 +33,9 @@ static char* getPassword(char *path, char *password)
FILE *filePass;
filePass = fopen(path, "r");
if(filePass == NULL) {
+ if(errno == ENOENT) { // file doesn't exist
+ printError("lpass: No such file exists\n");
+ }
callError(110);
}
@@ -66,7 +69,7 @@ static void showTree(char *path)
}
}
-static void changePass(char *root_path, char *add_path, char *password)
+static void insertPass(char *root_path, char *add_path, char *password)
{
/* root_path = /home/[username]/
add_path = banks/france/[number]
@@ -81,71 +84,34 @@ static void changePass(char *root_path, char *add_path, char *password)
}
int pass_buf = strlen(root_path) + strlen(add_path);
- char *final_path = (char*) malloc(sizeof(char) * pass_buf + 1);
+ char *final_path = (char*) malloc(sizeof(char) * pass_buf + sizeof(char));
strcpy(final_path, root_path);
strcat(final_path, "/");
strcat(final_path, main_path);
- if(chdir(final_path) != 0) {
- callError(107);
- }
-
- FILE *filePass;
- filePass = fopen(file_path, "w");
- if(filePass == NULL) {
- if(errno == ENOENT) { // file doesn't exist
- printError("lpass: No such file exists\n");
+ if(strcmp(main_path, "") != 0) {
+ int pid = fork();
+ if(pid == -1) callError(103);
+ if(pid == 0) { /* new process */
+ execlp("mkdir", "mkdir", "-p", main_path, NULL);
+ perror("mkdir");
+ exit(4);
}
- callError(114);
- }
- fputs(password, filePass);
-
- free(main_path);
- free(file_path);
- fclose(filePass);
-}
-
-static void insertPass(char *root_path, char *add_path, char *password)
-{
- /* root_path = /home/[username]/
- add_path = banks/france/[number]
- main_path = banks/france
- file_path = [number] */
-
- char *main_path = malloc(sizeof(char) * strlen(add_path) + 1);
- char *file_path = malloc(sizeof(char) * strlen(add_path) + 1);
-
- if(splitPath(add_path, main_path, file_path) == NULL) {
- printError("lpass: The path you specified is incorrect\n");
- }
-
- int pass_buf = strlen(root_path) + strlen(add_path);
- char *final_path = (char*) malloc(sizeof(char) * pass_buf + 1);
-
- strcpy(final_path, root_path);
- strcat(final_path, "/");
- strcat(final_path, main_path);
-
- int pid = fork();
- if(pid == -1) callError(103);
- if(pid == 0) { /* new process */
- execlp("mkdir", "mkdir", "-p", main_path, NULL);
- perror("mkdir");
- exit(4);
+ wait(&pid);
}
- wait(&pid);
-
+
if(chdir(final_path) != 0) {
callError(107);
}
// create file, copy password there
FILE *filePass;
- filePass = fopen(file_path, "w");
+ filePass = fopen(file_path, "w");
if(filePass == NULL) {
callError(108);
}
+
fputs(password, filePass);
free(main_path);
@@ -230,7 +196,7 @@ static int getAnswer(char *text)
static char *typePass(char *text, char *dest)
{
printf("%s", text);
- if(fgets(dest, (sizeof(char)*MAXLEN_PASSWORD + 1), stdin) == NULL) {
+ if(fgets(dest, (sizeof(char)*MAXLEN_PASSWORD + sizeof(char)), stdin) == NULL) {
nonvisibleEnter(0);
printError("lpass: Unexpected end of file\n");
}
@@ -272,7 +238,7 @@ int main(int argc, char *argv[])
};
int rootBuf = strlen(getenv("HOME")) + strlen(FULLNAMEFILE);
- char *rootPath = (char *) malloc(sizeof(char) * rootBuf + 1); // +1 for '\0'
+ char *rootPath = (char *) malloc(sizeof(char) * rootBuf + sizeof(char)); // +1 for '\0'
int path_init = 0;
strcpy(rootPath, getenv("HOME"));
@@ -340,7 +306,7 @@ int main(int argc, char *argv[])
if(strcmp(pass_one, pass_two) == 0) {
printf("Password correct\n");
- changePass(rootPath, passPath, pass_one);
+ insertPass(rootPath, passPath, pass_one);
printf("Password updated successfully for %s\n", passPath);
}
else printf("Passwords do not match\n");
@@ -353,7 +319,7 @@ int main(int argc, char *argv[])
if(checkFileExist(passPath) == 1) {
/* ask user about change pass */
- int buffSize = (strlen("Do you want generate new password and paste it in '' (Y/N)?") + strlen(passPath)) * sizeof(char) + 1;
+ int buffSize = (strlen("Do you want generate new password and paste it in '' (Y/N)?") + strlen(passPath)) * sizeof(char) + sizeof(char);
char *str = malloc(buffSize);
snprintf(str, buffSize, "Do you want generate new password and paste it in '%s' (Y/N)?", passPath);
@@ -412,8 +378,8 @@ int main(int argc, char *argv[])
printError("lpass: No such file exists\n");
}
- char *main_path = malloc(sizeof(char) * strlen(optarg) + 1);
- char *file_path = malloc(sizeof(char) * strlen(optarg) + 1);
+ char *main_path = malloc(sizeof(char) * strlen(optarg) + sizeof(char));
+ char *file_path = malloc(sizeof(char) * strlen(optarg) + sizeof(char));
if(splitPath(optarg, main_path, file_path) == NULL) { // check correct input
printError("lpass: The path you specified is incorrect\n");