Annotation of src/usr.bin/tcfs/tcfsadduser.c, Revision 1.8
1.8 ! aaron 1: /* $OpenBSD: tcfsadduser.c,v 1.7 2000/06/20 08:59:53 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
1.4 aaron 34: adduser_main(int argn, char *argv[])
1.1 provos 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: */
1.8 ! aaron 44: while ((val = getopt(argn, argv, "g:l:hv")) != -1)
1.1 provos 45: switch (val) {
46: case 'l':
1.4 aaron 47: strlcpy(user, optarg, sizeof(user));
1.1 provos 48: have_user = 1;
49: break;
50: case 'h':
1.6 fgsch 51: printf(adduser_usage, argv[0]);
1.4 aaron 52: exit(OK);
1.1 provos 53: break;
54: case 'v':
55: be_verbose = TRUE;
56: break;
57: default:
1.4 aaron 58: fprintf(stderr,
1.1 provos 59: "Try %s --help for more information.\n",
60: argv[0]);
1.4 aaron 61: exit(ER_UNKOPT);
1.1 provos 62: break;
63: }
64:
1.4 aaron 65: if (argn - optind)
66: tcfs_error(ER_UNKOPT, NULL);
1.1 provos 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) {
1.4 aaron 74: printf("Username to add to TCFS database: ");
75: fgets(user, sizeof(user), stdin);
76: user[strlen(user) - 1] = '\0';
1.1 provos 77: }
78:
79: if (be_verbose)
1.4 aaron 80: printf("Creating a new entry for user %s in the TCFS database...\n", user);
1.1 provos 81:
82: /*
83: * Creating a new entry into the key database
84: */
1.4 aaron 85: if (!tcfspwdbr_new(&user_info))
86: tcfs_error(ER_MEM, NULL);
1.1 provos 87:
1.4 aaron 88: if (!tcfspwdbr_edit(&user_info, F_USR, user))
89: tcfs_error(ER_MEM, NULL);
1.1 provos 90:
1.4 aaron 91: if (!tcfs_putpwnam(user, user_info, U_NEW))
92: tcfs_error(ER_CUSTOM, "Error: cannot add user.");
1.1 provos 93:
94: if (be_verbose)
1.4 aaron 95: printf("User entry created with success.\n");
1.1 provos 96:
1.4 aaron 97: tcfs_error(OK, NULL);
1.7 fgsch 98:
99: exit(0);
1.1 provos 100: }