Annotation of src/usr.bin/tcfs/tcfsadduser.c, Revision 1.1
1.1 ! provos 1: /*
! 2: * Transparent Cryptographic File System (TCFS) for NetBSD
! 3: * Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
! 4: *
! 5: * references: http://tcfs.dia.unisa.it
! 6: * tcfs-bsd@tcfs.unisa.it
! 7: */
! 8:
! 9: /*
! 10: * Base utility set v0.1
! 11: */
! 12:
! 13: #include <stdio.h>
! 14: #include <unistd.h>
! 15: #include <limits.h>
! 16:
! 17: #include <miscfs/tcfs/tcfs.h>
! 18:
! 19: #include "tcfslib.h"
! 20: #include "tcfserrors.h"
! 21:
! 22:
! 23: char *adduser_usage="Usage: %s [OPTION]...
! 24: Add an user entry to the TCFS database.
! 25:
! 26: -l <user> Username to add to the TCFS database
! 27: -h Shows this help
! 28: -v Makes the output a little more verbose\n";
! 29:
! 30: int
! 31: adduser_main (int argn, char *argv[])
! 32: {
! 33: char val;
! 34: int have_user = FALSE, be_verbose = FALSE;
! 35: char user[LOGIN_NAME_MAX + 1];
! 36: tcfspwdb *user_info;
! 37:
! 38: /*
! 39: * Going to check the arguments
! 40: */
! 41: while ((val = getopt(argn, argv, "g:l:hv"))!=EOF)
! 42: switch (val) {
! 43: case 'l':
! 44: strlcpy (user, optarg, sizeof(user));
! 45: have_user = 1;
! 46: break;
! 47: case 'h':
! 48: show_usage (adduser_usage, argv[0]);
! 49: exit (OK);
! 50: break;
! 51: case 'v':
! 52: be_verbose = TRUE;
! 53: break;
! 54: default:
! 55: fprintf (stderr,
! 56: "Try %s --help for more information.\n",
! 57: argv[0]);
! 58: exit (ER_UNKOPT);
! 59: break;
! 60: }
! 61:
! 62: if (argn-optind)
! 63: tcfs_error (ER_UNKOPT, NULL);
! 64:
! 65: /*
! 66: * Here we don't have to drop root privileges because only root
! 67: * should run us.
! 68: * However we can do better. Maybe in next versions.
! 69: */
! 70: if (!have_user) {
! 71: printf ("Username to add to TCFS database: ");
! 72: fgets (user, sizeof(user), stdin);
! 73: user[strlen(user)-1] = '\0';
! 74: }
! 75:
! 76: if (be_verbose)
! 77: printf ("Creating a new entry for user %s in the TCFS database...\n", user);
! 78:
! 79: /*
! 80: * Creating a new entry into the key database
! 81: */
! 82: if (!tcfspwdbr_new (&user_info))
! 83: tcfs_error (ER_MEM, NULL);
! 84:
! 85: if (!tcfspwdbr_edit (&user_info, F_USR, user))
! 86: tcfs_error (ER_MEM, NULL);
! 87:
! 88: if (!tcfs_putpwnam (user, user_info, U_NEW))
! 89: tcfs_error (ER_CUSTOM, "Error: cannot add user.");
! 90:
! 91: if (be_verbose)
! 92: printf ("User entry created with success.\n");
! 93:
! 94: tcfs_error (OK, NULL);
! 95: }