summaryrefslogtreecommitdiff
path: root/accman.c
diff options
context:
space:
mode:
Diffstat (limited to 'accman.c')
-rw-r--r--accman.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/accman.c b/accman.c
new file mode 100644
index 0000000..79a3d1c
--- /dev/null
+++ b/accman.c
@@ -0,0 +1,63 @@
+#include <accman.h>
+#include <string.h>
+#include <encrypt.h>
+#include <unistd.h>
+#include <encrypt.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <db.h>
+
+char *get_name(void)
+{
+ char name[32];
+ char *usr_n;
+
+ scanf("%s", name);
+ usr_n = (char *) malloc(sizeof(name) + DIM_MDOM + 1);
+ if (!usr_n) {
+ printf("No free memory available\n");
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy(usr_n, name);
+ strcat(usr_n, MDOMAIN);
+
+ return usr_n;
+}
+
+uint8_t confirm(struct user u)
+{
+ int i;
+ char choice[32];
+ ssize_t len;
+
+ printf("User: %s\n", u.n);
+ printf("Do you want to insert new user '%s'? [Y/n] \n", u.n);
+
+ len = read(0, choice, 32);
+ choice[len-1] = '\0';
+
+ for (i = 0; i < strlen(choice); i++)
+ choice[i] = toupper(choice[i]);
+
+ return (!strcmp(choice, "Y") || !strcmp(choice, "YES") ||
+ !strcmp(choice, "")) ? 1 : 0;
+}
+
+int main (void)
+{
+ struct user usr;
+
+ printf("Insert user name (user@etezian.org): ");
+ usr.n = get_name();
+ usr.p = get_crypt_sha256(getpass("Password: "));
+
+ if (confirm(usr)) {
+ db_insert_user(usr);
+ printf("User %s inserted correctly\n", usr.n);
+ }
+ else
+ printf("user insertion aborted\n");
+
+ return 0;
+}