GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_mkfs.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 0 61 0.0%
Branches: 0 307 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "cvmfs_config.h"
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 std::string fqrn = options.plain_args()[0].value_str;
26 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, "Owner of %s [%s]: ",
35 fqrn.c_str(), user_name.c_str());
36 std::string input;
37 int c;
38 while ((c = getchar()) != EOF) {
39 if (c == '\n') break;
40 input.push_back(c);
41 }
42 if (!input.empty()) user_name = input;
43 }
44 settings.SetOwner(user_name);
45
46 // Sanity checks
47 if (options.Has("no-autotags") && options.Has("autotag-span")) {
48 throw EPublish(
49 "options 'no-autotags' and 'autotag-span' are mutually exclusive");
50 }
51 if (options.HasNot("no-autotags") && options.HasNot("autotag-span") &&
52 options.Has("gc"))
53 {
54 LogCvmfs(kLogCvmfs, kLogStdout,
55 "Note: Autotagging all revisions impedes garbage collection");
56 }
57
58 // Needs to be done before the storage and its temp dir is configured
59 if (options.Has("no-publisher")) {
60 settings.GetTransaction()->GetSpoolArea()->UseSystemTempDir();
61 settings.GetKeychain()->SetKeychainDir(".");
62 }
63
64 // Storage configuration
65 if (options.Has("storage")) {
66 if (options.Has("s3config")) {
67 throw EPublish(
68 "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 bool configure_apache =
77 (settings.storage().type() == upload::SpoolerDefinition::Local) &&
78 options.HasNot("no-apache");
79
80 // Permission check
81 if (geteuid() != 0) {
82 bool can_unprivileged =
83 options.Has("no-publisher") && !configure_apache &&
84 (user_name == GetUserName());
85 if (!can_unprivileged) throw EPublish("root privileges required");
86 }
87
88 // Stratum 0 URL
89 if (options.Has("stratum0")) {
90 settings.SetUrl(options.GetString("stratum0"));
91 } else {
92 bool need_stratum0 =
93 (settings.storage().type() != upload::SpoolerDefinition::Local) &&
94 options.HasNot("no-publisher");
95 if (need_stratum0) {
96 throw EPublish("repository stratum 0 URL for non-local storage "
97 "(add option -w)");
98 }
99 }
100
101 // Union file system
102 if (options.HasNot("no-publisher")) {
103 if (options.Has("unionfs")) {
104 settings.GetTransaction()->SetUnionFsType(options.GetString("unionfs"));
105 } else {
106 settings.GetTransaction()->DetectUnionFsType();
107 }
108 } else {
109 if (options.Has("unionfs")) {
110 throw EPublish(
111 "options 'no-publisher' and 'unionfs' are mutually exclusive");
112 }
113 }
114
115 if (configure_apache) {
116 // TODO(jblomer): Apache configuration
117 }
118
119 // TODO(jblomer): for local backend we need to create the path as root and
120 // then hand it over
121 UniquePtr<Publisher> publisher(Publisher::Create(settings));
122 // if (options.Has("no-apache"))
123
124 LogCvmfs(kLogCvmfs, kLogStdout, "PUBLIC MASTER KEY:\n%s",
125 publisher->signature_mgr()->GetActivePubkeys().c_str());
126 LogCvmfs(kLogCvmfs, kLogStdout, "CERTIFICATE:\n%s",
127 publisher->signature_mgr()->GetCertificate().c_str());
128
129 LogCvmfs(kLogCvmfs, kLogStdout, "MANIFEST:\n%s",
130 publisher->manifest()->ExportString().c_str());
131
132 return 0;
133 }
134
135 } // namespace publish
136