Annotation of src/usr.bin/tcfs/tcfsadduser.c, Revision 1.3
1.3 ! fgsch 1: /* $OpenBSD: tcfsadduser.c,v 1.2 2000/06/19 20:35:47 fgsch Exp $ */
1.2 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 <stdio.h>
16: #include <unistd.h>
17: #include <limits.h>
1.3 ! fgsch 18: #include <string.h>
1.1 provos 19:
20: #include <miscfs/tcfs/tcfs.h>
21:
22: #include "tcfslib.h"
23: #include "tcfserrors.h"
24:
25:
26: char *adduser_usage="Usage: %s [OPTION]...
27: Add an user entry to the TCFS database.
28:
29: -l <user> Username to add to the TCFS database
30: -h Shows this help
31: -v Makes the output a little more verbose\n";
32:
33: int
34: adduser_main (int argn, char *argv[])
35: {
36: char val;
37: int have_user = FALSE, be_verbose = FALSE;
38: char user[LOGIN_NAME_MAX + 1];
39: tcfspwdb *user_info;
40:
41: /*
42: * Going to check the arguments
43: */
44: while ((val = getopt(argn, argv, "g:l:hv"))!=EOF)
45: switch (val) {
46: case 'l':
47: strlcpy (user, optarg, sizeof(user));
48: have_user = 1;
49: break;
50: case 'h':
51: show_usage (adduser_usage, argv[0]);
52: exit (OK);
53: break;
54: case 'v':
55: be_verbose = TRUE;
56: break;
57: default:
58: fprintf (stderr,
59: "Try %s --help for more information.\n",
60: argv[0]);
61: exit (ER_UNKOPT);
62: break;
63: }
64:
65: if (argn-optind)
66: tcfs_error (ER_UNKOPT, NULL);
67:
68: /*
69: * Here we don't have to drop root privileges because only root
70: * should run us.
71: * However we can do better. Maybe in next versions.
72: */
73: if (!have_user) {
74: printf ("Username to add to TCFS database: ");
75: fgets (user, sizeof(user), stdin);
76: user[strlen(user)-1] = '\0';
77: }
78:
79: if (be_verbose)
80: printf ("Creating a new entry for user %s in the TCFS database...\n", user);
81:
82: /*
83: * Creating a new entry into the key database
84: */
85: if (!tcfspwdbr_new (&user_info))
86: tcfs_error (ER_MEM, NULL);
87:
88: if (!tcfspwdbr_edit (&user_info, F_USR, user))
89: tcfs_error (ER_MEM, NULL);
90:
91: if (!tcfs_putpwnam (user, user_info, U_NEW))
92: tcfs_error (ER_CUSTOM, "Error: cannot add user.");
93:
94: if (be_verbose)
95: printf ("User entry created with success.\n");
96:
97: tcfs_error (OK, NULL);
98: }