summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)AuthorFilesLines
2022-08-06Use enum overload for field settingEd Tanous4-9/+13
There are two overloads of addHeader, one that takes a string, and one that takes a boost enum. For most common headers, boost contains a string table with all of those entries anyway, so there's no point in duplicating the strings, and ensures that we don't make trivial mistakes, like capitalization or - versus underscore that aren't caught at compile time. Tested: This saves a trivial amount (572 bytes) of compressed binary size. curl --insecure -vvv --user root:0penBmc https://192.168.7.2/redfish/v1 returns < Content-Type: application/json curl --insecure -vvv -H "Accept: text/html" --user root:0penBmc https://192.168.7.2/redfish/v1 Returns < Content-Type: text/html;charset=UTF-8 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I34c198b4f9e219247fcfe719f9b3616d35aea3dc
2022-08-04Preserve headers from the root object on expandEd Tanous1-0/+2
There is a bug where, when running an expand query, headers from the response object get dropped. These headers include OData.type, and the newly minted Link header, as well as possible others. This was actually noted in a TODO, although the author of the TODO, didn't fully understand the consequences at the time, and thought there was no functional impact. To resolve this, this commit resolves the TODO, and allows the Response object to be moved out, instead of having to create a new one, which preserves all the response state. To do this, it creates a move constructor on the Response object for this use. The move constructor is relatively benign, with one caveat, that we might be moving while in a completion handler (as is the most common use). So both the existing operator= and Response() move constructor are amended to handle this case, and simply null out the response object in the copied object, which would be correct behavior, given that each callback handler should only be called once per Response object. Tested: curl --insecure --user root:0penBmc -vvvv https://192.168.7.2/redfish/v1\?\$expand\=\*\(\$levels\=2\) returns the same body as previously, now with the included: OData-Version: 4.0 Allow: Get headers in the response. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I221364dd4304903b37cacb1386f621b073a0a891
2022-07-26authn: correct meson behaviorsNan Zhou1-1/+2
Today `basic-auth` (and other options) can be enabled even if `insecure-disable-auth` is enabled, which doesn't make sense. With this block this commit added in meson, If we disable authx with `insecure-disable-auth`, then all these auth options will be ignored. Tested: 1. code compiles with and without 'insecure-disable-auth'. 2. No new service validator errors when 'insecure-disable-auth' is turned on. 3. No new service validator errors when 'insecure-disable-auth' is turned off. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I2c634851f7aa7b9e57158770c5d40c12954c93a7
2022-07-25sdbusplus: use shorter type aliasesPatrick Williams4-35/+30
The sdbusplus headers provide shortened aliases for many types. Switch to using them to provide better code clarity and shorter lines. Possible replacements are for: * bus_t * exception_t * manager_t * match_t * message_t * object_t * slot_t Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: I46a5eec210002af84239af74a93c830b1d4a13f1
2022-07-23test treewide: iwyuNan Zhou9-13/+103
These changes are done by running iwyu manually under clang14. Suppressed some obvious impl or details headers. Kept the recommended public headers. IWYU can increase readability, make maintenance easier, and avoid errors in some cases. See details in https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md. This commit also uses its best effort to correct obvious errors through iwyu pragma. See reference here: https://github.com/include-what-you-use/include-what-you-use#how-to-correct-iwyu-mistakes Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I983b6f75601707cbb0f2f04546c3362ff4ba7fee
2022-07-16Remove usages of boost::starts/ends_withEd Tanous8-32/+28
Per the coding standard, now that C++ supports std::string::starts_with and std::string::ends_with, we should be using them over the boost alternatives. This commit goes through and updates all usages. Arguably some of these are incorrect, and instances of common error 13, but because this is mostly a mechanical it intentionally doesn't try to handle it. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ic4c6e5d0da90f7442693199dc691a47d2240fa4f
2022-07-12Fix const correctness issuesEd Tanous3-6/+6
cppcheck correctly notes that a lot of variables in the new code can be const. Make most of them const. Tested: WIP Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8f37b6353fd707923f533e1d61c5b5419282bf23
2022-07-11Google RoT: simplify subtree iterationNan Zhou1-9/+5
Use structured binding declaration to avoid verbose typing of subtree response. Tested: 1. code compiles 2. tested on hardware and RoT resources worked as expected. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I22758c196a097cce8e94208085fd59ce1363cefc
2022-07-11Google RoT: add unit tests for /google/v1Nan Zhou1-0/+39
Tested: unit test worked. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I4feb6c9cdf52930617a7011732a5837f06c1adda
2022-07-11Google RoT: remove global constant stringsNan Zhou1-13/+13
These variables are replaced by local string literals, which has better readability. Tested: tested on real hardware. GET: /google/v1/RootOfTrustCollection { "@odata.id": "/google/v1/RootOfTrustCollection", "@odata.type": "#RootOfTrustCollection.RootOfTrustCollection", "Members": [ { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth" } ], "Members@odata.count": 1 } GET /google/v1/RootOfTrustCollection/Hoth { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth", "@odata.type": "#RootOfTrust.v1_0_0.RootOfTrust", "Actions": { "#RootOfTrust.SendCommand": { "target": "/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand" } }, "Description": "Google Root Of Trust", "Id": "Hoth", "Location": { "PartLocation": { "LocationType": "Embedded", "ServiceLabel": "Hoth" } }, "Name": "Hoth", "Status": { "State": "Enabled" } } Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I4c21eeb6a521b657bd9a8eb7394e7748d000ad52
2022-07-11Google RoT: allign callback styleNan Zhou1-64/+85
The current convention: 1. route handler should be named as "handleAbcResouceMethod" 2. prefer inline functions instead of local lambdas Tested: 1. compiles 2. on Google hardware, the commands in https://gerrit.openbmc.org/c/openbmc/bmcweb/+/52222/32 worked GET: /google/v1/RootOfTrustCollection { "@odata.id": "/google/v1/RootOfTrustCollection", "@odata.type": "#RootOfTrustCollection.RootOfTrustCollection", "Members": [ { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth" } ], "Members@odata.count": 1 } GET /google/v1/RootOfTrustCollection/Hoth { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth", "@odata.type": "#RootOfTrust.v1_0_0.RootOfTrust", "Actions": { "#RootOfTrust.SendCommand": { "target": "/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand" } }, "Description": "Google Root Of Trust", "Id": "Hoth", "Location": { "PartLocation": { "LocationType": "Embedded", "ServiceLabel": "Hoth" } }, "Name": "Hoth", "Status": { "State": "Enabled" } } Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I0221b4b183579b33d0848d96a20398aee1a211d4
2022-07-07dbus_singleton: use stack variable and externNan Zhou1-1/+5
Currently, the |systemBus| connection is a static variable declared in headers. This has a problem that every translation unit will keep its own copy. It's not a problem today because there's only one translation unit "webserver_main.cpp.o". This issue was brounght up in https://gerrit.openbmc.org/c/openbmc/bmcweb/+/54758 Actually, the |systemBus| doesn't need to be a singleton. It can just be a stack variable, which is normally more efficient than heap variables. To keep minimum changes treeside, this commits keeps the existing |systemBus| variable as an external variable. It is defined in its own translation unit. It is initialized in the main translation unit. Reference: 1. Extern https://stackoverflow.com/questions/1433204/how-do-i-use-extern-to-share-variables-between-source-files Tested: 1. Romulus QEMU robot Redfish test passed; 2. Start and restart service on real hardware, no issues; 3. No new validator failures 4. Code compies Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I03b387bd5f218a86c9d1765415a46e3c2ad83ff9
2022-07-07Google RoT: avoid potential dangling pointerNan Zhou1-1/+1
The struct |ResolvedEntity| stores a pointer which might be dangling in the future when interface is not longer a string literal. Given that the interface string is small enough, this commits changes the data member to a string which is constructed (copied) from the string literal today. Tested: trivial change. Compiles. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I2759635f7fa296cc8aa141735efb3799a1503726
2022-07-07dbus_utility_test: fix test case namesNan Zhou1-6/+8
This commit applies the GTest test case naming convention: Camel case, use decriptive Test names. It also groups test cases according to the name. Reference: https://testing.googleblog.com/2014/10/testing-on-toilet-writing-descriptive.html http://google.github.io/googletest/primer.html#simple-tests Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ibd1bfcb4456b64e43f437cc2afa7464f03ee634c
2022-07-05Remove unused variablesEd Tanous1-1/+0
cppcheck finds a few variables that were unused in a few modules. Clean them up. Tested: Code compiles, unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7a95025891bb537b45b99b3cd649ad05533e78f4
2022-07-01Make nbd-proxy header build in all casesEd Tanous1-3/+3
We very intentionally don't do this "only include header if option is enabled" thing to make sure that compile issues are seen across all builds. Tested: Code compiles. Header changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I749aed62ed6cd73690f3d89d75df65bec77562c2
2022-07-01Remove BLONSEd Tanous1-1412/+0
This file was used in unit tests a while ago. It's not really a good test list, and ideally would be replaced with coverage directed fuzzing if we ever needed something like this in the future. Tested: Delete only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I9a7d3c422226e0366399ab43abd92f762e3e4fc7
2022-06-30Require explicit decorator on one arg constructorsEd Tanous1-2/+2
We essentially follow this rule already, not relying on implicit operators, although there are a number of cases where in theory we could've implicitly constructed an object. This commit enables the clang-tidy check. Tested: Code compiles, passes clang-tidy. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ia428463313b075c69614fdb326e8c5c094e7adde
2022-06-28http_utility_test: fix test case namesNan Zhou1-4/+14
This commit applies the GTest test case naming convention: Camel case, use decriptive Test names. It also groups test cases according to the name. Reference: https://testing.googleblog.com/2014/10/testing-on-toilet-writing-descriptive.html http://google.github.io/googletest/primer.html#simple-tests Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ie008ceac9e027b518e660745722ac5cc0af502da
2022-06-28http_utility_test: add namespaceNan Zhou1-8/+14
To save duplicate codes. Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ibb641942b24a92f61793995337963be80d4a6151
2022-06-28Fix shadowed variable issuesEd Tanous3-13/+13
This patchset is the conclusion of a multi-year effort to try to fix shadowed variable names. Variables seem to be shadowed all over, and in most places they exist, there's a "code smell" of things that aren't doing what the author intended. This commit attempts to clean up these in several ways by: 1. Renaming variables where appropriate. 2. Preferring to refer to member variables directly when operating within a class 3. Rearranging code so that pass through variables are handled in the calling scope, rather than passing them through. These patterns are applied throughout the codebase, to the point where -Wshadow can be enabled in meson.build. Tested: Code compiles, unit tests pass. Still need to run redfish service validator. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: If703398c2282f9e096ca2694fd94515de36a098b
2022-06-28http_utility_test: fix headersNan Zhou1-2/+2
"gmock/gmock.h" should be replaced with "gtest/gtest.h" given that only GTest macors are used. "http_utility.hpp" is a local header and "gtest/gtest.h" is a header in dependencies. The convention is to use <> for dependency headers. Reference: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html Tested: unit test passed Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I42b077090df59ee1c4fbfab3199d2ee9b4b242dc
2022-06-28dbus_utility_test: clean up headersNan Zhou1-5/+4
Removed unused headers and include missing headers. Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ie04af6c00d849f268ededffb3d01bb79f0f895cd
2022-06-28dbus_utility_test: add namespaceNan Zhou1-10/+17
This commit does nothing but add namespace to the test source. It can be shown that it saves a lot of duplicate codes. Tested: unit test compiles and passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I42a70c5c32c32c1cb09f7c3e36d6e5816aa3a53e
2022-06-28human_sort_test: add namespaceNan Zhou1-2/+7
Add an anonymous namespace and use using declarations. Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I2d29aa7ec7923addc41b0af564542932a5abd9b4
2022-06-28human_sort_test: fix headersNan Zhou1-2/+4
IWYU. Use <> for dependency headers and "" for bmcweb headers. Reference: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I6a329c8b04b0eccda7f601128f66770a7f119676
2022-06-27Rearrange forward_unauthorizedEd Tanous1-22/+21
This file is kind of hard to read. Try to improve it. This readability problem caused me to miss one of the cases and invert it, and because there's 6 possible clients/flows that need tested through these, my testing didn't catch it originally. Tested: Redfish protocol validator now passes one more test for www-authenticate. 18 failing test cases down to 12. ''' curl -vvvv --insecure -H "Accepts: application/json" https://192.168.7.2/redfish/v1/SessionService/Sessions ''' Now returns WWW-Authenticate when basic auth is enabled. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Idaed4c1fe3f58667b5478006d3091d820ca26d58
2022-06-25sessions: iwyunitroglycerine1-8/+0
While revisiting change 49039 I saw session.hpp included a few files that are not used. I removed them and the code still compiles. Signed-off-by: Sui Chen <suichen6@gmail.com> Change-Id: I97aa2359053ce6102b84af1ef555d881cd35eaba
2022-06-25multipart_test: use ASSERT_EQ correctlyNan Zhou1-20/+20
It makes sense to use ASSERT_EQ for the |parse| function, but not every attribute for the parsed results. Tested: unit test passes. Reference: https://testing.googleblog.com/2008/07/tott-expect-vs-assert.html Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I27629eb8d721d7e62c82fdb7afbf4698546f0bdb
2022-06-25multipart_test: add namespaceNan Zhou1-1/+6
Added an anonymous namespace. Putting codes in the global namespace is generally not recommended. Reference: https://stackoverflow.com/questions/47861534/why-does-google-test-sample-put-tests-in-an-anonymous-namespace Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ic141a1e71b80a47f9b9c0c5a0a73da68ee7c72d9
2022-06-25multipart_test: fix headersNan Zhou1-3/+7
IWYU. Use <> for dependency headers and "" for bmcweb headers. Reference: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Id759f66b9617e5e1c59177f21acb00fb0be28b93
2022-06-25openbmc_dbus_rest_test: fix headersNan Zhou1-3/+3
The "include/" directory is already in the search path specified by -I, so remove the prefix from the header. Use <> for dependency headers and "" for bmcweb headers. Reference: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html Tested: unit test passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Id0d95d927bb390dba311d9e4f4da3eef4e566ed7
2022-06-24dbus_utility: iwyuNan Zhou1-0/+6
Manually added some missing headers. The "dbus_singleton.hpp" one is causing issues for unit tests: unit test needs to include dbus_singleton even if it just uses a helper function like "getNthStringFromPath". Tested: code compiles. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I28544835a3e4483eb52f53f7ad89d233cadd4143
2022-06-23pam_authenticate: remove unused referenceNan Zhou2-2/+0
The header pam_authenticate isn't referenced at all in these two files. So remove it. Tested: codes compiles Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I4d9ea06dca2ce4d05add710ec3d6cc0df5c1a39d
2022-06-19openbmc_dbus_rest: use auto for json iteratorsNan Zhou1-3/+2
Clang++ complains about ``` error: use of overloaded operator '==' is ambiguous (with operand types 'nlohmann::json::const_iterator' (aka 'iter_impl<const nlohmann::basic_json<>>') and 'nlohmann::basic_json<>::iterator' (aka 'iter_impl<nlohmann::basic_json<>>')) if (argIt == transaction->arguments.end()) ``` Considering we often use auto for iterators, I changed all explict JSON iterator types in this file to auto. Tested: 1. compies on clang; Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I053de0618491dcb01ff8d4e25fe1ebe3c2d3c105
2022-06-18openbmc_dbus_rest_test: refactor testsNan Zhou1-62/+48
Thhis commit added namespace to unit tests and using declarations, which is a common practise to avoid duplicate namespaces in unit tests. It can be shown that after this change, many namespace scoping codes disappear. Tested: 1. Unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I02e221f83c1e330fb57122c8daccbe180ec37a14
2022-06-18openbmc_jtag_rest_test: move to openbmc_dbus_restNan Zhou1-0/+50
This commit does nothing but moving test codes from openbmc_jtag_rest_test.cc, a very old test file whose name is obsolote now, to a more recent and well maintained unit test file (openbmc_dbus_rest_test.cc). Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I3709d18c8ef5cbba5b3f6490a1e9d1798dfc8b52
2022-06-11On logout set Session cookie with expired dateGunnar Mills1-0/+5
The Session cookie is an HttpOnly cookie. HttpOnly means the cookie cannot be accessed through client side script because of this the GUI can not delete this cookie on log out. Recommendation online was setting this cookie to an expired date. From https://tools.ietf.org/search/rfc6265 "Finally, to remove a cookie, the server returns a Set-Cookie header with an expiration date in the past. The server will be successful in removing the cookie only if the Path and the Domain attribute in the Set-Cookie header match the values used when the cookie was created." For more information see https://stackoverflow.com/questions/5285940/correct-way-to-delete-cookies-server-side Modern browsers delete expired cookies although based on reading it might not be right away but on the next request from that domain or when the browser is cleaning up cookies. When I tested the cookie is deleted right away. Also set the SESSION to an empty string. Discussed in discord here: https://discord.com/channels/775381525260664832/855566794994221117/982351098998321163 Webui-vue and phosphor-webui both use this /logout route: https://github.com/openbmc/webui-vue/blob/a5fefd0ad25753e5f7da03d77dfe7fe10255ebb6/src/store/modules/Authentication/AuthenticanStore.js#L50 https://github.com/openbmc/phosphor-webui/blob/339db9a4c8610c5ecb92993c0bbc2219933bc858/app/common/services/userModel.js#L46 It seemed unnecessary to add it to the SessionCollection Post. Tested: No longer have the cookie after log out on webui-vue. Tested on Firefox and Chrome. Signed-off-by: Gunnar Mills <gmills@us.ibm.com> Change-Id: Ic12b6f628293a80c93ffbbe1bf06c9b2d6a53af7
2022-06-06Fix www-authenticate behaviorEd Tanous1-6/+13
bmcweb is in a weird position where, on the one hand, we would like to support Redfish to the specification, while also supporting a secure webui. For better or worse, the webui can't currently use non-cookie auth because of the impacts to things outside of Redfish like websockets. This has lead to some odd code in bmcweb that tries to "detect" whether the browser is present, so we don't accidentally pop up the basic auth window if a user happens to get logged out on an xhr request. Basic auth in a browser actually causes CSRF vulnerabilities, as the browser caches the credentials, so we don't want to make that auth method available at all. Previously, this detection was based on the presence of the user-agent header, but in the years since this code was originally written, a majority of implementations have moved to sending a user-agent by default, which makes this check pretty much useless for its purpose. To work around that, this patchset relies on the X-Requested-With header, to determine if a json payload request was done by xhr. In theory, all browsers will set this header when doing xhr requests, so this should provide a "more correct" solution to this issue. Background: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields "X-Requested-With Mainly used to identify Ajax requests (most JavaScript frameworks send this field with value of XMLHttpRequest)" Tested: curl -vvvv --insecure https://192.168.7.2/redfish/v1/SessionService/Sessions Now returns a WWW-Authenticate header Redfish-protocol-validator now passes 7 more tests from the RESP_HEADERS_WWW_AUTHENTICATE category. Launched webui-vue and logged in. Responses in network tab appear to work, and data populates the page as expected. Used curl to delete redfish session from store with DELETE /redfish/v1/SessionService/Sessions/<SessionId> Then clicked an element on the webui, page forwarded to login page as expected. Opened https://localhost:8000/redfish/v1/CertificateService in a browser, and observed that page forwarded to the login page as it should. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I60345caa41e520c23fe57792bf2e8c16ef144a7a
2022-06-01Try to fix the lambda formatting issueEd Tanous15-1667/+1578
clang-tidy has a setting, LambdaBodyIndentation, which it says: "For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope." bmcweb is very callback heavy code. Try to enable it and see if that improves things. There are many cases where the length of a lambda call will change, and reindent the entire lambda function. This is really bad for code reviews, as it's difficult to see the lines changed. This commit should resolve it. This does have the downside of reindenting a lot of functions, which is unfortunate, but probably worth it in the long run. All changes except for the .clang-format file were made by the robot. Tested: Code compiles, whitespace changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
2022-05-26auth: change authorization.hpp to authentication.hppNan Zhou1-2/+2
The existing authorization header is actually doing "authentication" work. The authorization is happening in routing.hpp where we fetch the role of the authenticated user and get their privilege set. This commits changes the name of the file, as well as the namespace, to be more precise on what the file actually does. Tested: 1. Trivial change, it builds Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Ib91ed70507a7308522c7e5363ed2f4dc279a19d9
2022-05-24bmcweb: fixes virtual media buffer overflowTroy Lee1-2/+3
The bmcweb is implementated as async i/o access, sometimes the input buffer still has unprocessed data, and the next websocket message comes in. The input buffer originally reserved only 1 nbd request packet size, so it will cause buffer overflow exception. Extend the buffer size and correctly check the remaining buffer size. v8: fix coding style v7: remove debug log and proxy.wait() change to keep this change simple v4: fix coding style v3: fix coding style v2: fix coding style Signed-off-by: Troy Lee <troy_lee@aspeedtech.com> Change-Id: I8df2445503393f63401678d9f2486a80d31aee16
2022-05-20google_api: Fix build issueJiaqing Zhao1-1/+2
Commit 4cee35e ("Add RootOfTrustCollection and RootOfTrust under Google service root.") still uses the crow::openbmc_mapper::GetSubTreeType removed in b9d36b4 ("Consitently use dbus::utility types"), causing build failure. This patch fixes the build issue by using the dbus::utility::MapperGetSubTreeResponse instead. Tested: Build pass. Change-Id: Ia2ca965f320ef18f431bfcb6d62c9c44eb935d9d Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
2022-05-20Add RootOfTrustCollection and RootOfTrust under Google service root.Vidya Satyamsetti1-10/+192
These are Google only resources powered by Hoth DBus interface. The ComponentsProtected links is hardcoded for now. But it will be queried from DBus and interpreted accordingly in the future. TEST: $curl -u root:0penBmc -X GET http://[::1]:$PORT/google/v1/RootOfTrustCollection { "@odata.id": "/google/v1/RootOfTrustCollection", "@odata.type": "#RootOfTrustCollection.RootOfTrustCollection", "Members": [ { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth" } ], "Members@odata.count": 1 } $ curl -u root:0penBmc -X GET http://[::1]:$PORT/google/v1/RootOfTrustCollection/Hoth { "@odata.id": "/google/v1/RootOfTrustCollection/Hoth", "@odata.type": "#RootOfTrust.v1_0_0.RootOfTrust", "Actions": { "#RootOfTrust.SendCommand": { "target": "/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand" } }, "Id": "Hoth", "Location": { "PartLocation": { "ServiceLabel": "Hoth", "Locationtype": "Embedded" } }, "Name": "RootOfTrust-Hoth", "Status": { "State": "Enabled" } $ curl -u root:0penBmc -X POST -d @req.json -H "Content-Type: application/json" http://[::1]:$PORT/google/v1/RootOfTrustCollection/Hoth/Actions/RootOfTrust.SendCommand { "CommandResponse": "033B0000" } Signed-off-by: Vidya Satyamsetti <satyamsetti@google.com> Change-Id: If64612468bb89e6d9251d848697608b7daf37339
2022-05-13Separate validFilename into a separate functionJosh Lehan2-2/+43
This will generalize it and make it callable from other places Tested: Added test cases, they pass Signed-off-by: Josh Lehan <krellan@google.com> Change-Id: I8df30d6fe6753a2454d7051cc2d8813ddbf14bad
2022-05-13Remove brace initialization of json objectsEd Tanous6-114/+141
Brace initialization of json objects, while quite interesting from an academic sense, are very difficult for people to grok, and lead to inconsistencies. This patchset aims to remove a majority of them in lieu of operator[]. Interestingly, this saves about 1% of the binary size of bmcweb. This also has an added benefit that as a design pattern, we're never constructing a new object, then moving it into place, we're always adding to the existing object, which in the future _could_ make things like OEM schemas or properties easier, as there's no case where we're completely replacing the response object. Tested: Ran redfish service validator. No new failures. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iae409b0a40ddd3ae6112cb2d52c6f6ab388595fe
2022-05-13Move /bus/system/<str>/<path> POST to methodEd Tanous1-345/+317
Per the reorganization we've done elsewhere, move this large lambda function to simplify it. Tested: Code move only. Code compiles. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib0586b34809167120bdc127868706ac517db4474
2022-05-12Move redfish v1 into redfish-coreEd Tanous1-21/+0
This file has existed for a long time, and predates redfish-core, so it was put in an inopportune place. Move the code to where it should be, in lib. Tested: Code compiles. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I422c27563a5e0f2a5debb2b1d4713aa8db0fe331
2022-04-30Fix unmounting image in proxy mode.Przemyslaw Czarnowski1-1/+1
Sometimes Slot0 got higher key than Slot1 and erase function for Slot1 invalidates elements with keys not less than the erased element. In that case invalid slot0 will be unmounted. Change order of calling close() and erase() functions to unmount correct device. Change-Id: I7a40a4518982f697d3eed635cde6d06978149cf0 Signed-off-by: Alicja Rybak <alicja.rybak@intel.com> Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
2022-04-30Fix compilation of nbd_proxy.hppPrzemyslaw Czarnowski1-4/+6
Fixes compilation errors after introducing * 7772638ea777820234e6004ee63dc558e629e35e Remove AsyncResp from openHandler * b9d36b4791d77a47e1f3c5c4564fcdf7cc68c115 Consistently use dbus::utility types Tested: When nbd_proxy is enabled, code compiles. Change-Id: I6422bbcb7086a8ebc6cc48c7c72636afd1e3ac21 Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>