am 6fd75635
: Merge "Fetch peer credentials for local sockets" into gingerbread
Merge commit '6fd75635d820754295557c300ccee89c643864cc' into gingerbread-plus-aosp * commit '6fd75635d820754295557c300ccee89c643864cc': Fetch peer credentials for local sockets
This commit is contained in:
commit
1db75e7b9b
2 changed files with 31 additions and 2 deletions
|
@ -4,16 +4,29 @@
|
|||
#include "../../../frameworks/base/include/utils/List.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
class SocketClient {
|
||||
int mSocket;
|
||||
pthread_mutex_t mWriteMutex;
|
||||
|
||||
/* Peer process ID */
|
||||
pid_t mPid;
|
||||
|
||||
/* Peer user ID */
|
||||
uid_t mUid;
|
||||
|
||||
/* Peer group ID */
|
||||
gid_t mGid;
|
||||
|
||||
public:
|
||||
SocketClient(int sock);
|
||||
virtual ~SocketClient() {}
|
||||
|
||||
int getSocket() { return mSocket; }
|
||||
pid_t getPid() const { return mPid; }
|
||||
uid_t getUid() const { return mUid; }
|
||||
gid_t getGid() const { return mGid; }
|
||||
|
||||
int sendMsg(int code, const char *msg, bool addErrno);
|
||||
int sendMsg(const char *msg);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <alloca.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
@ -9,9 +10,24 @@
|
|||
|
||||
#include <sysutils/SocketClient.h>
|
||||
|
||||
SocketClient::SocketClient(int socket) {
|
||||
mSocket = socket;
|
||||
SocketClient::SocketClient(int socket)
|
||||
: mSocket(socket)
|
||||
, mPid(-1)
|
||||
, mUid(-1)
|
||||
, mGid(-1)
|
||||
{
|
||||
pthread_mutex_init(&mWriteMutex, NULL);
|
||||
|
||||
struct ucred creds;
|
||||
socklen_t szCreds = sizeof(creds);
|
||||
memset(&creds, 0, szCreds);
|
||||
|
||||
int err = getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
|
||||
if (err == 0) {
|
||||
mPid = creds.pid;
|
||||
mUid = creds.uid;
|
||||
mGid = creds.gid;
|
||||
}
|
||||
}
|
||||
|
||||
int SocketClient::sendMsg(int code, const char *msg, bool addErrno) {
|
||||
|
|
Loading…
Reference in a new issue