include: reduce default stack size
[minix.git] / lib / libc / net / minix / getpeereid.c
blob6da016b263744087bfe2120b7db0ad4807ca1202
1 #include <errno.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <sys/socket.h>
6 /*
7 * get the effective user ID and effective group ID of a peer
8 * connected through a Unix domain socket.
9 */
10 int getpeereid(int sd, uid_t *euid, gid_t *egid) {
11 int rc;
12 struct ucred cred;
13 socklen_t ucred_length;
15 /* Initialize Data Structures */
16 ucred_length = sizeof(struct ucred);
17 memset(&cred, '\0', ucred_length);
19 /* Validate Input Parameters */
20 if (euid == NULL || egid == NULL) {
21 errno = EFAULT;
22 return -1;
23 } /* getsockopt will handle validating 'sd' */
25 /* Get the credentials of the peer at the other end of 'sd' */
26 rc = getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &cred, &ucred_length);
27 if (rc == 0) {
28 /* Success - return the results */
29 *euid = cred.uid;
30 *egid = cred.gid;
31 return 0;
32 } else {
33 /* Failure - getsockopt takes care of setting errno */
34 return -1;