[BACK]Return to tcfsrmuser.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/tcfsrmuser.c, Revision 1.3

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