[BACK]Return to tcfsadduser.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/tcfsadduser.c, Revision 1.2

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