~ubuntu-branches/ubuntu/trusty/libpam-mount/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/mnt_fallback/src/mtcrypt.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Kleineidam
  • Date: 2010-08-10 21:39:59 UTC
  • mfrom: (1.4.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810213959-d3l1pqi1h6vt65aa
Tags: 2.5-1
* New upstream release.
* Fixed debian/watch regex.
* debian/control: use Standards version 3.9.1
* Build libcryptsetup support only on Linux systems
  (Closes: #592492)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include <sys/wait.h>
13
13
#include <assert.h>
14
14
#include <errno.h>
 
15
#include <fcntl.h>
15
16
#include <limits.h>
16
17
#include <signal.h>
17
18
#include <stdbool.h>
346
347
 
347
348
static hxmc_t *mtcr_slurp_file(const char *file)
348
349
{
349
 
        hxmc_t *buf, *ln = NULL;
350
350
        struct stat sb;
351
 
        FILE *fp;
 
351
        char tmp[4096];
 
352
        hxmc_t *buf;
 
353
        int fd;
352
354
 
353
 
        fp = fopen(file, "r");
354
 
        if (fp == NULL) {
 
355
        if ((fd = open(file, O_RDONLY | O_BINARY)) < 0) {
355
356
                fprintf(stderr, "Could not open %s: %s\n",
356
357
                        file, strerror(errno));
357
358
                return NULL;
358
359
        }
359
360
 
360
 
        if (fstat(fileno(fp), &sb) == 0 && S_ISREG(sb.st_mode))
 
361
        if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode))
361
362
                buf = HXmc_meminit(NULL, sb.st_size);
362
363
        else
363
364
                buf = HXmc_meminit(NULL, 4096 / CHAR_BIT);
364
365
 
365
366
        if (buf == NULL) {
366
 
                fprintf(stderr, "%s\n", strerror(errno));
 
367
                fprintf(stderr, "%s: %s\n", __func__, strerror(errno));
367
368
        } else {
368
 
                while (HX_getl(&ln, fp) != NULL)
369
 
                        HXmc_strcat(&buf, ln);
 
369
                ssize_t ret;
 
370
                while ((ret = read(fd, tmp, sizeof(tmp))) > 0)
 
371
                        HXmc_memcat(&buf, tmp, ret);
370
372
        }
371
 
        fclose(fp);
 
373
        close(fd);
372
374
        return buf;
373
375
}
374
376
 
429
431
        if (opt->trunc_keysize != 0)
430
432
                mount_request.trunc_keysize = opt->trunc_keysize;
431
433
 
 
434
        w4rn("keysize=%u trunc_keysize=%u\n", mount_request.key_size,
 
435
             mount_request.trunc_keysize);
432
436
        if ((ret = ehd_load(&mount_request, &mount_info)) < 0) {
433
437
                fprintf(stderr, "ehd_load: %s\n", strerror(errno));
434
438
                return 0;