Commit 6f725390 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

First implementation of memory to file transfer

parent 617bad66
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,4 +13,4 @@ make
make install
cp <build-dir>/etc/norns.service /usr/lib/systemd/system/norns.service

sudo setcap cap_sys_ptrace,cap_chown=+ep ./urd
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ liburd_aux_la_SOURCES = \
	api/request.cpp \
	api/response.hpp \
	api/response.cpp \
	auth/process-credentials.cpp \
	auth/process-credentials.hpp \
	backends.hpp \
	backends/backend-base.cpp \
	backends/backend-base.hpp \
+1 −2
Original line number Diff line number Diff line
@@ -62,8 +62,7 @@ public:
            [this](const boost::system::error_code& ec) {
                if(!ec) {
                    std::make_shared<session<Message>>(
                            std::move(m_socket),
                            m_dispatcher
                            std::move(m_socket), m_dispatcher
                        )->start();
                }

+19 −1
Original line number Diff line number Diff line
@@ -55,8 +55,10 @@
#include <memory>
#include <vector>
#include <string>
#include <boost/optional.hpp>

#include "common.hpp"
#include "auth/process-credentials.hpp"

namespace norns {

@@ -106,6 +108,9 @@ struct request {

    virtual ~request() {}
    virtual request_type type() const = 0;
    virtual boost::optional<auth::credentials> credentials() const = 0;
    virtual void set_credentials(boost::optional<auth::credentials>&& creds) = 0;
    virtual void set_credentials(const boost::optional<auth::credentials>& creds) = 0;
    virtual std::string to_string() const = 0;

    static request_ptr create_from_buffer(const std::vector<uint8_t>& data, int size);
@@ -140,10 +145,22 @@ struct request_impl : std::tuple<FieldTypes...>, request {
        : std::tuple<FieldTypes...>(std::forward<FieldTypes>(fields)...),
          m_type(RT) { }

    request_type type() const override {
    request_type type() const override final {
        return m_type;
    }

    boost::optional<auth::credentials> credentials() const override final {
        return m_credentials;
    }

    void set_credentials(boost::optional<auth::credentials>&& creds) override final {
        m_credentials = creds;
    }

    void set_credentials(const boost::optional<auth::credentials>& creds) override final {
        m_credentials = creds;
    }

    // this is the implementation for the generic to_string() 
    // function for any RT that is not known. For known RTs, we 
    // provide concrete specializations in the cpp file
@@ -157,6 +174,7 @@ struct request_impl : std::tuple<FieldTypes...>, request {
    }

    request_type m_type;
    boost::optional<auth::credentials> m_credentials;
};

} // namespace detail
+14 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <boost/filesystem.hpp>

#include "common.hpp"
#include "auth/process-credentials.hpp"

namespace ba = boost::asio;
namespace bfs = boost::filesystem;
@@ -110,7 +111,19 @@ private:
                        if(!ec) {
                            Input req = m_message.decode_body(length);

                            Output resp = m_dispatcher->run(req->type(), std::move(req));
                            // if credentials were not provided in the requests payload,
                            // the request probably originated locally. In that case, we
                            // try to get the credentials from the local calling process 
                            // from the connection socket. If this also fails, 
                            // req->credentials() is set to boost::none, and it becomes
                            // the invoked handler's responsibility to validate the request
                            if(!req->credentials()) {
                                req->set_credentials(
                                        auth::credentials::fetch(m_socket));
                            }

                            Output resp = m_dispatcher->invoke(
                                    req->type(), std::move(req));

                            assert(resp != nullptr);

Loading