~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/daemon/main.c

  • Committer: Dustin Kirkland
  • Date: 2016-02-27 00:00:23 UTC
  • Revision ID: kirkland@ubuntu.com-20160227000023-h0e4oui5y1vbaurd
openingĀ 112

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <sys/stat.h>
36
36
#include <sys/wait.h>
37
37
#include <sys/resource.h>
38
 
#include "config.h"
39
38
#include "../include/ecryptfs.h"
40
39
 
41
40
static char *pidfile = NULL;
57
56
                memset (input, 0, input_size);
58
57
        }
59
58
 
60
 
        if (prompt_prog == NULL) {
 
59
        /*
 
60
         * Make sure enough buffer size for at least 1 char and EOS
 
61
         */
 
62
        if ((input_size < 2) || (prompt_prog == NULL)) {
61
63
                rc = -EINVAL;
62
64
                goto out;
63
65
        }
119
121
        }
120
122
        
121
123
        if (!strcmp (prompt_type, "password")) {
122
 
                if ((r = read (fds[0], input, input_size)) == -1) {
 
124
                if ((r = read (fds[0], input, input_size - 1)) == -1) {
123
125
                        rc = -errno;
124
126
                        goto out;
125
127
                }
210
212
                exit(1);
211
213
        }
212
214
        for (fd=0; fd < 3; fd++) {
213
 
                if (dup2(null, 0) == -1) {
 
215
                if (dup2(null, fd) == -1) {
214
216
                        syslog(LOG_ERR, "Failed to dup null: %m\n");
215
217
                        exit(1);
216
218
                }
268
270
                 required_argument, NULL, 'R'},
269
271
                {"version\0\t\t\tShow version information", no_argument, NULL,
270
272
                 'V'},
271
 
                {"channel\0\tCommunications channel (netlink or miscdev)",
272
 
                  required_argument, NULL, 'd'},
273
273
                {"help\0\t\t\tShow usage information", no_argument, NULL, 'h'},
274
274
                {NULL, 0, NULL, 0}
275
275
        };
276
 
        static char *short_options = "p:fC:R:Vd:h";
 
276
        static char *short_options = "p:fC:R:Vh";
277
277
        int long_options_ret;
278
278
        struct rlimit core = {0, 0};
279
279
        int foreground = 0;
280
280
        char *chrootdir = NULL;
281
281
        char *tty = NULL;
282
 
        uint32_t channel_type = ECRYPTFS_DEFAULT_MESSAGING_TYPE;
283
 
        int messaging_type_specified = 0;
 
282
        uint32_t version;
284
283
        int rc = 0;
285
284
        
286
285
        while ((long_options_ret = getopt_long(argc, argv, short_options,
314
313
                               PACKAGE_VERSION);
315
314
                        exit(0);
316
315
                        break;
317
 
                case 'd':
318
 
                        messaging_type_specified = 1;
319
 
                        if (strcmp(optarg, "netlink") == 0)
320
 
                                channel_type = ECRYPTFS_MESSAGING_TYPE_NETLINK;
321
 
                        else if (strcmp(optarg, "miscdev") == 0)
322
 
                                channel_type = ECRYPTFS_MESSAGING_TYPE_MISCDEV;
323
 
                        break;
324
316
                case 'h':
325
317
                default:
326
318
                        usage(basename(argv[0]), long_options,
329
321
                        break;
330
322
                }
331
323
        }
 
324
        rc = ecryptfs_get_version(&version);
 
325
        if (!rc && !(version & ECRYPTFS_VERSIONING_MISCDEV)) {
 
326
                rc = -EPROTONOSUPPORT;
 
327
                syslog(LOG_ERR, "%s: Current kernel does not have support for "
 
328
                       "/dev/ecryptfs; please use 2.6.26 or newer\n", __func__);
 
329
                exit(rc);
 
330
        }
332
331
        openlog(argv[0], LOG_PID | (foreground ? LOG_PERROR : 0), 0);
333
 
        if (!messaging_type_specified) {
334
 
                uint32_t version;
335
 
 
336
 
                rc = ecryptfs_get_version(&version);
337
 
                if (rc) {
338
 
                        syslog(LOG_WARNING, "%s: Unable to retrieve versioning "
339
 
                               "info from kernel module; falling back on "
340
 
                               "default values\n", __FUNCTION__);
341
 
                } else {
342
 
                        if (version & ECRYPTFS_VERSIONING_MISCDEV)
343
 
                                channel_type = ECRYPTFS_MESSAGING_TYPE_MISCDEV;
344
 
                        else
345
 
                                channel_type = ECRYPTFS_MESSAGING_TYPE_NETLINK;
346
 
                }
 
332
        if (rc) {
 
333
                syslog(LOG_WARNING, "%s: Unable to retrieve versioning "
 
334
                       "info from kernel module; assuming /dev/ecryptfs is "
 
335
                       "available\n " , __FUNCTION__);
347
336
        }
348
337
        tty = ttyname(0); /* We may need the tty name later */
349
338
        if (tty != NULL)
391
380
        cryptfs_get_ctx_opts()->prompt = prompt_callback;
392
381
        pthread_mutex_init(&mctx_mux, NULL);
393
382
        pthread_mutex_lock(&mctx_mux);
394
 
        rc = ecryptfs_init_messaging(&mctx, channel_type);
 
383
        rc = ecryptfs_init_messaging(&mctx, ECRYPTFS_MESSAGING_TYPE_MISCDEV);
395
384
        if (rc) {
396
385
                syslog(LOG_ERR, "%s: Failed to initialize messaging; rc = "
397
386
                       "[%d]\n", __FUNCTION__, rc);
401
390
        rc = ecryptfs_send_message(&mctx, NULL, ECRYPTFS_MSG_HELO, 0, 0);
402
391
        if (rc) {
403
392
                syslog(LOG_ERR, "%s: Error attempting to send message to "
404
 
                       "eCryptfs kernel module via transport of type "
405
 
                       "[0x%.8x]; rc = [%d]\n", __FUNCTION__, mctx.type, rc);
 
393
                       "eCryptfs kernel module via /dev/ecryptfs; rc = [%d]\n",
 
394
                       __func__, rc);
406
395
                pthread_mutex_unlock(&mctx_mux);
407
396
                goto daemon_out;
408
397
        }