#include #include #include #include #include #include #include #include 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; }