~ubuntu-branches/debian/lenny/ecryptfs-utils/lenny

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs_unwrap_passphrase.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-24 06:42:00 UTC
  • mfrom: (1.1.11 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20081024064200-oh6xmd4e4ogs7m2l
Tags: 63-1
MergingĀ upstreamĀ versionĀ 63.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
 * Copyright (C) 2007 International Business Machines
3
3
 * Author(s): Michael Halcrow <mhalcrow@us.ibm.com>
 
4
 *            Dustin Kirkland <kirkland@canonical.com>
4
5
 *
5
6
 * This program is free software; you can redistribute it and/or
6
7
 * modify it under the terms of the GNU General Public License as
20
21
 
21
22
#include <stdio.h>
22
23
#include <ecryptfs.h>
 
24
#include <string.h>
23
25
#include "config.h"
24
26
 
25
27
void usage(void)
26
28
{
27
29
        printf("Usage:\n"
28
30
               "\n"
29
 
               "ecryptfs_unwrap_passphrase [file] [wrapping passphrase]\n"
 
31
               "ecryptfs-unwrap-passphrase [file] [wrapping passphrase]\n"
 
32
               "or\n"
 
33
               "printf \"wrapping passphrase\" | "
 
34
               "ecryptfs-unwrap-passphrase [file] -\n"
30
35
               "\n");
31
36
}
32
37
 
38
43
        char salt[ECRYPTFS_SALT_SIZE];
39
44
        char salt_hex[ECRYPTFS_SALT_SIZE_HEX];
40
45
        int rc = 0;
 
46
        char *p;
41
47
 
42
48
        if (argc != 3) {
43
49
                usage();
44
50
                goto out;
45
51
        }
 
52
        if (strlen(argv[2]) == 1 && strncmp(argv[2], "-", 1) == 0) {
 
53
                if ((wrapping_passphrase =
 
54
                    (char *)malloc(ECRYPTFS_MAX_PASSWORD_LENGTH+1)) == NULL) {
 
55
                        perror("malloc");
 
56
                        goto out;
 
57
                }
 
58
                if (fgets(wrapping_passphrase,
 
59
                          ECRYPTFS_MAX_PASSWORD_LENGTH, stdin) == NULL) {
 
60
                        usage();
 
61
                        goto out;
 
62
                }
 
63
                p = strrchr(wrapping_passphrase, '\n');
 
64
                if (p) *p = '\0';
 
65
        } else {
 
66
                wrapping_passphrase = argv[2];
 
67
        }
 
68
 
46
69
        file = argv[1];
47
 
        wrapping_passphrase = argv[2];
48
70
        rc = ecryptfs_read_salt_hex_from_rc(salt_hex);
49
71
        if (rc) {
50
 
                printf("Unable to read salt value from user's "
51
 
                       ".ecryptfsrc file; using default\n");
 
72
                fprintf(stderr, "%s\n", ECRYPTFS_WARN_DEFAULT_SALT);
52
73
                from_hex(salt, ECRYPTFS_DEFAULT_SALT_HEX, ECRYPTFS_SALT_SIZE);
53
74
        } else
54
75
                from_hex(salt, salt_hex, ECRYPTFS_SALT_SIZE);
55
76
        if ((rc = ecryptfs_unwrap_passphrase(passphrase, file,
56
77
                                             wrapping_passphrase, salt))) {
57
 
                printf("Error attempting to unwrap passphrase; rc = [%d]. "
58
 
                       "Check the system log for more information from "
59
 
                       "libecryptfs.\n", rc);
 
78
                fprintf(stderr, "%s [%d]\n", ECRYPTFS_ERROR_UNWRAP, rc);
 
79
                fprintf(stderr, "%s\n", ECRYPTFS_INFO_CHECK_LOG);
60
80
                rc = 1;
61
81
                goto out;
62
82
        }