| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
|
| 6 |
|
|
#include "cmd_mkfs.h" |
| 7 |
|
|
|
| 8 |
|
|
#include <unistd.h> |
| 9 |
|
|
|
| 10 |
|
|
#include <string> |
| 11 |
|
|
|
| 12 |
|
|
#include "crypto/signature.h" |
| 13 |
|
|
#include "manifest.h" |
| 14 |
|
|
#include "publish/except.h" |
| 15 |
|
|
#include "publish/repository.h" |
| 16 |
|
|
#include "publish/settings.h" |
| 17 |
|
|
#include "sanitizer.h" |
| 18 |
|
|
#include "upload_spooler_definition.h" |
| 19 |
|
|
#include "util/pointer.h" |
| 20 |
|
|
#include "util/posix.h" |
| 21 |
|
|
|
| 22 |
|
|
namespace publish { |
| 23 |
|
|
|
| 24 |
|
✗ |
int CmdMkfs::Main(const Options &options) { |
| 25 |
|
✗ |
const std::string fqrn = options.plain_args()[0].value_str; |
| 26 |
|
✗ |
const sanitizer::RepositorySanitizer sanitizer; |
| 27 |
|
✗ |
if (!sanitizer.IsValid(fqrn)) { |
| 28 |
|
✗ |
throw EPublish("malformed repository name: " + fqrn); |
| 29 |
|
|
} |
| 30 |
|
✗ |
SettingsPublisher settings(fqrn); |
| 31 |
|
|
|
| 32 |
|
✗ |
std::string user_name = GetUserName(); |
| 33 |
|
✗ |
if (options.HasNot("owner")) { |
| 34 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, |
| 35 |
|
|
"Owner of %s [%s]: ", fqrn.c_str(), user_name.c_str()); |
| 36 |
|
✗ |
std::string input; |
| 37 |
|
|
int c; |
| 38 |
|
✗ |
while ((c = getchar()) != EOF) { |
| 39 |
|
✗ |
if (c == '\n') |
| 40 |
|
✗ |
break; |
| 41 |
|
✗ |
input.push_back(c); |
| 42 |
|
|
} |
| 43 |
|
✗ |
if (!input.empty()) |
| 44 |
|
✗ |
user_name = input; |
| 45 |
|
|
} |
| 46 |
|
✗ |
settings.SetOwner(user_name); |
| 47 |
|
|
|
| 48 |
|
|
// Sanity checks |
| 49 |
|
✗ |
if (options.Has("no-autotags") && options.Has("autotag-span")) { |
| 50 |
|
✗ |
throw EPublish( |
| 51 |
|
✗ |
"options 'no-autotags' and 'autotag-span' are mutually exclusive"); |
| 52 |
|
|
} |
| 53 |
|
✗ |
if (options.HasNot("no-autotags") && options.HasNot("autotag-span") |
| 54 |
|
✗ |
&& options.Has("gc")) { |
| 55 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, |
| 56 |
|
|
"Note: Autotagging all revisions impedes garbage collection"); |
| 57 |
|
|
} |
| 58 |
|
|
|
| 59 |
|
|
// Needs to be done before the storage and its temp dir is configured |
| 60 |
|
✗ |
if (options.Has("no-publisher")) { |
| 61 |
|
✗ |
settings.GetTransaction()->GetSpoolArea()->UseSystemTempDir(); |
| 62 |
|
✗ |
settings.GetKeychain()->SetKeychainDir("."); |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
// Storage configuration |
| 66 |
|
✗ |
if (options.Has("storage")) { |
| 67 |
|
✗ |
if (options.Has("s3config")) { |
| 68 |
|
✗ |
throw EPublish("options 'storage' and 's3config' are mutually exclusive"); |
| 69 |
|
|
} |
| 70 |
|
✗ |
settings.GetStorage()->SetLocator(options.GetString("storage")); |
| 71 |
|
✗ |
} else if (options.Has("s3config")) { |
| 72 |
|
✗ |
settings.GetStorage()->MakeS3( |
| 73 |
|
✗ |
options.GetString("s3config"), |
| 74 |
|
✗ |
settings.transaction().spool_area().tmp_dir()); |
| 75 |
|
|
} |
| 76 |
|
✗ |
const bool configure_apache = (settings.storage().type() |
| 77 |
|
|
== upload::SpoolerDefinition::Local) |
| 78 |
|
✗ |
&& options.HasNot("no-apache"); |
| 79 |
|
|
|
| 80 |
|
|
// Permission check |
| 81 |
|
✗ |
if (geteuid() != 0) { |
| 82 |
|
✗ |
const bool can_unprivileged = options.Has("no-publisher") |
| 83 |
|
✗ |
&& !configure_apache |
| 84 |
|
✗ |
&& (user_name == GetUserName()); |
| 85 |
|
✗ |
if (!can_unprivileged) |
| 86 |
|
✗ |
throw EPublish("root privileges required"); |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
// Stratum 0 URL |
| 90 |
|
✗ |
if (options.Has("stratum0")) { |
| 91 |
|
✗ |
settings.SetUrl(options.GetString("stratum0")); |
| 92 |
|
|
} else { |
| 93 |
|
✗ |
const bool need_stratum0 = (settings.storage().type() |
| 94 |
|
|
!= upload::SpoolerDefinition::Local) |
| 95 |
|
✗ |
&& options.HasNot("no-publisher"); |
| 96 |
|
✗ |
if (need_stratum0) { |
| 97 |
|
✗ |
throw EPublish("repository stratum 0 URL for non-local storage " |
| 98 |
|
✗ |
"(add option -w)"); |
| 99 |
|
|
} |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
|
|
// Union file system |
| 103 |
|
✗ |
if (options.HasNot("no-publisher")) { |
| 104 |
|
✗ |
if (options.Has("unionfs")) { |
| 105 |
|
✗ |
settings.GetTransaction()->SetUnionFsType(options.GetString("unionfs")); |
| 106 |
|
|
} else { |
| 107 |
|
✗ |
settings.GetTransaction()->DetectUnionFsType(); |
| 108 |
|
|
} |
| 109 |
|
|
} else { |
| 110 |
|
✗ |
if (options.Has("unionfs")) { |
| 111 |
|
✗ |
throw EPublish( |
| 112 |
|
✗ |
"options 'no-publisher' and 'unionfs' are mutually exclusive"); |
| 113 |
|
|
} |
| 114 |
|
|
} |
| 115 |
|
|
|
| 116 |
|
|
if (configure_apache) { |
| 117 |
|
|
// TODO(jblomer): Apache configuration |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
|
|
// TODO(jblomer): for local backend we need to create the path as root and |
| 121 |
|
|
// then hand it over |
| 122 |
|
✗ |
const UniquePtr<Publisher> publisher(Publisher::Create(settings)); |
| 123 |
|
|
// if (options.Has("no-apache")) |
| 124 |
|
|
|
| 125 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, "PUBLIC MASTER KEY:\n%s", |
| 126 |
|
✗ |
publisher->signature_mgr()->GetActivePubkeys().c_str()); |
| 127 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, "CERTIFICATE:\n%s", |
| 128 |
|
✗ |
publisher->signature_mgr()->GetCertificate().c_str()); |
| 129 |
|
|
|
| 130 |
|
✗ |
LogCvmfs(kLogCvmfs, kLogStdout, "MANIFEST:\n%s", |
| 131 |
|
✗ |
publisher->manifest()->ExportString().c_str()); |
| 132 |
|
|
|
| 133 |
|
✗ |
return 0; |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
|
} // namespace publish |
| 137 |
|
|
|