diff options
author | Andi Shyti <andi@etezian.org> | 2012-09-02 02:12:08 +0200 |
---|---|---|
committer | Andi Shyti <andi@etezian.org> | 2012-09-02 02:12:08 +0200 |
commit | fdb1692c4e93ec4a71453d5d6c319fe1d6405e60 (patch) | |
tree | 0f6142f3858f3f79f00d13097a73b60f89b37476 /accman.c |
accman: git repo created
Signed-off-by: Andi Shyti <andi@etezian.org>
Diffstat (limited to 'accman.c')
-rw-r--r-- | accman.c | 63 |
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; +} |