- From 80130d82bac62a58a7a4429ebff48bdb1180d8ac Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 4 Mar 2024 09:47:17 +0100
- Subject: [PATCH 1/3] libtirpc: Add wintirpc wrappers for |bind()|+|connect()|
- Add wintirpc wrappers for |bind()|--->|wintirpc_bind()|
- and |connect()|--->|wintirpc_connect()|.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- libtirpc/src/auth_time.c | 7 +++++--
- libtirpc/src/bindresvport.c | 4 ++--
- libtirpc/src/clnt_dg.c | 4 ++--
- libtirpc/src/clnt_vc.c | 2 +-
- libtirpc/src/rpc_soc.c | 4 ++--
- libtirpc/src/rpcb_clnt.c | 2 +-
- libtirpc/src/rtime.c | 2 +-
- libtirpc/src/svc_generic.c | 4 ++--
- libtirpc/src/wintirpc.c | 10 ++++++++++
- libtirpc/tirpc/wintirpc.h | 2 ++
- 10 files changed, 28 insertions(+), 13 deletions(-)
- diff --git a/libtirpc/src/auth_time.c b/libtirpc/src/auth_time.c
- index 2794534..95faae8 100644
- --- a/libtirpc/src/auth_time.c
- +++ b/libtirpc/src/auth_time.c
- @@ -425,7 +425,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid)
- saw_alarm = 0;
- /* XXX Need Windows signal/alarm stuff here XXX */
- #endif
- - res = connect(_get_osfhandle(s), (struct sockaddr *)&sin, sizeof(sin));
- + res = wintirpc_connect(s, (struct sockaddr *)&sin, sizeof(sin));
- if (res == SOCKET_ERROR) {
- msg("failed to connect to tcp endpoint.");
- goto error;
- @@ -434,8 +434,11 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid)
- msg("alarm caught it, must be unreachable.");
- goto error;
- }
- -// res = read(_get_osfhandle(s), (char *)&thetime, sizeof(thetime));
- +#ifndef _WIN32
- + res = read(s, (char *)&thetime, sizeof(thetime));
- +#else
- res = (int)wintirpc_recv(s, (char *)&thetime, sizeof(thetime), 0);
- +#endif
- if (res != sizeof(thetime)) {
- if (saw_alarm)
- msg("timed out TCP call.");
- diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
- index 874a589..d33deb7 100644
- --- a/libtirpc/src/bindresvport.c
- +++ b/libtirpc/src/bindresvport.c
- @@ -125,7 +125,7 @@ bindresvport_sa(sd, sa)
- *portp = htons(port++);
- if (port > endport)
- port = startport;
- - res = bind(_get_osfhandle(sd), sa, salen);
- + res = wintirpc_bind(sd, sa, salen);
- if (res >= 0 || errno != EADDRINUSE)
- break;
- }
- @@ -242,7 +242,7 @@ bindresvport_sa(sd, sa)
- }
- #endif
- - error = bind(_get_osfhandle(sd), sa, salen);
- + error = wintirpc_bind(sd, sa, salen);
- if (error) {
- int err = WSAGetLastError();
- }
- diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
- index 9798a8c..7541656 100644
- --- a/libtirpc/src/clnt_dg.c
- +++ b/libtirpc/src/clnt_dg.c
- @@ -366,7 +366,7 @@ clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
- nextsend_time = cu->cu_wait.tv_sec * 1000 + cu->cu_wait.tv_usec / 1000;
- if (cu->cu_connect && !cu->cu_connected) {
- - if (connect(_get_osfhandle(cu->cu_fd), (struct sockaddr *)&cu->cu_raddr,
- + if (wintirpc_connect(cu->cu_fd, (struct sockaddr *)&cu->cu_raddr,
- cu->cu_rlen) < 0) {
- cu->cu_error.re_errno = errno;
- cu->cu_error.re_status = RPC_CANTSEND;
- @@ -477,7 +477,7 @@ get_reply:
- msg.msg_flags = 0;
- msg.msg_control = cbuf;
- msg.msg_controllen = 256;
- - ret = recvmsg (_get_osfhandle(cu->cu_fd), &msg, MSG_ERRQUEUE);
- + ret = recvmsg (cu->cu_fd, &msg, MSG_ERRQUEUE);
- if (ret >= 0
- && memcmp (cbuf + 256, cu->cu_outbuf, ret) == 0
- && (msg.msg_flags & MSG_ERRQUEUE)
- diff --git a/libtirpc/src/clnt_vc.c b/libtirpc/src/clnt_vc.c
- index 3753462..6a4639c 100644
- --- a/libtirpc/src/clnt_vc.c
- +++ b/libtirpc/src/clnt_vc.c
- @@ -413,7 +413,7 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz, cb_xdr, cb_fn, cb_args)
- // thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
- goto err;
- }
- - if (connect(_get_osfhandle(fd), (struct sockaddr *)raddr->buf, raddr->len) == SOCKET_ERROR){
- + if (wintirpc_connect(fd, (struct sockaddr *)raddr->buf, raddr->len) == SOCKET_ERROR){
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = WSAGetLastError();
- mutex_unlock(&clnt_fd_lock);
- diff --git a/libtirpc/src/rpc_soc.c b/libtirpc/src/rpc_soc.c
- index 3073dac..5e5302a 100644
- --- a/libtirpc/src/rpc_soc.c
- +++ b/libtirpc/src/rpc_soc.c
- @@ -546,7 +546,7 @@ clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz)
- if (*sockp == SOCKET_ERROR) {
- *sockp = wintirpc_socket(AF_UNIX, SOCK_STREAM, 0);
- len = SUN_LEN(raddr);
- - if ((*sockp == -1) || (connect(_get_osfhandle(*sockp),
- + if ((*sockp == -1) || (wintirpc_connect(*sockp,
- (struct sockaddr *)raddr, len) == SOCKET_ERROR)) {
- rpc_createerr.cf_stat = RPC_SYSTEMERROR;
- rpc_createerr.cf_error.re_errno = errno;
- @@ -604,7 +604,7 @@ svcunix_create(sock, sendsize, recvsize, path)
- addrlen = sizeof(struct sockaddr_un);
- sa = (struct sockaddr *)&sun;
- - if (bind(_get_osfhandle(sock), sa, addrlen) == SOCKET_ERROR)
- + if (wintirpc_bind(sock, sa, addrlen) == SOCKET_ERROR)
- goto done;
- taddr.addr.len = taddr.addr.maxlen = addrlen;
- diff --git a/libtirpc/src/rpcb_clnt.c b/libtirpc/src/rpcb_clnt.c
- index 906db37..5e94d33 100644
- --- a/libtirpc/src/rpcb_clnt.c
- +++ b/libtirpc/src/rpcb_clnt.c
- @@ -682,7 +682,7 @@ __rpcbind_is_up()
- sun.sun_family = AF_UNIX;
- strncpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
- - if (connect(_get_osfhandle(sock), (struct sockaddr *)&sun, sizeof(sun)) == SOCKET_ERROR) {
- + if (wintirpc_connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == SOCKET_ERROR) {
- wintirpc_close(sock);
- return (FALSE);
- }
- diff --git a/libtirpc/src/rtime.c b/libtirpc/src/rtime.c
- index d6856b6..beaf828 100644
- --- a/libtirpc/src/rtime.c
- +++ b/libtirpc/src/rtime.c
- @@ -123,7 +123,7 @@ rtime(addrp, timep, timeout)
- return(-1);
- }
- } else {
- - if (connect(_get_osfhandle(s), (struct sockaddr *)addrp, sizeof(*addrp)) == SOCKET_ERROR) {
- + if (wintirpc_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) == SOCKET_ERROR) {
- do_close(s);
- return(-1);
- }
- diff --git a/libtirpc/src/svc_generic.c b/libtirpc/src/svc_generic.c
- index 7ba0bfc..24b0479 100644
- --- a/libtirpc/src/svc_generic.c
- +++ b/libtirpc/src/svc_generic.c
- @@ -224,7 +224,7 @@ svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
- if (bindresvport(fd, NULL) < 0) {
- memset(&ss, 0, sizeof ss);
- ss.ss_family = si.si_af;
- - if (bind(_get_osfhandle(fd), (struct sockaddr *)(void *)&ss,
- + if (wintirpc_bind(fd, (struct sockaddr *)(void *)&ss,
- (socklen_t)si.si_alen) == SOCKET_ERROR) {
- warnx(
- "svc_tli_create: could not bind to anonymous port");
- @@ -233,7 +233,7 @@ svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz)
- }
- wintirpc_listen(fd, SOMAXCONN);
- } else {
- - if (bind(_get_osfhandle(fd),
- + if (wintirpc_bind(fd,
- (struct sockaddr *)bindaddr->addr.buf,
- (socklen_t)si.si_alen) == SOCKET_ERROR) {
- warnx(
- diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
- index 53f6eab..47f0c96 100644
- --- a/libtirpc/src/wintirpc.c
- +++ b/libtirpc/src/wintirpc.c
- @@ -335,6 +335,16 @@ int wintirpc_accept(int in_s_fd, struct sockaddr *addr, int *addrlen)
- return out_s_fd;
- }
- +int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen)
- +{
- + return bind(_get_osfhandle(s), name, namelen);
- +}
- +
- +int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen)
- +{
- + return connect(_get_osfhandle(s), name, namelen);
- +}
- +
- wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len, int flags)
- {
- /* handle type overflow |size_t| ---> |int| */
- diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
- index 4cb145f..fbf7c66 100644
- --- a/libtirpc/tirpc/wintirpc.h
- +++ b/libtirpc/tirpc/wintirpc.h
- @@ -141,6 +141,8 @@ int wintirpc_closesocket(int in_fd);
- int wintirpc_close(int in_fd);
- int wintirpc_listen(int in_s, int backlog);
- int wintirpc_accept(int s_fd, struct sockaddr *addr, int *addrlen);
- +int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen);
- +int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen);
- wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len,
- int flags);
- wintirpc_ssize_t wintirpc_sendto(int s, const char *buf, size_t len,
- --
- 2.43.0
- From bd608e2ad37f2be7d899c54d912a4f0a8d82c56b Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 4 Mar 2024 19:12:31 +0100
- Subject: [PATCH 2/3] libtirpc: Add wintirpc wrappers for
- |getsockopt|+|setsockopt()|
- Add wintirpc wrappers for |getsockopt()|--->|wintirpc_getsockopt()|
- and |setsockopt()|--->|wintirpc_setsockopt()|.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- libtirpc/src/bindresvport.c | 8 ++++----
- libtirpc/src/clnt_bcast.c | 4 ++--
- libtirpc/src/clnt_dg.c | 2 +-
- libtirpc/src/clnt_generic.c | 2 +-
- libtirpc/src/getpeereid.c | 2 +-
- libtirpc/src/rpc_generic.c | 6 +++---
- libtirpc/src/svc_vc.c | 2 +-
- libtirpc/src/wintirpc.c | 22 ++++++++++++++++++----
- libtirpc/tirpc/wintirpc.h | 4 ++++
- 9 files changed, 35 insertions(+), 17 deletions(-)
- diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
- index d33deb7..01d1921 100644
- --- a/libtirpc/src/bindresvport.c
- +++ b/libtirpc/src/bindresvport.c
- @@ -185,7 +185,7 @@ bindresvport_sa(sd, sa)
- #ifdef _WIN32
- memset(sa, 0, salen);
- - if (error = getsockopt(_get_osfhandle(sd), SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
- + if (error = wintirpc_getsockopt(sd, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
- int sockerr = WSAGetLastError();
- return -1;
- }
- @@ -231,11 +231,11 @@ bindresvport_sa(sd, sa)
- if (*portp == 0) {
- socklen_t oldlen = sizeof(old);
- - error = getsockopt(_get_osfhandle(sd), proto, portrange, &old, &oldlen);
- + error = wintirpc_getsockopt(sd, proto, portrange, &old, &oldlen);
- if (error < 0)
- return (error);
- - error = setsockopt(_get_osfhandle(sd), proto, portrange, &portlow,
- + error = wintirpc_setsockopt(sd, proto, portrange, &portlow,
- sizeof(portlow));
- if (error < 0)
- return (error);
- @@ -252,7 +252,7 @@ bindresvport_sa(sd, sa)
- int saved_errno = errno;
- if (error < 0) {
- - if (setsockopt(_get_osfhandle(sd), proto, portrange, &old,
- + if (wintirpc_setsockopt(sd, proto, portrange, &old,
- sizeof(old)) < 0)
- errno = saved_errno;
- return (error);
- diff --git a/libtirpc/src/clnt_bcast.c b/libtirpc/src/clnt_bcast.c
- index 6ee6e60..411a3b2 100644
- --- a/libtirpc/src/clnt_bcast.c
- +++ b/libtirpc/src/clnt_bcast.c
- @@ -249,12 +249,12 @@ __rpc_broadenable(int af, int s, struct broadif *bip)
- #if 0
- if (af == AF_INET6) {
- fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
- - if (setsockopt(_get_osfhandle(s), IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
- + if (wintirpc_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
- sizeof bip->index) < 0)
- return -1;
- } else
- #endif
- - if (setsockopt(_get_osfhandle(s), SOL_SOCKET, SO_BROADCAST, &o, sizeof o) == SOCKET_ERROR)
- + if (wintirpc_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) == SOCKET_ERROR)
- return -1;
- return 0;
- diff --git a/libtirpc/src/clnt_dg.c b/libtirpc/src/clnt_dg.c
- index 7541656..de318e6 100644
- --- a/libtirpc/src/clnt_dg.c
- +++ b/libtirpc/src/clnt_dg.c
- @@ -281,7 +281,7 @@ clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz)
- #ifdef IP_RECVERR
- {
- int on = 1;
- - setsockopt(_get_osfhandle(fd), SOL_IP, IP_RECVERR, &on, sizeof(on));
- + wintirpc_setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on));
- }
- #endif
- ioctlsocket(_get_osfhandle(fd), FIONBIO, &one);
- diff --git a/libtirpc/src/clnt_generic.c b/libtirpc/src/clnt_generic.c
- index 92ec08d..a7756bb 100644
- --- a/libtirpc/src/clnt_generic.c
- +++ b/libtirpc/src/clnt_generic.c
- @@ -404,7 +404,7 @@ clnt_tli_create(const int fd_in, const struct netconfig *nconf,
- if (nconf &&
- ((strcmp(nconf->nc_protofmly, "inet") == 0) ||
- (strcmp(nconf->nc_protofmly, "inet6") == 0))) {
- - setsockopt(_get_osfhandle(fd), IPPROTO_TCP, TCP_NODELAY, (const char *)&one,
- + wintirpc_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one,
- sizeof (one));
- }
- cl = clnt_vc_create(fd, svcaddr, prog, vers, sendsz, recvsz,
- diff --git a/libtirpc/src/getpeereid.c b/libtirpc/src/getpeereid.c
- index 17b1a5c..c328b9c 100644
- --- a/libtirpc/src/getpeereid.c
- +++ b/libtirpc/src/getpeereid.c
- @@ -50,7 +50,7 @@ getpeereid(int s, uid_t *euid, gid_t *egid)
- int error;
- uclen = sizeof(uc);
- - error = getsockopt(_get_osfhandle(s), SOL_SOCKET, SO_PEERCRED, &uc, &uclen); /* SCM_CREDENTIALS */
- + error = wintirpc_getsockopt(s, SOL_SOCKET, SO_PEERCRED, &uc, &uclen); /* SCM_CREDENTIALS */
- if (error != 0)
- return (error);
- // if (uc.cr_version != XUCRED_VERSION)
- diff --git a/libtirpc/src/rpc_generic.c b/libtirpc/src/rpc_generic.c
- index 9491761..e5c8274 100644
- --- a/libtirpc/src/rpc_generic.c
- +++ b/libtirpc/src/rpc_generic.c
- @@ -490,7 +490,7 @@ __rpc_fd2sockinfo(int fd, struct __rpc_sockinfo *sip)
- #ifdef _WIN32
- WSAPROTOCOL_INFO proto_info;
- int proto_info_size = sizeof(proto_info);
- - if (getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
- + if (wintirpc_getsockopt(fd, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
- int err = WSAGetLastError();
- return 0;
- }
- @@ -505,7 +505,7 @@ __rpc_fd2sockinfo(int fd, struct __rpc_sockinfo *sip)
- sip->si_alen = len;
- len = sizeof type;
- - if (getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_TYPE, (char *)&type, &len) == SOCKET_ERROR) {
- + if (wintirpc_getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&type, &len) == SOCKET_ERROR) {
- int err = WSAGetLastError();
- return 0;
- }
- @@ -570,7 +570,7 @@ __rpc_nconf2fd(const struct netconfig *nconf)
- si.si_af == AF_INET6) {
- int val = 1;
- - setsockopt(_get_osfhandle(fd), SOL_IPV6, IPV6_V6ONLY, (const char *)&val, sizeof(val));
- + wintirpc_setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const char *)&val, sizeof(val));
- }
- return fd;
- }
- diff --git a/libtirpc/src/svc_vc.c b/libtirpc/src/svc_vc.c
- index 5345d4a..83c58fe 100644
- --- a/libtirpc/src/svc_vc.c
- +++ b/libtirpc/src/svc_vc.c
- @@ -359,7 +359,7 @@ again:
- if (__rpc_fd2sockinfo(sock, &si) && si.si_proto == IPPROTO_TCP) {
- len = 1;
- /* XXX fvdl - is this useful? */
- - setsockopt(_get_osfhandle(sock), IPPROTO_TCP, TCP_NODELAY, (const char *)&len, sizeof (len));
- + wintirpc_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&len, sizeof (len));
- }
- cd = (struct cf_conn *)newxprt->xp_p1;
- diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
- index 47f0c96..003958a 100644
- --- a/libtirpc/src/wintirpc.c
- +++ b/libtirpc/src/wintirpc.c
- @@ -337,12 +337,12 @@ int wintirpc_accept(int in_s_fd, struct sockaddr *addr, int *addrlen)
- int wintirpc_bind(int s, const struct sockaddr *name, socklen_t namelen)
- {
- - return bind(_get_osfhandle(s), name, namelen);
- + return bind(_get_osfhandle(s), name, namelen);
- }
- int wintirpc_connect(int s, const struct sockaddr *name, socklen_t namelen)
- {
- - return connect(_get_osfhandle(s), name, namelen);
- + return connect(_get_osfhandle(s), name, namelen);
- }
- wintirpc_ssize_t wintirpc_send(int s, const char *buf, size_t len, int flags)
- @@ -368,8 +368,8 @@ wintirpc_ssize_t wintirpc_recv(int socket, void *buffer, size_t length, int flag
- }
- wintirpc_ssize_t wintirpc_recvfrom(int socket, void *restrict buffer, size_t length,
- - int flags, struct sockaddr *restrict address,
- - socklen_t *restrict address_len)
- + int flags, struct sockaddr *restrict address,
- + socklen_t *restrict address_len)
- {
- /* handle type overflow |size_t| ---> |int| */
- assert(length < INT_MAX);
- @@ -382,6 +382,20 @@ int wintirpc_getsockname(int s, struct sockaddr *name, int *namelen)
- return getsockname(_get_osfhandle(s), name, namelen);
- }
- +int wintirpc_getsockopt(int socket, int level, int option_name,
- + void *restrict option_value, socklen_t *restrict option_len)
- +{
- + return getsockopt(_get_osfhandle(socket), level, option_name,
- + option_value, option_len);
- +}
- +
- +int wintirpc_setsockopt(int socket, int level, int option_name,
- + const void *option_value, socklen_t option_len)
- +{
- + return setsockopt(_get_osfhandle(socket), level, option_name,
- + option_value, option_len);
- +}
- +
- void wintirpc_syslog(int prio, const char *format, ...)
- {
- const char *prio_s;
- diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
- index fbf7c66..c1f7f22 100644
- --- a/libtirpc/tirpc/wintirpc.h
- +++ b/libtirpc/tirpc/wintirpc.h
- @@ -153,6 +153,10 @@ wintirpc_ssize_t wintirpc_recvfrom(int socket, void *restrict buffer,
- size_t length, int flags, struct sockaddr *restrict address,
- socklen_t *restrict address_len);
- int wintirpc_getsockname(int s, struct sockaddr *name, int *namelen);
- +int wintirpc_getsockopt(int socket, int level, int option_name,
- + void *restrict option_value, socklen_t *restrict option_len);
- +int wintirpc_setsockopt(int socket, int level, int option_name,
- + const void *option_value, socklen_t option_len);
- void wintirpc_syslog(int prio, const char *format, ...);
- void wintirpc_warnx(const char *format, ...);
- void wintirpc_register_osfhandle_fd(SOCKET handle, int fd);
- --
- 2.43.0
- From 87108a78b5de3a87efb65fcc061a47246a41ee38 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 4 Mar 2024 19:16:01 +0100
- Subject: [PATCH 3/3] daemon: More workarounds/hacks for
- getattr-afer-file-close
- More work on the workarounds/hacks for the getattr-afer-file-close
- issue.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/getattr.c | 19 ++++++-----------
- daemon/nfs41.h | 5 ++++-
- daemon/nfs41_session.c | 7 ++++++
- daemon/open.c | 48 ++++++++++++++++++++++++++++++++++++++++++
- daemon/upcall.c | 16 +++++++++++++-
- 5 files changed, 80 insertions(+), 15 deletions(-)
- diff --git a/daemon/getattr.c b/daemon/getattr.c
- index 9cfb00d..7975cc8 100644
- --- a/daemon/getattr.c
- +++ b/daemon/getattr.c
- @@ -82,25 +82,18 @@ static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *u
- goto out;
- }
- - /*
- - * If |upcall->state_ref| is garbage, then this should trigger
- - * an exception
- - */
- - volatile int ok = 0;
- - __try {
- - if (upcall->state_ref->session->client != NULL)
- - ok++;
- - }
- - __except(EXCEPTION_EXECUTE_HANDLER) {
- - eprintf("parse_getattr: Exception accessing "
- + if (!isvalidnfs41_open_state_ptr(upcall->state_ref)) {
- + eprintf("parse_getattr: Error accessing "
- "upcall->state_ref(=0x%p)->session->client\n",
- upcall->state_ref);
- - }
- - if (ok != 1) {
- status = ERROR_INVALID_PARAMETER;
- goto out;
- }
- EASSERT(upcall->state_ref->ref_count > 0);
- + if (upcall->state_ref->ref_count == 0) {
- + status = ERROR_INVALID_PARAMETER;
- + goto out;
- + }
- #endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- getattr_upcall_args *args = &upcall->args.getattr;
- diff --git a/daemon/nfs41.h b/daemon/nfs41.h
- index 53dec06..1c2be42 100644
- --- a/daemon/nfs41.h
- +++ b/daemon/nfs41.h
- @@ -23,6 +23,7 @@
- #ifndef __NFS41__
- #define __NFS41__
- +#include <stdbool.h>
- #include "util.h"
- #include "list.h"
- @@ -538,7 +539,9 @@ void nfs41_open_state_ref(
- void nfs41_open_state_deref(
- IN nfs41_open_state *state);
- -
- +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
- +bool isvalidnfs41_open_state_ptr(nfs41_open_state *state_ref);
- +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- struct __stateid_arg;
- void nfs41_open_stateid_arg(
- IN nfs41_open_state *state,
- diff --git a/daemon/nfs41_session.c b/daemon/nfs41_session.c
- index d7e5011..1447ab7 100644
- --- a/daemon/nfs41_session.c
- +++ b/daemon/nfs41_session.c
- @@ -24,6 +24,7 @@
- #include <process.h>
- #include <stdio.h>
- +#include "nfs41_build_features.h"
- #include "nfs41_ops.h"
- #include "nfs41_callback.h"
- #include "util.h"
- @@ -442,5 +443,11 @@ void nfs41_session_free(
- }
- DeleteCriticalSection(&session->table.lock);
- ReleaseSRWLockExclusive(&session->client->session_lock);
- +
- +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
- + (void)memset(session, 0, sizeof(nfs41_session));
- + debug_delayed_free(session);
- +#else
- free(session);
- +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- }
- diff --git a/daemon/open.c b/daemon/open.c
- index 3342fb1..4c739ae 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -121,6 +121,47 @@ static void open_state_free(
- #endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- }
- +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
- +bool isvalidnfs41_open_state_ptr(nfs41_open_state *state_ref)
- +{
- + /*
- + * If |>state_ref| is garbage, then this should trigger
- + * an exception
- + */
- + volatile int mark = 0;
- + __try {
- + if (state_ref != NULL) {
- + mark++;
- + if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref)) {
- + mark++;
- + if (state_ref->session != NULL) {
- + mark++;
- + if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref->session)) {
- + mark++;
- + if (state_ref->session->client != NULL) {
- + mark++;
- + if (DEBUG_IS_VALID_NON_NULL_PTR(state_ref->session->client)) {
- + mark++;
- + }
- + }
- + }
- + }
- + }
- + }
- + } __except(EXCEPTION_EXECUTE_HANDLER) {
- + eprintf("isvalidnfs41_open_state_ptr: Exception accessing "
- + "state_ref(=0x%p)->session->client, mark=%d\n",
- + state_ref, mark);
- + }
- +
- + if (mark == 6) {
- + return true;
- + }
- +
- + return false;
- +}
- +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- +
- /* open state reference counting */
- void nfs41_open_state_ref(
- IN nfs41_open_state *state)
- @@ -1116,6 +1157,13 @@ out:
- static void cleanup_close(nfs41_upcall *upcall)
- {
- +#ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
- + EASSERT(upcall->state_ref != INVALID_HANDLE_VALUE);
- + if (upcall->state_ref == INVALID_HANDLE_VALUE) {
- + return;
- + }
- +#endif /* NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS */
- +
- /* release the initial reference from create_open_state() */
- nfs41_open_state_deref(upcall->state_ref);
- }
- diff --git a/daemon/upcall.c b/daemon/upcall.c
- index 82fc5d2..126e740 100644
- --- a/daemon/upcall.c
- +++ b/daemon/upcall.c
- @@ -122,8 +122,22 @@ int upcall_parse(
- #ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
- if (upcall->state_ref != INVALID_HANDLE_VALUE) {
- + if (!isvalidnfs41_open_state_ptr(upcall->state_ref)) {
- + eprintf("upcall_parse: Error accessing "
- + "upcall->state_ref(=0x%p), opcode %d; "
- + "returning ERROR_INVALID_PARAMETER\n",
- + upcall->state_ref, upcall->opcode);
- + /*
- + * Set |upcall->state_ref| to |INVALID_HANDLE_VALUE|
- + * so that we do not try to dereference it
- + */
- + upcall->state_ref = INVALID_HANDLE_VALUE;
- + status = ERROR_INVALID_PARAMETER;
- + goto out;
- + }
- +
- if (upcall->state_ref->ref_count == 0) {
- - eprintf("upcall->state_ref(=0x%p).ref_count == 0, "
- + eprintf("upcall_parse: upcall->state_ref(=0x%p).ref_count == 0, "
- "opcode %d; returning ERROR_INVALID_PARAMETER\n",
- upcall->state_ref, upcall->opcode);
- /*
- --
- 2.43.0
msnfs41client: getattr-after-close2-hacks+wintirpc wrappers, 2024-03-04
Posted by Anonymous on Mon 4th Mar 2024 18:43
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.