summaryrefslogtreecommitdiff
path: root/usr.bin/tcfs/tcfsrmgroup.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
commit48893562fdfa12c4f376d2556da18e817a34484f (patch)
tree033e9aaa47f5617ba6ffbcf7e071ffb8f8f71b07 /usr.bin/tcfs/tcfsrmgroup.c
parent47bc7a26b81967e77c0f021899f1544966df67e2 (diff)
Initial import of very much rewritten TCFS userland. This code is still
nasty.
Diffstat (limited to 'usr.bin/tcfs/tcfsrmgroup.c')
-rw-r--r--usr.bin/tcfs/tcfsrmgroup.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/usr.bin/tcfs/tcfsrmgroup.c b/usr.bin/tcfs/tcfsrmgroup.c
new file mode 100644
index 00000000000..a41b983d183
--- /dev/null
+++ b/usr.bin/tcfs/tcfsrmgroup.c
@@ -0,0 +1,97 @@
+/*
+ * Transparent Cryptographic File System (TCFS) for NetBSD
+ * Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
+ *
+ * references: http://tcfs.dia.unisa.it
+ * tcfs-bsd@tcfs.unisa.it
+ */
+
+/*
+ * Base utility set v0.1
+ */
+
+#include <stdio.h>
+#include <grp.h>
+
+#include <miscfs/tcfs/tcfs.h>
+#include "tcfslib.h"
+#include "tcfserrors.h"
+
+char *rmgroup_usage="Usage: %s [OPTION]...
+Remove a TCFS group from the TCFS group database.
+
+ -g <group> Specifies the TCFS group to be removed
+ -h Shows this help
+ -v Makes the output a little more verbose\n";
+
+int
+rmgroup_main (int argn, char *argv[])
+{
+ int index, val;
+ gid_t gid;
+ int have_gid = FALSE, be_verbose = FALSE;
+
+ /*
+ * Going to check the arguments
+ */
+ while ((val = getopt(argn, argv, "hg:v")) != EOF)
+ switch (val) {
+ case 'g':
+ gid = (gid_t)atoi(optarg);
+ if (!gid && optarg[0] != '0') { /* group name given */
+ struct group *group_id;
+
+ group_id=getgrnam(optarg);
+ if (!group_id)
+ tcfs_error (ER_CUSTOM, "Nonexistent group.");
+ gid=group_id->gr_gid;
+ }
+
+ have_gid=TRUE;
+ break;
+ case 'h':
+ show_usage (rmgroup_usage, argv[0]);
+ exit (OK);
+ case 'v':
+ be_verbose=TRUE;
+ break;
+ default:
+ fprintf (stderr, "Try %s --help for more informations.\n", argv[0]);
+ exit (ER_UNKOPT);
+ }
+
+ if (argn-optind)
+ tcfs_error (ER_UNKOPT, NULL);
+
+ if (!have_gid) {
+ char *buff = NULL;
+ int len;
+
+ buff = (char*)calloc(2048, sizeof(char));
+ if (!buff)
+ tcfs_error (ER_MEM, NULL);
+
+ printf ("Group id of the TCFS group to remove from the database: ");
+ fgets (buff,2048,stdin);
+ len = strlen(buff) - 2;
+ buff[len] = buff[len] == '\n' ? 0 : buff[len];
+ gid=(gid_t)atoi(buff);
+
+ if (!gid && optarg[0] != '0') { /* group name given */
+ struct group *group_id;
+
+ group_id = getgrnam(optarg);
+ if (!group_id)
+ tcfs_error (ER_CUSTOM, "Nonexistent group.");
+ gid=group_id->gr_gid;
+ }
+
+ if (gid <=0 )
+ tcfs_error (ER_CUSTOM, "A positive ID please!");
+
+ free (buff);
+ }
+
+ if (!tcfs_rmgroup (gid))
+ tcfs_error (ER_CUSTOM, "Wrong ID or an error as occurred.\n");
+}