~ubuntu-branches/ubuntu/vivid/ecryptfs-utils/vivid

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs-stat.c

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2008-08-04 15:58:24 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20080804155824-c3ob82b8h6wpx2x6
Tags: 53-1ubuntu1
 * Merge from debian unstable (LP: #254714, #251245), remaining changes:
  - debian/rules: install ecryptfs auth-client-config profile
  - debian/control: Update maintainer, suggest auth-client-config
  - debian/ecryptfs.acc: define auth-client-config profile
  - debian/ecryptfs-utils.install: install auth-client-config profile
 * Dropped changes:
  - debian/ecryptfs-utils.dirs: handled by install -D rule
 * Additional changes
  - debian/ecryptfs.acc: Add to common-password stack, make all pam_ecryptfs
    entries optional (LP: #253816).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Present statistics on encrypted eCryptfs file attributes
 
3
 */
 
4
 
 
5
#include <stdio.h>
 
6
#include <fcntl.h>
 
7
#include <unistd.h>
 
8
#include <errno.h>
 
9
#include <sys/types.h>
 
10
#include <sys/stat.h>
 
11
#include "../include/ecryptfs.h"
 
12
 
 
13
static void usage(const char *filename)
 
14
{
 
15
        printf("Usage:\n\n"
 
16
               "%s <filename>\n", filename);
 
17
}
 
18
 
 
19
int main(int argc, const char *argv[])
 
20
{
 
21
        const char *filename;
 
22
        int fd = -1;
 
23
        ssize_t quant_read;
 
24
        struct ecryptfs_crypt_stat_user crypt_stat;
 
25
        char buf[4096];
 
26
        int rc = 0;
 
27
 
 
28
        if (argc == 1) {
 
29
                usage(argv[0]);
 
30
                goto out;
 
31
        }
 
32
        filename = argv[1];
 
33
        fd = open(filename, O_RDONLY);
 
34
        if (fd == -1) {
 
35
                printf("Error opening file [%s] for RD_ONLY access; errno msg "
 
36
                       "= [%m]\n", filename, errno);
 
37
                rc = -EIO;
 
38
                goto out;
 
39
        }
 
40
        quant_read = read(fd, buf, 4096);
 
41
        if (quant_read == -1) {
 
42
                printf("Error attempting to read from file [%s]; errno msg "
 
43
                       "= [%m]\n", filename, errno);
 
44
                rc = -EIO;
 
45
                goto out;
 
46
        }
 
47
        rc = ecryptfs_parse_stat(&crypt_stat, buf, quant_read);
 
48
        if (rc) {
 
49
                printf("Valid eCryptfs metadata information not found in [%s]"
 
50
                       "\n", filename);
 
51
                rc = 0;
 
52
                goto out;
 
53
        }
 
54
        printf("Decrypted file size: [%llu]\n", crypt_stat.file_size);
 
55
out:
 
56
        if (fd != -1)
 
57
                close(fd);
 
58
        return rc;
 
59
}