~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/utils/mount.ecryptfs.c

  • Committer: Michal Hlavinka
  • Date: 2009-02-17 15:16:28 UTC
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: mhlavink@redhat.com-20090217151628-0dsz0zzl8m8tdh73
improve interactive mode of mount.ecryptfs

- make interactive mode working
- echo when entering path to key file or fd
- fix mount option parsing
- fix error for empty passphrase
- fix (some) error codes
- don't error out when user cancels mount

Signed-off-by: Michal Hlavinka <mhlavink@redhat.com> 

-------------- This and the following will be ignored --------------

modified:
  src/key_mod/ecryptfs_key_mod_openssl.c
  src/key_mod/ecryptfs_key_mod_passphrase.c
  src/libecryptfs/cmd_ln_parser.c
  src/libecryptfs/decision_graph.c
  src/libecryptfs/module_mgr.c
  src/utils/mount.ecryptfs.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
                if ((*target)[len - 1] == '/')
101
101
                        (*target)[len - 1] = '\0';
102
102
        }
103
 
        if (options && (argc == NUM_REQUIRED_ARGS)) {
104
 
                fprintf(stderr, "Not enough remaining data for options\n");
105
 
                return -EINVAL;
106
 
        } else if ((options) && (argc > NUM_REQUIRED_ARGS)) {
 
103
        if ((options) && (argc >= NUM_REQUIRED_ARGS)) {
107
104
                int i;
108
105
 
109
106
                ptr = NULL;
116
113
                        fprintf(stderr, "Unable to find a list of options to "
117
114
                                        "parse, defaulting to interactive "
118
115
                                        "mount\n");
119
 
                        rc = -ENOENT;
120
 
                        goto out;
 
116
                        return 0;
121
117
                }
122
118
                len = strlen(ptr) + 1; /* + NULL-terminator */
123
119
                *options = malloc(len);
147
143
        char *end;
148
144
        int num_options = 0;
149
145
 
 
146
        if (!options)
 
147
                return 0;
 
148
 
150
149
        end = strchr(options, '\0');
151
150
        opt = options;
152
151
        while (opt) {
255
254
        size_t len;
256
255
        int used = 0, first = 1;
257
256
 
 
257
        if (!options)
 
258
                return 0;
 
259
 
258
260
        len = (strlen(options) + 1);
259
261
        if ((temp = (char*)malloc(len)) == NULL) {
260
262
                fprintf(stderr, "Out of memory\n");
292
294
static int process_sig(char *auth_tok_sig, struct passwd *pw)
293
295
{
294
296
        char *home;
295
 
        uid_t id;
296
297
        char *sig_cache_filename = NULL;
297
298
        char *dot_ecryptfs_dir;
298
299
        int flags;
362
363
                                       "file; continuing with mount.\n");
363
364
                } else {
364
365
                        printf("Aborting mount.\n");
365
 
                        rc = -EINVAL;
 
366
                        rc = ECANCELED;
366
367
                        goto out;
367
368
                }
368
369
        }
376
377
        char *opt;
377
378
        char *next_opt;
378
379
        char *end;
 
380
 
 
381
        if (!options || !option)
 
382
                return 0;
 
383
 
379
384
        int option_len = strlen(option);
380
385
 
381
386
        end = strchr(options, '\0');
418
423
                if (!opts_str_contains_option(opts, required_mount_opts[i])) {
419
424
                        printf("Required mount option not provided: [%s]\n",
420
425
                               required_mount_opts[i]);
421
 
                        rc = 1;
 
426
                        rc = -EINVAL;
422
427
                        goto out;
423
428
                }
424
429
                i++;
454
459
        if (rc)
455
460
                goto out;
456
461
        num_opts = ecryptfs_generate_mount_flags(opts, &flags);
457
 
        if (asprintf(&new_opts, "%secryptfs_unlink_sigs,", opts) == -1) {
458
 
                new_opts = NULL;
 
462
        if (!(temp = strdup("ecryptfs_unlink_sigs"))) {
459
463
                rc = -ENOMEM;
460
464
                goto out;
461
465
        }
 
466
        if ((rc = stack_push(&mnt_params, (void *)temp)))
 
467
                goto out;
462
468
        printf("Attempting to mount with the following options:\n");
 
469
        new_opts = opts;
 
470
        opts = NULL;
463
471
        while (!stack_pop_val(&mnt_params, (void *)&val)) {
464
472
                if(!val)
465
473
                        break;
467
475
                printf("  %s\n", val);
468
476
                if (sig_cache && memcmp(val, "ecryptfs_sig=", 13) == 0) {
469
477
                        if ((rc = process_sig(&val[13], pw))) {
470
 
                                printf("Error processing sig; rc = [%d]\n", rc);
 
478
                                if (rc != ECANCELED)
 
479
                                        printf("Error processing sig; "
 
480
                                               "rc = [%d]\n", rc);
471
481
                                goto out;
472
482
                        }
473
483
                }
474
 
                if (!strstr(temp, val)) {
475
 
                        rc = asprintf(&new_opts, "%s,%s", val, temp);
 
484
                if (!temp || !strstr(temp, val)) {
 
485
                        rc = asprintf(&new_opts, "%s%c%s", val,
 
486
                                      ((temp && *temp) ? ',' : '\0'), temp);
476
487
                        if (rc == -1) {
477
488
                                new_opts = NULL;
478
489
                                rc = -ENOMEM;
521
532
 
522
533
        rc = mlockall(MCL_FUTURE);
523
534
        if (rc) {
524
 
                fprintf(stderr, "Exiting. Unable to mlockall address space\n");
525
 
                return 0;
 
535
                fprintf(stderr, "Exiting. Unable to mlockall address space: %m\n");
 
536
                return -1;
526
537
        }
527
538
        if (dump_args) {
528
539
                int i;
588
599
                        &ctx, &mnt_params, version, opts_str,
589
600
                        ECRYPTFS_ASK_FOR_ALL_MOUNT_OPTIONS);
590
601
                if (rc) {
591
 
                        printf("Error attempting to evaluate mount options; "
592
 
                               "rc = [%d]. See your system logs for more "
593
 
                               "details on why this happened. Try "
594
 
                               "updating/reinstalling your "
595
 
                               "ecryptfs-utils package, contact your operating "
596
 
                               "system vendor, and/or submit a bug "
597
 
                               "report on the ecryptfs-devel mailing list on "
598
 
                               "Launchpad.\n", rc);
 
602
                        printf("Error attempting to evaluate mount options: "
 
603
                               "[%d] %s\nCheck your system logs for details "
 
604
                               "on why this happened.\nTry updating your "
 
605
                               "ecryptfs-utils package, and/or\nsubmit a bug "
 
606
                               "report on https://launchpad.net/ecryptfs\n",
 
607
                                rc, strerror(-rc));
599
608
                        goto out;
600
609
                }
601
610
                rc = ecryptfs_do_mount(argc, argv, mnt_params, sig_cache, pw);
 
611
                if (rc == ECANCELED) {
 
612
                    rc = 0;
 
613
                    goto out;
 
614
                }
602
615
                if (rc) {
603
616
                        if (rc > 0)
604
617
                                rc = -rc;
605
 
                        printf("Error mounting eCryptfs; rc = [%d]; strerr = "
606
 
                               "[%s]. Check your system logs; visit "
 
618
                        printf("Error mounting eCryptfs: [%d] %s\n"
 
619
                               "Check your system logs; visit "
607
620
                               "<http://launchpad.net/ecryptfs>\n",
608
621
                               rc, strerror(-rc));
609
622
                        if (rc == -ENODEV)