~raof/mir/symbols-file

« back to all changes in this revision

Viewing changes to src/server/frontend/socket_session.cpp

Implement a connection authorization mechanism.

Approved by Gerry Boland, Alan Griffiths, Robert Ancell, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "socket_session.h"
20
20
 
21
21
#include <boost/signals2.hpp>
 
22
#include <boost/throw_exception.hpp>
 
23
 
 
24
#include <stdexcept>
 
25
 
22
26
#include <sys/types.h>
23
27
#include <sys/socket.h>
24
28
 
156
160
        BOOST_THROW_EXCEPTION(std::runtime_error(error.message()));
157
161
    }
158
162
}
 
163
 
 
164
pid_t mfd::SocketSession::client_pid()
 
165
{
 
166
    struct ucred cr;
 
167
    socklen_t cl = sizeof(cr);
 
168
    
 
169
    auto status = getsockopt(socket.native_handle(), SOL_SOCKET, SO_PEERCRED, &cr, &cl);
 
170
    
 
171
    if (status)
 
172
        BOOST_THROW_EXCEPTION(std::runtime_error("Failed to query client socket credentials"));
 
173
    return cr.pid;
 
174
}