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