summaryrefslogtreecommitdiff
path: root/usr.bin/tcfs/tcfsadduser.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/tcfsadduser.c
parent47bc7a26b81967e77c0f021899f1544966df67e2 (diff)
Initial import of very much rewritten TCFS userland. This code is still
nasty.
Diffstat (limited to 'usr.bin/tcfs/tcfsadduser.c')
-rw-r--r--usr.bin/tcfs/tcfsadduser.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/usr.bin/tcfs/tcfsadduser.c b/usr.bin/tcfs/tcfsadduser.c
new file mode 100644
index 00000000000..84d0429cda7
--- /dev/null
+++ b/usr.bin/tcfs/tcfsadduser.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <unistd.h>
+#include <limits.h>
+
+#include <miscfs/tcfs/tcfs.h>
+
+#include "tcfslib.h"
+#include "tcfserrors.h"
+
+
+char *adduser_usage="Usage: %s [OPTION]...
+Add an user entry to the TCFS database.
+
+ -l <user> Username to add to the TCFS database
+ -h Shows this help
+ -v Makes the output a little more verbose\n";
+
+int
+adduser_main (int argn, char *argv[])
+{
+ char val;
+ int have_user = FALSE, be_verbose = FALSE;
+ char user[LOGIN_NAME_MAX + 1];
+ tcfspwdb *user_info;
+
+ /*
+ * Going to check the arguments
+ */
+ while ((val = getopt(argn, argv, "g:l:hv"))!=EOF)
+ switch (val) {
+ case 'l':
+ strlcpy (user, optarg, sizeof(user));
+ have_user = 1;
+ break;
+ case 'h':
+ show_usage (adduser_usage, argv[0]);
+ exit (OK);
+ break;
+ case 'v':
+ be_verbose = TRUE;
+ break;
+ default:
+ fprintf (stderr,
+ "Try %s --help for more information.\n",
+ argv[0]);
+ exit (ER_UNKOPT);
+ break;
+ }
+
+ if (argn-optind)
+ tcfs_error (ER_UNKOPT, NULL);
+
+ /*
+ * Here we don't have to drop root privileges because only root
+ * should run us.
+ * However we can do better. Maybe in next versions.
+ */
+ if (!have_user) {
+ printf ("Username to add to TCFS database: ");
+ fgets (user, sizeof(user), stdin);
+ user[strlen(user)-1] = '\0';
+ }
+
+ if (be_verbose)
+ printf ("Creating a new entry for user %s in the TCFS database...\n", user);
+
+ /*
+ * Creating a new entry into the key database
+ */
+ if (!tcfspwdbr_new (&user_info))
+ tcfs_error (ER_MEM, NULL);
+
+ if (!tcfspwdbr_edit (&user_info, F_USR, user))
+ tcfs_error (ER_MEM, NULL);
+
+ if (!tcfs_putpwnam (user, user_info, U_NEW))
+ tcfs_error (ER_CUSTOM, "Error: cannot add user.");
+
+ if (be_verbose)
+ printf ("User entry created with success.\n");
+
+ tcfs_error (OK, NULL);
+}