blob: 0ae9b822bae1fa04e0383cbaa2ac20f48f03d327 [file] [log] [blame]
Will Drewry831b74b2013-01-16 11:03:24 -06001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Will Drewry831b74b2013-01-16 11:03:24 -06005#include <base/command_line.h>
Gwendal Grignoudcdc1a42016-06-30 09:41:01 -07006#include <base/files/file_path.h>
Will Drewry831b74b2013-01-16 11:03:24 -06007#include <base/logging.h>
Alex Vakulenkoe7696532015-10-16 16:27:29 -07008#include <brillo/syslog_logging.h>
Will Drewry831b74b2013-01-16 11:03:24 -06009
Alex Vakulenkob4b694a2014-07-18 17:21:35 -070010#include "cryptohome/lockbox-cache.h"
Alex Vakulenkoa7dfe812014-07-31 09:47:14 -070011#include "cryptohome/platform.h"
Will Drewry831b74b2013-01-16 11:03:24 -060012
13namespace switches {
Tom Hughes6711cdc2020-09-14 08:34:01 -070014static const char* kNvramPath = "nvram";
15static const char* kUnlinkNvram = "unlink-nvram";
16static const char* kLockboxPath = "lockbox";
17static const char* kCachePath = "cache";
Will Drewry831b74b2013-01-16 11:03:24 -060018} // namespace switches
19
Tom Hughes6711cdc2020-09-14 08:34:01 -070020int main(int argc, char** argv) {
Alex Vakulenko274c74a2015-04-02 14:31:10 -070021 base::CommandLine::Init(argc, argv);
Will Drewry831b74b2013-01-16 11:03:24 -060022
Alex Vakulenkoe7696532015-10-16 16:27:29 -070023 brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderr);
Will Drewry831b74b2013-01-16 11:03:24 -060024
25 // Allow the commands to be configurable.
Tom Hughes6711cdc2020-09-14 08:34:01 -070026 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
Mattias Nisslerd4541502018-09-03 16:48:16 +020027 base::FilePath nvram_path(cl->GetSwitchValueASCII(switches::kNvramPath));
28 base::FilePath lockbox_path(cl->GetSwitchValueASCII(switches::kLockboxPath));
29 base::FilePath cache_path(cl->GetSwitchValueASCII(switches::kCachePath));
Will Drewry831b74b2013-01-16 11:03:24 -060030 if (nvram_path.empty() || lockbox_path.empty() || cache_path.empty()) {
31 LOG(ERROR) << "Paths for --cache, --lockbox, and --nvram must be supplied.";
32 return 1;
33 }
34
35 cryptohome::Platform platform;
36 bool ok = CacheLockbox(&platform, nvram_path, lockbox_path, cache_path);
37 if (cl->HasSwitch(switches::kUnlinkNvram))
hschameb398b42020-11-24 12:33:06 +090038 platform.DeleteFile(nvram_path);
Will Drewry831b74b2013-01-16 11:03:24 -060039 if (!ok)
hschameb398b42020-11-24 12:33:06 +090040 platform.DeleteFile(cache_path);
Will Drewry831b74b2013-01-16 11:03:24 -060041 return !ok;
42}