~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/daemon/main.c

  • Committer: Dustin Kirkland
  • Date: 2009-02-13 15:57:24 UTC
  • Revision ID: kirkland@canonical.com-20090213155724-1q3qz2o0cbyimu9x
debian/ubuntu packaging

Initial checkin of the Debian/Ubuntu packaging

Signed-off-by: Dustin Kirkland <kirkland@canonical.com>

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"
38
39
#include "../include/ecryptfs.h"
39
40
 
40
41
static char *pidfile = NULL;
209
210
                exit(1);
210
211
        }
211
212
        for (fd=0; fd < 3; fd++) {
212
 
                if (dup2(null, fd) == -1) {
 
213
                if (dup2(null, 0) == -1) {
213
214
                        syslog(LOG_ERR, "Failed to dup null: %m\n");
214
215
                        exit(1);
215
216
                }
267
268
                 required_argument, NULL, 'R'},
268
269
                {"version\0\t\t\tShow version information", no_argument, NULL,
269
270
                 'V'},
 
271
                {"channel\0\tCommunications channel (netlink or miscdev)",
 
272
                  required_argument, NULL, 'd'},
270
273
                {"help\0\t\t\tShow usage information", no_argument, NULL, 'h'},
271
274
                {NULL, 0, NULL, 0}
272
275
        };
273
 
        static char *short_options = "p:fC:R:Vh";
 
276
        static char *short_options = "p:fC:R:Vd:h";
274
277
        int long_options_ret;
275
278
        struct rlimit core = {0, 0};
276
279
        int foreground = 0;
277
280
        char *chrootdir = NULL;
278
281
        char *tty = NULL;
279
 
        uint32_t version;
 
282
        uint32_t channel_type = ECRYPTFS_DEFAULT_MESSAGING_TYPE;
 
283
        int messaging_type_specified = 0;
280
284
        int rc = 0;
281
285
        
282
286
        while ((long_options_ret = getopt_long(argc, argv, short_options,
310
314
                               PACKAGE_VERSION);
311
315
                        exit(0);
312
316
                        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;
313
324
                case 'h':
314
325
                default:
315
326
                        usage(basename(argv[0]), long_options,
318
329
                        break;
319
330
                }
320
331
        }
321
 
        rc = ecryptfs_get_version(&version);
322
 
        if (!rc && !(version & ECRYPTFS_VERSIONING_MISCDEV)) {
323
 
                rc = -EPROTONOSUPPORT;
324
 
                syslog(LOG_ERR, "%s: Current kernel does not have support for "
325
 
                       "/dev/ecryptfs; please use 2.6.26 or newer\n", __func__);
326
 
                exit(rc);
327
 
        }
328
332
        openlog(argv[0], LOG_PID | (foreground ? LOG_PERROR : 0), 0);
329
 
        if (rc) {
330
 
                syslog(LOG_WARNING, "%s: Unable to retrieve versioning "
331
 
                       "info from kernel module; assuming /dev/ecryptfs is "
332
 
                       "available\n " , __FUNCTION__);
 
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
                }
333
347
        }
334
348
        tty = ttyname(0); /* We may need the tty name later */
335
349
        if (tty != NULL)
377
391
        cryptfs_get_ctx_opts()->prompt = prompt_callback;
378
392
        pthread_mutex_init(&mctx_mux, NULL);
379
393
        pthread_mutex_lock(&mctx_mux);
380
 
        rc = ecryptfs_init_messaging(&mctx, ECRYPTFS_MESSAGING_TYPE_MISCDEV);
 
394
        rc = ecryptfs_init_messaging(&mctx, channel_type);
381
395
        if (rc) {
382
396
                syslog(LOG_ERR, "%s: Failed to initialize messaging; rc = "
383
397
                       "[%d]\n", __FUNCTION__, rc);
387
401
        rc = ecryptfs_send_message(&mctx, NULL, ECRYPTFS_MSG_HELO, 0, 0);
388
402
        if (rc) {
389
403
                syslog(LOG_ERR, "%s: Error attempting to send message to "
390
 
                       "eCryptfs kernel module via /dev/ecryptfs; rc = [%d]\n",
391
 
                       __func__, rc);
 
404
                       "eCryptfs kernel module via transport of type "
 
405
                       "[0x%.8x]; rc = [%d]\n", __FUNCTION__, mctx.type, rc);
392
406
                pthread_mutex_unlock(&mctx_mux);
393
407
                goto daemon_out;
394
408
        }