-
Notifications
You must be signed in to change notification settings - Fork 13
Upstream changes to prepare for the nario command #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
745f53f
5fd0606
56278bc
2e99f17
e3be76d
0faae43
359c0f3
a674293
d57e9f9
f857119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -546,47 +546,22 @@ static void performOp( | |||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case WorkerProto::Op::ExportPath: { | ||||||||||||||||||||||||||||||||||||
| auto path = store->parseStorePath(readString(conn.from)); | ||||||||||||||||||||||||||||||||||||
| readInt(conn.from); // obsolete | ||||||||||||||||||||||||||||||||||||
| logger->startWork(); | ||||||||||||||||||||||||||||||||||||
| TunnelSink sink(conn.to); | ||||||||||||||||||||||||||||||||||||
| store->exportPath(path, sink); | ||||||||||||||||||||||||||||||||||||
| logger->stopWork(); | ||||||||||||||||||||||||||||||||||||
| conn.to << 1; | ||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case WorkerProto::Op::ImportPaths: { | ||||||||||||||||||||||||||||||||||||
| logger->startWork(); | ||||||||||||||||||||||||||||||||||||
| TunnelSource source(conn.from, conn.to); | ||||||||||||||||||||||||||||||||||||
| auto paths = store->importPaths(source, trusted ? NoCheckSigs : CheckSigs); | ||||||||||||||||||||||||||||||||||||
| logger->stopWork(); | ||||||||||||||||||||||||||||||||||||
| Strings paths2; | ||||||||||||||||||||||||||||||||||||
| for (auto & i : paths) | ||||||||||||||||||||||||||||||||||||
| paths2.push_back(store->printStorePath(i)); | ||||||||||||||||||||||||||||||||||||
| conn.to << paths2; | ||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| case WorkerProto::Op::BuildPaths: { | ||||||||||||||||||||||||||||||||||||
| auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); | ||||||||||||||||||||||||||||||||||||
| BuildMode mode = bmNormal; | ||||||||||||||||||||||||||||||||||||
| if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 15) { | ||||||||||||||||||||||||||||||||||||
| mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /* Repairing is not atomic, so disallowed for "untrusted" | ||||||||||||||||||||||||||||||||||||
| clients. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| FIXME: layer violation in this message: the daemon code (i.e. | ||||||||||||||||||||||||||||||||||||
| this file) knows whether a client/connection is trusted, but it | ||||||||||||||||||||||||||||||||||||
| does not how how the client was authenticated. The mechanism | ||||||||||||||||||||||||||||||||||||
| need not be getting the UID of the other end of a Unix Domain | ||||||||||||||||||||||||||||||||||||
| Socket. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| if (mode == bmRepair && !trusted) | ||||||||||||||||||||||||||||||||||||
| throw Error("repairing is not allowed because you are not in 'trusted-users'"); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| mode = WorkerProto::Serialise<BuildMode>::read(*store, rconn); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /* Repairing is not atomic, so disallowed for "untrusted" | ||||||||||||||||||||||||||||||||||||
| clients. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| FIXME: layer violation in this message: the daemon code (i.e. | ||||||||||||||||||||||||||||||||||||
| this file) knows whether a client/connection is trusted, but it | ||||||||||||||||||||||||||||||||||||
| does not how how the client was authenticated. The mechanism | ||||||||||||||||||||||||||||||||||||
| need not be getting the UID of the other end of a Unix Domain | ||||||||||||||||||||||||||||||||||||
| Socket. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| if (mode == bmRepair && !trusted) | ||||||||||||||||||||||||||||||||||||
| throw Error("repairing is not allowed because you are not in 'trusted-users'"); | ||||||||||||||||||||||||||||||||||||
| logger->startWork(); | ||||||||||||||||||||||||||||||||||||
| store->buildPaths(drvs, mode); | ||||||||||||||||||||||||||||||||||||
| logger->stopWork(); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -806,13 +781,11 @@ static void performOp( | |||||||||||||||||||||||||||||||||||
| clientSettings.buildCores = readInt(conn.from); | ||||||||||||||||||||||||||||||||||||
| clientSettings.useSubstitutes = readInt(conn.from); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 12) { | ||||||||||||||||||||||||||||||||||||
| unsigned int n = readInt(conn.from); | ||||||||||||||||||||||||||||||||||||
| for (unsigned int i = 0; i < n; i++) { | ||||||||||||||||||||||||||||||||||||
| auto name = readString(conn.from); | ||||||||||||||||||||||||||||||||||||
| auto value = readString(conn.from); | ||||||||||||||||||||||||||||||||||||
| clientSettings.overrides.emplace(name, value); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| unsigned int n = readInt(conn.from); | ||||||||||||||||||||||||||||||||||||
| for (unsigned int i = 0; i < n; i++) { | ||||||||||||||||||||||||||||||||||||
| auto name = readString(conn.from); | ||||||||||||||||||||||||||||||||||||
| auto value = readString(conn.from); | ||||||||||||||||||||||||||||||||||||
| clientSettings.overrides.emplace(name, value); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+784
to
789
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate override count to prevent DoS
Apply: - unsigned int n = readInt(conn.from);
- for (unsigned int i = 0; i < n; i++) {
+ int n = readInt(conn.from);
+ if (n < 0) throw Error("invalid overrides count");
+ constexpr int kMaxOverrides = 4096;
+ if (n > kMaxOverrides)
+ throw Error("too many overrides in SetOptions (max: %d)", kMaxOverrides);
+ for (int i = 0; i < n; i++) {
auto name = readString(conn.from);
auto value = readString(conn.from);
clientSettings.overrides.emplace(name, value);
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| logger->startWork(); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -877,19 +850,12 @@ static void performOp( | |||||||||||||||||||||||||||||||||||
| auto path = store->parseStorePath(readString(conn.from)); | ||||||||||||||||||||||||||||||||||||
| std::shared_ptr<const ValidPathInfo> info; | ||||||||||||||||||||||||||||||||||||
| logger->startWork(); | ||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
| info = store->queryPathInfo(path); | ||||||||||||||||||||||||||||||||||||
| } catch (InvalidPath &) { | ||||||||||||||||||||||||||||||||||||
| if (GET_PROTOCOL_MINOR(conn.protoVersion) < 17) | ||||||||||||||||||||||||||||||||||||
| throw; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| info = store->queryPathInfo(path); | ||||||||||||||||||||||||||||||||||||
| logger->stopWork(); | ||||||||||||||||||||||||||||||||||||
| if (info) { | ||||||||||||||||||||||||||||||||||||
| if (GET_PROTOCOL_MINOR(conn.protoVersion) >= 17) | ||||||||||||||||||||||||||||||||||||
| conn.to << 1; | ||||||||||||||||||||||||||||||||||||
| conn.to << 1; | ||||||||||||||||||||||||||||||||||||
| WorkerProto::write(*store, wconn, static_cast<const UnkeyedValidPathInfo &>(*info)); | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| assert(GET_PROTOCOL_MINOR(conn.protoVersion) >= 17); | ||||||||||||||||||||||||||||||||||||
| conn.to << 0; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1064,7 +1030,7 @@ void processConnection(ref<Store> store, FdSource && from, FdSink && to, Trusted | |||||||||||||||||||||||||||||||||||
| auto [protoVersion, features] = | ||||||||||||||||||||||||||||||||||||
| WorkerProto::BasicServerConnection::handshake(to, from, PROTOCOL_VERSION, WorkerProto::allFeatures); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (protoVersion < 0x10a) | ||||||||||||||||||||||||||||||||||||
| if (protoVersion < MINIMUM_PROTOCOL_VERSION) | ||||||||||||||||||||||||||||||||||||
| throw Error("the Nix client version is too old"); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| WorkerProto::BasicServerConnection conn; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "nix/store/store-api.hh" | ||
|
|
||
| namespace nix { | ||
|
|
||
| /** | ||
| * Magic header of exportPath() output (obsolete). | ||
| */ | ||
| const uint32_t exportMagic = 0x4558494e; | ||
|
|
||
| /** | ||
| * Export multiple paths in the format expected by `nix-store | ||
| * --import`. The paths will be sorted topologically. | ||
| */ | ||
| void exportPaths(Store & store, const StorePathSet & paths, Sink & sink); | ||
|
|
||
| /** | ||
| * Import a sequence of NAR dumps created by `exportPaths()` into the | ||
| * Nix store. | ||
| */ | ||
| StorePaths importPaths(Store & store, Source & source, CheckSigsFlag checkSigs = CheckSigs); | ||
|
|
||
| } // namespace nix |
Uh oh!
There was an error while loading. Please reload this page.