aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/rpc/svc_vc.c
diff options
context:
space:
mode:
authorAlfred Perlstein <alfred@FreeBSD.org>2001-03-22 04:31:30 +0000
committerAlfred Perlstein <alfred@FreeBSD.org>2001-03-22 04:31:30 +0000
commit4ed6d63483283e86585a89ad889766e30c8cd865 (patch)
tree557943cf2416192a9ed920cedf91b6d7830b9ecc /lib/libc/rpc/svc_vc.c
parent2f7aab1c2674154bd642d4244454d31ea09fcefc (diff)
downloadsrc-4ed6d63483283e86585a89ad889766e30c8cd865.tar.gz
src-4ed6d63483283e86585a89ad889766e30c8cd865.zip
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.
Notes
Notes: svn path=/head/; revision=74627
Diffstat (limited to 'lib/libc/rpc/svc_vc.c')
-rw-r--r--lib/libc/rpc/svc_vc.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c
index 1006988e769c..0e84d6fdb4c5 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);
+}