~ubuntu-branches/ubuntu/karmic/cryptsetup/karmic-updates

« back to all changes in this revision

Viewing changes to luks/keyencryption.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2009-05-10 17:29:32 UTC
  • mfrom: (0.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090510172932-1e485f99qk3psrg0
Tags: 2:1.0.6+20090405.svn49-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Ubuntu specific:
    + debian/rules: link dynamically for better security supportability and
      smaller packages.
    + debian/control: Depend on initramfs-tools so system is not potentially
      rendered unbootable.
  - debian/initramfs/cryptroot-script wait for encrypted device to appear,
    report with log_*_msg (debian bug 488271).
  - debian/initramfs/cryptroot-hook: fix support for UUID and LABEL
    correlation between fstab and crypttab (debian bug 522041).
  - debian/askpass.c, debian/initramfs/cryptroot-script: using newline
    escape in passphrase prompt to avoid line-wrapping (debian bug 528133).
* Drop 04_fix_udevsettle_call.patch: fixed upstream differently.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        return div_round_up(x, m) * m;
46
46
}
47
47
 
 
48
static struct setup_backend *cleaner_backend=NULL;
 
49
static const char *cleaner_name=NULL;
 
50
static uint64_t cleaner_size = 0;
 
51
static int devfd=-1;
 
52
 
48
53
static int setup_mapping(const char *cipher, const char *name, 
49
54
                         const char *device, unsigned int payloadOffset,
50
55
                         const char *key, size_t keyLength, 
52
57
                         struct setup_backend *backend,
53
58
                         int mode)
54
59
{
55
 
        struct crypt_options k;
 
60
        struct crypt_options k = {0};
56
61
        struct crypt_options *options = &k;
57
62
        int device_sector_size = sector_size_for_device(device);
58
63
        int r;
66
71
                return -EINVAL;
67
72
        }
68
73
        options->size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
 
74
        cleaner_size = options->size;
69
75
 
70
76
        options->offset = sector;
71
77
        options->cipher = cipher;
87
93
        return r;
88
94
}
89
95
 
90
 
static int clear_mapping(const char *name, struct setup_backend *backend)
 
96
static int clear_mapping(const char *name, uint64_t size, struct setup_backend *backend)
91
97
{
92
 
        struct crypt_options options;
 
98
        struct crypt_options options = {0};
93
99
        options.name=name;
94
 
        return backend->remove(&options);
 
100
        options.size = size;
 
101
        return backend->remove(1, &options);
95
102
}
96
103
 
97
 
/* I miss closures in C! */
98
 
static struct setup_backend *cleaner_backend=NULL;
99
 
static const char *cleaner_name=NULL; 
100
 
static int devfd=0;
101
 
 
102
104
static void sigint_handler(int sig)
103
105
{
104
 
        if(devfd)
 
106
        if(devfd >= 0)
105
107
                close(devfd);
 
108
        devfd = -1;
106
109
        if(cleaner_backend && cleaner_name) 
107
 
                clear_mapping(cleaner_name, cleaner_backend);
 
110
                clear_mapping(cleaner_name, cleaner_size, cleaner_backend);
108
111
        signal(SIGINT, SIG_DFL);
109
112
        kill(getpid(), SIGINT);
110
113
}
160
163
        r = 0;
161
164
 out3:
162
165
        close(devfd);
163
 
        devfd = 0;
 
166
        devfd = -1;
164
167
 out2:
165
 
        clear_mapping(name,backend);
 
168
        clear_mapping(cleaner_name, cleaner_size, cleaner_backend);
166
169
 out1:
167
170
        signal(SIGINT, SIG_DFL);
168
171
        cleaner_name = NULL;
169
172
        cleaner_backend = NULL;
 
173
        cleaner_size = 0;
170
174
        free(dmCipherSpec);
171
175
        free(fullpath); 
172
176
        free(name);