summaryrefslogtreecommitdiffstats
path: root/kdesu/kdesud/secure.h
blob: edf58d9c6123aa0031561e6a7767f62c9b48a661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* vi: ts=8 sts=4 sw=4
 *
 * This file is part of the KDE project, module tdesu.
 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
 */

#ifndef __Secure_h_included__
#define __Secure_h_included__

#include "config.h"

#include <sys/types.h>
#include <sys/socket.h>

#ifndef HAVE_STRUCT_UCRED

// `struct ucred' is not defined in glibc 2.0.

struct ucred {
    pid_t     pid;
    uid_t     uid;
    gid_t     gid;
};

#endif // HAVE_STRUCT_UCRED


/**
 * The Socket_security class autheticates the peer for you. It provides
 * the process-id, user-id and group-id plus the MD5 sum of the connected
 * binary.
 */

class SocketSecurity {
public:
    SocketSecurity(int fd);

    /** Returns the peer's process-id. */
    int peerPid() { if (!ok) return -1; return cred.pid; }

    /** Returns the peer's user-id */
    int peerUid() { if (!ok) return -1; return cred.uid; }

    /** Returns the peer's group-id */
    int peerGid() { if (!ok) return -1; return cred.gid; }

private:
    bool ok;
    struct ucred cred;
};

#endif