summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2001-03-22 04:31:30 +0000
committeralfred <alfred@FreeBSD.org>2001-03-22 04:31:30 +0000
commit281af9370ca4060089860089233faf33682090ff (patch)
tree06c8eb9ac0e2912253da3c85456a24984746c85d /lib
parent2067928f4eb6211420175a84f11a6c8c20eeead0 (diff)
downloadFreeBSD-src-281af9370ca4060089860089233faf33682090ff.zip
FreeBSD-src-281af9370ca4060089860089233faf33682090ff.tar.gz
Hopefully fix some of the bugs in passing credentials over UNIX domain sockets.
Make struct cmessage visible from socket.h (about 4 places were defining it for themselves which wasn't good) Make __rpc_get_local_uid() useable and give it prototype that's visible. Fix some issues with printing out usernames from rpcbind and keyserv.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/rpc/clnt_vc.c9
-rw-r--r--lib/libc/rpc/svc_vc.c49
2 files changed, 32 insertions, 26 deletions
diff --git a/lib/libc/rpc/clnt_vc.c b/lib/libc/rpc/clnt_vc.c
index bce8fbe..433291c 100644
--- a/lib/libc/rpc/clnt_vc.c
+++ b/lib/libc/rpc/clnt_vc.c
@@ -110,12 +110,6 @@ struct ct_data {
XDR ct_xdrs; /* XDR stream */
};
-struct cmessage {
- struct cmsghdr cmsg;
- struct cmsgcred cmcred;
-};
-
-
/*
* This machinery implements per-fd locks for MT-safety. It is not
* sufficient to do per-CLIENT handle locks for MT-safety because a
@@ -785,6 +779,7 @@ time_not_ok(t)
t->tv_usec <= -1 || t->tv_usec > 1000000);
}
+static int
__msgread(sock, buf, cnt)
int sock;
void *buf;
@@ -808,7 +803,7 @@ __msgread(sock, buf, cnt)
return(_recvmsg(sock, &msg, 0));
}
-
+
static int
__msgwrite(sock, buf, cnt)
int sock;
diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c
index 1006988..0e84d6f 100644
--- a/lib/libc/rpc/svc_vc.c
+++ b/lib/libc/rpc/svc_vc.c
@@ -85,8 +85,8 @@ static bool_t svc_vc_reply __P((SVCXPRT *, struct rpc_msg *));
static void svc_vc_rendezvous_ops __P((SVCXPRT *));
static void svc_vc_ops __P((SVCXPRT *));
static bool_t svc_vc_control __P((SVCXPRT *xprt, const u_int rq, void *in));
+static int __msgread_withcred(int, void *, size_t, struct cmessage *);
static int __msgwrite(int, void *, size_t);
-static int __msgread(int, void *, size_t);
struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
u_int sendsize;
@@ -100,12 +100,6 @@ struct cf_conn { /* kept in xprt->xp_p1 for actual connection */
char verf_body[MAX_AUTH_BYTES];
};
-struct cmessage {
- struct cmsghdr cmsg;
- struct cmsgcred cmcred;
-};
-
-
/*
* Usage:
* xprt = svc_vc_create(sock, send_buf_size, recv_buf_size);
@@ -421,17 +415,18 @@ read_vc(xprtp, buf, len)
if (errno == EINTR)
continue;
/*FALLTHROUGH*/
- case 0:
- goto fatal_err;
- default:
- break;
+ case 0:
+ goto fatal_err;
+
+ default:
+ break;
}
} while ((pollfd.revents & POLLIN) == 0);
sa = (struct sockaddr *)xprt->xp_rtaddr.buf;
if (sa->sa_family == AF_LOCAL) {
- if ((len = __msgread(sock, buf, len)) > 0) {
- cm = (struct cmessage *)xprt->xp_verf.oa_base;
+ cm = (struct cmessage *)xprt->xp_verf.oa_base;
+ if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) {
cmp = &cm->cmsg;
sc = (struct sockcred *)(void *)CMSG_DATA(cmp);
xprt->xp_p2 = sc;
@@ -632,17 +627,17 @@ svc_vc_rendezvous_ops(xprt)
mutex_unlock(&ops_lock);
}
-static int
-__msgread(sock, buf, cnt)
+int
+__msgread_withcred(sock, buf, cnt, cmp)
int sock;
void *buf;
size_t cnt;
+ struct cmessage *cmp;
{
struct iovec iov[1];
struct msghdr msg;
- struct cmessage cm;
- bzero((char *)&cm, sizeof(cm));
+ bzero(cmp, sizeof(*cmp));
iov[0].iov_base = buf;
iov[0].iov_len = cnt;
@@ -650,13 +645,13 @@ __msgread(sock, buf, cnt)
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_namelen = 0;
- msg.msg_control = (caddr_t)&cm;
+ msg.msg_control = cmp;
msg.msg_controllen = sizeof(struct cmessage);
msg.msg_flags = 0;
return(_recvmsg(sock, &msg, 0));
}
-
+
static int
__msgwrite(sock, buf, cnt)
int sock;
@@ -685,3 +680,19 @@ __msgwrite(sock, buf, cnt)
return(_sendmsg(sock, &msg, 0));
}
+
+/*
+ * Get the effective UID of the sending process. Used by rpcbind and keyserv
+ * (AF_LOCAL).
+ */
+int
+__rpc_get_local_uid(SVCXPRT *transp, uid_t *uid)
+{
+ struct cmsgcred *cmcred;
+
+ cmcred = __svc_getcallercreds(transp);
+ if (cmcred == NULL)
+ return(-1);
+ *uid = cmcred->cmcred_euid;
+ return(0);
+}
OpenPOWER on IntegriCloud