~mrooney/ecryptfs/nautilus-integration

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs_add_passphrase.c

  • Committer: mhalcrow@us.ibm.com
  • Date: 2007-11-06 22:56:01 UTC
  • Revision ID: git-v1:f8357de9d554b274497b5cce9db4347254b7e7eb
Initial import of eCryptfs filesystem userspace utilities (mount helper, daemon component,
etc.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (C) 2007 International Business Machines
 
3
 * Author(s): Michael Halcrow <mhalcrow@us.ibm.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
18
 * 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include <ecryptfs.h>
 
24
#include "config.h"
 
25
 
 
26
void usage(void)
 
27
{
 
28
        printf("Usage:\n"
 
29
               "\n"
 
30
               "ecryptfs-add-passphrase [passphrase]\n"
 
31
               "\n");
 
32
}
 
33
 
 
34
int main(int argc, char *argv[])
 
35
{
 
36
        char passphrase[ECRYPTFS_MAX_PASSWORD_LENGTH + 1];
 
37
        char auth_tok_sig_hex[ECRYPTFS_SIG_SIZE_HEX + 1];
 
38
        char salt[ECRYPTFS_SALT_SIZE];
 
39
        char salt_hex[ECRYPTFS_SALT_SIZE_HEX];
 
40
        int rc = 0;
 
41
 
 
42
        if (argc != 2) {
 
43
                usage();
 
44
                goto out;
 
45
        }
 
46
        memcpy(passphrase, argv[1], ECRYPTFS_MAX_PASSWORD_LENGTH);
 
47
        passphrase[ECRYPTFS_MAX_PASSWORD_LENGTH] = '\0';
 
48
        rc = ecryptfs_read_salt_hex_from_rc(salt_hex);
 
49
        if (rc) {
 
50
                printf("Unable to read salt value from user's "
 
51
                       ".ecryptfsrc file; using default\n");
 
52
                from_hex(salt, ECRYPTFS_DEFAULT_SALT_HEX, ECRYPTFS_SALT_SIZE);
 
53
        } else
 
54
                from_hex(salt, salt_hex, ECRYPTFS_SALT_SIZE);
 
55
        if ((rc = ecryptfs_add_passphrase_key_to_keyring(auth_tok_sig_hex,
 
56
                                                         passphrase, salt))) {
 
57
                printf("Error attempting to insert passphrase "
 
58
                       "into the user session keyring; rc = [%d]. "
 
59
                       "Check the system log for more information from "
 
60
                       "libecryptfs.\n", rc);
 
61
                rc = 1;
 
62
                goto out;
 
63
        }
 
64
        auth_tok_sig_hex[ECRYPTFS_SIG_SIZE_HEX] = '\0';
 
65
        printf("Inserted auth tok with sig [%s] into the user session "
 
66
               "keyring\n", auth_tok_sig_hex);
 
67
out:
 
68
        return rc;
 
69
}