While coming across a build error in kdebase-runtime-4.4.5/kdesu/kdesud/, I noticed the following thread from a few months ago:

http://old.nabble.com/Patch%3A-kdebase-runtime-4.4.5-td29186298.html

The somewhat more expanded version of the code in question is here:

-----------------------------------
#if defined(SO_PEERCRED)

SocketSecurity::SocketSecurity(int sockfd) : pid(-1), gid(-1), uid(-1)
{
    ucred cred;
    ksocklen_t len = sizeof(struct ucred);
    if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0) {
        kError() << "getsockopt(SO_PEERCRED) " << perror << endl;
        return;
    }
    pid = cred.pid;
    gid = cred.gid;
    uid = cred.uid;
}

#else
# if defined(HAVE_GETPEEREID)
SocketSecurity::SocketSecurity(int sockfd) : pid(-1), gid(-1), uid(-1)
{
    uid_t euid;
    gid_t egid;
    if (getpeereid(sockfd, &euid, &egid) == 0) {
        uid = euid;
        gid = egid;
        pid = -1;
    }
}

# else
-----------------------------------

However, looking over getsockopt(2), I noticed the following:

"STANDARDS
     SO_PEERCRED is not supported, see getpeereid(2) instead."

With this in mind, I'm wondering if the better solution would be to skip the SO_PEERCRED define check, and use getpeereid instead. If so how would the check best be skipped? My first thought is just to put the HAVE_GETPEEREID at the top, but I don't know if that would have some sort of negative impact for other OSes. Another method would be add an additional check against !defined(__OPENBSD__), but I'd rather test against features than OSes if possible, unless it's the only option I have left. Thanks ahead of time for any suggestions.

- Onteria

Reply via email to