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

Annotation of src/usr.bin/tcfs/tcfsrmkey.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 <sys/types.h>
        !            15: #include <ctype.h>
        !            16: #include <pwd.h>
        !            17: #include <unistd.h>
        !            18: #include <sys/param.h>
        !            19: #include <sys/mount.h>
        !            20: #include <des.h>
        !            21:
        !            22: #include <miscfs/tcfs/tcfs.h>
        !            23: #include "tcfslib.h"
        !            24: #include "tcfserrors.h"
        !            25: #include <grp.h>
        !            26:
        !            27: extern char *optarg;
        !            28: extern int optind;
        !            29: char *rmkey_usage=
        !            30: "usage: tcfsrmkey [-f fliesystem-label][-g group][-p mount-point]\n";
        !            31:
        !            32: int
        !            33: rmkey_main(int argc, char *argv[])
        !            34: {
        !            35:        char *fs;
        !            36:        uid_t uid;
        !            37:        gid_t gid;
        !            38:        int es;
        !            39:        char x;
        !            40:        char fslabel[MAXPATHLEN], fspath[MAXPATHLEN];
        !            41:        int havempname = FALSE, havefsname = FALSE, isgroupkey = FALSE;
        !            42:        int havefs = FALSE;
        !            43:        int havename = FALSE, havefspath = FALSE;
        !            44:
        !            45:        while ((x = getopt(argc,argv,"f:p:g:")) != EOF) {
        !            46:                switch(x) {
        !            47:                case 'p':
        !            48:                        havempname = TRUE;
        !            49:                        strlcpy(fspath, optarg, sizeof(fspath));
        !            50:                        break;
        !            51:                case 'f':
        !            52:                        havefsname = TRUE;
        !            53:                        strlcpy(fslabel, optarg, sizeof(fslabel));
        !            54:                        break;
        !            55:                case 'g':
        !            56:                        isgroupkey = TRUE;
        !            57:                        gid = atoi(optarg);
        !            58:                        if (!gid && optarg[0] != 0) {
        !            59:                                struct group *grp;
        !            60:                                grp = (struct group *)getgrnam(optarg);
        !            61:                                if (!grp)
        !            62:                                        tcfs_error(ER_CUSTOM,
        !            63:                                                   "Nonexistant group\n");
        !            64:                                gid = grp->gr_gid;
        !            65:                        }
        !            66:                        break;
        !            67:                default:
        !            68:                        tcfs_error(ER_CUSTOM, rmkey_usage);
        !            69:                        exit(ER_UNKOPT);
        !            70:                }
        !            71:        }
        !            72:        if (argc-optind)
        !            73:                tcfs_error(ER_UNKOPT,NULL);
        !            74:
        !            75:        if (havefsname && havempname) {
        !            76:                tcfs_error(ER_CUSTOM, rmkey_usage);
        !            77:                exit(1);
        !            78:        }
        !            79:
        !            80:        if (havefsname) {
        !            81:                es = tcfs_getfspath(fslabel, fspath);
        !            82:                havename = TRUE;
        !            83:        }
        !            84:
        !            85:        if (havefspath)
        !            86:                havename = TRUE;
        !            87:
        !            88:        if (!havename)
        !            89:                es = tcfs_getfspath("default",fspath);
        !            90:
        !            91:        if(!es) {
        !            92:                tcfs_error(ER_CUSTOM,"fs-label not found!\n");
        !            93:                exit(1);
        !            94:        }
        !            95:
        !            96:        uid = getuid();
        !            97:
        !            98:        if (isgroupkey) {
        !            99:                es = tcfs_group_disable(fspath,uid,gid);
        !           100:                if(es == -1)
        !           101:                        tcfs_error(ER_CUSTOM, "problems updating filesystem");
        !           102:                exit(0);
        !           103:        }
        !           104:
        !           105:        es = tcfs_user_disable(fspath,uid);
        !           106:
        !           107:        if (es == -1)
        !           108:                tcfs_error(ER_CUSTOM,"problems updating filesystem");
        !           109:
        !           110:        exit(0);
        !           111: }