Annotation of src/usr.bin/tcfs/tcfsrmuser.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:
! 14: #include <stdio.h>
! 15: #include <unistd.h>
! 16:
! 17: #include <miscfs/tcfs/tcfs.h>
! 18: #include "tcfslib.h"
! 19: #include "tcfserrors.h"
! 20:
! 21: char *rmuser_usage="Usage: %s [OPTION]...
! 22: Remove an user entry from the TCFS dabatase.
! 23:
! 24: -l <user> Username to remove from the TCFS database
! 25: -h Shows this help
! 26: -v Makes the output a little more verbose\n";
! 27:
! 28: int
! 29: rmuser_main (int argn, char *argv[])
! 30: {
! 31: int have_user=FALSE;
! 32: int be_verbose=FALSE;
! 33: char *user, *passwd;
! 34: tcfspwdb *user_info;
! 35: int val;
! 36:
! 37: /*
! 38: * Going to check the arguments
! 39: */
! 40:
! 41: user=(char *) malloc(20);
! 42:
! 43: while ((val=getopt (argn, argv, "l:hv"))!=EOF)
! 44: switch (val)
! 45: {
! 46: case 'l':
! 47: strncpy (user, optarg, 9);
! 48: have_user=TRUE;
! 49: break;
! 50:
! 51: case 'h':
! 52: show_usage (rmuser_usage, argv[0]);
! 53: exit (OK);
! 54: break;
! 55:
! 56: case 'v':
! 57: be_verbose=TRUE;
! 58: break;
! 59:
! 60: default:
! 61: fprintf (stderr, "Try %s --help for more information.\n", argv[0]);
! 62: exit (ER_UNKOPT);
! 63: break;
! 64: }
! 65:
! 66: if (argn-optind)
! 67: tcfs_error (ER_UNKOPT, NULL);
! 68:
! 69: /*
! 70: * Here we don't have to drop root privileges because only root
! 71: * should run us.
! 72: * However we can do better. Maybe in next versions.
! 73: */
! 74: if (!have_user)
! 75: {
! 76: printf ("Username to remove from TCFS database: ");
! 77: fgets (user,9,stdin);
! 78: user[strlen(user)-1]='\0';
! 79: }
! 80:
! 81: if (be_verbose)
! 82: printf ("Deleting the entry for user %s from the TCFS database...\n", user);
! 83:
! 84: /*
! 85: * Deleting an entry from the key database
! 86: */
! 87: if (!tcfspwdbr_new (&user_info))
! 88: tcfs_error (ER_MEM, NULL);
! 89:
! 90: if (!tcfspwdbr_edit (&user_info, F_USR, user))
! 91: tcfs_error (ER_MEM, NULL);
! 92:
! 93: if (!tcfs_putpwnam (user, user_info, U_DEL))
! 94: tcfs_error (ER_CUSTOM, "Error: cannot remove user.");
! 95:
! 96: if (be_verbose)
! 97: printf ("User entry removed with success.\n");
! 98:
! 99: tcfs_error (OK, NULL);
! 100: }