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

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