[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.6

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